答:
First I wouldn't cause my production code to fail by throwing an exception.  Which leads to the second point.  My first failing code would be to use a magic number, either zero or something else.  The test for non-movement would then have a small, but non-zero of passing when it wasn't supposed to -- which is fine, that's in part why you have more than one test.

So, if your implementation had been

```<code>public void MoveY(double yDisplace){
  Y=0;
}
</code>```

Your test would have failed. Further tests would depend upon you seeing a way to break the existing code -- i.e you identify a problem not covered by the existing test or code.  In this case, it doesn't actualy move, so the next test, Move_Moves, would be to see if it does, get your red light and then fix the code.  The next step would be to realize that your initial test is really unnecessary, it's not even really a special case of your Move_Moves test: you would be testing that beforeY + yDistance = afterY, which covers zero just as effectively as 1.2.  So you delete the test.

Only if you have a more complex function, where zero could possibly be treated differently than 1.2 or 42, would you need to have test both to see if it moves the right amount, and that it doesn't move for zero.  Unproductive test should be removed just as any other code.

Which is my final point -- test are ways to identify how things can go wrong, and make sure that your production code has those ways covered both now, and in the future.  The reason to write the test first is to help you identify the edge cases before you put the code into production and to verify that your solution correctly handles them, you keep the test around to avoid rgression.  If a test won't help with either of those, don't write a test.

Title: What if I can't make my unit test fail in "Red, Green, Refactor" of TDD?

Body:
So let's say that I have a test:

```<code>@Test
public void MoveY_MoveZero_DoesNotMove() {
    Point p = new Point(50.0, 50.0);
    p.MoveY(0.0);
    Assert.assertAreEqual(50.0, p.Y);
}
</code>```

This test then causes me to create the class Point:

```<code>public class Point {
    double X; double Y;
    public void MoveY(double yDisplace) {
        throw new NotYetImplementedException();
    }
}
</code>```

Ok.  It fails.  Good.  Then I remove the exception and I get green. Great, but of course I need to test if it changes value.  So I write a test that calls p.MoveY(10.0) and checks if p.Y is equal to 60.0.  It fails, so then I change the function to look like so:

```<code>public void MoveY(double yDisplace) {
    Y += yDisplace;
}
</code>```

Great, now I have green again and I can move on.  I've tested not moving and moving in the positive direction, so naturally I should test a negative value.  The only problem with this test is that if I wrote the test correctly, then it doesn't fail at first.  That means that I didn't fit the principle of "Red, Green, Refactor."

Of course, This is a first-world problem of TDD, but getting a fail at first is helpful in that it shows that your test can fail.  Otherwise this seemingly innocent test that is just passing for incorrect reasons could fail later because it was written wrong.  That might not be a problem if it happened 5 minutes later, but what if it happens to the poor-sap that inheirited your code two years later.  What he knows is that MoveY does not work with negative values because that is what the test is telling him.  But, it really could work and just be a bug in the test.

I don't think that would happen in this particular case because the code sample is so simple, but if it were a large complicated system that might not be the case.  It seems crazy to say that I want to fail my tests, but that is an important step in TDD, for good reasons.

Body:
First I wouldn't cause my production code to fail by throwing an exception.  Which leads to the second point.  My first failing code would be to use a magic number, either zero or something else.  The test for non-movement would then have a small, but non-zero of passing when it wasn't supposed to -- which is fine, that's in part why you have more than one test.

So, if your implementation had been

public void MoveY(double yDisplace){
  Y=0;
}

Your test would have failed. Further tests would depend upon you seeing a way to break the existing code -- i.e you identify a problem not covered by the existing test or code.  In this case, it doesn't actualy move, so the next test, Move_Moves, would be to see if it does, get your red light and then fix the code.  The next step would be to realize that your initial test is really unnecessary, it's not even really a special case of your Move_Moves test: you would be testing that beforeY + yDistance = afterY, which covers zero just as effectively as 1.2.  So you delete the test.

Only if you have a more complex function, where zero could possibly be treated differently than 1.2 or 42, would you need to have test both to see if it moves the right amount, and that it doesn't move for zero.  Unproductive test should be removed just as any other code.

Which is my final point -- test are ways to identify how things can go wrong, and make sure that your production code has those ways covered both now, and in the future.  The reason to write the test first is to help you identify the edge cases before you put the code into production and to verify that your solution correctly handles them, you keep the test around to avoid rgression.  If a test won't help with either of those, don't write a test.


问:
Is using something other than XML advisable for my configuration file?
I have a small tool I'm designing which would require a configuration file of some sort. The configuration file in my case is really more of a database, but it needs to be lightweight, and if needed the end-user should find it easily editable. However, it also will contain a lot of things in it. (depending on certain factors, could be 1Mb or more)

I've decided I'd rather use plain ol' text, rather than trying to use SQLite or some such. However, with using text, I also have to deal with the variety of formats. So far, my options are

XML

JSON

Custom format

The data in my file is quite simple consisting for the most part of key-value type things. So, a custom format wouldn't be that difficult... but I'd rather not have to worry about writing the support for it. I've never seen JSON used for configuration files. And XML would bloat the file size substantially I think. (I also just has a dislike of XML in general).

What should I do in this case?

Factors to consider:

This configuration file can be uploaded to a web service(so size matters)

Users must be able to edit it by hand if necessary(ease of editing and reading matters)

Must be able to generate and process automatically (speed doesn't matter a lot, but not excessively slow)

The "keys" and "values" are plain strings, but must be escaped because they can contain anything. (unicode and escaping has to work easily)

Multiple configuration files. Basically, each config file is tied to one "project"

答:
After looking at your requirements, and seeing that you have a dislike for XML, I would advise you to go with JSON. I must admit that I've only dealt with XML and JSON, so I cannot speak for any other common configuration formats out there.

JSON is really easy to write, and if formatted correctly, easy to read. Google just LOVES JSON for configuration use in their tools. Also, JavaScript can turn it into objects natively.

ContentLicense: CC BY-SA 3.0


问:
What if I can't make my unit test fail in "Red, Green, Refactor" of TDD?
So let's say that I have a test:

```<code>@Test
public void MoveY_MoveZero_DoesNotMove() {
    Point p = new Point(50.0, 50.0);
    p.MoveY(0.0);
    Assert.assertAreEqual(50.0, p.Y);
}
</code>```

This test then causes me to create the class Point:

```<code>public class Point {
    double X; double Y;
    public void MoveY(double yDisplace) {
        throw new NotYetImplementedException();
    }
}
</code>```

Ok.  It fails.  Good.  Then I remove the exception and I get green. Great, but of course I need to test if it changes value.  So I write a test that calls p.MoveY(10.0) and checks if p.Y is equal to 60.0.  It fails, so then I change the function to look like so:

```<code>public void MoveY(double yDisplace) {
    Y += yDisplace;
}
</code>```

Great, now I have green again and I can move on.  I've tested not moving and moving in the positive direction, so naturally I should test a negative value.  The only problem with this test is that if I wrote the test correctly, then it doesn't fail at first.  That means that I didn't fit the principle of "Red, Green, Refactor."

Of course, This is a first-world problem of TDD, but getting a fail at first is helpful in that it shows that your test can fail.  Otherwise this seemingly innocent test that is just passing for incorrect reasons could fail later because it was written wrong.  That might not be a problem if it happened 5 minutes later, but what if it happens to the poor-sap that inheirited your code two years later.  What he knows is that MoveY does not work with negative values because that is what the test is telling him.  But, it really could work and just be a bug in the test.

I don't think that would happen in this particular case because the code sample is so simple, but if it were a large complicated system that might not be the case.  It seems crazy to say that I want to fail my tests, but that is an important step in TDD, for good reasons.

答: Your first test case came from your specification (which was possibly just in your head). Now, what does your specification say about negative values? Does it include them explicitly? If so, write a test. If not, don't.</p>


答:
JSON is a good choice for its flexibility, ease of reading and editing outside your program, the wide availability of parse libraries to support it.  It supports hierarchy, lends itself to simple forward / backward compatibility that a file that simply saves data in sequence doesn't.  I think it also has easy techniques for converting between Java classes and file data and then back the other way.  A lot of people know and have coded for this format, and the format is important for other programs that you will probably need to work with in the future.

Many systems were based on .ini format, and they are pretty easy to parse if you were writing a parser from scratch.

csv can be quick to code and works with very little overhead, but has issues with flexibility, forward/backward compatibility.

Using the registry was a common practice in Windows.

Using cookies is common for web development.

For a utility function, maybe just use free format text that matches your command line options, just read it in and make an argv string array from it.

Title: Is using something other than XML advisable for my configuration file?

Body:
I have a small tool I'm designing which would require a configuration file of some sort. The configuration file in my case is really more of a database, but it needs to be lightweight, and if needed the end-user should find it easily editable. However, it also will contain a lot of things in it. (depending on certain factors, could be 1Mb or more)

I've decided I'd rather use plain ol' text, rather than trying to use SQLite or some such. However, with using text, I also have to deal with the variety of formats. So far, my options are

XML

JSON

Custom format

The data in my file is quite simple consisting for the most part of key-value type things. So, a custom format wouldn't be that difficult... but I'd rather not have to worry about writing the support for it. I've never seen JSON used for configuration files. And XML would bloat the file size substantially I think. (I also just has a dislike of XML in general).

What should I do in this case?

Factors to consider:

This configuration file can be uploaded to a web service(so size matters)

Users must be able to edit it by hand if necessary(ease of editing and reading matters)

Must be able to generate and process automatically (speed doesn't matter a lot, but not excessively slow)

The "keys" and "values" are plain strings, but must be escaped because they can contain anything. (unicode and escaping has to work easily)

Multiple configuration files. Basically, each config file is tied to one "project"


答:
As far as configuration files go, "1Mb or more" is certainly on the large side, and the need to escape strings and maintain lots of matching quotes does not play well with humans. That is why for large configuration files that need to be maintained by humans you should definitely consider defining a custom format and building a custom parser. Here is an article on the subject of humans having to write XML: Humans should not have to grok XML.

When parsers and parser generators were in their infancy, you could make a case for not building a custom one by saying that building a custom language is too complex. Now that excellent and very simple parser generators have matured, there is no excuse: you can build a custom parser in a matter of a few hours, on par with the time it would take you to build a parser for an XML-based language*.

Here is a small tutorial explaining the process of building a custom parser with ANTLR. It is in Java, but ANTLR supports C# as well.

* Unless you go for deserialization-based conversion from XML, in which case building an XML-based parser would take less time, but your classes would need to have a "shape" that closely resembles your XML.


问:
projective geometry: how do I turn a projection of a rectangle in 3D into a 2D view
So the problem is that I have a 3D projection of a rectangle that I want to turn into 2D. That is I have a photo of a sheet of paper laying on a table which I want to transform into a 2D view of that sheet.

Thus, what I need is to get an un-distorted 2D image by reverting all the 3D/projection transformations and getting a plain view of the sheet from the top.
I happened to find some directions on the subject but they don't suggest an immediate instruction on how this can be achieved. It would be really helpful to get a step-by-step instruction of what needs to be done. Or, alternatively, a link on a resource that breaks it down to little details.

答:
What you need to convert this with is morphing/warping using for example an algorithm called Catmull-Rom cubic spline interpolation.

The "correction" is easier to achieve if you don't look at it as a 3D rectangle, but as a distorted perspective of an image.

Using morphing techniques can help you calculate the various interpolations along the two axis (how much you need to interpolate or not on a given x/y coordinate). The morph/warp is of course with a destination as a 'perfect' rectangle.

You didn't state what language you prefer, but here are some resources on the topic with source code (the first one shows a more complex mesh, but you would only need one "square" of that making it simpler):

http://davis.wpi.edu/~matt/courses/morph/2d.htm

Link

Catmull-Rom cubic spline interpolation:

http://www.ibiblio.org/e-notes/Splines/Cardinal.htm

ContentLicense: CC BY-SA 4.0


问:
Performing client-side OAuth authorized Twitter API calls versus server side, how much of a difference is there in terms of performance?
I'm working on a Twitter application in Ruby on Rails. One of the biggest arguments that I have with other people on the project is the method of calling the Twitter API. Before, everything was done on the server: OAuth login, updating the user's Twitter data, and retrieving tweets.

Retrieving tweets was the heaviest thing to do since we don't store the tweets in our database, so viewing the tweets means that we have to call the API every time. One of the people in the project suggested that we call the tweets through Javascript instead to lessen the load on the server. We used GET search, which, correct me if I'm wrong, will be removed when v1.0 becomes completely deprecated, but that really isn't a concern now.

When the Twitter API has migrated completely to v1.1 (again, correct me if I'm wrong), every calls to the API must be authenticated, so we have to authenticate our Javascript requests to the API. As said here:

We don't support or recommend performing OAuth directly through
  Javascript -- it's insecure and puts your application at risk. The
  only acceptable way to perform it is if you kept all keys and secrets
  server-side, computed the OAuth signatures and parameters server side,
  then issued the request client-side from the server-generated OAuth
  values.

If we do exactly what Twitter suggests, the only difference between this and doing everything server-side is that our server won't have to contact the Twitter API anymore every time the user wants to view tweets. Here's how I would picture what's happening every time the user makes a request:

If we do it through Javascript, it would be harder on my part because I would have to create the signatures manually for every request, but I will gladly do it if the boost in performance is worth all the trouble. Doing it through Ruby on Rails would be very easy since the Twitter gem does most of the grunt work already, so I'm really encouraging the other people in the project to agree with me.

Is the difference in performance trivial or is it significant enough to switch to Javascript?

答:
Your performance gain are going to come from Scaling up, (if you need to). Imaging you have a whole lot of users Option 2 would cause server side bottle neck much sooner than option 1.

Small scale where the server would have no problem with the load, the performance gains would be negligible.


问:
What kinds of projects is SCRUM considered to be suitable for?
I have been using SCRUM in three different projects over the last four years. One of SCRUM's advantages seems to be its flexibility and adaptability, e.g. wrt to changing customer requirements. Another advantage is that management can easily track the progress of a project.

SCRUM's flexibility can be an advantage e.g. when implementing a web application, where the requirements change very fast and the customers really understand what they want after they've seen a prototype.

On the other hand there are other kinds of software projects (e.g. in aerospace industry) where the requirements are pretty fixed: you get a requirement specification document and you have to come back six months later with working software and complete documentation. For this kinds of projects I doubt that the flexibility offered by SCRUM is needed (in the sense that you do not need to build prototypes and show them to the customer to get feedback on the requirements): you rather need a very structured and systematic approach, which is probably repeated over and over again for each project with little room for surprise.

So is SCRUM considered by its proponents a general-purpose software development
methodology or is it considered especially suited for certain categories
of projects or application areas?

For example, I recently looked at the website of a company producing
software for the aerospace industry and noticed that they are using the
V-model. Would a SCRUM proponent say that SCRUM is less suited for this
kind of projects or rather suggest that this company should try switching
to SCRUM?

Note that I am not asking for the opinion of the readers of this forum, but
I want to know what is the established opinion among SCRUM proposers: is SCRUM considered general-purpose or rather suitable for certain classes of
projects only? In the latter cases, for what kinds of projects?

答:
for starters, think of SCRUM as just one set of guidelines for implementing agile practices. Don't ever think of it as a 'holy book' of how to do projects. For many projects where a steady flow of tasks is required, Kanbam is more appropriate, for example.

Agile projects tend to fall down where you're doing projects that require a fixed end date, or a fixed cost. Whilst you can still do these projects using Agile methods, the need to plan everything up front to determine if you're likely to hit the target is not the usual agile way - in agile you tend to keep doing work until you run out of stuff to do, or run out of time to do it in. For most projects this is ok as the requirements change anyway during the project.


问:
Should I use an interface when methods are only similar?
I was posed with the idea of creating an object that checks if a point will collide with a line:

```<code>public class PointAndLineSegmentCollisionDetector {
    public void Collides(Point p, LineSegment s) {
        // ...
    }
}
</code>```

This made me think that if I decided to create a Box object, then I would need a PointAndBoxCollisionDetector and a LineSegmentAndBoxCollisionDetector.  I might even realize that I should have a BoxAndBoxCollisionDetector and a LineSegmentAndLineSegmentCollisionDetector.  And, when I add new objects that can collide I would need to add even more of these.

But, they all have a Collides method, so everything I learned about abstraction is telling me, "Make an interface."

```<code>public interface CollisionDetector {
    public void Collides(Spatial s1, Spatial s2);
}
</code>```

But now I have a function that only detects some abstract class or interface that is used by Point, LineSegment, Box, etc..  So if I did this then each implementation would have to to a type check to make sure that the types are the appropriate type because the collision algorithm is different for each different type match up.

Another solution could be this:

```<code>public class CollisionDetector {
    public void Collides(Point p, LineSegment s) { ... }
    public void Collides(LineSegment s, Box b) { ... }
    public void Collides(Point p, Box b) { ... }
    // ...
}
</code>```

But, this could end up being a huge class that seems unwieldy, although it would have simplicity in that it is only a bunch of Collide methods.

This is similar to C#'s Convert class.  Which is nice because it is large, but it is simple to understand how it works.  This seems to be the better solution, but I thought I should open it for discussion as a wiki to get other opinions.

答:
Programmingly speaking, pdr's solution offers the best design but I would have suggested first to use an IoC container (configured to return single instances), then using reflection if not possible and really lastly using a switch/case.

Now mathematically speaking, I think there are maybe more optimal solutions to this problem.
For example, if your goal is really to just detect the collision between several objects in motion an be able to resolve theses collisions, for example in a game like 'angry birds', there are many optimal algorithms.

I'd suggest that maybe you should expose the problem you are trying to solve on  https://gamedev.stackexchange.com/
Since for me it's more a math/physics programming problem than a 'pure' programming problem.

It would be a shame to design a complex Object Oriented solution whilst there is maybe a simpler (and with better performance) mathematical solution.


问:
Programming C++ using Qt4
Hey guys I am really new to the C++ programing I have a little knowledge in C and a bit more in C++, but I do not know them enough to call myself a programmer. I am working as a PHP Web Developer I like being a crafts man and creating things so that is the reason to combine the programming with web development. I think that I could really benefit from both of them and so... My question is:

Is it a good Idea to learn C++ with Qt or not?

Can you give me pros and cons of both?

Note: I do not want to become a programmer and give up the web development I want to combine them both.

答:
If you want to combine them both, then forget Qt, instead look to simple add-on extensions to PHP either via the command line (called using an system exec call), as a soap server (try gsoap) or as full PHP extensions. then you'll see how you can call and work with a C++ program from your web code which should keep part of the familiarity of coding you already have.

So: start with simple console applications that take input and return output on the command line (ie stdout). Then migrate to a soap server and keep most of your existing code, but restructure it to live in a class with lots of methods that you can call, input and output will be via the soap actions. Then (if necessary) further modify the code to act as a PHP  extension.

Once you've progressed through those 3 steps of increasing complexity, you should have enough knowledge to fill out better ways of performing the same tasks.

Title: Programming C++ using Qt4


问:
Control flow testing in white box - static or dynamic?
Yesterday I asked a question that happened to have another meaning inside. I can see that Control/data flow is often mentioned to be static analysis (when tools is used) or dynamic analysis testing in terms of white box testing. Could it be that automatic analysis tools can just help by creating graphs or they do actually test it with inputs (then it would not be static IMHO).</p>

答:
You can also have automatic analysis tools that perform symbolic execution. Klee is an example of this. Basically it goes through the program trying to figure out what are the possible values of variables at different points. Using that it decides which input variables can cover which parts of the code. It even does some cool things with modelling file systems and environment variables. Their paper is a fairly easy read and quite informative

So in general I think the distinction is not that simple. KLEE runs the code in a way, but I would not call that proper execution.


问:
What does it mean to write "good code"?
In this question I asked whether being a bad writer hinders you from writing good code. Many of the answers started of with "it depends on what you mean by good code".

It appears that the term "good code" and "bad code" are very subjective. Since I have one view, it may be very different from others' view of them.

So what does it mean to write "good code"? What is "good code"?

答:
As far as it goes for me...
I know I'm writing good code when a coworker that does work on another project comes along and is able to jump in and understand what I'm doing without me going over each block of code and showing what it is doing.

Instead of him saying, "Wait a minute, what?!"
He's saying, "Oh, ok, I see what you did there."

Good code also doesn't have a lot of sneaky workarounds or 'hacks.' Lines when, while you're writing it, you're also saying to yourself, "I know this is not a good way to do it, but I'm just gonna have to do it this way for now. I'll remind myself to improve it later..."

ContentLicense: CC BY-SA 2.5

Title: What does it mean to write "good code"?


问:
Why is Python used for high-performance/scientific computing (but Ruby isn't)?
There's a quote from a PyCon 2011 talk that goes:

At least in our shop (Argonne National Laboratory) we have three
  accepted languages for scientific computing. In this order they are
  C/C++, Fortran in all its dialects, and Python. You’ll notice the
  absolute and total lack of Ruby, Perl, Java.

It was in the more general context of high-performance computing. Granted the quote is only from one shop, but another question about languages for HPC, also lists Python as one to learn (and not Ruby).

Now, I can understand C/C++ and Fortran being used in that problem-space (and Perl/Java not being used). But I'm surprised that there would be a major difference in Python and Ruby use for HPC, given that they are fairly similar. (Note - I'm a fan of Python, but have nothing against Ruby).

Is there some specific reason why the one language took off? Is it about the libraries available? Some specific language features? The community? Or maybe just historical contigency, and it could have gone the other way?

答:
I've been wondering this same thing. I think it's, as Spencer Rathbun said, because of the procedural aspect of Python. Being a "non-programmer" myself, I find it beautiful the way you can code in Ruby and the Rails framework is excellent for ease of use. However, when coding for scientific purposes (math, biology, etc), you normally think in a "mathematical" language, that is, you don't care about statements like

```<code>Person.find_by_name 'Juanito'
</code>```

but you care more about

```<code>A = B*C + D
</code>```

So I think Ruby is powerful that many of it's features would be unused in a scientific program. It's easier just to think in procedures.

Body:
I've been wondering this same thing. I think it's, as Spencer Rathbun said, because of the procedural aspect of Python. Being a "non-programmer" myself, I find it beautiful the way you can code in Ruby and the Rails framework is excellent for ease of use. However, when coding for scientific purposes (math, biology, etc), you normally think in a "mathematical" language, that is, you don't care about statements like

Person.find_by_name 'Juanito'

but you care more about

A = B*C + D

So I think Ruby is powerful that many of it's features would be unused in a scientific program. It's easier just to think in procedures.


答:
Some good answers here already. But if I were in your shoes, before throwing XML over board, I would consider the following points:

XML is very well supported by the .NET framework and third-party tools, for JSON you will have to choose a third-party library and see if it fulfills all your requirements.

if you need manual editing only for a few exceptional cases, then XML will probably suffer your needs. If there is lots of editing to be done, and your list of configuration options has a particular complexity, your users most probably need some kind of dialog based option / configuration application - which means, it does not matter if the underlying XML format is 100% user-friendly. If you don't want to write such a thing, at least you can recommend some kind of XML editor to your users. Tools like XML notepad or the XML tools for Notepad++ work well for lots of people.

I guess the chances are higher that your end users have seen some kind of XML before than the chances that they have seen JSON before - which will make it a little bit easier for them to grasp it (if they really have to)

JSON does not support comments, which can make manual editing a pain

if size gets really a problem for uploading the data to a web service, consider using data compression

Actually, if you think about this points, and you don't want to use XML anyway, then go with JSON instead. Using XML or JSON provides you already with standard ways of escaping strings, standard ways of extending your configuration structure afterwards, and ready-made libs for reading and writing those formats - there is no need to reinvent the wheel with any "custom format".


问:
Programming Interview : How to debug a program?
I was recently asked the following question in an interview :

How do you debug a C++ program ?

I started by explaining that programs may have syntax and semantic errors. Compiler reports the syntax errors which can be corrected. For semantic errors, various debuggers are available. I specifically talked about gdb, which is command line, and Visual Studio IDE's debugger, which has a GUI, and common commands. I also talked about debug and release version of code, how assertions should be used for debug build, how exceptions helps in automatic cleanup & putting the program in valid state, and how logging can be useful (e.g. using std::clog).

I want to know if this answer is complete or not. Also, I want to hear how other people will go about answering this question in a structured manner ?

Thanks.

答:
If I were asking this question, I'd be looking for a higher level answer.  A "bug" is a gap between what you think the program is doing and what it is actually doing.  A primary tool to finding a bug is the scientific method.  Perform experiments using debuggers, logs, code modifications, whatever until you can make a theory about what is going on.  Then test that theory using as many cases as you can, again using whatever tools make sense.  Repeat until you can't disprove a theory.  Once you know what is going on, make the relavent changes and then test your fix.

What tools are involved varies depending on the bug and the environment.  Getting an answer of "a debugger" when asking "how do you find debug a program?" puts me off big time.  It's like answering "by using an editor" when asked how you write software.  A debugger is a tool, and like all tools in the industry, it will vary in quality, and might not even exist.  "Visual Studio" only works if you're looking at a Microsoft shop.  Will you be paralyzed if the problem only manifests itself in release mode, on a physical device that doesn't allow debugger attachments?

The other thing I would be looking for as an interviewer is questions about the issue that show you have knowledge about what to look for given certain conditions.  What is your approach if the system freezes in an app with multiple threads?  What is your approach when you have different behavior in release and debug mode?  What is your approach when you have a random crash that can't be tied to a particular line of code?  What is your approach to trace a memory leak?

Answers should mention tools in all of these cases of course, but the tools are secondary to the process.

I don't think this question is too vague at all.  When I interview, I love questions like this, because they can often result into deep conversations about software engineering process.  When that happens, you know you've got the right person.  There's no such thing as a "complete" answer or a "right" answer.  The point is not to get the question right but to use the question as a springboard to show your abilities.  As an interviewer, am more interested in giving you these opportunities than I am knowing that you can parrot back a "correct" answer.


答:
One factor that is really important to help understanding most any method of performing this operation is that you will be taking each pixel location of your END image and then calculating the position within the source image to calculate the pixel data from (using one of numerous interpolation methods.)

Understanding that the calculation goes "in reverse" is key to groking this type of transformation.

Title: projective geometry: how do I turn a projection of a rectangle in 3D into a 2D view

Body:
So the problem is that I have a 3D projection of a rectangle that I want to turn into 2D. That is I have a photo of a sheet of paper laying on a table which I want to transform into a 2D view of that sheet.

Thus, what I need is to get an un-distorted 2D image by reverting all the 3D/projection transformations and getting a plain view of the sheet from the top.
I happened to find some directions on the subject but they don't suggest an immediate instruction on how this can be achieved. It would be really helpful to get a step-by-step instruction of what needs to be done. Or, alternatively, a link on a resource that breaks it down to little details.


问:
What is the correlation between programming language and experience/skills of their users?
I'm sure there is such a correlation, because

experience and skill leads good programmers to picking languages that are better for them, in which they're more productive, and

working in a language forms how programmers think and influences their methods and skills.

Is there any research or some statistical data of this phenomenon?

Perhaps this is not a purely academic question. For example, if someone is starting a new project, it could be worth considering a language (among other criteria of course) for which there is a higher chance of finding or attracting experienced programmers.

Update: Please don't fixate on the last paragraph. It's not my intention to choose a language based on this criterion, and I know there are other far more important ones. My interested is mostly academic. It comes from the (subjective) observation and I wonder if someone has researched it a bit. Also, I'm talking about a correlation, not about a rule. Sure there are both great and terrible programmers in every language. Just that in general it seems to me there is a correlation.

答:
At a guess, I would say there is a correlation, but only a vague one, not worth putting any real weight on.

A programmer may end up using or gaining experience in a certain language for many reasons.  Off the top of my head:

$COMPANY has many projects in $LANGUAGE so I had to learn it

Jobs using $LANGUAGE pay really well

everyone says $LANGUAGE is the one to learn, either generally or for some application space

$LANGUAGE is better supported (open to interpretation as well)

$LANGUAGE has a bigger collection of libraries

I learned $LANGUAGE at $EDUCATIONAL_COURSE and that's what I stuck with.

$LANGUAGE is fun!

Google might give you some sites that show a correlation between langauage and wage, but that's differerent to expertise.

If you are starting a new project and want to choose a language that will get you good programmers, consider:

Good programmers generally cost more and/or are harder to get into your project

The best programmers know multiple languages, and can start using a new language with relative ease


问:
Hallmarks of a Professional PHP Programmer
I'm a 19 year old student who really REALLY enjoys programming, and I'm hoping to glean from your years of experience here. At present, I'm studying PHP every chance I get, and have been for about 3 years, although I've never taken any formal classes. I'd love to some day be a programmer full time, and make a good career of it.

My question to you is this: What do you consider to be the hallmarks or traits of a professional programmer? Mainly in the field of PHP, but other, more generalized qualifications are also more than welcome, as I think PHP is more of  a hobbyist language and may not be the language of choice in the eyes of potential employers. Please correct me if I'm wrong. Above all, I don't want to waste time on something that isn't worth while.

I'm currently feeling pretty confident in my knowledge of PHP as a language, and I know that I could build just about anything I need and have it "work", but I feel sorely lacking in design concepts and code structure. I can even write object oriented code, but in my personal opinion, that isn't worth a hill of beans if it isn't organized well. For this reason, I bought Matt Zandstra's book "PHP Objects, Patterns, and Practice" and have been reading that a little every day.

Anyway, I'm starting to digress a little here, so back to the original question. What advice would you give to an aspiring programmer who wants to make an impact in this field?

Also, on a side note, I've been working on a project with a friend of mine that would give a fairly good idea of where I'm at coding wise. I'm gonna give a link, I don't want anyone to feel as though I'm pushing or spamming here, so don't click it if you don't want to. But if you are interested on giving some feedback there as well, you can see the code on github. I'm known as The Craw there.

https://github.com/PureChat/PureChat--Beta-/tree/

答:
In addition to what Adrian Schneider and MainMa has written (which are both good), I do think that one hallmark of a professional programmer, regardless of language, is the realization that code has an extremely long half-life -- much longer than we commonly realize or for that matter expect when writing it.

Yes, there are extreme cases of systems dating back 50 years still in active use (business-critical applications written in COBOL back in the 1960s to 1970s still being used), but it doesn't need to be quite that extreme. Of course at the other extreme is ad-hoc code written to be executed only once. One of the applications I work on is basically a web-based CRUD application. Lots of table views, some specialized views, some reports, a few surrounding odds and ends. Really, nothing very fancy in the grand scheme of things. With some of the core classes and database code dating back 10+ years currently, I do believe it rather nicely fits around the median. The language and framework (C#.NET, in this particular case) have of course evolved over that time, and the people involved have gained experience in using it, but the old code remains in place because it works and works well enough, seeing minor changes now and then but most often just providing the foundation that the whole system rests on. My employment before that was centered around replacing an aging system which was designed for only a single user and with parts written 15+ years prior with something slightly more modern. Let me rephrase that. Some of the most important parts of the system I was tasked with replacing predated Windows 3.0.

A professional programmer will, when writing code that isn't explicitly throwaway code designed to solve a very specific one-time-only issue, consider the fact that the code s/he writes today will likely remain in some form for many years. If it is a core piece of the software, it is likely to remain for a significant portion of the product's lifetime. It is likely to need maintenance down the road by a programmer which has nothing to do with the original development team. Heck, it might even need maintenance by the programmer who originally wrote it! (If you don't get that, consider the saying that code you wrote six months ago may as well have been written by someone else -- then try six years rather than six months.)

From this comes the realization that code needs to be easy to read and understand, easy to modify and easy to extend to fit into new uses or meet changing requirements. It also needs to be easy to debug, as well as preferably easy to follow without running it through an interactive debugger.


答:
There is no simple way to answer a question like this, I am unaware in any statistic information around this but I can speak about my own experance as a programmer and the companies and projects i have have worked on.

The choice of picking a programming Lagrange is around a few things like what your trying to make, how fast you are trying to make it, and if there are any other requerments like number of users and so on pretty much they way the call scale these days.

An example of this is, if your making the front-end of a web page your choices are things like, html, css, javascript, flash/action script. Now while making the web page you want to add an extra region to the page you cant really do it with javascript unless your using html with it and css can really only edit the look of it so your truly left with html and flash, now what ends up happening is the world is moving away from flash so writing a website in flash may hurt you because you may end up having to remake that feature again, people on some mobile devices like phones and tablets wont be able to see your work.

Now when it comes to back-end code it gets a little tricker, but its pretty safe to say you don't want to make your entire website in bash scripts if you plan on handling any number of users, and choices like java is popular but may be more overhead than you need to make your birthday investigation page. In the end its a lot to do with trade offs and experiences. For example i am working on a project right now and I am writing lots of the back-end clean up and data pulling in python but the user facing site in php. I suspect that I will need to change the python stuff to java in the feature but for now i just want to get the project up and will come back to something like java later.

Lastly don't be afraid to learn new things and push your limits, and question why is something done like this, that little extra knowledge can go a long way.

Title: What is the correlation between programming language and experience/skills of their users?

Body:
I'm sure there is such a correlation, because

experience and skill leads good programmers to picking languages that are better for them, in which they're more productive, and

working in a language forms how programmers think and influences their methods and skills.

Is there any research or some statistical data of this phenomenon?

Perhaps this is not a purely academic question. For example, if someone is starting a new project, it could be worth considering a language (among other criteria of course) for which there is a higher chance of finding or attracting experienced programmers.

Update: Please don't fixate on the last paragraph. It's not my intention to choose a language based on this criterion, and I know there are other far more important ones. My interested is mostly academic. It comes from the (subjective) observation and I wonder if someone has researched it a bit. Also, I'm talking about a correlation, not about a rule. Sure there are both great and terrible programmers in every language. Just that in general it seems to me there is a correlation.


答:
A language is a tool, and different tools are better suited for different jobs.  It is true that some languages require more skill than others, but that should not be the main criterion for choosing a language for a project. Look at your project, find out which languages are typically used for this type of project on whatever platform you plan to use, and then decide among them based on your chances of finding or attracting experienced programmers.

Also, it is not so much the language that forms how programmers think, but the programming paradigm(s) that it supports, i. e. imperative vs. functional vs. object oriented etc.  Java and C# programmers think in pretty much the same way. C++ programmers may think in a variety of different ways, depending on which subset of the paradigms supported by C++ they actually use.

The skill of a programmer is not in knowing any particular language but in knowing several languages that support different paradigms, and knowing them well.  That gives you the flexibility to quickly pick up whatever the current language du jour happens to be.


问:
What is the pattern behind respond_to / respond_with in Rails?
Is there a specific name to this? For me it looks like a view router, or a presenter router (I would name it like that) but maybe there is a better name and explication.</p>

答:
You might get away with calling this a strategy pattern or a collection of template methods.

But don't try too hard to assign names to how ruby is used.  In ruby you can add and modify classes and individual objects, throw around code blocks etc., with such ease that the standard design patterns seem less pertinent after a while.


问:
Should tests be in the same Ruby file or in separated Ruby files?
While using Selenium and Ruby to do some functional tests, I am worried with the performance. So is it better to add all test methods in the same Ruby file, or I should put each one in separated code files?

Below a sample with all tests in the same file:

```<code># encoding: utf-8
require "selenium-webdriver"
require "test/unit"

class Tests < Test::Unit::TestCase

    def setup
        @driver = Selenium::WebDriver.for :firefox
        @base_url = "http://mysite"
        @driver.manage.timeouts.implicit_wait = 30
        @verification_errors = []
        @wait = Selenium::WebDriver::Wait.new :timeout => 10
    end

    def teardown
        @driver.quit
        assert_equal [], @verification_errors
    end

    def element_present?(how, what)
        @driver.find_element(how, what)
        true
        rescue Selenium::WebDriver::Error::NoSuchElementError
        false
    end

    def verify(&blk)
        yield
        rescue Test::Unit::AssertionFailedError => ex
        @verification_errors << ex
    end

    def test_1

        @driver.get(@base_url + "/")
        # a huge test here

    end

    def test_2

        @driver.get(@base_url + "/")
        # a huge test here

    end

    def test_3

        @driver.get(@base_url + "/")
        # a huge test here

    end

    def test_4

        @driver.get(@base_url + "/")
        # a huge test here

    end

    def test_5

        @driver.get(@base_url + "/")
        # a huge test here

    end
end
</code>```

答:
The number of files comprising your tests will be mostly irrelevant - The time spent running the tests themselves will be much greater than the time spent loading and compiling the files.

Instead try to keep your test code manageable - group related tests together, and try to keep the files withion the very rough ballpark of 50-500 lines.


问:
Brief explanation for executables in a GNU/Clang Toolchain?
I roughly understand that cc, ld and other parts are called in a certain sequence according to schemes like Makefiles etc. Some of those commands are used to generate those configs and Makefiles. And some other tools are used to deal with libraries. But what are other parts used for? How are they called in this process? Which tool would use various parser generators? Which part is optional? Why?

Is there a brief summary get these explained on how the tools in a GNU or LLVM/Clang toolchain are organised and called in a C/C++ project building?

Thanks in advance.

EDIT:

Here is a list of executables for Clang/LLVM on Mac OS X:

ar          clang           dsymutil        gperf           libtool         nmedit          rpcgen          unwinddump
as          clang++         dwarfdump       gprof           lorder          otool           segedit         vgrind
asa         cmpdylib        dyldinfo        indent          m4          pagestuff       size            what
bison           codesign_allocate   flex            install_name_tool   mig         ranlib          strip           yacc
c++         ctags           flex++          ld          mkdep           rebase          unifdef
cc          ctf_insert      gm4         lex         nm          redo_prebinding     unifdefall

答:
Most of those tools are not used in a standard project - I myself have never seen half of them.

This is the basic workflow, in terms of actual processes that are run:

```<code>gcc
|
v
cc1 -> as -> collect2 -> ld
</code>```

This on its own doesn't tell you all that much.  There is no cpp (The preprocessor) - that is integrated into cc1. cc1 itself is the backend and the "real" compiler - the gcc binary is a frontend for all the tools that do the actual work.  cc1 is the preprocessor/compiler backend, which compiles to assembly.  as is the assembler, which produces object files.  collect2 (I forgot about this myself, and was only made aware of it because I ran an strace) assists in arranging startup code in the executable (from here).  Finally, ld links the object files and libraries into the final executable.

For the actual use of these individual components, it's generally a better idea to call gcc and let it figure out what to do.  For example you can run gcc -S on a .c file to produce the .s assemply file, or gcc -E to only preprocess the source file.

Basically, man gcc is what you want to read.  Or at least skim through.

Body:
Most of those tools are not used in a standard project - I myself have never seen half of them.

This is the basic workflow, in terms of actual processes that are run:

gcc
|
v
cc1 -> as -> collect2 -> ld

This on its own doesn't tell you all that much.  There is no cpp (The preprocessor) - that is integrated into cc1. cc1 itself is the backend and the "real" compiler - the gcc binary is a frontend for all the tools that do the actual work.  cc1 is the preprocessor/compiler backend, which compiles to assembly.  as is the assembler, which produces object files.  collect2 (I forgot about this myself, and was only made aware of it because I ran an strace) assists in arranging startup code in the executable (from here).  Finally, ld links the object files and libraries into the final executable.

For the actual use of these individual components, it's generally a better idea to call gcc and let it figure out what to do.  For example you can run gcc -S on a .c file to produce the .s assemply file, or gcc -E to only preprocess the source file.

Basically, man gcc is what you want to read.  Or at least skim through.


问:
Suggestions for html tag info required for jQuery Plugin
I have written a tiny bit of jQuery which simply selects all the Select form elements on the page and sets the selected property to the correct value.  Previously I had to write code to generate the Select in php and specify the Selected attribute for the option that was selected or do loads of if statements in my php page or smarty template.

Obviosly the information about what option is selected still needs to be specified somewhere in the page so the jQuery code can select it.

I decided to create a new attribute on the Select item

```<code><Select name="MySelect" SelectedOption="2">  <-- Custom Attr SelectedOption
<option value="1">My Option 1 </option>
<option value="2">My Option 2 </option> <-- this option will be selected when jquery code runs
<option value="3">My Option 3 </option>
<option value="4">My Option 4 </option>
</Select>
</code>```

Does anyone see a problem with using a custom attribute to do this, is there a more accepted way, or a better jquery way?

答:
If you are absolutely sure you want this, you should call it data-something.

A new feature being introduced in HTML 5 is the addition of custom data attributes. This is a, seemingly, bizarre addition to the specification - but actually provides a number of useful benefits.

Simply, the specification for custom data attributes states that any
  attribute that starts with "data-" will be treated as a storage area
  for private data (private in the sense that the end user can't see it
  - it doesn't affect layout or presentation).

This is because, otherwise, the HTML you produce is invalid by HTML5 and will fail such validation checks.

This has very little to do with jQuery - jQuery is more about DOM manipulation, what you're really asking is a HTML question which can really only be answered by considering the standards (HTML5 or otherwise). That said, for readability, you should have the value inside the HTML. Anywhere else would just be confusing and unmaintainable in the long run.

Source: http://ejohn.org/blog/html-5-data-attributes/ (which points to http://dev.w3.org/html5/spec/#custom)


问:
Is O(1) random access into variable length encoding strings useful?
I remember reading that there are no existing data structures which allow for random-access into a variable length encoding, like UTF-8, without requiring additional lookup tables.

The main question I have is, is this even a useful property? I mean, to look up and replace random single codepoints in O(1) time.

答:
I would give the traditional, and really quite boring answer of it depends.

Is random access to individual characters (glyphs) in a string a useful property? Yes, definitely.

Do you need access to individual code points? I guess that could be useful in certain situations that aren't too contrived if you are doing extensive handling of text data, such as in for example word processing or text rendering. Data (text encoding) normalization is another possible use-case that I can think of. I'm sure there are other good uses as well.

Does it need to be in O(1) time? Really, with a few exceptions that are unlikely to apply in the general case, not necessarily. If O(1) time access is a requirement, it's probably easier to just use a fixed-length encoding such as UTF-32. (And you will still be dealing with cache misses and swap space fetches, so for sufficiently long strings it won't be O(1) anyway... :))


答:
There are languages that demand extra skill (assembly being a prime example), but in the vast majority of cases the programmer doesn't choose what language to work in.

Most of us spend our time either doing maintenance or adding features to an existing project, not starting new projects.  And even when starting a new project, there are many factors that go into choosing a language(s) -- mainly unrelated to what makes a language good or not.  The leading example for that, is that if you project includes a web presence, you're almost certainly going to be using javascript.

Basically, I think your hypothesis is incorrect.


问:
Debugging framework for domain specific language
I want to know if there are any tools/tool-kits which aid in building
source level debuggers for domain specific languages ?
(I work on a proprietary DSL, which doesn't have any tools
and sometimes debugging will become difficult, so, if in case
there are any such tool-kits, wanted to try)</p>

答:
This is an indirect answer to your question. In 1982 I wrote the first commercial C source-level debugger, CDB (also possibly the first remote debugger, kernel debugger, and multi-process/multi-thread debugger). I initially wrote it because I needed it (the only other option was sdb on a VAX, except I didn't have a VAX, and sdb sucked planetoids). This situation was in perfect harmony with The Cathedral and the Bazaar's first rule: Every good work of software starts by scratching a developer's personal itch.

Since you are the person with the itch, you are also quite possibly the best person to embark on this journey.

The following things are needed to create a source-level debugger:

A way of starting & stopping execution without killing the target process. Given your environment this may be trivial or it might be a deal killer. ptrace(2) was the key in UN*X-land.

A way of querying the current execution state of the target process. e.g Program Counter (PC) (or equivalent), Stack Pointer (SP), registers, and data/instruction memory. Like #1, trivial or deal killer.

A way of mapping the PC => file:line and vice versa—file:line => PC. This is critical because it's what differentiates a source-level debugger from an assembly-level debugger (or whatever the equivalent would be in your world). Compiled languages often generate additional symbols in the .o file that makes this mapping possible (although not always in a straightforward way).

A way of inserting and removing a breakpoint. How this is accomplished can vary wildly across environments. It needs to be done in such a way as to be as non-disruptive of the execution state as possible so that you can avoid the debugger equivalent of the Heisenberg uncertainty principle—i.e. the bug reacts differently depending on where you set the break. Note: You can't avoid this with timing-related bugs.

Once you have these things nailed down, your actual command processing should be pretty straightforward. For example, when you hit a breakpoint, you read the PC, map it to file:line and display that line (normally with +/-5 lines of context). For a stack trace, you get the SP and print each frame using the additional symbol info that gives local variable offset from the SP, etc., etc.

What commands make sense will be driven by how you (and your future users) think when using the language. Things that make sense for one language are nonsense when applied to another. For example, given the C declaration struct FOO *pfoo;, it's nice if typing *pfoo at the command prompt gives you a formatted dump of the structure pointed to. This might not make sense when debugging something like SQL, but there are often analogues.

The Devil is in the Details on these 4 items, so let me know if you would like any more help offline. My email is in my profile.


问:
What should I study to 'learn' Comp Sci?
[This question was originally asked on Stack Overflow, but recommended to move the question here.]

I can't find anything quite like the question I'm about to ask, so please forgive me if there's something just like it already, please feel free to point me in the right direction. It'll take a bit of background explaining too, please forgive me for that.

[backstory]

Basically, I graduated from University about 18 months ago with a degree in Business Information Systems and Japanese. The Japanese took up half of the degree so the BIS was only joint. I only learned PHP in terms of languages and basically no computing theory - everything was vocational (Networking, programming basics, CMS development, Office and VBA and then loads of Business theory courses).

Since this, I decided to teach myself C# and ASP.Net and try to get a position as a programmer. I created an online shop style website and a small CRM application in Windows Forms to both teach myself and build a portfolio, and luckily I managed to snag a developer position.

Bad side? I'm the only developer at my company. Now don't get me wrong, in the last year I've learned loads and loads, I did some devpt. before Uni so knew the basics anyway, but it was very much a "learning from books" job - every night.

Now then... I am now at a point where I'm building software on a regular basis, making good judgements for time scales, and have even been told my code and methodology are good by other professionals that have been in the game longer than me, and they have offered me jobs.

[/backstory]

What this whole thing boils down to, is that I now want to study up on the topics I'll have missed by not doing CS. More importantly, could you recommend books / free online courses? I want to learn about Computer Science theory, not just better coding.

Thank you!

答:
Here is a blog post I just learned about today. It's very interesting. The letter I wish I could write to my former self, and have beamed at light-speed through some kind of vacuum tube and delivered at the precise moment when I finally decided to learn to program.

First off, congradulations on gaining such high marks from seasoned professionals at such a young age.

I think the very thing you are truely looking for can be found by answering this question?

Where do you want to be five years from now?

Answer that question and then chart a path that leads you there.

As Mr. Miagi would say "Focus Danielsan".


问:
How can I get my own encryption algorithm tested?
I've just developed a block cipher symmetric-key algorithm and I am using it in some of my products. I want to put it to real test.

How would one go about entering their encryption algorithm into an international encrytption contest?

答:
Yes but they are normally the other way around.

Well respected experts in crypto are invited to submit their algorithms and everyone else in the world is invited to break them. The one that does best ends up as the next standard.
These algorithms have already stood up to the mathematical tests of their own inventors, their students and fellow researches as well as the experts at various inteligence agencies.

Sorry but nobody is going to put time/effort/resources into trying to break an algorithm by an amateur with no reputation, publications or standing in the field.


问:
Wide gap in my resume as a Java developer. What are must-have skills required to get hired those days?
For some legal reasons I haven't worked for anybody for the last 12 years. I am a java web developer or at least I am thinking so. For this period I have been working on my project- some sort of business network - and I did few small jobs, so right now I feel I am far behind in terms of my skills and the skills needed today.

I lingered too long on Struts and Hibernate and thought that could the job for my project. I need to get a job, right now, so I am spending most of my time brushing my skills.

My question is: What are the current necessary skills that could convince employers to hire me regardless of my past employment or the lack of it.

Right now I am on  AspectJ, IoC and Spring

答:
Hibernate is still very much relevant, though more as the leading implementation of the JPA standard.

Struts is well past its prime. But there's still a ton of legacy code using it that needs maintaining.

AOP never gained much commercial traction, so for resume polishing, AspectJ is a waste of time

Spring is definitely big, everyone uses Dependency Injection these days, either Spring or Java EE, with the CDI standard creating a common ground.

Since EJB version 3, Java EE (formerly J2EE) is regaining a lot of popularity.

Learning one (or preferably a few) web framework other than Struts would be very important. Could be Spring MVC, could be JSF, Apache Wicket or Play.

When you do web frontends, knowledge of JavaScript and JQuery is a must these days.

Automated testing using JUnit and assorted libraries, including some mocking framework shows that you care about quality.

Build automation using Ant or Maven, and Jenkins is needed in any truly professional environment.

But the size of you skillset bullet list doesn't matter when you can't convince prospective employers that you actually have experience with those technologies. They probably get 20 resumes a day from desparate people who outright lie in their resumes. The best thing you can probably do is build stuff you can actually put on the web to demonstrate your knowledge of these technologies.


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答:
Being from the Netherlands I've had the nasty experience of being forced to write comments (and even variable names) in Dutch at school.  Most of the time I rejected this attitude and wrote all that in pure English regardless, along with several other students that already had programming experience or learned fast.

In all the companies I've worked for the only use of Dutch was for strings the end-user could or would see, all other text (non-user documentation included) was in English.


问:
How old is "too old"?
I've been told that to be taken seriously as a job applicant, I should drop years of relevant experience off my résumé, remove the year I got my degree, or both. Or not even bother applying, because no one wants to hire programmers older than them.1

Or that I should found a company, not because I want to, or because I have a product I care about, but because that way I can get a job if/when my company is acquired.

Or that I should focus more on management jobs (which I've successfully done in the past) because… well, they couldn't really explain this one, except the implication was that over a certain age you're a loser if you're still writing code. But I like writing code.

Have you seen this? Is this only a local (Northern California) issue?

If you've ever hired programmers:2

Of the résumés you've received, how old was the eldest applicant?

What was the age of the oldest person you've interviewed?

How old (when hired) was the oldest person you hired?

How old is "too old" to employed as a programmer?

1 I'm assuming all applicants have equivalent applicable experience. This isn't about someone with three decades of COBOL applying for a Java guru job.

2 Yes, I know that (at least in the US) you aren't supposed to ask how old an applicant is. In my experience, though, you can get a general idea from a résumé.

答: I'm working in Korea. In this country, over 40s are too old as a programmer. So the board want them to be a manager. But only few of them can be a manager. Rest of them should be retired.  So they find a new job like a own business. It is why most korean programmers want to go abroad.</p>

Title: How old is "too old"?


问:
would a composite design pattern be useful for group membership?
I'm trying to think about the best way to handle group memberships on a website. People sign up and select checkboxes in a list of interests. Every week we send out interest-themed emails to those members that indicated that interest.

however i store the information in the database, while i am working with the lists and generating lists of email addresses or manipulating group memberships, the composite design pattern looked interesting.

it would be easy to populate the group, then do some aggregating functions that say... generate the list of email addresses based on the interests.

but i'm not sure i'm seeing any other advantages. i do need something scalable, and flexible.

thoughts?

答:
Design patterns apply more to code, than to databases. When you have entered the database world, you simply want a normalised database. The biggest issue you have with the composite pattern is scale: in order to manipulate those OO objects, you'd need to pull all the data from the database regardless if you need it - which is a waste and impractical if you get large lists.

In your case:

users: id, name, email, etc

interests: id, description

users_interests: user_id, interest_id

with the appropriate primary/unique keys. After that, you can get all of the information you need in a single database query.

For example:

All emails who are interested in cycling (id=2):

```<code>SELECT email FROM users
JOIN   user_interests ON user_interests.id = users.id
WHERE  user_interests.interest_id = 2
</code>```

All users who are interested in IDs 2, 3, 4 and 5:

```<code>SELECT email FROM users
JOIN   user_interests ON user_interests.id = users.id
WHERE  user_interests.interest_id IN (2, 3, 4, 5)
GROUP BY users.id
HAVING COUNT(users.id) = 4
</code>```

However, many frameworks (e.g. CakePHP for PHP) will do this for you.

Body:
Design patterns apply more to code, than to databases. When you have entered the database world, you simply want a normalised database. The biggest issue you have with the composite pattern is scale: in order to manipulate those OO objects, you'd need to pull all the data from the database regardless if you need it - which is a waste and impractical if you get large lists.

In your case:

users: id, name, email, etc

interests: id, description

users_interests: user_id, interest_id

with the appropriate primary/unique keys. After that, you can get all of the information you need in a single database query.

For example:

All emails who are interested in cycling (id=2):

SELECT email FROM users
JOIN   user_interests ON user_interests.id = users.id
WHERE  user_interests.interest_id = 2

All users who are interested in IDs 2, 3, 4 and 5:

SELECT email FROM users
JOIN   user_interests ON user_interests.id = users.id
WHERE  user_interests.interest_id IN (2, 3, 4, 5)
GROUP BY users.id
HAVING COUNT(users.id) = 4

However, many frameworks (e.g. CakePHP for PHP) will do this for you.


问:
RESTful API design - should a PUT return related data?
I have an API which allows a user to update their system status; and a separate call to retrieve system status updates from other users. Would it make sense to unify them under a PUT request where a user would request a PUT update with their own status update, and they would receive the status updates of other users?

My solution would allow the PUT request to call the GET request method internally. The reason behind this is that when a user updates their system status they should be informed of other users status immediately, and I don't feel that having 2 seperate requests is necessary - and should be optional.

I intend to keep the GET request for other users status as a status update for a user is not necessarily required in order to retrieve other users status', but once they update their own status is it vital that they get information about other users.

答:
I don't think you should, for a few reasons:

A PUT request it exactly that. They are sending you information and you should take it. You shouldn't change the semantics to "I'll take your data, if there's a mistake, I'll give you an error, but I'll also give you other data that you may or may not actually want or need.

What guarantees do you have that every caller of the PUT request wants the related data?

The caller wants to send you 1 update a second, and retrieve related records every minute. Why waste bandwidth and CPU giving them data they don't want?

What if the request fails or is rejected (e.g. empty/missing status)? Do you still return the related data

How are you going to separate the related data from the return messages from the PUT request? Is this consistent with your other APIs?

What is special about them updating then them getting updates about other users? Can't the two occur in parallel (i.e. they fire a GET and PUT at the same time?).

If you absolutely want this, you should make it an optional flag or call. If they specifically say fetchMeTheRelatedData then give it to then, but do not give it to them by default.


答:
LinkedIn tracks some interesting statistics about a wide range of skills including programming languages.

https://www.linkedin.com/skills/skill/C%2B%2B?trk=skills-pg-search

https://www.linkedin.com/skills/skill/Java?trk=skills-pg-search

https://www.linkedin.com/skills/skill/x86_Assembly?trk=skills-rel-10

https://www.linkedin.com/skills/skill/C%23?trk=skills-pg-search

On these pages, you can see the name of the skill, a short description, links to related skills, a year on year trend (C++ went down 8%).  You can display a bar graph that shows relative growth vs. some technologies they pick for you, size of the pool of people using the language (913k for C++), or the age break down for people using the language (31% for 18-24, 45% 25-35, and 17% 35-45).  Java has about one million, and has a profile that is surprisingly similar.  C# has been trending -3% y/y, has a smaller base 617k, 18-24 23%, 25-34 50%, and 35-44 20%.

For a skill like x86 assembler, there is a pool on only about 12K users, and surprisingly, 25-34 year olds are 41%, 18-24 year olds are 29%.

Use of these numbers from LinkedIn has all kinds of complications because the population of software developers is not even among age groups (18-24 9%, 25-34 47%, 35-44 31%, 45-54 17% for the term Software Development), and some of counts may relate to who uses LinkedIn (it may under represent college students not yet looking for work and older professionals who are established and not looking for work or who use person-to-person networking more than online).

http://www.eweek.com/c/a/Application-Development/Java-Drops-From-Top-Programming-Language-Spot-C-Rules-626622/ talks about language popularity, but doesn't give any characterization with regard to developer preference vs. age.


问:
Immutable Method in Java
In Java, there is the final keyword in lieu of the const keyword in C and C++.

In the latter languages there are mutable and immutable methods such as stated in the answer by Johannes Schaub - litb to the question How many and which are the uses of “const” in C++?

Use const to tell others methods won't change the logical state of this object.

```<code>struct SmartPtr {
    int getCopies() const { return mCopiesMade; }
}ptr1;

...

int var = ptr.getCopies(); // returns mCopiesMade and is specified that to not modify objects state.
</code>```

How is this performed in Java?

答:
You can't. I'm not familiar with Java 7, but at least in Java 6 you cannot tell the compiler a method is not supposed to mutate its arguments or the this instance.

Unfortunately final in Java doesn't mean the same as const in C++.

A final argument means something else: merely that you cannot reassign it, so that the following is an error:

```<code>A method(final B arg) {
    ...
    arg = something;  // error, since arg is final
    ...
}
</code>```

This is a good practice, but it won't prevent you from mutating arg by calling one of its methods.

A final method such as final A method(...) is related to subclassing rules, and not with mutation.

Title: Immutable Method in Java

Body:
You can't. I'm not familiar with Java 7, but at least in Java 6 you cannot tell the compiler a method is not supposed to mutate its arguments or the this instance.

Unfortunately final in Java doesn't mean the same as const in C++.

A final argument means something else: merely that you cannot reassign it, so that the following is an error:

A method(final B arg) {
    ...
    arg = something;  // error, since arg is final
    ...
}

This is a good practice, but it won't prevent you from mutating arg by calling one of its methods.

A final method such as final A method(...) is related to subclassing rules, and not with mutation.


问:
Statistical Software Quality Control References
I'm looking for references about hypothesis testing in software management. For example, we might wonder whether "crunch time" leads to an increase in defect rate - this is a surprisingly difficult thing to do.

There are many questions on how to measure quality - this isn't what I'm asking. And there are books like Kan which discuss various quality metrics and their utilities. I'm not asking this either. I want to know how one applies these metrics to make decisions.

E.g. suppose we decide to go with critical errors / KLOC. One of the problems we'll have to deal with with that this is not a normally distributed data set (almost all patches have zero critical errors). And further, it's not clear that we really want to examine the difference in means. So what should our alternative hypothesis be?

(Note: Based on previous questions, my guess is that I'll get a lot of answers telling me that this is a bad idea. That's fine, but I'd request that it's based on published data, instead of your own experience.)

答: I hope this answer is not too basic, but a simple, but I believe effect method for evaluating metrics is the control chart.  This chart shows an expected performance range, and when the metric goes outside, it is easy to spot.  Informally, there may be some techniques to plot defects per hundred committed changes vs. day within a 28 day sprint that would show whether changes early in the sprint were relatively defect free, but at then end, things turn ugly.  It might be interesting to show a before and after Agile that shows similar plots for days after the deadline vs. days before the deadline.</p>


问:
Hibernate set up for beginner
I am learning Hibernate (OR Mapping). I am using Maven for project management. However, I am currently reading a Hibernate book by O'Reilly, and they use ANT for their example. So my question is are there any difference between setting up hibernate with ANT and Maven?

Thanks in advance!

答:
No there is no difference when you setup Hibernate either way. Using maven or ant will only change the way you configure, build, deploy your project.

The way you write Hibernate code will not change in any way if you use Maven or Ant.

In maven pom.xml you will have to add the repository as documented below -

```<code> <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.1.Final</version>
            <classifier>tests</classifier>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>
</code>```

And the following repository will have to be added -

```<code>    <repository>
        <id>JBoss</id>
        <name>JBoss Repsitory</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>
</code>```

Title: Hibernate set up for beginner

Body:
No there is no difference when you setup Hibernate either way. Using maven or ant will only change the way you configure, build, deploy your project.

The way you write Hibernate code will not change in any way if you use Maven or Ant.

In maven pom.xml you will have to add the repository as documented below -

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.1.Final</version>
            <classifier>tests</classifier>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.0.CR2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>

And the following repository will have to be added -

    <repository>
        <id>JBoss</id>
        <name>JBoss Repsitory</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>


问:
confusion understanding the fluid 2 column navigation layout
I'm trying to understand the following cross-browser layout: http://matthewjamestaylor.com/blog/perfect-2-column-left-menu.htm but I'm having some confusion with some of its parts and there isn't enough information on the page or in the css comments to help me.

What is the purpose of the .colleft div? Why can't the 2 columns be directly under the .colmask container?

Why does the .colleft div have a right 75%? I don't understand its purpose/benefit.

Why don't the widths of .col1 and .col2 add up to 100%?

How was left:102% calculated for .col1 and left:6% for .col2? The comments for this are not very clear to me. How is it any different from not even specifiying a left/right css property?

答:
Do not be confused by the color-coded 'nested div structure'. It represents the div hierarchy in HTML, but the layout that is achieved is shown in the 'Percentage dimensions of the left menu layout'.

In this case, colleft is used as a spacer that sets aside space on the left column, while col2 is the actual content of the left navigation. Note the border around col2. Setting margins will probably give the same effect though.


问:
Is using something other than XML advisable for my configuration file?
I have a small tool I'm designing which would require a configuration file of some sort. The configuration file in my case is really more of a database, but it needs to be lightweight, and if needed the end-user should find it easily editable. However, it also will contain a lot of things in it. (depending on certain factors, could be 1Mb or more)

I've decided I'd rather use plain ol' text, rather than trying to use SQLite or some such. However, with using text, I also have to deal with the variety of formats. So far, my options are

XML

JSON

Custom format

The data in my file is quite simple consisting for the most part of key-value type things. So, a custom format wouldn't be that difficult... but I'd rather not have to worry about writing the support for it. I've never seen JSON used for configuration files. And XML would bloat the file size substantially I think. (I also just has a dislike of XML in general).

What should I do in this case?

Factors to consider:

This configuration file can be uploaded to a web service(so size matters)

Users must be able to edit it by hand if necessary(ease of editing and reading matters)

Must be able to generate and process automatically (speed doesn't matter a lot, but not excessively slow)

The "keys" and "values" are plain strings, but must be escaped because they can contain anything. (unicode and escaping has to work easily)

Multiple configuration files. Basically, each config file is tied to one "project"

答: I think YAML is best fit for your case. To my understanding, YAML is the de facto standard format for configuration files that need to be edited by hand. Many programming languages have a library for reading and/or writing YAML. JSON is closely related to YAML, but is little bit less easier to write than YAML, and is used more for communication between web server and the client program.</p>


问:
How do I sell my software on the Internet?
I'd like to sell my software on the 'net but am not sure how to do the whole Merchant setup.  I have access to Commerce Server 2009, and I want to seem professional so a plain old PayPal account is out.

What do I need to know/do to sell a few things using ASP.NET, accept credit cards, and what not?

答:
I've been using Share-it since 2002. http://www.shareit.com/

It works out to about 12%. They handle all of the product delivery and credit card transactions.


答:
The only way you can make a Java object immutable is from within the class of that object itself and not from other calling classes.

You may only have constant pointer (final reference by the official Java name) meaning that you cannot modify the reference to point to another object; you cannot have pointer to constant, meaning you cannot modify the referring object, as you may have in C/C++.

Title: Immutable Method in Java

Body:
In Java, there is the final keyword in lieu of the const keyword in C and C++.

In the latter languages there are mutable and immutable methods such as stated in the answer by Johannes Schaub - litb to the question How many and which are the uses of “const” in C++?

Use const to tell others methods won't change the logical state of this object.

```<code>struct SmartPtr {
    int getCopies() const { return mCopiesMade; }
}ptr1;

...

int var = ptr.getCopies(); // returns mCopiesMade and is specified that to not modify objects state.
</code>```

How is this performed in Java?


答:
The only way to create const method in Java is to create a const interface for the object. Like:

```<code>interface ConstSomething {
    int getCopies();
}
class Something implements ConstSomething {
    int getCopies() { return mCopiesMade; }
}
</code>```

Yes, unlike C++ const this affects performance, because now the method has to be called virtually.

Note, that the same applies to C#.

Title: Immutable Method in Java

Body:
The only way to create const method in Java is to create a const interface for the object. Like:

interface ConstSomething {
    int getCopies();
}
class Something implements ConstSomething {
    int getCopies() { return mCopiesMade; }
}

Yes, unlike C++ const this affects performance, because now the method has to be called virtually.

Note, that the same applies to C#.


答:
Java's final is not in lieu of C's const. In Java final may appear in five places. Attribute, variable and formal parameter declarations and class and method definitions. Using final for attributes, variables or parameters means, you cannot reassign them, so the following will not be accepted by the compiler:

```<code>final List<String> xs = new ArrayList<>();
xs = new LinkedList<>(); //illegal
</code>```

However, note that you can still change the object referenced by xs:

```<code>final List<String> xs = new ArrayList<>();
xs.add("Hello World");
</code>```

As for classes, final forbids inheriting from this class. So, this is illegal too:

```<code>final class A {
}

class B extends A { //illegal
}
</code>```

And for methods final forbids overriding the method in a subclass, thus the following is illegal.

```<code>class A {
    final void m() {}
}

class B extends A {
    final void m() { System.exit(1); } //illegal
}
</code>```

So why would anyone use one keyword for three different intentions? Well, they are connected. If you take a look at java.lang.String you will see, that it is declared as final. And since there are not operations in String that will change the value of the instance you can safely assume that

```<code>final String GREETING = "Hello, World!";
</code>```

defines a constant.

BTW, const is a reserved word in Java, too. But it has no semantics and thus cannot be used in any Java program.

Title: Immutable Method in Java

Body:
Java's final is not in lieu of C's const. In Java final may appear in five places. Attribute, variable and formal parameter declarations and class and method definitions. Using final for attributes, variables or parameters means, you cannot reassign them, so the following will not be accepted by the compiler:

final List<String> xs = new ArrayList<>();
xs = new LinkedList<>(); //illegal

However, note that you can still change the object referenced by xs:

final List<String> xs = new ArrayList<>();
xs.add("Hello World");

As for classes, final forbids inheriting from this class. So, this is illegal too:

final class A {
}

class B extends A { //illegal
}

And for methods final forbids overriding the method in a subclass, thus the following is illegal.

class A {
    final void m() {}
}

class B extends A {
    final void m() { System.exit(1); } //illegal
}

So why would anyone use one keyword for three different intentions? Well, they are connected. If you take a look at java.lang.String you will see, that it is declared as final. And since there are not operations in String that will change the value of the instance you can safely assume that

final String GREETING = "Hello, World!";

defines a constant.

BTW, const is a reserved word in Java, too. But it has no semantics and thus cannot be used in any Java program.


问:
Unit test: How best to provide an XML input?
I need to write a unit test which validates the serialization of two attributes of an XML(size ~ 30 KB) file.

What is the best way to provide an input for this test?

Here are the options I have considered:

Add the file to the project and use a file reader

Pass the contents of the XML as a string

Create the XML through a program and pass it

Which is my best option and why? If there is another way which you think is better, I would love to hear it.

答:
Option 2 is probably awkward since you will have to escape all double quotes " of the XML attributes.

Option 3 just moves the problem to another place.

Go for option 1. With an external XML file, you can use all the advantages of a XML editor to prepare the input.


答: It's not 100% what you're looking for, but you can have a look at Xtext and this thread. But obviously that might not help you if your in-house DSL isn't Xtext-based...</p>

Title: Debugging framework for domain specific language

Body:
I want to know if there are any tools/tool-kits which aid in building
source level debuggers for domain specific languages ?
(I work on a proprietary DSL, which doesn't have any tools
and sometimes debugging will become difficult, so, if in case
there are any such tool-kits, wanted to try)</p>


问:
Why is NoSQL faster than SQL?
Recently I was asked:

Why is NoSQL faster than SQL?

I didn't agree with the premise of the question... it's just nonsense for me personally. I can't see any performance boost by using NoSQL instead of SQL. Maybe SQL over NoSQL, yes but not in that way.

Am I missing something about NoSQL?

答:
The thing you are missing about NoSQL is that NoSQl cannot be compared to SQL in any way. NoSQL is name of all persistence technologies that are not SQL. Document DBs, Key-Value DBs, Event DBs are all NoSQL. They are all different in almost all aspects, be it structure of saved data, querying, performance and available tools.

So if someone asks you such question on interview, this should be the answer.

Title: Why is NoSQL faster than SQL?


答:
'NoSQL' (or more precisely: non-relational) databases give up some features of the traditional databases for speed, but more importantly for horizontal scalability.

The missing features depend on the concrete product, in general full ACID properties or even join operations are not supported. That is the price for the increased performance.

Title: Why is NoSQL faster than SQL?

Body:
Recently I was asked:

Why is NoSQL faster than SQL?

I didn't agree with the premise of the question... it's just nonsense for me personally. I can't see any performance boost by using NoSQL instead of SQL. Maybe SQL over NoSQL, yes but not in that way.

Am I missing something about NoSQL?


答:
There are many NoSQL solutions around, each one with its own strengths and weaknesses, so the following must be taken with a grain of salt.

But essentially, what many NoSQL databases do is rely on denormalization and try to optimize for the denormalized case. For instance, say you are reading a blog post together with its comments in a document-oriented database. Often, the comments will be saved together with the post itself. This means that it will be faster to retrieve all of them together, as they are stored in the same place and you do not have to perform a join.

Of course, you can do the same in SQL, and denormalizing is a common practice when one needs performance. It is just that many NoSQL solutions are engineered from the start to be always used this way. You then get the usual tradeoffs: for instance, adding a comment in the above example will be slower because you have to save the whole document with it. And once you have denormalized, you have to take care of preserving data integrity in your application.

Moreover, in many NoSQL solutions, it is impossible to do arbitrary joins, hence arbitrary queries. Some databases, like CouchDB, require you to think ahead of the queries you will need and prepare them inside the DB.

All in all, it boils down to expecting a denormalized schema and optimizing reads for that situation, and this works well for data that is not highly relational and that requires much more reads than writes.

Title: Why is NoSQL faster than SQL?


问:
Splitting big request in multiple small ajax requests
I am unsure regarding the scalability of the following model. I have little experience with large systems, big number of requests and so on but I'm trying to build some features considering scalability first.

In my scenario there is a user page which contains data for:

User's details (name, location, workplace ...)

User's activity (blog posts, comments...)

User statistics (rating, number of friends...)

In order to show all this on the same page, for a request there will be at least 3 different database queries on the back-end. In some cases, I imagine that those queries will be running quite a wile, therefore the user experience may suffer while waiting between requests.

This is why I decided to run only step 1 (User's details) as a normal request. After the response is received, two ajax requests are sent for steps 2 and 3. When those responses are received, I only place the data in the destined wrappers.

For me at least this makes more sense. However there are 3 requests instead of one for every user page view.
Will this affect the system on the long term? I'm assuming that this kind of approach requires more resources but is this trade of UX for resources a good dial or should I stick to one plain big request?

答:
Basically the speed is even less so no that does not really work out. You now still have the 3 queries which + overhead of 3 requests. Though page might build faster since it does not have to wait for all to complete.

If you don't like the speed don't abuse this ajax technique since it won't change your issue.

Instead cache the data and show the cache. You could even show an older cache and then load the most recent version with ajax if there is new data. Then the user has the page complete and most recent ones are added later after page is shown.

That request directly updates your cache so you have best of both worlds.