问:
Estimate of each localization's prospects on Mac App Store
I write utility programs (converters, compression tools, etc.) with simple UI’s, which I put for sale of for free download on the Mac App Store.

I write these programs in English, and usually add a French localization (which I do myself). By comparing the distribution of sales per country between a localized app and nonlocalized one, I can estimate how much the French localization boosts my sales. (The apps themselves are pretty generic and not country-specific, which makes the comparison possible.) For example, on nonlocalized app A, my sales in France are 2.5% of all sales, while on localized app B, sales in France amount to 10%. This means localization increased my overall revenue by 8.4%.[1]

My question is: does someone have an estimate of how much localization is worth for each language? (according to this metric, i.e. potential added revenue) This would be a great help to prioritize new localizations (which I cannot do myself).

[1] And not, that's not 8.5%.

答:
There is a similiar question here.

If your applications are small utility apps as you mention, with a simple UI, then they sound to me to be an ideal candidate for machine translation, even using Google Translate or Microsoft Translator - both provide API's to access these services, although Google will discontinue this at the end of 2011.

You have the distinct advantage in that you have complete control over your application, including the English strings. Investigate using Controlled English - this will improve the quality of your machine translated applications.

For the applications you release where you have used MT, you may want to add a disclaimer, or even allow native speakers to suggest better translations for what they deem to be bad translations. Lots have companies have used this as a successful model.

The advantage of this is that your localization costs will be zero. As long as the translations are of a good enough standard, the quality of your applications will not be affected.

Try this out on a subset of languages, or even one, and get the translation quality reviewed by some native speakers you know, or on some translation crowdsourcing website. This should give you a good idea of wheather or not this approach will work for you.


问:
How to most effectively debug code?
Bugs creeping into code can be minimized, but not entirely eliminated as it is written - programmers are, although many would disagree, only humans.

When we do detect an error in our code, what can we do to weed it out? How should we approach it to make most effective use of our valuable time and enable us to spend less time trying to find it and more time coding? Also, what should we avoid when debugging?

Note here that we're not talking about preventing bugs; we're talking about what to do when bugs do appear. This is a wide field, I know, and may be highly dependent on language, platform and tools. If so, keep to encompassing answers such as mindsets and general methods.

答: I think the reproduction of a bug is also important. All cases which reproduce the bug can be listed and then you can make sure that your bug fix covers all those cases.</p>

ContentLicense: CC BY-SA 2.5

Title: How to most effectively debug code?


问:
What is a good workflow for a C++ beginner?
I desire to become a more serious scientific C++ programmer.  To do so, I need  a consistent style of workflow (e.g., coding, test-driven development, etc.).  My question is simply what sort of workflow should I consider?  I am familiar with Linux and Mac, and prefer to use free tools like cppcheck, valgrind, g++, etc.  I prefer to use Qt and Boost within my programming toolbox, and I am considering using mock objects (either Google Mock or MockPP) within the TDD.  I typically use vim for my editor.

In essence, should I do something like the following:

TDD -> code -> cppcheck -> valgrind -> debug -> repeat until ready to
  use profilers and coverage mechanisms

or, should I pursue some other way?  I realize that the opinions will vary, and I also understand that I must first take the time to think through the process and document my thoughts whether written or UML before coding, and I also know that I should document the code as I step write the code.

Any and all thoughts will be appreciated.

答:
First read C++ annotations. It's free and online.

Honestly I don't think you're best off starting with TDD. TDD is really cool once you realize its true value. And to do that, I believe you've got to have your share of agonizing debugging.

So first you might want to just implement some random programs in C++. Just make-up games and such, or find some people who want things done (and maybe get some money out of it). Take your implementation seriously.

Then, once you think you're really good at programming (at this point, programming for you will probably stand for "making super complex things ultimately - and magically - work), read some books about Testing. Watch some GoogleTechTalks about testing.

Good authors you should remember: Robert C. Martin, Michael Feathers, Martin Fowler, Kent Beck.
Then search for some videos about clean, testable code by Misko Hevery from Google.

OwnerDisplayName: Tim

ContentLicense: CC BY-SA 3.0


问:
When should I be offloading work to a GPU instead of the CPU?
Newer systems such as OpenCL are being made so that we can run more and more code on our graphics processors, which makes sense, because we should be able to utilise as much of the power in our systems as possible.

However, with all of these new systems, it seems as if GPUs are better than CPUs in every way.  Because GPUs can do parallel calculation, multi-core GPUs actually seem like they'd be much better than multi-core CPUs; you'd be able to do many calculations at once and really improve speed.  Are there still certain cases where serial processing is still better, faster, and/or more efficient than parallel?

答:
The simple rule is, if what you are doing can be phrased in terms of constructs from linear algebra and is time critical, do it on the GPU otherwise use the CPU.

GPUs aren't like large numbers of CPUs, they have wildly different performance characteristics.


问:
Should "tags" be an nvarchar field in a table, or should it be another table altogether?
I am building a photography website and I want to allow the user to put tags on their photos for easy searching. But I'm not sure if I want the tags to be an nvarchar field in each picture and then search for that tag in each record or if I want to pull them out and create a separate table of tags and tagIds and then have a look up table, so I can just search the database for that ID.
So, what I'm asking is which would be better efficiency-wise and scalability-wise. The database will have over 3-4000 pictures.</p>

答:
This depends on how much control you want over your tags. Some sights are not sure how tags are going to be created and used, so they just keep it open. Your single field approach would handle this as would just haveing a single tags table joined to your image table.

A three table/Many-to-many approach is going to allow you to have more control over the tags table. If you need to reword tags, this is very easy. What you gain in control over these values, you'll lose in performance. The needs for your application should consider how much flexibility you want to give users.


答:
GPUs aren't generalist processors the way CPUs are.  They specialize in doing one very specific thing--applying the same code to a large amount of data--and they do it very, very well, much better than a CPU does.  But the majority of most applications is not about applying the same code to a large amount of data; it's about an event loop: waiting for input, reading the input, acting on it, and then waiting for more input.  That's a pretty serial process, and GPUs suck at "serial."

When you have a large amount of data that you need to process, and each item can be processed in parallel, independently of the others, then go ahead and send it to the GPU.  But don't think of this as "the new paradigm" that everything has to be squeezed into.

This question is tagged "optimization," so remember to treat it as one.  Apply GPU optimization where testing and profiling reveal that optimization is needed and the nature of the task is such that GPU optimization can be applied.  Otherwise, don't bother with it, as that would be premature or incorrect optimization, which causes more problems than it fixes.

Title: When should I be offloading work to a GPU instead of the CPU?

Body:
Newer systems such as OpenCL are being made so that we can run more and more code on our graphics processors, which makes sense, because we should be able to utilise as much of the power in our systems as possible.

However, with all of these new systems, it seems as if GPUs are better than CPUs in every way.  Because GPUs can do parallel calculation, multi-core GPUs actually seem like they'd be much better than multi-core CPUs; you'd be able to do many calculations at once and really improve speed.  Are there still certain cases where serial processing is still better, faster, and/or more efficient than parallel?


答:
However, with all of these new systems, it seems as if GPUs are better
  than CPUs in every way.

This is a fundamental mis-understanding. Present GPU cores are still limited compared to current top-line CPUs. I think NVIDIA's Fermi architecture is the most powerful GPU currently available. It has only 32-bit registers for integer arithmetic, and less capability for branch prediction and speculative execution then a current commodity Intel processor. Intel i7 chips provide three levels of caching, Fermi cores only have two, and each cache on the Fermi is smaller than the corresponding cache on the i7. Interprocess communication between the GPU cores is fairly limited, and your calculations have to be stuctured to accommodate that limitation (the cores are ganged into blocks, and communication between cores in a block is relatively fast, but communication between blocks is slow).

A significant limitation of current GPUs is that the cores all have to be running the same code. Unlike the cores in your CPU, you can't tell one GPU core to run your email client, and another core to run your web server. You give the GPU the function to invert a matrix, and all the cores run that function on different bits of data.

The processors on the GPU live in an isolated world. They can control the display, but they have no access to the disk, the network, or the keyboard.

Access to the GPU system has substantial overhead costs. The GPU has its own memory, so your calculations will be limited to the amount of memory on the GPU card. Transferring data between the GPU memory and main memory is relatively expensive. Pragmatically this means that there is no benefit in handing a handful of short calculations from the CPU to the GPU, because the setup and teardown costs will swamp the time required to do the calculation.

The bottom line is that GPUs are useful when you have many (as in hundreds or thousands) of copies of a long calculation that can be calculated in parallel. Typical tasks for which this is common are scientific computing, video encoding, and image rendering. For an application like a text editor the only function where a GPU might be useful is in rendering the type on the screen.


问:
What programming problems are best solved by using pointers?
Well, I basically understand how to use pointers, but not how best to use them in order to do better programming.

What are good projects or problems to resolve involving the use of pointers so I can understand them better?

答:
Write any non-trivial project in C and you WILL have to figure how/when to use pointers. In C++ you will mostly use RAII-enabled objects which manage pointers internally, but in C raw pointers have a much more prevalent role. As for what kind of project you should do, it can be anything non-trivial:

A tiny and simple web server

Unix command line tools (less, cat, sort etc.)

Some actual project you want to do for its own sake and not just for learning

I recommend the last one.


答:
Manipulating large amounts of data in memory is where pointers really shine.

Passing a large object by reference is equivalent to just passing along a plain old number. You can manipulate the needed parts directly as opposed to copying an object, altering it, then passing back the copy to be put in place of the original.

Title: What programming problems are best solved by using pointers?

Body:
Well, I basically understand how to use pointers, but not how best to use them in order to do better programming.

What are good projects or problems to resolve involving the use of pointers so I can understand them better?


答: Pixel level image manipulation is almost always easier and faster using pointers. Sometimes it is only possible using pointers.</p>


答:
One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers.

```<code>for(int i = 0; i < size; i++)
   std::cout << array[i];
</code>```

is the equivalent of

```<code>for(int i = 0; i < size; i++)
   std::cout << *(array + i);
</code>```

This knowledge allows you to do really cool things like copy an entire array in one line:

```<code>while( (*array1++ = *array2++) != '\0')
</code>```

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

Find some projects that play around with traditional c-strings and arrays.

Find some projects that use inheritance.

Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

Body:
One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers.

for(int i = 0; i < size; i++)
   std::cout << array[i];

is the equivalent of

for(int i = 0; i < size; i++)
   std::cout << *(array + i);

This knowledge allows you to do really cool things like copy an entire array in one line:

while( (*array1++ = *array2++) != '\0')

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

Find some projects that play around with traditional c-strings and arrays.

Find some projects that use inheritance.

Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.


答:
The pointer concept allows you to refer to data by address without duplicating the storage of data. This approach allows for writing efficient algorithms such as:

Sorting

When moving data in a sort algorithm you may move the pointer instead of the data itself—think of sorting millions of rows on a string of 100 chars; you save a lot of unnecessary data movements.

Linked lists

You can store the next and/or previous item location and not the entire data associated with the record.

Passing parameters

In this case, you pass the address of the data instead of the data itself. Again, think of a name compression algorithm that runs on millions of rows.

The concept can be extended to data structures such as relational databases where a pointer is akin to a foreign key. Some language don't encourage the use of pointers such as C# and COBOL.

Examples can be found in many places such as:

Why use pointers?

Why C has Pointers

The C Book's chapter on pointers

IBM's example program using pointers

The following post may be relevant in some way:

Do the young minds need to learn the pointer concepts?


答:
I'm surprised no other answer has mentioned this: pointers allow you to create non-contiguous and non-linear data structures, wherein an element may be related to multiple others in complex ways.

Linked lists (singly, doubly, and circularly linked), trees (red-black, AVL, trie, binary, space partitioning…), and graphs are all examples of structures that can be constructed most naturally in terms of references rather than just values.


问:
How to remove duplicate code (in general)?
In an OO language (e.g. but not limited to Java) how do you fix duplicate code depending on the scope of it's occurrence? I would start with (for example)

in the same class (scope) perform the Extract Method refactoring (fix)

in classes of the same hierarchy (scope) perform Extract Method and Pull Up (fix)

...

答:
In general - consolidate duplicate code into a single place and ensure original duplication site is calling the consolidated place.

In your examples, within a class this would be the extracted method and within a set of classes the pulled-up method within the base class.

In copy-paste code, this would be to remove the duplicates and ensuring that any users now use the single copy (in whatever level this is).

When dealing with different versions of libraries, consolidate on a single version (if possible).


问:
Are there any academic papers on the merits of imperative over functional programming?
There are lots of academic papers on the merits of functional programming floating around. There's also a lot of debate that I see (on the internet) going on about the relative merits of imperative vs. functional programming.

I'm interested to know if that debate extends in academia with actual published papers (the more recent the better I think) discussing the advantages of imperative programming over functional programming.

答:
Here is one: Imperative versus functional

It is from 1990 however, but by following citations you could find more recent ones.

This one only discusses some very basic benchmarking results, and is only cited once, so my previous advice won't get you far. :)

The problem is in order to do a proper comparison you first need to find actual things to compare. Benchmarks of similar applications would seem like a proper comparison, but this only compares languages and not the different paradigms per se. Even if you find a paper which finds a measurable aspect which could indicate that one paradigm trumps the other, this means the paradigm is only more suitable in that specific situation.

That's the same conclusion most people will give you here. One paradigm can be more suitable than the other based on the specific situation.


答:
To truly understand why pointers are important you need to understand the difference between heap allocation and stack allocation.

The following is an example of a stack allocation:

```<code>struct Foo {
  int bar, baz
};

void foo(void) {
  struct Foo f;
}
</code>```

Objects allocated on the stack only exist for the duration of the current function execution. When the call to foo goes out of scope so does the variable f.

One case where this becomes an issue is when you need to return something other than an integral type from a function (for example the Foo structure from the example above).

For example, the following function would result in so-called "undefined behavior."

```<code>struct Foo {
  int bar, baz
};

struct Foo *foo(void) {
  struct Foo f;
  return &f;
}
</code>```

If you want to return something like struct Foo * from a function what you really need is a heap allocation:

```<code>struct Foo {
  int bar, baz
};

struct Foo *foo(void) {
  return malloc(sizeof(struct Foo));
}
</code>```

The function malloc allocates an object on the heap and returns a pointer to that object. Note that the term "object" is used loosely here, meaning "something" rather than object in the sense of object-oriented programming.

The lifetime of heap-allocated objects is controlled by the programmer. The memory for this object will be reserved until the programmer frees it, i.e. by calling free() or until the program exits.

Edit: I failed to notice this question is tagged as a C++ question. The C++ operators new and new[] perform the same function as malloc. The operators delete and delete[] are analogous to free. While new and delete should be used exclusively to allocate and free C++ objects, the use of malloc and free is perfectly legal in C++ code.

Body:
To truly understand why pointers are important you need to understand the difference between heap allocation and stack allocation.

The following is an example of a stack allocation:

struct Foo {
  int bar, baz
};

void foo(void) {
  struct Foo f;
}

Objects allocated on the stack only exist for the duration of the current function execution. When the call to foo goes out of scope so does the variable f.

One case where this becomes an issue is when you need to return something other than an integral type from a function (for example the Foo structure from the example above).

For example, the following function would result in so-called "undefined behavior."

struct Foo {
  int bar, baz
};

struct Foo *foo(void) {
  struct Foo f;
  return &f;
}

If you want to return something like struct Foo * from a function what you really need is a heap allocation:

struct Foo {
  int bar, baz
};

struct Foo *foo(void) {
  return malloc(sizeof(struct Foo));
}

The function malloc allocates an object on the heap and returns a pointer to that object. Note that the term "object" is used loosely here, meaning "something" rather than object in the sense of object-oriented programming.

The lifetime of heap-allocated objects is controlled by the programmer. The memory for this object will be reserved until the programmer frees it, i.e. by calling free() or until the program exits.

Edit: I failed to notice this question is tagged as a C++ question. The C++ operators new and new[] perform the same function as malloc. The operators delete and delete[] are analogous to free. While new and delete should be used exclusively to allocate and free C++ objects, the use of malloc and free is perfectly legal in C++ code.


问:
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.

答:
<Sarcasm>

```<code>if(string.Contains("<Sarcasm>")) containsSarcasm = true;
</code>```

</Sarcasm>

Honestly, I have no idea how to go about this.  I think only about 30% of people in real life "get" sarcasm in the first place, so making a computer recognize it and understand it sounds like a very difficult task.

Edit  Based on the comments to my original post, I believe that I have perfectly illustrated the extreme difficulty of the task that is being asked.  Yes, the first half of my post was sarcastic.  I even emphasized that fact by using a made-up markup tag.  By posting a sarcastic comment about a trivial solution to an exceptionally difficult problem, and that sarcasm being interpreted as "unhelpful" brings up this question:

If you can't recognize written sarcasm, then how are you going to write an algorithm that recognizes it?

Oh, and Anna if someone includes the term "I think..." in their sentence, it usually indicates that it is an opinion that is being stated, not necessarily researched hard fact.

Body:
<Sarcasm>

if(string.Contains("<Sarcasm>")) containsSarcasm = true;

</Sarcasm>

Honestly, I have no idea how to go about this.  I think only about 30% of people in real life "get" sarcasm in the first place, so making a computer recognize it and understand it sounds like a very difficult task.

Edit  Based on the comments to my original post, I believe that I have perfectly illustrated the extreme difficulty of the task that is being asked.  Yes, the first half of my post was sarcastic.  I even emphasized that fact by using a made-up markup tag.  By posting a sarcastic comment about a trivial solution to an exceptionally difficult problem, and that sarcasm being interpreted as "unhelpful" brings up this question:

If you can't recognize written sarcasm, then how are you going to write an algorithm that recognizes it?

Oh, and Anna if someone includes the term "I think..." in their sentence, it usually indicates that it is an opinion that is being stated, not necessarily researched hard fact.


问:
Ideal programming language learning sequence?
What do you think? What is the ideal programming language learning sequence which will cover most of the heavily used languages and paradigms today as well as help to grasp common programming basics, ideas and practices?
You can even suggest learning sequence for paradigms rather than languages.

N.B. : This is port of the question I asked in stackoverflow and was closed for being subjective and argumentative.

答:
Python, Lisp, C, Haskell

Assuming the question was about an ideal learning sequence for newcomers to programming (since old hands at programming will have had their own (likely accidental) learning sequence), I'd suggest reading Norvig's essay on how to learn programming in 10 years, then:

Python: Start with a dynamic, high-level, OO & functional language.  Because it's really important for beginners to feel productive ASAP, and not be turned off by alien syntax, lack of libraries, lack of multi-platform, lack of learning resources, and lack of community.  Python is highly readable, has tons of good libraries (esp. scientific libraries - a modern scientist/engineer must know how to program), is easily run from most OSes, has tons of tutorials and entire free books, and is generally user-friendly — all while still being powerful enough to grow with you as you become an advanced programmer working on large problems.  It's also important to reinforce important+useful conventions for a beginner: code readability counts a LOT, and you should be writing code for yourself and others to readily understand.

Lisp: In particular, at least skim The Structure and Interpretation of Computer Programs or watch the SICP videos, and have one's eyes opened very wide by seeing the foundations and expressive power of programming - one can do so much with so little.  Learn how Lisp can express not just the functional paradigm, but OO, logical/declarative, and more - like the creation of new domain-specific languages.  Read Norvig's PAIP to witness what a master can do with the language.  Then check out Clojure, a modern Lisp dialect that could be one of the Next Big Things.

C: Only because it's the lingua-franca of computing. :)  Possibly optional these days if one is primarily a programmer in a particular non-software domain.  I find it ugly but worth knowing about to get an appreciation for the underlying hardware.  Go with K&R, of course.

Haskell: Pure functional power.  Where current Com.Sci. theory and practical expressive power meet.  See Real World Haskell.

After the above tour, one would be very adept at tackling problems and expressing solutions in code, and be totally comfortable with the paradigms here:


问:
How Do I calculate the the "Human Resources/Effort" for a programming project?
as a project manager or CTO how would I calculate the "time" it takes to develop a software system? For Example I would be responsible for developing a large web application in Java, MySQL, HTML, JSF. How do I correctly calculate how much time this takes?

Prerequisites:
I do not know the team that will do this job (so I can not ask them how long they might need). I did not do any calculations like this before. I am completely new in this role. But I have some very basic/slight programming background...

Also any good resources (=links) or answers are very much appreciated.

答:
You can't. We can't either. We can give you a rough guess, but that's all it will ever be - and it requires quite a bit of expertise to give you that, too.

You should first find a developer, then ask them fro a price estimate, then consider whether or not this price is good for you. If the project is big it might take a few days to do the estimate - in which case the developer may charge you for estimating the price.


问:
Which software methodology works when you are in learning phase of a technology?
In my scenario, we have a team of experienced developers with 3+ years and they are not co-located. We are in a learning phase in terms of the domain and technology. I want some recommendations in regards to what software methodology we should adapt.

I have thought of implementing waterfall, since we have to design upfront and we know all the design issues and technical challenges. Using agile on teams that are not co-located, we aren't sure how to estimate on per week bases when dont have a complete grasp on the technology.

答: Personally I'm a big fan of SCRUM. It allows for constant evaluation especially with new technologies. Every few weeks you'll have a sprint, and it'll allow for reevaluation.  I've used this in college development teams, and in real life. It's very effective, and adaptive. Do some research, I think this is your best option.</p>

OwnerDisplayName: Huzaifa

OwnerDisplayName: AmitApollo


答: Do a pilot project first. Implement a whole, but small, project as a pilot study. Implementing the pilot system, your team can experience all phases of a project development and learn how to deal with the problems that eventually will arise from the lack of expertise in the used technology. Furthermore, you can use the metrics from this pilot project to have better estimate for your main project planning. </p>

Title: Which software methodology works when you are in learning phase of a technology?

Body:
In my scenario, we have a team of experienced developers with 3+ years and they are not co-located. We are in a learning phase in terms of the domain and technology. I want some recommendations in regards to what software methodology we should adapt.

I have thought of implementing waterfall, since we have to design upfront and we know all the design issues and technical challenges. Using agile on teams that are not co-located, we aren't sure how to estimate on per week bases when dont have a complete grasp on the technology.

OwnerDisplayName: darlinton


答:
There are two general approaches, but most require a lot more information than you have right now. Without knowing more about the project and team, neither method can apply. Once you know more, you can either apply parametric estimation models, such as COCOMO II, size estimation methods such as function point analysis, proxy-based estimation, or team-based estimation techniques such as the Planning Game or wideband delphi.

Typically, before you begin estimating, you need at least a rough idea of the scope of the software project. This is usually done by starting to capture requirements in the form of a Software Requirements Specification, user stories, or some other technique. Establishing an overarching vision and scope for the project would also help as well.

Once you've established sufficient information about the project, you can begin the estimation process, depending on the methods that you choose. It might be advisable to even use multiple estimation methods. For example, using wideband delphi as a check for the output of COCOMO.

If you want to know more about software estimation, I would highly suggest reading Software Estimation: Demystifying the Black Art by Steve McConnell. He talks about many estimation topics and techniques and explains a number of best practices regardless of the size of the project. Also, for general project management topics, I would also suggest McConnell's Rapid Development: Taming Wild Software Schedules, where he talks about topics such as staffing, process management, and silver bullets.

Title: How Do I calculate the the "Human Resources/Effort" for a programming project?

Body:
as a project manager or CTO how would I calculate the "time" it takes to develop a software system? For Example I would be responsible for developing a large web application in Java, MySQL, HTML, JSF. How do I correctly calculate how much time this takes?

Prerequisites:
I do not know the team that will do this job (so I can not ask them how long they might need). I did not do any calculations like this before. I am completely new in this role. But I have some very basic/slight programming background...

Also any good resources (=links) or answers are very much appreciated.


答:
If you had a full natural language processing system and a database of facts ala the IBM Watson system, you might be able flag some statements as possible sarcasm. For example, "I hear your mother has cancer and you just got fired!" "Yeah, isn't life wonderful!" could be flagged because it could recognize that getting cancer and loosing a job are not generally described as positive experiences.

I assume you don't have the resources to put together a Watson grade system. You could put together a database of commonly used sarcastic phrases, and then use some sort of text matching algorithm between the target statement and the sarcasm database. I have to guess that it won't be very effective because all the phrases that are used sarcastically are used sincerely more frequently. For example "That's a nice X." is usually used sincerely, but is sometimes used sarcastically.

Sarcasm is very closely related to deception. It's not uncommon for a person using sarcasm to deny it when challenged on it, and their choice of words makes denial possible. I suspect this means that a good sarcasm detector is probably about as hard a problem as a conversational program that passes the Turing test.

Title: How to teach a script to detect sarcasm?

Body:
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.


答:
Estimation is complex for seasoned professionals. Especially that the project is big.
I suggest you finish the essential requirements phase and by then, sit with your senior programmer to identify the tasks and ask him for his input into this using some of what Thomas Owens suggested above.

You need to be aware that the estimate may have to be revised as the project progresses and as new team members start producing deliverables.

There are many variables that could go into a software project such as: People skills, number of people, development methodology, delivery methodology, customer cooperation, training time, utility software problems, back-end system interfaces, requirements stability, team communication, etc.

A warning note, the risk in your case is high.


问:
Patterns for ajax-heavy web applications
Up until now, I've been a great fan of the MVC pattern for developing web applications. For the web, I've developed mostly in PHP (with the Kohana and CodeIgniter frameworks) and Ruby (RoR).

As my applications become heavier on the Ajax side (single-page apps etc) I noticed that I can't help but betray the very basic concepts of MVC: Javascript is doing most of the works; calling controllers just to ask for views or more js/json code seems wrong.

After striving for keeping all the routing jobs in the controllers, now I've fundamentally split it between them and Javascript (that is, from the framework's PoV, part of the views). When asking for json the MVC subversion looks even more obvious: the js code doing the request is the controller; the framework's controller is merely acting as proxy for the model's data - what I'm actually asking for.

So, what should I look into?

I was thinking about pure-javascript applications, for instance with backbone.js and a document-based, json-spitting database (couchDB) as backend, but I love my relational databases.

Another option would be the following: I'd just make "routed models" in PHP/ruby/go/whatnot. Those will analyse the request, call the db, give back some json.

This approach looks interesting to me but it lacks any substantial documentation or academic analysis, so I'm a little afraid of the leap.

Ideas?

答:
If there isn't any academic analysis, do it yourself. Just experiment on your next small scale project, and see how you like it. Read Paul Graham's essay on why he choose Lisp for his startup, even though it wasn't commonly used. http://www.paulgraham.com/avg.html

There are plenty of MVC javascript frameworks out there. If you want to build a primarily javascript application, then do it.

Just build a restful API in rails or whatever framework you use that is just a wrapper for the database, and you won't have to give up you're relational database. Just call the api like you would call the database if this were a server based logic application.

Additionally, if you build your app this way, you can build in offline support very easily.


答:
Almost all programming problems that can be solved with pointers can be solved with other safer types of references (not referring to C++ references, but the general CS concept of having a variable refer to the value of data stored elsewhere).

Pointers by being a specific low-level implementation of references, where you can directly manipulate memory addresses are very powerful, but can be slightly dangerous to use (e.g., point to memory locations outside the program).

The benefit of using pointers directly is that they'll be slightly faster by not having to do any safety checks.  Languages like Java that don't directly implement C-style pointers will suffer a slight performance hit, but will reduce many types of difficult to debug situations.

As for why you need indirection, the list is fairly long, but essentially the two key idea are:

Copying values of big objects is slow and will make the object be stored in RAM twice (potentially very costly), but copying by reference is near instantaneous using only a few bytes of RAM (for the address).  E.g., say you have ~1000 big objects (each being about say 1MB of RAM) in memory, and your user needs to be able to select the current object (which will be acted upon by the user).  Having a variable selected_object that is a reference to one of the objects is much more efficient than copying the value of the current object into a new variable.

Having complicated data structures that refer to other objects like linked lists or trees, where each item in the data structure refers to other items in the data structure.  The benefit of referring to other items in the data structure means that you don't have to move every item in the list around in memory just because you inserted a new item to the middle of the list (can have constant time inserts).


答:
Pointers are used in so many programming languages below the surface without bugging the user about it. C/C++ just gives you access to them.

When to use them: As often as possible, because copying data is inefficient.
When to not use them:  When you want two copies that can be changed individually.  (What basically will end up copying the content of object_1 to another place in memory and returning a pointer - this time pointing to object_2)


答: If you need raw number-crunching, GPUs are the way to go. However, all those ALUs mean that there are less transistors dedicated to control flow (branching) circuitry. So, if you need to write something that needs a lot of complex control flow, lots of conditionals, etc., then a CPU will be faster.</p>


答:
In Rapid Development: Taming Wild Software Schedules, Steve McConnell provides a table that compares a number of life cycle methodologies based on several factors and rates them between Poor and Excellent. This chart can be found in Chapter 7, on pages 156-157, if you have a copy of the book.

If your project is characterized by poorly understood requirements and a poorly understood architecture, then the spiral model is favored. However, the spiral model is designed to detect and allow for negation of risks early. This requires training and discipline in tracking progress and the current state of the project so that decisions can be made in a timely manner.


答:
The trouble is, you're asking a question that doesn't have a well defined answer.  It's a function of the team, the technology choices (which you need to allow the team to make, don't specify them up front), and, most important of all, how often your business requirements change.

I think first of all you need to find yourself a lead developer and/or scrum master (or some other agile development expert), and get them to start the estimation process off.  That will get you an idea of how long it will be (and therefore how much it will cost) to get to something minimally useful.  From there you just prioritize features regularly, and they arrive within a fairly short time... but first you need that initial start.

Oh, and the estimate will depend on certain assumptions.  Do not change those assumptions without getting the estimate re-done, as that can make a really large difference.


问:
Which development methodology for a solo programmer on a 1 month project?
I've been tasked with a solo project to investigate & resolve memory leaks in 8000 lines of Javascript code.

I anticipate the project to take up to a month.

Please recommend a development methodology I can use to structure my efforts.

Prefer something light & easy to pickup and run with.

Thanks

答:
Best idea on a legacy code base like that is to "Divide and Conquer", by dividing the problem into smaller functional units, especially if it's not already structured well. This may involve some refactoring so that the code is more manageable, so look for seams where you might break it into smaller functions.

Some of this is covered in the excellent book Working Effectively with Legacy Code.

Another point is that if there aren't already any tests is to put in some unit tests to prevent from breaking things when refactoring so be sure to look for ways to test the code. There is a framework for unit tests called QUnit that can help with testing Javascript.


答: Sarcasm detection in computational linguistics (aka natural language processing) is an extremely difficult problem in its own right. It is basically a classification problem where a model must be trained first. A similar problem for finding double-entendres (PDF file) was recently researched and published. The techniques for both problems are comparable. </p>


问:
Is it common to separate back-end and front-end into two positions on web development projects?
At a web startup, is it more common to have an engineer working the front-end AND back-end of the feature (basically in charge of the whole feature)? Or have engineers separated between the back-end and front-end?

Which ones are more beneficial and for what situations?

The downside, I've noticed, regarding having one engineer in charge of the whole feature is that the person might only be particularly strong in either frontend or backend development but not both, thus sometimes having a decrease in speed and quality.

Having frontend and backend developers on one feature increase the speed of the feature and the quality AND it encourages collaboration. But I am concerned about having 2 engineers working on one feature which may be a poor use of resources since the 1 engineer can be placed on another feature to work on.

What is the common/best practice for allocation backend/frontend engineering resources at a small early-stage startup? And then how will it change as it grows?

答:
I think the successful implementation could be a few things.  If there is a sole developer that has a strong backend but also has a decent grasp on the user interface and all "front-end" pieces, then it could probably be successful.  That's not typically the case, though (in my personal experience).  For instance, I consider myself a back-end developer.  But I work on a lot of projects by myself.  Do I work on the presentation and the client-side pieces?  Sure.  Do they look as good as an actual talented designer and client-side developer would make?  Absolutely not.

It's all give and take.  But don't let the collaberation of two developers make you hesitate.  There are tried and true ways to maximize production between a developer and a designer.

In other words...It depends


答:
Typically, a development methodology is designed to manage a software project over its life cycle, from inception to end-of-life. What you have been assigned to do sounds more like a task rather than a software development project. It's a large task that needs to be broken down, but it's nothing that needs a formal development methodology. Instead, you should be working within the process defined for use in the project that this task is related to.

I would start with just a very simple, methodical series of steps:

Learn the system. Ask for requirements specifications, design documents, and any other relevant documents associated with this code base. Review them, along with the code. If anything is out-of-date, I would inquire about updating the documentation, since it would be of use to future developers.

Read the code and associated tests. Once you've read the documents, read the code. Note discrepancies between the documents and the code. If anything is incorrect, file defects as appropriate. Restrain yourself here - don't jump in and start fixing things without following the project-level process. If there are no tests or test cases are missing, this is a good time to create them, especially if your work will involve refactoring.

Execute the test cases. If any tests fail, file defect reports as appropriate.

Instrument and profile the code. I'm not familiar with JavaScript development tools, but try to profiling the executing code and find out where the memory leaks are and if certain conditions trigger them. It might also be good to just create a general performance profile of the code base to determine where the least efficient code is. Even if you aren't tasked with fixing it, you have the tools you need to find it, so document them to save time for future developers.

Prioritize the defects. This includes the memory leaks. Hopefully, you have more information about them by "there's a memory leak" at this point, so there should be a number of defects related to these problems. If there are any defects in the modules with memory leaks, fix those first. You want to make performance enhancements to code that otherwise passes tests.

Begin fixing the defects, starting with those with the highest priority. Be sure to run your tests (automated and manual) to ensure that the system hasn't become unstable.

Ask questions. Never take anything for granted. If you have access to the previous developers, take advantage of them when they have the time. Otherwise, consult documentation and Stack Overflow as appropriate. Make sure that you have a good understanding of how the system is behaving, why it is behaving that way, and convey that information to future developers through various forms of documentation.

Throughout this task, be sure that you use version control to keep track of changes. Good versioning and commit logs will help you keep track of what changes you have made and when you made them. Tracking time and tasks completed will help you improve your estimates as well as keep the managers or supervisors in-the-loop as to the current status of the project.

Title: Which development methodology for a solo programmer on a 1 month project?

Body:
I've been tasked with a solo project to investigate & resolve memory leaks in 8000 lines of Javascript code.

I anticipate the project to take up to a month.

Please recommend a development methodology I can use to structure my efforts.

Prefer something light & easy to pickup and run with.

Thanks


问:
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.

答: If you want to teach C++, I would start directly with C++ constructs as vector and cout, instead of the C subset like printf.</p>

OwnerDisplayName: recipriversexclusion

OwnerDisplayName: K-ballo


答:
The mindset and attitude to debugging is perhaps the most important part, because it determines how effectively you'll fix the error, and what you'll learn from it — if anything.

Classics on software development like The Pragmatic Programmer and Code Complete basically argue for the same approach: every error is an opportunity to learn, almost always about yourself (because only beginners blame the compiler/computer first).

So treat it as a mystery which will be interesting to crack.  And cracking that mystery should be done systematically, by expressing our assumptions (to ourselves, or to others) and then testing our assumptions, one-by-one if need be — using every tool at our disposal, especially debuggers and automated test frameworks.  Then after the mystery is solved, you can do even better by looking through all your code for similar errors you may have made; and write an automated test to ensure the error will not happen unknowingly again.

One last note - I prefer to call errors "errors" and not "bugs" - Dijkstra chided his colleagues for using the latter term because it's dishonest, supporting the idea that pernicious and fickle bug-fairies planted bugs in our programs while we weren't looking, instead of being there because of our own (sloppy) thinking: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1036.html

We could, for instance, begin with cleaning up our language by no longer calling a bug a bug but by calling it an error. It is much more honest because it squarely puts the blame where it belongs, viz. with the programmer who made the error. The animistic metaphor of the bug that maliciously sneaked in while the programmer was not looking is intellectually dishonest as it disguises that the error is the programmer's own creation. The nice thing of this simple change of vocabulary is that it has such a profound effect: while, before, a program with only one bug used to be "almost correct", afterwards a program with an error is just "wrong" (because in error).

Title: How to most effectively debug code?

Body:
Bugs creeping into code can be minimized, but not entirely eliminated as it is written - programmers are, although many would disagree, only humans.

When we do detect an error in our code, what can we do to weed it out? How should we approach it to make most effective use of our valuable time and enable us to spend less time trying to find it and more time coding? Also, what should we avoid when debugging?

Note here that we're not talking about preventing bugs; we're talking about what to do when bugs do appear. This is a wide field, I know, and may be highly dependent on language, platform and tools. If so, keep to encompassing answers such as mindsets and general methods.


答:
I think you should start with the data types that the language has built in like arrays and pointers, and when your students comprehend those, move on to classes and OO, then the STL.

The reason is that you can teach people to understand arrays without understanding much else besides variables and the underlying computer architecture, but you can't teach them to understand vector without teaching them classes first. If you use the STL from the get go, your students will have to just live with not having a clue about how vector works exactly. And then when you get to that point, they won't have a good enough grasp of pointers and arrays and things that you get from doing stuff like writing your own vector class, writing your own linked list class, etc. that will be necessary to appreciate and exploit its features. It annoys me when students say "what's that?" and teachers say "just ignore it, you'll learn it later."

And as Demian pointed out in the comments, deciphering the relatively cryptic messages you get from template errors is significantly harder than understanding the errors you may get from arrays/non-template constructs.

I do not feel the same way about cout and printf. Neither is any lower-level than the other, except that cout uses operator overloading.

This may seem stupid, but I am absolutely fanatic about having people understand the very basic building blocks of everything before moving on to the abstractions. You shouldn't use smart pointers until you're proficient with raw pointers, no vectors before arrays, that sort of thing.

I often say this, but I'll say it again: it's better to teach students long division first and then let them use a calculator than to let them use a calculator then teach them long division afterwards.

As for books to teach beginners, see the master list of good C++ books.

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.

OwnerDisplayName: Seth Carnegie


答:
I don't think this answer is a very realistic method of approach, but if you had the resources to do it I believe it would be possible.  Consider google's reCaptcha project which uses human beings to decipher words that computers can not read ("Learn More Recaptcha Page").  I believe the problem is similar, in that you are trying to get a machine to figure out something humans are at least better at doing already.

Imagine you had the resources to ask millions of people to identify sarcasm to you within a typed conversation context.  Imagine that you could ask that many people to submit to you the exact moment in the conversation when sarcasm was realized and as little of the conversation prior to the realization that one would need to mark that identification.  This could be stored in a database let's say, which your program had access to.  Then, as the user was typing the conversation to you, the database could be filtered for "similar" conversations.

How to evaluate similarity is something to think about, but one that I believe there's probably research in existence for already.  I believe it would be very much like the theory behind spelling error corrections.  Either way it would probably come down to a probabilistic value that the conversation being typed is in fact sarcastic, and at some point a threshold would have to be provided.

I do also like your idea of presenting the question "Was that sarcasm?" to the user and then using their response to reach a more accurate decision.

I do hope my answer was not a complete waste and I wish you luck in this endeavor.

-Asaf


答:
This is my own experience. Take it for whatever it's worth.

Looking back to when I started programming, I really wish I would have learned about memory first. No, it's not exciting. It'll make you glaze over. But it's a ridiculously easy concept to teach. Just show a 1-D table and make them go through a few mental exercises:

Lesson 1:

  This is 10 bytes of memory. This is the letter "a" being put into cell number 3. "a" is the value, and 3 is the address. OK? This is the number 3 being put into cell 5. Its value is 3 and it's address is 5. Now what can the number 3 mean? Well it could be just a number 3 -or- it could be a reference to address 3. Just like 1 might be a number or might be a country code. It's just a number, it all depends on how we treat it.

Lesson 2:

  Let's learn to count in binary. Let's count to 10 using binary finger counting. Interesting no? See how that only needed 4 fingers? So we say that only 4 bits are needed (1/2 cell). What's the highest you can count to on one hand (answer is 31). How about 2 hands (answer is 1023). Explain how more bits means higher number ranges. Remind them that a memory cell is 8 bits. Ask what happens when a number needs more than 8 bits. How would they put a multi-byte number into memory (in a logical way)? Introduce them to chars, shorts, integers, and longs.

Lesson 3:

  Here's a program I wrote in C++. It uses 32-bit integers. And this here is also a number. But this is a number used for pointing. By using this little asterisk thingie we're making a promise that the number is going to be used for pointing. And here's how we point it at the first number. The little ampersand fills the value in for us. Neat huh?

etcetera. Once you get basic memory down, everything else is cake. It's the poor students who assume the compiler is doing something magical (or that they never have to think about memory management) who tend to struggle the most. And C++ muddies the waters because some things get automatically cleaned up (i.e. a normal vector) while other things don't (i.e. a vector allocated using "new"). And don't even get me started on strings (char* vs. std::string -- try explaining that without pointer knowledge).

I don't know what platform your robot competition will be targeting, but if it's a limited-memory environment, memory mangement skills are crucial.

EDIT

Once you've taught them the fundamentals, then yes I say go C++ all the way. Technically they're just different libraries, but yeah there's no point in confusing them with more than one paradigm. Give them C++ tools (which includes pointers and arrays).


答:
I was taught C++ in high school as a first programming language, although it was more like "C+", now that you mention it; we used cout for writing text to the console and files, but also quite a few C functions (getch() was my favourite).

I think the most effective (and possibly fun) way of teaching the basics is using a goal-oriented curriculum: start with showing how to output stuff, then keyboard input, then simple file I/O, etc. Progress to a simple text-based game (or the robotics equivalent). Then when they ask, "How do I do X?", you can break down X in terms of examples they've already seen, e.g. "First you'll need to get the input from the user like we did in Z, then..." (obviously it isn't this easy in practice since X will likely be something that they need additional knowledge in order to do, e.g. "3D graphics", but you could still explain how it would work in a high-level way).

Examples you show them will start out as black-box copy-pasted magic, whose mysteries get unravelled as pieces of the programming puzzle are slowly figured out. For example, your students will learn the basics of ifs quite quickly, but they probably won't realize that a boolean expression is not exclusively limited to use within an if's condition (leading to classic if (blah) return true; else return false; code).

The subtleties of whether you choose an array or vector as a container will seem irrelevant to the students at first. A vector/array will simply be a way of having lots of variables as one variable, accessible via an index. Stick to one where you can. Pointers won't be understood until later either. That's not to say that you shouldn't explain things; just that you can't explain everything at once, and the stuff you do explain won't be completely absorbed. Humans learn organically, not linearly. I'd been using cout for a couple years before I properly understood what operator overloading was!

Oh, and don't be afraid of repetition. "This is like the Hello World program we did -- remember how we wrote text to the console?" (no...) "Let's go through it again just to make sure." ... And ask questions! Keep the students engaged with fun examples and lots of interaction.

C++ is a complex language, and no matter what you do, a significant amount of that complexity (and that of the craft of programming in general) will be lost on your students. Everything you show them will be new to them; most of it won't sink in at a deep level of understanding (at least, not right away). How memory works, how the components of a PC interact, what the stack and heap are, pointers, classes, even loops and if-else chains won't be properly understood by the majority. This is OK! They don't have to be understood to be used -- an amazing amount of cool programs can be written with super-ugly 1000-line functions with quintuple-nested redundant ifs and 43 variables named things like x_2r. The important thing is that the students are constantly learning and improving. Black boxes are fine as long as they become transparent (or at least translucent grey) in the long run. By the end of the course, they might not know what design patters are, but they should be able to look back at the programs they wrote in the first few weeks and cringe at their code. They should understand at a significant level of detail how the first program they wrote actually works (whereas when they wrote it they had no idea). But they won't know everything -- yet.


答:
As a real life example, building a limit order book.

the ITCH 4.1 feed, for example, has a concept of "replace" orders, where prices (and therefore, priority) can change.  You want to be able to take out orders and move them elsewhere.  Implementing a double-ended queue with pointers makes the operation very easy.


问:
What are the steps in beginning a large project, when all I have is a big idea?
I am computer engineering student. I've been thinking about
how I can handle a big project. What should be my first step to reach my goal in a more efficient and effective way?

When I come up with a project, I don't know how I should start working on it. Many times, I just ignore it. However, I don't want to ignore my project ideas anymore.

Now, I am asking to all of you, can anyone share his/her experiences? How should I start a project when all I have is an idea?

答:
what does success look like?

what are the unknowns in the project?

what are the knowns in the project?

what can you do to eliminate/discover the unknowns, to convert them into knowns?

what can you do to assemble the knowns to achieve success?

what's the next concrete step to take that moves the project forward?

repeat the last step until the project is done; accept that it may take years, and keep moving forward


答:
The problem of sarcasm detection is an open problem in computational linguistics - you'd be better served by searching google scholar than stackexchange for such things. There has, however, been some progress made on the issue. For spoken sarcasm, a robust recognizer can be built using "spectral and contextual features" that (the authors claim) detects sarcasm as well as a human annotator. The authors of the paper claim that the raw text is therefore not enough to detect sarcasm - indeed, they got better results by ignoring the actual words being said.

Tsur et al. have also reported some interesting results in textual sarcasm detection just last year with their SASI algorithm. They also report some additional followup findings in another paper.

In any case, this is the cutting edge of computational language research; do not expect anyone to hand you a libsarcasm on a silver platter. You will need large training datasets and a lot of free time to tweak your sarcasm detector - and even then, a precision of 77% (as reported in the SASI paper) isn't enough to reject a post based solely on a sarcasm flag.


问:
I'm a manager. How can I improve work relationships and communication with programmers?
A little background first. I'm a project manager at medium-sized company. I started as a CS major and had a little exposure to programming, but after a few months I knew it's not my path, so I switched over to management. That proved to be a good decision, and after graduating I've worked in software management at various companies (for 5 years now).

Recently, we had a very painful project. It was the worst of the worst, with many mistakes both on our side and on the customers side and just barely ending it without losses. It has led to many frustrating situations, one of which escalated to the point where one of our senior developers left company after a vocal argument with us (the management). This was a red flag for me: I did something terribly wrong. (for the record, the argument was about several mistaken time estimates)

I searched many places for answers and a friend pointed me to this site. There are many questions here about frustrations with management. I can understand that the general bad experiences lead to a general reluctance against "those guys in the suits".

I'm that guy in the suit. It may not look like it, but all I want is a successful project, and with limited resources it takes painful decisions. That's my job. One of the things the aforementioned senior developer complained about was work equipment. Frankly, I had no idea that the computers we had were not suited for working. After this, I asked many programmers and the general consensus was that we need better machines. I fixed that since then, but there was obviously a huge communication gap between me and the programmers. Some of the most brilliant developers are the most shy and silent people. I know that, and it was never a problem during an interview. People are different, and have strengths at different areas.

The case of the underpowered PCs is just one of the many that led me to thinking that there is a communication issue. How can I improve communication with programmers without being intimidating and repetitive?

What I'm hoping is that people don't complain about good things. If you love your workplace and love (or at least like :)) your manager, please tell me about them. What are they doing right? Similarly, if you hate it, please describe in detail why. I'm looking for answers about improving communication because I think that is my problem, but I might be wrong.

答: I'm surprised noone has mentioned this great book which is dealing exactly with your question and subject - "Peopleware: Productive Projects and Teams" by DeMarco and Lister. From the editorial : the major issues of software development are human, not technical . The first three reviews on amazon would easily be enough to convince me to buy this book if I was in your situation.


答:
You say you want to teach them C++ but not teach them any C constructs, but most of the programming constructs they'll need to know first are common to all languages and the C++ versions are rooted in C:

This is how you make a program [int main (..) { return 0; }]. Give a basic overview of the programming environment you want them to try out too. They'll need to know how to make a project and actually compile/run it.

This is a variable. Variables can store data (int, char, float, etc).

Strings (C++ ones are easier to use with cin).

This is how you read and write data (cin, cout). "Hello, %s!"

Conditionals (computers need to make decisions).

Loops (computers are good at doing the same thing over and over). Show while and for loops.

That should take about two lessons of an hour each. Make sure to prepare a concise set of notes that they can refer to in the practical component. You're not trying to make them brilliant programmers so give examples of how to read from the console, create structures, and everything else they'd need to do. Only use language-supported features, not custom utility libraries. You'll only confuse them more.

From the get-go, lead by example and show them examples of well laid out code. Indents should be correct, bracing and parentheses consistent in the style you are most comfortable with. Variable names should be meaningful. If you show slop as an example then they'll learn that slop is acceptable. It's a bad starting point. Stress the importance of getting indenting correct - I found that when the lot I taught indented their code consistently they were more easily able to see where they were going wrong. That was because most of their errors were incorrect scope for operations (putting operations in loops/conditionals that weren't meant to be, or the inverse).

Then move onto practical work. The best way to learn something is to break it and work out why. You'll want to make sure they have an easy to use environment to compile their code. Document it with screen shots in your hand outs.

A good example that helped me grok some of the concepts was build a Coke machine:

Output a menu of items and prices (storing the menu was an array of a user-defined structure. Could be a class in C++). Outputting it required a loop.

Read in the user's selection.

Ask the user for money. They could just enter coin denomination in cents (1, 5, 10, 20, 50, 100, 200 in Aus). Ignore unknown denominations. While the user hasn't put in enough money, keep asking (loops).

Calculate the change required (modulo division), giving the least number of coins. Print the output to the screen.

Wait for next user.

After that you can move onto C++ constructs; you don't want to dive in too far before they can at least make a basic program.

And above all, have lots of spare time and patience to devote to questions. There will be many, and most of them will make you cringe because they are so trivial that the answer is obvious to you.


答:
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.

definitely go right into using standard library types. a std::string or std::vector is what they should often use and (the vast majority of the implementations of) these types offer some form of error detection and error handling, while abstracting many of the complexities from the students.

you can spend a good chunk of time teaching students how memory is structured and how to manage memory (C style), or you can get straight to work using the idiomatic types of the language then explain implementation details if needed (and when they have a better understanding of what an array is and where they are used).

the syntax of std::vector (create/read/write) is not much more complicated than a C array's. in comparison, manual memory management and all the common errors new learners make with C arrays are far more difficult to learn, teach, and use.

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

cout. personally, i think cout's a easier to learn. perhaps more importantly, you should choose cout because it is more safe, versatile, and allows you to define how an object prints, which means you already have builtin functionalities and typesafety using the some standard library types. finally, you'll just end up with mixed programs when you realize they may also need to learn cout in addition to printf.

in fact, i think you should read Accelerated C++, by Koenig and Moo  and possibly use it for instruction (answering question 3 indirectly). in the book, they introduce std::cout just before return (page 3), and save pointers and arrays until chapter 10. if i could copy and paste the preface of that book as an answer to your question, i would. (note: i recommend you read it for the perspective of teaching c++).

Edit Here is the Preface

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

if you don't want to use Accelerated C++ (which does assume some background with programming in general), then maybe you would like Eckel's Thinking in C++. I have not read it, but it is a freely distributed C++ intro text.


问:
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.

答:
clients have direct access to the developers any time they want

That's a major problem right there. Clients should never have direct access to the developers. Developers should always be shielded from ad-hoc requests, which should be funneled through either management or lead developer (or a combination thereof).

Once the requirements are gathered by the lead/manager team (and vetted by the lead - some requests should be pushed back on, have further investigation done on them, etc etc before ever hitting the developers directly). Once the requirements are locked in, then it should be given to the developers, who are responsible for prioritizing (with help from the lead) and estimating.

Even if the developer needs to seek further details from the client at that point, (IMHO) it should still be done through a single point of contact (lead/manager) to avoid client confusion about who they're supposed to contact and when. So obviously, the more interruptions that hit a developer, the less productive they are.

I don't have the doc on hand, but it's proven that it takes at least fifteen minutes for a developer to get back in their programmer head space when any interruptions occur. It's the manager (and lead's) job to shield any absolutely required interruptions from the developers to allow them to do their job.

Once you've started shielding developers from clients, the next step is to manage client expectations better: If it's not in the spec that was signed off on (I'm hoping that your clients do sign off on them), it's not part of the project. Clients need to understand that if they want to add tasks, then others may not be completed in a given milestone. That gives them the onus of prioritizing what they want done and not done once the developers have provided a task estimate for the request.

You need to educate your clients on the impact of their request(s). Generally, once they understand how what they're asking for affects the rest of the project, you'll find that you get many less requests that aren't well thought through.


答:
Perusing the various StackExchange sites, I realize that it's rather in vogue to ask a question like this.  At risk of criticism and downvotes, I'll be honest.  This is not meant to troll or to flame, I am only meaning to help, by giving an honest assessment of the question.

And that assessment is as follows: This is a very strange question to ask of a C programmer.  Pretty much all it says is "I don't know C."  If I analyze a bit further and more cynically, there is an undertone of a follow-up to this "question":  "Is there some shortcut I can take to quickly and suddenly acquire the knowledge of an experienced C programmer, without devoting any time for independent study?"  Any "answer" that someone can give is no substitute for going and doing the legwork of understanding the underlying concept and its use.

I feel like it's more constructive to go learn C well, first hand, than to go on the web and ask people this.  When you know C well you won't bother asking questions like this, it will be like asking "what problems are best solved by using a toothbrush?"


答:
Should I start using STL from day one ...?

Yes.  Using native arrays in C++ is error prone and simply bad practice 99% of the time.

For I/O, should I stick to cout, etc... ?

Yes.

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

They aren't so young.  Learning to program does not require wisdom, just motivation and an open mind. I can't think of anything taught in the last two years of high school that would better prepare a student to learn to program.  Have you looked at Bruce Eckel's Thinking in C++? It's available for free download and very well reviewed.   Please avoid the popular but horrible C++: How to Program and all the Sam's Teach Yourself C++ ... books.


答:
Pointers are an essential part to any data structure implementation in C and data structures are an essential part of any non-trivial program.

If you'd like to learn why it is that pointers are so vital, then I'd suggest learning what a linked list is and trying to write one without using pointers. I haven't set you an impossible challenge, (HINT: pointers are used to reference locations in memory, how do you reference things in arrays?).


答:
I would teach strict C++. You know how when you write printf and give it to little params or the wrong type something strange happens? and if you use invalid pointers bad things may occur? DON'T TEACH THAT

From day one i would teach how to use references, STL and say you LOSE MARKS for using pointers. Don't teach smart pointers either. The only time i notice i use pointers are when i do GUI and objects (like an image box) must exist and be a valid image or null. For console programming i haven't use pointers (smart or raw) in a long time.

So in short dont teach them anything that can give them trouble. Teach iostreams, structs, tell them they lose marks on typecast too and dont try to teach design. You dont want anyone becoming a Seasoned professional


问:
Submit issue, pull request, or both for a very small fix?
I've made a 4-line bug fix to a minor issue in a library on github. The project is actively maintained with changes every few days.

What is the ideal way to submit a fix that small? Is it to fork, fix and submit a pull request; file an issue and a pull request; or just file the issue with my fix copy-pasted? (Or something else?)

答:
See if the project has guidelines about this.

Traditionally, you'd file a bug report, with a diff for your intended fix; the maintainer would then look at the diff and decide whether it's worth including.

Recently, the rise of distributed SCMs such as git, has spawned a different attitude where you're encouraged to just fork the project and post a link (or pull request); since forking and pulling are now cheap, the effort for the maintainer is often smaller in this scenario.

Of course, you can always do both: fork the project, apply your changes, dump a diff, and send a bug report containing both the diff and a URI to pull from.


答:
Even though pointers really shine while working with large memory objects, there is still a way to do the same without them.

The pointer are absolutely essential for so-called dynamic programming, it is when you don't know how much memory you'll need before your program executes. In dynamic programming you can request memory chunks during runtime and place your own data into those -- so you need pointer or references (the difference is not important here) to be able to work with those data chunks.

As long as you can claim certain memory during runtime and place your data into newly acquired memory you can then do the following:

You can have self-extending data structures. Those are structures that can extend themselves by claiming additional memory as long as their capacity runs out. The key property of every self-extending structure is that it consists of small memory blocks (termed nodes, list items etc. depending upon the structure) and every block contains references to other block(s). This "linked" structures build the majority of modern data types: graphs, trees, lists etc.

You can program using OOP (Object-Oriented Programming) paradigm. The whole OOP is based upon using not direct variables, but references to class instances (termed objects) and manipulating them. No single instance can exist without pointers (even though it is possible to use static-only classes even without pointers, that is rather an exception).


问:
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 ?

答:
A couple of points to consider:

Listeners should be well-behaved in as much that they protect their own code's execution from letting exceptions escape to the outside.

The event firer (?), that is the one firing the event, has (should have) no interest in whatever the listeners do with it. Its only job is to ensure that all listeners get to hear about the event. This means that it should protect against one of the listeners doing anything that would prevent other listeners from getting the event. So, yes, catch exceptions.

The event firer has no interest in catching exceptions other than to ensure that bad behaviour by one listener doesn't affect other listeners. So in this case "eating" the exception could be argued for. However, eating exceptions doesn't help anybody, so logging the exception with as much detail about the offending listener as possible is the way to go.

I wouldn't have the firer collect exceptions and finally raise one of its own accord. Quite simply because the firer did its job correctly and has no need to throw an exception. By logging the exceptions thrown by badly behaving listeners, the firer is already doing its part in aiding any debugging needed. (Logs should always be free of exceptions...).


答:
Here is my wisdom from 14 years experience:

if you have a startup, don't assign roles. Better hope that you assembled a good self organizing team. If everybody knows each other, everybody knows who does what the best. A project manager will only stand in the way.

later on, the distinction between front-end and back-end makes sense. In the backend, quality is prio one. Code has to be performant, secure and transaction safe. In the front-end, implementation time matters. And you must be able to rely on a good back-end. The different goals of front- and back-end don't work good together.

the back-end should already exist before the front-end coder starts to work. Otherwise, the front-end coder will be slowed down too much.

backend has to be able react fast on front-end requirements in order not to slow them down

Title: Is it common to separate back-end and front-end into two positions on web development projects?

Body:
At a web startup, is it more common to have an engineer working the front-end AND back-end of the feature (basically in charge of the whole feature)? Or have engineers separated between the back-end and front-end?

Which ones are more beneficial and for what situations?

The downside, I've noticed, regarding having one engineer in charge of the whole feature is that the person might only be particularly strong in either frontend or backend development but not both, thus sometimes having a decrease in speed and quality.

Having frontend and backend developers on one feature increase the speed of the feature and the quality AND it encourages collaboration. But I am concerned about having 2 engineers working on one feature which may be a poor use of resources since the 1 engineer can be placed on another feature to work on.

What is the common/best practice for allocation backend/frontend engineering resources at a small early-stage startup? And then how will it change as it grows?


答:
Funny, i just answered a question about C++ and talked about pointers.

Short version is you NEVER need pointers unless 1) the library you are using forces you 2) You need a nullable reference.

If you need an array, list, string etc just have it on the stack and use a stl object. Returning or passing stl objects are fast(unchecked fact) because they have internal code that copies a pointer instead of an object and will only copy the data if you write to it. This is regular C++ not even the new C++11 which will make it easier on library writers.

Your question might be answered at this part

If you do use a pointer make sure its in one of these two conditions. 1) You are passing input that may be nullable. An example is an optional filename. 2) If you want to give ownership away. As in if you pass or return the pointer you do not have ANY copies of it remaining nor use the pointer you give away

```<code>ptr=blah; func(ptr); //never use ptr again for here on out.
</code>```

But i havent used pointers or smart pointers for a very long time and i have profiled my application. It runs very fast.

ADDITIONAL NOTE: I notice that i do write my own structs and i do pass them around. So how do i do this without using pointers? Its not an STL container so passing by ref is slow. I always load my data list/deques/maps and such. I dont remember returning any objects unless it was some sort of list/map. Not even a string. I looked at code for single objects and i notice i do something like this { MyStruct v; func(v, someinput); ... } void func(MyStruct&v, const D&someinput) { fillV; } so i pretty much return objects (multiple) or preallocate/pass in a reference to fill (single).

Now if you were writing you're own deque, map, etc you'll need to use pointers. But you don't need to. Let STL and possibly boost worry about that. You just need to write data and the solutions. Not containers to hold them ;)

I hope you now never use pointers :D. Good luck dealing with libs that force you to

Body:
Funny, i just answered a question about C++ and talked about pointers.

Short version is you NEVER need pointers unless 1) the library you are using forces you 2) You need a nullable reference.

If you need an array, list, string etc just have it on the stack and use a stl object. Returning or passing stl objects are fast(unchecked fact) because they have internal code that copies a pointer instead of an object and will only copy the data if you write to it. This is regular C++ not even the new C++11 which will make it easier on library writers.

Your question might be answered at this part

If you do use a pointer make sure its in one of these two conditions. 1) You are passing input that may be nullable. An example is an optional filename. 2) If you want to give ownership away. As in if you pass or return the pointer you do not have ANY copies of it remaining nor use the pointer you give away

ptr=blah; func(ptr); //never use ptr again for here on out.

But i havent used pointers or smart pointers for a very long time and i have profiled my application. It runs very fast.

ADDITIONAL NOTE: I notice that i do write my own structs and i do pass them around. So how do i do this without using pointers? Its not an STL container so passing by ref is slow. I always load my data list/deques/maps and such. I dont remember returning any objects unless it was some sort of list/map. Not even a string. I looked at code for single objects and i notice i do something like this { MyStruct v; func(v, someinput); ... } void func(MyStruct&v, const D&someinput) { fillV; } so i pretty much return objects (multiple) or preallocate/pass in a reference to fill (single).

Now if you were writing you're own deque, map, etc you'll need to use pointers. But you don't need to. Let STL and possibly boost worry about that. You just need to write data and the solutions. Not containers to hold them ;)

I hope you now never use pointers :D. Good luck dealing with libs that force you to


答:
One thing to consider is that in typical FIRST code data structures of any form (structs, classes, arrays, vectors, lists) play a very small role. You typically deal with a very small amount of sensor data, and use it to decide a very small amount of actuator motions.

But what does play a huge role, and can be very hard to understand are all the different forms of control that go on.

So I'd put a lot of emphasis on control. Start with basics: if, for, while. Have them practice those a lot. Get them to know those well....

... but then it gets harder. Any robot code of moderate size eventually gets to some trickier control patterns:

Big "main" loop, that calls everything

State machines (these show up a lot)

Saving previous values / running counter (like for PID)

These are hard for beginners to understand. Thinking about how a program moves through code like this is confusing, you might not realize it now, but it is. It's going to give your students a lot more trouble than the language itself.

Also, good luck! Hope the season goes well.