答:
Case 1. When this is your own code:

In general, you only need to put Copyright notice in the work (here source code). The license doesn't require a mention.

For example, for Apache license doesn't need any such reference.

However, GPL specifically wants that you reference GPL License word inside each source code.

the process involves adding two elements to each source file of your
  program: a copyright notice (such as “Copyright 1999 Terry Jones”),
  and a statement of copying permission, saying that the program is
  distributed under the terms of the GNU General Public License

from: http://www.gnu.org/licenses/gpl-howto.html

In this case, to avoid the interpretation that the code is  uncondtionally GPL'ed, it makes sense that you either specify additional clause like

"subject to terms and condition provided in LICENSE.txt"

Case 2: If you are modifying the other person code:

You cannot do -dual license, and also you cannot modify anything on the source that provides licensing information.

BTW: There is one simpler alternative that is obvious.

If you make identical copy of the code which has no mention of GPL at all and you use that copy for the Commercial or alternative license.

But this might just be too cumbersome.

Title: Should I include multiply license header notice in dual license software?

Body:
Is it necessarily if a software released under both of LGPL3 && GPL3 terms have to include both license header notice top of each file?

Or just put GPL header notice? or simply put LGPL3 license text in some file like COPYING.LESSER ?

EDITED:

I am the copyright holder of the project!


问:
Is it a problem to have different styles of HTML coding within team?
I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a programming language we have very different styles evolving. I mean whenever we look at each other's code, we tend to put a good amount of time in understanding why the other one does that.

Now we want to build a larger website together and my question is- Is that a problem having very different styles in a team for web development(specifically)?

答:
If you're going to be regularly working on each other's code, you're going to need to be able to read it. Other people might even need to read it.

You can learn to read different code styles, but the problem emerges when you have to switch mindsets when you're looking at different sections of code. There's a very noticeable cost involved in this switch. Sometimes it's unavoidable, like switching from reading a Functional lang to reading Object Oriented code, but when you have to switch how you read just to read random pages of your site's code, it adds up fast.

If you both need to work on each other's code regularly, that cost is going to add up, and you're probably going to get into some discussions regarding code style: "Why the %$^% are you doing that?"

Additionally it is important that even if all your HTML pages are separate and don't need to be consistent in how the use IDs, classes ect, your CSS and your backend do need consistency. For your CSS to make sense you need to work out how you're going to use classes vs IDs and your naming for elements. Your forms are going to need some standards because the variable names you use for your forms go back into the server layer, and they need to map well to database inputs where relevant.

I also certainly wouldn't discard the notion of readable code since it's a markup language rather than a programming language; if anything it matters more in markup because your code isn't compiled, and non-semantic markup might actually display improperly or have accessibility issues.

ContentLicense: CC BY-SA 3.0


问:
How can I document someone else's past work?
We're in a bad situation of having very little documentation on customization our past workers made to a business critical system. Lots of changes were done to Crystal Reports, database entities, and proprietary configuration/programming files for our ERP software.

The current documentation generally reads something like this:

This program is run before invoicing. Known bugs: none.

Run this program after installing software X.

Changed the following fields in this report: (with no explanation of how or why)

Our IT shop is small, and in the case of the ERP software, most work was lumped on one person (that's me now) so no one else here knows what all we did. The IT and accounting department know bits and pieces (occasionally quite helpful ones) but it's not enough.

Another problem is our Accounting department seems to think we're well documented. It's true that we kept lots of records of what went wrong, but very little explains what (if anything) was done to fix these problems. We have hundreds of papers explaining bugs, but the documents explaining changes (as shown above) are almost useless.

How can I go about documenting past changes when I don't know what all was done? I can start with documenting what we've changed: Files, database tables ect which we need to have for the system to work. I can also document what we do; when reports are run, why people were told to use X report/program. But when one of these customized things has a problem, I'm always back to square one.

How can I proactively document this stuff for myself and others?

答:
First things first. Where are you storing your documentation? If you haven't already, set up a wiki. I prefer dokuwiki myself, and there is even a prebuilt vm, if you are so inclined.

This provides some important features:

Docs can be accessed anywhere on the company lan (installing on new computer...)

All docs are in one place

All docs are searchable

You can collaborate (new colleague, users of the software)

Now, if your documentation is in paper form then I wish you the best. If you have word docs, build an import script.

Finally, just use the stuff. Whenever you need to install something, put notes in the wiki. If you hit an edge case, put it in the wiki. This is where collaboration can shine, since you get other people to do the work for you.

Moving on to more specific documentation, if you need to work with the source for various projects, make sure you have a proper development environment set up! For a checklist of stuff you should have:

Version control (git, mercurial, fossil)

Bug tracking (trac, mantis, redmine, fossil)

Build system (autotools, scons, buildbot)

Project control (eclipse, specified directory structure, editor plugin)

Source documentation (README, TODO, INSTALL, Source comments)

Finally, because documentation can be boring, make it a game. Give yourself "points" for each item in your checklist, periodically checking your "score". It's a good way to see what you've accomplished, and how well. It also maps out where you need to go next.

Look at this as an opportunity to learn many things about how to set up a proper dev environment, and don't be afraid to try things and move on. Find something you like and migrate the environment over so that things are better. Approach this as a project where you are looking to build the best solution.

Edit:

As per rig's comment below, another useful thing to do is create diagrams of the source code. Freecode has stuff, and this article lists some for popular languages.


问:
Would you allow your programmers to use Messenger and social networks like Facebook?
I had many bosses, each one had a different approach about allowing or not use of Windows Live Messenger, Facebook, and many other Internet sites.

Of course Internet is really needed to research about the best way to solve a specific task. Sometimes you could have a friend online, also a programmer, who knows better about something.

For some managers, internet access would slow down project progress, and on the other hand, allow people to interact and find out brand new solutions.

What would you do?

答: In a team of developers it very quickly becomes clear who is productive and who is not.  IMHO, banning IM or Facebook will not make bad programmers any more productive, but it certainly will negatively affect the morale of the good ones.</p>

ContentLicense: CC BY-SA 2.5


问:
Which statically typed languages support intersection types for function return values?

Initial note:

This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values.

Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.)

Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how?

(If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.)

I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#:

```<code>interface IX { … }
interface IY { … }
interface IB { … }

class A : IX, IY { … }
class B : IX, IY, IB { … }

T fn()  where T : IX, IY
{
    return … ? new A()
             : new B();
}
</code>```

That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.)

P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately.

Footnote: Some resources about intersection types:

Wikipedia article for "Type system" has a subsection about intersection types.

Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism"

David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article.

A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.

答:
C++ functions all have a fixed return type, but if they return pointers the pointers can, with restrictions, point to different types.

Example:

```<code>class Base {};
class Derived1: public Base {};
class Derived2: public Base{};

Base * function(int derived_type)
{
    if (derived_type == 1)
        return new Derived1;
    else
        return new Derived2;
}
</code>```

The behavior of the returned pointer will depend on what virtual functions are defined, and you can do a checked downcast with, say,

Base * foo = function(...);dynamic_cast<Derived1>(foo).

That's how polymorphism works in C++.

Body:
C++ functions all have a fixed return type, but if they return pointers the pointers can, with restrictions, point to different types.

Example:

class Base {};
class Derived1: public Base {};
class Derived2: public Base{};

Base * function(int derived_type)
{
    if (derived_type == 1)
        return new Derived1;
    else
        return new Derived2;
}

The behavior of the returned pointer will depend on what virtual functions are defined, and you can do a checked downcast with, say,

Base * foo = function(...);dynamic_cast<Derived1>(foo).

That's how polymorphism works in C++.


答:
I think this is a futile exercise. If it works it works, if it doesn't work, you have to fix it.

The best way to document old stuff is as you work on it, document what you are doing and explain the business logic (which I assume was not documented). This will be a big help for any new developer.

Speaking of documenting old code/things, someone had to own it. Lets assume this is your current manager. He/she might not have full technical knowledge of it but will know what changes were made. In that case, it is not your job. May be the manager can write something about it what changes were made. That would be helpful to keep as history. If problem like that arise you can dig into those areas, that might be very helpful to you. But going into the code and document the changes is pretty useless IMO and probably impossible.

Title: How can I document someone else's past work?

Body:
We're in a bad situation of having very little documentation on customization our past workers made to a business critical system. Lots of changes were done to Crystal Reports, database entities, and proprietary configuration/programming files for our ERP software.

The current documentation generally reads something like this:

This program is run before invoicing. Known bugs: none.

Run this program after installing software X.

Changed the following fields in this report: (with no explanation of how or why)

Our IT shop is small, and in the case of the ERP software, most work was lumped on one person (that's me now) so no one else here knows what all we did. The IT and accounting department know bits and pieces (occasionally quite helpful ones) but it's not enough.

Another problem is our Accounting department seems to think we're well documented. It's true that we kept lots of records of what went wrong, but very little explains what (if anything) was done to fix these problems. We have hundreds of papers explaining bugs, but the documents explaining changes (as shown above) are almost useless.

How can I go about documenting past changes when I don't know what all was done? I can start with documenting what we've changed: Files, database tables ect which we need to have for the system to work. I can also document what we do; when reports are run, why people were told to use X report/program. But when one of these customized things has a problem, I'm always back to square one.

How can I proactively document this stuff for myself and others?


问:
Is this a proper implementation of an iOS MVC pattern?
After browsing the apple docs, I came across this sample of their MVC pattern:

Using NSNotificationCenter and without using KVO, would this diagram below represent a correct implementation of the MVC pattern?  If not, what’s wrong and how can it be corrected or improved?

App starts with the left light set to on, and the right one off.  Only one light may be on at a time.

Users presses the right switch, which sends a target action to the view controller.

The view controller receives the message, and send a message to the right light data model.

The right light uses NSNotificationCenter to notify the controller the right light has changed.

The controller receives the message, and performs the following method

BOOL rightLightOn = [rightLightData on];
    if( rightLightOn )
    {
      [rightLightImage setImage:onImage];
      [leftLightSwitch setOn:NO];
    }
    else
    {
      [rightLightImage setImage:offImage];
    }

The switch change causes the UISwitch to call the method “leftSwitchChanged” in the controller.

The controller receives the message, and send a message to the left light data model.

The left light uses NSNotificationCenter to notify the controller the left light has changed.

The controller receives the message, and again performs the same method shown above, but modified for the right light.

In addition, what if the system wasn’t using a switch, and instead was using a UIButton that displayed the text, “Turn On” or “Turn Off.”  Would the switch update it’s own text, then call “rightSwitchChanged” or would it call rightSwitchChanged immediately and wait for the view controller to change the text?

答:
Does it fulfill your requirements?

MVC, like all such software patterns, is subject to evolution.  There is no "right" or "proper" way.

For example, it's possible to bolt on a Javascript library to ASP.NET MVC, and have Model-View-ViewModel, where most of the client action actually takes place in the browser.  Some argue that this is a "purer" approach, and there are certain advantages to doing it this way.

Don't be an architecture astronaut, or get locked in to someone's idea of the "right way."  Do what works.


答:
Abandon your effort to document changes.

Instead, start documenting what currently works, and how. Keep that documentation up to date and current as you make changes in the future.


问:
Is it reasonable to run processes with CI tools?
At my company, we have a quagmire of disparate cron jobs (on multiple systems) and manually kicked off processes which keep our business functioning that is a result of years of expedient development and subsequent neglect.

Someday, we will need to come up with a more centralized solution for obvious reasons.

One thought that we have been kicking around is to use our Continuous Integration software (Jenkins) to run these processes, which seems logical.

My question is: Are other companies doing this? Is this a generally accepted practice? Doesn't this conflict with the definition of a CI tool implicit in its name? Are there any other options?

Note:
https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Jenkins claims that it focuses on "Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs". I'm not sure if this is exactly what I am talking about.

答:
I would have said that you're not using the right tool for the job here as the main point of CI tools is that they monitor something - your source code typically - and when there's a change they kick off a build/deploy/what ever.

However, these tools can run scheduled jobs (TeamCity does for example), so you can deploy a web site (for example) when there's no one around. So having a single central list of all the tasks you run is in fact a good idea. The tools should also allow you to decide when and how often these jobs are run.

Another benefit is that you can even monitor the system remotely (should you wish).

So, on balance, I'd say it was a sensible thing to do.


问:
Prepare source code handover plan
Our company is about to acquire a source code of a huge product.

What are thing to take into consideration when the handover starts, to make sure we have everything and be capable to maintain that product in the future?

答:
Does the code come with a test-suite?
Do all the tests in the test-suite pass?
How much coverage does the suite have?

I would recommend that, missing a test-suite, you make building the test-suite and related framework your first priority.

Title: Prepare source code handover plan


答:
You could write automated exploratory tests. These have several advantages :

You learn how the system works as you write them

They serve as executable documentation for later

If you run them on a regular or even continuous basis, they provide a nice security net to detect when changes break something or when they need to be updated

I don't know if it is feasible to write that kind of tests in your particular environment though.


答:
My gut reaction is the same, that you are using a tool that has a concept of schedule in it, to do the work of a job scheduler.

You've not mentioned what your jobs are, but your mention of CRON makes me guess they are shell scripts, etc. There are open source and commercial job scheduler packages out there. Sometimes they are referred to as batch schedulers. Some will just wrap up CRON and make it friendlier. Some, like Quartz scheduler, does powerful management of jobs, but requires them to be implemented as Java classes. You could potentially use that, and wrap up the runtime calls to your various scripts using a java wrapper. I believe you'll find plenty of options if you look further.

Title: Is it reasonable to run processes with CI tools?

Body:
At my company, we have a quagmire of disparate cron jobs (on multiple systems) and manually kicked off processes which keep our business functioning that is a result of years of expedient development and subsequent neglect.

Someday, we will need to come up with a more centralized solution for obvious reasons.

One thought that we have been kicking around is to use our Continuous Integration software (Jenkins) to run these processes, which seems logical.

My question is: Are other companies doing this? Is this a generally accepted practice? Doesn't this conflict with the definition of a CI tool implicit in its name? Are there any other options?

Note:
https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Jenkins claims that it focuses on "Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs". I'm not sure if this is exactly what I am talking about.


答: If you can't trust your employees to get their work done because of the presence of distractions, then you might be hiring the wrong type of people.</p>

Title: Would you allow your programmers to use Messenger and social networks like Facebook?

Body:
I had many bosses, each one had a different approach about allowing or not use of Windows Live Messenger, Facebook, and many other Internet sites.

Of course Internet is really needed to research about the best way to solve a specific task. Sometimes you could have a friend online, also a programmer, who knows better about something.

For some managers, internet access would slow down project progress, and on the other hand, allow people to interact and find out brand new solutions.

What would you do?


问:
Most effective way to increase programmer salary besides just doing your job?
If you have the time and resources, what would be the most effective way to increase your salary as a full-time programmer, outside of just doing your job?

By "salary" here, I mean salary (adjusted for location cost-of-living) coming from a single programming job.

答:
Chiming in with a point not yet covered, though it falls under negotiation.  Know what the market is paying for similar positions in the same area for the same size company, or at least learn as much as you can.  If your salary is too low be able to prove it to your employer with references.

This will help a lot in at least not being under-payed.  It might also help if your employer claims they are paying top dollar but are actually below that.

There are a lot of on-line sites with at least decent information.  Job sites and sites for recruiters often have some of this information, and there are sites more specifically focused.  I won't list any because it changes some and you should find as many as you can.


问:
Raise a ticket to issue tracking from external web application
I don't know if it's the right place to post this question but, to improve my productivity I need to install an open source issue-tracking system to keep tracks of all bugs and information about the completion.

There are a lot of open source systems to do that but I'm looking for one which could be hosted on PHP / MySql / Linux server and, in particular allows to raise a ticket via rest or soap from my Spring webapp (I thought to create a simple form in my webApp to submit a ticket).

I took a look to The Bug Genie, Mantis and WebIssues and the first two are very hard to be used by non IT user. WebIssues seems to be very easy also for my customers that just need to take a look to the ticket resolution status.

Any tips?

Note I prefer to install my own system in order to pay only one hosting service.

答:
Redmine. Or chili. Both are essentially the same, both let your do email bug reports pretty easily. They also have rest APIs that are pretty straightforward.

Runs on ruby but that co-exists just fine with the standard LAMP stack.


问:
Password hashing and support to your user
We've recently moved to a better password storage strategy, with it came all the good stuff:

Passwords are stored after going through bCrypt

User is sent an activation link on account creation to confirm ownership of address

Forgot password without security question, a link is sent to their email.

The link expires after 24 hours, at which point they will need to request a new one.

If the account is created from our staff, an email is sent with a random strong password in it.  Upon login in the user has to reset it to something we don't know and that is bCrypt'd.

Now this is in accordance with the "best-practice" around, but this increased our amount of support request a lot from regular users who don't understand all this, they just want to login.

We often get request from users who complain about:

Incorrect password (from the one that they need to reset they often paste it with a space at the end).  They tell us what they are using but we have no way of telling them what their actual password is.

Saying they aren't receiving the email we send them (activation, reset, etc.).  This is often not the case, after much troubleshooting we usually found out they did a typo in the email, that they aren't checking the right email account or that it simply went in the spam folder.

We of course can not try it for them as we don't have the password.  We are logging the failed attempts but we also clear the password they used since it's likely to be the password used for another account and we didn't want to store in a plain text log file.  This leaves us with pretty much nothing to help them when they report problems.

I’m curious as to how most people deal with issues like these?

答:
The fact that they are willing to call you up and tell you their password out loud tells you that to these users, the password and the info it protects is not that big a deal. I would never do any of those things with my banking password. But there are a number of sites that demand passwords for things that really don't deserve them. I have one standard password I use for all of those, and the more "hey that's not a strong password" or "we'll make you a password and force you to change it regularly" and so on, the less I want to use that service. I would have a short conversation with the "business value" people in your life to see whether in fact just keeping them plain-text in the db and emailing them to people on request would be a better approach.

If in fact this should be this secure, you could try what one of my clients did with the system we coded for them. While on the phone with the person, go into the db and change their email address to yours. Then go on the web and click Forgot Password. Wait for the email and use it to log in. Using the website, change the password to Password or something else that you verbally agree with the customer. Change their email address back to their own address and tell them "all set, your new password is active now!" Happy customer and you don't have to explain to them what all is going on.


答: we use Messenger inter-office. I would have to say "no" to facebook (etc.) as the temptation to update your profile rather then doing your coding, is too great. Of course, the exception would be if you are developing something for facebook (etc.)  Not to mention the addiction many people have to Farmville (etc.)</p>


答:
The first thing that jumps out is that your emails are going into junk mail. Setting up email so it is recognized as real isn't trivial. I suggest you look into how to stop your email being flagged incorrectly (separate question on SO?)

The second thing I would recommend is giving your users a one click website/app that initiates the password recover emails. Refuse to do it any other way than email, it's unsecure and sets a bad precedent.

Title: Password hashing and support to your user

Body:
We've recently moved to a better password storage strategy, with it came all the good stuff:

Passwords are stored after going through bCrypt

User is sent an activation link on account creation to confirm ownership of address

Forgot password without security question, a link is sent to their email.

The link expires after 24 hours, at which point they will need to request a new one.

If the account is created from our staff, an email is sent with a random strong password in it.  Upon login in the user has to reset it to something we don't know and that is bCrypt'd.

Now this is in accordance with the "best-practice" around, but this increased our amount of support request a lot from regular users who don't understand all this, they just want to login.

We often get request from users who complain about:

Incorrect password (from the one that they need to reset they often paste it with a space at the end).  They tell us what they are using but we have no way of telling them what their actual password is.

Saying they aren't receiving the email we send them (activation, reset, etc.).  This is often not the case, after much troubleshooting we usually found out they did a typo in the email, that they aren't checking the right email account or that it simply went in the spam folder.

We of course can not try it for them as we don't have the password.  We are logging the failed attempts but we also clear the password they used since it's likely to be the password used for another account and we didn't want to store in a plain text log file.  This leaves us with pretty much nothing to help them when they report problems.

I’m curious as to how most people deal with issues like these?


答:
I'd say use a third party authentication method, like Facebook, OpenID, Google... whatever is appropriate for your users. However, if your users can't remember your password, maybe they won't be able to use a third party authentication system...

Depending on your situation, you might be able to use another system, such as SSL client certificates (they are definitely hard to install for end users, but if this is a company and you can automate its installation, it's great), Windows SSO, a mobile app, etc.


答:
Maybe by implementing security rules that are not INSANE. By doing this, all you're getting is less security really, because the system is so hard to use that your clients will reeval passwords to you and their friends just to get it working!

Can't you just send them NORMAL links, then password below.
If the link gets broken by email client just display the form with one field "activation code"... "type activation code you have in the email"... 5 digits so they won't mistake 0 with O, etc. 4 digits are ok for credit cards and you need so complicated policy for simple login?
If the code won't work repeat the check with TRIMmed string? I guess it won't make it less secure, right? :)

For me it happens often too... i doubleclick on password and ending space gets copied. It's unbelivable to me why peple can't figure out just to remove ending white chars when the check failed and repeat the process? Then maybe TOGGLE letter casing for me to check if i didn't press CL accidentally.

You have overcomplicated it so badly. It's not "reset password" and "initial password"... but "Confirmation code" and "Enter confirmation number we send you to the email", "Don't have email? It was send to xxx@yyy.com, check your spam again, still dont have it? Resent your confirmation email". In HTML body a link. http://xxx.com/conf-12345-mymail-gmail-com.html. No mail client will break this.


问:
What's the deal with code reviews?
I've been wondering about code reviews recently, based on how many questions I've seen on here talking about them.

Between my internships, contracts, and full time jobs, I've worked for six different companies, and only one of them has done code reviews.

At the last two places I've worked, code was good (or at least good enough) if all the unit tests passed, and it got the stamp of approval from our tester.  We were all compotent programmers, so if the code worked, we were happy.

Now, there were a handful of times where something came up months or years down the line that might have been caught in a review, but they were so few and far between that I'm not sure it'd be useful.

I guess my question is:

Do you consider reviews to be useful?

How often do you do them?

How much of your time is spent reviewing code?

答:
Yes. Much can be learned from reviewing code, even if it's correct and simply written poorly.

As often as time allows, usually daily. At least a few times per week is enough.

Usually 30 minutes to an hour, depending on the nature of the review.

Remember, just because every company doesn't conduct code reviews doesn't mean it's a waste of time to do so. Perhaps they don't all simply realize the benefits or even know to include them as part of their development process.

Title: What's the deal with code reviews?


答:
1 - I do consider reviews useful, even if it's an informal process. Unit tests passing doesn't mean you caught all the cases, and unit tests attempt to test code in isolation, so you might have written code that ignored something that may cause problems when your code is integrated with other components. Plus, it might help you improve your ability and style if people can suggest better ways to write what you have written.

2 - I do them if I'm the reviewer for other people's fixes, though in my last company, we used Review Board and I would be requested frequently to look at people's code. I also sometimes glance at major code changes to see if the changes are sane.

3 - Perhaps 5% of my total time.

I always try to get someone to look at my code. As competent as you may be, it's good to have other people you trust to look at your code and see if they can offer up suggestions or give you the thumbs up.

And here's the link to Review Board, which can hook in with source control systems like svn and git.

Title: What's the deal with code reviews?

Body:
I've been wondering about code reviews recently, based on how many questions I've seen on here talking about them.

Between my internships, contracts, and full time jobs, I've worked for six different companies, and only one of them has done code reviews.

At the last two places I've worked, code was good (or at least good enough) if all the unit tests passed, and it got the stamp of approval from our tester.  We were all compotent programmers, so if the code worked, we were happy.

Now, there were a handful of times where something came up months or years down the line that might have been caught in a review, but they were so few and far between that I'm not sure it'd be useful.

I guess my question is:

Do you consider reviews to be useful?

How often do you do them?

How much of your time is spent reviewing code?


答:
Personally, if I wanted to slack off on a workplace, I would've used a book or a music player instead of facebook. Some people prefer chit-chat with colleagues.

And overall, all those internat-limitation policies seem like installing and locking a door without walls. If employee has a problem with attitude, it (problem) needs to be dealt with directly.


答:
Absolutely. There are lots of bugs you can catch early via code review. And there are certain types of bugs you can hardly catch any way else than code review (e.g. some concurrency bugs). But what is even more important: (group) code reviews are a great way to spread and share a coherent, consistent view of design, architecture, coding idioms and best practices throughout the development team. The only better way I can imagine is pair programming - which in fact is an extreme form of code review.

The prime goal of (classic, formal) code reviews is in fact not catching bugs already present in the code, but preventing (future) bugs from getting into the code, via the above mentioned continuous communication / mentoring / discussion between team members, generated during review meetings.

This is probably one of the reasons why code reviews are still rare. They show their real benefit only in the long term, so it takes perseverance to get there, and most managers (and developers alike) have never experienced it.

In our current project, we have been doing it only occasionally up to now, but it is bound to change. The new aim is to get every code change reviewed by someone else before it gets into production. In an earlier project, we did that and it was useful. In an even earlier project, we did formal group code reviews, and it was still useful, but fairly slow and time consuming. We couldn't have reviewed every code change in that manner without slowing down our pace of development enormously. But for some types of projects, even that pays off. If human lives are at stake, your prime motivation isn't saving dimes.

Up to now it was no more than an hour per week on average. According to our new process, this is surely going to increase. In the earlier projects mentioned, IIRC it was 2-4 hours per week on average.

Title: What's the deal with code reviews?


问:
Does the LGPL allow me to do this?
I am planning to develop a commercial software using a LGPL software.

In the LGPL software that I am using some functions in a class are not fully implemented. I want to modify the LGPL code so that the class and not-implemented functions are made visible outside the dll by adding dllexport infront of class and by adding virtual keyword infront of function.

Then I plan to implement those functions in my proprietary software. I am ready to distribute the modified LGPL code but not proprietary software that implements functions in the way I want.

Does that violate LGPL terms and conditions?

答:
"I want to modify the LGPL code ..." this says enough that you must release any of that modified code. Then extending whether or not extending that modified code is a derivative work is up for contention and if so it becomes subject to the LGPL.

What it appears you are trying to do is circumvent the LGPL, which in this case with these techniques you can't.

If it is a derivative work, then the program's terms must allow for
  "modification for the customer's own use and reverse engineering for
  debugging such modifications." Whether a work that uses an LGPL
  program is a derivative work or not is a legal issue.

But if what you are trying to do is circumvent the LGPL I would contact the FSF as recommended by Mark Booth.

Title: Does the LGPL allow me to do this?


答: You don't mention whether your coders got the code right on the first try, or if they commited code where QA found bugs that required fixing. If QA is finding bugs, perhaps doing code reviews would lower the number of bugs they find. If QA is finding less of the more obvious bugs, they have more time to find the less-obvious bugs. And the more time they spend finding the less-obvious bugs, the less likely your customers will find those same bugs.</p>

Title: What's the deal with code reviews?


答:
In some shops pair-programming has taken the place of code reviews. I suppose you can think of pair programming as a process of continuous code review.

In the humanities there is a famous saying that "Even Homer nods". Meaning that even if you are the worlds greatest coder, sometimes you are going to be distracted, off your game, or just plain screwing up. A second set of eyes is incredibly helpful in catching stuff like this. The earlier bugs or 'mis-features' are caught, the cheaper they are to fix. Sometimes these mistakes will pass existing tests, but be laying like booby-traps for when the code needs to be extended.

It also has the side effect of keeping everybody in the team at least a little aware of how the other bits work. This help avoid disasters where the one person who knew how the accounts receivable code worked is hit by a bus or leaves the team.

Title: What's the deal with code reviews?


答:
Let's think about the best case scenario: the code is perfect (which will never happen)

Would code reviews be useless?
No, everyone involved in the review would learn something and the review would facilitate conversation and exchange of ideas.

Anything less than the best case scenario has been addressed by other answers.

As far as how much time should be spent reviewing and how the review should be structured...this is highly dependent on many departmental/organizational factors and cannot be answered without this context.

Title: What's the deal with code reviews?


答:
I consider code reviews very useful and helpful.  Even if by some miracle the code is bug free it opens up opportunities to valuable insight.  I like to see how to do things differently and/or sometimes better.  When I do reviews I may also pick up something new or better while looking at the code someone else wrote.

How often they are done depends on what we are changing.  If it is a bugfix then it is likely it will go straight to QA after the developer submits a merge request.  If it is something larger and time permits then the code will be reviewed.

The amount of time spent reviewing depends on the code and the developer.  Some developers are more adept than others and some code changes are bigger than others so it varies. It never goes over an hour for me...plus the meeting will have about it (~30 minutes).

Title: What's the deal with code reviews?


问:
Is there any scenario where it's useful to keep mutable properties cached in domain objects for anything else than informational purposes?
Usually in a domain model, you'll have objects, and those objects will have properties that are mutable and properties that are immutable - for instance, a instance id/name will be immutable, while some other properties (specially properties that depend on relationships with other objects) can vary in the lifetime of an object

So, in the usual scenario where multiple clients are accessing the same data store, your ORM tool will usually model columns as properties and relationships as lists, in the mutual understanding that any mutable property might be outdated in the client - that is, they only represent caches of the values of the properties.

However, in many circumstances, one wants to do an operation that might require the actual state of the mutable properties, otherwise the operation might fail or produce data corruption, so in those cases you'll attempt a lock in the row in question, and if the row has already changed then you cancel or abort. In any case, the operation is done off the client application.

At some point I have to ask a question (oddly enough, its turning out to be surprising hard!), so I guess the question would be: is there any scenario where it's useful to keep mutable properties cached in domain objects for anything else than informational purposes? After all, if there are relationships that we care for, say we want to traverse the neighbours of some object, we'll want to do that with their real (not cached) states, which would involve a database transaction, or some other means to do the process atomically (maybe map reduce?).

答:
Ideally, you want to minimize entity state synchronization to avoid unnecessary DB access, so in cases where you don't have to worry too much about resource conflicts, optimistic locking works well.

There are three phases to optimistic locking:

Begin: Record a timestamp marking the transaction's beginning.

Modify: Read and write database values.

Validate: Check whether other transactions have modified data that this transaction has used (read or wrote). Always check transactions that completed after this transaction's start time. Optionally, check transactions that are still active at validation time.

Commit/Rollback: If there is no conflict, make all changes part of the official state of the database. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible.


答:
Do you even need to be doing it? The first thing you need to do it determine what you are protecting and who you are protecting it from. Maybe it's just no worth the cost of best practice, and maybe best practice won't even stop your attacker.

If you are up against the NSA, and have something they want, give up and make your users life easy. If you have credit card numbers, then you will have to put up with the problems the required level of security requires, because theres bad guys out there who want them and will spend money and time to get them. It it's access to a family photo album, do you need all that security.

Read up on Buce Scheiners works (Secrets and Lies) as a good start to understanding security.


问:
What are the non-technical reasons that make Object-Relational Mapping tools (ORMs) so difficult to write?
I know the technical pitfalls of writing an ORM are pretty well-known nowadays, but what are some non-technical factors (e.g., Scope) that make it difficult to writing a good ORM?

I have already read the technical reasons for why ORMs are so difficult to write from this Stackoverflow post: https://stackoverflow.com/questions/404083/is-orm-still-the-vietnam-of-computer-science

答: The biggest obstacle to creating a good O/RM is trying build an O/RM. Create the simplest solution that solves the problem at hand. Then as you identify problems that your solution doesn't address, expand. If you set out to create an O/RM the sheer scope of that problem will keep you from getting even a simple solution working.</p>


问:
Does giving a developer a slower development machine result in faster/more efficient code?
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards

答:
Development should be done in the best environment that is feasible.
Testing should be done in the worst environment that is feasible.</p>


问:
Syntax for goto labels
In C, C++ and some dialects of BASIC, goto labels are declared with the syntax label:. I'm working on a language that uses name: type as the syntax for variable declarations, so I'd prefer if possible to use something a bit more distinctive for labels. I am or at some point was passingly familiar with many languages that use that syntax for variable declarations, but off the top of my head I can't recall a single one of them that doesn't ban goto (not looking to argue about whether that's a good or bad design decision, just noting it did take place in those cases), so I'm trying to figure out where to look for precedent on labels.

What other forms of syntax has been used for goto labels? Are there any criteria I might be overlooking in choosing one over another?

(I just remembered Ada is an exception. But it uses <>, which doesn't mix well with the use of those symbols as C-style shift operators.)

答:
DOS batch scripts use :label.

// I personally would use >label. :)

Title: Syntax for goto labels


答:
Incorrect password (from the one that they need to reset they often
  paste it with a space at the end). They tell us what they are using
  but we have no way of telling them what their actual password is.

Fixable by instead including a link with a one-time GUID that logs them in and forces them to reset the password. Don't force the user to copy-paste.
(Also, why not strip whitespace at end of password in your form.)

Saying they aren't receiving the email we send them (activation,
  reset, etc.). This is often not the case, after much troubleshooting
  we usually found out they did a typo in the email, that they aren't
  checking the right email account or that it simply went in the spam
  folder.

Make sure your outgoing e-mail is de-spammed (maybe setup test accounts on some common mail services), log anything that happens and maybe report that to the user if they try to request a new reset (i.e., mail to johndoee@gmail.com failed, user not found, did you spell it correctly?). Also, be clear to users about spelling and spam issues.

Also, OpenID and other third-party auths are also an option, as others have said.


问:
How can I quantify the amount of technical debt that exists in a project?
Does anyone know if there is some kind of tool to put a number on technical debt of a code base, as a kind of code metric?  If not, is anyone aware of an algorithm or set of heuristics for it?

If neither of those things exists so far, I'd be interested in ideas for how to get started with such a thing.  That is, how can I quantify the technical debt incurred by a method, a class, a namespace, an assembly, etc.

I'm most interested in analyzing and assessing a C# code base, but please feel free to chime in for other languages as well, particularly if the concepts are language transcendent.

答: There's a pretty strong platform out there called CAST to look for technical debt in big applications. We used it on a project where we took over a big enhancement to a legacy system. It doesn't tell you what was in people's heads who wrote the code, but it examines code and finds code and architecture flaws, then quantifies to technical debt if you want to. The real use in looking at this, though, is not the $ amount but the list of problems already in the code. This tells you about a portion of the technical debt you have (so I do disagree with some of the answers up above). There is some technical debt that's purely design-based and that's very subjective - like pornography - you know it when you see it and know the context. I would argue whether that's really "technical" debt. There is some technical debt that's purely in the implementation and I believe that's worth measuring and tracking.</p>


答:
My guess: (but IANAL) you should release as open source the modified library as LGPL code and then drop it in a commercial program. That would work. Effectively you'd end up having an open source fork of the library around and then you'll be selling a front end for it.

But as many others rightfully said, ask the FSF: it's an intriguing patological scenario you have there; they could be wondering as much as you do if it's applicable or not. (or at least bother about it enough as to publish a FAQ entry on the topic)

Title: Does the LGPL allow me to do this?

Body:
I am planning to develop a commercial software using a LGPL software.

In the LGPL software that I am using some functions in a class are not fully implemented. I want to modify the LGPL code so that the class and not-implemented functions are made visible outside the dll by adding dllexport infront of class and by adding virtual keyword infront of function.

Then I plan to implement those functions in my proprietary software. I am ready to distribute the modified LGPL code but not proprietary software that implements functions in the way I want.

Does that violate LGPL terms and conditions?


问:
How serious is losing the source code?
If a software company loses the source code to one of the products they are selling, how serious would that be, in terms you could explain to a layman?  Would the term "gross negligence" be too strong?  Or "gross incompetence"?  Obviously no one got killed but isn't it as serious as some financial negligence that people get jail time for?

EDIT:
Let's say it's not a case of a disk drive crashing, natural disaster or anything like that.  Just they misplaced it.

答:
Ah, given this clarification from you (in the comments):

It was developed a long time ago, without source control, they've been selling it all this time and now suddenly they need to update it

In this specific situation, I would say it's probably not the end of the world. Given that they've been selling the software for years without needing the source code, then you can just say to this one customer that's requesting the update, "sorry no-can-do".

Now don't get me wrong, losing the code is not good. It's going to be very expensive for your company to re-write or reverse-engineer the original version (if that's what they decide to do). But it's not the end of the world. They've obviously survived for this long without needing the code, so they probably continue to survive without it.

This is assuming, of course, that the software they're selling is only a small part of their business. Which I'm guessing must be the case...

Title: How serious is losing the source code?


答:
The Go Programming Language kind of has this, but only for interface types.

In Go any type for which the correct methods are defined automatically implements an interface, so the objection in your P.S. doesn't apply. In other words, just create an interface that has all the operations of the interface types to be combined (for which there's a simple syntax) and it all Just Works.

An example:

package intersection

type (
    // The first component type.
    A interface {
        foo() int
    }
    // The second component type.
    B interface {
        bar()
    }

    // The intersection type.
    Intersection interface {
        A
        B
    }
)

// Function accepting an intersection type
func frob(x Intersection) {
    // You can directly call methods defined by A or B on Intersection.
    x.foo()
    x.bar()

    // Conversions work too.
    var a A = x
    var b B = x
    a.foo()
    b.bar()
}

// Syntax for a function returning an intersection type:
// (using an inline type definition to be closer to your suggested syntax)
func frob2() interface { A; B } {
    // return something
}
```

Title: Which statically typed languages support intersection types for function return values?

Body:
Initial note:

This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values.

Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.)

Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how?

(If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.)

I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#:

```<code>interface IX { … }
interface IY { … }
interface IB { … }

class A : IX, IY { … }
class B : IX, IY, IB { … }

T fn()  where T : IX, IY
{
    return … ? new A()
             : new B();
}
</code>```

That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.)

P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately.

Footnote: Some resources about intersection types:

Wikipedia article for "Type system" has a subsection about intersection types.

Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism"

David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article.

A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.


答:
You could make label a keyword and use something like:

```<code>label foo;
</code>```

or

```<code>LABEL FOO;
</code>```

if you want it to stand out more.

But as Mitch says, it really depends on what the rest of your language's syntax looks like.

There's an argument to be made that the label syntax shouldn't fit in cleanly with the rest of the language, so that goto labels stand out more.  (That was the rationale for Ada's <> syntax.)

Title: Syntax for goto labels

Body:
In C, C++ and some dialects of BASIC, goto labels are declared with the syntax label:. I'm working on a language that uses name: type as the syntax for variable declarations, so I'd prefer if possible to use something a bit more distinctive for labels. I am or at some point was passingly familiar with many languages that use that syntax for variable declarations, but off the top of my head I can't recall a single one of them that doesn't ban goto (not looking to argue about whether that's a good or bad design decision, just noting it did take place in those cases), so I'm trying to figure out where to look for precedent on labels.

What other forms of syntax has been used for goto labels? Are there any criteria I might be overlooking in choosing one over another?

(I just remembered Ada is an exception. But it uses <>, which doesn't mix well with the use of those symbols as C-style shift operators.)

Body:
You could make label a keyword and use something like:

label foo;

or

LABEL FOO;

if you want it to stand out more.

But as Mitch says, it really depends on what the rest of your language's syntax looks like.

There's an argument to be made that the label syntax shouldn't fit in cleanly with the rest of the language, so that goto labels stand out more.  (That was the rationale for Ada's <<LABEL>> syntax.)


答: I think Bugzilla meets all of your requirements, and I used to like it, back when I used it a few years ago.  It's well established, uses LAMP stack and I think probably a good place to look.</p>

Title: Raise a ticket to issue tracking from external web application

Body:
I don't know if it's the right place to post this question but, to improve my productivity I need to install an open source issue-tracking system to keep tracks of all bugs and information about the completion.

There are a lot of open source systems to do that but I'm looking for one which could be hosted on PHP / MySql / Linux server and, in particular allows to raise a ticket via rest or soap from my Spring webapp (I thought to create a simple form in my webApp to submit a ticket).

I took a look to The Bug Genie, Mantis and WebIssues and the first two are very hard to be used by non IT user. WebIssues seems to be very easy also for my customers that just need to take a look to the ticket resolution status.

Any tips?

Note I prefer to install my own system in order to pay only one hosting service.


答:
How about [label]? For example,

```<code>Stack<Solution> partialSolutions = new Stack<Solution>();
partialSolutions.add(initialSolution);

[weirdSearch]
if (partialSolutions.isEmpty()) {
    acceptedSolution = null;
    goto cleanup;
}

[weirdSearchSkipEmptyCheck]
Solution sol = partialSolutions.pop();
switch (rand() % 3) {
    [0] // accept this
    acceptedSolution = sol;
    goto cleanup;

    [1] // reject this and try the next solution
    goto weirdSearch;

    [2] // try a derived solution
    partialSolutions.push(sol.deriveAnotherSolution());
    goto weirdSearchSkipEmptyCheck;
}

[cleanup]
free(stack);
</code>```

I don't know of any language that uses this syntax, though it reminds me of sections in INI files.

Some other bad ideas:

```<code><label>
.label.
:label:
*label*
>label<
</code>```

These should all be easy to parse if your language is Java-like, since no other statement can begin with an infix operator.

Title: Syntax for goto labels

Body:
How about [label]? For example,

Stack<Solution> partialSolutions = new Stack<Solution>();
partialSolutions.add(initialSolution);

[weirdSearch]
if (partialSolutions.isEmpty()) {
    acceptedSolution = null;
    goto cleanup;
}

[weirdSearchSkipEmptyCheck]
Solution sol = partialSolutions.pop();
switch (rand() % 3) {
    [0] // accept this
    acceptedSolution = sol;
    goto cleanup;

    [1] // reject this and try the next solution
    goto weirdSearch;

    [2] // try a derived solution
    partialSolutions.push(sol.deriveAnotherSolution());
    goto weirdSearchSkipEmptyCheck;
}

[cleanup]
free(stack);

I don't know of any language that uses this syntax, though it reminds me of sections in INI files.

Some other bad ideas:

<label>
.label.
:label:
*label*
>label<

These should all be easy to parse if your language is Java-like, since no other statement can begin with an infix operator.


问:
What is the difference between APIs, Libraries, Runtime systems, and frameworks?

Possible Duplicate:

  Library vs. framework vs API?

I am having hard times understanding what these concepts really mean. This software stack thing is very confusing. Can you please help me with this question, or if you can refer me to some article/book where I can learn in details about this software stack and how they interact together. I tried wikipedia but there is not enough explanations there and the confusion still exists.

答:
Most of these terms have become very ambiguous.

"Library" is the simplest. It's just some utility code that resides on your computer, designed to be used by applications or other libraries. It could be a standard library that came with the compiler/interpreter, or it could be a third-party library. Some "pure" libraries are written only in the user's language, but libraries may contain DLLs, SOs, or other native code components.

"API" is sometimes used to refer to plain old libraries, minus the implementation. OpenGL is an API, while Mesa is a library which implements the OpenGL API. It is often, though not always, used to describe specifications of routines which, when called, must communicate with some external environment. That external environment could be the kernel ISRs (in the case of system calls) or the internet (for web APIs), or locally running services, etc.

"Framework" is a very broad term. It can refer to a plain library, as in the "Java Collections Framework". It is more often used to refer to libraries which impose some structure on applications which use them, such as MVC frameworks (Rails, Zend Engine). It can also refer to the architecture of a large modular application, like Eclipse or Drupal. Finally, it can be used to refer to an entire execution environment, as in ".NET Framework" which includes the CLR and the class library.

"Runtime system" is typically used to refer to an interpreter or virtual machine architecture. For native compilers, it can also be used to refer to a runtime library which provides built-in functions. (I don't know why "runtime library" is so named; they are usually linked statically.)


问:
How would you design a programming language?
If you were to design a programming language, how would you do it? What features would you put in? What would you leave out? Statically or dynamically typed? Strongly or weakly typed? Compiled or interpreted? Justify your answers.</p>

答:
To your first question, "how would you do it" - short answer, I wouldn't. I don't have enough  parser/compiler theory to pull that off. But I have been programming for 25 years, so I do have some ideas and opinions to share.

First off, I would try to come up with an OOP approach that lets you create truly connected models. What I mean by that is, models are one of the most important things in almost any kind of programming project - it's always a lot of grunt-work and continuous refactoring to get it right, and I blame that on a lack of real connectivity in OO languages.

Permit me to demonstrate. Let's say a class House has a Door property.

```<code>var door = house.Door;
</code>```

You now have a local variable with a reference to the Door instance.

But consider what just happened: You just ripped the Door off the House, and now you're quite happy passing the Door around, and the rest of your code is ignorant of the fact that this Door is actually attached to a House.

To me, this is fundamentally wrong.

And yes, I know, this is "easily" fixed on a case-by-case basis - in this case by maintaining a reverse reference from every Door to the House it's currently attached to. This of course opens your model to errors, since it's now your duty to accurately maintain two reverse references, so you make the House.Doors and Door.House properties private, and you add methods like House.AddDoor(), House.RemoveDoor(), Door.SetHouse() etc. and wire it all up, and unit-test it to make sure it actually works.

Isn't this starting to sound like a lot of work to model such a straight-forward relationship? A lot of code to maintain? A lot of code to refactor as the model evolves?

The problem is pointers. Every OO language I've seen, inherently suffers from the fact that an object-reference is really a pointer, because that's what computers use.

Pointers are not a good way to model the real world. Regardless of what world you're trying to model, it's almost guaranteed that any relationships in that world are going to be two-way relationships. Pointers point in one direction only.

I would like to see a language where the fundamental data-model is a graph - where all relationships, by default, have two ends. This would almost certainly provide a much more natural fit for modeling the real world, which is really the only thing we need computers for in the first place. (that and video games.)

I have no idea what syntax for such a language would look like, or whether it can even conceivably be expressed using text. (I've wondered if such a language would have to be graphical, somehow...)

I would also like to see all forms of accidental state eliminated.

For example, in web-development, we spend a lot of time shaping data from databases, into business-models, into view-models for presentation... then some of that data is presented on forms, which is really just another transformation... and state comes back from form-posts, and then we reshape that data and project it back onto the view-model, e.g. view-model binders and such... we then project from the view-model back onto the business-model... we then use object-relational mappers (or grunt work) to transform the data from the view-model and project it onto a relational database...

Is this starting to sound redundant? At what point during all of this madness did we really accomplish anything useful? And by useful I mean, something tangible - something the end-user can understand and cares about. At the end of the day, the hours you spent actually building something the users can even understand, are really the only hours well spent. Everything else is side-effects.

I would want a highly dynamic language. The write/compile/run-cycle is a tedious waste of time. Ideally, the language should just figure out what changed, and compile/load transparently, in the background, as needed.

Ideally, you shouldn't even have to hit "run" - things should happen on-screen, as you make changes, immediately reflecting the changes you make. The problem with the write/compile/run-cycle, or even for that matter the more direct write/run-cycle, is that you're too disconnected from what you're doing - in order to feel connected with our work, we need immediate feedback, instant results. Any wait is too long!

Again, I don't even know if this could be accomplished with a traditional IDE, or if this would require an entirely new kind of interface.

You should be able to use a mix of weak and strong typing, whatever is most suitable for the problem you're working on.

State in general should be something the language fully manages for you. Why should you need to rely on a database for persistence? Ideally, I'd like to be able to simply specify the life-term of any variable in the model: one web-request, one session, 24 hours, permanently.

Why do we have to choose between a whole array of storage solutions for different media and life-terms? - not to mention transforming and shaping the data to fit each media; browser cache, database, memory, disk, who cares! Data is data. Where you store your data (and for how long) should be a simple choice, not a battle against the Gods!

Well, good luck with that.

Body:
To your first question, "how would you do it" - short answer, I wouldn't. I don't have enough  parser/compiler theory to pull that off. But I have been programming for 25 years, so I do have some ideas and opinions to share.

First off, I would try to come up with an OOP approach that lets you create truly connected models. What I mean by that is, models are one of the most important things in almost any kind of programming project - it's always a lot of grunt-work and continuous refactoring to get it right, and I blame that on a lack of real connectivity in OO languages.

Permit me to demonstrate. Let's say a class House has a Door property.

var door = house.Door;

You now have a local variable with a reference to the Door instance.

But consider what just happened: You just ripped the Door off the House, and now you're quite happy passing the Door around, and the rest of your code is ignorant of the fact that this Door is actually attached to a House.

To me, this is fundamentally wrong.

And yes, I know, this is "easily" fixed on a case-by-case basis - in this case by maintaining a reverse reference from every Door to the House it's currently attached to. This of course opens your model to errors, since it's now your duty to accurately maintain two reverse references, so you make the House.Doors and Door.House properties private, and you add methods like House.AddDoor(), House.RemoveDoor(), Door.SetHouse() etc. and wire it all up, and unit-test it to make sure it actually works.

Isn't this starting to sound like a lot of work to model such a straight-forward relationship? A lot of code to maintain? A lot of code to refactor as the model evolves?

The problem is pointers. Every OO language I've seen, inherently suffers from the fact that an object-reference is really a pointer, because that's what computers use.

Pointers are not a good way to model the real world. Regardless of what world you're trying to model, it's almost guaranteed that any relationships in that world are going to be two-way relationships. Pointers point in one direction only.

I would like to see a language where the fundamental data-model is a graph - where all relationships, by default, have two ends. This would almost certainly provide a much more natural fit for modeling the real world, which is really the only thing we need computers for in the first place. (that and video games.)

I have no idea what syntax for such a language would look like, or whether it can even conceivably be expressed using text. (I've wondered if such a language would have to be graphical, somehow...)

I would also like to see all forms of accidental state eliminated.

For example, in web-development, we spend a lot of time shaping data from databases, into business-models, into view-models for presentation... then some of that data is presented on forms, which is really just another transformation... and state comes back from form-posts, and then we reshape that data and project it back onto the view-model, e.g. view-model binders and such... we then project from the view-model back onto the business-model... we then use object-relational mappers (or grunt work) to transform the data from the view-model and project it onto a relational database...

Is this starting to sound redundant? At what point during all of this madness did we really accomplish anything useful? And by useful I mean, something tangible - something the end-user can understand and cares about. At the end of the day, the hours you spent actually building something the users can even understand, are really the only hours well spent. Everything else is side-effects.

I would want a highly dynamic language. The write/compile/run-cycle is a tedious waste of time. Ideally, the language should just figure out what changed, and compile/load transparently, in the background, as needed.

Ideally, you shouldn't even have to hit "run" - things should happen on-screen, as you make changes, immediately reflecting the changes you make. The problem with the write/compile/run-cycle, or even for that matter the more direct write/run-cycle, is that you're too disconnected from what you're doing - in order to feel connected with our work, we need immediate feedback, instant results. Any wait is too long!

Again, I don't even know if this could be accomplished with a traditional IDE, or if this would require an entirely new kind of interface.

You should be able to use a mix of weak and strong typing, whatever is most suitable for the problem you're working on.

State in general should be something the language fully manages for you. Why should you need to rely on a database for persistence? Ideally, I'd like to be able to simply specify the life-term of any variable in the model: one web-request, one session, 24 hours, permanently.

Why do we have to choose between a whole array of storage solutions for different media and life-terms? - not to mention transforming and shaping the data to fit each media; browser cache, database, memory, disk, who cares! Data is data. Where you store your data (and for how long) should be a simple choice, not a battle against the Gods!

Well, good luck with that.


问:
How to get contributors assign copyright for copyright holder?
Let's say we have a company and we release our project under LGPL && GPLv3, as you know the only thing here is about contribution. People commit bug-fixes/features to the project, it's fine and we are GPL fans.

Basically company makes money by this project. So what about contributors ? I know they commit code and software get better and it is actual repay to them, But how we can get contributors assign copyright for copyright holder?

答:
In general, when an open source projects receives contributions from others because implicitly the contributor in contributing with the same license as that of project.  This is true for most open source licenses single or dual.
In this situation whether copyright of incremental work lies with project owner or the external contributor, everyone still has access to code.

However, the real question is what if the project has two licenses one open source and commercial? This is a problem because if an external contributor submits a patch that patch is not automatically ok that same patch gets redistributed to your customer automatically.

However, there are many successful projects, such as QT and MySQL, which have been available as open source as well as for commercial purposes.
Read this: http://www.dina.kvl.dk/~abraham/rants/license.html

For example, what MySQL does is that it has what is called Sun Contributing License. Read this, http://forge.mysql.com/wiki/ContributingFAQ
which says,

Contributors are required to sign the Sun Contributor Agreement (SCA)
  when contributing code to Sun/MySQL

Sameway, QT also makes it clear that

Contributing Code Not Owned by the Contributor

Read this: http://qt-project.org/legal.html

Of course, there is a possibility that given this condition, some people may not contribute back. However, that's only fair. But both these projects goes at great depth why contributor still gets benefited by contributing back.


问:
Why can't an AVL tree be recreated using pre-order traversal?
Given a binary search tree, I understand why I can use breadth-first and pre-order traversal to list the entries of the tree in such a way as to reconstruct the tree in the order in which its traversed.

However if we now consider an AVL tree and we want to traverse the tree in such a way as to recreate the same AVL tree (similar as to what we did with the plain binary tree)
then why does breadth first traversal always work and why does pre-order not work with this case given that it works for standard binary trees?

答: Unlike a plain binary tree, AVL trees are self-balancing. When an element is inserted into an AVL tree, the tree may need to perform node rotations in order to maintain a certain tree depth, which allows for logarithmic lookup time.  So, if you try to build a second AVL tree using pre-order node traversal on an existing AVL tree, the resulting tree will not necessarily have the same node structure, because it may need to perform node rotations in order to keep the tree balanced.</p>


问:
Job hopping, is it a problem?
How would you, as someone involved in the hiring process (manager,interviewer, etc) feel about a candidate that has changed jobs every 1-2 years?

update
Thanks for all the input everybody, some really great responses, and good info in every post.  I asked it because I'm currently at my 3 job in the last 5 years and I'm feeling like my position is going nowhere (like the position should have been contract in the first place, not full-time).

My only options here seem like transition to a different team doing something I'm not really interested in or look for new work, but I'm a little afraid my recent job history is all short stints.

答:
In the ideal world, the decision would be made on a case by case basis. Sometimes,  jumping frequently from job to job may be an indicator of a work ethic or other problem. Many times, it's nothing to worry about. For example, if you are just starting your career, you may need to try many different jobs before you know what you like. Also, certain job types, such as start-ups or contract roles naturally have a high turnover rate. Moreover, working at multiple companies has some advantages. After having worked at a number of companies, I can compare & contrast their methods and have a much better idea of what works and what doesn't; I've seen and solved a wide variety of problems; I've become very good at learning new skills; and I can bring this invaluable knowledge to a future employer. In fact, I've often found that someone that moves around every few years is a much better employee than somebody who has been stagnating at the same job for a decade.

In reality, many people do see this as a red flag and without giving more thought to it, pass over the candidate. It's a shame, but that's just the way it is.

Title: Job hopping, is it a problem?


问:
Is it possible to check that MS word file is hand written or auto generated by using some converter?
I got one project with some requirements.

Basically my client provide data entry work.  In that he converts image files(scan copy of articles, forms etc) to document file (MS word) by typing manually.  For maintaining quality of that work he set some roles on documents text formatting like specific font, font size, paper size etc., and he compare image files with specific document for proofreading which is very time consuming task, and his some smart employ use some image to word converter for that conversion rather then typing manually. He pays a lot in the Data entry and he don't want automated converted files using some conversion software.

So basically he want two functionality in his project that,

to automate standard format proofreading process and

to automatically reject image to word converted files.

this is the all scenario and now my question is that

Is it possible to find out which file is manually type by employ and which is converted by using some conversion software?

Is it possible that we can check file for specific standard format?

答:
For checking for the use of OCR software, find out whether the OCR software adds metadata to the file.

For checking for consistency with a specific format, write a VBA macro. MS Office VBA macros have access to the document object model. Of course, if you're going to that, you might as well just have the macro set the document's formatting to the required format.

I'm curious, though: does your client have a better reason for disallowing OCR than "I'm paying you for manual data entry so you can't use OCR"?


答:
If you must use GOTO statements, even knowing that they are unnecessary and an open invitation to mess up your programs, then do what Ichbiah et al (the original designers of Ada) did: MAKE THE SYNTAX UGLY.

Make it stick out like a giant thumb with a really hideous fungal infection that has been smashed with a hammer.  Make it EASY for the maintenance programmers to see it, so they will know that the author of the code they are asked to maintain was a total cretin, who needed to be forcibly transferred to the business school, rather than be allowed to matriculate in computer science, so they will be on the lookout for the not-quite-as-obvious idiot mistakes that are bound to be festering all through his alleged code.

Ichbiah admitted they did this, in so many words.  The DoD specification for the language explicitly required that it contain a GOTO statement, because the DoD believed (wrongly, in my personal opinion) that the case against it had not been made solidly enough.  They couldn't NOT put in a GOTO, but they could and did make it UGLY, to discourage its use.  Most places that used Ada outlawed its use immediately, or at least required management signoff on each and every GOTO, to encourage programmer to find a GOTO-less alternative.

Something like ###--->>>LABEL<<<---### would work.  The label must be on a line, with massive "decoration", all the way up against the left margin, and ALL BY ITSELF.

Or maybe something like --->>>LABEL   ... HEREBEDRAGONS, where "HEREBEDRAGONS" is a reserved word in the language, and any variation on HEREBEDRAGONS that is not all uppper case is defined to be a fatal syntax error.  Make it HARD and PAINFUL for the programmer to use it.

Title: Syntax for goto labels


答:
the method of last resort I used on a system with very illiterate users in the past was to direct the user to a screen where they were given a phone # and a confirmation number.  They called the phone number, verified their identity through manual means then read the confirmation.  the support person logged into a separate system, entered the number and got a second number to give back to the client.  the client used the second code to continue to the reset password page.  the client version of the page could not run from the support personnel's sub-nets and the support screen could not run from the clients.

it isn't bulletproof as a support person could use a vpn to run both ends from one location, but it was sufficient for audit since the support account was logged as responsible for the activity


问:
Need advice: Staying techie or going the MBA way?
I know this is a very subjective question and I am the best person to decide this for myself...but I am just looking for your views.

I have 5 years of experience as a professional developer. I have a decent background in Maths and have done my bachelors in engineering in CS. I have still not reached a stage in my career where growth is difficult and do not foresee this happenning for a very long time if ever because I find myself constantly (self) motivated to pick up new skills.

A lot of my friends have however been getting through their MBA lately ...and not from the likes of Harvard or Kellogs, just mediocre colleges. They've however been landing paychecks fatter than me even though they have little or no work experience.

Given that I have the option of pursuing an MBA an have my finances in order (and am planning an MBA from INSEAD / IE) would it make sense for me to sell out what I like doing and go for an MBA? Will I regret not doing an MBA later, given that I am in the right age/experience group to do an MBA?

I absolutely love what I am doing right now and also the people I'm doing it with, but am just worried if this career would be as rewarding financially as the one after a management degree.

答:
My apologies for being overtly blunt...MBA is not for everybody, so I would say know yourself and know what you want for yourself and see if MBA aligns with that. If for example, you are getting married so that you can be happy, then you are getting for the wrong reason. Same thing, if you are getting an MBA with the hope of getting a fat check or having the status, then you may be disappointed.

But if you are looking to have a MBA degree so that you can better understand the business structure and be equipped with advanced toolset for solving complex business problems and making informed business decisions or even apply some of those principles in everyday life, then maybe pursuing a MBA from a reputable business school can act as a catalyst to achieving such set objectives.

One thing I know is that if you have a background in IT and also possess a passion of seeing how businesses can derive better value from the effective use of technology, going through a well focused MBA program can create that path of becoming the strategic partner and Technology leader that businesses of today are looking as they use technology to create competitive advantage for their organization.

Again, this is not a path for everybody with a techie background. It is up to each individual to figure out what they want in life.


问:
Would you allow your programmers to use Messenger and social networks like Facebook?
I had many bosses, each one had a different approach about allowing or not use of Windows Live Messenger, Facebook, and many other Internet sites.

Of course Internet is really needed to research about the best way to solve a specific task. Sometimes you could have a friend online, also a programmer, who knows better about something.

For some managers, internet access would slow down project progress, and on the other hand, allow people to interact and find out brand new solutions.

What would you do?

答: With the proliferation of smart phones and mobile data plans, how exactly do you monitor and control use of the internet? You can create policies against use of company equipment and internet connections, but you can't eliminate the distractions. Your best bet is to hire people who get the job done. A developer who works eight solid hours a day, and spends two hours on "distractions," is worth more than a weak developer who puts in ten hours face time.</p>


答:
JavaScript does not have goto but it has labels:

```<code>outer:for(var i=0;i<10;++i) {...}
</code>```

and yet it has:

```<code>{ outer:"value" }
</code>```

and yet you can find there:

```<code>some? outer:"value";
</code>```

In JavaScript 2.0 typed variables were added:

```<code>var some:int;
</code>```

All this does not create any conflicts as ':' appears in different contexts.

Title: Syntax for goto labels

Body:
JavaScript does not have goto but it has labels:

outer:for(var i=0;i<10;++i) {...}

and yet it has:

{ outer:"value" }

and yet you can find there:

some? outer:"value";

In JavaScript 2.0 typed variables were added:

var some:int;

All this does not create any conflicts as ':' appears in different contexts.


答:
I'll buck the norm and say yes IF AND ONLY if they're writing server software.  Laugh all you want, but the most efficient team I ever saw was a group of Perl guys with Wyse terminals.  This was late 1990s, was a University off-shoot shop, and they were writing spatial gridding software (which basically just calculates).  They were however talking to some relatively powerful late-model RS/6000s.

Just to add interest to the event, there was a blind programmer there.  I was thoroughly impressed.

Title: Does giving a developer a slower development machine result in faster/more efficient code?

Body:
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards


问:
Open Source Licenses
I'm independently developing a physics-based game using HTML5 canvas and JavaScript; I've used no external code at all (including physics or game engines), and my code is about 5000 lines in length. The development is almost complete, and now I want to release it.

I am planning to release the game as a paid app on the Chrome, Android, and Apple app stores, but I also want to release the code under an open source license - one which allows free reading and gleaning of ideas from my code, but does not allow more than a couple lines to be copied. Basically I want people who know where to look and how to use to find free code, and the general public to buy it, while preventing piracy or the development of a near copy.

Is this possible with an open source license?

What license should I use?

答:
If you're concerned about protecting the code (legally), you should contact an attorney to craft a license that meets your somewhat non-typical needs, to make certain your application and code is properly protected. Creative Commons as a commenter above mentioned, isn't a good fit for software. If you feel like a CC license is right, you need to read the details of the license carefully and understand it. Don't rely only on the summaries provided.

Better though, I'd suggest that instead of (just) doing that, you'd consider creating a blog/web site that discusses the more interesting points of what you've done and why you think they were novel or interesting. I'd read it (as would likely others), whereas I wouldn't think to try to dive through your ideally minimized JavaScript code.

OwnerDisplayName: mndoftea

Title: Open Source Licenses


问:
Forcing aggregate root child access through the aggregate root alone
Context

I'm developing an application using a Domain Driven Design approach. I want to use a design pattern wherever appropriate and apply all SOLID principles.

Scenario

I have an order and I want to allow clients to add order lines to it.

Consider the following pseudo code:

```<code>class Order
    OrderLines[] (readonly)
    AddOrderLine(orderLine)

class OrderLine
    Product
    Amount

class OrderLineFactory
    OrderLine Create(product, amount)

class OrderLineRepository
    Save(orderLine)
</code>```

Now lets add an OrderLine to the Order:

```<code>Order.AddOrderLine(OrderLineFactory.Create(product: "Chocolate Cake", amount: 3))
</code>```

By the way, the OrderLineFactory is there because in my case, there is some relatively complex logic involved with creating order lines. This is one of the main reasons for applying the factory pattern.

Problem

The problem is that I could do this instead...

```<code>orderLine = OrderLineFactory.Create(product: "Chocolate Cake", amount: 3)
OrderLineRepository.Save(orderLine)
</code>```

...and get around the Order.AddOrderLine method, effectively short-cutting any checks that are performed in that method (e.g. protecting against duplicates or limiting the order amount).

Working towards a solution

An argument could be that there shouldn't be a Save method on OrderLineRepository, because an OrderLine isn't an aggregate root. This would (just like I want) render the client incapable of storing the bare OrderLine except from adding it to the Order and saving the Order consequently.

However, having a Save method on repositories that concern non-root aggregates, allows for saving changes made to them directly, such as:

```<code>orderLine = orderLineRepository.Get(31923)
orderLine.Amount = 5
OrderLineRepository.Save(orderLine)
</code>```

Not being able to save the OrderLine would require me to do something like...

```<code>order = OrderRepository.FindByOrderLineId(31923)
order.OrderLines[31923].Amount = 5
OrderRepository.Save(order)
</code>```

...which isn't all that efficient or practical. I could add a requirement to provide the (actually redundant) Order ID as well but that would put some unnecessary burden on the client.

So lets say I want to stick with my OrderLineRepository.Save method and still find a way to stop my client from being able to get around my Order.AddOrderLine method.

All I can think of now, is dropping the OrderLineFactory and creating a domain service that combines the creation and the assignment.

```<code>class OrderService
    AddOrderLine(order, product, amount)
</code>```

So we can:

```<code>order = orderRepository.Get(123)
OrderService.AddOrderLine(order: order, product: "Chocolate Cake", amount: 3))
orderRepository.Save(order)
</code>```

I don't really like the service combining multiple concerns here though, those of creation and assignment. That would call for... a factory... again.

Okay, let's consider a private factory then, one that's not available to the client but to the domain service alone. In my case I would get stuck with unit testing and Inversion Of Control. I'd be creating an uninjectable dependency, since my client wouldn't be able to register my non-public factory.

Summary

I want my client to be able to create order lines through the Order class and in no other way

I don't want to mangle multiple concerns in a single class

I want to keep OrderLine creation outside of the Order class

I'd like to keep using a factory for that

So I'm a little stuck here, trying to find the best way to deal with this. Any suggestions?

答:
Why not make the order responsible for creating orderlines?

The AddOrderline function could take the Product and Amount parameters and create an Orderline changing an orderline would be by product on an order so you would have a function ChangeOrderLine(string productName, int amount) and DeleteOrderLine(string productName)

Done and done.


答: THIS IS THE MOST DISGUSTING THING I HAVE EVER READ... I think giving your developer a 2 leged stool to sit on would have the same desired effect... "he will work for you, and when you are not looking, seek other employment"</p>


问:
Checking if a method returns false: assign result to temporary variable, or put method invocation directly in conditional?
Is it a good practice to call a method that returns true or false values in an if statement?

Something like this:

private void VerifyAccount()
{
    if (!ValidateCredentials(txtUser.Text, txtPassword.Text))
    {
        MessageBox.Show("Invalid user name or password");
    }
}

private bool ValidateCredentials(string userName, string password)
{
    string existingPassword = GetUserPassword(userName);
    if (existingPassword == null)
        return false;

    var hasher = new Hasher { SaltSize = 16 };
    bool passwordsMatch = hasher.CompareStringToHash(password, existingPassword);

    return passwordsMatch;
}
```

<p>or is it better to store them in a variable then compare them using if else values like this</p>

<pre class="lang-.NET prettyprint-override"><code>bool validate = ValidateCredentials(txtUser.Text, txtPassword.Text);
if(validate == false){
    //Do something
}
</code>```

I am not only referring to .NET, I am referring to the question in all programming languages it just so happens that I used .NET as an example

答:
As with all these things it depends.

If you aren't going to use the result of your call to ValidateCredentials then there's no need (other than for debugging purposes) to store the result in a local variable. However, if it makes the code more readable (and hence more maintainable) to have a variable go with that.

The code isn't going to be measurably less efficient.


答: Why use an additional variable? I prefer use the first approach, it's more readable and simple. </p>

Title: Checking if a method returns false: assign result to temporary variable, or put method invocation directly in conditional?

Body:
Is it a good practice to call a method that returns true or false values in an if statement?

Something like this:

private void VerifyAccount()
{
    if (!ValidateCredentials(txtUser.Text, txtPassword.Text))
    {
        MessageBox.Show("Invalid user name or password");
    }
}

private bool ValidateCredentials(string userName, string password)
{
    string existingPassword = GetUserPassword(userName);
    if (existingPassword == null)
        return false;

    var hasher = new Hasher { SaltSize = 16 };
    bool passwordsMatch = hasher.CompareStringToHash(password, existingPassword);

    return passwordsMatch;
}
```

<p>or is it better to store them in a variable then compare them using if else values like this</p>

<pre class="lang-.NET prettyprint-override"><code>bool validate = ValidateCredentials(txtUser.Text, txtPassword.Text);
if(validate == false){
    //Do something
}
</code>```

I am not only referring to .NET, I am referring to the question in all programming languages it just so happens that I used .NET as an example


答: Yes, it is usually fine to use such methods as if conditions. It is helpful though if the method name indicates that the method returns a bool; for instance CanValidateCredentials. In C-style languages this method is often takes the form of Is and Can prefixes, and in Ruby with the '?' suffix. </p>


答:
Is it a good practice to call a method that returns true or false values in an if statement?

Yes, if the conditional is not simple enough to inline and have it be readable.

or is it better to store them in a variable then compare them using if else values like this

You should only do this if your using the value in multiple places or need it to make the code more readable.  Otherwise the assignment to a variable is unnecessary.  Unnecessary code is at best wasteful and at worst a source of a defect.