问:
Proper way to measure the scalability of web Application
Let's say that I have a Web Application where I'm going to have 300 users and each one have to see data on real-time, imagine that each client make an ajax call to the server to see in real time what's happens with the changes of the data, this calls are made each 300 ms per user. I know that I can run a simulation to see if the hardware of my server supports this example. But what happens if the number of users starts to grow up. Is there a way that I can measure the hardware needed to handle this growing behaviour, a software, a formula, algorithm or maybe recommend me if I need to implement a distributed application with multiplies servers and balance the loads.</p>

答:
My recommendation is just to test it. You'll learn more about the behaviour of your code that way. To perform the testing, there are a wide variety of synthetic load testing tools - my personal preference is Gatling, but JMeter, golang's "hey" tool, and others exist to support this.

If you want to do paper based, though, as a basic starter, you could extrapolate from your current results. Eg: if you use 20% CPU to do 1000 users, then 2000 users you might do 40% CPU. This breaks down very quickly though as it depends strongly on your application.

Next along is queueing theory and Markov chains. This gets a little statistical/mathematical but can give you some good insight into the system.


问:
I Want To Program!
I am highly interested in learning how to program but I am unsure whether I want to lean towards web developing or software programming. Or does computer programming cover both in a nut shell? Where should or how should I start?</p>

答:
Interest is something that is developed when you actually work on that thing.

So IMHO you should give a try to both for some amount of time.Later find out the pros and cons of working with both.

Try finding out which one was easier to code or to understand,which one made you curious and develop inside you want to learn more.

Speaking about Computer Programming  its really a very wide topic.

Web Application and Software Programming is nothing less wider.

Web application is not just setting up a website and connecting to the database.Its much more then that.

You need to be very creative while designing a website to attract more people more over the security concerns is also an important aspect.

You also have different technologies to develop an web app.Getting familiar with the technologies will be something you will need to do on your own.

Software Programming its not just your desktop applications.You also have your CNC programming, OS , Drivers ,Gaming and much more. Technologies that you use are also numerous.

One More thing I want you to consider is the Market condition what's the latest thing.
Have a try at it cause its easier to find a job with a Latest technology knowledge then the one that is Outdated.

ContentLicense: CC BY-SA 3.0

Title: I Want To Program!


答:
Web development isn't exactly programming at first.

Web development is centered on formatting and displaying a semi-static page to the user. One does not need algorithms etc for this(not much at any rate), one just needs some aesthetic sense.

On the other hand, when you program, you start off with logic. I feel that this is a better thing to do, because once you know programming, segueing into webdev is pretty easy.

The "learning web development" process is like this:

Learn HTML/CSS . This is not programming.

Learn a bit of javascript for simple interactiveness. You still don't really learn programming this way.

Design some web pages. No programming required(HTML!=programming), its all aesthetic sense.

Decide to learn stuff like PHP. For most practical purposes of webdev, you still aren't programming much.

Learn advanced JS and advanced PHP. Use it. Now you're programming.

The "learn programming language" process is like this:

Learn basic syntax. If, for, while.

Learn about functions.

Write great algorithms. This is programming.

Web development focuses on the content displayed to the user. There really aren't too many algorithms etc involved--devising algorithms is what makes programming great--and you don't really need to apply any logical skills.

On the other hand, programming does focus on content, but it also heavily focusses on optimization and algorithms. You really have to think here. Besides, most programming languages are more structured.

Actually, over here, it really depends on what you're interested in. I find logical thinking more fun. Webdesigning only becomes fun for me when there's a large structured environment involved. The simple stuff you mostly do in webdev gets boring. For you, it may be different. You may want to try out both programming and webdev simultaneously(not too hard--they don't conflict).

Just a note:In contrast with whatever I said here, I personally started my foray into programming via HTML. I learned JS, and I went to other programming languages from there. But that's only because I focussed on algorithms even while scripting JS.

Title: I Want To Program!

Body: I am highly interested in learning how to program but I am unsure whether I want to lean towards web developing or software programming. Or does computer programming cover both in a nut shell? Where should or how should I start?</p>


问:
creative & complex vs simple and readable
Which is a better option?

It's not always that when you have something creative your code is going to look ugly.

But at times it does go a bit ugly.

e.g.

```<code>if ( (object1(0)==object2(0) &&
     (object1(1)==object2(1) &&
     (object1(2)==object2(2) &&
     (object1(3)==object2(3) )
    retval = true;
else
    retval = false;
</code>```

is simple and readable

```<code>bool retValue = (object1(0)==object2(0)) &&
                (object1(1)==object2(1)) &&
                (object1(2)==object2(2)) &&
                (object1(3)==object2(3));
</code>```

but having something like this will make some newbies scratch their heads.

So what do I go for? including simple code everywhere might sometime hamper my performance.

What I could think of was commenting wherever necessary but at times you get too curious to know what is actually happening.

答:
Others have covered the "what's good/bad"-- here's an additional point that may have been missed:

Newbies scratching their heads is good.

By "newbie", I mean new programmer. Not "new addition to team".

Whenever a newbie scratches his head, he learns something. He may have to ask someone else, but he'll learn in the end. The example you've given is readable to any intermediate programmer, and will teach the fact that "the conditions inside ifs can be used directly to make bools--thus conditional statements are bools". Pretty useful thing to know--but AFAIK never really explained in books/courses.


答:
It depends on where your interest really lies. I like to communicate and interact with the operating systems directly. So I go with software programming. You get to learn about the system more.

Web programming can be divided into client side and server side programming. In client side you do stuffs using javascript, css, html and the like and on the server side you can use the technology depending on the server you choose. Of course the server can also do presentation.

In both cases you have to deal with the same thing, i.e. the logic, presentation, persistence.

What differs is the programming language and the technology stack.

Title: I Want To Program!


问:
while(true) and loop-breaking - anti-pattern?
Consider the following code:

public void doSomething(int input)
{
   while(true)
   {
      TransformInSomeWay(input);

      if(ProcessingComplete(input))
         break;

      DoSomethingElseTo(input);
   }
}
```

<p>Assume that this process involves a finite but input-dependent number of steps; the loop is designed to terminate on its own as a result of the algorithm, and is not designed to run indefinitely (until cancelled by an outside event). Because the test to see if the loop should end is in the middle of a logical set of steps, the while loop itself currently doesn't check anything meaningful; the check is instead performed at the "proper" place within the conceptual algorithm.</p>

<p>I was told that this is bad code, because it is more bug-prone due to the ending condition not being checked by the loop structure. It's more difficult to figure out how you'd exit the loop, and could invite bugs as the breaking condition might be bypassed or omitted accidentally given future changes.</p>

<p>Now, the code could be structured as follows:</p>

<pre class="lang-java prettyprint-override"><code>public void doSomething(int input)
{
   TransformInSomeWay(input);

   while(!ProcessingComplete(input))
   {
      DoSomethingElseTo(input);
      TransformInSomeWay(input);
   }
}
</code>```

However, this duplicates a call to a method in code, violating DRY; if TransformInSomeWay were later replaced with some other method, both calls would have to be found and changed (and the fact that there are two may be less obvious in a more complex piece of code).

You could also write it like:

public void doSomething(int input)
{
   var complete = false;
   while(!complete)
   {
      TransformInSomeWay(input);

      complete = ProcessingComplete(input);

      if(!complete)
      {
         DoSomethingElseTo(input);
      }
   }
}
```

... but you now have a variable whose only purpose is to shift the condition-checking to the loop structure, and also has to be checked multiple times to provide the same behavior as the original logic.

For my part, I say that given the algorithm this code implements in the real world, the original code is the most readable. If you were going through it yourself, this is the way you'd think about it, and so it would be intuitive to people familiar with the algorithm.

So, which is "better"? is it better to give the responsibility of condition checking to the while loop by structuring the logic around the loop? Or is it better to structure the logic in a "natural" way as indicated by requirements or a conceptual description of the algorithm, even though that may mean bypassing the loop's built-in capabilities?

答:
I've trouble to find the other solutions better than the one with break. Well, I prefer the Ada way which allows to do

```<code>loop
  TransformInSomeWay(input);
exit when ProcessingComplete(input);
  DoSomethingElseTo(input);
end loop;
</code>```

but the break solution is the cleanest rendering.

My POV is that when there is a missing control structure, the cleanest solution is to emulate it with other control structures, not using data flow. (And similarly, when I have a data flow problem to prefer pure data flow solutions to the one involving control structures *).

It's more difficult to figure out how you'd exit the loop,

Don't be mistaken, the discussion wouldn't take place if the difficulty wasn't mostly the same: the condition is the same and present at the same place.

Which of

while (true) {
   XXXX
if (YYY) break;
   ZZZZ;
}
```

<p>and </p>

<pre class="lang-java prettyprint-override"><code>while (TTTT) {
    XXXX
    if (YYYY) {
        ZZZZ
    }
}
</code>```

render better the intended structure? I'm voting for the first, you don't have to check that the conditions matches. (But see my indentation).

ContentLicense: CC BY-SA 4.0

Body:
I've trouble to find the other solutions better than the one with break. Well, I prefer the Ada way which allows to do

loop
  TransformInSomeWay(input);
exit when ProcessingComplete(input);
  DoSomethingElseTo(input);
end loop;

but the break solution is the cleanest rendering.

My POV is that when there is a missing control structure, the cleanest solution is to emulate it with other control structures, not using data flow. (And similarly, when I have a data flow problem to prefer pure data flow solutions to the one involving control structures *).

It's more difficult to figure out how you'd exit the loop,

Don't be mistaken, the discussion wouldn't take place if the difficulty wasn't mostly the same: the condition is the same and present at the same place.

Which of

while (true) {
   XXXX
if (YYY) break;
   ZZZZ;
}

and

while (TTTT) {
    XXXX
    if (YYYY) {
        ZZZZ
    }
}

render better the intended structure? I'm voting for the first, you don't have to check that the conditions matches. (But see my indentation).


问:
CodeIgniter routing helping
Can you explain these two lines of code in
applications/config/routes.php file in the CodeIgniter framework?

```<code>$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
</code>```

答:
The following information is taken from the CodeIgniter-Documentation under http://codeigniter.com/user_guide/general/routing.html.

Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route that permits you to specify your own routing criteria. Routes can either be specified using wildcards or Regular Expressions

So your first line of code would redirect any call to your domain, when the URI contains no data to the view-Method in the pages-class like that:
http://example.com/ would redirect to http://example.com/pages/view/

The second line would redirect any call to the pages-class/view-method and pass the original URI as parameter like that:

http://example.com/articles/ would redirect to http://example.com/pages/view/articles/

So, basically you're setting up a Front Controller with these two lines.
Hope that helps.

EDIT:

In CodeIgniter, each URL can be splitted into class, method and data as stated here.
Example: http://example.com/classname/methodname/somedata.
Normally, calling the URL http:/example.com/show/1 would call the method 1 in the class article. Your second line of code would redirect this call to http://example.com/pages/view/articles/1 and therefor call the method  view in the class pages passing the arguments "articles" and "1" as data.

I would like to encourage you to read through the excellent CI-Documentation to fully understand those principles.

Title: CodeIgniter routing helping


问:
If I were to start doing a GUI how do I decide on what platform to use?
I hear about WPF, Silverlight but then there is also windows RT, metro stuff, windows 8 and so on at the moment - I'm having a hard time nailing what to bet on.

How do I, at a given point in time, find the best platform for doing somewhat future-proof GUI?

答:
You do not.  You write your code logic such that the GUI layer can easily be replaced with a different one -- code to an interface not an implementation.  As @Max states in his comment, this indeed does not need to be in your application language as long as you have a way to call it from said application. </p>

<p>As far as framework go, WX widgets could be useful as an example of how others have done a GUI that wrapps different implementations.  I am not suggesting that this is the one you should use. </p>

Body:
You do not.  You write your code logic such that the GUI layer can easily be replaced with a different one -- code to an interface not an implementation.  As @Max states in his comment, this indeed does not need to be in your application language as long as you have a way to call it from said application.

As far as framework go, WX widgets could be useful as an example of how others have done a GUI that wrapps different implementations.  I am not suggesting that this is the one you should use.


答:
You could do Load Testing with something like Apache JMeter This would allow for far tests with heavy load and if you install it on several machines could test for concurrency. It's scriptable, so you could write very complex user interactions. I haven't used it for some time now, but remember, that it allowed for a lot of options how to test your website.
Other alternatives are: Selenium, Watir, HtmlUnit, siege</p>

Title: Proper way to measure the scalability of web Application

Body: Let's say that I have a Web Application where I'm going to have 300 users and each one have to see data on real-time, imagine that each client make an ajax call to the server to see in real time what's happens with the changes of the data, this calls are made each 300 ms per user. I know that I can run a simulation to see if the hardware of my server supports this example. But what happens if the number of users starts to grow up. Is there a way that I can measure the hardware needed to handle this growing behaviour, a software, a formula, algorithm or maybe recommend me if I need to implement a distributed application with multiplies servers and balance the loads.</p>


答:
The answer of all answers: It depends

When you are developing a application you have to make some decisions:

Should it be a Webapp ? (aspx for example)

Should it be a Desktop App?

Which system do use my users?

etc pp.

So in this point you can think about abstraction. Encapsulate your pure logic in different assemblies and build only a UI Layer on top. In this way you can use different UI-Strategies.

But seriously: When you want to develop for Windows 8 be sure that the .NET 4.5 and the Windows RT has some difference to .NET 4.0 which is runable on XP, 7, Server ect. pp. So it is up to you and your customers which UI you are going to develop.

Title: If I were to start doing a GUI how do I decide on what platform to use?

Body:
I hear about WPF, Silverlight but then there is also windows RT, metro stuff, windows 8 and so on at the moment - I'm having a hard time nailing what to bet on.

How do I, at a given point in time, find the best platform for doing somewhat future-proof GUI?


问:
Introducing functional programming constructs in non-functional programming languages
This question has been going through my mind quite a lot lately and since I haven't found a convincing answer to it I would like to know if other users
of this site have thought about it as well.

In the recent years, even though OOP is still the most popular programming paradigm, functional programming is getting a lot of attention. I have only
used OOP languages for my work (C++ and Java) but I am trying to learn some
FP in my free time because I find it very interesting.

So, I started learning Haskell three years ago and Scala last summer. I plan to
learn some SML and Caml as well, and to brush up my (little) knowledge of Scheme. Well, a lot of plans (too ambitious?) but I hope I will find the time
to learn at least the basics of FP during the next few years.
What is important for me is how functional programming works and how / whether
I can use it for some real projects. I have already developed small tools in Haskell.

In spite of my strong interest for FP, I find it difficult to understand why
functional programming constructs are being added to languages like C#, Java, C++, and so on. As a developer interested in FP, I find it more natural to
use, say, Scala or Haskell, instead of waiting for the next FP feature
to be added to my favourite non-FP language.
In other words, why would I want to have only some FP in my originally
non-FP language instead of looking for a language that has a better support
for FP?

For example, why should I be interested to have lambdas in Java if I can switch
to Scala where I have much more FP concepts and access all the Java libraries
anyway?
Similarly: why do some FP in C# instead of using F# (to my knowledge,
C# and F# can work together)?

Java was designed to be OO. Fine. I can do OOP in Java (and I would like to keep using Java in that way). Scala was designed to support OOP + FP. Fine: I can use a mix of OOP and FP in Scala. Haskell was designed for FP: I can do FP in Haskell. If I need to tune the performance of a particular module, I can
interface Haskell with some external routines in C.

But why would I want to do OOP with just some basic FP in Java?

So, my main point is: why are non-functional programming languages being extended with some functional concept?
Shouldn't it be more comfortable (interesting, exciting, productive) to
program in a language that has been designed from the very beginning to
be functional or multi-paradigm? Don't different programming paradigms
integrate better in a language that was designed for it than in a language
in which one paradigm was only added later?

The first explanation I could think of is that, since FP is a new concept
(it isn't new at all, but it is new for many developers), it needs to be
introduced gradually. However, I remember my switch from imperative to OOP:
when I started to program in C++ (coming from Pascal and C) I really had to
rethink the way in which I was coding, and to do it pretty fast.
It was not gradual. So, this does not seem to be a good explanation to me.

Or can it be that many non-FP programmers are not really interested in
understanding and using functional programming, but they find it practically
convenient to adopt certain FP-idioms in their non-FP language?

IMPORTANT NOTE

Just in case (because I have seen several language wars on this site):
I mentioned the languages I know better, this question is in no way
meant to start comparisons between different programming
languages to decide which is better / worse.

Also, I am not interested in a comparison of OOP versus FP (pros and cons).
The point I am interested in is to understand why FP is being introduced
one bit at a time into existing languages that were not designed for it
even though there exist languages that were / are specifically designed
to support FP.

答:
Take a look at LINQ - it would not be possible without those some  FP features, whereas it hides all the scary FP stuff under the bonnet.

FP features are very useful for those who implement somewhat complicated libraries and frameworks - it is unreasonable to use a different language for such things. "End users", all the average enterprisey programmers, won't need to know anything about that arcane features, but they're happy to use the libraries built upon FP extensions.


问:
Which of these looks cleaner?
I have wrote a small method in a program to do one thing my method looks like this:

```<code>public static void removeExpiredAssignments(Module module){
    module.removeExpiredAssignments();
}
</code>```

So the method is called like:

```<code>removeExpiredAssignments(module);
</code>```

When the desired operation could be done by saying:

```<code>module.removeExpiredAssignments();
</code>```

Which is easy to understand from the code point of view?

答: Java still feels alien to me but I would expect to find the module.functionCall(); syntax; it really is "the java way". I was brought up in C (almost 20 years ago) and the function declaration feels old fashioned even to me, so that's saying something.

Title: Which of these looks cleaner?


答:
How do I, at a given point in time, find the best platform for doing somewhat future-proof GUI?

INMO, this is a desirable goal but neither realistic or well defined.

It is not well defined because you really should quantify the 'future' part. It is not realistic because history tells us that GUI technologies are the fastest to change, and their changes are radical.

Back to your question, one needs to see why this is important in real life applications. You see, even older technologies are not always dropped suddenly and the live for a long time.
Control vendors are still providing upgrades to Windows Forms application GUI components. You can develop a touch-based application today using Windows Forms. Something you probably can't do with native out-of-the box newer Silverlight!

The first thing I would do is to decide on your expected user environment. Next, I would identify the types of devices that the application must run on (applets, mobiles, web, desktop, etc.), then you check the supporting languages and tools.

WPF and Silverlight will still live, though may not be the magnet for improvement dollars. XAML, in some form, will be used in the Windows 8 world. if you think along the Silverlight path, then check the System Requirements matrix on MS-Silverlight.

Developing an application that is not dependent on the GUI, does not sound very realistic for many commercial business applications at least. The extra complexity is very difficult to justify. What business people sometimes tend to find is that the technology outlives the business model some applications are built on. (I remember a project we did for a large bank that lived for 3 months only because another bank acquired the one we did the project for :)).

If you are heading in the web direction, you may want to consider HTML 5 and JavaScript with 3rd party controls. There are good ones evolving these days.

Good luck.


答:
Looking at the current trends at Microsoft, you cannot future-proof your UI if you tighten it to a given framework. You need some abstraction to make your application future-proof, and there are good design patterns for that (see Model-View-Presenter and Model-View-ViewModel).

If you do not need tight control over how things look exactly, you can have a generic UI framework like wxWidgets, QT and SWT or a framework that helps you to avoid too much binding to your UI framework, something like Caliburn Micro.


答:
There are too many aspects to consider: your customers needs, the permissions you want to have on a system, the UX feel you want to give to your app, etc.

Metro apps are great for touch¹ and great for full-screen single application user experience. You can have several valid reasons to do a Metro app:

2D game like BabySmash,

A basic, single-tab, web browser which will mostly be used to access one or few websites (read the e-mails and go to Facebook) or a single website (kiosk mode),

A kiosk app,

Very technical and specialized apps for very specialized employees. For example, a multitouch Metro app is great for system monitoring where you can zoom on graphs, switch to more detailed visualizations by taping on thumbnails, etc. Note that in this case, the application remains always on, since the machine is intended for monitoring only.

Silverlight is great for:

Apps which cannot use HTML 5 (for the reasons of compatibility with legacy browsers) or they must use some features not available in HTML 5,

Apps to use inside a company, which doesn't require lots of permissions or a strong integration with the company infrastructure (accessing Active Directory? Printing something with no action from the user? Writing to shared folders?).

In both cases, the great point is that system administrators doesn't have to deal with installing/keeping secure/updating tasks related to your app.

WPF applications are great for everything else. If you need strong integration or additional permissions and if you know that your app will be used as a business app, side by side with others, in a daily work with no touch, go for an ordinary WPF app.

Don't forget about HTML. If your customers are non-technical people who will be never unable (or want to) install additional software, update it and maintain it without third party help, or if your customers use MacOS and would not run Windows on a virtual machine just to use your app, don't go with Metro/Silverlight/WPF at all. You have to use plain HTML/XHTML. It may either be HTML 5 if you know that 95% of your users will support it, or an older version if not. Flash is a solution too, since it's popular enough to be installed on most computers.

¹ It's not because they are Metro apps that they are automatically great for touch. You, as a developer/interaction design expert, must know how to implement efficiently the touch/multitouch to your app. Nothing is more annoying that an app which is intended to be multitouch and which does it totally wrongly (being at the same time unusable with mouse and/or keyboard, because the developer doesn't care that some people still use those input devices).


问:
What is a generic term for name/identifier? (as opposed to label)
I need to refer to a number of things that have both an identifier value (used in code and configuration), and a human-readable label. These things include:

database columns

dropdown items

subapplications

objects stored in a dictionary

I want two unambiguous terms. One to refer to the identifier/value/key. One to refer to the label.

As you can see, I'm pretty settled on the latter :) For the former, identifier seems best (not everything is strictly a key, and value and name could refer to the label; although, identifier usually refers only to a variable name), but I would prefer to follow an established practice if there is one.

Is there an established term for this? (Please provide a source.) If not, are there any examples of a choice from a significant source (Java APIs, MSDN, a big FLOSS project)?

(I wasn't sure if this should be posted here or to English Language & Usage. I thought this was the more appropriate expert audience. Happy to migrate if not.)

答: I'd go with id, both as the term most commonly used (in my experience) and as a personal preference.


答: A commonly used term is Name-value pair. The name part being the identifier and value being what you refer to as label.

Title: What is a generic term for name/identifier? (as opposed to label)

Body:
I need to refer to a number of things that have both an identifier value (used in code and configuration), and a human-readable label. These things include:

database columns

dropdown items

subapplications

objects stored in a dictionary

I want two unambiguous terms. One to refer to the identifier/value/key. One to refer to the label.

As you can see, I'm pretty settled on the latter :) For the former, identifier seems best (not everything is strictly a key, and value and name could refer to the label; although, identifier usually refers only to a variable name), but I would prefer to follow an established practice if there is one.

Is there an established term for this? (Please provide a source.) If not, are there any examples of a choice from a significant source (Java APIs, MSDN, a big FLOSS project)?

(I wasn't sure if this should be posted here or to English Language & Usage. I thought this was the more appropriate expert audience. Happy to migrate if not.)


问:
Do I have to remove my app from app store? (Copyright infringement)
I just got an copyright infringement notice that says my app infringes on the usage policies of the services my app uses.

However, this mail does not come directly from the company that runs the website I pull information from.
The mail comes from a company that has some paid apps in the same category on the app store (mine is free), so they obviously want me gone.

My question is, can I just ignore this mail until I hear directly from the company that runs the website? Judging from their (the company that contacted me) website, they have no connection what so ever to the company that I fetch information from.

答: Do you agree with the assessment in the letter? Are you infringing on the usage policy? If so, you should stop. This isn't a matter of "keep going until you get caught by the right person". If you're infringing, stop.</p>


答: Be proactive and contact the company who runs the service you are using, and ask them if they are ok with your app being available on the app store, and with the way it uses their services. This approach has benefits: If you ignore the email from this competing company, they might inform the service owners of your app, which might lead them to ask you to take it down. If you approach them directly they might take a more lenient view as it shows you are willing to comply with their terms and not sneak something by them (even if that's what you've been doing so far).</p>

Title: Do I have to remove my app from app store? (Copyright infringement)

Body:
I just got an copyright infringement notice that says my app infringes on the usage policies of the services my app uses.

However, this mail does not come directly from the company that runs the website I pull information from.
The mail comes from a company that has some paid apps in the same category on the app store (mine is free), so they obviously want me gone.

My question is, can I just ignore this mail until I hear directly from the company that runs the website? Judging from their (the company that contacted me) website, they have no connection what so ever to the company that I fetch information from.


答: You must get the opinion of a lawyer. They could be just trying to stomp you out without any real legal case.</p>


问:
Java API Deprecations
Who decides the API deprecations the JEE specification or the vendor of JDK like Sun, IBM?</p>

答: The Spec Lead and the EG group will decide via a JSR as part of the Java Community Process.  They are typically conservative in their deprecation and remove cycles.</p>

Title: Java API Deprecations


问:
Planning development when academic research is involved
Dear fellow programmers,

how do you do "software planning" when academic research is involved? And, on a side note, how do you convince your boss that writing software is not like building a house and it's more like writing a novel?

The gory details are below.

I am in charge of a small dev team working in a research lab. We started developing a software with the purpose of going public one day (i.e. sell and make money off that). Such software depends on, amongst other things, at least two independent research lines: that is, there are at least two Ph.D. candidates that will, hopefully, one day come out with a working implementation of what we need.

The main software depends also on other, more concrete resources that we as developers can take care of: graphics rendering, soft bodies deformation, etc.

My boss asked me to write the specifications, requirements AND a bloody GANTT chart of the entire project. Faced with the fact that I don't have a clue about the research part, and that such research is fundamental for the software, he said "make assumptions." For the clarity of the argument, he is a professor whose Ph.D. students should come up with the research we need. And he comes from a strictly engineering background: plan everything first, write down specifications and only then write down code that "it's the last part".

What I am doing now:

I broke down the product in features; each 'feature' is, de facto, a separate product;

Each feature is built on top of the previous one;

Once a feature (A) has a working prototype the team can start working on the next feature (B), while QA for is being done for A (if money allows, more people can be brought in, etc.);

Features that depend on research will come last: by then, hopefully, the research part will be completed (when is still a big question) ;

Also, I set the team to use SCRUM for the development of 'version 1.0', due in a few months. This deadline could be set based on reasonable assumptions: we listed all required features, we counted our availability, and we gave a reasonable estimate.

So my questions, again, are:

How do I make my boss happy while at the same time get something out the door?

How do I write specifications for something we -the developers- have no clue whether it's possible to do or not? (We still haven't decided which libraries to use for some tasks; we'll do so when we'll need to)

How do I get the requirements for that, given that there are yet no clients nor investors, just lots of interests and promises?

How do I get peace in the world?

I am sure at least one of my questions will be answered :)

ps: I am writing this anonymously since a potential investor might backfire if this is discovered. Hope you'll understand. However I must say I do not like this mentality of 'hiding the truth': this program will likely benefit many, and not being able to talk openly about this (with my name and my reputation attached) feels like censorship. But alas, I care more about your suggestions now.

答: I think in research development planning stuff in one go and tgen developing does not really work well. I work at a research institute, and we work more using rapid prototyping. Often developing a prototype yields the insight into what is needed exactly. By rapidly creating a prototype you can get feedback from your boss and the researchers and determine if this was what they where expecting, and also see if your approach works. Afterwards you can refactor and improve your code. This is what I see in practice at the research institutes where I worked.</p>


问:
Adding scripting capability to a .NET application
I already have a working implementation that adds scripting to an application. The application currently generates and compiles scripts from C# snippets (taken from different user provides configuration files) into assemblies using the CodeDOM. As it sounded like a good idea at first I ran into following issues:

difficult AppDomain handling and need for Serialization

performance issue => frequent script changes trigger a recompilation

changes cannot be made in-place in the scripts while running

difficult to provide a GUI for debugging (breakpoints), the script writer actually needs a debugger...

I "hacked" a solution against 1 by loading everything in the main AppDomain. The problem is that nothing can be unloaded... After some time the memory use is huge.

For this reason I eventually would consider to switch to an interpreted solution but want to remain near to a C# language because of the existing code-base. There is a bunch of libs around Vsa, S#, Script.NET, ... I need to access objects in my application from the scripts and also run methods in the scripts from my application. Do you also think that switching to an interpreted language the right strategy or should I try to add a debug mode to the existing concept by injecting code like calling a method between each line of the script to allow a step by step execution.... However the AppDomain handling remains a nightmare to handle.

It is certainly not the first time someone runs in such a situation. I could not find any FOSS wrapper/helper library to make the CodeDOM handling easier nor GUI elements to provide building blocks for a minimal debugger. Currently I built ma own GUI and step over calls in the scripts and show changes in the application objects (before/after calls) inside the GUI.

Please only refer to FOSS source/libs.

答:
You can reuse the machinery in Mono's C# Shell. It does what you've being doing with some improvements, like using a library containing a C# compiler, instead of running the command line one...

http://www.mono-project.com/CsharpRepl

Adding automatic imports and referenced assemblies is quite easy, to make them available for your users.

It is dual licensed under the terms of the MIT X11 or GNU GPL

Code at https://github.com/mono/mono/tree/master/mcs/tools/csharp

OwnerDisplayName: jdehaan


答: I would favour Identity over Identifier. The identifier is the value of the identity, if that makes sense.


问:
Java dev learning Python: what concepts do I need to wrap my head around?
Background: I've run through a few tutorials and written some small projects. All is going well enough using Google and StackOverflow.

Several times in the last few days I've found myself wondering "what am I missing?" - I feel that I'm still thinking in Java as I write in Python.

This question over at StackOverflow is full of tips about what resources to read up on  for learning Python, but I still feel that I'm a Java developer with a dictionary (no pun intended) to translate into Python.

What I really want to do is refactor my head to be able to write Pythonic Python instead of Java disguised as Python, without losing my Java skills either.

So, the crux of my question is: what concepts does a Java dev really need to learn to think Pythonic?  This includes anything that needs to be unlearned.

Note: I am asking about language concepts, not about language syntax.

答:
You may also want to take a look at Jython. It may only support Python 2.5, but we find it really powerful to be able to rapid prototype with Python and then rewrite in Java later if necessary.

 Based on my answer to What should I think about when switching from Python to Java? as that question has now been closed as a duplicate of this one!


问:
Why is JavaScript not used for classical application development (compiled software)?
During my years of web development with JavaScript, I come to the conclusion that it's an incredible powerful language, and you can do amazing things with it.

It offers a rich set of features, like:

Dynamic typing

First-class functions

Nested functions

Closures

Functions as methods

Functions as Object constructors

Prototype-based

Objects-based (almost everything is an object)

Regex

Array and Object literals

It seems to me that almost everything can be achieved with this kind of language, you can also emulate OO programming, since it provides great freedom and many different coding styles.

With more software-oriented custom functionalities (I/O, FileSystem, Input devices, etc.) I think it will be great to develop applications with.

Though, as far as I know, it's only used in web development or in existing softwares as a scripting language only.

Only recently, maybe thanks to the V8 Engine, it's been used more for other kind of tasks (see node.js for example).

Why until now it's only be relegated only to web development? What is keeping it away from software development?

答:
From here:

Note that I am basing all my arguments on real-world use cases.
  Counter-arguments that can't be backed up with an example of use in a
  real, complete, interesting, useful applications are invalid. I've
  seen the little "language demos" everyone else has, I've seen the blog
  posts detailing how prototypes and dynamic typing make some trivial
  little example a few lines shorter than it would be in C#, but those
  simply aren't relevant to the problems you run into writing real
  code rather than micro-demos and toys. So here's my gripes with JS:

a) Magic 'this'. This is this, except when this is that. JavaScript
  pushes you to use anonymous functions all over the place, except they
  always end up losing the proper context for the 'this' variable, so
  you end up having goofy code like "var _this = this" all over the
  place and then using that inside your callbacks or other functions.
  Some days I swear that the number of functions I manage to write that
  don't use a renamed 'this' are actually smaller than the number that
  do.

b) 1 + "1" - 1 = 10. Also, "1" + 0 = "10". Yes, this actually has
  caused bugs for our applications, where data that's expected to be a
  number was loaded from a JSON file as a string due to a bug in another
  application, and the result was not good. All our loading code had to
  be updated to add a ton of type conversions all over the place. When I
  need something to be a number I really freaking absolutely want it to
  be a number, not a string or an object or null or anything else. Lua,
  which is very similar to JavaScript in most respects, fixed this
  problem by just not being retarded enough to use the same operator for
  addition and string concatenation.

c) Global by default variables. So even if you take the argument that
  dynamic typing is just "easier" because you don't have to think about
  variable declarations, JavaScript throws that argument out the window
  by making you put 'var' in front of new identifiers all over the
  place. And then it silently screws you if you forget to.

d) Prototypes instead of classes. There are very few large-scale
  real-world JavaScript applications in existence that don't plug in
  their own class system to work around the inherent uselessness of
  prototypes in large application architecture. Those same apps make
  minimal use of prototypes to extend the base JavaScript types, and
  only because JS was so poorly designed that even the two interesting
  built-in types it comes with are lacking half the features you'd
  expect them to have.

e) Inability to create pass-by-value types. This is a frequent problem
  in just about every language aside from C++/D, actually. For those
  using JavaScript to write WebGL apps, take a look at all the linear
  algebra libraries for JavaScript. In 3D apps, you almost use vectors
  more often than you do scalars. Imagine if every integer in your app
  was passed by reference, so that "a = 1; b = a; b++" made both a and b
  equal to 2. Every little three component vector is a complete full
  object. They are passed by reference (the source of almost a half of
  the bugs in our WebGL game so far, in fact). They exist in great
  quantity, are heap-allocated, and are garbage-collected, which puts an
  intense amount of pressure on the GC which can and does result in GC
  pauses in even simple WebGL games, unless the developer jump through
  ridiculously complicated hoops to avoid creating new vectors in all
  the places where it's logical to create new vectors. You can't have
  operator overloading, so you have very large and ugly expressions to
  do basic operations. Accessing individual components is slow. The
  objects aren't natively packed and hence are incredibly slow to push
  into a vertex buffer, unless you implement them as a Float32Array
  instances, which confuses the crap out of the optimizers of both V8
  and SpiderMonkey currently. Did I mention they're passed by reference?

f) No built-in include or require functionality. Seriously, still.
  Third-party libraries exist but almost all of them have some kind of
  bug or another, not least of which is a confusing caching problem in
  at least Chrome making doing actual development a pain in the butt.

g) Dynamic typing. Yes, I'm willing to start that argument. You start
  noticing it the most the second you stop writing little Web apps or
  Web pages and start writing large apps where you actually have data
  that persists for longer than a single mouse click or request/response
  cycle: add the wrong kind of object to an array to process later and
  get a crash later from a missing method or member in a completely
  different bit of code than where the actual mistake was. Fun times.
  Yes, Java makes static typing seem evil. No, Java/C#/C++ are not the
  one and only way to do static typing. Type inference, implicit
  interface binding, etc. give you all the "easy to deal with and not a
  lot of keystrokes" advantages of dynamic typing without all the bugs.
  The second most popular Web language -- ActionScript 3 -- is
  statically typed, in fact, despite otherwise being identical to
  JS/ECMAScript. As an aside, I get more crashes from the Python apps on
  my Fedora desktop than I do from the C/C++ apps (actually, none of the
  C/C++ apps on my desktop crash, now that I think about it). Missing
  member exceptions == so much easier to develop and maintain apps,
  right?

h) Speed. Yes, there has been some ridiculously immense amounts of
  effort by a large number of super bad-ass developers put into the
  language runtimes to make JS almost half as fast as a low-grade C
  compiler that a single college Junior could write in a few months. And
  LuaJIT is in the same boat as JS in terms of fundamental language
  limitations but manages to do better than every JavaScript
  implementation anyway. People who don't understand what all the JS
  optimizations in V8 or such actually do like to claim the JS can do
  amazing things speed-wise, but the reality is that all those
  optimizations are basically just "try very very hard to analyze the
  code to figure out types for variables and then compile it like a
  slightly retarded statically-typed language's compiler would do it."
  Oh, and there's tracing, but then tracing also works on statically
  typed languages (and works better due to a lack of need for type
  guards in the generated machine code). Not a single one of those
  whizbang optimizations was invented by or for JS, in fact; most were
  taken from research JVMs (Java is evil!) or classical OOP languages
  (prototypes are awesome!).

i) No IntelliSense even possible. Want to see what methods exist on
  that variable you've got there on line 187 of foo.js in your text
  editor? Too bad. Go trace through the code until you figure out where
  it was initialized, then go trace through the code to find out what
  its prototype has on it. And then hope there's no code dynamically
  changing the prototype behind your back. In fact, just run it in a
  browser and set breakpoints, because finding out anything useful about
  the value any other way is basically impossible for any codebase
  larger than the toy_web_app.html sites that JavaScript apologists use
  to glorify the ease and simplicity of JavaScript. Some code editors
  try really hard to do better, and almost kinda sorta succeed for the
  really simple cases, sometimes, once.

j) No advantage. JavaScript isn't even special compared to other
  dynamically typed language. It is not capable of doing anything
  interesting at all all that can't also be done by Lua, Python, Ruby,
  etc. None of the JS implementations are any faster than LuaJIT or PyPy
  or various other advanced JIT-ing implementations of other dynamic
  languages. JS has no plus sides to it compared to other commonly
  available languages. Oh, except it runs natively in a Web browser
  without a plugin. Which is the only reason in the world why it's so
  popular. In fact, it's the only reason it event exists. If someone
  10 years ago had just thought, "heck, let's drop an existing
  well-designed and well-established language into our browser and get
  the other guys to do the same instead of making everyone use this
  goofy little hackjob that NetScape came up with," the Web would look a
  lot different (better) today. Just imagine the future if Chrome
  dropped Python into Chrome as a supported language. Or actually,
  imagine this: Google drops C/C++ into Chrome as a supported language
  (http://code.google.com/p/nativeclient/).


问:
Is it better to spend resources on a skilled team or good process practice?
Which one of these is of more importance? Skilled team or good process practice?

When I say skilled, I mean logical, creative members with good coding and testing skills.  Good process would be the development methodology, like agile, scrum, etc

答:
If your team isn't skilled (as in your definition), you will get nothing done at all. In this case the process doesn't matter.

Not skilled in the sense of not much experience would be another matter. If your people are talented, but have not much experience with projects, then a good process may help avoid problems. Testing and early response from customers as Agile provides would most likely avoid many problems in such a situation.


问:
What is the best approach for Single Sign On Application Development that is lightweight?
What is the best approach for Single Sign On Application Development that is lightweight?

By lightweight I mean not too much javascript. I know stackexchange does use single sign-on. Basically is the login credential stored as cookie? Or combination of IP-Address and other specific information about the logged in user?

答:
There is no need to use JavaScript in an SSO implementation. There are a number of existing Single Sign On solutions that do not utilize JavaScript. I suggest that you look at using one of these before you build SSO from scratch. I don't know if any of these qualify as "lightweight" in your book. Some will offer more features than others. Some are easier to set up than others. All should be fairly seamless to the end user.

If you do need to build SSO from scratch for whatever reason, you should look at the internals of an existing open source SSO solution like CAS to get an idea of how you can implement.


问:
How to detect if an app was already installed before
How do software applications keep track of whether the user already installed the application before in it's Windows system?

Say you install app X, trial version, remove it, then re install it, and when you run it again it detects you had already installed it before. If you uninstall and clean all registry information it shouldn't know you had already installed it before...

Disclaimer: I'm not trying to "hack" any application, just thinking about how this is implemented.

答:
There can be many ways to implement this. The general idea is that the first time the application is installed, it has to leave some indicator that it was there. This could be a registry key setting, a system configuration value, a hidden text file, some combinations of these, etc... When it is uninstalled, it must leave this artifact behind so that if the installer is run again, it will first look for that artifact(s) that proves the application was there already.

If you want to get very fancy, you have the installer send some sort of machine identifier (maybe CPU serial number + MAC address) to a central registration server. That way, even if all relevant settings are cleared locally, the registration server will still know that the other machine once had that application.


答:
A skilled team is most important.

A skill-less team with all of the right processes will fail.  If you don't believe me, bring your agile/scrum processes over to a different department (say, accounting) and see if they can make good software!

Title: Is it better to spend resources on a skilled team or good process practice?

Body:
Which one of these is of more importance? Skilled team or good process practice?

When I say skilled, I mean logical, creative members with good coding and testing skills.  Good process would be the development methodology, like agile, scrum, etc


问:
Why could citing bug IDs in patch notes be considered a bad practice?
Based on a comment and subsequent upvotes from Bug reopen vs. new:

Citing bug IDs in patch notes is just.. very unfriendly. – Krelp

It appears at least some people feel that referencing bug IDs in patch notes is not a good idea. I'm a fairly inexperienced developer, so I'm wondering why that's the case.

答:
There's nothing wrong with citing issue numbers in patch notes, provided users can read the issue which is being cited. If your bug database allows anyone to read, citing the bug number can be very useful indeed. (One better, if your patch notes are in a format that allows links, make those issue IDs be links to the issue in question.) This doesn't mean that you should expose all issues to the general public; it can still be useful to have ones that are shrouded (e.g., where they've got live passwords in!)

Citing an issue number where the person reading can't go and look up the details and history of the bug, that's quite unfriendly. Not that citing such issues without the issue ID is much friendlier.


答:
In my opinion, it's a good practice, assuming your users have read access to your bug database.  There are lots of times when people are waiting on a certain bug to be fixed in order to decide when to upgrade.

I think what's frowned upon is only citing the bug id and nothing else.  You should always also supply a description that is understandable without going to the bug tracker.  That also allows you to switch bug trackers in the future without entirely invalidating your previous release notes.

Title: Why could citing bug IDs in patch notes be considered a bad practice?

Body:
Based on a comment and subsequent upvotes from Bug reopen vs. new:

Citing bug IDs in patch notes is just.. very unfriendly. – Krelp

It appears at least some people feel that referencing bug IDs in patch notes is not a good idea. I'm a fairly inexperienced developer, so I'm wondering why that's the case.


答:
It is, as said in the quoted comment... unfriendly.

Unfriendly with yourself

Imagine the following scenario. You are viewing the logs in source control. You are wondering what a commit changed. Instead of explaining it in plain English, it tells you:

Solved #1307

You run the bug tracking system, hoping to have something helpful. Bug #1307 is reported as solved. In the description, you see:

Same bug as #1284

Thanks, its very helpful. You have now to navigate to bug report #1284 to read that it's a duplicate of bug #1113 which refers to bugs #1112, #1065 and #1067.

Five minutes later, you have no idea what are you searching for at the beginning.

A much more helpful version control log message would be:

Solved an issue with the users being unable to log on with a password longer than 25 characters (see #1307), by removing applying the same password length policy to the data access layer as the one used in the website itself.

In the same way, in the bug tracking system, the report #1307 could be more self-explanatory, recalling what was the bug report #1284 about, and how the new one is different from the old one.

Unfriendly with customers

This is not the only friendliness issue.

A second one is that by referencing too much with no additional info, you are making the patch notes/version control logs/bug tracking system reports unusable to someone not very familiar with those systems. When you deal with a bug tracking system daily, you know how to quickly navigate through the reports, view multiple reports side by side, etc. When you're a customer with no technical background, you can easily be lost.

Here again, more detailed messages are very helpful than just a reference. Note that you still want to keep references: nothing is more wrong than a bug which is the same as a bug you encountered two weeks ago, but don't recall its ID.

As a note, the same issue exists in many jurisdictions. In France for example, it is not unusual for a legislation to refer to multiple sources, which may change meanwhile. This means that in order to completely understand it, you have to spend sometimes hours in a library, searching for dozens of referred texts, each text having its own references to others.


答: Only having good practices, without skilled workers, is similar to the 1 million monkeys at 1 million typewriters writing all the great works...  I've seen too many out-source companies who play up their [CMM / ITIL / Agile / whatever] practices with developers who couldn't code themselves out of a figurative paper bag. </p>


答:
As others have pointed out, no amount of process is going to completely compensate for a team that lacks skills. However, it will go some way to ameliorate things. For example, but having a process in place that requires tests to be written and the tests to pass you will ensure that the code you produce works (to a certain degree).

However, a bad process can ruin the efforts of the most highly skilled developers if you allow shortcuts to be taken and untested code to be released (for example). By this I mean that if pressures from management/sales etc. force developers to circumvent otherwise good practice then the process is broken. A good process has to be one that management buys into and acknowledges and honours.

Skills and process are complementary. Without either you can't produce quality code.


答:
As technical people, we have a tendency to judge things based on their technical merit.  Our definition of "important" is that the software is creative, elegant, and interesting.  A company's definition of "important" is that the software has a positive effect on the company's revenue.  Having skilled team members is more important by the first definition.  Having a good process is more important by the second definition.  However, one being more important doesn't imply that the other is wholly unimportant.

Agile's whole point is that the process should adjust quickly to fit the needs of the business and the developers.  If you're doing it right, it's generally beneficial to both, but it takes a little time to settle in.  If you're trying to enforce some ideologically "pure" version of agile, you're going to have issues.


答:
I think people are missing a point here.

There is a core level of competence that is essential in members of the team - if you don't have that level then yes there is a problem - however the question then becomes what one means by "skilled", would one regard these adequately competent people as skilled?

If the environment and the processes are good then these competent developers will deliver where a team of more skilled individuals without good processes might not because they will not be working together.

Everyone goes looking for "rockstars" and "ninjas" yet that's not what most of us are - good processes are about getting the rest of us to work to the best of our abilities


答: Trying to implement a process perfectly is definitely the wrong thing to aim for. The goal should be to create useful software, the process is merely something that helps you reach that goal. If you ever feel that it's actually hindering you, you need to change that (and every good process description stresses this point).</p>


答:
It obviously depends who the people that will read the patch notes are, and the target users of the software.

But in most of cases, the vast majority of your users simply don't care about what the bug ID is. They don't care why it was broken, what the fix is, or anything else -- they only want to know what changed with a very succinct textual description without having to go to another page for each change.

Citing the bug IDs makes me stop and think, and I - as a user - don't want to think. It's sort of a usability issue.

Take a look for example at the change log of Visual Assist X. All those linked bug IDs are just noise that distract me from understanding what changed. And this is an add-on for a Visual Studio, targeting programmers. And I'm a programmer. If this bothers me, imagine the average user who doesn't even know what a bug tracker is..

PS: I was the author of the comment that sparked the question


答:
I would say it depends on your system: I'm lucky that the one I use automatically detects such references in commit messages and adds a link to the ticket stored in the bug tracker, so it's not an issue.

But if I were on a system where it's not available, I'd still mention the ticket ID (that way you can quickly search in logs by ticket ID) along with a short description of what the bug is.


问:
What's your favourite quote about programming?
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!

答:
There, it should work now.

— All programmers

LastEditorDisplayName: Roger Pate


答:
I think to be successful at software development you need to have a competent team and a good process. But a competent team with a good process will beat a team of experts with no process (of course real experts wouldn't work that way and almost no companies have a whole team of real experts). Incompetent developers with no process is the worst of all possible worlds. So really what you need to compare is a good process and competent developers and a poor process and competent developers and in this case the good process will win.

I would rank them this way

Expert developerts Good process

Competent developers Good process

Expert developers Poor process (bad process will drag you down and
cause delays and bad choices etc)

Competent developers Poor process

Incompetent developers Good process (but more likely to turn into
good developers with time)

Incompetent developers Poor process

Now the real problem is in defining competent developers and good process. A formal process is not necessarily a good one (see waterfall) and a developer with ten years of experience is not necessarily good either.

Scrum can be a good process in a legacy app, it can also be a bad process, the devil is in the details.


答:
Your development process is only as good as the weakest link, so both are important.

An otherwise good team who have a disastrous process inflicted upon them, one which stifles development rather than facilitating it, could actually end up less productive than a team of poor developers helped along by a good process (I've seen this happen).

In my experience however, good developers tend to gravitate towards a work flow which is more efficient, if they have the autonomy to do so. Inefficiencies or pointless bureaucracy tend to be imposed from above, so a good manager/team leader can be critical in preventing teams being stifled by process.

Another point is that changing a team is something that takes time, whereas changing a process is often something you can do at any time.

In peopleware, Tom DeMarco and Timothy Lister talk a lot about how to get teams to gel, talking about growing teams rather than building them. Different processes can put up barriers to teams gelling or they can encourage the team to grow, so that is a consideration when developing a process.

Optimising a workflow can be a continuous process however - problems or inefficiencies in the process can be discussed and resolved as you go along. If they work you can look at other ways to improve your process, if not you can go back to the old way. You just have to keep in mind that the process is a means to an end, not an end in itself.

On your final point, only you and your team can determine if Scrum, or any other methodology will fit your requirements. If you are working in an otherwise strongly waterfall environment, introducing agile techniques may just cause friction with other teams you need to interact with. Similarly if other teams are using Scrum, you may find that adopting it yourselves can help interaction with those teams.


答:
My answer is based on a couple of assumptions

The point is, which one will create better software?

Will one choice negate the other?

By skilled we're assuming at least a base level of competency

Is the fear that a process that is too rigid will prevent the team from hiring or keeping highly skilled developers? Does having a process hinder creativity, flexibility and delivering on time? And if that's the case, is it a poor process or one that needs some adjustment?

A structured process may make it easier to keep lesser developers or those with a tendency to be careless in line. Good processes by definition are the ones that return the best results.

A "highly" skilled developer that can't work within your team or your process for all practical purposes is not skilled. Skilled people deliver results in the context of the requirements. I'm not sure how far I would be willing to drop standards to appease some self-proclaimed, guru, prima donna, rock star, ninja, all star. Rowing faster than everyone else in the same boat can be counter-productive.


问:
while(true) and loop-breaking - anti-pattern?
Consider the following code:

public void doSomething(int input)
{
   while(true)
   {
      TransformInSomeWay(input);

      if(ProcessingComplete(input))
         break;

      DoSomethingElseTo(input);
   }
}
```

<p>Assume that this process involves a finite but input-dependent number of steps; the loop is designed to terminate on its own as a result of the algorithm, and is not designed to run indefinitely (until cancelled by an outside event). Because the test to see if the loop should end is in the middle of a logical set of steps, the while loop itself currently doesn't check anything meaningful; the check is instead performed at the "proper" place within the conceptual algorithm.</p>

<p>I was told that this is bad code, because it is more bug-prone due to the ending condition not being checked by the loop structure. It's more difficult to figure out how you'd exit the loop, and could invite bugs as the breaking condition might be bypassed or omitted accidentally given future changes.</p>

<p>Now, the code could be structured as follows:</p>

<pre class="lang-java prettyprint-override"><code>public void doSomething(int input)
{
   TransformInSomeWay(input);

   while(!ProcessingComplete(input))
   {
      DoSomethingElseTo(input);
      TransformInSomeWay(input);
   }
}
</code>```

However, this duplicates a call to a method in code, violating DRY; if TransformInSomeWay were later replaced with some other method, both calls would have to be found and changed (and the fact that there are two may be less obvious in a more complex piece of code).

You could also write it like:

public void doSomething(int input)
{
   var complete = false;
   while(!complete)
   {
      TransformInSomeWay(input);

      complete = ProcessingComplete(input);

      if(!complete)
      {
         DoSomethingElseTo(input);
      }
   }
}
```

... but you now have a variable whose only purpose is to shift the condition-checking to the loop structure, and also has to be checked multiple times to provide the same behavior as the original logic.

For my part, I say that given the algorithm this code implements in the real world, the original code is the most readable. If you were going through it yourself, this is the way you'd think about it, and so it would be intuitive to people familiar with the algorithm.

So, which is "better"? is it better to give the responsibility of condition checking to the while loop by structuring the logic around the loop? Or is it better to structure the logic in a "natural" way as indicated by requirements or a conceptual description of the algorithm, even though that may mean bypassing the loop's built-in capabilities?

答: Stick with your first solution.  Loops can become very involved and one or more clean breaks can be a lot easier on you, anyone else looking at your code, the optimizer, and the program's performance than elaborate if-statements and added variables.  My usual approach is to set up a loop with something like the "while (true)" and get the best coding I can.  Often I can and do  then replace the break(s) with a standard loop control; most loops are pretty simple, after all.  The ending condition should be checked by the loop structure for the reasons you mention, but not at the cost of adding whole new variables, adding if-statements, and repeating code, all of which are even more bug prone.


问:
choosing Database and Its Design for Rails
I am having a difficulty in deciding the database & its structure.

Let us say the problem is like this.
For my product I have various customers( each is an educational institute)
Each customer have their own sub-clients ( Institution have students)

Each student record will have some basic information like "name" & "Number" .
There are also additional information that a customer(institution) might want to ask sub-client(student) like "email" or "semester"

I have come up with two solutions :
1. Mysql

_insititution__

id-|- Description|

__Student__

id-|-instituition_id-|-Name-|-Number|

__student_additional_details__

student_id -|- field_name -|- Value

Student_additional_details will have multiple records for each student depending upon number of questions asked from institution.

2.MongoDb

_insititution___

id-|- Description|

_Student__

id-|-instituition_id-|-Name-|-Number|-otherfield1 -|- otherfield2

with mongo the structure itself can be dynamic so student table seems really good in mongo
. But the problem comes when I have to relate student with institution .

So which one is a better design ? Or some other idea ?

答:
There is nothing wrong with either approach from what I can tell, it is more a requirements/learning question. If you want to learn MongoDB then you can make it work. If you need it to work and there are no other advantages then your MySQL schema will work fine.

If you are interested in doing your work in MongoDB then I would suggest looking at http://www.mongodb.org/display/DOCS/Schema+Design for idea's about how to handle relationships inside of MongoDB


答:
Technically, I would suggest it is a key, value pair.  "Key" is the common term when describing the unique identifiers in associative arrays such as in Java's Map class, and is also what can uniquely identify a row in a database relation.

"Key" is also the familiar term when discussing decoding thins--when you see this, it means that...

The problem you can run into with "name" is that it implies something meaningful--especially when you are describing people or other things that explicitly have "names" (but which aren't necessarily useful as unique identifiers or keys).


问:
Are nullable types preferable to magic numbers?
I have been having a little bit of a debate with a coworker lately.  We are specifically using C#, but this could apply to any language with nullable types.  Say for example you have a value that represents a maximum.  However, this maximum value is optional.  I argue that a nullable number would be preferable.  My coworker favors the use of zero, citing precedent.  Granted, things like network sockets have often used zero to represent an unlimited timeout.  If I were to write code dealing with sockets today, I would personally use a nullable value, since I feel it would better represent the fact that there is NO timeout.

Which representation is better?  Both require a condition checking for the value meaning "none", but I believe that a nullable type conveys the intent a little bit better.

答: MAGIC_NUMBER code should absolutely always be avoided wherever possible. null is a much clearer expression of intent.


答:
Null isn't the only alternative to a magic number.

```<code>public static int NO_TIMEOUT = 0;  // javaish
</code>```

Null is evil.  In the example above you might be able to get away with it since the code would obviously be able to handle a null.  But in general what happens when you start passing nulls around is that sooner or later you get a null pointer exception.  It may not happen when you first write the code, but code is maintained for far longer than just the first release.  It's often maintained by people who don't know as much about the system as the original developers.

Scala (for example) has a nice alternative in the Option class.  The Option class has one of two values, Some - which wraps the value you really want and None - which has no value.

That makes it obvious to any developer that there may not be a value and you had better code for that.  Well, it should make it obvious anyway.

And not all magic numbers are a problem.  Depending on context 0, 1, 1024 etc. can all be obvious.  347?  Yeah, that one you should avoid.  :-)

Title: Are nullable types preferable to magic numbers?

Body:
I have been having a little bit of a debate with a coworker lately.  We are specifically using C#, but this could apply to any language with nullable types.  Say for example you have a value that represents a maximum.  However, this maximum value is optional.  I argue that a nullable number would be preferable.  My coworker favors the use of zero, citing precedent.  Granted, things like network sockets have often used zero to represent an unlimited timeout.  If I were to write code dealing with sockets today, I would personally use a nullable value, since I feel it would better represent the fact that there is NO timeout.

Which representation is better?  Both require a condition checking for the value meaning "none", but I believe that a nullable type conveys the intent a little bit better.

Body:
Null isn't the only alternative to a magic number.

public static int NO_TIMEOUT = 0;  // javaish

Null is evil.  In the example above you might be able to get away with it since the code would obviously be able to handle a null.  But in general what happens when you start passing nulls around is that sooner or later you get a null pointer exception.  It may not happen when you first write the code, but code is maintained for far longer than just the first release.  It's often maintained by people who don't know as much about the system as the original developers.

Scala (for example) has a nice alternative in the Option class.  The Option class has one of two values, Some - which wraps the value you really want and None - which has no value.

That makes it obvious to any developer that there may not be a value and you had better code for that.  Well, it should make it obvious anyway.

And not all magic numbers are a problem.  Depending on context 0, 1, 1024 etc. can all be obvious.  347?  Yeah, that one you should avoid.  :-)


答:
while(true) and break is a common idiom. It's the canonical way to implement mid-exit loops in C-like languages. Adding a variable to store the exit condition and an if() around the second half of the loop is a reasonable alternative. Some shops may Officially Standardize on one or the other, but neither one is superior; they are equivalent.

A good programmer working in these languages should be able to know what's going on at a glance if he or she sees either one. It might make a good little interview question; hand somebody two loops, one using each idiom, and ask 'em what the difference is (proper answer: "nothing", with maybe an addition of "but I habitually use THAT one.")

Title: while(true) and loop-breaking - anti-pattern?

Body:
Consider the following code:

public void doSomething(int input)
{
   while(true)
   {
      TransformInSomeWay(input);

      if(ProcessingComplete(input))
         break;

      DoSomethingElseTo(input);
   }
}
```

<p>Assume that this process involves a finite but input-dependent number of steps; the loop is designed to terminate on its own as a result of the algorithm, and is not designed to run indefinitely (until cancelled by an outside event). Because the test to see if the loop should end is in the middle of a logical set of steps, the while loop itself currently doesn't check anything meaningful; the check is instead performed at the "proper" place within the conceptual algorithm.</p>

<p>I was told that this is bad code, because it is more bug-prone due to the ending condition not being checked by the loop structure. It's more difficult to figure out how you'd exit the loop, and could invite bugs as the breaking condition might be bypassed or omitted accidentally given future changes.</p>

<p>Now, the code could be structured as follows:</p>

<pre class="lang-java prettyprint-override"><code>public void doSomething(int input)
{
   TransformInSomeWay(input);

   while(!ProcessingComplete(input))
   {
      DoSomethingElseTo(input);
      TransformInSomeWay(input);
   }
}
</code>```

However, this duplicates a call to a method in code, violating DRY; if TransformInSomeWay were later replaced with some other method, both calls would have to be found and changed (and the fact that there are two may be less obvious in a more complex piece of code).

You could also write it like:

public void doSomething(int input)
{
   var complete = false;
   while(!complete)
   {
      TransformInSomeWay(input);

      complete = ProcessingComplete(input);

      if(!complete)
      {
         DoSomethingElseTo(input);
      }
   }
}
```

... but you now have a variable whose only purpose is to shift the condition-checking to the loop structure, and also has to be checked multiple times to provide the same behavior as the original logic.

For my part, I say that given the algorithm this code implements in the real world, the original code is the most readable. If you were going through it yourself, this is the way you'd think about it, and so it would be intuitive to people familiar with the algorithm.

So, which is "better"? is it better to give the responsibility of condition checking to the while loop by structuring the logic around the loop? Or is it better to structure the logic in a "natural" way as indicated by requirements or a conceptual description of the algorithm, even though that may mean bypassing the loop's built-in capabilities?


答:
Consider:

Language,

Framework,

Context.

1. Language

Using ∞ can be a solution for a maximum.

JavaScript, for example, has an infinity. C# doesn't¹.

Ada, for example, has ranges. C# doesn't.

In C#, there is int.MaxValue, but you cannot use it in your case. int.MaxValue is the maximum integer, 2,147,483,647. If in your code, you have a maximum value of something, like a maximum accepted pressure before something explodes, using 2,147,483,647 has no sense.

2. Framework

.NET Framework is rather inconsistent on this point, and its usage of magic values can be criticized.

For example, "Hello".IndexOf("Z") returns a magic value -1. It maybe makes it easier (does it?) to manipulate the result:

```<code>int position = "Hello".IndexOf("Z");
if (position > 0)
{
    DoSomething(position);
}
</code>```

rather than using a custom structure:

```<code>SearchOccurrence occurrence = "Hello".IndexOf("Z");
if (occurrence.IsFound)
{
    DoSomething(occurrence.StartOffset);
}
</code>```

but is not intuitive at all. Why -1 and not -123? A beginner may also mistakenly think that 0 means "Not found" too or just mistype (position >= 0).

3. Context

If your code is related to timeouts in network sockets, using something which was used by everyone for decades for the sake of being consistent is not a bad idea. Especially, 0 for a timeout is very clear: it's a value which cannot be zero. Using a custom class in this case may make things more difficult to understand:

```<code>class Timeout
{
    // A value indicating whether there is a timeout.
    public bool IsTimeoutEnabled { get; set; }

    // The duration of the timeout, in milliseconds.
    public int Duration { get; set; }
}
</code>```

Can I set Duration to 0 if IsTimeoutEnabled is true?

If IsTimeoutEnabled is false, what happens if I set Duration to 100?

This can lead to multiple mistakes. Imagine the following piece of code:

```<code>this.currentOperation.Timeout = new Timeout
{
    // Set the timeout to 200 ms.; we don't want this operation to be longer than that.
    Duration = 200,
};

this.currentOperation.Run();
</code>```

The operation runs for ten seconds. Can you see what's wrong with this code, without reading the documentation of Timeout class?

Conclusion

null expresses well the idea that the value is not here. It's not provided. Not available. It's neither a number, nor a zero/empty string or whatsoever. Don't use it for maximum or minimum values.

int.MaxValue is strongly related to the language itself. Don't use int.MaxValue for a maximum speed limit of Vehicle class or a maximum acceptable speed for an aircraft, etc.

Avoid magic values like -1 in your code. They are misleading and lead to mistakes in code.

Create your own class which would be more straightforward, with the minimum/maximum values specified. For example VehicleSpeed can have VehicleSpeed.MaxValue.

Don't follow any previous guideline and use magic values if it's a general convention for decades in a very specific field, used by most people writing code in this field.

Don't forget to mix approaches. For example:

```<code>class DnsQuery
{
    public const int NoTimeout = 0;

    public int Timeout { get; set; }
}

this.query.Timeout = 0; // For people who are familiar with timeouts set to zero.
// or
this.query.Timeout = DnsQuery.NoTimeout; // For other people.
</code>```

¹ You can create your own type which includes infinity. Here, I'm talking about native int type only.

Body:
Consider:

Language,

Framework,

Context.

1. Language

Using ∞ can be a solution for a maximum.

JavaScript, for example, has an infinity. C# doesn't¹.

Ada, for example, has ranges. C# doesn't.

In C#, there is int.MaxValue, but you cannot use it in your case. int.MaxValue is the maximum integer, 2,147,483,647. If in your code, you have a maximum value of something, like a maximum accepted pressure before something explodes, using 2,147,483,647 has no sense.

2. Framework

.NET Framework is rather inconsistent on this point, and its usage of magic values can be criticized.

For example, "Hello".IndexOf("Z") returns a magic value -1. It maybe makes it easier (does it?) to manipulate the result:

int position = "Hello".IndexOf("Z");
if (position > 0)
{
    DoSomething(position);
}

rather than using a custom structure:

SearchOccurrence occurrence = "Hello".IndexOf("Z");
if (occurrence.IsFound)
{
    DoSomething(occurrence.StartOffset);
}

but is not intuitive at all. Why -1 and not -123? A beginner may also mistakenly think that 0 means "Not found" too or just mistype (position >= 0).

3. Context

If your code is related to timeouts in network sockets, using something which was used by everyone for decades for the sake of being consistent is not a bad idea. Especially, 0 for a timeout is very clear: it's a value which cannot be zero. Using a custom class in this case may make things more difficult to understand:

class Timeout
{
    // A value indicating whether there is a timeout.
    public bool IsTimeoutEnabled { get; set; }

    // The duration of the timeout, in milliseconds.
    public int Duration { get; set; }
}

Can I set Duration to 0 if IsTimeoutEnabled is true?

If IsTimeoutEnabled is false, what happens if I set Duration to 100?

This can lead to multiple mistakes. Imagine the following piece of code:

this.currentOperation.Timeout = new Timeout
{
    // Set the timeout to 200 ms.; we don't want this operation to be longer than that.
    Duration = 200,
};

this.currentOperation.Run();

The operation runs for ten seconds. Can you see what's wrong with this code, without reading the documentation of Timeout class?

Conclusion

null expresses well the idea that the value is not here. It's not provided. Not available. It's neither a number, nor a zero/empty string or whatsoever. Don't use it for maximum or minimum values.

int.MaxValue is strongly related to the language itself. Don't use int.MaxValue for a maximum speed limit of Vehicle class or a maximum acceptable speed for an aircraft, etc.

Avoid magic values like -1 in your code. They are misleading and lead to mistakes in code.

Create your own class which would be more straightforward, with the minimum/maximum values specified. For example VehicleSpeed can have VehicleSpeed.MaxValue.

Don't follow any previous guideline and use magic values if it's a general convention for decades in a very specific field, used by most people writing code in this field.

Don't forget to mix approaches. For example:

class DnsQuery
{
    public const int NoTimeout = 0;

    public int Timeout { get; set; }
}

this.query.Timeout = 0; // For people who are familiar with timeouts set to zero.
// or
this.query.Timeout = DnsQuery.NoTimeout; // For other people.

¹ You can create your own type which includes infinity. Here, I'm talking about native int type only.


答:
Null isn't any better than a magic number.

The important thing is to NAME the values that have magic effects, if you have to have such values, and to make sure that the definitions of those names are someplace that will be seen by anybody who bumps into the magic value and wtf's.

```<code>if (timeout == 4298435) ... // bad.
if (timeout == null) ... // bad.
if (timeout == NEVER_TIME_OUT) ... // yay! puppies and unicorns!
</code>```

Body:
Null isn't any better than a magic number.

The important thing is to NAME the values that have magic effects, if you have to have such values, and to make sure that the definitions of those names are someplace that will be seen by anybody who bumps into the magic value and wtf's.

if (timeout == 4298435) ... // bad.
if (timeout == null) ... // bad.
if (timeout == NEVER_TIME_OUT) ... // yay! puppies and unicorns!


答:
You could also go with this:

public void doSomething(int input)
{
   while(TransformInSomeWay(input), !ProcessingComplete(input))
   {
      DoSomethingElseTo(input);
   }
}
```

<p>Or less confusingly:</p>

<pre class="lang-java prettyprint-override"><code>bool TransformAndCheckCompletion(int &input)
{
   TransformInSomeWay(input);
   return ProcessingComplete(input))
}

public void doSomething(int input)
{
   while(TransformAndCheckCompletion(input))
   {
      DoSomethingElseTo(input);
   }
}
</code>```

Body:
You could also go with this:

public void doSomething(int input)
{
   while(TransformInSomeWay(input), !ProcessingComplete(input))
   {
      DoSomethingElseTo(input);
   }
}

Or less confusingly:

bool TransformAndCheckCompletion(int &input)
{
   TransformInSomeWay(input);
   return ProcessingComplete(input))
}

public void doSomething(int input)
{
   while(TransformAndCheckCompletion(input))
   {
      DoSomethingElseTo(input);
   }
}


问:
How to deal with tautology in comments?
Sometimes I find myself in situations when the part of code that I am writing is (or seems to be) so self-evident that its name would be basically repeated as a comment:

```<code>class Example
{
    /// <summary>
    /// The location of the update.
    /// </summary>
    public Uri UpdateLocation { get; set; };
}
</code>```

(C# example, but please refer to the question as language-agnostic).

A comment like that is useless; what am I doing wrong? Is it the choice of the name that is wrong? How could I comment parts like this better? Should I just skip the comment for things like this?

答:
I would remove the tautology but keep the comment, I would comment properties and variable names by giving a sample value, so that the usage is clearly understood:

```<code>property UpdateLocation:TUpdateLocation;  // url="http://x/y/3.2/upd.aspx",proto=http
</code>```

Now I know exactly what goes in there, and from the comment, I have a clear idea how to use it.

Title: How to deal with tautology in comments?

Body:
I would remove the tautology but keep the comment, I would comment properties and variable names by giving a sample value, so that the usage is clearly understood:

property UpdateLocation:TUpdateLocation;  // url="http://x/y/3.2/upd.aspx",proto=http

Now I know exactly what goes in there, and from the comment, I have a clear idea how to use it.


问:
How does one become a big contributor to an opensource project?
I know that the default advice for open source projects, and getting started, is to start fixing bugs. But I have a feeling that its the path that one would want to take if they wanted to be a tester/fixer of bugs in the project. How does one become an active contributor of an opensource project? [I.e. on the level of architecture]</p>

答:
This is probably going to sound like a bit of a tautology, but if you want to become a major contributor of new features, use the product for a while, find a new feature that would improve it, write up the code to implement the feature, and contribute it.

The reason people are advised to start out with bugfixes is that that gets them to dig around in the codebase and familiarize themselves with the way things work.  That'll also get you to participate in the project's discussion community, whatever that may be, (usually a mailing list or forum,) so you'll get a feel for the direction of the project. You'd feel a bit foolish if you get 80% of the way done with your new feature only to find that someone else has been working on it all along and they just finished it!


答: You can do this by getting to know those already in that position and demonstrating an interest to join them, which is best accomplished by fixing bugs, finding bugs, and participating in development.</p>

Title: How does one become a big contributor to an opensource project?

Body: I know that the default advice for open source projects, and getting started, is to start fixing bugs. But I have a feeling that its the path that one would want to take if they wanted to be a tester/fixer of bugs in the project. How does one become an active contributor of an opensource project? [I.e. on the level of architecture]</p>


答:
In this case, the null value is a great way to indicate there is no maximum. Generally when the special case means that the value in question does not apply, that you just don't want the feature it configures, null is a good indication of this.

A problem with using null to represent special cases is that there is only one null value, and there may be multiple special cases. In this case, I would pass an enumeration as an additional parameter, which can indicate a special case, or to use the int value normally. (This is essentially what the Nullable<> does for you, though it uses a boolean instead of an enum and combines the parameters into a single structure.)


问:
Are there code reviews in opensource projects? If so, what tools are used to do this?
I know there is a big push for code reviews in commercial development. However, are code reviews used in open source software or is based on trust? If so, then how are they performed? [Is it a delayed commit, "a pre commit environment", is there a tool that allows for the patch to be sent to another dev]?

Are there any projects that use code reviews?

From my understanding the Linux kernel is mostly based around trust of the committer. MySQL was based on the main author's approval and the performance impact.

答:
Larger OSS projects will have a number of core committers. So I guess they are the de-facto "code reviewers".

Also, since OSS code is by it's nature open to everyone there is likely to be much more discussion around the code you are writing. Whilst this may not be in the form of formal code reviews, you will certainly find out if your code is not considered up to scratch for a specific OSS project.


答:
In this case, I think a nullable type makes perfect sense.

Null means absence of value.  This is a distinctly different concept than a number having a value of 0.

If you want to say "If I don't give you a value, use the maximum" then passing in null is the exact correct way to express that.


问:
How does one write a book on a new framework?
How are authors able to write a book on a framework that is just released? A framework like spring is updated, and a book is released in the next day. Is this typically by people who are direct contributors? Are they basing it off of beta/alpha versions?

I find this rather difficult to understand as that documentation is rarely up to snuff by the time the framework is updated.

答: Those who write books about frameworks are generally involved in the framework they are writing about, they have access to documentation and pre-release versions of the framework. They aren't random people that know about programming, they likely contacted the development team about writing a book and got the information or were asked by the development team to write a book. Also good frameworks keep their documentation up to date, its part of being a good framework, though the general public may not have access to the most up to date documentation.</p>


答:
In C#, many CLR classes have a static Empty member:

System.String.Empty

System.EventArgs.Empty

System.Guid.Empty

System.Drawing.Rectangle.Empty

System.Windows.Size.Empty

This keeps you from having to remember whether to use a magic value or use null in order to construct an empty object.

But what if you're dealing with a simple value type like an int?  In that case, consider whether you're falling victim to Primitive Obsession.  It's quite possible that your apparently simple numeric property would benefit from its own class or struct, which would allow you to specify the Empty member and also add other behavior specific to that kind of value.


答:
Null is worse to use than MagicNumber. Null represents the idea expressed better, but it isn't consistent across platforms in how it behaves, using MagicNumber always works the same which is beneficial.

depending on the environment/language used null could

simply be 0

may not be a legal value

may produce unexpected results due to three way logic

MagicNumber always behaves the same.


问:
Why would a programmer want to separate implementation from interface?
The bridge design pattern separates implementation from the interface of a program.

Why is this advantageous?

答:
You really have two very different questions here, though they are related.

The more general question is the one in the title, why would you separate interface from implementation in general.  The second question is why the bridge pattern is useful.  They are related because the bridge pattern is a specific way of separating interface from implementation, that has some specific other consequences as well.

The general question is something vital for every programmer to understand.  It is what prevents changes in a program from propagating everywhere.  I can't imagine humans being able to program without using this.

When you write a simple addition statement in a programming language, that is already an abstraction, (even if it isn't using operator overloading to add matrices or something like that) that goes through quite a lot of other code before it finally gets executed on a circuit in your computer.  If there was no separation of the interface (say, "3+5"), from the implementation (a bunch of machine code), then you would have to change your code every time the implementation changed (like you wanted to run on a new processor).

Even within a simple CRUD application, every method signature is, in a broad sense, the interface to it's implementation.

All these kinds of abstraction have the same basic goal - have the calling code express it's intent in the most abstract possibly way that gives the implementer as much information as needed.  That provides the minimal possible coupling between them, and limits the ripple effect when code needs to be changed as much as possible.

It sounds straightforward, but in practice it gets complicated.

The bridge pattern is a specific way of separating certain bits of implementation into interfaces.  The class diagram of the pattern is more informative than the description.  It's more like a way to have pluggable modules than a bridge, but they named it bridge because it's often used where the modules have been created prior to the interface.  So creating a common interface for similar existing implementations sort of "bridges" the difference and allows you code to work with any of the implementations.

So, say you wanted to write an add-on to a word processor, but you want it to work on multiple word processors.  You might create an interface that abstracts out the word processor based functionality you need (and which must be implementable by each word processor since you can't change those), and one implementer of that interface for each word processor you want to support.  Then your application can call that interface and not worry about the details of each word processor.

It's actually slightly more detailed than that, because each class might really be a class hierarchy (so, there  might not just be an abstract word processor, but an abstract Document, abstract TextSelection, etc., with concrete implementations for each), but it's the same idea.

It's a bit like a facade, except in this case the abstraction layer is focused on providing the same interface to multiple underlying systems.

It's related to Inversion Of Control, since the concrete implementer will be passed to methods or constructors and will determine the actual implementation called.