问:
Why are shortcuts like x += y considered good practice?
I have no idea what these are actually called, but I see them all the time. The Python implementation is something like:

x += 5 as a shorthand notation for x = x + 5.

But why is this considered good practice? I've run across it in nearly every book or programming tutorial I've read for Python, C, R so on and so forth. I get that it's convenient, saving three keystrokes including spaces. But they always seem to trip me up when I'm reading code, and at least to my mind, make it less readable, not more.

Am I missing some clear and obvious reason these are used all over the place?

答:
For some insight to why these operators are in the 'C-style' languages to begin with, there's this excerpt from K&R 1st Edition (1978), 34 years ago:

Quite apart from conciseness, assignment operators have the advantage
  that they correspond better to the way people think. We say "add 2 to
  i" or "increment i by 2," not "take i, add 2, then put the result back
  in i." Thus i += 2. In addition, for a complicated expression like

```<code>yyval[yypv[p3+p4] + yypv[p1+p2]] += 2
</code>```

the assignment operator makes the code easier to understand, since the reader doesn't have to check painstakingly that two long
  expressions are indeed the same, or wonder why they're not.  And an
  assignment operator may even help the compiler to produce more
  efficient code.

I think it's clear from this passage that Brian Kernighan and Dennis Ritchie (K&R), believed that compound assignment operators helped with code readability.

It's been a long time since K&R wrote that, and a lot of the 'best practices' about how people should write code has changed or evolved since then. But this programmers.stackexchange question is the first time I can recall someone voicing a complaint about the readability of compound assignments, so I wonder if many programmers find them to be a problem? Then again, as I type this the question has 95 upvotes, so maybe people do find them jarring when reading code.

Body:
For some insight to why these operators are in the 'C-style' languages to begin with, there's this excerpt from K&R 1st Edition (1978), 34 years ago:

Quite apart from conciseness, assignment operators have the advantage
  that they correspond better to the way people think. We say "add 2 to
  i" or "increment i by 2," not "take i, add 2, then put the result back
  in i." Thus i += 2. In addition, for a complicated expression like

yyval[yypv[p3+p4] + yypv[p1+p2]] += 2

the assignment operator makes the code easier to understand, since the reader doesn't have to check painstakingly that two long
  expressions are indeed the same, or wonder why they're not.  And an
  assignment operator may even help the compiler to produce more
  efficient code.

I think it's clear from this passage that Brian Kernighan and Dennis Ritchie (K&R), believed that compound assignment operators helped with code readability.

It's been a long time since K&R wrote that, and a lot of the 'best practices' about how people should write code has changed or evolved since then. But this programmers.stackexchange question is the first time I can recall someone voicing a complaint about the readability of compound assignments, so I wonder if many programmers find them to be a problem? Then again, as I type this the question has 95 upvotes, so maybe people do find them jarring when reading code.


问:
Assuming "clean code/architecture" is there a difference in "effort" between PHP or Java/J2EE web application development?
A client asked us to estimate effort when selecting PHP as the implementation language for his next web-based application. We spent about a week exploring PHP, prototyping, testing etc., We are quite new to this language - may have hacked around it in the past but, let's go with PHP-noobs but application development experts (for the lack of a better, less flattering word :)

It seems, that if we write, clean maintainable code, follow separation of concerns, enterprise architecture patters (DAOs etc.) the 'effort' in creating an object-oriented PHP based web-application seems to be the same for a Java based one.

Here's our equation for estimating the effort (development/delivery time):

```<code>ConstructionEffort = f(analysis, design, coding, testing, review, deployment)
</code>```

We were specifically comparing effort estimates in creating an enterprise application with the following:

PHP + CakePHP/CodeIgniter (should we have considered others?)

Java + Spring + Restlet

It's an end-to-end application:

Client: Javascript/jQuery + HTML/CSS

Middle tier/Business Logic - (Still evaluating PHP/Java)

Database: MySQL

The effort estimates of the 1st and 3rd tier are constant and relatively independent of the middle tier's technology. At a high level with an initial breakdown into user stories of the requested features as well as a high-level SWAG on the sheer number of classes/SLOC that would be required for PHP doesn't seem to differ by much from what is required of the same in Java. Is this correct?

We are basing our initial estimates on the initial prototyping/coding we've done with PHP - we are currently disregarding fluency with the language as a factor, since that'll be an initial hurdle and not a long term impediment IMHO (we also have sufficient time to become quite fluent with PHP).

I'm interested in knowing the programmers' perspective with respect to effort when creating similar applications with either of the languages to justify choosing one over the other. Are we missing something here? It seems we are going against popular belief of PHP being quicker to market (or we being very fluent with Java have our vision clouded). It doesn't seem to have any coding/programming effort saving from what we/ve played around with.

答:
In general, you will be more productive in a language / framework you know well. This will likely be a bigger factor in productivity than any intrinsic differences between the language / frameworks.

Regarding the particular languages you are considering.:

PHP is good for quick, dynamic web sites. This is where PHP has its roots.

Java is better for more robust enterprise applications that need to be maintained / developed over the long term

It's worth noting that the Java platform (which you can consider separately from the language) is extremely powerful with probably the world's best GC, exceptional JIT compilation and a huge ecosystem of libraries and tools. In the long run, this is probably going to be a more attractive strategic choice for serious applications.

Since it sounds as if you already have Java platform skills but don't really know PHP, I would definitely pick Java over PHP for your middle tier implemetation. If you are interested in high productivity, you might also want to consider:

Dynamic JVM languages like Groovy or Clojure - these offer all the high productivity of modern dynamic languages with the advantages of being well integrated into the Java platform.

Modern Java web frameworks such as Play or Vaadin - the newer frameworks are IMHO much more productive than J2EE. J2EE is probably overkill unless you are building a mission critical enterprise application.

ContentLicense: CC BY-SA 3.0


问:
Can anybody recomend a good SEO book?
Im currently developing a ASP MVC site.

Is there any book out there for ASP MVC SEO or just SEO in general?

答:
SEO is not language-specific, since all web languages produce the html/css etc that the web 'runs on'.

However, many others (including myself) will recommend "The Art of SEO". It covers all fundamentals of SEO and explains many parts of SEO in-depth.

Title: Can anybody recomend a good SEO book?


问:
Is is preferable to design top down or bottom up?
As I understand, top-down design is by refining the abstract high level concept into smaller concrete and comprehensible parts, until the smallest building block is defined. On the other hand, bottom up defines low level parts, then gradually build up higher level blocks until the whole system is formed.

In practice, it is said best to combine the two methods: starts with high level specification to fully specify the domain knowledge, its relationship and constraints. Once the problem is well understood, smallest building blocks are created to build up the system.

The process of:

Creating requirement spec

Create a design spec (with diagrams)

Implement

Deliver

Repeat (in iterative development, rather than doing a whole chunk in each phase, we do a little bit each repeatedly, and got daily meeting to adapt to customer's dynamic requirement)

looks perfectly normal to me (with specs as plans). It has its flaws but that's why we got iterative development: instead of spending time on one phase, says, requirement analysis to study every possible thing in domain knowledge which is subjected to changes (possibly daily), we do a little bit of analysis, a little bit of design and then implement it.

Another way is that each iteration is a mini-waterfall fashion, where analysis is done in a few days (or a week). The same applies for design. The rest of time is spent for implementation. Is there something inherently wrong with top-down approach in combination with iterative development?

In his essay Programming Bottom Up, Paul Graham seems to encourage build from bottom up completely, or program it from bottom up, but not the requirement analysis/design phase:

Experienced Lisp programmers divide up their programs differently. As
  well as top-down design, they follow a principle which could be called
  bottom-up design-- changing the language to suit the problem.

As far as I get, what he meant is that Lisper still performs top-down design, but program bottom up, is that true? Another point he wrote:

It's worth emphasizing that bottom-up design doesn't mean just writing
  the same program in a different order. When you work bottom-up, you
  usually end up with a different program. Instead of a single,
  monolithic program, you will get a larger language with more abstract
  operators, and a smaller program written in it. Instead of a lintel,
  you'll get an arch.

Does this means that during the period of writing a program in Lisp, you end up with a generic tool?

答:
Top-down is a great way to describe things you know, or to re-build things that you've already built.

Top-down biggest problem is that quite often simply there is no "top". You will change your mind about what the system should do while developing the system and while exploring the domain. How can be your starting point something that you don't know (i.e. what you want the system to do)?

A "local" top down is a good thing... some thinking ahead of coding is clearly good. But thinking and planning too much is not, because what you are envisioning is not the real scenario (unless you've already been there before, i.e. if you are not building, but re-building). Global top-down when building new things is just nonsense.

Bottom-up should be (globally) the approach unless you know 100% of the problem, you need just the known solution to be coded and you don't care about looking for possible alternative solutions.

Lisp approach is the distilled bottom-up. You not only build bottom up but you can also shape the bricks the way you need them to be. Nothing is fixed, freedom is total. Of course freedom takes responsibility and you can make horrible things by misusing this power.

But horrible code can be written in any language. Even in languages that are shaped as cages for the mind, designed with the hope that with those languages even monkeys could get good programs up and running (an idea so wrong on so many levels that it hurts even just thinking about it).

Your example is about a web server. Now in 2012 this is a well-defined problem, you have specs to be followed. A web server is just an implementation problem.
Especially if you are aiming at writing a web server substantially identical to the other gajillion of web servers that are out there then nothing is really unclear, except some minutiae. Even your comment about RSA is still talking about a clearly defined problem, with formal specifications.

With a well defined problem, with formal specifications and already known solutions then coding is just connecting in the dots. Top down is ok for that. This is the project manager heaven.

In many cases however there is no proven well-known approach to be used to connect the dots. Actually very often is hard to say even what are the dots.

Suppose for example you are asked to instruct an automatic cutting machine to align the parts to be cut to a printed material that is not perfectly conforming to the theoretic repetitive logo. You are given the parts and pictures of the material as taken by the machine.

What is an alignment rule? You decide. What is a pattern, how to represent it? You decide. How to align the parts? You decide. Can parts be "bent"? It depends, some not and some yes, but of course not too much. What to do if the material is just too deformed for a part to cut it acceptably? You decide. Are all the material rolls identical? Of course not, but you cannot bug the user to adapt alignment rules for every roll... that would be impractical. What pictures are seeing the cameras? The material, whatever that may mean... it can be color, it can be black over black where just the light reflex makes the pattern evident. What does it mean to recognize a pattern? You decide.

Now try to design the general structure of a solution for this problem and give a quote, in money and time. My bet is that even your system architecture... (yes, the architecture) will be wrong. Cost and time estimation will be random numbers.

We implemented it and now it's a working system, but changed our mind about the very shape of the system a big number of times. We added entire sub-systems that now cannot even be reached from the menus. We switched master/slave roles in protocols more than once. Probably now we've enough knowledge to attempt re-building it better.

Other companies of course did solve the same problem... but unless you are in one of these companies most probably your top-down detailed project will be a joke. We can design it top-down. You cannot because you never did it before.

You can probably solve the same problem too. Working bottom-up however. Starting with what you know, learning what you don't and adding up.

New complex software systems are grown, not designed. Every now and then someone starts designing a big new complex ill-specified software system from scratch (note that with a big complex software project there are only three possibilities: a] the specification is fuzzy,  b] the specification is wrong and self-contradictory or c] both... and most often [c] is the case).

These are the typical huge-company projects with thousands and thousands of hours thrown into powerpoint slides and UML diagrams alone. They invariably fail completely after burning embarrassing amounts of resources... or in some very exceptional case they finally deliver an overpriced piece of software that implements only a tiny part of the initial specs. And that software invariably is deeply hated by users... not the kind of software you would buy, but the kind of software you use because you're forced to.

Does this mean that I think that you should think only to code? Of course not. But in my opinion the construction should start from bottom (bricks, concrete code) and should go up... and your focus and attention to detail should in a sense "fade" as you are getting farther from what you have. Top-down is often presented as if you should put the same level of detail to the whole system at once: just keep it splitting every node until everything is just obvious... in reality modules, subsystem are "grown" from subroutines.
If you do not have a previous experience in the specific problem your top down design of a subsystem, module or library will be horrible. You can design a good library once you know what functions to put in, not the other way around.

Many of the Lisp ideas are getting more popular (first class functions, closures, dynamic typing as default, garbage collection, metaprogramming, interactive development) but Lisp is still today (among the languages I know) quite unique in how easy is to shape code for what you need.

Keyword parameters for example are already present, but if they were not present they could be added. I did it (including keyword verification at compile time) for a toy Lisp compiler I am experimenting with and it doesn't take much code.

With C++ instead the most you can get is a bunch of C++ experts telling you that keyword parameters are not that useful, or an incredibly complex, broken, half backed template implementation that indeed is not that useful.
Are C++ classes first-class objects? No and there's nothing you can do about it. Can you have introspection at runtime or at compile time? No and there's nothing you can do about it.

This language flexibility of Lisp is what makes it great for bottom-up building. You can build not only subroutines, but also the syntax and the semantic of the language. And in a sense Lisp itself is bottom-up.


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

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

答:
A normal person believes a kilobyte is 1000 bytes, a coder believes a kilometer is 1024 meters.

-Unknown

LastEditorDisplayName: Roger Pate

ContentLicense: CC BY-SA 2.5


答:
What's wrong with top-down approach in combination with iterative development?

Using a top-down approach with iterative development does not deliver any working code in the first iterations. It delivers design documents and such which the customer will have a hard time with giving feedback on. Responses like, "yeah I guess (this is too abstract for me)" will not help you along in further specifying the specifics of the desired system by the customer.

Instead you only create a general overview of what is requested. (Requirements) to use as a general guideline for what defines a finished product and what deserves priority to implement.
From there on you create working products for every iteration which the customer can actually toy with to see if this was what they had in mind. If not, then it won't be an issue as there has not been spent hundreds of hours into designing a system that works different from what the customer asks now.

did Paul Graham encourage build from bottom up completely? Or just program it from bottom up, but not the requirement analysis/desing phase?

I will not speak for another person. Also I didn't read his essay. The answer I'm giving you comes from my education as well as experiences.

This means, during the period of writing a program in Lisp, you end up with a generic tool which can be used to write similar programs of the original one, doesn't it?

Using this approach means that you will end up with more abstract building blocks. Simply because you will have to build standalone subsystems that can be presented straight away you can't create a top-down design that is heavily intertwined and has to be implemented all at once. It improves re-usability, maintainability but most of all allows more flexible response to change.

Title: Is is preferable to design top down or bottom up?

Body:
As I understand, top-down design is by refining the abstract high level concept into smaller concrete and comprehensible parts, until the smallest building block is defined. On the other hand, bottom up defines low level parts, then gradually build up higher level blocks until the whole system is formed.

In practice, it is said best to combine the two methods: starts with high level specification to fully specify the domain knowledge, its relationship and constraints. Once the problem is well understood, smallest building blocks are created to build up the system.

The process of:

Creating requirement spec

Create a design spec (with diagrams)

Implement

Deliver

Repeat (in iterative development, rather than doing a whole chunk in each phase, we do a little bit each repeatedly, and got daily meeting to adapt to customer's dynamic requirement)

looks perfectly normal to me (with specs as plans). It has its flaws but that's why we got iterative development: instead of spending time on one phase, says, requirement analysis to study every possible thing in domain knowledge which is subjected to changes (possibly daily), we do a little bit of analysis, a little bit of design and then implement it.

Another way is that each iteration is a mini-waterfall fashion, where analysis is done in a few days (or a week). The same applies for design. The rest of time is spent for implementation. Is there something inherently wrong with top-down approach in combination with iterative development?

In his essay Programming Bottom Up, Paul Graham seems to encourage build from bottom up completely, or program it from bottom up, but not the requirement analysis/design phase:

Experienced Lisp programmers divide up their programs differently. As
  well as top-down design, they follow a principle which could be called
  bottom-up design-- changing the language to suit the problem.

As far as I get, what he meant is that Lisper still performs top-down design, but program bottom up, is that true? Another point he wrote:

It's worth emphasizing that bottom-up design doesn't mean just writing
  the same program in a different order. When you work bottom-up, you
  usually end up with a different program. Instead of a single,
  monolithic program, you will get a larger language with more abstract
  operators, and a smaller program written in it. Instead of a lintel,
  you'll get an arch.

Does this means that during the period of writing a program in Lisp, you end up with a generic tool?


问:
What factors should I consider when choosing names for identifiers?
What factors do I need to consider when choosing names for identifiers such as variables? I am concerned about space issues, i.e. extra memory consumption when choosing longer names.

As an example, take these two variables:

```<code>bool noExp = true;
bool willNotExpireEver = true;
</code>```

Each one will take up memory the size of bool. But what about the variable names? They are after all characters that have to be stored somewhere. Where does the space for them get allocated? Am I wasting pace by choosing longer names?

答:
First, to answer the obvious sub-question:

"so is it better to name variables short..."

Short answer: No.

Long answer: Variable-names are for the programmer's amusement only. The linker replaces references to variables with memory-addresses and there is no run-time overhead at all. Also, it is bad practice to use variable-names that dont mean anything.

The title of your question "best way to name variables" is very broad and there are good names and bad names. In general it is a good idea to use something descriptive (what is it) and distinctive (how is it different than the other variables), more specifically there are certain best-practices like describing the type of the variable as a short prefix like in hungarian notation, like intTotal and strUsername.

I hope this helps!


答:
Is there appropriate way to declare variables name to avoid memory or space issues.

Variable names are mostly for humans. The C# compiler does not care about your name as long as it obeys language rules. So, to answer your question, there are no memory or space issues that could result just from the name.
However, there are problems that could result from using the same name with different scoping but this is not what you are asking about.

bool noExp = true;
  bool willNotExpireEver = true;

two variable should occupy same space in memory that is size of bool rite?

No. In general each variable occupies different memory location for a period of time in the program's execution life time. This duration depends on where it is declared and when it was disposed of.

now where do variable names go? I mean they are somehow characters after all, where do they get space?

The role of the compiler is to take your friendly English like names and convert them to addresses to be used by the binary code. That is why the English name does not really matter to the compiler.

so is it better to name variables short or it does not matter?

As suggested by other answers, there are some common conversions on how to name variables.
This is a matter of taste, and due to some lessons learned by others. In general, don't include the variable type as part of the name.

Title: What factors should I consider when choosing names for identifiers?

Body:
What factors do I need to consider when choosing names for identifiers such as variables? I am concerned about space issues, i.e. extra memory consumption when choosing longer names.

As an example, take these two variables:

```<code>bool noExp = true;
bool willNotExpireEver = true;
</code>```

Each one will take up memory the size of bool. But what about the variable names? They are after all characters that have to be stored somewhere. Where does the space for them get allocated? Am I wasting pace by choosing longer names?


问:
What is the ideal learning path to building Android apps with Scala, without prior Java experience
Unfortunately, there are not currently any books on the subject of 'Learn Android Development with Scala', which would be the ideal solution. I'm guessing that I'll need to pick up at least 3 books here, one for each topic. However, I have no idea what order to read them in, whether to read them simultaneously, what parts of the Java book I can safely skip, etc.

What is the best path for me to get started building Android apps using Scala?

答:
The most detailed resource I know for android developers is: http://developer.android.com/index.html

developing android apps with scala has not developed to a satisfying standard just yet. you can read about it more here: http://www.slideshare.net/janberkel/android-development-with-scala


答:
During runtime both variables occupy the same amount of memory. So here's no reason for optimization. But code is not for the one time shot, it's also for the maintenance of the project. It for different people trying to understand the code and the semantics after maybe a long time. So it's important that the meaning of the variable (or any other identifier) is in the given context as helpful as possible.

That doesn't mean that all variable names should be as long as possible. It depends of their scope and the transparency of the surrounding code. But when giving a class, method, constant or variable a name always keep in mind that anyone else may sometimes have the task to understand your code and your intention. This way you easily know when to just use a variable like i in a for-loop or MyUserfulEntityProxy for a class.


答:
This question has been answered before on stackoverflow.

To quote from there:

No it doesn't. Compiler actually does not save original variable names, you can look at the IL code of any compiled assembly with disassembler.

So to cut it short, no there are no factors that support preferring shorter identifier names.

However, there are some side effects that should be considered when optimizing for performance: Don't compromise on maintainability!

When optimizing for performance, benefits that might be gained by optimization should always be valued against the disadvantages it brings you. Suppose variable name length would have an effect, it is often wiser to choose longer names to further readability and improve maintainability through this. But longer is not always better either. Openly discuss the choice of variable names through code reviews.

Also, variable names should is not something that is going to be there eternally. Be bold and refactor if the name does not fit the variable content anymore.


答:
To me, the most important remarks Paul Graham makes in his article are these:

[...] Lisp programmers [...] follow a principle which could be called bottom-up design-- changing the language to suit the problem. In Lisp, you don't just write your program down toward the language, you also build the language up toward your program.

Or, as it is known in C++ circles: Library Design is Language Design (Bjarne Stroustrup)

The main idea of top down design is: first you plan, then you code. Beanow is correct when he writes, that there are problems when executable code comes late in the process. In bottom up design you always have code, and that code that can be tested.

Also, your code is not flat. By that I mean, it tends to have more levels of smaller abstractions. In top down design people often end up with big abstrations down to some arbitrary level and below that no abstractions at all. Code designed bottom up OTOH often contains less low level control and data structures since they are likely to be abstracted away.


问:
Assembly in a research paper
I am doing a research paper on programming, and I need to somehow explain assembly... I've never learned the language, but I understand what it is used for and kinda what it looks like...

```<code>MOV A,47
ADD A,B
HALT
</code>```

And from what I understand, it is used for writing some compilers, small bits of code that need to be really fast, and other tasks... But this is kind of a question for people who have used/studied assembly and understand it fairly well. And no, I'm not asking for you to type up this segment of the research paper for me. That would be selfish. I just need a brief explanation, clarification on the subject (I'm just unsure if what I know is true or not) and a pointer in the right direction.

For a research paper (I need to explain this VERY simply...) what is purpose of using Assembly in today's society? Of course it was important back in the day but now with all the high level languages, when is this low level language used?

答:
It's an oversimplification but Assembly is as close as you can get to the machine.  As compilers and hardware performance advance this is less important but situations still exist.  Some examples:

Graphics - these are machine specific.  Getting 100% of what the device will give you requires assembly.

Optimizing speed - if it really needs to be fast and you are smarter than the compiler.  (historically a big reason - less so today)

Legacy code - once upon a time memory and processing speed were more expensive than human time.  People wrote assembler to optimize limited resources.  Believe it or not some of this code is still around.

Embedded devices - by definition very close to the machine.

Good luck on the paper prohect  As always, please cite sources you use from here.  Why not share what you come up with?

Title: Assembly in a research paper


问:
How can I get into C++ graphics library?
I have been programming for a year so far and I know 2 languages: C and C++. I've covered the basics, I've written functional windows programs, and I've written complicated bits of code. When I was using Turbo C for learning the C language I noticed a library called "Graphics.h". I've looked it up and I received amazing examples of graphics manipulation. My question is straightforward. How can I get started with learning graphics in C++? Is there a good tutorial that covers it all up?</p>

答:
graphics.h isn't relevant to anything. It's been 10-15 years since that header was useful. The same for the Turbo C compiler.

You need to upgrade your compiler to, let's say, Visual Studio 2010 Express (free) for Windows. Then you can look at things like Direct2D and GDI+ for 2D graphics.


问:
What is the best way to allow a client to contribute to a project?
We've been building a CRM for a client. Now that the first major phase has been finished, and a second one agreed upon, the client would like to pick up some of the work, making minor amendments to the database schema and business processes the first phase while we build the second.

I'm undecided whether this is at all practical, but assuming it is, I'd like some pointers on which measures can be taken to make this at all workable. Here's what I've got so far:

Until now, the client has mostly seen the project from a user's point of view; clearly, a two-part seminar ought to take place where we introduce him to the inner workings:

first, showing the existing database schema and, by way of example, extending it,

then, showing some sample code, and writing a new business process for the schema enhancement.

The code currently resides in an internal Subversion repository. While we could set up a public one or one on his network (which we can VPN to), I feel a distributed system would work better. I appear to be the only one who feels that way, however, so I could use some good convincing arguments.

I'm not sure how to mandate/ensure that code that runs in production is committed. Seems like "x made a critical, undocumented change right before going on vacation; now y's trying to figure out this bug that's been occurring ever since" disasters are inevitable. Ideally, all changes, before deployment, would:

be documented in an issue tracking system,

occur on a separate testing environment first, and

have to pass automated tests.

Alas, I doubt the discipline for any of those will prevail.

Assume that a plug-in architecture or separate project aren't viable options, because 1) the former doesn't exist, and 2) the latter would prohibit the client from looking at and possibly modifying existing code, an ability I believe he would insist on.

答:
Seems like this is a much a management issue as it is a technical issue.  I've dealt with situations like this in both consulting and software firms.  From an overall "How much value will the customer get out of the software?" and "How much effort will I need to maintain it post-production?" this is actually a good situation for you.  Many clients insist on their people being involved.  It will take a lot of work though.

Beginning with the end in mind, you will need is a good Statement of Work.  This will list what you're on the hook for, and what they're on the hook for.  A Roles and Responsibilities matrix is a less legalistic document that describes who owns each item, who is involved, and who just needs to be informed.  Both of these assume that you have a well defined Work Breakdown Structure that list at a low level (low enough to estimate) what each task is.

In terms of creation, it's usually the reverse order:  Scope (which you clearly already have) -> WBS (which you may have) -> Roles and Responsibilities matrix -> SOW.

Once you have the ownership clearly defined, it's time to manage the code and environments.  I am fairly agnostic on code management tools.  What I will say is that it's vital to do a code review for everything done by someone outside the core team.  If the tool you're using flags this, all the better.  You want to avoid someone clamping something on that goes against key architectural decisions previously made.  The 4 eyes concept (2 additional eyes reviewing everything) is the single most important tactical decision you can make.

Environments are also painful to manage.  Usually I've experienced situations where "We do our work on our environment, when we're done it goes to yours" and both the vendor and client struggle through.  Your situation sounds more complex.  I'd advise to try and find a way for them to work in your environment until the project is finished.  If you can find a way to train the client in managing their environments (don't assume they're good at this) then all the better.

A couple other caveats...

Don't assume the client has the same productivity as your team.
(You'll get upwards surprises on domain knowledge, downward
surprises on speed specific to your software.)

Don't assume the client knows your methodology.

Don't assume the client shares your team's workethic.  (I've seen
both upwards and downwards surprises.)

Spend lots of time training and co-locating.

Every hour spend teaching the client to troubleshoot will save many days in the future.

Do utilize the client to work through their internal organization for you, and find experts in content and domain questions.

Do utilize the client to sell train their organization.

By default involving clients in your development process will force you to think like a professional services firm.  David Maister wrote the best book on the topic.  Even if only 20% is relevant to you, it's worth reading.

Despite all these caveats, including clients in your teams can do wonders to bringing you closer to your buyers.  These clients are the ones most likely to be future references.  Good luck in making the best of this situation!


问:
Managing constants in application
Our application is having 2 parts a web app running ROR and a web service running Sinatra. The application communicates with the mobile device for which we use different constants depending on the message we need to the send to the device.
We are currently using integer constants saved up in a module. Eg:

```<code>SEND_HI="122"
</code>```

As the application has grown and we have around 50+ constants we are realizing that this is a bad way to handle constants as different developer seems to give different constants and clashes occur. Also there is a mismatch between the constant values in ROR and sinatra (due to developers mistake obviously).
What is a pain free way to handle constants or message identifiers.

答:
The two big techniques in this area are namespace management and "single-source-of-truth".

The basic idea of namespace management is to have a hierarchy of naming so that the name of a constant make it clear what part of the system it relates to, and what it's for.   In C++ for example, this is done with the "namespace" keyword, while in Python and Java this is done via class and module names.

Single-source-of-truth is a technique for managing shared constants across different implementation languages.  The idea is that you maintain the master values for a specific category of constants in a single file.   This file is then processed by your build system to generate as output a definition in each implementation language in your wider system.   This means that there's a single place for maintaining these, and (say) the C header file which the C-based part of your system includes to get the values of the constants is never checked in to the version control system.  There is only one place to update the value of a constant, or add a new related constant.

Title: Managing constants in application


答:
Back in the graphics.h days each compiler had it's own limited graphics library.

Now you program to either DirectX (Microsoft) or OpenGL (everywhere). After a few years of being sidelined to high-end Unix cad OpenGL/OpenGLEs is making a big splash  on mobile devices

For a list of books see https://stackoverflow.com/questions/5926357/c-opengl-books

One warning - there are a lot of 20year old out of date opengl tutroials on the web - start here An intro to modern OpenGL.

ps. Some of the maths of 3D graphics (matrix transformations etc) might be beyond what you have covered in school but it's very easy - you just have to sit down and work through it. But do go through all the math until you understand it, you will need it!

Title: How can I get into C++ graphics library?

Body: I have been programming for a year so far and I know 2 languages: C and C++. I've covered the basics, I've written functional windows programs, and I've written complicated bits of code. When I was using Turbo C for learning the C language I noticed a library called "Graphics.h". I've looked it up and I received amazing examples of graphics manipulation. My question is straightforward. How can I get started with learning graphics in C++? Is there a good tutorial that covers it all up?</p>


答:
Graphics typycally require some knowledge about platform specific interfaces, some general math, and eventually some typical pattern.

You can start from the Widows GDI (and GDI+) and from the X Window system (for Unix/Linux)

and move to 3d with openGL(every platform) or Direct3d(on Windows)


问:
In Scrum, should tasks such as development environment set-up and capability development be managed as subtasks within actual user stories?
Sometimes in projects we need to spend time on tasks such as:

exploring alternate frameworks and tools

learning the framework and tools selected for the project

setting up the servers and project infrastructure (version control, build environments, databases, etc)

If we are using User Stories, where should all this work go?

One option is to make them all part of first user story (e.g. make the homepage for application). Another option is to do a spike for these tasks. A third option is to make task part of an Issue/Impediment (e.g. development environment not selected yet) rather than a user Story.

答:
Do whatever makes most sense in your company. Don't ever let how other people do things be a hindrance to common sense.

But I will say that all of these tasks sound like something that should happen long before you start development. So I question whether Scrum is even relevant to these tasks. There is some ongoing maintenance and such to source control and databases, but these shouldn't be scheduled, they should just be things that happen and effect your velocity.

There will be times when you have to select a framework or whatever during a project, but when I say that I mean a framework like nHibernate, not a framework like .NET. In those cases, research should be spiked and timeboxed, not to mention fairly short. Try to manage it as if you had a developer off sick for a couple of days.

Knowledge transfer is another ongoing process which should be managed outside of the general development velocity.


问:
How to estimate sprint velocity with varying team capacity?
We are a small team of 4 devs rather green in Scrum. Coming from all over the country, we often take odd days off or whole weeks off to go home. Therefore our team capacity changes dramatically from one iteration to another due to annual leaves, which leads to very different velocities from one iteration to another. How do we account for team capacity when estimating velocity at the Planning Meeting? Historical data will reflect very different capacities and we cannot wait one whole year to derive an average for our estimate velocity.</p>

答:
Velocity can vary even if capacity remains same.

So just trust your velocity it will take care of varying capacity itself i.e. assuming you are into 3rd sprint, take average of the last two completed sprints to commit to the next sprint. do not worry about variance in capacity.


答:
Kurzfristige Hacks tendieren dazu, langfristige Lösungen zu werden.

  — Bodo Tasche

Translated: Current hacks tend to be long-term solutions.

Body:
What's your favourite quote about programming?

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


答:
One option is to make them all part of first user story e.g. make the homepage for application.

Breaks "user story" as a concept.  What user is involved in this?  None.  This is work you should already have done.

Another option is to do a spike for this.

Not bad.

Third option is to make task part of an Issue (e.g. Development environment not selected yet) rather than a user Story.

About the same as a spike as far as planning and overheads are concerned.

Setup is not a user story.

It's what you should have in place before you even started this project.

You can't really start the project unless you have the framework/tool and servers setup and ready to go.

I'm well aware that many organizations don't really exist until after the contract is signed.  I'm also well aware that many organizations don't choose a technology until after the contract is signed.  These are all inefficient things that are outside any user stories.

Title: In Scrum, should tasks such as development environment set-up and capability development be managed as subtasks within actual user stories?

Body:
Sometimes in projects we need to spend time on tasks such as:

exploring alternate frameworks and tools

learning the framework and tools selected for the project

setting up the servers and project infrastructure (version control, build environments, databases, etc)

If we are using User Stories, where should all this work go?

One option is to make them all part of first user story (e.g. make the homepage for application). Another option is to do a spike for these tasks. A third option is to make task part of an Issue/Impediment (e.g. development environment not selected yet) rather than a user Story.


答:
We thought about this problem quite a lot in the past year.

While I agree that a basic framework should exist before the project starts, in practical use it can be part of the project itself. So you have to manage somehow.

While mixing project setup with user stories might make sense sometimes we have settled on  simple tasks that can be added to the product backlog and get the same attention as user stories. We know that these technical tasks are necessary sometimes, but they have to be justified in any case. If the team thinks that they are absolutely necessary to achieve a certain goal, they will be part of a sprint.

It's hard to say what works best for you, so experiment! A spike might suffice for now, but I think you'll end up with the same problem later, so plan ahead. Do tasks that are a placeholder for such activities. To separate tasks from stories two I will quickly compare them based on my experience with them.

Task: A task is a technical necessity. It might be things for configuration management or general project setup, like setting up a repository for commits, or adding the hottest code review tool you have ever seen to the development process. Tasks should be considered in planning, same as a user story. If the team can convince the product owner that having the latest and greatest code review tool increases performance and ups team communication by eliminating long lasting pair programming sessions or in-person code reviews, then it will get the product owner's attention.

Stories: Focused on business perspective only, stories always produce visible value to the customer. Internal quality is something that goes along with producing business value.

We even assign story points to tasks and sometimes work with them the same we would do with stories.

In the end I would go for this solution in your case (which could be applied in general as well):

Separate "setup" and technical stuff into tasks (stuff that does not directly produce business value for the product owner).

Maybe do a spike prior to project setup to get the most important tools into place (SCM, dev tools, process defintion, coding standards etc.)

Accept that these tasks pop up over the duration of the project and plan for this by having a separate "type" of activities other than stories.


答:
A simple graphics library is the Simple Fast Multimedia Library for C++ which is cross platform, modern and very easy.

SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network.

Discover their features more in detail in the tutorials and the API documentation...

With SFML, your application can compile and run out of the box on the most common operating systems: Windows, Linux, Mac OS X and soon Android & iOS.

Pre-compiled SDKs for your favorite OS are available on the download page...

SFML has official bindings for the C and .Net languages. And thanks to its active community, it is also available in many other languages such as Java, Ruby, Python, Go, and more.

Learn more about them on the bindings page...

Alternatively you could use OpenGl (I would prefer due to platform independence) or DirectX.


问:
What are the practical uses of Windows Services?
I am new to working with Windows Services. Although I have learnt to create  Windows Services in VS2010  I would like to know some practical ways in which windows services could be used?

I tried Googling with the current context in mind only to find more tutorials on how to create Windows Services.

EDIT on Bounty Offer:

All the answers are great but I was looking for more practical examples on windows services and their implications? This will help developers know when it is appropriate to use them with the case study.

答:
Here's a sample usage of the service concept with real code (se below).

What it does is to configure a service bus that consumes off of a queue and listens to messages from web servers and client GUIs.

When it receives the messages it does what logic the domain warrants, it saves the events to disk and publish those events to the message broker.

Most larger applications that are loosely coupled implement some sort of "worker" architectures like the thing below.

The Documently project is a sample project that we have created for people like yourself to learn distributed architectures with. You can ask questions directly to me in the project, or fork it and implement some feature to learn from and then submit a pull request (and get code comments).

https://github.com/haf/Documently/blob/master/src/Documently.Domain.Service/Program.cs:

```<code>using System.Threading;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Documently.Infrastructure;
using Documently.Infrastructure.Installers;
using MassTransit;
using Topshelf;
using log4net;
using log4net.Config;

namespace Documently.Domain.Service
{
    class Program
    {
        private static readonly ILog _Logger = LogManager.GetLogger(typeof (Program));

        private IWindsorContainer _Container;
        private IServiceBus _Bus;

        public static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "Domain Service Main Thread";
            HostFactory.Run(x =>
            {
                x.Service<Program>(s =>
                {
                    s.ConstructUsing(name => new Program());
                    s.WhenStarted(p => p.Start());
                    s.WhenStopped(p => p.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Handles the domain logic for the Documently Application.");
                x.SetDisplayName("Documently Domain Service");
                x.SetServiceName("Documently.Domain.Service");
            });
        }

        private void Start()
        {
            XmlConfigurator.Configure();
            _Logger.Info("setting up domain service, installing components");

            _Container = new WindsorContainer()
                .Install(
                    new RavenDbServerInstaller(),
                    new CommandHandlerInstaller(),
                    new EventStoreInstaller(),
                    new BusInstaller(Keys.DomainServiceEndpoint)
                    );

            _Container.Register(Component.For<IWindsorContainer>().Instance(_Container));
            _Bus = _Container.Resolve<IServiceBus>();

            _Logger.Info("application configured, started running");
        }

        private void Stop()
        {
            _Logger.Info("shutting down Domain Service");
            _Container.Release(_Bus);
            _Container.Dispose();
        }
    }
}
</code>```

Body:
Here's a sample usage of the service concept with real code (se below).

What it does is to configure a service bus that consumes off of a queue and listens to messages from web servers and client GUIs.

When it receives the messages it does what logic the domain warrants, it saves the events to disk and publish those events to the message broker.

Most larger applications that are loosely coupled implement some sort of "worker" architectures like the thing below.

The Documently project is a sample project that we have created for people like yourself to learn distributed architectures with. You can ask questions directly to me in the project, or fork it and implement some feature to learn from and then submit a pull request (and get code comments).

https://github.com/haf/Documently/blob/master/src/Documently.Domain.Service/Program.cs:

using System.Threading;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Documently.Infrastructure;
using Documently.Infrastructure.Installers;
using MassTransit;
using Topshelf;
using log4net;
using log4net.Config;

namespace Documently.Domain.Service
{
    class Program
    {
        private static readonly ILog _Logger = LogManager.GetLogger(typeof (Program));

        private IWindsorContainer _Container;
        private IServiceBus _Bus;

        public static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "Domain Service Main Thread";
            HostFactory.Run(x =>
            {
                x.Service<Program>(s =>
                {
                    s.ConstructUsing(name => new Program());
                    s.WhenStarted(p => p.Start());
                    s.WhenStopped(p => p.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Handles the domain logic for the Documently Application.");
                x.SetDisplayName("Documently Domain Service");
                x.SetServiceName("Documently.Domain.Service");
            });
        }

        private void Start()
        {
            XmlConfigurator.Configure();
            _Logger.Info("setting up domain service, installing components");

            _Container = new WindsorContainer()
                .Install(
                    new RavenDbServerInstaller(),
                    new CommandHandlerInstaller(),
                    new EventStoreInstaller(),
                    new BusInstaller(Keys.DomainServiceEndpoint)
                    );

            _Container.Register(Component.For<IWindsorContainer>().Instance(_Container));
            _Bus = _Container.Resolve<IServiceBus>();

            _Logger.Info("application configured, started running");
        }

        private void Stop()
        {
            _Logger.Info("shutting down Domain Service");
            _Container.Release(_Bus);
            _Container.Dispose();
        }
    }
}


问:
Sharding with IoC
I've come across a situation where I need to shard a database (Oracle, but that doesn't particularly matter).

The gist of the problem is I have written a large-scale system in a fairly standard TDD-style, with repositories and services hidden behind interfaces. Dependency injection is used to implement particular versions of the services and repositories at runtime, with this functionality allowing for crazy client requirements (for example we migrated from MSSQL to Oracle in under a week, which would not have been possible if the architecture was not properly decoupled!).

The problem now arises that I need to shard off a large portion of the data into a separate archival system, for performance reasons. The table structure has to remain the same due to time constraints, and I would like the purity of the architecture to remain the same, with no one section of the system having knowledge of the inner workings of another. The system will need to be switched from one shard to another dynamically via a user input (what input this is is yet to be finalised).

So, the two ways I can think of to approach this issue are:

1 - Pass in the required connection string on creation of a repository. This is not ideal as it means that the service layer, or worse, the UI, needs to know about the underlying sharding. This will make the design very inflexible in future, and require things like the sit-in-front caching layer (a write-through cache implementation on top of the IService) to be updates so their methods take a connection string as a parameter, which just seems wrong.

2 - Create a new IConnectionProvider subsection of the system that abstracts the connection information for the repository. This would be more ideal, as the repositories would remain self-contained, but I cannot think of a good way to switch this implementation without having to specify the relevant interface as a parameter to each method call, which goes back to the service layer specifying which connection to use.

Does anyone have any experience with this issue, or any opinions on a preferably low-labor yet still fairly pure implementation in this situation?

答:
I think it depends on how well your entities that you are persisting are segregated. If they are coupled and you are relying on cross-table joins to bring some arbirary read (+projection) state up and then deserialize it back, then you probably have a problem.

On the other hand, if you can load an entity or aggregate root + value objects from your repository without having to pull up a complete cross-entity-boundary object graph and have that be consistent in a transaction, then there's definitely the possibility there to shard in the repository.

In my world, the repository is the actual thing that implements sharding - it's a coherent 'bag of entities by id'.

That said; what are your sharding on? Entity type? Then, e.g. with Windsor, use an IHandlerSelector implementation that looks at the type of the repository (meaning type of entity requested) and chooses the right instance depending on whether it's a 'hot' entity, or a 'cold' one.

Similarly, for ranges of keys or based on entity data/attributes, you could do a handler selector that looks at some thing on the entity.

An alternative is to start publishing an event stream from operations on your entities and have those events create a read model that is denormalized already; avoiding the join-problems that might be the root cause of your scalability problems (this is speculative from my side based on experience).

Title: Sharding with IoC


问:
Interacting With Data Using Multiple Databases/Servers
All of the projects that I've had to deal with so far have only required a single database on a single server. I'm interested in learning more about how projects that need to scale move to  multiple databases and/or servers to help manage the load. I'm aware of High Scalability, but I'm particularly interested in some code examples or additional resources where I could read more on the subject.

For instance:

How are joins constructed between two tables on multiple databases? (A code example here would be helpful).

Are there any special strategies for tracking which tables are in which database?

Does the application code need to know that one or more databases are spread across multiple servers? If not, at what level are the requests filtered?

When is it time to move beyond a 1 database/1 server setup? How common is it to need to do this?

答:
There are three major types of replication configurations for databases:

Master-Slave

Master-Master

Consensus

Master-Slave example: MySQL master + MySQL slaves, MongoDB

Master-Master example: CouchDB, Cassandra, Riak

Consensus example: ScalienDB

...to name a few.

These have different characteristics. Master-slave configs allow slave nodes to catch up with the master at their maximum rate while serving read-requests very rapidly, while the master server is responsible for the data integrity. Because all writes go to the master, there is never lock contention because a single relatively slow writer is blocking many readers, but on the other hand, the slave servers are eventually consistent and you don't get the transaction isolation guarantees that you would have from reading only from the master. (further reading; ACID vs BASE, Transaction isolation levels, database replication, MVCC/Isolation: Snapshot, Transactional Replication)

Master-Master always allow writes, so you'd have multiple authorities on what is true. This may or may not be a problem, depending on what your application is doing, but if you write conflicting data you may get multiple results the next time you read that key/row/column which you'll have to merge with application logic and save back to the database. (further reading: CAP-theorem, CouchDB replication, Riak replication, consistent hashing, Bitcask & StormDB, Quorum- w/ MongoDB on network split, merge resolution strategies)

Consensus-based databases with replication across nodes, such as Scalien would always be consistent on writes, but at the cost of exchanging multiple messages before ACKing the write. This isn't much of a problem if you have a fast ethernet and you don't need to write to disk before ACKing, which you won't need if your minimum of three servers are on different server racks with separate power supplies (one dies; the other two makes sure they've saved on disk). (further reading; PAXOS, PAXOS COMMIT, two-phase-commit with distributed transactions, three-phase-commit)

Misc further reading: (book: 'Elements of Distributed Computing', vector clocks, version vectors, matrix vectors, logical clocks, bakery algorithm, interval tree clocks, actors and reactive programming and reactors, software transactional memory, transactors, AKKA, Stact, fallacies of distributed computing, gossip protocols, Cassandra's anti-entropy gossip protocol extensions, distributed hash tables, papers on merging data in a distributed setting, ZooKeeper architecture, InfoQ-presentation on "asynchronous protocol", HBase architecture, MapReduce paper, Amazon Dynamo paper that started all NoSQL-stuff, queueing, rabbitmq high-availability clustering)

I hope I gave some food for thought :). You can follow me on twitter @henrikfeldt if you want tweets about this stuff, too.


答:
For programmers the primary reason for using service is:

This program needs to start automatically on a Windows machine after a reboot.

Anything you write which must conform to the above must run as a Windows Service.

Title: What are the practical uses of Windows Services?

Body:
I am new to working with Windows Services. Although I have learnt to create  Windows Services in VS2010  I would like to know some practical ways in which windows services could be used?

I tried Googling with the current context in mind only to find more tutorials on how to create Windows Services.

EDIT on Bounty Offer:

All the answers are great but I was looking for more practical examples on windows services and their implications? This will help developers know when it is appropriate to use them with the case study.


问:
How to design classes in right way (sending messages)
Trying to design small project in right way and have a trouble in it:\

about task: need to realize multiplication of big numbers, using fft

First, i have classes

```<code>class LargeNumber{};
class Field{}; -- abstract (maybe interface would be better)
class C_C:public virtual Field{};
class Z_p:public virtual Field{};
</code>```

So, LargeNumber can use Z_P(modulo P) or C_C(complex) classes (more correct: C_C and Z_P have Mul and Sum functions to multiply LargeNumber objects)

but another task more interesting and difficult.

I need to calculate all operations and time each 'big' operation take. And also need to throw messages and create logs.

How to solve this problem? ( what should i do? )

Also will be great, if you comment patterns and your best practices.
and so this classes:

```<code>class LargeNumber {
  private:
  int length;
  vector <short int> number;
  public:
  //prototype
  LargeNumber clone(){
        return (*this);
  }
  //get
  int Length() const;
  vector <short int> Number()const;
  //static
  static LargeNumber& GenerateOne(int);// create new LargeNumber
  static void Print(const LargeNumber& print);
  //constructors
  LargeNumber();
  LargeNumber(const LargeNumber& obj);
  explicit LargeNumber(int len);
  explicit LargeNumber(vector <short int>);
  LargeNumber(int,int);
  //destructors
  ~LargeNumber();
  void Kill();
  //operators
  LargeNumber& operator= (const LargeNumber& );
  LargeNumber& operator--();
  LargeNumber& operator++();
  bool operator<(const LargeNumber&)const;

  };

 class Field {
  private:
  inline int max(const int a, const int b){return (a>b?a:b);}
  inline int min(const int a, const int b){return (a<b?a:b);}
  int i;
  //need Mod and 2**P-1
  LargeNumber& Deux (const int );

  LargeNumber& Mod (LargeNumber&);
  public:
         virtual ~Field();
         virtual LargeNumber& Sum (const LargeNumber& , const LargeNumber& );
         virtual LargeNumber& Sub (const LargeNumber& , const LargeNumber& );
         virtual LargeNumber& Mul (const LargeNumber& , const LargeNumber& );
         virtual LargeNumber& Pow (const LargeNumber& , const LargeNumber& );
         virtual bool Prime (LargeNumber& );

  };
</code>```

答: Don't reinvent the wheel, use a good existing implementation of arbitrary-precision arithmetic, like Bruno Haible's CLN (which is partly based on GNU GMP).</p>


答:
OK, so here's another viewpoint on scalability.

Let's discuss what it means for things to be data, what it means to have behaviour and what it means to have application logic.

Normally, when one ventures into the land of enterprise applications and the like, one would have exposure to the idea of layering. Of course, layering is all over the place in computers, such as in the networking stack (ISO model), or in graphics (Photoshop), or in SOA (services may call siblings or children, but never parents).

However, the specific type of layering that has been abused with no regard what so ever is that of the 'GUI', 'Business Logic Layer' and then 'Data Access Layer'. I mean, yeah, the idea is good in principle, like communism is good in principle, but in reality it's not.

Let's have a look at why. The argument I'm going to use is about coupling; points from one layer that touches points at another layer. Whenever you start creating a n-tier aka layered app in the default-enterprisey-mode that people go into, they create sooo many points of contact between the layers.

In its core, the idea is that layers are interchangeable; but they are not! Why? Because of all the call-site coupling.

Instead, have a look at why network is decoupled! Because the interface is a byte-stream over a single file pointer that points to an open socket! All of the layers in the ISO models are like what the design pattern called 'chain of responsibility' is to object orientation! Each layer wraps the underlying layer, without knowing the semantics of the data in that underlying layer.

As a package of data walks towards ethernet and raw electrical signals at the bottom it gets continuously wrapped by layers that only know of its own specific message envelope, its own specific 'batch of bytes' that it can send; and nothing else. It does not need to alter call-paths depending on the contents of the package.

Contrast this to n-tier where you would have to alter call-path in your application layers on a 'call' traversing your layers on its way to the database - for example, 'gold customers' are polymorphically a superset of 'normal customers' and so because we use 'table-per-subclass' we need to know about this now that the data (entity) is traversing the layers; both in the so called 'business logic layer' and in the data layer which is actually doing the saving.

It's neither scalable nor optimal from a computing perspective.

Why is it not scalable? Because the architecture is coupled, and then you're still inside the same old DB that you were trying to scale out to many nodes! But, because you need ACID for this, that and a third entity (data object) you need to have them in a single database that does transactions!

Righty, so with that rant out of the way; what other ways are there?

Well, there's the hated acronym called 'SOA', i.e. service oriented architecture. Of course, the Tomas Erls of the world, would have you implement all your layers but with XML and SOAP instead.

For all of the above reasons, this is the wrong way to go, because you'd be coupling yourself to those XML proxies just like you'd couple yourself to the application layers as explained above.

Instead, use messaging and let whatever implements functionality for them, listen to them. Your service surface then becomes a list of messages that you can send and you haven't coupled your operations to your service facade; and you don't even need to know what application or endpoint implement these operations, because all that you're doing is publishing a message that some other routing mechanism will route to the correct consumer!

Because you have decoupled the service facades from the actual operations that you want to perform, you can now add multiple services; in fact, this is how Netflix does it. Have a look at these presentations: http://www.slideshare.net/adrianco/global-netflix-platform. http://www.slideshare.net/adrianco/global-netflix-platform. They're good!

Title: Interacting With Data Using Multiple Databases/Servers

Body:
All of the projects that I've had to deal with so far have only required a single database on a single server. I'm interested in learning more about how projects that need to scale move to  multiple databases and/or servers to help manage the load. I'm aware of High Scalability, but I'm particularly interested in some code examples or additional resources where I could read more on the subject.

For instance:

How are joins constructed between two tables on multiple databases? (A code example here would be helpful).

Are there any special strategies for tracking which tables are in which database?

Does the application code need to know that one or more databases are spread across multiple servers? If not, at what level are the requests filtered?

When is it time to move beyond a 1 database/1 server setup? How common is it to need to do this?


问:
What tools do you use to manage requests from users?
I'm drowning in user emails and I'd like to implement a better way to manage all these requests I get and put them in a queue where those people on a team, as well as users, have access to them and can make common notes. I'm thinking about some sort of task management tool that would allow multiple tasks to be created under a project where emails, comments, ideas, etc. could be dropped/entered and easily accessible.

I need something that all parties can be involved in - users, managers, team leaders, developers. I'm looking for a tool that can allow:

Users to just drag/drop an email to submit a request for maintenance or enhancement.

Developers to just see their queue and the weighted priority of each task/project.

A team of developers to see what everyone is working on in real-time.

Management to keep a a log of time spent on each task.

I I am starting to look in more of a Agile/Scrum direction for solving this problem. I found list of scrum agile sofware project management open source tools. Since I am limited on time, has anyone used these? Which one should I test to see if it will meet my needs? TeamPulse is a good direction, but think it is a little too bloated. I need something simple for all parties.

答:
Redmine

...project management web application. Written using the Ruby on Rails framework, it is cross-platform and cross-database.

Redmine is open source and released under the terms of the GNU General Public License v2 (GPL)...

Some of the main features of Redmine are:

Multiple projects support

Flexible role based access control

Flexible issue tracking system

Gantt chart and calendar

News, documents & files management

Feeds & email notifications

Per project wiki

Per project forums

Time tracking

Custom fields for issues, time-entries, projects and users

SCM integration (SVN, CVS, Git, Mercurial, Bazaar and Darcs)

Issue creation via email

Multiple LDAP authentication support

User self-registration support

Multilanguage support

Multiple databases support...


问:
Hashing growth strategy
What is a good growth strategy for hash tables? If the number of elements exceeds the number of buckets, I increase the number of buckets with the following formula:

```<code>n = int(n * 1.618033988749895) | 1;
</code>```

Does that sound sensible? (The | 1 part makes sure I get an odd number.)

答: The two obvious problems with that growth plan are possible memory fragmentation though this also depends on how the underlying array is implemented) and of course the fact that the expression overflows: the right hand side of the expression may involve an overflow.   In C, this produced undefined behaviour.   In other languages, this may produce a runtime exception or a new value of n that is smaller than the previous one.</p>

Title: Hashing growth strategy


答:
I think you are mixing two independent things. An user story shouldn't include any technical details.

The choice of framework, setting up repositories and servers, and other tasks, should go into the initial iteration.


问:
Which is the most permissive open-source license?
Which is the most permissive open-source license available?

"Permissive" would be defined as "the minimal requirements about how the software can be redistributed".

答: I believe that your question doesn't have a single answer because there are lots of different licenses. I use the simplified BSD license in my projects which is very permissive.</p>


答:
The WTFPL (Do What The Fuck You Want To Public License) :

The WTFPL (Do What The Fuck You Want To Public License) is an
  infrequently used, extremely permissive free software license. The
  original Version 1.0 license, released March 2000, was written by
  Banlu Kemiyatorn who used it for Window Maker artwork. Samuel "Sam"
  Hocevar, a French programmer who was the Debian project leader from 17
  April 2007 to 16 April 2008, wrote version 2.0. It allows for
  redistribution and modification of the software under any
  terms—licensees are encouraged to "do what the fuck [they] want to".
  The license was approved as a GPL-compatible free software license by
  the Free Software Foundation.

Title: Which is the most permissive open-source license?

Body:
Which is the most permissive open-source license available?

"Permissive" would be defined as "the minimal requirements about how the software can be redistributed".


问:
How to add personal android projects to my CV to get into Android job market
I am an experienced Java Programmer. 1 year back I started android programming and published 3 Apps into the market. But these all are my personal projects. Now I want get into the android job market. As my android experience is not corporate experience does the companies consider this? How to add these android projects to my CV to get into Android job market?

Thanks

答:
Come up with a company name (and make a web page for it)

Call yourself the owner

Add the products to your CV under that company

Because, after all, if you are writing software for the android market (especially if you are selling them), then you are your own company, and you do have 'commercial' experience.

Dont undersell your 'personal' projects just because they arent developed within a cubicle farm.  Being able to conceptualize, implement, and ultimately sell your own software is a big deal.


问:
Is is preferable to design top down or bottom up?
As I understand, top-down design is by refining the abstract high level concept into smaller concrete and comprehensible parts, until the smallest building block is defined. On the other hand, bottom up defines low level parts, then gradually build up higher level blocks until the whole system is formed.

In practice, it is said best to combine the two methods: starts with high level specification to fully specify the domain knowledge, its relationship and constraints. Once the problem is well understood, smallest building blocks are created to build up the system.

The process of:

Creating requirement spec

Create a design spec (with diagrams)

Implement

Deliver

Repeat (in iterative development, rather than doing a whole chunk in each phase, we do a little bit each repeatedly, and got daily meeting to adapt to customer's dynamic requirement)

looks perfectly normal to me (with specs as plans). It has its flaws but that's why we got iterative development: instead of spending time on one phase, says, requirement analysis to study every possible thing in domain knowledge which is subjected to changes (possibly daily), we do a little bit of analysis, a little bit of design and then implement it.

Another way is that each iteration is a mini-waterfall fashion, where analysis is done in a few days (or a week). The same applies for design. The rest of time is spent for implementation. Is there something inherently wrong with top-down approach in combination with iterative development?

In his essay Programming Bottom Up, Paul Graham seems to encourage build from bottom up completely, or program it from bottom up, but not the requirement analysis/design phase:

Experienced Lisp programmers divide up their programs differently. As
  well as top-down design, they follow a principle which could be called
  bottom-up design-- changing the language to suit the problem.

As far as I get, what he meant is that Lisper still performs top-down design, but program bottom up, is that true? Another point he wrote:

It's worth emphasizing that bottom-up design doesn't mean just writing
  the same program in a different order. When you work bottom-up, you
  usually end up with a different program. Instead of a single,
  monolithic program, you will get a larger language with more abstract
  operators, and a smaller program written in it. Instead of a lintel,
  you'll get an arch.

Does this means that during the period of writing a program in Lisp, you end up with a generic tool?

答:
I'm not sure how this answer would apply to Lisp, but I just finished reading Agile Principles, Patterns and Practices, and the author, Uncle Bob, strongly advocates top-down approach for C# (also applicable to C++) with which I fully agree.

However, unlike some other answers that drew a conclusion that top-down approach means that in the first interaction you only deliver documents and overall design, the book points to another method: TDD combined with evolutionary design.

The idea is that you start from the top and define your highest abstraction levels (or local highest) and as soon as they are defined you make them do useful work so that feature #1 is immediately working.  Then as you add more and more features you refactor your code and evolve design as needed while always staying aware of SOLID principles.  This way you will not end up with too many abstraction layers and you won't end up low-level design that doesn't fit the overall architecture. If you are not sure what this means, the book I mentioned above has a whole chapter with an example where developers take concepts and start with UML diagrams and low level classes, only to realize half those classes are not needed once coding actually begins. In essence with this approach, low-level code is naturally pushed down as more high-level details are defined in the project.

And lastly, if you practice SOLID, you shouldn't run into a situation where you have high-level abstractions defined and then get into details and all of a sudden find that there's no OOD or abstractions.  That's not really the fault of top-down design, but lazy engineering.

If you are interested to read more about XP and evolutionary design, here's a good read from Martin Fowler, another great author: "Is Design Dead?"


答:
Between the two you listed MIT is much more permissive than GPL (or LGPL).

If you want even more permissive, there's always Beerware and as a side effect you might even get some free beer out of it.


答:
I went on a Scrum course recently and the instructor suggested that a special sprint called Sprint 0 should be used to solve exactly these sorts of problems.  There were people on the course with varying degrees of experience in Scrum and pretty much all of the experienced people agreed, saying that they did the same thing.  In some cases, the companies used Sprint 0 to evaluate the project and decided if it was feasible or not.

To someone new to the Scrum methodology like myself, it seems like a fantastic solution because it keeps you free from user stories and all of the other aspects of a normal sprint such as user feedback.

As Sprint 0 is the same length of time as your other sprints, it acts as a way of ensuring you don't spend too much time getting things set up because they can always be tweaked later.  The main point is to get yourself into a state where you can actually start developing the product.


问:
Programming judge with versus system
I'm looking for a programming judge system which supports putting contestants programs against each other in "matches". The format could be either for example a tournament style or chess ranking, but this isn't that important. A good example would be Google's AI challenge (http://aichallenge.org/)

The only systems I've found so far are "regular" programming judges, i.e. those who can check if a program passes or fails a given problem, like DOMJudge.

Do you know of any systems like this?

答: You could have a look at Caia. It is used by the Dutch informatics olympiad to organize programming competitions where the submitted programs compete against each other.</p>

Title: Programming judge with versus system


问:
Should I add MSDN notes or Stack Overflow links to source code?

Possible Duplicate:

  Is it OK to put a link to Q&A sites in a program's comments?

I'm creating a powershell / C# host and want to add the following comment

// This method cannot be called multiple times on a given pipeline. The state of the
// pipeline must be NotStarted when Invoke is called. When this method is called, it
// changes the state of the pipeline to Running.
// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms569128(v=vs.85).aspx
if (pipeline.PipelineStateInfo.State == PipelineState.NotStarted)
{
    Collection<PSObject> results = pipeline.Invoke();
}
```

Is this an appropriate comment?  What would you improve about it?

答:
If you program is nontrivial,
then your code must stand alone and pass the tests of time.
Becuase if the source code is lost, then it will not be changed and read , but otherwise code can live on for a very long time. Some of the older SO users will have stories about code that is multiple decades old still running.

I've worked on systems that were still in active development after decades.
Links to websites would be well broken by the time a new programmer wanted to read them.

As Neither MSDN or SO are guaranteed to be around, all a link does is irritate.

Sir Tim Berners Lee wrote a very impassioned plea for URL's to be constant, so that links would have value going forward. So far, not so successful.
Maybe we'd have been better off if he'd patented the web and forced us to do it his way as part of the license terms?


答:
Ok, let’s break it down:

How are joins constructed between two tables on multiple databases?
(A code example here would be helpful).

This is pretty straightforward.  SQL Objects have anywhere from a one to four part naming convention:

Servername.databasename.schemaname.tablename

If all your tables are on the same server on the same database , with the same owner/schema, you can just ignore the first three parts and use what you are most used to:

```<code>Select a.*,b.* from
tableA a inner join
tableB b on a.col1=b.col1
</code>```

If one of your tables is in a different database and both use the default schema for their databases, then you simply add the database to the second table:

```<code>Select a.*,b.* from
tableA a inner join
databaseC..tableB b on a.col1 = b.col1
</code>```

If you happen to be in a third database different from either of the ones you are querying you use both database names explicitly:

```<code>Select a.*,b.* from
databaseD..tableA a inner join
databaseC..tableB b on a.col1 = b.col1
</code>```

If you end up using different schemas and/or owners you can add those in:

```<code>Select a.*,b.* from
databaseD.john.tableA a inner join
databaseC.accounting.tableB b on a.col1 = b.col1
</code>```

And lastly, if you are very careful about it and have a very good reason, you can join a (usually small) table on another server:

```<code>Select a.* from
databaseD.john.TableA a inner join
ATLANTA.databaseC.accounting.tableB b on a.col1 = b.col1
</code>```

When is it time to move beyond a 1 database/1 server setup? How common is it to need to do this?  Are there any special strategies for tracking which tables are in which database?

I’ll combine these two because they go together.  You’re almost always generally fine to start off with the assumption that one database one server is enough until your design/business/technical constraints force you to use more.

So to answer your second question first, since you generally have a reason for having separate databases, it should be fairly obvious from knowing the design of your system where something is.

As to when/why it’s necessary to move beyond a single database. Usually it’s a mix of business rules, politics, and/or technical reasons.

For instance, where I work we have 16 databases spread across 4 servers.  We have a MainDB, ImageDB, referencetableDB, HighvolumeTransactionDB, ReportingDB, StagingDB, ProcessingDB, ArchiveDB, FinancialDB.   To give some examples of why they are different:

FinancialDB, sensitive information

Image DB, specific different storage and recovery requirements

ReferenceDB, low transaction,
high read

ReportingDB, very high read, needs to be restored/replicated to various other environments unlike a lot of the other data

StagingDB, nothing permanent, just a beefed up tempdb that we have more control over

MainDB, interfaces with all the other DBs but needs differential backups so...we split out the

HighVolumeTransaction tables, (which are relatively transient), to their own DB so
as to keep the backup reasonable size.

Archive, Lots of the same data from Main and Reporting, but with longer retention periods and harder hitting queries digging deep in the data.  If this was still combined with Main/Reporting it would bog our system down.

•   Does the application code need to know that one or more databases are spread across multiple servers? If not, at what level are the requests filtered?

In a broad sense, they probably do.  At a minimum they need to know what server they are pointing at in the database connection string.  Processing, Reporting, Main, etc.

From there, they do need a database context to execute under.  Generally that would be the most used one for the application, maybe even the original one from the one database/one server days of the application.  You CAN have the application explicitly switch database context on every call but that makes it very hard to adjust the database without changing the app.

The usual, (or at least, MY usual), approach is to always access through one or maybe two main databases.

Then create views into other databases as necessary combined with interfacing with the database through stored procedures.

So to illustrate:

Let’s say you want to get a Client’s demographic information, Sales data and Credit balance and that’s spread across three tables originally all in the MainDB.

So you write a call from your app:

```<code>Select c.ClientName, c.ClientAddress, s.totalSales,f.CreditBlance from
Clients c join Sales s on c.clientid = s.clientid inner join AccountReceivable f on
c.clientid=f.clientid where c.clientid = @clientid
</code>```

Awesome. However, now anytime we change a columname, or rename/move a table, you have to update the app code.  So instead we do two things:

    Create Clients, Sales, AccountReceivables Views (you wouldn’t use Select * but I’m demoing here)

```<code>Use MainDB
GO
Create view v_Clients as select * from Clients
Create view v_Sales as select * from Sales
Create view v_AccountReceivable as select * from AccountReceivable
Go
</code>```

Then we’d also create a stored procedure, spGetClientSalesAR

```<code>Create proc spGetClientSalesAR @clientID int
as
Select c.ClientName as ClientName,
       c.ClientAddress as ClientAddress,
       s.totalSales as TotalSales,
       f.CreditBlance as CreditBalance
from
v_Clients c join v_Sales s
    on c.clientid = s.clientid
inner join v_AccountReceivable f
    on c.clientid=f.clientid
where c.clientid = @clientid
</code>```

And have your app call that.

Now as long as I don’t change the interface on that stored proc, I can  pretty much do anything I need to do to the backend database to scale up or out.

In the extreme, I could even make my old MainDB just a bunch of shelled stored procedures and views such that underneath those views we created looked like this:

```<code>Create view v_Clients as select * from ServerX.DatabaseY.dbo.Clients
Create view v_Sales as select * from ServerQ.DatabaseP.dbo.Sales
Create view v_AccountReceivable as select * from ServerJ.DatabaseK.dbo.AccountReceivable
</code>```

And your app would never know the difference, (assuming fast pipes and well staged data among other things).

Obviously that’s extreme and I’d be lying if I said everything was planned this way, but using stored procedures/views even if you do it while refactoring will allow you a lot of flexibility as your app grows from its humble one database/one server beginning.

Body:
Ok, let’s break it down:

How are joins constructed between two tables on multiple databases?
(A code example here would be helpful).

This is pretty straightforward.  SQL Objects have anywhere from a one to four part naming convention:

Servername.databasename.schemaname.tablename

If all your tables are on the same server on the same database , with the same owner/schema, you can just ignore the first three parts and use what you are most used to:

Select a.*,b.* from
tableA a inner join
tableB b on a.col1=b.col1

If one of your tables is in a different database and both use the default schema for their databases, then you simply add the database to the second table:

Select a.*,b.* from
tableA a inner join
databaseC..tableB b on a.col1 = b.col1

If you happen to be in a third database different from either of the ones you are querying you use both database names explicitly:

Select a.*,b.* from
databaseD..tableA a inner join
databaseC..tableB b on a.col1 = b.col1

If you end up using different schemas and/or owners you can add those in:

Select a.*,b.* from
databaseD.john.tableA a inner join
databaseC.accounting.tableB b on a.col1 = b.col1

And lastly, if you are very careful about it and have a very good reason, you can join a (usually small) table on another server:

Select a.* from
databaseD.john.TableA a inner join
ATLANTA.databaseC.accounting.tableB b on a.col1 = b.col1

When is it time to move beyond a 1 database/1 server setup? How common is it to need to do this?  Are there any special strategies for tracking which tables are in which database?

I’ll combine these two because they go together.  You’re almost always generally fine to start off with the assumption that one database one server is enough until your design/business/technical constraints force you to use more.

So to answer your second question first, since you generally have a reason for having separate databases, it should be fairly obvious from knowing the design of your system where something is.

As to when/why it’s necessary to move beyond a single database. Usually it’s a mix of business rules, politics, and/or technical reasons.

For instance, where I work we have 16 databases spread across 4 servers.  We have a MainDB, ImageDB, referencetableDB, HighvolumeTransactionDB, ReportingDB, StagingDB, ProcessingDB, ArchiveDB, FinancialDB.   To give some examples of why they are different:

FinancialDB, sensitive information

Image DB, specific different storage and recovery requirements

ReferenceDB, low transaction,
high read

ReportingDB, very high read, needs to be restored/replicated to various other environments unlike a lot of the other data

StagingDB, nothing permanent, just a beefed up tempdb that we have more control over

MainDB, interfaces with all the other DBs but needs differential backups so...we split out the

HighVolumeTransaction tables, (which are relatively transient), to their own DB so
as to keep the backup reasonable size.

Archive, Lots of the same data from Main and Reporting, but with longer retention periods and harder hitting queries digging deep in the data.  If this was still combined with Main/Reporting it would bog our system down.

•   Does the application code need to know that one or more databases are spread across multiple servers? If not, at what level are the requests filtered?

In a broad sense, they probably do.  At a minimum they need to know what server they are pointing at in the database connection string.  Processing, Reporting, Main, etc.

From there, they do need a database context to execute under.  Generally that would be the most used one for the application, maybe even the original one from the one database/one server days of the application.  You CAN have the application explicitly switch database context on every call but that makes it very hard to adjust the database without changing the app.

The usual, (or at least, MY usual), approach is to always access through one or maybe two main databases.

Then create views into other databases as necessary combined with interfacing with the database through stored procedures.

So to illustrate:

Let’s say you want to get a Client’s demographic information, Sales data and Credit balance and that’s spread across three tables originally all in the MainDB.

So you write a call from your app:

Select c.ClientName, c.ClientAddress, s.totalSales,f.CreditBlance from
Clients c join Sales s on c.clientid = s.clientid inner join AccountReceivable f on
c.clientid=f.clientid where c.clientid = @clientid

Awesome. However, now anytime we change a columname, or rename/move a table, you have to update the app code.  So instead we do two things:

    Create Clients, Sales, AccountReceivables Views (you wouldn’t use Select * but I’m demoing here)

Use MainDB
GO
Create view v_Clients as select * from Clients
Create view v_Sales as select * from Sales
Create view v_AccountReceivable as select * from AccountReceivable
Go

Then we’d also create a stored procedure, spGetClientSalesAR

Create proc spGetClientSalesAR @clientID int
as
Select c.ClientName as ClientName,
       c.ClientAddress as ClientAddress,
       s.totalSales as TotalSales,
       f.CreditBlance as CreditBalance
from
v_Clients c join v_Sales s
    on c.clientid = s.clientid
inner join v_AccountReceivable f
    on c.clientid=f.clientid
where c.clientid = @clientid

And have your app call that.

Now as long as I don’t change the interface on that stored proc, I can  pretty much do anything I need to do to the backend database to scale up or out.

In the extreme, I could even make my old MainDB just a bunch of shelled stored procedures and views such that underneath those views we created looked like this:

Create view v_Clients as select * from ServerX.DatabaseY.dbo.Clients
Create view v_Sales as select * from ServerQ.DatabaseP.dbo.Sales
Create view v_AccountReceivable as select * from ServerJ.DatabaseK.dbo.AccountReceivable

And your app would never know the difference, (assuming fast pipes and well staged data among other things).

Obviously that’s extreme and I’d be lying if I said everything was planned this way, but using stored procedures/views even if you do it while refactoring will allow you a lot of flexibility as your app grows from its humble one database/one server beginning.


问:
Can someone find a job as a programmer without an education?
Interested in knowing from the more experienced ones if someone can find a job as a programmer without even a highschool degree. Consider the said person to be an average programmer. Would someone even consider giving him/her a chance on an interview ? The languages of interest would be python/php/java/c#

Please answer for your region/city/country only. No "go back to school" answers please.

答: I'd start at a small company with no HR filters to worry about, get some experience there and then move to a bigger company once you have a nice job or two in your job history. Education matters less and less and we find Computer Science graduates who can't even do the FizzBuzz test and self-educated programmers are blowing them away.</p>


问:
Is it important for a solution to be an efficient one?
I solve many problems, mostly from Top Coder. I will get answers for many, but most times I end up with an inefficient solution.

In real-world implementations - does it really matter that a solution to the problem is efficient? If so how I can improve it?

答:
That depends on the structure of the contest, but generally, yes: performance is a consideration most of the time, according to their documentation.  Sometimes, as in the later link, you have to hunt, but to quote:

Write clean, clear, efficient code. Even though there is no review line item specifically for this, reviewers are nevertheless likely to react better to code that is easy for them to read and understand. With efficient code you get a potential performance advantage in stress and benchmark testing, as well as likely kudos (and a few extra points) from the reviewers.

The best way to improve at this is to write code that is efficient, which you are already doing.  Even if you complete the work, spend time on improving the efficiency of it - even after the competition - and that will pay off.

You probably also want to invest in theory, such as books on algorithms, that can give you two things: more efficient tools to solve a specific problem, and more efficient mechanisms for identifying what the problem you have to solve is.

Finally, computer science courses are increasingly available online, and will cover the background you need to improve.