问:
How do you manage feature requests and software changes?
I am a Software Engineer and over the past few years I have become the de-facto software project manager simply because there isn't one. So to keep our sanity in the R&D/Engineering department, customers have become accustomed to coming to me with their requests. I have no experience in this realm so it is my first time acting as a project manager for software projects. I have managed other things but not software.

So, how do you manage software projects and mark priorities? Requests come in at infrequent intervals so we very well could be working on something for someone else and then another person comes in with a "rush" job that needs working on. Is it easier to just say First Come, First Serve or is it the person with the most money?

答:
I've seen projects where requirements changes are managed by a very heavyweight change control system. This is bad. Many important changes do not happen because the customer does not want to go through the hassle of submitting a change control, so the software doesn't match their needs. Some small changes get slipped in "under the radar" to avoid the process, so the software doesn't even match what you think it does.

Conversely, I've also seen projects where the project manager thinks "reactive" means getting the coders to respond to every request from the users, which just means you never get any core development done and your code becomes a big unwieldy mess of hack atop hack. Essentially you now don't have any developers, you have a team of overqualified sales engineers.

So one might hope there's a situation between these two poles that works well, and I expect that what works best for you is both a personal choice and situated. There's definitely value in capturing the cost of each change. In a framework like Scrum you can express the cost in story points, and the team can trade off the work they do in each iteration versus the total available effort. If you have a product manager you can get that person to quantify the expected benefit of a change or feature request. This is usually done in terms of protected revenue (how many customers would leave if you didn't do this) and attracted revenue (how many customers will arrive if you do do this). That can help with prioritisation, but can also just reflect the bias or personal preference of the product manager.


问:
Should I use a unit testing framework to validate XML documents?
From http://www.w3.org/XML/Schema:

[XML Schemas] provide a means for defining the structure, content and semantics of XML documents.

I'm using an XML Schema (XSD) to validate several large XML documents. While I'm finding plenty of support within XSD for checking the structure of my documents, there are no procedural if/else features that allow me to say, for instance,

If Country is USA, then Zipcode cannot be empty.

I'm comfortable using unit testing frameworks, and could quite happily use a framework to test content integrity.

Am I asking for trouble doing it this way, rather than an alternative approach? Has anybody tried this with good / bad results?

--

Edit: I didn't include this information to keep it technology agnostic, but I would be using C# / Linq / xUnit for deserialization / testing.

答:
I use C# to deserialize XML documents into classes and unit test from there.  I do this in addition to verifying the XML document against the XSD file, and it works great.  I highly recommend this method of validating XML.

...I would be using C#...

Look into XMLUnit for .NET

ContentLicense: CC BY-SA 3.0


答:
I don't think unit test framework would help you.

Unit test frameworks were designed to solve these things:

Automatically register unit tests.

Select which tests to run depending on command-line or other arguments.

Simplify repeated initialization and deinitialization.

Report values used in failed conditions.

Now I don't see how any of those would help you. You have one long list of tests, that you need to apply to the document, you need to run all tests, you don't want to initialize and deinitialize separately for each test and you need messages describing what is wrong with the document, not dump of some random objects you compared to check.

Especially this test isolation stuff and the fact, that unit test frameworks are generally not designed to be run on externally provided sets of data is probably going to get in your way more than anything else might help you. Because you have to write the tests themselves in the raw language anyway and that's almost all the work there is.

So I'd say just pick a language you know, a good XML parsing library, that will give you convenient access to the document tree and just write a simple application with that.

Ad edit: .NET has a compiler (you give it XSD and it spits out class definitions; it can go the other way too) to generate object representation corresponding to the document from it's XSD, which is by far most convenient method to access the document elements and will verify the document conforms to the XSD as side-effect. So I'd recommend using that for reading the document. That has nothing to do with unit test, of course.

Title: Should I use a unit testing framework to validate XML documents?

Body:
From http://www.w3.org/XML/Schema:

[XML Schemas] provide a means for defining the structure, content and semantics of XML documents.

I'm using an XML Schema (XSD) to validate several large XML documents. While I'm finding plenty of support within XSD for checking the structure of my documents, there are no procedural if/else features that allow me to say, for instance,

If Country is USA, then Zipcode cannot be empty.

I'm comfortable using unit testing frameworks, and could quite happily use a framework to test content integrity.

Am I asking for trouble doing it this way, rather than an alternative approach? Has anybody tried this with good / bad results?

--

Edit: I didn't include this information to keep it technology agnostic, but I would be using C# / Linq / xUnit for deserialization / testing.


答:
You should write some .NET classes to do your validation and then verify their expected behavior with unit tests.

The process for actually finding the documents and validating them should be completely separate (Perhaps some other set of types that use a FileSystemWatcher on a folder you can drop into). Pointing your unit tests at the XML documents you need validated is a poor idea; you should not have to use a IDE or test-runner to run your business.

Use a high level exception handler to prevent an invalid file from crashing your process.  There's nothing special about unit testing frameworks that make them useful in regular applications (they're essentially exception handlers).

Plus, how are you planning on logging exceptions if you will use a testing framework to run your code?


答:
The title of your question begins with "Should I use...". "Should" is a strong word. You should test, but whether you use a unit testing framework or something else depends on a lot of factors. You can use a unit testing framework if that is what you are comfortable with.

However, it sounds like you aren't testing units per se, and unit testing frameworks are heavily optimized for that particular niche. You might want to choose an acceptance testing framework such as cucumber or the robot framework or specflow. These types of tools let you express your tests more like business requirements rather than just a set of inputs and outputs.


问:
How do I handle priority and propagation in an event system?
Let's say I have a simple event system with the following syntax:

```<code>object = new Object();
object.bind("my_trigger", function()  { print "hello"; });
object.bind("my_trigger", function()  { print "hello2"; });
object.trigger("my_trigger");
</code>```

How could I make sure hello2 is printed out first? (I do not want my code to depend on which order the events were bind).

On top of that, how would I prevent my events from propagating? (e.g. I want to stop every other event from being executed)

答:
A co-worker suggested the following:

```<code>object = new Object();
object.bind("my_trigger", function()  { print "hello"; });
object.bind("my_trigger", function()  { print "hello2"; return false; }, { priority : 10 });
object.trigger("my_trigger");
</code>```

Upon binding, I order my events based on the priority and execute them in serial until one of them returns false and stops the execution.

Body:
A co-worker suggested the following:

object = new Object();
object.bind("my_trigger", function()  { print "hello"; });
object.bind("my_trigger", function()  { print "hello2"; return false; }, { priority : 10 });
object.trigger("my_trigger");

Upon binding, I order my events based on the priority and execute them in serial until one of them returns false and stops the execution.


问:
What is the best way to evaluate new programmers?
What is the best way to evaluate the best candidates to get a new job (talking merely in terms of programming skills)?  In my company we have had a lot of bad experiences with people who have good grades but do not have real programming skills.  Their skills are merely like code monkeys, without the ability to analyze the problems and find solutions.

More things that I have to note:

The education system in my country sucks--really sucks.  The
people that are good in this kind of job are good because they have talent for it
or really try to learn on their own.

The university / graduate /post-grad degree doesn't mean necessarily that you know exactly how to do the things.

Certifications also mean nothing here because the people in charge of the certification course also don't have skills (or are in low paying jobs).

We need really to get the good candidates that are flexible and don't have mechanical thinking (because this type of people by experience have a low performance).

We are in a government institution and the people that are candidates don't necessarily come from outside, but we have the possibility to accept or not any candidates until we find the correct one.

答:
Based on my 25 years of programming (which, admittedly includes only a 5 or 6 instances of hiring other programmers) :

Positive indicators:

Passionate about technology

Programs as a hobby

Will talk your ear off on a technical subject if encouraged

Significant (and often numerous) personal side-projects over the years

Learns new technologies on his/her own

Opinionated about which technologies are better for various usages

Very uncomfortable about the idea of working with a technology he doesn’t believe to be “right”

Clearly smart, can have great conversations on a variety of topics

Started programming long before university/work

Has some hidden “icebergs”, large personal projects under the CV radar

Knowledge of a large variety of unrelated technologies (may not be on CV)

Negative indicators:

Programming is a day job

Don’t really want to “talk shop”, even when encouraged to

Learns new technologies in company-sponsored courses

Happy to work with whatever technology you’ve picked, “all technologies are good”

Doesn’t seem too smart

Started programming at university

All programming experience is on the CV

Focused mainly on one or two technology stacks (e.g. everything to do with developing a java application), with no experience outside of it

In addition, I'd suggest:

The FizzBuzz test (or something like it to test basic ability to write an algorithm.

Harder version of the FizzBuzz test (to get them to the failure or near-failure point.)

Discuss their code and see if they are willing to be self critical and look for improvements (which they probably didn't have time do do in a short on the spot test) such as:
-  good variable names (I've had very experienced skilled coders use variables in production like "flag" (WTF??)
-  modularization.
-  Anticipating problems and doing "defensive coding"

A willingness to see "flaws" as opportunities for improvement.  I think the best coders always look unflinchingly for flaws in their previous code. They are not so egocentric as to think that finding a flaw their is a personal affront. They see it as an opportunity to do better. (Those that can't look at flaws unflinchingly either are overwhelmed by seeing a flaw (and become super underconfident or, to avoid just that, they ignore the flaws.

Can they debug?

Can they Unit Test? (I've talked to way too many programmers who say "QC does that".  I'm not talking about Testing, I'm talking about testing: you write a function, does it work? Does it make reasonable efforts to deal with likely problems (NULL input, etc.) ?  If you can't do that, how do you know when you're done?

Do they have good communication skills? (at a minimum: good comprehension and self knowledge about when they do and do not understand and a willingness to say "I don't understand, please explain it again".

Much of the summary above is from How to spot a good programmer, which is  a great article, focused a bit more on longer range indicators. It definitely confirms my intuitions and experience. It's also a lot of things (like "passion") that aren't normally mentioned in a checklist of "what's a good programmer".

ContentLicense: CC BY-SA 4.0


问:
What is the objective of unit testing?

Possible Duplicate:

  Is unit testing or test-driven development worthwhile?

I've been working with C# for the last 2 years, and I've never done any unit testing. I just need to know what the objective of unit testing is. What kind of results do we expect from unit testing? Is code quality checked by unit testing? In my view, unit testing is the job of testers; if that is true, then as a developer why would I need to write test code if the tester does the unit testing? Why should I write extra code for testing? Do I need to maintain a separate copy of a project for unit testing?

答:
Every "unit" has an implicit contract: roughly, "if you supply these inputs, I will give you these outputs". Unit tests serve to prove that the contract has been fulfilled, and notify you when it has been broken.

They are useful if you write them first (tdd) in that you know you are done when all the tests pass (assuming all the tests are a fair representation of the contract). After the code has been written, the unit tests will tell you when a change breaks the contract.

For example, lets say you have a function that converts a string to all uppercase. You unit tests must prove that, given a string, it does exactly that. Later, somebody passes in a unicode string and your function fails. That means either that unicode inputs were not part of the contract, so you have to add a new feature, or it was part of the contract and the test is telling you that the code has a bug and isn't honoring the contract.

Not only do you get the benefits of bug detection, but the very act of writing the unit tests help you to fully understand what your code is expected to do. It makes you think about edge cases, about what inputs are required, and what outputs are expected.

Title: What is the objective of unit testing?


问:
Why was Java chosen for Android?
Why was Java chosen for Android, instead of something like C++? I have heard that Java uses quite a lot of memory and I would presume that low memory usage would be quite important on mobile devices. Is there any real advantage to using Java instead of a language like C++ on a mobile device?</p>

答:
This article sheds some light on the situation. The most pertinent link within that article is this. So you've got a massive install base with lots of programmers who know the language and it's widely taught at universities. C++ was dropped from my school's curriculum, Java is still here. Java has Java ME which has a massive install base on other cellphones. The Pantec Ease I have in my pocket right now has a little coffee cup in the corner of the screen. Anyone care to guess what that is?

This answer on Stack Overflow covers it pretty well too.

Summary of SO answer:

java is a known language, developers know it and don't have to learn it

its harder to shoot yourself with java than with c, c++ code since it has no pointer arithmetic

it runs in a vm, so no need to recompile it for every phone out there and easy to secure

large number of developement tools for java (see first)

several mobile phones already used java me, so java was known in the industry

the speed difference is not an issue for most applications, if it were you  should code in assembly

Title: Why was Java chosen for Android?


答:
Not sure why exactly Java was chosen but it was probably for a number of reasons

To capture the large group of developers who are familiar with and use Java

Fill the mobile gap in Java where technologies like J2ME where Java is lacking.

Secondly, there is not Java Virtual Machine specified for Android.  Instead all Java code is compiled for running on Dalvik, which is a lightweight, optimized VM specifically designed for running in mobile environments.  It purportedly enhances battery life and maximizes efficient use of resources.

Title: Why was Java chosen for Android?

Body: Why was Java chosen for Android, instead of something like C++? I have heard that Java uses quite a lot of memory and I would presume that low memory usage would be quite important on mobile devices. Is there any real advantage to using Java instead of a language like C++ on a mobile device?</p>


答:
I'll hazard a guess that Google choose Java for familiarity, if nothing else. Many of Google's projects revolve at least concepts of Java schematics (GWT for example).

In addition, it's a language widely taught in technical schools (unlike say, Javascript (which Android also zealously supports)). Java's certainly not the best language for a mobile device in terms of performance and production, but it is well known.

Also remember that Android came in a little late to the party. Forcing developers to use C++, a low-level compiling language, would make it harder to generate a 'wow' factor, and if nothing else, Android needed numbers (of apps) and flashiness to get off the ground.

Title: Why was Java chosen for Android?


问:
Is this kind of Design by Contract useless?
I've just started informatics university and I'm attending a programming course about C(++). The programming professor prefers to connect every topic with a type of programming design that is similar to Design by Contract. Basically, what he asks us to do is to write every exercise with comments that denote the pre-condition, post-condition, and invariants that should prove the correctness of each program we write.

But this doesn't make any sense to me. Maybe writing down your thoughts prevent you from making some mistakes, but if this is all an abstract thing, then if your program intuition is wrong, you'll write your program wrong, and then you'll also write pre and post conditions wrong. In the end, you'll be convinced that a wrong program might actually be correct.

I had some programming experience before this course and I found myself comfortably with just writing a program and unit testing it. It takes less time to accomplish and is less "abstract" than just thinking about what every single piece of your program should do in every case (which is kinda like mentally testing it).

Finally, determining the pre and post conditions takes me about 80% of the total time of the exercises. It's harder to think about putting down this pre and post correct than to write the program itself.

Am I right in thinking that working with pre-conditions, post-conditions, and invariants aren't worth anything? Should I convince myself that this method is right?

答:
When I tested out of my Java course, my professor was much the same way; 90% of the project was developing a flow chart and writing pseudo code, and the actual program took no more than a few hours to write.

Since then however, I have been writing down my processes more and more... not by any particular method or anything, but just figuring out all the angles of my end program. I feel like it has saved time in the long run.

When I first started programming, I didn't need to do all the overhead, because the programs I made were trivial. So, I was in the same boat as you: "Why are we wasting time doing all of this?"

Once you start working on larger productions, possibly with some help on the side, having a plan in plain english will be more beneficial than writing several dozen lines of code only to change your mind an hour later.

So, I wouldn't condone what your professor is teaching you, though for an intro class it is indeed rather pointless. With large and more obscure projects, writing out the plan of action is helpful. Who knows, you could be working for a pointy-haired boss someday that needs to know what you're trying to do and doesn't speak C++.

Lastly, don't think that the way you're being taught to plan out your code is the only way to do it. Planning methods are just tools like the programming languages they assist.


问:
Does MVC apply only to web
It is almost and instantaneous whenever I talk to developers about Model View Controller (MVC) they say you make a request to a url the server builds a entity (MODEL) and provides you with visual representation of that model.

So does this mean MVC is only for the web or have I been meeting people who are just developers who employ MVC for writing web applications?

Are there usages for MVC on desktop style applications?

I for one am new to paradigm and would like to know of any super-set to MVC

答: No, it applies even for standalone applications.  Example Java Swing follows MVC.</p>

Title: Does MVC apply only to web


答:
I recommend priority queues in a producer/consumer setup.

edit:
I've used priority queues in sort of a pub/sub system before. I set up a router object; a method of that object was a sender, with the priority and destination point specified. There was a reader method which would be the destination point.
Under the hood would be priority queues. The router object would handle reading and writing the queues.

It was actually a multithreaded system; the producers of information would be things like a http server, files, etc, the consumers could be the windows event queue, files, or http messages. The router would handle the messaging between the producers and consumers.

For filtering, I would determine who cares about the filtering, and place the filter block as part of that element.  Possibly each element (producer, router, and consumer) would get the capability to hook. (e.g., a list of functions passed in and AND'd together to allow a message to pass).

Title: How do I handle priority and propagation in an event system?

Body:
Let's say I have a simple event system with the following syntax:

```<code>object = new Object();
object.bind("my_trigger", function()  { print "hello"; });
object.bind("my_trigger", function()  { print "hello2"; });
object.trigger("my_trigger");
</code>```

How could I make sure hello2 is printed out first? (I do not want my code to depend on which order the events were bind).

On top of that, how would I prevent my events from propagating? (e.g. I want to stop every other event from being executed)


问:
How should I evaluate new browser languages?
In these days there are many projects whose aim is to bring new languages to the browser by compiling them to JavaScript. Among the others one can mention ClojureScript, CoffeScript, Dart, haXe, Emscripten, Amber Smalltalk.

I'd like to try a few of these out, but I am not sure what I should be looking for when evaluating these languages to see if they are suitable for production.

How should I evaluate a new browser language, and what are the pitfalls I should be looking for?

答:
I find playing with a new technology is always going to be the best way to get to know it.

Once you have mastered the basics, you often start to try the more advanced features, or scenarios (ie. using the tool in some complex web app).

These are when you can start to find the limitations of a tool.

When this happens, I start searching SO, forums etc, to try and find ways round the issues. In these places you'll probably start to read other people's opinions and issues they have came across and it helps you get a better "feel" for the tool.

A more formal way might be trying to benchmark the tool against other solutions. Does it perform "well". (where "well" is to be defined by your system needs).


答:
Formally proving the correctness of the program you're using is well-known to be extremely arduous and only suitable for the smallest programs. The amount of time necessary to formally prove anything but the most trivial programs correct is insane and not practical at all.

However, having a design and specification are essential tools, even if you don't prove your programs correct against them.

Title: Is this kind of Design by Contract useless?

Body:
I've just started informatics university and I'm attending a programming course about C(++). The programming professor prefers to connect every topic with a type of programming design that is similar to Design by Contract. Basically, what he asks us to do is to write every exercise with comments that denote the pre-condition, post-condition, and invariants that should prove the correctness of each program we write.

But this doesn't make any sense to me. Maybe writing down your thoughts prevent you from making some mistakes, but if this is all an abstract thing, then if your program intuition is wrong, you'll write your program wrong, and then you'll also write pre and post conditions wrong. In the end, you'll be convinced that a wrong program might actually be correct.

I had some programming experience before this course and I found myself comfortably with just writing a program and unit testing it. It takes less time to accomplish and is less "abstract" than just thinking about what every single piece of your program should do in every case (which is kinda like mentally testing it).

Finally, determining the pre and post conditions takes me about 80% of the total time of the exercises. It's harder to think about putting down this pre and post correct than to write the program itself.

Am I right in thinking that working with pre-conditions, post-conditions, and invariants aren't worth anything? Should I convince myself that this method is right?


问:
Certifications for Javascript developers?
I'm looking for a solid and but fast paced entry in field of javascript development.

The following topics come to my mind:

Javascript advanced concepts, OOP

jQuery, jQuery-UI, jQuery-Mobile

backbone.js

node.js

BDD and/or TDD

The courses of http://www.codelesson.com seem promising.

What certificates for Javascript developers exist/can be recommended?

What other vendors can you recommend?

答: I don't know of any certificates that really test everything you described. I would suggest getting a base certificate like CIW JavaScript Specialist or W3Schools JavaScript Certification(some dispute W3Schools credibility) and then building a portfolio on your own of the technologies and skills inside of JavaScript you wanted to show off. A GitHub username full of sample code beats a Certificate any day.</p>


答:
If it makes you feel better bad programmers exist in pretty much every country. How to weed them out is the problem.

First weeding is the resume. One thing I look for is a lot of claimed language experience and nothing to describe what they did in that language. I've seen resumes that pretty much claim they know every language ever invented and yet their experience shows they've only actually worked with Access and Visual Basic. Those go right in the trash. 10 page resumes go right in the trash (especially ten page resumes from people with less than 2 years of experience which I have gotten). From recent college grads with little experiece, you have to be really picky about how they present themselves. The best candiates are careful with their resumes, they don't have errors. Are you really looking for someone who cares so little he didn't bother to proofread his resume?

Professionally prepared resumes go in the trash too. Once you've read hundreds of resumes, you can pick them out as they use the exact same phrasing. You can't trust the content in a professionally-prepared resume and you know the person didn't do his own prep. This is the kind of person who will rely on others to solve his problems for him, do you really want that in a programming position?

Look for things that make the person stand out for the ones you pick. That's harder of course with the ones just out of school, but look for accomplishments, contributions to open source, etc.

The next weed out is the phone interview. Ask about basic concepts that relate to the actual job you have. If people don't have basic knowledge of concepts you need them to have, they aren't worth bothering to bring in to a personal interview. The young often think this is unfair becasue they can look up everything on the Internet, but the truth is I have never met a good programmer who had to look up everything on the Internet. You should have some knowledge of your profession that you don't have to look up each time.

After the phone interview you should pick the best 4-5 candidates and interview. Of course if you only have 1-2 good candidates, don't bother interviewing people you already eliminated. Now you are going to ask the hard questions and get a feel for how they approach problems. I would never use the fizzbuzz test because it is too well known so the answers tell you nothing.  Instead make up some problems from your own code base. I might  give them a requirement and a piece of code and ask them if the code meets the requirement and if not why not and what they might to do make it meet the requirement. I would ask them to describe the most difficult programming problem they have had to solve and what steps they took to find the answer. I would ask some more in-depth technical questions. Remember you are trying to get a feel for their technical competence, their problems solving and debugging ability and their ability to fit with your existing team. I also ask questions that they probaly don't know the answer to to judge how well they handle stress, it's a stressful job, I don't want someone who folds in the interview because the stress of the job is greater than the interview stress. I look for strengths in areas we are currently weak in and ability to work in teams and to present themselves to the customers (our devs deal extensively with users), your list may be different.

Title: What is the best way to evaluate new programmers?

Body:
What is the best way to evaluate the best candidates to get a new job (talking merely in terms of programming skills)?  In my company we have had a lot of bad experiences with people who have good grades but do not have real programming skills.  Their skills are merely like code monkeys, without the ability to analyze the problems and find solutions.

More things that I have to note:

The education system in my country sucks--really sucks.  The
people that are good in this kind of job are good because they have talent for it
or really try to learn on their own.

The university / graduate /post-grad degree doesn't mean necessarily that you know exactly how to do the things.

Certifications also mean nothing here because the people in charge of the certification course also don't have skills (or are in low paying jobs).

We need really to get the good candidates that are flexible and don't have mechanical thinking (because this type of people by experience have a low performance).

We are in a government institution and the people that are candidates don't necessarily come from outside, but we have the possibility to accept or not any candidates until we find the correct one.


问:
Are there any concrete examples of where a paralellizing compiler would provide a value-adding benefit?
Paul Graham argues that:

It would be great if a startup could give us something of the old
  Moore's Law back, by writing software that could make a large number
  of CPUs look to the developer like one very fast CPU. ...
  The most ambitious is to try to do it automatically: to write a
  compiler that will parallelize our code for us. There's a name for
  this compiler, the sufficiently smart compiler, and it is a byword for
  impossibility. But is it really impossible?

Can someone provide a concrete example where a paralellizing compiler would solve a pain point? Web-apps don't appear to be a problem: just run a bunch of Node processes. Real-time raytracing isn't a problem: the programmers are writing multi-threaded, SIMD assembly language quite happily (indeed, some might complain if we make it easier!). The holy grail is to be able to accelerate any program, be it MySQL, Garage Band, or Quicken. I'm looking for a middle ground:
 is there a real-world problem that you have experienced where a "smart-enough" compiler would have provided a real benefit, i.e that someone would pay for?

A good answer is one where there is a process where the computer runs at 100% CPU on a single core for a painful period of time. That time might be 10 seconds, if the task is meant to be quick. It might be 500ms if the task is meant to be interactive. It might be 10 hours. Please describe such a problem.

Really, that's all I'm looking for: candidate areas for further investigation. (Hence, raytracing is off the list because all the low-hanging fruit have been feasted upon.)

I am not interested in why it cannot be done. There are a million people willing to point to the sound reasons why it cannot be done. Such answers are not useful.

答:
Summary:

I don't think very many people can answer your query as there are some pretty big assumption hurdles present in it. I would recommend studying Functional Programming in general and Scala in particular to deeply understand the kinds of breakthroughs occurring which are strongly related to what it appears you desire.

Details:

To succinctly rephrase your question I think you may be asking:

Please tell me about a personal experience I have had where I worked
  on a problem using traditional single-threaded assumptions where I
  know that I would experience an improvement with a "magically parallelizing" compiler.

I think the challenge is the assumptions (many) required to jump from an existing assumed single-threaded code base to understanding all the different, complex and hard intricacies which are present to take the same program and accurately parallelize it via a compiler. This is a non-trivial jump, one that almost no-one can realistically make without having done both types of implementation.

Having said all of that, I do think there are some software engineering practices that might help you move closer to what you might be seeking. And what I sense you are seeking is to spend as little time as possible having to redesign your single-thread assumed code into something that can be easily parallelized. And that requires you become aware of several domains of work which will support this.

You must pick a language which naturally supports the notion of parallel code.

The language must also have libraries for which easily converting single-threaded code to be able to be multi-threaded is a simple class/method/function renaming.

You need to ensure the language BY DEFAULT supports immutability, and then strongly practice immutability within all of your single-threaded assumed software design.

If you follow all three of these practices, you will find the complexity of moving between single-threaded assumed code and parallelizing it will be dramatically reduced. Absent any one of the three practices above, you will find the hurdles to moving from single-threaded to multi-threaded to be so complex as to be not worth the orders of magnitude of extra effort required. And it's even less likely a compiler can be written to make said jumps.

And I am speaking from personal experience. I started a Java project in 2000 based on roughly the same reasoning you used above. It was an ANN/GA (Artificial Neural Network/Genetic Algorithm) distributed computing system to attempt to create a Go (game) AI. Go being quite a challenge, I started with Checkers first to ensure my system worked. For every hour of useful "single-threaded" work I did, I spent another 99 hours (no exaggeration) on technical tangents unrelated to the core goal. I eventually got my entire system working across 10 nodes. However, after having spent close to 2000 hours working on it, I was completely burned out on attempting to do the Go implementation.

I've since sat back and remained very interested in how I might be able to redo the 2,000 hours of work and reduce it to something on the order of 20-50 hours. I finally resorted to inventing my own language and libraries to see if I could solve it faster that way. Talk about a huge technical tangent, huh? :)

Right after I started generating my list of desirable requirements in 2010/Dec, a friend of mine asked me why I was doing all that work. And then he suggested I take a look at Clojure and Scala. I quickly read up on Clojure and didn't like how noisy/boilerplate-ish it felt coming from Java. I then read up on Scala. And I couldn't believe that it had over 60% of the kinds of features I wanted myself. I then purchased the newly released "Programming in Scala, 2nd Edition" and completely read the e-reader version before I got the physical copy.

I've spent all the time between then and now working very hard to grok Scala, Functional Programming and thinking exclusively in terms of immutability. It's been quite challenging to my decades of OO experience. However, I think I am finally rounding the corner on a couple of the core challenges...finally!

Will I use Scala (and Akka, Play and Scala-IDE) and completely re-create my AI system so I can continue on to my Go goal? I'm playing around with it now. I still have so much to learn and so much more confidence to gain before I'm able to code as quickly in Scala and it's libraries as I can in Java with its libraries.

Anyway, it seemed you wanted a personal story from which to draw your conclusions about the possible profitability of a "single-threaded assumed code based automagically parallelized" compiler. Hopefully, this helped.


答:
You should ignore these new languages unless they have a native VM/interpreter in at least two browsers. Only JavaScript currently complies with that criteria.

If a language doesn't have a native VM/interpreter it's inefficient. If your writing a non-toy application then you will care about being able to optimise performance heavy parts of your application. Having to use the abstracted language and hand optimised JS is a maintenance nightmare

If a language isn't natively supported in browsers then it's not future proof, it's a phase that will dissappear soon, (VBScript anyone?)

All of these abstractions are leaky. Your going to have to write or debug JavaScript in the end, and I wouldn't want to do both when I can only do JavaScript.

If your willing to maintain both JavaScript and the abstracted language in your application then you might want to consider using them

Title: How should I evaluate new browser languages?

Body:
In these days there are many projects whose aim is to bring new languages to the browser by compiling them to JavaScript. Among the others one can mention ClojureScript, CoffeScript, Dart, haXe, Emscripten, Amber Smalltalk.

I'd like to try a few of these out, but I am not sure what I should be looking for when evaluating these languages to see if they are suitable for production.

How should I evaluate a new browser language, and what are the pitfalls I should be looking for?


答:
Yes, but these problems are few and far between in the world of line-of-business apps.

My problem was solved by manually implementing a threaded solution. I had a location and many resources, and I had to calculate the time it would take for each resource to get to the location. Performing the calculations in parallel was trivial, but offered the opportunity to reduce the overall time taken from n (resources) to 1.

Of course, as the problem was trivial to implement (push each resource to a queue, which were popped by a thread pool to calculate with a simple semaphore to wait for all the resources to complete), a smart compiler wouldn't have offered much help. There is OpenMP that offers the kind of smart compilation with just a couple of pragmas, or functional programming constructs that make this kind of task-splitting easy.

Title: Are there any concrete examples of where a paralellizing compiler would provide a value-adding benefit?

Body:
Paul Graham argues that:

It would be great if a startup could give us something of the old
  Moore's Law back, by writing software that could make a large number
  of CPUs look to the developer like one very fast CPU. ...
  The most ambitious is to try to do it automatically: to write a
  compiler that will parallelize our code for us. There's a name for
  this compiler, the sufficiently smart compiler, and it is a byword for
  impossibility. But is it really impossible?

Can someone provide a concrete example where a paralellizing compiler would solve a pain point? Web-apps don't appear to be a problem: just run a bunch of Node processes. Real-time raytracing isn't a problem: the programmers are writing multi-threaded, SIMD assembly language quite happily (indeed, some might complain if we make it easier!). The holy grail is to be able to accelerate any program, be it MySQL, Garage Band, or Quicken. I'm looking for a middle ground:
 is there a real-world problem that you have experienced where a "smart-enough" compiler would have provided a real benefit, i.e that someone would pay for?

A good answer is one where there is a process where the computer runs at 100% CPU on a single core for a painful period of time. That time might be 10 seconds, if the task is meant to be quick. It might be 500ms if the task is meant to be interactive. It might be 10 hours. Please describe such a problem.

Really, that's all I'm looking for: candidate areas for further investigation. (Hence, raytracing is off the list because all the low-hanging fruit have been feasted upon.)

I am not interested in why it cannot be done. There are a million people willing to point to the sound reasons why it cannot be done. Such answers are not useful.


答:
if your program intuition is wrong you'll write your program wrong

Yup. This is the way the world is.

When I was a lad we were taught to think about how our program would work, to split it into manageable parts, and to think about how those parts would fit together. Then write these thoughts down so you wouldn't forget them. And then, you could write your program and it'd be bug-free and work correctly. At the time a lot of people programmed by sitting down and start typing, which gave dreadful results, but they got the instant gratification we desire.

So, here you're being taught to think first, code second. That the code is almost irrelevant when compared to the overall design. These things are true, these things will make you a much better programmer. You'll notice this when you leave university and have to start working on real-world applications,the ones that make your uni coursework look like mickey-mouse apps. The ones where you are no longer working with a thousand lines of code, but several million lines. Then you'll understand exactly why you need to think hard before setting finger to keyboard.

Most of the time, both me and other students have written programs
  that seemed ok and that had correct pre and post condition too. But at
  the moment of testing it was just completely wrong.

Yes, this is why he's making you do it - if you cannot think how to write a correct program, how do you expect to be able to, well, write correct programs? You can write it iteratively using a code-test-fixbugs-code-test-fixbugs approach, which is fine for small stuff, but again, get a big project and you'll spend a impressive amount of time getting it to work right.


答:
JavaScript certification is called github.

It's called write modules, maintain modules, and share modules with the community, build popularity, etc.

As a JavaScript employer I couldn't care less what certification you have, I care about either examples of github modules showing quality code or live websites/web applications show high quality code.

Title: Certifications for Javascript developers?

Body:
I'm looking for a solid and but fast paced entry in field of javascript development.

The following topics come to my mind:

Javascript advanced concepts, OOP

jQuery, jQuery-UI, jQuery-Mobile

backbone.js

node.js

BDD and/or TDD

The courses of http://www.codelesson.com seem promising.

What certificates for Javascript developers exist/can be recommended?

What other vendors can you recommend?


答:
This list could be used to evaluate a language, technology or process.

Does this language offer some benefit over what I currently use and trust?

Who else is using the technology in production and how does it seem from a user stand point?

What kind of community support does this project have? The more people using and working with something new the better your chances of getting things fixed and new features added.

What kind of learning curve does this language have for your team? The more difficult it is to pick up the greater the returns in functionality, speed, readability or maintainability must be.

Does this make sense for the project you are trying to complete? A great technology with only a few small advantages may not be worth the switch.

Lastly, give it an eye test. See how it works on a small sample to see how it really works for you and what problems you need to solve.

Specific things to look for with languages that compile to JavaScript:

Speed is a big issue with JavaScript, so testing the new language on a task vs the JavaScript you write yourself would be very helpful. You may find that the language writes faster running code than you do.

How easy is it to debug vs using strait JavaScript? It can be an issue if the generated JavaScript is to difficult to understand when things go wrong.

Check the overhead of using the included libraries, if everything is local it can be deceiving on how much code is being transferred to the client at every page load.


问:
Why hill climbing is called anytime algorithm?
From wikipedia, Anytime algorithm

In computer science an anytime algorithm is an algorithm that can
  return a valid solution to a problem even if it's interrupted at any
  time before it ends. The algorithm is expected to find better and
  better solutions the more time it keeps running.

Hill climbing

Hill climbing can often produce a better result than other algorithms
  when the amount of time available to perform a search is limited, such
  as with real-time systems. It is an anytime algorithm: it can return a
  valid solution even if it's interrupted at any time before it ends.

Hill climbing algorithm can stuck into local optima or ridge, after that even if it runs infinite time, the result won't be any better. Then, why hill climbing is called anytime algorithm?

答:
At the start of hill climbing, you already have a solution, therefore it can return a valid solution even if interrupted, fulfilling one part of the anytime requirements.

Hill climbing also normally produces better results the more the algorithm runs, although the time taken to find a better solution can approach infinity if the algorithm gets stuck. However, the definition for an anytime algorithm says that it is expected to produce better results, and we expect hill climb algorithms to produce better results, although sometimes they don't.

So an anytime algorithm:

Requires: A valid solution to be available even if the algorithm is interrupted before completion.

Expects: Improvements in solution as time goes on.

Hill climbing fulfills both the requirement and the expectation, so it can be described as an anytime algorithm.


答:
The answer to your question is hidden in the quoted piece of text:

it can return a valid solution even if it's interrupted at any time before it ends.

The important part is in the definition of valid in this context - that it satisfies all the constrains and is better or at least not worse than what you already had.

These algorithms are not called Anytime because improvement of its result is guaranteed to be a monotonously rising function. They are called so, because you can get a usable (valid, consistent, good enough...) result whenever you stop them. This even means that you can ask for a so far best result at any time, use it in your business and let the algorithm continue improving it even more (or not).

Title: Why hill climbing is called anytime algorithm?

Body:
From wikipedia, Anytime algorithm

In computer science an anytime algorithm is an algorithm that can
  return a valid solution to a problem even if it's interrupted at any
  time before it ends. The algorithm is expected to find better and
  better solutions the more time it keeps running.

Hill climbing

Hill climbing can often produce a better result than other algorithms
  when the amount of time available to perform a search is limited, such
  as with real-time systems. It is an anytime algorithm: it can return a
  valid solution even if it's interrupted at any time before it ends.

Hill climbing algorithm can stuck into local optima or ridge, after that even if it runs infinite time, the result won't be any better. Then, why hill climbing is called anytime algorithm?


问:
Options for Opensource license?
I am choosing a license for my open source software and I've learned about GPL, EBMS and BSD. GPL seems to be most popular one.

The problems are:

Would anybody kindly name a few popular opensource licenses? Since I do not see any EBMS BSD license is popular.

Are there any chart or table that have list out the advantages/disadvantages of using anyone?

Why is the GPL always the license developers choose from, what are its benefits?

答:
A few other popular open-source licenses are the Apache License and X11/MIT License.

Wikipedia has a pretty good comparison of free software and open-source (there is a difference) licenses: http://en.wikipedia.org/wiki/Comparison_of_free_software_licenses

GPL is common amongst large open-source software distributions for a variety of reasons, including maturity, comprehensiveness, and the backing of Free Software Foundation. However, it is a very comprehensive license, and can cause legal compatibility problems if you're going to be distributing your software or using GPL-licensed software in your own. See this chart to get an idea of the trickiness of working with the GPL: http://en.wikipedia.org/wiki/File:Quick-guide-gplv3-compatibility.svg

Your main concern should be how you want other people to be able to use your code, and an attached license is the current method for publishing what people are and are not allowed to do with your software, protecting you from liability if people use your software, and providing a legal grounds enforcing how you want your software to be used.

This is part of the issue with using the GPL and other highly-restrictive licenses, publishing your software with those licenses could possibly prevent people from using your software. On the flip side, very open licenses (like MIT/X11 or BSD) give users lots of freedom, but also don't give you legal recourse if your code is used in a way you don't approve of (like for commercial gain).

Title: Options for Opensource license?


答:
Is there a real-world problem that you have experienced where a "smart-enough" compiler would have provided a real benefit, i.e that someone would pay for?

At a previous employer, I worked in a group that wrote software for residential building energy simulation. Basically, each simulation run uses the past 20 years of weather (the datasets include hourly weather measurements at various airports around the world) for a building at the location and orientation of the building. This allows the user to determine which changes in insulation, heating or other things would make the biggest bang for the buck for their particular situation.

From a previous question of mine:

Individual tasks for offloading the simulation would be

- packaging a file (about 5Mb),

- uploading it to our servers,

- decomposing the package into individual simulations (each run takes about 30-120 seconds and is totally parallelizable), the number of simulations is a function of the number of options selected by the user (insulation, building orientation, etc) and the worst case of selecting every possible option would result in about 1E50 simulations. Running 100 to ~1E5 simulations isn't unknown, but the majority of users will run less than 10.

- reassembling the completed simulations and downloading the now much larger file.

Source

The budget cuts did indeed come and I'm no longer there, so the question over at scicomp is moot.

An architect/engineer running a large number of simulations to determine the effective energy consumption for a housing development (and most effective insulation/heating/cooling schemes for houses at various orientations) could easily spend a couple weeks on an 8 core machine with all the various combinations. Or, it could be parallelized and run in a couple of minutes on the 42,440 core cluster (downloading the results might take a day).


问:
is there a formal algebra method to analyze programs?
Is there a formal/academic connection between an imperative program and algebra, and if so where would I learn about it?

The example I'm thinking of is:

```<code>if(C1) { A1(); A2(); }
if(C2) { A1(); A2(); }
</code>```

Represented as a sum of terms:

```<code>(C1)(A1) + (C1)(A2) + (C2)(A1) + (C2)(A2) = (C1+C2)(A1+A2)
</code>```

The idea being that manipulation could lead to programatic refactoring - "factoring" being the common concept in this example.

答:
As others have pointed out there is a lot of existing research into formal methods for program analysis. A former colleague of mine is an active researcher in this area and his page gives several pointers on where to start.

There are several keywords in that area, each of which basically spawns a whole research area itself. Hence, your question cannot be fully answered here, but we can at least provide some direction. For the most part, these approaches are separated into three branches:

Algebraic semantics are one way of giving semantics to programming languages via different algebras. See the wikipedia article for an overview. Things like Kleene algebras or Omega algebras fit in there.

Operational semantics are quite popular calculi to model behaviors (for example, the lambda calculus, or LISP)

Denotational semantics rely on a fitting domain. They include, for example, approaches rooted in predicate or linear logic (think Prolog or more advanced languages like CHR).

And just like in physics we are also interested in unifying these branches, at which point you enter the realms of the unified theories of programming.

Sorry for not giving a specific answer to the question, but there's enough material available for all of this to keep you busy for a few decades, and unless a desired application is in mind it's not really possible to make a choice from these.


问:
Do ORMs enable the creation of rich domain models?
After using Hibernate on most of my projects for about 8 years, I've landed on a company that discourages its use and wants applications to only interact with the DB through stored procedures.

After doing this for a couple of weeks, I haven't been able to create a rich domain model of the application I'm starting to build, and the application just looks like a (horrible) transactional script.

Some of the issues I've found are:

Cannot navigate object graph as the stored procedures just load the minimum amount of data, which means that sometimes we have similar objects with different fields. One example is: we have a stored procedure to retrieve all the data  from a customer, and another to retrieve account information plus a few fields from the customer.

Lots of the logic ends up in helper classes, so the code becomes more structured (with entities used as old C structs).

More boring scaffolding code, as there's no framework that extracts result sets from a stored procedure and puts it in an entity.

My questions are:

has anyone been in a similar situation and didn't agree with the store procedure approach? what did you do?

Is there an actual benefit of using stored procedures? apart from the silly point of "no one can issue a drop table".

Is there a way to create a rich domain using stored procedures? I know that there's the possibility of using AOP to inject DAOs/Repositories into entities to be able to navigate the object graph. I don't like this option as it's very close to voodoo.

Conclusion

First, thank you all for your answers. The conclusion that I've arrived is that ORMs don't enable the creation of Rich Domain models (as some people mentioned), but it does simplify the the amount of (often repetitive) work. The following is a more detailed explanation of the conclusion, but is not based on any hard data.

Most applications request and send information to other systems. To do this, we create an abstraction in the model terms (e.g. a business event) and the domain model sends or receives the event. The event usually needs a small subset of information from the model, but not the whole model. For example in a online shop, a payment gateway requests some user information and the total to charge a user, but doesn't require the purchase history, available products, and all the customer base. So the event has a small and specific set of data.

If we take the database of an application as an external system, then we need to create an abstraction that allows us to map the Domain Model entities to the database (as NimChimpsky mentioned, using a data-mapper). The obvious difference, is that now we need to handcraft a mapping for each model entity to the database (either a legacy schema or stored procedures), with the extra pain that, since the two are not in sync, one domain entity might map partially to a database entity (e.g a UserCredentials class that only contains username and password is mapped to a Users table that has other columns), or one domain model entity might map to more than one database entity (for example if there's a one-to-one mapping on the table, but we want all the data in just one class).

In an application with a few entities, the amount of extra work might be small if there's no need to transverse the entities, but it increases when there's a conditional need to transverse the entities (and thus we might want to implement some kind of 'lazy loading'). As an application grows to have more entities, this work just increases (and I have the feeling that it increases non-linearly). My assumption here, is that we don't try to reinvent an ORM.

One benefit of treating the DB as an external system, is that we can code around situations in which we want 2 different versions of an application running, in which each application has a different mapping. This becomes more interesting in the scenario of continuous deliveries to production... but I think this is also possible with ORMs to a lesser extent.

I'm going to dismiss the security aspect, on the basis that a developer, even if he doesn't have access to the database, can obtain most if not all the information stored in a system, just by injecting malicious code (eg. I can't believe I forgot to remove the line that logs the credit card details of the customers, dear lord!).

Small update (6/6/2012)

Stored procedures (at least in Oracle) prevent doing anything like continuous delivery with Zero downtime, as any change to the structure of the tables will invalidate the procedures and triggers. So during the time that the DB is being updated, the application will be down too.
Oracle provides a solution for this called Edition-Based Redefinition, but the few DBAs I've asked about this feature mentioned that it was poorly implmented and they wouldn't put it in a production DB.

答:
Is there an actual benefit of using stored procedures?

In the financial world (and places where Sarbanes-Oxley compliance is required), you need to be able to audit systems to ensure that they do what they are supposed to do. In these cases, it is much easier to ensure compliance when all data access is through stored procedures. And when all ad-hoc SQL is removed, it is much harder to hide things. For an example of why this would be a "good thing", I refer you to Ken Thompson's classic paper Reflections on Trusting Trust.


答:
Real-world experience is always the best way to learn, but often times you do need some formal training to either get your started, or at least get you pointed in the right direction.  People who are already familiar with programming and development often forget that it can be difficult for someone new to the profession to just "jump in" and you can't learn how to code just by staring at someone else's code (which can also lead to blind copy/pasting of other people's code without truly understanding how it works).

I can vouch for CodeLession.  They have a good range of courses from beginner to expert, with real instructors leading the course (not just a canned set of YouTube videos) and available to answer questions.  Very often the instructors are experts in the particular field (i.e. jQuery core contributors teaching jQuery courses).


问:
Getting started with ClojureScript and Google Closure
I would like to investigate whether ClojureScript, with the associated Google Closure library is a reasonable tool to build modern, in-browser, Javascript applications.

My current Javascript stack consists of jQuery, Backbone and RequireJS with the possible additions of some widgets libraries like jQueryUI or KendoUI. So it will be quite a big leap (I already know how to work in Clojure, although I have little experience).

What is a good roadmap to do so? Should I learn the Google Closure library first, or can I grasp it together with ClojureScript?

One thing I am concerned about is the overall application structure. Backbone is rather opinionated on how to organize your application. I am not sure whether Google Closure also includes some components to help with the design of the application. And, if this is the case, I do not know how to tell whether this structure will port to ClojureScript or a ClojureScript application will require a different organization anyway, and only use - say - the widgets and DOM manipulation features of Closure.

答:
To add to the above comments, but Rich Hickey goes into the relationship between ClojureScript and Google Closure tools in his intro of ClojureScript. http://blip.tv/clojure/rich-hickey-unveils-clojurescript-5399498

Basic gist is in the comments:

ClojureScript is a compiler for Clojure that emits JavaScript ... and is design to emit ... code [that] is compatible with the advanced compilation mode of the Google Closure optimizing compiler.


答:
GPL (copyleft) supporters are indeed most vocal ones. But I wouldn't agree that the GPL is the most popular license, if you actually count how popular software which uses given license is. Consider how many of the following you use every day.

Firefox — Mozilla Public License

Chrome (Webkit, V8) — BSD

Apache HTTP server  — Apache License

nginx; ligHTTPd — both BSD

Eclipse Platform and most apps — Eclipse Public License

Python — Python License

Ruby — Ruby License or BSD

PHP — PHP License

SVN — Apache License

OpenSSL — Apache License / BSD

OpenSSH — BSD

All of above have open source, non-copyleft licenses.

Difference is, that if you create derived work incorporating non-copyleft licensed code, you can choose any license you want for the code you wrote. On the other hand if you create derived work incorporating even a smallest part of copyleft licensed code, whole thing must be licensed under that copyleft license. Hence copyleft licenses are sometimes referred to as "viral".

Title: Options for Opensource license?

Body:
I am choosing a license for my open source software and I've learned about GPL, EBMS and BSD. GPL seems to be most popular one.

The problems are:

Would anybody kindly name a few popular opensource licenses? Since I do not see any EBMS BSD license is popular.

Are there any chart or table that have list out the advantages/disadvantages of using anyone?

Why is the GPL always the license developers choose from, what are its benefits?


答:
I went through this when deciding how to release software at my company.  I narrowed it down to the GPL, LGPL, BSD, and Apache.

--

The GPL was a viral licence... meaning any modifications to the software had to be released  with code if released at all, and any products that rely on it (*sometimes) needed to be released as GPL

The LGPL was similar, but was more permissible with regards to being used in other non-GPL software.

The BSD license is super simple, and to the point.   Do anything you want. Don't hold me liable.  Keep this notice.

The Apache license is like the BSD license, except it appears to be written by legal professionals in a more modern way (which, sadly, matters).  It covers intellectual property ownership and liability issues a little more comprehensively.

--

I wanted no barriers to people using my software, but I wanted the most protection and clarity about who owns it.  Free Software is not my religion, so using the GPL was not a necessity.  (If you are really adamate about the ideals behind the "free software" movement, then the GPL makes a lot of sense).  Note: "Free Software" and "Open Source" have a very different meaning.

I concluded that it would be cool if people used my software for commercial and/or closed source products, and I liked the legal crispness of it, so I opted for the Apache License.

Title: Options for Opensource license?


答:
Unit tests serve several related purposes:

Verify that requirements are being met;

Develop more precise specifications for the code;

Test functional units in isolation;

Make regression testing easier (i.e., make sure you don't break working code).

Verify that requirements are being met

For example, I'm working on some code to display transaction history for a bank account.  I have a requirement that if I get a history record where fee, escrow, or interest amounts are greater than 0, I break those out into separate entries with their own transaction codes and descriptions.  One method in one class is responsible for this, so I write code that calls that method directly (or, if that particular method isn't publicly visible, I call the method that calls the method under test) with known inputs for each case, and then check the results for each of those inputs to verify that the right sub-transactions have been created, with the right data.

Develop more precise specifications for the code

As you're developing your unit tests, you will inevitably find that the requirements do not cover all possible cases.  For example, I have another requirement that says if the transaction code is X, do one thing, and if it's Y, do something else.  But there's nothing telling me what to do if the transaction code isn't either X or Y.  It's a hole in the specification that needs to be filled, in this case by the architect.  It's a good way of checking your work.

In a way, the unit test becomes the specification for the code.

Test functional units in isolation

This is a biggie.  Unit testing allows you to test your code as you're writing it; you don't have to wait until all the pieces are in place before testing can begin.  If you're testing a piece of code that relies on another class or method, you can write up a dummy implementation of that class or method that returns known values or behaves in a known manner, so that you can test specific scenarios.

It also encourages you to factor your code more aggressively, reducing dependecies between components, which makes the code easier to maintain and extend.

Make regression testing easier

The nightmare scenario is releasing a patch that breaks working code.  By running unit tests as part of every build, you guard against accidental breakage because the associated test will fail.  You can then analyze the failure and see if the break is real (i.e., someone coded in a bug) or if the requirement/specification changed, and adjust the unit test accordingly.

Title: What is the objective of unit testing?

Body:
Possible Duplicate:

  Is unit testing or test-driven development worthwhile?

I've been working with C# for the last 2 years, and I've never done any unit testing. I just need to know what the objective of unit testing is. What kind of results do we expect from unit testing? Is code quality checked by unit testing? In my view, unit testing is the job of testers; if that is true, then as a developer why would I need to write test code if the tester does the unit testing? Why should I write extra code for testing? Do I need to maintain a separate copy of a project for unit testing?


答:
There are no procedural if/else features that allow me to say, for instance, if Country is USA, then Zipcode cannot be empty.

For this, you'll want to use XQuery. At one previous employer, we worked with government forms, and the newer forms were to be submitted via XML. The "edit tests" (which included things like zip code cannot be empty for US addresses) were expressed as XQueries and XPath expressions. Because many used dates for validation, it turns out that one cannot use the built-in validation in .NET (you need XPath 2 for dates, and that's not in .NET) and have to use external parsers (we chose Altova's).


问:
How to store a list of Objects that might change in future?
I have set of Objects of the same class which have different values of their attributes.
and I need to find the best match from a function under given scenarios out of these objects.

In future these objects might increase as well.

Quite similar to the way we have Color class in awt.
we have some static color objects in the class with diff rgb values.
But in my case say, I need to chose the suitable color out of these static ones based on certain criteria.

So should I keep them in an arrayList or enum or keep them as static vars as in case of Colors.
because I will need to parse through all of them and decide upon the best match.
so I need them in some sort of collection.
But in future if I need to add another type I will have to modify the class and add another list.add(object) call for this one and then it will violate the open-close principle.
How should I go about it ?

EDIT:
To be more precise I have a roughly 7-8 branches of  restaurants which wont increase that much..may be by 3-4 in few years and I need a function that will return the nearest Restaurant satisfying few other criteria.

and For that I need to parse through all of them to decide which one suits the customer the most.

答:
It really depends on how many objects you have and how many dimensions each object is free to move in.

Finding the closest match for a mutli-dimensional value is something which lends itself to spatial databases and space partitioning trees e.g. a k-d tree. Of course if you only have a few dozen objects then just checking them all is also an option.

I think your analogy of the Color class may be throwing you slightly as (AFAIK) I don't think Color provides any nearest matching capabilities anyway and also you probably need to leave the RGB colour space to define a useful distance metric


答:
Beside the good thoughts, Dirk Gadsden, vartec and gahooa shared, I will advocate for popular licenses per se.

If somebody uses your software, and sees: GPL (or BSD, apache, mozilla)-license, he might not need to read it, understand it and accept it, because he already knows it.

If you bundle a product from 4 external libs, all having a different license, reading through all that stuff isn't a joy. Your new Beer-&-Postcard license might be a funny thing, but is one more thing to know. Don't do it.

Popular licenses have been proofread and maybe survived legal battles.

Title: Options for Opensource license?


答:
What about video transcoding? That is a very CPU hungry operation, and even though there are some multithreaded encoders, the majority are single threaded and are not so quick. </p>

<p>It's a big enough problem that people make and buy expensive hardware to do it for the cpu. </p>

Body:
What about video transcoding? That is a very CPU hungry operation, and even though there are some multithreaded encoders, the majority are single threaded and are not so quick.

It's a big enough problem that people make and buy expensive hardware to do it for the cpu.


答:
At least as far as I know, the first implementation of MVC was in Smalltalk. It was definitely present in Smalltalk-80. Though I don't have any documentation handy to prove it, I believe it (or something quite similar anyway) had been in Smalltalk for a few years by then.

Most OO GUI frameworks have included at least some variant of MVC. I'm not sure, however, exactly what "superset" would mean in this case. It's a little hard to say whether any given variant is a superset, subset, or peer of MVC, but I'd tend to consider most of them peers.

In any case, many (most?) of these have been used for desktop development, not web development. Thanks to some old AT&T patents, most windowing systems require programs to be able to re-generate views on demand. This (almost) forces at least some degree of separation between code that maintains the current state (the model) and code that displays that state (the view). That still leaves a lot of room for variation in 1) the degree to which the controller functionality is isolated, and 2) the exact details of where to draw the lines between each of the major pieces.

Title: Does MVC apply only to web

Body:
It is almost and instantaneous whenever I talk to developers about Model View Controller (MVC) they say you make a request to a url the server builds a entity (MODEL) and provides you with visual representation of that model.

So does this mean MVC is only for the web or have I been meeting people who are just developers who employ MVC for writing web applications?

Are there usages for MVC on desktop style applications?

I for one am new to paradigm and would like to know of any super-set to MVC


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

This question has two parts...

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

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

Update:

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

- specific server side programming optimizations

- test labs

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

答: Yes, of course! And making them working using only a sheet of paper and a pencil will effect in ever more efficient code (and obviously more portable). Of course, only if pencils aren't too sharp.  </p>

ContentLicense: CC BY-SA 2.5


问:
Implementing a ILogger interface to log data
I have a need to write data to file in one of my classes.

Obviously I will pass an interface into my class to decouple it.

I was thinking this interface will be used for testing and also in other projects.

This is my interface:

```<code>//This could be used by filesystem, webservice
public interface ILogger
{
   List<string> PreviousLogRecords {get;set;}
   void Log(string Data);
}

public interface IFileLogger : ILogger
{
  string FilePath;
  bool ValidFileName;
}

public class MyClassUnderTest
{
  public MyClassUnderTest(IFileLogger logger) {....}
}

[Test]
public void TestLogger()
{
   var mock = new Mock<IFileLogger>();
   mock.Setup(x => x.Log(Is.Any<string>).AddsDataToList()); //Is this possible??

   var myClass = new MyClassUnderTest(mock.Object);

   myClass.DoSomethingThatWillSplitThisAndLog3Times("1,2,3");

   Assert.AreEqual(3,mock.PreviousLogRecords.Count);

}
</code>```

This won't work I don't believe as nothing is storing the items so is this possible using Moq and also what do you think of the design of the interface?

答:
Well, I'm taking a bit of a stab at your first question here, since I'm not clear on what "AddsDataToList" means and your code wouldn't compile either way, but it appears what you're looking to do is use Moq's callback functionality.  Something along the lines of:

```<code>mock.Setup(x => x.Log(Is.Any<string>()).Callback((string s) => mock.Object.PreviousLogRecords.Add(s));
</code>```

As for the design of the logger (and apart from the appropriate comment that lots of loggers already exist), it seems reasonable enough, although I personally like to avoid exposing collections as properties.  Reason being, the call syntax gets kind of Law-Of-Demeter-violation-ish.

```<code>logger.PreviousLogRecords.Count
</code>```

or

```<code>if(logger.PreviousLogRecords[0].Equals("asdf"))
</code>```

Anyway, on the first count, if you update your post a bit, I can probably comment more specifically on what you're trying to do with Moq.

Body:
Well, I'm taking a bit of a stab at your first question here, since I'm not clear on what "AddsDataToList" means and your code wouldn't compile either way, but it appears what you're looking to do is use Moq's callback functionality.  Something along the lines of:

mock.Setup(x => x.Log(Is.Any<string>()).Callback((string s) => mock.Object.PreviousLogRecords.Add(s));

As for the design of the logger (and apart from the appropriate comment that lots of loggers already exist), it seems reasonable enough, although I personally like to avoid exposing collections as properties.  Reason being, the call syntax gets kind of Law-Of-Demeter-violation-ish.

logger.PreviousLogRecords.Count

or

if(logger.PreviousLogRecords[0].Equals("asdf"))

Anyway, on the first count, if you update your post a bit, I can probably comment more specifically on what you're trying to do with Moq.


答:
Simply store your objects in an ArrayList of type Object.  Then, you can add any type of object to that collection.  It can be a mixed, aka heterogeneous collection.

```<code>List<Object> mixedList = new ArrayList<Object>();
list.add(new String("I'm a string"));
list.add(new Integer(1));
list.add(new Long(1l));
</code>```

Title: How to store a list of Objects that might change in future?

Body:
I have set of Objects of the same class which have different values of their attributes.
and I need to find the best match from a function under given scenarios out of these objects.

In future these objects might increase as well.

Quite similar to the way we have Color class in awt.
we have some static color objects in the class with diff rgb values.
But in my case say, I need to chose the suitable color out of these static ones based on certain criteria.

So should I keep them in an arrayList or enum or keep them as static vars as in case of Colors.
because I will need to parse through all of them and decide upon the best match.
so I need them in some sort of collection.
But in future if I need to add another type I will have to modify the class and add another list.add(object) call for this one and then it will violate the open-close principle.
How should I go about it ?

EDIT:
To be more precise I have a roughly 7-8 branches of  restaurants which wont increase that much..may be by 3-4 in few years and I need a function that will return the nearest Restaurant satisfying few other criteria.

and For that I need to parse through all of them to decide which one suits the customer the most.

Body:
Simply store your objects in an ArrayList of type Object.  Then, you can add any type of object to that collection.  It can be a mixed, aka heterogeneous collection.

List<Object> mixedList = new ArrayList<Object>();
list.add(new String("I'm a string"));
list.add(new Integer(1));
list.add(new Long(1l));


答:
Comparing to other open-source licenses - GPL is most restrictive:

To use GPL for your application - you should use GPL and LGPL libraries only.

If your application is under GPL - than any proprietary software can not use it (be compiled with) or any part of your application.

Commercial software can execute your GPL application, but it there is restrictions about delivery.

Several version exists: GPL, GPL v2, GPL v3(significant changes).

Most software of Linux distributions is GPL/LGPL.

BSD, Apache - is less restrictive, and used by huge numbers of libraries.

Note: You can use more than one license. Like, you can publish your app under GPL and additionally sell commercial licenses ("Ext JS 4" library use this approach).

Title: Options for Opensource license?


问:
Common practice in handling bounce message
At now I mainly create a mail account separately  (with different domain name eg.noreply@example.com) and i add this mail as one return path. So the bounce message will only go to that mailbox and i parse the mail message one by one to check the failure receipent and the error code, then i convert the error code to the actual error message.

Finally, the error message and the fail receipent's mail  are post to my system and let my system user check the bounce information.

Is it a common practice? Since i am worry about the mail other from bounce message have sent to my mail box, that would be a disaster if i parse them without filter them out, but how can i filter out between bounce message and normal mail?

Thank you for any kind of help.

答: If you want to be sure that the mail you are filtering is truly a bounce back then include some sort of identifying information in the email that you can verify before you notify users. This could be something like a reference number. With this reference number you can match it up with other information you already have, like time sent and to whom, to further verify the bounced email.</p>


问:
PHP, when to use iterators, how to buffer results?

When is it best to use Iterators in PHP, and how can they be implemented to best avoid loading all objects into memory simultaneously?

Do any constructs exist in PHP so that we can queue up results of an operation for use with an Iterator, while again avoiding loading all objects into memory simultaneously?

An example would be a curl HTTP request against a REST server

In the case of an HTTP request that returns all results at once (a la curl), would we be better off to go with streaming results, and if so, are there any limitations or pitfalls to be aware of?

If using streaming, is it better to replace curl with a PHP native stream/socket?

My intention is to implement Iterators for a REST client, and separately a document ORM that I'm maintaining, but only if I can do so while gaining benefits from reduced memory usage, increased performance, etc. Thanks in advance for any responses :-)

答:
When is it best to use Iterators in PHP

Use an iterator anytime you want to access a "collection" of data (like an array) but in an object oriented way. It is nice to be able to use object access but also perform a "foreach" on that same object.

Do any constructs exist in PHP so that we can queue up results of an operation for use with an Iterator, while again avoiding loading all objects into memory simultaneously?

Nothing intrinsic; however, you just need to write sort of a paginator. You don't load the collection object up with 10,000 objects. You load like 20 or 50 or 100, then you skip ahead when you've exhausted the current set.

The cool thing about using an object here is that all of this is happening behind the scenes. I mean, you have to program it; however, once it works and you become a consumer of this object, you never again have to worry about the internals. Just use it. Just add this to the list of benefits as well.

Another benefit is that you can now test these collections. Sure, you could theoretically test an array; however, an array can't exhibit behaviors like an object can. Plus with an iterator, you still get (most of) the benefits of a simple array.

...is it better to replace curl with a PHP native stream/socket?

If you use something that is streams compatible (like file_get_contents), and you use stream context, there is little that you can't do. In fact, since not everyone has cURL, this may be the more portable option.


问:
Looking for a better Factory pattern (Java)
After doing a rough sketch of a high level object model, I am doing iterative TDD, and letting the other objects emerge as a refactoring of the code (as it increases in complexity). (That whole approach may be a discussion/argument for another day.)

In any case, I am at the point where I am looking to refactor code blocks currently in an if-else blocks into separate objects. This is because there is another value combination which creates new set of logical sub-branches.

To be more specific, this is a trading system feature, where buy orders have different behavior than sell orders. Responses to the orders have a numeric indicator field which describes some event that occurred (e.g. fill, cancel). The combination of this numeric indicator field plus whether it is a buy or sell, require different processing buy the code.

Creating a family of objects to separate the code for the unique handling each of the combinations of the 2 fields seems like a good choice at this point.  The way I would normally do this, is to create some Factory object which when called with the 2 relevant parameters (indicator, buysell), would return the correct subclass of the object. Some times I do this pattern with a map, which allows to look up a live instance (or constructor to use via reflection), and sometimes I just hard code the cases in the Factory class.

So - for some reason this feels like not good design (e.g. one object which knows all the subclasses of an interface or parent object), and a bit clumsy.

Is there a better pattern for solving this kind of problem?  And if this factory method approach makes sense, can anyone suggest a nicer design?

答:
Your approach sounds good to me.  Philosophically, while your factory does know about every subclass, it doesn't know that it knows.  In other words, in the future subclasses might be generated elsewhere, in places your factory knows (and cares) nothing about.  At the other end, the users of these subclasses neither know nor care where they came from.  Might be from the factory, might be from somewhere else.

Your bad feeling on this is that you are replacing a simple mechanism with a fancy one, and you don't (yet) really need the power you are getting.  You may indeed be wasting your time.  But if your system grows, you might have several factories, and many other objects might create these subclasses, including the subclasses themselves.  So long as your factory does not need to know about all the subclasses, and so long as your "consumers" don't need to know which factory, if any, they came from, your design is sound.  Everything is properly encapsulated and polymorphic.

One other thing:  in Java more so than in other languages, a subclass often works better than putting a switch in the base class.  In Java I'll subclass anything if I need a slightly different behavior.  In C#, I'll go to a lot of trouble to make one class highly flexible with extra fields and extra constructor parameters.  A new Java class can be created in a small block of code with no references to it elsewhere--a local or anonymous class.  In C# the new class has to be placed well away from the only spot to reference it as anything but its base class--and it may be several levels of base--or interface.


问:
How do I capture information from a website that doesn't provide an API?
Do you know any good tutorials, frameworks, anything that can help me to write code that captures information from a website that don't have a public API, or hasn't been written in a RESTful way?

I've heard there's a Ruby gem that simulates a browser, but I forgot its name and couldn't find any information about it anymore.

答:
Well, for Java you can use the apache HttpClient library, which will allow you to (easily) make http calls and cope with sessions and the like.  Likewise, .NET has an class called... HttpClient.

Consuming the response, if you don't have some sort of predefined arrangement, will require you to set some expectations (it can't really be TOTALLY arbitrary) and do some parsing to glean information from the response you get.

I can't speak to Ruby, but I'm guessing there's something similar in most modern languages.


问:
Where Can I List My Opensource Project?

Possible Duplicate:

  How can I get the word out about a new (open-source) library I've developed?

I have hosted my latest project, a JVM-based MIDI processor/API called Mjdj MIDI Morph, on Github (here and here). Now I need to bring some interest to it, even if it's negative interest (so I can improve it). I've looked up open source list on Google and end up with such things as this page on Wikipedia, which makes it quite clear that they don't want your project if it's new. Where should I list my project? Short of adwords and talking it up in forums and trade shows, where should I submit my URLs?

答: How about a Wikipedia page that is directly topically related to what your software does?  I have a simulation library that supplies routines for studying genetics, so I put a link on the page for "linkage disequilibrium," since my software allows you to model it.</p>

Title: Where Can I List My Opensource Project?


答:
Go with an ArrayList.  You can modify it freely and search it fast.  You won't violate the open-close principle.

Exception:  if you have a lot of entries, say over a million, and you're running at 80%+ on your CPU and want more speed, things get interesting.  Large arrays can do odd things to memory in this situation if you are not careful, and ArrayList will do awkward things when you're not looking.  Also, if you want to spot the closest object in the list to some arbitrary object--say, the closest color you have to something with an RGB of 233.121.55--you'll need a multi-dimensional storage system.  Say a quadtree or, with colors an octree.  (If your colors have an alpha component, I suppose you'd need a hexadecimaltree.)

But I'm betting the ArrayList will work just fine for you.  You can scan 100,000 entries in an ArrayList in the blink of an eye.


问:
How to setup users for desktop app with SQL Azure as backend?
I'm considering SQL Azure as DB for a new application I'm developing. The reason I want to go with Azure is because I don't want to have to maintain yet another database(s) and I want my users to be able to access the data from anywhere. The problem is that I'm not clear regarding how to users will connect. The application is a basic CRUD type of windows app.

I've read that you need to add your IP to SQL Azure's firewall to connect to it, but I don't know if it's only for administration purposes only. Can anyone clarify if anyone (anywhere) can access the data with the proper credentials?

Which of the following scenarios would work best (if at all)?

A) Add each user to SQL Azure and have the app connect directly to Azure as if it was connecting to SQL Server

B) Add an anonymous user SQL Azure and pass the real user's password/hash with every call so the Azure database can service the requests accordingly.

C) Put a WCF service in between so that it handles the authentication stuff. The service will only serve the appropriate information to the user given his/her authentication and SQL Azure would be open to the service exclusively.

D) - ideas are welcomed -

This is confusing because all Azure examples I see are for websites. I have a hard time believing SQL Azure wouldn't handle the case of desktop apps connecting to it. So what's the best practice?

答:
SQL Azure does require each client's IP to be registered in Azure's firewall.

In this case the only option is to have an intermediary service (WCF service for my purposes) that accepts user's requests, authenticates them, and provides the data. This service in turn would communicate with SQL Azure.


答:
There are a variety of Ruby libraries for parsing (X)HTML into a structured format. Two of the oldest and most popular libraries for this are Hpricot and Nokogiri. These libraries provide a variety of capabilities for working with HTML data.

A few things to keep in mind when doing this:

Respect copyright! site authors likely won't be happy about people scraping data from their sites and using it without permission. Ask first!

Changes can break things easily. If they change the structure of your site, your code will likely blow up if not written properly.

Title: How do I capture information from a website that doesn't provide an API?

Body:
Do you know any good tutorials, frameworks, anything that can help me to write code that captures information from a website that don't have a public API, or hasn't been written in a RESTful way?

I've heard there's a Ruby gem that simulates a browser, but I forgot its name and couldn't find any information about it anymore.


问:
How to keep your third party libraries up to date?
Let's say that I have a project that depends on 10 libraries, and within my project's trunk I'm free to use any versions of those libraries. So I start with the most recent versions. Then,  each of those libraries gets an update once a month (on average). Now, keeping my trunk completely up to date would require updating a library reference every three days.

This is obviously too much. Even though usually version 1.2.3 is a drop-in replacement for version 1.2.2, you never know without testing. Unit tests aren't enough; if it's a DB / file engine, you have to ensure that it works properly with files that were created with older versions, and maybe vice versa. If it has something to do with GUI, you have to visually inspect everything. And so on.

How do you handle this? Some possible approaches:

If it ain't broke, don't fix it. Stay with your current version of the library as long as you don't notice anything wrong with it when used in your application, no matter how often the library vendor publishes updates. Small incremental changes are just waste.

Update frequently in order to keep change small. Since you'll have to update some day in any case, it's better to update often so that you notice any problems early when they're easy to fix, instead of jumping over several versions and letting potential problems to accumulate.

Something in between. Is there a sweet spot?

答:
I use NuGet to keep my third party libraries up to date.

When a friend, coworker, or blog notifies me that one of my 3rd party DLLs is out of date, NuGet makes it very easy to update it.


问:
Why was Tanenbaum wrong in the Tanenbaum-Torvalds debates?
I was recently assigned reading from the Tanenbaum-Torvalds debates in my OS class. In the debates, Tanenbaum makes some predictions:

Microkernels are the future

x86 will die out and RISC architectures will dominate the market

(5 years from then) everyone will be running a free GNU OS

I was a one year old when the debates happened, so I lack historical intuition. Why have these predictions not panned out? It seems to me, that from Tanenbaum's perspective, they're pretty reasonable predictions of the future. What happened so that they didn't come to pass?

答: Production became cheaper, x86 came so close to the price of RISC, that it wasn't feasible anymore to use it. There was also a small vendor lock-in.</p>


答:
Not sure.

Half-right.  Today's "x86" chips are RISC under the hood, with basically a "CISC interface".  x86 didn't die out because Intel had enough market share and enough revenue to make that transition and get it right before other RISC solutions captured significant market share from them.

Two main reasons: compatibility and usability.

Again, the existing systems (Windows and, to a lesser extent Mac OS) have a very large installed base.  That means lots of users using lots of programs.  Free GNU OSes can't duplicate that.  The WINE project has done a lot of work in that direction, but it's still no substitute for an actual Windows system, and the WINE developers don't even try to claim that it is.  People don't want to use an OS that won't run their favorite programs, no matter how theoretically awesome it is.  (And without an installed user base, no one wants to develop for the system. It's a chicken-and-egg problem.)

And then we get to usability.  My mom has a Windows system.  She can use it just fine for her purposes.  Everything she needs to work with her computer is available from the Windows interface, and if I said the words "command line" to her, she wouldn't even know what I'm talking about.  As far as I know, it's still not possible to do that on any free GNU OS.  In fact, Linux is so hard to work with that even the greatest of the community demigods have serious troubles with simple tasks sometimes.  And they never seem to "get it" and work to fix the issues, which is why they never gain market share.  (The linked article should be required reading for anyone who ever tries to produce any mass-market program!)

Title: Why was Tanenbaum wrong in the Tanenbaum-Torvalds debates?

Body:
I was recently assigned reading from the Tanenbaum-Torvalds debates in my OS class. In the debates, Tanenbaum makes some predictions:

Microkernels are the future

x86 will die out and RISC architectures will dominate the market

(5 years from then) everyone will be running a free GNU OS

I was a one year old when the debates happened, so I lack historical intuition. Why have these predictions not panned out? It seems to me, that from Tanenbaum's perspective, they're pretty reasonable predictions of the future. What happened so that they didn't come to pass?


答:
1)  He was wrong on the microkernels.  To my understanding the need for speed requirement trumps the separation of concerns enforced in microkernels, at least in the Linux kernel.

2) The predominant architecture in tablets and mobile phones is ARM which is a RISC instruction set.  Even Windows has been ported.

3) Everyone does not run a free GNU OS.  This is primarily because of patents and backward compatibility. Those not wanting Windows frequently choose OS X.