答:
Great Question.

It is important to distinguish between 'Development' and 'R&D.'

Point 1

R&D = experimenting with ideas/technology that may  never actually
become a product.

Software Development = working on a product/service desired by a real
customer.

Point 2

R&D is all about developing new solutions for a specific problem
domain.  The end result of this endeavor is something that I call
"research toys".

To be a software product, the research toy has to be completely
re-implemented.  Failure to do so will result in a product that
appeals to an increasingly elite and erudite user base.  The problem
here is that this elite and erudite user base typically has no money
to spend.

To be a successful, the software product must be a faithful
re-implementation of the research toy, accessible and loved by the
commodity user.  To be truely remarkable, the software product must
simultaneously appeal to the elite and erudite user.

Point 3

Research implies scholarly or scientific inquiry and tends to be aimed
at the greater good of an industry or society at large. Product
development has different motivations and outcomes: it is driven by
the potential for profit. The state of product development is healthy.
The state of lighting research is not.

We need a collective commitment to the greater good to answer such
questions. But this is not just philanthropy; the answer would address
a practical goal. Light sources that are spectrally tuned to the
visual system will be more sustainable. They will use less energy by
generating their output in regions of the spectrum where the visual
system responds most strongly, resulting in better seeing for building
users. This example reinforces the difference between research and
product development.

Point 4

All development of new products to be R&D. I think some of you are
confusing pure, abstract science with R&D. They aren't the same. R&D
can be very product oriented. Scientists may be looking for a vaccine
to cure AIDs. That is a very specific task to create a product to sell
and it is certainly R&D and not just guys sitting around messing
about with whatever they feel like.

Point 5

R&D in the technical world = finding ways to do something interesting
or important, using known techniques and technology as a starting point.

Software development = finding ways to do something interesting or
important, using known techniques and technology as a starting point.

Point 6

Virtually all software development is the D part of R&D. Some times,
there are very little R in Software 'R&D'. Some times, there are pretty
large R in Software 'R&D'.

It depends on several measurement. For example,

Managing software development for various sized companies, R&D takes
on different meanings depending on the size of the company, customer
base, etc.

In a small software company, with only a hand full of employees, the
line between R&D software and Production software is usually very
small. What one day is a software R&D project, may the next day be
shipping as production software to customers.

As software companies grow, and they have one or more production
software lines, they tend to create greater separation between R&D
software projects and Production software products (for obvious
reasons). This R&D gap is typically created to create greater
diversification in their software products for tomorrow, while
allowing the production software development to continue to produce
today.

This is not to say that the production software products won't get
innovative new features. The production software developers are
typically just as "sharp" as the R&D developers. In fact, at one
company, we had an enrichment program that allowed production software
developers to rotate in and out of R&D projects. This not only added
fresh brain power to the R&D teams, but in many cases, the production
developers came back with new ideas on producing better production
level software.

Point 7

D = "knowing where you want to be at the end", and R is because "at
the beginning of the project, you don't know what will be required to
get there"

Point 8

R&D are the lucky folks who get to do anything they want without
accountability.

Good research/resource on this topic :

http://www.econ.upf.edu/~albertbanal/Commercial%20Incentives.pdf

http://www.csiic.ca/pdf/Gegenworte.pdf

http://web.cecs.pdx.edu/~york/York-CS-Summit-Beijing2006.pdf

Title: What is the difference between development and R&D?

Body:
I was asked by a colleague to explain clearly the difference between ordinary development and research and development (R&D) and was unable to do it. After reading Wikipedia, I still don't have the precise answer.

According to Wikipedia (slightly modified):

There are two primary models:

In one model, the primary function is to develop new products;

in the other model, the primary function is to discover and create new knowledge about scientific and technological topics for the purpose of uncovering and enabling development of valuable new products, processes, and services.

The first model is confusing. Does it mean that development (not R&D) consists exclusively in adding new features to a product, solving bugs and doing maintenance? What if something which was previously developed as a new feature becomes a separate product?

The second model is less confusing, but still, how to qualify whether something is new knowledge or existent knowledge which is just rediscovered?

Later, Wikipedia adds that ordinary development is different from R&D because of its:

nearly immediate profit or immediate improvement.

It's still not clear enough. How to qualify "nearly immediate profit"? What if a task has an immediate profit but requires heavy research? Or if it is basic but has uncertain profit, like the enforcement of a common style over the codebase?

For example, does it belong to development or R&D to:

Develop an engine which abstracts the access to the database, simplifying and shortening enormously the code of other applications (existent or ones which will be written in future) which should access to the database?

Establish a new service-oriented architecture for the entire organization of company resources, in order to move from a bunch of separate and autonomous applications to a set of well-organized, interconnected web services, like what is used by Amazon?

Design a new communication protocol to allow faster replication of data between two data centers of the company?

Conceive a new type of software testing while working on a specific product, knowing that this type of testing will improve/simplify the testing process?

Prove that Functional programming is more appropriate than OOP for a specific application, based on evidence, logic and previous experience?

Enhance the existent application by adding gestures on tactile screens, after doing studies and testing that shows that those gestures improve the productivity of the users by a ratio of at least 1.4 for a precise set of tasks?

Find a way to strongly enhance the Power usage effectiveness (PUE) of a data center?

Create a Domain-Specific Language (DSL)?

In short, how could I determine whether I'm doing R&D while working on something?


问:
What is the difference between development and R&D?
I was asked by a colleague to explain clearly the difference between ordinary development and research and development (R&D) and was unable to do it. After reading Wikipedia, I still don't have the precise answer.

According to Wikipedia (slightly modified):

There are two primary models:

In one model, the primary function is to develop new products;

in the other model, the primary function is to discover and create new knowledge about scientific and technological topics for the purpose of uncovering and enabling development of valuable new products, processes, and services.

The first model is confusing. Does it mean that development (not R&D) consists exclusively in adding new features to a product, solving bugs and doing maintenance? What if something which was previously developed as a new feature becomes a separate product?

The second model is less confusing, but still, how to qualify whether something is new knowledge or existent knowledge which is just rediscovered?

Later, Wikipedia adds that ordinary development is different from R&D because of its:

nearly immediate profit or immediate improvement.

It's still not clear enough. How to qualify "nearly immediate profit"? What if a task has an immediate profit but requires heavy research? Or if it is basic but has uncertain profit, like the enforcement of a common style over the codebase?

For example, does it belong to development or R&D to:

Develop an engine which abstracts the access to the database, simplifying and shortening enormously the code of other applications (existent or ones which will be written in future) which should access to the database?

Establish a new service-oriented architecture for the entire organization of company resources, in order to move from a bunch of separate and autonomous applications to a set of well-organized, interconnected web services, like what is used by Amazon?

Design a new communication protocol to allow faster replication of data between two data centers of the company?

Conceive a new type of software testing while working on a specific product, knowing that this type of testing will improve/simplify the testing process?

Prove that Functional programming is more appropriate than OOP for a specific application, based on evidence, logic and previous experience?

Enhance the existent application by adding gestures on tactile screens, after doing studies and testing that shows that those gestures improve the productivity of the users by a ratio of at least 1.4 for a precise set of tasks?

Find a way to strongly enhance the Power usage effectiveness (PUE) of a data center?

Create a Domain-Specific Language (DSL)?

In short, how could I determine whether I'm doing R&D while working on something?

答:
$40,000 per year bump in salary?

In R&D, the R sometimes uses research to describe a thing that is also described as technology development where we discover how to do something we didn't know how to do.  Perhaps well described as applied research, we might design something to spec, then usually try to patent it or otherwise protect or exploit it to competitive advantage.

The R could also refer to risk, because research and development projects often try to combine both the discovery and exploitation of new technology and exploitation of known technologies together.  Among other risks to this approach are splitting your focus, building prototype that are NOT intended to be thrown away, and the likelihood that marketing is involved and will treat estimates as contracts.

R&D is a term that can dress up a department that is mostly involved in development.  Most technology projects should combine research with some kind of prototype, but making one or a dozen of something doesn't seem like development to me unless it can be handed off to manufacturing.

Research usually includes a notion of rigor like examining the literature or patents looking for prior art, asserting claims of new innovation and demonstrating their value and uniqueness in some way.  Academic research sometimes synthesizes ideas from academic literature, models some phenomenon mathematically, or reports a case study with analysis, conclusions, and a proposal for future study.

Perhaps R&D is interested in things that are have not been done before but in the short term will be made available as a product.

ContentLicense: CC BY-SA 3.0


答:
The difference is in the expectations.

When I've been working in R&D, I was primarily expected to provide research results.

When I've been working in development, I was primarily expected to provide working software.

These are not totally separated, and there can be quite substantial gray areas in between. In development, it sometimes happened that I was expected to perform some research. Likewise, in one of research projects, I was assigned to develop particular program.


问:
Can I use EPL licensed libraries and not Give out the Source code of my Application?
If I use EPL licensed software ( namely Eclipse jars ) in an application, do I have to give the users the source code and the right to redistribute? If that is not the case, what rules should I follow if I use EPL licensed software libraries in an application that I wish to distribute?</p>

答:
IANAL, but the Eclipse Public License (EPL) does not require distribution of require access to the source code.

On the characters of the EPL let me quote the GNU people:

The Eclipse Public License is similar to the Common Public License, and our comments on the CPL apply equally to the EPL. The only change is that the EPL removes the broader patent retaliation language regarding patent infringement suits specifically against Contributors to the EPL'd program.

And another quote on the Common Public License Version 1.0

This is a free software license. Unfortunately, its weak copyleft and choice of law clause make it incompatible with the GNU GPL.

'Weak copyleft' in this quote means that you are not required to use the same license for a derived work. So you can take EPL licensed code, include it in you own work, and distribute the result under a non-free, proprietary license.

Edit:

For details on what you are required to do as a user of EPL licensed software, see '3. REQUIREMENTS' of the EPL:

iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.

See also this answer: https://softwareengineering.stackexchange.com/a/138656/34768


问:
Beautiful Erlang Code
I'm trying to learn more about Erlang than the toy projects I've been playing with. To this end, I'm reading through Programming Erlang and some of the archives from Armstrong on Software.

I would also like to read over some example (preferably production) code that showcases the sorts of things you can build with Erlang that would be disproportionately difficult in other languages. Aside from (I assume) Yaws, are there any publicly available examples of beautiful Erlang code that I could read through to gain a better understanding of the language and/or see the idiomatic uses for various language constructs?

I'm specifically not looking for code that "gets the job done" but uses questionable practices, or examples along the lines of "here's how you write factorial in Erlang".

In the same vein, can anyone recommend any good literature for learning this language (other than the mentioned "Programming Erlang")? For preference, something you yourself used to learn it, but if there's some community standard books for it, throw those in too.

答:
Since you added the tag functional-programming, how about writing an Erlang compiler or interpreter in Haskell? Erlang is not quite state-of-the-art anymore, like at all.
I recommend to learn Erlang in one or two days, like some other languages (LISP, Prolog), and then to forget about them; they are just a step to unlearn imperative OOP-languages.

For smaller tasks than implementing a compiler, see Project Euler.

[EDIT]
To answer the comment:

From a technical view: Erlang was good in the old days, when there weren't multicore-processors. But now –given the existing compilers/interpreters I am arare of– it just does not scale anymore like it should. An interpreter written in Haskell would scale, compiled to Haskell would make it faster but would remove the on-the-fly code-replacing feature.

From the Programmers' view: Haskell is not for all applicable tasks the best choice, but atm, the probably more advanced languages are very experimental, and those not applicable tasks have usually sth to do with either embedded systems (like microcontrollers and GPUs) or numbercrunching, where C and Assembler are still the best choice.

What exactly is something that you could do with Erlang better than in other languages?

ContentLicense: CC BY-SA 2.5

Title: Beautiful Erlang Code


答:
As others have said, R & D involves research. For me, research is working on something that no people know how to do at the present time. If it has been done, it is not research, although it may require significant time investments to study the existing solutions and the literature.

About your list:

Develop an engine which abstracts the access to the database, simplifying and shortening enormously the code of other applications (existent or ones which will be written in future) which should access to the database?

Many ORM exist. Unless yours does something truly different, I would not count it as R & D.

Establish a new service-oriented architecture for the entire organization of company resources, in order to move from a bunch of separate and autonomous applications to a set of well-organized, interconnected web services, like what is used by Amazon?

Nope.

Design a new communication protocol to allow faster replication of data between two data centers of the company?

If this improves on known protocols, then I would consider this R & D.

Conceive a new type of software testing while working on a specific product, knowing that this type of testing will improve/simplify the testing process?

Prove that Functional programming is more appropriate than OOP for a specific application, based on evidence, logic and previous experience?

Enhance the existent application by adding gestures on tactile screens, after doing studies and testing that shows that those gestures improve the productivity of the users by a ratio of at least 1.4 for a precise set of tasks?

Find a way to strongly enhance the Power usage effectiveness (PUE) of a data center?

Create a Domain-Specific Language (DSL)?

None of these things seems to include research. To give other examples of things that I would consider R & D:

Improve the type inference in Scala, allowing better unification

Invent a new kind of compiler optimization

Create a new database that has significant differences from the existing ones - say like CouchDB was when it was conceived

Develop a working, usable library for functional reactive programming

Find a new exploit in existing software or protocols

Invent a new compression algorithm


问:
Stored procedure Naming conventions?
One of our senior developers has stated that we should be using a naming convention for stored procedures with an "objectVerb" style of naming such as ("MemberGetById") instead of a "verbObject" type of naming ("GetMemberByID"). The reasoning for this standard is that all related stored procedures would be grouped together by object rather than by the action.

While I see the logic for this way of naming things, this is the first time that I have seen stored procedures named this way. My opinion of the naming convention is that the name can not be read naturally and takes some time to determine what the words are saying and what the procedure might do.

What are your takes on this? Which way is the more common way of naming a stored proc, and does a what types of stored proc naming conventions have you used or go by?

答:
Instead of "objectVerb", you could use "namespace_verbObject", like Member_GetById.

It will group procedures by namespace, and still use traditional "verbSomething" naming.

Title: Stored procedure Naming conventions?


问:
In C and C++, what methods can prevent accidental use of the assignment(=) where equivalence(==) is needed?
In C and C++, it is very easy to write the following code with a serious error.

```<code>char responseChar = getchar();
int confirmExit = 'y' == tolower(responseChar);
if (confirmExit = 1)
{
    exit(0);
}
</code>```

The error is that the if statement should have been:

```<code>if (confirmExit == 1)
</code>```

As coded, it will exit every time, because the assignment of the confirmExit variable occurs, then confirmExit is used as the result of the expression.

Are there good ways to prevent this kind of error?

答: Just use left hand assignment, compiler warnings can help but you have to make sure you get the right level otherwise you'll either be swamped with pointless warnings or won't be told ones you want to see.</p>


问:
Should the number of developers be considered when estimating a task?
I am pretty inexperienced with working in agile projects but I have tried it a few times and I always run into this problem when estimating a task.

Do we bring into the estimate the number of developers that will work on the task?

Let me explain:
Task A is estimated to one time unit and developer 1 will work on it.
Task B is also estimated to one time unit and developer 2 and 3 will work on it together.

I.e. if developer 1 begins to work on task A at the same time developer 2 and 3 begins to work on task B they will all finish at the same time according to the estimate.

Should the estimate for task B be twice of that for task A or the same?

The problem as I see it is that when a task is received and estimated, it is not always possible to know how many people will work on it. And if you assumed that two developers would work on the task for one time unit but it turns out that only one developer will actually do it, this will not automatically mean that that developer will work on it for two time units.

Is there any standard practice for this?

答:
The number of developers should not be considered when estimating. However, the skill of the developer(s) should.

Initially you should be considering the complexity of the task. This is all relative, so all it tells you is that task A is twice as hard as task B, but 30% easier than task C (for example).

Then once you've got these complexity values you need to assign the man hours (or effort). This will vary depending on the skill of the developer. Task A might take 2 hours for an experienced developer, but might take a junior 8. Again, though you are ignoring how many developers are assigned to the task.

When you do assign developers you don't just simply divide the man hours by the number of people. There is an overhead - each person you add to a task reduces the overall effectiveness of the team until you get to a point where adding a person actually makes the task take longer.


问:
What are some good End-User Programming solutions you have seen?
End-User Programming is where regular end users, i.e. non-programmers, are able to customize a program, or create a new one, with minimal training or instruction.

App Inventor for Android is one recent example, but perhaps the most popular example of end-user programming is the spreadsheet.

What examples of end-user programming have you seen used, or believe to be useful? What's the philosophy of the system? What challenges remain?

答: Microsoft SharePoint allows users to do quite a bit graphically without any code. It includes data entry with formating and verification, security, work-flow. </p>


答: I'd suggest using some abstract values (something similar to Scrum's story points) in order to determine how much work does it take to solve the problem. Every developer in the team should have a monthly minimum to contribute (e.g. a junior developer should provide a minimum of 20 "points" worth solutions, a senior developer should provide around 50). Knowing the total number of points the project is worth and monthly number of points your team can provide, you could estimate how long will it take to accomplish all the tasks. </p>

Title: Should the number of developers be considered when estimating a task?

Body:
I am pretty inexperienced with working in agile projects but I have tried it a few times and I always run into this problem when estimating a task.

Do we bring into the estimate the number of developers that will work on the task?

Let me explain:
Task A is estimated to one time unit and developer 1 will work on it.
Task B is also estimated to one time unit and developer 2 and 3 will work on it together.

I.e. if developer 1 begins to work on task A at the same time developer 2 and 3 begins to work on task B they will all finish at the same time according to the estimate.

Should the estimate for task B be twice of that for task A or the same?

The problem as I see it is that when a task is received and estimated, it is not always possible to know how many people will work on it. And if you assumed that two developers would work on the task for one time unit but it turns out that only one developer will actually do it, this will not automatically mean that that developer will work on it for two time units.

Is there any standard practice for this?


问:
Which is more effective in coding? Reducing line of code and execution of code?
I have this doubt many years. I am wring some code to achieve some functionality. For example I am writing 20 lines of code to achieve the functionality and my co worker writing the code for the same functionality with just 5 lines. Since he used some looping statement to achieve that, but that code will execute around 30 to 50 times.

So which is best way of coding? As per my knowledge I always try to reduce coding length as much I can.

答:
I am new to programming. I read some books about design patterns, TDD/BDD, unit testing and so on.

From what I understand more code means more potential bugs. Moreover, one of TDD/BDD major goals is to write enough code only to make the test pass. I am practicing TDD/BDD as much.


答:
This answer must be very general but:

The first priority must be clarity. Usually concise code is clearer than long winded code, but, often not. So favour five or six simple easy to understand lines of code over one brilliant but obscure hard to read one-liner.

The second priority may be speed of execution, so you may want to re-factor your code if (and only if!) your code is running too slowly for the given requirements. (The brilliant but obscure one-liner may be much faster; on the other hand hard coding twenty lines with subscripts 0 to 19 can be faster than a for (x=1,x < 20 ;x++) loop ).

The other rule of thumb is if you cannot see the whole function in one screenfull (say 60 lines!) then consider breaking it up. Being able to see all the code in one eyeful really helps comprehension.

Title: Which is more effective in coding? Reducing line of code and execution of code?

Body:
I have this doubt many years. I am wring some code to achieve some functionality. For example I am writing 20 lines of code to achieve the functionality and my co worker writing the code for the same functionality with just 5 lines. Since he used some looping statement to achieve that, but that code will execute around 30 to 50 times.

So which is best way of coding? As per my knowledge I always try to reduce coding length as much I can.


答:
You want to break it down into a set of steps early on. The first step is the estimation and that is estimating the cost of the task in your preferred agile units.

Your developers will be able to process a certain number of units per sprint, this varies among developers depending on their skill level. Skill level is not just technical ability, but things like familiarity with the code and business domain.

One thing I haven't seen mentioned so far is, if you are estimating the cost of a bit of work and you think it will have multiple developers working on it, then you probably haven't broken the story down into sufficiently small stories.


问:
Examples of when we'll use interpreted language over compiled language?
I understand the differences between interpreted and compiled languages, but if someone could provide some examples of situations when one is likely to use interpreted languages over compiled languages, as well as situations when one is likely to use compiled languages over interpreted languages, it'd be really helpful.</p>

答:
Besides the reasons the others have mentioned, there is one particularly important use case for choosing an ad hoc interpretation over any form of compilation or any hybrid approach.

In case if a programming language is used as a communication protocol, and when response latency is important, it makes more sense to avoid wasting time on compilation and any possible preprocessing.

This applies to agent languages, for example, or for the way how, say, Tcl/Tk is normally used.

Another possible reason for sticking with interpretation is when a language interpreter is used for bootstrapping itself or a more elaborate, higher level language, and its simplicity is more important than the bootstrap process performance.

For nearly any other possible use case, compilation (or a hybrid approach) is a better fit.


答:
lines of code is too rough measure of code. Certainly long convoluted code can often be improved by shortening it, but at the same time short obfuscated code can often be improved by lengthening it.

The critical thing to understand is that the length of the code is actually a symptom in this process, the primary concerns are symmetry (fairly objective) and readability (fairly subjective) and finally performance (objective)

symmetry

Any time you improve code by shortening what you are actually doing is exploiting some symmetry in the code. I.E. two or more bits of code are doing something which is the same in some way, they may be completely different in other ways, but if you can separate out the code which is the same you can remove the duplication.

readability

This is inherently subjective however generally people agree that longer descriptive names are better than shorter ones. Less specific, more general code can use shorter more generic names as there is less to describe, but any time you have a specific meaning specific naming helps.

performance

after you have looking at the clarity of your code the next question is is it fast enough? At design time you can look at complexity of structures & algorithms and hopefully prove that you are at least in the right ball park. To fully answer the question though you need to measure the implementation. Only if the measured performance is not good enough is it worth going back to optimize your bottlenecks.


问:
Writing jenkins plugin: where is the documentation?
On my current project we're using Jenkins to monitor our builds.
Now they want me to write a Jenkins plugin to add some more monitoring parameters.

I've taken a look at how the status monitor plugin works, and I can't figure some things out. I've tried to look for documentation for writing a plugin, but that seems to be sorely lacking. (the site only mentions how to generate the base project, and refers to a tutorial that's not that informative)

What I'm trying to do is just add some options to each build, add a link, and a monitoring page. Adding to the main page is apparently done by adding the action, but I'm still trying to figure out the rest. And how it all ties in.

Does anyone have any pointers, or a place where I can find some decent documentation?

答:
The following resources may help you

Documentation

http://hudson-ci.org/docs/index.html

https://wiki.jenkins-ci.org/display/JENKINS/Extend+Jenkins

https://wiki.jenkins-ci.org/display/JENKINS/Plugins

https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial

http://wiki.hudson-ci.org/display/HUDSON/Extend+Hudson

http://jenkins-ci.org/category/sections/development

Book

http://www.packtpub.com/jenkins-continuous-integration-cookbook/book

http://shop.oreilly.com/product/0636920010326.do

Tutorial

http://code.dblock.org/implementing-my-first-jenkins-plugin-ansicolor

https://github.com/tupilabs/jenkins-testlink-plugin-tutorial

http://blog.codecentric.de/en/2012/08/tutorial-create-a-jenkins-plugin-to-integrate-jenkins-and-nexus-repository/

http://tupilabs.com/books/jenkins-testlink-plugin-tutorial/en/


问:
How do Programmers in the East see programmers in the West?
The other half of this question: How do programmers in the West see programmers in the East?

I think it's just as interesting and important to see how programmers in the east view programmers in the west.

The eastern part of the world (India/China/Philippines ) is often seen as mainly providing outsourcing services to the western world (USA and Europe).

Do you have the experience of working as part of an offshore team? If yes, how was it?

Do you hold any generalized ideas or opinions about the programmers from the West (e.g. Are they cooperative, do they deliver on time or do they do quality work?)

答:
I'm basing the following on my personal experience, and extrapolating it. Meant to be taken with a pinch of salt.

Generally speaking, Indian programmers seem to think of their western counterparts to be any one or more of the following:

Arrogant overlords

This may have something to do with India's history - imperial rule by the British, and the resultant distrust. Though outsourcing contributes to a lot of jobs in India, the fact that they are hired by people from the West doesn't escape them. A casual statement could be construed as proof (again!) that Westerners are arrogant.

Not committed.

In India, the concept of going away on vacations to spend time with one's family is not as established as it is in the West. Thus, going away on vacations is tantamount to not showing sufficient commitment to the job.

Due to the prevalent social structure, it's not considered helpful for career progression if you ask for breaks even if your job contract clearly allows you a certain number of days every year.

It's expected that you kowtow to your managers and please them. Challenging authority is a strict No-no, and may sometimes have disastrous consequences.

Unnecessarily stern

Plain-talking is not very welcome in India. If someone has made a serious mistake, it's expected that you'd go out of your way to sugar-coat what would otherwise be a reprimand or, at the very least, a blunt conversation. Since Westerners seem to like to call a spade a spade, they're looked upon as very harsh judges.

Culturally, westerners treat their colleagues cordially, but keep their distance. Indian programmers get very chummy with their colleagues, and therefore a dressing down is generally very hard to do.

Obsessed with deadlines

This is very baffling for Indian programmers. Deadlines, they think, are made only to be missed and subsequently reset. If they say they'll deliver something in x days, and they take x + 5 days, they expect you to be "more understanding" of the reasons for the delay.

Creative, deserving of respect

More often than not, programmers in India are told what to do. In the light of that fact, it shouldn't very hard to understand why original software seldom comes from India. So, the fact that almost all software that is used in everyday life comes from the West is reason for respect and admiration.


问:
Equal Gifts Algorithm Problem
Problem Link - http://opc.iarcs.org.in/index.php/problems/EQGIFTS

It is Lavanya's birthday and several families have been invited for the birthday party. As is customary, all of them have brought gifts for Lavanya as well as her brother Nikhil. Since their friends are all of the erudite kind, everyone has brought a pair of books. Unfortunately, the gift givers did not clearly indicate which book in the pair is for Lavanya and which one is for Nikhil. Now it is up to their father to divide up these books between them.

He has decided that from each of these pairs, one book will go to Lavanya and one to Nikhil. Moreover, since Nikhil is quite a keen observer of the value of gifts, the books have to be divided in such a manner that the total value of the books for Lavanya is as close as possible to total value of the books for Nikhil. Since Lavanya and Nikhil are kids, no book that has been gifted will have a value higher than 300 Rupees...

For the problem, I couldn't think of anything except recursion. The code I wrote is given below. But the problem is that the code is time-inefficient and gives TLE (Time Limit Exceeded) for 9 out of 10 test cases! What would be a better approach to the problem?

Code -

```<code>#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;

int n,g[150][2];

int diff(int a,int b,int f) {
    ++f;
    if(f==n) {
               if(a>b) {
                       return a-b;
               }
               else {
                    return b-a;
               }
    }
    return min(diff(a+g[f][0],b+g[f][1],f),diff(a+g[f][1],b+g[f][0],f));
}

int main() {
    int i;
    scanf("%d",&n);
    for(i=0;i<n;++i) {
                     scanf("%d%d",&g[i][0],&g[i][1]);
    }
    printf("%d",diff(g[0][0],g[0][1],0));
}
</code>```

Note - It is just a practice question, & is not part of a competition.

答:
Kevin Cline already said it, but deleted his answer, so I'll repeat and explain: This problem is a knapsack problem. Each pair of books can be represented by the price difference of those two books. Those price differences should be equally distributed, which equals to finding a subset of the price differences of which the sum is half the total sum of all price differences.

Example:

```<code>Pair   Book1   Book2  Difference
1      100     60     40
2      90      40     50
3      70      50     20
4      65      55     10
</code>```

Examining the set of differences, {40,50,20,10}, the total is 40+20+50+10 = 120, so we look for a subset with a sum close or equal to 120/2 = 60.
Using one of the existing algorithms for the knapsack problem, we get e.g. {50,10}.
This subset can be mapped back to the pairs, so one child gets the more expensive book of pairs 2 and 4, while the other kid gets the more expensive book of pairs 1 and 3.

http://en.wikipedia.org/wiki/Knapsack_problem#Approximation_algorithms explains algorithms for approximating the solution of knapsack problems.

Title: Equal Gifts Algorithm Problem

Body:
Kevin Cline already said it, but deleted his answer, so I'll repeat and explain: This problem is a knapsack problem. Each pair of books can be represented by the price difference of those two books. Those price differences should be equally distributed, which equals to finding a subset of the price differences of which the sum is half the total sum of all price differences.

Example:

Pair   Book1   Book2  Difference
1      100     60     40
2      90      40     50
3      70      50     20
4      65      55     10

Examining the set of differences, {40,50,20,10}, the total is 40+20+50+10 = 120, so we look for a subset with a sum close or equal to 120/2 = 60.
Using one of the existing algorithms for the knapsack problem, we get e.g. {50,10}.
This subset can be mapped back to the pairs, so one child gets the more expensive book of pairs 2 and 4, while the other kid gets the more expensive book of pairs 1 and 3.

http://en.wikipedia.org/wiki/Knapsack_problem#Approximation_algorithms explains algorithms for approximating the solution of knapsack problems.


问:
How should I implement a command processing application?
I want to make a simple, proof-of-concept application (REPL) that takes a number and then processes commands on that number.

Example:
I start with 1. Then I write "add 2", it gives me 3. Then I write "multiply 7", it gives me 21. Then I want to know if it is prime, so I write "is prime" (on the current number - 21), it gives me false. "is odd" would give me true. And so on.

Now, for a simple application with few commands, even a simple switch would do for processing the commands. But if I want extensibility, how would I need to implement the functionality? Do I use the command pattern? Do I build a simple parser/interpreter for the language? What if I want more complex commands, like "multiply 5 until >200" ? What would be an easy way to extend it (add new commands) without recompiling?

Edit: to clarify a few things, my end goal would not be to make something similar to WolframAlpha, but rather a list (of numbers) processor. But I want to start slowly at first (on single numbers).

I'm having in mind something similar to the way one would use Haskell to process lists, but a very simple version. I'm wondering if something like the command pattern (or equivalent) would suffice, or if I have to make a new mini-language and a parser for it to achieve my goals?

Edit2: Thanks for all the responses, all have been very helpful to me, but Emmad Kareem's helped me the most, so I'll chose it as the answer. Thanks again!

答:
This sounds like an interpreter. It looks like you are worried about the implementation more than the detailed functionality (I am only guessing here). This project if extended is not a trivial task. Make sure you study the scope clearly as this requires engineering approach and not an ad-hoc development approach to get a reliable product rather than a product with 1000 patches that works sometimes only.

Decide on a syntax and be ready to parse it and perform the necessary syntax checks. This link may help you with this:Create your own parser.

Take a look at: this topic as it touches on different aspects of the work, also there are good links that may help you (specially the answer by RMK).:Creating a Language interpreter. You may want to see an example of a nice looking project that is somewhat similar at: Ultimate Programmable Scientific Calculator. You can find source code and working program for a command line C# interpreter here Command-Line-Implementation-of-C#-Made-for-Teaching. Using the compiler to do the complex tasks for you like parsing and variable typing, etc. may be a clever way to escape the complexities of writing all this yourself. Also, there is the Mono option which provides a charp shell feature that you may want to take a look at: CsharpRepl.


问:
What is the difference in a developer's years of experience with a language?
As stated by the title, what is the difference in years of experience in given language in terms of developers? For example, if one developer has had five years working with language A and the other developer has had two years working with language B followed by three years working with language A, would there be perceivable difference between them?</p>

答:
Here is what I would expect/hope:

Fluency - they should be able to write more code off the top of their head and less time looking up syntax.

Know the difference between previous and current versions and how to migrate code from one to another.

Have a fuller understanding of compiling, distributing, testing, and creating upgrades and patches.

Create/Include Add-Ons to the IDE and gain efficiency from them.


答:
Unless you're specifically interested in writing the actual parser for yourself, I'd suggest having a look at one of the parser generator frameworks. For C you have YACC or Bison, but there should be other alternatives for other languages if you prefer.

These takes away the complexities of parsing complex grammars and lets you concentrate on the task you want to do. Of course this may be overkill for the grammar you suggest in the question, but since you mention having the option of expanding to a more complex grammar later, it's at least worth getting some inspiration from these frameworks.

Title: How should I implement a command processing application?

Body:
I want to make a simple, proof-of-concept application (REPL) that takes a number and then processes commands on that number.

Example:
I start with 1. Then I write "add 2", it gives me 3. Then I write "multiply 7", it gives me 21. Then I want to know if it is prime, so I write "is prime" (on the current number - 21), it gives me false. "is odd" would give me true. And so on.

Now, for a simple application with few commands, even a simple switch would do for processing the commands. But if I want extensibility, how would I need to implement the functionality? Do I use the command pattern? Do I build a simple parser/interpreter for the language? What if I want more complex commands, like "multiply 5 until >200" ? What would be an easy way to extend it (add new commands) without recompiling?

Edit: to clarify a few things, my end goal would not be to make something similar to WolframAlpha, but rather a list (of numbers) processor. But I want to start slowly at first (on single numbers).

I'm having in mind something similar to the way one would use Haskell to process lists, but a very simple version. I'm wondering if something like the command pattern (or equivalent) would suffice, or if I have to make a new mini-language and a parser for it to achieve my goals?

Edit2: Thanks for all the responses, all have been very helpful to me, but Emmad Kareem's helped me the most, so I'll chose it as the answer. Thanks again!


答:
The only thing that lines of code measures is how many lines of code you have.

There are no hard and fast rules for how many you should or should not have; just use what you need to get the job done, make sure that it's reasonably sane and maintainable and that it has a low enough likelihood of making you wince when you come back to it in 6 months time, and you'll do fine.


答:
Concise and Reduced code is

Clear

Easy to Understand

Easy to Debug

Easy to refactor

Better execution of code

Performs/plays important role for better user interaction

Time saving and gives better outcome.

Ultimately we do code for faster performance.

Both of them, concise code and better execution are not comparable
  term.  Better to have both. If you turn it a comparable term,
  then first priority is better performance.

Related Tutorials

https://stackoverflow.com/questions/952194/should-code-be-short-concise

http://www.stevemcconnell.com/ieeesoftware/bp06.htm

http://www.ibm.com/developerworks/rational/library/11-proven-practices-for-peer-review/index.html

Related Books

http://www.amazon.com/Effective-Programming-More-Writing-ebook/dp/B008HUMTO0


问:
Why does Java use UTF-16 for internal string representation?
I would imagine the reason was fast, array like access to the character at index, but some characters won't fit into 16 bits, so it wouldn't work...

So if you have to handle special cases anyways, why not just use UTF-8?

答:
For the main part, for the sake of plain and simple future-proofing. Whether it was a misguided reason and the wrong way to go about it is a different question.

You can see some reasons behind some of their design decisions in this document about the 2004 switch to Java 5 and UTF-16, which explains some of the shortcomings as well: Supplementary Characters in the Java Platform, and see Why does the Java ecosystem use different encodings throughout their stack?.

For more details on the pitfalls of using UTF-16, and why UTF-8 is likely to be a better option in general, see Should UTF-16 be considered harmful? and the UTF-8 Everywhere manifesto.


问:
What are some known/common development specialties?
In an answer that I posted to another question, I noted that there is likely to become more and more specialization in software development: there being experts or specialists for given type of programming.

I'm wondering, what specialties are known to exist in reasonable quantities in the industry now (not academia), that are not technology specific (eg. for this discussion winforms isn't a specialty)? I'm also interested in the industry that such a specialist would have to work in if necessary.

答:
"Developer DBA" role/team exists but isn't common enough or appreciated.

Talking about larger shops, a Production DBA team may have a few 1000 SQL Server instances to manage and monitor, provide disaster recovery, liaise with SAN, network and OS teams etc

Who is there for the development teams? Tuning? Indexes? Design? Coding standards?

Saying that, as a Developer DBA myself, I've met plenty of client developers who know more about databases than I do... :-)

Of course, knowledge of the business is useful too. if you're hired to improve some code that prices complex derivatives in investment banking, then some subject matter expertise is almost as important as whizzy coding skills.


答: Because it used to be UCS-2, which was a nice fixed-length 16-bits. Of course, 16bit turned out not to be enough. They retrofitted UTF-16 in on top.</p>

Title: Why does Java use UTF-16 for internal string representation?

Body:
I would imagine the reason was fast, array like access to the character at index, but some characters won't fit into 16 bits, so it wouldn't work...

So if you have to handle special cases anyways, why not just use UTF-8?


问:
DDD: service contains two repository
Does it correct way to have two repository inside one service and will it  be an application or domain service?

Suppose I have a Passenger object that should contains Passport (government id) object. I am getting Passenger from PassengerRepository. PassengerRepository create request to server and obtain data (json) than parse received data and store inside repository.

I have confused because I want to store Passport as Entity and put it to PassportRepository but all information about password contains inside json than i received above.

I guess that I should create a PassengerService that will be include PassengerRepository and PassportRepository with several methods like removePassport, addPassport, getAllPassenger and etc.

UPDATE:

So I guess that the better way is represent Passport as VO and store all passports inside Passenger aggregate. However there is another question: Where I should put the methods (methods calls server api) for management passenger's passport. I think the better place is so within Passenger aggregate.

答:
It's not unheard of for a service to have two repositories, but it is often a hint of a poor design. It's worth looking at, to see if you could improve your design but, if you look and you can't improve it, you shouldn't worry too much.

In your case, I think you need to look at the concept of Aggregates in DDD.

Aggregates are groups of things that belong together. An Aggregate Root is the thing that holds them all together.

If Passenger and Passport don't belong together, I don't know what does. Your aggregate root in this case should obviously be Passenger.

Title: DDD: service contains two repository


问:
Will SRS be sufficient enough for the programmers to do their work, without the additional overhead of FS?
We always make 2 documents the SRS (Software Requirement Specification) and the FS (Functional Specifications) documents for the coders aka programmers.

As I have examined the SRS is more like containing both functional and non-functional requirements as compared to the FS that deals only with the functional requirements.

To cut it short will the SRS be sufficient enough for the programmers to do their work? and not make any FS anymore?

答:
As long as programmers and QA agree that this is sufficient and you're happy that what is being delivered and not spending too much time later explaining features to dev/QA -  I don't think people would care what the document is called. No reason to have two docs that are largely duplicates of each other.

You'll need to identify which requirements in SRS are traceable to features(when user clicks A, B happens) and which are not (Ex. extensiblity, cost) so you can get agreement that software meets the requirements when all is said and done.


问:
Why are strings so slow?
Ever since my very first programming class in high school, I've been hearing that string operations are slower — i.e. more costly — than the mythical "average operation." Why makes them so slow? (This question left intentionally broad.)</p>

答:
This is an old thread and I think that the other answers are great, but overlook something, so here's my (late) 2 cents.

Syntactic Sugar-Coating Hides Complexity

The problem with strings is that they are second class citizens in most languages, and are in fact most of the time not really a part of the language specification itself: they are a library-implemented construct with some occasional syntactic sugar-coating on the top to make them less of a pain to use.

The direct consequence of this is that the language hides a very large part of their complexity away from your sight, and you pay for the sneaky side-effects because you grow into the habit of considering them like a low-level atomic entity, just like other primitive types (as explained by the top-voted answer and others).

Implementation Details

Good Ol' Array

One of the elements of this underlying "complexity" is that most string implementations would resort to using a simple data-structure with some contiguous memory space to represent the string: your good ol' array.

This makes good sense, mind you, as you want the access to the string as a whole to be fast. But that implies potentially dreadful costs when you want to manipulate this string. Accessing an element in the middle might is fast if you know what index you are after, but looking for an element based on a condition isn't.

Even returning the size of string might be costly, if your language doesn't cache the string's length and needs to run through it to count characters.

For similar reasons, adding elements to your string will prove costly as you'll most likely need to re-allocate some memory for this operation to occur.

So, different languages take different approaches to these issues. Java, for instance, took the liberty of making its strings immutable for some valid reasons (caching length, thread-safety) and for its mutable counterparts (StringBuffer and StringBuilder) will choose to allocate size using larger-sized chunks to not need to allocate every time, but rather hope for best case scenarios. It generally works well, but the down-side is to sometimes pay for memory impacts.

Unicode Support

Also, and again this is due to the fact that the syntactic sugar coating of your language hides this from you to play nice, you often don't think it terms of unicode support (especially for as long as you don't really need it and hit that wall). And some languages, being forward thinking, do not implement strings with underlying arrays of simple 8-bit char primitives. They baked in UTF-8 or UTF-16 or what-have-you support for you, and the consequence is a tremendously larger memory consumption, which is often times not needed, and a larger processing time to allocate memory, process the strings, and implement all the logic that goes hand in hand with manipulating code points.

The results of all this, is that when you do something equivalent in pseudo-code to:

```<code>hello = "hello,"
world = " world!"
str = hello + world
</code>```

It may not be - despite all the best efforts the language developers put in to have them behave as you'd except - a simple as:

```<code>a = 1;
b = 2;
shouldBeThree = a + b
</code>```

As a follow-up, you may want to read:

Is it Inefficient to concatenate strings one at a time?

Title: Why are strings so slow?

Body:
This is an old thread and I think that the other answers are great, but overlook something, so here's my (late) 2 cents.

Syntactic Sugar-Coating Hides Complexity

The problem with strings is that they are second class citizens in most languages, and are in fact most of the time not really a part of the language specification itself: they are a library-implemented construct with some occasional syntactic sugar-coating on the top to make them less of a pain to use.

The direct consequence of this is that the language hides a very large part of their complexity away from your sight, and you pay for the sneaky side-effects because you grow into the habit of considering them like a low-level atomic entity, just like other primitive types (as explained by the top-voted answer and others).

Implementation Details

Good Ol' Array

One of the elements of this underlying "complexity" is that most string implementations would resort to using a simple data-structure with some contiguous memory space to represent the string: your good ol' array.

This makes good sense, mind you, as you want the access to the string as a whole to be fast. But that implies potentially dreadful costs when you want to manipulate this string. Accessing an element in the middle might is fast if you know what index you are after, but looking for an element based on a condition isn't.

Even returning the size of string might be costly, if your language doesn't cache the string's length and needs to run through it to count characters.

For similar reasons, adding elements to your string will prove costly as you'll most likely need to re-allocate some memory for this operation to occur.

So, different languages take different approaches to these issues. Java, for instance, took the liberty of making its strings immutable for some valid reasons (caching length, thread-safety) and for its mutable counterparts (StringBuffer and StringBuilder) will choose to allocate size using larger-sized chunks to not need to allocate every time, but rather hope for best case scenarios. It generally works well, but the down-side is to sometimes pay for memory impacts.

Unicode Support

Also, and again this is due to the fact that the syntactic sugar coating of your language hides this from you to play nice, you often don't think it terms of unicode support (especially for as long as you don't really need it and hit that wall). And some languages, being forward thinking, do not implement strings with underlying arrays of simple 8-bit char primitives. They baked in UTF-8 or UTF-16 or what-have-you support for you, and the consequence is a tremendously larger memory consumption, which is often times not needed, and a larger processing time to allocate memory, process the strings, and implement all the logic that goes hand in hand with manipulating code points.

The results of all this, is that when you do something equivalent in pseudo-code to:

hello = "hello,"
world = " world!"
str = hello + world

It may not be - despite all the best efforts the language developers put in to have them behave as you'd except - a simple as:

a = 1;
b = 2;
shouldBeThree = a + b

As a follow-up, you may want to read:

Is it Inefficient to concatenate strings one at a time?


问:
Inter-process and inter-thread data sharing
I know that operating systems facilitate inter-process and inter-thread data sharing. I want to know about the mechanisms used to facilitate such sharing. I read about "pipes". What are the other ways?</p>

答:
Threads operate in the common address space, so in-memory data structures can be shared without any restrictions (assuming, of course, that proper synchronization has been put in place). One can pass an address of an in memory data structure to another thread in order for the thread to be able to access that data structure.

Processes, on the other hand, operate in separate memory spaces, so they use one of several approaches:

Serialized data exchange - this can be implemented on top of pipes or other in-memory exchange data protocols (e.g. connecting via TCP to a server running on localhost). The data needs to be serialized and deserialized, making this approach less practical as the volume of data goes up. Note that this is not precisely sharing, because all the data is copied both ways.

Shared Memory - this lets you exchange large amounts of data without serialization. This is a true data sharing, because no copying is done. However, ensuring proper synchronization becomes a responsibility of your application. Memory-mapped files is another variation of shared memory, retaining all the advantages and the disadvantages of the approach.


答:
It possibly depends on your organization and the size of your product, but I would think that the more times the input of customers and system engineers are converted from one form to another, the more costly your product and perhaps more seriously, the more disconnected will be the developers relative to the customer.

Distinguishing between functional and system requirements probably has some benefits, but I think mostly our documentation needs to grow vertically (more descriptive) rather than horizontally (bigger waterfall, more handoffs).  Even big DoD projects are organizing into System of Systems approaches so they can be done with smaller teams, smaller specs, smaller budgets, and higher potential for reuse.

Another consideration might be whether you use the V-model.  In the V-model, there is a customer specification cycle that pairs with acceptance testing, design that pairs with system integration testing, and development that pairs with unit testing.  If your two requirements documents don't line up with the creation of test cases, that could lead to some pathology.  For example, it you have requirements in which no corresponding test cases forces the shalls to be interpreted concretely (for example, the system shall have superior performance means nothing, but the system shall respond to touch screen presses within 200 ms does and can be tested), then you can end up with real  disagreements about suitability and deliverability of the product.

Title: Will SRS be sufficient enough for the programmers to do their work, without the additional overhead of FS?

Body:
We always make 2 documents the SRS (Software Requirement Specification) and the FS (Functional Specifications) documents for the coders aka programmers.

As I have examined the SRS is more like containing both functional and non-functional requirements as compared to the FS that deals only with the functional requirements.

To cut it short will the SRS be sufficient enough for the programmers to do their work? and not make any FS anymore?


答:
Depending on the scope and type of an application, if what you need are command line applications you could use pipes by writing and reading from console, if you are writing an intranet application or standalone application and processes accessing data are parallel or on different machines you can use a database server.

If what you need is not complex you can use files or database systems that are integral part of the application like SQL lite, but here you would need to implement flagging so you don't corrupt data if both process try to write data.

Title: Inter-process and inter-thread data sharing

Body: I know that operating systems facilitate inter-process and inter-thread data sharing. I want to know about the mechanisms used to facilitate such sharing. I read about "pipes". What are the other ways?</p>


问:
Architecture for Social Graph data that has a Time Frame Associated?
I am adding some "social" type features to an existing application.  There are a limited # of node & edge types.  Overall the data itself is relatively small (50,000 - 70,000 for each type of node) there will be a number of edges (relationships) between them (almost all directional).

This, I know, is relatively easy to represent with an SDF store (such as BrightstarDB) or something like Microsoft's Trinity (or really many of the noSQL options).

The thing that, I think, makes this a unique use case is that each relationship will have a timeframe associated with it (start and end dates).  Right now, I'm thinking of just storing this in a relational structure and dealing with the headaches of "traversing the graph", but I'm looking for suggestions on a better approach (both in terms of data structure and server):

```<code>Column
================
From_Node_ID
Relationship
To_Node_ID
StartDate
EndDate
</code>```

Any suggestions or thoughts are welcomed.

答:
You should check out Neo4j-open source graph database. It is a mature and well supported project. It has a well written-updated documentation. It is java based but has several client libraries for ruby, jruby, php, python, c#... It works as embedded(a jar file) or as a server(you may connect and operate over HTTP with its REST based structure). And finally, it is disk based transactional.

In Neo4j, you could have properties assigned to nodes and also to relations. That means, in your case, you may connect two nodes with a relation that has properties called "StartDate" and "EndDate" or any other property you wish.

For example if you have users as nodes you may have a relationship called "interested_in" and you may connect UserA to UserB with the relation "interested_in" and assign StartDate as the date you created relation and later on you may assign an EndDate property as the date "interested_in" relation come to an end.

It may look like:

```<code>UserA -[interested]-> UserB
      StartDate:20121102
       EndDate:20121107
</code>```

And users(I mean your nodes) could be connected to your existing database via giving "id" property to Neo4j nodes coming from your existing database. Or you may copy all or several properties(i.e name, surname, birth date, etc...) to the nodes in Neo4j, but this time you may need to synchronize your users in Neo4j and your database every time an update occurs in your data stores.

There are several example data models within the documentation of Neo4j

There is also InfiniteGraph which is similar to Neo4j and stated as "Distributed Graph Database", but I do not have any experience with it. For your case(50,000 - 70,000 for each type of node) Neo4j would be a perfect match with its support up to billions of nodes and relationships.

Body:
You should check out Neo4j-open source graph database. It is a mature and well supported project. It has a well written-updated documentation. It is java based but has several client libraries for ruby, jruby, php, python, c#... It works as embedded(a jar file) or as a server(you may connect and operate over HTTP with its REST based structure). And finally, it is disk based transactional.

In Neo4j, you could have properties assigned to nodes and also to relations. That means, in your case, you may connect two nodes with a relation that has properties called "StartDate" and "EndDate" or any other property you wish.

For example if you have users as nodes you may have a relationship called "interested_in" and you may connect UserA to UserB with the relation "interested_in" and assign StartDate as the date you created relation and later on you may assign an EndDate property as the date "interested_in" relation come to an end.

It may look like:

UserA -[interested]-> UserB
      StartDate:20121102
       EndDate:20121107

And users(I mean your nodes) could be connected to your existing database via giving "id" property to Neo4j nodes coming from your existing database. Or you may copy all or several properties(i.e name, surname, birth date, etc...) to the nodes in Neo4j, but this time you may need to synchronize your users in Neo4j and your database every time an update occurs in your data stores.

There are several example data models within the documentation of Neo4j

There is also InfiniteGraph which is similar to Neo4j and stated as "Distributed Graph Database", but I do not have any experience with it. For your case(50,000 - 70,000 for each type of node) Neo4j would be a perfect match with its support up to billions of nodes and relationships.


问:
Dealing with curly brace soup
I've programmed in both C# and VB.NET for years, but primarily in VB. I'm making a career shift toward C# and, overall, I like C# better.

One issue I'm having, though, is curly brace soup. In VB, each structure keyword has a matching close keyword, for example:

Namespace ...
    Class ...
        Function ...
            For ...
                Using ...
                    If ...
                        ...
                    End If
                    If ...
                        ...
                    End If
                End Using
            Next
        End Function
    End Class
End Namespace
```

<p>The same code written in C# ends up very hard to read:</p>

<pre class="lang-csharp prettyprint-override"><code>namespace ... {
    class ... {
        function ... {
            for ... {
                using ... {
                    if ... {
                        ...
                    }
                    if ... {
                        ...
                    }
                }
            }
            // wait... what level is this?
        }
    }
}
</code>```

Being so used to VB, I'm wondering if there's a technique employed by c-style programmers to improve readability and to ensure that your code ends up in the correct "block". The above example is relatively easy to read, but sometimes at the end of a piece of code I'll have 8 or more levels of curly braces, requiring me to scroll up several pages to figure out which brace ends the block I'm interested in.

答:
Put your starting curly brace in the same "rank" as your ending one, like this:</p>

```<code>namespace ...
{
    class ...
    {
        function ...
        {
            for ...
            {
                using ...
                {
                    if ...
                    {
                        ...
                    }
                    if ...
                    {
                        ...
                    }
                }
            }
            // It's the `function` level!
        }
    }
}
</code>```

Title: Dealing with curly brace soup

Body:
Put your starting curly brace in the same "rank" as your ending one, like this:

namespace ...
{
    class ...
    {
        function ...
        {
            for ...
            {
                using ...
                {
                    if ...
                    {
                        ...
                    }
                    if ...
                    {
                        ...
                    }
                }
            }
            // It's the `function` level!
        }
    }
}


答:
A common convention is to add a comment after the closing brace to indicate the structure that it's closing:

```<code>if {
   ...
} // end if

while (condition) {
   ...
} // end while
</code>```

etc.  I've never warmed to this convention myself, but some people find it helpful.

Title: Dealing with curly brace soup

Body:
I've programmed in both C# and VB.NET for years, but primarily in VB. I'm making a career shift toward C# and, overall, I like C# better.

One issue I'm having, though, is curly brace soup. In VB, each structure keyword has a matching close keyword, for example:

Namespace ...
    Class ...
        Function ...
            For ...
                Using ...
                    If ...
                        ...
                    End If
                    If ...
                        ...
                    End If
                End Using
            Next
        End Function
    End Class
End Namespace
```

<p>The same code written in C# ends up very hard to read:</p>

<pre class="lang-csharp prettyprint-override"><code>namespace ... {
    class ... {
        function ... {
            for ... {
                using ... {
                    if ... {
                        ...
                    }
                    if ... {
                        ...
                    }
                }
            }
            // wait... what level is this?
        }
    }
}
</code>```

Being so used to VB, I'm wondering if there's a technique employed by c-style programmers to improve readability and to ensure that your code ends up in the correct "block". The above example is relatively easy to read, but sometimes at the end of a piece of code I'll have 8 or more levels of curly braces, requiring me to scroll up several pages to figure out which brace ends the block I'm interested in.

Body:
A common convention is to add a comment after the closing brace to indicate the structure that it's closing:

if {
   ...
} // end if

while (condition) {
   ...
} // end while

etc.  I've never warmed to this convention myself, but some people find it helpful.


问:
Should the number of developers be considered when estimating a task?
I am pretty inexperienced with working in agile projects but I have tried it a few times and I always run into this problem when estimating a task.

Do we bring into the estimate the number of developers that will work on the task?

Let me explain:
Task A is estimated to one time unit and developer 1 will work on it.
Task B is also estimated to one time unit and developer 2 and 3 will work on it together.

I.e. if developer 1 begins to work on task A at the same time developer 2 and 3 begins to work on task B they will all finish at the same time according to the estimate.

Should the estimate for task B be twice of that for task A or the same?

The problem as I see it is that when a task is received and estimated, it is not always possible to know how many people will work on it. And if you assumed that two developers would work on the task for one time unit but it turns out that only one developer will actually do it, this will not automatically mean that that developer will work on it for two time units.

Is there any standard practice for this?

答: If you have a task that can be performed by multiple people, I would suggest that you're estimating at too high a level. Try to break your tasks down to something approaching atomic chunks of work. In this way your question "goes away" and it becomes easier to schedule (and communicate) as work can be performed serially or in parallel depending on other priorities.</p>


答:
Depending on your IDE: put your cursor at the open/close brace and it'll highlight both that and the corresponding brace.

Collapse the block and it shows you where it opens/closes.

Write smaller code blocks. Seriously. Check out Clean Code, and never run into this problem again (and have more readable/maintainable code).

One note, the following is valid c# syntax that might help your particular situation:

```<code>using (var type = new MyDisposable1())
using (var type2 = new MyDisposable2())
{
    /* do what you will with type2 and type2 */
}
</code>```

Title: Dealing with curly brace soup

Body:
Depending on your IDE: put your cursor at the open/close brace and it'll highlight both that and the corresponding brace.

Collapse the block and it shows you where it opens/closes.

Write smaller code blocks. Seriously. Check out Clean Code, and never run into this problem again (and have more readable/maintainable code).

One note, the following is valid c# syntax that might help your particular situation:

using (var type = new MyDisposable1())
using (var type2 = new MyDisposable2())
{
    /* do what you will with type2 and type2 */
}


答:
I recently decided to try and formalize two rules about flow control constructs that basically go like this:

You should have nothing but necessary code-flow constructs

You should make the code-flow constructs as small as possible

For exactly the reasons you have mentioned and are clearly aware of, I think these are great rules to follow. There are a couple simple techniques you can employ to accomplish them:

Exit scope as soon as you can (this includes the scope of loops as well as functions)

Watch for elses that could be mitigated by exiting the function from the preceding if and apply the scope exiting technique as I mentioned

Reverse your conditional checks when the code inside an if is great than that outside

Factor code inside of a loop out to another method when the size of the loop grows to obscure the rest of the method

Watch for any scopes that only contain another scope, for instance a function whose entire scope is filled by an if with nothing outside of the if

I detailed here examples of how not following these can end up with you doing as you said and putting code in the wrong code block, which is bad and an easy cause of bugs cropping up during maintenance.

Title: Dealing with curly brace soup


答:
I think you need to tough it out with the braces. Eventually they will become second nature to you and you will be wondering how you ever lived without them.

Make sure they are indented appropriately though, and that some spacing convention is being followed (doesn't matter which).

Title: Dealing with curly brace soup


答:
This is one of the oldest causes of warfare in computing, unfortunately.  Reasonable arguments can be made from both sides (better vertical real-estate economy versus easier ability to visually match opening brace with closing brace), but in reality a simple source-code formatter will resolve everything for you.  MS Visual C# has one built in that works well.

Be warned however that if you are working as part of a team you will be expected to conform to the conventions used by that team, so it pays to gain some familiarity with both styles and to refrain from getting religious over brace styles.

So while you're learning by all means focus on the style that makes it easier for you to learn, but keep half an eye on the other while you're at it and you'll do fine.

Title: Dealing with curly brace soup


答: Message Queue is another option. A process can write to the tail of a queue and another process can read from the head of that queue. Message queue's advantage is that it supports asynchronous operation.


问:
How to use PostgreSQL on AWS - Ubuntu 11.10
I'm extremely new to cloud-computing, Linux, and PostgreSQL, so if this is a stupid question, I apologize.

I've managed to create an m1.large instance running Ubuntu 11.10, connect via Putty SSH, and install PostgreSQL (sudo apt-get install postgresql), but that is as far as I've gotten.

My goal is to run several python web-scraping scripts that I've written on this instance (so as not to eat up all of our bandwidth (smaller company at the moment)) and insert the scraped data into a PostgreSQL table on the instance and later retrieve that data to store on our local server (as I've heard AWS EBS is unreliable and I don't want to take chances).

How can I configure PostgreSQL on my AWS instance? How can I access the data from my machine? I currently use PgAdmin3 to manage PosgreSQL on our local server. Can I use this same interface to manage PostgreSQL on my AWS instance?

Any suggestions, solutions, links, etc is greatly appreciated. And again, if this is a dumb question, I apologize.

Thanks!

答:
First, you need to open an inbound port(mentioned here) for postgresql on your EC2 instance. I am not an expert of postgresql but it should be 5432 if you are using defaults.

You may follow help.ubuntu's documentation to configure postgre, especially you need to make postgre listen to network in order to accept connections from internet via changing the related line in postgresql.conf to: listen_addresses = '*'. This entry would be useful

After these steps you may connect to your postgre via your usual PgAdmin3 by entering your public DNS address of your EC2 instance(something like "ec2-3-3-25-16.compute-1.amazonaws.com") as host address. Or you may use Elastic IP feature of AWS to assign a simpler IP address to your EC2 instance.


问:
Why creating a new MDX language instead of extending SQL?
I have a long experience with SQL, but recently began working with datawarehouse and OLAP technologies: building fact and dimension tables, that then are queried using MDX (MultiDimensional eXpressions).

The problem is that MDX works with a completely different logic compared to SQL, and it's a whole new learning curve even for someone with a strong SQL background.

Yes, MDX allows you to do things that would be hard or almost impossible with plain SQL.
But sometimes it's frustrating to be hours around an MDX to do something you know you could achieve in minutes using SQL (ok, you can tell me to RTFM ...).

But why go on to the trouble of creating a new completely different language when you could build on SQL, extend it to add the features needed by OLAP applications?

答:
Each database vendor has their own set of proprietary SQL extensions to achieve certain piecemeal goals.  But none of these extensions have achieved widespread adoption like SQL has.

If your goal is to create enhanced functionality in a standards-based way, you have two options. You can either go to the SQL standards committee and make your case (which could take years), or you can create your own standard and hope the community adopts it.
Vendor extensions on the SQL standard have not succeeded in this way.

So Microsoft, instead of taking a piecemeal approach, decided to go all in and create a comprehensive solution. And it worked; the industry adopted it as the go-to solution for OLAP querying.
Ergo, a defacto standard, without the committee pain.

MDX is a de-facto standard, created by a single vendor.  Assuming you can get broad buy-in, you have eliminated the need for design by committee, and saved yourself a lot of time, effort and money.


答:
There is an add-on to the editor that may help you at: C# Outline.

The add-on extends the VS20xx editor for C# by adding features to collapse, expand and highlight nested blocks of code. These features allows for easier editing and reading of nested contents of code blocks such as if, while, etc.

Title: Dealing with curly brace soup


问:
Forbidding or controlling "Hidden IT..." Who should write and maintain ad-hoc software applications?
Bigger companies usually have the problem, that it is not possible to write all programs employees want (to save time and to optimize processes) due to a lack of staff and money.

Then hidden programs will be created by some people having (at least some) coding experience (or by cheap students/interns...). Under some circumstances these applications will raise in importance and spread from one user to a whole department.

Then there is the critical point: Who will maintain the application, add new features, ...? And this app is critical. It IS needed. But the intern has left the company. No one knows how it works. You only have a bunch of sources and some sort of documentation.

Does it make sense to try and control or forbid application development done ad-hoc outside of the IT department (with the exception of minor stuff like Excel macros)?

答:
Sarbanes-Oxley and similar legislation outside of the US, combined with privacy laws and internally self-imposed privacy and security process and policies are the "hammer" that can and often are used to clamp down on the shadow-IT phenomenon.

As soon as customer or employee personally identifiable information (or any data you don't want to get out) starts circulating in these spreadsheets, you have an accident waiting to happen.

Similarly, as soon as one of these skunkworks IT projects takes that Excel spreadsheet and uses it as the data behind an externally-facing web app up that is hacked, you will have your CIO and CEO storming into the office of whoever built that app in a weekend coming to explain the consequences.

And then there is the issue that when you look at these efforts multiplied over the hundreds (or thousands) of departments in a Fortune 500 enterprise, you soon find that your enterprise has over 100 customer "master" databases.  Your customers start to complain that they updated their contact information in one place but it is still out of date in 10 others, or that you don't even know how much business you do with your large partners because the information is spread across 10 shadow IT databases.

All of this gives rise to onerous compliance and audit processes that are no fun for anyone but are the hard facts of life of IT in an enterprise environment.

A good strategy is to look across all of the departments that are doing this and make a case to move their investment in shadow IT into IT proper, making the argument that IT can achieve an economy of scale and do this work more efficiently than the current ad-hoc distributed skunkworks model.  This can be a hard sell in an environment where IT budget constraints and delivery velocity gave rise to the skunkworks in the first place, but combined with the audit/fiduciary risks can make a good one-two punch.


问:
Sharing Large Database Backup Among Team
I work on a team of three - five developers that work on an ASP.net web application remotely. We currently run a full local database from a recent backup on all of our machines during development. The current backup, compressed, is about 18 GB.

I'm looking to see if there's an easier way to keep all of our local copies relatively fresh without each of us individually downloading the 18 GB file over HTTP from our web server on a regular basis. I guess FTP is an option, but it won't speed the process up at all.

I'm familiar with torrents and the thought keeps hitting me that something like that would be effective, but I'm unsure of the security or the process.

答: Does your database support incremental backups or log shipping?  If so, you might try one of those, and just update the database instead of doing a complete restore.  This won't give much advantage if your DB structure changes a lot, but if it's mostly data changes then this could save you a good deal of time (and network bandwidth).</p>


问:
What does it mean to write "good code"?
In this question I asked whether being a bad writer hinders you from writing good code. Many of the answers started of with "it depends on what you mean by good code".

It appears that the term "good code" and "bad code" are very subjective. Since I have one view, it may be very different from others' view of them.

So what does it mean to write "good code"? What is "good code"?

答:
I'll simply go with "maintainable"

All code has to be maintained: no need to have that task made more difficult than necessary

If any reader doesn't understand this simple requirement or needs it spelled out, then  that reader should not be writing code...

Title: What does it mean to write "good code"?


答: A frustration many companies, or departments in companies, have is that their IT departments get in the way and make it difficult for them to get their work done or do new things. This leads departments, that feel as if they are being held back by IT policies, to attempt to solve their own problems. Communication is key. If departments are working around IT, what you really have is an IT problem. IT can't afford to be seen as the enemy. Companies, and especially IT departments, need to realize that they need to work together instead of against each other. If departments communicate with their IT staff (especially the ones who should have oversight) and tell them their needs and how they are working to solve their own problems, IT at least will have the option of helping to solve problems instead of finding out after the fact when a crisis comes to pass. Keep IT in the loop.</p>

Title: Forbidding or controlling "Hidden IT..." Who should write and maintain ad-hoc software applications?

Body:
Bigger companies usually have the problem, that it is not possible to write all programs employees want (to save time and to optimize processes) due to a lack of staff and money.

Then hidden programs will be created by some people having (at least some) coding experience (or by cheap students/interns...). Under some circumstances these applications will raise in importance and spread from one user to a whole department.

Then there is the critical point: Who will maintain the application, add new features, ...? And this app is critical. It IS needed. But the intern has left the company. No one knows how it works. You only have a bunch of sources and some sort of documentation.

Does it make sense to try and control or forbid application development done ad-hoc outside of the IT department (with the exception of minor stuff like Excel macros)?


答:
But if I want extensibility, how would I need to implement the functionality?

You shouldn't. Extensibility creates a whole lot of complexity for very little gain. That said, you'll need to provide a hook into the existing state. A way to see the state, modify the state, and provide a mechanism to return other results (print to screen). You'll need a way for the core code to discover modules, load them, and dispatch commands to them.

Do I use the command pattern?

You can, but it's likely not appropriate.

You're not going to take the entire input and send it off for processing, but instead parse the input, dispatch to the correct handler and let it do its work. The command doesn't vary in that communication; so no command pattern.

Do I build a simple parser/interpreter for the language?

You'll need something to handle breaking the input into tokens. For an extensible solution, you probably won't do much more. For a well-defined solution, having a full parse tree will provide better performance, error handling, and debug-ability.

but rather a list (of numbers) processor

Then perhaps you should look into the LISt Processing language. The juxtaposition of code and data should fit in well with what you describe.


问:
Set modified date = created date or null on record creation?
I've been following the convention of adding created and modified columns to most of my database tables. I also have been leaving the modified column as null on record creation and only setting a value on actual modification.

The other alternative is to set the modified date to be equal to created date on record creation.

I've been doing it the former way but I recent ran into one con which is seriously making me think of switching. I needed to set a database cache dependency to find out if any existing data has been changed or new data added. Instead of being able to do the following:

SELECT MAX(modified) FROM customer

I have to do this:

SELECT GREATEST(MAX(created), MAX(modified)) FROM customer

The negative being that it's a more complicated query and slower. Another thing is in file systems I believe they usually use the second convention of setting modified date = created date on creation.

What are the pros and cons of the different methods? That is, what are the issues to consider?

UPDATE

I believe given the apparent trade-offs I'm going to go with modified = created strategy.  In addition, I was curious how other web databases handled this and I noticed drupal seems to follow the convention of modified = created also.

答:
I think you've summed them up already.

The big pro for initially having the last modified date equal to the created date are that your code is a lot simpler. Simpler code is good as it's easier to maintain.

The only con I can think of right now is that if you need to check to see if the record has been modified your code will have to compare two dates rather than just checking if the modified date is null. Not really a big downside.


答:
With modified = created if you want the latest modifications with never edited ones included you can rely on the modified column. However if the modified column is initialized with null you have to do a COALESCE(modified, created) which would perform worse.

With modified = created if you want modifications with never edited ones excluded you simply where modified != created, and with modified initialized null you have to do a where modified IS NOT NULL which would have a fairly similar performance, though slightly better and increasing performance with more records having a null modified column.

These are really the only differences, both give the same abilities to filter and aggregate data, you just have to use slightly different techniques for each. I prefer initializing modified = created to avoid the coalesces. Though initializing with nulls may depending on your database system save disk space, especially if edits are uncommon to the point that you'll have mostly nulls. Also if you have mostly nulls, then the performance of the where modified IS NOT NULL will be a good bit better than the where modified != created due to the smaller set meeting the condition.

Edit:
Also, if you are interested in data based on modifications frequently enough that you would put an index on this column (pretty uncommon scenario but I don't know your use case), the index where modified = created would have different performance characteristics than initializing it with null, and any coalesces would with significant enough null's lose any benefit from the index because the coalesces will push the query off the index.

Title: Set modified date = created date or null on record creation?

Body:
I've been following the convention of adding created and modified columns to most of my database tables. I also have been leaving the modified column as null on record creation and only setting a value on actual modification.

The other alternative is to set the modified date to be equal to created date on record creation.

I've been doing it the former way but I recent ran into one con which is seriously making me think of switching. I needed to set a database cache dependency to find out if any existing data has been changed or new data added. Instead of being able to do the following:

SELECT MAX(modified) FROM customer

I have to do this:

SELECT GREATEST(MAX(created), MAX(modified)) FROM customer

The negative being that it's a more complicated query and slower. Another thing is in file systems I believe they usually use the second convention of setting modified date = created date on creation.

What are the pros and cons of the different methods? That is, what are the issues to consider?

UPDATE

I believe given the apparent trade-offs I'm going to go with modified = created strategy.  In addition, I was curious how other web databases handled this and I noticed drupal seems to follow the convention of modified = created also.


问:
How should I implement a command processing application?
I want to make a simple, proof-of-concept application (REPL) that takes a number and then processes commands on that number.

Example:
I start with 1. Then I write "add 2", it gives me 3. Then I write "multiply 7", it gives me 21. Then I want to know if it is prime, so I write "is prime" (on the current number - 21), it gives me false. "is odd" would give me true. And so on.

Now, for a simple application with few commands, even a simple switch would do for processing the commands. But if I want extensibility, how would I need to implement the functionality? Do I use the command pattern? Do I build a simple parser/interpreter for the language? What if I want more complex commands, like "multiply 5 until >200" ? What would be an easy way to extend it (add new commands) without recompiling?

Edit: to clarify a few things, my end goal would not be to make something similar to WolframAlpha, but rather a list (of numbers) processor. But I want to start slowly at first (on single numbers).

I'm having in mind something similar to the way one would use Haskell to process lists, but a very simple version. I'm wondering if something like the command pattern (or equivalent) would suffice, or if I have to make a new mini-language and a parser for it to achieve my goals?

Edit2: Thanks for all the responses, all have been very helpful to me, but Emmad Kareem's helped me the most, so I'll chose it as the answer. Thanks again!

答:
What you are describing is very close to a stack language.

For instance in Factor what you describe would be done like

```<code>1
2 +
7 *
even? not
</code>```

Or you could define your own words and then use them, like

```<code>: add ( x y -- sum ) + ;
: multiply ( x y -- product ) * ;
: odd? ( n -- ? ) even? not ;
</code>```

With these definitions the above example becomes

```<code>1
2 add
7 multiply
odd?
</code>```

Usually stack languages are trivial to parse because they use single words that are space separated. I suggest you have a look at Factor - it may be eaxctly what you want. It should be easy to define the words that do the processing you need.

EDIT: If you actually want to design a similar language, I suggest that you play with one of them anyway. Parsing a stack language is trivial - you split on blank spaces, and a naive implementation of processing is easy: you just need to take care of what happens on a stack.

Body:
What you are describing is very close to a stack language.

For instance in Factor what you describe would be done like

1
2 +
7 *
even? not

Or you could define your own words and then use them, like

: add ( x y -- sum ) + ;
: multiply ( x y -- product ) * ;
: odd? ( n -- ? ) even? not ;

With these definitions the above example becomes

1
2 add
7 multiply
odd?

Usually stack languages are trivial to parse because they use single words that are space separated. I suggest you have a look at Factor - it may be eaxctly what you want. It should be easy to define the words that do the processing you need.

EDIT: If you actually want to design a similar language, I suggest that you play with one of them anyway. Parsing a stack language is trivial - you split on blank spaces, and a naive implementation of processing is easy: you just need to take care of what happens on a stack.


问:
Should I use C style in C++?
As I've been developing my position on how software should be developed at the company I work for, I've come to a certain conclusion that I'm not entirely sure of.

It seems to me that if you are programming in C++, you should not use C style anything if it can be helped and you don't absolutely need the performance improvement. This way people are kept from doing things like pointer arithmetic or creating resources with new without any RAII, etc. If this idea was enforced, seeing a char* would possibly be a thing of the past.

I'm wondering if this is a conclusion others have made? Or am I being too puritanical about this?

答:
It is basically the way standard C++ is intended and encouraged (by the committee and the community) to be used:

use C++ language idioms (mostly based on RAII, like smart pointers)

don't use C language idioms until you can't avoid it (which still happen regularly, when interfacing with C interfaces)

This is what we have been calling "modern C++" for almost 10 years now. But most C++ developers start only now to realize it makes code looks like there is not much need for raw pointers, writing new/delete, and other error-prone constructs.

Now these constructs (C or not) are still there both for retrocompatibilty and for allowing you to write libraries to, again, free the other developers from having to play with them.
Also, C should be used to interface with C libraries, for low level constructs that require C-style code. Any other case, you can avoid using C idioms when you have C++ available.

For clarification: using C style doesn't improve performance (assuming you understand C++ constructs and RAII). In fact, a lot of algorithms written in C++ are faster than the same in C, just because C++ give more info to the compiler to make him optimize in calling context (I'm thinking about template algorithms/types for example).

So performance is not necessarily a valid reason to use C idioms when you write C++.

Title: Should I use C style in C++?