答:
I have about 4 years of experience, and I can tell you from my experience as a junior developer what I wish I had in terms of mentoring. It seems that you are actually describing the type of developer I was when I started :)

Essentially you want to encourage them to learn.  Some people think that after they are done with college, they don't have to read books or learn anymore.  This kind of attitude can lead to looking for shortcuts and just "getting it done".

Get them "The Pragmatic Programmer" and have them read it. This book will help them realize that programming is a craft/career and not just a job.  Recommend books for them to read every quarter or so. Help them build their "knowledge portfolio" (as mentioned in Pragmatic Programmer).  I highly recommend Safari Books Online which has a lot of CS/Programming books.

With their knowledge portfolio, they will know where to look if they have issues.  Teach them where to look.  I myself discovered the usefulness of StackOverflow recently (and as you know, it's better looking here then just Google).

It looks like you can't spend a lot of time with them, but Pair Programming is very helpful.  If you can't do that, then at least do code reviews using CodeCollaborator or another similar tool. They don't take as much time as you think they do.

Unit tests are very important as well.  They can quickly reveal bad development practices, especially if you couple that with continuous integration.

Title: How to Mentor a Junior Developer


问:
Why almost no webpages hash passwords in the client before submitting (and hashing them again on the server), as to "protect" against password reuse?
There are many sites on the Internet that require login information, and the only way to protect against password reusing is the "promise" that the passwords are hashed on the server, which is not always true.

So I wonder, how hard is to make a webpage that hashes passwords in the client computer (with Javascript), before sending them to the server, where they would be re-hashed? In theory this doesn't give any extra security, but in practice this can be used to protect against "rogue sites" that don't hash your password in the server.

答:
I think it's a good method to use when building something like a framework, CMS, forum software, etc., where you don't control the servers that it might be installed on. That is, YES, you should always recommend use of SSL for logins and logged-in activity, but some sites using your framework/cms won't have it, so they could still benefit from this.

As others have pointed out, the benefit here is NOT that a MITM attack couldn't allow someone else to log into this particular site as you, but rather that that attacker wouldn't then be able to use the same username/password combo to log into possibly dozens of other sites you might have accounts on.

Such a scheme should salt with either a random salt, or some combo of site-specific and username-specific salts, so that someone who gains the password can neither use it for the same username on other sites (even sites using the identical hashing scheme), nor against other users of the site site who might have the same password.

Others have suggested that users should create unique passwords for every single site they use, or use password managers. While this is sound advice in theory, we all know this is folly to rely on in the real world. The percentage of users who do either of these things is small and I doubt that will change any time soon.

So a javascript password hasher is kind of the least that a framework/cms developer can do to limit the damage of someone intercepting passwords in transit (which is easy over wifi networks these days) if both the site owner and the end users are being negligent about security (which they likely are).

ContentLicense: CC BY-SA 4.0

ContentLicense: CC BY-SA 3.0


问:
How to Mentor a Junior Developer
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).

答:
Depending on the task given, I'd be tempted to take a few different approaches:

Ask them what would they try next to complete the task.  This can give an idea of where from the "I don't know what to do" to "Well, I would try this but..." category are they in terms of having their own idea that may be useful for a starting point.

Take a quick look at what they want to do and offer hints so that they figure out the problem.  This is rather than give the answer of, "Just take out this line of code," suggest they look at what is there and is it all necessary.

If the first couple aren't going to work, then I'd try to get them to follow my directions on what to do to resolve the issue.  This is the next step in the progression where if they have no idea where to start and the hints don't work, this is the next point.

Lastly, if nothing else works then I'd do the work for them but I'd try to avoid this as much as possible since this is how issues like one person intimately knowing a system get created as someone may take a view of offloading work onto me for this system that I seem to know so well.

Title: How to Mentor a Junior Developer


答:
There was once a question around here that contained this kind of information, and the piece that stuck with me the most was don't touch their keyboard

In short, tell your junior how to accomplish what they are trying to do, but do not do it for them.

But in addition to that, here are some other tips:

Encourage Google (or any other search tool). If you know the answer can be found online easily, tell them to look it up instead of telling them the answer. Ultimately you want to teach them how to teach themselves, and not have them become dependent on you.

Make yourself available to answer questions. If you are ever not available or do not wish to be interrupted, make it clear to them that they should hold their questions until a specified time.

Do code reviews regularly to tell them what they are doing right/wrong. Use this as an opportunity to point out best practices

Begin early with best practices. It's better to take extra time to teach them the right way, than to try and change their methods later on.

Get them started early with planning/documentating what they are going to be doing instead of letting them begin by writing code.

Be open to learning from them. They probably spend more time than you learning, and it's possible that they learn something that you didn't know.

Help them learn from their mistakes. There are going to be mistakes, so be sure you show them that mistakes are part of learning, and that they should use them as an opportunity to learn.

(From RuneFS below) Instead of telling them how to do something, try to help them figure it out themself. This will help improve their ability to logically work through a problem, and increases their learning ability

(From RuneFS below) Instead of telling them what they did wrong, tell them of ways they can improve it. Be sure to include why your way is better than theirs. This will boost their confidence instead of weaken it. Of course, if they aren't listening to you then don't be afraid to just tell them to do it the right way :)

Title: How to Mentor a Junior Developer

Body:
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).


问:
How can I demonstrate my productivity to management?
My university has a module for software development with a real client. Some of my team members work in the computer lab all the time, which is an extremely noisy environment with lots of interruptions and distractions. There are about 30 people always talking. People always go on Facebook, YouTube, or tell jokes to each other in addition to doing "work". Some of my team members work 3 hours every day in this environment.

I attend our weekly team meetings and use our online project management system extensively. I address all emails and have a chat client on busy, but I do get messages. I use online resources a lot when solving my problems. However, outside the team meeting and pair programming sessions, I do most of my work in a quiet environment where I can focus and concentrate and I block out all external as well as internal interruptions. I focus on my task 100%. I find that I'm about 10 times more productive this way than in the lab and I can get a lot of work done.

The problem is that our tutors or "management" don't see me doing work in the lab. Thus, I do not appear to be working to them. Thus they think I do no team work. How can I convince them that I do team work because I have lots of communication with my team, but at the same time I like to work on my own? I would like to prove that, just because I work alone a lot and don't necessarily do all of my work in the lab, I'm still a productive member of the team.

UPDATE Management told me that the problem was that I spend working in a team 60% of my time, and I work alone 40% of the time. They told me I should spend 99% of my time working with my team face to face in the lab, aka office.

Some relevant comments of some answers, that some might miss:

"Problem is I don't really need to ask my team anything, because I rather google it myself. And I trust Google a lot more than my supervisor or team members for some reason. Hence I often disagree with them. I'm not doing team work, because essentially I'm doing "web" work."

" I trust information that I find online (i.e. SE) more than my supervisor's or team mates' expertise."

UPDATE 2
I stopped doing any serious work at home, I just stay in the lab now and have fun with my team while also do some work occasionally. As the accepted answer shows, this isn't about me being productive but rather fulfilling my managers' and team mates' expectations. If I and my manager have different beliefs about how to do software development, it's the manager's that counts because they have the power to fail/fire me. In my opinion face to face meetings aren't as effective as online conversations, and working in a noisy lab isn't as productive as working in a quite environment. I think team mates shouldn't be able to interrupt me any time they want, while I'm in the middle of a task. I think one needs at least 50% of the time to do productive work alone and 50% of the time to synchronize with the team. Anyway, this is just my opinion, and that doesn't count in this case.

答:
What people perceive is more important than the truth.

In the real world, perception is reality. If they perceive you as something because of your behavior, that is what you represent and it is very hard to change this perception by trying to argue with the person. What they perceive is more important to them than reality, because it is a belief system to them at that point, and beliefs are pretty concrete and hard to change.

They have an idea of what they want you to be doing, feel lucky someone told you and didn't just kick you to the curb with no explanation. That is what happens on the outside, you just get let go for some amorphous reason, it is easier and cleaner for most people to deal with.

Remember, this involves someone forming a belief system about you, this is tricky territory!

For good or bad, you will have to do what this person believes you should be doing! Nothing else will be effective, and trying to prove them wrong is a no-win situation for you.

At many places, old school managers like to see "butts in chairs". Senior members that have proven themselves, don't have to worry about this as much, but that takes years to get to that point of trust with some people. This is changing very very slowly.

And honestly, if you are working on a team and not in a position to be communicating with them all day long, you really aren't working on a team. You are on and team and working on your own which is perceived as being a loner and cowboy, neither is a team member personality.

You can get a good set of ear plugs. Good closed back around the ear noise canceling headphones are a good investment if you like to listen to music. Personally I like to only hear the clicking of my Model M keyboard!

But you need to learn how to work in a noisy distracting environment, or change your major. In the real world, cubes are the norm, and noisy environments are prevalent.

This will be especially bad at the beginning of your career, you will be sat next to banks of copy machines, break rooms, in server rooms and next to sales and marketing people that talk about absolutely nothing all day long. Expect to work 8 - 10 hours a day in a noisy distracting environment in the real world.

It isn't about demonstrating your productivity, it is about fulfilling their expectations. And in this case they expect you to be in the lab with your team mates.


问:
What is a good alternative to the name variable for a language that only has immutable references or labels?
For example, in functional languages, variables are single assignment and their values are immutable once assigned. So they have two states unbound and bound, once bound they can't be changed.

Is there some mathematical term or other computer science term that is most appropriate for such as thing? Something that semantically doesn't imply variance or mutability.

If not there doesn't exist such as term and if you were designing a language that had such constructs, what other than the word variable would you use to for these?

I am not really looking to poll for ideas, I am trying to figure out if there is already an accepted industry ( any industry ) term for such a thing.

答:
Why not just stick with that term? It may not be 100% appropriate, but when you choose a different name that will probably a cause of more misunderstandings than the ones you try to solve. Designers of other functional languages may had the same problem, but they decided to use the term "variable", either.

XSLT (which is widely used):

http://www.w3schools.com/xsl/el_variable.asp

Haskell:

http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-240003.2

Scheme:

http://www.scheme.com/tspl2d/binding.html

Erlang:

http://www.erlang.org/doc/reference_manual/expressions.html

All of them are using the term "variable", too.

Of course, other language designers prefer to talk of "bindings" or "bound values", like here for F#:

http://msdn.microsoft.com/en-us/library/dd233238.aspx


答: constant, or const would probably be familiar to people using languages such as C and C++,</p>

Title: What is a good alternative to the name variable for a language that only has immutable references or labels?

Body:
For example, in functional languages, variables are single assignment and their values are immutable once assigned. So they have two states unbound and bound, once bound they can't be changed.

Is there some mathematical term or other computer science term that is most appropriate for such as thing? Something that semantically doesn't imply variance or mutability.

If not there doesn't exist such as term and if you were designing a language that had such constructs, what other than the word variable would you use to for these?

I am not really looking to poll for ideas, I am trying to figure out if there is already an accepted industry ( any industry ) term for such a thing.


答: It's still a variable if it can take on various values in different invocations.  In other words, even though it can't be changed once assigned, that symbol can be assigned to different values initially.  That's in contrast to a constant which contains the same value every time it is invoked.


答:
Just call them variables. Math has variables; functional languages have the same kind of variables.

See also this essay by Bob Harper on this terminology issue.


问:
Base classes as factories?
I was writing some code over the weekend and I found myself wanting to write a factory as a static method in a base class.

My question is simply to know if this is a c# idomatic approach?

My sense that it might not be comes from the fact that the base class has knowledge of the derived class.

That said, I'm not sure of a simpler way to get the same result.  A whole other factory class seems (to me at least) like unneeded complexity (?)

Something like:

```<code>class Animal
{
  public static Animal CreateAnimal(string name)
  {
     switch(name)
     {
        case "Shark":
          return new SeaAnimal();
          break;
        case "Dog":
          return new LandAnimal();
          break;
        default:
          throw new Exception("unknown animal");
     }
  }
}
class LandAnimal : Animal
{
}

class SeaAnimal : Animal
{
}
</code>```

答:
Taken to the extreme, the factory could be generic as well.

```<code>interface IFactory<K, T> where K : IComparable
{
    T Create(K key);
}
</code>```

Then one can create any type of factory of objects, which in turn could create any type of object.  I am not sure if that is simpler, it is certainly more generic.

I don't see anything wrong with a switch statement for a small factory implementation.  Once you are into large number of objects or possible different class hierarchies of objects, I think a more generic approach is better suited.

Title: Base classes as factories?

Body:
Taken to the extreme, the factory could be generic as well.

interface IFactory<K, T> where K : IComparable
{
    T Create(K key);
}

Then one can create any type of factory of objects, which in turn could create any type of object.  I am not sure if that is simpler, it is certainly more generic.

I don't see anything wrong with a switch statement for a small factory implementation.  Once you are into large number of objects or possible different class hierarchies of objects, I think a more generic approach is better suited.


答:
Ask leading questions back to steer him to answers rather than simply telling him (well you can tell him some basic things like what the server name is and what database stores the information). Show him how to find his answers.

And never rewrite his code when it is wrong, tell him what is wrong and expect him to fix it. You get what you expect. You don't help anyone by making him dependant on you.

Code reviews are critical too. And if you pair program, let him have the keyboard frequently. Even if you are telling him what to type, he will learn from doing the typing more that he will learn just sitting next to you while you program.

Take some examples from the software that are typical of how the application is structured and go through them with him line by line making sure he understands why each line is needed and what it does. It is your job to ensure he knows the coding standards and how the code is organized and why you (as a company) do things the way you do.

If he has a different way to suggest, listen carefully. In the first place he may be right. In the second place, listening will tell you where his weakness in understanding are if what he suggests is not practical. Further, people tend to respect you more if you listen to them. When he is wrong, then back to the leading questions to get him to see for himself why the idea is wrong. IF he is even close to being right, go with his ideas sometimes, nothing is more discouraging than always being told that your ideas are worthless.

Ask questions about his background. He may know some things you haven't had a chance to work with. If so and the opportunity to use them comes up, ask him questions about his knowledge.

If your application is at all old, it probably has some sneaky "gotchas" than someone new won't have any way to know about.  So when he is starting to work on an areas where you have one or more of these gotchas, you might tell him about them as he is getting up to speed before coding, then look to see if he fell into the gotcha when he coded.

Finally, you get respect in part by giving respect. Treat everyone you mentor respectfully. Don't make them feel belittled or stupid. They will listen to you alot better if you treat them with respect.

Title: How to Mentor a Junior Developer


答:
Make a distinction between lower and higher levels of learning.  If it's knowledge, comprehension, or application related, I have no problems just straight out giving them the answer, with a brief explanation of how they can look it up next time.  This isn't school, it isn't cheating, and they won't rely on you that way forever.  Just don't plan on getting anything else done for the first week or two, so it won't annoy you when you don't.

After the first couple weeks, if you get interrupted too often with these kinds of questions, use a pomodoro timer and don't answer any questions until the end of a pomodoro.  Google is easy for you now because you know what to search for.  They often don't, so if you must tell them to google something, tell them what search terms to use that will get the best results.

If a problem is related to analysis, synthesis, or evaluation, I spend more time on the topic.  This is where you provide your reasoning behind your decisions and help them reach the same conclusions.  This comes up most often in matters of design and style.  Don't just tell them to use a certain design, show them why it's superior to their first choice.  Let them make mistakes, and let them fix their own mistakes.

Title: How to Mentor a Junior Developer


答:
I always make sure the developer wants my help, and I take great care not to go deeper into explanations than their patience can tolerate.  Like everybody, I love the sound of my own voice!

I treat them as equals, and make sure to ask their opinion as often as I sound off.

Catch them doing something right and let them know.

I always learn something when I do this right -- about my craft, about my profession, about the developer, and about teaching.

The first lesson always is: when to know you've been trying it on your own too long.  Many people take pride in finding their own answers, and burn valuable time going in circles.

Title: How to Mentor a Junior Developer


答:
I've taught people various subjects in the past, and the thing that has most struck me is how most people do not have any problem solving skills. That is, if you show them an exact solution, then they are able to reuse it later if they recognize or are told they need it.

But, very few situations in life are like that. Unless your job is a "mental factory" involving sticking widget A to widget B with tool C, then you will need to have a couple of items:

A toolbox of skills and tools

A problem solving method

For example, take a look at this answer I posted. That covers the problem solving method that many people do not have. College did not teach this to anyone in the CompSci program, you either already knew or figured it out yourself.

Once the junior dev understand how to go about solving problems, they need a set of tools with which to do so.

Debugger (College never mentioned this)

Profilers

Text editor

Shell (and associated utils)

Resources (books, google, SO, manpages)

Determine what is lacking for the junior dev, and you can help them improve. Just be aware that some people really aren't interested in learning how to solve their own problems and just want an "obvious step by step" solution handed to them. These are not good developers.

Hopefully, you won't have any of those. If you do, realize that no matter how much time you spend, they won't every help themselves. It would require effort, and it is easier to just ask you to do it for them. It's similar to the welfare problem, and explained by economic theory.

Enlightened self interest says people will take what they view as the most advantageous option in any given situation. Notice that it is what they view. I see the most important thing as being self sufficient and learning. So, I do things myself. But others may see that they just need to provide working code by the deadline. So they look for the least costly method of doing so. By providing them with "freebies" they need outlay the smallest effort to complete their objective. Until you remove that crutch, they will not grow.

Title: How to Mentor a Junior Developer


问:
how to find out if spelling mistakes in source code are a serious issue or not?
I find very troubling amount of spelling mistakes I see everyday in our codebase, from which I will reproduce a very short but representative example:

```<code>ArgumnetCount
Timeount
Gor message from queue
</code>```

Unfortunately this is in no way limited to one person. There is a lot of non-native English speakers in our team who contribute to that, however I can also pinpoint some of the worst spelling mistakes to our Software Architect who is American, born and raised.

These are also to be found even in emails, presentations, documents, whatever piece of written information we have in a software development company.

I'd like to know how to find out if it is a serious issue or not?

I've always met these spelling mistakes with concern, but my own, personal, official policy is that we are not paid to spell things right, we are paid to get things done, so inside the company I never really criticized anyone about it. But I have raised this issue with some of my close friends, and never settled it for good.

答:
Spelling errors in public class names and methods are simply unprofessional.  They cost time and money.  They are painful in statically typed languages like Java, where the IDE can produce a menu of class and method names.  They are intolerable in dynamically typed languages.

Even worse are spelling errors in database table names and column names.

In my experience, correct spelling is only slightly related to the coder's English proficiency.  I have seen native English speakers produce code with essentially random spelling and word breaks, and have seen non-native English speakers who are careful to produce correct spellings.  But correct spelling is highly related to the overall code quality.  Capable programmers, no matter their English proficiency, care about the quality of their work, and are careful with naming.


答:
It should be obvious that the compiler doesn't care about misspellings, as long as you're using the same spelling, e.g. when referencing a variable. The question then becomes whether misspellings have a negative impact on the ability of team members to maintain the code.

The only way I can see to do that would be to talk to the people doing the maintenance, and you could start by asking if anyone had a harder time following code that contained misspellings.

I don't think there's any way to remove subjectivity from this issue completely, but to reduce it, you could (manually or through a script) scan the source to get an estimated number of misspellings for a particular code module, and see if maintenance on the modules with a higher number of misspellings took more time on average than those modules with fewer misspellings.

Not all modules are made equal of course, so you could think about weighting your results with various metrics such as the cyclomatic complexity of the module.

Title: how to find out if spelling mistakes in source code are a serious issue or not?

Body:
I find very troubling amount of spelling mistakes I see everyday in our codebase, from which I will reproduce a very short but representative example:

```<code>ArgumnetCount
Timeount
Gor message from queue
</code>```

Unfortunately this is in no way limited to one person. There is a lot of non-native English speakers in our team who contribute to that, however I can also pinpoint some of the worst spelling mistakes to our Software Architect who is American, born and raised.

These are also to be found even in emails, presentations, documents, whatever piece of written information we have in a software development company.

I'd like to know how to find out if it is a serious issue or not?

I've always met these spelling mistakes with concern, but my own, personal, official policy is that we are not paid to spell things right, we are paid to get things done, so inside the company I never really criticized anyone about it. But I have raised this issue with some of my close friends, and never settled it for good.


答:
Because it would add little to no value.  The reason hashing is that if your database gets hacked, the hacker would not have a list of valid password, just hashes.  Therefore they could not impersonate any user.  Your system has no knowledge of the password.

Secure comes from SSL certificates plus some form of authentication.  I want my users to supply a password so I can calculate the hash from it.

Also, the hashing algorithum would be on the server in a more secure area.  Putting it on the client, it's pretty easy to get the source code for Javascript, even if its hidden referenced scripts files.

Title: Why almost no webpages hash passwords in the client before submitting (and hashing them again on the server), as to "protect" against password reuse?

Body:
There are many sites on the Internet that require login information, and the only way to protect against password reusing is the "promise" that the passwords are hashed on the server, which is not always true.

So I wonder, how hard is to make a webpage that hashes passwords in the client computer (with Javascript), before sending them to the server, where they would be re-hashed? In theory this doesn't give any extra security, but in practice this can be used to protect against "rogue sites" that don't hash your password in the server.


问:
Are there cases where it is a good idea to disallow remote access to a database?
My coworker is working on a project and decided to have the database subside entirely on the glassfish server with glassfish being the only thing that can directly access the database. He will then create web services and a library in Java to access this data.

To me that sounds like a horrible way to structure the architecture of one of the most important databases in the company (contains all the employee data). I've mentioned to him that it is a bad idea because it isn't possible to easily get data out currently, to which he said he would write a java library to wrap the REST web service. The problem is that I deal with .NET and I told him that. The web service doesn't work and there is no documentation and currently I have to export data from the database to Excel using PhpMyAdmin and then read it from there since it would take a long time for me to properly format the SQL to work with MS SQL Server.

My question is this: does my coworker have a decent design and I'm just suffering because it is in its infancy or am I correct and this design is awful. If it is an awful design, what are points I can bring up to help him see that it may be better to have a more open database?

答:
In practice, the cases where allowing remote access to a database are extremely rare.

By allowing a direct access to a database, you let, by default, anyone:

Access all the data in your database (so, in your case, all the employee data),

Change it, because it's funny,

Delete everything, because it's even funnier.

You can give remote access:

If you are 99,999% sure that your data is protected and only authorized people can read and change it,

And if the database accounts are protected against bruteforce,

And if there is an audit you're constantly monitoring in order to shut down the database in case of a risk of unauthorized access,

And if there are regular backups of your database, preventing the loss of data if something still goes wrong.

Is it your case?

Securing your database from the outside world and letting the users access the data only through web services is like closing doors and windows in your house when leaving for a holiday and letting only the mailbox open. Allowing the remote access to your database is like letting all the doors and windows opened in your house when leaving for a holiday, and expecting that the mailman would be the only one who will enter in your house.


答:
The problem is that I deal with .NET

Web services, whether REST or SOAP, are not a Java standard.  Both Java and .NET have a number of tools for interfacing with, and generating proxy classes for web services.  This is somewhat of a universal standard.  See the Wikipedia reference for more information on Web Services.  http://en.wikipedia.org/wiki/Web_services

The web service doesn't work and there is no documentation

The WSDL is your most fundamental form of documentation but more is always better.  Typically web services are to support componentization as well as data securtity.  As a consumer of his web services you are not supposed to worry about the underlying data store.  The interface for your web service is your contract, that lays out what functionality is available, and what you need to know about the data structures.  This helps in componentization because you should be able to assume that the web service will predictably return certain results which can be easily mocked against in unit testing.

Perhaps your colleague simply designed the web services poorly and this is causing you confusion?  Perhaps you just are not familiar working with component based software before and you are confused?  Perhaps both.

He will then create web services and a library in Java to access this data.

If he creates Web Services then you do not need a Java library to access them.  You can just as easily write a .NET library, and I know that recent versions of Visual Studio have tools that can automatically create web service proxy classes for you based on a WSDL.  There is also support for REST based web services as well.

To me that sounds like a horrible way to structure the architecture of one of the most important databases in the company (contains all the employee data).

It is actually very good.  I wouldn't want inexperienced junior programmers accessing sensitive employee data that they are not authorized to view.  Only individuals with access to this server should be able to access the production database directly.

I've mentioned to him that it is a bad idea because it isn't possible to easily get data out currently

Typically your friend will give you an interface for his web service early so that you can begin development of your own components.  It doesn't matter if these web services do not exist yet, because you can mock these web service calls until the services become available.

does my coworker have a decent design

Without seeing his design documents and performing a full design review I cannot say for certain, but it sounds like he has a good idea.

Title: Are there cases where it is a good idea to disallow remote access to a database?

Body:
My coworker is working on a project and decided to have the database subside entirely on the glassfish server with glassfish being the only thing that can directly access the database. He will then create web services and a library in Java to access this data.

To me that sounds like a horrible way to structure the architecture of one of the most important databases in the company (contains all the employee data). I've mentioned to him that it is a bad idea because it isn't possible to easily get data out currently, to which he said he would write a java library to wrap the REST web service. The problem is that I deal with .NET and I told him that. The web service doesn't work and there is no documentation and currently I have to export data from the database to Excel using PhpMyAdmin and then read it from there since it would take a long time for me to properly format the SQL to work with MS SQL Server.

My question is this: does my coworker have a decent design and I'm just suffering because it is in its infancy or am I correct and this design is awful. If it is an awful design, what are points I can bring up to help him see that it may be better to have a more open database?


答:
In my experience such basic spelling errors are troubling, and may be symptomatic of deeper problems. Every project I've worked on with "trivial" errors like that had real problems in design that somehow made it through the review process only to crop up during development, which is not when you want to find out that the critical functionality you really need isn't there.

I'd double-check the specs for the system (if they exist) and examine the overall design;  I wouldn't be surprised if you found some holes.


问:
Unit testing - Database coupled app
What would be the best approach at unit testing a model that integrates into an application that is tightly coupled to database?

The specific scenario here is a shopping cart - I'd like to be able to test the adding removing and retrieving of items from the cart as well as pricing logic etc. This in my mind all requires database access though I have read several times that database access should be avoided.

答:
I built a plugin for Symfony 1.4 (PHP) to tackle this problem (among others).  It is modeled after the way Django's test framework (Python) operates:  the framework builds and populates a separate test database before each test starts, and it destroys the test database after each test completes.

I had a couple of concerns about this strategy, both in terms of performance (if the schema doesn't change, why not simply clear the data instead of rebuilding the entire structure?) and convenience (sometimes I want to inspect the database after a test failure, so don't destroy it indiscriminately!), so I took a slightly different approach.

Before the first test runs, the database is destroyed and rebuilt, in case there have been model changes since the last test.  Before each subsequent test runs, the data in the database are cleared out, but the structure is not rebuilt (though a manual rebuild can be triggered from a test if necessary).

By selectively loading data fixtures in each test, one can create the proper environment for that test without interfering with subsequent tests.  Fixture files can also be re-used, which makes this task much less onerous (though it is still my least favorite part of writing tests!).

In both test frameworks, the database adapter is configured to use the test connection instead of the "production" connection to prevent test execution from corrupting existing data.

Title: Unit testing - Database coupled app


答:
This is a common problem in the workplace. It isn't sensible or productive, but it sates a desire in certain management types.

First things first, if not spending time in the lab is going to cost you grades, spend time in the lab. This is not the time to fight for the rights and wrongs of the situation, just suck it up, get the grades, get the hell out of there.

In the workplace, it can be a sign of problems, but sometimes it is just senior management wanting everyone to feel that everyone else is pulling their weight. In organisations where you have high profile teams who work long hours it is common for management to start asking for better time keeping of other teams when profits are down and so on. Again, it's generally best just to suck it up if it's a short duration thing, or move on, but there's no real middle ground.

Title: How can I demonstrate my productivity to management?

Body:
My university has a module for software development with a real client. Some of my team members work in the computer lab all the time, which is an extremely noisy environment with lots of interruptions and distractions. There are about 30 people always talking. People always go on Facebook, YouTube, or tell jokes to each other in addition to doing "work". Some of my team members work 3 hours every day in this environment.

I attend our weekly team meetings and use our online project management system extensively. I address all emails and have a chat client on busy, but I do get messages. I use online resources a lot when solving my problems. However, outside the team meeting and pair programming sessions, I do most of my work in a quiet environment where I can focus and concentrate and I block out all external as well as internal interruptions. I focus on my task 100%. I find that I'm about 10 times more productive this way than in the lab and I can get a lot of work done.

The problem is that our tutors or "management" don't see me doing work in the lab. Thus, I do not appear to be working to them. Thus they think I do no team work. How can I convince them that I do team work because I have lots of communication with my team, but at the same time I like to work on my own? I would like to prove that, just because I work alone a lot and don't necessarily do all of my work in the lab, I'm still a productive member of the team.

UPDATE Management told me that the problem was that I spend working in a team 60% of my time, and I work alone 40% of the time. They told me I should spend 99% of my time working with my team face to face in the lab, aka office.

Some relevant comments of some answers, that some might miss:

"Problem is I don't really need to ask my team anything, because I rather google it myself. And I trust Google a lot more than my supervisor or team members for some reason. Hence I often disagree with them. I'm not doing team work, because essentially I'm doing "web" work."

" I trust information that I find online (i.e. SE) more than my supervisor's or team mates' expertise."

UPDATE 2
I stopped doing any serious work at home, I just stay in the lab now and have fun with my team while also do some work occasionally. As the accepted answer shows, this isn't about me being productive but rather fulfilling my managers' and team mates' expectations. If I and my manager have different beliefs about how to do software development, it's the manager's that counts because they have the power to fail/fire me. In my opinion face to face meetings aren't as effective as online conversations, and working in a noisy lab isn't as productive as working in a quite environment. I think team mates shouldn't be able to interrupt me any time they want, while I'm in the middle of a task. I think one needs at least 50% of the time to do productive work alone and 50% of the time to synchronize with the team. Anyway, this is just my opinion, and that doesn't count in this case.


答:
It seems that your Coworker decided to go with a Service Oriented Architecture (SOA)

SOAs have many advantages and are becoming increasingly common. I don’t know why exactly your chose this design, but you should ask him why before trying to convince him it’s wrong.

The most common reason to choose SOA is Code mobility, you can have a common codebase to be consumed my many clients. (iPhone, Android, Web App, Remote Clients ect..) Here are a few more..

On a Side note, SOA is a VERY marketable skill right now, I would not be surprised if your coworker decided to go this route just to develop those skills. Putting the ethical considerations aside, it may not be a bad idea for you to close your eyes and follow his lead.


答:
Your organisation as you describe it is very different from mine. I am in contol of my juniors work, and I do see it as my role to judge. So a lot is different.

One thing that I'd like to advise you to do anyway, is to frequently visit their desk in the first two weeks especcially. Something like three times a day the first week, gradually decreasing.

The message I try to send this way is that I care about their productivity. I make sure they dont get stuck. I ensure they follow the rules, and don't reinvent the wheel. I teach them to commit as often as possible. Learn them to develop incrementally, and think about design incrementally.

My worst nightmare are developers that each day tell you that they need just one more day to get their feature done. After weeks delay, you get an overcomplicated design, which is hacked from the start by its author. Extra unrequested buggy features, are thrown in the mix to compensate for the delay, and because they were a free side effect of the design.

I believe that many developers are inclined to this approach. If you're left on your own with a compex task, it is a natural reaction to try to prove you can do it on your own. But it is the wrong response. Quality is teamwork, and the sooner they learn, the better.

Title: How to Mentor a Junior Developer


问:
Good resources for advanced C++ topics?
What are some good resources for advanced C++ topics. I know C++, but have little knowledge of threading, advanced meta-programming and inner-workings of meta-programming and I'd like to get better. </p>

答:
A book I learned a lot from is "Advanced C++ Programming Styles and Idioms" by Jim Coplien. He starts very simple, then as you progress through the book the material becomes more and more challenging. At the end of the book you wonder whether this is still C++. Yes, it is!

This book certainly looks at C++ from a very specific angle. When I look at the various books I have read, this one sticks out and I learned a great deal from it. I'm sure other people have other favorites and that is fine, too. Jim's book is my favorite C++ book.

Title: Good resources for advanced C++ topics?


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

This question has two parts...

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

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

Update:

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

- specific server side programming optimizations

- test labs

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

答: For many applications the issue is getting developers to test with real world data sets before they are "done."  For interactive applications, a baseline test machine/VM would be required.</p>

ContentLicense: CC BY-SA 2.5


答: The first time you waste time searching for the Timeout variable just to find out it was written as Timeount, you'll know another reason why spelling is important.


答:
This is actually two separate, but related issues. It depends on where the misspellings are:

1) In source code. If you have an identifier like ArgumnetCount, that can create real problems when someone comes along and uses the correct spelling. So you should fix those mistakes whenever possible. If you need to preserve backwards API compatibility, you can do something like:

```<code>/**
 * @deprecated - use setArgumentCount()
 */
public void setArgumnetCount(int c) {
    setArgumentCount(c);
}
</code>```

2) In human-readable text (emails, documentation, code comments). Writing those correctly is important, but I would say it's a lower priority, since the parsing software inside your head is a lot more forgiving. If you see a text with a few mistakes, that's still readable, then don't worry about it - it's not your problem. But if someone sends you some free-associative nonsense and expects you to use that nonsense as the blueprint for a multi-user web application, then you should send the author a polite note requesting clarification (something like: "You illiterate moron, how do you expect me to understand this shit?")

Body:
This is actually two separate, but related issues. It depends on where the misspellings are:

1) In source code. If you have an identifier like ArgumnetCount, that can create real problems when someone comes along and uses the correct spelling. So you should fix those mistakes whenever possible. If you need to preserve backwards API compatibility, you can do something like:

/**
 * @deprecated - use setArgumentCount()
 */
public void setArgumnetCount(int c) {
    setArgumentCount(c);
}

2) In human-readable text (emails, documentation, code comments). Writing those correctly is important, but I would say it's a lower priority, since the parsing software inside your head is a lot more forgiving. If you see a text with a few mistakes, that's still readable, then don't worry about it - it's not your problem. But if someone sends you some free-associative nonsense and expects you to use that nonsense as the blueprint for a multi-user web application, then you should send the author a polite note requesting clarification (something like: "You illiterate moron, how do you expect me to understand this shit?")


答:
I'd say, just go ahead and use fixtures to pre-load the data.  It's how unit testing frameworks seem to work in general, when testing the manipulation of data.

But if you really want to avoid having to connect to a database of any sort and go by the overly-strict definition that unit tests don't touch anything outside of the code, take a look at object mocking - it may give you ideas.

For example, instead of dropping the SQL directly in the code where you need it, have a way to call a method that does only what that SQL does.   UsePerson.getPhoneNumber(), for example, instead of SELECT phone_number FROM person WHERE id = <foo>.  Not only is it cleaner and easier to understand at a glance, but during testing you can mock the Person object so that getPhoneNumber() will always return 555-555-5555 or something, instead of touching the database.

Title: Unit testing - Database coupled app

Body:
What would be the best approach at unit testing a model that integrates into an application that is tightly coupled to database?

The specific scenario here is a shopping cart - I'd like to be able to test the adding removing and retrieving of items from the cart as well as pricing logic etc. This in my mind all requires database access though I have read several times that database access should be avoided.


答:
One thing I've done here in my job that I found really useful was to setup a forum (i.e. PHPbb) for internal Q&A, and follow the rule that if the question and/or the answer takes more than 5 min, it should be asked and answered via the forum. The benefits:

It forces the junior dev to state clearly the question, which makes it easier to answer, not to mention the times in which he finds the answer himself, just by thinking a little more about it

It avoids duplicated questions, since the junior dev should start by searching for similar questions already made

It helps in building a knowledge base that will be useful for future hires and for documenting many small things that could be lost in time.

Title: How to Mentor a Junior Developer


答:
Is it colour or color?  Whose version of English do you think is the correct one?
One mans correct spelling is another mans excuse to start an winnable war.

If you want to start a war, pick your battles carefully and win them. In your case, don't worry about comments, worry less about internals and focus (almost) exclusively on API's


答:
Boze noise cancelling headphones (if you have the cash).    I use these.  They don't get rid of everything but they help.  I used them with pandora and classical music when I write code (stay away from non instrumental music or you will have a tendency to sing along and it becomes a distraction in your own mind).

This will allow you to sit in the lab and remove distractions.

Also, Jarrod Roberson's "perception" post was spot on too.  If they want to see you in the lab, then you need to be in the lab.  It doesn't matter if the boss/instructor is wrong, they are still the boss.  The perception is more important in this case than the reality.  Of course you have the choice to do it your own way, but then you'll have to take responsibility for the consequences of your decision; there are no moral victories.


答: Depending on the contex "variable" or "binding" would work. I think "binding" is more likely to come up in statements like let in Haskell or Lisp.


答:
This really sounds like a code monkey farm, professors want you to adapt to the "war room" environment, (aka open space environment) that so many companies nowadays, think is optimal.

By the time you'll leave college the optimal formula will be different, again.

(maybe they'll settle for some form of remote work, finally)

By the time I enrolled, everybody though cubicles where the best of the best.

Then, as college kids joined the workforce, "the industry" changed his mind, college kids kind of had developed a taste for computer labs where source control was done by screaming "I'm editing this file now!" and similar antics.

Real version control used to suck, (i.e. CVS, a little SVN) there was no facebook to distract, and no smartphones to circumvent LAN restrictions, so... it kinda worked.

"War rooms" where modeled after those college kids.

Those rooms didn't age up very well, though.

"War rooms" today end up being of two kinds:

noise farms, where everybody is doing whatever he likes, (and mufflers, ear plugs or headphones are the only way around it)

awkward silent panopticons, where nobody is doing anything of his liking, everybody checks on everybody, and everybody feels more and more miserable, every minute that passes.

So, instead of telling you how to work, they should observe how you get the work done and then write papers about it, so that "the industry" may learn from it.

But then again, my guess is you're in a code monkey farm, they are building computer scientists for "the industry", the way "the industry" wants them, and you're gonna run into trouble if you stand too much for your (sane) work habits.

Cope with what they're requesting, drag around the weight of your unproductive team members (poor souls, they would probably perform better in a more focused environment) and let the overall code quality degrade: you're in that class to prove that teamwork, done in the way your professor is evangelizing, doesn't work very well.


问:
How is software scalability measured?
I was asked to make some small technical presentation about specific application scalability. The application is developed using Java, Spring MVC, Hibernate. I have access to the application source code.

How can I measure software scalability (using sources) and what metrics do I need to look after when measuring software scalability?

答:
I would start with reading Wikipedia article on the subject.

In short, scalability is how system performance grows with adding more resources or, alternatively, how the resource utilization grows with increasing load. For example, how many concurrent users can your site handle until response time grows beyond 0.3 sec? The same question after you double the available RAM/disk/CPU/etc. You probably can use your knowledge of the application internals to decide which parameters are worth checking.

Setup a test bench with a server machine and one or more client machines. Use some tool to limit the amount of resources available to the server (e.g. ulimit) or run some interfering application on the server. Measure how the server deals with client requests. Repeat the above gradually increasing/decreasing interfering load/available resources. At the end you get n-dimensional space with  dots in it. It may be simpler to change only one parameter at a time while fixing all the others at some typical value (or a couple of values). In this case you can represent the result as a bunch of 2D graphs with server performance (e.g. number of users/requests) on one axis and resource utilization/availability on the other.

There are more complex scenarios where your application uses several servers for several part of the application and you can vary their amount and ratio, but I guess it's not your case. At most, you probably may want to vary the number of threads/processes, if this matters.

If you measure the whole application you usually don't need source code access. However, you may be interesting in measuring some specific part of the code (e.g. only DB or UI). Then you can use the source code to expose only this module for measurements and run your tests. This is called a microbenchmark.

If you're looking for examples, there is a plenty of them in academic articles. Search the google scholar for performance evaluation + your preferred terms.

Title: How is software scalability measured?


问:
Built in Scala library slow?
I found this question and accepted answer on StackOverflow. It's related to the slow JSON parser in the standard Scala library.

The consensus as it were,  is that the build-in JSON library is slow, and, in the words of DMC: "it's like that, and that's the way it is"

Maybe I'm just being naive here, but that sounds like a bad approach to grow the language. Shouldn't the built-in libraries be perfect? They don't have to be everything for everyone, and I accept that Scala is extendable. But, if there is a built-in library, then surely it should be rock solid and as fast as the language have to offer.

I'm lodging a complaint with Star Command ;-)

Does anyone know where or how a normal guy like me can voice my opinion on this, i.e. where we can go to help shape the Scala language?

Update:

This question was not intended in any negative way. Scala, it's creators and the Scala community is choc-full off goodness. I was simply surprised to see that something like the built-in JSON parser was far from optimal (according to the question in the link provided)

答: So fix it. This is how open-source works my man. You have an itch, you scratch it. You do know you can run Java JSON parsers in Scala, right? </p>

Title: Built in Scala library slow?


问:
What are effective ways to introduce the concept of code kata into the workplace?
In your experiences, what are some effective ways to introduce code kata practice into an organization or company?

To be clear, I'm not concerned with the usefulness of code kata. I'm interested in methods to introduce this concept to a development team.

答: One idea is when implementing a new algorithm that is a bit tricky or difficult is have multiple developers implement it independently. More than likely there will be two or more different implementations. Then switch with each other and try and implent the others implementation independently. Then get together and determine which way is best. This way you practice and it looks like you are just getting to the best solution.</p>


答:
Interestingly, I worked at a startup where we ended up doing this.  I think it actually worked pretty well, but only because of the specific situation we were in.  It was a mod_perl shop where class auto-reloading actually worked correctly.  All the developers used vim as their IDE of choice (or used some remote editing software).  The end result was that very little (if any) time was lost waiting for code to compile/reload/etc.

Basically, I like this idea IFF there is a negligible impact on the development cycle for all developers, and it only impacts runtime operation of your code.  If your code is in anyway compiled, preprocessed, etc, then you are adding time to "fix bug; test; next" loop that developers are working in.

From the interpersonal side, people were never forced to use the slow servers, but if you used the slow servers, you didn't have to do any of your own maintenance or setup.  Also, this setup existed from the very beginning, I can't imagine trying to sell this to an established development team.

After rereading your original question, it occurs to me that one thing that perpetually terrifies me is development environments that differ from production environments.  Why not use a VM for code execution that you can cripple for runtime without affecting the dev workstation?  Lately, I've been using/loving VirtualBox.

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

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

This question has two parts...

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

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

Update:

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

- specific server side programming optimizations

- test labs

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


问:
Can someone find a job as a programmer without an education?
Interested in knowing from the more experienced ones if someone can find a job as a programmer without even a highschool degree. Consider the said person to be an average programmer. Would someone even consider giving him/her a chance on an interview ? The languages of interest would be python/php/java/c#

Please answer for your region/city/country only. No "go back to school" answers please.

答:
Is there a kind of relaxation point, where one can just apply to random company and know that his previous two (junior, right), three or five years already made him a good reputation?

What about soap bubble software giants (IBM?), doesn't they recruit totally incompetent (e.g. non-educated, and non-degree) persons way too often? I can tell that by totally poor software quality

And what about those managers who just have a personal reasons in dropping your candidature right after the talk?

By counting those factors, one will always know: no matter how much years he had worked, there's always an envy HR guy who will drop his candidature just to hire some non-grade code monkey for having talks, beers and no envy in him.

There's no reason for CIO to start yelling at HR guys with "you just lost us an ex-Google worker who had two degrees and a wonderful career" altitude, because they didn't "lost an ex-Google worker" so no reason for punishing them.

But also, there's no reason to start applying for big companies just for this: they already wasted the budget on their advertising, student support programs etc. Usually they would not hire a self-taught specialist who was not brainwashed by their internship, their in-school job fair advertisements - this will occasionally lead them to opinion that PR is a money waste, noone gives such a disgrace to themselves. Once again - if you want to go this way, go to LinkedIn and find some disappointed tech leader to invite you.


答:
I would use data to demonstrate the point, and show the differences in productivity.
I would stay at the lab/office and annotate every distraction (non-project related) and log its duration and date-time, as well as the project related activities (duration and date-time) and output produced that day(s) (Number of Classes, Number of Methods, Lines of Code and/or Function Points). Then, I'd do the "lone wolf" and log the same data.

Then show the results comparison to you boss/teacher, and then analyze the data with him, and let him come to the logical conclusion.


答:
When I was graduating, apart from noisy distractions from the students there used to be online tests conducted for different batches for which we had to wait an additional 2 hours to get the lab machines. But the training to work on distracted environments payed off eventually when we started working on a live environment.

In a real environment as Jarrod Roberson pointed out, there could be marketing and sales people surrounding your development environment. If you are lucky to be placed among other development teams conference calls could be another big time distraction which can go all day long.

That said, I suggest you take your supervisor words positively as it is definitely going to prepare you for the real world where you can adapt easily.

Good luck.


问:
Is it possible to combine programming languages?
I've been programming for a while, I've written some rudimentary programs, and I want to keep learning. I've reached that point where you just don't know what to learn next, and I'd like to ask a question for my own curiosity.

The question, in a nutshell, is if you can combine multiple programming languages into 1 result? For example, can this code be possible?

```<code><html>
cout << "Hello world!";
</html>
</code>```

or

```<code>import java.util.Scanner;
cout << "Insert a number from 1 to 10";
Scanner n = new Scanner(System.in);
System.out.println("The value you entered was" +n.newLine());
</code>```

This feels like a silly question but I can't possible know if it's possible or not, so that's why I'm asking it. In this question I notice he is using Python code in html code, if my above example is not possible, what did he do?

答:
The .NET framework is built for allowing several languages to participate in one solution. It works as long as the language can produce CLR-compatible byte code.

http://www.geekinterview.com/question_details/1047


问:
Drawbacks of code kata
Code kata is a concept that proposes to hone programmer's skill by doing small problems many times trying to improve the code at each iteration.  The name comes from an analogy to martial art kata where forms (aka kata) are practices done over and over leading to improvements.  </p>

<p>From the reaction I got to my last question on the topic, I wish to know what are the draw backs of this approach? </p>

答:
Code kata just takes time.

Being full time developer and father, I don't want to make computing a hobby.

And I don't imagine that my boss would pay me to develop applications unrelated to my current project.

Title: Drawbacks of code kata


答: From my perspective the main drawback is that it would be horrendously boring. Also programmers seem to thrive on developing software that does something useful or cool. The code kata approach would seem to be the opposite of that.</p>

Title: Drawbacks of code kata

Body:
Code kata is a concept that proposes to hone programmer's skill by doing small problems many times trying to improve the code at each iteration.  The name comes from an analogy to martial art kata where forms (aka kata) are practices done over and over leading to improvements.  </p>

<p>From the reaction I got to my last question on the topic, I wish to know what are the draw backs of this approach? </p>


答:
It's very hard, very ugly and often useless to combine multiple programming languages in 1 file.

It is however possible to have a big project written in more than 1 language. For example, both Mozilla Firefox and MySQL have C and C++ code in them. When it comes to big projects, this practice is often used because a particular language provides some features that another does not. In PHP, for example, you can ask for the execution of a binary executable, take its result and use it in your PHP code from that point on.

If you're curious about what languages are used for some of the most important open source projects in the world, you can check out Ohloh.net. Statistics about the source code of many projects can be found there.

Title: Is it possible to combine programming languages?

Body:
I've been programming for a while, I've written some rudimentary programs, and I want to keep learning. I've reached that point where you just don't know what to learn next, and I'd like to ask a question for my own curiosity.

The question, in a nutshell, is if you can combine multiple programming languages into 1 result? For example, can this code be possible?

```<code><html>
cout << "Hello world!";
</html>
</code>```

or

```<code>import java.util.Scanner;
cout << "Insert a number from 1 to 10";
Scanner n = new Scanner(System.in);
System.out.println("The value you entered was" +n.newLine());
</code>```

This feels like a silly question but I can't possible know if it's possible or not, so that's why I'm asking it. In this question I notice he is using Python code in html code, if my above example is not possible, what did he do?


问:
What is the differences between committing and patching?
I am quite new to source control and would like to know the differences between committing and patching? Also, how/when a patch is use and can it be used on a web application?</p>

答:
I can understand your confusion, the two words are closely related. There is a glossary for Mercurial that says:

Patch (noun) The product of a diff operation.

Example: "I've sent you my patch."

Patch (verb) The process of using a patch file to transform one changeset into another.

Example: "You will need to patch that revision.

Commit (noun) A synonym for changeset.

Example: "Is the bug fixed in your recent commit?"

Commit (verb) The act of recording changes to a repository. When files are committed in a working directory, Mercurial finds the differences between the committed files and their parent changeset, creating a new changeset in the repository.

Example: "You should commit those changes now."

So, to elaborate a bit: a patch is a description of changes between two versions/changesets. You get that description with hg diff and it looks like this:

```<code>diff --git a/x b/x
--- a/x
+++ b/x
@@ -1,3 +1,3 @@
 a
-old line
+new line
 b
</code>```

The patch is in unified diff format. This is a machine-readable format so Mercurial can apply a patch to make the same changes somewhere else — Mercurial can use the patch to patch your code.

When you've made changes to your files, you can commit the changes with hg commit. This creates a new changeset (which is also known as a commit). As you can see from the glossary, a changeset records the differences between the committed files and the parent changeset — this is a patch. So a changeset will have a patch inside, plus other information such as committer name, date, and message.

A patch is often used when you need to discuss code with a coworker. You can send him a patch in an email and he can review it. You can also use a patch if you want to modify a file with committing the change — for a webapp, you could have a patch with your local customizations. When you get a new version of the app, you first remove the patch, update the app, and then re-apply the patch. That way you can maintain your customizations as a patch on top of the original source code.

Body:
I can understand your confusion, the two words are closely related. There is a glossary for Mercurial that says:

Patch (noun) The product of a diff operation.

Example: "I've sent you my patch."

Patch (verb) The process of using a patch file to transform one changeset into another.

Example: "You will need to patch that revision.

Commit (noun) A synonym for changeset.

Example: "Is the bug fixed in your recent commit?"

Commit (verb) The act of recording changes to a repository. When files are committed in a working directory, Mercurial finds the differences between the committed files and their parent changeset, creating a new changeset in the repository.

Example: "You should commit those changes now."

So, to elaborate a bit: a patch is a description of changes between two versions/changesets. You get that description with hg diff and it looks like this:

diff --git a/x b/x
--- a/x
+++ b/x
@@ -1,3 +1,3 @@
 a
-old line
+new line
 b

The patch is in unified diff format. This is a machine-readable format so Mercurial can apply a patch to make the same changes somewhere else — Mercurial can use the patch to patch your code.

When you've made changes to your files, you can commit the changes with hg commit. This creates a new changeset (which is also known as a commit). As you can see from the glossary, a changeset records the differences between the committed files and the parent changeset — this is a patch. So a changeset will have a patch inside, plus other information such as committer name, date, and message.

A patch is often used when you need to discuss code with a coworker. You can send him a patch in an email and he can review it. You can also use a patch if you want to modify a file with committing the change — for a webapp, you could have a patch with your local customizations. When you get a new version of the app, you first remove the patch, update the app, and then re-apply the patch. That way you can maintain your customizations as a patch on top of the original source code.


答:
I'll give you my look on it.

Basically, I learn well when I:

Am given a formal introduction to the topic. I can never learn something new without somebody (yes, a person) answering all of the questions I have on the new concepts. Once I have that done I...

Get a book. As my mentor, you should have the exact same book so I could always say something like, "Hey, what does that mean in chapter four, page 72, paragraph 6..." and you'll know exactly what I'm talking about. Once I have a book, I am more independent, and really only ask questions. Then I...

Start a project together. This is the most important part of the process. This is where you can start teaching me about Best Practices, Algorithms, difficult (but useful) language features, etc..

Now you had said that you have your own projects to take care of, and that you don't always have the time. That's why we were blessed with StackOverflow. I'm sure they would be happy to help him debug his code. As for questions that aren't on-topic there, he can ask here.

With that said, you still have to work with him on a regular basis. A general "timeline" should be:

1 month. Should know basic syntax. Still not independent when coding.

3 months. At this point he should know the syntax like the back of his hand, and should be able to solve simple problems with ease. He is much more independent, just not quite there yet.

6 months. They should know, on top of everything else: Best Practices, Common Algorithms, etc. He should be able to make a project himself, maybe with a bit of help from SO.

Besides the above, the easiest way to make somebody independent is to give them a difficult topic to learn, and give them nothing to help them but the internet. He will be forced to learn by himself and he will know his stuff.

After he knows what you want him to know, set him free. Allow him to go off and learn what he wants to learn (you could always say you want him to keep working in that language).

I hope this helps! By the way, let him read this: Teach Yourself Programming in Ten Years.

Title: How to Mentor a Junior Developer


问:
How can I move a team from C# ASP.NET development to PHP development using Drupal?
I have a team of skilled C# developers with vast experience in creating ASP.NET MVC applications. We will soon be starting a new big web site project based on the Drupal platform. My developers do not have any experience in Drupal or PHP and I want to make the transition as quickly and effective as possible.

We decided to make this decision based on two factors:

In my organization there are a couple of teams competing on doing this project. None of the other teams has experience in PHP or Drupal, and I truly believe that my team would do it the best, whether it's ASP.NET or Drupal.

One of the requirements from higher management was that we won't build something from scratch, but use an existing foundation. Many of the requirements are available in plugins/modules for the various CMS.

I know this is not an ideal environment, but it's a given state and I have to make the best out of it. None of the .NET Framework based CMS supported all of our requirements. Since my team is dynamic in nature, I believe it can adapt to working with Drupal.

Hiring other people is not an option, and sending them to a course will take too much time.
I thought about dedicating a week in which each developer will study a specific subject and then will pass it on to the team.

Any suggestions on how you would do it?

答:
As a .net developer who actually spent a few months learning php+Drupal, my answer is don't do this. </p>

<p>Use dot net nuke or something similar instead. Sure is not as good as Drupal, but man it's going to save you months of learning. </p>

Body:
As a .net developer who actually spent a few months learning php+Drupal, my answer is don't do this.

Use dot net nuke or something similar instead. Sure is not as good as Drupal, but man it's going to save you months of learning.


答:
In principle, I don't see drawbacks in code kata. You try to accomplish the same task many times, with different approaches and different languages. But

it is rather difficult to introduce it in a work place. You are usually expected to be proficient or reasonably productive. I am not saying it would not be useful (better to spend some time to improve the skills of a new hire than to pay for the not so good code he will write in the time to come) but it is rather difficult none the less.

you must actuallu try to improve in some sense. Writing the same code in the same way one thousand times will not make you improve (rather it will dull you). You must understand your previous errors, what went wrong or not worked out as expected. This is the most important part. It is a form of self study, so you must study.

Title: Drawbacks of code kata


问:
How do programmers quit a job?
I'm thinking about leaving my current employer and wondering how one goes about that process in the programming world. We have a lot of projects on the go at the moment and I'm the only developer. We have 4-5 projects that are fairly big and need to be done in the next few months and even a few longer than that.

I'm leaving because I'm the only employee and that's doing me no good. I'm young and want to learn, so a team would be nice. It's also too much work and the company is managed horribly.

I have no contract to worry about so I could theoretically quit and just not come back without notice. Just wondering how this is normally handled.

Should I write a resignation letter

How much notice should I give

Should I give a reason for leaving

Should I go to my boss who is the main reason I'm leaving or go to his boss?

Overview of replies

From the feedback here, it looks as though it's best to give 2-4 weeks of notice, and present a written resignation. Don't go into detail explaining why you're leaving in most cases. Don't burn bridges. Be professional.

答:
Before you quit your current job find a new one first!!

Finding a job is always easier when you already have one.  It looks better to recruiters and potential employers if you're currently employed.

Writing a letter is hardly necessary unless you want to make a statement, and if you do, be diplomatic about it.  At my previous job, which I wasn't terribly happy with, I was getting all kinds of calls for opportunities - far more than I received while job hunting unemployed.  I eventually got a great offer - my current job which I'm really happy with - and just gave notice to my previous employer.  I sat down with my manager and explained the opportunity I had and she was very understanding.  I gave at least a month's notice because I had that much time until I started my current job.

But two weeks notice is just fine - you'd be lucky to get more than that from your employer if they ever decide to let you go!  And I doubt they'd be writing you a letter.

Title: How do programmers quit a job?


答:
I think programming kata, like martial arts kata, is mainly about form over function. It may teach you to write elegant code, but it will not teach you to solve the problems you are writing the code for. I think a better way to improve as a programmer is to solve puzzles that require actual problem solving, and to work on larger projects that will teach you the value of well-factored code in a way that code kata can never teach you.

As an aside, I think terms like 'code kata' and 'software craftsmanship' are more about romanticizing our profession than they are about describing anything novel or useful.

Title: Drawbacks of code kata


问:
How to measure external quality of software
For my thesis, I am doing research into the characteristics of Behavior Driven Development (BDD). One of the BDD claims is that by specifying the requirements in a ubiquitous language together with the customer, the software will score better on the external quality. Another claim of BDD is that it produces clean code with a high code coverage.

In my experiment, I will perform a software project both in BDD and traditional style, so that in the end I have two end products. The second claim of BDD is easy verifiable, by checking the code against some quality metrics, like Lines of Code, Cyclomatic Complexity and Code Coverage. However, I cannot think of a good measurement for the first claim. Is there anybody out here who has done this already? Or maybe can propose an alternative experiment that can validate this claim?

答:
Have a few people act as your customers for both projects (even better if they are actual customers, i.e. would want to use your software).  After demoing the project to them ask them to fill out a survey measuring satisfaction and missing features.

You may want to make the projects different, but of roughly the same size scope and complexity, otherwise your 2nd version (whether BDD or not) will be better designed and closer to the customer's wants, because you will have the hindsight of version one.


问:
How to Mentor a Junior Developer
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).

答:
The other answers are very good, but I wanted to comment on this one sentence.

Recently and in the past we've had people start here who seem to have an attitude toward development/programming which is different from mine and hard for me to reconcile; they seem to extract just enough information to get the task done but not really learn from it.

Most people want to know how to do something.  This attitude is fine in the beginning when you're overwhelmed with learning new things and learning how to do your job.

Rare are the people that want to know why something is done.  These are the people that smart managers want, even if they are hard to manage at times.

Some people code to get paid well.  Others happily accept money for coding.  It's much nicer to work with people that have a passion for design and coding.  Unfortunately for me, it was also pretty rare.  At least until I found Stack Overflow.

Title: How to Mentor a Junior Developer


问:
How much Code Coverage is "enough"?
We are starting a push for code coverage here at my work, and it has got me to thinking.... How much code coverage is enough?

When do you get to the point of diminishing returns on code coverage?  What is the sweet spot between good coverage and not enough?  Does it vary by the type of project your are making (ie WPF, WCF, Mobile, ASP.NET)  (These are C# classes we are writing.)

答: I'm of the opinion that code coverage alone is a poor metric.  It's easy to produce tons of useless tests that cover the code, but don't adequately check the output, or don't test edge cases, for example.  Covering code just means it doesn't throw an exception, not that it's right.  You need quality tests- the quantity isn't that important.

Title: How much Code Coverage is "enough"?


答:
As a boxer, I'd have to disagree with the principle behind the kata. It's too rigid to be actually useful. In the ring, you have to understand how to apply the principles you have learned in a free flowing environment.

This is not to say that learning and improving of the technique should not be done. Practicing on the bags allows you to work through a using a punch and feeling how you throw it, the same as a kata. But it isn't as rigid. You are practicing many things at the same time, moving around the bag, throwing from a stable platform, aiming, breathing, the list goes on.

Most importantly, everything is learned together the way it will actually be used. If you can write the most beautiful for loop ever, but you can't understand how to fit it into a program, then what good is it?

I would say that a better thing to do if you want practice would be building yourself tools, or working on tools you use. It requires exercising all of your skills and in the end you may have something useful.

Title: Drawbacks of code kata


问:
What is a recommended pattern for REST endpoints planning for foresighted changes
Trying to design an API for external applications with foresight for change isn't easy, but a little thought up front can make life easier later on. I'm trying to establish a scheme that will support future changes while remaining backward compatible by leaving prior version handlers in place.

The primary concern on this article is to what pattern should be followed for all defined endpoints for a given product/company.

Base Scheme

Given a base URL template of https://rest.product.com/ I have devised that all services reside under /api along with /auth and other non-rest based endpoints such as /doc. Therefore I can establish the base endpoints as follows:

```<code>https://rest.product.com/api/...
https://rest.product.com/auth/login
https://rest.product.com/auth/logout
https://rest.product.com/doc/...
</code>```

Service Endpoints

Now for the endpoints themselves. Concern about POST,GET,DELETE is not the primary objective of this article and is the concern on those actions themselves.

Endpoints can be broken down into namespaces and actions. Each action must also present itself in a way to support fundamental changes in return type or required parameters.

Taking a hypothetical chat service where registered users can send messages we may have the following endpoints:

```<code>https://rest.product.com/api/messages/list/{user}
https://rest.product.com/api/messages/send
</code>```

Now to add version support for future API changes which may be breaking. We could either add the version signature after /api/ or after /messages/. Given the send endpoint we could then have the following for v1.

```<code>https://rest.product.com/api/v1/messages/send
https://rest.product.com/api/messages/v1/send
</code>```

So my first question is, what is a recommended place for the version identifier?

Managing Controller Code

So now we have established we need to support prior versions we need to thus somehow handle code for each of the new versions which may deprecate over time. Assuming we are writing endpoints in Java we could manage this through packages.

```<code>package com.product.messages.v1;
public interface MessageController {
    void send();
    Message[] list();
}
</code>```

This has the advantage that all code has been separated through namespaces where any breaking change would mean that a new copy of the service endpoints. The detriment of this is that all code needs to be copied and bug fixes wished to be applied to new and prior versions needs to be applied/tested for each copy.

Another approach is to create handlers for each endpoint.

```<code>package com.product.messages;
public class MessageServiceImpl {
    public void send(String version) {
        getMessageSender(version).send();
    }
    // Assume we have a List of senders in order of newest to oldest.
    private MessageSender getMessageSender(String version) {
        for (MessageSender s : senders) {
            if (s.supportsVersion(version)) {
                return s;
            }
        }
    }
}
</code>```

This now isolates versioning to each endpoint itself and makes bug fixes back port compatible by in most cases only needing to be applied once, but it does mean that we need to do a fair bit more work to each individual endpoint to support this.

So there's my second question "What's the best way to design REST service code to support prior versions."

答:
The first URI design option expresses better the idea that you are versioning the whole API. The second could be interpreted as versioning the messages themselves. So this is better IMO:

rest.product.com/api/v1/messages/send

For the client library I think using two full implementations in separate Java packages is cleaner, easier to use and easier to maintain.

That being said, there are better methods for evolving APIs than versioning. I agree with you that you should be prepared for it,  but I think of versioning as the method of last resort, to be used carefully and sparingly. It is a relatively big effort for clients to upgrade. A while back I've put some of these thoughts in a blog post:

http://theamiableapi.com/2011/10/18/api-design-best-practice-plan-for-evolution/

For REST API versioning specifically, you'll find this post by Mark Nottingham helpful:

http://www.mnot.net/blog/2011/10/25/web_api_versioning_smackdown


答:
One of the developers in my group recommended doing an occasional freeform refactoring that caught your fancy just to prove that it could be done - then revert the whole thing.

That seems to be the best real-world application of a "kata" that I've heard of.

It prepares you for if/when you ever get to do the refactoring for a real issue, and isn't a waste of time on an imaginary problem that may or may not apply to your codebase.

Title: What are effective ways to introduce the concept of code kata into the workplace?

Body:
In your experiences, what are some effective ways to introduce code kata practice into an organization or company?

To be clear, I'm not concerned with the usefulness of code kata. I'm interested in methods to introduce this concept to a development team.


答: I work on a slow Windows95 machine, and it allows me efficiently to write MindForth artificial intelligence in Forth and in JavaScript.</p>

OwnerDisplayName: Mentifex