答:
I like the natural rhythm in pair programming. </p>

<p>That is, you program for a while until you feel somewhat tired, then switch and let the other person continue. This gives you a break from the  physical coding and switches your focus from syntax/writing to planning and look-a-head. It keeps your mind refreshed. At least for me anyway. </p>

Title: What is the most effective work rhythm for a programmer?

Body:
I was wondering what is the best work rhythm for the job a programmer does? I am coding all day long and sometimes I get stuck in a problem and it keeps me occupied a few hours before I realize that maybe I need a break.

Some say frequent and short brakes help you but sometimes when I am focused on a problem I feel like a break would not help, but rather loose my focus. So how often should a break be taken, and how long? The more basic question regarding this issue is comes from the fact that, you can get tons of "good ideas" ('promodo' for instance) on the net, that promise you will be more effective in whatever you do.

Are these principles good or, this is something everybody should decide for himself?
I wonder if any of them can accomplish what it promises! I mean what they promise is that (if the conditions are met) it works for everybody. Are there really such principles? And if there are, what are these and how can we find them?

Body:
I like the natural rhythm in pair programming.

That is, you program for a while until you feel somewhat tired, then switch and let the other person continue. This gives you a break from the  physical coding and switches your focus from syntax/writing to planning and look-a-head. It keeps your mind refreshed. At least for me anyway.


问:
How big should OSGi bundles be?
Or more completely "What are the trade-offs and questions that should be raised when trying to decide the bundle structure of an OSGi application?"

Our existing OSGi bundles have tended to be quite fat: basically an API bundle and an implementation bundle, but with a lot of functionality. That has advantages in terms of project and build complexity, but maybe doesn't give us all the reusability and flexibility we desire.

So in a recent project, we intentionally made quite thin bundles. We did a walkthrough this AM and we wondered if we'd gone too far. In this quite-small service we had 7 bundles, several of which only had 1 domain class. The question raised was "This is almost like we're driving towards a bundle per package. But we have classes and packages already in the language, are we going too far with our bundle granularity?"

To make it concrete, this is a Web Service that performs a calculation on the aggregate results of other Web queries (specifically, we query a bunch of astronomical databases for objects in a given area and then we filter the results based on our own criteria and then we estimate a probability of an adequate observation based on the filtered results). We ended up with 7 bundles, which seems like a lot for what is essentially "a servlet that performs a calculation."

Is such very-fine granularity good (lots of flexibility at runtime) or bad (overly complicated)? How can we develop our intuition about the "just right" granularity of our OSGi bundles?

答:
Since there hasn't been any answer so far, let me just give you an impression of how I usually approach this matter. To me, OSGi bundles roughly correspond to components in software architecture and the most important factor in whether or not to turn something into its own bundle is the value of being able to exchange it.

Whenever you can imagine that a future version of your product may want to rely on a different component that performs the same tasks (i.e., same interface), but does it in a different way, turning it into an OSGi bundle certainly isn't the worst way.

Another (albeit obvious) point is when you are writing software that can be extended by others via adding their own bundles.

As all of this sounds rather abstract, let's make it more concrete based on your example:

you aggregate results of web queries. I wouldn't mind bundling up aggregators for each database. Chances are that you may have to add in another database someway down the road and you should be able to easily delegate that task to others by giving them an existing bundle for another database and ask them to add the new one in the monkey-see monkey-do way.

you filter results. Filters are one of the things that tend to change quite often, and hence, are a natural fit for bundling so you can easily exchange them.

As for the calculations I do not know enough about it, but generally I do not think 7 bundles are too much for what you're describing.

There is one thing to keep in mind though: the effort of creating so many bundles only really pays when you have a product that is continually being worked on. If in the following weeks/months/years you will be adding new bundles all over the place, having a fine granularity makes it easier to fit the new functionalities in and replace old ones.

If on the other hand you are going to have to rewrite almost everything anyways, because your product only ever receives major upgrades that seem like new products, then you do not gain much anyways.

ContentLicense: CC BY-SA 3.0

Title: How big should OSGi bundles be?


问:
What do I need to do, to get placed in any software company?
I'm doing my 3rd year CSE Engineering. I guess this is the right time to ask this question!

As in the next year, I'm going to do projects, "get my hands dirty". And there is only few days left out, as I know many people in Stack Overflow are working in Software field, I thought to ask these question.

Does the project that I'm doing in my final year need to be excellent? If so, what kind of project to do? And how do you say that the project is excellent or not?

Writing the code is very fun and serious at times. But the code should have a good algorithm?

And mostly in any software companies interview, what kind of question they ask?

Not but not the least, mastering in any particular language speaks in interviews?

答:
Does the project that I'm doing in my final year need to be excellent? If so, what kind of project to do? And how do you say that the project is excellent or not?

A program is a program if it is programmed to do what it is supposed to do. Not being too aphoristic, if you can always establish a correct relationship between your code and the resultant program, even if the relationship tends to be wrong, it is a good program (Actually, there are only bad programs since good programs are correct programs). So if you can explain your logic in the creation of your program and can extend the logic till its execution, your program is excellent irrespective of whether it is big or small and you can always build upon it. So choose a problem, think of a few solutions and program it. Don't think of programming straight away. Remember the basic scientific research rule

Cause and effect must always be proved

Writing the code is very fun and serious at times. But the code should have a good algorithm?

An algorithm is good when it is understood by the computer. Its great when it could be understood by humans. (That's why you search Google not wolfram alpha even for math solutions) So to create great algorithms, understand the problem and try to explain it in logic or mathematical terms. A rule from Pragmatic Programmer

Rule 51# Don't gather requirements - dig for them

And mostly in any software companies interview, what kind of question they ask?

The difficult part of your question since this is hugely subjective. Most questions to a newcomer are technically oriented. Just visit some interview questions site

Not but not the least, mastering in any particular language speaks in interviews?

Definitely yes. But mastering design and patterns is the best bet in the long run since understanding the requirements is the single biggest task in software engineering (in fact, in any domain). An another rule from Pragmatic Programmer

Rule 53# Abstractions Live Longer than Details

OwnerDisplayName: Anto Aravinth

ContentLicense: CC BY-SA 2.5


问:
Data Serialization to process business logic
Going by the general principle of data abstraction, I normally abstract data in a serialized format(JSON) and pass it as a parameter to the Business Logic(BL) modules such that the BL module always see a consistent format of the data irrespective of the underlying data storage layer. Even if I use a ORM, I use the serialized format of that ORM. I feel I have the following advantages.

By serializing data, there would be better control over data and parameters

Any developer can write BL without thinking too much about the underlying data storage

Wrappers can be written for new databases (There are a lot of ready-made wrappers to convert data into JSON)

Testing could be done ruthlessly and without a database (since the data format is serialized)

Functionally easier to understand and better OLAP, OLTP integration

I also notice the following drawbacks

A new layer to be added between the database and the BL module (most ORM's nowadays come with a predetermined JSON format)

Extra function calls slow down the application (but I think this trade-off is OK when compared to better testing and easy maintenance)

Increased level of abstractions may confuse the developer

I make the above observations mostly in the context of business applications
To follow this discussion, lets have an example so that things could be discussed in its context.
Assume a product database having the columns: Product,Rate,Taxes and we need to create a invoice

Code without database abstraction

```<code>GET rate,taxes for product X from database
multiply qty with rate and add taxes
display invoice
</code>```

Code with database abstraction

```<code>  GET rate,taxes for product X from database
  Convert it into JSON
  call create_invoice function //This does all the calculations
  display invoice
</code>```

In the second example, I would pass arguments in the form (Product=X, Qty=5, Rate=5, Taxes=0.05). If taxes are to be split into more that one category (State Tax=0.03, Central Tax=0.02) or a discount factor to be added  I would just increase the number of parameters in the BL functions such that the database fields, the JSON keys and the function parameters match (this is done automatically during serialization and most ORM's do it). This makes it easy, in my approach, to extend functions and also make modules independent of data since the modules always know the data they can receive and even if they receive a new parameter, they can adapt it provide the underlying code is intelligent.

My general questions are

Is this a good pattern and what's it called (Data abstraction comes to my mind)?

Pros/Cons of this pattern(apart from those mentioned above) in the context of business application, apps for embedded devices, big data

Is there a difference between this pattern and ORM (I believe so since ORM is mostly a class wrapper to get data from a database while this pattern is more oriented towards data structure)

If this is good, can this be easily understood by a new developer?

答:
Databases already provide a standard format for their responses and database drivers already know how to interpret/use them. The JSON marshalling and unmarschalling steps are therefore superfluous if the result in its format won't be transferred to another system.

In my opinion you should move more towards encapsulation, with native objects and structures instead of passing a serialized data fragment around.

The only advantage I see is the testing process; you can inject methods with random JSON data and don't  need a database. But that's kind of a big trade-off for so much perfomance-loss.


问:
Making an HTML5 application for both Android and iOS
I was checking out a video tutorial on HTML5 using Dreamweaver to do Android and iOS apps (using Phonegap) and it clearly mentioned that you need a Mac to debug and simulate for iPhone, iPod, etc. Is there any way around this?

I really want to develop apps for iOS and android (more iOS) using HTML5 but what I need to know is if you develop an app with HTML5 and debug it in an android environment, is it still portable to iOS?

My apologies if this question seems a bit ignorant but none of my google searches return results that answered my question. Maybe I'm not even asking the right question.

答:
In principle, an HTML5 application should behave the same on any device.

But there are small (and some not so small) implementation differences across different architectures/platforms. The most important factor to consider is the touch gestures that the iPhone provides, that some Android phones don't and vice-versa.

On the other hand, HTML5 is only a front-end. To build a functional application you will almost certainly need a back-end. HTML5 provides some persistence mechanisms but they are very limited.

The last (minor) thing to consider is the wrapper you need to display the HTML5. It will be different for Android and iOS.

You're better off writing a web-based application with a server back-end and letting your users access it from whatever device over their browser.


问:
Difference between static testing and code review

Possible Duplicate:

  What is the difference between Static code analysis and code review?

What is the difference between static testing and code review?

I found some information on wikipedia that in both cases the programmer checks the syntax and code logic for bugs.

答: The difference is in the who: Static testing is done by the programmer himself, preferably with the help of static testing tools. Code review is done by another human.

OwnerDisplayName: dbow

OwnerDisplayName: thiton


问:
Automatically update copyright date range from git?
As I write, we're 10 days into 2012.  I bet many programmers are editing the copyright string at the top of their source files to something like:

```<code>// Copyright 2008, 2010-2012 Some Company Unlimited
</code>```

Your version control system knows when files were modified so surely it can help write or rewrite these strings.  So my question: is there a script that can examine git logs for each file and output (or better insert) a string like that about?

I'm using git so that's of primary interest but do let me know if such scripts exist for other systems.

Update:

We need a script that does this:

Walks all source files in our working copy

Locates existing copyright string and identifies years e.g. 2007,2009-2011 would be {2007, 2009, 2010, 2011}

For each year that is not mentioned, diff between 1 Jan and 31 Dec (or today if current year).  Examine diff and decide if it's worthy of a mention in the copyright string

Insert new copyright string.

答:
is there a script that can examine git logs for each file and output (or better insert) a string like that about?

It's not a script per se, but Git feature, which you can use for this task: smudge/clean filter pair


问:
"Gödel, Escher, Bach" still valid today?
I have just completed a course on computability and logic which was an interesting course. The lecturer recommend a few books on his slides, which include "Gödel, Escher, Bach". I can see the book is quite famous, and looks very interesting. But I have a few questions to ask regarding its content.

Is the content still valid today? I guess most theoretical stuff doesn't change over night, but are there any major points which no longer hold today that I should be aware of?

I assume we actually HAVE made some progress in the last 30 years or so. Can any of you recommend a book on the subject which includes this progress (logic, AI, computability)?

Another question: Do I have to know about Escher and Bach?

答:
To answer the other question (belatedly) about having to know about Escher and Bach, I can say: no, you don't have to know about their work.

All relevant ideas and facts will be right there in Hofstadter's text: he includes some of Escher's graphical work (where it really helps to focus the reader's mind) and sometimes mentions Bach.

However, I didn't get into Bach until after I had read GEB, and I don't feel I have missed out on anything. If you get curious about Bach's compositions, you can easily just listen to a few of them and quickly get the gist thanks to Hofstadter's ideas rather than the other way around.

On a tangent: I was really only familiar with Escher's work (although I hadn't considered it in depth) and not even with Gödel's ideas until I read GEB. I have to admit that I didn't initially understand Gödel's theorem -- I read the book when I was still studying Classical Philology -- until I did some (actually: a lot of) reading on the side.

So in conclusion: you don't need to know about Escher and Bach but you do need to understand Gödel's ideas. You can however start reading up on Gödel after you have begun reading GEB, when Hofstadter starts incorporating Gödel's ideas.


问:
How to keep a big and complex software product maintainable over the years?
I have been working as a software developer for many years now. It has been my experience that projects get more complex and unmaintainable as more developers get involved in the development of the product.

It seems that software at a certain stage of development has the tendency to get "hackier" and "hackier" especially when none of the team members that defined the architecture work at the company any more.

I find it frustrating that a developer who has to change something has a hard time getting the big picture of the architecture. Therefore, there is a tendency to fix problems or make changes in a way that works against the original architecture. The result is code that gets more and more complex and even harder to understand.

Is there any helpful advice on how to keep source code really maintainable over the years?

答:
Since you've tagged the question with project management, I've tried to add some non-code points :)

Plan for turnover - assume that the entire development team will have disappeared by the time it hits its maintenance phase - no developer worth their salt wants to be stuck maintaining his / her system forever. Start preparing handover materials as soon as you have time.

Consistency / uniformity cannot be stressed enough. This will discourage a culture of 'go it alone' and encourage new developers to ask, if they are in doubt.

Keep it mainstream - technologies used, design patterns and standards - because a new developer to the team (at any level) will have more chance of getting up and running quickly.

Documentation - especially architecture - why decisions were made, and coding standards. Also keep references / notes / roadmaps into documenting the business domain - you would be amazed how difficult it is for corporate business to explain what it is they do to a developer with no domain experience.

Lay down the rules clearly - not just for your current development team, but think about future maintenance developers. If this means putting a hyperlink to relevant design and coding standard documentation on every page, so be it.

Ensure that the architecture and especially code layers are clearly demarcated and separated - this will potentially allow for the replacement of layers of code as new technologies come along, for example, replace a Web Forms UI with an HTML5 jQuery UI, etc., which may buy a year or so of added longevity.


问:
Should unit tests be stored in the repository?
I'm a growing programmer who's finally putting unit testing into practice for a library that I'm storing on GitHub.

It occurred to me that I might include the test suites in the repo, but as I look around at other projects, the inclusion of tests seems hit-or-miss.

Is this considered bad form? Is the idea that users are only interested in the working code and that they'll test in their own framework anyway?

答: I've just finished reading "Brownfield Application Development in .Net", and this provides some excellent advice of the structure of an application, including source control and where/how/why to include unit tests (particularly in the area of Continuous Integration).  If you're a .Net developer, I'd recommend it.</p>


问:
Make a big deal out of == true?
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

答:
I write if(var==false) because after writing var i dont feel like backtracking and write ! behind it. Also i like how ==false makes it look more clear.

However == true is just weird. I dont know if there is a point of making a big deal. I wouldnt unless he is pushing others to use it or to make it a coding standard.

Title: Make a big deal out of == true?


问:
What are the complexities of memory-unmanaged programming?
Or in other words, what specific problems did automated garbage collection solve? I've never done low-level programming, so I don't know how complicated can freeing resources get.

The kind of bugs that GC addresses seem (at least to an external observer) the kind of things that a programmer that knows well his language, libraries, concepts, idioms, etc, wouldn't do. But I could be wrong: is manual memory handling intrinsically complicated?

答:
Really, managing your own memory is just one more potential source of bugs.

If you forget a call to free (or whatever the equivalent is in whichever language you're using), your program can pass all of its tests, but leak memory.  And in a moderately complex program, it's quite easy to overlook a call to free.


答: Manual resource is not only tedious, but also difficult to debug. In other words, not only is it tedious to get it right, but also when you get it wrong, it's not obvious where the problem is. This is because, unlike for example division by zero, the effects of the error show up away from the source of error, and connecting the dots requires time, attention and experience.</p>

Title: What are the complexities of memory-unmanaged programming?

Body:
Or in other words, what specific problems did automated garbage collection solve? I've never done low-level programming, so I don't know how complicated can freeing resources get.

The kind of bugs that GC addresses seem (at least to an external observer) the kind of things that a programmer that knows well his language, libraries, concepts, idioms, etc, wouldn't do. But I could be wrong: is manual memory handling intrinsically complicated?


答:
Considering a non-garbage-collected memory management technique from an equivalent era as the garbage collectors in use in current popular systems, such as C++'s RAII. Given this approach, then the cost of not using automated garbage collection is minimal, and GC introduces plenty of it's own problems. As such, I'd suggest that "Not much" is the answer to your problem.

Remember, when people think of non-GC, they think malloc and free. But this is a giant logical fallacy- you'd be comparing non-GC resource management of the early 1970s to the garbage collectors of the late 90s. This is obviously a rather unfair comparison- the garbage collectors that were in use when malloc and free were designed were much too slow to run any meaningful program, if I remember correctly. Comparing something from a vaguely equivalent time period, e.g. unique_ptr, is much more meaningful.

Garbage collectors can handle reference cycles more easily, although these are pretty rare experiences. In addition, GCs can just "throw up" code because the GC will take care of all memory management, meaning that they can lead to faster dev cycles.

On the other hand, they tend to run into massive problems when dealing with memory that came from anywhere except their own GC pool. In addition, they lose a lot of their benefit when concurrency is involved, because you have to consider object ownership anyway.

Edit: Many of the things you mention have nothing to do with GC. You're confusing memory management and object orientation. See, here's the thing: If you program in a completey unmanaged system, like C++, you can have as much bounds checking as you like, and the Standard container classes do offer it. There's nothing GC about bounds checking, for example, or strong typing.

The problems you mention are solved by object-orientation, not GC. The origin of array memory and making sure you don't write outside it are orthogonal concepts.

Edit: It is worth noting that more advanced techniques can avoid the need for any form of dynamic memory allocation at all. For example, consider the use of this, which implements Y-combination in C++ with no dynamic allocation at all.


问:
Better approach for updating live website on Server
I follow a very raw approach while updating my website on server. The approach I follow doesn't seem right, so I am interested in knowing a recommended way of updating a LIVE project, be it on shared host or dedicated server.

Right now, for any changes in View, I simply upload and overwrite the view files on server. Similarly for any code changes, I upload and overwrite the .dll and .pdb files. Currently my website doesn't have any traffic so there has been no issue so far. But, Is this a recommended approach for a website with good amount of traffic. And if not, then how should one approach updation on the server.

答:
What many high traffic sites do is deploy using a web farm.

The general workflow is like this:

Take half of the servers off the farm

Update these servers and test

Put servers back in farm and take remaining servers off the farm

Update these servers and test

Put remaining servers back in farm

If this is no possible, I suggest creating two sites on your live server - a live site and a deployment site web applications and directories:

Deploy to the deployment site

Test

Change IIS configuration so:

The live site now points to the directory of the deployment site

The deployment site now points to the directory of the formerly live site


答:
From your question it seem like you only have one server, which begs the question "How do you test your changes?"

A better workflow would be to make the changes on your development PC and upload them to a test server first and then test the changes there. This "test server" need not be a physical server; it could be a virtual machine on your development box. The point being that changes need to be tested on some sort of webserver with the appropriate database engine or whatever your website requires. Ideally you would have some sort of automated regression and link checking etc to make sure that the changes you made did not break anything.

Once you feel happy with your changes then they would be moved to a staging site for turnover to production. The staging site should be as close to your production environment as possible. Further it should be accessible to your clients and users so that they can review and approve the changes before being placed into production.

Once everyone has had a change to review and approve the changes on the staging site the next step is to move them to the production server. Depending on the changes this might be as simple as copying files or could possibly involve schema changes to database tables etc.

The key to properly moving from the staging site to the production site is to insure:
1) You have a complete backup of the production site.
2) Have a plan to revert the changes (restore the backup files perhaps) should your changes cause a problem.

For a high volume or mission critical site you might have multiple sets of production servers with the changes moved from staging to half the servers at a time so that the website is never down. For the majority of sites scheduling 5 minutes of down time in the middle of the night to backup files and move the changes to a single production server is probably more than good enough.

Title: Better approach for updating live website on Server

Body:
I follow a very raw approach while updating my website on server. The approach I follow doesn't seem right, so I am interested in knowing a recommended way of updating a LIVE project, be it on shared host or dedicated server.

Right now, for any changes in View, I simply upload and overwrite the view files on server. Similarly for any code changes, I upload and overwrite the .dll and .pdb files. Currently my website doesn't have any traffic so there has been no issue so far. But, Is this a recommended approach for a website with good amount of traffic. And if not, then how should one approach updation on the server.


问:
Can manager classes be a sign of bad architecture?
Lately I've begun to think that having lots of manager classes in your design is a bad thing. The idea hasn't matured enough for me to make a compelling argument, but here's a few general points:

I found it's a lot harder for me to understand systems that rely heavily on "managers". This is because, in addition to the actual program components, you also have to understand how and why the manager is used.

Managers, a lot of the time, seem to be used to alleviate a problem with the design, like when the programmer couldn't find a way to make the program Just WorkTM and had to rely on manager classes to make everything operate correctly.

Of course, mangers can be good. An obvious example is an EventManager, one of my all time favorite constructs. :P My point is that managers seem to be overused a lot of the time, and for no good reason other than mask a problem with the program architecture.

Are manager classes really a sign of bad architecture?

答:
Can manager classes be a sign of bad architecture?

You answered your question : they do not have to be a sign of a bad design.

Except for the example in your question with the EventManager, there is another example : in the MVC design pattern, the presenter can be seen as a manager for the model/view classes.

However, if you misuse a concept, then it is a sign of a bad design and possibly architecture.


问:
How can I answer interview questions about developing in a team when I've always been a lone developer?
In an interview, I was asked about about my experiences in developing in team settings. However, I've been self taught and have only worked on projects on my own. How would you go about answering this question? I just brought up school clubs and how I was able to play well with others, but this isn't really developer related.</p>

答:
Bring up the most relevant experiences that you have that address the question. If you've never worked on a development team before, don't make things up. Look at other organizations, teams, and groups that you've been a part of and discuss times that you needed to collaborate with others to solve some kind of problem. You can talk about different problems that arose and how you interacted with the team to solve them.

Skills such as leadership and teamwork generally translate well between different applications. If you understand how to work well with a team in one context, it might not be a perfect fit, but you can probably adapt well to other contexts. Map various skills and abilities that you have to the context of the organization and job that you are interviewing with.


答:
Short answer: it depends.

There are several distinct forms of "manager classes", some of them are good, some others are bad, and for most of them it depends a lot on the context if introducing a manager class is the right thing. A good starting point for getting them right is to follow the single responsibility principle - if you know exactly what each of your manager class is responsible for (and what not), you will have much less problems understanding them.

Or to answer your question directly: it is not the number of manager classes indicating a bad architecture, but having too many of them with unclear responsibilities, or dealing with too many concerns.

Title: Can manager classes be a sign of bad architecture?

Body:
Lately I've begun to think that having lots of manager classes in your design is a bad thing. The idea hasn't matured enough for me to make a compelling argument, but here's a few general points:

I found it's a lot harder for me to understand systems that rely heavily on "managers". This is because, in addition to the actual program components, you also have to understand how and why the manager is used.

Managers, a lot of the time, seem to be used to alleviate a problem with the design, like when the programmer couldn't find a way to make the program Just WorkTM and had to rely on manager classes to make everything operate correctly.

Of course, mangers can be good. An obvious example is an EventManager, one of my all time favorite constructs. :P My point is that managers seem to be overused a lot of the time, and for no good reason other than mask a problem with the program architecture.

Are manager classes really a sign of bad architecture?


答:
In a code review, the source code is read by a human. This is often someone other than the original developer, but that's not a requirement. For example, the Personal Software Process enables personal code reviews guided by checklists of specific problems to identify. Alternatively, there are a number of techniques that involve other people - pair programming, over-the-shoulder checks, and formal inspections.

Regardless of the technique used, there are a number of reasons why a code review would be performed, although some techiques lend themselves better to specific purposes. For example, a large amount of code written by a new developer could be reviewed to ensure that they are following the team's conventions and are understanding the design and implementation goals of the team. Code reviews also allow for checking for logic errors and security problems. Tests can also be reviewed to ensure that the test cases correspond to requirements and that they are providing appropriate coverage.

Static analysis of code is performed by various tools scanning the source files, and in some cases, the binary files, to identify potential problems, ranging from indexing errors to unneeded assignments to security holes. These tools typically produce reports that indicate the location and severity of possible issues.

Often, static analysis and code reviews are used together to provide coverage. In my experiences, individual developers run static analysis over their own code prior to a code review. After reviewing the results of the static analysis, they correct any issues that might cause problems, then submit their code for review. By finding and correcting problems that are easily identified automatically, the human code reviewers can focus their efforts on a different subset of problems.

Title: Difference between static testing and code review

Body:
Possible Duplicate:

  What is the difference between Static code analysis and code review?

What is the difference between static testing and code review?

I found some information on wikipedia that in both cases the programmer checks the syntax and code logic for bugs.


答:
One thing I haven't yet come across any static code analysis tool which will catch is logic mistakes. For example, the code may be absolutely beautiful and perfect from every technical angle, but if a method TransferMoney() calls targetAccount.withdraw() rather than targetAccount.deposit(), that's a pretty glaring error which any half-way thorough code review is going to catch because the human doing the code review is likely better at understanding the intended semantics of the TransferMoney() method. Similar mistakes can be made in ways that are far from as obvious, particularly to the developer writing the code.

Static analysis can only figure out if the code is correct technically, it cannot do much about the business logic implemented by that code.


问:
What is the best way to handle product versioning and branching of long term projects?
In a general sense, for long term projects that may have multiple releases during the products life cycle and require support of previous products, what is the best way to handle product versions and branching of the code base?

In a more specific sense, assume that proper distributed version control is in place (i.e. git) and that the teams are small to large in size and that developer may be working on multiple projects at once. The major issue that is being faced is that there is a contractual obligation to support old versions as they existed at the time which means that new development can not patch old code (Microsoft Office products could be an example of this, you only get patches for the feature year you own).

As a result the current product versioning is a touch convoluted as each main product has multiple dependencies, each with their own versions which may change between annual releases. Likewise, while each product has its own repository, most of the work is not done on the main source trunk but rather on a branch for that years product release with a new branch being made when the product is released so that it may be supported. This in turn means that getting a product's code base isn't a simple matter as one might think when using version control.

答:
"Long term" is an indicator that you need versioning, but it does not implicate any specific versioning and branching strategy. The more interesting question is how many product lines or major version lines you want to support (which depends on the contract with your customers). You will at least need one branch for every product line / major version line for which you have a maintenance contract.

On the other hand, it depends on your team size. If you have a big development team, with different people working on different features in parallel, you will obviously need more feature branches than if you have team of one or two people. If you are working with some bigger team, you should consider using distributed version control, which makes parallel working on different branches (and reintegrating them later into the trunk) much more efficient.


答: Just tell the truth, exactly what you've told us. Being able to tell the truth instead of a perceived "right way to answer" is a sign of emotional intelligence and HR people look for that. I recently had an interview where I was asked "how well do you deal with pressure?". I simply answered that I don't know since I haven't been put in a very high pressure situation yet, and they were happy with my answer (I did get the job and their interview process was not without rigour).</p>

Title: How can I answer interview questions about developing in a team when I've always been a lone developer?

Body: In an interview, I was asked about about my experiences in developing in team settings. However, I've been self taught and have only worked on projects on my own. How would you go about answering this question? I just brought up school clubs and how I was able to play well with others, but this isn't really developer related.</p>


答:
While it might be easy to say that they are inherently indicative of a bad design, they can serve to bring a lot of good and reduce code complexity and other boilerplate code throughout the project by encompassing a single task and responsibility universally.

While the prevalence of Managers may be because of poor judgement on design, they may also be to handle the poor design decisions or incompatibility issues with other components in a componentized design or third-party UI components, or third-party webservices with a strange interface as examples.

These examples demonstrate where they are terribly useful for certain situations in reducing overall complexity and promoting loose coupling between various components and layers by encapsulating the "ugly code" in single place.  One gotcha though would be that people find it tempting to make Managers as singletons, I would advise against this, and of course as others have suggested Single Responsibility Principle should always be followed.


答:
You should always be open and honest with those that are interviewing you. Seasoned interviewers can smell smoke from a mile away.

This type of question gives you a peek inside the organization. In this case they are telling you to expect a team environment and now is the time to discuss a few points; first, do you desire to work in a team environment; second, can you work in a team environment; lastly, what have you learned from previous team experiences.

Telling them that you haven't been exposed to an environment that works in teams isn't a deal breaker and should lead to a discussion that relates to non-professional team experiences you have had, much like you told them about.

I, as others have pointed out, would say that you answered the question perfectly.


答:
I'm in agreement with the other answers as to static analysis and code reviews. I'd like to add a couple points that I feel are important to both.

For static analysis (at least for c#) there are some really nice tools (FXCop) that are able to identify implementation issue such as the disposable pattern. It's also a good tool to identify some code smells, such as coupling or cyclomatic complexity. I'm not suggesting they are perfect, but I've found a number of these useful for identifying issues.

As for code reviews, the biggest thing code reviews are used for where I work is to break down knowledge silos and teach others what is it you have written. Usually a great conversation comes from the review about how code is written, challenging others with different view points, learning new conventions, etc.

As you can see, they are very different tasks both of which have use to most developers. Computers are also really good at finding things that violate very specific rules where humans are better at the opposite.

I hope you are asking so that you can utilize both, and not to choose one over the other.


答:
The "freedom from having to worry about freeing resources" that garbage-collected languages supposedly provide is to a considerable extent an illusion. Keep adding stuff into a map without ever removing any, and you will soon understand what I am talking about.

In fact, memory leaks are quite frequent in programs written in GCed languages, because these languages tend to make the programmers lazy, and make them acquire a false sense of security that the language will always somehow (magically) take care of every object that they do not wish to have to think about anymore.

Garbage collection is simply a necessary facility for languages that have another, more noble goal: to treat everything as a pointer to an object, and at the same time hide from the programmer the fact that it is a pointer, so that the programmer cannot commit suicide by attempting pointer arithmetic and the like. Everything being an object means that GCed languages need to allocate objects far more often than non-GCed languages, which means that if they put the burden of deallocating those objects on the programmer, they would be immensely unattractive.

Also, garbage collection is useful in order to provide the programmer with the ability to write tight code, manipulating objects inside expressions, in a functional programming fashion, without having to break the expressions down into separate statements in order to provide for the deallocation of every single object that participates in the expression.

Aside from all that, please note that in the beginning of my answer I wrote "it is to a considerable extent an illusion". I did not write that it is an illusion. I did not even write that it is mostly an illusion. Garbage collection is useful in taking away from the programmer the menial task of attending to the deallocation of his objects. So, in this sense it is a productivity feature.


答:
I've never done low-level programming, so I don't know how complicated
can freeing resources get.

Funny how the definition of "low-level" changes over time.  When I was first learning to program, any language that provided a standardized heap model that makes a simple allocate/free pattern possible was considered high-level indeed.  In low-level programming, you'd have to keep track of the memory yourself, (not the allocations, but the memory locations themselves!), or write your own heap allocator if you were feeling really fancy.

Having said that, there's really nothing scary or "complicated" about it, at all.  Remember when you were a child and your mom told you to put away your toys when you're done playing with them, that she is not your maid and wasn't going to clean up your room for you?  Memory management is simply this same principle applied to code.  (GC is like having a maid who will clean up after you, but she's very lazy and slightly clueless.)  The principle of it is simple: Each variable in your code has one and only one owner, and it’s the responsibility of that owner to free the variable’s memory when it is no longer needed.  (The Single Ownership Principle)  This requires one call per allocation, and several schemes exist that automate ownership and cleanup in one way or another so you don't even have to write that call into your own code.

Garbage collection is supposed to solve two problems.  It invariably does a very bad job at one of them, and depending on the implementation may or may not do well with the other one.  The problems are memory leaks (holding on to memory after you're done with it) and dangling references (freeing memory before you're done with it.)  Let's look at both issues:

Dangling references: Discussing this one first because it's the really serious one.  You've got two pointers to the same object.  You free one of them and don't notice the other one.  Then at some later point you attempt to read (or write to or free) the second one.  Undefined behavior ensues.  If you don't notice it, you can easily corrupt your memory.  Garbage collection is supposed to make this problem impossible by ensuring that nothing is ever freed until all references to it are gone.  In a fully-managed language, this almost works, until you have to deal with external, unmanaged memory resources.  Then it's right back to square 1.  And in a non-managed language, things are trickier still.  (Poke around on Mozilla's bug-tracker for Firefox sometime and see if you can find how many different crash bugs were caused by their garbage collector screwing up and freeing things too early!)

Fortunately, dealing with this issue is basically a solved problem.  You don't need a garbage collector, you need a debugging memory manager.  I use Delphi, for example, and with a single external library and a simple compiler directive I can set the allocator to "Full Debug Mode."  This adds a negligible (less than 5%) performance overhead in return for enabling some features that keep track of used memory.  If I free an object, it fills its memory with 0x80 bytes (easily recognizable in the debugger) and if I ever attempt to call a virtual method (including the destructor) on a freed object, it notices and interrupts the program with an error box with three stack traces--when the object was created, when it was freed, and where I am now--plus some other useful information, then raises an exception. This is obviously not suitable for release builds, but it makes tracking down and fixing dangling reference issues trivial.

The second issue is memory leaks.  This is what happens when you continue to hold on to allocated memory when you no longer need it.  It can happen in any language, with or without garbage collection, and can only be fixed by writing your code right.  Garbage collection helps to mitigate one specific form of memory leak, the kind that happens when you have no valid references to a piece of memory that has not yet been freed, which means the memory stays allocated until the program ends.  Unfortunately, the only way to accomplish this in an automated manner is by turning every allocation into a memory leak!

I'm probably going to get dinged by GC proponents if I try to say something like that, so allow me to explain.  Remember that the definition of a memory leak is holding on to allocated memory when you no longer need it.  In addition to having no references to something, you can also leak memory by having an unnecessary reference to it, such as holding it in a container object when you should have freed it.  I've seen some memory leaks caused by doing this, and they are very difficult to track down whether you have a GC or not, since they involve a perfectly valid reference to the memory and there are no clear "bugs" for debugging tools to catch.  As far as I know, there is no automated tool that allows you to catch this type of memory leak.

So a garbage collector only concerns itself with the no-references variety of memory leaks, because that's the only type that can be dealt with in an automated fashion.  If it could watch all your references to everything and free every object as soon as it has zero references pointing to it, it would be perfect, at least with regards to the no-references problem.  Doing this in an automated manner is called reference counting, and it can be done in some limited situations, but it has its own issues to deal with.  (For example, object A holding a reference to object B, which holds a reference to object A. In a reference-counting scheme, neither object can be freed automatically, even when there are no external references to either A or B.)  So garbage collectors use tracing instead: Start with a set of known-good objects, find all objects that they reference, find all objects that they reference, and so on recursively until you've found everything.  Whatever does not get found in the tracing process is garbage and can be thrown away.  (Doing this successfully, of course, requires a managed language that puts certain restrictions on the type system to ensure that the tracing garbage collector can always tell the difference between a reference and some random piece of memory that happens to look like a pointer.)

There are two problems with tracing.  First, it's slow, and while it's happening the program has to be more or less paused to avoid race conditions.  This can lead to noticeable execution hiccups when the program is supposed to be interacting with a user, or bogged-down performance in a server app.  This can be mitigated by various techniques, such as breaking allocated memory up into "generations" on the principle that if an allocation doesn't get collected the first time you try, it's likely to stick around for a while.  Both the .NET framework and the JVM use generational garbage collectors.

Unfortunately, this feeds into the second problem: memory not getting freed when you're done with it.  Unless the tracing runs immediately after you finish with an object, it will stick around until the next trace, or even longer if it makes it past the first generation.  In fact, one of the best explanations of the .NET garbage collector I've seen explains that, in order to make the process as fast as possible, the GC has to defer collection for as long as it can!  So the problem of memory leaks is "solved" rather bizarrely by leaking as much memory as possible for as long as possible!  This is what I mean when I say that a GC turns every allocation into a memory leak.  In fact, there is no guarantee that any given object will ever be collected.

Why is this an issue, when the memory still gets reclaimed when needed?  For a couple of reasons.  First, imagine allocating a large object (a bitmap, for example,) that takes a significant amount of memory.  And then soon after you're done with it, you need another large object that takes the same (or close to the same) amount of memory.  Had the first object been freed, the second one can reuse its memory.  But on a garbage-collected system, you may well be still waiting for the next trace to run, and so you end up unnecessarily wasting memory for a second large object.  It's basically a race condition.

Second, holding memory unnecessarily, especially in large amounts, can cause problems in a modern multitasking system.  If you take up too much physical memory, it can cause your program or other programs to have to page (swap some of their memory out to disc) which really slows things down.  For certain systems, such as servers, paging can not only slow the system down, it can crash the whole thing if it's under load.

Like the dangling references problem, the no-references problem can be solved with a debugging memory manager.  Again, I'll mention the Full Debug Mode from Delphi's FastMM memory manager, since it's the one I'm most familiar with.  (I'm sure similar systems exist for other languages.)

When a program running under FastMM terminates, you can optionally have it report the existence of all allocations that never got freed.  Full Debug Mode takes it a step further: it can save a file to disc containing not only the type of allocation, but a stack trace from when it was allocated and other debug info, for each leaked allocation.  This makes tracking down no-references memory leaks trivial.

When you really look at it, garbage collection may or may not do well with preventing dangling references, and universally does a bad job at handling memory leaks.  Its one virtue, in fact, is not the garbage collection itself, but a side-effect: it provides an automated way to perform heap compaction.  This can prevent an arcane problem (memory exhaustion through heap fragmentation) that can kill programs that run continually for a long time and have a high degree of memory churn, and heap compaction is pretty much impossible without garbage collection.  However, any good memory allocator these days uses buckets to minimize fragmentation, which means that fragmentation only truly becomes a problem in extreme circumstances.  For a program in which heap fragmentation is likely to be a problem, it's advisable to use a compacting garbage collector.  But IMO in any other case, the use of garbage collection is premature optimization, and better solutions exist to the problems that it "solves."

ContentLicense: CC BY-SA 4.0


答:
Garbage collector does not address any "bugs". It is a neccessary part of some high level languages semantics. With a GC it is possible to define higher levels of abstractions, such as lexical closures and alike, whereas with a manual memory management those abstractions will be leaky, unnecessarily bound to the lower levels of the resource management.

A "single ownership principle", mentioned in the comments, is quite a good example of such a leaky abstraction. A developer should not be concerned at all about the number of links to any particular elementary data structure instance, otherwise any piece of code would not be generic and transparent without a huge number of additional (not directly visible in the code itself) limitations and requirements. Such a code cannot be composed into a higher level code, which is an intolerable breach of the layers of responsibility separation principle (a major building block of the software engineering, unfortunately not respected at all by most of the low level developers).


答:
Managers can be a sign of a bad architecture, but more often than not they are just a sign of an inability on behalf of the designer to come up with better names for his objects, or simply just a reflection of the fact that the English language (and any human language for that matter) is suitable for communicating every-day practical concepts, and not highly abstract, highly technical concepts.

A simple example to illustrate my point: before the Factory Pattern was named, people were using it, but they did not know how to call it. So, someone who had to write a factory for his Foo class may have called it FooAllocationManager. That's not bad design, that's just lack of imagination.

And then someone needs to implement a class which maintains lots of factories and hands them out to various objects that ask for them; and he calls his class FactoryManager because the word Industry just never occurred to him, or he thought it would be uncool because he never before heard of something like that in programming. Again, a case of lack of imagination.


答:
Since many of these answers seem to focus on biggish teams, even from the outset, I am going to put my view as part of a two-man development team (three if you include the designer) for a startup.

Obviously, simple designs and solutions are best, but when you have the guy that literally pays your salary breathing down your neck, you don't necessarily have time to think about the most elegant, simple and maintainable solution. With that in mind, my first big point is:

Documentation Not comments, code should be mostly self documenting, but things like design documents, class hierarchies and dependencies, architectural paradigms, etc. Anything that helps a new, or even existing, programmer to understand the code base. Also, documenting those odd pseudo-libraries that pop-up eventually, like "add this class to an element for this functionality" can help, since it also prevents people from re-writing functionality.

However, even if you do have a severe time limit, I find that another good thing to keep in mind is:

Avoid hacks and quick fixes. Unless the quick fix is the actual fix, it is always better to figure out the underlying problem to something, and then fix that. Unless you literally have a "get this working in the next 2 minutes, or you're fired" scenario, doing the fix now is a better idea, because you aren't going to fix the code later, you're just going to move onto the next task you have.

And my personal favorite tip is more of a quote, though I cannot remember the source:

"Code as if the person that comes after you is a homicidal psychopath that knows where you live"

Title: How to keep a big and complex software product maintainable over the years?

Body:
I have been working as a software developer for many years now. It has been my experience that projects get more complex and unmaintainable as more developers get involved in the development of the product.

It seems that software at a certain stage of development has the tendency to get "hackier" and "hackier" especially when none of the team members that defined the architecture work at the company any more.

I find it frustrating that a developer who has to change something has a hard time getting the big picture of the architecture. Therefore, there is a tendency to fix problems or make changes in a way that works against the original architecture. The result is code that gets more and more complex and even harder to understand.

Is there any helpful advice on how to keep source code really maintainable over the years?


问:
Intellectual Property cost
If a piece of bespoke software was developed by a company and the Intellectual Property was retained by the company that wrote it, but now the client of the software company wants to get that source code (and its IP) how much should it cost them? How would you calculate a fair cost for the purchase of that source and IP?

UPDATE: Just to add, the software in question is of no use to anyone else (for any legitimate purpose) as it ties in directly with the business processes of one company. It is not something that can be subsequently sub-licensed or installed outside the company in question. There are links of to third party services (but these were existing services that the bespoke software had to integrate with in the first place).

答:
I doubt you can put a hard equation down for this one, it's very subjective. I guess some important things to consider would be:

How much of the software was custom built for them? If this number is high, you've probably billed them nearly the worth of the binaries + source.

Are others using this? Would your company losing the ownership of the IP potentially upset anyone else?

I'd also put a higher price on handing over the IP than I would on the source code.

Title: Intellectual Property cost


答: Let them know that working on your own wasn't just by choice and that you are interested in working within a team. Be upfront about what you see as the good and the bad. I think he biggest concern is are you going to get along with others. Some programmers don't and prefer to work alone.</p>


答:
Telling the truth is the best option, and saying what you've said isn't a bad thing to do.  But think about what the truth really is -- think about analogous situations and talk about those, and think about what you know about your deficiencies and talk about those. Not all companies will care about your well-thought-out and reasoned answer that really says "I have no experience in that" but many will.

I used to teach a course in university that was primarily about communicating the skills of a new graduate (in business and engineering fields, typically) to the HR folks who would be looking at their resume and trying to decide to hire them or not.  What I would tell students is that everything counts when you're entry level or junior level.  If your only teamwork experience is a year of working with three people on a senior project, in whatever field it may be, talk about it: what you did, what you learned, and how that matches up with what they're asking.  When we practiced mock interview questions, I stressed that the answer is often not nearly as important as how you got to the answer.

So, think about your answers without worrying that they're not developer related, if you don't have experience like that, and worry about how they could be -- more specifically, how you could be the developer that they want.  That will mean answering honestly and showing what you might perceive to be a shortcoming, but if you add to it a thoughtful sentence or two about how you see yourself in the future, fitting in on a team, playing nice with others, working in an Agile (or other development methodology) environment, that will be to your benefit.


答:
Be honest about your weaknesses. When asked go into detail about how you intend to improve on those weakenesses (in your case working more as a team).

A candidate who has apraised himself, identified his weaknesses and is actively working to improve on them is often better than somone who dosent have any weaknesses (ie they do but just dont know them).


答:
Manager classes can be a sign of a bad architecture, for a few reasons:

Meaningless Identifiers

The name FooManager says nothing about what the class actually does, except that it somehow involves Foo instances. Giving the class a more meaningful name elucidates its true purpose, which will likely lead to refactoring.

Fractional Responsibilities

According to the single responsibility principle, each code unit should serve exactly one purpose. With a manager, you may be artificially dividing that responsibility.

Consider a ResourceManager that coordinates lifetimes of, and access to, Resource instances. An application has a single ResourceManager through which it acquires Resource instances. In this case there is no real reason why the function of a ResourceManager instance cannot be served by static methods in the Resource class.

Unstructured Abstraction

Often a manager is introduced to abstract away underlying problems with the objects it manages. This is why managers lend themselves to abuse as band-aids for poorly designed systems. Abstraction is a good way to simplify a complex system, but the name “manager” offers no clue as to the structure of the abstraction it represents. Is it really a factory, or a proxy, or something else?

Of course, managers can be used for more than just evil, for the same reasons. An EventManager—which is really a Dispatcher—queues events from sources and dispatches them to interested targets. In this case it makes sense to separate out the responsibility of receiving and sending events, because an individual Event is just a message with no notion of provenance or destination.

We write a Dispatcher of Event instances for essentially the same reason we write a GarbageCollector or a Factory:

A manager knows what its payload shouldn’t need to know.

That, I think, is the best justification there is for creating a managerlike class. When you have some “payload” object that behaves like a value, it should be as stupid as possible so that the overall system remains flexible. To provide meaning to individual instances, you create a manager that coordinates those instances in a meaningful way. In any other situation, managers are unnecessary.


问:
How to incrementally update a database when deploying a website?
We use JSF over Tomcat along with a backing proprietary DB.

I want to know how the addition of new database fields or/and stored procedures should be handled when we deploy a new version of the application.

We deploy by sending a WAR file to the hosting Team, as such our WAR should be able to
setup the stored procedure when it starts.

What are the possible appropriate strategies to be able to incrementally update the database?

答:
I usually have db changes deployed outside the main application, usually via a script that is executed by the DBA.

I suppose you could do the changes from inside your application, if your application has permission to modify the database structure. I guess what would have to happen is your application would start up, some new procedure would run at startup, make all the necessary database changes and then probably restart. The trick is to make sure the changes only happen once. This could probably be done by checking a version number in a special table and using that to decide if the database should be modified.

It also adds db maintenance activities to the main application, which IMO is not a good idea because the application is probably designed to do something else (bloggin, banking, medical health records, online hotel reservations, etc...). Sometimes you may want to keep your database deployments completely separate from the core application.

From a technical point of view, it's quite possible to do this. Should it be done? That's a different question.


问:
How to react to wrong/not answered questions during interview?
Today I have held my first interview with potential interns.
While this has been mostly open questions, I have had some trivial programming tasks for them:

Write a function that returns true if triangle sides (all integers) a, b and c can represent a right triangle.

FizzBuzz.

Calculate the Nth element of Fibonacci using recursion (if they didn't know what Fibonacci was, I would even write them the definition F(n) = F(n-1) + F(n-2); F(1) = 1; F(0) = 1).

Implement structure List for integer and write function to reverse it.

These are obviously very easy tasks and I was not prepared for someone not to solve them.

How should I act when they struggle with these questions? Should I give up the answer? Give tip by tip (I did that and ended up solving the problem myself)? Or just move on (or maybe just stop) with the interview?

ps. By having problems with questions, I don't mean like having a bug, I mean if they can't even get started. This was a case with Fibonacci and List questions.

答:
It depends on the calibre of the position you are trying to fill.

If you are going for a senior developer, then I would expect them to know all of that. If they got it wrong and I was feeling evil, I would just stop the interview, thankyou and good bye. If I was in a more polite mood, I would just thank them and rush through the rest of the interview.

If I was going for a junior developer, then those questions could be considered quite tough. I would be more interested in exploring their ability and willingness to learn. So I would try giving them hints and guide them along and see how they respond.


答:
Fizzbuzz is an absolute requirement. If they can't code Fizzbuzz, you shouldn't hire them.

I typically ask the candidate for a pre-interview code session, where we use Google Docs to work through a programming problem (typically Fizzbuzz + a higher level problem if they can easily complete Fizzbuzz).

I'm typically on the phone or on skype with them during this, and since I'm watching them complete the problem (and talking to them about what they're thinking at certain points), I can be reasonably confident that they didn't just google the answer.

As long as your other problems are specified well (that is, you give them the formula for each), then your questions are just fine.

When I interview candidates, I try to stick to programming problems that they're likely to encounter. I love string manipulation problems because when you're on the web, just about everything user facing has to do with some sort of string manipulation.  How they handle that is important.

Title: How to react to wrong/not answered questions during interview?

Body:
Today I have held my first interview with potential interns.
While this has been mostly open questions, I have had some trivial programming tasks for them:

Write a function that returns true if triangle sides (all integers) a, b and c can represent a right triangle.

FizzBuzz.

Calculate the Nth element of Fibonacci using recursion (if they didn't know what Fibonacci was, I would even write them the definition F(n) = F(n-1) + F(n-2); F(1) = 1; F(0) = 1).

Implement structure List for integer and write function to reverse it.

These are obviously very easy tasks and I was not prepared for someone not to solve them.

How should I act when they struggle with these questions? Should I give up the answer? Give tip by tip (I did that and ended up solving the problem myself)? Or just move on (or maybe just stop) with the interview?

ps. By having problems with questions, I don't mean like having a bug, I mean if they can't even get started. This was a case with Fibonacci and List questions.


答:
The point of giving questions like this in an interview is to determine whether someone can figure out how to solve problems.  The job of being a programmer generally consists of two things:  "Take these requirements and implement them in code" and "figure out why the implementation isn't matching the requirements and fix it."  So what you're really looking for is not a solution to these specific questions, but the ability to figure things out.

Understanding this, I would give a hint or two to get someone started, and maybe some more if it's clear that they're making real progress but missing a detail somewhere.  But if it becomes clear that they just can't figure out how to solve the problem, then you have your answer and there's no need to continue with the exercise.

To give an example, when I interviewed at my current job, I was given a question about finding the shortest path from one node to another on a graph.  I replied that I'd likely use something like Dijkstra's Algorithm, which I vaguely remembered having learned about one day back in college and had never used since, and gave a quick (and incorrect) explanation of it that satisfied the specific conditions given by the question.  The interviewer pointed out that my solution would end up in an infinite loop if the graph was modified slightly, and that jogged my memory, so I explained the right way to avoid this problem.  And I ended up getting the job.


答:
IMHO your first two questions should be solvable to anyone calling him/herself a programmer, be it junior or senior, straight out of school or self-taught.

If I see that the interviewer is struggling with either of these, I would try to rephrase the problem, and check whether (s)he fully understood it. Then encourage her to use pen and paper, whiteboard, draw figures or whatever approach she prefers to tackle the problem. I also ask her to think aloud, to get a view into her thought process and if needed, give little hints if she is on the right track just doesn't dare to advance, or has some obstacle. But if even several hints don't help, or - as you mentioned above - I end up solving the problem for her, I would probably finish the interview to stop more wasting of our time. In an interview, I am always striving to see and focus on what the candidate knows, instead of what she doesn't, but if I can't seem to find any significant knowledge, I give up after a while.

The 3rd and 4th ones are somewhat more difficult, so I could accept if a junior couldn't get them, if (s)he otherwise demonstrated a good problem solving approach and enthusiasm. But for a senior, they are still a must.


问:
What should be the Roadmap for JAVA EE
I have done Java SE and want to start JAVA EE. But i am very confused, from where i have to start .So please tell me the roadmap from where to start Java EE ?</p>

答:
Java EE is a huge umbrella of APIs to build scalable and distributed applications.

You may not need to touch subjects like EJB, JMS, JCA (Java Connector API) at this moment.

I think the most important part that you need to study now is Java Servlets and JSP (doing Java web development).

You really need to know how to build web applications by using raw Servlets and JSPs before adopting a web framework like SpringMVC, Grails, Play! ...

I heartily recommend Head First Servlets and JSP, 2nd Edition.

Also have a look at The Java EE 5 Tutorial to see what Java EE offers in general.

Title: What should be the Roadmap for JAVA EE


答:
I agree with @FrustratedWithFormsDesigner in that it is quite possible, AND that the script for updating your database structure should not be brought along with your application code. Because of this your application would require other permissions allowing to create tables, alter tables, etc. which you most probably don't need during the "normal" usage of your application. So, in terms of security, not a good thing, since your application should only have the permissions needed to work properly.

Anyway, back to the main point. It is quite possible to properly do that by creating a special table in your database, let's say X_VERSION, in which you will simply have the current version of the database schema (it may be a timestamp too).
Whenever you alter your database schema, you put that change into a SQL script named [Timestamp-XXX-WhateverItIsYouAreDoing.sql], where:

Timestamp is the timestamp, for example 20110111-165500

XXX is a number, which will be useful later to know the order of execution of the scripts

Whatever, etc. is some text that will help you remember what you do in that script

Whether your database updating program is in your application or outside does not matter for the following steps; whenever you deliver a new version of your application, your update program should do this:

Look up the current timestamp in X_VERSION

Check all the scripts that must be executed between the version found in X_VERSION and the new version

Loop over the scripts, and for each script

Execute the script updating your database/schema

Update the timestamp in X_VERSION to the timestamp of the executed script

When all scripts are done, you know your application can safely start.

Bonus:
If you want to have a safe way to go back to a previous version, whenever you create a script altering your database, always create somewhere a script that will allow you to go back to the previous version. It may sometimes be a bit hard (like removing a column for example, not all DBMS allow this), but always try. You will then be prepared to revert to a previous version if necessary.

Title: How to incrementally update a database when deploying a website?

Body:
We use JSF over Tomcat along with a backing proprietary DB.

I want to know how the addition of new database fields or/and stored procedures should be handled when we deploy a new version of the application.

We deploy by sending a WAR file to the hosting Team, as such our WAR should be able to
setup the stored procedure when it starts.

What are the possible appropriate strategies to be able to incrementally update the database?


答:
for intern positions you might be asking a bit much.

I have no idea what you even mean by the 4th question. as for asking a recursion question, its a bit impractical, go through your own code base and determine the number of areas recursion is used, I'm willing to bet that its few-none. Interview situations are stressful, and expecting candidates to implement rarely used strategies that are backwards compared to most things you will ever program is unfair to them, especially towards the beginning of an interview.
Personally I would be asking questions where they have to explain what important concepts mean/ how they are used, providing canned examples. I would be much more interested in candidates that can tell you X book or Google Y search will provide everything needed to implement something to your code base.


答:
My goal for any job interview, no matter which side I'm on, is to end up feeling like I'm talking to a colleague.  Colleagues come into my office all the time when they're stuck on a problem.  I ask my colleagues for help when I get stuck myself.  So in an interview, I try to recreate that dynamic.

In other words, what would you say if a colleague needed to implement a fibonacci sequence and didn't know what it was?  You would explain it to them until they grasp it enough to continue on their own.  There's no shame in ignorance as long as it's not permanent.

If you go through that exercise and still can't picture yourself working with that person, then they're not a good fit for the job.


答:
Do I have to know about Escher and Bach?

Not at all! The book introduces some of their work to illustrate some concepts, so you'll learn enough about them by the way.

Title: "Gödel, Escher, Bach" still valid today?

Body:
I have just completed a course on computability and logic which was an interesting course. The lecturer recommend a few books on his slides, which include "Gödel, Escher, Bach". I can see the book is quite famous, and looks very interesting. But I have a few questions to ask regarding its content.

Is the content still valid today? I guess most theoretical stuff doesn't change over night, but are there any major points which no longer hold today that I should be aware of?

I assume we actually HAVE made some progress in the last 30 years or so. Can any of you recommend a book on the subject which includes this progress (logic, AI, computability)?

Another question: Do I have to know about Escher and Bach?


答:
Intern interviews are a different breed of interview. What I typically do is use my standard developer questions (like the ones you provided) to gauge where they are at in their education. The ability to solve these problems will vary greatly from sophomores to seniors.

After I have that information, I then focus the interview on other skills such as, will they be able to work on a team, are they teachable, will they benefit from interning at our company, are they passionate about development / learning, etc.

To me, it's the non technical things that really set an intern apart from the other candidates. I would much rather spend a few months coaching / mentoring somebody that is driven to learn and grow, than somebody that just wants a job for the semester.


问:
Data Serialization to process business logic
Going by the general principle of data abstraction, I normally abstract data in a serialized format(JSON) and pass it as a parameter to the Business Logic(BL) modules such that the BL module always see a consistent format of the data irrespective of the underlying data storage layer. Even if I use a ORM, I use the serialized format of that ORM. I feel I have the following advantages.

By serializing data, there would be better control over data and parameters

Any developer can write BL without thinking too much about the underlying data storage

Wrappers can be written for new databases (There are a lot of ready-made wrappers to convert data into JSON)

Testing could be done ruthlessly and without a database (since the data format is serialized)

Functionally easier to understand and better OLAP, OLTP integration

I also notice the following drawbacks

A new layer to be added between the database and the BL module (most ORM's nowadays come with a predetermined JSON format)

Extra function calls slow down the application (but I think this trade-off is OK when compared to better testing and easy maintenance)

Increased level of abstractions may confuse the developer

I make the above observations mostly in the context of business applications
To follow this discussion, lets have an example so that things could be discussed in its context.
Assume a product database having the columns: Product,Rate,Taxes and we need to create a invoice

Code without database abstraction

```<code>GET rate,taxes for product X from database
multiply qty with rate and add taxes
display invoice
</code>```

Code with database abstraction

```<code>  GET rate,taxes for product X from database
  Convert it into JSON
  call create_invoice function //This does all the calculations
  display invoice
</code>```

In the second example, I would pass arguments in the form (Product=X, Qty=5, Rate=5, Taxes=0.05). If taxes are to be split into more that one category (State Tax=0.03, Central Tax=0.02) or a discount factor to be added  I would just increase the number of parameters in the BL functions such that the database fields, the JSON keys and the function parameters match (this is done automatically during serialization and most ORM's do it). This makes it easy, in my approach, to extend functions and also make modules independent of data since the modules always know the data they can receive and even if they receive a new parameter, they can adapt it provide the underlying code is intelligent.

My general questions are

Is this a good pattern and what's it called (Data abstraction comes to my mind)?

Pros/Cons of this pattern(apart from those mentioned above) in the context of business application, apps for embedded devices, big data

Is there a difference between this pattern and ORM (I believe so since ORM is mostly a class wrapper to get data from a database while this pattern is more oriented towards data structure)

If this is good, can this be easily understood by a new developer?

答:
Usually, i work in languages/environment which is are closer to systems compared to example here so my answer could be slightly biased. However, there is an interesting concept/pattern i have found with many good designers.

Usually, in order to foster the code to be reused - certain things needs to be generalized. Classic examples of generalization are text books examples of inheritance; and one realize that once a generic API for a class of objects it helps evolve systems. We all know that it is good to abstract out common versus specific functionality in such manner.

However, i have seen this with many designers that sometimes they try and do super generalization. One of the example i saw is a a classic C++ application. Instead of generalizing by keeping most common parameters specific to an abstract(virtual) function, the code does super generalization by passing parameters as arbitrary list of name-value-pairs. Now any function/method can be generalized trivially if all relevant arguments/parameters are serialized and passed to function and de-serialized in processing it.

But such a super generalization is very bad. Not only that it adds overhead of adding serialization/deserialization process -but more importantly the semantics are lost.  Now the callee function can put in arbitrary parameters and the whole thing begins to get misused way beyond context. You also run into un-handled, misspelled parameters, out-of-context parameters and so on; all this because there is no way to control what sort of parameters can go in.

As a thumb rule, i would always be worried of super generalizations and be rather simple.

NOTE: The pattern you described above is NOT ORM. In ORM, you generally treat a DB record with equivalent Object which has same attribute. The JSON based representation still requires translation to native object before use.


答:
My answer may seem a bit unkind or dismissive, but I think it works well. To begin with, I give the candidate a question that is very easy, which serves as a warm up question to help build their confidence. Whether or not they succeed, I move onto a question that is less trivial, and directly related to what the job entails.

At this point, it's all or nothing. If they sail through it, great, no problem. If they struggle a bit, no prob, I'll help prod them along and then move onto other questions to guage other abilities.

If, however, they utterly lack the ability to solve it, I go ahead and burn the rest of the interview time helping them along. The candidate still feels engaged in the interview, but I don't have to steer the interview in different, irrelevant directions. It's good for the candidate, too, since it may be educational.


问:
Resources on learning to program in machine code?
I'm a student, fresh into programming and loving it, from Java to C++ and down to C. I moved backwards to the barebones and thought to go further down to Assembly.

But, to my surprise, a lot of people said it's not as fast as C and there is no use. They suggested learning either how to program a kernel or writing a C compiler. My dream is to learn to program in binary (machine code) or maybe program bare metal (program micro-controller physically) or write bios or boot loaders or something of that nature.

The only possible thing I heard after so much research is that a hex editor is the closest thing to machine language I could find in this age and era. Are there other things I'm unaware of? Are there any resources to learn to program in machine code? Preferably on a 8-bit micro-controller/microprocessor.

This question is similar to mine, but I'm interested in practical learning first and then understanding the theory.

答:
I strongly suggest that you reconsider your goal and here's why:

I first learned 6502 Assembly Language on the BBC Microcomputer (Model B, 32K). It had an awesome BASIC implementation that included a macro assembler. We had them at school so I wrote all sorts of mischievous programs that would do things like direct screen buffer manipulation to make a Lemming walk across each screen, around the room (they were networked) if the machines hadn't been used for 10 minutes. It resulted in fits of giggles among my Year 7 friends.

When I got a Commodore 64 at home, I learned that it had a 6510 CPU which also ran 6502 assembly language but with some interesting extras. I had to buy an assembler (came on a cartridge) and invoke the programs via BASIC. With grand visions of writing a best-selling game, I eventually managed to create several demos that bit-twiddled video display hardware registers on interrupt to do interesting colour bar effects that animated to funky chip music. Impressive, but not that useful.

I then got an Acorn Archimedes A310 which had an ARM2 CPU so I used the same awesome BASIC implementation with built-in macro assembler as the BBC Micro (same heritage). I managed to put together a couple of games which an arty friend provided graphics for, plus some sinusoid-based trippy demos. Both of these were hard work to program and bad code could take down the machine (accidentally trip hardware reset register, etc), losing everything if I hadn't saved (to floppy!).

At University I was introduced to C++ and thus C. I was able to use it to program Sun/Solaris and some other large mainframe computers. I have no idea what CPU architectures these machines ran on - I never needed to use assembler or read machine code as the C++ tools gave me the power I needed to produce professional applications.

After Uni, I worked on Windows and several flavours of Unix. C and C++ worked on all these machines and eventually Java did too.

I then worked on Windows and Dreamcast using C++ with DirectX with comprehensive tool chain for debugging.

I then took a job working with ARM-based chipsets for Smart TVs (in 2000). Although my experience with ARM2 may have been relevant here, the job was C based. I found that all the poking about with hardware that I'd done on the Archimedes could also be done in C using straightforward bit-twiddling operations. Part of my role was to migrate the code base to Windows, Playstation 2, Linux, other TV and mobile chipsets. All of these platforms were available with both a C compiler (often GCC) and some level of API to write to the underlying machine - the embedded world is rarely a kernel O/S. I didn't ever need to know the full machine code for any particular platform beyond writing a boot loader and mini-BIOS, both of which jumped into C code at the first available opportunity (after setting up trap vectors, ensuring endian-ness and instruction-mode and establishing a stack).

The next job was working with C++, C# and JavaScript on Windows. No machine code.

The current job is working with C++, JavaScript, Python, LUA, HTML and other languages on various platforms. I've no idea what machine code these platforms run, nor do I need to know - the compiler translates our code into whatever it needs to be. If it crashes, I catch the error in a debugger or through runtime diagnostics (exceptions, signals, etc).

For fun, I develop iOS applications on the little spare time I have at home. It uses Objective-C and an API that works across multiple chipsets. Apparently they're ARM-based, but I've never seen any machine code in my development.

While its' a fascinating exercise to learn assembly language, there are now much higher-level tools and languages that allow you to be an order-of-magnitude (or two) more productive.

The number of job opportunities available to an amazing assembly language/machine code programmer are miniscule compared to something like JavaScript, Java, C#, C++ or ObjC.

I'd advise you make this a hobby/side-interest rather than a main goal.


答:
You said that you are interviewing for intern positions in the question so this is from that standpoint, for full time developers the bar is going to be a bit higher.

When you are interviewing interns you have to remember that they may not have completed their studies and that they may have also entered into college without any previous background in programming and computer science. As such, you need to scale expectations to what you can reasonably expect someone to know and to the degree of prestige of the position (i.e. Google can get away with expectations that a company people haven't heard of can).

Looking through the questions that you presented I would likely view them as follows in an interview:

1) Write a function that returns true if triangle sides (all integers) a, b and c can represent a right triangle.

Basic application of geometry with simple coding, most students should be able to do this without much difficulty. At most a reminder of the Pythagorean Theorem might be needed if they are showing a bit of stress because of being in an interview. This could almost be seen as a "ego boost" problem in that it can help settle some people if they are very nervous going into the interview.

2) FizzBuzz

Again, another application of some basic control statements. Students that haven't been exposed to the modulus operator, or haven't used it much, might need to be reminded of it, but shouldn't encounter any real problems solving the problem.

3) Calculate the Nth element of Fibonacci using recursion (if they didn't
  know what Fibonacci was, I would even write them the definition F(n) =
  F(n-1) + F(n-2); F(1) = 1; F(0) = 1).

This tends to be a fairly common problem so most (if not all) students will see it at some point prior to graduation. The catch is that it usually shows up when recursion is presented to the students as it lends itself well or a recursive or loop based solution which can then be compared so students from different schools might see it at different times depending upon the sequence of courses. In practice, if someone couldn't come up with the recursive I'd ask for an alternative using loops and if they couldn't come up with that I would be more concerned at their potential ability.

4) Implement structure List for integer and write function to reverse it.

This question might actually be a bit too open-ended as it is written so it could also be a good question to see how the candidate seeks additional information (e.g. should delete functions be included, conversion to arrays, etc), but given a well defined problem statement ("Implement a basic list structure for integers that allows for numbers to be added to the end or at an arbitrary index, deleted, and include a function to return a reversed copy of the list") students should be able to solve the problem as long as lists are a common structure presented either in an early data structures course, or in an early basic computer science course.

In terms of dealing with the candidates, if they are struggling, make sure they are relaxed and allow them a bit of leniency as they might just be having performance anxiety as this might be their first real interview. Tips on solving the problems might be required, most so in the case of the third and fourth problems as opposed to the first two.

Also, structure the overall interview process so that there are "graceful exit" points built in. For example you might have the following agenda:

Meet and greet, interview procedures.

Short interview with staff programmer(s), basic questions about background.

Presentation of programming quiz.

Break

Return from break, dismissal of some candidates that aren't a good fit.

Extended interview with staff programmer(s).

Interview with human resources (if required).

Wrap up.

This interview flow tends to work well if you want to be able to dismiss candidates early as they know from the beginning that they might be dismissed after the break. The short interview before the quiz also means that they aren't just showing up to take the test which gets them some interview practice and may also allow them to decide that they aren't a good fit. If there are other programmers observing the quiz or assisting the candidate during it then it also gives them a chance to pass/fail the candidate while they are taking a short break.

At all time when you are interviewing for an internship and the candidates are students you must remember that they are still students and may not have much practice with interviews (leading to possible performance anxiety) and may also have not reached the point in their studies to even be able to answer the questions which means it might be a good idea to send them on their way with a copy of the "ideal solution(s)" to the problems they are given as well.


问:
Staying alert and awake while coding
What methods do you use to stay awake and alert while working?

Personally I drink coffee non stop throughout the day.  But I've also heard of this thing called exercise that should help too.  Does anyone else have tips and tricks to stay more awake and alert while working?  Redbull? Maybe a magic pill that won't require me to sleep?

答: Sleep well in home. That's it</p>

Title: Staying alert and awake while coding

Body: Sleep well in home. That's it


问:
Core competencies for software developers in the financial sector?
I have an interview coming up for a company operating in the financial markets. Other than generic skills like OOD, refactoring, testing and so on, what are the core areas that a financial software developer specifically needs? </p>

<p>I can think of some obvious ones like rounding modes, differences between floating point data types etc. What other areas should I be brushing up on?  </p>

答:
Professional Attitude
Understand how the business generates money and how you (will) contribute to that. On the scale of "1 - sticking plaster over the problems" to "10 - (re-)write it from scratch", be aware that you need to be comfortable operating at the low end. Understand that Project X needs to be delivered to paying customer Y by date Z. If you've got to work evenings/weekends, hire contractors or cut features to ensure delivery that yields payment, you'll have to do it (or at least convince them you would).

Handling Financial Information
As others have noted, "Security" (authorization / authentication) around what users can or can't see/gain access to, Compliance with legislation (no naked short selling, etc), Accuracy with calculations (understanding limits of numerical representation) and being able to explain your workings to anyone who asks.

Working with Scale
Financial institutions usually run a 24x7 operation on a global basis. There will be load-balancing, redundancy, caching, logging/monitoring, SLAs and likely an army of sysadmins and DBAs keeping things running. If you're happy to deploy fresh code worldwide in one step with no back-out plan, best to keep your resume up to date as that is a recipe for disaster.

Motivated
Some of the systems you'll work on will be rather dull compared to e.g. iOS apps. You need to be motivated to succeed with relatively small projects and deliver them successfully before you'll be allowed onto bigger things. The monetary rewards will surely motivate you at bonus time, but you need to keep this momentum throughout the year.


答:
If you really got a potential intern who acts like a deer in the headlight because he's never been interviewed, has anxiety issues, has never been in a real life situation like that (you usually notice from their body language), you can just start by asking them what they've worked on last.

Then it'll be his territory so he might not be crazily nervous. When you find an appropriate place ask, "Hey, how did you implement that?". If he can explain, it might give you some insight into his way of thinking.

Put your own tests on the agenda after that.