问:
Does "open source" ever become "my source"?
If I were to download some open source code that does some neat thing that I am needing, but doesn't have nearly as many options or bells and whistles that I need... and I make a TON of changes to where some of the base code is still there from the open source project, but a lot has changed and a lot has been added... will that code ever become "my source" as opposed to "open source"?

EDIT:

BTW, I don't actually have a project in mind, this is just in general terms - so I wouldn't know the license. This question just crosses my mind from time to time when I see a project that I could improve on...

答:
There are few things you need to learn when dealing with opensource code. First, you can visit this wikipedia link for an overview of Opensource

The next thing to consider is the opensource license you are dealing with. Not all opensource license allows to do what you are thinking of achieving. For detailed reference to the licensing, vist Opensource license. Match the license of your code with the one found on this link and learn what can be done with the code you are making use of.


答:
It depends on the license that the Open Source project is using. If it is a GPL license, if you ever intend to release you binaries or source to the public, then you must use a GPL-compliant license. That means the code will never be entirely yours.

If the license is the Free-As-In-Free-Beer license, then you can do anything you want with it and probably release it as your code too, unless it specifies otherwise.

ContentLicense: CC BY-SA 3.0

Title: Does "open source" ever become "my source"?

Body:
If I were to download some open source code that does some neat thing that I am needing, but doesn't have nearly as many options or bells and whistles that I need... and I make a TON of changes to where some of the base code is still there from the open source project, but a lot has changed and a lot has been added... will that code ever become "my source" as opposed to "open source"?

EDIT:

BTW, I don't actually have a project in mind, this is just in general terms - so I wouldn't know the license. This question just crosses my mind from time to time when I see a project that I could improve on...


问:
Is it normal to think about a design problem for days with no code written?
Sometimes I stare blankly into space or sketch ideas and write some pseudo codes on paper. Then I scratch it out and start again, then when I think I have the correct solution for the problem I begin writing the code.

Is it normal to think for days without writing any code? Is this a sign that I am approaching the problem entirely wrong? It makes me nervous to not getting any tangible code written in my IDE.

答:
Here's my thought case.

Starting from scratch First a rough idea of what you want is required. Try to get a list of some requirements, or create them. It should take a bit of time to figure things out here. Once you have at least a piece that you are confident you want, knowing most of the interface of that piece, then start coding.

Fixing a problem with existing code First of all, track through the problem. This might require some time of not writing real code (Some debug code might be written, but this typically won't be kept). Once you find the problem, depending on the complexity, start writing code to try and fix it. Little thought should be required once the bug is known. If the issue works out to be a major design flaw, see the next section.

Design changes/ major features This is most likely the one which will require the most thought. Thought as to preserving structure, backwards compatibility, etc. must be included. Thinking through for the best change could save a significant time, but typically for me is not more than a few days.

Adding a simple feature If no significant design change is required, then simply code in your feature, using some trial/error. This shouldn't require a ton of time in general.


问:
Analyzing a programming language
In SICP, the authors state (Section 1.1) that there are three basic "mechanisms" of programming languages:

primitive expressions, which represent the simplest entities the language is concerned with

means of combination, by which compound elements are built from simpler ones

means of abstraction, by which compound elements can be named and manipulated as units

How can I analyze a mainstream programming language (Java, for example) in terms of these elements or mechanisms?

答:
I don't know if it is correct, but the way I understand the division is as follows:

primitive expressions,
These would be, things such as >>,+,*,/,int,boolean,variables,methods etc.

means of combination,
This can be debatable, either its things like + and concact, or its talking about more advanced ideas like inheritance vs composition and the methods to do that. Injection, the new operator, extending etc.

means of abstraction,
This would be the syntax used to name variables, and methods, as well as means of creating interfaces, classes, static classes, overloading methods etc.

However, its possible you need to give us more info from the book so we know exactly what is meant there.

ContentLicense: CC BY-SA 4.0

Title: Analyzing a programming language


答:
In short no.

What you are describing is plain and simple a derived work.  It can be 99.9% code that you have added, but because it is derived from some one elses code, you are still required to respect the copyright and license of the original code.

What other options do you have?

```<code>Can you look at that code, see how it works and then write your own version from scratch?
</code>```

This is not so clear cut. However you are still at substantial risk of breaching copyright.   If you copy any code verbatim It's a breach.  If you cut and paste code and then rename the variables etc... It's a breach.  If you copy a technique to solve a specific problem, writing new code as you go, that is still a breach of copyright.

If you look at the code and think that's how you use that function and then go off and write your own program from scratch without copying verbatim those two lines of code then you are probably the owner of your code.

```<code>To be 100% sure of owning my code, what doctor need to do?
</code>```

The key is to avoid the risk of copyright claims in the first place. Do not look at copyrighted code for examples. So not write code when someone else (like your employer) could have a claim on your code). Use source control to log regular changes to the code. ( this proves you wrote it, and demonstrates the code development rather than you copied it wholesale) and do not reuse your code in an environment where the recipient has reason to believe they now own the code.

```<code>So why is everyone else talking about licenses?
</code>```

Most code available on the Internet is available under license. That license allows you access to that code on terms that the code owner has chosen. How you can use that code and you entitlements and rights to the code are defined in the software license, and may entitle you to create derived works, to sell those for profit and to not have to give anyone your source code. Likewise it may not. It all depends on the license terms.  However someone else owns the copyright to the original code and you cannot prevent them licensing that same code to your competitors.

Body:
In short no.

What you are describing is plain and simple a derived work.  It can be 99.9% code that you have added, but because it is derived from some one elses code, you are still required to respect the copyright and license of the original code.

What other options do you have?

Can you look at that code, see how it works and then write your own version from scratch?

This is not so clear cut. However you are still at substantial risk of breaching copyright.   If you copy any code verbatim It's a breach.  If you cut and paste code and then rename the variables etc... It's a breach.  If you copy a technique to solve a specific problem, writing new code as you go, that is still a breach of copyright.

If you look at the code and think that's how you use that function and then go off and write your own program from scratch without copying verbatim those two lines of code then you are probably the owner of your code.

To be 100% sure of owning my code, what doctor need to do?

The key is to avoid the risk of copyright claims in the first place. Do not look at copyrighted code for examples. So not write code when someone else (like your employer) could have a claim on your code). Use source control to log regular changes to the code. ( this proves you wrote it, and demonstrates the code development rather than you copied it wholesale) and do not reuse your code in an environment where the recipient has reason to believe they now own the code.

So why is everyone else talking about licenses?

Most code available on the Internet is available under license. That license allows you access to that code on terms that the code owner has chosen. How you can use that code and you entitlements and rights to the code are defined in the software license, and may entitle you to create derived works, to sell those for profit and to not have to give anyone your source code. Likewise it may not. It all depends on the license terms.  However someone else owns the copyright to the original code and you cannot prevent them licensing that same code to your competitors.


问:
Munging intro level knowledge of set theory with intro level knowledge of electronics to parse and evaluate the content of HL7 messages
This question is being asked for the purposes of evaluating whether or not attempting to use things I picked up in college was a good idea, or even remotely defensible.

Last year I wrote a 'formula creator' for figuring out what to do with fields or how to populate fields of HL7 data.  The fact that it's HL7 data is almost unimportant, except for the fact that it's not always known whether or not an HL7 field is going to exist or if it's going to repeat.

Therefore, I thought, if I need to get a list of these fields I can return myself a set of them.  If I don't find them at all, I can add an undefined, fuzzy value, to the set.  Then I can evaluate certain things on the set, (i.e. do all of them exists, do more than 6 match some regular expression, do the ascend from greatest to least).

Everything works OK, except what to do with 'All Of' and empty set.

For the interest of making a program easy to use, should 'all of []' return true or false?  I tried to make a case that "In set theory, the existential operator yadda yadda deaf ears".

I'd like an answer to the first question, because it may require going back to the drawing board, but I'll fast forward a to a few months ago we got around that problem by never having an empty set.  If we encountered 0 fields in the HL7 message, we'll just ploink undefined in the set.

The way I wanted to use undefined was as some sort of catalyst for, "I have no idea".  So True or Undefined = Undefined, False and Undefined = Undefined and Not Undefined = Undefined.  I made it a point to be very consistent in my programming with this, but everything that ailed the program could have been alleviated by making "Not Undefined" = True.

I told the two guys who actually use my program to 'always make his formulas to expect the true case', cuz that's how Don Knuth does it.

In summary, my program works.  The problem is that it is encumbered by my adherence to principles, clearly outside the domain of the problem, that if I slackened would make the program flow better and function without requiring me to consult the source code.

My question is, should abstractions match the domain?

Can I legitimately argue to a nurses, bosses and (more military minded) programmers that "all of an empty sack is true" or "the opposite of unknown is still unknown"?

答:
Given the structure of HL7, wouldn't a tree be more natural than sets?  I guess even if you use a tree, the collection of child segments (or child segments of a given segment type, if that's what you are referring to) would be a set (though I would call it a collection, since sets imply not being ordered and not having duplicates, and HL7 segments might care about the order and the notion of equality of segments doesn't really exist).

I don't think it's going to work out as well to represent a collection of zero elements as a collection of one undefined element.  It will probably give you more edge cases (simple example - a count operator to determine how many segments exist).  Plus it forces you into a three valued logic, which is a pain, for no apparent benefit.

There is no reason operators that act on collections can't act on empty collections.  Again, the behavior should be what gives you the fewest surprises and fewest edge cases.  Generally this will match up with what makes sense mathematically.

Is AllOf something that checks if a property is true for every element of the collection?  If so, I assume your current implementation returns undefined for a collection of 1 undefined element?  Or did you define it such that in that case in returns true or false?  If so, you haven't gained anything versus just returning that value for an empty collection.  If it does return undefined, do you then write code that treats it as true or as false?  Either way, there's your answer to what AllOf should return for an empty set.

I personally would have AllOf return true for an empty collection (or set).  I would toss the 3 value logic unless it's proved valuable for some reason.  I would allow empty collections.  I would probably use the Composite pattern to represent HL7 nodes.  I would not use sets, but lists.  I would try to leverage the collection implementations of whatever platform I was using.  For example, in C# I would make sure I could use the generic collection extension methods and LINQ with my segments.

Yes, abstractions should match the domain, and I think the abstractions you are using could match a little better.

You could argue to nurses, bosses, and programmers about your abstractions, but really only the programmers should really need to care.  And I don't think you probably need unknowns at all, so that would cut down the amount of arguing.


答:
As others have described already NO, at least not with the standard GPL as I know it so I am not going to beat a dead horse.

Assuming this open source project is lacking and you start a completely seperate project that USES the binaries from the GPL'ed project in question and provides its own behavior to make up for the lacking behavior, then that seperate project would be YOUR source.

For instance, "Crappy LGPL project named Bamboozle is good at making widgets, but doesn't pre-process RoughArgs first.  You create a proprietary product called Flamboozle that you pass a regular OR RoughArgs and spits out Widgets.  Behind the scenes it uses Bamboozle, but does something else on top of it and that is what you are selling.

This can be perfectly legal assuming that you do not explicitly violate the license agreement and in a typical LGPL you wouldn't be as long as you include the Bamboozle license agreement with all distributed copies of Flamboozle.


问:
Why does Java not permit the use of headers as in C++
I have a question that I did not find an answer for except the following answer that does not meet my requirements:

"Because James Gosling didn't want to"

I know that Java can have interfaces (only pure virtual functions, no attributes), but it is not the exact same thing as class definitions.

答:
In every language - there are two stages for creating final binary code - compiling and linking (of course, there is loading but that has not much impact here). At the time of compiling one only needs to put hooks (the specification of functions that will be called) at appropriate place. Linker actually joins them when both real code is available. So far there is no difference between C++ and Java.

There is, however, a need for C++ to have declaration and definition separate. If you keep the implementation in header, and if the header file changes, the code which is linked with it needs to get recompiled. Where as if the definition is in separate file, the code only needs to get re-linked.

Understand that C++ does have option for having static linking which implies that the object code is fixed along with the calling application.
Please note that both in C and C++, it is not invalid to have programming in header file or even do #include . it only means that you need to bother about how linking happens with these object files.

The situation in Java is very different. Each class file is compiled with .class file. Indeed, the need for caller class function compilation which is served as a header section in .class file. However, in Java final linking is done only inside the Runtime (the virtual machine) only with given that specification of class file's byte code.

See this and this


问:
Is it a good idea to always use Google as the first step to solving a problem?

Possible Duplicate:

  Importance of learning to google efficiently for a programmer?

Avoiding lengthy discussions, as a senior level student in CS, how can I get away from Googling problems I run into? I find myself using it too much; I seemingly reach for the instant answer and then blindly copy and paste code, hoping it works. Anyone can do that. I've read the related threads about being a better programmer, but mostly those recommend practicing on pet projects, which I have done, but again I feel EVERY wall encountered, from design through completion, was hurdled with Google.

Do professionals instantly "research" their problem? Or do you guys step back and try and figure it out yourselves?

I'm talking about both 'algorithm/design' problems as well as compiler issues.

答:
I always trust my ability to come up with something, which is not necessarily beautiful. Then I try to improve on it. In case I really be stuck on something, I'll look for some inspiration on the web.

As a student, to not concentrate on what, but to look into why is what really matters. Learning is about raw creativity and aesthetic sensitivity. To me, nothing ever compares to originality. To rediscover or to reinvent something makes an awful lot more sense than to just know or master something.

The web is merely a tool but not instrumental in developing our ability to discover and to create something truly beautiful.


问:
Values, types, kinds, and…?
We all know what a value is. A type is the type of a value. A kind is (loosely) the type of a type. A type constructs a value; a kind constructs a type. So what is the type of a kind, a thing that constructs kinds?

Is there such a thing? Does it have a name? Is it useful?

答:
According to the basic Wikipedia entry about kinds "a kind is the type of a type constructor or, less commonly, the type of a higher-order type operator".  So I understand that to mean the type of a kind is a kind and it's kinds all the way down (which makes sense - otherwise we would need an infinite number of names, one for each meta-type(i)).

From the same reference:

"(* => *) => * is the kind of a higher-order type operator from unary type constructors to proper types. These are very seldom encountered, even in programming language theory, but see Pierce (2002), chapter 32 for an application."

would seem to indicate it has limited but non-zero usefulness.

Not a great answer, but hopefully it will stop the "not a real question" close votes until someone who, say, implemented a Haskell compiler and really knows what he's talking about comes along...

Title: Values, types, kinds, and…?


答:
I agree with the other answers that, in principle, taking time to think through a problem/solution is a good idea. However, if you feel like you're stuck, I have a few recommendations for ways to get the planning process a bit more coherent:

Create design artifacts. So what if you don't write code? Maybe you just write down a journal of your thoughts. Or a sketch of a general solution. Or even just a really good summary of the problem that you refine over time. As you consider ideas and accept/reject them, keep a log of your reasoning on the subject. This way, at the end of the day you can still point to real-world deliverables as evidence of your labor.

Talk to people! There's nothing like having a living, breathing human being with whom to discuss ideas. If you think you're stuck, talk it through with someone. Grab someone--anyone!--and explain the problem to them. Sketch out your thoughts on how to solve the problem. Even if all they do is inhale, exhale, and blink for ten minutes while you babble, chances are you'll discover new insight just in the process of explaining the problem.

Title: Is it normal to think about a design problem for days with no code written?

Body:
Sometimes I stare blankly into space or sketch ideas and write some pseudo codes on paper. Then I scratch it out and start again, then when I think I have the correct solution for the problem I begin writing the code.

Is it normal to think for days without writing any code? Is this a sign that I am approaching the problem entirely wrong? It makes me nervous to not getting any tangible code written in my IDE.


问:
Organizing Git repositories with common nested sub-modules
I'm a big fan of Git sub-modules.  I like to be able to track a dependency along with its version, so that you can roll-back to a previous version of your project and have the corresponding version of the dependency to build safely and cleanly.  Moreover, it's easier to release our libraries as open source projects as the history for libraries is separate from that of the applications that depend on them (and which are not going to be open sourced).

I'm setting up workflow for multiple projects at work, and I was wondering how it would be if we took this approach a bit of an extreme instead of having a single monolithic project.  I quickly realized there is a potential can of worms in really using sub-modules.

Supposing a pair of applications: studio and player, and dependent libraries core, graph and network, where dependencies are as follows:

core is standalone

graph depends on core (sub-module at ./libs/core)

network depdends on core (sub-module at ./libs/core)

studio depends on graph and network (sub-modules at ./libs/graph and ./libs/network)

player depends on graph and network (sub-modules at ./libs/graph and ./libs/network)

Suppose that we're using CMake and that each of these projects has unit tests and all the works.  Each project (including studio and player) must be able to be compiled standalone to perform code metrics, unit testing, etc.

The thing is, a recursive git submodule fetch, then you get the following directory structure:

```<code>studio/
studio/libs/                    (sub-module depth: 1)
studio/libs/graph/
studio/libs/graph/libs/         (sub-module depth: 2)
studio/libs/graph/libs/core/
studio/libs/network/
studio/libs/network/libs/       (sub-module depth: 2)
studio/libs/network/libs/core/
</code>```

Notice that core is cloned twice in the studio project.  Aside from this wasting disk space, I have a build system problem because I'm building core twice and I potentially get two different versions of core.

Question

How do I organize sub-modules so that I get the versioned dependency and standalone build without getting multiple copies of common nested sub-modules?

Possible solution

If the the library dependency is somewhat of a suggestion (i.e. in a "known to work with version X" or "only version X is officially supported" fashion) and potential dependent applications or libraries are responsible for building with whatever version they like, then I could imagine the following scenario:

Have the build system for graph and network tell them where to find core (e.g. via a compiler include path).  Define two build targets, "standalone" and "dependency", where "standalone" is based on "dependency" and adds the include path to point to the local core sub-module.

Introduce an extra dependency: studio on core.  Then, studio builds core, sets the include path to its own copy of the core sub-module, then builds graph and network in "dependency" mode.

The resulting folder structure looks like:

```<code>studio/
studio/libs/                    (sub-module depth: 1)
studio/libs/core/
studio/libs/graph/
studio/libs/graph/libs/         (empty folder, sub-modules not fetched)
studio/libs/network/
studio/libs/network/libs/       (empty folder, sub-modules not fetched)
</code>```

However, this requires some build system magic (I'm pretty confident this can be done with CMake) and a bit of manual work on the part of version updates (updating graph might also require updating core and network to get a compatible version of core in all projects).

Any thoughts on this?

答:
I suppose that when you integrate both graph and network submodules into studio, you always must have the same version of core at a given time in the history of studio.
I would simlink the studio/libs/core submodule into studio/libs/{graph,network}/libs.

Update:

I creted multiple repositories with the dependencies you stated:

```<code>./core      <--- (v2)
./graph
./graph/libs
./graph/libs/core  <--- (v2)
./graph/.gitmodules
./network
./network/libs
./network/libs/core  <--- (v1)
./network/.gitmodules
./studio
./studio/libs
./studio/libs/graph
./studio/libs/graph/libs
./studio/libs/graph/libs/core <--- (v1)
./studio/libs/graph/.gitmodules
./studio/libs/network
./studio/libs/network/libs
./studio/libs/network/libs/core  <--- (v1)
./studio/libs/network/.gitmodules
./studio/studio
./studio/.gitmodules
</code>```

v1 and v2 are two different versions of core.
graph handles version 2, whereas network needs some work and is stuck at version 1.
In studio, the local embedded versions of core both points to v1 in order to have a working program.
Now, apart from the build perspective, everything works well with submodules.

I can now remove the following directory :

```<code>./studio/libs/network/libs/core
</code>```

And replace it with a symbolic link :

```<code>./studio/libs/network/libs/core@ -> ../../graph/libs/core/
</code>```

I commit locally this change and lose the ability to have two separate versions of core inside studio, but I only build core once.
When I'am ready to upgrade to v2, I can do :

```<code> git submodule update # (--rebase ?)
</code>```

... inside studio/libs/network.

Body:
I suppose that when you integrate both graph and network submodules into studio, you always must have the same version of core at a given time in the history of studio.
I would simlink the studio/libs/core submodule into studio/libs/{graph,network}/libs.

Update:

I creted multiple repositories with the dependencies you stated:

./core      <--- (v2)
./graph
./graph/libs
./graph/libs/core  <--- (v2)
./graph/.gitmodules
./network
./network/libs
./network/libs/core  <--- (v1)
./network/.gitmodules
./studio
./studio/libs
./studio/libs/graph
./studio/libs/graph/libs
./studio/libs/graph/libs/core <--- (v1)
./studio/libs/graph/.gitmodules
./studio/libs/network
./studio/libs/network/libs
./studio/libs/network/libs/core  <--- (v1)
./studio/libs/network/.gitmodules
./studio/studio
./studio/.gitmodules

v1 and v2 are two different versions of core.
graph handles version 2, whereas network needs some work and is stuck at version 1.
In studio, the local embedded versions of core both points to v1 in order to have a working program.
Now, apart from the build perspective, everything works well with submodules.

I can now remove the following directory :

./studio/libs/network/libs/core

And replace it with a symbolic link :

./studio/libs/network/libs/core@ -> ../../graph/libs/core/

I commit locally this change and lose the ability to have two separate versions of core inside studio, but I only build core once.
When I'am ready to upgrade to v2, I can do :

 git submodule update # (--rebase ?)

... inside studio/libs/network.


问:
Multiuser System With Encrypted Database
I am currently developing a hosted solution in ASP.NET using MVC3 and Entity Framework. This product will then be made available to a number of clients as a hosted solution.

As the data stored by each client will be critical to their business, we anticipate that many of them will insist that the data is stored in an encrypted form in the database. We are therefore designing the system with this in mind.

Are there any recommended procedures for doing this? How would one go about encrypting the clients data in such a way that even us with root access to the database cannot possibly access their data?

I believe there is no built in support in EF for encrypted data, is this true? And if so, how would one encrypt/decrypt the data?

答:
As far as preventing access, database schemas could be useful.  Schemas could be created and access could be granted to specific database users, which exclude god level accounts such as SA and so forth.  When the database is created, the creation scripts could be dynamic to allow for it.

```<code>Example:  Database1.ClientX.Table1
          Database2.ClientY.Table1
</code>```

If a database user wasn't given access to the ClientX schema, then they couldn't see any of the database no matter what thier privilege level to the DBMS system was.  Of course a user was high privilege could give themselves access to that schema, but I assume there is some trust given to the few DBAs who actually have those permissions.

As far as encryption, probably some sort of secure middleware layer would be the best.  Each middle ware layer could have a different private key, so they couldn't decrypt each others data.  That way you wouldn't have to store keys on each client, but on the middle layer, maybe in a config file or something.

The keys to encrypt the data would probably been encrypted as well so if any one got access to the server they could just grab them and connect up to the middle layer and see everything.  Who has access to those keys, someone who is trusted.

```<code>Client X Data- MiddleWare Layer X Encrypt/Decrypt- Database X
Client Y Data- MiddleWare Layer Y Encrypt/Decrypt - Database Y
</code>```

A separate DB instance would be the most secure.

Body:
As far as preventing access, database schemas could be useful.  Schemas could be created and access could be granted to specific database users, which exclude god level accounts such as SA and so forth.  When the database is created, the creation scripts could be dynamic to allow for it.

Example:  Database1.ClientX.Table1
          Database2.ClientY.Table1

If a database user wasn't given access to the ClientX schema, then they couldn't see any of the database no matter what thier privilege level to the DBMS system was.  Of course a user was high privilege could give themselves access to that schema, but I assume there is some trust given to the few DBAs who actually have those permissions.

As far as encryption, probably some sort of secure middleware layer would be the best.  Each middle ware layer could have a different private key, so they couldn't decrypt each others data.  That way you wouldn't have to store keys on each client, but on the middle layer, maybe in a config file or something.

The keys to encrypt the data would probably been encrypted as well so if any one got access to the server they could just grab them and connect up to the middle layer and see everything.  Who has access to those keys, someone who is trusted.

Client X Data- MiddleWare Layer X Encrypt/Decrypt- Database X
Client Y Data- MiddleWare Layer Y Encrypt/Decrypt - Database Y

A separate DB instance would be the most secure.


问:
Who should train new programmers? Junior or senior programmers?
On my team, we often require the most senior programmers to train/mentor the brand new junior programmers. However, these same senior programmers are the ones who are doing the bulk of the real, important work.

I've tried to argue to my manager that it makes sense to have the junior programmers, who are showing a high aptitude, take the new programmers under their wing. First off, it will free up the senior developers to work on more important initiatives (not that mentoring isn't important). Next, it will give the junior programmers a bit of pride in their job that they would be looked to for such a responsibility and they may learn something in teaching. Finally, it will save the company money, as senior developers cost a great deal more than juniors.

My boss has failed to be persuaded since this is how it has worked on this team since the beginning of time, apparently. Assuming that the decision has been made that some sort of training/mentoring is mandatory, can anyone provide me with some better arguments or tell me why I am wrong? What does your team do?

**We can all agree that seniority does not necessarily denote competence so just assume by "senior programmers" i mean "top programmers".

答: Not every top programmer is a top teacher. I would recommend to make the training by somebody who can explain and who has an overview on the 'environment' of your company (technical things, but also organizational like contacts).</p>


答:
Well if the senior programmers in the team don't really master their trade more than the juniors, only have been around longer and/or have a higher social/political status within the team, then indeed it doesn't really make a big difference who - if anyone - mentors the newcomers. Chances are, they will all gravitate towards the same level of mediocrity anyway... :-(

If, OTOH, a senior is really (at least noticeably closer to) a master programmer in the true sense of the world, it can make a big difference. A junior may easily teach not-so-best practices to the new kid on the block. And it is much more difficult to unlearn a suboptimal or bad approach later, than to start by learning the best practice.

That said, if a junior has the talent, and has reliably demonstrated that (s)he knows what (s)he is doing regarding a certain tool, technique or area, (s)he can indeed be a useful trainer on that specific area.

But note that - from a certain point of view - the whole point of mentoring/training is to enable seniors to delegate some of their not-so-challenging tasks to others, so that they can focus on the really tough stuff. For this to happen, they need to actually teach those tasks and skills to their peers first, and teach them well, so that the tasks are taken over properly, once and for all.

Title: Who should train new programmers? Junior or senior programmers?

Body:
On my team, we often require the most senior programmers to train/mentor the brand new junior programmers. However, these same senior programmers are the ones who are doing the bulk of the real, important work.

I've tried to argue to my manager that it makes sense to have the junior programmers, who are showing a high aptitude, take the new programmers under their wing. First off, it will free up the senior developers to work on more important initiatives (not that mentoring isn't important). Next, it will give the junior programmers a bit of pride in their job that they would be looked to for such a responsibility and they may learn something in teaching. Finally, it will save the company money, as senior developers cost a great deal more than juniors.

My boss has failed to be persuaded since this is how it has worked on this team since the beginning of time, apparently. Assuming that the decision has been made that some sort of training/mentoring is mandatory, can anyone provide me with some better arguments or tell me why I am wrong? What does your team do?

**We can all agree that seniority does not necessarily denote competence so just assume by "senior programmers" i mean "top programmers".


答: In most companies I have worked in, a Junior programmer was someone with less than 3 years experience. Whilst I would be happy, as an experienced programmer with mentoring experience to refer a new programmer to a junior programmer for training on a particular topic, I would want to retain control, rather than to delegate all mentoring responsibility to someone who still needs mentoring supervision themselves.</p>


答:
Look at this from another angle.  What kinds of skills and knowledge are you wanting to have transferred amongst the programmers here?  If the senior programmers are doing most of the real, important work doesn't this maintain a bit of isolation in terms of who knows which system?  Getting the juniors in to know the system so that they can be backups for the senior is a rather logical direction to take as it is that senior knowledge of potentially years of built up knowledge getting passed along that is the most important here.  Seniors mentoring juniors does seem like a kind of natural formation to my mind.

A junior programmer mentoring another junior programmer doesn't quite make sense to my mind.  Pairing a couple of junior programmers together though could make sense in a way.  In having a couple of people work together on a task so that it isn't just one person's idea can be quite useful as well as help foster a more collaborative environment where a team pulls together in a sense.  Depending on the environment you have this may or may not make a lot of sense to do.


问:
Why are people so strongly opposed to #region tags in methods?
I hear a lot about keeping methods short and I've heard a lot of programmers say that using #region tags within a method is a sure sign that it is too long and should be refactored into multiple methods. However, it seems to me that there are many cases where separating code with #region tags within a method is the superior solution to refactoring into multiple methods.

Suppose we have a method whose computation can be separated into three rather distinct phases.  Furthermore, each of these stages is only relevant to the computation for this method, and so extracting them into new methods gains us no code reuse. What, then, are the benefits of extracting each phase into it's own method? As far as I can tell, all we gain is some readability and a separate variable scope for each phase (which will help prevent modifications of a particular phase from accidentally breaking another phase).

However, both of these can be achieved without extracting each phase into its own method. Region tags allow us to collapse the code into a form which is just as readable (with the added benefit that we no longer have to leave our place in this file should we decide to expand and examine the code), and simply wrapping each phase in {} creates its own scope to work with.

The benefit to doing it this way is that we don't pollute the class level scope with three methods which are actually only relevant to the inner workings of a fourth method. Immediately refactoring a long method into a series of short methods seems to me to be the code-reuse equivalent to premature optimization; you are introducing extra complexity in order to address a problem which in many cases never arises. You can always extract one of the phases into its own method later should the opportunity for code reuse arise.

Thoughts?

答:
Although I agree that usually it's better to refactor code than to use #region, it's not always possible.

To support that statement, let me give an example.

```<code>class Foo : IComparable
{
  private String name;
  private int foo;
  private Bar bar;

  public int CompareTo(Foo other)
  {
#region Ascending on name
     if (this.name < other.name) return -1;
     if (this.name > other.name) return 1;
#endregion
#region Usual order on bar
     int compBar = bar.compareTo(other.bar);
     if (compBar != 0) return compBar;
#endregion
#region Descending on foo
     if (this.foo > other.foo) return -1;
     if (this.foo < other.foo) return 1;
#endregion
     return 0; // equal
  }
</code>```

It's easy to readjust the regions to alter the order, or to extend when addional fields are added to the class. Comments are required anyway to quickly see how the ordering is supposed to work. And most of all: I don't see how refactoring will help readability in this case.

However, those exceptions are rare. Usually it is possible to refactor, like many of the other answers say.

Body:
Although I agree that usually it's better to refactor code than to use #region, it's not always possible.

To support that statement, let me give an example.

class Foo : IComparable
{
  private String name;
  private int foo;
  private Bar bar;

  public int CompareTo(Foo other)
  {
#region Ascending on name
     if (this.name < other.name) return -1;
     if (this.name > other.name) return 1;
#endregion
#region Usual order on bar
     int compBar = bar.compareTo(other.bar);
     if (compBar != 0) return compBar;
#endregion
#region Descending on foo
     if (this.foo > other.foo) return -1;
     if (this.foo < other.foo) return 1;
#endregion
     return 0; // equal
  }

It's easy to readjust the regions to alter the order, or to extend when addional fields are added to the class. Comments are required anyway to quickly see how the ordering is supposed to work. And most of all: I don't see how refactoring will help readability in this case.

However, those exceptions are rare. Usually it is possible to refactor, like many of the other answers say.


答:
I had this situation at a previous company. The senior developers, which were only a few, were mentoring an increasing number of junior developers to the point where they could not do the other tasks assigned to them. After a while the senior developers brought it up with our manager and it was decided that the developers who were somewhere in between junior and senior would act as mentors but for difficult issues they could go ask the senior developers.

It worked out pretty well. Before that, a few of the senior developers were starting to look for new jobs because they were not being challenged at work. After, they were able to work on new features and get stuff done. What do your senior developers think of the situation?

In my view, being senior is not just about expertise in the domain, the title in your email footer or for how long you have worked. It's also a mindset, to help and guide junior developers. And what better way to get more senior developers in a team than letting the not so senior do the mentoring?


问:
Why don't we store the syntax tree instead of the source code?
We have a lot of programming languages. Every language is parsed and syntax checked before being translated into code so an abstract syntax tree (AST) is built.

We have this abstract syntax tree, why don't we store this syntax tree instead of the source code (or next to the source code)?

By using an AST instead of the source code. Every programmer in a team can serialize this tree to any language they want (with the appropriate context free grammar) and parse back to AST when they are finished. So this would eliminate the debate about the coding style questions (where to put the { and }, where to put whitespace, indentation, etc.)

What are the pros and cons of this approach?

答:
I think, if you store both the text and the AST, then you haven't really added anything useful, since the text is already there in one language, and the AST can quickly be reconstructed from the text.

On the other hand, if you only store the AST, you lose things like comments which can't be recovered.


答:
You could argue that this is exactly what byte code is in .NET.  Infact redgate's reflector program does translate byte code back into a range of .NET programming languages.

However, there are problems.  Syntax is language specific in as much as there are things that you can represent on one language that have no representation in other languages.  This occurs in .NET with C++ being the only .NET language that has access to all 7 access levels.

Outside of the .NET environment it gets much trickier.  Each language then start having their own set of associated libraries.  It would not be possible to reflect a generic syntax in  both C and Java that reflected the same execution of instructions as they solve simular problems in very different ways.

Title: Why don't we store the syntax tree instead of the source code?

Body:
We have a lot of programming languages. Every language is parsed and syntax checked before being translated into code so an abstract syntax tree (AST) is built.

We have this abstract syntax tree, why don't we store this syntax tree instead of the source code (or next to the source code)?

By using an AST instead of the source code. Every programmer in a team can serialize this tree to any language they want (with the appropriate context free grammar) and parse back to AST when they are finished. So this would eliminate the debate about the coding style questions (where to put the { and }, where to put whitespace, indentation, etc.)

What are the pros and cons of this approach?


答:
I think it works out best when the mentors volunteer for the task.  Around here, we don't have a very formal mentoring process.  Sometimes our manager has something specific in mind, but other times he says something like, "Anyone have a good idea on a project for the new guy?"  and whoever has the best idea ends up doing the mentoring.

What ends up happening is the new hire is put on a project that can afford the learning curve time, and mentored by the person most familiar with the project.  That might be someone who's been here 10 months or 10 years.  Sometimes people end up mentoring the mentors a little bit, but the advantage is the newer people still remember all the difficulties of being new and how they overcame them.


答:
I'm reiterating some of the things that have been said already but I have two views.

Business:
As a business, you want productivity and lower risks. Although senior developers are doing the bulk of the work, you want them to transfer their knowledge of the system down which lowers risk. Productivity wouldn't be affected that much because you need to give these seniors some rest time to do less critical things (teaching junior devs). Aside from systems, they also have many disciplines that junior devs do not yet know or grasp.

Respect:
Juniors taking new developers under their wing is kind of like the blind leading the blind. Juniors are not yet up-to-speed with everything to be in charged of teaching others. Also, it might not work out because the respect may not be there. Respect towards the junior developer is in question because your skill set vs the beginner's skill set is probably not that far off. Tackling a problem together is a different story though. There is no question of respect in terms of senior devs teaching beginners or even juniors. We all know that when respect is lacking in two individuals or in a team, disaster is waiting to happen...


问:
Using Vim when coding a large-scale application
I'm starting to learn Vim, and following some of the advices given here in stackexchange. I'm beginning to use it in some toy projects and I'm cool with that.

But I started to wonder how you can be productive without opening other files all the time just to know how's that class' Name, what's that macro included in other file, etc. etc.

What are the common advices you can give?

答: I do all my programming in vim.  I actually find it easier than any IDE I've used.  You can have multiple files open at the same time, even on the same screen (look up tabs and windows).  I'm usually working in X, so I have several (6) xterm screens open: one for c files in vim (several in tabs), another for headers in vim (also tabs), and non-vim windows: build, debug, configuration, etc.  Even when I'm on a pure console, I can use tabs, windows, and code folding to see what I need, and I can build, and even view manpages without exiting vim, you just need to know the right commands.  And there are so many, I'm sure I haven't even mastered half of them. And it's hard to beat vim's search and replace.</p>


答:
Whitespace and Comments

Generally an AST does not include whitespace, line terminators, and comments.

Meaningful Formatting

You are correct that in most cases this is a positive (eliminates formatting holy wars), there are many cases where the formatting of the original code conveys some meaning, such as in multi-line string literals and "code paragraphs" (separating blocks of statements with an empty line).

Code that can't be compiled

While many parsers are very resilient to missing syntax, code with errors often results in a very weird syntax tree, which is fine and dandy up until the point where the user reloads the file.  Ever make a mistake in your IDE and then all of a sudden the entire file has "squigglies"?  Imagine how that would be reloaded in another language.

Maybe users don't commit unparsable code, but they certainly do have a need to save locally.

No two languages are perfect matches

As others have pointed out, there are almost no two languages that have perfect feature parity.  The closest I can think is VB and C#, or JavaScript and CoffeeScript, but even then VB has features like XML Literals that don't quite have equivalents in C#, and the JavaScript to CoffeeScript conversion might result in a lot of JavaScript literals.

Personal Experience:

In a software application I write, we actually need to do this, as the users are expected to enter "plain English" expressions that are converted to JS in the background.  We considered only storing the JS version, but found almost no acceptable way to do so that reliably loaded and unloaded, so we ended up always storing both the user text and the JS version, as well as a flag that indicated if the "plain english" version parsed perfectly or not.


答:
I would opt for mentors primarily being a step or two below the top programmers in the organization.

While you've given some good reasons for that, I'd point out one more that I think is particularly important: teaching is one of the best ways of learning, especially learning enough more to make some of those last steps up from really good to great. One particularly important part of this is learning to not only do things well, but do a good job of articulating what you're doing and why. I, for one, have frequently found that to do a good job of explaining why I'm doing something in a particular way, I have to sit back and think about it enough that 1) my own understanding improves considerably, and 2) I often reevaluate the situation enough to improve my own work.

Although it may well be more difficult for them to do it, this can be particularly helpful for programmers whose social skills may be somewhat...lacking compared to their peers. Pushing them a bit out of their comfort zone from pure coding into more social aspects like mentoring may help them as much as the people they mentor. Obviously if you're going to do that, though, you need to be particularly careful about choosing who to pair together -- the wrong pairing could end up hurting both of them.


答:
I'm going to take a contrarian position to most of the answers here: as a student you should use Google only as a last resort. Actually, using Google is fine for looking up API signatures, man pages, or bits of language syntax. But, if the assignment is to write your own implementation of some data structure or protocol, you should aboslutely NOT be copying code from the web. If you do you are just throwing your tuition money away.

School work is different from work work. At work the goal is to create a working piece of software. At school the goal is to learn computer science and software development. Rarely will any of the software you write for school ever get run again once it's turned in. The entire point of the exercise is to make you think hard about the problem, have you chase down some of the blind alleys, and see why they are blind alleys.

Back in the 80s there was a popular movie called "The Karate Kid" (it's just been remade, but I have no idea if someone your age is familiar with it). In the movie a young kid asks his neighbor to teach him martial arts. The neighbor agrees, but says the kid has to to earn the lessons by doing some work for him first. He procedes to have the kid paint his fence and wash his car, over and over again. This drives the kid crazy, because he doesn't care about that crap, he just wants to kick the butt of the neighborhood bully. Of course in the end it's obvious that the neighbor didn't actually care about getting his fence painted or his car washed either; he was making the kid go through the exercises to teach him discipline, patience, balance, and coordination. So it is with your college assignments. The point is not just to complete the assignment, it's to learn something by completing the assignment.

You already know how to use Google. Use your college projects to learn something new.

Title: Is it a good idea to always use Google as the first step to solving a problem?

Body:
Possible Duplicate:

  Importance of learning to google efficiently for a programmer?

Avoiding lengthy discussions, as a senior level student in CS, how can I get away from Googling problems I run into? I find myself using it too much; I seemingly reach for the instant answer and then blindly copy and paste code, hoping it works. Anyone can do that. I've read the related threads about being a better programmer, but mostly those recommend practicing on pet projects, which I have done, but again I feel EVERY wall encountered, from design through completion, was hurdled with Google.

Do professionals instantly "research" their problem? Or do you guys step back and try and figure it out yourselves?

I'm talking about both 'algorithm/design' problems as well as compiler issues.


答:
I sort of like some of your idea, but you're significantly overestimating how easy it is to translate language to language.  If it were that easy, you wouldn't even need to store the AST, since you could always parse language X into the AST then go from AST to language Y.

However, I do wish compiler specifications thought a bit more about exposing some of the AST through some kind of API.  Things like aspect oriented programming, refactoring, and static program analysis could be implemented through such an API, without the implementer of those capabilities having to redo so much of the work already implemented by compiler writers.

It is strange how often programmer's data structure for representing a program is as a bunch of files containing strings.


答:
I've found that things like the business rules and design guidelines are the most critical things that a more senior programmer has to be able to pass on to junior developers or even newly hired senior/expert developers or contractors. Problems tend to come up when this key information is hoarded or never explained. Perhaps this is what your manager is concerned about more than actual programming knowledge.

As for programming knowledge itself, that is best passed around the group at all levels. Even experienced programmers learn new stuff all the time, especially in complex development frameworks. This sharing can be formal, as in a lunch-and-learn session, or through informal discussions when time permits.


问:
Why am I seeing so many for(;;) constructs?
To my way of thinking, a for loop is used to iterate over a known or determinable range.

```<code>String[] names = //something;
for ( int i = 0; i < names.length; i++ ) { //do stuff }
</code>```

which is equivalent (scoping of i aside) to :

```<code>String[] names = //something;
int i = 0;
while (i < names.length )
{
   // do stuff
   i++;
}
</code>```

In other words, the for loop is simply a (highly useful) syntactic sugar for a commonly used while construct.

However, I'm seeing a lot of for(;;) constructs on the web which are functionally equivalent to while(true)

What is the reasoning for this?  Why would the infinite for loop be preferred over the infinite while loop?

// I even saw a java textbook that didn't use while loops at all!  Leading to such monstrous constructs as:

```<code>String input = getInput();
for( ; !inputIsValid(input) ; )
{
   //redo;
}
</code>```

答: for(;;) can be read as "forever" which some find more natural than "while true".</p>


问:
Are there any unions for software developers?
Why does Software Engineering not have union representation like other professional occupations, such as teaching? Are there any unions for software developers that exist and are successful?</p>

答:
TL;DR No unions because its not in the interests of everyone else.

There are some organisations  for software developers globally, and in each country. They all share one characteristic.
What do Professional bodies for software development like, IEEE CS,ACM, BCS, and ACS have in common: no regulatory powers. Not a coincidence. Don't want another Bar Association starting up. Programming is essential to the world but arrived as a job after the other professionals had already carved out their regulatory powers.

As Software Development is not regulated anywhere in the world, it is not a Licensed profession. Most developers have university educations and are culturally disinclined to join unions.

(I'm going to use the term software development instead of software engineering from a desire to avoid the whole what is software engineering issue)

There is an interesting piece of game theory going on too:

Young developers out of school take low paying positions to get work.
Employers use the threat of getting in cheaper replacements to hold down salaries.

There is also a supply of discipline-crossers like Physicists, Electronic engineers and the like who will work in software development if they can get paid. Over production of EE's, Physicists and Mathematicians supply more cheap labour.
('Regular' engineering doesn't pay particularly well, and even being a PE isn't cost effective [check Job vacancies for PE positions and see the differential in pay against non-PE].)

Now this is not true in many other professions, as they are generally Licensed like regular engineering, Law and Medicine, for example:  Lawyers don't have to worry about firms getting in Philosophers. (Junior law is  a snake-pit though....)

Most western countries also have a special class of Visa for non permanent residents with Software skills. This is generally pushed by large firms in the country who want cheaper overseas developers. (Large corporates claim persistently there is a shortage, but this doesn't seem to be backed up by, for example by the US census data.)

Now, the Bar Association might have an issue if a special Visa was created for importing cheaper lawyers. This is not as absurd as it sounds, as Medical Doctors from most countries have to re-qualify to practice in many countries they might migrate to. So it seems like our professional friends manage that a bit better than us independent minded software developers.

So there are many downwards pressures on salaries.

Lets do a thought experiment.
Suppose there was a global Professional body for software development.
We're going to try to consider a situation where no software developer loses out. Not out of niceness, just because the jobs would all move to wherever the organisation wasn't.
It might perhaps have a de-facto membership: if you develop software , you're a member.
Lets suppose that instead of trying to get any country to stop importing labour, they just set rates that were global. The set rates would have to be ample for people in expensive, wester nations.

Obviously our brethren in the developing world would be very very happy. Happier than a Bangalore senior programmer. (and that used to be pretty happy IIRC.)

Now all software developers are happy.
Who would be unhappy?

The Physicists and EE's and Mathematicians would be happy. ( They'd be software developers)

But individuals and business globally would pay a lot more for software. They'd be unhappy.
Where is software used ? Everywhere in the world economy, there is software.

If such an organisation  existed, it'd be banned immediately. ( in most "right thinking" countries. ;))

It is, I think an isomorphic issue to "too big to fail." : Too useful to allow collective bargaining.

Software developers are victims of 1) their own success 2) their penchant for undercutting each other.  "The old rooster cage" argument.


问:
How Do I interview Front-End Web Developers?
For the first time I'm in the position where I'm helping interview potential front-end developers. The other interviewer is more business & PM-focused, although he is a former developer. I probe for knowledge and background in CSS, Javascript, and other related technologies, but those questions are really just testing for lingo.  I feel that it would be unfair to ask very specific questions about CSS when we're not in front of a computer.

I've also been given websites that these web developers have written. Is that enough to go on for interviewing front-ends?  We're also looking for general aptitude, rather than a databank of knowledge.

答:
I'd also ask about how to structure a site, such as navigation and folder layouts. This should give you a feel for how well they can put together a site as a whole rather than just laying out a page.

If your site is public facing, see what they know about search engine optimizatiion (SEO).

If they have public facing websites, visit them during the interview and quiz them about their design choices and how they did what they did.

Ask them what they would do if they were given a Photoshop layout for a site and how they would break down the task of building a functioning site from it.


问:
The cross-over between designing for performance/pre-mature optimisation

Possible Duplicate:

  When is optimization not premature and therefore not evil?

Whilst designing my own .Net SQL access library, I found that I want everything thing to run as fast as possible so I tend to look at the fastest ways of doing things. This often gets criticised as pre-mature optimisation when I am just looking for the fastest way of doing something.

My question is there a cross-over between designing for performance and pre-mature optimisation?

答:
I think the best process is to do the foundational work for your SQL database, so that you can easily make it faster, but don't actually do those steps yet.  Set up your tables smartly and write any views you need, so that the interaction with .NET's models (I assume you're using MVC) won't change.

Then, when the client, PM or Testers start complaining about performance, you can go save the day with optimization.  And keep notes (to yourself, or on the company's wiki) about what optimizations you can do, while you're still thinking about it.


答:
I've faced several interview styles over the years.  They seem to break down as follows:

Do you seem as the right sort of person?

When I have worked in these companies they seem to hire and fire quickly. At interview they make a judgement about whether you could fit in, and that you seem to be talking the right stuff, and if after a few weeks you are not demonstrating this, the new recruit fails probation and is removed.

Asked 20 random facts.

These kind of interviews are very revealing to the candidate.  They tell the candidate what problems the interviewer has faced, and the level of work involved.  The problem is that they positively select people who have read the book, rather than identify programming talent. When I have worked in these environments the quality of the other programmers has been variable, and generally poor.

Demonstrate skills.

This is the interview technique I primarily use. I give the person a role related task and then observe how they perform. Do they ask key questions about the brief? Are they familiar with the subject? Does their performance seem consistent with their CV?  Do they have a design?  Did they actually implement their design or did it stray? If you ask questions about their design decisions do they give a considered answer as to why? Or did they mentally flip a coin? If you introduce a constraint that should cause a design decision to change do they recognise that?

With regards to asking specific CSS questions whilst not on a computer, I'd agree that a 20 random question approch would not identify the best candidates for you, but I would be looking for evidence of a suitable level of familiarity of CSS issues with open questions.  e.g. can you give me an example of how you could improve the presentation of...

In my experience its best to be patient whilst recruiting, at times rejecting 90%+ of candidates and insisting on the best.

Title: How Do I interview Front-End Web Developers?

Body:
For the first time I'm in the position where I'm helping interview potential front-end developers. The other interviewer is more business & PM-focused, although he is a former developer. I probe for knowledge and background in CSS, Javascript, and other related technologies, but those questions are really just testing for lingo.  I feel that it would be unfair to ask very specific questions about CSS when we're not in front of a computer.

I've also been given websites that these web developers have written. Is that enough to go on for interviewing front-ends?  We're also looking for general aptitude, rather than a databank of knowledge.


答:
Simple answer: the person who does the training should be the person who is best at training who also wants to do training.

Some people enjoy training and mentoring. Some people hate it. You don't want people doing things they hate - it's bad for them, it's likely bad for the person being trained, and it's probably bad for the whole team. It doesn't add anything. Meanwhile, letting people do what they enjoy is good for them, the team, and hopefully the trainee will catch some enthusiasm.

Similarly, some people are good at training and some people are not. There's a type of human interaction or intelligence that allows some people to be good at understanding how others tick; a trainer should be able to deliver knowledge in a way that the trainee will understand. A good trainer can do this, and can learn that the trainee likes to 'understand' things, or 'see' things, or 'do' things - the various ways that people learn. A bad trainer delivers a rehearsed speech and is inflexible, and will get frustrated when the trainee doesn't catch on to their idiosyncratic ways of learning.

I assume you want the trainees to get the best training - thorough yet efficient. If your 'top programmers' are keen to train then they should do it. If the 'junior programmers' are up to it then they should have a shot, too. It doesn't hurt to have a few people participate in the training program - that way you can determine who wants to train, and who is good at training.

I'm not sure from your question whether you're a senior programmer who wants to get out of training (no criticism - you've got more important things to do, or just don't love it), or a junior programmer who wants to get in to it. But either way, you're trying to do what you enjoy - and don't we all want to do the tasks we enjoy? Happy employees leads to better work environments and better output.


答:
It's difficult to read and modify an AST, instead of source code.

However, some compiler related tools does allow to use the AST. Java bytecode and .NET Intermediate code work similar to an AST.


问:
Should you abandon an ORM framework when you need to implement a bulk operation?
Here's a common situation:

You need to implement a bulk operation in an application that uses an ORM framework.

After the first pass, you've noticed significant performance problems.

Here's my question:

In this situation, should you favor a solution that includes raw SQL?

Or are there well-known design patterns that can help you mitigate problems that are commonly associated with bulk operations with ORM frameworks?

EDIT:

I'm not asking if you should remove the ORM framework from the entire application.

I'm asking: Should you forgo the ORM framework for this small slice of the application?

答:
Been in that situation. Sometimes, you have to.

Some O.R.M. allows developer to skip the object model, and go straight to the database layer.

There are also O.R.M., that use bulk operations, encapsulated, as Object Oriented.


问:
Using static classes as namespaces
I have seen other developers using static classes as namespaces

```<code>public static class CategoryA
{
    public class Item1
    {
        public void DoSomething() { }
    }
    public class Item2
    {
        public void DoSomething() { }
    }
}

public static class CategoryB
{
    public class Item3
    {
        public void DoSomething() { }
    }
    public class Item4
    {
        public void DoSomething() { }
    }
}
</code>```

To instantiate the inner classes, it will look like the following

```<code>CategoryA.Item1 item = new CategoryA.Item1();
</code>```

The rationale is that namespaces can be hidden by using the "using" keyword. But by using the static classes, the outer-layer class names have to be specified, which effectively preserves the namespaces.

Microsoft advises against that in the guidelines. I personally think it impacts the readability. What are your thoughts?

答:
Namespaces in Java, JavaScript and .NET related aren't complete, and only allow to store classes, but other stuff like constants or global methods, don't.

Many developers use the "static classes" or "static methods" tricks, even if some people don't recommended.

Title: Using static classes as namespaces


答:
Many large-scale applications have been (of mine, at least, two ;) , and my guess is, many more will be written completely in Vim. IDEs as such are still a rather modern innovation, so to speak.

However, plain vanilla vi (ouch) or Vim are a bit lacking. Knowing Vim and thinking in some of its ways help a bit, and plugins help a lot, for which www.vim.org is an endless source of. Some specific to the language you're using, and some general ones (for commenting, for file browsing, for ...) turn it quickly into a very rapid development environment. After all (and some will surely argue) an IDE is just an editor with plugins packed in a nicer interface. There isn't much graphical stuff in an IDE either.

Title: Using Vim when coding a large-scale application

Body:
I'm starting to learn Vim, and following some of the advices given here in stackexchange. I'm beginning to use it in some toy projects and I'm cool with that.

But I started to wonder how you can be productive without opening other files all the time just to know how's that class' Name, what's that macro included in other file, etc. etc.

What are the common advices you can give?


答:
I believe the idea is interesting in theory but not very practical since different programming languages support different constructs some which don't have equivalents in other languages.

For example, X++ has a 'while select' statement which couldn't be written in C# without a lot of extra code (extra classes, extra logic, etc). http://msdn.microsoft.com/en-us/library/aa558063.aspx

What I'm saying here is that many languages have syntactic sugars that translate in big blocks of code of the same language or even elements that don't exist at all in others. Here is an example why the AST approach will not work:

Language X has a keyword K that is translated, in AST in 4 statements: S1, S2, S3 and S4. The AST is now translated in language Y and a programmer changes S2. Now what happens with the translation back to X? The code is translated as 4 statements instead of a single keyword...

The last argument against the AST approach are the platform functions: what happens when a function is embedded in the platform? Like .NET's Environment.GetEnvironmentVariable . How do you translate it?


答:
One aspect of experienced programmers who move from an IDE to a console / xterm environment, is finding a replacement for the indexing of source code objects (function names, variables). I believe the general term used for Microsoft's Visual Studio is Intellisense or something like that.

In the Unix/Linux world, such as vim, one tool used if ctags or the popular multiple language Open Source implementation, exuberant ctags. It is not vim specific, and is supported by a number of Unix, Linux, MS Windows, Mac OS text editors, including Emacs, CRiSP, vile & a number of other vi clones, nedit, gedit, JED, UltraEdit, BBEdit, and DreamWeaver (some of these are via third-party plugins).

Beyond that, good design and thoughtful decomposition, organization of larger projects makes the project manageable in that there are only 1-2 obvious potential places to look for any given bit of information (typedef or class definitions, etc.).

Also I use multiple instances of vim (often via view for read-only viewing of source files), as well as a limited use of multiple edit buffers per vim instance (primarily for moving or refactoring code between files). I find using only a few source files open at a time can help in its own small way, to keep me focused on the task on hand.


问:
What should I mock in tests of an application with service tier and DAO tier?
My classes are following this structure

Service Tier (creates and maps InputDTO to DB Data)

DAO Tier (actually executes DB calls)

When I write service tier JUnit tests, the DAO tier is called, and this expects an actual DB connection and getting data from the DB.

Should I be mocking the DAO tier completely from the service tier, or should I be mocking the DB connection and data received from the DB?

Secondly, the app expects certain data from a cache.

For JUnit run time, there is no cache, so how should this be handled? The service tier method includes looking up the cache to get the details.

答:
In the abstract the answer is quite simple.

You have three layers.

[The test case] -> [The behaviour under test] -> [The collaborators used by that behaviour]

The third layer is what should be mocked. For example:

the PokemonCaptureServiceTest;

tests PokemonCaptureService;

which uses Pokeball

In this example it turns out that Pokeball is third party logic. It requires all sorts of plumbing like database connections and property files etc. You trust your third party has tested it appropriately, so you'd like to omit it from your testing of PokemonCaptureService. Hence it should be mocked.

However, in another time and place, the collaborator Pokeball is a simple class that introduces very little complexity into the test case and can be included in the test easily. In this case you may decide to include a real instance of Pokeball in the PokemonCaptureService instance being tested.

There is no hard and fast rule. It is up to you to design your tests in the way that seems best to you. Your objective is to create correct and maintainable tests as quickly as possible. Experience is key here. Write more tests & you will very soon gain a good intuition for it.


答:
In my opinion, Vim gives you a very strong editor with basic features, but it's up to you to spice it up with scripts/addons you'll most likely use in your projects. These will probably be different depending on whether you mostly edit scripts, documentation, or files that need to be compiled.

As an example, I use zencoding for the occasional html/css editing, snipmate for Textmate-like snippets, and a couple of python-related add-ons (pyflakes, pep8, vimpdb, etc.) for Python coding, which is what I do most often.

Then there are other addons that I don't use often, but I still find them helpful every once in a while, like Dpaste and ConqueTerm.

Still, to me, the most useful features of Vim are built-in (time-based undo, quick navigation, range filters, etc.) - things that I couldn't find (or at least are not that easy-to-access) in IDEs. So once you set up your Vim to have the bits and pieces of an IDE that you really need (snipmate, ctags...) you can get the benefit from both IDE and console environments.

My use of Vim is console-only, so I can't say how helpful these tools are with Gvim.

Despite all the addon goodness, however, I still find myself running !grep ... or ^Z + find ... every now and then.


答:
As mentioned by umlcat, there are some ORMs that will let you use bulk operations.

Even better, many ORMs are extensible, so you can just write your own method for running bulk operations, if not supported already. If the bulk operation in your application is something you can factor out, I'd add it as a layer on the ORM (to do that, you'll probably need to write raw SQL), but then in the application, use the ORM method you've implemented.

This also makes unit testing and debugging easier. Once you have good test coverage for your ORM methods, you're free to use it in your apps. Otherwise, debugging raw SQL (especially big ones with transactions and many JOINs) can be a pain.

It once took me almost a day to spot a bug in a raw SQL call that was almost 100 LOC, and the bug was just a single character! Since then, I try to avoid having raw SQL in the app, and have all SQL procedures separately unit-tested.

Title: Should you abandon an ORM framework when you need to implement a bulk operation?

Body:
Here's a common situation:

You need to implement a bulk operation in an application that uses an ORM framework.

After the first pass, you've noticed significant performance problems.

Here's my question:

In this situation, should you favor a solution that includes raw SQL?

Or are there well-known design patterns that can help you mitigate problems that are commonly associated with bulk operations with ORM frameworks?

EDIT:

I'm not asking if you should remove the ORM framework from the entire application.

I'm asking: Should you forgo the ORM framework for this small slice of the application?


答: All the experienced programmers I have asked can recognize for(;;) more quickly than while(true) or while(1).

Title: Why am I seeing so many for(;;) constructs?

Body:
To my way of thinking, a for loop is used to iterate over a known or determinable range.

```<code>String[] names = //something;
for ( int i = 0; i < names.length; i++ ) { //do stuff }
</code>```

which is equivalent (scoping of i aside) to :

```<code>String[] names = //something;
int i = 0;
while (i < names.length )
{
   // do stuff
   i++;
}
</code>```

In other words, the for loop is simply a (highly useful) syntactic sugar for a commonly used while construct.

However, I'm seeing a lot of for(;;) constructs on the web which are functionally equivalent to while(true)

What is the reasoning for this?  Why would the infinite for loop be preferred over the infinite while loop?

// I even saw a java textbook that didn't use while loops at all!  Leading to such monstrous constructs as:

```<code>String input = getInput();
for( ; !inputIsValid(input) ; )
{
   //redo;
}
</code>```


答:
I have found the best design optimization is to find the simplest way to do things.  Complexity costs in many ways.  Most of your library is likely to be lightly used, so having the fastest performance won't be critical.  Working correctly is always critical, and much more likely with a simpler design.

Design to interfaces rather than particular implementation.  This will allow you to replace the implementation if needed.  Once you have the library implemented, you can profile it see if there are areas you can optimize.

Designing for optimization is getting more difficult and error prone.  You really need something you can measure.  Write the simplest code that works, then optimize.

Title: The cross-over between designing for performance/pre-mature optimisation

Body:
Possible Duplicate:

  When is optimization not premature and therefore not evil?

Whilst designing my own .Net SQL access library, I found that I want everything thing to run as fast as possible so I tend to look at the fastest ways of doing things. This often gets criticised as pre-mature optimisation when I am just looking for the fastest way of doing something.

My question is there a cross-over between designing for performance and pre-mature optimisation?


问:
What is a good way to familiarize myself with PHP, coming from an ASP.NET background?
Currently, I'm very comfortable with building tools/web apps in an ASP.NET environment. I'm not really looking to leave tbh, as I really like C#, ASP.NET, MVC 3, Visual Studio, etc.

However, right now I know almost nothing about PHP and that seems like a deficiency that I'd like to rectify.

Are there any books (or other learning methods) that would be a good resource to learn PHP? Obviously there are plenty of beginning PHP books, but I am already comfortable with much of what is involved with building a web page, and interested in focusing on PHP itself which might not be compatible with the scope of some beginning PHP books.

I went through the PHP Manual quite a bit, and it doesn't seem to flow as smoothly as might be ideal. Is there a beginning PHP book that would be appropriate? I miss the cohesiveness that most books contain when looking through those samples. There is lots of info more, but it feels more like a reference while coding than a primary learning vehicle.

答:
Yannis has a lot of good stuff to say there but I read, Build Your Own Database Driven Web Site, 4th Edition, and it was filled with everything I needed to know to get started on the right path to developing professional PHP web applications.

I was also working exclusively on .NET before I started doing some PHP work. PHP is a lot easier to work with but has some peculiar issues when developing large scale applications and this book gets you started on that.

One issue for me was that how PHP is not strictly an Object Oriented language. It has all sorts of functions in procedural form and Object Oriented form and it kinda takes a while to get used to, coming from a language where everything is organized into classes and namespaces.

Another one was how easily you can mix up everything in PHP making things a lot more difficult. In .NET the tools that you use, such as Visual Studio, guide you to actually practice good coding standards by doing some of the work for you. Usually a .aspx page would have it's HTML Markup and C# code separated into two files.

If you are a heavy user of .NET tools, and prefer to work with ASP.NET controls, still another is issue for you would be the lack of controls (GridView etc) in PHP. I know that there are a lot of libraries/frameworks that give you something similar but they are not exactly part of the basic PHP package.

Another issue for me was how in PHP, there is heavy use of Arrays and Hashes serving more like collections in .NET. They are everywhere and it would be a good to get used to the fact that arrays are not just an ordered list of the same type of objects/scalar units. They can server as a collection objects to house all sorts of stuff.

I can go on and on but to mention one of the major things I found very peculiar to PHP (I don't know it could be also common in other languages), is how often the "include" (and related) functions are used so commonly. I can say that the book from Sitepoint can get you up to speed with all of this.


答: Correctness first, if only to build a good set of unit tests. Optimizing within that framework will likely get the best overall results.</p>


问:
Security issues with freelancing work on an existing website
I currently have a website that has been recently completed. I'm contemplation using a freelance service such as SO for all future components. There is a considerable amount of work to be completed on-top of the existing infrastructure.

I've tried searching for an answer to this question, but it's so generic in terms that it's difficult.

My site is fairly complex using relational databases, MySQL, PHP, Javascript, JQuery, and Ajax.

I'm concerned about using a freelance worker on the site in regards to giving them admin access to the server and allowing them to access the existing databases. Is there a tried and true way to handle / manage this? I'm open to allowing it, but what safety precautions and other ideas do you have to prevent mischief?

答:
I suggest making a clone in a development environment to minimize damage if something does happen, intentional or not.

Otherwise, make sure to use ftp/database passwords that are unique to this project only.
Make a full site backup including files, settings, and database.

I agree with Shark that you don't want to hinder work performance with extreme security measures. In the end its all up to you and how important this data is. There may be some better solutions that require some time and resources if you have them, but I am under the impression you just want to get the damn thing up and running.

OwnerDisplayName: randelsr

OwnerDisplayName: David Houde


答:
Ask them about why modal dialogs are bad -- not because you think they are bad necessarily, but to see if they've thought about it. Ask them if they know what "mental model" means. Ask them to give you two examples of what they think are particularly good websites, and have them explain why they think they are good. Ask them to define what is meant by the css "box model".

In other words, don't ask them about specific syntax, ask them about what they know about the difference between good and bad websites. Syntax is easy to look up, a good design sense... not so much.

The goal isn't to make sure you only hire candidates that believe what you believe, but to find candidates that have actually thought about these things. I'd rather hire someone that disagrees with my personal opinion about modal dialogs but know why others think differently than they do, then hire someone who has the same beliefs that I do.

You want candidates that think. There are so many programmers who just code the way someone else has showed them to code without giving it a second thought. It's like the eternal battle of curly braces in C-like languages. It's not important (to me, anyway) that someone agrees with me, only that they are aware of the debate and that they have formed their own opinion rather than just doing it the way they were told to do it.


答:
In design, concentrate on the algorithm and approach to solving the problem.  In implementation, concentrate on the quirks of the language that make something efficient or inefficient.

It's been said many times, but it really is much tougher to change a bad algorithm later on than it is to optimize an implementation of an algorithm.


答:
Bypass the ORM. Not only that but bypass "regular" sql as well. Use a bulk utility of your database to insert extremely large data sets to a staging table. Then use sql to perform your staging activities.

Your "flavor-of-the-blog" ORM may not work for all situations.


问:
How do I develop in more languages with less IDEs
I would like to set up my computer so that I can develop in .net, C#, Java, ActionScript,  JS/CSS, and functional languages such as Scala or Haskell.  However, I want to do this with the least amount of full-featured IDEs to learn / programs taking up harddrive space on my computer / running multiple IDEs simultaneously.

Which programs can I use to minimize the amount of full-featured IDEs I have to learn/use.  (For example, if Eclipse could handle all of these frameworks, that would be a valid answer)

Edit:  Seems this question is still getting hits many years later. Today, (2018) I use Visual Studio Code as my "one IDE to rule em".

答:
Beware that IDE usage is a holy-war topic.

Use the best tool for the job.  If an IDE is good at language X and not at language Y, then only use it for X and get something else for Y.  Compared to pretty much any computer game you might pick off the shelf, and IDE is nothing your hard drive and system RAM can't handle.  I'll add that when tasting a new language an IDE can make it easier to start playing around, don't be afraid to get the one that fits the job.  Android Java is a good example of that- if you just want a taste there's nothing easier than Eclipse/Android to get your feet wet.


问:
Are some languages or language features better for testing?
I am, and like being, a VB.net coder. I have a couple of largish programs in c# that I must maintain and I don't really like writing C# code while developing. It isn't horrible but I much prefer the VB.net environment for development.

However recently I have started writing all my tests in C#. I started doing this so I could use all the great tools, such as the mock libraries, available in C#.

But even after I found Teleriks extremely capable justmock free edition for VB.net I have found I still write almost all my tests in C# (now using the C# version of JustMock BTW). Even when I don't need these testing tools I find that I just like C# better for writing tests.

I think I like VB.net for general coding while solving problems as I write because:
1. Like the sugary sweetness of things like XML Literals. Plus LINQ just seem easier and more expressive in VB.
2. Don't need worry about the syntax nearly as much (casing, line terminators etc.) I can focus on my ideas. (The extra verbosity is handled by #3 below and coderush and other IDE tools)
3. Think the tight integration with IDE of Visual Studio and VB.net (background compiling for example) is just the bees knees. (Though C# is getting much better.)

But for tests I am not thinking about the big picture or really solving problems. Each test method is independent and the succinctness of C# just reinforces and aids this fact.

I initially found this surprising because I always thought a scripting type language would be better for writing tests. But after actually writing many thousands of them I don't see any benefits in using a scripting language. In fact I find Option Strict and Explicit being true (which turns of the scripty nature of vb) even more helpful in the test projects.

But maybe I am wrong and there are languages even more suited to writing tests? Would something like IronPython be good for writing test? Maybe BOO with its macros? I wouldn't think so but might a functional language bring anything to the table?

More simply, are there language features that aid in writing good tests? And if so what language has the greatest numbers of these desirable features?

答:
I would say that it's more important to write your programs in a testable way than it is to seek specific language features that aid in that testing.  You can write tests in python or clojure just as easily as you can in c# or Java, if you write your programs in a way that facilitates that testing.

As a committed c# developer, I can tell you that there are definite advantages to having a structured, strongly-typed way to write programs and unit tests. But there is something to be said for working in a language that has more "immediacy" like python.  By utilizing a REPL, you can more quickly distill your ideas into testable pieces of code, and in the long run, you might need fewer unit tests, since you are constantly testing your code as you write it.


答:
I don't intent to be part of VIM vs. IDE debate. I guess that is personal pref. But i use a lot of VIM and here is why i find it very powerful to use vim

Two parts of the answer:

A. Most things VIM allows most thing you can do with IDEs,(i am not trying to put every feature but just a few non-obvious that make vi look limiting)

you can go traverse the prototypes if you have ctags enabled and do ctrl+{

You can open multiple windows simultaneously sing :sp 'filename'  command. Of course, sometime i just open multiple terminals to make life more easy.

Powerful syntax highlighting. Default as well as other stuff. Also, unlike some IDEs, if there is a mismatch of open braces, string or  don't match with closed ones, gives you a very clear indication. It is for most languages rather than specific.

You can execute command line using command ":!make" without going out of window.

Traverse much faster based on word, based on search (vi support regexp if you are available), and you can traverse { to } using ESC %

It is possible to do work in GDB while doing step debugging and keeping vi (in other window to work on the code). When you decide to change the file, you can make again and reload it in GDB.

B. Many things you find it better in VIM

Search and replacement is definitely much more powerful.

You can create your custom look and feel and (black+green as oppsed to white+blue) and more importantly your own powerful command.

Vertical Block select. Try ctrl+v and move cursor vertically. This is truly an unimaginable feature!

Sounds wiered -but try to cut/copy a block and having to past it 30 times! It takes no more effort than doing it 1 time. Also, try to redo (not undo) an activity one or multiple times.

Auto indenting, tab control and automated way to convert your comments in block comments or comments of particular styling.

Effective merge conflict with vimdiff.

The most important thing with console based work environment is that you never touch the MOUSE! so if you are fast on key board- IDE's are no good.

Work on multiple machines, servers simultaneously! Doesn't look obvious but sometimes when you work on server, you directly login in multiple machines and do things.

Will answer about how to do in vi if those features are in serious demands.
See this site Vimcast. of course, there are many.

But yes, most console based stuff is old fashioned, and in no way i am saying anything against IDEs.


问:
Any good resources for a non-technical guy to learn software project management?
There are many resources on general project management, but are there any specifically for non-technical people for software project management, covering topics such as requirements gathering, use cases and general architecture?</p>

答:
Project Management is a unified issue. Every scenario(that may be the company envo, the team, co-ordinators, clients etc) makes you to adapt around basic fundamentals of sofware development and project management as in whole. There are two books which i would like you to consider and read for implementing better strategies in managing and outputting a project.

Software Project Management: A Unified Framework : This book provide detailed study on economics, metrics, and management strategies necessary to plan and execute a software project successfully.

Software Project Survival Guide (Pro -- Best Practices) : This one comes from Microsoft publications and in this the Author, Steve McConnell cover the concepts and strategies you need for mastering the development process, including planning, design, management, quality assurance, testing, and archiving


问:
Values, types, kinds, and…?
We all know what a value is. A type is the type of a value. A kind is (loosely) the type of a type. A type constructs a value; a kind constructs a type. So what is the type of a kind, a thing that constructs kinds?

Is there such a thing? Does it have a name? Is it useful?

答: In Haskell, we call the "types" of kinds sorts, though I don't know the nomenclature for other languages.

Title: Values, types, kinds, and…?


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

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

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

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

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

答:
As for code (from short snippets to whole classes) you have written and which you think that you will possibly need to reuse in the future: maintain a public programming blog in which you write and explain all of these. This has a number of advantages:

The most obvious, you will have a code repository to check in the future.

You will want to write really useful blog posts, so that other people that might read them will actually understand them. Most times this will force you to refactor your code on the fly, which is a good thing.

Occasionally blog readers may point bugs or suggest useful improvements to your code, which is a VERY good thing.

You may write a regular blog or use programming oriented sites like Refactor My Code or The Code Project.


问:
What is an effective way to familiarize yourself with a new application in a new language?

Possible Duplicate:

  How do I pick up a new language quickly, given I know several others?

I started a new job working on an application I'm vaguely familar with, and it's in PERL! I come from a PHP and Java background, so while I understand the basics, there are lot of nuances in PERL that make it troublesome.

updated
<
Im supposed to be a UI developer, but the smallness of the office requires me to learn and do a lot more than just javascript. So that was slightly unexpected in some aspects and I'm just thinking about what approach to take with this > /updated

So far I've been sifting through the code to understand what each part does, printed out copies of code and try to lookup APIs I'm not familiar with, and so I dunno how effective this process is -- I feel like it's gonna take some time -- and I dont want my new employers to feel like I'm not being productive.

Anyone have some ideas or approaches for this kind of situation?

I read some of the questions about learning new languages, but I'm curious to see if anyone's had experience with this with PERL.

答:
You should focus your learning on small use cases in the code. Try to run a specific scenario. See what parts of the code it touches. Fixing bugs and writing tests helps you focus as well.

Also, try to find some documentation, specs or "architecture" documents; or someone with experience in that code base, for some "knowledge transfer". It's normal to be unproductive in new code bases, even experienced developers are. You never know how much quality (or lack thereof) you'll find.

The book "Working Effectively with Legacy Code" should help.

As for Perl, you should learn the language as much as possible. When you don't understand a particular construct, look it up. Perldocs, CPAN and a good Perl book are indispensable.

OwnerDisplayName: codeninja

OwnerDisplayName: Jordão