答:
I think this may well be the only case when prefixes are useful.

Classes and interfaces really do have different semantics, and because both are types, are easy to mix up.

When I see a class declaration, I can instantly tell what it derives from and what it implements:

```<code>public sealed class ActivityCollection : List<Activity>,
    IList<Activity>, ICollection<Activity>, IEnumerable<Activity>,
    IList, ICollection, IEnumerable
</code>```

It would be harder to understand if the definition looked like

```<code>public sealed class ActivityCollection : ListClass<Activity>,
    List<Activity>, Collection<Activity>, Enumerable<Activity>,
    List, Collection, Enumerable
</code>```

And how would you call ListClass? Clearly it's not just ListBase because it's usable on its own.

So, we either have to solve a problem we just invented, or adapt a prefix that separates classes from interfaces, which is what .NET Framework designers did.

Also, personally I find it useful when I can tell from the method signature that it works with interfaces.

```<code>public void PrintLines (IEnumerable<string> source)
</code>```

It's like a signal to my head: hey, I can implement this! I can feed the method whatever matches the contract.

Of course one can argue it's not that important but this is one of those little things that make the prefix worth it for me. It's especially useful when writing a lot of code with IoC containers when you constantly work with interfaces and need to easily differentiate between the two.

By the way, not only the interfaces have prefixes in .NET type system. Don't forget about the generic type parameters:

```<code>public delegate TResult Func<in T, out TResult>(
    T arg
)
</code>```

This is another situation when it's extremely useful to be able to differentiate between classes and another kind of types.

Title: What's the reasoning behind the "I" prefix naming convention for interfaces in .NET?

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

Body:
I think this may well be the only case when prefixes are useful.

Classes and interfaces really do have different semantics, and because both are types, are easy to mix up.

When I see a class declaration, I can instantly tell what it derives from and what it implements:

public sealed class ActivityCollection : List<Activity>,
    IList<Activity>, ICollection<Activity>, IEnumerable<Activity>,
    IList, ICollection, IEnumerable

It would be harder to understand if the definition looked like

public sealed class ActivityCollection : ListClass<Activity>,
    List<Activity>, Collection<Activity>, Enumerable<Activity>,
    List, Collection, Enumerable

And how would you call ListClass? Clearly it's not just ListBase because it's usable on its own.

So, we either have to solve a problem we just invented, or adapt a prefix that separates classes from interfaces, which is what .NET Framework designers did.

Also, personally I find it useful when I can tell from the method signature that it works with interfaces.

public void PrintLines (IEnumerable<string> source)

It's like a signal to my head: hey, I can implement this! I can feed the method whatever matches the contract.

Of course one can argue it's not that important but this is one of those little things that make the prefix worth it for me. It's especially useful when writing a lot of code with IoC containers when you constantly work with interfaces and need to easily differentiate between the two.

By the way, not only the interfaces have prefixes in .NET type system. Don't forget about the generic type parameters:

public delegate TResult Func<in T, out TResult>(
    T arg
)

This is another situation when it's extremely useful to be able to differentiate between classes and another kind of types.


问:
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 think the only reason, according to Microsoft's Naming Guidelines about Interfaces and Classes, is that, sometimes you have conflicts between the name of the interface and the class implementing that. This goes back to the fact that interfaces are in fact the skeleton, not the meat, and the implementer class is in fact the meat (realizing the blueprint). Thus, IAnimal is only describing what an animal should have, while Animal can tell you that what it has.

However, I personally completely agree with you on the point that we could simply use Animal Base for the interface, and Animal for the class.

On the other hand, sometimes two things are conflicting so much, that a team decides to provide a convention to prevent further conflicts, in spite of already-made decisions. For example, in ASP.NET MVC, both Partial Views and Layouts (master pages), are just like a normal View, while they serve different functionality. Thus Microsoft in spite of emphasizing not to use underscore in naming, suggests to underscore Layouts and Partial Views with an underscore.

ContentLicense: CC BY-SA 3.0


问:
Team of 1: Do I need Project Management & Versioning Software?

Possible Duplicate:

  Version control for independent developers?

I work as a Junior Programmer in a team of 1. I am looking for suggestions of what open source/free Project Management(I cant remember the correct term?) programs, ie things like Github would be suitable for my & the companies needs.

I create websites using just javascript, HTML & CSS, I create cross platform mobile applications using Mosync C++ API & I create Facebook iFrame apps using HTML, javascript, css & their Graph API.

The boss is really not willing to purchase a subscription from a "Project Management Program"(BTW whats the correct term?) so I would be looking for a free service. I currently use DropBox because it allows me to work from anywhere & gives a limited ability to go back to an older version of a file but I have found that I have made a change in a project & it broke something else so I needed to go back to the old version of a file & it was not there in dropbox(maybe they only keep the last version before a save).

If you were on a team of one do you think it would be necessary to even use this? And if yes, what service would you use?

答:
My short answer: Yes!

Do a bit management, play around with agile, get into each pitfall.
For the management, including tickets, wiki, agile, time logging etc, I recommend Redmine as it is free.

For versioning: I do only little tests (less than 100 lines) without git/svn. Everything else should be versioned as can step back when you programmed a mess that can't be undone easily. Also you can check for changes that introduced a bug you didn't have had before. Github is a good service, but I am not sure if non public gits are free.


问:
Do you have to be good at math to be a good programmer?
It seems that conventional wisdom suggests that good programmers are also good at math. Or that the two are somehow intrinsically linked. Many programming books I have read provide many examples that are solutions to math problems, or are somehow related to math as if these examples are what make sense to most people.

So the question I would like to float is: do you have to be good at math to be a good programmer?

答:
For me, it was the other way around

because i liked programming, i was good at math, because for most concepts, i had a practical application, starting simple with logic (x and y or z), to simpler analysis ("ok, f(x) is a function. i know that, that even looks exactly like the functions in Pascal. go on"), to higher stuff (a mapping |R -> |R? ah, thats like a Dictionary with floats as keys and values).

I was often surprised, that math was not just not that hard, but instead provided me a much easier way of thinking about my programming problems than those clumsy, pragmatic languages i was coding in ever could.

OwnerDisplayName: Charles Roper

ContentLicense: CC BY-SA 2.5


答:
You need to retrieve old versions of your files: you definitely need a version control system. This is not the aim of Dropbox.

You also need to access your files from wherever you happen to be. You need either a cloud storage or a USB device.

github and others provide both but their free flavour often is reserved for open-source projects. If you are ok with that, go for github.

The alternative is a svn/git/whatever local repository put on a USB thumb drive.

Title: Team of 1: Do I need Project Management & Versioning Software?

Body:
Possible Duplicate:

  Version control for independent developers?

I work as a Junior Programmer in a team of 1. I am looking for suggestions of what open source/free Project Management(I cant remember the correct term?) programs, ie things like Github would be suitable for my & the companies needs.

I create websites using just javascript, HTML & CSS, I create cross platform mobile applications using Mosync C++ API & I create Facebook iFrame apps using HTML, javascript, css & their Graph API.

The boss is really not willing to purchase a subscription from a "Project Management Program"(BTW whats the correct term?) so I would be looking for a free service. I currently use DropBox because it allows me to work from anywhere & gives a limited ability to go back to an older version of a file but I have found that I have made a change in a project & it broke something else so I needed to go back to the old version of a file & it was not there in dropbox(maybe they only keep the last version before a save).

If you were on a team of one do you think it would be necessary to even use this? And if yes, what service would you use?


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

答:
This happens all the time to me.  I just have so many things going on in that noggin of mine I'll forget so many of the simplest things.  Names, birthdays, irritating meetings all slip through like water through sand.  But anything to do with computers, programming, math or anything like that just stays there.  The best way to memorize a language, technology or even a project is write a Cheat Sheet.

I generally have a qucik reference for everything I work with so I can quickly remind myself whats going on.  I also have a notebook I keep all my notes in and reference page numbers on the cheat sheets.


答:
Do not ever do any development without version control. Seriously.

Even if you're just running git locally, without any server, it's still infinitely better than no version control at all. Just the ability to look back through changes, revert where necessary, see when/why you made a particular change... all this is invaluable.


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

答:
I'm after some solid evidence

Then stop wasting your time here.

Find some code that's expensive to maintain.  It's easy.  Look at your organization's trouble tickets.

Find some code that's cheap to maintain.  Find code that's run frequently, but has few or no trouble tickets.

Measure the complexity with any of the widely available complexity tools.

Bask in the evidence.

You have now provided numbers to confirm the obvious.


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

答: Other answers recommended getting a lawyer or crossing out the terms which you don't like. I think you should just run away from them. You caught them and their tricks now, but what about the future?</p>


问:
What should I expect from a technical evaluation for C++?
I have been asked to go for a technical test/evaluation for a job as a junior developer, mainly using C++. This is my first test/evaluation, and it is 2 hours long.

My C++ is a bit rusty as I have been doing projects recently on PHP.

This is a UK company, however im guessing technical testing of candidates will be pretty much the same everywhere.

What should I expect in one of these tests?

答: Practice code kata Pick a simple algorithm (ring buffer, Hanoi tower, binary search, whatever) and code it from scratch.  Then do it again the next time, and the next time, and the next time, and the next time, and so on.  Look at how you can improve them at each iteration.


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

答:
Basically, the backtrack algorithm works like this:

Create an X by Y array. Set all squares to empty.

Set the queen count to zero.

Set your current position to (1,1)

See if you can place a queen in the current position.

If you can, set Array(X,Y) to queen, increment the queen count. If you placed all queen, stop, you have a solution.

If the current position is not (X,Y), increment the current position and go to step 4.

Find the queen in the last position (the one that comes last in the order you increment positions). Set the current position to the position of that queen, remove it, and decrement the queen count.

If the queen count is zero, stop, there is no solution.

Increment the current position.

Go to step 4.


问:
Conversion of a number from Single precision floating point representation to a Half precision floating point
I have a code where I have to work on Half precision floating point representation
numbers. To achieve that I have created my own C++ class fp16 with all operators(arithmetic logical, relational) related to this type overloaded with my custom functions, while using a Single precision floating point number with a Half precision floating point number.

Half precision floating point = 1 Sign bit , 5 exponent bits , 10 significand bits = 16 bit

Single precision floating point = 1 Sign bit, 8 exponent bits, 23 significand bits = 32 bits

So what I do to convert from a Single precision floating point number to a Half precision floating point number:-

For significand bits - I use truncation i.e. loose 13 bits from the 32 bits to get 10 bits significand for half precision float.

What should I do to handle the exponent bits. How do I go from 8 exponent bits to 5 exponent bits?

Any good reading material would help.

答: Convert to +INF or -INF as appropriate. The result certainly should be numerical, NaN is logically wrong.


答:
It's true you can expect anything.

They told you the test was C++ but maybe it is really the C subset of C++ they use in their tests (you'll use char arrays instead of standard library strings). This will be hard to know.

If it's really C++, I would advise you to see the basics:

Classes, variables, arrays

references, pointers (and why you should not use them by default)

the usage of the const keyword

Oriented Object concepts ( inheritance, polymorphism ... )

Templates

then:

Standard library usages ( std::string, std::vector, containers, ... )

Title: What should I expect from a technical evaluation for C++?

Body:
I have been asked to go for a technical test/evaluation for a job as a junior developer, mainly using C++. This is my first test/evaluation, and it is 2 hours long.

My C++ is a bit rusty as I have been doing projects recently on PHP.

This is a UK company, however im guessing technical testing of candidates will be pretty much the same everywhere.

What should I expect in one of these tests?


问:
why getMonth() starts with 0
I was coding a function to remove a day from a date value in javascript and i was kind of surprise that javascript's getMonth() starts from 0 for January to 11 for December. Why javascript's  getMonth() starts with 0?</p>

答:
at a guess, to help with indexing into arrays.

Imagine you have your month display strings stored in an array and want to get the correct string using getMonth()

of course, why arrays start at zero is another question

Title: why getMonth() starts with 0


答:
First let’s, check I understand the problem correctly.

The issue is that you have taken the job now; I assume that you have also left your last job.

So they are giving you no option but to sign what you consider being an unreasonable contact that you did not know about when you commited to taking the job.

It is also likely that the employment contract you have signed says they can get rid of you at little or no costs to themselves within the probation period.

As they can get rid of you at little or no cost to them, they have lots of power over you, as they know you need the job you have no power over them.  (Also everyone else in the past is likely to have given up and signed the NDA regardless of saying they would not, so why should they believe you are different?)

However it is very likely that the NDA is being forced on them by the head office or some investor and that it has no real life meaning, but you can’t depend on it.

From the line below is based on my understanding of English law, am not a legal expert, elsewhere in the world the legal system will be different, (even Scotland has its own legal system)

Under English law you get very few employment rights if you have not been in a job for over 2 years.

Under English law restrictions in a contact between an employer and an employee is only enforceable by the employer if it is deemed to be “reasonable” by the courts.

Under UK law if someone in a position of little power is made to sign a contract by someone (or a company) in a position of power, the contact is very hard to enforce unless the party in the position of power can show that they have not abused their power.

(None of this is the case if you are contracting var a limited company)

The company can afford a lot more legal cost then you can if there is every an issue with the NDA, however they can’t afford to have all their mangers in court on many days, so your time can be used to make it VERY costly for them if there is ever an issue.

So I would write on the NDA

that you are signing it under “protest”,

that you did not see it until 3 weeks after you took the job and resigned from the last job

that you have been given no option but to sign it

Then hope that the HR person doesn’t understand the value of what you have just done…   If they make you sign a 2nd copy without the above, record the fact in a dated email to a 3rd party you could use as a witness.

However remember that you are expected under UK law to keep information confidential that you get as part of your employment, so in real life the NDA will make very little difference in most cases.   (An employer can still get an injection against you without having had you sign an NDA.)

Do not get legal advice unless you are willing to walk away from the job if the company will not change the contract.   As the process of getting legal advice will show you signed the contract with your “eye open” and therefore make it easier to enforce.  (That is way it is common for a VC to pay for independent legal advice for all employees of a company they invest in, so that the new employment contact is more likely to “sick”.)

Evan the fact you have posted a question on programmers.se may weaken your defence if the company ties to enforce the NDA.

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?


问:
What are "Metro apps"?
While it is relatively new now (2011/09/15), are there any resources for explanations of Metro applications for Windows8?

I've not seen anything at the moment that summarises an "elevator pitch" for them.

答:
From: http://dougseven.com/2011/09/14/i-know-what-youre-thinking-and-youre-wrong/ (A Telerik Executive VP's blog).

Metro style apps are intended to be touch centric, sensor aware, single screen apps that will likely run on smaller form factors more often than a desktop or laptop PC (in fact we were thinking about calling these apps ‘NISA apps’ – Natural Interface, Sensor Aware apps….we canned that idea).

Title: What are "Metro apps"?


问:
Common Qt Producer/Consumer Example: What is the point of multithreading here?
While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site:

You're doing it wrong...

I got the point of this site, but people are usually referring to the code example which is in the referenced blog:

Threading without the headache

The blog has a small code example attached, the core of it being posted by KornP in this SO answer:

Qt moveToThread() vs calling new thread when do we use each

So if you take a closer look we have the following behaviour:

Producer P produces an item, while Consumer C waits for events to appear in its event loop.

P forwards the produced data through a signal and returns to event loop idling.

C receives the signal in its event loop and consumes the data.

C emits a signal to the producer thread and returns to event loop idling.

Start over from 1.

In other words: while P is producing, C does nothing and while C is producing, P does nothing.

What is the point of having a producer and consumer like this in two different threads?
Wouldn't a single thread accomplish exactly the same?

答:
in this simple case, yes, there's no real benefit in using threads other than showing how threads work I guess. It's still interesting though: P's event loop keeps on running while the actual work is done by C. This is what you want in order to keep the user interface (which P might very well be) responsive.

Things get more interesting with concrete examples. Suppose C comsumes data by storing it in a buffer, and dumps it to a file when the buffer has enough data. This dumping might take while, but P can just continue it's business putting data in the queue without noticing C is busy nor without any slowdown.

ContentLicense: CC BY-SA 4.0


答:
Check out my extensive answer on Stack Overflow.

There are plenty of relevant sources available indicating their 'elevator pitch', and new information is made available at a regular interval on the BUILD blog.

The article which will probably interest you the most talks about 'Designing for Metro style and the desktop'.

If you have time to watch it, I got a good impression of where they want to head to from watching the keynote of the BUILD conference.

For immediate hands-on experience you can download the developer preview.

Title: What are "Metro apps"?

Body:
While it is relatively new now (2011/09/15), are there any resources for explanations of Metro applications for Windows8?

I've not seen anything at the moment that summarises an "elevator pitch" for them.


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

答:
Table based layouts are in some ways, easier to learn than pure CSS layouts for people just beginning to learn HTML. Also, back in the day, you couldn't reliably use CSS and have it work on all browsers. So virtually all of the HTML tutorials up through the 2000 or so used tables exclusively for layouts. A lot of that HTML code was passed over to other sites (via View Source) and a lot of people learned from those tutorials and didn't bother learning CSS layouts.

I'll offer myself up to be flamed here and say that you'll be fine if you start doing your layouts in tables before learning CSS. The differences at the beginner level are minor at best. You won't be able to make really intricate layouts in EITHER until you've had a year or two of experience, so there's really not much difference. Start with the tables in order to get some stuff on the screen and to keep yoru interest, and slowly keep reading up on CSS (which is clearly superior in the long run). I used to be a CSS-Zealot back in the day of "Designing with Web Standards" but that was just because it was fun being self-rituous and superior.


答:
Most likely because the C library call invoked to get the value to return, returns months this way.

(And the reason for that design was most likely because the library call was designed along with the program to actually print the date, where a zero-based index could be used directly to print the month names)

Title: why getMonth() starts with 0

Body: I was coding a function to remove a day from a date value in javascript and i was kind of surprise that javascript's getMonth() starts from 0 for January to 11 for December. Why javascript's  getMonth() starts with 0?</p>


问:
How to transition a small team developing on a remote testserver from svn to git
At the company I work we use SVN. The SVN repository resides on the local server. When developing we commit the changes to SVN on the local server which transfers the changes via ftp to a testsite remote test server. The whole team uses the same testsite.
We use a remote testserver so that we don't have to setup anything on our local machines.
If developer A wants to see the changes of developer B on is local machine, he must simply update his working copy.

Most of the time we are very happy with this approach:

it's simple

svn is nicely integrated in Netbeans

Things that bother us are:

the changes are transfered via ftp. When transferring a lot of files
this can be quite slow

we would like to have a repository "in the cloud" so we can
develop not only from our office but from anywhere (and without have
to setup a vpn)

Is our workflow possible if we were to use github to host our repository?
These things are important to us:

we are not going to develop locally, we would still like to use a
testsite on a testserver that is shared by the entire team

because we do a lot of small changes pushing the changes to the
testsite should be very easy

we have a lot of small sites so the setup that a developer should do
per site should be minimal

答:
Have you tried looking Jenkins (used to be Hudson?)

We had some good experiences, where we set up a local Jenkins, and a remote Jenkins Slave on the external Test server that just updated his local copy of the svn, and compiled everything (ant+javac+stuff), deployed everything, restarted the JBoss instance.

All on the external test server.


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

答:
It's hard to get people to accept unit testing because it seems like a waste of time ("we could be coding another money-making project!") or recursive ("And then we have to write test cases for the test cases!")  I am guilty of saying both.

The first time you find a bug, you have to face the truth that you're not perfect (how quickly we programmers forget!) and you go, "Hmmm."

Another aspect of unit testing is that the code must be written to be testable.  Realizing that Some Code is easily testable and Some Code is not makes a good programmer go "Hmmm."

Did you ask your coworker why unit testing was only useful for external-facing APIs?

One way to show the value of unit testing is to wait for a nasty bug to happen and then show how unit testing could have prevented it.  That's not to rub it in their faces, that's to, in their minds, move unit testing from an Ivory Tower Theoretical to an in-the-trenches reality.

Another way is to wait until the same error happens twice. "Uhhh, well Boss, we added code to test for a null after last week's problem, but the user entered an empty thing this time!"

Lead by example.  Write unit tests for YOUR code, then show your boss the value.  Then see if the boss will call in pizza for lunch one day and give a presentation.

Finally, I can't tell you the relief I feel when we're about to push to prod and I get a green bar from the unit tests.


问:
If the purpose of a single complicated LOC is clear, would you bother to split it on to multiple lines to make its method clear as well?
Given some (relatively) complicated line of code, I would often be inclined to split it onto multiple lines to make its function/purpose clear to others.

However, if it is quite clear from context what a line does, would you still do the same thing merely to make clearer how it does it? Or would you take the attitude that future developers probably don't know/care how it works, only that it works?

For some context, the particular line that's prompted this question is Python code that takes a string like "1.title" and uses it to modify self.data[1].title:

```<code>#IRL, these 2 values are already set somehow
id = "1.title"
val = "foo"

setattr(self.data[int(id[:id.index(".")])], id[id.index(".")+1:], val)
</code>```

That last line is not the nicest thing in the world to read, so I was thinking of splitting it into:

```<code>index = int(id[:id.index(".")])
attrib = id[id.index(".")+1:]
setattr(self.data[index], attrib, val)
</code>```

If you wanted to go crazy, you could even do dotLocation = id.index(".") first, and use that in the setting of index and attrib.

This is probably a bit clearer to someone else reading it for the first time, but I prefer it nice and concise on one line, and it's highly unlikely that anyone is going to need to modify this one-line utility function. Is there really much point to splitting it up like that?

(Note: I'm fully aware that this is not exactly life-or-death stuff. I'm not going to lose any sleep over it,  I'm just wondering what others would do in this kind of situation.)

(Last thing: someone might want to add better tags to this, it's my first Programmers question :) )

答:
Single line statements are fine, when they can be read linearly, e.g.:

```<code>[r.name for r in rows].sort.splitIntoColumns(2)
</code>```

I find that yours:

setattr(self.data[int(id[:id.index(".")])], id[id.index(".")+1:], val)

is not as clear.  The repetition of id.index(".") breaks the reading flow, and it's a bit too low-level for me.  Why didn't you use split?

```<code> index, name = id.split(".")
 setattr(self.data[int(index)], name, val)
</code>```

That's only slightly longer, but seems quite clear to me.

Body:
Single line statements are fine, when they can be read linearly, e.g.:

[r.name for r in rows].sort.splitIntoColumns(2)

I find that yours:

setattr(self.data[int(id[:id.index(".")])], id[id.index(".")+1:], val)

is not as clear.  The repetition of id.index(".") breaks the reading flow, and it's a bit too low-level for me.  Why didn't you use split?

 index, name = id.split(".")
 setattr(self.data[int(index)], name, val)

That's only slightly longer, but seems quite clear to me.


问:
Sequel vs S-Q-L

Possible Duplicate:

  What's the history of the non-official pronunciation of SQL?

I hear it every so often, "In sequel server...", and for some reason I cringe every time. Maybe it's because SQL doesn't mean sequel, it means Structured Query Language. However, I hesitate to mention anything because it is a little bit nitpicking after all.

I do see the resemblance between SQL and sequel, but it's still wrong, is it not? Where does this way of phrasing come from?

答:
I assume this is due to the history of SQL. According to wikipedia, SQL was formerly known as SEQUEL (Structured English Query Language) until it had to be changed because SEQUEL was already a trademark of another company.

SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce
  in the early 1970s. This version, initially called SEQUEL (Structured
  English Query Language), was designed to manipulate and retrieve data
  stored in IBM's original quasi-relational database management system,
  System R, which a group at IBM San Jose Research Laboratory  had
  developed during the 1970s. The acronym SEQUEL was later changed
  to SQL because "SEQUEL" was a trademark  of the UK-based Hawker
  Siddeley aircraft company.

Moreover, I pronounce SQL "sequel" because it's easier for the tongue, you can say it more fluently.

Title: Sequel vs S-Q-L


答:
This is a good question and that name is of rather historical meaning:

SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL (Structured English Query Language), was designed to manipulate and retrieve data stored in IBM's original quasi-relational database management system, System R, which a group at IBM San Jose Research Laboratory had developed during the 1970s.[8] The acronym SEQUEL was later changed to SQL because "SEQUEL" was a trademark of the UK-based Hawker Siddeley aircraft company.

From http://en.wikipedia.org/wiki/SQL

After CS School I used to say ESS-QEW-ELL. But in a professional environment it just didn't seem right and made me start calling it "SEQUEL" - And it's so much easier to say, too.

Title: Sequel vs S-Q-L

Body:
Possible Duplicate:

  What's the history of the non-official pronunciation of SQL?

I hear it every so often, "In sequel server...", and for some reason I cringe every time. Maybe it's because SQL doesn't mean sequel, it means Structured Query Language. However, I hesitate to mention anything because it is a little bit nitpicking after all.

I do see the resemblance between SQL and sequel, but it's still wrong, is it not? Where does this way of phrasing come from?


答:
Saying Ess-Que-Ell is a burdensome mouthful. That's why I and nearly everyone else just relaxes and pronounces it sequel.

Who cares?

Title: Sequel vs S-Q-L


答:
We just moved from SVN to Git last month.  (We love it btw)  Jenkins is a great idea, but you can also do something pretty basic.  We set up a git clone on our test/nightly environment and have a cron job pull from source control every so often.  The cron script is a simple one line pull from git.  Because it's a repository clone, it only pulls updates and we can switch branches to test different things.

We are using a paid, secure github account right now rather than setting up our own secure git server.  The price is reasonable, and it's working very well for us.

Title: How to transition a small team developing on a remote testserver from svn to git

Body:
At the company I work we use SVN. The SVN repository resides on the local server. When developing we commit the changes to SVN on the local server which transfers the changes via ftp to a testsite remote test server. The whole team uses the same testsite.
We use a remote testserver so that we don't have to setup anything on our local machines.
If developer A wants to see the changes of developer B on is local machine, he must simply update his working copy.

Most of the time we are very happy with this approach:

it's simple

svn is nicely integrated in Netbeans

Things that bother us are:

the changes are transfered via ftp. When transferring a lot of files
this can be quite slow

we would like to have a repository "in the cloud" so we can
develop not only from our office but from anywhere (and without have
to setup a vpn)

Is our workflow possible if we were to use github to host our repository?
These things are important to us:

we are not going to develop locally, we would still like to use a
testsite on a testserver that is shared by the entire team

because we do a lot of small changes pushing the changes to the
testsite should be very easy

we have a lot of small sites so the setup that a developer should do
per site should be minimal


答:
Assuming you mean tables used as page layout rather than just for tabular data...

You're seeing tables because CSS is frustrating to use (admittedly less now than a few years ago). At some point one has to get work done. To do it "right" using CSS requires endless fussing and experimentation. Tables, on the other hand, can be grasped intuitively.

If you want to do it right (by using CSS) and you don't want to waste your life on CSS, the best compromise is to settle on a few different layouts and crib some CSS off of template websites. Use the templates as a starting point. Starting from scratch with CSS is a recipe for frustration.

Title: Why are so many HTML tables used in page markup?

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


问:
STDOUT and its impurity
I've read a lot of books and articles about functional programming and still ashamed of not being able to understand for sure some very basic concepts.

One of the main ideas of functional programming is that same input always should produce same output. Therefore, say, querying database or writing file could not be done in a pure functional style by definition. That's for example, is one of reasons we need monads.

The question is - why we consider STDOUT output as something impure? Yes, any filehandler is risky - we never can be sure that data always will be written. But what about STDOUT? Why should we think of it as of something unreliable? Is it more unreliable that evaluation itself? I mean, we always can pull the trigger and thus, interrupt calculation.

答:
While purity in a functional program is a worthy goal, the reality is that every non-trivial, useful program will have some impurity (or "side effects"), for the reasons you mentioned.

Completely pure programs are, by definition, a sealed black box, and are essentially uninteresting.

The functional language Haskell takes care of this problem by isolating side effects such as output in monads.  The monad preserves a purely functional style of programming, while still making it possible to produce output.

Title: STDOUT and its impurity


问:
Tips for planning a rewrite of a large PHP project?
I've decided to completely rewrite a PHP framework (Using MVC) that I've been working on, on and off, for years. My problem up until now was that I would just come up with ideas, throw them into Trac as tickets, and add them later - without worrying about the design of the framework itself. Over time this has caused some problems and I think a rewrite would be helpful, however I'm not sure where to begin with the planning of it - I know I don't want to use Trac, and I know I need more than just tickets and milestones - but what else would I need?

I really want to thoroughly plan this rewrite out, I want to detail every feature I want, where it will go, and how it will connect to every other part - but I have no experience with this level of planning. Any advice? Any programs that will help? I'm getting tired of Trac, I've never really liked it.

I know I'll need a design document, but is there any certain layout I should follow? I'll also need bug tracking, tickets, milestones, etc., but beyond Trac I don't know what's good for that either. I'm sure there's more I'll need but I have no idea what, so any help would be appreciated.

答:
What I enjoy using is Redmine as a schedule tracker.  IT handles each of those items very well, along with being so much more user friendly (in my opinion) than trac.

Regarding your re-write, it's important to first understand you will never anticipate every feature / new extension that can come up, so to try and write your application as flexible as possible.  Using many of the MVC frameworks which PHP has can help leverage this; however some of these frameworks also pidgin hole you if your DB architecture isn't flexible from the start (Cake). I would really focus on making things as abstract as you can, and whenever you see something hard coded ask yourself what it's for and why can't it be stored in a DB.

Really DB design helps answer so many questions and issues, and is where I see the main importance of how your application interacts; so I would recommend spending a good majority of time analyzing how the data is stored,  and how your DB is structured.

OwnerDisplayName: Jon

OwnerDisplayName: Frederico


答:
As a issue tracking software, JIRA is great, but it's very expensive. Another good tool that i'm using is Eventum. It's free.

But the most important part is to have a good idea of what you need.
First you have to gather the requirements for your application, to have an overall feeling about what you want and as complete as possible.

Based on that you will create software requirements, that is a more technical approach in which you'll describe the modules that will be part of your application, their functions and sub-functions, objects, classes, their interfaces, just about everything.

By know you'll have a good understanding of the complexity of the application and the lines of code needed, so you can make an estimate and create a schedule. It's important to have a schedule and deadline, or else you may end up never finishing it.

Hope it helps

Title: Tips for planning a rewrite of a large PHP project?

Body:
I've decided to completely rewrite a PHP framework (Using MVC) that I've been working on, on and off, for years. My problem up until now was that I would just come up with ideas, throw them into Trac as tickets, and add them later - without worrying about the design of the framework itself. Over time this has caused some problems and I think a rewrite would be helpful, however I'm not sure where to begin with the planning of it - I know I don't want to use Trac, and I know I need more than just tickets and milestones - but what else would I need?

I really want to thoroughly plan this rewrite out, I want to detail every feature I want, where it will go, and how it will connect to every other part - but I have no experience with this level of planning. Any advice? Any programs that will help? I'm getting tired of Trac, I've never really liked it.

I know I'll need a design document, but is there any certain layout I should follow? I'll also need bug tracking, tickets, milestones, etc., but beyond Trac I don't know what's good for that either. I'm sure there's more I'll need but I have no idea what, so any help would be appreciated.

OwnerDisplayName: Dan Bizdadea


答:
See below some things I do when developing a big project:

1 - I use a planning tool like OpenProj and add all the features I want to include as a task. For example, right now I am working on a feature to allow my users to automatically log on after they register in my site. I have a task in my plan like "feature-autologin".

2 - I am a one-man development shop so I usually move from one feature to the next. My plan is created in a way that all features are sequential. I don't invest too much time estimating how much time I will need for each feature. I usually consider that each one will take me a day to develop. If one takes more, I simply update the plan and all the future tasks move accordingly.

3 - I use git extensively. Each feature is a branch. Once I complete each feature, I merge it back to the development branch and create a new branch for the next feature.

4 - If I find a bug in the software I create a small git branch to fix it and merge it back once it is resolved. I make sure I update both the development branch and my current feature branch I am working on. By the way the bug becomes another task in my OpenProj plan. Something like "bug-wrong-address". And when I insert it, all the other features get moved back in the timeline.

5 - While I am developing, if I think about a new feature, I simply include it in the plan where I think it will best fit and adjust the timeline again.

I hope this helps. It sounds like you have an exciting project ahead of you. Good luck!

OwnerDisplayName: jdias


答:
Therefore, say, querying database or writing file could not be done in a pure functional style by definition. That's for example, is one of reasons we need monads.

Nobody "needs" monads, that's just one way to describe things. In fact, it's probably not even the best way. Some form of effect typing, uniqueness types, or a system based on full linear logic seem more persuasive in theory but are all more radical departures from well-known type systems and more complicated to express. Monadic IO as found in Haskell is a compromise between usability and simplicity, since it essentially models fully imperative programming in a way that coexisted easily with the existing ML-style type system already used in the language.

The question is - why we consider STDOUT output as something impure? Yes, any filehandler is risky - we never can be sure that data always will be written. But what about STDOUT? Why should we think of it as of something unreliable? Is it more unreliable that evaluation itself? I mean, we always can pull the trigger and thus, interrupt calculation.

It's not, and we don't. Input to, and output from, the program as a whole can be simply regarded as arguments and results from treating the entire program as one large pure function. As long as it prints the same thing to stdout if you feed it the same thing from stdin, it's still a pure function. In fact, before introducing monadic IO, Haskell used a stream-based I/O system that used pure lazy streams for input and output. It dropped it because it was apparently a pain to use, which may give you some idea of why you haven't heard of anything like this. :]

To make the point in a sillier way, consider the minimalist esoteric language, Lazy K:

Lazy K is a garbage-collected, referentially transparent functional programming language, with a simple stream-based I/O system.

What distinguishes Lazy K from other such languages is its almost total lack of other features. It does not, for example, offer an integrated Hindley-Milner polymorphic type system. It is not shipped with an extensive standard library with support for platform-independent GUI programming and bindings to other languages. Nor could any such library be written since, among other things, Lazy K does not provide any way to define or refer to any functions other than built-ins. This inability is complemented by a matching lack of support for numbers, strings, or any other data type. Nevertheless, Lazy K is Turing-complete.

(...)

Lazy K programs live in the same timeless Platonic realm as mathematical functions, what the Unlambda page calls "the blessed realm of the pure untyped lambda calculus." Just as garbage collection hides the process of memory management from the programmer, so referential transparency hides the process of evaluation. The fact that some calculation is necessary in order to view a picture of the Mandelbrot set, or in order to "run" a Lazy K program, is an implementation detail. That's the essence of functional programming.

(...)

How to handle input and output in a language without side effects? In a certain sense, input and output aren't side effects; they are, so to speak, front- and back-effects. So it is in Lazy K, where a program is simply treated as a function from the space of possible inputs to the space of possible outputs.

I doubt you'll find a more purely functional language than that!

Keep in mind, though, that the above applies only to essentially taking the input and output of a pure function and connecting them to stdin/stdout "externally" in some way. There's a big difference between that and having access to the real system-level I/O primitives. The implementation details of reading and writing to the streams may leak impurity unless carefully encapsulated.

I expect this is the main reason that you can't do this directly in Haskell--the sensible use cases are slim compared to using monadic IO, and for the latter there's a lot of benefit to having access to the real thing. I believe that's why, for instance, the command-line arguments to the program aren't simply passed as arguments to main, even though it seems intuitively that they should be.

You can recover a minimal version of something like this in a specific program, though--just capture the arguments as pure values and then use the interact function for the rest of your program.

Title: STDOUT and its impurity

Body:
I've read a lot of books and articles about functional programming and still ashamed of not being able to understand for sure some very basic concepts.

One of the main ideas of functional programming is that same input always should produce same output. Therefore, say, querying database or writing file could not be done in a pure functional style by definition. That's for example, is one of reasons we need monads.

The question is - why we consider STDOUT output as something impure? Yes, any filehandler is risky - we never can be sure that data always will be written. But what about STDOUT? Why should we think of it as of something unreliable? Is it more unreliable that evaluation itself? I mean, we always can pull the trigger and thus, interrupt calculation.


答: If you are going for a complete rewrite, why not also consider if you should be using php at all? A change/upgrade of technology might be the catalyst you want to improve your design/scalability/maintainability etc...</p>


问:
Unit testing newbie team needs to unit test
I'm working with a new team that has historically not done ANY unit testing.  My goal is for the team to eventually employ TDD (Test Driven Development) as their natural process.  But since TDD is such a radical mind shift for a non-unit testing team I thought I would just start off with writing unit tests after coding.

Has anyone been in a similar situation?  What's an effective way to get a team to be comfortable with TDD when they've not done any unit testing?  Does it make sense to do this in a couple of steps?  Or should we dive right in and face all the growing pains at once??

EDIT

Just for clarification, there is no one on the team (other than myself) who has ANY unit testing exposure/experience.  And we are planning on using the unit testing functionality built into Visual Studio.

答:
Practice on existing bugs/defects.

This is a really tough situation.  I've never gone all the way to TDD from nothing before, but in my experience, getting a team to go from no unit tests to proactively writing them has been a very "one step at a time" approach.

First, get them comfortable writing unit tests and knowing really what they are and their benefits.  For my teams, it's been best to write unit tests for existing bugs.  Current bugs in systems have two things that you need to teach people to write unit tests well:

an expected precondition and postcondition

an outcome that currently is not what is expected and violates that precondition/postcondition

This gives members very concrete practice examples.  They can write a test before they fix the bug, so that it fails.  Then, they can fix the code so that it passes, and fixes the bug.  Once they're comfortable with this, then you can get them the rest of the way so that they can write unit tests with no code up-front and then write new code to get their tests to pass.

I think the trick is to give them something to practice on where there are clear method pre/post-conditions.  If requirements for methods are fuzzy, it's hard for even experienced TDD people to know exactly where to start.  Take it a step at time and you'll get there.  Good luck!


答: Sometimes I base decisions like this on the ease of debugging the statements as separate lines.  Every so often, while debugging, a single overloaded line of code becomes an impediment because it obscures the intermediate results.</p>

Title: If the purpose of a single complicated LOC is clear, would you bother to split it on to multiple lines to make its method clear as well?

Body:
Given some (relatively) complicated line of code, I would often be inclined to split it onto multiple lines to make its function/purpose clear to others.

However, if it is quite clear from context what a line does, would you still do the same thing merely to make clearer how it does it? Or would you take the attitude that future developers probably don't know/care how it works, only that it works?

For some context, the particular line that's prompted this question is Python code that takes a string like "1.title" and uses it to modify self.data[1].title:

```<code>#IRL, these 2 values are already set somehow
id = "1.title"
val = "foo"

setattr(self.data[int(id[:id.index(".")])], id[id.index(".")+1:], val)
</code>```

That last line is not the nicest thing in the world to read, so I was thinking of splitting it into:

```<code>index = int(id[:id.index(".")])
attrib = id[id.index(".")+1:]
setattr(self.data[index], attrib, val)
</code>```

If you wanted to go crazy, you could even do dotLocation = id.index(".") first, and use that in the setting of index and attrib.

This is probably a bit clearer to someone else reading it for the first time, but I prefer it nice and concise on one line, and it's highly unlikely that anyone is going to need to modify this one-line utility function. Is there really much point to splitting it up like that?

(Note: I'm fully aware that this is not exactly life-or-death stuff. I'm not going to lose any sleep over it,  I'm just wondering what others would do in this kind of situation.)

(Last thing: someone might want to add better tags to this, it's my first Programmers question :) )


问:
Creating a Performance Model for a Legacy product
I've been given the task for creating a performance model for a legacy product. The product is about 10 years old and has never had any performance requirements or performance models before. Generally whats happened in the past is a customer will complain that a particular feature is slow or they are not getting the throughput that they want/need and the developers will investigate and see if any more performance can be squeezed out the code for the feature.

Since the product doesn't have any hard measurements and metrics for past versions I fell all I can do is create baselines for the current version and go from there. Other developers sometimes notice that memory usage is really high and ask why. Also, I am new to the product so I don't know all the feature points (which there are hundreds to thousands) and the performance cost of running each.

The program is an ASP.NET/.NET 2.0 webapp on IIS 6. I've started looking into performance counters and the CLR Profiler to start getting measurements. I've also read the following docs:

Measuring ASP.NET Performance

Improving ASP.NET Performance

So my question is: How can I create a performance model for a legacy product that I am new too and hasn't had a performance model/requirement in the past?

答:
Start with the web server logs to understand the profile of the load, how many users are using the system on a daily basis and which pages they are going to.   Most business processes will have leaf node pages which are distinct enough to allow for direct collection of how often a business process is completed within a given time window and matched to the number of users on the system.   If you have the logs for multiple years then by running the same set of queries on a regular sample basis, once every three months as an example, you will be able to show changes in usage patterns over time, including any increases in the user base.   These increases are critically important if you will be conducting performance tests so the load can be projected outward a good 12-18 months to see what performance will be like in the future.

Next, speak with product support within your organization.  This is an oft overlooked part of the organization which captures user expectations.   Check with their management and their logs/call coding to see what people call in on most often from a "slow" perspective.   These are your critical timing events.   You may have a general response time category for the interface, but these events that people call in on need to have explicit call outs in your performance requirements.

Speak with the business owners about your findings.   Use the findings as a framework for additional requirements/prioritization on what you have.   Most of the time additional requirements will come out of this discussion.

Incorporate these items into your standard requirements document for the product future revisions

Work with development to implement unit, component assembly and systems integration tests tied to performance as noted in the requirements.   It does not hurt here to have a feedback loop so developers can see a build to build difference in performance and also be assigned ownership for fixing performance which declines from build to build.

Measure performance in functional testing.   If it does not work for one, then it will never work for many.   The earlier you can find a performance defect the better because performance testing is usually the last 100 yards on the track before you ship.   The more time you can save up front the better.

Make sure your performance test tool can effectively test your interface and you are measuring against your critical timing points.

Once you make it to production find a way to measure the same elements on a consistent basis in production to see if what you are observing in production matched what you were seeing in test.   Modify your next generation requirements based upon your observations


答:
I would suggest to refactor heavily instead

The Problem you anticipate here:

I really want to thoroughly plan this rewrite out, I want to detail every feature I want, where it will go, and how it will connect to every other part - but I have no experience with this level of planning. Any advice? Any programs that will help? I'm getting tired of Trac, I've never really liked it.

is a real tough one. It is basically the Waterfall model with all its uglyness. Here's some anecdotical evidence for the problems with the 'great rewrite' approach, that comes to the conclusion: you will probably not anticipate the problems correctly, and end up with another mess you want to rewrite from scratch. Not because you're bad, but because it's impossible to get something big right in one shot.

When you instead start to refactor, you can write individual tickets and you can continue using the project. The trick here is to identify smaller changes that lead to an overall better design.

For example: you mention, you have no MVC, but you want to. As a first step, you could take a single PHP-file, and, assuming the usual mixup, sort it, so that in the top you have all db-access, calculation, etc, in the bottom you have the "templating" (first tickets, for each file). As a second step, you could encapsulate all these templating  parts into functions, that get their parameters passed. (a lot of more tickets). Done? Congrats, you finished your V in MVC.


问:
Is there a need for garbage collection in a stack-based language?
What is the need for garbage collection (GC) in a stack-based language? In a language like Forth or RPL (on HP calculators), is there a need for garbage collection?

I would think, since output is popped off the stack, that there wouldn't be any need. Am I missing something?

答: GC is normally applied to memory allocated on the heap. I'm not familiar with Forth or RPL, but if there is no heap, and everything is stored on a global stack instead, then there's nothing for GC to do.</p>


答:
I've been on teams that didn't do any unit testing but it was introduced and has become almost common to have some tests now.  I would suggest exploring how well does your team understand the basics of unit testing as well as what tools are you wanting to bring in here?

In my case it was bringing in nUnit for some .Net code that was a mix of business logic, user interface, and back-end functionality.  I would suggest seeing if there are some people that are more willin to want to get to it more than others so that a couple of people on the team get it and it can spread a bit better than the flip side where you try to get everyone to jump in on this.  By getting some to do it well first, this enables some cross-training so that those that pick it up can be tested as to how well can they teach it to someone else.

Another point is to consider bringing in those that have more expertise to try to show this off to some extent.  Thoughtworks was brought in where I work to show us some stuff that some of it did get widely adopted and other parts not so much, but I think that would be true in most places.

Title: Unit testing newbie team needs to unit test

Body:
I'm working with a new team that has historically not done ANY unit testing.  My goal is for the team to eventually employ TDD (Test Driven Development) as their natural process.  But since TDD is such a radical mind shift for a non-unit testing team I thought I would just start off with writing unit tests after coding.

Has anyone been in a similar situation?  What's an effective way to get a team to be comfortable with TDD when they've not done any unit testing?  Does it make sense to do this in a couple of steps?  Or should we dive right in and face all the growing pains at once??

EDIT

Just for clarification, there is no one on the team (other than myself) who has ANY unit testing exposure/experience.  And we are planning on using the unit testing functionality built into Visual Studio.


答:
Yes, you're right. But the stack basedness is just a part of the whole story. For example, the Java bytecode interpreter is stack-based as well (the compiled code works -- for efficiency reasons -- differently). This tells us, that any language can be transformed into a stack language.

What matters are the objects outside of the stack, those who can outlive the current method execution. As long as the language has nothing like malloc or new, there are no such objects and you need no delete nor GC.

A language lacking dynamic memory allocation is quite limited in its usefulness.

Title: Is there a need for garbage collection in a stack-based language?

Body:
What is the need for garbage collection (GC) in a stack-based language? In a language like Forth or RPL (on HP calculators), is there a need for garbage collection?

I would think, since output is popped off the stack, that there wouldn't be any need. Am I missing something?


问:
Moving from one man project to team project in the future. What should I be doing now in preparation and what can wait?
To elaborate I am interested in knowing what people think you need to put in place while still a one man project (team source control, documentation, builds etc) and what things don't need to be done until that point when the second person comes onto the project.

Anyone with any experience of moving through this scenario, their insights will be appreciated.

答:
My take: Start with document your internal project's architecture for someone... who is not aware of it. Try to explain which assumptions are in place and when/where you diverted from common practices and why.

Build automation: Great idea, may I add configuration automation for a dev machine. The easiest it is to build the more it will be (so more/faster testing deployment).

Another idea (it helped me a lot once): Ask the new developer to do some clean-up small scale tasks in different areas of your code base, so that he will get accustomed to the layout tools etc. One good idea is to remove obscure areas that might add confusion later on (example: if you used emmm python for two lines of a shell script somewhere and your project is based on java, ask those two lines to be rewritten in java so that the developer #3 will need to know less in order to work)


答:
Consider using an existing framework. CakePHP, Zend Framework, CodeIgniter and Symfony are the known ones for PHP. If they cater the needs of hundreds or thousands of users, I'm sure they can cater yours.

If you're willing to learn/use something other than PHP - Django (Python) and Rails (Ruby) are pretty much the leading frameworks for conventional web applications.

That's, of course, unless you want experience creating frameworks - which, I might add, is of much less value in the market (rather than knowing how to use existing, supported frameworks well).


问:
Can GPL-licensed software be resold?
My research group is developing some software for research purposes. The project leader wants the software to be open source and likes the GPL, but wants to ensure that they software cannot be sold.

Are we reading the GPL correctly? The software can be freely modified, (re)distributed, and sold? If so, I see why it would be difficult to effectively sell the software; however, the GPL isn't quite strict enough for our needs.

Any suggestions?

答: You may sell as many copies of GPL software as you can move, but you have to release the source for free.</p>

Title: Can GPL-licensed software be resold?


答:
Writing to STDOUT can fail if you're not connected to a terminal device, or if you (for some reason) closed the file-descriptor for it.

Also, STDOUT is not always "the console screen". Sometimes it's piped to another program. Sometimes the pipe is broken.

Title: STDOUT and its impurity


答:
What I've learned.  (I tried a different order.  I was wrong.  This is the order in which things become relevant.)

Put everything into source code control.  Use something everyone has access to and start right now.  No exceptions.  No delays.  No excuses.

Create a QA/Test area that is totally separate from your personal "working" or "development" environment. At least a separate user id. Ideally on a separate VM.

Completely separate.  No possible overlap with your current working environment.

Stop testing beyond unit test in your own working environment.  Code and unit test you do "as yourself".  All other testing (integration, performance, whatever) you do on the separate VM.  Never test as yourself.  Always test as a separate QA user.  Ideally on a separate VM.

"Works for me," is a bad thing to have to say to your team member(s).  Very bad.  You need to figure out what they're doing wrong.  Several times a day.

Plan to write down everything.  Use a plain-text markup tool (RST or Markdown or something) so that all documentation is plain-text in the version control repository.  A tool can create HTML pages (i.e., Docutils for RST) or PDF's or whatever seems best.  Don't use proprietary document formats (i.e. MS-Word).  They may not play well with some source-code control systems.

The first things you need to write down are the following.

How to create a working development environment.  When in doubt, create a Virtual machine and do the entire operation on that virtual machine.  Be sure that the steps really work and the documentation is clear.  Actual lines typed at the actual command line kind of clarity.

How to run the unit test suite.  Again.  Be sure that the instructions work and do not require thinking.  "Type this:" "Confirm that:" kind of stuff.  It's not that your team members are stupid.  It's that you don't remember what you're assuming unless you write it all down.

How to run the integration test suite.

Don't waste a lot of time describing the architecture or the design principles.  You need to get someone up and running first.  You can explain stuff later.

The next things to document are the user stories.  And the test cases that support those stories.  And the data fixtures required for the test cases that support those user stories.

You will be sharing this.  It goes under source code control.

Eventually, you can document the other 4 views.

Logical view is helpful stuff to document.  Pictures are acceptable here.  This tends to evolve rapidly, so don't spend time capturing the legacy information.  Work out a way to cooperate with your team member(s).

Process view is often helpful.  Depends on the overall application how important this is.

Development view -- modules, libraries, frameworks, etc. -- is often described informally.  A picture might help, but it's notoriously hard to make this complete enough that someone can pick up a document and make heads or tails of it.  Even long-established, very public projects have library documentation that is simply ignored.  (Leading to a lot of Stack Overflow questions.)

Besides being acceptable to be informal, this tends to change rapidly.

Deployment information.  Servers.  IP addresses.  Database credentials.  All that stuff must get written down.  Eventually.

Title: Moving from one man project to team project in the future. What should I be doing now in preparation and what can wait?

Body:
To elaborate I am interested in knowing what people think you need to put in place while still a one man project (team source control, documentation, builds etc) and what things don't need to be done until that point when the second person comes onto the project.

Anyone with any experience of moving through this scenario, their insights will be appreciated.


答:
I would focus on automating everything which require manual work, thus can be screwed up by an inexperienced person. Which, based on your brief comment above, includes the following:

install version control and replace the manual backups with automated ones,

set up automatic deployment as much as possible (as the minimum, write a script to deploy via FTP rather than doing it by hand.

If you fail to do these, either you will get chained to do these tasks forever, or (some of) the new guy(s) will inevitably screw up something sooner or later.

The other important task is, as @dimitris noted, documentation. @S. Lott added much more detail on this, so just +1 to him rather than repeating :-)


问:
What should I expect from a technical evaluation for C++?
I have been asked to go for a technical test/evaluation for a job as a junior developer, mainly using C++. This is my first test/evaluation, and it is 2 hours long.

My C++ is a bit rusty as I have been doing projects recently on PHP.

This is a UK company, however im guessing technical testing of candidates will be pretty much the same everywhere.

What should I expect in one of these tests?

答:
Are you:

Writing code

taking multiple choice

In person interview

When writting code

They will expect you to know (and use):

RAII

The Rule of three

Understand smart pointers

They will probably test you on:

Inheritance

Virtual functions

Serialization to/from a stream

overload the arithmetic operators (not often used in real life but easy to write a test around).

If you are unlucky they may think

Multiple inheritance and virtual base classes is something you should know.

Its not but some people go hog crazy.

When taking multiple choice

Understand all the OO terminolgy

Know the C++ ways of implementing OO

In Person Interview

All the above.

Knowledge of recursion

How to convert recursion into a loop

How to estimate Big O() complexity

The standard sorting algorithms (not just bubble).


答:
My suggestion is to not worry about it. Under the GPL, while you can sell it, there's really no point in buying it. Potential buyers can simply go get the source and compile it themselves. And if the build process is difficult, it just takes one person to figure it out and host the version with an automated build.

The only reason I've seen to directly sell GPL software is for people that have a lousy internet connection, and want it delivered to them on a physical medium, like a DVD.

Ask you project lead why he doesn't want people to sell the software. The GPL will probably suffice.

Now, you can make money on the open source model, but it has to be done at oblique angles. People could, for instance, take your code and become experts at it. They could then sell their support to your end-users. They could also seek commissions for further developing your code-base. The GPL doesn't block this. If you have problems with either of those, make your own license.

Title: Can GPL-licensed software be resold?

Body:
My research group is developing some software for research purposes. The project leader wants the software to be open source and likes the GPL, but wants to ensure that they software cannot be sold.

Are we reading the GPL correctly? The software can be freely modified, (re)distributed, and sold? If so, I see why it would be difficult to effectively sell the software; however, the GPL isn't quite strict enough for our needs.

Any suggestions?


答:
What has been posted has been great so far, but I'll add something and a story! I would say practice applying what you know in C++ to problems in the domain of the software company. It's great if you know all the ins and out of C++ but if you can't apply to a problem, you're useless to the company. Seeing as this is a junior dev position, I wouldn't think they would expect you to know everything about C++.

I took my first technical test for my first developer job last week and was surprised at what I found. I was expecting something like FizzBuzz or something more nitty gritty (this was for Java, btw) but what I found was they gave me a file and had me parse it to a new format, which is what part of the job was. On top of that, they let me use Google and their own libraries. Bottom line, you need to know C++ but if you want to know what the test may be like, take a look at the domain of the position you're applying for and work on implementing C++ towards something in that domain.


问:
how to start with ASP.NET MVC 3 razor
I going to start a new project in my company in which are involved the use of MVC 3, now this is the first time that we are using this framework, and i have a couple of questions,

It's recommended to start with MVC3 and not from the MVC2?

Any Tutorials in specific that you can recommend?

This framework have full integration with jQuery?

答:
Yes, use MVC 3 first. Having Razor is such a boon to productivity, I find.

The Plural Sight video tutorials on the ASP.NET website are very good

Yes, the framework has brilliant integration with jQuery as standard

Title: how to start with ASP.NET MVC 3 razor


答:
The easiest and safest for you is to license under a Creative Commons Non-Commercial. Including further options for limiting like No Derivative Works.

See: http://creativecommons.org/

Using this would disallow commercial use of the product without you having to modify the license.

SO uses the CC license for this content but it can be used for any published medium.

Title: Can GPL-licensed software be resold?


问:
can a team lead's work ever be done working remotely
I am currently a software developer. As a next milestone in my career I am thinking I must establish myself as team leader which leads a small development team in order to meet deliverables, deployments, etc. I've read various post in this site itself which discusses the pros and cons of working from home. But I am not sure if this aspect was quite discussed/debated. I haven't stepped into the team leading role per se, but I would like to know the responsibilities that come with the title, and if (and how) that can be managed while working from home.</p>

答:
I have worked with many Team Leads that are remote and do so myself. It is no different than anything else remote. Just need Chat, Email, Phone, and various Tools for remote work (Version Control, etc...)

Meetings are over phone, developers communicate via Chat, private messages are via Email, and code is centralized in a version control system.


答:
It helps if you think of purity in terms "Changes the state of the outside world". That could include writing to a console, log file, ejecting the CD or "Launching the Missiles". </p>

<p>It also can be an issue in terms of concurrent execution. If you know a function has no side effects you can easily arrange for concurrency as you can prove that there can be no race conditions or the like. </p>

Title: STDOUT and its impurity

Body:
It helps if you think of purity in terms "Changes the state of the outside world". That could include writing to a console, log file, ejecting the CD or "Launching the Missiles".

It also can be an issue in terms of concurrent execution. If you know a function has no side effects you can easily arrange for concurrency as you can prove that there can be no race conditions or the like.


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

答:
Since you apparently live in the US, this would be subject to US law.

US law (at least in most states -- contracts fall under state law) has a a provision that says a court cannot enforce contract provisions that are "unconscionable". Although I'm not a lawyer, my immediate guess would be that a couple of the clauses you've mentioned would be deemed unconscionable by any court -- at least those saying you agree a priori to any changes they might make in the future, and the one saying that if you're accused of violating the agreement you won't defend yourself. As such, I doubt they could enforce those clauses even if you did agree to them.

At the same time, my immediate reaction would be to run away as fast as you can. Unless other aspects of the job are extraordinarily great, I wouldn't even try to negotiate better terms. IMO, you've seen enough to know that these people are thoroughly unethical, and that is reason enough to just stay away. Even if they did eventually agree to treat you decently, the fact that they even tried to get you to agree to this indicates that it's better to move on to a better opportunity (and nearly anything, including flipping burgers, would qualify as better, in this case).

Edit:

Assuming this opportunity is in South Carolina, the following definition would apparently apply:

In South Carolina, unconscionability is defined as the absence of meaningful choice on the part of one party due to one-sided contract provisions, together with terms that are so oppressive that no reasonable person would make them and no fair and honest person would accept them.

(Quoted from the S.C. Supreme Court decision in Simpson v. MSA of Myrtle Beach.)


答: Pro ASP.NET MVC 3 Framework by Adam Freeman and Steven sanders is a one stop learning for MVC framework with hands on project development. Hope this one fulfils your appetite for learning MVC </p>

Title: how to start with ASP.NET MVC 3 razor

Body:
I going to start a new project in my company in which are involved the use of MVC 3, now this is the first time that we are using this framework, and i have a couple of questions,

It's recommended to start with MVC3 and not from the MVC2?

Any Tutorials in specific that you can recommend?

This framework have full integration with jQuery?


答:
Should the company decide to prosecute me for breach of contract that
  I agree not to defend myself

Does this mean you are agreeing to mandatory binding arbitration? Credit card companies like to use this trick. When the company is  paying the arbitrators they rarely find in favor of the individual.

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.

Can this legally be put in the contract? If this would hold up in court it would give your employer carte blanche to add whatever they wanted to a new contract and force you to sign it.


答:
"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."

IANAL.

This clause is unenforceable.  At the very worst, they can dismiss you for not signing the amendment, but they can't hold you legally responsible for an amendment you didn't sign.

After my employment ends at the company I would be required to
  continue my duties there to assist in the perfection of its software,...

Wow.  Just WOW!!! "You're fired, but you have to keep showing up without pay until the release is PERFECT!"

Should the company decide to prosecute me for breach of contract that
  I agree not to defend myself,...

At this point, A British Army Colonel will pop up and say, "OK, Stop that, it's getting silly!"  This is a fundamental violation of the principles of justice in almost any (democratic) jurisdiction.

My bet is that after consulting a lawyer, (On your own dime!) He or She will tell you to sign it, because the entire contract will be thrown out by a judge before it even gets to a hearing.  Then I'd talk to the lawyer who drafted the contract, and report him to the local bar.  This is the type of thing lawyers get disbarred over.


答:
I agree that any breach of the contract would inflict irreparable harm on the company.

Generally, this clause is added because it enables the company to get a restraining order without having to prove to the court that some damages have occured. Without this clause, it will take time to get a court hearing in order to allege damages and several months could go by before they could get their restraining order against you.

Everything I develop while under the company's employment is its property

Again, this is a common clause. Some are better worded, some I've seen appear exactly as you've summarized it here.

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

This is one where you push back and walk away from the table. The part before the comma says you will continue to work for free after you quit or are fired.

More and more states are enforcing non-compete clauses. You don't want to sign any that can come back to bite you. Part of what makes it so easy for companies to screw you over are social networking sites like Facebook or LinkedIn ("I started working for blah..."). In the past, they had to work in order to find this out, but now you do the work for them.

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.

This is another "just walk away" claws.

Should the company decide to prosecute me for breach of contract that I agree not to defend myself

This is where you crumple the thing up and throw it in the face of whoever handed it to you. Never sign anything like this. Not even if you are starving and about to die. This goes along with the "irreparable harm" clause to make getting a restraining order against you automatic to the point where the court doesn't even bother to notify you.


问:
Should Professional Development occur on company time?
As a first-time part-time software developer at a small consulting company, I'm struggling to organise time to further my own software development knowledge - whether that's reading a book, keeping up with the popular questions on StackOverflow, researching a technology we're using in-depth, or following the front page of Hacker News. I can see results borne from my self-allocated study time, but listing and demonstrating the skills and knowledge gained through Professional Development is difficult.

The company does not have any defined PD policy, and there's a lot of pressure to get something deliverable done now! when working for consultants. I've checked what my coworkers do, and they don't appear to allocate any time to self-improvement; they just work at the problems they're given, looking up specific MSDN references, code samples, and the like as they need them.

I realise that PD policy is going to vary across companies of different size and culture, and a company like my own is probably a bit of an edge case. I'd love to hear views and experiences from more seasoned developers; especially those who have to make the PD policy choices in their team or company.

I'd also like to learn about the more radical approaches to PD, even if they're completely out there; it's always interesting to see what other people are trying.

Not quite a summary, but what I'm trying to ask:

Is it common or recommended for companies to allocate PD time?

Whose responsibility is it to ensure a developer's knowledge and skills are up to date?

Should a part-time work schedule inspire a lower ratio of PD time : work?

How can a developer show non-developer coworkers that reading blogs and books is net productive?

Is reading blogs and books actually net productive? (references welcomed)

Is writing blogs effective as a way of PD? (a recent theme on Hacker News)

This is sort of a broad question because I don't know exactly which questions I need to ask here, so any thoughts on relevant issues I haven't addressed are very welcome.

答:
If the company has a mature development team then there may be time allocated to professional development as part of the overall process.  On the flip side, I've seen in start-ups where you don't have professional development done on the company dime as the company is struggling to survive in some ways so there are bigger fish to fry in a sense.

The developer has most of the responsibility for keeping their knowledge and skills up to date though I would note that often a developer will have to refine skills as needed.  For example, of the hundreds of applications my company uses which ones do I really need to know in-depth versus just having a passing knowledge of the API I'd connect for my part of the system I'm building.  There is also something to be said for date here having a couple of connotations.  While there is one that is knowing the latest and greatest, the other side is that what the company uses may differ and that is the version to know really well.

A part-time work schedule shouldn't be a factor in deciding how much time to spend on professional development versus work to my mind.  The question is how well would your boss handle this.

Depending on which non-developer co-workers, this could be useful or useless.  If we are talking about people that you rarely communicate on a regular basis, then this may not be a good idea.  On the flip side, your manager and those who work on projects with you may ber another story though in this case the key is to use what knowledge you gain from blogs and books to some extent.  To some extent, using Google Fu to find how to do something is up this alley to my mind and would be a starting point if you want to get some things unblocked by things like Websense.

Reading blogs and books is productive if you are getting something out of it.  For example, if you are a web developer that usually works on database-driven websites where there aren't any advanced Mathematics needed, then reading about numerical analysis and symbolic computation may not be that useful.  On the flip side, reading Refactoring may be useful if you want to know more about the subject and weren't taught a lot about it.

Writing blogs would fall into that category of questionable professional development to my mind.  If you are doing it with an eye towards getting feedback and developing your skill then I could see it working.  On the other hand if you are doing it purely to stroke your own ego, then I'd question the effectiveness so it can go both ways.