答:
The thing to remember is that the product originally requested is very rarely the product the customer actually wants. 80% of it will never be used and the other 20% of it will be used differently.

Changing requirements as the project goes on almost always allows the customer to end up with the product they needed, rather than the product they wanted. This is good. For you and for them.

But they do need to understand that each new requirement will cost them an old requirement (or delay the project) and they should always go through a Product Owner, who is managing both the long-term plan and the current sprint (which should not be changing unless it really has to).

Get a backlog of high-level stories and point-score them -- break these down only as they come close to the top of the pile. Also, start a burn-down chart. Put all this stuff in a place visible to the customer; if that means an electronic copy, fair enough, but if they regularly visit your office then cover the walls with whiteboards and put the info there, where everyone can see it and be driven by it.

This will serve to teach them about cause and effect. When they can see work is being checked off but the burn-down chart is not moving in the right direction, it is very easy to explain to them why. And if it isn't then it is your team who needs to question their estimates.

More often than not, such projects are driven by deadlines rather than features, so the customer can look at the features they've asked for and start thinking "hold on, this feature isn't that important, we should lose it to make sure we hit the deadline."

Finally, teach them that the sprint should be sacrosanct. Once they've requested something be delivered in this sprint, the cost of changing their mind should be greater than changing their minds about the future plan. Add a 3-point job to the current sprint and you should remove a 5-point job from it.

Title: Managing software projects - advice needed

Body:
I work for a large government department as part of an IT team that manages and develops websites as well as stand alone web applications.

We’re running in to problems somewhere in the SDLC that don’t rear their ugly head until time and budget are starting to run out.

We try to be “Agile” (software specifications are not as thorough as possible, clients have direct access to the developers any time they want) and we are also in a reasonably peculiar position in that we are not allowed to make profit from the services we provide. We only service the divisions within our government department, and can only charge for the time and effort we actually put in to a project. So if we deliver a project that we have over-quoted on, we will only invoice for the actual time spent.

Our software specifications are not as thorough as they could be, but they always include at a minimum:

Wireframe mockups for every form view

A data dictionary of all field inputs

Descriptions of any business rules that affect the system

Descriptions of the outputs

I’m new to software management, but I’ve overseen enough software projects now to know that as soon as users start observing demos of the system, they start making a huge amount of requests like “Can we add a few more fields to this report.. can we redesign the look of this interface.. can we send an email at this part of the workflow.. can we take this button off this view.. can we make this function redirect to a different screen.. can we change some text on this screen… can we create a special account where someone can log in and get access to X… this report takes too long to run can it be optimised.. can we remove this step in the workflow… there’s got to be a better image we can put here…” etc etc etc.

Some changes are tiny and can be implemented reasonably quickly.. but there could be up to 50-100 or so of such requests during the course of the SDLC. Other change requests are what clients claim they “just assumed would be part of the system” even if not explicitly spelled out in the spec.

We are having a lot of difficulty managing this process. With no experienced software project managers in our team, we need to come up with a better way to both internally identify whether work being requested is “out of spec”,  and be able to communicate this to a client in such a manner that they can understand why what they are asking for is “extra” work.

We need a way to track this work and be transparent with it.

In the spirit of Agile development where we are not spec'ing software systems in to the ground and back again before development begins, and bearing in mind that clients have access to any developer any time they want it, I am looking for some tips and pointers from experienced software project managers on how to handle this sort of "scope creep" problem, in tracking it, being transparent with it, and communicating it to clients such that they understand it.

Happy to clarify anything as needed.

I really appreciate anyone who takes the time to offer some advice.

Thanks.


问:
How to handle fired listeners exceptions
This is more of a design question and i was hoping to get pros and opinions on what makes sense.

BACKGROUND

Imagine something that holds one or more event listeners. Every now and then the thing fires events to its listeners.

PROBLEM

The problem is of course that listeners that follow after a listener that throws never get to know about the event. THis means that the order of listeners thus is an issue.

SOLUTION #1

Execute all listeners catching any thrown exceptions. This means all listeners are fired but in itself introduce other problems.

What should be done with caught exceptions ?

One option is to catch them all and after firing all events throw another exception which holds all the problems. ++

The other option is to log ~~

The last is to simply ignore these exceptions. --

Listeners are executed in isolation which is good. ++

SOLUTION #2

This option is the simplist and simply lets any thrown exception from a listener escape, resulting in remaining listeners never getting fired. Problems with this approach mean that

the order of listeners is significant(-)

simple to implement(+).

before listeners can affect the caller

Q

Which approach makes sense and causes the least number of problems. Does it really make sense to isolate listeners so they get events but cannot cause a running operation to abort if they throw ?

答:
Usually the event source (observable) is decoupled from observers.
So the design is something as below :

```<code>Observable -> (fires)-> Observer1,Observer2,Observer3...ObserverN
</code>```

However if you need to add extra logic add one more indirection using an ObserserProcessor class.

```<code>Observable -> (fires)
           |->ObserverProcessor1-->(log each)--> Observer1 ... Observer9
           |->ObserverProcessor2-->(whatever)-->Observer10 ... Observer20
</code>```

This way your logic of observers are still decoupled from observable class but grouped nicely so that you can still add extra processing logic in the middle.

I hope this helps.

ContentLicense: CC BY-SA 3.0

Body:
Usually the event source (observable) is decoupled from observers.
So the design is something as below :

Observable -> (fires)-> Observer1,Observer2,Observer3...ObserverN

However if you need to add extra logic add one more indirection using an ObserserProcessor class.

Observable -> (fires)
           |->ObserverProcessor1-->(log each)--> Observer1 ... Observer9
           |->ObserverProcessor2-->(whatever)-->Observer10 ... Observer20

This way your logic of observers are still decoupled from observable class but grouped nicely so that you can still add extra processing logic in the middle.

I hope this helps.


问:
How a port "listens", pull or push?
When you write a code to listen from a port, like 80 for example, what happens under the hood? Is the method the OS uses to listen is pull, or push? In other words, does the OS checks that port every x milliseconds for example?

I just don't get it. The more I think about it, the more it seems to me that it can't be anything other than pulling.

I mean, even if OS set a callback function, still something should understand that new information has arrived to call that callback function. That something still should use pull to understand the arrival of the new data.

How a port listens?

答:
The code that listens to a port just waits for a message from the network.

Whenever the Ethernet chip receives a message, an interruption is raised. The kernel handles this interruption and forwards the message to the network driver. That message goes through the TCP/IP stack and either gets filtered out or passed to the code that listens to the port.

Title: How a port "listens", pull or push?


答:
Theoretically, this depends on the specifics of the OS and network hardware. In practice, mainstream OSes and hardware use a push model based on interrupts for interaction between the hardware and the OS (and all the software controlled by the OS).

Basically, an interrupt is a very, very low-level mechanism through which peripheral hardware can signal the CPU that there is an event that needs to be handled (like a network packet having arrived, a key having been pressed, etc.). The CPU reacts to this by suspending whatever it was doing at that time and executing an interrupt handler instead.

Interrupt handling is typically done by the OS or at least started by the OS and handed off to more specific application code that has been registered as interested in a particular type of event.

Title: How a port "listens", pull or push?

Body:
When you write a code to listen from a port, like 80 for example, what happens under the hood? Is the method the OS uses to listen is pull, or push? In other words, does the OS checks that port every x milliseconds for example?

I just don't get it. The more I think about it, the more it seems to me that it can't be anything other than pulling.

I mean, even if OS set a callback function, still something should understand that new information has arrived to call that callback function. That something still should use pull to understand the arrival of the new data.

How a port listens?


答:
The Ethernet hardware will be the one polling the physical wire ( or wireless ).
When it has a 'good enough' reason, it'll interrupt the processor.
The processor will figure our the proper driver which will handle the interrupt.
The interrupt handler will handle the event ( read/write data ). driver will also tell
the Os to wakeup any waiting threads..</p>

Title: How a port "listens", pull or push?


问:
Teaching C++ to first time high school students: Where to draw the line?
I will be mentoring a team of high school students for the FIRST Robotics Competition, most teams here develop[ their robot software using C++. For many of the students on the team this will be their first introduction to programming. I wouldn't have chosen C++ for teaching programming to high schoolers (e.g. Python or Javascript would have been easier I think) but the choice is set.

I want to teach them proper C++ (i.e. avoid a mixed C/C++ dialect, i.e. C+) but I don't want to scare them either with needless complexity. For that matter:

Should I start using STL from day one, esp. vector or just stick with standard arrays? Arrays are easier to introduce but the pointer errors may be harder to catch.

For I/O, should I stick to cout, etc. or do you think printf would be easier to learn?

Are there any online resources for C++ that are suitable to use for such young learners?

Thanks!

EDIT: Thanks for so many excellent answers. In addition to Accelerated C++, which is suggested by many people, I have found that C++ For Everyone is an excellent text.

答:
I have taken a bunch of programming classes in my life from high school to College. I can say that I really didn't learn too much from my first c++ class other than how to print things to a stream.

My advice, as a young student, who has only for the past few years had any real work being a developer, is to not dumb things down on them. Tell them what they are doing and how it works down to the operating system level (No need to get into comp eng IMO).

I think teaching them C is a better way to go about it (it will still almost always compile as C++ as you know). Teaching them what the terminal really is, how their program interacts with it, that a string is an array of chars ended with a \0 in memory, what malloc is and how C++ abstracts it, how a char and an int are stored in memory, ect... These things are what makes someone actually know how to solve a problem when they come across it in development.

I can not stress the importance of letting the kids program and being there mainly to answer questions. In my experience, you learn a language by using it. Books and lessons can be helpful and are necessary to get started, but in the end, I say give them a C/C++ file and say: This is an example of X, I'd like you to do Y(which can be done by hacking X). Show them how to use man pages(if they are using *NIX) or show them cplusplus.com and let them explore the std libs to figure out things on their own.

TL;DR
Let the kids teach themselves. Be there to provide structure and answer questions.

Also: Linked lists are the truth!

OwnerDisplayName: recipriversexclusion


问:
Warning-free Objective C code
I am currently creating my first iPhone app in Objective C and getting a lot of warnings because I've in many places taken advantage of the fact that Objective C is a dynamically typed language. I get a lot of 'class' may not respond to '-message:' warnings. Should I strive to remove all these warnings? If yes, then what's the benefit of having a dynamic language at your disposal?</p>

答:
I can't really answer the question about Objective-C being really dynamic or not. I think it stays in the middle of dynamic and static world.

However, keeping warnings is rarely a good practice, as real warnings you are interested in are lost in the middle of a lot of warnings you don't care about.

So, you should get rid of these warnings. There are several things you can do :

disable the "may not respond to" warnings (but you may lost real warnings)

use protocols ( quite static way )

use optional declarations in protocols ( a bit "more dynamic" ).

use optional declarations in categories for NSObject for example ( even "more dynamic" )

use "performSelector" method, which explicitly tells you, the reader of your code, and the compiler that you are calling "dynamic" method"

use id "type" wherever an instance should be used in a non static way

Disclaimer : I don't say all of these points are good practices, but they are technical ways of achieving the goal of getting rid of warnings

Title: Warning-free Objective C code


答:
You're not teaching them programming in a general way, you're teaching them a kind of embedded programming using Robots and such. If I understood correctly.

First, I think you should check what libraries you're going to use and what you need.

If you happen to have a C library to use or C-like with a lot of pointers and C-arrays, then I guess you'd need a way to teach them how to use it or why you use it.

But, you can show them some simple codes to get them started with strings and vectors, that's how C++ works. That does not mean you can't teach them pointers.

Maybe you should make it clear of the differences between low level C++ ( which resembles C) and high level C++ with the STL. One of the most difficult thing in C++ for beginners is to see what is C, what is C++ and what are the different system APIs.

As the goal here isn't to learn general programming but to enter a Robot competition, I'd oriented the teaching this way.

Title: Teaching C++ to first time high school students: Where to draw the line?

Body:
I will be mentoring a team of high school students for the FIRST Robotics Competition, most teams here develop[ their robot software using C++. For many of the students on the team this will be their first introduction to programming. I wouldn't have chosen C++ for teaching programming to high schoolers (e.g. Python or Javascript would have been easier I think) but the choice is set.

I want to teach them proper C++ (i.e. avoid a mixed C/C++ dialect, i.e. C+) but I don't want to scare them either with needless complexity. For that matter:

Should I start using STL from day one, esp. vector or just stick with standard arrays? Arrays are easier to introduce but the pointer errors may be harder to catch.

For I/O, should I stick to cout, etc. or do you think printf would be easier to learn?

Are there any online resources for C++ that are suitable to use for such young learners?

Thanks!

EDIT: Thanks for so many excellent answers. In addition to Accelerated C++, which is suggested by many people, I have found that C++ For Everyone is an excellent text.


问:
Difference between a defect and a bug in testing?
What is the difference between a defect and a bug? </p>

答:
According to Dependability: basic concepts and terminology:

A system failure occurs when the delivered service deviates from
  fulfilling the system function, the latter being what the system is
  intended for. An error is that part of the system state which is
  liable to lead to subsequent failure: an error affecting the service
  is an indication that a failure occurs or has occurred. The adjudged
  or hypothesized cause of an error is a fault.

I understand defect as just another name for fault.

Bug is confusing and can represent a fault or a failure depending on the context.

Note that there is no mention of specification: even a spec can be faulty.


问:
Is it okay to fake part of the class under test?
Suppose I have a class (forgive the contrived example and the bad design of it):

```<code>class MyProfit
{
  public decimal GetNewYorkRevenue();
  public decimal GetNewYorkExpenses();
  public decimal GetNewYorkProfit();

  public decimal GetMiamiRevenue();
  public decimal GetMiamiExpenses();
  public decimal GetMiamiProfit();

  public bool BothCitiesProfitable();

}
</code>```

(Note the GetxxxRevenue() and GetxxxExpenses() methods have dependencies which are stubbed out)

Now I'm unit testing BothCitiesProfitable() which depends on GetNewYorkProfit() and GetMiamiProfit().  Is it okay to stub GetNewYorkProfit() and GetMiamiProfit()?

It seems like if I don't then I'm simultaneously testing GetNewYorkProfit() and GetMiamiProfit() along with BothCitiesProfitable(). I'd have to make sure I setup the stubbing for GetxxxRevenue() and GetxxxExpenses() so that the GetxxxProfit() methods return the correct values.

So far I've only seen example of stubbing dependencies on external classes not internal methods.

And if it is okay, is there a particular pattern I should use to do this?

UPDATE

I'm concerned that we might be missing the core issue and that is probably the fault of my poor example.  The fundamental question is: if a method in a class has a dependency on another publicly exposed method in that same class is it okay (or even recommended) to stub that other method out?

Maybe I am missing something, but I'm not sure splitting up the class always makes sense.  Perhaps another minimally better example would be:

```<code>class Person
{
 public string FirstName()
 public string LastName()
 public string FullName()
}
</code>```

where full name is defined as:

```<code>public string FullName()
{
  return FirstName() + " " + LastName();
}
</code>```

Is it okay to stub FirstName() and LastName() when testing FullName()?

答:
To simplify your examples further, say you're testing C(), which depends on A() and B(), each of which have their own dependencies. IMO it comes down to what your test is trying to achieve.

If you're testing the behaviour of C() given known behaviours of A() and B() then it is probably easiest and best to stub out A() and B(). This would probably be called a unit test by purists.

If you're testing the behaviour of the entire system (from C()'s perspective), I would leave A() and B() as implemented and either stub out their dependencies (if it makes it possible to test) or set up a sandbox environment, such as a test database. I would call this an integration test.

Both approaches may be valid, so if it's designed so you can test it either way up-front it will probably be better in the long run.


答:
Dan McGrath's answer nailed it right.

A bug is the result of a coding error

A defect is a deviation from the requirements

Maybe an example would make it clearer.

Example: Client wanted the web form to be able to save and close the window.

Scenario #1: Web form have a save button, and another close button.
Result: Defect, because client wanted the 1 button to save and close the window. Developer misunderstood and created separately. Because both buttons performed their requirements, it is not a bug, but a defect because it didn't meet client's requirement.

Scenario #2: Web form have a save & close button, but only saves but does not close.
Result: Bug. Because the button does not perform as required/expected. Developer knows it is suppose to produce that result but ultimately it didn't. (perhaps coding error)

Not sure if this makes it clearer.

p/s: from a developer stand point (I was once), both defects and bugs are just as important. We'll still fix it.

We even encountered weird anomalies, which we categorized under bugs and we continously try to figure out what is the cause and how to fix it. Terming it bugs doesn't make it trivial compared to defects.

Title: Difference between a defect and a bug in testing?

Body: What is the difference between a defect and a bug? </p>


问:
Computer Science and other advance topics taught in javascript
I'm an 'okay' Javascript developer working on browser javascript and node.js. However because I'm self taught, starting from copying and pasting jquery, there are a lot of holes in my programming/CS education.

I don't really have the time to devote myself to fully learning all the CS concepts that might be taught in a real college program, and learning C or Scala or whatnot, I'm just too addicted to hacking and making things that work. On some level studying CS seems to be 'premature scaling' in Hacker News parlance.

But every so often I get struck by the thought that maybe there is something that I should really really learn to take my skills and productivity to the next level.

Is there a book, a list of concepts or things that I can study and learn in my 'down time' that would see reasonable returns on my productivity and ability in 1 - 2 months?

Thanks!

And yes, the only language I know and use is Javascript, though I have tinkered with Python (High School), Ruby (RoR), PHP (Drupal), and Assembly (Making Diablo 2 Mods) in the past.

Please note that a book like O'Reilly's JavaScript Web Applications is too easy for me and not really what I'm talking about.

答:
I would start with "Javascript: The Good Parts" by Doug Crockford. Also read his web site carefully.

If really want to understand computation check "Structure and Interpretation of Computer Programs" by Abeleson and Sussman. You can get it free online, or buy a hard cover. Its written using Scheme, but scheme is a pretty simple language and you will have no problem picking it up.

The other thing I would recommend is venturing out past JavaScript. Check out "Seven Languages in Seven Weeks".

O'Relly also has a page on path to Javascript Mastery:

http://oreilly.com/javascript/index.html


问:
Why C++ cannot adopt D's approach for its concept implementation?
As many of you guys know, concepts, C++'s approach for constraining possible types for a template argument has failed to be included in C++11.

I learned that the D programming language 2.0 has a similar feature for its generic programming. Its solution seems to me quite elegant & simple.

So my question is why C++ cannot use a similar approach.

The C++ concept's goal might be bigger than what D's implementation provides?

Or C++'s legacy prevents it from adopting such an approach?

Or any other?

Thanks for your answers.

p.s. To see some examples of D's generic programming power, please refer to this: https://stackoverflow.com/questions/7300298/metaprogramming-in-c-and-in-d/7303534#7303534

答:
You mean D's template constrains?

As far a I know, C++ concepts had been proposed on behalf of boost::concept.
The problem, here, is that boost is a library written for C++03.
C++11 has other syntax capabilities that allow to implement certain things in a different way C++03 allows (hence, boost itself can be rewritten taking advantages of the new syntax).

The standard committee dropped concepts because it  will had taken too long to specify them (thus delaying again the c++11 approval). They will probably go in the next C++ release.

Meanwhile, D syntax is different then C++ and D itself retain some expression evaluation capabilities at compile time C++ cannot always have without breaking some legacy code (something D dosn't have, having it a shorter history).
C++ itself now has static_assert and costexpr, that allows to improve the compile time evaluation capabilities. May be in future will reach a similar level.

OwnerDisplayName: Emilio Garavaglia


问:
What percentage of bugs should be stamped out before a project can be accepted as a stable release?
We have been working with a shopping cart for DotNetNuke, and have had endless problems with the developer's releases of their product. Every release fixes one thing but new bugs pop up elsewhere.

I know that bugs are inevitable and that we cannot squash all of them at the time, but can someone please tell me what percentage of bugs should be stamped out before a product can be accepted as a stable release?

答:
I don’t think it’s a matter of percentage.

Each bug has to be evaluated on its own to decide whether it’s a show-stopper for the particular project in question, based on the likely cost of the bug if not fixed before release, and the likely cost of delaying release until the bug can be fixed.

(For example, Stack Overflow spent quite a while with a notification icon that didn’t display properly in Chrome. The costs of that bug were so low that it could happily be left for several weeks, as the team had bigger issues to focus on.)

And remember that “bugs” is just shorthand for “known bugs”. You could fix 100% of your known bugs and still not be in shape for launch, because you haven’t tested well enough.

OwnerDisplayName: SixfootJames

OwnerDisplayName: Paul D. Waite


答:
To master JavaScript I think you need to put as much effort as any other language, which I think Douglas Crockford explains well in The Good Parts. I haven't read the book and would instead recommend watching his presentation, which is both educational and entertaining, and I personally think it has made me a better JavaScript programmer.

Douglas Crockfords presentation of The Good Parts is freely available here:
http://www.youtube.com/watch?v=hQVTIJBZook

Title: Computer Science and other advance topics taught in javascript

Body:
I'm an 'okay' Javascript developer working on browser javascript and node.js. However because I'm self taught, starting from copying and pasting jquery, there are a lot of holes in my programming/CS education.

I don't really have the time to devote myself to fully learning all the CS concepts that might be taught in a real college program, and learning C or Scala or whatnot, I'm just too addicted to hacking and making things that work. On some level studying CS seems to be 'premature scaling' in Hacker News parlance.

But every so often I get struck by the thought that maybe there is something that I should really really learn to take my skills and productivity to the next level.

Is there a book, a list of concepts or things that I can study and learn in my 'down time' that would see reasonable returns on my productivity and ability in 1 - 2 months?

Thanks!

And yes, the only language I know and use is Javascript, though I have tinkered with Python (High School), Ruby (RoR), PHP (Drupal), and Assembly (Making Diablo 2 Mods) in the past.

Please note that a book like O'Reilly's JavaScript Web Applications is too easy for me and not really what I'm talking about.


问:
Is an architecture description document a violation of the DRY Principle?
The DRY Principle (Don't Repeat Yourself) states that "every piece of knowledge must have a single, unambiguous, authoritative representation within a system."  Most of the time this refers to code, but it is often extended to documentation also.

It is said that every software system has an architecture whether you chose it or not.  In other words, the software you build has a structure and that "as built" structure is the architecture of the software.  Since a built software system comes with an architecture, is creating an architecture description of that system a violation of the DRY Principle?  After all, if you need to know the architecture then you could always just look at the code...

答:
An architecture description does not violate the DRY principle.

Your software system comes with an architecture, sure. And it's spread out over many files, in many classes, with many extraneous and details that are unnecessary for an overview.

Your architecture document should be like the first paragraph of a news report: it's an outline, a summary, a roadmap of the project.

ContentLicense: CC BY-SA 2.5


答:
It is not possible to give a percentage number that should be fixed - if you fix 90% of bugs, one of the remaining bugs could be so severe as to cripple your application.

Instead, all bugs should be classified by severity. A few suggestions for classifications would be:

Show Stopper

Critical

High

Medium

Low

By very definition, all Show Stoppers MUST be fixed, otherwise the application will not function. Critical bugs should also be fixed before shipping.

Any remaining bugs, such as High/Medium/Low priority bugs should then be considered, ideally they should all be fixed, but if this cannot be achieved due to time or budget constraints, then each remaining bug should be evaluated and it should be determined if it is still OK to ship with the issue remaining.

Title: What percentage of bugs should be stamped out before a project can be accepted as a stable release?

Body:
We have been working with a shopping cart for DotNetNuke, and have had endless problems with the developer's releases of their product. Every release fixes one thing but new bugs pop up elsewhere.

I know that bugs are inevitable and that we cannot squash all of them at the time, but can someone please tell me what percentage of bugs should be stamped out before a product can be accepted as a stable release?


答:
The Standard of C++ is a normative document, which sets rules that will remain (mostly unaffected) in the future documents. Therefore the committee has taken a very cautious approach with regard to its updates.

The additions to the standard library were somewhat easy. A number of libraries had been in Boost for a long time: it had been proved they worked.

Additions to core concepts in the language however are much more difficult to experiment with, because it first requires modifying a compiler. A C++03 feature (the export of templates) had been specified without compiler support... the result was horrid. The implementers of the EDG compiler frontend reported it as a massive task (several man years) for very little gain. No other compiler ever tried to implement it. It's not a comfortable situation.

Features like constexpr or static_assert were easy (and already emulated by libraries). Lambdas are quite well understood and implemented in a variety of other languages, there has been extensive research already, so it was mainly a matter of syntax.

On the other hand Concepts were judged too new and untried. They were barely specified in time, there had been no proof of concept... and thus they were rejected, rather than waiting for them (or making a mistake).

Why not following D ? There is no saying that it won't. The committee has encouraged people to rethink from scratch, with no urging deadline, and to try their hands at including them in a compiler to see how they interact with other features in the language. There's notably the question of separating Concepts and Concept Maps: should they be bundled as one or not ?

FYI: There is currently a branch of Clang dedicated to this experimentation, led by Larisse Voufo from the university of Indiana.

Title: Why C++ cannot adopt D's approach for its concept implementation?

Body:
As many of you guys know, concepts, C++'s approach for constraining possible types for a template argument has failed to be included in C++11.

I learned that the D programming language 2.0 has a similar feature for its generic programming. Its solution seems to me quite elegant & simple.

So my question is why C++ cannot use a similar approach.

The C++ concept's goal might be bigger than what D's implementation provides?

Or C++'s legacy prevents it from adopting such an approach?

Or any other?

Thanks for your answers.

p.s. To see some examples of D's generic programming power, please refer to this: https://stackoverflow.com/questions/7300298/metaprogramming-in-c-and-in-d/7303534#7303534


答:
Theres not really percentage, A good way to work is to monitor the rate of bug insertion - All else being equal, when it starts to fall, the product is becoming stable. If you say something like "Ship it when x% are fixed", you will probably ship unstable code

Therefore the answer is not as easy as "At percent x we call it a release". It's better to say "Once the insertaion rate is y% of the (maximum/typical/average) insertion rate,  the software becomes a release candidate" Release candiates are tested for acceptance, and released or not after anaylisis of known and unknown bugs. You may decide to fix more severe bugs in release candidates, but you must not add features or make improvements.

Using statistical methods it is possible to "determine" unknown bugs. By that I mean get a statistical value of how many and how severe the ones you have not found are. Most of us have a gut instinct for this number, but few (including me) can do the maths.

Of couse, it you are not counting and like me, no good at math, you can go on gut instinct, and just ship it when its ready.......


问:
How to teach a script to detect sarcasm?
I'm currently building a fun script, that basically matches given phrases and gives a predefined response based on the match-points. You can ask it to retrieve some information based on live feeds, run tasks, tell anecdotes or just chat with her.

I already have built-in detection for badwords, caps lock or both. The program has a girl name and I tried to make as close to being a girly-girl as possible, on the logic terms (for example: everybody knows that most girly-girls take 700ms to respond to a question, joking of course). So here is a little example:

Client: WHAT IS YOUR PROBLEM?

  Kiku: DONT USE THAT TONE WITH ME!

  Client: #### you

  Kiku: why are you being so mean to me :/

However, I really would like to add sarcasm-feature to it. So if you write something in sarcasm, then she will detect it and respond accordingly. Now this is a tricky part, How do you teach a script, what sarcasm is?

To me more specific. What are the most common sarcastic words used today? Or how to get that statistic? How can I make the script understand the context of the given phrase?

UPDATE

As this question is getting alot of hype, I think things should be cleared out a bit more. It is very clear, that making a script fully detect sarcasm is basically impossible. At least in reasonable matter. However, I do believe that some amount of possible sarcasm could be detected.

I currently have made it so far, that my script can detect a very limited sarcasm. I predefined some common sarcastic-words (however, alone they are useless.) For example: like, whatever, yeah, right and great. And then it first matches, the simple things, like uppercase and quoted: THANKS you are so smart or oh you are so "SMART".

Since the scripts main function is to do tasks or retrieve information, and afterwords it will ask if that was what you meant. Then I thought, adding "thanks" as a special variable. So yeah thanks or whatever thanks will trigger the possible sarcasm, and the script will ask you: "Do I detect sarcasm?" Your best bet would be to say "sorry" then, otherwise it will add a warning-point and if the limit is reached -- it will start ignoring you.

As these very very simple algorithms seem to actually work, then this idea has a future, of course after alot of tuning and tweaking. However, is somebody alot smarter would make a open-source software with the same idea in mind. Then this feature could be hooked to alot of functions on the web. Customer care would probably benefit the most, however, this kind of software could also be used detecting "flaggable"-content.

答:
My 2 cents:

Ask a psychologist about how to recognize sarcasm in phrases, with that info compare them to the input.

But it would be a really hard project, with the effort used in that, you could do the best O.S. in the world for sure :P


答:
If you know a method for measuring the percentage of remaining bugs in a software, you will be the richest man of all times.

If you target only known bugs, a stable release should contain none.


问:
As a teen, how can I find "friends" for programming
I'm a teen who has been programming for about 3 years, I can do some basic Software and so, but I feel I can't do all by myself.

What can I do to find people interested in Programming ? None of my friends does, I only have a Cousin which is studying Software Engineering, but he is in another country.

I live in Spain, so It's more difficult that in USA.

答:
You can contribute to open source and you will find people from all over the world , you can look at their code and learn. Some open source groups are very elitist some friendly. Choose your pick.

Good for you on starting early :)


答:
If you're talking about actually meeting up with real people you might find this difficult as a teenager.  The easiest places to meet like-minded people when it comes to programming are probably at college/university and/or when you get a job as a programmer.  Perhaps there are evening computing classes you can attend nearby?

On the other hand, not having programmers local to you is hardly an impediment to progressing as a programmer.  There are countless ways of communicating/collaborating with people over the internet.  Find an open source project you're interested in and start contributing.  You won't meet people face to face but you can still get the benefit of other people's experience and knowledge.  Start following projects on sites like github or create your own projects and ask others for help.

Title: As a teen, how can I find "friends" for programming

Body:
I'm a teen who has been programming for about 3 years, I can do some basic Software and so, but I feel I can't do all by myself.

What can I do to find people interested in Programming ? None of my friends does, I only have a Cousin which is studying Software Engineering, but he is in another country.

I live in Spain, so It's more difficult that in USA.


答:
There are various options that help you reach many people sharing your same interests.

Write a blog about programming, in a blog platform with many users.

Create an open source project or contribute to an existing one. If it's something people like to use, you will find many who will join and help you.

Follow programming groups on social networks.

Search on programming related forums. There are many people willing to start a common project, or looking for help.

Go to a college or university, you will meet many people with your same interests there.


问:
Observer pattern over HTTP and TCP/IP (Server-Client)
I have a server and many clients (around 50 clients) who connect to that server based on a web application, which is of course based on HTTP protocol, which in turn uses TCP/IP (correct me if I'm wrong, cause I'm not really good at networking).

The problem is that, I should develop an alert mechanism, in which, when somebody submits a form with dangerous values, the manager (who is also connected via the same web application) should receive an alert pop-up on his screen, almost real-time (instantly).

However, since the HTTP protocol is stateless, I' a little puzzled here. I don't know how I can implement this.

One of the solutions could be to use JavaScript alongside setInterval() function to pull data each second from server. But this seems a little dirty to me and unprofessional.

Do you guys have any idea of implementing another solution?

答: You should use some kind of ajax push (see Comet) to notify the clients. It can eliminate the need for polling, you basically keep an established connection open which can be used to notify the browser of ocurring events. However, this does not work with all browsers. You fall back to "long polling" in such cases.


问:
How much effort should we spend to programming for multiple cores?
Processors are getting more and more cores these days, which leaves me wondering...

Should we, programmers, adapt to this behaviour and spent more effort on programming for multiple cores?

To what extent should we do and optimize this? Thread? Affinity? Hardware optimizations? Something else?

答:
We're now (October 2010) in a time of immense transition.

We could today purchase a 12 core desktop.

We could today purchase a 448 core processing card (search for NVidia Tesla).

There are limits to how much we developers can work in ignorance of the tremendously parallel environments our programs will be working within in the near future.

Operating systems, runtime environments and programming libraries can only do so much.

In the future, we'll need to be partitioning our processing into discrete chunks for independent processing, using abstractions like the new .NET "Task Framework".

Details such as cache management and affinity will still be present - but they'll be the provence of the ultra-performant application only. No same developer will be wanting to manage these details manually across a 10k core machine.


答:
Finding an open source project that you are interested in and starting to contribute will serve you well. You'll make a bunch of new acquaintances that might turn into friends. You'll certainly learn a lot of useful stuff by doing that.

Another thing you can do is look for part time work in a software company near you. If you're not looking to make a lot of money it's usually easy to get some entry level work. You can learn a huge amount by working with real pros.

There are lots of other ways to contact people who have an interest in programming. The Internet is awesome for that. StackOverflow is a good site if you have questions. There's countless IRC channels and news groups, online forums, etc.

See if you can locate an interest group near you. A Linux user group will have more than a handful of programmers. If there isn't one, you can always think about starting one. I am sure there's a number of like-minded individuals near you that would turn up.


答:
In the real world? Find a hackday/lanuage of choice user group. In the online world, well there's plenty of groups around open source projects, and then you have the wild west of IRC as well.

Start with a specific language in mind and work from there, there's probably hundreds of thousands of groups out there but if you have a direction it'll make it easier to find something relevant to your interests.


答:
As the others pointed out, participating in online communities and projects is a very good way to go. I wanted to add yet another option:

You might try to convince your parents to go to a conference nearby on a subject, that interests you. Usually it's fairly cheap for students.

It will definitely give you the chance to meet many people, some of which you will in fact stay in contact with.


问:
Find the average speed for roads
I am working on a mobile application and I would like to ask you a question. Is there an API or a method to get/calculate the average speed that a car should have in a road. I am working on a GPS like application and I want to calculate the average time that it will take a user to cover a certain path.

Thanks.

答:
This will require you to access some database(s) which hold maximum allowed speeds for each road. Looking to purchase such information can turn out to be quite costly, especially if you want to cover wide areas. Combining several different data sources can also result in some extra required effort.

Probably it's best to use an existing service, like Google Maps. A quick look at their API indicates they can provide you with some of the information you need.

Title: Find the average speed for roads


问:
Should we embed virtual machines rather than languages
Ok, so I am trying to learn front-end programming. Trying to figure out how javascript is a pain, and various projects (GWT, Coffeescript, Capuccino's objective/j...) are trying to fix this with languages that compile to JS.

What would you do if you were to reinvent the browser?

I think I would embed a VM rather than a language (quite like Java applets except less complex and with a DOM API instead of a canvas and self-contained environment).

I suppose this has been suggested many times, but I cannot find resources on this, and most of the embedding tutorial I stumble on address embedding languages (guile, lua, python, whatever).

Thoughts?

答:
An embedded language IS an embedded virtual machine, and vice versa.  Each has a defined interface to the browser, each has a defined user interface (syntax or instruction set or call it what you will).

If I were going to reinvent the browser, and provide a language for extensions, I would provide a LISP.  Most probably, I would look at a LISP based on GNU Emacs LISP (possibly GUILE?), because that particular LISP had certain scope and binding design decisions resolved in ways that allowed extensions to interoperate.

Why LISP?  In my personal opinion, LISP does some things easily that other languages do poorly or not at all.  It is perfectly feasible to compile procedural (more limited) languages to LISP, but, if you hit some of the corner cases, it can be very difficult to compile LISP to, say, C.


答:
When software gets close to shipping, you often get a lot more miner bug reports and bug reports that are asking you for new functionality.   This shows that there are not many “show stoppers” that are preventing your testers using the app.

So talking about “percentage of bugs fixed” is not useful…


问:
What is the best way to INSERT a large dataset into a MySQL database (or any database in general)
As part of a PHP project, I have to insert a row into a MySQL database. I'm obviously used to doing this, but this required inserting into 90 columns in one query. The resulting query looks horrible and monolithic (especially inserting my PHP variables as the values):

```<code>INSERT INTO mytable (column1, colum2, ..., column90)
VALUES
('value1', 'value2', ..., 'value90')
</code>```

and I'm concerned that I'm not going about this in the right way. It also took me a long (boring) time just to type everything in and testing writing the test code will be equally tedious I fear.

How do professionals go about quickly writing and testing these queries? Is there a way I can speed up the process?

答:
With MySQL you can use alternate syntax for insert statements:

```<code>insert into table
        set column1 = value1
          , column2 = value2
          , column3 = value3
</code>```

Body:
With MySQL you can use alternate syntax for insert statements:

insert into table
        set column1 = value1
          , column2 = value2
          , column3 = value3


答: Programming is not yet a science its more of a mixture of science and creativity mixed in with a few other things. One cannot simply measure quality by way of some counter in a bug report. For one there is no way of knowing all bugs in the system have been entered which would lead to a lower than actual score, ruining the analysis.</p>


答:
Here is a QA with Herb Sutter, he talks about concepts at the 15minutes mark.

http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answers

If you like that, here is another one: http://channel9.msdn.com/Shows/Going+Deep/Conversation-with-Herb-Sutter-Perspectives-on-Modern-C0x11

Now as to your question. Why not the D version? Well why use it? C++ is a very complex and stable language. Each feature needs to be selected extremely carefully, because it usually has to be supported for decades. If you look at the first C++ standard and follow the revisions, there are some deprecated features, but even those have to be still supported. So it makes sense to design concepts to 100% fit C++.

As for why it wasn't included in C++0x. Well because it was huge. The proposal was 100 pages long and very hard to implement. It was decided that this feature needs more time to mature until it is included into the standard.


问:
What do we mean by "design" in software engineering?
I have been reading about different software methodologies. Every method has a design phase to some extent, more or less.

I am not clear on what we mean by designing. Does this mean writing your thought process on how you will code the feature? Or it is a way of saying what you have coded or will code.

The point where I am most confused is the real world, which is different than putting your thoughts in documents and saying it will work. Since coding details can change, I don't know what's the point of having a design before coding.

答:
First of all, the design is, in my opinion, a process of preparing / thinking over the project / software / application, so it is consistent, fulfilling the goals, meeting the requirements. Design also helps making the software production process more efficient (because it is about some really basic things in the project, how they should work etc.).

Wikipedia says:

Software design is a process of problem solving and planning for a
  software solution. After the purpose and specifications of software
  are determined, software developers will design or employ designers to
  develop a plan for a solution. It includes low-level component and
  algorithm implementation issues as well as the architectural view.

Which means that you make a plan before building the structure (in this case: software).

And why do we first design, then implement, even if many things change? Please see the following picture (source: http://www.agilemodeling.com/essays/costOfChange.htm) that clarifies this the best (at least I think so):

OwnerDisplayName: Tadeck


答: Most methodologies have different phases in the software life cycle. It all depends on which methodology you choose. However the gist of most of them is planning, design, coding, implementation/deployment, and then maintenance. But you'll have to look at each different one for what their worth.</p>

Title: What do we mean by "design" in software engineering?

Body:
I have been reading about different software methodologies. Every method has a design phase to some extent, more or less.

I am not clear on what we mean by designing. Does this mean writing your thought process on how you will code the feature? Or it is a way of saying what you have coded or will code.

The point where I am most confused is the real world, which is different than putting your thoughts in documents and saying it will work. Since coding details can change, I don't know what's the point of having a design before coding.

OwnerDisplayName: AmitApollo


答:
Good question!  (although it's more appropriate for programmers.stackexchange)

I used to ponder this point a lot too; how can you design a program before you've coded it ? I mean you don't know what you're going to write after all!

Well, to me, it comes down to a nutshell that many great artisans of our industry have echoe'd;

A good programmer says 'I can solve this problem' and writes 100 lines of code.
A great programmer says 'I've seen this problem before' and re-uses the code they wrote last time.

Designing a program is sitting down, thinking about the various issues of the problem-domain and working out in a general fashion how you might solve that issue, or how you've solved it before, and (more so I've found recently) when to decide whats important and whats not.

I guess what I'm driving at is that Design is all about visualising the bigger picture; but its hard to do so until you've been there at least once.

To use a metaphor, any programmer can write a program that mixes flour and water; but it takes further understanding to make a system that bakes a cake.

Ok, bad metaphor - but I hope you see what I'm driving at.

OwnerDisplayName: Russ C


答:
Designing is to think of how you will structure your project: what subsystems, components, modules, but also what classes, functions and variables it will consist of. Before you start writing code you do some kind of design in your head, maybe on the function or class level, and maybe its very thin, but you cannot write anything without having a design in your mind.

The design that is done in the design phase is normally on the system level, where you decide what kind of subsystems your product will consist of (for instance web + database server) or what the main components will be (like a user management, audio processing, database abstraction, etc.). Those high level abstractions will help divide responsibilities, help schedule the project and provide the main structuring of the code to be written.

But design is not necessarily a specific phase, its something that is done over and over on different levels of abstraction. And as you pointed out, you will learn a lot when coding, and some parts of the design might have to change, which is perfectly fine. And the major abstractions, the one that were I mentioned before which are defined during design phase, are generally on a high enough abstraction to not be affected by issues on the code level.

OwnerDisplayName: inflagranti


答: Quite simply, C++ has a hell of a lot more historical baggage than D. It would be much easier to implement an awful lot of things if it wasn't for the fact that C++ has massive amounts of historical code which must continue to work correctly and as expected. D doesn't have this problem.</p>


问:
Violation of the DRY Principle
I am sure there's a name for this anti-pattern somewhere; however I am not familiar enough with the anti-pattern literature to know it.

Consider the following scenario:

or0 is a member function in a class. For better or worse, it's heavily dependent on class member variables.  Programmer A comes along and needs functionality like or0 but rather than calling or0, Programmer A copies and renames the entire class.  I'm guessing that she doesn't call or0 because, as I say, it's heavily dependent on member variables for its functionality.  Or maybe she's a junior programmer and doesn't know how to call it from other code.  So now we've got or0 and c0 (c for copy).  I can't completely fault Programmer A for this approach--we all get under tight deadlines and we hack code to get work done.

Several programmers maintain or0 so it's now version orN.  c0 is now version cN.  Unfortunately most of the programmers that maintained the class containing or0 seemed to be completely unaware of c0--which is one of the strongest arguments I can think of for the wisdom of the DRY principle.  And there may also have been independent maintainance of the code in c. Either way it appears that or0 and c0 were maintained independent of each other.  And, joy and happiness, an error is occurring in cN that does not occur in orN.

So I have a few questions:

1.) Is there a name for this anti-pattern?  I've seen this happen so often I'd find it hard to believe this is not a named anti-pattern.

2.) I can see a few alternatives:

a.) Fix orN to take a parameter that specifies the values of all the member variables it needs.  Then modify cN to call orN with all of the needed parameters passed in.

b.) Try to manually port fixes from orN to cN.  (Mind you I don't want to do this but it is a realistic possibility.)

c.) Recopy orN to cN--again, yuck but I list it for sake of completeness.

d.) Try to figure out where cN is broken and then repair it independently of orN.

Alternative a seems like the best fix in the long term but I doubt the customer will let me implement it.  Never time or money to fix things right but always time and money to repair the same problem 40 or 50 times, right?

Can anyone suggest other approaches I may not have considered?

答:
Sounds like spaghetti code to me. The best fix is a refactor/rewrite.

a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow is conceptually like a bowl of spaghetti, i.e. twisted and tangled...

ContentLicense: CC BY-SA 4.0

Title: Violation of the DRY Principle


答:
it is just called duplicate code - I don't know of any more fancy names for this. The long term consequences are as you described, and worse.

Of course, eliminating the duplication is the ideal option if only possible. It may take a lot of time (in a recent case in our legacy project, I had several methods duplicated across more than 20 subclasses in a class hierarchy, many of which had evolutionarily grown their own slight differences / extensions over the years. It took me about 1,5 years through successive unit test writing and refactoring to get rid of all duplications. Perseverance was worth it though).

In such a case, you may still need one or more of the other options as temporary fixes, even if you decide to start moving towards eliminating the duplication. However, which of those is better depends on a lot of factors, and without more context we are just guessing.

Lots of small improvements can make a big difference in the long run. You don't necessarily need the customer's explicit approval for these either - a little refactoring every time when you touch said class to fix a bug or implement a feature can go a long way over time. Just include some extra time for refactoring in your task estimates. It is just like standard maintenance to keep the software healthy in the long run.

Title: Violation of the DRY Principle

Body:
I am sure there's a name for this anti-pattern somewhere; however I am not familiar enough with the anti-pattern literature to know it.

Consider the following scenario:

or0 is a member function in a class. For better or worse, it's heavily dependent on class member variables.  Programmer A comes along and needs functionality like or0 but rather than calling or0, Programmer A copies and renames the entire class.  I'm guessing that she doesn't call or0 because, as I say, it's heavily dependent on member variables for its functionality.  Or maybe she's a junior programmer and doesn't know how to call it from other code.  So now we've got or0 and c0 (c for copy).  I can't completely fault Programmer A for this approach--we all get under tight deadlines and we hack code to get work done.

Several programmers maintain or0 so it's now version orN.  c0 is now version cN.  Unfortunately most of the programmers that maintained the class containing or0 seemed to be completely unaware of c0--which is one of the strongest arguments I can think of for the wisdom of the DRY principle.  And there may also have been independent maintainance of the code in c. Either way it appears that or0 and c0 were maintained independent of each other.  And, joy and happiness, an error is occurring in cN that does not occur in orN.

So I have a few questions:

1.) Is there a name for this anti-pattern?  I've seen this happen so often I'd find it hard to believe this is not a named anti-pattern.

2.) I can see a few alternatives:

a.) Fix orN to take a parameter that specifies the values of all the member variables it needs.  Then modify cN to call orN with all of the needed parameters passed in.

b.) Try to manually port fixes from orN to cN.  (Mind you I don't want to do this but it is a realistic possibility.)

c.) Recopy orN to cN--again, yuck but I list it for sake of completeness.

d.) Try to figure out where cN is broken and then repair it independently of orN.

Alternative a seems like the best fix in the long term but I doubt the customer will let me implement it.  Never time or money to fix things right but always time and money to repair the same problem 40 or 50 times, right?

Can anyone suggest other approaches I may not have considered?


问:
Is "call and return" a pattern or an antipattern?
Imagine to have this code:

```<code>class Foo:
  def __init__(self, active):
    self.active = active
  def doAction(self):
    if not self.active:
      return
      # do something

f=Foo(false)
f.doAction() # does nothing
</code>```

This is a nice code; I actually have (not in Python) a global active variable called "dosomething" and a routine called "something," where the first thing happening inside the "something" routine is if not dosomething return.

An alternative implementation would call to a routine that always performs an action, and the flag is checked at invocation time, as in the following code:

```<code>class Foo:
  def doAction(self):
    # do something

doaction = False

f=Foo()
if doaction:
  f.doAction()
</code>```

What is your opinion on this? I personally find that the first solution violates the least surprise principle: The caller is invoking an action which is never performed in response to a status which has been set somewhere else, but from the code it looks like the action is performed.

Would you consider it a total pattern, a total antipattern, or just an option with no strong opinion for or against it?

答:
The relevant principle is in my opinion: Tell, Don't Ask

The question is: is self.active something within the domain of Foo.

If it is in Foo's domain, and you go for the second solution, you would violate encapsulation by imposing knowledge of it to the caller, and should be avoided.
A good example would be a Customer, that is considered active when he has payed it's bills.

If it is not in Foo's domain, one should refactor, so that active it is not a member variable of Foo.


答:
If I understand you properly, there is too much going on in the class.  That creates methods that do not follow the single responsibility principle.  Leading to code that needs to be moved around, pieces taken while others left out.  This could also create a lot of members.

You should also review the accessibility modifiers.  Ensure those things that are public, should in fact be public.  The consumer doesn't need to know about every little member...use encapsulation.

This calls for a refactor.  It also appears that code is being written with no upfront design.  Look into Test Driven development.  Write the code how it should be called rather than calling code however it is implemented.  Look into TDD for some hints on how to accomplish the task.

Title: Violation of the DRY Principle


答:
If you're copying code, you'll introduce a technical debt of double maintenance or more specifically: code duplication.

Usually this is fixed through refactoring. More specifically you redirect all the calls to a new function (or a new method in a new class) that has the common code. The easiest way to start is to remove all the copied code and see what breaks, in which you fix by redirecting the calls to the common code.

Getting your customer to agree to refactor code may be difficult since it is hard to convince a non-technical person to fix a technical debt. So the next time you give time estimates, just include the time it takes to refactor to your estimates. Most of the time customers do assume you're doing clean up of the code during the time you do the fix.

Title: Violation of the DRY Principle


答:
There is a reference to the WET (We Enjoy Typing) pattern but I don't know if it is a standard name.

...Software licensing is a notable exception to the DRY (Don't Repeat Yourself) practice - software licensing code should be as WET (We Enjoy Typing - the opposite of DRY) as possible.

If you isolate your licensing logic in one place, separated from other concerns, you make it far easier to modify your software to disable the licensing altogether. It is much better to repeat the licensing logic many times throughout the application, preferably such that it is executed numerous times throughout a single execution of the software.

For example, we suggest that you perform a licensing check during installation, during application startup, and whenever important features are accessed. Don't check the licence once during startup & pass that value around; instead, actually replicate the licensing check in each area. It's inconvenient, but far better than releasing a product that's easy to crack...

Title: Violation of the DRY Principle


问:
Teaching C++ to first time high school students: Where to draw the line?
I will be mentoring a team of high school students for the FIRST Robotics Competition, most teams here develop[ their robot software using C++. For many of the students on the team this will be their first introduction to programming. I wouldn't have chosen C++ for teaching programming to high schoolers (e.g. Python or Javascript would have been easier I think) but the choice is set.

I want to teach them proper C++ (i.e. avoid a mixed C/C++ dialect, i.e. C+) but I don't want to scare them either with needless complexity. For that matter:

Should I start using STL from day one, esp. vector or just stick with standard arrays? Arrays are easier to introduce but the pointer errors may be harder to catch.

For I/O, should I stick to cout, etc. or do you think printf would be easier to learn?

Are there any online resources for C++ that are suitable to use for such young learners?

Thanks!

EDIT: Thanks for so many excellent answers. In addition to Accelerated C++, which is suggested by many people, I have found that C++ For Everyone is an excellent text.

答:
Should I start using STL from day one, esp. vector or just stick with standard arrays? Arrays are easier to introduce but the pointer errors may be harder to catch.

The problem with arrays is that anything except simple textbook examples will require dynamically sized arrays, and the moment you need dynamically sized arrays, std::vector is so much more easier. Also, the only way to safely handle dynamically sized arrays is to wrap them in your own class, which would be a poor std::vector rip-off.

Contrary to inexplicably popular belief, students can use features that require complex mechanics to be implemented without knowing how to implement such beasts themselves. As I have said in a comment: You wouldn't even think of considering not teaching strings in other languages, just because their implementation is complex, would you?

For I/O, should I stick to cout, etc. or do you think printf would be easier to learn?

Why would a set of archaic format string conventions that make your program blow up through the roof the moment you get something wrong (which happens the moment you change a typedef in some seemingly unrelated header) be preferable to the type safety of std::cout?

Are there any online resources for C++ that are suitable to use for such young learners?

Most C++ resources, online or not, are bad. And I'm not talking about using hard-to-read fonts or language. I'm talking glaringly obvious factual errors. There's very few good C++ resources, mostly one or two dozen books. The only one I know is online is Bruce Eckel's Thinking in C++.

For a decade, I have taught C++ to students with very different background using Koenig/Moo's Accelerated C++ as a base. My course has changed a lot in that decade, is is now nowhere near the book, except for the underlying principle: Use the modern, correct, safe idioms from the very beginning. Do not teach your students how to manually manipulate memory, just to have them later unlearn that in favor of safer idioms. As you can see at some of the answeres provided here, this does not work: Those once taught the manual ways first will rarely ever understand the advantage of using modern, safe idioms.


问:
How to manage a project in school?
I just started doing PhD and we are supposed to do a project for a class, there are 14 people taking the class and we are supposed to develop a system all together.

I was away from academia and working in the industry before, and I know it is very hard to manage even a couple of people towards the same goal.

We are going to make the first meeting in a couple of weeks. First, I will suggest using a version control system like SVN. Second, I will try to take the lead for the architecture of the system, because I think I am more experienced. Since the class is about computer vision and I anticipate that most of the people's background is research related so there is a big chance that I am more experienced. I will gladly hand architecture to someone else if he/she is more experienced.

What else should we do to progress without much hassle?

PS. You can assume every one of us is going to work remotely, and meet once in a week at it's best (not everyone will attend though). And the project needs to be finished in 2 months. It does not need to be a perfect, complete product, we just need to make a prototype.

PPS. The aspects of the group reminds me of open source project groups, maybe the answers will be helpful for those groups as well.

答:
Note that this isn't specific to school since the problem you said is a pretty generic issue

Pick a reliable VCS and stick with it. SVN is the easiest but depending on how your developing it (see below), you could also consider something a little less linear. Something like Git (but not Git itself) would be better since you can do easy branching.

Divide the project into distinct modules. This way you can hand somebody a module outline and say "Write this". Code separation helps greatly.

Get something like Bugzilla or JIRA to track issues/features (unless your using something like Google code that has this stuff built in) and assign people reports there. This way somebody can just browse through the reports and figure out who's working on what.

Pick one or two of the most experienced/knowledgeable people to be project leaders as well. This way it looks like more of a group effort and your not the only weak link in the design ("Where's nimcap?" "Oh he's sick" "Well what am I supposed to do? I've [insert problem]")

Title: How to manage a project in school?


问:
Patterns to avoid long switch block in UI?
Sometimes you have many entities which have common parts, but also should be addressed uniquely in UI. For example, in a CMS, you have many content types (like news, images, articles, pages, etc.) which have title, URL, SEO settings, etc. in common, but which also have specific fields. For example, image have a path field, while news doesn't have that.

Now when you want to work with these items per page, you encounter long switch and if blocks. For example:

```<code>switch(currentLoadedContentType)
{
   case ContentType.Gallery:
       // Show gallery specific fields;
       break;
   case ContentType.News:
       // Show news specific fields;
       break;
   case ContentType.Artiel:
       // Show artiels specific fields;
       break;
   case ContentType.Page:
       // Show pages specific fields;
       break;
}
</code>```

As you increase the number of content types, this lists gets longer and longer. What patterns are available to reduce the length or eliminate this long switch, but at the same time don't result in repetition. (I'm a big fan of DRY).

答:
I am assuming, you display the fields in a generic fashion (e.g. a propertygrid).

If so, you could make the model objects know about their 'public' data.
For example, the model base class has a user_customizable_properties method, and in the view, instead of the switch statement, you could do something like

```<code>for field in currentLoadedContentType.user_customizable_properties():
    show_field(field)
</code>```

Frameworks like ruby/rails or django provide their scaffolding/admin interface this way (although they use a little more reflection than my example)

Body:
I am assuming, you display the fields in a generic fashion (e.g. a propertygrid).

If so, you could make the model objects know about their 'public' data.
For example, the model base class has a user_customizable_properties method, and in the view, instead of the switch statement, you could do something like

for field in currentLoadedContentType.user_customizable_properties():
    show_field(field)

Frameworks like ruby/rails or django provide their scaffolding/admin interface this way (although they use a little more reflection than my example)


问:
How a port "listens", pull or push?
When you write a code to listen from a port, like 80 for example, what happens under the hood? Is the method the OS uses to listen is pull, or push? In other words, does the OS checks that port every x milliseconds for example?

I just don't get it. The more I think about it, the more it seems to me that it can't be anything other than pulling.

I mean, even if OS set a callback function, still something should understand that new information has arrived to call that callback function. That something still should use pull to understand the arrival of the new data.

How a port listens?

答:
OK, I am not a Ethernet hardware engineer, but I think I can take a stab at your question. When you write code to listen from a port, the following happens:

Your application code blocks/sleeps/"selects"/polls until the OS signals that a packet has arrived (with an some bits in the IP header indicating that packet is associated with that particular "port" and thus with your application that is listening on that port)

The OS typically doesn't poll (in x86/PC architectures) for new packets, it just merrily runs along until it receives an interrupt from the Ethernet network hardware (passed along by the Ethernet network driver, the OS/hardware interface).

The Ethernet network hardware itself under the covers typically contains a Ethernet controller and some "receiving buffers" aka "packet buffers". The Ethernet network driver will manage the details of noticing that a buffer is full and the OS should be notified; I am not totally clear whether this is typically push or pull within the Ethernet hardware but I suspect it's interrupt driven, or some register on the chip gets set when a buffer is ready.  But what sets the buffers?

An even lower-level portion of the Ethernet hardware fills the buffers (or DMAs packets to main memory directly). A very low-level logic actually recognizes the swings in voltage (or optical signalling) and translates those as "bits" and places the results into the packet receiving buffers (and perhaps sets register values within the Ethernet hardware).  (Sidenote: back before Network Interface Cards, when people used serial/parallel port connections, a single byte coming in could generate a hardware interrupt (IRQ) to the OS; see paragraph four of http://zone.ni.com/devzone/cda/tut/p/id/4052 )

How does that lowest-level hardware know what constitutes a "bit"? Well, Ethernet, at least most of the older/common ones, use Manchester Coding  to decode voltage swings as bits.  What does that imply? Well, as that page mentions, there is an underlying assumption that each bit is transmitted in a fixed time, an implicit clock signal. (This is why Ethernet speeds in the standards are fixed at either 10Mb/s, 100Mb/s, 1000Mb/s etc. and not completely variable; both sides of the ethernet connection must agree to the transmission rate via configuration or some initial handshaking mechanism when the Ethernet cable is plugged in. There is an actual clock circuit in hardware on both sides of the wire supporting those one or more of those frequencies. Sometimes the rate of this clock is called its frequency or the signalling rate.)   While I would call it sampling, not polling/pulling, it seems correct to me to say that the voltage level is sampled at every X amount of time and the decision is made whether or not a bit is 1 or 0.

So your intuition that "pulling" occurs is, at the lowest hardware level, perhaps correct... the Ethernet circuit "pulls" what the voltage level is at certain intervals. (But the term "pull"ing can be downright incorrect if one is speaking at the OS level.) Of course, if you start talking about voltage levels and exactly how things are triggered, neither electrical nor optical physics will use the terms "push" or "pull" for describing electrical fields and potentials, but let's assume we're all programmers, not physicists here. :-)

Title: How a port "listens", pull or push?


问:
Effectiveness of "what is your greatest strength/weakness" interview questions
As someone who is now finding himself on the other end of the interview table, I'm wondering how useful these questions are from an employer's perspective. Some of my coworkers think they're good because you can see "how they respond," but I'm not convinced it tells you anything useful, for several reasons:

It's not a very comfortable question and can lead people to twist their answers, even if not on purpose

People may not fully know their greatest strengths or weaknesses (i.e. judge them by their peers)

Explaining what a strength is isn't as good as showing it

I still don't know any more about the candidate afterwards

The rationale of my coworkers is that it can help weed out people that give ridiculous responses, like one guy that said his greatest strength was "his intellect" or people that try to turn the weakness question into a strength like "I work too hard." But I think there's more effective ways to determine such things. If you want to see if someone's smart, ask them technical questions. If you want to see if someone is productive, look at their work history. If you want to see how someone reacts under stress or change, ask them how they've dealt with it and ask for concrete examples.

What are people's thoughts on these questions, from the perspective of an interviewer? What do they really tell you about a candidate, and what are better alternatives? How do I convince my colleagues of this?

答:
I think the effectiveness of the question depends on your ability to read people. A guy that is obviously saying bullsh*t have better chance to be saying bullsh*t later when you hire him. A guy that give a canned answer also gives up unconscious hint about his personnality (it usually infer a certain fear about authority - which can be a good thing - but it's still something you can infer about his personality).

So no I don't think the question is useless unless you are pretty poor at reading people (it's a skill). All soft questions like this one is mostly to get to know the guy and see if he is a good fit for you. Maybe this is not the best question for that and it's totally ok not to ask it if you don't feel like it but I don't think it is as useless as you seem to think it is.


问:
One-line functions that are called only once
Consider a parameterless (edit: not necessarily) function that performs a single line of code, and is called only once in the program (though it is not impossible that it'll be needed again in the future).

It could perform a query, check some values, do something involving regex... anything obscure or "hacky".

The rationale behind this would be to avoid hardly-readable evaluations:

if (getCondition()) {
    // do stuff
}
```

where getCondition() is the one-line function.

My question is simply: is this a good practice? It seems alright to me but I don't know about the long term...

答:
Depends on that one line. If the line is readable and concise by itself, the function may not be needed. Simplistic example:

void printNewLine() {
  System.out.println();
}
```

<p>OTOH, if the function gives a good name to a line of code containing e.g. a complex, hard to read expression, it is perfectly justified (to me). Contrived example (broken into multiple lines for readability here):</p>

<pre class="lang-java prettyprint-override"><code>boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isFemale()
        && (taxPayer.getNumberOfChildren() > 2
        || (taxPayer.getAge() > 50 && taxPayer.getEmployer().isNonProfit()));
}
</code>```

Body:
Depends on that one line. If the line is readable and concise by itself, the function may not be needed. Simplistic example:

void printNewLine() {
  System.out.println();
}

OTOH, if the function gives a good name to a line of code containing e.g. a complex, hard to read expression, it is perfectly justified (to me). Contrived example (broken into multiple lines for readability here):

boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isFemale()
        && (taxPayer.getNumberOfChildren() > 2
        || (taxPayer.getAge() > 50 && taxPayer.getEmployer().isNonProfit()));
}


答:
It depends. Sometimes it's better to encapsulate an expression in a function/method, even if it's only one line. If it's complicated to read or you need it in multiple places, then I consider it a good practice. In the long term it's easier to maintain, as you've introduced a single point of change and better readability.

However, sometimes it's just something you don't need. When the expression is easy to read anyway and/or just appears in one place, then don't wrap it.

Title: One-line functions that are called only once

Body:
Consider a parameterless (edit: not necessarily) function that performs a single line of code, and is called only once in the program (though it is not impossible that it'll be needed again in the future).

It could perform a query, check some values, do something involving regex... anything obscure or "hacky".

The rationale behind this would be to avoid hardly-readable evaluations:

if (getCondition()) {
    // do stuff
}
```

where getCondition() is the one-line function.

My question is simply: is this a good practice? It seems alright to me but I don't know about the long term...


答:
Yes, this can be used to satisfy best practices. For instance, it is better to have a clearly-named function do some work, even if it is only one line long, than to have that line of code within a larger function and need a one-line comment explaining what it does. Also, neighbouring lines of code should perform tasks at the same abstraction level. A counterexample would be something like

```<code>startIgnition();
petrolFlag |= 0x006A;
engageChoke();
</code>```

In this case it is definitely better to move the middle line into a sensibly-named function.

Body:
Yes, this can be used to satisfy best practices. For instance, it is better to have a clearly-named function do some work, even if it is only one line long, than to have that line of code within a larger function and need a one-line comment explaining what it does. Also, neighbouring lines of code should perform tasks at the same abstraction level. A counterexample would be something like

startIgnition();
petrolFlag |= 0x006A;
engageChoke();

In this case it is definitely better to move the middle line into a sensibly-named function.


问:
What is the difference between artificial intelligence (AI) and swarm intelligence?
I understand that when we try to implement swarm intelligence, it basically has multiple independent units communicating and with each other. What I am unsure of is if swarm intelligence an extension of artificial intelligence or if it is a discipline in and of itself.</p>

答: I would call it a subset of AI. It's artificial intelligence but using a more decentralized model.</p>


问:
I code rarely. Is this a bad sign?
I am a computer science student and learning Java now a days.

I want to be a good developer/programmer.

I like reading books. I search on the internet for the related topics and study them. I refer to StackOverflow and other good programming websites daily but I code rarely. Is this a bad sign? If yes then what should I do to overcome this problem?

答: "It depends" would be my short answer to this.  It isn't necessarily a bad sign, as my first programming job out of university I remember having to learn how to use Visual Studio, IIS, and MS-SQL Server on the job which I did accomplish, though this was back in 1997.  I would suggest investigating how you learn something as well as what kind of algorithms do you know as some of them got drilled into my head like divide and conquer.</p>

Title: I code rarely. Is this a bad sign?


答: I've used Swarm Intelligence in my thesis and I'm studying AI in my master. I would say that AI is a huge field and Swarm Intelligence would intersect both AI - multi-agent system - and Operations Research - optimization - fields.</p>

Title: What is the difference between artificial intelligence (AI) and swarm intelligence?

Body: I understand that when we try to implement swarm intelligence, it basically has multiple independent units communicating and with each other. What I am unsure of is if swarm intelligence an extension of artificial intelligence or if it is a discipline in and of itself.</p>


问:
Reinventing the wheel because it doesn't exist
One of the languages I have to use at work is a very small, niche language called psl. One of the largest complaints I have about it as a language is that the libraries are very limited.

While that's understandable for a small language developed by a couple of guys, it does cause me some dilemmas. Specifically, I find myself "rewriting" functions that are standard in other languages because they don't exist here.

This is especially problematic when I'm attempting to write a function to solve a problem, and management doesn't want to spend the time to do so. They want me to use hard coded magic numbers instead, which I know will need to change multiple times over the life of the code.

This doesn't quite fit the antipattern reinventing the wheel because it didn't exist here in the first place. What kind of anti pattern would this fit?

答:
Writing functionality that doesn't exist in standard libraries or as usable COTS or OSS solutions isn't an anti-pattern. It's a necessity driven by the technology stack that was  chosen. If an inappropriate technology stack was chosen for the project simply because it was used successfully before, that's an example of the Silver Bullet anti-pattern.

Using magic numbers in your code, instead of isolating them into configuration settings or as constants is an example of the Magic Numbers anti-pattern. As FrustratedWithFormsDesigner mentioned in the comments, management dictating design details is also a sign of micromanagement.

The project might be experiencing the Vendor Lock-In anti-pattern, if technology was chosen and software designed in such a way that it is difficult or impossible within a reasonable amount of effort to change the libraries and tools used.


答:
I see this forking in one of two different roads.  My first inclination is that of code smell, an indicator of a deeper problem.  Why do you need to use a custom niche language?

A.  Because your company has found it worth the time and effort to do so.

Then, you are not "reinventing the wheel".  The language is new and offers enough added-value to merit the time investment for new functionality.

OR...

B.  Because you are being elitist and/or otherwise made a bad decision.

You started reinventing the wheel the moment you decided to invent your own language to solve problems that can already be effectively solved with other, more mature languages.

Title: Reinventing the wheel because it doesn't exist

Body:
One of the languages I have to use at work is a very small, niche language called psl. One of the largest complaints I have about it as a language is that the libraries are very limited.

While that's understandable for a small language developed by a couple of guys, it does cause me some dilemmas. Specifically, I find myself "rewriting" functions that are standard in other languages because they don't exist here.

This is especially problematic when I'm attempting to write a function to solve a problem, and management doesn't want to spend the time to do so. They want me to use hard coded magic numbers instead, which I know will need to change multiple times over the life of the code.

This doesn't quite fit the antipattern reinventing the wheel because it didn't exist here in the first place. What kind of anti pattern would this fit?


答:
In addition to Peter's answer, if that condition may need to be updated at some point in the future, by having it encapsulated the way you suggest you would only have a single edit point.

Following Peter's example, if this

boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isFemale()
        && (taxPayer.getNumberOfChildren() > 2
        || (taxPayer.getAge() > 50 && taxPayer.getEmployer().isNonProfit()));
}
```

<p>becomes this</p>

<pre class="lang-java prettyprint-override"><code>boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isMutant()
        && (taxPayer.getNumberOfThumbs() > 2
        || (taxPayer.getAge() > 123 && taxPayer.getEmployer().isXMan()));
}
</code>```

You make a single edit and it's updated universally.  Maintainability wise, this is a plus.

Performance wise, most optimizing compilers will remove the function call and inline the small code block anyway.  Optimizing something like this can actually shrink the block size (by deleting the instructions needed for the function call, return, etc) so it's normally safe to do even in conditions that might otherwise prevent inlining.

Body:
In addition to Peter's answer, if that condition may need to be updated at some point in the future, by having it encapsulated the way you suggest you would only have a single edit point.

Following Peter's example, if this

boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isFemale()
        && (taxPayer.getNumberOfChildren() > 2
        || (taxPayer.getAge() > 50 && taxPayer.getEmployer().isNonProfit()));
}

becomes this

boolean isTaxPayerEligibleForTaxRefund() {
  return taxPayer.isMutant()
        && (taxPayer.getNumberOfThumbs() > 2
        || (taxPayer.getAge() > 123 && taxPayer.getEmployer().isXMan()));
}

You make a single edit and it's updated universally.  Maintainability wise, this is a plus.

Performance wise, most optimizing compilers will remove the function call and inline the small code block anyway.  Optimizing something like this can actually shrink the block size (by deleting the instructions needed for the function call, return, etc) so it's normally safe to do even in conditions that might otherwise prevent inlining.


问:
Managing software projects - advice needed
I work for a large government department as part of an IT team that manages and develops websites as well as stand alone web applications.

We’re running in to problems somewhere in the SDLC that don’t rear their ugly head until time and budget are starting to run out.

We try to be “Agile” (software specifications are not as thorough as possible, clients have direct access to the developers any time they want) and we are also in a reasonably peculiar position in that we are not allowed to make profit from the services we provide. We only service the divisions within our government department, and can only charge for the time and effort we actually put in to a project. So if we deliver a project that we have over-quoted on, we will only invoice for the actual time spent.

Our software specifications are not as thorough as they could be, but they always include at a minimum:

Wireframe mockups for every form view

A data dictionary of all field inputs

Descriptions of any business rules that affect the system

Descriptions of the outputs

I’m new to software management, but I’ve overseen enough software projects now to know that as soon as users start observing demos of the system, they start making a huge amount of requests like “Can we add a few more fields to this report.. can we redesign the look of this interface.. can we send an email at this part of the workflow.. can we take this button off this view.. can we make this function redirect to a different screen.. can we change some text on this screen… can we create a special account where someone can log in and get access to X… this report takes too long to run can it be optimised.. can we remove this step in the workflow… there’s got to be a better image we can put here…” etc etc etc.

Some changes are tiny and can be implemented reasonably quickly.. but there could be up to 50-100 or so of such requests during the course of the SDLC. Other change requests are what clients claim they “just assumed would be part of the system” even if not explicitly spelled out in the spec.

We are having a lot of difficulty managing this process. With no experienced software project managers in our team, we need to come up with a better way to both internally identify whether work being requested is “out of spec”,  and be able to communicate this to a client in such a manner that they can understand why what they are asking for is “extra” work.

We need a way to track this work and be transparent with it.

In the spirit of Agile development where we are not spec'ing software systems in to the ground and back again before development begins, and bearing in mind that clients have access to any developer any time they want it, I am looking for some tips and pointers from experienced software project managers on how to handle this sort of "scope creep" problem, in tracking it, being transparent with it, and communicating it to clients such that they understand it.

Happy to clarify anything as needed.

I really appreciate anyone who takes the time to offer some advice.

Thanks.

答:
It seems to me there are 2 separate issues.

The feature implemented isn't actually how they wanted it to be.

Seeing the feature they now want additional work done.

I would suggest the following:

Make the priority list of what is being worked public

Management (your or your manager) should be how work get's prioritized.  Work that is not prioritized does not get development time.  Let your customer communicate with you about their work and when it will be started.  I've found customers usually just want to make sure they haven't been forgotten.

Implement sign-off on a feature-by-feature basis

We work in vertical slices at work.  What this means is that when a feature is done it can be demoed in a working system.  I have the developers communicate before and after starting feature work with the customer.  This assures the developer has a good idea of what the customer wants, the customer can make small changes that didn't occur to them before, or didn't capture in the requirements.  After the feature is implemented the developer gets sign-off so the customer gets what they want.  The developers have to know how to defer the requests for additional work that doesn't belong within the scope of the feature to the appropriate manager.

Always do mockups first

Always do the mockups first and treat that as it's own feature.  Then get the customer to evaluate the mockups and sign off on them.

Follow up

Follow up as projects (or project phases) are completed.  Talked to the customers to make sure they are happy with what they got.  Ask them how they liked the process used during the project.  Did they get what they want, do they have any suggestions, etc.

I have found these techniques work for me pretty well.


答:
I think that in many cases such a function is good style, but you may consider a local boolean variable as alternative in cases when you don't need to use this condition somewhere in other places e.g.:

bool someConditionSatisfied = [complex expression];
```

This will give a hint to code reader and save from introducing a new function.

Body:
I think that in many cases such a function is good style, but you may consider a local boolean variable as alternative in cases when you don't need to use this condition somewhere in other places e.g.:

bool someConditionSatisfied = [complex expression];

This will give a hint to code reader and save from introducing a new function.


答:
I propose that Swarm Intelligence is both Artificial Intelligence and a subfield of Artificial Intelligence.

Swarm Intelligence as a subfield implies (through action) that intelligent systems can cluster and work alone as clusters, solving problems, where each subsystem within each cluster depends on peer systems to solve an ultimate problem.

Artificial Intelligence, if you follow the concept Minsky described the human brain by in "Society of Mind," is a bunch of swarms and/or problem-solving systems coming together to solve 'big' problems.  The subsystems in each swarm solve small problems (which may be analyzing obstructions and figuring out if help is needed); the swarm solves the problems each subsystem encountered via analyses.

I think the difference between Swarm Intelligence and Artificial Intelligence exists relative to the complexity of the system being gauged for intelligence.  For example:  Take one bee (the insect) and show it a meadow full of flowers.  The bee can look at the set of flowers and realize that it doesn't have the capacity to carry all the nectar from the meadow back to its hive.  That realization, in itself, can be looked at as intelligence ('artificial' if the bee was man-made).  When the bee goes back to its hive and asks other bees to help it with the acquisition of the nectar, the other bees will agree.  Once they all reach the meadow and disperse evenly among the flowers, if they all share the same problem and are working for the same cause--which may be to make a cup of honey--each bee is part of one large intelligence.  So the swarm of bees was an intelligence on its own.

That's what I assume, but correct me if I'm wrong in my assumption.