答:
The right answer is ....

```<code>"We should forget about small efficiencies,
say about 97% of the time: premature
optimization is the root of all evil"
Donald Knuth
</code>```

Focus on providing value to your clients. Create solution that is clean, easy to understand and easy to maintain.

Then if you need more "power" you can profile your application. With profiling you will pin point bottlenecks that when changed, will provide biggest benefit and boost in "efficency".

Title: Can applications affect power consumption in a substantial way?

Body:
Is there anything that can be done for a single general purpose application to affect the power consumption of the device it is running on?

I am not familiar with how optimizations to individual applications may affect power consumption in a general way, can someone explain if different approaches to writing applications affect power consumption of the device they are running on?

That is, can a single program, that does the exact same thing functionally, written in different ways drastically affect the power consumption of a device in general, not about how different un-related programs might affect the power consumption of a device.

Body:
The right answer is ....

"We should forget about small efficiencies,
say about 97% of the time: premature
optimization is the root of all evil"
Donald Knuth

Focus on providing value to your clients. Create solution that is clean, easy to understand and easy to maintain.

Then if you need more "power" you can profile your application. With profiling you will pin point bottlenecks that when changed, will provide biggest benefit and boost in "efficency".


问:
Starting on a large project, should I split it into more concise parts?
Background: Currently an intern at a company and working on repurposing older programs (still in use, but for different departments) for use in testing new hardware. The new hardware is different in terms of register layout and firmware interface from the older iterations of hardware. I have been given free reign on how to setup this project as it is to be used for the new hardware exclusively.

Currently there is a single .c file and 5 different header files that make up the program. The .c file is currently over 10000 lines long and comprises EVERY single function in use of main().

My question is, should I split the code into more recognizable chunks of .c files? It is currently only a mild annoyance to go through and find the methods I need, but it is time-consuming and I do have deadlines. What are the benefits and tradeoffs of doing so now, rather than later?

I aim to finish re-purposing the program by next week (this is heavy optimism, it will most likely take two weeks), so is it more efficient to start culling and moving around code now, or will I benefit more from just attempting to force my way through as is?

答:
Here's what I did in my previous job. I too faced this problem where some idiot thought that it would be good idea to put the code in file and since he will be the only one working on it for years to come, he roughly knew line numbers for each function/method.

I knew it was going to break things If I would try to modularize whole code, so I started picking out pieces of methods/functions which I was changing. For example I had to fix a shopping cart display issue and for that I had to make changes in method/function clearShoppingCart(), so I took this code placed it in a separate file ShoppingCartUtility.java

Over a period of 3 months, I had moved out 75% of code in a manageable and easy to understand structure.

Cheers!
Dinesh

ContentLicense: CC BY-SA 3.0


问:
Is 37Signals Basecamp a hype?
What's so unique about it? Heard great things about it, used it, found that beside the Google Apps Integration there's nothing really special about it. Maybe I just don't get it?

So, what's your reason to use basecamp?

答: It's a great way to centralize information on projects and to have a solid record of communication between users. It's also great if you are working with a distributed team.</p>

ContentLicense: CC BY-SA 2.5

Title: Is 37Signals Basecamp a hype?


问:
How does learning assembly aid in programming?
I have been programming in higher level languages (Python, C#, VBA, VB.NET) for around 10 years and I have completely zero understanding on what's going on, "under the hood."

I am wondering what are the benefits of learning assembly, and how will it aid me as a programmer? Can you please provide me with a resource that will show me exactly the connection between what I write in higher level code to what happens in assembly?

答:
Since you didn't mention C or C++ in the languages you know list. I would STRONGLY recommend learning them well before even thinking about assembly. C or C++ will give all the basic concepts that are totally transparent in managed languages and you will understand most of the concepts mentioned in this page with one of the most important languages that you could use in real world projects. It is a real added value to your programming skills. Please, be aware that assembly is used in very specific areas and it is not nearly as useful as C or C++.

I would even go further to say that you should not dive to assembly before understanding how unmanaged languages work. It is almost a mandatory reading.

You should learn assembly if you want to go even further down. You want to know how exactly each and every construct of the language is created. It is informative but it is a whole lot different level complexity.

OwnerDisplayName: Артём Царионов


答:
In short I think the answer is because you can do more if you learn assembly.  Learning assembly grants access to the realms of embedded device programming, security penetration and circumvention, reverse engineering and system programming which are very hard to work in if you don't know assembler.

As for learning it to improve program performance, this is doubtful in applications programming.  Most of the time there are so many things to focus on first before ever hitting this level of optimization like optimizing your i/o access on both disk and network, optimizing how you build the GUI, choosing the right algorithms, maxing out all your cores, running on the best hardware money can buy and switching from interpreted to compiled languages.  Unless you're creating software for other end users, hardware is cheap compared to a programmer's hourly wage, especially with cloud availability.

Also, you have to weigh increased program execution speed with readability of your code after you get hit by a bus, quit or come back to the code base to change it a year after you wrote the last version.

OwnerDisplayName: Артём Царионов

Title: How does learning assembly aid in programming?

Body:
I have been programming in higher level languages (Python, C#, VBA, VB.NET) for around 10 years and I have completely zero understanding on what's going on, "under the hood."

I am wondering what are the benefits of learning assembly, and how will it aid me as a programmer? Can you please provide me with a resource that will show me exactly the connection between what I write in higher level code to what happens in assembly?


问:
How do I treat application aspects with regard to features and user stories?
When drawing up a backlog, I have several requirements that apply to a great many user stories, i.e. aspects of the application like error handling and feedback. How do I include these (without using an #include directive in each user story )? Should I treat error presentation as a feature, then have user stories for this feature like "system catches exception, and shows info to user"?</p>

答:
Dealing with user feedback is critical to user experience, but also applies to different parts of the application in different ways.

Take the following two examples:

One story might focus on a direct user interaction in which a fatal error occurs. A modal dialog is used to inform the user of the error and notify that recovery is impossible. The story for this would be: "As a user I want to be informed about an invalid entry of some data form so that I can go back and correct this error immediately". This user story implies that this is a fatal blocking error which the user needs to correct immediately.

In a second story the user forgets to enter mandatory data into a form. The story would be: "As a user I want missing fields in an entry to be highlighted so that I know what the required fields are."

This subtle notification is vastly different and cannot be combined with the first story into one general error handling story. However, both can arise from internal exceptions.

Remember that it is important to convey the "what" of a story, so for example the error scenario which should be dealt with in a specific situation. The how of the error (i.e. an exception is being thrown somewhere) is almost irrelevant to the product owner as it holds no business value. From a technical standpoint having a sound architecture is something I would expect from my product in any way.

In the end you will gain flexibility and extensibility by focusing on the business value and have well seperated and small user stories.


答:
Actually, what would probably be best for you would be a class that doesn't (to my knowledge) exist anywhere:  It would be a class that combines a brief overview of machine/assembler language and storage addressing concepts with a tour through compiler construction, code generation, and runtime environments.

The problem is that with a high-level, far-away-from-the-hardware language like C# or Python you don't really appreciate the fact that every move you make turns into hundreds if not thousands of machine instructions, and you don't tend to comprehend how a few lines of a high-level language can cause vast amounts of storage to be accessed and modified.  It's not so much that you need to know precisely what is going on "beneath the covers", but you need to have an appreciation for the scope of what's happening, and a general conception of the types of things that occur.

OwnerDisplayName: Артём Царионов


问:
How is the JVM and Java's WORA different from other high level languages?
In the Java world, we often talk about the JVM, and when Java was new it had the supposedly killer feature of "Write Once, Run Anywhere."

From the way people talk and write, this seems different from the way that Python, for example, works.  Yet I've not been aware of any way that Python code that I've written would work differently on another machine.  (Though I haven't written that much Python.)

So what am I missing?  How is the JVM different from a Python interpreter?  Is there a way that Python lacks Java's platform independence?  Or is this just a cultural difference?

答: Except that Java is emphatically not WORA. I've seen Java software that broke after Java has been upgraded to a higher version on the minor version number. IMHO, WORA is just a marketing gimmick.


问:
Should an API platform enforce only receiving JSON requests?
I am building an API platform.

I have already ensured that the platform always returns JSON responses.

My question is

Should my API platform enforce the rule that all requests must be JSON?
What are the benefits of making all requests to be JSON?

I understand the benefits of making all responses to be JSON as this means consistency for the client apps using the API.

I fail to see the benefits of making all requests to be JSON as well.

I am asking this because GitHub API v3 appears to be enforcing this rule.

My API platform will involve uploading of files in the requests. As far as I know, JSON requests does not work well with file uploads.

Or do I do a hybrid?

Enforce that anything NOT to do with file upload should send their requests as JSON?

And allow an exception for file upload?

答:
I think this is a question of approach, and you are right on "failing to see the benefits" of such restriction. Your service has a defined API; some of the entries require structured data (commands and data objects), others process streams (file upload). If I see it in this way, I see no problem.

If you have to accept something as a stream, you don't force anyone using an improper format (now JSON), but let them send you that file in the most natural way. This is not "breaking" some rule, but the simplest way to do the job. KISS.

If you have to process data hierarchies from the client: commands and objects, yes, it is nice to give one, and perhaps the easiest way to send you hierarchies, JSON is okay. For your clients.

But for you inside the service, it is not beneficial to actually see JSON, because that is only a stream syntax and the handler components around it (the same exists for XML and perhaps other formats as well). Your codes don't need JSON, they need data hierarchies. So my advice here is to hide the fact that now you use JSON format and handlers, from all of your higher level codes. The options:

deserialize to actual object instances within your platform,

convert to a hierarchy of Maps, Dictionaries or alike

or hide the actual JSON node objects behind a simple interface with getAttribute, getChildren, etc. methods.

Some time later you might be unable to force a client to use JSON, because their systems communicate through XMLs, can only use plain forms without JavaScript, or their data is actually in a database. Then you will love the concept of having JSON invisible to the rest of your code by any of the above means: you then just write the next wrapper for that XML (or HTTP request parameter package, whatever), and you are done: the same API and code can be reached through another "data language".

At least this is how I see it.


答:
You should be familiar with one level 'deeper' in the system that you are working at.  Skipping too far down in one go isn't bad, but may not be as helpful as one would desire.

A programmer in a high level language should learn a lower level language (C is an excellent option).  You don't need to go all the way to assembly to have an appreciation of what goes on under the covers when you tell the computer to instantiate an object, or create a hash table, or a set - but you should be able to code them.

For a java programmer, learning some C would help you with memory management, passing arguments.  Writing some of the extensive java library in C would go a  ways to understanding when to use what implementation of Set (do you want a hash? or tree?).  Dealing with char* in a threaded environment will assist in understanding why String is immutable.

Taken to the next level... A C programmer should have some familiarity with assembly, and assembly types (oft found in embedded systems shops) would likely do well with understanding things at the level of gates.  Those who work with gates should know some quantum physics.  And those quantum physicists, well, they are still trying to figure out what the next abstraction is.

OwnerDisplayName: Артём Царионов


问:
Can applications affect power consumption in a substantial way?
Is there anything that can be done for a single general purpose application to affect the power consumption of the device it is running on?

I am not familiar with how optimizations to individual applications may affect power consumption in a general way, can someone explain if different approaches to writing applications affect power consumption of the device they are running on?

That is, can a single program, that does the exact same thing functionally, written in different ways drastically affect the power consumption of a device in general, not about how different un-related programs might affect the power consumption of a device.

答:
Power consumption concerns are often to detriment of performance, so the two need to be balanced. Apply cost of capital accounting to consider more efficient hardware, and it becomes a very complex tradeoff. (simply do you spend 100 hours to save a milliwatt/hour, or $10 for a more efficent PSU in the conputers running the software). The only time it makes commercial sense to worry about power consumption (caused by software) is a server farm the size Google runs, battery powered devices, and if marketing want a tick on the Tree Hugging Greenie box.

Its too complex to trivialise it by saying "Make you algorithms more effiecent" - thats just the first step. The performance/power curve and particular the "perceived performance"/power curve are non linear. It depends if you have control and to what level through the OS in use.

Beyond that, the question will have different answers to each specific situation. For instance I once worked on a battery powered system (target 18 months on a 9V cell) that was more power efficent running at max clock speed for short duration than sleeping, yet another micro running similar software was better to tick over on a slow clock for a minute or so then sleep.


问:
RDBMS same type of optional data for multiple tables
I have an embedded database (SQLite), it stores information about events and page views, its purpose is to track the user journey inside my application. I need to provide support for optional custom properties on my events and page views.

In code this is not a problem, however I am torn between two solutions for storing that information.

So I have Events and PageViews tables, my first option for persisting the optional custom properties is to have a EventsCustomProperties table which has only a name and value column and a reference (foreign key) to the event.
In this solution I would also have a PageViewCustomProperties with the same structure.

The problem I have with this is having two tables which are identical other then their relationships with other tables.

In my other solution I would have one CustomProperties table, and in addition to the name, value and relationship key, it would also have a type column, which I should use manually in code to map the relationship id to an event or a page view.
In this solution the actual use of foreign keys is redundant.

My dilemma is that in the first solution I am respecting one normalisation rule of repeating groups of data, buy in the second solution I am breaking another rule although I cannot get my head to remember the name of the rule.

So it seems I will break rules whatever I do. Can anyone suggest a better way or a preference to the first or second solution.

答: Here is one way of doing it. It is close to your first solution. This is a variation on a regular star-schema. Star-Schemas sometimes trade normalization for efficiency. The proposed solution below is based on my understanding of the problem, but this is incomplete, for example, to verify the correctness of this, you need to list the most common queries you'd expect to issue and see if this is valid or not. I have only listed the PKs.


问:
At what point can I say I've "learned" a language?
In my few years of programming, I've toyed with everything from Ruby to C++.  I've done everything from just learning basic syntax (Ruby) to completing several major (for me) projects that stretched my abilities with the language.  Given this variety (and the fact that truly learning a language never stops), when can I say I know (or have learned) a language?</p>

答:
I think you have learned a language when you don't see it. You don't see the for cycles and data accesses, but the workflow of the algorithm.

You don't play tricks with parameter passing and array processing, magic macros. You don't think of your code as a self marketing material to show to your friends and teachers, but to express your understanding of a problem, and your will to the computer the most readable way.

You have habits that help you avoiding lots of mistakes just by following them, like: use {} code blocks and () in expressions even if you are absolutely sure that "it will be only one line" or "I am no fool and know operator precedence order".

You stop counting how many classes, patterns and framework APIs you know. This is what intellisense, the references and tutorials, and the Google is for. But when you look at a problem, you immediately know what parts it can be split, and with what tools and algorithms you will solve them.

What you do works, is elegant and small. You enjoy coding and easily find your bugs. Yes, masters also make bugs because they are humans - but they find them quickly because their code structure leads them to the right place.

And finally realize: you have learned to think, analyze and solve problems; compared to them, the actual language is secondary, just the current box of rules and tools.


答:
One idea (taken from SCRUM): Things that need to be checked for every user story are included into the so-called "definition of done".

Usually "definition of done" includes technical things, like:

all tests are green

code is reasonably clean

code causes no regressions

But it can also include user-visible things:

no user operation takes more than a second, or

all GUI controls can be used with the keyboard alone

The team must check the "definition of done" for every user story before they declare it done.

One option would be to include appropriate error handling into this "definition of done". However, as the other answers point out, the examples you cite (errorhandling & feedback) are actually probably not really good examples for requirements that apply "everywhere":

Proper error handling & feedback usually depends on the context, so it needs to be defined separately for the places where it's needed. So in this case it may be better to formulate error handling as separate user stories, as explained by malte's answer.

Title: How do I treat application aspects with regard to features and user stories?

Body: When drawing up a backlog, I have several requirements that apply to a great many user stories, i.e. aspects of the application like error handling and feedback. How do I include these (without using an #include directive in each user story )? Should I treat error presentation as a feature, then have user stories for this feature like "system catches exception, and shows info to user"?</p>


问:
What are the best practices regarding unsigned ints?
I use unsigned ints everywhere, and I'm not sure if I should.  This can be from database primary key id columns to counters, etc.  If a number should never be negative, then I will always used an unsigned int.

However I notice from other's code that no one else seems to do this.  Is there something crucial that I'm overlooking?

Edit: Since this question I've also noticed that in C, returning negative values for errors is commonplace rather than throwing exceptions as in C++.

答:
I would recommend that outside space-constrained data-storage and data-interchange contexts, one should generally use signed types.  In most cases where a 32-bit signed integer would too small but a 32-bit unsigned value would suffice for today, it won't be long before the 32-bit unsigned value isn't big enough either.

The primary times one should use unsigned types are when one is either assembling multiple values into a larger one (e.g. converting four bytes to a 32-bit number) or decomposing larger values into smaller ones (e.g. storing a 32-bit number as four bytes), or when one has a quantity which is expected to "roll over" periodically and one needs to deal with it (think of a residential utility meter; most of them have enough digits to ensure that they won't possibly roll over between readings if they're read three times a year, but not enough to ensure they won't roll over within the useful life of the meter).  Unsigned types often have enough 'weirdness' that they should only be used in cases where their semantics are necessary.


答:
To me, the biggest draw has been the simplicity, which leads to flexibility. The concepts that Basecamp helps to manage are easily understandable, and there's very little configuration to worry about. (Have you ever tried to use a tool like JIRA? Even its configuration has configuration.)

The simplicity starts to pay dividends when you are composing project teams of varying technical experience. The basic nature of to-do list items and milestones are easily understandable by most anybody.

Title: Is 37Signals Basecamp a hype?

Body:
What's so unique about it? Heard great things about it, used it, found that beside the Google Apps Integration there's nothing really special about it. Maybe I just don't get it?

So, what's your reason to use basecamp?


问:
tcp retransmission queue
I'm trying to understand how tcp retransmission queue works so I can implement it in my application that uses TCAP over SCTP.
What I understood from the TCP queue is that every message is saved in retransmission queue with with a time, when the timer reaches 0 the message will be sent again.

My question is how to check the time on that message, is it like a thread that constantly checks the retransmission queue or is it something else?

答:
Unlike some earlier protocols which used packet sequence numbers, TCP connections use byte sequence numbers.  Each packet essentially says "I have received the data stream from you up to but not including byte A; I would be interested in seeing up to W bytes beyond that.  Here are N bytes from me starting with sequence number T".  The byte sequence numbers are 32 bits, and are initialized to an arbitrary value when a connection is opened, and they wrap from 0xFFFFFFFF to 0; when comparing sequence numbers, one should generally subtract using unsigned values, and then look at the result as an unsigned value.

Typically, an implementation will keep track of the sequence number of the next byte it expects, the highest sequence number for which it has received an acknowledgment, the sequence number of the last byte transmitted, how long it should wait for an acknowledgment before retransmitting, and how long it should wait for more data before acknowledging what it has.

Any time the data has data to send which the other unit would be interested in, it should send it and setting the timer for expect an acknowledgment if it isn't already running.  Any time it receives an acknowledgment for some but not all of the data it has sent, it should reset that timer.  Any time that timer expires without having received an acknowledgment for all data, the unit should load its "last byte transmitted" sequence number with the highest sequence number for which it has received an acknowledgment.

If data arrives with the incoming packets, the unit should set a timer to acknowledge it.  When the timer expires, the unit should send out a packet even if it doesn't have any data of its own to send.  If the unit sends out a packet for any other reason, it can acknowledge all data received up to that point, and may thus cancel the acknowledgement timer.

Note that it's possible for many packets' worth of data to be acknowledged by a single return acknowledgment; it's also possible that data which was sent out as multiple packets may get retransmitted as one larger packet.  Units should expect that they may receive a packet containing a mixture of old and new data; they should simply process the new data and ignore the old.  Note that units should acknowledge data they receive whether or not any of it was 'new'; the acknowledgement should indicate the sequence number of the next expected byte, regardless of what data was in the packet being acknowledged.

TCP is in many ways a fairly simple protocol, although newer implementations include a lot of "optional" wrinkles.  Generally, devices like embedded microcontrollers can get by with implementing a small subset of the features that full-fledged PC's are likely to include.

Title: tcp retransmission queue


问:
How to get good design when using agile methods?
I have been using an agile methodology (SCRUM) for about three years now and I see certain advantages to it, especially in the short-term feedback at many levels (from customers having early access to implemented features, from testers that can test features as soon as they are implemented, from other developers that can provide very early feedback on new code through review, etc).

On the other hand, I have two open problems, the first of which I will try
to explain in this question.

Problem : Difficulty to get a good design

I try to do refactoring as soon as the code gets messy, I write unit tests as much as I can (which does help to prevent bugs in general and when refactoring in particular). On the other hand, developing some complex feature in small increments, with daily commits and continuously rethinking the code when it gets unstructured is not allowing me to produce really good design.

The only well-designed module I could produce recently I obtained by taking a different approach: I analyzed the problem for a few days (I actually had had the problem going through my mind for a couple of months before I started to work on it seriously), sketched a rather detailed design of all the involved classes and their relationships for a couple more days, and then locked myself up in my office and wrote down the whole code by working without interruption for about three weeks. The result was the best thing I have produced in a while, with very few bugs that were rather easy to locate and to fix, and with a very clear design, which has not required any relevant changes since then.

So up to now I found it much more effective to get an overall picture of what I want to do beforehand than starting to write code in small increments in the hope that the big picture magically emerges in the process. With my best effort, the small-increment development approach has always led me to worse design.

Question: Has anyone had a similar experience? Am I applying SCRUM the wrong way or what should I pay attention to if I want to develop in small increments and still end up with a well-designed piece of software? Or should I schedule a design user story before starting the actual coding? Is this considered a good practice, at least for features that are more complex than average?

EDIT - NOTE

I am aware of the fact that good design is not something absolute and
does not have a value on its own but it depends on the context,
and that one should aim at a design that is good enough for the problem
at hand.

For example, I do not care (too much) about good design if I have to implement a simple component that (1) must be ready as soon as possible, (2) is going to be used only once, (3) is not used by other parts of the system (YAGNI).

I do care about good design when a component (1) will be used several times and in several different releases of a product, (2) needs to be maintained and extended over time, (3) has a lot of other components depending on it.

答: You always need the bigger picture of what the end goal should be, and what features are intended to be implemented and when, before you start a project. Working on stories as atomic tasks is asking for trouble. You need to keep future requirements in mind as much as possible.</p>


答:
"Well-designed" is subjective

What does "well designed" mean to you? to the Product Owner? to the Customer?

Is "well designed" a goal of the product owner? a goal of the customer? or just You?

Is what you consider "not well designed" still meeting the Product Owners expectations and making the customer happy? Then that is pretty "well designed".

Good Enough and YAGNI

Nothing in most Agile methodologies speaks of "well designed", because any system that the Product Owner accepts the stories as complete and the customers believe it meets their requirements is "well designed".

It is expected that the developers are professionals and will pragmatically use best practices, appropriate designs and idioms to implement the features and stories.

If you are not factoring in the time to do things correctly that is a developer problem, if the Product Owner is demanding things in less time that these can be done, it is their prerogative to do this, and your responsibility to educate them about the consequences in the form of technical debt stories.

SCRUM

The Agile Methodology that can be written down, isn't the Agile Methodology." - Jarrod Roberson

SCRUM is supposed to be a framework of tools to manage the total lifecycle of a software product. It isn't supposed to be a rigid set of things, just a good place to start and hopefully improve on.

Most shops I have worked in have what are called Sprint ZERO, Sprints for the senior members of the team to sketch out an overall architecture or theme of the product.

Stories that are larger than say 20 usually get broken down until they are actually a few 3 - 5 point Stories. One of these stories is, "As a team we need to meet to discuss how we are going to design this feature, so that we will have as little technical debt as possible given the time allotted."

Generally

In general a "well designed" system, is Good Enough and follows YAGNI.

Agile, and SCRUM in particular as an implementation of Agile are more about how to produce a product as transparently as possible to the Product Owner / Sponsors.

It isn't about anything technical design/architecture wise. It is more a philosophy about how to approach delivering software that meets the customers needs and expectations. If there isn't what you call "well designed" parts, that is not a failing per se, as it is not a fundamental part of the philosophy.

Title: How to get good design when using agile methods?

Body:
I have been using an agile methodology (SCRUM) for about three years now and I see certain advantages to it, especially in the short-term feedback at many levels (from customers having early access to implemented features, from testers that can test features as soon as they are implemented, from other developers that can provide very early feedback on new code through review, etc).

On the other hand, I have two open problems, the first of which I will try
to explain in this question.

Problem : Difficulty to get a good design

I try to do refactoring as soon as the code gets messy, I write unit tests as much as I can (which does help to prevent bugs in general and when refactoring in particular). On the other hand, developing some complex feature in small increments, with daily commits and continuously rethinking the code when it gets unstructured is not allowing me to produce really good design.

The only well-designed module I could produce recently I obtained by taking a different approach: I analyzed the problem for a few days (I actually had had the problem going through my mind for a couple of months before I started to work on it seriously), sketched a rather detailed design of all the involved classes and their relationships for a couple more days, and then locked myself up in my office and wrote down the whole code by working without interruption for about three weeks. The result was the best thing I have produced in a while, with very few bugs that were rather easy to locate and to fix, and with a very clear design, which has not required any relevant changes since then.

So up to now I found it much more effective to get an overall picture of what I want to do beforehand than starting to write code in small increments in the hope that the big picture magically emerges in the process. With my best effort, the small-increment development approach has always led me to worse design.

Question: Has anyone had a similar experience? Am I applying SCRUM the wrong way or what should I pay attention to if I want to develop in small increments and still end up with a well-designed piece of software? Or should I schedule a design user story before starting the actual coding? Is this considered a good practice, at least for features that are more complex than average?

EDIT - NOTE

I am aware of the fact that good design is not something absolute and
does not have a value on its own but it depends on the context,
and that one should aim at a design that is good enough for the problem
at hand.

For example, I do not care (too much) about good design if I have to implement a simple component that (1) must be ready as soon as possible, (2) is going to be used only once, (3) is not used by other parts of the system (YAGNI).

I do care about good design when a component (1) will be used several times and in several different releases of a product, (2) needs to be maintained and extended over time, (3) has a lot of other components depending on it.


答:
It is very possible to implement in small increments and end up with well-structured maintainable code.  In theory, it's very simple: if you ensure that the code is well-structured after each change, it will always be well-structured.  Your code is becoming poorly structured because you are continuing to add code when you should be refactoring.

No matter how much time you spend on design, eventually the requirements will change in some unanticipated way and you will have to write code that does not fit the original design.  Then you will have to make an incremental change.  If you have a good set of unit tests, and are skilled at refactoring, then you will be able to keep the code well-structured as you meet new requirements.


答:
In my humble opinion, it doesn't help much.

I used to know x86 assembly very well.  It helped a little when assembly came up in my courses, it came up once during an interview, and it helped me prove that a compiler (Metrowerks) was generating bad code.  It's fascinating how the computer actually works, and I feel intellectually richer for having learned it.  It was also very fun to play with at the time.

However, today's compilers are better at generating assembly than almost anyone on almost any piece of code.  Unless you're writing a compiler or checking that your compiler is doing the right thing, you are probably wasting your time by learning it.

I admit that many questions that C++ programmers still usefully ask are informed by knowing assembly.  For example: should I use stack or heap variables? should I pass by value or by const reference?  In almost all cases, however, I think that these choices should be made based on code readability rather than computational time savings.  (E.g., use stack variables whenever you want to limit a variable to a scope.)

My humble suggestion is to focus on skills that really matter: software design, algorithm analysis, and problem solving.  With experience developing big projects, your intuition will improve, which increases your value much more than knowing assembly (in my opinion).

OwnerDisplayName: Артём Царионов


问:
Rails application - how to optimize/reduce database calls when iterating over a collection
What's the best way to optimize a Rails app where you need to pull info from the database for a collection of items?

For example, if I am building an online forum system... I would have a number of Posts and the posts would have_many :recommendations and :comments and :favorites. When I display the posts in my view, I might need to display this info - like a count of how many comments there are, and whether or not my current user has favorited/recommended the post.

I was playing around with this and it seems there are a huge number of DB queries being executed! First I'm grabbing my collection of posts - then, iterating through each one, I am going to the comments table, the favorites table, etc... to get counts or see if records exist for that particular post. So for every post I have, I'm executing 3 separate queries!

Is there a more efficient way to get this data, or are tons of queries like this normal for a scenario like I describe?

答:
If information like how many comments, up-votes, favorites a post have is frequently used, you are better off storing these counts somewhere; querying the DB every time for number of comments in a post, number of followers a user have, etc. may quite soon become your performance bottleneck.

Two common approaches exist:

Add column/field for Posts in the database that store the comment count. when new comments are added, increase that counter field by one (synchronously), or update that count every hour/day (asynchronously).

Use cache (memcache, redis) to store those numbers to reduce database queries. Memory cache are usually required for high traffic sites, anyway.

Either way you can weave it into your ORM / Abstraction Layer, so there won't be too much additional code involved. For advantages/disadvantages, there are plenty of discussions/debates around this issue on the net. Google it for thorough and detailed explanations :)


问:
Why do we need to put N before strings in Microsoft SQL Server?
I'm learning T-SQL. From the examples I've seen, to insert text in a varchar() cell, I can write just the string to insert, but for nvarchar() cells, every example prefix the strings with the letter N.

I tried the following query on a table which has nvarchar() rows, and it works fine, so the prefix N is not required:

```<code>insert into [TableName] values ('Hello', 'World')
</code>```

Why the strings are prefixed with N in every example I've seen?

What are the pros or cons of using this prefix?

答:
Edit: Microsoft finally introduced UTF-8 support in SQL Server 2019 (15.x).  So this answer, originally posted in 2012, is outdated.

Because MS SQL Server has poor support for UTF-8 compared to other RDBMS.

MS SQL Server follows the convention, used within Windows itself, that "narrow" strings (char in C++, CHAR or VARCHAR in SQL) are encoded in a legacy "code page".  The problem with code pages is that they have a limited number of characters (most are single-byte encodings, which limits the reportoire to 256 characters) and are designed around a single language (or group of languages with similar alphabets).  This makes it hard to store multilingual data.  For example, you can't store both Russian and Hebrew data because Russian uses code page 1251 and Hebrew uses code page 1255.

Unicode solves this problem by using a single giant coded character set with room for more than a million characters, enough to represent every language in the world.  There are several Unicode encoding schemes; Microsoft prefers to use UTF-16, for historical reasons.  Because UTF-16 represents strings as a sequence of 16-bit code units instead of the traditional 8-bit, a separate character type is needed.  In MSVC++, this is wchar_t.  And in MS SQL, it's NCHAR or NVARCHAR.  The N stands for "national", which seems backwards to me because Unicode is about inter-nationalization, but that's the ISO terminology.

Other SQL implementations let you store UTF-8 text in a VARCHAR column.  UTF-8 is a variable-length (1-4 bytes per character) encoding that's optimized for the case when your data is mostly in the Basic Latin range (which are represented as the same 1 byte per character as ASCII), but can represent any Unicode character.  Thus, you'd avoid the "twice as much space" problem mentioned by bwalk2895.

Unfortunately, MS SQL Server does not support UTF-8 VARCHAR, so instead you have to either use UTF-16 instead (and waste space for ASCII text), use a non-Unicode code page (and lose the ability to represent foreign characters), or store UTF-8 in a BINARY column (and deal with inconveniences like SQL string functions not working properly, or having to view the data as a hex dump in your GUI DB manager).

ContentLicense: CC BY-SA 4.0


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

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

答:
Computer Science is no more about computers than astronomy is about telescopes

— Edsger Dijkstra

LastEditorDisplayName: Roger Pate


问:
How to teach Exception Handling for New Programmers?
How do you go about teaching Exception Handling to Programmers. All other things are taught easily - Data Structures, ASP.NET, WinForms, WPF, WCF - you name it, everything can be taught easily.

With Exception Handling, teaching them try-catch-finally is just the syntactic nature of Exception Handling.

What should be taught however is - What part of your code do you put in the try block? What do you do in the catch block?

Let me illustrate it with an example.

You are working on a Windows Forms Project (a small utility) and you have designed it as below with 3 different projects.

UILayer

BusinessLayer

DataLayer

If an Exception (let us say of loading an XDocument throws an exception) is raised at DataLayer (the UILayer calls BusinessLayer which in turns calls the DataLayer), do you just do the following

```<code>//In DataLayer
try {
    XDocument xd_XmlDocument = XDocument.Load("systems.xml");
}
catch(Exception ex)
{
    throw ex;
}
</code>```

which gets thrown again in the BusinessLayer and which is caught in UILayer where I write it to the log file?

Is this how you go about Exception Handling?

答:
Like most things, exceptions and exception handling will likely seem like a solution in search of a problem to new programmers until you show why the seemingly simpler solution (C-style return codes and errno) works so poorly.  I would start out by motivating the problem and putting it in context.  Show how error handling could be done using return codes or global/static variables.  Then give examples of why it doesn't work well.  Then and only then, introduce exceptions and explain that they're a form of out-of-band signaling and that the whole point is that the default behavior if you ignore an exception is to pass the buck up the call stack to someone who can handle it.

Bottom line:  Showing how error handling was done in C will make the students understand what exceptions are really for and why catching exceptions that you can't really handle is basically simulating the way things were done in the Dark Ages.


答:
We've been working with scrum for several months, and I want to share my experience concerning your problem.

A few months ago I was given a big piece to implement. I had all the specifications ready, so I had to implement new features accordingly. The task was to take about 5-6 weeks (as I estimated). I spent the first week working on design only. The task was a little complicated: there was a main object which, as I concluded from the spec, had 15 different states, and the UI was to have different behaviours for every state.

I designed the whole workflow, and DB structure and classes afterwards.

I don't see any other approach in my case. If I dived into coding at once, I would have got a big nasty mess at the end _ almost impossible to maintain and extremely difficult to make any further changes. But the changes came in the next 2 weeks, so I had to rework the code. This was easy now, with the initial thought-out design. This saved our time, money and nerves.

After this experience I'm absolutely sure that its worth making an acceptable design in the beginning, than hope that with some miracle you'll have it at the end.


问:
Cannot understand a certain point in Agile Manifesto Principles
I was reading Agile Manifesto Principles. Everything seems clear and reasonable except for one point:

Simplicity--the art of maximizing the amount of work not done--is
  essential.

I dont understand this. Does this mean that the work that wasn't done should be somehow exaggerated? If so, it doesn't really make sence.

答:
The idea is to avoid doing work that's not necessary, i.e. "maximize the amount of work not done".

So if in a traditional project you would plan and build a great abstract base system to allow for all your possible needs later one, you just skip that and build the simplest thing that can possible work for the current requirements. Don't build stuff that you don't need.

YAGNI is a related concept.


问:
Version control management of large projects
I'm used to version control, in particular I currently use Mercurial. I have some doubts about how to make it work in large teams, where there is a good probability of having more people working on the same file.

Let me make an example with Mercurial (but any decentralized system will be more or less the same). Say we have a central server and three developers Alice, Bob and Carl. The three decide to start working at the same moment and they all pull from the server. By chance it happens that they are working on the same file.

Alice finishes first, and push her changes to the server. Then both Bob and Carl finish, more or less at the same time. Before pushing, they check whether there is something new, and find Alice's commit. So they pull it, and each one merges the changes locally. Then Bob pushes it and Carl pushes its changes.

What happens here is that on the server there are two heads: one by Bob and one by Carl, and both include merges with Alice's work. Whoever now pulls from the server will find a little mess. Of course one can just merge Bob and Carl heads, but that may not be as simple. Bob and Carl may have had different ideas on how to merge with Alice's work.

As soon as more people start working on the project, things can go even worse. So, while in theory I understand how merges are supposed to work, it is not clear to me how to make things manageable in a large project.

How do people manage to resolve conflicts when there are many people working on the same file, possibly having done different merges in different orders?

答:
I don't know if mercurial supports this, but in a small cohesive team, the centralized workflow may be the best. In this workflow developers have to update/pull from the central server first before they can push a new commit.

In larger or distributed projects, I recommend the gatekeeper workflow:

The developers do not merge from each other. The gatekeeper merges developer branches into a branch designated as the official branch.

Developers work on feature branches, and when a feature is done they propose to the gatekeeper for merging.

The gatekeeper has good overall understanding of the project. If merging a branch results in conflicts, he may need help from the developer to sort them out, but maybe not, as the conflicts should be caused by a merge proposal he recently approved himself.

The gatekeeper is also in charge of the quality of code and project-wide best practices. He rejects merge proposals that have any problems, the original developer should perform any necessary fixes and resubmit his branch.

Being a gatekeeper is a full-time activity.

As the project grows larger, there can be more gatekeepers, forming a hierarchy.


答:
On the other hand, developing some complex feature in small increments, with daily commits and continuously rethinking the code when it gets unstructured is not allowing me to produce really good design.

Then don't do that.

Not everything fits into the nice agile box. Often times a product will have a few complex things that can't be farmed out to individuals and cannot be completed in any sane manner within a sprint. Forcing them into that box will only cause trouble. But these should be few and far between. If you find that many of your components are like this, your product owner needs to work at breaking things up better (with your team). I am fine doing like what you did: take the story, design it, then hammer it out ASAP with the expectation that it will take a few weeks.

In the more general case, there are 3 things that I've seen done for getting good design in Agile:

Actually do design - A lot of places I've seen start their sprint and just start cowboying out code. You'll get bad design this way. Agile doesn't change the development process of plan - code - test - release, it just shortens it to more granular pieces. At the beginning of the sprint, sit down as needed and actually design your solution.

Have an architect/lead - Once your project is big enough, you'll end up with multiple scrum teams working on different pieces of the application. It is very useful to have someone (or multiple people depending on the size of the application) whose primary job is to know what all of the teams are doing from a design standpoint. They can answer questions and guide the teams towards a more harmonious over-arching design. Having each scrum team have a lead that knows most of what other teams are doing I've also seen and was very effective.

Be a pragmatist - I covered this one above. Agile is a tool, and like any tool; it doesn't apply to all problems. If it doesn't make sense to apply to some component, then don't apply it there. Your goal is to ship good software; don't forget it.


问:
How to run thread if multiple data is insert in the multiple table
I'm facing problem in gsoap , if two user go to register
    at a same time then database is<br>
    locked, i think its threading problem ,
    how to handle it, please insist me. I am running multiple threads in background. every 5 seconds sending data to server. </p>

答:
Generally speaking, when working with a database it should be set up so you don't have to worry about things like that.  As EIYusubov suggested, you need to look into the code you are using for for DB access.  What types of reads and writes are you requesting?

(Most) DBs are intended to be multi-user and multi-threaded / multi-session.  Sending data every five seconds (as suggested by Tech.Rahul) is or should be nothing to a DB server, and you shouldn't have any lock contention.

It's possible you could have a case where one user is getting stale data.

```
User A @ 4.9 seconds - retrieves dataset XYZ^1
User B @ 5.0 seconds - updates dataset XYZ^1 to become => XYZ^2
User C @ 5.1 seconds - retrieves dataset XYZ^2
```

Note: times in the example are just arbitrary

So User C wouldn't have what User A is looking at, but that' not going to cause a deadlock situation as you described.  Given the short amount of time elapsed between User A and User C, then User A could be said to be looking at dirty data.

Body:
Generally speaking, when working with a database it should be set up so you don't have to worry about things like that.  As EIYusubov suggested, you need to look into the code you are using for for DB access.  What types of reads and writes are you requesting?

(Most) DBs are intended to be multi-user and multi-threaded / multi-session.  Sending data every five seconds (as suggested by Tech.Rahul) is or should be nothing to a DB server, and you shouldn't have any lock contention.

It's possible you could have a case where one user is getting stale data.

User A @ 4.9 seconds - retrieves dataset XYZ^1
User B @ 5.0 seconds - updates dataset XYZ^1 to become => XYZ^2
User C @ 5.1 seconds - retrieves dataset XYZ^2

Note: times in the example are just arbitrary

So User C wouldn't have what User A is looking at, but that' not going to cause a deadlock situation as you described.  Given the short amount of time elapsed between User A and User C, then User A could be said to be looking at dirty data.


问:
OSS - GPL v3 plugins in non-copyleft codebase.
I've been working on software to modify a game's resource files, and I'm planning on releasing it in open source.  I'm perfectly fine with releasing my code under gpl v3.  However, I'm afraid that that would deter others from writing extensions for my software, as I have had others offer to do so - the community which I'm working with is very much afraid of open source leeches, and as a result, the majority of popular released projects are closed source.  As such, I'd be more comfortable with something like BSD or MIT.

The codebase is extremely modular, and one window might consist of the end products of many different plugins.  One plugin which I am working with is the work (licensed under gpl v3) of a person who I have communicated with, who was enthusiastic of me using his software.  As one other person has contributed to that software, I don't think he can simply release his source to me under a different license.  In the future, I'd like to have more plugins for a variety of things which would be difficult to manually implement (as doing so would require large amounts of reverse engineering).

Tl;dr: As I am in good terms with these people, is there any means for me to use their code as plugins?  I would have permission, but licensing would be the issue, since others have contributed to the codebases.  If so, would it be okay if i distributed their plugins with my built software (in a plugins folder)?  How about placing them in the code repository and visual studio solution?

Any other advice would be appreciated.

Thanks!

答:
You need to ask and see how the copyright assignment (if any) was setup for those other projects.  If the lead for the other project had copyright assigned to him or the project, then he would be able to release the code to you for use under a different license.

The copyright owner is allowed to re-release code under a different license.  In the case of a GPL'd project, the GPL'd version of the code is allowed (and must!) continue to exist as such.  The only real concern there from your point of view is you potentially have a competing codebase.  From what you've described, that doesn't sound like all that much of an issue.

If necessary, the owner of the other project can contact the other contributor to gain permission to re-release.  Likewise, if the other contributor previously wrote an email to the effect of "Here, have it and do with it as you wish", then they have effectively assigned copyright to the owner of the project.

Your straits are not as dire as they may appear.  :-)


问:
async & await - poll for alternatives
Now that we know what is in store for c#5, there is apparently still an opening for us to influence the choice of the two new keywords for 'Asynchrony' that were announced by Anders Heijsberg yesterday at PDC10.

```<code>async void ArchiveDocuments(List<Url> urls) {
    Task archive = null;
    for(int i = 0; i < urls.Count; ++i) {
        var document = await FetchAsync(urls[i]);
        if (archive != null)
            await archive;
        archive = ArchiveAsync(document);
    }
}
</code>```

Eric Lippert has an explanation of the choice of the current two keywords, and the way in which they have been misunderstood in usability studies. The comments have several other propositions.

Please - one suggestion per answer, duplicates will be nuked.

答:
I think async is fine, but maybe that's because I associate it with ASP.NET async pages - same idea.

For the await keyword I prefer continue after or resume after.

I don't like yield or any of its variants, because the semantics are such that the method may never actually yield execution; it depends on the state of the task.

Title: async & await - poll for alternatives


问:
How many make threads to use?
When I (re-)build large systems on a desktop/laptop computer, I tell make to use more than one thread to speed up the compilation speed, like this:

```<code>$ make -j$[ $K * $C ]
</code>```

Where $C is supposed to indicate the number of cores (which we can assume to be a number with one digit) the machine has, while $K is something I vary from 2 to 4, depending on my mood.

So, for example, I might say make -j12 if I have 4 cores, indicating to make to use up to 12 threads.

My rationale is, that if I only use $C threads, cores will be idle while processes are busy fetching data from the drives. But if I do not limit the number of threads (i.e. make -j) I run the risk to waste time switching contexts, run out of memory, or worse. Let's assume the machine has $M gigs of memory (where $M is in the order of 10).

So I was wondering if there is an established strategy to choose the most efficient number of threads to run.

答:
I ran a series of tests, building llvm (in Debug+Asserts mode) on a machine with two cores and 8 GB of RAM:

Oddly enough, it seems to climb until 10 and then suddenly drops below the time it takes to build with two jobs (one jobs takes about the double time, not included in the graph).

The minimum seems to be 7*$cores in this case.

Title: How many make threads to use?


问:
Use verbs with functions, nouns with classes - what about interfaces?
Ok, I understand the normal conventions of using verbs with functions and nouns with classes. What about interfaces? Is there any methodology when coming up with interface names that may not be that obvious?

Just to make it clear, I'm not talking about whether to put an "I" in front of the name or if to use camelCase or PascalCase. I'm wondering about the method of figuring out a clear, semantic name for an interface.

EDIT
I'm obsessing on how to name an interface in the clearest way. I guess it just needs to be a noun too because when I think of naming classes I think of the closest "real" world object it can relate to. I suppose real world interfaces are things like a keyboard, mouse, remote control, ATM screen. Those are all nouns. Anyhow, any additional insight on a good way to formulate interface names would be appreciated.

答: An interface is used like a class. Therefore, it should also be named with a noun when you name classes with nouns. Prefer abstract nouns, for example "Vehicle" when the classes are "Car" and "Truck".</p>


答: Since an interface is really just an expression of the "what" but not "how" of a type, I would name them in the same way that you name classes, at least from a parts of speech perspective.  The only thing I might add to this is that they're often going to be more general than the specific implementers (e.g. "Customer" interface may have "ProspectiveCustomer" and "PayingCustomer" implementers).  </p>

Title: Use verbs with functions, nouns with classes - what about interfaces?

Body:
Ok, I understand the normal conventions of using verbs with functions and nouns with classes. What about interfaces? Is there any methodology when coming up with interface names that may not be that obvious?

Just to make it clear, I'm not talking about whether to put an "I" in front of the name or if to use camelCase or PascalCase. I'm wondering about the method of figuring out a clear, semantic name for an interface.

EDIT
I'm obsessing on how to name an interface in the clearest way. I guess it just needs to be a noun too because when I think of naming classes I think of the closest "real" world object it can relate to. I suppose real world interfaces are things like a keyboard, mouse, remote control, ATM screen. Those are all nouns. Anyhow, any additional insight on a good way to formulate interface names would be appreciated.


答:
I'd say it depends on what the interface defines. In some cases when the interface is rather specific and detailed, I think a noun is best. Examples are IList, ICollection.

Sometimes though an interface is more about adding certain general features to a class. In that case I think an adjective is best. Examples are IDisposable, IEnumerable, ...

Maybe another way to think about this is how many "abilities" your interface defines.

For example, the IList<T> interface defines these abilities: Add, Clear, Contains, Insert, Remove, ... These are all properties of a list so IList is a good name.

IDisposable on the other hand only defines one ability: Dispose. So it is suited for anything that is disposable. Hence the name IDisposable.


答:
Quick Answer: Interface is more about addition of a SET of abilities, features, common boundaries or interconnections between entities, classes, models, concepts, etc..

Thing about adding common behavior to classes and entities, and then a good meaningful name will come up to identify the set of realted features.

Interface Naming like : IStateMachineBuilder, IUserContextProviderBuilder, IEntityBuilderBuilder, IActiveAware, etc. probably explain the concept.


问:
Company PC refresh, laptop or desktop?
My company is getting PC refreshes with a choice of to have a desktop or laptop.  Each one seems to have its pros and cons. Would you want the flexibility and freedom of the laptop but take the risk of working extra hours at home? Or a desktop limited to one place, but not having to worry about taking work home and disrupting home time?

I'm not asking what would be better for coding, but more for convenience and productivity.  I currently have a desktop and work about 8 to 9 hours a day, with only coming in on the weekends for when we get behind on major deadlines. I love developing but I also have quite a busy life after work. I feel that having a work laptop will only haze the line of work and home.

答:
If you can connect remotely, you probably don't need a laptop. I worked at a company where only company issued computers could connect to the VPN, so I went with a laptop.

A laptop is useful when commuting on public transportation.

Someone mentioned meetings. I'm amazed how often we revert to the paper-age when it comes to meetings. But having to print out the agenda is much better than a powerpoint presentation.

Title: Company PC refresh, laptop or desktop?


问:
Can applications affect power consumption in a substantial way?
Is there anything that can be done for a single general purpose application to affect the power consumption of the device it is running on?

I am not familiar with how optimizations to individual applications may affect power consumption in a general way, can someone explain if different approaches to writing applications affect power consumption of the device they are running on?

That is, can a single program, that does the exact same thing functionally, written in different ways drastically affect the power consumption of a device in general, not about how different un-related programs might affect the power consumption of a device.

答:
While it is true that in terms of the CPU there isn't much to be done, there are often features of the device that consume power when used.  On a PC, mostly no one cares, but it is definitely true that a disk read will (assuming non-SSD drives) cause the hard drive to spin and the head to move, which will consume some bit of power.  On a PC this is trivial, but on a mobile device, this can be a very real issue.

On a phone, the most obviously example of this is communications.  Sending a wireless signal takes energy.  On a PC, connected to a 500 WATT power supply, it is inconsequential.  On a phone, it is not.  An application that constantly polls a server for large amounts of data will use dramatically more power than one that uses no network at all.

This is a very real issue, just google for "Android application drained my battery".  Here is one of many pages telling developers how to minimize power consumption.

In general, you want to optimize for performance in general (i.e. make the CPU as much as possible) and also for network usage.  Communicate as little as possible with as small messages as possible.

As others have said, this is a task for after most of your code is complete, when you've identified an issue and profiled power use.


答:
This idea is very similar to a concept from the Toyota Production System (TPS), which led to the more generic Lean Manufacturing and then the application of those techniques to Lean Software Development. The TPS significantly predates the agile movement, with its roots in manufacturing in the late 1950s.

The concept of maximizing the amount of work not done is similar to eliminating waste. In the manufacturing environment, waste includes things like overproduction of goods, waiting for resources, unnecessary movement of people or products, too much inventory, and defective products. In Lean Software Development, these wastes were translated into unnecessary functionality, delays in the development process, unclear requirements that slow the production of software, a lack of testing, and communication delays.

The overall idea of both concepts is the same - things that don't add value are wasteful and should be minimized. The ultimate goal is to increase quality while reducing time and cost to produce.

Title: Cannot understand a certain point in Agile Manifesto Principles

Body:
I was reading Agile Manifesto Principles. Everything seems clear and reasonable except for one point:

Simplicity--the art of maximizing the amount of work not done--is
  essential.

I dont understand this. Does this mean that the work that wasn't done should be somehow exaggerated? If so, it doesn't really make sence.


答:
Remove the parenthetical comment. What remains is "Simplicity is essential", which by the way is an application of the principle to its expression itself.

Simplicity is essential, because you have distilled what you really need, removing what is making the task at hand heavier, less elegant: complex.

I have always interpreted in the sense of Pascal's take on brevity: "I would have written a shorter letter, but I did not have the time." You have to avoid what is unneded (from the letter, from the code) and this is an active task, and not an easy one. It is not something which happens by itself.


问:
Release Management versions control?
We recently experienced a deployment issue where it turned out that the version objects were not in sync in one of the environments.

We have a large database group and different teams have different responsibilities and ownerships - I might code on schema X, Y, Z but I also will have dependancies on objects owned by other groups. This is the same no matter what technology - java libraries having different versions and what not.

My aim is to have something be in a webpage or a database table or something that I can see that for object A I have version X installed in Production, X + 1 in UAT and QA, and X + 2 installed in DEV.

How do other folks handle this? How do you pick up version changes? Do you rely on SCM? Build numbers? Hash value of the source code?

I'm interested in managing version consistency across technologies - java to db for instance.

答:
Quick Answer: The easiest way would be setting build-tags/value (application code, database schema version, dependencies, etc..) in your Database or app.configuration, and directly reading from there when application is starts.

Each build need to have a pre-generated label attached to the build.

Example of Application version-ing from VS perspective -  Versioning Controlled Build

Example of build process for Python project - Your Version Control and Build Systems Don’t Scale

Title: Release Management versions control?


问:
In what specific ways did Pascal and or Delphi influence Java?
I was reading in the side bar of the Java language wiki page and it says it was influenced by Pascal and Delphi.
this isn't the fact anymore, there are no references to Delphi on the entire referenced wiki page as of this edit, probably should remove all references to Delph from this question as well

At first glance Java appears to just be C++ with a garbage collector, and no pointers. Delphi and Java both came out the same year.

I am curious if someone who knows Java and Pascal / Delphi really well could look at Java and say "Feature X in Java is influenced by feature Y in Pascal (or Delphi)."

Additionally was the influence in later versions of Java (so the feature from Pascal or Delphi didn't show up until Java version Z), or was it actually in the seeds of the Java language? Delphi and Java both came out the same year, so Delphi's influence in the genesis of Java seems less likely.

Alternatively it may be that Delphi or Pascal influenced the Java Platform in some other way, and not the language specifically.

[This was rewritten to be clearer. That may have changed the scope of the question to the point the existing comments and answers don't fit. My intention was to clarify and not change.]

答:
One definitive influence on java was the idea and use of p-Code (pseudo-code) in the Pascal package from UCSD. It was popular in the early days of the Apple-II computer.

This idea of p-Code is very similar to that of Java.


问:
How does learning assembly aid in programming?
I have been programming in higher level languages (Python, C#, VBA, VB.NET) for around 10 years and I have completely zero understanding on what's going on, "under the hood."

I am wondering what are the benefits of learning assembly, and how will it aid me as a programmer? Can you please provide me with a resource that will show me exactly the connection between what I write in higher level code to what happens in assembly?

答:
Unless you are a compiler writer, or need something highly optimized (like data processing algorithm), learning assembly coding will provide you no benefits.

Writing and maintaining code written in assembly is very difficult, therefore even if you know assembler language very well, you shouldn't use it, unless there are no other ways.

The "Optimizing for SSE: A Case Study" article shows what is possible to do if you go to assembly. The author managed to optimize the algorithm from 100 cycles/vector to 17 cycles/vector.

OwnerDisplayName: Артём Царионов


答:
If you know a language well, you should have at least basic knowledge of the technology one level of abstraction lower.

Why? When things go wrong, knowledge of the underlying mechanics makes it far easier to debug strange problems, and naturally write more efficient code

Using Python(/CPython) as an example, if you start getting weird crashes or poor performance, knowledge of how to debug C code can be very useful, same with is knowledge of it's ref-counting memory management method. This would also help you know when/if to write something as a C extension, and so on...

To answer your question in this case, knowledge of assembly really wouldn't help an experienced Python developer (it's too many steps down in abstraction - anything done in Python would result in many many assembly instructions)

..but, if you are experienced with C, then knowing "the next level down" (assembly) would indeed be useful.

Similarly, if you are using CoffeScript then it's (very) useful to know Javascript. If you are using Clojure, knowledge of Java/JVM is useful.

This idea also works outside of programming languages - if you are using Assembly, it's a good idea to be familiar with how the underlying hardware functions. If you are a web-designer, it's a good idea to know how the web-application is implemented. If you are a car mechanic, it's a good idea to have some knowledge of some physics

OwnerDisplayName: Артём Царионов


问:
What are the major differences between OpenGL ES 2.0 and 1.x?
I have to learn OpenGL and get a basic OpenGL app built, and I have a few questions:

What are specific things programmers need to know to program in these frameworks?

How does the shader language in 2.0 affect using these libraries?

Are there any compelling reasons to start with 1.x before 2.0?

答:
As already mentioned OpenGL 1.x and 2.x are very different.

OpenGL ES 1.0 uses a fixed pipeline, which is a fancy way of saying you use built-in functions to set lights, vertexes, colors, cameras, and more.

OpenGL ES 2.0 uses a programmable pipeline, which is a fancy way of saying all those built-in functions go away, and you have to write everything yourself.

To get more info on topic with good tutorials, check resources listed below

Advanced Game Programming with OpenGL

OpenGL ES 2.0 For Beginners Tutorial

official link to OpenGL.org


答:
I would recommend learning algorithms: sorting, linked lists, binary trees, hashing, etc.

Also learn lisp see Structure and Interpretation of Computer Programs groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures this video course will teach you everything you need to know, including algorithms (how to do everything based on a few primitive commands, one lisp primitive and some assembler provocatives).

Finally if you must learn assembler learn an easy one like ARM ( also it is used in about 4 times more devices than x86).

OwnerDisplayName: Артём Царионов


问:
What technology/algorithm should be used to abstract meaning or keywords from a passage of text?
Hi and thanks for looking!

Background

I have a project wherein I need to abstract meaning from a passage of text to determine what the text is seeking and then match that text to a list of search results.

Now, I have some context with this and the following scenario is very close, but doesn't violate my NDA with the client:

Let's say I have a software developer job description from a posting on Craig's List.  I want to somehow parse that description and make a guess as to whether the posting is seeking a C# developer, a DBA, a SDET, a C++ dev, etc.  Even better, it would be good to distill certain parameters such as years/level of experience and experience with any particular stacks (.NET, Java, etc).

Once I have abstracted the requisition, I then need to reference a database of resumes (CVs) to find a ranked set of matches, probably using the same algorithm or at least a system of tags.

Question

How best do I attain this goal?  Should I be looking into building an index of keywords?  Natural Language Processing?  Evolutionary Algorithms?

We have to assume that human interaction will be very minimal.

Example Job Posting

Here is an example Job Posting that I have pulled at random from Craig's List:

We invite you to bring your career to an environment where talent is rewarded and new ideas are encouraged. At Seattle Children's, the Pacific Northwest’s premier pediatric care center, we offer more than just state-of-the-art facilities and open career growth potential. You will also find a true commitment to our patients and families that reach far beyond the bounds of clinical expertise.
  The Applications Development Senior position in the Center for Developmental Therapeutics will develop, test, standardize and implement software for high throughput data analysis. This includes system analysis, design, application support, research into standards, and customer/vendor relations management in support of production operations. For example, supporting the integration of different computational approaches into an end-to-end workflow for high throughput data analysis, including applications for proteomics and metabolomics. Participate in all phases of the project lifecycle, including architecture, design, development, alpha, beta, release and production support. The ideal candidate will have a Bachelor's degree in the field and a minimum of three years of experience with software development; working knowledge of JAVA, Spring, AJAX, JSF, Hibernate, JQuery, and JUnit; and solid experience with SQL tuning and understanding the execution plan will be key to this role.
  Please ensure to complete the job assessment questions right after you submit your application for this opening.
  Required:
  - Bachelor's Degree in Computer Science, Math, Business, or related field
  - Three (3) years software development experience
  - Working knowledge of JAVA, Spring, AJAX, JSF, Hibernate, JQuery, and JUnit
  - Solid experience with SQL tuning and understanding the execution plans
  - Strong understanding of multi-tiered web applications and scalability challenges
  Preferred:
  - Five (5) or more years software development experience
  - Experience developing large software systems
  - Experience with web services (HTTP, JSON, SOAP, XML), Unix/Linux environments, and distributed systems (HADOOP)
  - Experience in software and algorithmic development for molecular biology, biotechnology, microarrays or proteomics.
  We offer competitive pay, generous paid time off, transportation discounts, and employee reward and recognition programs.

Thanks!

Matt

答:
Generally, the language used in job ads is grounded and uses similar constructions all the time. Applying a complex NLP would be too much for it.

One possible approach is to match using tags assigned to job ads and resumes. A rule based system would be faster to implement for a limited data sets but might be harder to maintain, e.g. adding new keywords. Machine learning approach can be more flexible but needs a training set what means an additional cost.

Resumes and job ads usually use a little bit different phrases. Sometimes a candidate doesn't mention all technologies or mention a similar one. You can enhance your system by having a taxonomy of the keywords: parent keywords (Web technology -> HTML; CSS; JavaScript) or similar keywords ( Python <=> Ruby )

If you have an existing data for matching resumes to job ads, you can leverage it using machine learning. The system learns which phrases goes together, which keywords are or aren't important, plus you can define rules for extracting more specific features like the needed experience (junior, senior), offered experience (e.g. based on the details in experiences section of resume) and so on.


问:
How to get good design when using agile methods?
I have been using an agile methodology (SCRUM) for about three years now and I see certain advantages to it, especially in the short-term feedback at many levels (from customers having early access to implemented features, from testers that can test features as soon as they are implemented, from other developers that can provide very early feedback on new code through review, etc).

On the other hand, I have two open problems, the first of which I will try
to explain in this question.

Problem : Difficulty to get a good design

I try to do refactoring as soon as the code gets messy, I write unit tests as much as I can (which does help to prevent bugs in general and when refactoring in particular). On the other hand, developing some complex feature in small increments, with daily commits and continuously rethinking the code when it gets unstructured is not allowing me to produce really good design.

The only well-designed module I could produce recently I obtained by taking a different approach: I analyzed the problem for a few days (I actually had had the problem going through my mind for a couple of months before I started to work on it seriously), sketched a rather detailed design of all the involved classes and their relationships for a couple more days, and then locked myself up in my office and wrote down the whole code by working without interruption for about three weeks. The result was the best thing I have produced in a while, with very few bugs that were rather easy to locate and to fix, and with a very clear design, which has not required any relevant changes since then.

So up to now I found it much more effective to get an overall picture of what I want to do beforehand than starting to write code in small increments in the hope that the big picture magically emerges in the process. With my best effort, the small-increment development approach has always led me to worse design.

Question: Has anyone had a similar experience? Am I applying SCRUM the wrong way or what should I pay attention to if I want to develop in small increments and still end up with a well-designed piece of software? Or should I schedule a design user story before starting the actual coding? Is this considered a good practice, at least for features that are more complex than average?

EDIT - NOTE

I am aware of the fact that good design is not something absolute and
does not have a value on its own but it depends on the context,
and that one should aim at a design that is good enough for the problem
at hand.

For example, I do not care (too much) about good design if I have to implement a simple component that (1) must be ready as soon as possible, (2) is going to be used only once, (3) is not used by other parts of the system (YAGNI).

I do care about good design when a component (1) will be used several times and in several different releases of a product, (2) needs to be maintained and extended over time, (3) has a lot of other components depending on it.

答:
Hind-sight is 20-20. If you had the information at you disposal at the beginning of the project to figure the whole thing out and then write the code in a few weeks, I suggest you do it.

You are not giving enough credit to all of the insights you gained, the approaches that were tried and failed/had to be changed, and the increased ability of the client/users to provide requirements enough credit.

Why would anyone with a history of successful water-fall projects, switch to an agile methodology?


问:
Designing a library that is easy to use: composition or inheritance
I have designed a small library for work that consists of a few exposed classes. These can basically be thought of as a server class and client class. But now that I am writing all the test cases and examples, I am questioning myself on whether the classes should be used in a class or inherited.

I know about the composition over inheritance theology but at the same time, the OOP basics pop into my head: has-a and is-a relationships.

My main question is which makes more sense and which would make it easier for the programmers that use my library?

I have already ready numerous topics on SO and Programmers regarding this topic, none really target my question though:

Where does this concept of "favor composition over inheritance" come from?

Why should I prefer composition over inheritance?

Composition vs. Inheritance

答:
Programmers should favor composition over inheritance in OO languages, period. Unless your library has a compelling reason to make forced inheritance more natural/effective, then you should assume that people will consume your library via composition.

Especially as a library writer since changing a class that is being inherited will cause more failure (in general) than one that is being composed.


问:
Is 37Signals Basecamp a hype?
What's so unique about it? Heard great things about it, used it, found that beside the Google Apps Integration there's nothing really special about it. Maybe I just don't get it?

So, what's your reason to use basecamp?

答: I've used it a few times to organise groups for various aims and I would do so again. It's easy to use, easy to understand and it does stuff you need but not stuff you don't need. I just found it really easy to get along with.</p>

Title: Is 37Signals Basecamp a hype?


问:
Does there exist a decent monetary bounty system for open source software?
I personally would be willing to pay $10 to someone who can offer to make microphone drivers work with one of my laptops under Ubuntu 10.10. I thought that other users could contribute to the same thing, and thus find a willing developer. Does there exist such a project(s)?</p>

答:
At present, it seems as though there are three (3) active sites that are worth considering:

COfundOS

FOSS Factory

PubSoft: Public Software Fund, Inc. (It could be defunct as there has been nothing new in the News section since 2007).

See alternativeTo for confirmation and further details.  There have been several others, like BountySource, that are no longer in service.  There is also some information in Wikipedia (but it really needs updating).


问:
Does this BSD-like license achieve what I want it to?
I was wondering if this license is:

self defeating

just a clone of an existing, better established license

practical

any more "corporate-friendly" than the GPL

too vague/open ended

and finally, if there is a better license that achieves a similar effect?

I wanted a license that would (in simple terms)

be as flexible/simple as the "Simplified BSD" license (which is essentially the MIT license)

allow anyone to make modifications as long as I'm attributed

require that I get a notification that such a derived work exists

require that I have access to the source code and be given license to use the code

not oblige the author of the derivative work to have to release the source code to the general public

not oblige the author of the derivative work to license the derivative work under a specific license

Here is the proposed license, which is just the simplified BSD with a couple of additional clauses (all of which are bolded).

Copyright (c) (year), (author) (email)

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice, this    list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice,    this list of conditions and the following disclaimer in the
documentation    and/or other materials provided with the
distribution.

The copyright holder(s) must be notified of any redistributions of source    code.

The copyright holder(s) must be notified of any redistributions in binary    form

The copyright holder(s) must be granted access to the source code and/or the    binary form of any redistribution upon the copyright
holder's request.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

答:
IMO (3) and (4) are onerous.  After all, do you really want an email for every download?  Do you want to oblige distributors to create custom FTP/HTTP servers that send an email for every download?   Do the other copyright holders want to receive these notifications?   If I made an enhancement and distributed the result I'd be signing up for such notifications, and wouldn't want to receive that spam, however, people would be obliged to send it to me anyway.  How will parties redistributing the code in source or binary form even assure themselves they have successfully complied with these conditions?

Condition (5) is problematic because "the copyright holders" is going to be a large number of people (potentially), not just the original authors.  It is unclear to me how a redistributor can even be certain that they have successfully "granted access" to all copyright holders.  That is, I'm not certain that a party acting in good faith can even be sure they're in compliance.

The license appears to be drafted as if you will be the only "copyright holder".   That is, it's an attempt at an open source license for a project you're assuming will be unsuccessful as an open source project.  In other words, you seem to be assuming that there will be few contributors.

Frankly complying with this license would such a pain in the ass that I'd just prefer not to use the code at all, or even distribute it, even if it did appear to be potentially useful.


问:
How to develop front end (UI) for my Django website
I am learning Django and new to web development. Please excuse me if you find this question too dumb.

So, I am creating a Facebook application using Django which I would like to host in Google App Engine. The project would be focusing on reading RSS/ Atom feeds of any website (That's all I can say now).

I am sure enough to process the RSS/Atom files but I am worried about the front end (User Interface) part - "The design part". I don't know HTML/ CSS/ JavaScript (I can handle simple HTML stuff but that doesn't lead to any designing thing).

First, I thought of using tools like dreamweaver or any equivalent software for designing UI but when I really started learning django and getting into it, It seems to be a "not possible" thing.

So,

How should I design the UI part of my site? Can't I use tools like dreamweaver?

If NO, what's the best way for guy like me who doesn't know JavaScript/ CSS

If YES, what's the best open source alternative to dreamweaver?

Can Google App Engine handle all this suff?

How people who deal with Django edit those template pages. The Django mentions the it will separate the logical (views) and design (templates) parts so that different departments in a company can handle separately. But Considering the fact that the Django's HTML pages are filled with "tags" which are no way related to HTML (designing), how UI people handle it?

答:
What I do is I either design a layout in dreamweaver, or hire a designer to create HTML "wireframes" with fake data, then I go over it and use Django's (or Jinja's) template tags to make it into a working template. I know some HTML, but I would never be able to make anything attractive. Functional? Yes! Pleasant to look at? Glob No!

So, in conclusion; With just some basic knowledge of HTML, you can modify a pre-made HTML document to work as a template.


问:
How to get experience in large scale databases?
I have written applications that are very small scale and the code I write works fine for them. But I have often wondered how the server side code I write would scale up from 100s of queries per day to millions.

Also when looking at possible jobs/projects, people are often looking for developers with experience in this sort of high traffic database design so I would at least like to be able to  say, I havent gotten to work on a project that was this popular, but I at least have tried to simulate it.

Are there tools or frameworks that can generate a lot of traffic or at least simulate what would happen with traffic on different orders of magnitude so I could get some practice writing optimized code for higher traffic applicaitons?

答:
This is a common problem not only for people who have written applications that are very small scale, but also for those who did actually write large scale apps and are not able to test them.  The lack of a testing environment (a very large database or data files) is often amongst developers.
For example, I worked on a few different projects that were time limited:

An SQL Loader which was supposed to load 15 milion rows into a table (200 columns) in less than 10 minutes. Of course until a 100 MB file from SAS platform was provided it was impossible to test the loader. Only after that I could set the right loader parameters (commits, bindsize etc..)

An UPDATE on the same table with some very complicated rules (joining other 3-4 tables depending on the data that already exists) to run in 5 minutes. Of course I needed real data into the table and I couldn't fake the same row milions of times. How could I have known how fast the procedure completed without the data? After that I tunned the procedures using MERGE instead of UPDATE, deterministic functions etc..

So what I'm trying to say is that you shouldn't worry about this because you'll deal with it when the time is right. It's difficult to simulate real complex data but I'm sure that's not going to be a key skill in your employer's eyes.