答:
The only question I would have is how the command service processes your commands.  Are they handled asychronously or is your client waiting for the command service to process the command and complete the write to the repository before returning an ack/nack?  If you're looking for scalability, that may be one area that you could focus on to improve scalability.

Other than that, it looks good on the surface.

Good luck!!

Title: What is the best way to scale a CQRS system?

Body:
In the previous months I have been asking a lot of questions concerning the architecture of an application I'm working on. Thanks to the answers the architectural design has changed - in fact, it has really been simplified as shown in the following graph:

Internally I have a two services (NOT WCF!) that follow CQS principles. It means that the query service simply returns database views; while the command service has a full domain model that contains all business logic, and repositories to access the database (no event mechanism or other complex pattern here). Both services use the same database. These services are class libraries, NO WCF services, because they are used only internally so I don't need the overhead of WCF (don't distribute your objects, Martin Fowler's first law).

These internal operations are used by the ASP.NET MVC site and the PartnerService. This PartnerService is a WCF service, which exposes the functionality I would like to be exposed to partners.

If I ever need to scale because of high traffic, I could add web servers and/or migrate parts to a full CQRS system (my contracts are already designed for it).

Does anyone see any problems with this?

One thing I see is that if the query or command service changes, this impacts both the web site and partner service directly, so I have to deploy the changes to both. But I don't know if this is an issue...?

Any feedback is appreciated! Thanks!

OwnerDisplayName: David Hoerster


问:
What are the worst false economies in software development?
What are the worst false economies (that is ways of saving money that ultimately cost more than they save) prevalent in the software industry and how do you combat them?</p>

答:
Optimization before profiling (aka premature optimization).

Too many times I've seen someone reach for a clever solution which needlessly complicates maintenance and readability on the grounds that it's faster.  Naturally, the code hasn't been bench marked (not even with micro-benchmarks), so it quickly becomes "faster based on the more persuasive argument" over a section of code which most likely didn't impact the overall performance of the entire application by much.

As such, it is a very false economy, and the kind of false economy that occasionally entangles even the seasoned pros.

ContentLicense: CC BY-SA 2.5

ContentLicense: CC BY-SA 3.0


问:
Can applications override the OS keyboard layout?
We have in-house .NET application, which can be used across multiple languages. Lately we received a strange bug that is when our application is being used, user was unable to enter accent characters (Spanish, Win 7) in other applications (ex: MS Word or Notepad). Strange, huh!

Did anyone come across similar bug? If yes how did you solve that?

答:
You can use keyboard hooks to hijack the keyboard. I might start by looking for SetWindowsHookEx calls in your code. Maybe try running your program normally and Notepad as Administrator; keyboard hooks don't work with higher privilege processes, so that might narrow down the problem a little.

You can change keyboard layout within your code, but only by changing the registry, and it requires a restart before it works (or at least a logout, maybe) -- so I highly doubt that that's the culprit.

As Jose notes, the input layout may have also changed. Go into the Windows Region and Language settings and under Keyboards and Languages -> Change keyboards -> Language Bar, choose Floating On Desktop. Try changing around several applications to see if the input language is getting switched. If it is, you should turn off any keyboard layouts that you're not using (you probably won't need English), or hit left alt + shift whenever the language gets switched.


问:
My boss wants a narrated line-by-line English explanation of our code
I have been specifically asked to give line by line (or as appropriate - for example, image by image, etc.) explanation or commentary which my boss wants to be able to read and follow.

Since he is not a programmer, he can not follow the code so wants it all translated into English.

Has anyone been asked to do this before?

I have commented on all of the source code and used JSDoc to generate full documentation of all functions, variables, etc... and included an implementation example, and full working demos with comments throughout.

Is there anything else I can do to comment the code for non-programmers?

This isn't a reasonable request, is it?

UPDATE

In the end, I managed to explain why it was not a good use of time to do what he was asking. He is a reasonable guy, and just did not have an understanding of what my job involves. Once he saw this post, I think he quickly understood that it was not a normal request.

I did provide documentation that is suitable for another programmer to follow (JSDoc and inline comments - as well as some extra notes on technical issues), and a very broad flow chart diagram of the main logic of the program for my boss to follow.

In the end, all parties were satisfied and we have moved on.

答: This may be a dumb thing to actually do, but could you put together a compiler that compiles whatever language(s) you're using into English "prose"?  You could run your code through the compiler, use something like wc to figure out how many lines it is, and then make it available to your boss (perhaps threatening to print it ;).

OwnerDisplayName: BIlly Moon


答:
Bring him into your office and give him a tour of your code.

He'll realize part way through that he made an absurd demand, and he'll walk away and never bother you again.

If you don't give into his demands to help him try to understand your code, he'll find different but equally absurd ways to poke at you.

This is a case where appeasement works better than abrasion.

Title: My boss wants a narrated line-by-line English explanation of our code

Body:
I have been specifically asked to give line by line (or as appropriate - for example, image by image, etc.) explanation or commentary which my boss wants to be able to read and follow.

Since he is not a programmer, he can not follow the code so wants it all translated into English.

Has anyone been asked to do this before?

I have commented on all of the source code and used JSDoc to generate full documentation of all functions, variables, etc... and included an implementation example, and full working demos with comments throughout.

Is there anything else I can do to comment the code for non-programmers?

This isn't a reasonable request, is it?

UPDATE

In the end, I managed to explain why it was not a good use of time to do what he was asking. He is a reasonable guy, and just did not have an understanding of what my job involves. Once he saw this post, I think he quickly understood that it was not a normal request.

I did provide documentation that is suitable for another programmer to follow (JSDoc and inline comments - as well as some extra notes on technical issues), and a very broad flow chart diagram of the main logic of the program for my boss to follow.

In the end, all parties were satisfied and we have moved on.


答:
My boss wants a narrated line-by-line English explanation of our code

Tough.

Since he is not a programmer, he can not follow the code, so wants it all translated into English.

If he is not a programmer, he should not be reading the code. At all.

Provide high-level documentation instead.

This isn't a reasonable request, is it?

No.


问:
How do you tackle really bizarre errors that keep you puzzled for more than 10 hours?
You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle?</p>

答: Google it. Stackoverflow it. Post it on forums. Basically if you can't solve it alone, get people to help.</p>


答:
Since I used to teach programming, I would be only too happy to give it a go.

He will quickly find out he's getting more than he bargained for,
which will make me sad because I like explaining things :-)


问:
Are there minimum quality standards for .NET applications?
Does Microsoft require third party .NET applications to meet any minimum standards for things like application security or code quality?</p>

答:
Microsoft itself has common guidance on how secure your code should be.
For starters, there is a Microsoft Security Development Lifecycle (SDL). The MS SDL also contains further guidance to fulfill common compliance such as HIPAA.

Visit Microsoft SDL:
http://www.microsoft.com/security/sdl/default.aspx

Code quality in .NET can be achieved if you meet common guidelines for good codes (taken from Microsoft's best practices):

Secure by default

Secure by design

Secure in deployment

More on this: MS SD3 Video

But the best way to implement these are by practising these into everyday habits of developing software, especially when writing codes.


问:
"positively formulated" vs. "reads as english sentence" style logic
Sorry, I'd be happy to have someone improve the title of this question.

What are the benefits and downsides of "positively formulated" logic vs. having it "english readable". I'm looking for a generic position that can be placed into code guidelines.

Examples of what I see as "positively formulated" logic

```<code>if ($obj->isValid()){

if ($found){

if ($first){
    //do nothing
}else{
    doX();
}

$this->useFields(array('a','b'));
</code>```

Examples of what I see as "negatively formulated" logic

```<code>if (!$first)
    doX();
}

$this->unset(array('d','e','f','g'));
</code>```

Whereas if focusing on "English readable" I would see this as good:

```<code>if (isValid()){

if ($found){
</code>```

and this is not "English readable"

```<code>if ($l){

if (isValid() || !isActive()){
    doX();
}
</code>```

答:
Firstly I would question the benefits of "English readable". Natural languages and English in particular can be vague, ambiguous and misleading to an astounding degree.

How many meanings can a statement like "If x is not red and green" have?

The one profession which is stuck with using English yet requires a high degree of precision - the law - has ended up using a version of English that is unrecognizable to and unreadable by most native English speakers.

You need to assume that whoever is reading your code has a minimal understanding of the program language's syntax and it's common idioms.

Secondly I see no reason while "positively formulated" should be superior to "negatively formulated" in general. The most concise formulation which conveys the intention is the one to use.

So

```<code>if (!$first) {
    doX();
}
</code>```

Is in my opinion better than:-

```<code>if ($first){
    //do nothing
}else{
    doX();
}
</code>```

If you must go down that road then its better to change the condition name and invert the logic:

```<code>if ($subsequent) {
    doX();
}
</code>```

The only thing I would really avoid is the double negative as in

```<code>if (!notValid)
</code>```

Or visual basics unavoidbale:

```<code>if not Obj IsNothing
</code>```

Body:
Firstly I would question the benefits of "English readable". Natural languages and English in particular can be vague, ambiguous and misleading to an astounding degree.

How many meanings can a statement like "If x is not red and green" have?

The one profession which is stuck with using English yet requires a high degree of precision - the law - has ended up using a version of English that is unrecognizable to and unreadable by most native English speakers.

You need to assume that whoever is reading your code has a minimal understanding of the program language's syntax and it's common idioms.

Secondly I see no reason while "positively formulated" should be superior to "negatively formulated" in general. The most concise formulation which conveys the intention is the one to use.

So

if (!$first) {
    doX();
}

Is in my opinion better than:-

if ($first){
    //do nothing
}else{
    doX();
}

If you must go down that road then its better to change the condition name and invert the logic:

if ($subsequent) {
    doX();
}

The only thing I would really avoid is the double negative as in

if (!notValid)

Or visual basics unavoidbale:

if not Obj IsNothing


问:
What is the best way to scale a CQRS system?
In the previous months I have been asking a lot of questions concerning the architecture of an application I'm working on. Thanks to the answers the architectural design has changed - in fact, it has really been simplified as shown in the following graph:

Internally I have a two services (NOT WCF!) that follow CQS principles. It means that the query service simply returns database views; while the command service has a full domain model that contains all business logic, and repositories to access the database (no event mechanism or other complex pattern here). Both services use the same database. These services are class libraries, NO WCF services, because they are used only internally so I don't need the overhead of WCF (don't distribute your objects, Martin Fowler's first law).

These internal operations are used by the ASP.NET MVC site and the PartnerService. This PartnerService is a WCF service, which exposes the functionality I would like to be exposed to partners.

If I ever need to scale because of high traffic, I could add web servers and/or migrate parts to a full CQRS system (my contracts are already designed for it).

Does anyone see any problems with this?

One thing I see is that if the query or command service changes, this impacts both the web site and partner service directly, so I have to deploy the changes to both. But I don't know if this is an issue...?

Any feedback is appreciated! Thanks!

答:
I think you are on to a winner here.

You have several options for scaling (from easiest to requires some effort).

Buy a bigger machine.

Run each component on its own server.

Run more servers for each component (except for the Database)

Replicate the database and service the "visitors" queries from the replication.

Partition the database by "member id" and run several separate instances of the database to service that group of members.

If you need to scale any more then you are "facebook" and can afford a rewrite.

OwnerDisplayName: Lud


答: Although I agree that this is an unreasonable request, your boss may appreciate something like  the output of Docco, which separates your code and line-by-line or clause-by-clause comments into two-column HTML output, with the code on one side and prose on the other. You have to type the comments yourself, of course, but the presentation is rather nice IMHO, even for non-technical readers. See, for instance, a line-by-line commented section of the annotated code for Underscore.js. There are Python and shell script versions as well.</p>


答:
Probably, this request is a good time to learn things like ANTLR. Take ANTLR, take your language's grammar, parse all the code you have, traverse your AST generating template-based descriptions for every node, so i++ is described as increase i by 1 using postfix increment operator. That should be really funny. Your boss may also want this tool to be included to the build script, so every time you make any changes, he'll receive a ~20 MB e-mail describing what the new version does.

P.S. Just kidding, he's an idiot.


问:
How to sell a high SO reputation at an interview
A question with absolutely no relevance to myself:

How would a programmer with a stellar SO reputation (like 30k+) market his or herself to poential employers/investors who have never heard of SO?
In other words, how can one describe SO in a few sentences that will make a high reputation sound impressive at an interview?

答:
Your reputation doesn't make you a guru.  It just means you spend a lot of time here and tend to post helpful stuff.  Particularly in the early days of SO, you could get a massive reputation spike just for posting a funny cartoon or joke.

Your reputation could come with a negative: What if the employer decides that a high reputation means you'll spend all day posting instead of working?


问:
Should development methods squash a developer's individualism?
I'm in my final semester of college and am taking a software engineering course.  In the class we learn about various software development methods. The one we focused on, and used to develop our project, was the waterfall method.

I feel like the instructor may have implemented it wrong. In our class diagrams, we had to list ALL properties and methods including private ones. I have read a few books, namely Clean Code, that say to keep functions as short and focused as possible. It seems tedious to list every little function in our diagrams if they don't help other developers out (they're private, no one else will use them). Plus, I may not think of every tiny function when designing the program, they may come along when refactoring.

Did the instructor tell us wrong by asking us to list every function? And, do these design methods squash the developer's individualism to write code how they can best understand it?

答: Some software engineering classes, such as the one I had, are taught in a weird style where 'failure is success', success is a wasted opportunity to learn from failure, and more is less and less is more. If this is one of those, then just stick with the assignments and enjoy the weirdness.</p>


答:
It's possible that your boss is just uninformed and intimidated, but is actually a reasonable person.  If so, reasoning with him/her might work - a casual conversation where you promise to provide "what he really wants" ie; a prose guide to what the program is doing.

If it comes down to "my way or the highway" better check your gas now.


问:
How much effort goes into maintaining a build system?
In StackExchange Podcast #09 it is remarked:

Another study recently looked at how much effort goes into maintaining the build system: 5 to 30% of all development effort is spent on maintaining the build system.  With the variations being huge even when working on similar projects.

What is the name of the study referenced, and where can it be found? The audio of the podcast contains no further details.

Additionally, does anyone have any links to other studies covering the same topic.

答:
I haven't heard the podcast, but the study is probably a paper from the most recent ICSE, called "An Empirical Study of Build Maintenance Effort" by Shane McIntosh et al. Check the Direct link (or the official DOI page if you want metadata).

Their study focuses mostly on how often source code changes impact the build and how many developers on a team are typically concerned with maintaining the build. I remember that it's an interesting study, but I found the numbers a bit difficult to interpret, as is often the case with empirical studies trying to find connections between things :)


答:
First, ask what the goal here is. Come up with alternate ways to accomplish whatever explanation he has.

Next, provide an estimate of how long this would take, both in terms of how many hours it would take to put together and how long it would take to run through. Ask, in delicately phrased terms, if both your time isn't spent better doing something else instead.

Start by telling him how many thousands of lines of code your app is.

If that fails, as already suggested, provide a sample of what he should expect when you narrate the entire code with him. That should satisfy him.

If he persists, start looking around for a new job.

BTW, this is really a case where the project manager should intervene and explain to the boss that this level of detail is not in everyone's interest.


答:
This isn't an irrational idea, and quite logical. It is her duty to check through the code and see if there is something there to break.

Now it is up to you, as what you can do your best to make it simple. As someone already suggested, making a good design document with simple UML diagrams can be the best way. It is not always necessary to comment line-by-line. As an end user, (or a customer) someone can make a request, now it is up to you, how you full-fill it (making design docs or end user docs or writing comments line by line).

Even in my job, when I joined a new company I was told to do so by my lead. When you are new at a place, you need some time to build your reputation, and at that time such requests come. I fulfilled it, by creating UML diagrams modulewise.


问:
What is the most obscure sorting algorithm you know?
I just read about cyclesort via a sortvis.org blog post.
This is probably the most obscure one I have heard of so far, since it uses maths that I am not familiar with (detecting cycles in permutations of integer sets).

What is the most obscure one you know?

答:
Dont remember the name, but it was basically</p>

```<code>while Array not sorted

  rearrange the array in a random order
</code>```

Body:
Dont remember the name, but it was basically

while Array not sorted

  rearrange the array in a random order


答:
Making line by line explanation will definitely increase your coding file size, this is the reason for introducing documentation separately.

Anyway, if he wants much more very detailed line by line explanation, then just attach the documentation of the programming language in which you used to code and ask him to refer from that (for example, if you are coding in Java then refer to JavaTM 2 Platform, Standard Edition, v 1.4.2 API Specification ).

Definitely this will work. :-)


答:
Shell sort

Maybe the algorithm itself isn't that obscure, but who can name an implementation that's actually used in practice?  I can!

TIGCC (a GCC-based compiler for TI-89/92/V200 graphing calculators) uses Shell sort for the qsort implementation in its standard library:

```<code>__ATTR_LIB_C__ void qsort(void *list, short num_items, short size, compare_t cmp_func)
{
  unsigned short gap,byte_gap,i,j;
  char *p,*a,*b,temp;
  for (gap=((unsigned short)num_items)>>1; gap>0; gap>>=1)    // Yes, this is not a quicksort,
    {                                                         // but works fast enough...
      byte_gap=gap*(unsigned short)size;
      for(i=byte_gap; i<((unsigned short)num_items)*(unsigned short)size; i+=size)
        for(p=(char*)list+i-byte_gap; p>=(char*)list; p-= byte_gap)
          {
            a=p; b=p+byte_gap;
            if(cmp_func(a,b)<=0) break;
            for(j=size;j;j--)
              temp=*a, *a++=*b, *b++=temp;
          }
    }
}
</code>```

Shell sort was chosen in favor of quicksort to keep code size low.  Although it's asymptotic complexity is worse, the TI-89 doesn't have a whole lot of RAM (190K, minus the program size and the total size of any unarchived variables), so it is somewhat safe to assume that the number of items will be low.

A faster implementation was written after I complained about it being too slow in a program I was writing.  It uses better gap sizes, along with assembly optimizations.  It can be found here: qsort.c

Title: What is the most obscure sorting algorithm you know?

Body:
I just read about cyclesort via a sortvis.org blog post.
This is probably the most obscure one I have heard of so far, since it uses maths that I am not familiar with (detecting cycles in permutations of integer sets).

What is the most obscure one you know?

Body:
Shell sort

Maybe the algorithm itself isn't that obscure, but who can name an implementation that's actually used in practice?  I can!

TIGCC (a GCC-based compiler for TI-89/92/V200 graphing calculators) uses Shell sort for the qsort implementation in its standard library:

__ATTR_LIB_C__ void qsort(void *list, short num_items, short size, compare_t cmp_func)
{
  unsigned short gap,byte_gap,i,j;
  char *p,*a,*b,temp;
  for (gap=((unsigned short)num_items)>>1; gap>0; gap>>=1)    // Yes, this is not a quicksort,
    {                                                         // but works fast enough...
      byte_gap=gap*(unsigned short)size;
      for(i=byte_gap; i<((unsigned short)num_items)*(unsigned short)size; i+=size)
        for(p=(char*)list+i-byte_gap; p>=(char*)list; p-= byte_gap)
          {
            a=p; b=p+byte_gap;
            if(cmp_func(a,b)<=0) break;
            for(j=size;j;j--)
              temp=*a, *a++=*b, *b++=temp;
          }
    }
}

Shell sort was chosen in favor of quicksort to keep code size low.  Although it's asymptotic complexity is worse, the TI-89 doesn't have a whole lot of RAM (190K, minus the program size and the total size of any unarchived variables), so it is somewhat safe to assume that the number of items will be low.

A faster implementation was written after I complained about it being too slow in a program I was writing.  It uses better gap sizes, along with assembly optimizations.  It can be found here: qsort.c


答:
Sleep Sort is rather novel.

```<code>    #!/bin/bash
    function f() {
        sleep "$1"
        echo "$1"
    }
    while [ -n "$1" ]
    do
        f "$1" &
        shift
    done
    wait
</code>```

example usage:

```<code>    ./sleepsort.bash 5 3 6 3 6 3 1 4 7
</code>```

Body:
Sleep Sort is rather novel.

    #!/bin/bash
    function f() {
        sleep "$1"
        echo "$1"
    }
    while [ -n "$1" ]
    do
        f "$1" &
        shift
    done
    wait

example usage:

    ./sleepsort.bash 5 3 6 3 6 3 1 4 7


答:
Google Code Jam had a problem about an algorithm called Gorosort, which I think they invented for the problem.

Goro has 4 arms. Goro is very strong. You don't mess with Goro. Goro needs to sort an array of N different integers. Algorithms are not Goro's strength; strength is Goro's strength. Goro's plan is to use the fingers on two of his hands to hold down several elements of the array and hit the table with his third and fourth fists as hard as possible. This will make the unsecured elements of the array fly up into the air, get shuffled randomly, and fall back down into the empty array locations.

http://code.google.com/codejam/contest/dashboard?c=975485#s=p3


答: I don't know if it's the most obscure, but spaghetti sort is one of the best in situations where you can use it.</p>


答: One of the original Knuth books, "Sorting and Searching", had a middle fold-out that diagrammed a process which sorted a tape file using no hard disk. I think it used six tape drives, and explicitly showed when each was being read forward, read backwards, rewinding, or idle. Today it is a monument to an obsolete technology.</p>


问:
Is Java instanceof operator considered reflection, and what defines reflection?
I had a discussion with a coworker today, whether usage of using the Java operator instanceof is a kind of reflection. And the discussion quickly evolved into what actually defines reflection.

So, what is the definition of reflection?

And is the usage of instanceof considered "using reflection" ?

And in addition, if instanceof is considered reflection, then is polymorphism not also "using reflection"? If not, what is the difference?

答:
This is the definition of reflection according to wikipedia:

In computer science, reflection is the process by which a computer
  program can observe (do type introspection) and modify its own
  structure and behavior at runtime.

I couldn't have said it better myself and highlighted the important part for your question. That said, yes, instanceof is considered using reflection. The program observes its structure and conducts type introspection.


答:
You might be interesting in the following article: http://java.sun.com/developer/technicalArticles/ALT/Reflection/

The key in this article is a code snippet where they simulate the "instanceof" keyword by using the "isInstance" method of the "Class" class, which is part of the reflection feature of Java.

Title: Is Java instanceof operator considered reflection, and what defines reflection?

Body:
I had a discussion with a coworker today, whether usage of using the Java operator instanceof is a kind of reflection. And the discussion quickly evolved into what actually defines reflection.

So, what is the definition of reflection?

And is the usage of instanceof considered "using reflection" ?

And in addition, if instanceof is considered reflection, then is polymorphism not also "using reflection"? If not, what is the difference?


答:
For the sake of clarity, I would consider two answers.

Theoretically, instanceof is a form of reflection, as explained in Falcon's answer.

In computer science, reflection is the process by which a computer
  program can observe (do type introspection) and modify its own
  structure and behavior at runtime.

However, practically, when a programmer talks about using reflection he usually refers to much more than just checking whether a variable is of a certain type. This is such a rudimentary concept, without which, polymorphism wouldn't be possible.

Do note that using instanceof often indicates a code smell, and proper polymorphism can often be used instead.


答: Code IS English already, 'for', 'if', 'else', etc. Just do a search and replace for certain characters. For example, replace '>' with 'greater than'.


答:
It would be very nice if we had a translator "Language X to English" that does this. Then one could grin and say, no problem, boss, you'll have that in a minute. And then comes a mail with some megabytes of text that reads:

Let a be a new integer array with 20 elements.

Let x be a variable to store integers.

Set x to 0

While x is smaller than 20 do what is prescribed in the next 2 lines

set the array element of a with the index x to the result of calling nThPrime with the argument x+1

increase x by 1

....

Another option would be to suggest programming in Shakespeare henceforth.


问:
Question about raw Javascript vs frameworks in interviews
If it's wiser to know a framework such as jQuery, MooTools, DoJo, etc. to get over cross-browser issues, why are interviews asking for only javascript?</p>

答:
Because if you know "real" Javascript, then it doesn't matter if you know jQuery but not MooTools, DoJo but not Closure, etc. If you know "real" Javascript, you should be able to pick up any particular Javascript library with relative ease.

It's (often) better to use a library that helps with the cross-browser issues, but you can't know the library without knowing the language. If you don't know "Javascript" and all you can do is cut'n'paste samples from a particular library, then you can't really put "Javascript" as a language on your resume anyway, IMO.


答:
Because frameworks are changing more often than language features. If you are a good javascripter, it is more likely than he could be able to learn relatively quicker any framework. And without really deep knowledge of "just js", understanding the core functionality of any big library is hard. </p>

<p>It always better to know what is going on behind the scenes. Besides, knowledge of the language itself helps you to distinct good architectural from bad ones. </p>

Title: Question about raw Javascript vs frameworks in interviews

Body: If it's wiser to know a framework such as jQuery, MooTools, DoJo, etc. to get over cross-browser issues, why are interviews asking for only javascript?</p>

Body:
Because frameworks are changing more often than language features. If you are a good javascripter, it is more likely than he could be able to learn relatively quicker any framework. And without really deep knowledge of "just js", understanding the core functionality of any big library is hard.

It always better to know what is going on behind the scenes. Besides, knowledge of the language itself helps you to distinct good architectural from bad ones.


答:
A framework is a level of abstraction above javascript. </p>

<p>If you dont know a framework but do know javascript its a matter of a few hours to learn the specifics. You cant use a framework properly without knowing javascript. </p>

Body:
A framework is a level of abstraction above javascript.

If you dont know a framework but do know javascript its a matter of a few hours to learn the specifics. You cant use a framework properly without knowing javascript.


答: It is easier to evaluate a person's skill/knowledge by examining their coding style within a finite set of language features - such as JavaScript. The object of the exercise is not to create code that works well accross different platforms, but to examine the candidate - in this case, you.</p>


答:
Write down the problem.

Think hard.

Implement the solution.

Title: How do you tackle really bizarre errors that keep you puzzled for more than 10 hours?

Body: You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle?</p>


答: It's a very unreasonable request. You're hired to write code and program, and any documentation you write is supposed to help other developers or programmers working on the same project - not your boss or employee.</p>


答:
Don't let this fact stop you from learning commonly used frameworks though.
Knowing JavaScript alone may not be always sufficient.</p>


问:
Copyleft Licenses - Need to attribute?
I'm currently evaluating which license to use for my next OS project, and things are getting more and more interesting after I decided that I really want to understand what the licenses mean.

Up until now, I just licensed everything under MIT because I like the MIT and their license is nice and short. And probably because it didn't really matter as only a hand full of people actually used my products.

But now, I'm at the brink of releasing something that will surely be used by many people and also be subject to major modifications, so I want to choose the right license to go with.

From what I understand, there are two groups of licenses; Copyright and Copyleft. Now, I read (and think to understand) MIT and BSD-2/3-Clause, but I'm really having trouble to get the gist of (L)GPL and alike.

My main problem is; I want to always be named in derivative works of my project. I don't really care if it's used proprietary or free, I just want to make sure that anyone who reads the code sees "ah, that's the original author" (referring to me).

Is there a clause in the copyleft licenses that assures this attribution? Or can this only be done using permissive copyright ones?

答:
You need to remember the different between copyright and the license. If you write the code, you can always be named in the source files as the copyright holder, regardless of the license. If that is your only requirement, any license will do, it's choice has no bearing on that requirement.

The only slight clarification is that some licenses, like the BSD, forbid removal of the copyright sections. You might use that since it does state your requirement explicitly.

The thing with the GPL, is only use it because you understand the ethics of free software. Using the GPL is an ethical statement, rather than a means to make your software more popular.

Edit: The GPL is not an "open source" license, there's an important difference between open and free, it's not mere semantics. Preventing inclusion in a larger proprietary piece of software isn't primarily intended as a tool for competitive advantage, it's intended as a means to stop the proprietary software using the GPL software and not affording the freedoms that the GPL provides.

Title: Copyleft Licenses - Need to attribute?


答:
Um ...

Did you build your code from a specification?
Was the requirement correctly documented?

If he's a half decent manager he should be asking "Does this meet the requirements?"

If you said yes to the above ... give him those docs + the stuff you already mentioned, if he still wants more he's an idiot and clearly should not be managing a dev team.

And before that dumbass comes back with "well what do we know" ... i'm betting there's at least 50 years of combined experience in this thread alone.

Role of a manager:
  1. Identify and assign objectives.
  2. Ensure they are correctly carried out.
  3. Don't ask dumb questions that should already be answered.

Frankly if you have a solution already built he should know what's been written.
If he has no idea what you're doing then I'm guessing smoeone above him has demanded details of what his team are up to.

You could be really smart and link back your solution to the business plan and show where you are meeting the core objectives of the business then pass on the details to his line manager stating that your own manager does not seem capable of understanding you.

You'll probably get his job.

I have been specifically asked to give line by line (or as appropriate
  - e.g. image by image etc.) explanation/commentary which my boss wants
  to be able to read and follow.

Give him a flow chart lol ...

Either that or he's asking for user documentation?


问:
Writing documentation for well understood methods like equals in Java
Is it a good practice to write comments for widely known methods like equals, compareTo etc?

Consider the below code.

```<code> /**
 * This method compares the equality of the current object
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }
</code>```

My company madates to enter comments like the above.Is the above Javadoc comment required?
Is it not obvious and well understood what the equals method and the likes (compare,compareTo) etc does?

What are your suggestions?

答: In my opinion, and I think this may be controversial, you should indicate in the comment in which class you've overridden the class. Then six months down the line when you wonder whether it's implemented or not you'll be able to see without opening the class up.</p>


答:
JavaDoc already supports the inheriting of comments. According to the documentation, "constructors, fields and nested classes do not inherit doc comments", but methods such as equals() will. Since the Object class has a well-documented equals() method, you should just be able to inherit that documentation without a problem.

The documentation for the method needs to come from somewhere so that it is accessible in your IDE and in the generated web documentation. Explicitly rewriting accurate and comprehensive comments that exist in a superclass is not necessary, and I would argue clutters the code files.

If this is corporate policy, then you have two options. You can go along with it sliently, and deal with the extra effort of writing and maintaining documentation (often in violation of the DRY principle, which can also be applied to documents as well as code). The other option would be to seek company policy - explain why this policy isn't a good idea and the benefits of changing it (in terms of time, money, effort, quality - things that management understands).

Title: Writing documentation for well understood methods like equals in Java

Body:
Is it a good practice to write comments for widely known methods like equals, compareTo etc?

Consider the below code.

```<code> /**
 * This method compares the equality of the current object
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }
</code>```

My company madates to enter comments like the above.Is the above Javadoc comment required?
Is it not obvious and well understood what the equals method and the likes (compare,compareTo) etc does?

What are your suggestions?


答:
Our coding standard dictates that when overriding a method it is not necessary to document it unless, in overriding it, the documentation in the parent class or interface is no longer accurate and comprehensive for the sub- or implementing-class.

For equals, we might want to note that the comparison is only done on a primary key when comparing a database backed entity as that is not entirely consistent with the documentation for Object.equals().


问:
Alternative for Access+SQL Server for enterprise projects
We're a small software company, developing projects for manufacturing facilities about analysis, traceability, reporting etc. We're using Access for front end, SQL Server for back end. We've quite big customers too and our company is growing. So far it is working fine but I wonder should we move to more influential technologies, such as web based solutions. What do you think about the future of Access?</p>

答:
Enterprises care about solutions that work, are usable, can scale to their needs, and that the company behind them are responsive to change and can support the product.

General programming languages like C# or Java tend to get picked because they are assumed to be more flexible, but if you already have a solution in Access, it suggests to me that Access is a fine solution.

Here are some things I would consider:

Is the Access code maintainable?

Do you use source control?

How will you handle any customizations they might need?

Can you hire people to maintain it?

There are good and bad C#/Java solutions, and there are also good and bad Access solutions. Personally speaking, I think more of the CRUD/reporting apps we write with WPF/WinForms/Silverlight should be built with Access.

If you are confident your Access solution will meet the needs of your customers, don't let technical biases peer pressure you into rebuilding something that works.

What you may want to consider is how your product will change to meet enterprise demands. Instead of forms and data, would you like to build more intuitive and task-based user interfaces? If there are features you'd like to add that would be difficult or impossible to do in Access, then that may justify a switch.

(I say this as a WPF/ASP.NET programmer by day)


问:
How can I use Scrum with a freelance team?
I'm working in a start-up. I have a background with teamwork and management, but I'm currently the only developer. We have a project that will involve a few developers in the form of 2 freelancers. I will function as a developer as well as the ScrumMaster. The project is scheduled to last three to four months. The 3 developers (myself and the two freelancers) have never worked together before.

Would it be possible or advisable to use Scrum to manage this type of project? Would there be any problems organizing or running the team using Scrum?

答:
Since you will be the scrummaster then I believe the answer to "is it possible to organize..." is really one best answered by you; you know your personality, management and organizational skills better than we do. Any methodology is do-able given sufficient understanding and commitment from all parties (that's often the hard part - does everyone in this startup understand what "Agile" and Scrum mean; short iterations with partial functionality added at each and lots of customer feedback?).

Also to be considered is this - is everyone involved already experienced with Scrum? If not, and especially if there is an appreciable amount of skepticism or animosity toward Agile/Scrum, perhaps a 3-month project is too short a window to be a)gelling as a team, b)getting the "real work" done, and c)learning a new methodology.

No matter what methodology you choose, Team relationships are an excellent place to start, btw.


问:
What to do when the programming activity becomes a problem?
I once saw a program (can't remember which) where it talked about people "experiencing flow" when they are doing something they are passionate about. When "in flow", they tend to lose track of time and surrounding, concentrating only on their activity at hand.

This happens a lot for me when I program; most particularly when I face a problem. I refuse to give up until it's solved. This usually leads to hours just rushing by and I forget to eat lunch, dinner gets pushed into far into the evening, and when I finally look at the clock, it's way into the wee-hours of the night and I will only get a few hours of sleep before having to rise early in the morning. (This is not to say that I'm in flow only when facing a problem - but I find it particularly hard to stop programming and step back when there's something I can't solve immediately.)

I love programming, but I hate it when it disrupts my normal routines (most importantly eating and sleeping patterns). And sitting still for so many hours, staring a screen, is not healthy.

Please, any ideas on how I can get my rampant programming activity under control?

答:
[I already have an answer to this question, which got roundly ignored point-wise. So I only stand to be ignored again...]

I've been thinking about this question today while I'm coding. For me, one the biggest reasons I don't want to put something down is that the transition costs are too high. I've got 5 terminal windows open, two or three servers open, etc., and plus I know what I'm doing.

To handle the terminal windows being open etc., I just sleep my machine, and most of the states are maintained. But as to knowing where you are and what you're doing...

One of the ways that MIGHT help you to stop when you're in-the-middle-of-something is to document where-you-are as-you-go. I pretty much do this now anyway, otherwise my ADD takes over: I always write the next 4 or 5 mini-tasks that I need to do, plus ANYTHING that I'm keeping in my short- or medium-term memory. This way, picking up the task the next day is easier.

So, by lowering the costs of stopping and restarting, you may be more motivated to stop. Or not, and this answer is off-base as well :)


问:
What factors should I be looking at to increase performance in image resizing?
I'm setting up a web app in which people will upload images. Once uploaded the images will be watermarked then resized multiple times (Thumbnails, different sizes etc.) and finally uploaded to Amazon S3 for storage.

The web app is written in Python with the Tornado framework, I don't really want to lock up the Tornado threads with the image processing so I'm going to send it out to a seperate script (and possibly even seperate servers) using Gearman (I've developed an async-gearman client for Python/Tornado).

One of the advantages of Gearman is that it's possible to launch jobs in multiple languages, so the actual processing and uploading of the image could be done in ether Python, Ruby, PHP, Perl, Java, C, or something else.

This leaves the question, is one better for the job? Are there certain libraries only available for specific languages that are especially good at image resizing? The most important thing will be performance: we'd like to be able to run as many jobs on a server as possible. Are there other factors I should be looking at?

I'd prefer to stick with Python, Ruby, or PHP because that's what I'm familiar with but if the performance gain from doing it in Java/C is good enough I'd be okay with implementing it like that.

I'm not looking for code examples, I can find those myself, but I'd like to know if there are any big differences between the image processing libraries. I know PHP probably has the easiest to use wit GD, and I've used a couple of the Python libraries before and they seem okay. I've never done anything with images in Ruby.

答:
I think there are many libraries in many languages to do this, and they all work pretty well.

What you probably should be looking for though is just an image processor for the platform you host your application on.  This will be the most efficient and most supported method.

ImageMagick is just one of many examples.  Many third party hosting companies have this already installed and available for applications as well.

OwnerDisplayName: samarudge


答:
I think I'd appreciate hearing that an interviewee understands that jQuery selectors are a vast improvement over getElementByName. That way they know there IS something underlying the framework, and they know enough about it to drop a function name.

That's really all I need to hear about their understanding of "raw javascript". God help me, I'd love to never code "raw javascript" ever again.

I know how to put gas in the car. I don't need to know how to refine dead dinosaurs into gas.

Yes I did just call raw javascript a dead dinosaur.


答:
In my team we usually use the @inheritDoc annotation for equals() and hashcode() but I wish we did not.

For these two methods I always have to look at the implementation. Since you are overriding a method, that means you want it to do something different. I think this deserves its own documentation.

It is good to at least document what attributes participate in the method and even maybe why that is.


答:
You need to step back. My motto is 'if the problem is too hard then you are solving the wrong problem'. What are your assumptions? don't trust anything.

The corollary to that is 'the weirder the problem, the weirder the solution'. The computer's strength is its logic so you can't win on logic. You have a brain and have to out-think it.

In modern times there are so many other things interacting on a system - firewalls, AV, Antispyware, automatic updates happening every night - you have to deal with moving targets.


问:
Should you refactor existing code that is not broken in a project focused on new features?
Given a small project that aims to add new functionality to application, the changes introduced touch some existing code, involving updating these in certain areas. During implementation, I've found some of these code which were updated have candidates for refactoring.

Is this an appropriate time to refactor which in turn would require regression testing for those components affected (thus possibly introducing scope not originally part of the project)? Or should I defer, complete the functionality and perhaps have a separate project for refactoring (although I'm a bit hesitant as business users might not fully sponsor a project that does not add any functionality, unless they value code maintainability...)?

答:
Absolutely.

Refactoring should be done on a working and "passing" project. When all your tests (at the unit, system, and acceptance levels) pass, you know that your product meets requirements. When you refactor, you can continue to confirm that all tests continue to pass. If any test begins to fail, then you did something wrong and need to correct it. If you have failing tests, you should correct those before refactoring so you can always ensure your refactoring isn't changing the functionality of the system.

This is also a perfect time for refactoring, assuming you have the time and resources to carry out the refactoring and still deliver on time and budget. Refactoring now will make it easier to understand and maintain your system, so as you add even more new features, it becomes easier. You need to fight against code rot and software entropy.

As Joel Etherton points out in the comments, you need to manage the scope of refactoring. Focus on refactoring the parts of the system that you will soon be adding features to, performing refactorings that will make it easier to work with or add the new features. The use of static analysis, metrics tools, and code reviews can help you identify areas that are most critical. You don't want to miss deadlines because you were refactoring - you still need to continue to add value to the customer.

You mention the customer not seeing value in refactoring. Typically, the customer doesn't care about the quality of the code, but of the product. Refactoring will make it easier for you to maintain a high product quality and keep delivering a product that meets the changing needs of the customer. Try to negotiate time to refactoring into your schedule (customer wants X features in Y days, try to see if you can't get Y+Z days or X-N features so you can spend time on design, refactoring, and implementation), if you can.


答:
Refactor soon, refactor often.

If you can afford it (time, money, etc.) you should do it.

I say this because sometimes you may run out of time, or like you say not getting money for a code maintenance intervent, or you want to complete your project as soon as possible, and more in general because refactoring needs resources. But apart from that it's always a good time for refactoring.

You want an up-to-date code, and if you feel that your code actually needs some changes, especially when adding new functionalities, then you should change it.

Don't forget with a version control system you can actually fork your project into a new branch, so you won't affect your current code at all.

Title: Should you refactor existing code that is not broken in a project focused on new features?

Body:
Given a small project that aims to add new functionality to application, the changes introduced touch some existing code, involving updating these in certain areas. During implementation, I've found some of these code which were updated have candidates for refactoring.

Is this an appropriate time to refactor which in turn would require regression testing for those components affected (thus possibly introducing scope not originally part of the project)? Or should I defer, complete the functionality and perhaps have a separate project for refactoring (although I'm a bit hesitant as business users might not fully sponsor a project that does not add any functionality, unless they value code maintainability...)?


答:
Remember that comments help developers of all sort if they are correct.

The problem is that they are sometimes incomplete and not accurate.

To be honest comparing 2 objects may be tricky (e.g. comparing 2 invoice objects), also your method may evolve with time and would then need to be commented.

Showing the method objective, rules, etc. in a "useful and meaningful" comment is a good thing.


答: It sounds like refactoring the code will make it easier to add the new features; that's the theory. Include this in the scope of the new features. You're more likely to get buy-in from business users this way. In this case, you should be able to make a compeling arguement and justify the time for refactoring. Hopefully they'll understand that this is a necessary part of the development process and will have fewer objections. You may not always be able to demonstrate this direct benefit.</p>


答:
If you know JavaScript, you will be able to build your own library with your own functionalities, often needed in working environments for proprietary tools.

I once found a bug in jQuery and had to patch it myself, because I couldn't wait for them to release a patch. I was able to do it easily because I know JavaScript.

Being a good coder in JavaScript means you know many concepts such as closures, prototyping and other good features this powerful language offers, and that you may end up not using/understand when relying on a "write less, do more" library.

Then, even if you will use one of those libraries or frameworks, you will ultimately understand when it's best to use their functionalities and when it's best not to. Because they offers many good functionalities by writing little code, but it's really easy to overuse them, and create poor and sloppy code, while with plain JS would've been much faster.


答:
If the refactoring is needed to implement the new functionality then it should be done and factored in as part of the new development.

Having duplicated code will cost you (both you personally and the company) more in the long run as edits get made to one place and not another.

You do need to have a set of tests - either automated unit tests or regression tests that you can run that prove that you haven't introduced problems to the existing functionality.

If the refactoring is just a "nice to do" - i.e. it's not in code directly affected by the new functionality then I'd leave it alone. You are introducing a change for the sake of change.


问:
My boss wants a narrated line-by-line English explanation of our code
I have been specifically asked to give line by line (or as appropriate - for example, image by image, etc.) explanation or commentary which my boss wants to be able to read and follow.

Since he is not a programmer, he can not follow the code so wants it all translated into English.

Has anyone been asked to do this before?

I have commented on all of the source code and used JSDoc to generate full documentation of all functions, variables, etc... and included an implementation example, and full working demos with comments throughout.

Is there anything else I can do to comment the code for non-programmers?

This isn't a reasonable request, is it?

UPDATE

In the end, I managed to explain why it was not a good use of time to do what he was asking. He is a reasonable guy, and just did not have an understanding of what my job involves. Once he saw this post, I think he quickly understood that it was not a normal request.

I did provide documentation that is suitable for another programmer to follow (JSDoc and inline comments - as well as some extra notes on technical issues), and a very broad flow chart diagram of the main logic of the program for my boss to follow.

In the end, all parties were satisfied and we have moved on.

答:
When you refer to your 'Boss' is this "a middle manager in charge of you/your team"? or The Owner of your Company? Are you paid "by the hour" or "on a salary"?

IF your boss is a middle tier manager who is accountable, TALK TO HIS BOSS, point out that to meet your boss' requirement your productivity to the company will be cut to 1/3 of what it could be.

IF your boss is "the guy who signs the checks" explain to him the same thing, just more diplomatically. Your job has gone from "Write the code" to "Write the code, write the explanation of the code, explain the explanation."


答:
Consider answering the quesitons below, then it would be easy for you to do the decision. The wisdom "don't fix it if it is not broken" is tempting but not always true for professional work.

0-Is there a customer complaint about this code?

1-Is this necessary for the functionality of the application

2-Is the current code harmful?

3-Is the cost of change worth it?

4-Could you afford the cost?

5-Is this the best utilization of your skills to the organization

6-Would your changes require your user to re-install the new change - Could you justify that to the customer?

7-Could you tolerate the risk of a bad fix?

8-Does the change affect other code outside your project?

9-Is this an evolving product or a stable product? If it is evolving could you include the changes with the next release?


答:
Applications written with Access and especially Excel tend to pop up in organizations whenever very specific business problems need to be solved quickly and in an ad-hoc manner with zero to minimal support from professional developers. These are GOOD and POWERFUL tools and this is a perfectly valid way to use them.

The problems start when requirements and problems become more complex and the existing ad-hoc systems based on Access or Excel can no longer keep up either because no one is maintaining them or the scale is just getting too large to handle.

I don't think your organization has these problems. Why? Because you probably have people dedicated to the development and maintenance of this product who presumably have strong control of the application and the way it scales. In the right hands and in the right context, Access is perfectly capable.

I think the real problem is finding people to develop/maintain this application in the long term. Access is just not as attractive/glamorous as other technologies. That alone could be enough to at least consider migrating to other application platforms.

Title: Alternative for Access+SQL Server for enterprise projects

Body: We're a small software company, developing projects for manufacturing facilities about analysis, traceability, reporting etc. We're using Access for front end, SQL Server for back end. We've quite big customers too and our company is growing. So far it is working fine but I wonder should we move to more influential technologies, such as web based solutions. What do you think about the future of Access?</p>


问:
When conducting a code review, should the focus be on the completeness of the requirement?
Given that the reviewer is not part of the project, but was assigned to review because he has done some coding for the application being updated/enhanced.

Is it the reviewer's job to ensure that the requirement is complete and correct? Or is this the QA and business tester's responsibility?

If the developer and the reviewer misses a requirement which is discovered in UAT, is the reviewer also at fault (probably to a lesser degree)?

答:
It obviously depends on your code review process but personally I'd say the functional completeness of the requirement is more within the remit of the QA / Test team than the code reviewer.

That's not to say that a code reviewer shouldn't be able to pick up on problems with the functionality where they find them (assuming they have the knowledge to identify them), just that it's not their primary aim.

I'd generally see code review as looking to uncover coding errors and inefficiencies, vulnerabilities, memory leaks,  that is not checking that what has been implemented is correct against the specification, but that it is "correct" within itself.

If you do want to extend it beyond this to include more of a functional review, you need to accept that that's going to have an impact on the time you need commit to it. If you want the reviewer to be fully familiar with the functional requirements and to be checking them as well, then you obviously need to allow a lot more time for reading and understanding the requirements and checking the code against them.

But it shouldn't be seen as a substitute for proper QA and testing, at most this would be an additional layer.

Broadly speaking:

Code review - is the code which has been produced efficient, secure
and robust

QA - does it do what is outline in the specification

UAT - does the finished application actually work within the business


答:
If the reviewer spots any problem he should definitely mention them (especially if he is the SME).

But when I receive code that needs to be reviewed I am concentrating at the function level. I see my primary job as reviewer is to make sure the code is readable and maintainable in the future (if I spot bugs I will point them out but I am not going to write unit tests (though if I spot missing unit tests I will point that out)).

Maintainability covers a lot of ground. Some of the things I look for are: style (though anything I point out in style are suggestions and I don't require them to be fixed). Obvious errors or coding styles that can cause problems or that will make the code hard to extend. Algorithms that are very efficient (and there is a simple know better one). Anything that is not trivial self documenting that does not have a description of what the goal of the code is.

It is the job of tests and QA to make sure it does a sufficient job.

Title: When conducting a code review, should the focus be on the completeness of the requirement?

Body:
Given that the reviewer is not part of the project, but was assigned to review because he has done some coding for the application being updated/enhanced.

Is it the reviewer's job to ensure that the requirement is complete and correct? Or is this the QA and business tester's responsibility?

If the developer and the reviewer misses a requirement which is discovered in UAT, is the reviewer also at fault (probably to a lesser degree)?


答:
What you look for in a code review depends what you hope to accomplish it and what type of code review you are conducting. Some code reviews focus on security and looking for vulnerabilities, others look at style and conformance to coding guidelines, while others are just a sanity check for the code. Typically, the reviewer is told (either per guidelines or in the form of a checklist) what kinds of problems the code review is looking for, so their attention can be focused on critical sections.

If you are concerned about high quality, you probably want to introduce reviews at each phase. Requirements reviews can be used to ensure completeness and understandability of requirements. Design reviews are used to ensure that all requirements are addressed by the architecture and design of the system. Code reviews can be used to ensure that the code matches the design and doesn't contain errors before testing, as well as to review the strength of test cases.

When it comes to ensuring that requirements are properly implemented, it's everyone's responsibility, from the requirements engineer to document it to the architect and developers to understand it, design for it, and implement it to the testers who write test cases and test procedures. If anyone identifies an ambiguity, conflicting requirements, or some aspect of the system that doesn't meet a specified requirement, that individual needs to document it and somehow report it (usually by reporting a defect in your bug tracker).


答:
It all comes down to what YOU want him to do. But generally speaking, I think of code review as a very specific function. He is there to check for the code. Make sure the code is up to standards and optimally written. If you make your code reviewer do the same thing your Q&A people will do, then you'll be doing double the work for double the time, and the same results. Which is often unnecessary.

This becomes more critical when you have several projects. You can't have 1 reviewer spend too much time on any one project, because Q&A is waiting to test it and you delay the entire process.

Which is why functions need to be clearly defined, as to not duplicate work.


问:
Idea for a domain specific language or DLR port?
I have my undergraduate final year project coming up and am very interested in lexers, parsers, compilers and so on. I would like to use the DLR (.NET 4.0 dynamic language runtime) for my undergraduate final year project, but am struggling to find a reason to use it!

A domain specific language would be an idea, but most of the domains I can think of have already been done. A possibility was a primarily semantic web focused triple store query language similar to SPARQL, but the domain is rather complicated and the query engine would take quite a while to write and optimise.

I am also thinking about different programming paradigms, particularly higher level ones such as array/collection programming languages rather than scalar. A language which is less specific in terms of the domain, but with which it is 'easier to process X, which is commonly used or dealt with in situation Y' would be interesting.

Another approach would be to attempt to port an existing language (or at least part of it, time permitting) to the DLR. Preferably not APL or Perl - I'm not a masochist. Edit: To clarify, by 'Port' I mean host an existing language on the DLR, such as IronJS, IronPython, IronRuby, etc.

Does anyone have any ideas for a domain specific language, preferably but not necessarily suitable for the DLR?

答: The Lisp/Scheme family of languages are very nice to play with in terms of parsing, compilation, interpretation, etc...</p>


问:
Would a language which doesn't allow comments yield more readable code?
Just out of curiosity, I started wondering whether a language which doesn't allow comments would yield more readable code as you would have be forced to write self-commenting code.

Then again, you could write just as bad code as before because you just don't care. But what's your opinion?

答:
Code can certainly be self-commenting in explaining what it is doing, but it is not always possible for code to explain why it is doing it. That is where comments are most needed.

If, for example, a section of code is needed to comply with a specific regulation, how do you explain that without a comment? If the algorithm used by a particular piece of code is described in a paper written in 1998 by M. Matsumoto and T. Nishimura, how do you explain that without a comment? If an algorithm doesn't provide exactly the optimum functionality but makes a very specific justified compromise that may cause future issues if other code is changed, how do you explain that without a comment?

What if one section of code was audited by an independent auditor so it cannot be modified without invalidating that audit and the code is used to build a product whose compliance with that audit is required by your customers. How do you indicate that without a comment?


答:
Not sure what a DLR port is (so can't help there)...

But I always thought that a drum machine would make a fun domain specific language - perhaps just for the snare drum for a marching band.

The reason is that drum rudiments can often be more conveniently spoken in words (with specific names) rather than written down on sheet music.

So for example, a mini-language that went something like as follows would be fun,

```<code>bar bar1 : flam tap for 2 beats, quater rest, 9-stroke roll.
bar bar2 : swiss army triplet for 4 beats.
rythm r1 : (bar1, bar2) repeat 10 at 130 beats per minute.
save r1 as "my_beat.wav".
</code>```

or what have you.

Scope to make it as easy or difficult as you like....

Title: Idea for a domain specific language or DLR port?

Body:
I have my undergraduate final year project coming up and am very interested in lexers, parsers, compilers and so on. I would like to use the DLR (.NET 4.0 dynamic language runtime) for my undergraduate final year project, but am struggling to find a reason to use it!

A domain specific language would be an idea, but most of the domains I can think of have already been done. A possibility was a primarily semantic web focused triple store query language similar to SPARQL, but the domain is rather complicated and the query engine would take quite a while to write and optimise.

I am also thinking about different programming paradigms, particularly higher level ones such as array/collection programming languages rather than scalar. A language which is less specific in terms of the domain, but with which it is 'easier to process X, which is commonly used or dealt with in situation Y' would be interesting.

Another approach would be to attempt to port an existing language (or at least part of it, time permitting) to the DLR. Preferably not APL or Perl - I'm not a masochist. Edit: To clarify, by 'Port' I mean host an existing language on the DLR, such as IronJS, IronPython, IronRuby, etc.

Does anyone have any ideas for a domain specific language, preferably but not necessarily suitable for the DLR?

Body:
Not sure what a DLR port is (so can't help there)...

But I always thought that a drum machine would make a fun domain specific language - perhaps just for the snare drum for a marching band.

The reason is that drum rudiments can often be more conveniently spoken in words (with specific names) rather than written down on sheet music.

So for example, a mini-language that went something like as follows would be fun,

bar bar1 : flam tap for 2 beats, quater rest, 9-stroke roll.
bar bar2 : swiss army triplet for 4 beats.
rythm r1 : (bar1, bar2) repeat 10 at 130 beats per minute.
save r1 as "my_beat.wav".

or what have you.

Scope to make it as easy or difficult as you like....


问:
Best Mechanism for Generating License Keys
What methods / libraries / tools would people suggest for generating license keys (those lovely AAAAA-AAAAA-AAAAA-AAAAA-AAAAA things you put in when you register software)?

Any gotchas to look out for when implementing them?

(At the moment I'm interested in this as a general thing rather than language specific so just state what language you're using if your solution is language specific).

答:
My preferred method is to generate 10,000 random license strings, SHA1 (or MD5) hash them or HMAC them, and include all or part of the SHA1/MD5 hash in the executable itself. When a license string is entered, you simply use obfuscated code to generate the hash of the string and compare it to the ones in the list. If it matches, it's a valid license. If you run low on licenses, release a new version with more strings.

Using just the first 96-bits of the SHA1 hash is adequate. So 10,000 licenses would take under 120KB. Algorithmic generation of keys or creation of a key generator would be impossible. The only vulnerability you'd have to worry about is reverse engineering or bypassing. (Or someone distributing their valid key.)


答:
What you seem to want is a more controlled way of working, whilst still actually being productive with your programming?

If so, have a look at The Pomodoro Technique where you deliberately take short non-disruptive breaks every half hour, and longer breaks every two or three hours.

It also involves making sure your tasks are broken down into things that can be done in small chunks - so you focus on the things that actually need doing, and avoid running away on a single problem.

There are plenty of similar techniques out there, which might vary in detail, but the key points of making sure problems are broken into discrete tasks which can be crossed off, and that you must take regular breaks, should help you to focus when you need to and move on when you might otherwise waste time down a rabbit hole.

Title: What to do when the programming activity becomes a problem?

Body:
I once saw a program (can't remember which) where it talked about people "experiencing flow" when they are doing something they are passionate about. When "in flow", they tend to lose track of time and surrounding, concentrating only on their activity at hand.

This happens a lot for me when I program; most particularly when I face a problem. I refuse to give up until it's solved. This usually leads to hours just rushing by and I forget to eat lunch, dinner gets pushed into far into the evening, and when I finally look at the clock, it's way into the wee-hours of the night and I will only get a few hours of sleep before having to rise early in the morning. (This is not to say that I'm in flow only when facing a problem - but I find it particularly hard to stop programming and step back when there's something I can't solve immediately.)

I love programming, but I hate it when it disrupts my normal routines (most importantly eating and sleeping patterns). And sitting still for so many hours, staring a screen, is not healthy.

Please, any ideas on how I can get my rampant programming activity under control?


问:
Is it okay to use a language that isn't supported by your company for some tasks?
I work for a company that supports several languages: COBOL, VB6, C#, and Java. I use those languages for my primary work, but I often find myself coding some minor programs (e.g. scripts) in Python because I find it to be the best tool for that type of task.

For example: an analyst gives me a complex CSV file to populate some DB tables, so I use Python to parse it and create a DB script.

What's the problem?

The main problem I see is that a few parts of these quick and dirty scripts are slowly gaining importance and:

My company does not support Python

They're not version controlled (I back them up in another way)

My coworkers do not know Python

The analysts have even started to reference them in emails ("launch the script that exports..."), so they are needed more often than I initially thought.

I should add that these scripts are just utilities that are not part of the main project; they simply help to get trivial tasks done in less time. For my own small tasks they help a lot.

In short, if I were a lottery winner to be in a accident, my coworkers would need to keep the project alive without those scripts; they would spend more time fixing CSV errors by hand, for example.

Is this a common scenario? Am I doing something wrong? What should I do?

答:
If those are tools you use for yourself, you are free to do anything that makes you more productive.

Actually, you should be encouraged to make and use such tools, which will ultimately became an extension of your arms.

Eventually, they will recognize the importance of having such tools, no matter what language they are written in, and will start to implement in their working environment.

ContentLicense: CC BY-SA 4.0


问:
Lists & Collections in MVVM - which approach to take?
I'm currently working on a Silverlight app using Caliburn.Micro.

At present, we have Views (eg: PeopleView) and View Models (eg: PeopleViewModel) that equate to 'pages' of the application.

PeopleView might contain a ListBox ("People") which is bound to an ObservableCollection of Person objects, and has an ItemTemplate assigned to denote how each Person object should be displayed.

However, one of my colleagues has begun to implement a list in another way, where each Person is a View Model (ie: PersonViewModel) and has an associated PersonView to determine how that PersonViewModel should be displayed in the ListBox.

The latter seems more MVVM (or at least has more mention of V and VM!) but I'm not sure whether there's a particularly large advantage to doing one over the other.

Are both of these ways valid? Is either better than the other?

答:
Ok, so assuming Person is your entity (model object)...

You can do it either way, but with some caveat's:

1) Binding directly to a model object works well in read-only screens.  If you just return a list of People and you want the user to choose one, great, it's easy to just bind to that list.

2) Binding directly to your domain model can start to suck if you're implementing a screen that allows you to manipulate those objects.  The state of the data under edit can represent an invalid model state until validated and saved.

Due to #2, a lot of people make a PersonViewModel that's really for editing.  I don't think that's a good idea either.  I think you need to define model classes that represent the state during the editing (and mapping operations between the Person and PersonEdit classes, including validation).

Now if you want to go adding a PersonViewModel, it does have some advantages.  Let's say your Person has a property DateOfBirth and a derived property Age, and another derived property AgeGroup (perhaps Toddler, Preteen, Teen, etc.).  What if you want to display those people highlighted different colors based on their age group?  You can either define a ValueConverter (if you still want to bind directly to the Person object), or you can wrap the Person object in a PersonViewModel and add an AgeGroupColor property to the view model.  Then you can bind directly to that.  Which method you choose is really up to you.  A lot of people don't like ValueConverters, and I agree they're a little verbose for what they do, so I'd probably go with the view model option, like your friend.


答:
Yes, both ways are valid. There are pros and cons to each approach.

If the Person can be displayed in several different ways depending on the context - whether it's in a ListBox or on a "page" then using your technique with an ItemTemplate to control how it's displayed in the list is probably the better way to go.

I think you need to look at your overall design and see which fits best. Changing the implementation part way through is a bad idea though. Some "pages" will be the old style and others will be the new, leading to inconsistencies in the user experience and potentially increased effort in maintaining and extending the system. If nothing else, you will have to go through the existing code to make it conform to the new format.

Title: Lists & Collections in MVVM - which approach to take?

Body:
I'm currently working on a Silverlight app using Caliburn.Micro.

At present, we have Views (eg: PeopleView) and View Models (eg: PeopleViewModel) that equate to 'pages' of the application.

PeopleView might contain a ListBox ("People") which is bound to an ObservableCollection of Person objects, and has an ItemTemplate assigned to denote how each Person object should be displayed.

However, one of my colleagues has begun to implement a list in another way, where each Person is a View Model (ie: PersonViewModel) and has an associated PersonView to determine how that PersonViewModel should be displayed in the ListBox.

The latter seems more MVVM (or at least has more mention of V and VM!) but I'm not sure whether there's a particularly large advantage to doing one over the other.

Are both of these ways valid? Is either better than the other?


答:
A picture is worth a thousands words. Draw some Use Case and Sequence diagrams. They should be sufficient to explain the purpose/flow of the software.

P.S: Whatever you do avoid stuffing your source with comments. That will add bloat especially if it's stored in a versionning system. Add some numbers/codes instead which refer to the diagrams suggested.

Body:
I have been specifically asked to give line by line (or as appropriate - for example, image by image, etc.) explanation or commentary which my boss wants to be able to read and follow.

Since he is not a programmer, he can not follow the code so wants it all translated into English.

Has anyone been asked to do this before?

I have commented on all of the source code and used JSDoc to generate full documentation of all functions, variables, etc... and included an implementation example, and full working demos with comments throughout.

Is there anything else I can do to comment the code for non-programmers?

This isn't a reasonable request, is it?

UPDATE

In the end, I managed to explain why it was not a good use of time to do what he was asking. He is a reasonable guy, and just did not have an understanding of what my job involves. Once he saw this post, I think he quickly understood that it was not a normal request.

I did provide documentation that is suitable for another programmer to follow (JSDoc and inline comments - as well as some extra notes on technical issues), and a very broad flow chart diagram of the main logic of the program for my boss to follow.

In the end, all parties were satisfied and we have moved on.


答:
Well, I got to admit that working with 20 different languages stinks, A LOT.

You have a Bash script that calls Python script that calls Perl script that calls Java binary that calls C dll...

Then something hits the fan in the whole pipeline, and you go through - WTH IS DAT KODEZ? Especially in Perl... And debugging simple, say, encoding problem, turns into a nightmarish mess. You can't debug 5 out of 7 languages effectively, and it turns into a real pain.

Or you have to add a simple change, but you create 10 errors because Perl has gotchas, Java has gotchas, etc.

And that 7+ language chain starts one step at a time.

Tread carefully, here be dragons...

Title: Is it okay to use a language that isn't supported by your company for some tasks?

Body:
I work for a company that supports several languages: COBOL, VB6, C#, and Java. I use those languages for my primary work, but I often find myself coding some minor programs (e.g. scripts) in Python because I find it to be the best tool for that type of task.

For example: an analyst gives me a complex CSV file to populate some DB tables, so I use Python to parse it and create a DB script.

What's the problem?

The main problem I see is that a few parts of these quick and dirty scripts are slowly gaining importance and:

My company does not support Python

They're not version controlled (I back them up in another way)

My coworkers do not know Python

The analysts have even started to reference them in emails ("launch the script that exports..."), so they are needed more often than I initially thought.

I should add that these scripts are just utilities that are not part of the main project; they simply help to get trivial tasks done in less time. For my own small tasks they help a lot.

In short, if I were a lottery winner to be in a accident, my coworkers would need to keep the project alive without those scripts; they would spend more time fixing CSV errors by hand, for example.

Is this a common scenario? Am I doing something wrong? What should I do?


问:
How to learn from open source
I see this problem quite often.  I like a certain value proposition of an open-source project. I try out the basic tutorials. Great. It works! But if I move on to more complex problems, I spend hours of doing research, debugging, frustrations, etc.

What are your strategies to keep motivation in open-source going?  What is the reward of open-source after success of basic tutorials?  What "success" of open-source did you experience?

答:
I am assuming you are looking at small open source libraries like those found on github.  In my case I am often using one to solve a specific problem.  If it doesn't solve it cleanly, then I dig in, learn how the code works and make changes as necessary.  If my change is for something useful or a bug fix I attempt to contact the open source owner or fork my own branch.

Other times I am just adapting something close to my own needs, in those cases I just keep my changes and move on.  I add watches or check back in regularly to see what has been updated.

As in the notes though, this is the life of software development.  It's an ever changing environment.

Title: How to learn from open source


答:
You could also suggest a move to Literate Programming and COBOL or FORTRAN since https://stackoverflow.com/questions/152160/using-noweb-on-a-large-java-project or just ask why he doesn't require every graphist to explain every single use of any tool he makes.

You're a specialist, you are expected to deliver a high end product, not to explain in detail that you paint a greenish stroke here, and then apply a 2px gaussian blur etc.


答:
There's no point having a PersonViewModel if it doesn't have any additional properties over and above the Person model. It's just a waste of time.

However, if you're using value converters to convert a Person in any way then I'd have used a PersonViewModel and not bothered with the value converter.

PersonViewModel should simply expose the Person object and any additional properties. I wouldn't proxy every single Person property into the PersonViewModel.


问:
Why do some functional languages need software transactional memory?
Functional languages, by definition, should not maintain state variables. Why, then, do Haskell, Clojure, and others provide software transactional memory (STM) implementations? Is there a conflict between two approaches?</p>

答: Sometimes a program requires mutable state (for instance, database contents for a web app) and it would be great to be able to use it without losing the benefits of functional programming. In non-functional languages, mutable state permeates everything. If you make it explicit with some kind of special API, then you can confine it to a small identifiable region while everything else remains purely functional. Benefits of FP include easier debugging, repeatable unit testing, painless concurrency, and multicore/GPU friendliness.</p>


问:
Is Java instanceof operator considered reflection, and what defines reflection?
I had a discussion with a coworker today, whether usage of using the Java operator instanceof is a kind of reflection. And the discussion quickly evolved into what actually defines reflection.

So, what is the definition of reflection?

And is the usage of instanceof considered "using reflection" ?

And in addition, if instanceof is considered reflection, then is polymorphism not also "using reflection"? If not, what is the difference?

答:
YES, "instanceof" operator its a form of reflection. The previous answers tell you why.

"Reflection" or "object / class introspection" is a hype these days, but several programming languages have use some of that concept, from some time.

DOT NET (Java clone), (mis) uses a lot.


问:
What does artifact mean?
The dictionary defines artifact as:

artefact, artifact [ˈɑːtɪˌfækt]
  n

something made or given shape by man, such as a tool or a work of art, esp an object of archaeological interest

anything man-made, such as a spurious experimental result

(Life Sciences & Allied Applications / Biology) Cytology a structure seen in tissue after death, fixation, staining, etc., that is not normally present in the living tissue

The word artifact often appears in software development, software development cycles, effort estimation, etc. But the above definition doesn't make sense to me in that context.

Could someone please explain this word by giving some specific examples from software industry?

答:
In software development life cycle (SDLC), artifact usually refers to "things" that are produced by people involved in the process. Examples would be design documents, data models, workflow diagrams, test matrices and plans, setup scripts, ... like an archaeological site, any thing that is created could be an artifact.

In most software development cycles, there's usually a list of specific required artifacts that someone must produce and put on a shared drive or document repository for other people to view and share.

Title: What does artifact mean?


答:
I think this Wikipedia article covers it pretty well.

An artifact is one of many kinds of tangible by-product produced during the development of software. Some artifacts (e.g., use cases, class diagrams, and other UML models, requirements and design documents) help describe the function, architecture, and design of software. Other artifacts are concerned with the process of development itself—such as project plans, business cases, and risk assessments.

Title: What does artifact mean?

Body:
The dictionary defines artifact as:

artefact, artifact [ˈɑːtɪˌfækt]
  n

something made or given shape by man, such as a tool or a work of art, esp an object of archaeological interest

anything man-made, such as a spurious experimental result

(Life Sciences & Allied Applications / Biology) Cytology a structure seen in tissue after death, fixation, staining, etc., that is not normally present in the living tissue

The word artifact often appears in software development, software development cycles, effort estimation, etc. But the above definition doesn't make sense to me in that context.

Could someone please explain this word by giving some specific examples from software industry?


答: I think there are other ways the term is used that mean more like a side-effect, but the main use I see of the word "artifact" within the software industry is to mean "the product that is created". So, like, the program the developers are writing is a "software artifact".</p>

Title: What does artifact mean?


答:
Is it the reviewer's job to ensure that the requirement is complete and correct? Or is this the QA and business tester's responsibility?

It is the QA (Software quality assurance) responsibility to ensure that the requirement is complete and correct. Anyone assigned to do that wears tester's hat no matter how large is his developer's badge.

(source: dilbert.com)


答:
You ask how you keep the motivation in using a given open source API project?

The trick is figuring out which Open Source projects are the good ones.  The major qualification in Open Source is the fact that you have access to the source code, which is extremely useful when you need to find out how things work (which usually happens when you need behaviour to change in some situation), but this does not imply anything else than that.  This includes the quality of the project which is completely unrelated to the openness of the source.

Quality consists of several more or less subtle things when speaking of a code project:

How well is the API designed?  Does the code you need to write to actually call the API read easily?

How well written is the actual code in the API?   Is it easy to understand what goes on?  Are the data structures well chosen and do not have expensive runtime characteristics?  Are variable names well chosen?   Does the code conform to a coding standard?

Is the API documented?  This is both the design and javadoc of the actual code, and is it useful?  This is more important than  you may think, as it shows the maturity of the code.

Does the project have a web page?  Is it updated and without broken links?  Does it provide easy access to source code, downloads and documentation?

Does the project have a community and mailing lists?  Are the archives available and accessible?  Is the community helpful?

All these things are useful to  have in mind when choosing if you want to use a given open source project or not.  Any derivation from the best should cause a warning sign to flash in your head as it is an indication that this is not a best-of-breed project.

Then when you found the project, you like what you see, there is the final test:

How hard is it to get up and running from scratch with a simple program invoking the API in a useful way?

This should be

explained in an easy to spot location on the project web site and/or in the documentation in the download bundle.

easy to get right - the documentation must be accurate, the program simple to write or adapt from a given, simple example, and both well explained and easily understandable.

quick to get right - if you need to do any debugging at this point to get the program to run as explained, something is very wrong.

If it is evident that this is an anticipated and prioritized use case, then this should be trivially simple.   If it is evident that the project does not care about this particular thing, then I would strongly consider not using it!  If it is uphill here, it will be uphill many, many times later, and it will be better to just not use it.

Title: How to learn from open source

Body:
I see this problem quite often.  I like a certain value proposition of an open-source project. I try out the basic tutorials. Great. It works! But if I move on to more complex problems, I spend hours of doing research, debugging, frustrations, etc.

What are your strategies to keep motivation in open-source going?  What is the reward of open-source after success of basic tutorials?  What "success" of open-source did you experience?


问:
Should a developer accept a workload estimation done by a Excel macro?
In a new project, a friend had to write tests where the time required to write them was calculated by an Excel macro written by his non-developer manager.

In such circumstances, should a developer accept the responsibility to write and run the tests in the calculated time? Are the results of these test trustworthy?

For information, my friend refused to be responsible for estimations he didn't made, ask succeed to work on another project, and have been replaced by an inexperienced out-of-the-school yes-guy.

答:
In theory, a developer should never accept an estimate made by any other person, no matter how it was arrived at. One reason is that giving a longer estimate than your manager is comfortable with immediately exposes a potential schedule problem or perhaps a misunderstanding about the scope of work to be done.

People generally find programming-time estimation even more difficult than programming itself, so if your manager can write an Excel macro can solve that problem, he can probably construct a macro to write the code (unlikely).

Now, in practice, if you understand the work and the estimates look reasonable, it makes sense to simply express some concern about the methodology in passing but then provisionally agree to see if you can meet them. Later, if the work is taking you longer than the estimates, you should bring this to your managers' attention at the earliest possible moment. Be prepared to discuss the exact reasons based on your actual implementation experience. Hopefully at that point your manager will not be unreasonable and continue to insist that you work to mechanically generated estimates.


问:
What standards does your team use for your specification documents headers and footers?

TL;DR:

What header/footer do you put on your Functional&Technical specifications to avoid people having different versions at meetings?

Story:

We're have a lot of documents, being changed by everyone. Functional specifications, technical specifications, addendums, etcetera.

Problem is offcourse that during a meeting, after an hour someone notices their printed version differs from someone else's.

I thought this could be solved by forcing everyone to use the same header/footer on each document:

Header

Project concerned

Document title (center aligned)

Document author (right aligned)

Footer

Last modification date

Date on which document was printed

Full document path and name (which always include the version number)

Page X of Y

This way, we could all easily check the filename and last modification date before starting the meeting, and make sure everyone has the same copy and is talking about the same document.

Would this work? Am I missing something? What do you guys use for your specifications to avoid versioning problems?

答:
What header/footer do you put on your Functional&Technical specifications to avoid people having different versions at meetings?

We do not have a standard set in stone accoss projects, but something like this will be a good minimum:

project

subsection of project

creator

create datetime

last modified by

last modified datetime

Even better is to check specifications and design documents into source control (Sharepoint does a lot of the same things if it is easier for business people). Souce control will log all of the stuff above, plus keep a history of all of the changes. Also, I would recommend forcing comments with check ins. Meaningful comments on changesets can be a huge help if checkins happen frequently from lots of people. Basically, just treat the spec like a part of the project (because it is).