问:
What can you do to decrease the number of deployment bugs of a live website?
I'm sure lots of you have experienced this problem. A website or web application is running and is live. You want to upload the next version, but you haven't figured out everything, like setting a value to false in configuration file, inserting another record into the database, and doing lots of minor stuff which can sometimes count to 20 or more parameters.

As soon as you upload the new version, everything breaks. Now, fixing the problem may only take up to 20 minutes, but the overall stress that you tolerate, and the financial and goodwill damage to the company are sometimes not forgettable.

What are the ways to reduce these types of bugs which arise from the initial configuration of new version deployment?

PS: Please don't mention check-lists, cause we already have them. The problem with check-lists is that, they should always get updated, but they won't.

答:
Many answers here already tell you how to implement your specific solution to the problem, but, as far as I can tell, the real problem isn't one of properly migrating/updating a website. It may be that the design/architecture behind it is fragile.

If that's true, you'll have to adjust the architecture for your system such that it is robust enough to continue functioning properly even if configuration settings change or are not properly set, and such that it degrades gracefully if they occur. Ideally, if you've added in new functionality or changed old functionality in ways that require a new database column, your site will work even if the column is missing (maybe without the new functionality, or with a degraded form of the old functionality). Your client should not be losing money - at worst, he might not be getting new money from the improvements you've put in.

If your system is fragile enough that configuration settings can cause such serious problems, program updates are not going to be the only sources for problems - and figuring out how to do the updates safely will only increase the damage you'll experience when failure comes from a different source.


问:
Best book, articles and literature on unit testing
In my battle to introduce unit testing in my workgroup, I find a lot of people that have little to none knowledge of the concept. Can you suggest:

best articles or tutorials for quickly introducing people on the topic

best comprehensive book(s) for learning unit testing in depth

academic works and studies that prove the effectiveness of unit testing

答: Growing Object-Oriented Software, Guided by Tests was quite an eye-opener, the why, and the how all clearly laid-out on a book-long example.</p>

ContentLicense: CC BY-SA 2.5


问:
What are some good Photo and Artwork APIs?
We had an idea for starting a ecards service and were looking into the possibility of populating our site using photo/artwork APIs.  Due to legal reasons, Flikr probably won't work, although I've started to scour the web for other options.

Basically we just need two functions

the user should be able to browse the site's collection and choose a picture

we should be able to recall and render a specific picture on our site.  From there we should have no problem building our application.  The main obstacle is that we're lacking content at the moment.

I haven't been able to find too many examples of this being done, so I was wondering if anyone here might know people who have done something similar to what we're trying to do, or know of any leads that might be able to help us out.  Suggestions for other APIs that are out there, or forums/communities that might be able to point us in the right direction are also welcome.

答:
What you're looking for probably doesn't exist. Your best bet is to find a method which automates users' import of their own images, and allowing them to migrate them from other sites. For example, a user might log on to your site and ask you to import their images from Flickr, explicitly giving you permission to use them as you see fit in the process.

Otherwise, you might want to look into stock photo companies, which can provide you access to large numbers of photos at a price - though, I think you'll have a hard time convincing them to let you compete with their business model.

ContentLicense: CC BY-SA 3.0


问:
Did eastern PKUFFT algorithm beat FFTW3 (Fastest FFT on the west) 20 fold?
I wonder if PKUFFT is Chinese algorithm/library and is it really better than FFTW, MKL?

Edit: I will elaborate. My personal programmers interest is in fast parallel algorithms like FFTW3, which was my favorite until I stumbled upon chinese claim of superior run with PKUFFT. It is on google, if you search for FFTW3, Intel MKL, GPU and things. I don't know anything about this library, but I would be very interested to learn.

I can guess PKU stands for Peking Univ. There is nothing on web except presentation and mentioning of some commonly available hardware (GPU, infiniband, etc.). Everything, including compilers was available for years. The improvement of 2000% is significant. The news are 1 year old. But no details about algorithm itself.

It will be interesting to know if there is genuine discovery in algebra, or just technical effect with unfair advantage of knowing specific platform better than competing teams.

答:
It looks like the benefit comes from a better use of underlying architecture (and the improvement is in the 20-25x range). They figured out a better way to, in general, take advantage of parallel GPU/CPU architectures, reducing the overhead for the parallelized algorithm.

This is not an improvement in the underlying algorithm for FFT. This is an improvement in the general application of heavy math algorithms to many-core/multi-core architectures.

The technique continues to improve, with innovative optimizations. See http://www.springer.com/us/book/9783642164040 for more info


问:
Is it possible to take a binary compiled for ARMv7 architecture and convert it to ARMv6?
Is it possible to take a binary compiled for ARMv7 architecture and convert it to ARMv6 ?
Are there any tools that can do this?</p>

答: In theory, yes, it is possible. No, there are no tools that can do this, and, in general, it is not recommended. The overhead, performance hit, and human effort required doesn't match the potential reward.</p>


问:
How can we design mobile chatting XMPP server
I have a xmpp server design problem, I have been thinking and searching about this for a while, but cannot reach a decision, I hope experts here can give me a hint, really appreciate.

<Requirement>

   Build a mobile chatting server, this server should allow:

1. Register new user

2. upload user photos

3. edit their personal information.

4. User can chat with each other.

5. Release API and allow android or IOS to use.

6. Should be extensible, should allow us to add new features later without too much structure change.

<My question>

I know there is OpenFire open source xmpp server that we can use, but these two are standalone servers, they don't allow user to upload pictures, edit their own personal information, or some other activities.

So how can achieve this? Can we create all the add-on features on Tomcat server, and make Openfire working with it together?
Or can we create Plugin in openfire to achieve this? What is the best solution?

答: The XMPP portions of the work can be handled by something like ejabberd. The rest of the work is up to you to implement, as a web-application of your choice (the choice is fairly unlimited, there are XMPP tools, sample components and related libraries in most if not all the popular web-app frameworks). </p>


问:
I use an IDE (Eclipse) to develop software.  Why should I switch to vim or emacs?
My day job is  java/web developer. I have been using eclipse for ~5years. I think its excellent and I also use Webstorm for javascript and html/jsp.

I do on occasion need to ssh into server and mess around with config files; for this I use vi and it pains me. I have to get up a webpage listing the syntax/commands : press escape, then asterix, turn around three times and the text will be entered two lines above your cursor. Its so unintuitive to me, and I imagine anyone who grew up in the late eighties nineties.

Here are the main reasons I think eclipse is brilliant(and I assume other IDE's), and do not switch to emacs and/or vim.

Error highlighting with no need to
recompile project.

Code assist.

Refactoring.

Opening call hiearchy/Opening
declaration.

Fully integrated with source control.

Debugger is included.

availablity of 3rd party plugins - eg
findbugs/checkstyle.

One of the arguments I hear is that with emacs/vim you can create your own plugins - well OK, but you can do that in eclipse too. But you don't need to as everything is already there!  Its like saying buy this half built car, you can build the rest yourself.

Why are people using emacs/vim ? Do people who use it actually work on complex object-oriented projects in large organisations ?

What are the reasons to switch to vim/emacs. How would my productivity increase if I did switch?

答:
Personally both programs drive me up the wall.  The problem with Eclipse is that its slow as snot when you're working on a large project and that's when its not doing 'DGLP Indexing' or whatever.  want to refresh your repository? got 15 minutes?  Oh and how about that nifty trick where you Ctrl-C some text then Ctrl-P it somewhere but instead of it going where you wanted it to it opens a completely different file and pasts over something else and you're left wondering wtf was there in the first place.  Oh and did i mention working with eclipse on a large project over a vpn? practically impossible.

As for vim, its nice and fast assuming you know the multitude of completely senseless key combinations to make it do something and good luck if you find yourself in some unknown mode by accident.  Also with vim you pretty much have to know your entire projects directory structure in your head in order to open the correct files.  Vim's main advantage is that in theory you can create code faster because its all keys, but in reality i don't care how much text i'm writing, it not the volume of text that matters its the quality of the code and often quality code requires staring at dozens of files for hours on end until you figure out the exact right thing to type (which is usually very short).

What i wish is that someone would write a command line program, like vim, that actually has a directory structure like eclipse on the side or something that you could expand/collapse and open files from.  Does anybody know anything like this?


答:
If you aren't happy with VIM or EMACS, you could look on that machine for other text editors.  There might be some flavor of nedit or gedit or somesuch that you can use which will have more familiar commands (ctrl x,c,v and s do what you'd expect for example).

You probably have more than two choices on your distro, it is worth it to take a look.

Title: I use an IDE (Eclipse) to develop software.  Why should I switch to vim or emacs?

Body:
My day job is  java/web developer. I have been using eclipse for ~5years. I think its excellent and I also use Webstorm for javascript and html/jsp.

I do on occasion need to ssh into server and mess around with config files; for this I use vi and it pains me. I have to get up a webpage listing the syntax/commands : press escape, then asterix, turn around three times and the text will be entered two lines above your cursor. Its so unintuitive to me, and I imagine anyone who grew up in the late eighties nineties.

Here are the main reasons I think eclipse is brilliant(and I assume other IDE's), and do not switch to emacs and/or vim.

Error highlighting with no need to
recompile project.

Code assist.

Refactoring.

Opening call hiearchy/Opening
declaration.

Fully integrated with source control.

Debugger is included.

availablity of 3rd party plugins - eg
findbugs/checkstyle.

One of the arguments I hear is that with emacs/vim you can create your own plugins - well OK, but you can do that in eclipse too. But you don't need to as everything is already there!  Its like saying buy this half built car, you can build the rest yourself.

Why are people using emacs/vim ? Do people who use it actually work on complex object-oriented projects in large organisations ?

What are the reasons to switch to vim/emacs. How would my productivity increase if I did switch?


问:
Application development practices in a non-software company
Let me preface this by apologizing if this has been covered elsewhere, but I was unable to find sufficient information in my searching.

Background information

I work at a non-software company developing desktop applications in a team of four members, where I have been employed for more than 18 months. Being my first job out of college, I was unsure what kind of development environment to expect. What I found was transition of applications developed in a legacy language being rewritten in an OO language.

The problem

On our development, we have no guidance, practices, etc for how we plan (if any planning is done at all), code, and deploy our applications. As you can imagine, such a policy (or lack there-of) has bred pure chaos for managing applications, with often times each developer creating his/her own way of handling situations. In other words, LOTS of repetition. I have come to understand why I am the third new hire they have had in three years (other two left after one year).

Allow me to list off other issues:

No unit testing. The only type of "testing" that is done is handing
it over to the user and asking if this is what they wanted. Half the
time the user doesn't have time to check it and just starts using it
to produce their analysis data.

No database. We have several, several thousands of records and
information that are stored over a multitude of CSV files.

No documentation. This speaks for itself. No user requirements.
No explanation for how to make the program work. Nothing.

No bug tracking at all.

No version control.

Overwhelming number of applications. We have well over 150+ small applications. Many of which no one knows what they even do or how they work. The development policy is each time the user needs a new report, create a brand new program with just one button. Push they button and magically on a network share in a folder, several reports in notepad are created.

And many more issues...

So... what are you asking us?

Ah, now we get to the real reason for all of this. I have been tasked by my manager to propose suggestions and guidelines for our development team. Mind you, I am not optimistic that anyone will actually heed them, but I have to propose them none-the-less. Most of the suggestions I have found are for software companies. I have been informed by other people at my company that such practices would be "overkill" at our work.

What are some practices that application developers at a non-IT company follow?

Thank you for your time.

答:
Suggestions:

pass the Joel test. That will take care of most of your issues (as a note -- passing does not mean you have to have everything checked, but if you have a score lower than, say, 80%, you should consider the test failed).

If you don't think that you can accomplish #1, pass the Joel test anyway. Trust me, it is just better that way. (The second rule of <s>fight club</s> being a developer...)

Completely reject the idea that you are "not a software company." Is your department building software? Then for all <s>intensive porpoises</s> intents and purposes, you should behave as if the product is the output application. No exceptions, no excuses -- if you are building software, then you are building software.

The number of times when software development best practices are not the best idea are extremely rare. For example: Unit tests are best unless all your application is doing is printing "Hello world". Even then, you should have verified integration testing and QA.

Read The Mythical Man Month. If you can get your boss to read it, get him to. If not, at least do him the favor of saying, "Hey, I just came across a really awesome book, let me tell you about it."

Some rules which I have found which should be immediately applied:

No code goes into production which is not in version control. The build must be made from the centralized repository.

No untested code in production. No exceptions. If you're thinking about making an exception, hit yourself. (Don't know about the rest of the world, but I have been really burned by this).

Redundant knowledge is cheap. Redundant work is expensive -- make sure that there are at least two people who are at least reasonably up to date on a given project (the person working on it, and someone else. If using pair programming, then that should be sufficient). This way, if someone goes on vacation to Mount McKinley or some other far off location, there will be a way to cover until that person returns. (Or worse, calling someone on vacation (Calling someone on vacation, by the by, surefire way to annoy them)).

No undocumented code -- all public methods must have at least one line describing what they do, even if it is felt that the name is "self-documenting".

Any person who is currently working on code which should go into production, should be subject to code review. This is especially true for the people who believe that they do not need code review.

Finally remember the acronyms which should be looked for in said code reviews: DRY, KISS, YAGNI, etc.

For your own sanity, remember PEBKAC, but don't tell others.


问:
Have objects delivered in terms of code reuse?
I have often heard it said that objects have not delivered in terms of code reuse. Do you agree? If you believe that they haven't, why not?</p>

答:
No, "objects" haven't made code re-use any easier or more common. The same concerns that prevent code from being re-used in a modular program (designing, testing and documenting a general-purpose API requires considerably more up-front effort than writing a one-off routine, and the jack of all trades may be the master of none - logic intended to be re-used may not be well optimized for the uses it is actually put towards) apply to OO programs, with the added concern that a poorly-designed object model can hamper the re-use of otherwise reusable code.

OO is a handy abstraction for a good many problems, but be wary of '80s-'90s hype: it doesn't magically solve the fundamental problems of our trade any more than it makes waffles for you while you sleep.


答:
Suggestions

Change Architecture

From a maintenance standpoint web based solutions are much easier to manage because you control the code on the backend.  You don't have to support multiple versions of an app, and you can more easily manage releases and distribute fixes.  Again, that is all because you control the backend.

Pick your battles

You are a software company because you make software.  That being said, you may need to pick your battles when it comes to process change.  Make a few changes, document the benefits that they yield, and then propose more.  Too much change at the same time(even if it's all for the better) can be disastrous and may make the company less willing to change.  Gradual change is much easier to accept, especially if you build up a track record of successes.

The basics

Revision control system, bug tracking (I suggest Redmine), these are the absolute basics for development.  These should be easy to push through because it's about organizing and protecting the companies assets.

Get buy in from your fellow developers

Your doomed to failure unless you get your fellow developers to buy in to changing your process.

Later on

Automated tests, continuous integration, database usage, consolidation of functionality into libraries, etc.

Title: Application development practices in a non-software company

Body:
Let me preface this by apologizing if this has been covered elsewhere, but I was unable to find sufficient information in my searching.

Background information

I work at a non-software company developing desktop applications in a team of four members, where I have been employed for more than 18 months. Being my first job out of college, I was unsure what kind of development environment to expect. What I found was transition of applications developed in a legacy language being rewritten in an OO language.

The problem

On our development, we have no guidance, practices, etc for how we plan (if any planning is done at all), code, and deploy our applications. As you can imagine, such a policy (or lack there-of) has bred pure chaos for managing applications, with often times each developer creating his/her own way of handling situations. In other words, LOTS of repetition. I have come to understand why I am the third new hire they have had in three years (other two left after one year).

Allow me to list off other issues:

No unit testing. The only type of "testing" that is done is handing
it over to the user and asking if this is what they wanted. Half the
time the user doesn't have time to check it and just starts using it
to produce their analysis data.

No database. We have several, several thousands of records and
information that are stored over a multitude of CSV files.

No documentation. This speaks for itself. No user requirements.
No explanation for how to make the program work. Nothing.

No bug tracking at all.

No version control.

Overwhelming number of applications. We have well over 150+ small applications. Many of which no one knows what they even do or how they work. The development policy is each time the user needs a new report, create a brand new program with just one button. Push they button and magically on a network share in a folder, several reports in notepad are created.

And many more issues...

So... what are you asking us?

Ah, now we get to the real reason for all of this. I have been tasked by my manager to propose suggestions and guidelines for our development team. Mind you, I am not optimistic that anyone will actually heed them, but I have to propose them none-the-less. Most of the suggestions I have found are for software companies. I have been informed by other people at my company that such practices would be "overkill" at our work.

What are some practices that application developers at a non-IT company follow?

Thank you for your time.


答:
I am very much an Emacs guy.  I use it for all my programming, and actively encourage my co-workers to use it, too (and they actively ignore me).  I find it far more productive than any IDE, and I would never change.

Unless I am writing Java or C# (and I imagine there's other languages in this category).  They have such large libraries of stuff with long names, that the gains I get from using Emacs are completely lost in trying to remember everything.

I certainly encourage you to try vim and/or Emacs.  But you're likely going to end up back in Eclipse for Java.


答:
It appears you know pretty well what the issues are, the problem is getting solutions accepted.  The processes that you have found for software development for an IT company apply to anyone trying to write good software.  The software can't tell if you are an IT company (if it can - you're definitely an IT company).

Ask if the current process is producing the results they want - if they are OK with having analysis reports that may or may not be accurate custom produced from scratch every time with no ability to support them or reuse the code or the data for future requests, then your current "process" (or nearly any process) is fine.

If any of these things are considered problems, then doing the things you have to do fix them is by definition not overkill.


问:
Is this agile? Scrum? How to improve agility?
Is this agile?  Scrum?  Any suggestions on how this can be made more agile under the circumstances?  Which points are positives and which can be improved?

The product is developed for a customer who will re-sell it while paying us royalty.

The team does not get to talk directly to the end user.  Only to the reseller.

A product requirements document was created before starting development.

The requirements are rigid and do not change.

A delivery schedule was agreed on with milestones such as "alpha", "beta" etc. and features/times attached to those milestones.

All developers on the Scrum team report to the product owner, a software manager.

Testers on the team report to a QA manager.

The product owner has directed the team towards certain high risk technical tasks.  The output of those tasks is not usable by the end user but rather some technology/code that will eventually be used in the product.

The product owner has created a backlog based on the requirements.

The product owner is unable to answer some questions regarding the product.  He refers to others or to the documented requirements.

The team goes through the motions of Scrum.  Daily Scrum, Sprint Planning, Retrospective etc.  There is a ScrumMaster.

Every sprint the product owner and management decide what backlog items the team works on.

There is a burndown chart.  Scrum board with stories and tasks.  The estimates on those come from the team.

The team sits in an open floor "bull pen" shared with other teams, all visible and audible.  There is cross-team noise and there is foot traffic around the team area.

The team may be required to attend various meetings not directly related to the goals of the sprint.

There are pressures to select certain technical solutions.  Some tools and processes are mandated.

答:
A product requirements document was created before starting development. And then you build the project using Scrum and Sprints.

It is an iterative and incremental development and not really agile.

Quite a few of so called scrum projects have a requirements document (PRD) written first and also UI design done upfront, though they do not have rigid requirements.

At minimum for Agile, in addition to what you are doing, in sprint end demo Product owner, customers and team should give feedback and PO should have ability to change requirements based on that feedback. Additionally, team should be self organizing.


问:
Is there a correlation between code complexity and developer productivity?
Is the time spent refactoring a code base worth it in the long run, in terms of developer productivity?

It seems pretty clear to me that modifying a clean, well designed system is much simpler and faster than working on a poorly designed one, but I'm after some solid evidence. Are there any studies around this topic?

答:
Empirically, software with higher complexity metrics, such as cyclomatic complexity, are harder to maintain. There is research supporting this dating back to the 1970s ("Program Complexity and Programmer Productivity", E.T. Chen). There is also work that suggests that complexity density, which is cyclomatic complexity over size of the system also relates to maintenance time ("Cyclomatic complexity density and software maintenance productivity", G.K. Gill, C.F. Kemerer), which is also available for free here. Unfortunately, an IEEE subscription is necessary to Chen's paper, but you can try to look it up on other sources if you're interested.

From a quality perspective, it's often worth it to spend some time refactoring, assuming you have a test framework in place to prevent the introduction of new defects. This will allow you to more easily implement new features to your system, add additional tests, and train new developers to work.

Ultimately, however, there is the pressure to deliver new functionality and added value. You need to balance refactoring with the implementation of new functionality and repair of defects.

ContentLicense: CC BY-SA 4.0


问:
Does it make sense to compute cyclomatic complexity/lines of code ratio?
In general, maintainability index relies on many factors. For example, in Visual Studio, it rely on cyclomatic complexity, depth of inheritance, class coupling and lines of code; those four values must be as low as possible.

At the same time, I've never seen, neither in code metrics tools, nor in books, the comparison between only cyclomatic complexity (CC) and lines of code (LC).

Does it make sense to compute such ratio? What information does it give about the code? In other words, is it better to decrease more the CC than the LC to have a lower ratio?

What I notice is that for small projects, the ratio CC/LC is low (⅓ and lower). In other words, LC is high, and CC is low. In large projects, CC/LC is in most cases bigger than ½. Why?

答: There is a metric of cyclomatic complexity per source statements - it's called cyclomatic complexity density. This metric can be used to estimate the maintenance time and effort required for software projects.</p>


问:
N queens, X by Y board decision problem interview question
I was asked the following question in an interview today and I've been thinking about it ever since. I was not able to answer it and haven't been able to find a solution online.

Given a chess board with dimensions X by Y and N queens, determine whether it is possible to arrange these queens on the board such that they cannot attack each other.

A 2 x 3 board with 2 queens does have a solution so the algorithm would return true:

```<code>Q . .
. . Q
</code>```

I'm looking for a programming approach to this puzzle, not just ways to solve it on paper, for example.

答:
This is more of a comment really, but it doesn't fit in there ...

A chess board has 8x8 squares, no more no less (these questions always annoy me with that approach of a customized chess board).

But anyways, if you have an x*y chess board, and n queens and taking that the queen "takes" these fields

could you just create a two dimensional array and "flag" all fields that one queen attacks. Then place the other one (from the middle of the board), flag the remaining fields, and so on ... until you run either of fields or queens.

This is of course a very simplified approach, since if positioned in a bad manner, I gather the maximum number of queens would vary.

Hmm, just found this as well - 8 queens problem.


问:
Forgetting stuff I've done before and how do you fix this
I'm not sure if it's just me or if this is common in our field.

The past year has been a bit intense for me. I've been learning a few different technologies to get some tasks done and sometimes I've had to completely focus on that one new technology I'm learning.

What I noticed though when I go back to using everything together in the full project is that I forgot how to do things that I already knew how to do before I started focusing on learning that other new technology. Sometimes I find that I forget even simple things like the syntax for selecting a div in jquery, that I have to go back to old files to get a quick peek.

Sometimes I could be coding something that I recognize I did before in another project, but can't quite remember which project it was for, so I have to go through several projects and look through the code to try and remember where I did that.

What ways have you invented to prevent yourself from forgetting things you've done before, or to easily access code you've written in the past?

答:
I can assure you it seems to get worse as you get older :-) But that's because the longer you're into developing, the more knowledge there is to forget.

On the other hand, you gain more "intuition". You recognize patterns, how to solve certain problems, and other things you've learned in older projects with different languages and environments and can make use of them even though the current conditions are different. I mean, I constantly look back at code I wrote just a year ago and think, "Today I would write it differently" and even quite often "Today I know how to solve this one better".

So, even though you might forget a lot of stuff like method and class names for a certain API, your skills normally improve on a higher level.


问:
Computer Science and other advance topics taught in javascript
I'm an 'okay' Javascript developer working on browser javascript and node.js. However because I'm self taught, starting from copying and pasting jquery, there are a lot of holes in my programming/CS education.

I don't really have the time to devote myself to fully learning all the CS concepts that might be taught in a real college program, and learning C or Scala or whatnot, I'm just too addicted to hacking and making things that work. On some level studying CS seems to be 'premature scaling' in Hacker News parlance.

But every so often I get struck by the thought that maybe there is something that I should really really learn to take my skills and productivity to the next level.

Is there a book, a list of concepts or things that I can study and learn in my 'down time' that would see reasonable returns on my productivity and ability in 1 - 2 months?

Thanks!

And yes, the only language I know and use is Javascript, though I have tinkered with Python (High School), Ruby (RoR), PHP (Drupal), and Assembly (Making Diablo 2 Mods) in the past.

Please note that a book like O'Reilly's JavaScript Web Applications is too easy for me and not really what I'm talking about.

答:
I did go through the hoops of learning in the official channels and at first it did make me jump a bit when you brushed aside this education as superfluous.  However I do also agree with you that over design is just as bad as under design, worst in a sense as it may convince people that designing may not be so good after-all.

Programming is not about languages or principles, it`s about structuring an idea, yours, or even harder, someone else's into a formal executable form.  The methods that will most help you do this are not found in APIs or libraries though if you scratch the surface and see beyond the methods and objects you will recognize some of these methodologies.  It is what makes the difference between an API that is easy to learn, obvious to use and hard to get wrong.  After a short while you should be able to just guess without looking at the proper syntax and if the API is well designed you should be pretty close to what is actually needed.

That said, if I were to give you simple advices to make you a better Javascript programmer it would be this :

Get Crockford`s (+1 for Zachary) material about the language.  It is by far the best I have found and the only one that guides you towards doing it right.  Most likely the inspiration of all the good Javascript that appeared in the past years.  Look around the website, there is plenty of video material as well which fits pretty good for a educational transit if you have the privilege to travel by bus or metro to work.  This point alone will give you the significant returns you seek.

Read about SOLID.  Then get back to Crockford's material, you will recognize a lot of that in his speech and in his comments about the language.  You are a pragmatic guy so at first this stuff will seem a bit alien and too abstract for you, still, your perseverance will be richly rewarded as the principles sink in over time.  I am still learning a lot around this (15 yr since graduation) and every time a new principle sinks in my code makes a big leap in quality making me overall more productive.  Don't expect it to all come to you like an epiphany so do come back to it every few months as your understanding grows.

learn another language.  it will help you career wise but also will be a source of teachings.  Just to see how a different language implements the same ideas will give you a better grasp on these ideas.  that said, for your profile I'm not sure that gearing yourself towards the Java or C# would be advisable.  When used to the freedom of a language like Javascript, even after following Crockford's castrations, Java or C# will feel like a prison to you.  I see that you have had some contact with Python, you can dig further in the subject or you can pick up on another language.  Scala, F# are a bit harder but will give you more insight in some of the capabilities of javascript. Groovy, Ruby should also fit your profile fairly well and give you a good return on investment.  I must say however that Python is and remains one of my favourite languages (I am fairly proficient on a bout 12-15 languages).

Hope that helped, best of luck in your learnings.


问:
How would you quantify quality?
What should be the core functions of games which represents an excellent game? What quality goals it should achieve to become successful game?

Any concise formed answer will get me on track.

答:
This is an insanely difficult question to answer and unfortunately I don't have an answer for you (but this is longer than a comment, thus posting as an answer).

AFAIK, there are no metrics concerning methods to quantify the fun factor in a game during the design and implementation phase. Otherwise, you wouldn't have bombs and metacritic wouldn't be overly useful.

It's fairly easy to find out whether or not a game is fun after having played it: If you want to play it again, then you've achieved your goal. Having said that, even this metric is entirely subjective, so you'd need to focus test it against a broad audience before knowing whether or not you've achieved your goal.

My suggestion?

Find games that you enjoy playing (preferably ones that are popular and perhaps have a high'ish metacritic rating (although that's not always the end-all-and-be-all of how fun a game is)) and "borrow" ideas from it. Play others and "borrow" ideas from them. Throw together a design for a game and talk to a few people about it. Get their opinion.

If you have the time after that, throw together a prototype. Have some of your friends try it. Get feedback and use it. Then, look at implementing the real thing.

Title: How would you quantify quality?


问:
Examples of composition in software engineering?
In programming, various terms like abstraction are mentioned quite heavily. What, however, is composition? What is a basic but effective example of composition at play to result in good quality code (good quality meaning easy to understand, short and concise, etc).</p>

答:
In OO, there are at least these meanings of Composition in addition to what was mentioned before:

1-Composition of different data types in a class represents a new type.

Class Household
{
public car myCar;
public oven myOven;
public tv myTv;
}

2-Composition as a type of association between 2 objects
composition in UML is reppresented using the "has a" association label and is represented by black-filled diamond shape.
See:

http://www.publicjoe.f9.co.uk/csharp/tut/csharp04m.html

http://en.wikipedia.org/wiki/Object_composition

3-Inner classes represent a type of composition. In C#.Net you can have 1 class code file having more than 1 class definition inside it.

In Entity Relationship Modeling, composition is implemented by including the primary key of the parent table as part of the key of the primary key of the child table and establishing a constraint such that when the parent is deleted, all children are deleted.

This representation, toget*strong text*her with composition in object association results in lif-time strong bond between components so that no one can live (or have a business meaning) without the other. A good example may be an invoice that is composed of header and detail lines. The detail lines by themselves are meaningless without the header information and vice verse.

OwnerDisplayName: dotnetdev


答:
This isn't (IMO) a very interesting problem from a programming point of view. You could come up with a recursive algorithm that tries every arrangement, something like this:

```<code>bool try_queens(Board board, int n)
{
    if (n == 0) {
        // no queens left to place, so we're done
        return true
    }
    // try each open position until we find one that works
    for each position on the board {
        if (is_empty(board, position) and not is_attacked(board, position)) {
            place_queen(board, position)
            if (try_queens(board, n-1)) {
                return true
            }
            remove_queen(board, position)
        }
    }
    // if we get this far, there's no available position
    return false
}

main()
{
    initialize board(X,Y)
    return try_queens(board, N)
}
</code>```

If you think about the problem a bit, you'll realize that there's no way to fit N queens on a board where X < N or Y < N because that would require that at least two queens end up in the same rank or file, and they would therefore attack each other. If you read about the n-queens problem, you'll quickly learn that it's always possible to place N queens on a NxN board for N > 3. Now we know that the answer is NO for (X < N or Y < N) and YES for (X >= N and Y >= N, N > 3). All that's left are the special cases:

N=1 (YES)

N=2 (YES for X>=2 and Y>2 or vice versa)

N=3 (YES for X>=3 and Y>3 or vice versa)

So now our nice recursive function becomes a simple function that just compares N to X and Y and returns a canned result. That's great from a performance point of view, since you can get an answer in constant time. It's not so great from a programming point of view because you realize, at this point, that the question is really more about how well you can solve puzzles than it is about your ability to write a recursive function.

(And boy oh boy, I really hope that I didn't make some dumb mistake in my smarty-pants answer. ;-)

Title: N queens, X by Y board decision problem interview question

Body:
I was asked the following question in an interview today and I've been thinking about it ever since. I was not able to answer it and haven't been able to find a solution online.

Given a chess board with dimensions X by Y and N queens, determine whether it is possible to arrange these queens on the board such that they cannot attack each other.

A 2 x 3 board with 2 queens does have a solution so the algorithm would return true:

```<code>Q . .
. . Q
</code>```

I'm looking for a programming approach to this puzzle, not just ways to solve it on paper, for example.

Body:
This isn't (IMO) a very interesting problem from a programming point of view. You could come up with a recursive algorithm that tries every arrangement, something like this:

bool try_queens(Board board, int n)
{
    if (n == 0) {
        // no queens left to place, so we're done
        return true
    }
    // try each open position until we find one that works
    for each position on the board {
        if (is_empty(board, position) and not is_attacked(board, position)) {
            place_queen(board, position)
            if (try_queens(board, n-1)) {
                return true
            }
            remove_queen(board, position)
        }
    }
    // if we get this far, there's no available position
    return false
}

main()
{
    initialize board(X,Y)
    return try_queens(board, N)
}

If you think about the problem a bit, you'll realize that there's no way to fit N queens on a board where X < N or Y < N because that would require that at least two queens end up in the same rank or file, and they would therefore attack each other. If you read about the n-queens problem, you'll quickly learn that it's always possible to place N queens on a NxN board for N > 3. Now we know that the answer is NO for (X < N or Y < N) and YES for (X >= N and Y >= N, N > 3). All that's left are the special cases:

N=1 (YES)

N=2 (YES for X>=2 and Y>2 or vice versa)

N=3 (YES for X>=3 and Y>3 or vice versa)

So now our nice recursive function becomes a simple function that just compares N to X and Y and returns a canned result. That's great from a performance point of view, since you can get an answer in constant time. It's not so great from a programming point of view because you realize, at this point, that the question is really more about how well you can solve puzzles than it is about your ability to write a recursive function.

(And boy oh boy, I really hope that I didn't make some dumb mistake in my smarty-pants answer. ;-)


问:
How can I advocate unit testing on private code?
I'm trying to advocate unit testing in my workgroup, but an objection I often get is that it should be used only for externally exported API (which is only a minimal and non critical part of our system), and not on internal and private code (which now has only functional testing).

While I think that unit test can and should be applied to all the code, how can I persuade my coworkers?

答:
here's another reason: in the hypothetical case I would have to choose between unit testing the external API vs the private parts, I'd choose the private parts.

If every private part is covered by a test, the API consisting of these private parts should be covered for almost 100% as well, excpt for just the upper layer. But that is likely to be a thin layer.

On the other hand when only testing the API it can be really hard to fully cover all possible code paths.


答:
If the interviewer had asked you to write the code for the problem, then I think that it is not fair. The algorithm requires work. However, if the idea was to show the interviewer the classes, methods or some concepts that you'd need to use or something similar, then it may be a fair question.

The problem is a classical Computer Science problem and is discussed in many such books.
An excellent explanation, with animation and 12 different solutions together with some code could be found here:

http://en.wikipedia.org/wiki/Eight_queens_puzzle

Also code can be found here:
http://www.codeproject.com/KB/java/EightQueen.aspx

Don't feel bad about this, as I said, it is not an easy one.


问:
Legal issues with an NDA that I do not want to sign
I've been given a non-disclosure agreement (NDA) to sign by my current employer that I do not want to sign.  It is incredibly open ended and I feel that it should have been a condition of my initial employment agreement, which I signed three weeks ago.

The document contains very many definitions in the form of "including but not limited to," and "directly or indirectly."

As well, it states that:

I agree that any breach of the contract would inflict irreparable harm on the company (I agree that a breach may result in harm to the company but not necessarily irreparable harm).

Should the document be amended any time in the future and I refuse to sign the amendment that I would be in violation of its terms.

Everything I develop while under the company's employment is its property (neglecting to say whether what I develop on my own time, distinctly from my work, is my own).

After my employment ends at the company I would be required to continue my duties there to assist in the perfection of its software, that I would not be allowed to perform any duties directly or indirectly related to my duties there for one year after my employment at the company ends (would I not be allowed to engineer software for a year?).

Should the company decide to prosecute me for breach of contract that I agree not to defend myself, and that all terms in the document would be transferred to any company which purchases the one I work for without my consent.

In short, they would legally own me for life and could absolutely destroy me for any reason they deemed fit.

Are there any legal arguments that I could use to defend myself against signing the contract?  For example, the fact that the NDA was not part of my initial employment agreement or that the document is intentionally abstract and vague to allow them to fill in the blanks any way they please?

The company hosts the entirety of its source code on a site which employs a publicly accessible SCM and greatly embraces open source software — the chances that I would ever come in contact with information that could legally be considered a "trade secret" or "confidential information" is very slim, so why would I need to sign the NDA?  I do not believe that many of the employees there actually took the time to understand the NDA before they signed it, and know for a fact that a few of them did not.

Are the terms of this agreement commonplace among the software engineering community?

答:
First, I am not a lawyer, so do not take this as legal advice:

If you want help understanding what it means, hire a lawyer. Plenty of lawyers will let you pay for an hour or two of their time to understand the ramifications of this NDA. Don't ask the company, as they are not impartial.

Second, you can't "defend" yourself in the way that you described it. Most programmers work under "at will" employment. You can leave at any time and they can fire you at any time. If you don't like the terms, say "no" and find a different job.

If you come to the conclusion that the NDA is a deal killer, go ahead and negotiate with the company (if you were going to leave anyway, what's the worst they can say?)

It is good you took the time to read it. For definitive answers, consult a lawyer (as opposed to, say, an online Q&A website).


答:
The clauses you mention come from several different standard contracts.

An NDA basically covers "anything we tell you, you can't tell to anyone else, no matter what".  There are some standard exceptions to this (which should be explicitly listed in the NDA).  These standard exceptions are:

Publicly available knowledge from some other source.

Things that you have learned independently from some other source.

Anything the company gives you permission in writing to talk about.

The NDA covers things such as company secrets, know-how, source code, and other bits of knowledge.  And a company absolutely can suffer irreparable harm if some of these things are made public.  No company will employ you without having you sign one, and you generally won't be able to negotiate any of the points on this -- your choices will probably be to either sign it, or not work for the company.

Now, you bring up a few other clauses, notably an Intellectual Property Assignment device, which assigns rights to what you develop to the company.  Most (but not all) companies include a clause in that which states "which relates to the business of the Company".  If that's there, and your home project doesn't have anything to do with the work done by the company, then you're pretty much okay.  If not, then you may be able to negotiate to amend the contract;  companies are usually far more willing to amend this part of the contract, than the NDA.  (I've had success at modifying exactly this clause at my last two workplaces).   But do be aware that this isn't a cut and dry issue.  Lots more insightful commentary on the ownership of side-projects here: If I'm working at a company, do they have intellectual property rights to the stuff I do in my spare time?

Finally, you mention a non-compete clause, with a one-year duration.  This is a standard clause, but with an absurdly long duration -- more usually it's a one or two month duration, but asking for a year is completely abusive.  You should definitely not sign the contract in that form.  Further discussion on this issue here:  http://www.joelonsoftware.com/articles/fog0000000071.html

To directly answer your question:  Yes, these terms are very common within the software engineering community.  Though all the clauses you mentioned are standard, some of them of them sound a bit more severe than usual.  The important thing is to be aware that a contract is a meeting of minds and a negotiation.  You don't have to sign something if you're not happy with it, and you can absolutely propose alterations to the contract before you sign it.

Title: Legal issues with an NDA that I do not want to sign

Body:
I've been given a non-disclosure agreement (NDA) to sign by my current employer that I do not want to sign.  It is incredibly open ended and I feel that it should have been a condition of my initial employment agreement, which I signed three weeks ago.

The document contains very many definitions in the form of "including but not limited to," and "directly or indirectly."

As well, it states that:

I agree that any breach of the contract would inflict irreparable harm on the company (I agree that a breach may result in harm to the company but not necessarily irreparable harm).

Should the document be amended any time in the future and I refuse to sign the amendment that I would be in violation of its terms.

Everything I develop while under the company's employment is its property (neglecting to say whether what I develop on my own time, distinctly from my work, is my own).

After my employment ends at the company I would be required to continue my duties there to assist in the perfection of its software, that I would not be allowed to perform any duties directly or indirectly related to my duties there for one year after my employment at the company ends (would I not be allowed to engineer software for a year?).

Should the company decide to prosecute me for breach of contract that I agree not to defend myself, and that all terms in the document would be transferred to any company which purchases the one I work for without my consent.

In short, they would legally own me for life and could absolutely destroy me for any reason they deemed fit.

Are there any legal arguments that I could use to defend myself against signing the contract?  For example, the fact that the NDA was not part of my initial employment agreement or that the document is intentionally abstract and vague to allow them to fill in the blanks any way they please?

The company hosts the entirety of its source code on a site which employs a publicly accessible SCM and greatly embraces open source software — the chances that I would ever come in contact with information that could legally be considered a "trade secret" or "confidential information" is very slim, so why would I need to sign the NDA?  I do not believe that many of the employees there actually took the time to understand the NDA before they signed it, and know for a fact that a few of them did not.

Are the terms of this agreement commonplace among the software engineering community?


问:
Explicit or implicit looping?
Why or when is "explicit" preferred when implicit solutions often are more readable and less code? It says "explicit is better than implicit" when for example an implicit loop is better than an explicit loop isn't it?

```<code>for every in all:
  every.updated = True
</code>```

The above looks implicit to me and better than an explicit counter since a counter is another thing that can go wrong and why not leave to the compiler or other environment instead of requirement an explicit counter variable:

```<code>  for(int i=0, i<a.length, i++)
...
</code>```

And there are languages where all looping is "implicit" - what does it mean and when is it preferred? And not explicitly setting a value to nullor None or likewise seems better to me and I want to rewrite code when I "solve" a requirement by explicitly setting return null or String name = null since I think being explicit about what should be null and None should have a more clear solution such as only use a variable if it's needed and if I write return null somewhere I'm probably doing it wrong. When I was writing Java I found myself writing return null and declaring values as null at some places and I didn't like it and could rewrite it even though the case where I put return null was reached only in case of error.

I asked the guru at work whether we ever should declare a variable to null, isn't defaults much better?

I'd be glad to know your thoughts about this. An example where it is better to be explicit I can think of is declaring a list and explicitly declaring what type is in the list is better than just a list of objects e.g. it's preferred to declare ArrayList<ArrayList> instead of just an ArrayList if we know that it's a list of lists.

答: In Java the enhanced for loop, for each syntax, has a performance impact.  Typically returning a null value is a poor practice at best.  You generally want to return an object created using the default constructor instead.  This prevents run time exceptions involving null references.  There are instances where you may want to return null though, for example when trying to create a file.</p>

OwnerDisplayName: Niklas R

Title: Explicit or implicit looping?


答:
I would tell them that you can't sign that without legal counsel, and as you didn't know they would be asking you to sign anything additional, they should cover your legal costs. Explain that you simply can't sign something that complicated without an expert to advise you.

If they refuse, don't sign it. If they cover your legal costs, let your attorney hash it out with their attorneys at their expense on both sides.

That type of agreement is commonplace. But the particular terms of your agreement are very one-sided.

If things get ugly, hire a lawyer yourself. He can explain to your employer that by springing this on you after they claim to have employed you and refusing to negotiate in good faith, they have breached the implied covenant of good faith and fair dealing in your employment contract. The implication being, obviously, that you sign that and then you work for them. Not that you sign that, and they pressure you to give up additional rights for nothing.

Also, if they want to own projects you do on your own time, they need to pay you the fair market value of those projects. There's no reason you should give it to them for nothing. Your initial salary negotiations assumed they were only buying your work time. If they want more than that, they have to pay for it. (This is more evidence they breached the implied covenant. To come back and ask for more for the same price is bad faith if they intended to do it all along.)


问:
Do modular PHP frameworks really improve applications?
One of the goals of modular frameworks like Kohana or Alloy is to make it easy to add and remove components (i.e. "plugins" or "modules").

However, in all the larger projects I have ever worked - the system often becomes dependent on the modules it is built on. After all, that is why they are there - to build with them.

So, I'm wondering if the concept of building distinct separate sections of a web application as independent modules is even a good idea to begin with? For example, we may build a general user, forum, and blog module - but each project is different and usually involves building many layers of abstractions to add new features - or editing the files directly to customize them. I can't re-use the same module on multiple projects.

In other words, they are no longer just a plug-in-play add-on to the site.

Now I'm not confusing this with proper class design to ensure un-coupled MVC and library logic. But I'm wondering if "MMVC" was a superfluous effort to apply proper class design concepts to application design as well. After all, many migration systems or database libraries like Doctrine require all the relations spelled out in the models from day one, thereby linking the entities.

Is it one of those things that sounds like a good idea when the project starts, but eventually is shown to be a useless feature? Do modules have their place in systems like wordpress - but not in frameworks where you are obviously building something custom?

答:
The purpose of modules and frameworks is not so much to achieve independence of functions as it is to achieve reusability and flexibility.  In most other occupations, this kind of reuse of function and flexibility is central to achieving success.

Think about how difficult it would be to work on your car if you had to buy a whole new tool set for each car, because the tools were not interchangeable.  Or worse, you hae to build the tools from scratch, because there wasn't a factory to create them.  Both of these concepts (universal pluggability and object factories) are present in well-written  modules and frameworks.

...but each project is different and usually involves building many
  layers of abstractions to add new features - or editing the files
  directly to customize them. I can't re-use the same module on multiple
  projects.

You are describing tight coupling, an undesirable trait of software that's intended to be reused.  Properly written libraries, frameworks and modules achieve loose coupling through software patterns such as Inversion of Control, message passing, and universally-understood communication methods such as REST and XML.  These are not the only methods by which loose coupling can be achieved.

Obviously, it is impossible to write a completely decoupled system; one part of the system has to know something about the other part of the system, or nothing gets accomplished.  But a high degree of decoupling can be achieved nevertheless.

Writing modular software takes more work and forethought than writing tightly-coupled systems, but the effort can be worth it, especially when writing a framework or library that will be used by many people.


问:
Using SVN along with WAMP
I would like to run SVN server on my local machine along with WAMP.
All SVN server binaries include Apache. Whereas I don't need Apache as I'm already running WAMP.

Please let me know if there are any installs available that includes only the SVN server.
If there are none available, shall I go ahead with what's available? And how would I do that without breaking anything.

PS: I tried CollabNet and VisualSVNServer. Both includes Apache.

答:
SVN is a module and you could be able to include it in your existing apache. I have never done this. How to do this should be part of the svn documentation.

If you're only develop on this machine, you could also use the file:// protocol and wouldn't need to integrate with apache.

Update:

httpd, the Apache HTTP server is the chapter from the SVN book containing information about hosting svn repositories with apache.

Title: Using SVN along with WAMP


问:
Boss wants to convert all developers to virtualized desktops

Possible Duplicate:

  Thoughts on Development using Virtual Machines

My boss has been singing the praises of leveraging virtualized desktops for all our developers in the company - about 100 people.  I think this is a horrible idea and can think of no other companies pursuing a similar course of action.

He believes that he can run Word and Outlook much faster over his server hosted virtual machine and has somehow come to believe that this will work for software development just as well. I have grave doubts of this.

Can anyone else provide me with some objective technical and/or business data on this scenario which can be used to dissuade him?

I can see desktop virtualization as a viable option for task based workers who sit in front of MS Office or a LOB app all day, but for software development, I see this as a huge potential blunder. I for one, have no interest in returning to dumb terminals and blind faith in operations to keep the servers and network tuned to our needs.

If such a system is instituted, I may very well leave the company... as I see the policy betraying a clear lack of understanding and a diminished perception of value in what the devs are doing...

答: I work on a daily basis (as a developer) using RDP to a virtualized desktop and I would say it's not that practical. Especially when you're doing performance tests you can never do a clean test thus your results are less easy to compare. Adding to that you'll always have some delay between your keystrokes and the remote computer handling your input</p>

OwnerDisplayName: Hotrodmonkey


答:
Why not give it a try? Offer to set up a side by side comparison so that you can make a fair comparison and so all the developers can take the new system for a spin. You might even switch for a month or two and really give it a shot. Possible outcomes:

You have a bunch of problems. Maybe the sys admins don't give you access to the tools you need, or the system is just too slow, or the keyboard makes your hands hurt, or whatever. As the first developer to try the new system, your manager is going to want to know what you think and will probably be eager to help you solve the problems you find.

The new system works better than you expected and is at least passable. The biggest downside is that you lose some control over your machine. That was probably coming anyway, though, and by volunteering to go first (and not whining about it) you at least garner some points with your manager.

Surprise! The new system really does work well. Maybe it's as fast as your current machine, or maybe it's faster. You might discover some advantages that you didn't have with your desktop machine. For example, I worked on one such system where you could pull your token out of one terminal and stick it in another, and you'd be right where you left off. I still didn't love the system, but it was really nifty to be able to sit down at any desk and access your own environment. Worked great for showing someone else something that you were working on. The downside here is that you have to admit that your manager was right, but you still get the points for going first.

If you give the new system an honest try and find real problems, your manager should be smart enough and honest enough to admit that his plan might not work so well, at least for the developers. He shouldn't be so invested in his plan that he can't see the real problems. But by the same token, you shouldn't be so emotionally attached to the way you work now that you're afraid to try something new.

Title: Boss wants to convert all developers to virtualized desktops

Body:
Possible Duplicate:

  Thoughts on Development using Virtual Machines

My boss has been singing the praises of leveraging virtualized desktops for all our developers in the company - about 100 people.  I think this is a horrible idea and can think of no other companies pursuing a similar course of action.

He believes that he can run Word and Outlook much faster over his server hosted virtual machine and has somehow come to believe that this will work for software development just as well. I have grave doubts of this.

Can anyone else provide me with some objective technical and/or business data on this scenario which can be used to dissuade him?

I can see desktop virtualization as a viable option for task based workers who sit in front of MS Office or a LOB app all day, but for software development, I see this as a huge potential blunder. I for one, have no interest in returning to dumb terminals and blind faith in operations to keep the servers and network tuned to our needs.

If such a system is instituted, I may very well leave the company... as I see the policy betraying a clear lack of understanding and a diminished perception of value in what the devs are doing...


答:
I do not see how we can objectively answer this question. Why does it seem so bad? What is your issues with virtual environment?

Although I agree about the issues related to virtualized environment mostly delay in the input and availability. We did use such scenario for a while but get this... programmers and servers were on opposite sides of the globe.

Delay was horrible, yet, we still managed to be productive. Now that does not mean I would return to such an environment - it really was horrible. On the other hand there are many specialized set-ups that we have to use for some aspects of the system's development. For use it is just much more convenient to use a virtual environment and fire it up when we need it than getting all the environments up and running on all the stations.

There are advantages to running in a virtual environment and the disadvantages can be worked around. For example the performance tests it would seem obvious to me that a dedicated hardware would be necessary for this to obtain any sort of reliable results over time.

There are also disadvantages most of which have impacts more on the business side of the job than the strict engineering side. For example availability. Perhaps the company really though it through and estimated that they can cut costs by centralizing the setups even if this means that x% of the time part of or the whole team will be idle due to system outages. That said, true impact studies as these are rarely done properly. Now getting forced time off (paid I might add) might not always feel right but it is their money they are waiting here. Your time has already been bought and paid for, how it is used is really up to them. But like you said, if the way they choose to spend your time feels wrong then you always have the choice to move on.

My point here is that if you want to convince someone of a decision being wrong you have to be ready to see the other side of the coin. Maybe they did not see the problems you are fearing will happen, but maybe you did not see the problems that led to this decision. But how you asked your question here I can just see that this is not going anywhere.


答:
We use virtual desktops heavily and with powerful servers sitting on your LAN and fast storage the performance can be quite adequate for software development.  It's not quite up to par with the latest and fastest but it's close.  Some of the benefits are being able to quickly replicate and deploy VMs, automatic backups and being able to access your desktop from anywhere (e.g. meeting room, home etc.).

Need a particular OS flavor for testing? Not a problem.  You can take snapshots before installing stuff etc.

The feel (this is VMware View) is pretty much indistinguisable from a physical PC.  Multiple monitors, USB...

So it really depends.  You have to weigh the benefits vs. the small performance decrease.  It's not just the cost of a PC but the cost of maintaining that hardware.  The initial investment in building a good VDI infrastructure for software development can easily be much higher than the cost of PCs (storage is crazy and servers aren't cheap either).

I've commented on a similar question before, see:

https://stackoverflow.com/questions/4240359/what-are-the-pros-and-cons-of-a-vm-as-a-dev-environment/4240766#4240766

Disclosure :-) We develop software for virtual desktops - hence we eat our own dogfood.

EDIT: expanding on the performance question:

The overhead of running inside a VM using modern CPUs is quite small.

There are very fast I/O solutions geared towards VDI enviornments (mostly use SSD caching).

So in a well architected, unloaded, VDI enviornment "raw" performance is quite good.  Again, not as good as a cutting edge stand-alone PC but pretty good.

The "residual" cost is the cost of remoting the desktop (e.g. screen, keyboard, mouse) over the network.  This is mostly a function of how many pixels are changing on the screen and for software development work is not a heavy load.  As a rough guideline I'd estimate that less than 5% of a modern CPU core is required to support this.  If you do intensive 3D graphics (e.g.) then virtualization is probably not for you (yet?).


答:
As long as you are connected with a reasonably fast LAN and they have not made a complete mess of the sizing and configuration of the servers you should not notice any difference.

There are numerous advantages to these environment:-

Some tasks are faster -- large build tasks can take advantage of the extra processing power and memory of the server hardware.

If you need to test against multiple versions of the OS or system software you just deploy more Virtual desktops.

Its cost effective to deploy many cheaper workstations and a few powerful servers than vice versa.

Utilization. Unless all your developers never get sick, never take vacation, never go to meetings and never stop for coffee, then you will get better utilization from the shared server environment -- 90% average cpu, memory etc over a working day as opposed to maybe an average of 10% workstation usage for a working day.

Maybe you prefer a dedicated workstation but its really not worth fighting your boss over.


问:
What's the reasoning behind the "I" prefix naming convention for interfaces in .NET?
I know the "I" convention has been around since COM, but I've never understood why it hasn't been reconsidered like every other naming convention before .NET has.

Consumption wise, the only thing that separates an interface from, say, an abstract class, is that they can be multiply inherited. But everything after Visual Studio 2003 has shown type signatures in tooltips, so it's as useless as all the other Hungarian notations that have been discarded.

I also thought it might be so that you can have a basic implementation of the interface with the same name, e.g. Message inheriting IMessage, but most of the .NET libraries have gone for adding the word "Base" at the end (e.g. System.Collections.ReadOnlyCollectionBase) instead -- and this makes more semantic sense.

COM interop seems to be another possible reason -- but it's not as if the wrapper classes that it generates are perfectly idiomatic .NET, so I doubt that that was an aesthetic consideration.

In one of my newer projects I've forgone the convention entirely, and it feels just fine. Is there something I'm missing?

答:
I don't think your missing anything, it's just a historical habit.

I agree with you as well and have also dropped the 'I' on a couple of small to medium projects with no detrimental effect.


答:
IANAL

When the company I worked for was bought out by a big company, we had lots of new paperwork to go through. One of them was a medical form which said something like "I agree to allow hospitals, doctors, nurses, and anyone else to look at my medical records, insurance claims, and anything else". The "else" clauses meant that I would agree to allow anyone to see anything.

Would I make a stink? Would I submit? Would I refuse?

I figured that the personnel department was told to get a signed form K3799F from every person. So I scratched out the words I didn't like, and signed it.

People have warned me that this was not legally binding. By giving me the form the company was "making me an offer". By altering it and submitting it to them I was "refusing the offer and making a counter-offer". I didn't care whether it was legally binding, on me or on the company. The important part was that the original wording in the form was not binding on me.

Never heard any more about it. The clerks must have taken the paper and stuffed it into my employment file, probably without reading it, possibly noticing the alterations and knowing that to bring up the matter would just create more work for them.

So if you're in a similar situation, with everybody getting stuck with the same form at the same time, you can try what I did. Scratch out the parts you don't like, then sign it and hand it in. The worse that can happen is that you get called into the HR office and yelled at. But there's a really good chance that you'll never hear about it again.

Oh yes - keep a copy.


问:
Why are so many HTML tables used in page markup?
I'm trying to get into web development, so I started learning HTML, CSS, and javascript. I've been coming along really well with javascript, but I still can't make anything with HTML and CSS to save my life. I was going to ask for some places or tips to improve, but I know the question has been asked countless times and would just get deleted, so I figured I would just view the source of some other people's websites. </p>

<p>What I keep seeing is tables left and right. Is there a valid reason to use tables? </p>

答:
To lay out tabular data.

Here are a few questions to ask yourself when choosing between tables and css containers.

Tables are for Tabular Data. Period.

The
 tag is not evil. Despite what some people think and say, the point of CSS is not to never use it. However, a corollary to the principle of Semantic HTML is that you should never use tables for layout. Let me say that again, as its own paragraph, for emphasis:

Never use tables for layout. Ever.

If you can't decide whether or not a table is the right choice, ask yourself these questions:

“Do the rows or columns of information share a common attribute?”

“If I changed the order of the rows or columns, would it still make sense?”

“If I transposed the axes of the table (made rows into columns and vice-versa) would it still make sense?”

If the answer to the above is generally “Hrm...I guess not,” then you shouldn't be using a table.

If you need more convincing, see "Why Tables Are Bad (For Layout) Compared to Semantic HTML + CSS".

Body:
To lay out tabular data.

Here are a few questions to ask yourself when choosing between tables and css containers.

Tables are for Tabular Data. Period.

The <table> tag is not evil. Despite what some people think and say, the point of CSS is not to never use it. However, a corollary to the principle of Semantic HTML is that you should never use tables for layout. Let me say that again, as its own paragraph, for emphasis:

Never use tables for layout. Ever.

If you can't decide whether or not a table is the right choice, ask yourself these questions:

“Do the rows or columns of information share a common attribute?”

“If I changed the order of the rows or columns, would it still make sense?”

“If I transposed the axes of the table (made rows into columns and vice-versa) would it still make sense?”

If the answer to the above is generally “Hrm...I guess not,” then you shouldn't be using a table.

If you need more convincing, see "Why Tables Are Bad (For Layout) Compared to Semantic HTML + CSS".


问:
What should I include in XML documentation comments?
I'm trying to make a point of documenting my code better, especially when it comes to the XML comments on class members, but often it just feels silly.

In the case of event handlers, the naming convention and parameters are standard and clear:

```<code>/// <summary>
/// Handler for myCollection's CollectionChanged Event.
/// </summary>
/// <param name="sender">Event Sender</param>
/// <param name="e">Event Arguments</param>
private void myCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    // actual code here...
}
</code>```

I also frequently have simple properties that are (IMO) named clearly so that the summary is redundant:

```<code>/// <summary>
/// Indicates if an item is selected.
/// </summary>
public bool ItemIsSelected
{ get { return (SelectedItem != null); } }
</code>```

I don't feel like such comments don't add any information that the declaration itself doesn't already convey.  The general wisdom seems to be that a comment that repeats the code is best left unwritten.

Obviously, XML documentation is more than just regular inline code comments, and ideally will have 100% coverage.  What should I be writing in such cases?  If these examples are OK, what value do they add that I may not be appreciating now?

答:
XML doc comments are intended for public members.

The compiler warning clearly states this:

Missing XML comment for publicly visible type or member 'Type_or_Member'

You should only add XML comments to private members if those members aren't already obvious from their names.

OwnerDisplayName: mbmcavoy

OwnerDisplayName: SLaks


答:
Pure opinion here, so take it for what it's worth.

I hate superfluous xml comments. Doubly so for the ghost doc style ones that simply add spaces to the method/property name. It adds no value and simply clutters my view of the actual code.

If something needs clarification, by all means, comment it. However, a lot of clarity can be conveyed by small focused methods with meaningful names. Don't comment code if you can improve it and make the comment unnecessary.

Don't even get me started on the unnecessary use of this. and Me..

As a side note, I would love to have a Visual Studio addin that let me toggle the visibility of xml comments. (hint, hint)

Title: What should I include in XML documentation comments?

Body:
I'm trying to make a point of documenting my code better, especially when it comes to the XML comments on class members, but often it just feels silly.

In the case of event handlers, the naming convention and parameters are standard and clear:

```<code>/// <summary>
/// Handler for myCollection's CollectionChanged Event.
/// </summary>
/// <param name="sender">Event Sender</param>
/// <param name="e">Event Arguments</param>
private void myCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    // actual code here...
}
</code>```

I also frequently have simple properties that are (IMO) named clearly so that the summary is redundant:

```<code>/// <summary>
/// Indicates if an item is selected.
/// </summary>
public bool ItemIsSelected
{ get { return (SelectedItem != null); } }
</code>```

I don't feel like such comments don't add any information that the declaration itself doesn't already convey.  The general wisdom seems to be that a comment that repeats the code is best left unwritten.

Obviously, XML documentation is more than just regular inline code comments, and ideally will have 100% coverage.  What should I be writing in such cases?  If these examples are OK, what value do they add that I may not be appreciating now?

OwnerDisplayName: whatknott


问:
Why is the 'final' keyword used so little in the industry?
Since I discovered the powers of the final keyword in Java a few years ago, it helped me to make my codes a lot more readable, since people can easily see what are read-only variables. It may also provide a little boost to the JIT, and while that's a very limited one, it can't harm, especially when targeting embedded devices such as android platforms.

But more than everything, it contributes to make a design more robust to changes, and guide other committers when they need to modify the code base.

However, while browsing some of the JDK source code, I never stumbled upon this keyword, either for classes, methods, or variables. The same applies for various systems I had to review.

Is there a reason? Is it a common design paradigm to let everything mutable from the inside?

答:
Well to start with, official Java Code Conventions neither favor nor prohibit particular use of final. That is, JDK developers are free to choose the way they prefer.

I can't read their mind but to me, the preference on whether to use final or not has been a matter of focus. A matter of whether I have enough time to thoroughly concentrate on the code or not.

Say, in one of my projects we could afford spending average a day on like 100 lines of code. In this project, I had a distinct perception of final as a garbage that just obscures things that are already expressed clearly enough in the code. It looks like JDK developers fall in that category, too.

On the other hand, it was totally opposite in another project, where we spent an hour average on 100 lines of code. There, I found myself shooting final like a mashine gun in my own and in other's code - simply because it was the quickest way to detect an intent of the guy who wrote it before me and, similarly, the quickest way to communicate my own intent to the guy who will work on my code later.

It may also provide a little boost to the JIT, and while that's a very limited one, it can't harm

Reasoning like above is slippery. Premature optimization can harm; Donald Knuth goes as far as to calling it "the root of all evil". Don't let it trap you. Write dumb code.

OwnerDisplayName: Aurélien Ribon


答:
On a public member XML documents should be fairly verbose and complete, as @SLaks has mentioned.

However they can be really useful on private, protected or internal members too because Visual Studio will populate intellisense and help tooltips with the XML doc comments.

This means that:

```<code>// describe what this does
private void DoSomething()
{
    // or describe it here...
</code>```

Might be perfectly sufficient documentation, but:

```<code>/// <summary>describe what this does</summary>
private void DoSomething()
{
</code>```

Will be much easier to see quickly from elsewhere in your code.

Generally on public XML comments I'm writing for some external user of the API, and on internal XML comments I'm writing for me or others on my team.

Skipping parameter descriptions is probably a bad idea for the former and fine for the latter.

I would add (in public API docs especially) always include whether get or set on properties:

```<code>/// <summary>Gets a value indicating whether an item is selected.</summary>
public bool ItemIsSelected
{
    get { return SelectedItem != null; }
}
</code>```

It's not obvious from C#'s intellisense whether get or set are available, but putting it on the XML comment will mean you can tell at a glance from the tooltip.

Body:
On a public member XML documents should be fairly verbose and complete, as @SLaks has mentioned.

However they can be really useful on private, protected or internal members too because Visual Studio will populate intellisense and help tooltips with the XML doc comments.

This means that:

// describe what this does
private void DoSomething()
{
    // or describe it here...

Might be perfectly sufficient documentation, but:

/// <summary>describe what this does</summary>
private void DoSomething()
{

Will be much easier to see quickly from elsewhere in your code.

Generally on public XML comments I'm writing for some external user of the API, and on internal XML comments I'm writing for me or others on my team.

Skipping parameter descriptions is probably a bad idea for the former and fine for the latter.

I would add (in public API docs especially) always include whether get or set on properties:

/// <summary>Gets a value indicating whether an item is selected.</summary>
public bool ItemIsSelected
{
    get { return SelectedItem != null; }
}

It's not obvious from C#'s intellisense whether get or set are available, but putting it on the XML comment will mean you can tell at a glance from the tooltip.


问:
WinRT and .NET: What is it, where do i place it and what does it change?
Say I'm a .NET developer and want to build my application on WinRT. What I've read is that it is a completely new API for Windows 8, strongly related to Metro-style apps.

I'm assuming that I can develop for WinRT in .NET/C#? How does it relate for example to WPF or Silverlight? Does WinRT provide it's own UI framework, or can I build a WPF application on top of WinRT?

What about basic I/O. .NET provides methods for that, if I develop with/for WinRT, do I have to use other methods, or will the .NET framework use WinRT under the hood?

Besides these specific questions, the overal question is really how does it relate to the other APIs and frameworks I'm currently familiar with as a .NET/C# developer?

答:
I guess you are going way ahead at this time. Let Microsoft roll Win-8 and the rest of the story will unfold later. They might have planned to roll out a new API along the lines of New OS, but that surely can't come before the OS itself. </p>

<p>So, just wait for few quarters and then think about WinRT </p>

Body:
I guess you are going way ahead at this time. Let Microsoft roll Win-8 and the rest of the story will unfold later. They might have planned to roll out a new API along the lines of New OS, but that surely can't come before the OS itself.

So, just wait for few quarters and then think about WinRT


问:
On what basis would you split donation money among your open source team members without any strife?
I am a developer of an open source project which is hosted in SourceForge.

It started out as a little app then after some releases, it got more and more popular and it started consuming more time and responsibility from me. So I have enabled the donation option in SourceForge.

I'm passionate to continue developing it for free but if (ever) any money comes in, how should I split it with my team?

Should I split the amount equally among the number of team members? (50-50 as it is two-member team now)

Number of classes, commits or any other valuable submissions by team members?

Any other idea?

What would you do in such situation? Please give your opinions.

I hope this question will be useful for others.

答:
Just my opinion, but I'd say don't worry about it until it's worth worrying about. If you're getting a few bucks here and there for yourself, I wouldn't sweat it or feel guilty about it unless someone specifically asks.

Now, for ongoing work, I might say "hey, I have a donation button up on the site and I'll give you n% of the cut when donations come in" just to call it out and be open about it.


答:
As I understand it WinRT is a new framework sitting on top of the Windows Kernel. Most functionality of .Net should be available in WinRT as well although namespaces and implementations may differ.

What happens to WPF or Silverlight is anyones best guess, they didn't get much mention on Build yet. I suppose Silverlight will see a final version 5 and .Net 4.5 but I doubt both will be advanced that much further. On the other side WinRT apps only run on Win8 and some apps don't even make sense in Metro-Design so MS should/could/who knows? be working on improvements to the .Net Framework for some time/forever. ;)

Title: WinRT and .NET: What is it, where do i place it and what does it change?

Body:
Say I'm a .NET developer and want to build my application on WinRT. What I've read is that it is a completely new API for Windows 8, strongly related to Metro-style apps.

I'm assuming that I can develop for WinRT in .NET/C#? How does it relate for example to WPF or Silverlight? Does WinRT provide it's own UI framework, or can I build a WPF application on top of WinRT?

What about basic I/O. .NET provides methods for that, if I develop with/for WinRT, do I have to use other methods, or will the .NET framework use WinRT under the hood?

Besides these specific questions, the overal question is really how does it relate to the other APIs and frameworks I'm currently familiar with as a .NET/C# developer?


答: I've found a blog entry from Julian Bucknall that summarizes the keynote along with two slides. Maybe this will shed some light for your question, but always remember: it's a beta thing and might change regardless what is published now and by whom ...</p>


答:
Either put it back into the project (buy servers ect) or split it equally between significant contributors (dont give any to people who have only done a couple of lines).

People dont work on open source projects for the money. Trying to share money in any complex way emphisies the cash aspect of the project and is borderline insulting

Title: On what basis would you split donation money among your open source team members without any strife?

Body:
I am a developer of an open source project which is hosted in SourceForge.

It started out as a little app then after some releases, it got more and more popular and it started consuming more time and responsibility from me. So I have enabled the donation option in SourceForge.

I'm passionate to continue developing it for free but if (ever) any money comes in, how should I split it with my team?

Should I split the amount equally among the number of team members? (50-50 as it is two-member team now)

Number of classes, commits or any other valuable submissions by team members?

Any other idea?

What would you do in such situation? Please give your opinions.

I hope this question will be useful for others.


答:
I recommend not distributing it to project members at all. Appoint or elect a treasurer, open an account and  deposit the money to earn simple interest. If you distribute donated funds between developers, at least one will become disenfranchised as the project grows.

Instead, consider the other possibilities for the funds:

Swag. Print up some T shirts to send to people who have made more than trivial contributions to the code.

Bounties. Put a reward on the feature the community really wants but nobody really feels like implementing. This is also a great way to get new long term contributors. Or, 'sweeten the pot' a bit for fixing a really perplexing bug. The bounties don't have to be cash, especially if you have swag to give. It also doesn't have to be swag, a Pi in hand is worth 10 in the oven.

Hardware. Buy stuff that the community owns that all developers can use. This could be servers, or gadgets that are shared through the mail.

Tools/Licensing. You might need to pay for software, even being an open source project. You might need to buy a copy of Acme Widgets to study it for the purpose of creating an open alternative, or you might need to help a great contributor upgrade their development environment.

Events. Help send your developers to conferences or key events when opportunities present themselves.  Or, sponsor your own meetup if enough people would be able to attend.

Legal Fees. While (thankfully) still relatively uncommon1, you might find yourself in litigation for a number of reasons. It's good to have some money put away. This could be simply enforcing your license or copyright, or defending against something else.

There are so many ways that the money could be spread so everyone benefits, it really doesn't make much sense to limit the good it could otherwise do.

If you get to the point that donations and community support make hiring some of the most prolific developers to work on the project full time reasonable, it means you should be looking at the project as more of a business than a hobby.

1 Litigation in open source is a lot like plane crashes. You read about the horror stories and drama in the news when something happens, but don't forget the nearly millions of projects that have and will continue to exist without any issue whatsoever


答:
I think the "implicit" looping here isn't very implicit. Compare this with Scala, where you have operations on lists without any hint of looping:

```<code>List(1,2,3,4).foreach(println)

List(1,2,3,4).map(x => x*x)

List(1,2,3,4).filter(_ % 3 != 0)
</code>```

Still, the enhanced for loops (or "for every"... in Python) are better than explicit loops, it's a step in the right direction, abstracting from the low level details. E.g. for most operations it isn't even important that you have a linear data structure, you can implement the three methods above easily for other data structures like trees, and you wouldn't even note the difference.

Title: Explicit or implicit looping?

Body:
Why or when is "explicit" preferred when implicit solutions often are more readable and less code? It says "explicit is better than implicit" when for example an implicit loop is better than an explicit loop isn't it?

```<code>for every in all:
  every.updated = True
</code>```

The above looks implicit to me and better than an explicit counter since a counter is another thing that can go wrong and why not leave to the compiler or other environment instead of requirement an explicit counter variable:

```<code>  for(int i=0, i<a.length, i++)
...
</code>```

And there are languages where all looping is "implicit" - what does it mean and when is it preferred? And not explicitly setting a value to nullor None or likewise seems better to me and I want to rewrite code when I "solve" a requirement by explicitly setting return null or String name = null since I think being explicit about what should be null and None should have a more clear solution such as only use a variable if it's needed and if I write return null somewhere I'm probably doing it wrong. When I was writing Java I found myself writing return null and declaring values as null at some places and I didn't like it and could rewrite it even though the case where I put return null was reached only in case of error.

I asked the guru at work whether we ever should declare a variable to null, isn't defaults much better?

I'd be glad to know your thoughts about this. An example where it is better to be explicit I can think of is declaring a list and explicitly declaring what type is in the list is better than just a list of objects e.g. it's preferred to declare ArrayList<ArrayList> instead of just an ArrayList if we know that it's a list of lists.

Body:
I think the "implicit" looping here isn't very implicit. Compare this with Scala, where you have operations on lists without any hint of looping:

List(1,2,3,4).foreach(println)

List(1,2,3,4).map(x => x*x)

List(1,2,3,4).filter(_ % 3 != 0)

Still, the enhanced for loops (or "for every"... in Python) are better than explicit loops, it's a step in the right direction, abstracting from the low level details. E.g. for most operations it isn't even important that you have a linear data structure, you can implement the three methods above easily for other data structures like trees, and you wouldn't even note the difference.