答:
I personally wouldn't start with the hardcore theory. I'd start with practical programming intermingled with some elements of the theory. It could keep one much more motivated and not scare him off.

It is for instance a case with musical schools. A huge portion of students quit because they get bored with the theory and eventually lose interest.

Besides, the theory is not that good when it is learned before having gotten your hands dirty with practice. You won't know when and how to apply it.

But if you had some theory knowledge then practiced a lot, after that a serious course in IT would push you on a different level. Otherwise the years spent in a university are just wasted on a deaf year.

In that order:

Some basic theory about hardware, computer architecture and programing that hardware. Just basic.

Then develop practical things. Basic applications to keep interest. First local, then something with graphics. Web pages not yet since you would want to demonstrate the server-side programming and it is often useless without databases.

Drop him some database knowledge crops

Interface you local application with the database. Then try web development.

Adjust the course as you go.


问:
Are short identifiers bad?
Are short identifiers bad? How does identifier length correlate with code comprehension? What other factors (besides code comprehension) might be of consideration when it comes to naming identifiers?

Just to try to keep the quality of the answers up, please note that there is some research on the subject already!

Edit

Curious that everyone either doesn't think length is relevant or tend to prefer larger identifiers, when both links I provided indicate large identifiers are harmful!

Broken Link

The link below pointed to a research on the subject, but it's now broken, I don't seem to have a copy of the paper with me, and I don't recall what it was. I'm leaving it here in case someone else figure it out.

http://evergreen.loyola.edu/chm/www/Papers/SCP2009.pdf

答: In some applications a short variable simply cannot explain the data in the variable. Short or long is irrelevant. Using a longer variable does not make your code slower. Sure it is more effort typing out a long variable name but atleast the person who reads the code 6 months later (which may be you) will be able to make out what is happening without needing to put traces assuming that is even possible.</p>

ContentLicense: CC BY-SA 3.0

Title: Are short identifiers bad?

ContentLicense: CC BY-SA 2.5


问:
If you had to go back and re-learn your skill set, how would you do it?
My younger brother is looking to start programming. He's 14, and technically-inclined, but no real experience programming. He's looking to me for guidance, and I don't feel as if my experience is enough, so I figured I'd ask here.

He's more interested in web programming, but also has an interest in desktop/mobile/server applications.

What would be a good learning path for him to take? I'm going to buy him a bunch of books for Christmas to get him started; the question is, what should he learn, and in which order?

The way I see it, he needs to learn theory and code. I'd like to start him off with Python or Ruby or PHP. If he wants to get in to web, he's also going to need to learn HTML, CSS, Javascript, etc.

Out of those three domains (Languages, Theory, Markup/Etc.), what is the best order do you think to learn in? Also, am I missing anything?

Thanks!

答:
I'd go with learning stuff for the mobile phone arena, that's prime real estate there.  Get him set up with an IDE that has a phone emulator, and get him a phone he can push the apps to.

Set him up for some real world usage and hacking, supplemented with some theory from your books to guide him.  Make sure they have good samples.


答:
Starting with web dev is a nice idea. You can get results even if you're a true beginner, and if you mess up, it won't matter much.

I'd say Html/CSS + Php. As Jeff stated in his comment, having his site hosted will matter, and Php hosters aren't expensive, often even free.

As for theory, I would simply forget it for the moment. The way I understand it, he mostly wants to have fun, and let's face it, theory isn't very fun. Besides, if he does like programming, he will have plenty of it in school.

Obviously we all care about nice code, but if he's just going to play around, what does it matter if his code is messy?

Title: If you had to go back and re-learn your skill set, how would you do it?

Body:
My younger brother is looking to start programming. He's 14, and technically-inclined, but no real experience programming. He's looking to me for guidance, and I don't feel as if my experience is enough, so I figured I'd ask here.

He's more interested in web programming, but also has an interest in desktop/mobile/server applications.

What would be a good learning path for him to take? I'm going to buy him a bunch of books for Christmas to get him started; the question is, what should he learn, and in which order?

The way I see it, he needs to learn theory and code. I'd like to start him off with Python or Ruby or PHP. If he wants to get in to web, he's also going to need to learn HTML, CSS, Javascript, etc.

Out of those three domains (Languages, Theory, Markup/Etc.), what is the best order do you think to learn in? Also, am I missing anything?

Thanks!


问:
After how much experience, should one start to use a framework for serious development?
Long time back, when I was reading my introductory programming books on (Basic, Pascal, C/C++), one thing that was emphasized is you can't become a professional programmer over night or over few weeks. It takes time to grasp programming and to apply it for solving problems and developing applications.

Now, once someone has the grasp of basic programming, the person can quickly adapt to new technologies. In recent times, the use of frameworks in application development is prevalent. Though the learning curve for framework is way smaller than that of programming, even so they too would require some time to learn. Of course, different frameworks have different complexity, hence the learning curve would vary greatly.

My question is, should one start to do commercial projects while they are learning a particular framework, or should a demo/learning project be done first to get the hang the framework and then proceed onto real projects?

答: When one understands the need of a framework.</p>


答:
The most logical thing to do is to start using a framework when you feel the pain that the framework is supposed to reduce.

So if you want to do Java web programming, I would start with Servlets and JSP, and use straight JDBC to connect to the database.

It won't be long until you are tired of created repetitive Servlets, and then you know that you should learn Spring MVC or Struts 2.  And when the JDBC is causing you pain, start using Hibernate.

You are right that it is easier to learn a framework than a language, but I think that it can be very demoralizing to try to learn a framework that solves problems that you have never experienced.

Title: After how much experience, should one start to use a framework for serious development?

Body:
Long time back, when I was reading my introductory programming books on (Basic, Pascal, C/C++), one thing that was emphasized is you can't become a professional programmer over night or over few weeks. It takes time to grasp programming and to apply it for solving problems and developing applications.

Now, once someone has the grasp of basic programming, the person can quickly adapt to new technologies. In recent times, the use of frameworks in application development is prevalent. Though the learning curve for framework is way smaller than that of programming, even so they too would require some time to learn. Of course, different frameworks have different complexity, hence the learning curve would vary greatly.

My question is, should one start to do commercial projects while they are learning a particular framework, or should a demo/learning project be done first to get the hang the framework and then proceed onto real projects?


答:
Does his high school offer classes in computer science?  For example in the United States the Advanced Placement program has a computer science class that goes through quite a bit of the basic computer science concepts (flow of control, basic object oriented development practices, loops, etc.).

I was able to attend a high school that offered computer science courses for basically all 4 years (from an introductory course through to basic LIPS, MIPS, and Open GL).  I ended up testing out of the basics in college and then re-learning a lot of the other languages and topics in upper level courses.  I can tell you that 14-17 year old brain had a lot more difficulty wrapping around the theory than an 18-22 year old brain did.  Topics like recursion, pointer arithmetic, low-level programming, network topography, and functional programming took me a long time to get in high school, but the second time around in college I found them to be a breeze, perhaps because I'd already tackled them but also perhaps because of what developmental scientists have proved about the young brain - some of the abstract thinking required for higher math and CS concepts is still developing.

Even though it was difficult, thinking through CS starting at 14 is extremely helpful.  Doing it without teachers seems like it would have been complicated.  I would've spent time developing web pages for fun because it's what I loved to do back then (and now), but I would never have taught myself pointers, recursion, and LISP for fun at the time.


问:
What's a good Programming Metaphor?
I am referring to explaining to the non-programmer what programming is. I made sure to search for similar questions before creating this one, but the few ones I did find seemed to dodge the question, and I specifically would like to see some metaphors or analogies. I personally find it easier to explain something technical to someone through the use of metaphors or analogies.

The reason I'm interested in this is because many people encounter the work of a programmer on a daily basis, but if you ask the average person what a programmer is or does, they don't really know. This leads to certain situations of misunderstanding (ex. "[...] but I thought you were good with computers!")

I really would like to find the best one out there. I would like to be able to easily explain to someone what my career choice is about. Of course, at least the general idea.

I personally don't have a solid one, but I have long thought about it and I have usually gravitated towards the 'language' metaphor, where we happen to know a language that computers understand, and therefore we are able to tell computers what to do, or "teach" them, to solve our problems.

For example:

Imagine that in an alternate reality, humanoid robots with artificial intelligence exist, and some people are able to communicate with them through a common language, which is a variation of English. These people who can communicate with the robots are able to teach them how to solve certain problems or do certain tasks, like doing our chores.

Well, although robots like that don't exist yet, programmers of our time are like those people, but instead of communicating with the robots, they communicate with computers. Programmers "teach" the computers how to perform certain tasks or solve certain problems by means of software which they create by using this "common language".

Programmers and this "common language" are what give us things like email, websites, video games, word processors, smart phones (to put it simply), and many other things which we use on a daily basis.

I don't mean to put programming on the throne or anything, it's just the best metaphor I could come up with.

I'm sure someone will find some issue with this one, it's probably a bit contrived, but then again that's why I'm asking this question.

答:
The best metaphor for anything is itself.  Anything different will lose some accuracy.  As such, picking the best metaphor depends on what, specifically, you want to capture about programing.  Since there will be a lot of answers given here about coding metaphors, I'll answer with the classic metaphor for the development process as a whole:

Building Construction

The most common aspect of this metaphor is that a physical architect is somewhat analogous to a software architect.  Here are a few other parallels:

Changes are cheaper and cheaper the earlier you make them.  That is, you can move one line on paper now or 10 tons in cement later.

A building without a proper plan will tend to collapse

The builders attempt to implement what the client wants.  If the client doesn't accurately describe what they want the building to look like (or there is some other failure in communication), it'll be costly to change.

There are certain laws of physics that cannot be bent.  Just as a three-hundred foot wide 2nd story cannot be built on a 100-foot wide 1st story, feature X cannot be built without a robust subsystem Y.

Of course, like any metaphor, it has its limitations.  Some flaws with it:

Buildings are 1-time use; you build it somewhere, and there it stays.  You can't copy it a million times for a million different users with a million different needs at zero incremental cost.

Buildings are considerably more immutable than software.

There's no clear analogy to building material cost.  A line of code costs nothing- only the time it takes to produce it costs money.

The incremental architecture that is (depending on who you ask) possible with software is not possible with construction, where you design it once, then build it.

So, like any analogy, it depends what you're trying to explain.  Be wary of over-relying on any one metaphor, or your customer will start wondering what the property taxes on his new payroll system will be.

Title: What's a good Programming Metaphor?


答:
You should definitely do a bit of background research before you consider using a particular framework. For starters, looking into the documentation about the kind of problems the framework claims it can solve, ask people about their experience with this framework on places like stackexchange, read the reviews of the people who have used this framework. If its possible and the project's open sourced, check the download count of the project -- the more the merrier in this case.

When you are done with all of that, start digging in deeper. Look into the fine print like the minimum compiler and OS versions required to use this framework, dependencies on other frameworks (if any) that this framework might have, performance limitations etc.

Doing a small project and investing your time into this framework comes after all of these.


答:
My logical preference based on what I know now:

Figuring out how things work now - While you state he is technically-inclined, how well does he understand how a computer works at this point?  For example, does he understand differences between mark-up and scripts?  What about writing little scripts to do this or that?  This would be my suggestion for a starting point as demystifying what we have around us is a good starting point given all of stuff that could be explored pretty freely.

Pick a language, IDE, and source control.  Now while this may seem like quite a bit to hurl at someone, these are the rather basic tools that with a little practice he may well then move on to bigger things.  Figuring out how to make a "Hello World!" web page that has the message embedded in JavaScript isn't a bad starting point if one wants something a bit more concrete here.

Now start adding some of the harder stuff.  How to do loops or conditions?  This isn't really that fancy yet but we're still at the understanding the building block stage here.  Lastly introduce the idea of classes and what are some ideas behind this concept.

Those would be where I'd start if someone wanted to get some basics of my skill-set.


答:
The first paper you link to looks interesting, but its conclusion is that they found no significant evidence for or against the hypothesis that "grounding hints", including meaningful variable names, help in code comprehension. The used gaze dwell time as a proxy for code comprehension which is interesting, but not a slam dunk.

I'm afraid I found the second paper just silly. The first problem is that the examples of long names they provide are gratuitously long, providing no extra information. I think we can all agree that making a variable name longer just to make it longer is stupid. Their example of naming a variable distance_between_abscissae rather than dx is a straw man.

More importantly, their experiment is a test of simple memorization rather than comprehension. It tests the ability of subjects to fill in missing pieces of a variable name when presented in a list with no context. Yes, longer names are harder to memorize, but when I'm coding I don't memorize variable names, I use them to provide context. I suppose you could argue that the difficulty of remembering long variable makes code harder to write, but code is read far more often than it is written, so which activity should be optimized?

Title: Are short identifiers bad?

Body:
Are short identifiers bad? How does identifier length correlate with code comprehension? What other factors (besides code comprehension) might be of consideration when it comes to naming identifiers?

Just to try to keep the quality of the answers up, please note that there is some research on the subject already!

Edit

Curious that everyone either doesn't think length is relevant or tend to prefer larger identifiers, when both links I provided indicate large identifiers are harmful!

Broken Link

The link below pointed to a research on the subject, but it's now broken, I don't seem to have a copy of the paper with me, and I don't recall what it was. I'm leaving it here in case someone else figure it out.

http://evergreen.loyola.edu/chm/www/Papers/SCP2009.pdf


答: I think you have to use a framework with non-trivial work in order to really understand it. Of course, this will mean you go outside the lines at some points and you may have some refactoring to do later. If you have a real project, and you know which framework you are planning to use - why wait?</p>


答:
Register him an account for StackOverflow.com and Programmers.StackExchange.com

and get him into the habit of browsing different questions when he is bored. Start with the hot/most popular questions.

Also

Help him come up with a goal of something he wants to create that is slightly beyond his reach, a simple game, an app that can send a tweet? It has to be something that is exciting. This will help guide the topics he exposes himself to and provide him motivation through the tangible output he creates.

And

Where possible don't buy books in physical form if he works well with digital print, I am sure one of you has an android or iphone or blackberry or ipod touch? Get the ibooks or kindle app and buy digital versions.

Having to deal with a physical book slows the process of knowledge acquisition; the tools built into digital readers provide many benefits to technical reading.

Note: as mentioned in the comments, there are drawbacks to digital vs printed books, so take this point with a grain of salt


问:
Commenting/In-Code Documentation Styles
This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else.

I have a teacher who says we should explicitly list each parameter with a description, even if there's only one.  This leads to a lot of repetition:

```<code>double MyFunction(const int MyParam);
// Function: MyFunction
// Summary: Does stuff with MyParam.
// Input: int MyParam - The number to do stuff with.
// Output: MyParam with stuff done to it.
</code>```

When writing in-code documentation, how detailed are you?

答:
If it's a public API method then yes you should provide detailed documentation, especially on parameters and expected behaviour.  Many people feel that this can be relaxed for private methods/functions, YMMV.

Overall I prefer writing clean code (small methods/functions that do one thing and one thing well) with sensible variable names.  This makes much of your code self-documenting.  However, I certainly always document any edge cases, uses of concurrency and complex algorithms.

In short think of your self as a little bit worse for wear at 3am in the morning 3 months from now.  You'll be thanking yourself for your awesome public docs as opposed to figuring out what parameter (boolean flag) means...

Title: Commenting/In-Code Documentation Styles


答:
That's similar to how most -Doc frameworks parse in-code documentation (JavaDoc, PHPDoc, etc.).

From Java, auto-generated by IDE:

```<code>/**
 * [Description]
 * @param str [Description]
 * @param isCondition [Description]
 * @return [Description]
 */
public int testFunction(String str, boolean isCondition) {
    ...
}
</code>```

This is the same format used to generate the Documentation for the built-in language features - Example: http://download.oracle.com/javase/6/docs/api/java/lang/String.html

This format is quite helpful because it clearly shows to any third-party user how to interface with your code.  If your functions are private methods that are only used internally, then it can be a little pointless - but I'd guess your teacher is trying to get you into a good practice until you are all experienced with making that distinction.

The only bit I often find somewhat redundant is the return description - Usually it's nearly identical to my method description.

Title: Commenting/In-Code Documentation Styles

Body:
This might be a stupid question, but it's been in the back of my head for a while and I can't find a decent answer anywhere else.

I have a teacher who says we should explicitly list each parameter with a description, even if there's only one.  This leads to a lot of repetition:

```<code>double MyFunction(const int MyParam);
// Function: MyFunction
// Summary: Does stuff with MyParam.
// Input: int MyParam - The number to do stuff with.
// Output: MyParam with stuff done to it.
</code>```

When writing in-code documentation, how detailed are you?

Body:
That's similar to how most -Doc frameworks parse in-code documentation (JavaDoc, PHPDoc, etc.).

From Java, auto-generated by IDE:

/**
 * [Description]
 * @param str [Description]
 * @param isCondition [Description]
 * @return [Description]
 */
public int testFunction(String str, boolean isCondition) {
    ...
}

This is the same format used to generate the Documentation for the built-in language features - Example: http://download.oracle.com/javase/6/docs/api/java/lang/String.html

This format is quite helpful because it clearly shows to any third-party user how to interface with your code.  If your functions are private methods that are only used internally, then it can be a little pointless - but I'd guess your teacher is trying to get you into a good practice until you are all experienced with making that distinction.

The only bit I often find somewhat redundant is the return description - Usually it's nearly identical to my method description.


答:
Several languages have API document generation features like Ruby, Java, C# and C++ (via a command line tool).  When you think about it in that way, it makes writing the API docs much more important.  After all, it answers the question "how do I do ...?"  So I won't do anything repetitive like Function: MyFunction when the name of the function is plain for everyone to see.  The API doc generation tools are smart enough to do that for me.  However, the following details are useful, particularly on public methods/functions:

Summary (what it does and when relevant a summary of how to use it)

List of parameters and what is expected

What the return value (output) will be

Any exceptions that can be thrown explicitly and why

These can become useful reference tools when you are trying to debug code.  Many IDEs will also use the API docs in their tool tips as you hover over the function name.

If it's a language without those features, the comments help, but not nearly as much.

Title: Commenting/In-Code Documentation Styles


答:
For starters, I agree that the "Function:" line in your example is completely redundant. It's also been my experience that people taught in school to add that type of comment continue adding that type of comment in their production code.

Good comments don't repeat what's in the code. They answer the question "Why?" instead of "What?" or "How?" They cover expectations about the inputs, as well as how the code will behave under certain conditions. They cover why algorithm X was chosen instead of algorithm Y. In short, exactly the things that wouldn't be obvious to someone else1 from reading the code.

1: Someone else who is familiar with the language the code is written in. Don't write comments to teach, comment to supplement information.

Title: Commenting/In-Code Documentation Styles


问:
What's the better way to charge for a cloud platform, simple but more expensive, or complicated but cheaper for most?
I'm working on a cloud platform, and was curious what people prefer in terms of paying for web services.

There's the option of very simple pricing (tiers and such), which is easy to project costs on, easy to compare, but (possibly significantly) more expensive for the average user, because you're always either underpaying or overpaying.

The other option is a complicated pricing structure with many different factors, a lot harder to project costs on, but you're literally paying only for what you use, so it comes out to a lower price for the average user.

Which do you prefer?

答:
It depends on what is the cost difference and whether it is worth my time to figure out that cost difference. If it is a matter of $10-20/month, then I surely dont think its a big deal for most people and they would prefer simplicity over cost. </p>

<p>On the other hand, if its a matter of a few hundred/thousands dollars per month, I would definitely not mind taking the time out to figure what I exactly need and what I don't. </p>

Body:
It depends on what is the cost difference and whether it is worth my time to figure out that cost difference. If it is a matter of $10-20/month, then I surely dont think its a big deal for most people and they would prefer simplicity over cost.

On the other hand, if its a matter of a few hundred/thousands dollars per month, I would definitely not mind taking the time out to figure what I exactly need and what I don't.


问:
Why are more programmers not freelance these days?
Leaving the whole pie to only a few of them, amplifying the huge differences between the two status. Pay is a (huge) one, not having to do overtime is another.

I leave the question open to hopefully get many great answers on all the different subjects that affects that feeling and decision not to go.

While this question is really global, I'll be interested in any studies, facts, articles, opinions regarding local markets such as US, India and even Australia in which I'm in love with.

答:
I think a lot of it is the illusion of job security most people currently have when they are employed full time.  I have not seen that full time employers are now any more loyal to there FTEs than they are to contractors.

There is also the administrative overhead (billing, taxes, accounting, etc, etc) of freelancing that most people don't like to deal with.


答: I write very, very detailed instructions for a very, very dumb machine. </p>

Title: What's a good Programming Metaphor?

Body:
I am referring to explaining to the non-programmer what programming is. I made sure to search for similar questions before creating this one, but the few ones I did find seemed to dodge the question, and I specifically would like to see some metaphors or analogies. I personally find it easier to explain something technical to someone through the use of metaphors or analogies.

The reason I'm interested in this is because many people encounter the work of a programmer on a daily basis, but if you ask the average person what a programmer is or does, they don't really know. This leads to certain situations of misunderstanding (ex. "[...] but I thought you were good with computers!")

I really would like to find the best one out there. I would like to be able to easily explain to someone what my career choice is about. Of course, at least the general idea.

I personally don't have a solid one, but I have long thought about it and I have usually gravitated towards the 'language' metaphor, where we happen to know a language that computers understand, and therefore we are able to tell computers what to do, or "teach" them, to solve our problems.

For example:

Imagine that in an alternate reality, humanoid robots with artificial intelligence exist, and some people are able to communicate with them through a common language, which is a variation of English. These people who can communicate with the robots are able to teach them how to solve certain problems or do certain tasks, like doing our chores.

Well, although robots like that don't exist yet, programmers of our time are like those people, but instead of communicating with the robots, they communicate with computers. Programmers "teach" the computers how to perform certain tasks or solve certain problems by means of software which they create by using this "common language".

Programmers and this "common language" are what give us things like email, websites, video games, word processors, smart phones (to put it simply), and many other things which we use on a daily basis.

I don't mean to put programming on the throne or anything, it's just the best metaphor I could come up with.

I'm sure someone will find some issue with this one, it's probably a bit contrived, but then again that's why I'm asking this question.


问:
How to make security usable in a web application?
I'm in the planning stages of developing a web application that I want to make as secure as possible. I'm pretty clear about how to do that from a technical point of view, but there is one massive potential security hole: I want the site to have users.

As anyone who has ever been a user knows, users forget usernames, forget passwords, sometimes forget that they even had an account with your site. Users respond to phishing emails and give away their credentials. If you do anything that they find too complicated they won't use your site, it has to be simple and all happen in as few clicks as possible, but we have to balance that out by making it as hard as possible for users to accidentally give away their credentials and to keep access to the service as secure as possible.

What I'm particularly interested in are strategies that go beyond the standard username and password combination and ways of recovering or resetting passwords that make things easy for users but hard for anyone trying to steal their account. I know a lot of sites provide an extra user-set security question, but because I don't trust users not to create a stupid question like "what is 1+1" I don't see how this can guarantee security.

Are there strategies that could be useable to the most clueless user but challenging to a determined and targetted attack aiming to break into their account? If not what are the closest things we could get? As a user what are the best/worst sites for this you have encountered and why?

答:
As per your comment

I don't trust users not to create a
  stupid question like "what is 1+1" I
  don't see how this can guarantee
  security.

You don't need to guarantee security - in fact having a question like that shouldn't be a problem. Let users set the hints they need.

Now for ebanking, there is a juicy enough target that phishers do make good money, so if you are in the same space you could look at what some of the banks do very successfully in the anti-phishing space - antiphishing.org has some useful info, then applications like Trusteer's Rapport provide further security around the connection, and for the higher value areas they use 2 factor auth, often in the form of smart cards.

The solutions for various different risk and usability levels are pretty well understood, so you might find it is simpler to reuse an existing concept than redevelop - the cost of usability testing could be high!


答:
DEBT

In my youth I didn't think debt was a big thing, and got into a lot of student loans.  This now means I get to work very hard to pay them off.  A startup business wouldn't provide the income I need to keep up.

The SBA has shown in the past that a high percentage of businesses fail in the first five years, and one of the major reasons is under-capitalization.   I would recommend that anyone getting into their own business make sure they can support themselves for a long period of time without any income from the business.

Having said all that, as soon as my situation changes, I will be looking at getting back into business full-time (have had a few side ones in the past).  Even if I don't make as much as my job, the freedom is worth the cost.

Title: Why are more programmers not freelance these days?

Body:
Leaving the whole pie to only a few of them, amplifying the huge differences between the two status. Pay is a (huge) one, not having to do overtime is another.

I leave the question open to hopefully get many great answers on all the different subjects that affects that feeling and decision not to go.

While this question is really global, I'll be interested in any studies, facts, articles, opinions regarding local markets such as US, India and even Australia in which I'm in love with.


问:
Has working on open source projects helped your productivity in your day job?
If yes, can you provide an example? Is it due to learning new tricks that you wouldn't learn otherwise by reading other's code? Or any other reasons as well?</p>

答:
Yes, working on any kind of projects outside of work help expand your knowledge on a particular subject, allow you to network with other developers, and help you build your portfolio.

As a developer, there is no reason not to have something working on the side, whether it is an open source or commercial project or even a technical blog.

Also, I've found side projects a way to stay passionate about programming.  On your own projects you get to do whatever you want which can be exciting and a nice change from the day-to-day corporate programmer life.

The more things you work on, the more you will learn and the more marketable you become.


答:
In the US, health insurance is tied to your employment status. If I had a spouse who could put me on his health insurance, I could consider freelancing full time, but I could never make enough money to pay for living expenses plus private health insurance at my age. Health insurance for people over 50 is very, very expensive, I need to be part of a group policy.

When I did freelance in my 30's, I frankly hated it. I spent too much time on marketing and accounting and not enough time on the interesting parts. Plus I hated not knowing how much money I would have in any month (customers sometimes being slow to pay as well as variances in how much work I had), makes it hard to plan.


问:
Does double-shifting as a PM affect your developer-productivity?
Has it ever happened to you that you are a good developer but suddenly you need to lead a team or are responsible for some PM activities as well? Did you find that it affected your productivity? How did you handle it?

I love my job, but I sometimes feel I was much happier as a programmer and the additional burden of being a Project Manager is currently affecting my productivity as a developer. What do you guys suggest as remedies to this?

I do not have an alternative currently to quit from my job - basically because Im working for a startup that I co-founded.

答:
I think that it's impossible to quickly shift from PM mode to Dev mode.
I'm teamleader in my normal job and programmer for a website during the nights.
When I become teamleader I tried to keep contributing with the code, but I soon discovered that it was impossible.

The new responsibilities required me to speak with people or check emails several times in a hour, impossible to write code in that condition.
So now when I have some spare minutes at work I started to seat with someone of the team, especially with junior, and try to help him/her.

I saw that this is increasing team productivity overall probably more than if I could spend some time writing code.


答:
Well... not especially open source, but working for some hobby project in your free time can really help you with your coding skill and with your cv as well.

As example I started using python for a report generating tool in 2001 and then I was able to apply for a work in python in 2003.

It happened again with Java technologies and now I'm learning Scala...

Title: Has working on open source projects helped your productivity in your day job?

Body: If yes, can you provide an example? Is it due to learning new tricks that you wouldn't learn otherwise by reading other's code? Or any other reasons as well?</p>


问:
How is IntelliJ better than Eclipse?
I know there have been questions like What is your favorite editor/IDE?, but none of them have answered this question: Why spend the money  on IntelliJ when Eclipse is free?

I'm personally a big IntelliJ fan, but I haven't really tried Eclipse. I've used IntelliJ for projects that were Java, JSP, HTML/CSS, Javascript, PHP, and Actionscript, and the latest version, 9, has been excellent for all of them.

Many coworkers in the past have told me that they believe Eclipse to be "pretty much the same" as IntelliJ, but, to counter that point, I've occasionally sat behind a developer using Eclipse who's seemed  comparably inefficient (to accomplish roughly the same task), and I haven't experienced this with IntelliJ. They may be on par feature-by-feature but features can be ruined by a poor user experience, and I wonder if it's possible that IntelliJ is easier to pick up and discover time-saving features.

For users who are already familiar with Eclipse, on top of the real cost of IntelliJ, there is also the cost of time spent learning the new app. Eclipse gets a lot of users who simply don't want to spend $250 on an IDE.

If IntelliJ really could help my team be more productive, how could I sell it to them? For those users who've tried both, I'd be very interested in specific pros or cons either way.

答:
I work with Intellij (9.0.4 Ultimate) and Eclipse (Helios) every day and Intellij beats Eclipse every time.

How? Because Intellij indexes the world and everything just works intuitively. I can navigate around my code base much, much faster in Intellij. F3 (type definition) works on everything - Java, JavaScript, XML, XSD, Android, Spring contexts. Refactoring works everywhere and is totally reliable (I've had issues with Eclipse messing up my source in strange ways). CTRL+G (where used) works everywhere. CTRL+T (implementations) keeps track of the most common instances that I use and shows them first.

Code completion and renaming suggestions are so clever that it's only when you go back to Eclipse that you realise how much it was doing for you. For example, consider reading a resource from the classpath by typing getResourceAsStream("/ at this point Intellij will be showing you a list of possible files that are currently available on the classpath and you can quickly drill down to the one you want. Eclipse - nope.

The (out of the box) Spring plugin for Intellij is vastly superior to SpringIDE mainly due to their code inspections. If I've missed out classes or spelled something wrong then I'm getting a red block in the corner and red ink just where the problem lies. Eclipse - a bit, sort of.

Overall, Intellij builds up a lot of knowledge about your application and then uses that knowledge to help you write better code, faster.

Don't get me wrong, I love Eclipse to bits. For the price, there is no substitute and I recommend it to my clients in the absence of Intellij. But once I'd trialled Intellij, it paid for itself within a week so I bought it, and each of the major upgrades since. I've never looked back.

Title: How is IntelliJ better than Eclipse?


答:
It seems to become increasingly difficult to work on projects alone.  There seems to be quite a bit of work out there, but not something I can take on alone.

Most projects are becoming more and more complex, and it takes a team of developers/designers, etc.  This becomes difficult in freelance as I would have to contract out some of the work.


答:
Yes it does. I worked at a firm where the team leader quite and a replacement was no where in site. The head of accounting started to 'manage' our group by basically let us manage ourselves and explain everything we were working on in a weekly meeting as if speaking to a 2-year-old (Including dealing with his tantrums.).

I felt I wasn't learning anything. Spending too much time on BS instead of coding. No one in our group was considered good enough to be the leader. The situation was chaos. Once the main project I was working on was near completion, I started looking for another job and found one.

If your goal is to be a PM, do both for awhile, but don't stick with a situation where you can't choose the path you want.

Title: Does double-shifting as a PM affect your developer-productivity?

Body:
Has it ever happened to you that you are a good developer but suddenly you need to lead a team or are responsible for some PM activities as well? Did you find that it affected your productivity? How did you handle it?

I love my job, but I sometimes feel I was much happier as a programmer and the additional burden of being a Project Manager is currently affecting my productivity as a developer. What do you guys suggest as remedies to this?

I do not have an alternative currently to quit from my job - basically because Im working for a startup that I co-founded.


问:
Why does DirectX use a left-handed coordinate system?
I considered posting on Stack Overflow, but the question strikes me as being far too subjective since I can't think of a reasonable technical explanation for Microsoft's choice in this matter. But this question has bugged me for so long and the issue keeps coming up in one of my projects, and I have never actually seen an attempt at explaining this:

OpenGL uses a right-handed coordinate system, where the +Z part of the world coordinate system extends toward the viewer.

DirectX uses a left-handed system where the +Z part of the world coordinate extends into the screen, away from the viewer.

I never used the Glide API, so I don't know how it worked, but from what I can gather, it uses a left-handed system as well.

Is there a technical reason for this? And if not, is there some conceptual advantage to a particular handedness of a coordinate system? Why would one choose one over the other?

答:
It's pure history.  In ancient days the early cave-graphics programmers thought of the monitor (teletype? stonetype?) viewing surface as two dimensional graph paper.  In math and engineering the usual conventions for plotting data points on graph paper is: x=right, y=up.   Then one day, about a week after the invention of the silicon wheel, someone thought of 3D graphics.  When the candle-bulb of this idea blinked on above their head, for whatever reason, they choose to add Z= away from viewer.  (Ouch, my right hand hurts just imagining that.)

They had no idea that someday their far descendants would become engineers, scientists, fine artists, commercial artists, animators, product designers etc and find 3D graphics useful.   All these fine modern people use right-handed coordinate systems to be consistent with each other and the more established math texts and physics conventions.

It is foolish to base the 3D coordinate system on the display surface.  It's the model that counts - the triangles and polygons and planes describing a house, chair, overweight green ogre or galaxy.  Nowadays we all design and model stuff in right-handed XYZ systems, and do so in terms of the model's world, even before thinking how it'll be rendered.  The camera is added at some point, possibly made to fly around in crazy ways, and it's invisible infrastructure that converts the model to pixels that within its bowels must twerk around with coordinated system transforms.

Just to add to the confusion, some graphics libraries recognize that CRTs scan the image from top to bottom, and so have Y=down.  This is used even today in all windowing systems and windows managers - X11, fvwm, gtk+, Win31 API, etc.  How new-fangled 3D GUI systems like Clutter, Beryl etc deal with Z, is a separate issue from 3D graphics modeling. This need concern only applications programmers and GUI designers.


问:
What does backup procedures and troubleshooting guidelines mean for a system
I am writing the documentation for a piece of software which I have made but I don't understand what it means in some aspects.

It asks me to write about backup procedures but what exactly does this mean? Does this mean like backing up the database on another hosting service or something else entirely?

I am dumbfounded by what troubleshooting guidelines are as well.

If you have any idea what this could mean feel free to give your insight even if you aren't 100% sure in case it could spark what it means inside of me. Thanks.

答:
What you're asked to do is, I believe, describe (1) what would happen if something wrong happens, and (2) how to react when it happens. The official term is disaster recovery plan, but I assume they call it "backup procedures" and "troubleshooting guidelines" in order to be more specific.

Backup procedures

Imagine that I, as a customer, am working with your software product. I may have:

Files which I stored in a location I've chosen,

Data which is stored by your application, given that I don't have to know where this data is saved,

Configuration.

Backing up the files is generally the responsibility of the customer, since they are separate enough from the application. I may have Microsoft Word files that I open sometimes with Word, sometimes with Open Office, and sometimes with my custom-made app which extracts some information from them. None of those apps should be responsible of those files, since none own them.

Data, on the other hand, is strongly related to the application itself, and the user doesn't have to deal with this data directly. It's up to the application to keep this data safe, eventually with the help of the user. Configuration is in the same category. It's the same data, but more specific and even more linked to the application.

Scenarios

Imagine the following scenarios:

My hard disk fails. What happens? I may have baked up my files, but what happens with the application data and configuration? Do I have to reconfigure everything? Or was your application helpful enough to back the data up somewhere (in a cloud service or in a location I've chosen and that I baked up together with my personal files)? Would it be clever enough to recover all my settings?

I want to migrate to a new PC. Do I have to redo all the configuration, or the app is smart enough to let me back the data up in one click, and restore it in one click later?

Example · Adobe Lightroom

If you have used Adobe Lightroom, photos themselves (RAW/NEF files) would be in the first category, the catalog will be in the second one, and templates will be in the third one.

While I have to deal with backing up the photos themselves, I shouldn't care about the catalog, and even more about the templates. Lightroom does a good job of backing up the catalog (by providing a choice every time I shut the application down), but does nothing to backup the templates. Adobe's website specify the location of the templates, but it means that when I have to migrate it from one machine to another, I have to copy those files manually. Dealing manually with the photos, the catalog and the templates is not the best user experience I would expect from such product, and while I expect to have to protect my photos myself, a one-click backup solution for both the catalog and the templates would be welcome.

Example · Google Chrome

Chrome has a different approach. When using the sync feature, it bakes up the bookmarks, the entered passwords, the list of extensions, the browser settings, etc. on Google servers.

This approach would be problematic for a software product such as Lightroom, because I don't want my 500 MB catalog to be synchronized with Adobe's servers each time I change it (I have an impression that diffs won't work for that). On the other hand, this is a particularly elegant approach for software products such as a browser, a word processor or even NVIDIA Control Panel where I pick the options for my GPU.

Conclusion

In a document which describes backup procedures, I expect to read:

What needs to be baked up in order to become operational as fast as possible after the loss of all information except the backups,

How easy/difficult is to make backups for an end user,

Is there a scheduled backup, and if there is, what's the frequency,

How to automate the backup procedure (and eventually the recovery procedure as well),

Is my data safe, if it's stored in the cloud (I certainly don't want Google to have my Amazon's password stored in plain text),

Are there scalability issues (Lightroom catalog takes less than a second to back up when you have a few hundred of photos; with dozens of thousands of them, it may take a few minutes),

etc.

Troubleshooting guidelines

This is rather the description of any issue which may happen with your piece of software. For example, what happens if it runs out of space? Would it crash, or would it, instead:

Alert the user that the PC is running out of space a few hours or minutes before it occurs, and:

Later, alert the user that now, the PC is out of space, and either gracefully shutdown if there is nothing unsaved, or keep running and ask the user to free some space to save the data, or chose a different location.

In the same way, what would happen if there are network connectivity issues? Or any other issue relevant to your specific case?


问:
How to refactor my design, if it seems to require multiple inheritance?
Recently I made a question about Java classes implementing methods from two sources (kinda like multiple inheritance). However, it was pointed out that this sort of need may be a sign of a design flaw. Hence, it is probably better to address my current design rather than trying to simulate multiple inheritance.

Before tackling the actual problem, some background info about a particular mechanic in this framework:

It is a simple game development framework. Several components allocate some memory (like pixel data), and it is necessary to get rid of it as soon as you don't need it. Sprites are an example of this.

Anyway, I decided to implement something ala Manual-Reference-Counting from Objective-C. Certain classes, like Sprites, contain an internal counter, which is increased when you call retain(), and decreased on release().

Thus the Resource abstract class was created. Any subclass of this will obtain the retain() and release() implementations for free. When its count hits 0 (nobody is using this class), it will call the destroy() method. The subclass needs only to implement destroy().

This is because I don't want to rely on the Garbage Collector to get rid of unused pixel data.

Game objects are all subclasses of the Node class - which is the main construction block, as it provides info such as position, size, rotation, etc.

See, two classes are used often in my game. Sprites and Labels.

Ah... but wait. Sprites contain pixel data, remember? And as such, they need to extend Resource.

But this, of course, can't be done. Sprites ARE nodes, hence they must subclass Node. But heck, they are resources too.

Why not making Resource an interface?

Because I'd have to re-implement retain() and release(). I am avoiding this in virtue of not writing the same code over and over (remember that there are multiple classes that need this memory-management system).

Why not composition?

Because I'd still have to implement methods in Sprite (and similar classes) that essentially call the methods of Resource. I'd still be writing the same code over and over!

What is your advice in this situation, then?

答:
tl;dr: composition is good, implementation inheritance is... an unfortunate choice.

What you try to achieve is to make Sprite look simultaneously like a Resource and like a Node. You don't need this. You need a way to expose the Resource interface and the Node interface.

Imagine:

```<code>// traditional part

interface Node {
  Position getPosition();
  // anything else
}

interface Resource {
  void allocate(...);
  void destroy();
}

// composition interfaces

interface NodeHolder {
  Node asNode(); // the only method
}

interface ResourceHolder {
  Resource asResource(); // the only method
}

// reusable resource helper

class ResourceImpl implements Resource {
  public void allocate(...) { /* some implementation */ }
  public void destroy() { /* some implementation */ }
}

// you could have a default Node implementation the same way,
// but you don't have to; you could directly extend a Node implementation:

class Sprite
  extends NodeBaseImpl
  implements NodeHolder, ResourceHolder
{
  private Resource my_resource;
  public Sprite(...) {
    // whatever construction needed
    my_resource = new ResourceImpl();
  }

  public Resource asResource() { return my_resource; } // composition!
  public Node asNode() { return this; } // composition again! :)
  // ...
}
</code>```

Now all your resource-managing code operates on ResourceHolders, and all your node-handling code operates on NodeHolders. No code assumes that any object inherits a specific base class; only interfaces are used:

```<code>List<NodeHolder> nodes = new ArrayList<>(5);
nodes.add(new Sprite(...));
nodes.add(new Minimap(...));
nodes.add(new HitpointBar(...));
// can add more NodeHolders
...

// Rotate them all
for (NodeHolder nh : nodes) { nh.asNode().rotate(15); }
</code>```

Implementations can be inherited or composed, to your taste. Only code to copy all over are methods asNode(), etc, which are usually trivial, and only one per interface.

You double the number of interfaces, though, because you use nnnHolder interface dispatch to explicitly do what e.g. Go does automatically.

Body:
tl;dr: composition is good, implementation inheritance is... an unfortunate choice.

What you try to achieve is to make Sprite look simultaneously like a Resource and like a Node. You don't need this. You need a way to expose the Resource interface and the Node interface.

Imagine:

// traditional part

interface Node {
  Position getPosition();
  // anything else
}

interface Resource {
  void allocate(...);
  void destroy();
}

// composition interfaces

interface NodeHolder {
  Node asNode(); // the only method
}

interface ResourceHolder {
  Resource asResource(); // the only method
}

// reusable resource helper

class ResourceImpl implements Resource {
  public void allocate(...) { /* some implementation */ }
  public void destroy() { /* some implementation */ }
}

// you could have a default Node implementation the same way,
// but you don't have to; you could directly extend a Node implementation:

class Sprite
  extends NodeBaseImpl
  implements NodeHolder, ResourceHolder
{
  private Resource my_resource;
  public Sprite(...) {
    // whatever construction needed
    my_resource = new ResourceImpl();
  }

  public Resource asResource() { return my_resource; } // composition!
  public Node asNode() { return this; } // composition again! :)
  // ...
}

Now all your resource-managing code operates on ResourceHolders, and all your node-handling code operates on NodeHolders. No code assumes that any object inherits a specific base class; only interfaces are used:

List<NodeHolder> nodes = new ArrayList<>(5);
nodes.add(new Sprite(...));
nodes.add(new Minimap(...));
nodes.add(new HitpointBar(...));
// can add more NodeHolders
...

// Rotate them all
for (NodeHolder nh : nodes) { nh.asNode().rotate(15); }

Implementations can be inherited or composed, to your taste. Only code to copy all over are methods asNode(), etc, which are usually trivial, and only one per interface.

You double the number of interfaces, though, because you use nnnHolder interface dispatch to explicitly do what e.g. Go does automatically.


问:
How to avoid oscillation by async event based systems?
Imagine a system where there are data sources which need to be kept in sync. A simple example is model - view data binding by MVC. Now I intend to describe these kind of systems with data sources and hubs. Data sources are publishing and subscribing for events and hubs are relaying events to data sources. By handling an event a data source will change it state described in the event. By publishing an event the data source puts its current state to the event, so other data sources can use that information to change their state accordingly.

The only problem with this system, that events can be reflected from the hub or from the other data sources, and that can put the system into an infinite oscillation (by async or infinite loop by sync). For example

```<code>A -- data source
B -- data source
H -- hub

A -> H -> A -- reflection from the hub
A -> H -> B -> H -> A -- reflection from another data source
</code>```

By sync it is relatively easy to solve this issue. You can compare the current state with the event, and if they are equal, you don't change the state and raise the same event again.

By async I could not find a solution yet. The state comparison does not work by async event handling because there is eventual consistency, and new events can be published in an inconsistent state causing the same oscillation. For example:

```<code>A(*->x) -> H -> B(y->x)
    -- can go parallel with
B(*->y) -> H -> A(x->y)
    -- so first A changes to x state while B changes to y state
    -- then B changes to x state while A changes to y state
    -- and so on for eternity...
</code>```

What do you think is there an algorithm to solve this problem? If there is a solution, is it possible to extend it to prevent oscillation caused by multiple hubs, multiple different events, etc... ?

update:

I don't think I can make this work without a lot of effort. I think this problem is just the same as we have by syncing multiple databases in a distributed system. So I think what I really need is constraints if I want to prevent this problem in an automatic way. What constraints do you suggest?

答:
If you have designed your system such that a data source changes state (and fires an event) for every event that it receives, then you have an inherently instable (oscillating) system if that data source is involved in a loop of events.

The only ways to avoid oscillations in such a system are:

Somehow ensure that the events received by such a data source don't originate from itself (directly or indirectly through other events). This is harder than it seems and the trouble is that you generally don't see an error until the oscillations actually happen.

Ensure that each data source has some combinations of states and events where it either ignores the event or at least doesn't fire a new event.

So, in the case of the simple reflection of event E, data source A should ignore event E if it is received in state x.

In general, in every event-driven system there will be a number of events that don't make sense when received in certain states. It is those events that should dampen out any oscillations that occur.

The main source for oscillations that remains would be two (external) events that occur at the same time and try to put the system into different states. These kinds of oscillations are inherent to the system and will have to be addressed on a case by case basis. Generally, that would involve preferring one state over the other and ignoring the events that would trigger the oscillations when received in the preferred state.


问:
Modelling highly specific business requirements
How can one go about modelling highly specific business requirements, which have no precedent in the system? Take for example the following requirement:

When a purchase order contains N lines, is over X value in total and is being recorded against project Y, an email needs to be sent to persons A and B with the details

This requirement supplements other requirements surrounding purchase orders, but comes in at a much later date in response to some ongoing problem elsewhere in the business.

Persons A and B are not part of any role or group in the system, and don't hold any specific responsibility; they are simply the two people the business has appointed to receive these emails in this very specific case. Projects are also data driven, so project Y has no special properties to distinguish it from any other project. The only way to identify it is to compare its identifier to a magic number.

How can one go about modelling this kind of case without introducing too much additional complexity? That I can think of right now, there are a couple of options.

Perform the checks and actions inline with the existing code. Here we find the correct spot in the code, check the conditions in the requirement and send the emails to hardcoded addresses. Of course this is fraught with issues. At the very least it stops working if one of these people leaves or changes their email address. At worst you have to ensure that any tests and test data are aware that additional actions are taken for a specific set of criteria.

Introduce some form of events system. Here we introduce an eventing system, so that we might react to some event, and fulfil the requirement outside of the usual path of execution. This sounds like a cleaner solution than option 1, but the work involved is ultimately probably slightly overkill for this one small requirement. That said, having it in place does allow the system to handle these kinds of specific requirements consistently and easily in the future.

Are there any other (good/better) ways of handling highly specific requirements? I mean other than telling the other parts of the business no!

答:
Option one seems fine if you provide some sort of configuration setting somewhere in the system so that you can change the Email addresses.

Option two seems like overkill for what appears to be a relatively straightforward business requirement.  Only implement it if it appears that it will solve more problems than just this specific requirement.


答:
I suggest that you take both options.

Step 1: Introduce the concept of an Alertable category that can be applied to projects. For each instance of Alertable, allow the attachment of one or more users (who have email addresses). Introduce the concept of a Condition which can be attached to each Alertable which holds a generalizable predicate. So you model those concepts on your whiteboard to the point where you can clearly see most of the code.

Step 2: Now, take your existing code and use the terminology of the concepts you built in the previous paragraph, implement the capability. You will hard wire Project Y to pretend that it has an Alertable instance, hard wire the Condition detection, and then hard wire the alerting process.

Your code might look like this:

In Project object:

```<code>Boolean isAlertable() {
   return projectNumber == MAGICNUMBER;
}
</code>```

In the PurchaseOrder object, check the project for isAlertable(). Hard wire the condition check at this time, because implementing a generalized predicate is premature. Then, ask the Project to send the alert emails.

The point of the first step is to see if you really understand the concept. It also lays the groundwork for future development. The point of the second step is to get the job done. There is a good possibility that, in future, you will receive similar kinds of requests for "odd" alerting requirements. In that case, you can be ready with a design that you can apply.

Title: Modelling highly specific business requirements

Body:
How can one go about modelling highly specific business requirements, which have no precedent in the system? Take for example the following requirement:

When a purchase order contains N lines, is over X value in total and is being recorded against project Y, an email needs to be sent to persons A and B with the details

This requirement supplements other requirements surrounding purchase orders, but comes in at a much later date in response to some ongoing problem elsewhere in the business.

Persons A and B are not part of any role or group in the system, and don't hold any specific responsibility; they are simply the two people the business has appointed to receive these emails in this very specific case. Projects are also data driven, so project Y has no special properties to distinguish it from any other project. The only way to identify it is to compare its identifier to a magic number.

How can one go about modelling this kind of case without introducing too much additional complexity? That I can think of right now, there are a couple of options.

Perform the checks and actions inline with the existing code. Here we find the correct spot in the code, check the conditions in the requirement and send the emails to hardcoded addresses. Of course this is fraught with issues. At the very least it stops working if one of these people leaves or changes their email address. At worst you have to ensure that any tests and test data are aware that additional actions are taken for a specific set of criteria.

Introduce some form of events system. Here we introduce an eventing system, so that we might react to some event, and fulfil the requirement outside of the usual path of execution. This sounds like a cleaner solution than option 1, but the work involved is ultimately probably slightly overkill for this one small requirement. That said, having it in place does allow the system to handle these kinds of specific requirements consistently and easily in the future.

Are there any other (good/better) ways of handling highly specific requirements? I mean other than telling the other parts of the business no!

Body:
I suggest that you take both options.

Step 1: Introduce the concept of an Alertable category that can be applied to projects. For each instance of Alertable, allow the attachment of one or more users (who have email addresses). Introduce the concept of a Condition which can be attached to each Alertable which holds a generalizable predicate. So you model those concepts on your whiteboard to the point where you can clearly see most of the code.

Step 2: Now, take your existing code and use the terminology of the concepts you built in the previous paragraph, implement the capability. You will hard wire Project Y to pretend that it has an Alertable instance, hard wire the Condition detection, and then hard wire the alerting process.

Your code might look like this:

In Project object:

Boolean isAlertable() {
   return projectNumber == MAGICNUMBER;
}

In the PurchaseOrder object, check the project for isAlertable(). Hard wire the condition check at this time, because implementing a generalized predicate is premature. Then, ask the Project to send the alert emails.

The point of the first step is to see if you really understand the concept. It also lays the groundwork for future development. The point of the second step is to get the job done. There is a good possibility that, in future, you will receive similar kinds of requests for "odd" alerting requirements. In that case, you can be ready with a design that you can apply.


问:
what's the point of method overloading?
I am following a textbook in which I have just come across method overloading. It briefly described method overloading as: when the same method name is used with different parameters its called method overloading.

From what I've learned so far in OOP is that if I want different behaviors from an object via methods, I should use different method names that best indicate the behavior, so why should I bother with method overloading in the first place?

答:
Method overloading is typically used for variants of the same behavior:

Do the same thing for different types

A default version with fewer parameters and a complex version that allows more control via additional parameters.

A good example are the various massively overloaded methods in java.util.Arrays:
they do the same thing on arrays of the various primitive types, as well as providing variants that e.g. operate only on a part of the array, or do things like sorting with a Comparator rather than the natural ordering.

Title: what's the point of method overloading?


问:
Is it OK to reoccupy my old GitHub username to protect repository redirections?
I'm considering changing my GitHub username from the old alias I was using as a kid to my real name. I'm concerned about my repository URLs. GitHub will redirect the old URLs, but if someone creates a new account using my old username and creates a repository with the same name as one of my repositories, the URL redirection will break and the URL will lead to their repository, not mine.

Now, this is understandable, and GitHub recommends to not count on the redirect in the long term, and update all the remotes, but I'm concerned about some Vim plugins I'm hosting on GitHub. It's a common practice to manage Vim plugins with Git(either as separate repositories or as submodules), and if one of the plugins' remotes break you'll get error messages when you try to batch-update all your plugins(it happened to me once...). It's not that hard to solve, and the chances that'll happen are slim, but I would still like to avoid causing trouble to the users of my plugins...

To prevent this, I think to create a new account with my old username. That way I can avoid the risk of someone else taking my old username and breaking the redirects of my old repositories.

While researching this approach I've found GitHub's Name Squatting Policy. According to that policy, GitHub can delete or rename inactive accounts. To my understanding, they do this to prevent Cybersquatting, but surely this isn't the case with my fake account - I'm not holding someone else's name in an attempt to sell it to them, I'm merely occupying a name I was using to protect my old URLs...

So, is it acceptable to go with this plan an create a fake account with my old username?

答:
So, is it acceptable to go with this plan an create a fake account with my old username?

You are asking the wrong people.

There is only one arbiter of what is acceptable use of Github account names; i.e. Github themselves.

Ask them, via their normal support channels.


问:
Do input template languages exist?
When I have to create some textual representation of data, I can use a template language, so that my code does not have to worry about the structure of the output file - I can sometimes even write code that's independent of whether the output is XML, LaTeX or any other plain text. A simple example:

Template (in separate file):

```<code><someXmlTag>
$variableName
</someXmlTag>
</code>```

Code:

```<code>Template(temstring).substitute(variableName="value")
</code>```

Result (written to output file):

```<code><someXmlTag>
value
</someXmlTag>
</code>```

I want to do the same, but in the opposite direction. I have XML or plain text or whatever files to input. I want to describe the input structure in a separate file that looks like the input but has these variable declarations in it, and I want to handle it with code that's independent of the structure.

Has this been done before? What approach was used and how did it work out?

(We usually handle XML input by using an XML parser library to describe the input structure in program code, handle plaintext input by writing regexes in code, and don't handle LaTeX input because LaTeX can't really be parsed.)

答:
A variety of tools like this exist. The choice of tool depends ont the type of input and the kind of extraction or transformation required.

The simplest tool is Perl like regexps that now exist in most modern languages.
The main limitation of these is that they do not naturally handle recursive structure in the input. Also languages/formats with reasonably complex escaping/unescaping mechanisms can be tricky to capture correctly with regexps.

If you are specifically interested in XML input pattern matching then CDuce and XDuce are probably closest to what you are after. Scala also has a similar but weaker form of XML pattern matching built into the language.
This kind of thing used to be a fairly active area a few years ago, many of the tools are listed on this Wikipedia page.

General input with recursive structure requires some form of parser generator like yacc, bison or Antlr.

Title: Do input template languages exist?


答:
Absolutely.

Often, I participate in the development of open-source projects I use at work -- there's no better way to maintain expertise on something than to be one of the people who wrote it!

Coding on things unrelated to work can help one avoid tunnel-vision in programming.  By staying active in different kinds of development projects, I've avoided "well...we always did it like that" syndrome.

Working in open source, I've had the opportunity to receive guidance from coders far more experienced than myself; this has made me a better coder.

Working in open source, I got real-world experience managing development teams, so I was ready when I came to a leadership position at work.

Working in open source, I get exposed to new technologies earlier than I would in the workplace: when the time comes to evaluate technology Foo for use at work, I have opinions and the facts and experience to back them up.

It's just plain fun. :)


问:
First ATMs programming language
First ATMs performed tasks like a cash dispenser, they were offline machines which worked with punch cards impregnated with Carbon and a 6-digit PIN code.

Maximum withdrawal with a card was 10 pounds and each one was a one-time use card - ATM swallowed cards!

The first ATM was installed in London in the year 1967, as I looked at time line of programming languages, there were many programming languages made before that decade.
I don't know about the hardware either, but in which programming language it was written? (also which hardwares were used?)

*I didn't find a detailed biography of John Shepherd-Barron (ATM inventor at 70s)

Update

I found this picture, which is taken from a newspaper back to the year 1972 in Iran.

Translated PS :

Shows Mr. Rad-lon (if spelled correctly), The manager of Barros (if spelled
  correctly) International Educational Institute in United Kingdom at the right, and
  Mr. Jim Sutherland - Expert of Computer Kiosks.

In the rest of the text I found on this paper, these kind of ATMs which were called "Automated Computer Kiosk" were advertised with this moto:

Mr. Rad-lon (if spelled correctly) puts his card to one specific location of Automated Computer Kiosk and after 10 seconds he withdraws his cash.

Two more questions are:

1- How those ATMs were so fast? (withdrawal in 10 seconds in that year)

2- I didn't find any text on Internet which state about "Automated Computer Kiosk", Is it valid or were they been called Computer in that time?

答:
Most computing devices of that era were purpose-built - case, display, circuitry, operating system, backend process (if any): the whole works. This was both to get decent performance out of the beast and because there were no reasonable alternatives, general purpose CPUs were not available until the early 1970s. This doesn't mean they could only perform basic functions: the Apollo Navigation Computer was hand-wired and went to the moon and back. But it won't do anything else.

ATMs in 1967 didn't need to be complex. There was no international banking network, no multiple card types to handle (just that one bank's), no encryption to deal with. Just read the stripe, send the card number and PIN to the backend mainframe, and discharge a pre-selected amount of money.

Title: First ATMs programming language


答:
In C-family of languages, scanf() family of functions takes a format string that looks almost the same as the format string used for printf() family of functions.

```<code>int num = 5;
printf("%d", num);
scanf("%d", &num);
</code>```

For XML, XForm does two-way binding, though you would need to declare the binds separately rather than inside the template itself, XForm can even do complex stuffs like binding into repeated/looped data. What makes this possible is due to the use of XPath for describing data binds.

You could also argue that regular expression with multiple capturing groups and findall() are a kind of input template languages as well.

how did it work out?

In general, parsing in XML, JSON, or other formatted languages cannot be done with general purpose string-based input template language (e.g. scanf, regex). XML and JSON has their own idea about what tokens are significant and what tokens can be collated/ignored (e.g. whitespace), so a general string-based input formatting language will generally be too cumbersome/too limited be able to parse XML/JSON completely. If you need to parse in XML, you need an input template language that understands XML syntax, and so on.

Title: Do input template languages exist?

Body:
When I have to create some textual representation of data, I can use a template language, so that my code does not have to worry about the structure of the output file - I can sometimes even write code that's independent of whether the output is XML, LaTeX or any other plain text. A simple example:

Template (in separate file):

```<code><someXmlTag>
$variableName
</someXmlTag>
</code>```

Code:

```<code>Template(temstring).substitute(variableName="value")
</code>```

Result (written to output file):

```<code><someXmlTag>
value
</someXmlTag>
</code>```

I want to do the same, but in the opposite direction. I have XML or plain text or whatever files to input. I want to describe the input structure in a separate file that looks like the input but has these variable declarations in it, and I want to handle it with code that's independent of the structure.

Has this been done before? What approach was used and how did it work out?

(We usually handle XML input by using an XML parser library to describe the input structure in program code, handle plaintext input by writing regexes in code, and don't handle LaTeX input because LaTeX can't really be parsed.)

Body:
In C-family of languages, scanf() family of functions takes a format string that looks almost the same as the format string used for printf() family of functions.

int num = 5;
printf("%d", num);
scanf("%d", &num);

For XML, XForm does two-way binding, though you would need to declare the binds separately rather than inside the template itself, XForm can even do complex stuffs like binding into repeated/looped data. What makes this possible is due to the use of XPath for describing data binds.

You could also argue that regular expression with multiple capturing groups and findall() are a kind of input template languages as well.

how did it work out?

In general, parsing in XML, JSON, or other formatted languages cannot be done with general purpose string-based input template language (e.g. scanf, regex). XML and JSON has their own idea about what tokens are significant and what tokens can be collated/ignored (e.g. whitespace), so a general string-based input formatting language will generally be too cumbersome/too limited be able to parse XML/JSON completely. If you need to parse in XML, you need an input template language that understands XML syntax, and so on.


问:
Why learn git when there are GUI apps for GitHub?
Given that GitHub provides GUI apps for both Mac and Windows, what are the benefits of learning to use git from the command line?

Currently I'm using their mac app to update my repositories, and so far it seems to cover my needs. What might I be missing out on?

答:
I just learned one case in which CLI can be better than GUI. To illustrate this, I took an example from a book git - version control for everyone.

When you want to share over an intranet, then you can use:

Gitolite server

Common share directory with bare repositories

Look at the steps for creating a bare repo.

Creating a bare repository in CLI mode

The command for creating a bare repository would be the same as the one that you used to
clone a repository except for the  --bare parameter, which makes all the difference.
git clone --bare C:\Users\raviepic3\Desktop\Workbench C:\generic_share\
Bare_Workbench
Executing the preceding code in your console should create a bare clone of our Workbench repository in your common shared folder called  generic_share .

Creating a bare repository in GUI mode

Creating a bare clone from an already existing repository using GUI is an easy process. All you need to do is:

Copy the  .git directory from the existing repository and paste it with a different_name.git (whatever name you want to give to your new bare repository) outside the repository. In our case we have a non bare repo called  Workbench at C:\Users\raviepic3\Desktop\ inside which we have  content.docx . And now I want to create a new bare repository from this using GUI. I'll copy C:\Users\raviepic3\Desktop\Workbench.git and paste it as C:\generic_share\Bare_Workbench.git .

Open the  config file inside  Bare_Workbench.git with a text editor and find the
line which says  bare = false and replace the string  false with  true .

Save and exit.

In GUI, you have to do so many clicks and remember which file is to be edited. In CLI, one simple command does it all for you.


答:
You get consistency in naming.
    The real issue is human memory for method names, right? we find it easier to remember names that are commonly used and economy of typing, allowing for shorter method names? fewer different names means (mathematically) that the name itself carries less information.

Below is scenario ::

```<code>function Person FindPerson(string nameOfPerson) { ... }
function Person FindPerson(date dateOfBirth) { ... }
function Person FindPerson(int age, string dogsName) { ... }
</code>```

is preferable to 'uniquely named' functions:

```<code>function Person FindPersonByName(string nameOfPerson) { ... }
function Person FindPersonByDOB(date dateOfBirth) { ... }
function Person FindPersonByAgeAndDogsName(int age, string dogsName) { ... }
</code>```

This way the coder writing a client calling these functions can operate at a higher level of conceptual thinking ("I need to find a person") and doesn't need to remember- the compiler will be left to match the applicable overload.

Title: what's the point of method overloading?

Body:
I am following a textbook in which I have just come across method overloading. It briefly described method overloading as: when the same method name is used with different parameters its called method overloading.

From what I've learned so far in OOP is that if I want different behaviors from an object via methods, I should use different method names that best indicate the behavior, so why should I bother with method overloading in the first place?

Body:
You get consistency in naming.
    The real issue is human memory for method names, right? we find it easier to remember names that are commonly used and economy of typing, allowing for shorter method names? fewer different names means (mathematically) that the name itself carries less information.

Below is scenario ::

function Person FindPerson(string nameOfPerson) { ... }
function Person FindPerson(date dateOfBirth) { ... }
function Person FindPerson(int age, string dogsName) { ... }

is preferable to 'uniquely named' functions:

function Person FindPersonByName(string nameOfPerson) { ... }
function Person FindPersonByDOB(date dateOfBirth) { ... }
function Person FindPersonByAgeAndDogsName(int age, string dogsName) { ... }

This way the coder writing a client calling these functions can operate at a higher level of conceptual thinking ("I need to find a person") and doesn't need to remember- the compiler will be left to match the applicable overload.


答: The most obvious way my work productivity has benefitted from open source is when I submit a bugfix for a bug that is preventing me from doing work.</p>


问:
AngularJS: structuring a web application with multiple ng-apps
The blogosphere has a number of articles on the topic of AngularJS app structuring guidelines such as these (and others):

http://www.johnpapa.net/angular-app-structuring-guidelines/

http://codingsmackdown.tv/blog/2013/04/19/angularjs-modules-for-great-justice/

http://danorlando.com/angularjs-architecture-understanding-modules/

http://henriquat.re/modularizing-angularjs/modularizing-angular-applications/modularizing-angular-applications.html

However, one scenario I have yet to come across for guidelines and best practices is the case where you have a large web application containing multiple "mini-spa" apps, and the mini-spa apps all share a certain amount of code.

I am not referring to the case of trying to have multiple ng-app declarations on the same page; rather, I mean different sections of a large site that have their own, unique ng-app declaration.

As Scott Allen writes in his OdeToCode blog:

One scenario I haven't found addressed very well is the scenario where
  multiple apps exist in the same greater web application and require
  some shared code on the client.

Are there any recommended approaches to take, pitfalls to avoid, or good sample structures of this scenario that you can point to?

Update - 9/10/2015

One project with an interesting organization strategy is MEAN.JS and its modules folder.

https://github.com/meanjs/mean

https://github.com/meanjs/mean/tree/master/modules

Another example is from the ASP.NET Music Store SPA example.
https://github.com/aspnet/MusicStore
https://github.com/aspnet/MusicStore/tree/master/src/MusicStore.Spa/ng-apps

答:
If your application needs multiple ng-app declarations on the same page, then you need to manually bootstrap AngularJS module, by injecting a module name as shown below :

```<code>angular.element(document).ready(function() {
  angular.bootstrap(document, ['TodoApp']);
});
</code>```

This  plunker elaborates on how we could manually bootstrap AngularJS.

Body:
If your application needs multiple ng-app declarations on the same page, then you need to manually bootstrap AngularJS module, by injecting a module name as shown below :

angular.element(document).ready(function() {
  angular.bootstrap(document, ['TodoApp']);
});

This  plunker elaborates on how we could manually bootstrap AngularJS.


答:
Yes, it has been done before. For example you can use the same URL templates by routing a web application and by constructing links:

```<code>/users/{id} + {id:123} -> /users/123 -- constructing a link
/users/123 + /users/{id} -> {id:123} -- routing requests
</code>```

Be aware that input and output representations of the same data are usually asymmetric. For example by REST you respond with hypermedia and you usually request with just a simple JSON, which is a huge difference...

Input representations are usually much simpler, and they can contain validation data, while output representations are more complex, and they does not contain validation data unless they describe input fields. So your approach has its limits.

Title: Do input template languages exist?

Body:
Yes, it has been done before. For example you can use the same URL templates by routing a web application and by constructing links:

/users/{id} + {id:123} -> /users/123 -- constructing a link
/users/123 + /users/{id} -> {id:123} -- routing requests

Be aware that input and output representations of the same data are usually asymmetric. For example by REST you respond with hypermedia and you usually request with just a simple JSON, which is a huge difference...

Input representations are usually much simpler, and they can contain validation data, while output representations are more complex, and they does not contain validation data unless they describe input fields. So your approach has its limits.


答:
Single Page Apps (SPAs) aren't really intended to be used the way that you're suggesting with a really large application and multiple mini-SPAs within the main one.  The biggest problem will be page load times as everything has to be loaded up front.

One way to tackle this is using a navigation page that will take you to individual SPAs.  The navigation page will be fairly lightweight, and then you'll only load one SPA at a time based upon what was selected.  You can provide a link bar with navigation links within each of your SPAs so users don't always have to go back to the navigation page when they need to go to another area.

Using this approach can create some challenges with persisting information across SPAs.  But we're talking about something SPAs weren't intended to do.  There are some frameworks that can help with client side data persistence.  Breeze is the first that comes to mind, but there are others.

Regarding layout - several Programmers questions address large project layout, depending upon your particular needs.  I came across this one and this one.  There is nothing magical about SPAs that would affect your application layout beyond what is already answered in those questions.

That said, there are differing approaches that work best for different projects.  I would recommend sticking with the base layout as provided by the angular seed project.  Create separate folders from the provided ones for your custom packages and source code.  And within your source folder, use a project layout that makes sense for your needs.

Title: AngularJS: structuring a web application with multiple ng-apps

Body:
The blogosphere has a number of articles on the topic of AngularJS app structuring guidelines such as these (and others):

http://www.johnpapa.net/angular-app-structuring-guidelines/

http://codingsmackdown.tv/blog/2013/04/19/angularjs-modules-for-great-justice/

http://danorlando.com/angularjs-architecture-understanding-modules/

http://henriquat.re/modularizing-angularjs/modularizing-angular-applications/modularizing-angular-applications.html

However, one scenario I have yet to come across for guidelines and best practices is the case where you have a large web application containing multiple "mini-spa" apps, and the mini-spa apps all share a certain amount of code.

I am not referring to the case of trying to have multiple ng-app declarations on the same page; rather, I mean different sections of a large site that have their own, unique ng-app declaration.

As Scott Allen writes in his OdeToCode blog:

One scenario I haven't found addressed very well is the scenario where
  multiple apps exist in the same greater web application and require
  some shared code on the client.

Are there any recommended approaches to take, pitfalls to avoid, or good sample structures of this scenario that you can point to?

Update - 9/10/2015

One project with an interesting organization strategy is MEAN.JS and its modules folder.

https://github.com/meanjs/mean

https://github.com/meanjs/mean/tree/master/modules

Another example is from the ASP.NET Music Store SPA example.
https://github.com/aspnet/MusicStore
https://github.com/aspnet/MusicStore/tree/master/src/MusicStore.Spa/ng-apps


问:
Should sanity be a property of a programmer or a program?
I design and implement languages, that can range from object notations to markup languages. In many cases I have considered restrictions in favor of sanity (common knowledge), like in the case of control characters in identifiers. There are two consequences to consider before doing this:

It takes extra computation

It narrows liberty

I'm interested to learn how developers think of decisions like this. As you may know Microsoft C# is very open on the contrary. If you really want to prefix your integer as Long with 'l' instead of 'L' and so risk other developers of confusing '1' and 'l', no problem. If you want to name your variables in non-latin script so they will contrast with C#'s latin keywords, no problem. Or if you want to distribute a string over multiple lines and so break a series of indentation, no problem.

It is cheap to ensure consistency with restrictions and this makes it tempting to implement. But in the case of disallowing non-latin characters (concerning the second example), it means a discredit to Unicode, because one would not take full advantage of its capacity.

答:
Don't go out of your way to prevent bad code. You'll never cover any sizable subset of all the ways to write bad code and every additional rule costs something (time, money, mental capacity, opportunity, complexity, etc.). One can write FORTRAN in any language, don't try to fight it.

Instead, ask positive questions: How much do I, and the user, gain by restricting the language this? Does it make the parser simpler and faster? Does it really simplify the language? Does it make it easier to write good code (as opposed to harder to write bad code)? Does it have synergies with other features that add entirely new benefits? Weigh those benefits against the aforementioned costs.


问:
Preferred way for dealing with customer-defined data in enterprise application
Let's say that we have a small enterprise web (intranet) application for managing data for car dealers. It has screens for managing customers, inventory, orders, warranties and workshops.

This application is installed at 10 customer sites for different car dealers.

First version of this application was created without any way to provide for customer-specific data. For example, if dealer A wanted to be able to attach a photo to a customer, dealer B wanted to add e-mail contact to each workshop, and dealer C wanted to attach multiple PDF reports to a warranty, each and every feature like this was added to the application, so all of the customers received everything on new update.

However, this will inevitably lead to conflicts as the number of customers grow as their usage patterns are unique, and if, for instance, a specific dealer requested to have an ability to attach (for some reason) a color of inventory item (and be able to search by this color) as a required item, others really wouldn't need this feature, and definitely will not want it to be a required item. Or, one dealer would like to manage e-mail contacts for their employees on a separate screen of the application.

I imagine that a solution for this is to use a kind of plugin system, where we would have a core of the application that provides for standard features like customers, inventory, etc, and all of the customer's installed plugins.

There would be different kinds of plugins - standalone screens like e-mail contacts for employees, with their own logic, and customer plugin which would extend or decorate inventory items (like photo or color).

Inventory (customer,order,...) plugins would require to have installation procedure, hooks for plugging into the item editor, item displayer, item filtering for searching, backup hook and such.

Is this the right way to solve this problem?

答: In the beginning, you will develop "custom" designs for your existing customers. Once you have a "critical mass" of these "custom" designs (for your original customers), you will be able to mix and match your designs for newer customers. At this point it will make sense to have specific installation procedures, hooks, editors, etc. </p>