答:
Checked exceptions are also in ADA.

(Warning, this post contains strongly held beliefs that you might find confronting.)

Programmers don't like them and complain, or write exception swallowing code.

Checked exceptions exist because things can not only fail to work, you can do a failure mode/effects analysis and determine this in advance.

File reads can fail. RPC calls can fail. Network IO can fail. Data can be mis-formatted when parsed.

The "happy path" for code is easy.

I knew a guy at University who could write great "happy path" code. None of the edge cases ever worked. These days he does Python for an open source company. Nuff said.

If you don't want to handle checked exceptions, what you're really saying is

```<code>While I'm writing this code, I don't want to consider obvious failure modes.

The User will just have to like the program crashing or doing weird things.

But that's okay with me because

I'm so much more important than the people who will have to use the software

in the real, messy, error-prone world.

After all, I write the code once, you use it all day long.
</code>```

So checked exceptions are not going to be liked by programmers, because it means more work.

Of course, other people might have wanted that work done.

They might have wanted the right answer even if the file server failed/ USB stick dies.

It's a strange belief in the programming community that you should be using a programming language that makes your life easier, that you enjoy, when your job is to write software. You job is solving someones problem, not letting you engage in programmatic Jazz improvisation.

If you're an amateur programmer (not programming for money), feel free to program in C# or some other language with no checked exceptions. Heck, cut out the middle man and program in Logo. You can draw pretty patterns on the floor with the turtle.

Body:
Checked exceptions are also in ADA.

(Warning, this post contains strongly held beliefs that you might find confronting.)

Programmers don't like them and complain, or write exception swallowing code.

Checked exceptions exist because things can not only fail to work, you can do a failure mode/effects analysis and determine this in advance.

File reads can fail. RPC calls can fail. Network IO can fail. Data can be mis-formatted when parsed.

The "happy path" for code is easy.

I knew a guy at University who could write great "happy path" code. None of the edge cases ever worked. These days he does Python for an open source company. Nuff said.

If you don't want to handle checked exceptions, what you're really saying is

While I'm writing this code, I don't want to consider obvious failure modes.

The User will just have to like the program crashing or doing weird things.

But that's okay with me because

I'm so much more important than the people who will have to use the software

in the real, messy, error-prone world.

After all, I write the code once, you use it all day long.

So checked exceptions are not going to be liked by programmers, because it means more work.

Of course, other people might have wanted that work done.

They might have wanted the right answer even if the file server failed/ USB stick dies.

It's a strange belief in the programming community that you should be using a programming language that makes your life easier, that you enjoy, when your job is to write software. You job is solving someones problem, not letting you engage in programmatic Jazz improvisation.

If you're an amateur programmer (not programming for money), feel free to program in C# or some other language with no checked exceptions. Heck, cut out the middle man and program in Logo. You can draw pretty patterns on the floor with the turtle.


问:
What constitutes a dead programming language?
Imagine you were elected coroner of IEEE or somesuch governing body and you had to pronounce a programming language as dead.  What signs would you look for?  Are there any zombie languages out there that don't know they're already dead?</p>

答: A language is dead when no one in their right mind would ever do a greenfield project in it.  Just like dead human languages aren't completely irrelevant (because we study history), dead programming languages aren't completely irrelevant (because we maintain all that crufty historical code). </p>

ContentLicense: CC BY-SA 2.5

ContentLicense: CC BY-SA 3.0


问:
In Java, what are checked exceptions good for?
Java's checked exceptions have gotten some bad press over the years. A telling sign is that it's literally the only language in the world that has them (not even other JVM languages like Groovy and Scala). Prominent Java libraries like Spring and Hibernate also don't use them.

I personally have found one use for them (in business logic between layers), but otherwise I'm pretty anti-checked exceptions.

Are there any other uses that I don't realize?

答:
Checked exceptions should have encouraged people to handle errors close to there source. The further away from the source, the more functions have terminated in the middle of running, and the more likely that the system has entered an inconsistent state. Additionally, it is more likely that you catch the wrong exception by accident.

Sadly, people have tended to either ignore exceptions or  add ever increasing throw specifications. Both of these miss the point of what checked exceptions are suppose to encourage. They are like transforming procedural code to use many Getter and Setter functions supposedly making it OO.

Essentially, checked exceptions are attempting to prove a certain degree of correctness in your code. Its pretty much the same idea as static typing, in that it attempts to prove that certain things are correct before the code even runs. The problem is that all of that extra proof takes effort and is the effort worthwhile?


问:
What are the benefits of using Dependency Injection and IoC Containers?
I'm planning to do a talk on Dependency Injection and IoC Containers, and I'm looking for some good arguments for using it.

What are the most important benefits of using this technique, and these tools?

答: The examples that really opened my eyes were seeing how it made it possible to easily unit test the objects created in such a fashion. Prior to that, I had trouble attempting to isolate objects for a unit test. I would often write tests to interacted with a much larger system. This was really  hard because the system as a whole was much less predictable and much more prone to change then the individual components. </p>


答:
IMO, checked exceptions are a flawed implementation of what might have been a pretty decent idea (under completely different circumstances -- but really isn't even a good idea under the current circumstance).

The good idea is that it would be nice to have the compiler verify that all exceptions that a program has a potential to throw will be caught. The flawed implementation is that to do that, Java forces you to deal with the exception directly in whatever class invokes anything that's declared to throw a checked exception. One of the most basic ideas (and advantages) of exception handling is that in case of an error, it allows intermediate layers of code that have nothing to do with a particular error, to completely ignore its very existence. Checked exceptions (as implemented in Java) don't allow that, thus destroying a major (the primary?) advantage of exception handling to start with.

In theory, they could have made checked exceptions useful by enforcing them only on a program-wide basis -- i.e., while "building" the program, build a tree of all the control paths in the program. Various nodes in the tree would be annotated with 1) exceptions they can generate, and 2) exceptions they can catch. To assure the program was correct, you'd then walk the tree, verifying that every exception that was thrown at any level in the tree was caught at some higher level in the tree.

The reason they didn't do that (I'd guess, anyway) is that doing so would be excruciatingly difficult -- in fact, I doubt anybody's written a build system that can do that for anything but extremely simple (bordering on "toy") languages/systems. For Java, things like dynamic class loading render it even more difficult than in many other cases. Worse, (unlike something like C) Java isn't (at least normally) statically compiled/linked to an executable. That means nothing in the system really has the global awareness to even try to do this kind of enforcement until the end user actually starts to load the program to run it.

Doing enforcement at that point is impractical for a couple of reasons. First of all, even at best it would extend startup times, which are already one of the single biggest, most common complaints about Java. Second, to do much good, you really need to detect the problem early enough for a programmer to fix it. When the user is loading the program, it's too late to do much good -- your only choices at that point are to ignore the problem, or refuse to load/run the program at all, on the off chance that there might be an exception that wasn't caught.

As they are, checked exceptions are worse than useless, but alternative designs for checked exceptions are even worse. While the basic idea for checked exceptions seems like a good one, it's really not very good, and happens to be a particularly poor fit for Java. For something like C++, that's normally compiled/linked into a complete executable with nothing much like reflection/dynamic class loading, you'd stand a little more chance (though, quite frankly, even then enforcing them correctly without the same kind of mess they currently cause in Java would still probably be beyond the current state of the art).

Title: In Java, what are checked exceptions good for?

Body:
Java's checked exceptions have gotten some bad press over the years. A telling sign is that it's literally the only language in the world that has them (not even other JVM languages like Groovy and Scala). Prominent Java libraries like Spring and Hibernate also don't use them.

I personally have found one use for them (in business logic between layers), but otherwise I'm pretty anti-checked exceptions.

Are there any other uses that I don't realize?


问:
Are certain problems solved more elegantly with AOP?
I've come across the idea of Aspect Oriented Programming, and I have some concerns with it.

The basic idea seems to be that we want to take cross-cutting concerns which aren't well modularized using object and modularize them. That is all very fine and well.

But the implementation of AOP seems to be that of modifying code from outside of the module. So, for example, an aspect could be written that changes what happens when a particular object is passed as a parameter in a function. This seems to go directly against the idea of modules. I should not be able to modify a module's behavior from outside of that module, otherwise the whole point of modules are overturned. But aspects seem to be doing exactly that!

Basically, aspects seems to be a form of code patching. It may useful for some quick hacks; but, as a general principle perhaps its not something you want to do. Aspect Oriented Programming seems to me taking a bad practice and raising to a general design principle.

Is AOP a good practice?  Are certain programming problems solved more elegantly with AOP?

答:
One situation in which AOP might be the only decent as well as practical solution is when you don't have access to the source code. To use the tired old example of the Logging cross-cutting concern:

Let's say you want to log the flow of control in a third party library you consume. You have your own code fully instrumented with logging statements. However, for this library you don't have the source, making it impossible to add your logging statements. Since you do have the bytecode, AOP allows you to instrument that third party library anyway.

And if you're creating a Logging aspect anyway, you might as well consider implementing Logging with AOP troughout your own code as well.


答:
Aspect-Oriented Programming makes it possible to do certain types of programming that are difficult to do without unnecessarily scattering code throughout your application or library that is unrelated to the primary functions of your software (i.e. cross-cutting concerns).  Examples include:

Logging and Monitoring

Performance analysis

Debugging and Tracing

Undo Functionality

Validation of inputs and outputs

Morphing the behavior of existing objects

Object Filters

Security Implementation

Managing transactions

By confining such cross-cutting concerns to a single part of the application, and then referencing these features in the code via attributes, method call interception, or dynamic proxies, you allow the encapsulation of the cross-cutting behavior; this has all of the benefits (i.e. a single modification point) encapsulation would provide anywhere else in your application.

The key point here is that AOP encapsulates behaviour that is 1) common throughout the application, and 2) peripheral to the application's primary functionality.

Title: Are certain problems solved more elegantly with AOP?

Body:
I've come across the idea of Aspect Oriented Programming, and I have some concerns with it.

The basic idea seems to be that we want to take cross-cutting concerns which aren't well modularized using object and modularize them. That is all very fine and well.

But the implementation of AOP seems to be that of modifying code from outside of the module. So, for example, an aspect could be written that changes what happens when a particular object is passed as a parameter in a function. This seems to go directly against the idea of modules. I should not be able to modify a module's behavior from outside of that module, otherwise the whole point of modules are overturned. But aspects seem to be doing exactly that!

Basically, aspects seems to be a form of code patching. It may useful for some quick hacks; but, as a general principle perhaps its not something you want to do. Aspect Oriented Programming seems to me taking a bad practice and raising to a general design principle.

Is AOP a good practice?  Are certain programming problems solved more elegantly with AOP?


答:
First of all, like any other programming paradigm you need to do it right for it to work well.

For me the advantage of checked exceptions is that the authors of the Java runtime library ALREADY have decided for me what common problems I might reasonably be expected to be able to handle at the calling point (as opposed to a top-level catch-print-die block) and consider as early as possible how to handle these problems.

I like checked exceptions because they make my code more robust by forcing me to think about error recovery as early as possible.

To be more precise, to me this makes my code more robust as it forces me to consider strange corner cases very early in the process as opposed to saying "Oops, my code does not handle if the file doesn't exist yet" based on an error in production, which you then have to rework your code to handle.  Adding error handling to existing code can be a non-trivial task - and hence expensive - when reaching maintenance as opposed to just doing it right from the start.

It might be that the missing file is a fatal thing and should cause the program to crash in flames, but then you make that decision with

```<code>} catch (FileNotFoundException e) {
  throw new RuntimeException("Important file not present", e);
}
</code>```

This also shows a very important side effect.  If you wrap an exception, you can add an explanation which goes in the stack-trace!  This is so extremely powerful because you can add information about e.g. the name of the file that was missing, or the parameters passed to this method or other diagnostic information, and that information is present right in the stack trace which frequently is the single thing you get when a program has crashed.

People may say "we can just run this in the debugger to reproduce", but I have found that very frequently production errors cannot be reproduced later, and we cannot run debuggers in production except for very nasty cases where essentially your job is at stake.

The more information in your stack trace, the better.  Checked exceptions help me get that information in there, and early.

EDIT:  This goes for library designers as well.  One library I use on a daily basis contains many, many checked exceptions which could have been designed much better making it less tedious to use.

Body:
First of all, like any other programming paradigm you need to do it right for it to work well.

For me the advantage of checked exceptions is that the authors of the Java runtime library ALREADY have decided for me what common problems I might reasonably be expected to be able to handle at the calling point (as opposed to a top-level catch-print-die block) and consider as early as possible how to handle these problems.

I like checked exceptions because they make my code more robust by forcing me to think about error recovery as early as possible.

To be more precise, to me this makes my code more robust as it forces me to consider strange corner cases very early in the process as opposed to saying "Oops, my code does not handle if the file doesn't exist yet" based on an error in production, which you then have to rework your code to handle.  Adding error handling to existing code can be a non-trivial task - and hence expensive - when reaching maintenance as opposed to just doing it right from the start.

It might be that the missing file is a fatal thing and should cause the program to crash in flames, but then you make that decision with

} catch (FileNotFoundException e) {
  throw new RuntimeException("Important file not present", e);
}

This also shows a very important side effect.  If you wrap an exception, you can add an explanation which goes in the stack-trace!  This is so extremely powerful because you can add information about e.g. the name of the file that was missing, or the parameters passed to this method or other diagnostic information, and that information is present right in the stack trace which frequently is the single thing you get when a program has crashed.

People may say "we can just run this in the debugger to reproduce", but I have found that very frequently production errors cannot be reproduced later, and we cannot run debuggers in production except for very nasty cases where essentially your job is at stake.

The more information in your stack trace, the better.  Checked exceptions help me get that information in there, and early.

EDIT:  This goes for library designers as well.  One library I use on a daily basis contains many, many checked exceptions which could have been designed much better making it less tedious to use.


问:
What should every programmer know about programming?
Please, stay on technical issues, avoid behavior, cultural, career or political issues.

答: The more you know about how security works on your platform of choice the better.</p>


问:
How do you deal with boring repetitive tasks and activities?
When you encounter in your work some boring, repetitive (possibly not-programming) task how do you deal with it? Do you try to automate it immediately? Do you postpone automation till you encounter the task twice? Do you try to delegate it? Do you try to find something interesting in it? What do you do to make the work more joyful? Learn deeper to make it more interesting? Learn deeper immediately or when you need it regularly? </p>

答:
It depends what the job is.

Some boring repetitive tasks (like going to weekly progress meetings) can't be automated. You just have to put up with them.

Some (like not having an automated build system) you might put up with forever if you only do the build once a year.

And some - you try to automate because it lets you do other more productive things, and also removes the possibility of human error.


答:
If there is a point and value in automating it, I will absolutely do so - time considering.

Example:

Daily System Statistic Collection that could take up to an hour manually - Automate

A Data Collection Routine once in a blue moon taking +- 15mins - I just do it

Title: How do you deal with boring repetitive tasks and activities?

Body: When you encounter in your work some boring, repetitive (possibly not-programming) task how do you deal with it? Do you try to automate it immediately? Do you postpone automation till you encounter the task twice? Do you try to delegate it? Do you try to find something interesting in it? What do you do to make the work more joyful? Learn deeper to make it more interesting? Learn deeper immediately or when you need it regularly? </p>


问:
Is what someone publishes on the Internet fair game when considering them for employment as a programmer?
(Originally posted on Stack Overflow but closed there and more relevant for here)

So we first interviewed a guy for a technical role and he was pretty good. Before the second interview we googled him and found his MySpace page which could, to put it mildly, be regarded as inappropriate.  Just to be clear there was no doubt that it was his page (name, photos, matching biographical information and so on).

The content was entirely personal and in no way related to his professional abilities or attitude.

Is it fair to consider this when thinking about whether to offer them a job?

In most situations my response would be what goes on in someone's private life is their own doing. However for anyone technical who professes (implicitly or explicitly) to understand the Internet and the possibilities it offers, is posting things in a way which can so obviously be discovered a significant error of judgement?

EDIT: Clarification - essentially it was a fairly graphic commentary on porn (but of, shall we say, a non-academic nature).  I'm actually more interested in the general concept than the specific incident as it's something we're likely to see more in the future as people put more and more of themselves on-line.

My concerns are not primarily about him and how he feels about such things (he's white, straight, male and about the last possible victim of discrimination on the planet in that sense), more how it reflects on the company that a very simple search (basically his name) returns these things and that clients may also do it.  We work in a relatively conservative industry.

答:
It's not always clear which MySpace and Facebook content is public.

To me the main questions are: what does it tell about him and how would this relate to his work at your company?


答:
It depends on what that info is (is it more of an 'awkward stuff I wouldn't want public' or more serious), but it might show what that person would be like when interacting with the other employees, and that might have a big impact on the team.

Also, if you hire him and somebody who wants to work with your company finds that info, how would that affect your company?

Title: Is what someone publishes on the Internet fair game when considering them for employment as a programmer?

Body:
(Originally posted on Stack Overflow but closed there and more relevant for here)

So we first interviewed a guy for a technical role and he was pretty good. Before the second interview we googled him and found his MySpace page which could, to put it mildly, be regarded as inappropriate.  Just to be clear there was no doubt that it was his page (name, photos, matching biographical information and so on).

The content was entirely personal and in no way related to his professional abilities or attitude.

Is it fair to consider this when thinking about whether to offer them a job?

In most situations my response would be what goes on in someone's private life is their own doing. However for anyone technical who professes (implicitly or explicitly) to understand the Internet and the possibilities it offers, is posting things in a way which can so obviously be discovered a significant error of judgement?

EDIT: Clarification - essentially it was a fairly graphic commentary on porn (but of, shall we say, a non-academic nature).  I'm actually more interested in the general concept than the specific incident as it's something we're likely to see more in the future as people put more and more of themselves on-line.

My concerns are not primarily about him and how he feels about such things (he's white, straight, male and about the last possible victim of discrimination on the planet in that sense), more how it reflects on the company that a very simple search (basically his name) returns these things and that clients may also do it.  We work in a relatively conservative industry.


答:
It is absolutely relevant.

It is part of his background and gives you an extra autobiographical view into his personality.  You have a very limited ability fin an interview and from a CV to find out whether someone will fit in your company.  This is another resource that gives further insight into his attitudes and behaviour.  It would seem that often people are more open on facebook, maybe bragging about pulling a sickie or being too hung over to go to work.  If this is acceptable at your company then you can ignore these confessions.  If not then don't hire.


答:
It will be totally fair if you talk with the person under question about what they have published on the Internet.  My employer did talk about my social networking profiles and what I have published there.  In the end, they were happy, and, I got recruited.

I had published personal as well as professional information on those social networking pages.  I talked with the employer about everything they told they had seen and brought up for discussion.


答:
When you hire somebody you are not just hiring technical ability. You are also hiring personality, and in fact its the personality part that makes working with others either easy or hard.

Personality (or "character") is the bit thats hardest to judge during an interview process, and the part that causes the most problems in the workplace. The more you can find out about a person, who they are, how they think, what they think, how they act and react - the better able you are to make a judgement about whether you can or want to work with them. If they are foolish enough to put information in a public space which lets you form that judgement more easily, then so be it. Use it, for better or worse. Just do not ever explain the reason you used for the "no hire" decision.

Feeling uncomfortable with somebody (and hence no hire) is common enough during an interview - the attitude, demeanor, zip / zing / whatever all forms part of your opinion, and nobody says you can't use that. Public information about character is no different.

However - a caution - HR / personnel departments can frown in using this kind of public information on the grounds that private life is not work. However, I have to disagree with them.


答:
Oh Sex! You would be surprised of the diversity of the thing. Yesterday on TV, there was a documentary on fetishism. That was very instructive. I wasn't aware of all the things people could do... did you knew about zentai???

My opinion is regardless their private practices (as soon as it doesn't hurt someone else), such difference should not be used to pick, or not pick someone, just like his skin color, religion or political orientation.

I want also add that if he is happy in his sexuality, this will affect his work at your company positively.

On ther other hand, it's perfectly understandable that his behavior outside the company may affect the company. And therefore, some juridictions may approve firing someone that had bad behavior. And it's perfectly understandable that a company won't hire someone telling on his blog that his thing is animals, or that he likes to be nude in parks.


答:
If I have a boring task requiring minimal brain power, I save it either for those mornings when I am lucky not to have killed myself on the way to work or for long long Friday afternoons.

Unless I can automate it of course!


问:
The written roles of software development manager
We all know what a software development manager does, but I'm afraid that we only know it vaguely. We think we know what he is doing, but to exactly list down what is the job scope is a bit hard.

In your opinion, what are the roles of a software development manager?

答:
Speaking as someone in the job (who has also been a developer), the key things I have to do are:

Keep the development team on track (and happy where possible) - move things out of their way that are stopping them work where possible, explain why it's not possible where they can't be moved to try and reduce any resulting stress (people are more likely to accept things if they at least understand them).  Ultimately if there is a conflict between the project and the team that can't be resolved, normally the project will win.  That's doesn't necessarily make you popular with the team but you're paid to deliver projects/products, not as a union leader.  The obvious skill is in minimising how often this happens.

Make sure that the team are communicating with the customer the right amount.  This tends to be equal parts keeping the customer away from the team, and making sure the team are asking the customer about things they don't understand fully (rather than just making assumptions which may be incorrect).  Developers are very big on making sure that the customer doesn't disturb them and occasionally forget that the customer might have something useful to add.

Project planning and prioritisation of resource conflicts, customer demands, support issues and the like.  I tend to be the person who says this customer takes priority over that one, or that this bug has to be fixed before it ships but that one can go out as a known issue.

Manage the commercial side of development - that is making sure that things that should be charged for and being charged for and that we're not trying to charge for things which should be covered under support.

Be the voice of the team in the business and the business within the team - help everyone understand the other's position and help resolve differences where they arise.  This largely tends to cover cultural conflicts between the teams needs/wants and the larger organisations, and budget matters.  This is actually pretty shitty as it means when there are disagreements you're everyone's enemy.

Work with the team to ensure sufficient processes and tools are in place to meet the requirements of the business and customers.  Make sure that these processes are being followed and adjusted as needed.  Some of this is making sure the team define processes (for instance for technical things they understand better than I do), some is defining them myself (for things I understand better than they do - planning, estimating and so on).  The important word here is sufficient - you don't want process for process sake but there are things that have to happen and process is the best way to achieve that consistently.

Ensure that every member of the team is working to at least a reasonable level, and ideally beyond that.  Work with them to help resolve any issues that are preventing them reaching this level.  I'd love to say that my role is making them be the best they can be but while this is true to a degree other demands (project, budget, time) mean that this will almost always be compromised to a greater or lesser extent.

Doing all the administration and stuff the organisation (and the law) demand

Overall it's part mentoring, part secretarial, part project management, part account management and part PR (for the team).  There's a lot of picking up things the developers don't need to think about or don't think about doing, and some making sure they do things they need to do but don't want to do.

What it's not about is being the best developer (generally you're too hands off to remain current for long so you need to accept that people will know more than you - the skill is in knowing where your longer but outdated experience is more relevant than their shorter but more recent experience) or being some sort of dictator.  In that respect the best way to think about it is not that you're more senior, just that you have different responsibilities.  Sometimes this will involve making the final call on something (which may go against the views of the team) but more often it should be about consensus or compromise.

ContentLicense: CC BY-SA 4.0


答:
If automating it will take longer than getting the task done, then I'll postpone automating it until I have to do it a second time.  But if I can automate the task faster than I can do it, then it's automated without hesitation.

No sense wasting time.


问:
Does anybody ever uses the OpenId url Log in?
As programmers I think we are the most inclined to use new technologies and things that are not so mainstream.

I absolutely love OpenId's ability to log in with credentials you already have, but I always use a provider that I already use and that is the fastest to log in, like google. God knows I'd never used it if i had to type in the whole "https://www.google.com/accounts/o8/id" I like to click on the google button and then just say yes (the first time, then its just clicking the button).

Does any of you ever uses the Generic "Enter your own provider" OpenId?

Do you think its worth to even offer it to more casual end users?

答: I have both a mylid.net account and a delegated myopenid account on my personal site. the stack* sites don't seem to like the delegdted account, so I use my mylid account here.</p>


问:
What keymap do you prefer in ReSharper?
I am using ReSharper since version 3 and I always used InteliJ Idea/Resharper 2.x keymap schema. Recently I have learned Ilya's Visual Studio keymap. They each have advantages.

What keymap do you use/prefer with ReSharper?

答:
The simple answer is 'it depends'; most developers I know (and I include myself in this) are creatures of habit. When developing, I tend to find that my 'muscle-memory' takes over when I'm performing tasks, whether that be using ReSharper keyboard mappings or the choice of CLI to use when doing simple command line tasks.

Both keymaps have their own advantages as you've stated, but the biggest advantage is how productive it makes you without getting in your way. Personally I use the Visual Studio keymap, because that's the one I know and for 90% of the tasks I need to perform with ReSharper I don't need to think about the steps involved in activating them (Ctrl+R Ctrl+V to introduce a variable for example).

Title: What keymap do you prefer in ReSharper?


答:
I think the part that makes it relevant is that most people, if they were going to be posting this kind of content, would want to do so under some kind of pseudonym. By attaching it directly to your real world identity I guess you're either really confident about these matters or a little bit ill-adjusted socially. Perhaps, depending on the content and context, something of both.

It would be very hard not to take that information into account when you are considering potential employees and I do think that not to have thought of that shows a potential lack of professionalism, certainly a lack of common-sense if you're going for interview. You would also have to think about the effect that posting this type of content would have on colleagues if they were to google on someone's name- would it make any of their co-workers feel awkward or ill at ease?


答:
You have to take things on a case by case basis.

You cannot blanket statement say "we will choose between candidates based on what they say online."

If you find a web page where your candidate says, "Here are the nine steps to fooling any interviewer into believing you are a good programmer." Clearly you need to consider this.

On the other hand, if a page you find about them says "I like big butts, and I cannot lie." Well I don't think it's fair to judge them on that.

You have to make you decision based on what you know (obviously, you know that) but be aware of your prejudices, and put yourself in their shoes.

Update

If your company's image is what you're worried about, there are two factors you need to consider: the likelihood that a customer will meet your candidate, and the likelihood that the customer will then go on to Google stalk your candidate. I imagine the second is so low as to make the first immaterial, and generally the first is quite low too.

Update

In response to the comment that you need to consider the impact of discovery.

Absolutely. I had forgotten about that. I think that would be the likelihood that discovery would cause a noticeable loss of income.

I still think this is offset by the likelihood of Google stalking. But then, I'm not a conservative type, so I don't know how they react to meeting new people, particularly people that don't hold a lot of clout in an organisation.


问:
Best language or tool for automating tedious manual tasks
We all have tasks that come up from time to time that we think we'd be better off scripting or automating than doing manually.

Obviously some tools or languages are better for this than others - no-one (in their right mind) is doing a one off job of cross referencing a bunch of text lists their PM has just given them in assembler for instance.

What one tool or language would you recommend for the sort of general quick and dirty jobs you get asked to do where time (rather than elegance) is of the essence?

Background: I'm a former programmer, now development manager PM, looking to learn a new language for fun.  If I'm going to learn something for fun I'd like it to be useful and this sort of use case is the most likely to come up.

答:
Python

The obvious answer (and with good reason) is Python. Its a solid language, available cross platform. As its dynamic you can run it interactively which is great for lashing stuff together and it has a fairly large selection of libraries so its a general purpose language so can be applied to most problems.


答:
Powershell

This is less generic than Python - but if you exist in a Windows environment then its probably that its going to be more useful.

Its more shell/script like than Python (because that's what it is) but it can hook into the .NET framework which gives you a quite extraordinary depth of capability. It also has broad community support.

Microsoft have been busy adding powershell to their server products (hence the "more useful") and have introduced remoting to allow you to run scripts there from your console here.

Title: Best language or tool for automating tedious manual tasks

Body:
We all have tasks that come up from time to time that we think we'd be better off scripting or automating than doing manually.

Obviously some tools or languages are better for this than others - no-one (in their right mind) is doing a one off job of cross referencing a bunch of text lists their PM has just given them in assembler for instance.

What one tool or language would you recommend for the sort of general quick and dirty jobs you get asked to do where time (rather than elegance) is of the essence?

Background: I'm a former programmer, now development manager PM, looking to learn a new language for fun.  If I'm going to learn something for fun I'd like it to be useful and this sort of use case is the most likely to come up.


答:
Autoit is unbeatable. It's a tool with a language.

Easy to learn BASIC-like syntax

Simulate keystrokes and mouse movements

Manipulate windows and processes

Interact with all standard windows controls

Scripts can be compiled into standalone executables

Create Graphical User Interfaces (GUIs)

COM support

Regular expressions

Directly call external DLL and Windows API functions

Scriptable RunAs functions

Detailed helpfile and large community-based support forums

Compatible with Windows 2000 / XP / 2003 / Vista / 2008 / Windows 7 / 2008 R2

Unicode and x64 support

Digitally signed for peace of mind

Works with Windows Vista's User Account Control (UAC)


答: elisp, if you have seen the wealth of tasks it is used in order to accomplish through its underlying platform Emacs.  Emacs can eschew all the functionality of a full blown window manager, IDE, Office, browser, email client, chat client, shell, filesystem explorer, and more.  Most of it is accomplished through elisp programs.</p>


答:
If you have a Visual Studio background go for that one. If you have a Java background go for IntelliJ.

The Visual Studio one does have the advantage that other developers who want to use your pc for five minutes don't have to pull their hair out. but even then some hotkeys are different.

Title: What keymap do you prefer in ReSharper?

Body:
I am using ReSharper since version 3 and I always used InteliJ Idea/Resharper 2.x keymap schema. Recently I have learned Ilya's Visual Studio keymap. They each have advantages.

What keymap do you use/prefer with ReSharper?


问:
Worst coding standard you've ever had to follow?
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

答:
I once worked on a project in which the project lead mandated that every variable - EVERY variable - be prefixed with "v".  So, vCount, vFirstName, vIsWarranty, etc.

Why?  "Because we're working in VBScript and everything is a Variant anyway".

WTF.

OwnerDisplayName: Christopher Hawkins


答:
For some tasks, Actions might be a good fit.

It has a sort-of flowcharting process, where you can add actions to be run sequentially. New actions can be written in java.

Disclaimer: I've yet to use it.


答:
For complex automation you may want to use Robot Framework. The framework is mostly aimed at automated testing but can also be used for general automation.

You can easily write your own libraries in Python and there are a number of pre-existing ones (selenium, AutoIt, telnet, ssh, swing, etc) which allow you to drive all sorts of things which is very powerful if you're in a mixed enviroment.

It is keyword driven so you can create new keywords and hence abstract away repetitive tasks and even has an IDE which is being actively developed that allows for some simple refactorings.


问:
Enterprise knowledge sharing?
I recently read this article on knowledge sharing and immediately recognized the same problem within my own organization. My main goal now is to 'kill peer-to-peer collaboration' as the default method of communication for non-private, system related discussions. Otherwise you end up with all of the historical knowledge living in the heads of individuals, or lost in a massive email system.

My question for the group is as follows:

What methods / software have you used to encourage more 'public' discussions among your developers?

Some initial ideas I had.. any feedback would be great:

Internal news group

'better' wiki software (using Sharepoint now)

Message board

(I would love to have an internal instance of StackExchange, but don't think that is an option!)

Note: As stated above, we already have a wiki, but I dislike the wiki idea because things are usually only added to the wiki after the fact, if at all.

Thanks!

答:
We have a large internal Sharepoint site and a customer-facing support site, that takes a lot of documents from the internal Sharepoint site. This is less about implementation detail and more about support admittedly, but as I work largely in a support capacity we need access to a lot of implementational information and so we end up being drivers for the engineering team to document what they are doing and why. A detailed bug tracking system is also valuable for following up how problems were solved.

In our company, partly because we have development spread across a couple of locations, a lot of discussions about new features and support problems end up happening over email. Rather than trying to change this, the easiest approach is an email archiving system that makes the discussions searchable and trackable- effectively a newsgroup type approach. We are able to do this through Sharepoint, although one has to be aware of the limits on list size as although it will grow to millions of items you can't actually do much in terms of sorting very large lists or editing views on them without it crashing out dramatically.

Title: Enterprise knowledge sharing?


问:
Dev approaches to complex JavaScript UI's
I am trying to understand the landscape of different approaches, and best practices, around the development of complex client-side JavaScript.

I'm not sure what to label this class of application, perhaps heavy AJAX or RIA (but not plugins like Flash/Silverlight).  I'm referring to web apps with these characteristics:

Emulate rich/native desktop UX in JavaScript

Contain most/all behavior in client-side JS, using the server as a data-API (JSON/Html-Templates).

This is in contrast to using the web-server for the UI rendering, producing all HTML in a page-refresh model.

Some examples are:

Google Docs / Gmail

Mindmeister

Pivotal Tracker

As we move forward into HTML5, I can see this style of RIA development, with heavy JavaScript, becoming ever more common and necessary to compete.

QUESTION: So what are the common approaches emerging around managing these kinds of heavy JS developments?

Client-side code, as an app grows in features, is fiendishly complicated.  There are problems scaling a development effort across multiple teams with raw JS (or so I hear, and can well believe it).

Google has approached the problem by building GWT that compiles from a higher level language (Java) to JS, leaning on the existing development infrastructure that the higher level language has (Eclipse, strong-typing, refactoring tools), along with abstracting browser compatibility and other issues away from the developer.

There are other tools, like Script# for C# that do something similar.  All this puts JS more in the role of an IL (Intermediate Language). ie. "You never really write in that 'low level language' anymore."

But this 'compile to JS' is not the only approach.  It's not apparent that GWT is the dominant approach...or indeed will become it.

What are people doing with rich-client JavaScript? Some orienting questions:

Are most shops crafting JS manually (atop libs like jQuery et al)?

Or are there many many different approaches, with no clear best-practice emerging?

Are most shops avoiding RIA scale development in favor of the simpler to developer server-side/page-redraw model?  If so, will this last?

Is compiling to JS perhaps an emerging future trend?  Or is this just wrong headed?

How do they manage the complexity and refactoring of client JS?

Modularization and distribution of work across teams?

The application, enforcement, and testing of client-side patterns like MVC/MVP etc.

So, what are the emerging trends in this heavy-JavaScript and HTML5 future of ours?

Thanks!

答:
Personally I think that frameworks such as jQuery are vital not just to deal with variations across different browsers but also to tuck those differences away so that they're not adding noise to the code. Tools like GWT, Websharper and others take that further and definitely have a place but I wonder if it's just an extra layer of indirection in most cases.

Something that I'm suprised that no-one has mentioned is unit testing. It's now generally accepted that complex server side apps should have automated unit tests and I think that the time has already come where the JS in RIA apps is complex enough to need unit testing - together with the architecture/code that makes that possible.

However, unlike with complex server side apps, my gut feeling based on what I see and hear is that the vast majority of complex client side apps have absolutely no unit testing (I'm not talking about selenium testing here, real unit testing).

I think that the next emerging trend will be the introduction of unit testing (and code that is unit-testable).  Having just completed a project with a moderate amount of non-unit tested JavaScript I'm hoping it will be the last.


答:
Forcing inline comments for version control was about the most pointless coding standard I ignored.

```<code>//Changed on 2/2/2004 By Ryan Roberts for work item #2323332
Dim Some Horrendous VB
//End Changed
</code>```

The Oracle DBA that insisted on correct use of whitespace while 'maintaining' a database with a highly contended table that had over 200 fields and 40 triggers comes close.

Title: Worst coding standard you've ever had to follow?

Body:
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

Body:
Forcing inline comments for version control was about the most pointless coding standard I ignored.

//Changed on 2/2/2004 By Ryan Roberts for work item #2323332
Dim Some Horrendous VB
//End Changed

The Oracle DBA that insisted on correct use of whitespace while 'maintaining' a database with a highly contended table that had over 200 fields and 40 triggers comes close.


答: I would rather spend up to 1.5 times what it would take to do it manually, automating it instead. I attempt to justify this to myself beacuse I'm learning something whilst I automate and keeping my brain active.</p>


问:
How does understanding computer architecture help a programmer?
It is said, by Mike P. Wittie, in the course curriculum of computer architecture that,

Students need to understand computer architecture in order to
  structure a program so that it runs more efficiently on a real machine

I'm asking to more experienced programmers or professionals that have a background in this topic:

How does learning computer architecture help you? What aspect benefits you most? How did learning computer architecture changed your programming structuring?

答:
It can help quite a bit actually. Understanding concepts such as shared memory and inter-processor communication and the potential delays involved with these can help a programmer arrange their data and communicative methods to avoid relying heavily on these mechanisms, if needed. This is true for other areas of programming such as horizontal scaling, where distribution and communication among a program or system of programs is a main focal point.

Understanding the pitfalls or tar pits of a physical system can help you arrange such a program to help negotiate the physical systems as quickly and efficiently as possible. Simply throwing data into a communication queue and expecting it to scale is an undersight of what may really need to be put in place, especially if you must scale your software onto larger systems for better support.

Equally, understanding the benefits of something such as functional programming can really be exemplified in the light of understanding what's going on a physical, systems level and thus makes even more traction for concepts such as these, in my opinion.

One last quick example could be understanding the concept of say stream-processing and how sending data off to a processing unit like a video card may be best done in a very specific manner such as: send off all required calculations, receive back the frame of data in one fell swoop. In something like video graphics or maybe even physics calculations you wouldn't want to continually have an open communication with such a device; thus knowing this you would want to arrange this part of your program as such.

After all, if programmers did not understand these issues and road-blocks then these solutions would never exist in the format that they do.


问:
Implementing a new coding standard to an existing application
Recently we have had some turnaround in the shop I work in, because of this comments in our source code were made hastily and explained very little.  We have started working on the departments first draft of coding standards and one of the bigger questions is: Should we implement this standard across the existing source code?  Since this is only our coding standards first draft (done to promote flexibility and future considerations), should we be implementing on new features and during maintenance?

Update: I would like to say thank you for all of the answers and comments that were received on this topic.  Our shop has started to move forward with developing a draft for our coding standards and we have taken bits and pieces from all of the comments and answers to work with throughout our process.  Thank you for your time and experience on this matter.

答:
Definitely implement on new features and during maintenance. There is no value in spending time manually retweaking code to meet the guidelines. If you are an internal development shop, the business will have more pressing matters. If you are a commercial development shop, that is effort that is wasted while the competition does something.

The only real caveat is if you can easily feed your rules into an automated system and apply them. Since standards are new, this would most likely take more time than is prudent to devote to it.


答:
What has worked best for me in the past and currently is that as we refactor code we use the current coding standards. If during this refactoring the code becomes unclear (because say we refactored out a method in one spot but it is not consistent with the rest of the class) we tend to bring the whole class up to the current standard. It really depends.

All forward and new development is in the new standard.

One reason we only update older code as it is refactored though, is because much of the legacy code is maintained by a few core developers. If we wholeheartedly changed the standard on the legacy code these developers would have a harder time. As we refactor out this code and move on though, this is less of a problem and the legacy developers learn the new standard (often they are doing the refactoring too) and bring the code forward.

All in all this rarely takes much more time than doing the work necessary there and it doesn't stop development on the product as a whole for everyone for a bit while all code is being brought to standard. This process is accounted for in the velocity of the developers in the sprints they are on and is transparent to management outside of the tech teams so no one has to ask or present why additional time is necessary to change code that is currently working. Trying to explain to executive management that is not technical why coding standards matter and why they are changing versus getting new features for Sales in the code is remarkably difficult at times. This process avoids it.

Title: Implementing a new coding standard to an existing application

Body:
Recently we have had some turnaround in the shop I work in, because of this comments in our source code were made hastily and explained very little.  We have started working on the departments first draft of coding standards and one of the bigger questions is: Should we implement this standard across the existing source code?  Since this is only our coding standards first draft (done to promote flexibility and future considerations), should we be implementing on new features and during maintenance?

Update: I would like to say thank you for all of the answers and comments that were received on this topic.  Our shop has started to move forward with developing a draft for our coding standards and we have taken bits and pieces from all of the comments and answers to work with throughout our process.  Thank you for your time and experience on this matter.


问:
Do I check generated code in to source control or not?
I'm developing a .Net application that uses google protocol buffers. Historically the application used the approach, advocated by the protobuf-net team, of decorating the classes with attributes instead of using .proto files.

I am now in the process of migrating part of the application's client to another technology and there is a strong desire to start using the .proto files as the authority so that the two technologies can inter-operate.

My plan is to automatically generate the C# from the .proto, however, my question is should I check the resulting files back into source control? Note I expect the process of code generation to be fast.

How do I choose appropriate approach for above case? What is considered the best practice?

答:
A lot of files in .net are automatically generated by Visual Studio; nevertheless, we usually check these in so that anyone checking out the source code has a complete version that builds and runs. (See, for example, classes made from xsd files for deserializing xml.)

I would view these files the same way; they're C# source code that was generated via a tool but which is necessary for the program to build. Therefore, check them in.


问:
Splitting user stories into smaller stories
I've been reading various techniques for splitting large user stories in helpful ways, such as by user workflow through the system etc. What I'm struggling with is how to word these smaller stories if all they achieve is facilitating the next step in the process and not delivering the application's main benefit to the user.

For example, if my new system is split down into 3 smaller stories along the lines of;

Create a new account online

Create certain entities against my new online account

Have my mobile device query these entities against my account and act on them

The system only really provides useful functionality to the end user when all stories are complete. So if following the traditional "As a [User] I would like [Functionality] so I can [Benefit]" The benefit of the first and second story is simply facilitating subsequent stories and not really providing the user with the main piece of functionality (the epic). Is this the correct way to do this?

答:
You have three stories here which have to be done (probably in a sequence) to achieve a goal, being able to query against the entities from a mobile device is a feature which will deliver a business goal, it does not appear to be the business goal itself IMHO.

Here's my suggestion, phrase the business goal that your epic has to achieve and define stories like so

As a user I would like to register myself on the system so I can [business goal]

As a registered user I would like to create entities in my account so I can [business goal]

As a registered user with account entities I would like to act on queries against my entities from a mobile device so I can [business goal]


问:
Architecture change from using disk to RAM to read and write key/value pairs coming over a network
A WebApp writes a stream of data coming over a network to disk as key/value pair and then reads & send it over network again after few milliseconds in 99% of case. In 1% of cases write/read can be few hours to days apart (really don't know).

Latency is strict "no" in the app and we have to serve 100% of customers therefore I am planning to put data into RAM and later read and send it over network and only write to disk if the data is not read from RAM within a certain prefixed interval.

What could be possible solution to this problem?

P.S - Memcached looks like a good solution for using RAM instead of disk but Can memcached read/write of disk after time_to_live?

I also looking at Couchbase but I don't want to write to disk in all cases as 99% write/read happens in the matter of milliseconds.

Is it possible that after time_to_die Memcached could write the key/value to Couchbase instead of removing it from RAM and read it on demand?

[Edit 1]

After spending last few trying to explore various options. The following looks like a possible solution

Write the data stream simultaneously to the RAM (using Memcached) and disk using (GlusterFS).

In case the data is demanded by the application layer check it first in the RAM (Memcached) if it return the data ok, if it does not check the data on disk GlusterFS.

Remove data stream from RAM if data is demanded by application or when time_to_live is reached whichever is earlier.

Suggestion most welcome.

答:
A lot of how you handle this problem is going to hinge on that requirement of 100% of the customers being served. When the goal is absolutely no downtime then performance will almost always have to take a second position to reliability.

You say that your timespan for a typical response is a matter of milliseconds but how do you want to handle the situation where an error occurs within this timeframe? It is easy to imagine a machine getting reset while it is waiting on a long process (say on the order of hours) but that reset could also happen directly in the middle of a transaction that would typically happen in a matter of milliseconds. Maybe the machine loses power at that exact moment or the RAM ends up corrupted.

If reliability is the key to your system then I would say that your only real option is to write the data to a safe storage location before you process it. If the data is not safely stored then it is not processed by the system.

The better solution would most likely be to lower your requirement form 100% to 99.9% or similar and then you could ignore situations like the aforementioned error within a typically fast process.


问:
Is it possible for a browser to use peer-to-peer browsing?
I was recently asked this from my friend after explaining how µTorrent worked, he then went to ask me, "Could this be used for browsing the web?", (not a direct quote) but I found my self thinking about this for a while there after.

Could someone be credited with making the first Peer-2-Peer browser?

How could it send the correct data without it being modified?

Would it be faster than normal browsers? (Referring to the way µTorrent works, I find when I use a torrent it's faster than a web download.)

Can it save on server loads, prevent DDoS, more?

答:
Could someone be credited with making the first Peer-2-Peer browser?

A browser already operates using peer-to-peer communication. While writing this post my computer is speaking directly with the computer at programmers.stackexchange.com. There's no central machine in the middle that is handling my connection and the connection to the server here.

How could it send the correct data without it being modified?

You ask the peer for data and it sends that data. It is up to the peer to determine what to give you when you ask. There's nobody else to get in the way and modify everything.

Would it be faster than normal browsers? (Referring to the way µTorrent works, I find when I use a torrent it's faster than a web download.)

Torrents are not inherently faster than any other internet communication. All machines connected to the internet have a maximum speed that they can send data at depending on multiple factors (actual internet connection speed, congestion, etc...). As such if you are trying to download a file from a server that has a very poor connection it will go slowly. If you attempt to download the same file from uTorrent and find many peers available for it there will be more bandwidth and thus it will go faster.

Try downloading a file from a provider that you know has plenty of speed available and you will see how fast HTTP can be: http://cachefly.cachefly.net/100mb.test

Can it save on server loads, prevent DDoS, more?

Not really. There's still a computer sending data and thus said computer can be overloaded with too many requests like any other.


问:
Automatically delete files after they expire
I've got this idea for some time and I was wondering if anyone has seen such a feature/app in any operating system and if you haven't, what do you think about it. Where do you think I should begin?

The idea is simple. I think we all have those files that are made and probably used for a few days and then are left on our disk and we never delete them or even check to see if we need them again. It'd be cool if you could right click on a file and click on "Expire in.. 3 days" for example. And the file gets deleted after 3 days. I have a great need for this and maybe some people will find it useful.

I was thinking of writing a script and use the Nautilus Action project in GNOME for a start.

答: The SEFS - Self Expiring File System  prototype implementation has been designed based on the freely available FUSE file system. I have done this for my Masters Degree in Computer Science.</p>


问:
Why do .Net books talk about stack vs heap memory allocation?
It seems like every .net book talks about value types vs reference types and makes it a point to (often incorrectly) state where each type is stored - the heap or the stack.  Usually it's in the first few chapters and presented as some all-important fact.  I think it's even covered on certification exams. Why does stack vs heap even matter to (beginner) .Net developers?  You allocate stuff and it just works, right?</p>

答:
You guys are all missing the point.  The reason why the stack / heap distinction is important is because of scope.

```<code>struct S { ... }

void f() {
    var x = new S();
    ...
 }
</code>```

Once x goes out of scope, the object that was created is categorically gone.  That is only because it is allocated on the stack, not the heap.  There is nothing that could have gone in in the "..." part of the method that can change that fact.  In particular, any assignments or method calls could only have made copies of the S struct, not created new references to it to enable it to keep living.

```<code>class C { ... }

void f() {
     var x = new C();
     ...
}
</code>```

Totally different story!  Since x is now on the heap, its object (that is, the object itself, not a copy of it) could very well continue to live on after x goes out of scope.  In fact, the only way it won't continue to live is if x is the only reference to it.  If assignments or method calls in the "..." part have created other references that are still "live" by the time x goes out of scope, then that object will continue living.

That is a very important concept, and the only way to truly understand "what and why" is to know the difference between stack and heap allocation.

Body:
You guys are all missing the point.  The reason why the stack / heap distinction is important is because of scope.

struct S { ... }

void f() {
    var x = new S();
    ...
 }

Once x goes out of scope, the object that was created is categorically gone.  That is only because it is allocated on the stack, not the heap.  There is nothing that could have gone in in the "..." part of the method that can change that fact.  In particular, any assignments or method calls could only have made copies of the S struct, not created new references to it to enable it to keep living.

class C { ... }

void f() {
     var x = new C();
     ...
}

Totally different story!  Since x is now on the heap, its object (that is, the object itself, not a copy of it) could very well continue to live on after x goes out of scope.  In fact, the only way it won't continue to live is if x is the only reference to it.  If assignments or method calls in the "..." part have created other references that are still "live" by the time x goes out of scope, then that object will continue living.

That is a very important concept, and the only way to truly understand "what and why" is to know the difference between stack and heap allocation.


答:
Knowing your architecture allows you to know when something that's being asked for is impossible.

I was once asked to write a program to communicate with a PIC over a PC serial port. The protocol would have the PIC sending nine-bit bytes, with no flow control. I would display in my program's UI the values of the fields in the packets that the PIC sent. Obvious question: how do I read the ninth bit of each byte? The protocol engineer and I decided that we would try setting the parity to MARK and then treat the ninth bit as a parity bit. I would read the value of the ninth bit according to the success or failure of the parity check. Well, I implemented that, and it didn't work. The values being displayed were obviously wrong. And after three continuous days of researching PC UART architecture, I found out why.

Here's why. The PC UART buffers its input. By the time it interrupts the CPU to say "READY TO READ", any number of bytes could have accumulated in its buffer. There is, however, only one Line Status Register to hold the value of the parity check. It is therefore impossible to tell which byte in the buffer failed the parity check. So: make sure that the buffer is only one byte long, you say? That's a flow control setting, and I already mentioned that this protocol didn't have flow control. If I didn't know the architecture of the hardware I was programming, I would never have been able to say: "Reading the ninth bit is impossible and needs to be cut."

Title: How does understanding computer architecture help a programmer?

Body:
It is said, by Mike P. Wittie, in the course curriculum of computer architecture that,

Students need to understand computer architecture in order to
  structure a program so that it runs more efficiently on a real machine

I'm asking to more experienced programmers or professionals that have a background in this topic:

How does learning computer architecture help you? What aspect benefits you most? How did learning computer architecture changed your programming structuring?


答: It is fine to implement new coding standards in existing code.  It is important that you are able to objectively prove that the coding standards changes did not impact the actual functioning of the software.  To that end, you should create unit tests that prove how the code currently functions and use these unit tests to prove that the changes to the code (coding standards should be cosmetic in nature) did, in fact, not change the functionality of the code.</p>


答:
Understanding the principles of computer architecture requires learning many important principles of programming. Therefore, a knowledge of computer architecture is relevant to programming in any language, no matter how high level.

These important principles include:

Fundamental data structures like arrays and stacks

Program structure: Loops, conditionals, subroutines (jump and call)

Considerations of time and space efficiency

Systems: The way various components fit together through abstract interfaces. Apparently this is controversial, so I will elaborate. Take the instruction set, a construct with a general form (operands, addressing modes, encoding)
that is applicable to many different kinds of operations, such as arithmetic, logical, memory modification, and interrupt control.
This illustrates a general principle of system design, namely that systems are composed of individual subsystems that all share the same
abstract interface, and that abstract interfaces are capable of handling many specific components.  This principle is also visible in a web application
which may store the same kind of object (abstract interface) in a database, in memory, or on a web page (subsystems). In each case, the abstract interface
specifies the general form without specifying the concrete detail. System design is the art of knowing what to make general and what to make specific. This
is a skill honed by designing and understanding systems -- in any language and at any level.


问:
LGPL, .lib, .dll, and linking
I am trying to build a project which uses an unmodified copy of libconfig (http://www.hyperrealm.com/libconfig/). libconfig is LGPL, but I don't want to open source any of my code. By my understanding, LGPL means I need to provide the source for the library (easy), and a means for them to use their own modified version of the library. It's the latter component that confuses me a bit (apologies for some c naivete).

Currently, my VS2010 solution has my project, and the libconfig project. The libconfig project builds a dll, but I also need to link my project against the .lib of libconfig to get the dll's definitions (Can someone explain why this is necessary, when I'm already including the header file?). Despite the linking, the .dll file needs to be present at runtime for the binary to be able to run

Do I need to provide all of the .obj and .lib files I produce to satisfy the LGPL? Is there a way to avoid the linking of the .lib file? I've looked into LoadLibary and GetProcAddress but it looks way more complicated than I'd like.

Or am I simply overestimating the requirements of the LGPL here?

If there's another, more permissive config library for c++, that would also solve my dilemma. But I haven't been able to find something (and I'd like to avoid boost).

答: The "means for them to use their own modified version of the library" in this context is letting users use their own libconfig.dll instead of yours if they want.  By making it dynamically linked you have fulfilled this requirement.  They can just replace the file.  If you had made it statically linked instead, where you don't need the libconfig.dll in order to run, you would also have to provide your object files and build scripts.

Title: LGPL, .lib, .dll, and linking


问:
Are there concrete reasons not to use libraries and code snippets heavily?
Overall I'm in programming for about 8 years now and it seems to me that I'm relying more and more on open source libraries and snippets (damn you GitHub!) to "get the job done". I know that in time I could write me own implementation but I like to focus on the overall design.

Is this normal (non corporate environment)? What could go wrong if my "programming" is nothing more than gluing different libraries together?

I know about "don't reinvent the wheel" but what happens when you don't invent a single wheel anymore?

答:
That's generally a good idea, so long no legal issues exist.

However, make sure you take the time to understand what the library does and how it does it.  Using a "magic" library to take care of things you don't understand is a good way to have some part of it blow up on you because you used it wrong, and then you have no idea how to fix it.


问:
The advantages & disadvantages to be had from using a Web Framework?
This question is focused on extracting the advantages and disadvantages of using Web based Frameworks: such as Cake PHP, Zend, jQuery, ASP.NET). This question is completely language agnostic. Let me start with the notion of "Standing on the shoulders of Giants".

Advantages:

Empowers Developers - by taking features that would have previously have taken 100's of lines of code and compressing them into one simple function call empowers developers to integrate more complex features into their Web Sites.

Allow for Quicker development of applications - this is very relevant for people that need websites created in a very small window (has anyone any examples of this?)

Lower Costs - allows programmers to pass cost savings onto the customer, a whole new range of customers generated that wanted a website but previously could not afford the higher development costs.

Disadvantages:

Lost Understanding - by relying on the features of a framework a developer is in danger of loosing understanding on how things work (underneath the hood).

The configuration cliff - once you go further than the configuration of your framework your productivity drops right off, it can be difficult to implement features outside of a frameworks configuration.

Developer tramlines - you (the developer) has to do things the way that the developer want you to do things.

I wonder what people make of my points, and whether anybody disagrees with them?  Also if people have additional points I would be grateful.

答:
I speak from personal experience in the last 13 years. In my company we used struts, after a short curve it was great. In my next we used an architecture that was mostly opaque, somewhat struts like but grown, we could extend it but the core code was only jars. And so on. in the last 3 years have been working in a small company (number of dev < 30) and it was all our own jsps, servlets and ejbs. Looking at our multiple clients and the repetition of jsps, in 2012 was to make a j2ee filter that mimiced 20% of struts2. Why not use stuts 2? I wish we had but : could not get it passed our chief architect; not enough experience or time.

So we had intercepters some common jsps that our mini framework used. Now when I have had the time to go thru a struts 2 book I see that we have missed so much!

We do use some great algorithms and caches and UI but have lost a lot of hours and burdened with a lot of code that we have a 3 year plan to retire.


答:
Code reuse is a very good idea. It reduces redundancy and promotes maintainability.

The title suggests you are using the code as a library, but the text of your question implies you might be copying the source code into a new project. I'd stick to using other developers' code as a library as much as possible.

There is a problem if the code is bad or somehow broken or based on a model that doesn't fit your application very well. In that case it might be simpler to scrap some or all of the code and start from scratch than trying to understand why it was written in a given way. Keep the other code around for reference, though; you may come across an issue that you aren't sure how to solve. Chances are the other developer probably came across the same issue, and it's worthwhile to see how they solved it.

Title: Are there concrete reasons not to use libraries and code snippets heavily?

Body:
Overall I'm in programming for about 8 years now and it seems to me that I'm relying more and more on open source libraries and snippets (damn you GitHub!) to "get the job done". I know that in time I could write me own implementation but I like to focus on the overall design.

Is this normal (non corporate environment)? What could go wrong if my "programming" is nothing more than gluing different libraries together?

I know about "don't reinvent the wheel" but what happens when you don't invent a single wheel anymore?


答:
Memcached is just a cache. The out of box java version at https://code.google.com/p/quickcached/ supports writing to disk on exit but for what you need, I think you will have to add your own code.

One thing to consider is how much of data, at peak load do you think you will have 3 years from today? If that is not too much can use your own RAM with a in memory cache like whirly, and your own thread that peeks in the to cache every 5 minutes and saves to disk items that are not yet picked up. Note: your POJO will have to have the checked in time, whirly wont tell you when an item was put into its cache.

Title: Architecture change from using disk to RAM to read and write key/value pairs coming over a network

Body:
A WebApp writes a stream of data coming over a network to disk as key/value pair and then reads & send it over network again after few milliseconds in 99% of case. In 1% of cases write/read can be few hours to days apart (really don't know).

Latency is strict "no" in the app and we have to serve 100% of customers therefore I am planning to put data into RAM and later read and send it over network and only write to disk if the data is not read from RAM within a certain prefixed interval.

What could be possible solution to this problem?

P.S - Memcached looks like a good solution for using RAM instead of disk but Can memcached read/write of disk after time_to_live?

I also looking at Couchbase but I don't want to write to disk in all cases as 99% write/read happens in the matter of milliseconds.

Is it possible that after time_to_die Memcached could write the key/value to Couchbase instead of removing it from RAM and read it on demand?

[Edit 1]

After spending last few trying to explore various options. The following looks like a possible solution

Write the data stream simultaneously to the RAM (using Memcached) and disk using (GlusterFS).

In case the data is demanded by the application layer check it first in the RAM (Memcached) if it return the data ok, if it does not check the data on disk GlusterFS.

Remove data stream from RAM if data is demanded by application or when time_to_live is reached whichever is earlier.

Suggestion most welcome.


答:
Legally reusing code has almost no downsides and two huge upsides:

It gets the job done. This is the more important one for professional development. Ultimately, you have a well-paying job because you know how to make things happen that would stump most non-programmers; reuse allows you reach that goal faster, so you become more valuable in your job.

You learn stuff. This is the more important reason for self-improvement. There is no better way to improve coding than to read good code written by others. Even bad code written by others usually teaches you something! And there is no better way to understand how a library, API, language, or domain works than reading and improving solutions already written by others. Both things usually happen when you reuse existing code, because no pre-existing solution will ever do quite what you need - and the ensuing tinkering with the source is where the knowledge boost comes from.


问:
How can I create a web form that displays and accepts Tamil language?
I am developing a PHP Application that needs to display and accept content written in tamil.
For example "login" should be written in tamil on the form. </p>

<p>How can I achieve this ? </p>

答:
If you want to display tamil characters on a web page, be it in PHP or any other web technology, you have to indicate to the browser that the page is written in UTF-8.

Also, "how to create web sites in indian languages?" might help you as it gives why and how you have to do it.

In short:

Make sure to save your PHP file in UTF-8.

Indicate to the browser that the page should be viewed in UTF-8 by adding the following meta to the page: <meta http-equiv=Content-Type content="text/html; charset=utf-8">

You have to configure your web application to serve UTF-8 content. As such, The HTTP Content-Type header should look like so: Content-Type: text/html; charset=utf-8

I'm not a PHP programmer at all, but you should check out How to display unicode data in PHP, this should help you a lot.


答:
Save the files in UTF-8 if using a editor like Editplus or eclipse you can google how to

Use a multipart form with UTF encoding https://stackoverflow.com/questions/1075513/php-parsing-multipart-form-data

In your persistance / data base layer set up the tables to accept UTF-8 and your good to go. If using My SQL its usually on by default for varchar

Title: How can I create a web form that displays and accepts Tamil language?

Body:
I am developing a PHP Application that needs to display and accept content written in tamil.
For example "login" should be written in tamil on the form. </p>

<p>How can I achieve this ? </p>


答: Usually, copying large amounts of source code is poor practice.  If the code was developed for another application at your company, then you should reuse the code by extracting it into a library to be used by both applications.  You should not copy the code.  Copying the code will force you to maintain two copies instead of one common copy.


答:
In addition to the reasons in the other answers, not using the code (as long as it's a good fit for your problem) can be considered unethical because:

You might be intentionally wasting your employers time OR

You might be intentionally delivering a lesser product

Keep in mind, both of those are hard to determine beforehand.

Also, look at Not Invented Here, which commonly referred to as an anit-pattern.


问:
Implementing oAuth 2 server
Do you have any pointers on how one should go about implementing the oAuth2 protocol itself? That is, the server side or the "provider" facet of OAuth2?

If you have tried to implement (a part of) it, please share the issues and the solutions. Note that this is completely technology and programming language agnostic - except, of course, for the de-facto standard cryptological technologies that might be involved. The IETF draft (v23) for oAuth2 is located here

答:
OAuth 2 does not have much in the way of cryptography requirements.  It relies more on the communications being over secure channels.  We have implemented a full-fledged OAuth 2 service (http://www.assurebridge.com/our-products/mobileconnect/) and found that the most complex parts are the authentication (before issuing the token) and the verification of an incoming token.  Both of these are not actually part the the spec so you need a tremendous amount of flexibility here.

The other issue is state.  Since the OAuth server needs to remember the token, it must maintaining all current, non-expired tokens.  To be fault tolerant you need to look into a distributed session store like jcache or nCache.

Since there is back channel communication and verification, you also need a good http client library as well as JSON.

The other area we faced was performance.  Since every request from a client application to an application service requires a access token and that access token needs to be verified with the security service, this generated a lot of traffic.  We implemented a caching scheme to cut down on the back and forth making sure the cache timed out before the tokens expired.

I agree, the Google implementations are a good place to start since they have become a de-facto standard.

Good luck!

Oleg

Title: Implementing oAuth 2 server


问:
What is ASM.js and what does it mean for everyone?
I'm starting to hear rumblings about this project called ASM.js. Currently their web site is terrible and confusing. Here's what I know from my research on the web.

It is a subset of JavaScript that can be highly optimized. I'm guessing because it avoids the more dynamic parts of the language.

Performance of code compiled to ASM.js runs at about half the speed of C (not light).

The intention is for compilers to make their target language ASM.js.

Firefox is going to be shipping with ASM.js optimization baked in.

The Mozilla and Unreal teams ported the Unreal Engine to the web with it and its running in a build of Firefox at near-native speeds.

There doesn't seem to be any concrete information on the web about what this really is or the usefulness or ultimate purpose. Is it that I can compile my otherwise server-side code bases and have it run in the browser at close-to-native speeds? What are the ramifications for developers?

答:
You already described what it is. The use is that it's a low-level language that works across all browsers, is quite fast in most and very fast in some. What you make of this is as open-ended as what you do with any other programming language.

The use case Mozilla seems most keen on is this: There are already ways of compiling languages with LLVM backends (most prominently C and C++) to JavaScript, via Emscripten. asm.js is very close to what Emscripten already emits, so this allows Emscripten code (which is already impressively fast on today's JavaScript JIT compilers) to become even faster, furthering the goal of porting existing code bases to the web. Again, what exactly you use this for is your decision. Porting games is one use cases (which Mozilla is apparently actively involved in), but there are countless things written in C and C++, quite a few of which might come in handy for someone's web site. Some I've seen flung around (plus some of my own devising), with no guarantee regarding feasibility:

Porting general-purpose algorithms (e.g. zlib, libjpeg, openssl, FFT implementations) to empower JavaScript/websites to do more, without having to create a new web standard and depending on individual browsers to implement it.

Porting interpreters, so that languages other than JavaScript can run in the browser, with less overhead and minimal porting effort.

Using asm.js as a backend for more compilers, especially those that don't map well to JavaScript and don't need most of its features and overhead. An example could be a language designed for fast numeric work with no memory allocation.

Using asm.js to create a JIT in JavaScript. It may implement any language at all -- for example ActionScript.

In the same vein, porting existing JIT compilers to run in the browser (cf. porting interpreters, with effectively nil overhead over JS). This is probably only feasible when JIT compilers are automatically generated, as with PyPy.


问:
Do integrated systems increase development time and cause inflexibility?
I work for a large financial company that manages money for thousands of clients.  This company has very complex business processes and they operate in a very dynamic environment.

This is a fairly old company and over the years they have implemented many heterogeneous systems to automate processes within the company.

There are rumors in the company that there may be an effort to move to "a system" (re-written from scratch) that consolidates the many disparate systems in place now.

Debate has arisen that questions the value of such a move:

One side claims a single system is easier and cheaper to maintain due to greatly reduced redundancy i.e. properly factored business logic, unified data model, reusable UI components, etc.

Other side claims that the company, clients, and products (financial instruments) are too complex and too dynamic to be pigeonholed by one system. Single system will risk  breakages in one component when another is modified.  There is no way and no reason to consolidate business logic because it is too client- and product-specific.  Time to implement changes will increase because multiple higher level components will be affected by changes to lower level components.

Question:
Should the company seek to invest time and resources in creating a unified data model, factoring business logic and creating reusable code at all layers?  Or should they "copy and modify" in order to speed development time, reduce the chance of regression, and reduce complexity? Is there a false dilemma presented here (i.e will there be a net change one way or the other and does one answer necessarily preclude another)?   To be clear, this really a matter of long term goals and priorities, not about a specific product design.  The company will never eliminate a certain amount of redundancy and it would not be desirable for them to do so.

答:
Your comparisation seems to be wrong. You are talking about:

1 big system handling everything in the business

multiple systems handling all seperate parts of the business

Now the issue with this is very simple: That one big system won't be ONE. It will very likely be a group of libraries, models, etc. which combined show like a single application maybe. But the internals won't be ONE big thing.

Now to answer:

Single system will risk breakages in one component when another is modified

If you have two systems communication together you have the same. In one application it's even easier (interfaces and integration tests) to be sure this does not happen.

Should the company seek to invest time and resources in creating a unified data model, factoring business logic and creating reusable code at all layers?

Sounds impossible. Maybe when the world stood still it might be possible to wrap it all in code. In real: That won't succeed. You will have some parts more nice than others. Which goes to your next question:

Or should they "copy and modify" in order to speed development time, reduce the chance of regression, and reduce complexity?

This is a business case which you should define per case. If you can make a million by having a copy-paste-solution next week it might be worth it. You can always refactor it further in the future.

Generally: You ask for a choice which is not the real choice. What I would expect if I read the story is: Start with this project from the start. So with the business goals in mind. Based on that see which result the current tools give. Which data they share. Then compare the options to integrate them or replace them. It's likely that replacing all is very expensive so maybe a hybrid solution is better. Keep the complex but good tools, integrate the rest. And then link the existing complex tools to the general platform.

I'm not mentioning anything about writing from scratch, enough research on that available.


答:
Learning computer architecture helps immensely in programming.

Without understanding the environment the program is running in, your mental model is seriously handicapped. We see the world, not as it is, but as we are -- through the mental model.

You won't notice the difference in happy case scenarios, where everything just happens to work, but it will make a crucial difference when you are working on harder problems or debugging weird bugs (ie. real life programming).

It's the difference between "WTF?" and "Ah, of course!".


问:
How web-servers identify a client
I have seen on some sites which say ,for-example, multiple votes/views from same computer will be neglected/penalized etc. For-example liking a facebook page, or youtube video from same computer(different accounts) will not increase its worth(according to my knowledge).

How do these sites identify bogus votes? I just need a direction.

答:
Simplest way to do it would be to filter based on IP address. That means that even legitimate votes from separate users behind a firewall will be discounted. That may seem unfair, but the only other way to do it is with the browsers 'user-agent' identifier or a set of 'accept' headers (for example).  But users such as myself who run various browsers from a single machine would easily circumvent mechanisms like that.  The good web developers are well aware of that and will likely err on the side of being slightly unfair to some legitimate voters than to allow scammers who log in to multiple accounts from different browsers to vote from.

It really depends on the nature of the site taking the poll, but gathering as much metrics from users as possible and analysing the statistics will help to identify the legit from the fraudulent. Usually this sort of research has been done before hand and an algorithm is selected accordingly.

If I had to do it on a site right now with no metrics, I would filter solely on IP addx.

Title: How web-servers identify a client


问:
In Java, would you sacrifice type safety for a nicer programming interface
When and why would you generally sacrifice typesafety for a nicer programming interface?

Let me give you an example: if you had the choice between two event aggregators, which one would you prefer and why?

Reflective Version:

```<code>SomeEvent.subscribe(instance, "nameOfAMethod"); //method called via reflection
SomeEvent.fire(arg1, arg2);  //the firing could actually even be statically typed
</code>```

Statically typed version:

```<code>EventSystem.getEvent(SomeEvent.class).subscribe(new EventHandler<Payload>() {
   public void eventOccurred(Object sender, Payload payload) {
       //event handler code here
   }
});

EventSystem.getEvent(SomeEvent.class).fireEvent(payload);
</code>```

Please note, that in Java, due to type erasure, you cannot implement a generic interface with different type parameters more than once and need to resort to anonymous or external classes for handlers.

Now the reflective event system has a nicer user interface, but you lose type safety. Which one would you prefer? Would you create empty event classes just for the sake of having a symbol, like Microsoft does it with PRISM in its event aggregator?

答:
if you have the time now then do it with the type checking. if its code that might last up to December 2013 you will regret method 1 later, unless its a small project and you will be the only one working on it ... no even then if you have the time i would go with the typed.

Why? clearer, less mistakes, more verbose yes but will help keep some bugs at  bay and that is a good thing


答:
You would be sacrificing more than just type safety.  Reflection is at least an order of magnitude slower in Java than using strong types.

It's a false dichotomy anyway.  It's possible to have a nice programming API without sacrificing type safety.  See http://boo.codehaus.org/

Title: In Java, would you sacrifice type safety for a nicer programming interface

Body:
When and why would you generally sacrifice typesafety for a nicer programming interface?

Let me give you an example: if you had the choice between two event aggregators, which one would you prefer and why?

Reflective Version:

```<code>SomeEvent.subscribe(instance, "nameOfAMethod"); //method called via reflection
SomeEvent.fire(arg1, arg2);  //the firing could actually even be statically typed
</code>```

Statically typed version:

```<code>EventSystem.getEvent(SomeEvent.class).subscribe(new EventHandler<Payload>() {
   public void eventOccurred(Object sender, Payload payload) {
       //event handler code here
   }
});

EventSystem.getEvent(SomeEvent.class).fireEvent(payload);
</code>```

Please note, that in Java, due to type erasure, you cannot implement a generic interface with different type parameters more than once and need to resort to anonymous or external classes for handlers.

Now the reflective event system has a nicer user interface, but you lose type safety. Which one would you prefer? Would you create empty event classes just for the sake of having a symbol, like Microsoft does it with PRISM in its event aggregator?


答:
When and why would you generally sacrifice typesafety for a nicer programming interface?

Rarely if ever, and then only if the type un-safety was dealt with effectively in another manner.

Verbose/awkward programming interfaces yield a little fewer bugs, and far lower severity bugs than typeless interfaces in the middle of typed languages. Because let's be honest, using string lookups or casting out of Object is its own horrible programming interface - now you have a horrible programming interface and typing issues.