答:
Just some type of personal subjective opinions and experience regarding mentioned problems and questions

Know/demonstrate if the migration would actually benefit the employees and the company.

Will it (benefits) will appears really? Which troubles in current workflow you want eliminate fist? Are they really troubles and showstoppers or just some annoyances, significance of which is exaggerated for bosses?

"People accidentally breaking other's builds..." is problem of planning, workflow and management (missing QA, work-patterns, not used automated *-test), not tools

"Unnecessary bureaucracy when it comes to granting access..." some type of ACL and restrictions is a must, from my POV. This (almost) missing feature in Mercurial can be a bigger headache

"slowness due to network latency" - DVCS just delay (can delay) a time of sync with remotes, not eliminate it totally

"Trouble when trying to collaborate with external providers..." Mercurial will change nothing technically and organizationally, may do process only harder, because it can get relation many-2-one instead old one-one (single repo to single repo)

"Workaround to integrate modules from other repositories..." Mercurial's subrepos aren't easiest and fully automatic part of... Handwork and accuracy is a must

Last two points are closed by Mercurial more or less, but sufficiently justified to consider the transition

Ease the embracement of change, or at least make it look like its
  worth the effort

It's heavy depend from local situation and current workflow (which I can't know) - some devs consider just movement from "commit" to "commit + push" as life drama. But all changes in common can be more deep and hard.

No opinions. But if you'll simulate CVCS (to some degree) with Mercurial, it can may facilitate the initial stages of migration

Not complicate others' jobs.

Pure development can be as autonomous, as the developer wants, thus -  doesn't interfere with other devs. But, besides code-monkey, changes will appear for everybody (testers, PMs, releasers, doc-writers)

how can the migration process affect integrators the least?

Sorry, if I don't know how integration process works now, I can say nothing how don't broke it and how to do minimal impact... Also think about possible wanted and requested changes in old style, which can bring new tool from new class

Title: Moving from a CVCS to a DVCS in a big company, what is the right way to do it?

Body:
I just started a new job and I'm currently at the process of trying to introduce a DVCS (mercurial, but the actual DVCS is not really a matter of discussion at this point, it could also be git) to the company (big, multinational). So far I've gotten nothing but positive attention, even at managerial and directive level, but I want to make sure I'm not at all disruptive to the organization or anyone's jobs.

The way the developers are set up is in a team room, so there's a lot of communication going on. There is also an integrator, that communicates on a daily basis two or three times with the team leader. Also, there are more development teams on other parts of the world, maybe 20 offices in 6 or 7 countries.

Company culture is open and there would be no problem pilot testing the tool  but the real question is (in capital letters):

HOW DO YOU CONVINCE MANAGEMENT AROUND ALL THE OFFICES OVER THE WORLD THAT ITS A SANE THING TO DO AND WILL ACTUALLY BRING HAPPINESS AND PRODUCTIVITY TO DEVELOPERS? (say pilot testing and showing it works is just one part of the answer).

Elaborating on the context...

Does it make sense to make the switch?, yes (note: current SCM is Perforce). I've witnessed several sources of frustration classic to centralized source control management, including:

People accidentally breaking other's builds or stepping on each others' toes while submitting code revisions.

This is not often as the responsible must wear a pink hat (hilarious stuff) until the build is fixed, but the hat is still there, and when builds get broken it affects the other offices around the world.

DVCS to the rescue: Builds are now broken in a single office, people lose the fear to use version control and can actually second-guess themselves after or check with a peer by sharing their changes easier and not necessarily with the rest of the group.

Unnecessary bureaucracy when it comes to granting access (e.g. looks like everyone is granted access to most of the code).

There is a dedicated group of admins who take 1 to 3 days to grant access to the code, meanwhile other developers must ask their peers for the code just to look at it... but AFAIK, the often wait instead.

DVCS to the rescue: Administration does not have to be centralized on a little group of overwhelmed people, new employees get the code from the project's responsible (1st level) or a peer with repository access (2nd level) who could even review their code and submit it along with his/her changes.

Complaints with regards to slowness due to network latency. Not that directly, but sometimes a) The perforce server is down, b) Internet is down, c) Internet or perforce server is slow. Yes, not that often, but it is annoying enough to kick you off your train of thought sometimes.

DVCS to the rescue: When using the DVCS you obviously don't need a network connection. Worst case scenario?, share your changes over LAN or sneakernet (with patch queues).

Trouble when trying to collaborate with external providers that do not necessarily belong to the organization. This happens often enough and security is a concern here AFAIK, and clients suffer from the access bureaucracy.

DVCS to the rescue: So granting access to a subrepo here would be the ideal solution here... also, clients themselves could use version control among themselves without needing to set up their own server and they would be able to integrate better to the internal workflow as currently Perforce access access to the local network, and thus more bureaucracy which is not necessarily security here, as external collaborators still have access to thumbdrives and email. Actual security would be having externals work in-situ... in a dungeon or something, and grope them à la TSA on their way out to make sure they are not getting the code out.

Workaround to integrate modules from other repositories. Requires additional maintenance/effort from the developers. **They actually wrote themselves (I think) a plugin to make Perforce fetch files from other repositories in other parts **

DVCS to the rescue: Their solution looks a lot like the mercurial subrepo feature, which uses a file (.hgsub) to indicate what code goes where, but they have to maintain the other repositories' states in the same file (which is done separately and automatically by mercurial in the .hgsubstate file).

Working with the source code requires to mark files for edit in advance. This adds an annoying extra step IMHO. If you don't do this the file will be in read only mode and you will not be able to edit it on your IDE, also, this in my opinion makes the local copy prone to low integrity. This trait of Perforce makes me think there was a lazy developer that didn't want to make the client check the files against the repository before versioning the changes. It also makes me think/personify Perforce as an idiot paranoid that says "DON'T CHANGE THE FILES WITHOUT TELLING ME OR THE SQUIRRELS WILL COME AND EAT ME!".

DVCS to the rescue: Well... I guess any other SCM software knows there are no carnivore squirrels.

Little project integrity in developers' machines (see previous point; its harder to add changes without previously indicating them to Perforce). You don't need a DVCS for this... but if you make changes locally and for some reason forgot to add them, you are going to have a hard time detecting it. Once you detect it there is a two step command line instruction thing I saw somewhere to detect changes you did without telling Perforce.

Given that context what would you say is the best way to... ?:

Know/demonstrate if the migration would actually benefit the employees and the company.

Ease the embracement of change, or at least make it look like its worth the effort

Not complicate others' jobs.

Convince management worldwide.

Avoid making the integrator's job a royal pain.

My second question (and focusing on the last point) I've always been a DVCS evangelist mainly because it eases the work and collaboration between developers... but up to this point I've never been faced with having to consider the integrators' perspective (the one in charge of coordinating teams' source code, creating and releasing the builds... from across the globe) who at some point might have to face two SCM sources or at least the migration itself. Then, how can the migration process affect integrators the least?.


问:
In what areas of programming is algorithm run time actually an important issue?
Sometimes I hear people say that because of the speed of processors and the amount of memory available, algorithm efficiency and runtime aren't, in practice, of major concern.

But I imagine there are still areas where such considerations do remain of paramount importance.  Two that come to mind are in algorithmic trading, where thousands of transactions must be conducted in fractions of a second, and embedded systems programming, where memory and power are often scarce.  Am I right about these examples ?  and what other areas would also be examples?

答:
Other areas include many kinds of real-time signal processing, feedback control systems, oil exploration deconvolution, video compression, ray tracing and movie frame rendering, virtual reality systems, games where high frame rate might be a significant competitive advantage, and smartphones and other mobile device apps, where large numbers of CPU cycles will consume the users battery life faster.

I'm quite surprised this question would even be asked, since for any Top-500 supercomputer ever built, there is likely a waiting list of researchers who can max it out and wish for magnitudes more compute power or magnitudes better algorithms to solve some problem (fold some protein to decipher cancer, etc.) before they retire.

ContentLicense: CC BY-SA 3.0


问:
Website with test data files for specific algorithms/data structures?
Is there any website, like SPOJ and Project Euler, with the test data files available for specific algorithms/data structures? </p>

<p>I know it's a fun challenge to solve those problems on your own, but I am looking for test data files where the algorithm/data structure to use are explicitly mentioned. </p>

<p>"Implement a linked list and do this and that with the data to confirm!",
"Implement a hash tree and do this and that with the data to confirm!" etc. </p>

答:
The Computer Language Benchmarks Game has a dozen of tasks with input file, expected results and solutions in many programming languages.

For example, the k-nucleotide benchmark (Hashtable update and k-nucleotide strings) is defined like this:

```<code>We use FASTA files generated by the fasta benchmark as input for this benchmark.
Note: the file may include both lowercase and uppercase codes.

Each program should

 1. read line-by-line a redirected FASTA format file from stdin
 2. extract DNA sequence THREE
 3. define a procedure/function to update a hashtable of k-nucleotide keys and count
    values, for a particular reading-frame — even though we'll combine k-nucleotide
    counts for all reading-frames (grow the hashtable from a small default size)
 4. use that procedure/function and hashtable to
   - count all the 1-nucleotide and 2-nucleotide sequences, and write the code and
     percentage frequency, sorted by descending frequency and then ascending
     k-nucleotide key
   - count all the 3- 4- 6- 12- and 18-nucleotide sequences, and write the count and
     code for the specific sequences GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT
</code>```

Body:
The Computer Language Benchmarks Game has a dozen of tasks with input file, expected results and solutions in many programming languages.

For example, the k-nucleotide benchmark (Hashtable update and k-nucleotide strings) is defined like this:

We use FASTA files generated by the fasta benchmark as input for this benchmark.
Note: the file may include both lowercase and uppercase codes.

Each program should

 1. read line-by-line a redirected FASTA format file from stdin
 2. extract DNA sequence THREE
 3. define a procedure/function to update a hashtable of k-nucleotide keys and count
    values, for a particular reading-frame — even though we'll combine k-nucleotide
    counts for all reading-frames (grow the hashtable from a small default size)
 4. use that procedure/function and hashtable to
   - count all the 1-nucleotide and 2-nucleotide sequences, and write the code and
     percentage frequency, sorted by descending frequency and then ascending
     k-nucleotide key
   - count all the 3- 4- 6- 12- and 18-nucleotide sequences, and write the count and
     code for the specific sequences GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT


问:
better way to learn programming with the intention of getting a job?

Possible Duplicate:

  How to get a job with no experience?

So I've worked on a desktop software coding Swing GUI for past 2 years.

I feel that even having a live website selling my java desktop software (customers buy it occassionally) is not enough experience, contrary to opinions from this site, very little of my experience building, running the software business is discussed during interviews.

Often jobs have extensive list of qualifications which I think I can cover 70%, but I don't have example projects for each language and framework, rather I've played around with different open source libraries and build things based on what is needed.

When I land interviews, sometimes I pass all the technical questions but sometimes I don't when they ask me about experience I don't have.

When I do land interviews, I cannot complete the programming tasks in time. I over think the problem, and while I have done more complex problems working on my software project, I cant think quickly enough to do the testing questions fast enough.

What other ways can I improve my skills to better showcase my skills?

How many portfolio of projects do I need to be convincing? Should I take a course from a local college in Java?

答:
I would avoid taking more classes. Why pay for abstracted instruction that lacks real experience. I've always been a firm believer in relevent work experience over education.

The best way to learn without much risk or involvement would be to look into volunteering your time (yes free) for non-profits.

The free time you volunteer is great because you can usually dictate your terms. You can easily walk away from the project. If not you don't lose anything. Albeit, it maybe harder to find something in terms of the java world (i'm a php programmer myself). Just keep looking i guess. With capitalism, there are always firms looking for cheap or nearly free labor.


问:
Might I run into any trouble if I plug into an existing service/application with my own application and charge for it?
I know this is more of a lawyer question, however I figure someone here has probably done this and can give me a quick answer.

Lets take a moderately extreme case. I build an adapter for a website that translates the requests and markup into a more formal API. I then take this API I developed and build a mobile app on it.

So in short I take a site that doesn't support mobile. Build a mobile application, and then charge for the mobile application.

I am not talking about charging for any of the original product. Simply the extension to the product.

I ask because there is a site I would really like to build a mobile app for, because it would make my life easier, and it would be pretty gravy if I could earn some cash on the side from the work as well.

答:
When building on the product of somebody else, e.g. the example you gave of extending a website or even simpler cases like writing a plugin for Adobe Photoshop, there are several aspects you should be considering.

Legal: This is what Karlson already mentioned, make sure you are not violating any licensing agreements, the terms of service of the website you are extending etc.

Economic: By extending an existing product, your business lives and dies with that product. If people don't like to use that product anymore (for whatever reason), nobody will be using your extension, no matter how great it is and without you ever having done anything wrong. Also, the company makign the original product might decide to include your extension into their product; think about how many people would still be willing to pay for a Photoshop plugin, if the same functionality (or maybe even 80% of it) was already included right out of the box by Adobe themselves?

Technological: Unless you have some kind of cooperation agreement with the company whose product you are extending, you might find yourself playing catch-up whenever they release a new version of the product. At best you will need some time to chnage the way you interface with their product (making you customers unhappy by forcing them to live withou´t your product for a while), at worst, there is a breaking change that makes it impossible to extend the product the way you used to (making you tell your customers they can no longer use the thing they paid you good money for).

See also this Joel On Software article quoting this Dave Winer blog post
Co-existing with platform vendors.


问:
Understanding Loose / Tight Coupling in the "Real World"
I wont say what "community" because I want a non-biased explanation, but let's say you're building a reusable module and that module requires 3+ dependent modules and removing 1 of them causes a breaking error not only in your app as a whole which uses this module, but the module itself.

From my understanding (which must be wrong) a loosely coupled modular system will not break by simply removing one module. The app should still run but without that "feature" / module and the module itself shouldn't causes everything to not run simply because a dependent module doesn't exist.

Is this wrong? If so, if modules are still dependent to the point of everything not working whats the difference between tight/loose coupling?

答:
Loose coupling is essentially the indirect dependency between module on how they can evolve.

Generally, when there is a tightly coupled systems different modules/objects have a very specific behaviors that assumes that behavior of the peripheral objects. Such objects are linked/coupled to other modules behaviors and they cannot be re-used in isolation or in any other context.

Such modules even though responsible for individual functionality cannot evolve independently or cannot evolve

An example:

Let's say you have 3 objects
Shape (a model object) and Canvas (a UI element).
Now

Assume that a method shape.draw(Canvas) will draw an object on the plane that is supplied by the plane of the canvas.

Now, sometimes windows are partially covered and are resized. In such cases,
the above method might just do something like this.

```<code>shape::draw(Canvas) {
   Rect.WindowLeft = Canvas.GetWindowRect.getLeftOffset();
   Rect.LeftPixel = Canvas.GetWindowRect.pixels() + Rect.WindowLeft;
   ....  // like this get all co-ordinates.

   draw_instance(Rect);  // This will draw the actual shape.
}
</code>```

Basically, here the draw function picks up the rectangle where things needs to be drawn. This is easy to understand (people might call this simple) code. However, this is extremely coupled code.

Imagine the situation:

What if the canvas's mechanism of holding windows is no longer a rectangle?

what if there are additional offsets that Canvas keeps which is private?

What if some other application wants the same shape but no longer has a GUI window (for example, it is creating images and saving in files).

The root cause of the problem is that object shape knows and hence tightly coupled with Canvas.

What is desirable that a pixel set is given to shape where it writes; the shape should not have (even implicit) knowledge about where the pixels are actually written.

OwnerDisplayName: Oscar Godson

Body:
Loose coupling is essentially the indirect dependency between module on how they can evolve.

Generally, when there is a tightly coupled systems different modules/objects have a very specific behaviors that assumes that behavior of the peripheral objects. Such objects are linked/coupled to other modules behaviors and they cannot be re-used in isolation or in any other context.

Such modules even though responsible for individual functionality cannot evolve independently or cannot evolve

An example:

Let's say you have 3 objects
Shape (a model object) and Canvas (a UI element).
Now

Assume that a method shape.draw(Canvas) will draw an object on the plane that is supplied by the plane of the canvas.

Now, sometimes windows are partially covered and are resized. In such cases,
the above method might just do something like this.

shape::draw(Canvas) {
   Rect.WindowLeft = Canvas.GetWindowRect.getLeftOffset();
   Rect.LeftPixel = Canvas.GetWindowRect.pixels() + Rect.WindowLeft;
   ....  // like this get all co-ordinates.

   draw_instance(Rect);  // This will draw the actual shape.
}

Basically, here the draw function picks up the rectangle where things needs to be drawn. This is easy to understand (people might call this simple) code. However, this is extremely coupled code.

Imagine the situation:

What if the canvas's mechanism of holding windows is no longer a rectangle?

what if there are additional offsets that Canvas keeps which is private?

What if some other application wants the same shape but no longer has a GUI window (for example, it is creating images and saving in files).

The root cause of the problem is that object shape knows and hence tightly coupled with Canvas.

What is desirable that a pixel set is given to shape where it writes; the shape should not have (even implicit) knowledge about where the pixels are actually written.


答:
Sometimes I hear people say that because of the speed of processors
  and the amount of memory available, algorithm efficiency and runtime
  aren't, in practice, of major concern.

Take it with a grain of salt. More computing power basically just means that your n can become much larger before it significantly slows down. For most everyday problems, this n is now large enough that you don't need to care. However, you should still know the complexities of your algorithms.

With more available resources, it may need to crunch more data later. Today you need to analyze a 10MB log file with 100,000 lines. In a year you may have a 100GB log file with 1,000,000,000 lines. If the amount of data grows faster than the resource powers, you run into problems later.

With more available resources, more layers are stacked upon each other. OS, OS framework, 3rd party framework, language interpreter, and finally on top your own tool. All unnecessary inefficiencies in all the different layers multiply up. Tomorrow your tool may run on a new OS with more bells and whistles, that itself eats more cycles and more memory, leaving less for you.

So to answer your question, you still need to care where more and more data needs to be crunched (enough examples given in the other answers), and where you do not provide the final tool, but another abstraction layer for other tools.

Title: In what areas of programming is algorithm run time actually an important issue?

Body:
Sometimes I hear people say that because of the speed of processors and the amount of memory available, algorithm efficiency and runtime aren't, in practice, of major concern.

But I imagine there are still areas where such considerations do remain of paramount importance.  Two that come to mind are in algorithmic trading, where thousands of transactions must be conducted in fractions of a second, and embedded systems programming, where memory and power are often scarce.  Am I right about these examples ?  and what other areas would also be examples?


答: It's not a question of what application domains are runtime-sensitive. Any program, anywhere,  has a minimum performance below which it is effectively worthless. The point of algorithm complexity is how it varies with increasing input size. In other words, the areas where speed particularly matters are those where you expect to have to scale beyond not just your current problem size, but the order of magnitude of your current problem size. If you process the tax applications of the citizens of a département of France, the task may be large, but it's not likely that either the population size or the complexity of processing one record will ever increase ten or hundred-fold, so whatever works for you now, will probably keep working. But if you try to create something that will take off at internet volumes, algorithm complexity is key: anything that depends more than linearly or log-linearly on the input size will become much more expensive very fast, and eventually processor speed just can't keep up with the growth.


答: Algorithm efficiency isn't a major concern nowadays because we're using efficient algorithms. If you used an O(n!) algorithm, it would be slow on any kind of hardware.</p>


答:
Algorithm complexity is becoming more and more important as the sheer amount of data increases. Fortunately, efficient generic solutions for common programming problems (searching and sorting, mainly) are included in pretty much every modern programming language's standard library, so normally, a programmer doesn't have to worry about these things much. The downside is that many programmers do not know at all what is going on under the hood and what the characteristics are of the algorithms they use.

This becomes especially problematic as many applications aren't properly stress-tested: People write code that works well for small test data sets, but when confronted with a few thousand times more data, the code grinds to a halt. Something that works well for ten records quickly explodes when the data set grows. Real-world example: a piece of code that was supposed to clean out items that weren't linked to any category anymore used a three-level nested loop, which is O(n^3). With just 10 records in the test database, this meant 1000 checks - perfectly doable, and doesn't introduce a noticable delay. However, the production database quickly filled with around 1000 rows, and suddenly the code does a billion checks each time.

So: No, you don't need to know the ins and outs of implementing all sorts of neat algorithms, and you don't need to be able to invent your own, but you do need some basic knowledge of common algorithms, what their strong and weak points are, when and when not to use them, and you need to be aware of the possible impact of algorithmic complexity, so that you can decide which level of complexity is acceptable.


问:
Are utility classes with nothing but static members an anti-pattern in C++?
The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as free functions in a namespace.

I come from a C# background where the latter option does not exist and thus naturally trend toward using static classes in the little C++ code I write. The highest voted answer on that question as well as several comments however say that free functions are to be preferred, even suggesting static classes were an anti-pattern. Why is that so in C++? At least on the surface, static methods on a class seem indistinguishable from free functions in a namespace. Why thus the preference for the latter?

Would things be different, if the collection of utility functions needed some shared data, e.g. a cache one could store in a private static field?

答:
I guess to answer that we should compare the intentions of both classes and namespaces. According to Wikipedia:

Class

In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior. Data field members (member variables or instance variables) enable a class object to maintain state. Other kinds of members, especially methods, enable a class object's behavior. Class instances are of the type of the associated class.

Namespace

In general, a namespace is a container that provides context for the identifiers (names, or technical terms, or words) it holds, and allows the disambiguation of homonym identifiers residing in different namespaces.

Now, what are you trying to achieve by putting the functions in a class (statically) or a namespace? I would wager that the definition of a namespace better describes your intention - all you want is a container for your functions. You don't need any of the features described in the class definition. Note that the first words of the class definition are "In object-oriented programming", yet there is nothing object-oriented about a collection of functions.

There are probably technical reasons as well but as someone coming from Java and trying to get my head around the multi-paradigm language that is C++, the most obvious answer to me is: Because we don't need OO to achieve this.


答:
At least on the surface, static methods on a class seem indistinguishable from free functions in a namespace.

In other words having a class instead of a namespace has no advantages.

Why thus the preference for the latter?

For one thing it saves you typing static all the time, though that's arguably a rather minor benefit.

The main benefit is that it's the least powerful tool for the job. Classes can be used to create objects, they can be used as the type of variables or as template arguments. Neither of those are features you want for your collection of functions. So it's preferable to use a tool that doesn't have those features, so that the class can't accidentally be misused.

Following from that using a namespace makes it also immediately clear to any users of your code that this is a collection of functions and not a blueprint to create objects from.

Title: Are utility classes with nothing but static members an anti-pattern in C++?

Body:
The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as free functions in a namespace.

I come from a C# background where the latter option does not exist and thus naturally trend toward using static classes in the little C++ code I write. The highest voted answer on that question as well as several comments however say that free functions are to be preferred, even suggesting static classes were an anti-pattern. Why is that so in C++? At least on the surface, static methods on a class seem indistinguishable from free functions in a namespace. Why thus the preference for the latter?

Would things be different, if the collection of utility functions needed some shared data, e.g. a cache one could store in a private static field?


答:
A few years ago I had to write an algorithm that sorted test tubes arranged on n racks into two distinct partitions: i.e. one subset of the tubes were 'chosen' and the rest were
'not-chosen' and the end result would be that no rack would have both a 'chosen' and 'not-chosen' tube on it (there were some extra requirements such as compression). Each rack contained a maximum of 100 tubes.

The algorithm was to be used to drive a tube sorting robot in a pharmaceutical laboratory.

When the original specification was given to me I was allocated in the region of 1 minute of calculation time to sort around 2000 tubes as we thought that usability wise that was not too painful. There was a requirement that number of moves was to be minimal over all possible combinations as the robot itself was slow.

The implicit assumption was that the complexity would be exponential with the number of tubes. However, whilst working on the algorithm design I discovered that there is a fast O(n) algorithm where n is the number of racks that performed an optimal partitioning of the tubes. The result of that was that the algorithm sort time was instant so the sorting display would be updated in real time as the user configured their sort operation.

For me the difference between the user sitting for a minute after every change and having an instantly responsive GUI was the difference between a piece of software that was functionally sufficient and a piece of software that was a pleasure to use.


答: I'd be very cautious in calling that an anti-pattern. Namespaces are usually preferred, but as there are no namespace templates and namespaces can't be passed as template parameters, using classes with nothing but static members is quite common.</p>

ContentLicense: CC BY-SA 4.0


问:
Do most programmers copy and paste code?
I learned very early on that cutting & pasting somebody else's code takes longer in the long run that writing it yourself.  In my opinion unless you really understand it, cut & paste code will probably have issues which will be a nightmare to resolve.

Don't get me wrong, I mean finding other peoples code and learning from it is essential, but we don't just paste it into our app.  We rewrite the concepts into our app.

But I'm constantly hearing about people who cut & paste, and they talk about it like it's common practice.  I also see comments by others which indicate it's common practice.

So, do most programmers cut & paste code?

答:
In most cases, code that you'll find on the net won't fit your exact purposes.

What is see myself doing a lot is copying code from someone, stripping it down to the very essence and then adding code till it meets my requirements. I'll always refactor it to match my naming conventions and coding style.

I personally hate it when I read a tutorial and they start by showing code for a complicated case. Start with the essence and show building blocks to extend the code. If I ever start an own blog, I'll provide people with a commented code example which shows the essence of what I want to do, how you can add functionality/special cases and a fully working example of the basic feature.


答:
... several comments however say that free functions are to be
  preferred, even suggesting static classes were an anti-pattern. Why is
  that so in C++? At least on the surface, static methods on a class seem
  indistinguishable from free functions in a namespace. Why thus the
  preference for the latter?

An all-static class will get the job done, but it's like driving a 53-foot semi truck to the grocery store for chips and salsa when a four-door sedan will do (i.e., it's overkill).  Classes come with a small amount of additional overhead and their existence might give someone the impression that instantiating one might be a good idea.  The free functions offered by C++ (and C, where all functions are free) don't do that; they're just functions and nothing else.

Would things be different, if the collection of utility functions
  needed some shared data, e.g. a cache one could store in a private
  static field?

Not really.  The original purpose of static in C (and later C++) was to offer persistent storage that's usable at any level of scope:

```<code>int counter() {
    static int value = 0;
    value++;
}
</code>```

You can take the scope out to the level of a file, which makes it visible to all narrower scopes but not outside the file:

```<code>static int value = 0;

int up() { value++; }
int down() { value--; }
</code>```

A private static class member in C++ serves the same purpose but is limited to the scope of a class.  The technique used in the counter() example above also works inside C++ methods and is something I'd actually recommend doing if the variable doesn't need to be visible to the entire class.

Body:
... several comments however say that free functions are to be
  preferred, even suggesting static classes were an anti-pattern. Why is
  that so in C++? At least on the surface, static methods on a class seem
  indistinguishable from free functions in a namespace. Why thus the
  preference for the latter?

An all-static class will get the job done, but it's like driving a 53-foot semi truck to the grocery store for chips and salsa when a four-door sedan will do (i.e., it's overkill).  Classes come with a small amount of additional overhead and their existence might give someone the impression that instantiating one might be a good idea.  The free functions offered by C++ (and C, where all functions are free) don't do that; they're just functions and nothing else.

Would things be different, if the collection of utility functions
  needed some shared data, e.g. a cache one could store in a private
  static field?

Not really.  The original purpose of static in C (and later C++) was to offer persistent storage that's usable at any level of scope:

int counter() {
    static int value = 0;
    value++;
}

You can take the scope out to the level of a file, which makes it visible to all narrower scopes but not outside the file:

static int value = 0;

int up() { value++; }
int down() { value--; }

A private static class member in C++ serves the same purpose but is limited to the scope of a class.  The technique used in the counter() example above also works inside C++ methods and is something I'd actually recommend doing if the variable doesn't need to be visible to the entire class.


答:
Back in the day I needed to take a FORTRAN class. I knew other imperative languages by then, so I figured I could do FORTRAN without much studying. When I turned in my first homework, professor returned it to me and asked to redo it: he said that Pascal programs written in FORTRAN syntax do not count as valid submissions.

Similar issue is in play here: using static classes to host utility functions in C++ is a foreign idiome to C++.

As you mentioned in your question, using static classes for utility functions in C# is a matter of necessity: free-standing functions are simply not an option in C#. The language needed to develop a pattern for allowing programmers define free-standing functions in some other way - namely, within static utility classes. This was a Java trick taken word-for-word: for example, java.lang.Math and System.Math of .NET are nearly isomorphic.

C++, however, offers namespaces, a different facility for achieving the same goal, and it actively uses it in the implementation of its standard library. Adding an extra layer of static classes is not only unnecessary, but also somewhat counterintuitive to readers without C# or Java background. In a sense, you are introducing a "loan translation" into the language for something that can be expressed natively.

When your functions need to share data, the situation is different. Because your functions are no longer unrelated, Singleton pattern becomes the preferred way of addressing this requirement.


答:
Perhaps you need to ask why you would want an all-static class?

The only reason I can think of is that other languages (Java and C#) that are very much 'everything is a class' require them. These languages cannot create top-level functions at all, so they invented a trick to keep them, and that was the static member function. They're a bit of a workaround, but C++ doesn't need such a thing, you can create brand new top-level, independent functions directly.

If you need functions that operate on a specific data item, then it makes sense to bundle them into a class that holds the data, but then, these stop being functions and start being members of that class that operate on the class' data.

If you have a function that doesn't operate on a particular data type (I use the word here as classes are ways to define new data types) then it really is an anti-pattern to shove them into a class, for no other than semantic purposes.


问:
Ways to present testing results
I'm doing a school project which requires us to create a computer application and then write documentation; therefore I have to write testing documentation, I already have a of test plan (Validate all input and test all features) but how do I present the testing results in my project (e.g. table etc.)?</p>

答:
I would consider reporting various test coverage metrics. This will show that your tests are correctly exercising the full functionality of your application. Although, coverage metrics are like any statistics - they need to be clearly explained as they can be reported in mis-leading ways.

See types of coverage metrics on Wikipedia.

You can gather coverage metrics for applications that are tested both my manual and automated testing techniques.

Title: Ways to present testing results


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

答:
An external link is fine, perhaps with a brief synopsis on why said link
is interesting.  If at all possible, keep the whole comment on a single line.

If you are concerned that the link will be invalid in the future then make a local copy of the web page (Internet Explorer allows saving a whole webpage including images in a single file) and put the file in your documentation folder and link to that.


答:
The point of a comment is to explain why something is coded the way it is. Your comment is a good explanation why you have that extra check of the pipeline state there.

I think link is redundant though, because it is merely pointing to the current version of the documentation for the Invoke method. Unless your editor has support for clicking on such http-links, I would think it's faster to just press F1 on the Invoke method to bring up its documentation. Links might also change and using the help system to get documentation for a method seems the more natural way to get the most up-to-date information on a method.

Things would be different, however, if that was a link to a Stack Overflow question or some other source that solves a particular issue you had with a piece of code, e.g. information beyond what is provided in the official documentation. Especially if it took you a while to find online, it might be worth keeping the link to it in your code. But since even Stack Overflow posts aren't guaranteed to be around forever, making a local copy of the post might be more sensible if the information is critical to understanding a piece of code.

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

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


答:
Your comment is not needed as the code is clear enough to explain that it won't do anything if the state isn't NotStarted. If it is called multiple times then it has no effect. Maybe, you should consider the method name to clearly describe your method's intent.

On the separate case of putting references in your code, then yes add them in if they truly add value.


答: It's always nice to find a short comment where it is necessary. I support my teammates when they place a hyperlink to a good knowledge source instead of writing a long story about what's going on here. This approach cleans your code and keeps your comment up-to-date.</p>


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

答:
Bugzilla (roa any ticketing system - Jira etc..) should be great here.
It allows tickets (that will be tasks in your case) to be linked and finally, you can create tickets for your taskforce (engineers etc..).

Bugzilla supports products, components, ticket dependencies and the like - probably all you need for managing your task queue.

+1 for not letter customers send emails that will create tickets directly.

ContentLicense: CC BY-SA 2.5


答:
The information that should be included in a test report includes:

a summary of test results

the test ID number and the result of that particular test

any problems encountered in testing

times when the test procedure was deviated from

Since you are performing manual tests, each of your tests should be documented somehow, even if it's as simple as a numbered list of steps and what is expected to happen after each result. Every test should have a unique identifier that you can use to refer to it.

A test report that covers an entire suite of tests typically summarizes the results, including information such as the number of tests run, perhaps even identifying the name of the test suite or a listing of the tests executed. If there is only one test executed, then this often isn't needed as it's not necessary to summarize a single test.

For every test executed, identify the test by its identifier, note any problems or deficiencies in your testing plan (useful for identifying key problems that lead to changes in the test plan), and the final result of each test as a pass/fail. Depending on the specifics of the test, it might be useful to also note what caused the failure - what was the actual output, what error occurred, and so on.

How you format it depends on the nature of the data. A summary is best represented textually, but it could be represented by a pie or bar chart that shows the end result of various tests in terms of passing or failing. Specific test results are typically binary (pass/fail), but it's also useful to capture some kind of notes about why they failed. The testing reports that I've seen are typically in document format, but often contain tables. If you have large numbers of tests and need to easily produce graphs and charts, spreadsheets might be more useful.

Title: Ways to present testing results

Body: I'm doing a school project which requires us to create a computer application and then write documentation; therefore I have to write testing documentation, I already have a of test plan (Validate all input and test all features) but how do I present the testing results in my project (e.g. table etc.)?</p>


问:
Should the controller pass data to a view in the MVC pattern?
I work with ASP.NET MVC (and other web-based MVC implementations) quite often, but this is something I've never been sure of: Should controller and view communicate?

Of course the controller should be choosing which view to use, but what I mean is should the controller be passing data to the view? In my opinion, if the view is expecting data from the controller, then they're effectively tied together as a (controller, view) pair. Instead, I usually have the view communicate with the model itself and be independent of any controller.

Do I have the right approach, or is this a case of there being no one correct answer? Does the answer change when working in the web versus other environments? Does the answer change when you have the concept of a strongly-typed view (like in ASP.NET MVC) or not?

答:
The controller prepares data which will further be passed to the view for rendering / displaying. It also accepts user input data through a publish-subscribe mechanism or similar. Check out the first diagram on Wikipedia or Martin Fowler's website for more information about MVC.

if the view is expecting data from the controller, then they're effectively tied together as a (controller, view) pair.

While a view generally accepts data, in most MVC frameworks, it does not depend on specific controllers. Exceptions are, for instance, the JavaServer Faces family. Generally speaking, frameworks like Rails, Django or Spring MVC allow you to decouple views from controllers by passing data (the context, commonly a map/dictionary/bag) to a view (where a view is an implementation of the template view pattern).

Does the answer change when you have the concept of a strongly-typed view (like in ASP.NET MVC) or not?

Whether or not your programming language is strongly-typed has no influence on the way your are organizing your application.


问:
Does having Master's degree in Computer Science help your career?
I am curious about experiences of programmers who have gone beyond college or university and now work in the industry. I am not talking about academia (you need PhD there anyway). Do you have a Master's degree? Has it helped your career? Are there any other benefits besides the knowledge one gains while pursuing the degree?</p>

答: For me personally, I joined a company that will pay for my Masters in CS.  It's part of my decision on choosing careers.  I choose to go after my MS because it deepens my knowledge of CS much better.  In my undergrad I didn't get much exposure to AI, but in my Master's work so far I have, and that's far more rewarding and useful, to learn a new area of CS, than doing it strictly for potential job advancement.


问:
T-SQL stored procs orders of magnitude faster than LINQ
According to answers I've seen on stackoverflow, stored procedures (and to a lesser extent db functions) tend to perform better vs. LINQ + ORM frameworks (e.g. Entity Framework).

I want to determine if the performance difference is large enough to justify an increase in development time, assuming it takes more time to write equivalent, reasonably complex query operations in T-SQL vs. LINQ.

In which scenarios is there an order-of-magnitude (or at least a very large constant factor) difference in running time, between a performance-optimized stored proc  and its equivalent, performance-optimized LINQ counterpart? Or for scalar- or table- valued functions vs. the LINQ equivalent?

Hopefully, it is not too difficult to see that this question follows the guidelines per the FAQ. It's not asking a subjective question like, "which is better, T-SQL or LINQ?". It's asking for a few specific scenarios  (can give abstract or concrete examples)  where there is a significant difference in performance. If that still doesn't make sense to you, and you still think this question is not constructive and should be closed, please leave an explanation why if you can.

答:
In which scenarios is there an order-of-magnitude (or at least a very large constant factor) difference in running time, between a performance-optimized stored proc and its equivalent, performance-optimized LINQ counterpart? Or for scalar- or table- valued functions vs. the LINQ equivalent?

1 - When your business logic requires examining different data rows or large amount of data in general before it makes a decision or before it calculates a result, stored procedures have the advantage of doing this processing on the database server itself and could take a binary decision or perform the calculation on the server without passing any business data to the client. This results in good performance indeed. Let' say you have a complex business rule that would need examining 3 tables before you perform an insert. If you want your middle tear to do that, you have to bring the data via a query or more to the middle tear, execute the C# code (for example) and then continue with the insert or raise an error. When you implement the same logic on the server, you don't have to pass any data to the client (except the result).

2 - Stored procedures are also used in triggers and that is something you can't use LINQ for.


问:
Moving from a CVCS to a DVCS in a big company, what is the right way to do it?
I just started a new job and I'm currently at the process of trying to introduce a DVCS (mercurial, but the actual DVCS is not really a matter of discussion at this point, it could also be git) to the company (big, multinational). So far I've gotten nothing but positive attention, even at managerial and directive level, but I want to make sure I'm not at all disruptive to the organization or anyone's jobs.

The way the developers are set up is in a team room, so there's a lot of communication going on. There is also an integrator, that communicates on a daily basis two or three times with the team leader. Also, there are more development teams on other parts of the world, maybe 20 offices in 6 or 7 countries.

Company culture is open and there would be no problem pilot testing the tool  but the real question is (in capital letters):

HOW DO YOU CONVINCE MANAGEMENT AROUND ALL THE OFFICES OVER THE WORLD THAT ITS A SANE THING TO DO AND WILL ACTUALLY BRING HAPPINESS AND PRODUCTIVITY TO DEVELOPERS? (say pilot testing and showing it works is just one part of the answer).

Elaborating on the context...

Does it make sense to make the switch?, yes (note: current SCM is Perforce). I've witnessed several sources of frustration classic to centralized source control management, including:

People accidentally breaking other's builds or stepping on each others' toes while submitting code revisions.

This is not often as the responsible must wear a pink hat (hilarious stuff) until the build is fixed, but the hat is still there, and when builds get broken it affects the other offices around the world.

DVCS to the rescue: Builds are now broken in a single office, people lose the fear to use version control and can actually second-guess themselves after or check with a peer by sharing their changes easier and not necessarily with the rest of the group.

Unnecessary bureaucracy when it comes to granting access (e.g. looks like everyone is granted access to most of the code).

There is a dedicated group of admins who take 1 to 3 days to grant access to the code, meanwhile other developers must ask their peers for the code just to look at it... but AFAIK, the often wait instead.

DVCS to the rescue: Administration does not have to be centralized on a little group of overwhelmed people, new employees get the code from the project's responsible (1st level) or a peer with repository access (2nd level) who could even review their code and submit it along with his/her changes.

Complaints with regards to slowness due to network latency. Not that directly, but sometimes a) The perforce server is down, b) Internet is down, c) Internet or perforce server is slow. Yes, not that often, but it is annoying enough to kick you off your train of thought sometimes.

DVCS to the rescue: When using the DVCS you obviously don't need a network connection. Worst case scenario?, share your changes over LAN or sneakernet (with patch queues).

Trouble when trying to collaborate with external providers that do not necessarily belong to the organization. This happens often enough and security is a concern here AFAIK, and clients suffer from the access bureaucracy.

DVCS to the rescue: So granting access to a subrepo here would be the ideal solution here... also, clients themselves could use version control among themselves without needing to set up their own server and they would be able to integrate better to the internal workflow as currently Perforce access access to the local network, and thus more bureaucracy which is not necessarily security here, as external collaborators still have access to thumbdrives and email. Actual security would be having externals work in-situ... in a dungeon or something, and grope them à la TSA on their way out to make sure they are not getting the code out.

Workaround to integrate modules from other repositories. Requires additional maintenance/effort from the developers. **They actually wrote themselves (I think) a plugin to make Perforce fetch files from other repositories in other parts **

DVCS to the rescue: Their solution looks a lot like the mercurial subrepo feature, which uses a file (.hgsub) to indicate what code goes where, but they have to maintain the other repositories' states in the same file (which is done separately and automatically by mercurial in the .hgsubstate file).

Working with the source code requires to mark files for edit in advance. This adds an annoying extra step IMHO. If you don't do this the file will be in read only mode and you will not be able to edit it on your IDE, also, this in my opinion makes the local copy prone to low integrity. This trait of Perforce makes me think there was a lazy developer that didn't want to make the client check the files against the repository before versioning the changes. It also makes me think/personify Perforce as an idiot paranoid that says "DON'T CHANGE THE FILES WITHOUT TELLING ME OR THE SQUIRRELS WILL COME AND EAT ME!".

DVCS to the rescue: Well... I guess any other SCM software knows there are no carnivore squirrels.

Little project integrity in developers' machines (see previous point; its harder to add changes without previously indicating them to Perforce). You don't need a DVCS for this... but if you make changes locally and for some reason forgot to add them, you are going to have a hard time detecting it. Once you detect it there is a two step command line instruction thing I saw somewhere to detect changes you did without telling Perforce.

Given that context what would you say is the best way to... ?:

Know/demonstrate if the migration would actually benefit the employees and the company.

Ease the embracement of change, or at least make it look like its worth the effort

Not complicate others' jobs.

Convince management worldwide.

Avoid making the integrator's job a royal pain.

My second question (and focusing on the last point) I've always been a DVCS evangelist mainly because it eases the work and collaboration between developers... but up to this point I've never been faced with having to consider the integrators' perspective (the one in charge of coordinating teams' source code, creating and releasing the builds... from across the globe) who at some point might have to face two SCM sources or at least the migration itself. Then, how can the migration process affect integrators the least?.

答:
People accidentally breaking other's builds or stepping on each others' toes while submitting code revisions

This is an issue with organizational communication and programmer discipline. A DVCS is actually likely to make things worse in this situation, because individual programmers can keep working in their isolated repositories and not discover merge conflicts until they've become all but intractable.

Unnecessary bureaucracy when it comes to granting access (e.g. looks like everyone is granted access to most of the code).

How will a DVCS change this? Unless you have broad-based access rules (eg, everyone in "developer" group has permission to write the repo), you're going to wind up with bureaucracy. After all, someone has to maintain the ACL.

Trouble when trying to collaborate with external providers that do not necessarily belong to the organization.

A big win for DVCS. But it begs the question: how often do you expect to share repositories with these external providers? And how often do you expect to exchange updates?

Workaround to integrate modules from other repositories. Requires additional maintenance/effort from the developers.

How will a DVCS help here? I hope you're not planning to import the other module's source into your repo.

Working with the source code requires to mark files for edit in advance. This adds an annoying extra step IMHO.

I don't know Perforce, but optimistic locking has been available in every SCM that I've used since SCCS.

As I see it, your real problem is organizational, with developers happily doing their own thing without talking to one-another. In this situation, just adding a DVCS will make things worse, as I described above. To really make it work, you'd need to create the role of integration czar: a person who is responsible for pulling finished work from the various developers and making sure that it fits together. That's the way that Linus works, and it's the way that GitHub makes you work, but I'm not sure that it will go over well in most companies.

That said, there are a lot of benefits that a DVCS can bring to a team that communicates well. And Mercurial's server mode allows for informal sharing between team members, which I think is a Good Thing. But I'll second Karl's answer: start with a pilot project. And roll out slowly.


答:
Yes.

Adding links to your code is a great practice, and what makes it better is that you're explaining your reasoning of doing so.

One thing I would improve about the comment though is to leave some space between the link and the comment for better readability.

Another practice (alternative) would be to, on top of of adding the link, make your comment an excerpt of the article.


答:
The question you are raising is discussed in my team from time to time. We argue about two approaches, which both have their cons and pros.

The first, argues that the controller may update the view by the following pattern. It listens to both GUI and model events. When a GUI event occurs,
it executes the required action in the model, which in turn fires and event. Now the controller is usually updating the view with the required data.

The second approach, argues that the view itself is listening to the model events and updates itself with the data which is either attached to the event or by querying the model.

In the first approach you have more power to the controller which is really controlling everything which is going on your application. The power to decide in which way the view should be updated according to what event is in his hands and this way you are keeping your view pure. However, as you said, this way you have your view and controller coupled.

In the second you are decoupling them but your view is actually controlling itself in some manner.

Title: Should the controller pass data to a view in the MVC pattern?

Body:
I work with ASP.NET MVC (and other web-based MVC implementations) quite often, but this is something I've never been sure of: Should controller and view communicate?

Of course the controller should be choosing which view to use, but what I mean is should the controller be passing data to the view? In my opinion, if the view is expecting data from the controller, then they're effectively tied together as a (controller, view) pair. Instead, I usually have the view communicate with the model itself and be independent of any controller.

Do I have the right approach, or is this a case of there being no one correct answer? Does the answer change when working in the web versus other environments? Does the answer change when you have the concept of a strongly-typed view (like in ASP.NET MVC) or not?


问:
What defines a software architect?
At what  point does a developer stop being simply a developer and turns into a software architect. Or in other words, what's the minimum job description of a software architect?  </p>

答:
I think there is no best answer than:

An architect do architecture.

So if you do architecture, you are an architect. Maybe you asked for what is a "good" architect ? Or maybe a predefined task list?

In addition to the other excellent answers, including the one from Jim Leonardo, please read this document:

Who needs an architect - Martin Fowler

My opinion ?

Architecture is a team sport

OwnerDisplayName: mumtaz

LastEditorDisplayName: mumtaz

Title: What defines a software architect?


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

答:
I'm not familiar with any formal studies regarding PHP and Java effort or productivity explicitly - most work looks at languages of different generations. I know that Java is a third-generation language, and I'm pretty sure that PHP is also a third-generation language. This says that, all other things being equal, the inherent effort needed to produce the same product with both languages is close enough to not have a significant impact on the project.

However, knowledge of programming languages has been shown to indicate an difference in productivity of 1.20. It's one of the smaller factors: the capability of the team, the complexity of the project, even the tools used have a much greater impact on project performance than programming languages.

So, in short, the choice of programming language will have a difference in productivity. However, it's one of the smaller differences. I would be far more concerned with the other aspects of the project.

If you're interested in more, I'd look into tools such as COCOMO and SLIM and the underlying research that went into them. These estimate modeling tools allow you to take into account your knowledge and capabilities in different aspects of projects and determine how they impact your schedule, budget, and effort/productivity levels.


答:
Metrics are your friend here.

How many passes or cycles of tests did you do?  What percent of tests passed or failed?  Track defects by severity over time.  How many defects were found in the wrong phase?  (UAT finding defects that should be caught on unit testing) how many design or requirements changes were found in each phase?

Enjoy!

Title: Ways to present testing results


答:
It will take less time to develop application in PHP, but, most probably it will not be architecturally consistent enough and, therefore, it will have more bugs.
Nevertheless, cost of the change of PHP application will be lower comparatively to Java application.

On the other hand, Java application will take more time to design and develop, but it will be more robust and consistent. Most probably it will have less bugs, but it will be more difficult to implement changes.

Even though it might seem that languages are equal in the terms of time and efforts estimation, that's not true. It really depends on the specific application domain whether it will be good to use PHP or Java. Language does not matter, technology does. And there are PHP-technology and Java-technology. That's what you really need to take into account because both PHP-technology and Java-technology cannot be applied to some specific domains due to the language-technology specifics. For example, I would not ever try to apply PHP-technologies for Natural Language Processing. While it would be an overhead to develop simple admin panel in Java.

Application domain is what really matters.

Title: Assuming "clean code/architecture" is there a difference in "effort" between PHP or Java/J2EE web application development?

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


问:
How to get a job with no experience?
I am about to be a new college grad and I am trying to get an internship or a jr software engineer position. However, I have no experience at all in the field.

All I will have is my degree and my in class projects that I have completed. How can I make my resume more attractive so that I can get an interview? Also, how should I structure the details of my in class projects? Should I provide extensive detail?

答:
Early in your career online searches won't help.  At that point you have to get through HR.  Your beat options are either on campus recruiting, or if that is passed, network like crazy.  Be polite and assertive but not so aggressive that you willscarebpeople.  Be prepared to make 50 calls and 50 emails to get 10 introductory meetings, 5 first rounds, 2 all day interviews, and 1 offer.

Once at the interview show your eagerness.  Research the company deeply first.  Show up to the interview 10 minutes early.  Be polite to the receptionist.  Bring code samples.  Don't talk about money.  Do talk about finding a good mentor.   Send a Thank You to everyone you meet.  If you do this, even people who don't want to hire you will be willing to help out.

Title: How to get a job with no experience?


问:
How often do you use Formal UML?
I used ad-hoc MUML (made-up modeling language) to design and explain system fairly frequently.  It looks similar to UML and tends to be pretty well understood.

However, I've had a professor or two that harped on the use of strict, formal UML, as close to the spec as possible.  I always suspected that strict UML wasn't really as common as they claimed.  So, how 'bout it- how often do you actually draw out complete diagrams that use all the proper line endings, multiplicity, member type symbols, etc?

答:
Ironically, UML is supposed to be flexible.

In the real world, it is not supposed to be a pedantic exercise in doing it one right way.  It is about effectively communicating and documenting a system/process/idea.

To answer your question, I'm with the others.  I've never fully utilized full-on, formal UML.

Title: How often do you use Formal UML?


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

答:
Experience gained making those apps are more important.

It would be a waste of space to simply list the applications that you have worked on in the past and simply leave it at that.  It doesn't matter if these are personal applications or commercial applications.

What is important is the quality of the software that you have produced, and what you have learned in the process.

If you list these attributes first and then lastly present your applications as "proof", then it should be inconsequential if these were commercially created or paid for apps or personal projects.

IMO the most important aspects of writing any software for that matter are:

Results - are you proud of your achievements of these personal apps, are they of a quality you are happy for an interviewer to evaluate your skill based on these applications.  If not then DO NOT list them.

Methods used for Quality Assurance - Did you write JUnit Tests, perform end user testing with multiple emulators in various screen resolutions / orientations.  Does the software work without crashing, handle exceptions correctly etc.

What you have learned creating your personal apps - What technology did you use, what have you learned that can be applied to your next commercial app.

If you can answer the above questions in your resume (very quickly in bullet form), and express that you went through the same process as you would have for a commercial app.

You will then be showing clearly that you have relevant experience.


答:
So the question do you want to target Android Market only or Android + Java?

If you are an experienced Java developer, I would say mention your experience as Java developer and then add your experience as an Android developer. Try to indicate that you are making a shift. This way you will have a professional experience as well as your own project to indicate you are trying to make switch. Three projects are good enough to get into Android Market. Even one is good enough. You just have to sell yourself. I probably would list them on the top since that is where I am focusing now.

I had a similar change of career from C++ development to web development. Initially I had listed only one of my PHP projects and my resume was a mixture of C++ and PHP. Gradually got a couple of more projects that I added and then I just totally focused it on Web Development. I still mentioned my C++ experience. I had better success with my web developer resume although the C++ market wasn't that bad at all.

Should you list your personal project?

Absolutely. As Justin answer says if you are proud of it, mention it! You must! Believe it or not I got sold by stuff that I did personally years ago when I was a student. I was proud of it so I mentioned it. One could have said, why bother mentioning such thing, and they wouldn't be that wrong.

I think it is important to highlight both your experiences Java + Android. And you are good to go.

Title: How to add personal android projects to my CV to get into Android job market

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


答:
Quick Short Answer

PHP, is easy & fast for the first time, but, if becomes complicated when updates to code are done. Java may seem complicated at first, but, it will help things later.

In both cases, consider, not just the progr. lang. plus frameworks, also, specially if you go for PHP.


问:
Which of the following data duplication options across shards is recommended?
High performance mysql book suggests that for sharding a blog application, one may want to put comments data across 2 shards: first, on the shard of a person posting comment, and on the shard where the post is stored.

So this raises the question how to reliably duplicate this data. Which of the following data duplication options across shards is recommended?

Option 1: Make 2 separate inserts from the PHP script.

Pros: a) Logic is in application layer.

Cons: a) User is held for 2 inserts. b) This logic will need to be duplicated in every client trying to insert similar data.

Conclusion: Seems reasonable.

Option 2: Form federated tables and use some trigger to handle the insert of duplicate.

Pros: a) App layer doesn't need to worry about multiple inserts

Cons: a) Every shard need to have federated connection to every other shard; b) Federation will work on machines in LAN, but what about at 2 different sites. c) what if connection to federated server fails.

Conclusion: Doesn't seem like a sound idea.

Option 3: Messaging such as RabbitMQ

Pros: a) Different clients can insert data at one place, and all subscribers can consume the insert.

Cons: a) Complex; b) may impose overhead in order to host messaging server, and clients; c) not sure how will it work with a look-up service to locate appropriate shards

Conclusion: Not sure

Option 4: your suggestion?

I will greatly appreciate your help.

答:
This question can be restated more generally as "when do I denormalize data to improve performance." And the answer is "when the cost of performing a normalized query exceeds your performance threshold, and the cost of maintaining duplicate data is justified."

Let's start with a traditional relational design for a bank. How do you compute the current account balance? In a fully normalized schema, you would perform a query against the transaction table. However, your users will be checking their balances all the time, and you don't want to pay the cost of that query for every balance inquiry. So you make the decision to add a field to your ACCOUNTS table, in which you store the current balance and update it as part of every transaction.

On the other hand, given the requirement "show customers the total amount they've spent, by payee," you'd probably perform the query against transactions, rather than attempt to denormalize. While there may be some users who check their payment breakdown on a daily basis, most users will never do it. So you don't want to waste disk space and coding time on a denormalized table.

I think the same thing applies to "show me all my comments." Yes, there are some users who will do this all the time (and I may be one of them; I often check the "Activity" tag on SO to pay attention to questions that I've answered or commented on). But it's probably not the majority of your users, so it's probably not that expensive in the grand scheme of things to perform an all-shards query to retrieve the data.

Or maybe it is. In that case, you have to answer the question "who is to be master" (or, without the Alice in Wonderland reference, the "authoritative source"). In the case of the bank account, the transaction table is always the master. If, for some reason, the balance as stored on the account is different from that calculated from transactions, you must update the former from the latter.

In the case of blog comments, I believe that the blog entry is the authoritative source. Which means that, when the request completes, I want that table to be updated, regardless of what happens to the comments-by-user table. And I also want the comments-by-user table to have a reference to the comments-by-entry table, so that I can reconstruct it if the two get out of sync.

How you accomplish this is a trade-off between complexity, response time, and how important it is that you keep the two tables in sync.

As you point out, having triggers between the various shards is silly; the whole reason for sharding is independent database operations. So you can throw it out right away.

Updating both tables at the same time is the approach with the fewest moving parts. Over the long term, it will be the most maintainable. And it will be the easiest to debug if something goes wrong.

But if response time is important, then you might think of some sort of messaging approach: update the comments-by-entry table, and queue a message to update the comments-by-user table. If it takes an hour for that message to be processed -- or if it gets lost in a system crash -- no big deal, you can always recover. By no means should you use a messaging approach to update both tables.

So, bottom line is that there are no clear-cut answers; it's all about tradeoffs. And that's why they pay us.


问:
Designing a scalable and robust retry mechanism
Backstory

I have an Messaging Server Application that is responsible for brokering/proxying calls made from an Application Tier to numerous external services.  The purpose of this application is to abstract the technicalities of invoking these services away from the main Application Tier.

This works well as the Application Server does not have to worry about http/ldap etc protocols, wcf, ftp, soap, ebxml etc etc.  They simply send a "payload", with a few identifiers, and the Messaging Server handles the rest.  It also means that if a service definition changes the Application Server does not need to be changed.  Additionally the Messaging Server is back ended by an SQL 2008 database that stores an audit of all messages sent and associated responses etc.

The general data flow architecture of this is as follows:

Application Server(s) => Load Balancer => Messaging Server(s) => [X] => External Services

The Question

I need to implement a retry mechanism into the Messaging Application tier.  The intention is to gracefully recover from situations where the Messaging Server isn't able to forward onto the target service (i.e. service down, network issues, timeouts etc), i.e issues with point [X] in the architecture above.

The high level design requirement is:

Application Server sends a request to the Messaging Server.  This then attempts to forward to the external services.  If the first attempt at this fails the Messaging Server responds synchronously to the Application Server stating that the message is "in retry"

The Messaging Server then proceeds to retry the fowarding per the contract (i.e. X retries with Y seconds between each).

One of two things will happen next, all contracted retries will have been performed unsuccessfully or one of the retries will succeed.  In either case a message is sent back into the Application Tier to notify the state of the messaging request.

A few gothcas

The message to retry can't be held in "memory" as if that Messaging Server goes down the message is lost.  Additionally a retry contract could be 5 times once every 12 hours, holding data in memory for that length of time isn't feasible.  That said some retry contracts could be 5 times once every 5 seconds.

If the forward network goes down and then recovers the load of the retries should be spread across the entire messaging tier rather than a single server.

The question

The commucation between Application and Messaging tier isn't a concern as that framework is already in place.  However the architecture of the retry framework in the Messaging Tier is still up in the air.  How would you implement this?

Options we have/are considering

On failure store the retry data in a database, then have a polling service that checks the database every second.  If a message is found that is scheduled for retry this is push back onto the Messaging Tier via the Load Balancer

On failure store the retry data in a database, use a CLR job to poll the database and push messages, scheduled for retry, back onto the Load Balancer

Other Information

May or may not be relevant:

All code is C#

Databases are SQL 2008

Comms from Application to Messaging tier is performed via WCF with BasicHttpBinding.

We have complete control over all aspects of the Messaging Server tier and no control over the Application Tier.

The Messaging Tier currently handles around 500k transactions per hour, so you can imagine how quickly things will backup if there is a failure on one of the external services

答:
Consider a exponential retry timeout

In the solution you've provided above having a retry mechanism every 1 second is naive solution.

You should consider a exponential time increase up to a maximum (decided by the business).

This is to avoid situations where you are spending valuable cycles on polling an ever increasing backlog of messages which will only fail and slowing down the processing of messages that can be handled and processed immediately.

Poisoned Messages

It is possible for poisoned messages to show up.  These messages may never be able to be processed for one reason or another.  You should consider having a process in place to identify and handle these messages.

This is a business decision, not an implementation detail

I think the most pertinent question is not what is said here, but what does the business want to do in this situation?  How to actually create a retry polling mechanism is trivial.  What the business wants to do in that situation is not, and is purely a business decision.

Real world example

I wrote a Distributed System for my employer a number of years ago (MSMQ, C#, etc).  I implemented a system whereby messages would have a retry mechanism which would retry using an exponential function until it hit a max of once per hour.

I had a NAGIOS monitor in place which would poll and then detect number of failed messages in the queue and then push an alert if it reached a certain threshold.  This would instantly alert the business that a vendor was offline and that clients who would be expecting a turnaround of lets say an hour.

It would then be a business decision (in this case the business decided to cancel all of these queued backlog of messages and then handle these manually via the helpdesk).  And so the application had to be written to be able to allow manual processing of these messages.

In other instances where the vendor was only offline for a few minutes, the retry mechanism picked them up and handled them as per normal.  However having the exponential timeout allowed the system to gracefully process regular transactions and the backlog without snowing the server under when the vendor came back online.


问:
In what areas of programming is algorithm run time actually an important issue?
Sometimes I hear people say that because of the speed of processors and the amount of memory available, algorithm efficiency and runtime aren't, in practice, of major concern.

But I imagine there are still areas where such considerations do remain of paramount importance.  Two that come to mind are in algorithmic trading, where thousands of transactions must be conducted in fractions of a second, and embedded systems programming, where memory and power are often scarce.  Am I right about these examples ?  and what other areas would also be examples?

答:
Three more that haven't been mentioned:

1)  Many real time strategy games.  Look at those which have units which can't share a position.  Watch what happens to the pathfinding when a large group of units moves through restricted terrain.  I have yet to encounter a game without some sort of substantial problem with this because there simply isn't enough CPU power available.

2)  Many optimization problems.  (Edit:  Since I wrote this answer I've hit one.  My objective was to prune redundant paths so as to leave all nodes connected with the minimum weight of the connecting paths.  My original approach worked pretty well until I moved more of the pruning to that routine, then I realized it was 2^n.  Now it's n^2 even though that can sometimes produce a slightly non-optimal result.)

3)  Things which must operate on large amounts of data in realtime.  Consider a DVD:  You usually get 2 hours of video in 4.7gb.  Consider a typical video file at the same resolution:  Those 2 hours of video will generally come in under 1gb.  The reason for this is when the DVD spec was laid down you couldn't make a reasonably-priced DVD player that could decode the more modern formats fast enough.


答: Create a section at the bottom that lists what you did.  If anything is piblicly available, mention it there.  Also include all the buzzwords to get it by HR and the auto filters.</p>


答:
Your answer: Not at all

I have extensive experience with both PHP and Java and I can tell you that if you know PHP well enough and you are not a total noobie and know that PHP can do classes, interfaces (and soon now even traits for horizontal reuse), exceptions, automatic class loading, etc., your PHP code can look better than Java code, and even work better.

Don't believe me?, check the Symfony framework to see (IMHO) the best architected piece of PHP software out there, look at its manual for code examples.

The real problem behind PHP

Noobies, script kiddies and mediocre programmers... there are a lot, and they all seem to turn to PHP for being too easy. PHP is too easy indeed, and that is not a bad thing (blame the excellent language documentation).

Every language has its flaws and as a matter of fact, one of the most flawed languages around is javascript, and look where it is now (hint: everywhere).

Some of the advantages when selecting PHP

Wider and cheaper market for developers. Just look for PHP developers with OO background and a good attitude towards learning if you choose Symfony (you won't regret it, specially because of Doctrine, the ORM Symfony uses), but there is a learning curve (smaller than it appears, it does appear big sometimes).

Cheaper hosting services.

Easier to setup your developer and production environments.

So the effort could be about the same, but the previous perks are what separate it from Java, and I'm sure there are more.


问:
What language does Introduction to Algorithms by Cormen use?

What language, if any, is used in this book? My school is currently using a terrible book for the algorithms course that I have to take next year and I'd like to convince the department head that Introduction to Algorithms by Cormen is a much, much better book.

答:
Its language agnostic. No language in particular. To understand the syntax of the pseudo-code you have the explanation of used conventions after first algorithm which I remember was perhaps Insertion Sort.

Yes it does have a treatment on data structures as well.


答: You can call it as your Pet-Projects and put it under your educational qualification before professional experience to highlight it in same order.</p>


答:
You make an initial assumption that you need experience to get hired. That is not a true statement. Plenty of companies hire new grads. And, they don't expect you to have experience at all.

So what do they want from a new grad? They want you to be smart. They want you to have natural talent for coding. That's basically it. If you have that, you're hired.

How do they determine that you're smart? The best measure of that is your GPA. You're pretty far along now, so hopefully you have a 3.5+ GPA, and failing that, you have a high GPA in your CS coursework. If you have the high GPA, put it on your resume. If you did any significant projects in school, put them on there as well.

Now, not all companies hire new grads. So, once you have your resume together, you need to find the companies that might hire you. One place is a career fair at your school. A second place is on linkedin. There are tons of recruiters on linkedin. Find them. Message them. Ask them if they're hiring for new grads. Hint: Larger companies are more likely than very small companies to do this. Also, get a linkedin account and link against everyone who is good in your CS program. You'll discover after you get hired someplace that companies pay $$ for engineering referrals. All those people you talk to in class every day can turn into serious coin in your pocket down the line.

Finally, you get some interviews. This is where they try to figure out if you have programming talent. The standard fare is data structures and whiteboard coding. Make sure you know data structures cold. Make sure you can code on a whiteboard. As in, "write a function that verifies a binary search tree is valid (in the sense that every node to the left is less than, and every node to the right is greater than)." Make sure you can do it well enough that the code (mostly) would compile. It doesn't have to be perfect, but it better not be 1/2 java, 1/4 pascal, and 1/4 random sloppy pseudocode. This takes practice to be good at. I suggest you spend time practicing with friends or you'll have a rough time your first few interviews.

Now, if you can do this, you WILL get offers. If you're in a big city, you'll probably get more than one. You don't realize it yet, but finding good programmers is hard. And companies snap them up (even new grads with no experience) when they find them.

Good luck.

Title: How to get a job with no experience?

Body:
I am about to be a new college grad and I am trying to get an internship or a jr software engineer position. However, I have no experience at all in the field.

All I will have is my degree and my in class projects that I have completed. How can I make my resume more attractive so that I can get an interview? Also, how should I structure the details of my in class projects? Should I provide extensive detail?