问:
Responsibilities of Build Script and Build Server
I need some clarifications on the responsibilities of the Build Script and the Build Server.

I read several articles on the Net about continuous integration and builds. Including

The F5 Key Is Not a Build Process

The Build Server: Your Project's Heart Monitor

Daily Builds Are Your Friend

And I had a conversation with my advisor about the build process of our software. Because he is very experienced I trust his statements, but I were left with confusion.

As I understand it, from my research (and please correct me here, since it is what I am asking about) the ideal should be as following:

every project has its build script

this script builds the project

this script makes sure the dependencies are built previously

Since dependencies could be other project, with their own build script a tree-like hierarchy accrues. There may be a top build script which builds all projects and applications.

However the Build Server's responsibilities are:

check out the repository

trigger the build

trigger tests and other QA tools

make the artifact available

This may be triggered manually, nightly or whenever the repository changes

The objectives of my advisor are, as I understand them, that one build script is way to inflexible and not maintainable (Aside from the fact that it would take very long from creating one for our legacy code base). Also the Build Server should maintain the dependencies, for example to use older dependencies when creating them new fails.
And particular for Ant as it was the concrete subject, is not able to build all kind of different technologies which are used in the code base, and is not able to maintain the dependencies.

Can you please elaborate the objectives, and clarify the responsibilities?

答:
These things are orthogonal:

The build script is the mechanism that, upon invocation on freshly checked-out source tree, yields a complete build of required targets and dependencies. It could simply be 'make all' if you've got a makefile, or a suitable invocation of MSBuild, Ant, Maven or Scons. If you have a complex hierarchy of dependencies or related projects, your 'build script' may be a top-level file that invokes each of them in turn, checking for success as you go.

The build script is just one script of possibly many - checkout, build, test, package - but you could have an all-in-one mechanism controlled by command line params - it depends on your environment.

The build server, or rather continuous integration server, is the automation mechanism responsible for scheduling/triggering, monitoring and reporting of the checkout -> build -> test -> package -> stage -> deploy pipeline. You could use cron/Task Scheduler if you had nothing more sophisticated to hand, but there are many excellent tools now such as Jenkins, Cruise Control, TeamCity, etc.

It is important that you can invoke a build without using the CI server, in the case that it is busy/offline/unreachable/otherwise-unavailable, so therefore the logic to get the build/test/whatever done needs to be outside of the CI system, but is invokable by it, parameterized by branch/build type/version/architecture, etc.


问:
How should you deal with a popular project that you no longer want to maintain?
I am the maintainer of a project which has a large non-technical userbase. I've been maintaining it for about 4 years now and adding new features as they've been requested.

I'd like to move on to other projects now and stop developing for this application. Because of the non-technical nature of the users, there have been very few code contributions in the past. I don't believe I will be able to find anyone else to take over the project in my stead.

Bugs, issues, feature requests - these are still coming in. I am still responding to emails for help, as I am not sure if I should ignore them, tell them that I'm not working on the application, or if I should respond to emails in only certain cases.

What is the best way to 'abandon' this project, but still let users use the application?

Update (July 2016) - It didn't go as planned.  I made an announcement in the README and soon after, I started receiving contributions of a more substantial nature.  Pull requests with bug fixes, features, documentation, issue activity.  Since then, the project has felt 'reinvigorated' and I'm now happily maintaining it along with newer projects.  I have collaborators as well.  At a guess, it may have been the kind of contributions which were affecting my view of the project and with the quality of contributions improving, it didn't feel like a chore any more.

答:
Announce your abandoning of the product to your community of users. Maybe you will find a successor for your role as maintainer. Try to organize some time of handover, as you would with a project in your day job.

As esr put it in The Cathedral And The Bazaar:

When you lose interest in a program, your last duty to it is to hand it off to a competent successor.

ContentLicense: CC BY-SA 3.0


问:
Implementing base-10 floating point division
I'm implementing floating-point arithmetic, for a micro-controller which does not support floating point numbers, in either hardware or software.
(Software being "written" in a sort of electrical diagram program.)
I've finished encoding/decoding from/to integers, adding, subtracting, and multiplication.
My "floats" are represented as C * 10^E, where:

C, the coefficient, is a 32-bit signed integer in the range 100000000-999999999, or 0.

(Nine digits of precision, plus the special case of zero.)

E, the exponent, is a 32-bit signed integer covering the whole 32-bit range.

(Yes, it's overkill.)

I chose round base-10 numbers to make the verification of the math easy.
My strategy for the multiplication was to split up the two numbers AaaBbbCcc and DddEeeFff into three pieces each (millions, thousands, and ones) and compute the multiplication as

```<code>(ABC * 10^Y) * (DEF * 10^Z) =
  ((AD * 10^12) +
   ((AE + BD) * 10^9) +
   ((AF + BE + CD) * 10^6) +
   ((BF + CE) * 10^3) +
   (CF * 10^0))
  * 10^Y+Z
</code>```

Each * and + representing a normal multiplication or addition, and 10^N being faked with me hard-coding in a 1000, 1000000, etc.
Also note that this neither recurses or loops, and any answer cannot recurse or loop.
I've got access to integer addition, subtraction, division, multiplication, modulo, cos/sin/tan/arccos/arcsin/arctan, absolute value, and square root.

Main Question:

I can/will eventually figure out how to do division with a similar approach of splitting the coefficients into smaller numbers which will be better for 32-bit division.
I haven't done my algebra in a long time, so multiplication took me about a day and a half.
Since I presume division to be more complicated conceptually, it would be super handy if somebody on SE could do the hard math for me.
So, how do I do this?

答:
The Handbook of Floating-point Arithmetic, while rather expensive, is about as comprehensive a reference as you can get on the subject. It's designed with applicative uses in mind though it may be hard to parse the formal sections of math contained there-in. However, it will give a solution set for division in both hardware and software if you can parse the content which is not particularly mathy unless you delve into the proof sections of the book.

Wikipedia also lists a number of division algorithms, most of which are covered in mind-numbing detail in the above book. The article even links a Javascript simulator to test out various algorithms.


问:
What's the word for an operation that can be applied multiple times and never change state beyond the initial application?
I'm trying to remember a word, I think it's related to computational or database theory. The closest synonym is atomic but that's not exactly it. Basically it's a kind of computation that should produce the same result even when run multiple times in a row, meaning it doesn't create side effects for itself.

I specifically ran across this word in a Stack Overflow answer about a chmod command (or some other permission related operation).

Hopefully that's enough to go on. Poking around Wikipedia isn't much help.

答:
You might be thinking of "Idempotent".

Idempotence is the property of certain operations in mathematics and computer science, that they can be applied multiple times without changing the result beyond the initial application.


答:
The general word is Idempotence which applies to both computers and to mathematics. It is not the same thing as Reentrant which it often gets confused with. Idempotence is precisely what you described, Reentrant is basically interruptible with the ability to pick up exactly where you left off.

Purely Functional languages like Haskell are built around the principle of being as close to Idempotent as is possible. The first three letters of the acronym ACID in Database Theory are Idempotence as applied to Databases.

Title: What's the word for an operation that can be applied multiple times and never change state beyond the initial application?

Body:
I'm trying to remember a word, I think it's related to computational or database theory. The closest synonym is atomic but that's not exactly it. Basically it's a kind of computation that should produce the same result even when run multiple times in a row, meaning it doesn't create side effects for itself.

I specifically ran across this word in a Stack Overflow answer about a chmod command (or some other permission related operation).

Hopefully that's enough to go on. Poking around Wikipedia isn't much help.


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

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

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

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

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

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

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

答: Maybe flip it around: if you found out this person was (say) a former World Cup soccer champion, or had received the Congressional Medal of Honor, would you be more likely to hire them?  Either way, I think it's totally valid to use this information when making your decision.  For example, if the candidate professed serious political/religious/racist beliefs, you should consider whether they would integrate well with the rest of the department.

ContentLicense: CC BY-SA 2.5


问:
How many regression bugs from refactoring is too many.
Recent QA testing has found some regression bugs in our code. My team lead blames recent refactoring efforts for the regressions.

My team lead's stance is "refactor, but don't break too many things", but wouldn't tell me how many is "too many". My stance is it's QA's job to find bugs that we can't find, and refactoring usually introduces breaking changes. So sure, I can be careful, but I don't knowingly release code with bugs to QA. I do it because I don't see them.

If the refactoring was necessary, how many regression bugs should be considered too many?

答:
You are right that refactoring code is important. It prevents code rot and improves code. It makes for cleaner code.

But good code is not only clean code, it's code that is correct, and thus by definition contains as few bugs as possible (ideally none). The first goal of your code is to produce its expected result. So if your refactoring is introducing bugs you might want to consider the net effect of those refactorings.

You should refactor code that is tested. If it's not, add tests and then refactor. This way you know you haven't broken anything. This will help mitigate the risks of a similar situation from happening in the future.

As for refactoring introducing bugs, refactoring should not alter the behavior of a program. I will quote from Wikipedia:

disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior

Sadly nowadays, refactoring has come to mean anything from this definition to total rewrites.

I would alter what your team lead said from:

refactor but don't break too many things

To:

refactor and don't break anything

As for finding bugs being the job of the QA, quality isn't someone else's problem. The goal should be that QA finds nothing. Realistically finding as little as possible.


答:
My stance is it's QA's job to find bugs that we can't find,

Finding bugs is a joint responsibility.

QA's job is to find bugs that you don't find.  There should not be such a thing as bugs that you can't find.  (And if there is, then maybe you should ask for access to the tools / tests that they are using so that you can find them for yourself.

refactoring usually introduces breaking changes.

That is not true.  Refactoring done properly doesn't break things.  And you could argue that fixing the things that break should be part of the refactoring.

The problems arise in reality when:

the refactoring triggers latent bugs in other parts of the codebase that the tests you can run don't reveal, or

you can't do the full refactor because someone else "owns" some parts of the code that is affected by the refactor.

You shouldn't cop the blame for latent bugs (unless they were yours in the first place).  But on the other hand, if your refactoring is intentionally changing APIs and or behaviours then you need to discuss this with all parties before you refactor, and have a plan for dealing with the effects.  On the third hand1, if the breaking change is unexpected or accidental ... then you should have thought it through in more detail.

And finally, if the regressions were your fault (or partly your fault), then "man up" and take the blame.  And aim to do better next time.

If he agrees that refactoring is necessary (which he does), then why does he have a problem when stuff breaks? Especially when it hasn't affected our schedule so far.

That is easy to answer if you put yourself into his shoes.  He thinks you did the wrong thing in the way you refactored the code.  This time it didn't impact on the schedule.  But next time, it could.  He is trying to prevent that eventuality.

1 - A Larry Niven allusion.

Title: How many regression bugs from refactoring is too many.

Body:
Recent QA testing has found some regression bugs in our code. My team lead blames recent refactoring efforts for the regressions.

My team lead's stance is "refactor, but don't break too many things", but wouldn't tell me how many is "too many". My stance is it's QA's job to find bugs that we can't find, and refactoring usually introduces breaking changes. So sure, I can be careful, but I don't knowingly release code with bugs to QA. I do it because I don't see them.

If the refactoring was necessary, how many regression bugs should be considered too many?


答:
You might be looking for a pure function.

As defined in the link, two conditions make a function pure:

The function always evaluates the same result value given the same argument value(s).

Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output
  to I/O devices.


问:
How do I take responsibility for my code when colleague makes unnecessary improvements without notice?
One of my teammates is a jack of all trades in our IT shop and I respect his insight.

However, sometimes he reviews my code (he's second in command to our team leader, so that's expected) without a heads up. So sometimes he reviews my changes before they complete the end goal and makes changes right away... and has even broken my work once.

Other times, he has made unnecessary improvements to some of my code that is 3+ months old.

This annoys me for a few reasons:

I am not always given a chance to fix my mistakes

He has not taken the time to ask me what I was trying to accomplish when he is confused, which could affect his testing or changes

I don't always think his code is readable

Deadlines are not an issue and his current workload doesn't require any work in my projects other than reviewing my code changes.

Anyways, I have told him in the past to please keep me posted if he sees something in my work that he wants to change so that I could take ownership of my code (maybe I should have said "shortcomings") and he's not been responsive.

I fear that I may come off as aggressive when I ask him to explain his changes to me.

He's just a quiet person who keeps to himself, but his actions continue. I don't want to banish him from making code changes (not like I could), because we are a team--but I want to do my part to help our team.

Added clarifications:

We share 1 development branch. I do not wait until all my changes complete a single task because I risk losing some significant work--so I make sure my changes build and do not break anything.

My concern is that my teammate doesn't explain the reason or purpose behind his changes. I don't think he should need my blessing, but if we disagree on an approach I thought it would be best to discuss the pros and cons and make a decision once we both understand what is going on.

I have not discussed this with our team lead yet as I would prefer to resolve personal disagreements without getting management involved unless it is necessary. Since my concern seemed more of personal issue than a threat to our work, I chose to not bother the team lead. I am working on code review process ideas--to help promote the benefits of more organized code reviews without making it all about my pet peeves.

答:
I think you are handling it the right way for now - but there will soon be a tipping point where it distracts you to the extent you might not be happy coding this way at all.

If I were you, I would request a quick one-to-one with this person and explain my PoV calmly yet firmly. Team ownership of code etc is all fine but unless you give every developer enough space to put his work out, make mistakes and improve you will never build good code. This can be a friction area sooner rather than later.

(There is a totally different answer if this was on workplace.stackexchange. Figuring out the correct way to do code reviews is the easy bit. Convincing your co-worker to comply with this is a lot harder).

OwnerDisplayName: Jesslyn


问:
Banking Applications need Auto save?
We are developing a banking application. It's internal project of the bank. The application has to capture huge data to process.

So auto save is recommended approach to capture? How to perform validations in case of auto save?

And on jsp unload saving the data is correct approach?

Which is best way of saving form data in case of auto save? If any network errors occur, how to handle, mean giving end user the data is not saved? I think it's just a feasible solution. Please suggest me optimal solution.

答:
data capture + high data volume + web application + performance == FAIL

Sorry, but you will have to seriously rethink the planned solution route to your homework assignment.

Think client-server instead.

Title: Banking Applications need Auto save?


问:
What does using ZeroMQ in Erlang offer that Erlang already didn't?
I'm only passingly familiar with either, but it seems like most of what ZeroMQ offers is already built into Erlang, yet there's an Erlang-ZeroMQ binding that's fairly active according to its github page.  What am I missing?</p>

答: Perhaps communication with a ZeroMQ bound but non Erlang process.</p>


问:
How do I get my first job at a freelancing website?
I am new to freelancing websites. The problem is I have zero rating and I can't get any projects even if I bid the lowest amount.

I tried bidding aggressively. I even tried bidding the lowest possible amount to get my first project but still people having higher ratings get the project. This in turn prevents me from getting any rating which prevents me from getting any new projects.

I am stuck in this cycle.

答:
You can make some projects for free, in order to increase your rating. Just keep on searching for projects. That's it. When you get and complete the first one, you will get all the next ones faster and faster. Try to get each project you know for sure you can complete in time.

Good portfolio is extremely important. A project customer will look portfolios of freelancers and make a decision, who to choose. Make a portfolio of you previous works and put a link to it in your profile so that people could see, that you actually can do this kind of work well.

Also you can probably specify in your profile, which kind of work you can do. Maybe, it worths putting there information of your education, where did you study which technology. For how long do you use each of them.


问:
Implement a file system for ios devices
I've read that ios apps can communicate via unique urls. An online tutorial on tutsplus
says

Communication between apps provides your application with an opportunity to take advantage of other application’s functionality, send and receive data between apps, and provide a rich user experience that “just works”.

I have to admit that since I have no experience with objective c and cocoa I only scanned the article. But as far as I've understood the url based communication, your app can register a unique url that serves as a socket for communication.

Is this not the perfect basis for a crude file system ? I know that all ios apps run in a sandbox and can only access their own data. I do recognose the merits of this design decision but still it seems cure and curse at the same time. This is not meant to be a discussion about apple's ecosystem and the concept of ios apps.

My question is simply:

Can url communication be used to create a file storage that works like a simple "desk" ? I would love an app that could store and host my files to allow a simpler workflow between different apps. Is this technically possible or did I misunderstand the url system ? Would apple allow an app like this in the app store ?

答:
While I think your use case is solved by the URI scheme communication, it wouldn't be a good user experience. Here's some documentation about the URI handling (see the Implementing Custom URL Schemes section).

To build a file system using that, you'd define a URI scheme that lets other apps tell you an action, a path, and a callback URI. Something like:

```<code>x-my-filesystem://home/Documents/MyFile.doc?action=read&callback=x-doc-reader%3A%2F%2F...
</code>```

When someone tried to open one of your files from another app, it would switch their iPhone to your app. Then when you've handled the request you'd call the callback, and it would hand the thing back to the other app. That's visually jarring as well as slow—you've added twice the transition animation time (about a second in total) on top of the actual work time. In addition, you'd run the risk of being rejected for "duplicating Apple functionality", as the device already has a filesystem. Admittedly not one that can be used for IPC, but it has one.

The Dropbox-style approach of providing an SDK used by host apps solves all of the problems above. Unlike a filesystem for a "traditional" operating system like OS X or Windows, apps need to specifically opt-in to both the Dropbox approach and the custom-URI one outlined above. The remote filesystem technique gives apps cross-device syncing (including potentially across platforms) so is better still than the technique you outline.

Title: Implement a file system for ios devices

Body:
While I think your use case is solved by the URI scheme communication, it wouldn't be a good user experience. Here's some documentation about the URI handling (see the Implementing Custom URL Schemes section).

To build a file system using that, you'd define a URI scheme that lets other apps tell you an action, a path, and a callback URI. Something like:

x-my-filesystem://home/Documents/MyFile.doc?action=read&callback=x-doc-reader%3A%2F%2F...

When someone tried to open one of your files from another app, it would switch their iPhone to your app. Then when you've handled the request you'd call the callback, and it would hand the thing back to the other app. That's visually jarring as well as slow—you've added twice the transition animation time (about a second in total) on top of the actual work time. In addition, you'd run the risk of being rejected for "duplicating Apple functionality", as the device already has a filesystem. Admittedly not one that can be used for IPC, but it has one.

The Dropbox-style approach of providing an SDK used by host apps solves all of the problems above. Unlike a filesystem for a "traditional" operating system like OS X or Windows, apps need to specifically opt-in to both the Dropbox approach and the custom-URI one outlined above. The remote filesystem technique gives apps cross-device syncing (including potentially across platforms) so is better still than the technique you outline.


答:
ZeroMQ bindings are available for a lot of programming languages, not just Erlang; this is one of the library's great strengths.

Erlang's built-in mechanisms are probably great as long as everything uses Erlang, but I doubt they are in any way compatible with other languages' native networking mechanisms.

Title: What does using ZeroMQ in Erlang offer that Erlang already didn't?

Body: I'm only passingly familiar with either, but it seems like most of what ZeroMQ offers is already built into Erlang, yet there's an Erlang-ZeroMQ binding that's fairly active according to its github page.  What am I missing?</p>


问:
Tricky compareTo, inheritance, easy to extend - Java
Let's say we have 4 classes A, B, C, D where: A is a superclass of both B and C and C is a superclass of D. I suppose, in a diagram, it should look like this:

```<code>   A
 /   \
B     C
       \
        D
</code>```

Moreover, the class A implements the interface

```<code>Comparable<A>
</code>```

and also implements a method

```<code>public int compareTo(A another)
</code>```

I'd like to be able to compare every pair of objects x, y such that they are instances of classes from the set {A, B, C, D}.  Naturally, I should implement a compareTo method in each of these classes but by default I'm doing this with one sided effect, i.e. defining how to compare object c from C with b from B doesn't tell anything about how to compare b with c.
Now, I could write a lot of code and handle all of those cases (this also means I would have to use 'isInstance' method to handle these, right?) but then every two classes have to be 'aware of' existence of others. So if I wanted to add another class, E, such that D is a superclass of E, I would have to serve all cases in the new class E and moreover I'd have to change something in classes A, B, C, D in order to 'be aware of E'.

So I'm struggling to find an elegant solution to it, i.e. one that doesn't entail changing a lot while adding a new class to the hierarchy.
How can I achieve this?

Thank you in advance for help.

答:
I think what you want is sort of multiple dispatch which is ususally implemented in Java using the Visitor-Pattern but you would have to change the code when adding new classes.

Since you don't really need full-blown multiple dispatch I think the following might be a good solution. Write your compareTo methods like this: (This is the one in TestB)

```<code>@Override
public int compareTo(TestA o) {
    if(o instanceof TestB) {
        // add your code instead
        System.out.println("Compare Bs");
        return 0;
    } else {
        return super.compareTo(o);
    }
}
</code>```

Since the call to x.compareTo is resolved at run-time you always run the compareTo function of the most specific class. By checking if the other argument is instanceof the current class you can detect when you have to move up the hierarchy which you can do calling super.compareTo.

Let me know if you have any further questions. :)

Edit: I assumed what you wanted to do was compare as the most specific common ancestor as per your comment on the original question.

Body:
I think what you want is sort of multiple dispatch which is ususally implemented in Java using the Visitor-Pattern but you would have to change the code when adding new classes.

Since you don't really need full-blown multiple dispatch I think the following might be a good solution. Write your compareTo methods like this: (This is the one in TestB)

@Override
public int compareTo(TestA o) {
    if(o instanceof TestB) {
        // add your code instead
        System.out.println("Compare Bs");
        return 0;
    } else {
        return super.compareTo(o);
    }
}

Since the call to x.compareTo is resolved at run-time you always run the compareTo function of the most specific class. By checking if the other argument is instanceof the current class you can detect when you have to move up the hierarchy which you can do calling super.compareTo.

Let me know if you have any further questions. :)

Edit: I assumed what you wanted to do was compare as the most specific common ancestor as per your comment on the original question.


问:
How to decide the token expiry time in REST web service
I am working on creating a REST ws exposing few API's. A token is required for each API call. I am confused about the expiry time to be set for the token.

Security+Performance wise what is the ideal expiry time for token (if there is one)?

答:
Generally speaking I'd say it depends on what the API is for.

If your users are just going to make the occasional call, then a short expiry will be fine - a few minutes, perhaps; just long enough to cover a second call if there's an error with the first one.

If they'll be using it in longer sessions, then a longer time will be needed; about twice the length of the average session seems sensible, so if the average user uses the software in a way that generates API calls for about twenty minutes, then a thirty- or forty-minute expiry time should do.

If the API is used more continuously, perhaps by a mobile app that's updating regularly all day, then  it's a judgement call.

If the calls are far enough apart, then a short token is fine, as in the first example; they'll have to auth every time, but not on re-submissions if there's an error.

If the calls are more frequent, then it's just a matter of how long you think is "secure"; I'd say definitely not more than a day. If you have the facility to do so, try timing some calls, with no token, a valid token and an expired token. Then, look at your average usage and see how often it generates API calls. I'd say to set your expiry time such that the average time for all calls is not more than 1.5 times the average call with a valid token (ie. the process of getting a new token is not adding more than 50% to the total time). If that feels slow in testing, reduce the fraction to 1.45, 1.4, 1.35 etc until it feels ok.


答:
In linear algebra linear, idempotent functions are called projections. Maybe that's the word you're looking for. :)

http://en.wikipedia.org/wiki/Projection_(linear_algebra)


问:
Tool helping with estimations
I am looking for a tool supporting me with estimations.

What I would like to do is to specify a higher level task and break it into several smaller tasks. When a task is small enough, I could assign the time it takes to finish it. The sum of these quantifiers should show up in the parent tasks.

One could use Project for this, but IMHO this is some kind of overkill ...

Also nice would be if you could do this like mindmapping so that a parant node sums up all of its childs estimations.

Is something like this out there?

答:
You can try AbstractSpoon's ToDoList. It has also been packaged as a portable application.

You can type the estimate in the “Time Est.” field (and choose a unit). They will add up to the parent task.

Title: Tool helping with estimations


问:
How to handle "animated" game where the visual should "animate" instead of abruptly change?
I've been playing around and learning javascript/KineticJS by making some simple games (think like board games).

I have the game model that is relatively logically simple. When a "move" is given to my game model, it updates the properties of all the pieces.

However, I would like to make the view have some nice-looking animation. For example, when six pieces are taken I don't want them to disappear all at once, I'd rather have them animate out 1 by 1.

To solve this problem, I basically have the game model tell my view "I updated the following pieces: [list]" And my view adds them to a "visual update queue" that a timer thread is always checking and handling one by one each time it triggers.

I'm interested in any opinions on this approach, and since this has obviously been considered before, if any of you handle this problem differently.

Thanks!

答:
A common approach is to have a main loop which calls all your visible game objects beginFrame(time_diff) function with a time value. That time value is the delta-time (milliseconds) since last time it was called.

What you then need is some kind of interpolation system which is based on that time_diff. For instance, you could update the alpha-value based on the time_diff and some interpolation of the alpha value. So you essentially add animations to specific scene objects. For instance:

"On piece_1 Linearly interpolate the alpha value from 0 to 1 with duration 1.5 seconds"

That way you handle all your game objects (scene objects) in the same predictable way.

Obviously, this requires a bit of work to implement so you might want to check out some existing game framework which provide this for you, for instance Sparrow. Its for ObjC but the author describes the process pretty well. Sparrow does not use a main loop, but uses events. So each game object has to register themselves with the event dispatcher, but the idea is the same.


答:
Another possibility is deterministic.

In computer science, a deterministic algorithm is an algorithm which,
  given a particular input, will always produce the same output, with
  the underlying machine always passing through the same sequence of
  states.


答:
Advice 1: Pick the price accordingly to your skills

Bidding the lowest amount may be the problem. In the eyes of a customer, low price equals low quality. Persons who already tried the services of freelancers and IT consulting companies know that lowest price means more money to pay later, and a much higher risk of seeing the project never succeeding.

If I hire a developer who asks $10 per day of work, I can't and shouldn't expect too much. I may be very surprised about how good and serious this developer is, but if the project fails, the only person to blame would be myself.

If I hire a developer and pay him $900 per day, I expect some good job in return. If the project is late, with no architecture and design whatsoever, written in crappy code and not matching half of the original functional and non-functional requirements, the only reason to blame myself would be the fact that I was too naive to be ripped off by a liar.

Pick the price accordingly to your skills. Don't ask too much: the customers will be disappointed. Don't ask too little: you will get customers who are desperate enough to sacrifice quality for immediate savings or who have no idea about how software development works.

Advice 2: Build your profile accordingly to what your customers are looking for

It's like during a hiring process: different types of companies are expecting different things from you, and a given CV type will work for some, but not for others.

For example, I myself have a US-oriented CV which fails completely in France. Here, in France, companies don't want candidates to write code during the interviews, they don't want to read about your projects, they don't care about how much do you share with the community or how much do you publish open source code, and they definitively don't know what competency matrix is. On the other hand, my CV will work much better if I search for a job at Fog Creek, Google or Microsoft.

In the same way, learn what are your customers expecting.

Do they expect you to be highly rated by the community?

Do they expect to see samples of your source code?

Do they want to exactly know who are you, what is the registration number of your company, etc. (I personally don't bear doing business with someone who don't even care giving me his family name)?

Do they expect you to be in their country or their city? Maybe they also expect to be able to visit you or that you visit them if they want to discuss about their project in more details?

Do they want somebody friendly and open?

Are they searching for a company or for a person?

Do they care about how well you write, or they are satisfied with a person who makes two mistakes in three words in average?

etc.

How do you learn about what your customers are looking for? Given the context, it's not an easy task, because you often have too little information about a given customer. You may still:

Do assertions from everything you can get from the freelancing website, especially the description of the project. A one sentence description and a 300 pages PDF document with functional and non-functional requirements indicate two very different profiles, and your response should change accordingly.

Watch the profiles of your competitors who won the bid. Why they won? Were they asking for a lower price? Was their profile more complete? Better written? Were they giving feedback and asking lots of questions about the project? Yes, rating is extremely important, but it's not the sole factor.

If you can, interview the persons who might have been the customers. How do they react? What do they expect? The task is very similar to what you do when you test a software product to determine if the user experience is good enough.

Advice 3: Ask for a feedback to more experienced persons

You can't ask for this sort of feedback on Stack Exchange, because it's both off-topic and too localized, but you can ask for feedback to the persons you know in real life. Show them your profile. What do they think? What could or should be improved?

The persons you may be interested in are:

Your fellow developers. Unless you're an expert in your domain, you may not know a few things, and reveal it in your profile. When a candidate for an interview writes: "I'm familiar with the latest database products like Sql.", it's embarrassing.

Visual designers and interaction designers (if you're building your own website with your profile). Ideally, hire one designer. If you can't, at least ask for a feedback to one. Don't be disappointed about how terrible your website is: most websites you visit daily are astonishingly terrible, and still they are used and are making money.

Persons who are familiar to proofreading. When I need to hire someone and receive a CV in French, from a native French speaker, where there are mistakes in nearly every sentence - mistakes Microsoft Word would underline, I already know that the candidate must be excellent technically to be hired.

Most people don't know how to write, but what is acceptable for a YouTube comment or a text message is not acceptable for a public profile or a book.

Proofreading your profile is very valuable. Even if you're a native speaker. Native speakers are convinced that they don't make mistakes; they do, and much more they could even imagine.

Persons who work in human resources, in psychology, in marketing, etc. They are all valuable as well.

Title: How do I get my first job at a freelancing website?

Body:
I am new to freelancing websites. The problem is I have zero rating and I can't get any projects even if I bid the lowest amount.

I tried bidding aggressively. I even tried bidding the lowest possible amount to get my first project but still people having higher ratings get the project. This in turn prevents me from getting any rating which prevents me from getting any new projects.

I am stuck in this cycle.


问:
What is the difference between a stock-hardware and a micro-coded machine in "A Critique of Common Lisp"?
I was reading this article: A Critique of Common Lisp and finding it hard to make out the precise definition of "stock-hardware machine" and its difference with "micro-coded" machines. I tried to search for a precise definition of the former to no avail.

What I currently construe stock-hardware machine to be is that, it refers to the computer chip-set commonly available in the market (without much customization).

So given that I would like to ask, what is meant by a stock-hardware machine (in the context of the paper) and how does it differ from a micro-coded machine?

答:
In the mid 70s (almost 40 years ago) a few Lisp Machines started to appear. Xerox (PARC) and MIT were developing them. Later Symbolics, LMI, TI and some others. Xerox was using one of their typical bit-slice processors and MIT developed a custom processor (CONS and then the CADR). The Xerox processor was used in a computer which also could run their office software suite and the Smalltalk software. The Xerox processor was using different instruction sets for each. The instruction sets of the processor was programmed in microcode. The MIT Lisp machine also had a processor, which could be programmed in microcode - but it was only used for Lisp. At that time processors were not microprocessor CPUs like today, but one or several boards which make a single CPU. Most computers during the 70s capable of running Lisp were time-shared mainframes or so-called mini-computers (often machines from DEC). Workstations or powerful personal computers did not exist then. The Lisp Machines were designed to be the first personal workstations (single user, no time-sharing, large address space, bitmap display, graphics, mouse, network, ...). To run Lisp efficiently with the processor technology at that time, they needed customized instruction sets. We are talking about early machines with around 1 MB RAM, virtual memory on disk, and less than 1 MIPS (million instructions per second).

The microcoded machines had specially crafted instruction sets to support the execution of Lisp (stack architecture with stack instructions, generic arithmetic, fast function calls, Lisp datatypes, GC support, ...). In the case of the MIT Lisp Machine, the hardware itself also had extensions (like special memory word widths).

The stock-hardware computers were using CPUs like the DEC VAX, Motorola 68k, Intel 86 and later SPARC, POWER, MIPS, ALPHA and many others. These computers used the CPUs like they came from the manufacturer (DEC, Motorola, Intel, IBM, ...). Beyond simple bug fixes (and Lisp developers found several bugs in CPUs) there was no special adaption of the instruction set of these computers while they were running Lisp. Some of them even might have been able to have loadable microcode - but it was not used for Lisp.

The microcoded Lisp CPUs allowed very simple instruction sets and thus a relatively simple Lisp compiler. Additionally some variants allowed to compile simple Lisp functions to microcode. The MIT used a custom CPU, because they wanted a large address space for Lisp, compact code and quick execution for the first personal workstations. A combination which was not available on the market at that time (1970s/ early 80s). Note that these CPUs appeared before Common Lisp (which was first published in 1984). Over time the manufacturers moved the CPUs through different technologies and different Lisp versions. Thus they added support for object-oriented programming (Flavors, CLOS) and logic programming to the instruction sets. It was not unusual for a new Lisp release to also come with an improved microcode with new/improved instructions. Later TI and Symbolics developed microprocessors - single-chip CPUs for Lisp. At least the Symbolics chip was not designed to support loadable microcode.

Summary:

microcoded machines are computers with either bit-slice CPUs or special Lisp cpus with special instruction sets for Lisp.

stock-hardware machines are computers with typical commercial CPUs, as they were designed by the manufacturer - without special Lisp support. Of the later stock hardware machines only the SPARC architecture contains a very tiny amount of support for Lisp (and Smalltalk).


问:
When should I care about performance?
For the longest time in places like Java's IRC channel, SO, and other places I've been told something along the lines of "Worry about how the code looks and its readability/understandability now, and performance later if absolutely necessary". So for the longest time, I haven't really been OCD about performance for my small desktop or web apps, just removing the obviously inefficient.

Most responses are "What about scalability?". Thats a legitimate point, but if my app was only built to parse, say, files 10,000 lines long, should I make my code a mess for the small percentage of people that are going to shove in a 1,000,000 line file?

My main question is when should I trade the easy but somewhat inefficient ways of doing tasks for big giant complicated beasts that do things extremely quickly but destroy any possible ways of upgrading and make the code excessively difficult and prone to rewriting anyway by the next developer?

答:
I try to make code readable - performance be damned.

When, and if, code proves to be too slow, I will refactor it to be faster. Usually refactoring process is followed with lot of comments since code does tend to be less readable.

Title: When should I care about performance?


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

答: Test like you fly, fly what you tested.</p>

Body: Test like you fly, fly what you tested.


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

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

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

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

答:
For windows I highly recommend AutoIt (http://autoitscript.com). Make sure to install the Scite package from the downloads section.

http://autoitscript.com/forum is a great resource for getting help and finding UDF's function to include in scripts.

AutoIt is able to control application windows and controls allowing you automate just about anything. It also requires no dependencies after you compile you executable.

OwnerDisplayName: SiliconChaos


问:
Is it better to have file stored as a zip in cloud service?
I am developing enterprise iPad application which contained large amount of different bundle data in terms of group of images.

Is it worth to stored as a compressed file format or normal set of individual files?

I am not worrying about huge amount of data which is reside in the cloud.

My concern is that cloud computing provider only charges depending upon the request not about how much data where stored.

If I store single file in cloud then it make more request while using the app. So it will cost so much.

Is it better to be stored as a compressed file in cloud?

答:
Given the power the IPad and other tablets have, I think that uncompressing one "big" file should not be a big deal in your program. Of course, what "big" means is totally subjective... And since your provider charges you per request, it's a smart thing to do.

It's also always a good thing to try to make as few requests to the cloud as possible regardless of the provider charging model, and the type of the application. You never know when a connection to the cloud could be cut off, right ?

Finally, it's also a good thing if you update your package after deploying your application. If you allow updates, your application would only need to check if one file has been updated.

Edit: kinda related: one single compressed js file VS compressed requirejs module files


问:
Maintenance code needs improvements
I am currently maintaining/enhancing a project a bit old speaking of the 1990's. Atleast 15 developers would have worked over it.
Going through the code for understanding is bit difficult.

No coding standards being followed.

OOP concepts not clear.

Too many unnecessary methods and functions, also unused files.

Worst of all global objects (hard to determine when its created and destroyed).

At times I feel should I be correcting the code so its better to work on, but my PM says we should not bother about it. As we have to finish the tasks within deadlines. This also leads to difficulties in tracking the bugs occurring.

Any suggestions on how should I approach it?

答:
You should start commenting in the code where possible. Obviously this includes your stuff but make comments on other pieces, that don't seem clear or have some obvious coding flaw. At the very least this will make it a little bit easier for you to read when you come back to pieces of it and also for any future developers. At best, it will help you to make your case to your manager as to why you need to spend time fixing the code.

Managers will also never spend the time to maintain things, or so I'm told, they just care about getting it done. I would nonetheless start slowly refactoring it in the places you are working on. If your manager asks why, simply tell them it was so jumbled you had to do something to even be able to work on it. I'm not saying make it perfect, but clean it up as you go.

Title: Maintenance code needs improvements


问:
What is the difference between "Syntax" and "Syntactic Sugar"

Background

The Wikipedia page on Syntactic Sugar states:

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for humans to use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

I don't really understand what the difference is between Syntactic Sugar and Syntax.

I appreciate the point that the sugary version can be clearer, more concise, perhaps boil off some boilerplate. But I feel at some level, all the syntax is essentially doing that to form an abstraction over what the code gets compiled down to.

From the same Wikipedia page:

Language processors, including compilers, static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring".

As a thought exercise, if I take "often" in this statement to mean "always": If the difference were just whether the compiler "desugars" the syntax before moving to a next stage, how might a coder who does not know the innards of the compiler know (or care) what is Sugar'd Syntax or not?

A very much related question on this site "Rigorous Definition of Syntactic Sugar?" has an answer which commences:

IMHO I don't think you can have a definition for syntactic sugar, because the phrase is BS and is likely to be used by people that talk about "real programmers" using "real tools" on "real operating systems"

Which might indicate to me that perhaps there isn't a huge difference to the coder using the language?
Perhaps the difference is only perceptible to the compiler writer? Though there may be instances in which it's helpful for the coder using the language to know what's under the hood of the Syntactic Sugar? (But perhaps in reality any discourse on the subject tends to use the term as flame bait?)

The heart of the question

So... the short version of the question:

Is there a real difference between Syntax and Syntactic Sugar?

Who does it matter to?

Extra Food for Thought

Bonus on topic contradiction:

On the Wikipedia page an example is given:

For instance, in the C language the a[i] notation is syntactic sugar for *(a + i)

Whereas another answer on the above linked question talks about the same example:

Now consider a[i] == *(a + i). Think about any C program that uses arrays in any substantive way.

And summarizes that:

The [] notation facilitates this abstraction. It's not syntactic sugar.

The opposite conclusion for the same example!

答:
Syntax is what a language processor uses to understand what the constructs of a language mean. Constructs that are deemed to be syntactic sugar also have to be interpreted by the language processor and thus are part of a languages syntax.

That what sets syntactic sugar apart from the rest of the syntax of a language is that it would be possible to remove the syntactic sugar from the language without affecting the programs that can be written in the language.

To give a more formalistic definition, I would say

Syntactic sugar are those parts of a language's syntax whose effects are defined in terms of other syntax constructs in the language.

This is in no way meant to denigrate syntactic sugar, or the languages that have it, because the use of syntactic sugar often leads to programs whose intent is more understandable.


问:
When is it better to offload work to the RDBMS rather than to do it in code?
Okay, I'll cop to it: I'm a better coder than I am at databases, and I'm wondering where thoughts on "best practices" lie on the subject of doing "simple" calculations in the SQL query vs. in the code, such as this MySQL example (I didn't write it, I just have to maintain it!) -- This returns the username, and the users age as of the last event.

```<code>SELECT u.username as user,
       IF ((DAY(max(e.date)) - DAY(u.DOB)) < 0 ,
       TRUNCATE(((((YEAR(max(e.date))*12)+MONTH(max(e.date)))
       -((YEAR(u.DOB)*12)+MONTH(u.DOB)))-1)/12, 0),
       TRUNCATE((((YEAR(max(e.date))*12)+MONTH(max(e.date))) -
       ((YEAR(u.DOB)*12)+MONTH(u.DOB)))/12, 0)) AS age
FROM users as u
JOIN events as e ON u.id = e.uid
...
</code>```

Compared to doing the "heavy" lifting in code:

Query:

```<code>SELECT u.username, u.DOB as dob, e.event_date as edate
FROM users as u
JOIN events as e ON u.id = e.uid
</code>```

code:

```<code>function ageAsOfDate($birth, $aod)
{    //expects dates in mysql Y-m-d format...
     list($by,$bm,$bd) = explode('-',$birth);
     list($ay,$am,$ad) = explode('-',$aod);

     //Insert Calculations here
     ...
     return $Dy; //Difference in years
}

echo "Hey! ". $row['user'] ." was ". ageAsOfDate($row['dob'], $row['edate']) . " when we last saw him.";
</code>```

I'm pretty sure in a simple case like this it wouldn't make much difference (other than the creeping feeling of horror when I have to make changes to queries like the first one), but I think it makes it clearer what I'm looking for.

Thanks!

答:
You want to do all set-based operations in the database for performance reasons. So aggregation functions, sorting functions, joins etc.

This age calculation, I'd do in code. The only reason I might ever do something like this in a database query is if it required lots of columns that I wouldn't otherwise select that could actually amount to enough data to meaningfully slow down my query. Selecting a few integer values will not make a meaningful performance difference. And even if it makes a moderate performance difference I will be biased towards keeping this logic in the application code.


答:
The main difference is that syntax is grammar defined in a language to allow you to expose some functionality. As soon as you could get to that functionality, any other syntax that lets you do the same thing is considered sugar. That of course runs into odd scenarios about which of the two syntaxes is the sugar, especially since it's not always clear which came first.

In practice, syntactic sugar is only used to describe syntax added to a language to facilitate ease of use, like making infix lhs + rhs map to lhs.Add(rhs). I would consider C's array indexing to be syntactic sugar.

It matters mostly because elegant designs tend to limit the amount of duplication. Needing (or at least wanting) syntactic sugar is seen by some as a sign of a design failing.

Title: What is the difference between "Syntax" and "Syntactic Sugar"

Body:
Background

The Wikipedia page on Syntactic Sugar states:

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for humans to use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

I don't really understand what the difference is between Syntactic Sugar and Syntax.

I appreciate the point that the sugary version can be clearer, more concise, perhaps boil off some boilerplate. But I feel at some level, all the syntax is essentially doing that to form an abstraction over what the code gets compiled down to.

From the same Wikipedia page:

Language processors, including compilers, static analyzers, and the like, often expand sugared constructs into more fundamental constructs before processing, a process sometimes called "desugaring".

As a thought exercise, if I take "often" in this statement to mean "always": If the difference were just whether the compiler "desugars" the syntax before moving to a next stage, how might a coder who does not know the innards of the compiler know (or care) what is Sugar'd Syntax or not?

A very much related question on this site "Rigorous Definition of Syntactic Sugar?" has an answer which commences:

IMHO I don't think you can have a definition for syntactic sugar, because the phrase is BS and is likely to be used by people that talk about "real programmers" using "real tools" on "real operating systems"

Which might indicate to me that perhaps there isn't a huge difference to the coder using the language?
Perhaps the difference is only perceptible to the compiler writer? Though there may be instances in which it's helpful for the coder using the language to know what's under the hood of the Syntactic Sugar? (But perhaps in reality any discourse on the subject tends to use the term as flame bait?)

The heart of the question

So... the short version of the question:

Is there a real difference between Syntax and Syntactic Sugar?

Who does it matter to?

Extra Food for Thought

Bonus on topic contradiction:

On the Wikipedia page an example is given:

For instance, in the C language the a[i] notation is syntactic sugar for *(a + i)

Whereas another answer on the above linked question talks about the same example:

Now consider a[i] == *(a + i). Think about any C program that uses arrays in any substantive way.

And summarizes that:

The [] notation facilitates this abstraction. It's not syntactic sugar.

The opposite conclusion for the same example!


问:
Why have a wrapper constructor when storing a function in a data type?
I can never do too many Haskell tutorials.  There is always something to refine and learn.  So, I am working through chapter 10 of Real World Haskell, and everything makes sense.

but

Why do

```<code>newtype Parse a = Parse { runParse :: ParseState -> Either String (a, ParseState) }

identity :: a -> Parse a
identity a = Parse (\s -> Right (a, s))

getState :: Parse ParseState
getState = Parse (\s -> Right (s, s))

putState :: Parse ()
putState = Parse (\s -> Right ((), s))
</code>```

Why not simply do

```<code>type Parse a = ParseState -> Either String (a, ParseState)

identity :: a -> Parse a
identity a = \s -> Right (a, s)

getState :: Parse ParseState
getState = \s -> Right (s, s)

putState :: Parse ()
putState = \s -> Right ((), s)
</code>```

In other words, what is the purpose of the wrap and unwrap pattern in here (which I see used in a lot of different places in Haskell)?  We get the same Parse Whatever data type, but without the extra indirection.

答:
It looks like using the notation you're taking issue with is a point of contention. From the comments on that Real World Haskell page:

I'm trying to go through the monad chapter now (chapter 14), and it
  looks more and more like the parse example in this chapter is somewhat
  contrived, in that some concepts it presents don't make sense and lead
  to what looks like needlessly hard-to-understand and complicated code...

and

While newtype and record syntax are explained in chapter 6, here (and
  for the rest of the book) they're not used for "records", just for
  what looks like a poor man's substitute for encapsulation. I can't
  really see why. Isn't the module system provided by Haskell enough for
  this purpose?

In other words, the answer may well be "don't".


答:
Whatever the original connotation of the phrase was, nowadays it is primarily a pejorative, almost always phrased as "just" or "only" syntactic sugar.  It pretty much only matters to programmers who like to do things the unreadable way and want a concise way to justify that to their colleagues.  A definition by those who primarily use the term today, from their point of view, would be something like:

Syntax that is redundant with other more widely applicable syntax, in
  order to provide a crutch for programmers who don't really understand
  the language.

That's why you get two opposite conclusions for the same syntactic element.  Your first example on array notation is using the original positive meaning of the term, something similar to Bart's answer.  Your second example is defending array notation against the charge of being syntactic sugar in the pejorative sense.  In other words, it is arguing the syntax is a useful abstraction rather than a crutch.


问:
Is it a good idea to build a library on top of somebody else's library?
Is it a good idea to use somebody else's library as a base and build your own library over that.

I want to make a JavaScript Canvas framework for a animation player on top of KineticJS. Should I do it? Do I need permission from the author of KineticJS? Do I just say to users to donwload KineticJS before my library, or do I just copy paste the kineticJS code in my library?

答:
To think of it from the other side:

Unless you are writing assembly on the bare metal, you are pretty much guaranteed to require other libraries, e.g. the C standard libraries, your operating system libraries, GUI toolkits, etc. Somewhere along the chain of execution, your code will involve several other libraries.

Building upon the work of others is a fundamental aspect of code re-use, and we wouldn't make much progress if every single project had to start from scratch.

So, you should approach whether to use KineticJS the same way you would for whether to use a given language, operating system, etc.


问:
Incorporating web designer's HTML pages into an MVC4 application
We are embarking on a new project which will be using the ASP .NET MVC4 platform.

I have been informed that the design is being outsourced to a custom design firm and they will be supplying us with HTML pages and stylesheets.

How easy will it be to incorporate these css stylesheets and HTMl pages in our application?
Do I need to ask for something more than HTML pages?

My personal experience is limited to one site that was built for an in-house and I used the HTMLHelper to generate Views. Another past experience I have from long-ago is using Classic ASP and that was a breeze since I could literally mash up ASP and HTML together.

My question is, what is this a good approach to incorporating HTML and stylesheets from a web designer into an ASP.NET MVC4 web application?

答:
Converting/incorporating a static HTML website in to ASP.NET MVC is very easy, and relatively hassle free. The situation you describe is one that occurred frequently at my last job. You won't need to ask for anything more than the static HTML site; HTML, JS, CSS and images are fine to start from.

You mentioned using classic ASP and HTML together in one file. ASP.NET MVC has something very similar to this with with the templating engine: Razor. Briefly, it gives you full access to the C# language (and I believe VB) inside pages which would otherwise be just HTML. Using this inside our (.cs)HTML pages is the main way in which we convert static HTML. It should be noted that Razor is not the only templating engine we can use with ASP.NET MVC.

In terms of work flow when doing this, we would:

Start by identifying a set of overarching layouts for all pages (eg some pages might have a left-aligned menu whilst others might have no menu at all). We would then strip out all of the markup which differed between pages of the same layout (typically this is the real content of the page) and use the resulting markup as a template page.

Place all of the separated markup from each file in to an appropriate view file, and set the appropriate layout files, to create the individual pages of the site.

Examine the views we created in step 2 to find common elements - such as a tables, menus and forms. These common elements could then be extracted in to partial views, and the markup in the pages replaced with a call to the partial view.

Once layout pages have been created and common elements extracted to partial views, begin incorporating your business logic by strongly typing your views and partials.

After step 4, the processes are the same as creating an ASP.NET MVC site without the base of static HTML.


问:
Why would anyone need this java syntax?
One day while trawling through the Java language documentation, as you do, I found this little beauty lurking within Double:

```<code>0.25 == 0x1.0p-2
</code>```

Now, obviously (!) this means take the number hexadecimal 1 and right shift it decimal 2 times. The rule seems to be to use base 16 on the integer side and base 2 on the real side.

Has anyone out there actually used the right hand syntax in a necessary context, not just as a way getting beers out of your fellow developers?

答: Completely insane, right? Many, many moons ago I worked with a guy that would write stuff like that. He came from an assembly background and would argue that his code would run faster than what the compiler would produce. I think this argument went away decades ago (along with programmers with an assembly background !)</p>

Title: Why would anyone need this java syntax?


答:
The other answers haven't mentioned a key concept:  abstract syntax; without it, the term "syntactic sugar" doesn't make any sense.

Abstract syntax defines the elements and structure of languages, and how phrases of that language can be combined to build bigger phrases.  Abstract syntax is independent of concrete syntax.  The term "syntactic sugar", as I understand it, refers to concrete syntax.

In general, when designing a language, you'll want to create concrete syntax for each term of your abstract syntax, so that people can write code in your language using plain text.

Now let's say you create an awkward concrete syntax for foo.  Users complain, and you implement a new concrete syntax to represent the same abstract syntax.  The result is that your abstract syntax and semantics haven't changed, but you now have two concrete syntaxes for the same abstract syntax term.

This, I believe, is what people mean when they say "syntactic sugar" -- changes which only affect concrete syntax, but which do not affect abstract syntax or semantics.

And so the difference between "syntactic sugar" and "concrete syntax" is now clear.  To me. :)

This interpretation also helps explain what Alan Perlis might have meant when he said "syntactic sugar causes cancer of the semicolon":  all the concrete syntactic sugar in the world can't fix weak abstract syntax, and all the effort you expend adding that sugar is effort you aren't spending dealing with the real problem -- the abstract syntax.

I should also note that this is solely my opinion; I only believe it because it's the only interpretation I can think of that makes sense to me.


答:
Really, your first quote from Wikipedia says it all "...makes things easier to read...", "....sweeter for humans to use....".

In writing, shortened forms such as "don't" or "haven't" could be considered syntactic sugar.


答:
First, I'll address some of the other answers with a concrete example. The C++11 range-based for loop (much like foreach loops in various other languages)

```<code>for (auto value : container) {
    do_something_with(value);
}
</code>```

is exactly equivalent to (ie, a sugared version of)

```<code>for (auto iterator = begin(container); iterator != end(container); ++iterator) {
    do_something_with(*iterator);
}
</code>```

Now, despite adding no new abstract syntax or semantics to the language, it does have real utility.

The first version makes the intent (visiting every item in a container) explicit. It also prohibits unusual behaviour such as modifying the container during traversal, or further advancing iterator in the loop body, or getting the loop conditions subtly wrong. This avoids possible sources of bugs and, in doing so, reduces the difficulty of reading and reasoning about the code.

For example, a one-character mistake in the second version:

```<code>for (auto iterator = begin(container); iterator <= end(container); ++iterator) {
    do_something_with(*iterator);
}
</code>```

gives a one-past-the-end error and undefined behaviour.

So, the sugared version is useful precisely because it's more restrictive, and thus simpler to trust & understand.

Second, to the original question:

Is there a real difference between Syntax and Syntactic Sugar?

No, "syntactic sugar" is (concrete) language syntax, considered "sugar" because it doesn't extend the abstract syntax or core functionality of the language. I like Matt Fenwick's answer on this.

Who does it matter to?

It matters to users of the language, as much as any other syntax, and in that sugar is provided to support (and in some sense bless) specific idioms.

Finally, on the bonus question

The [] notation facilitates this abstraction.

this sounds a lot like the definition of syntactic sugar: it supports (and provides the language authors' blessing for) using pointers as arrays. The p[i] form isn't really more restrictive than *(p+i), so the only difference is the clear communication of intent (and a slight readability gain).

Body:
First, I'll address some of the other answers with a concrete example. The C++11 range-based for loop (much like foreach loops in various other languages)

for (auto value : container) {
    do_something_with(value);
}

is exactly equivalent to (ie, a sugared version of)

for (auto iterator = begin(container); iterator != end(container); ++iterator) {
    do_something_with(*iterator);
}

Now, despite adding no new abstract syntax or semantics to the language, it does have real utility.

The first version makes the intent (visiting every item in a container) explicit. It also prohibits unusual behaviour such as modifying the container during traversal, or further advancing iterator in the loop body, or getting the loop conditions subtly wrong. This avoids possible sources of bugs and, in doing so, reduces the difficulty of reading and reasoning about the code.

For example, a one-character mistake in the second version:

for (auto iterator = begin(container); iterator <= end(container); ++iterator) {
    do_something_with(*iterator);
}

gives a one-past-the-end error and undefined behaviour.

So, the sugared version is useful precisely because it's more restrictive, and thus simpler to trust & understand.

Second, to the original question:

Is there a real difference between Syntax and Syntactic Sugar?

No, "syntactic sugar" is (concrete) language syntax, considered "sugar" because it doesn't extend the abstract syntax or core functionality of the language. I like Matt Fenwick's answer on this.

Who does it matter to?

It matters to users of the language, as much as any other syntax, and in that sugar is provided to support (and in some sense bless) specific idioms.

Finally, on the bonus question

The [] notation facilitates this abstraction.

this sounds a lot like the definition of syntactic sugar: it supports (and provides the language authors' blessing for) using pointers as arrays. The p[i] form isn't really more restrictive than *(p+i), so the only difference is the clear communication of intent (and a slight readability gain).


问:
Performance of single-assignment ADT oriented code on modern CPUs
Working in immutable data with single assignments has the obvious effect of requiring more memory, one would presume, because you're constantly creating new values (though compilers under the covers do pointer tricks to make this less of an issue).

But I've heard a few times now that the losses there in performance are outweighed by the gains in the way that the CPU (its memory controller specifically) can take advantage of the fact that the memory is not mutated (as much).

I was hoping someone could shed some light on how this is true (or if it's not?).

In a comment on another post it was mentioned that Abstract Data Types (ADT's) have to do with this which made me further curious, how do ADTs specifically effect the way the CPU deals with memory? This is however an aside, mostly I'm just interested in how purity of language necessarily affects the performance of the CPU and its caches etc.

答:
CPU (its memory controller specifically) can take advantage of the fact that the memory is not mutated

Advantage is, this fact saves compiler from using membar instructions when data is accessed.

A memory barrier, also known as a membar, memory fence or fence instruction, is a type of barrier instruction which causes a central processing unit (CPU) or compiler to enforce an ordering constraint on memory operations issued before and after the barrier instruction. This typically means that certain operations are guaranteed to be performed before the barrier, and others after.

Memory barriers are necessary because most modern CPUs employ performance optimizations that can result in out-of-order execution. This reordering of memory operations (loads and stores) normally goes unnoticed within a single thread of execution, but can cause unpredictable behaviour in concurrent programs and device drivers unless carefully controlled...

You see, when data is accessed from different threads, at multi-core CPU it goes about as follows: different threads run at different cores, each using its own (local to their core) cache - a copy of some global cache.

If the data is mutable and programmer needs it to be consistent between different threads, measures need to be taken to guarantee the consistency. For programmer, this means using synchronization constructs when they access (eg read) data in particular thread.

For compiler, synchronization construct in the code means it needs to insert a membar instruction in order to make sure that changes made to the copy of data at one of the cores are properly propagated ("published"), to guarantee that caches at other cores have the same (up-to-date) copy.

Somewhat simplifying see note below, here's what happens at multi-core processor for membar:

All cores stop processing - to avoid accidentally writing to cache.

All updates made to local caches are written back to global one - to ensure that global cache contains most recent data. This takes some time.

Updated data is written back from global cache to local ones - to ensure that local caches contain most recent data. This takes some time.

All cores resume execution.

You see, all the cores are doing nothing while data is being copied back and forth between global and local caches. This is necessary to ensure that mutable data is properly synchronized (thread safe). If there are 4 cores, all 4 stop and wait while caches are being synced. If there are 8, all 8 stop. If there are 16... well you've got 15 cores doing exactly nothing while waiting for stuff needed to do at one of these.

Now, let's see what happens when data is immutable? No matter what thread accesses it, it is guaranteed to be the same. For programmer, this means no need to insert synchronization constructs when they access (read) data in particular thread.

For compiler, this in turn means no need to insert a membar instruction.

As a result, access to data doesn't need to stop cores and wait while data is being written back and forth between global and local caches. That's an advantage of the fact that the memory is not mutated.

Note somewhat simplifying explanation above drops some more complicated negative effects of data being mutable, for example on pipelining. In order to guarantee required ordering, CPU has to invalidate pilelines affected by data changes - that's yet another performance penalty. If this is implemented by straightforward (and thus reliable:) invalidation of all pipelines, then the negative effect is further amplified.


问:
Is it acceptable for child classes to "break" parent class functionality?
One of the devs that works with me is following the Open/Closed Principle to add functionality to a Model by extending from our framework ORM.

```<code>class BaseModel extends ORM {
   ...
}
</code>```

All our models are now inheriting BaseModel, and this model works well in the context of our application.

```<code>class Product extends BaseModel {
  ...
}
</code>```

The problem comes when we tried to use the models as if they where extending directly from the ORM, use some of the most basic functionality:

```<code>$product = Product::factory();
$product->name = 'foo';
$product->price = 9.99;
$product->save();
</code>```

This code should have worked well but it failed because now the factory method requires a list of parameters.

I think that as long as the models works well within the context of our product we are good; but I also have mixed feelings about not supporting some of the basic core functionality of the parent class.

Thoughts?

答:
Any public accessible method is part of a contract on how things can be used. By requiring parameters on a descendent class' method, this contract is violated (see the already mentiond LSP).

Nevertheless, sometimes it is necessary to add parameters. In such case, the overriding method should still be able to use the original signature. In your example, this can be achieved by assigning reasonable default values to the parameters in BaseModel::factory().

OwnerDisplayName: Onema


答:
As nibra already stated, you have a contract for this public accessible method and you're not allowed to break it.

A really simple rule is, for an extended class, you can extend the type of input you accept, but be more specific on the output, so you don't break the contract.

Title: Is it acceptable for child classes to "break" parent class functionality?

Body:
One of the devs that works with me is following the Open/Closed Principle to add functionality to a Model by extending from our framework ORM.

```<code>class BaseModel extends ORM {
   ...
}
</code>```

All our models are now inheriting BaseModel, and this model works well in the context of our application.

```<code>class Product extends BaseModel {
  ...
}
</code>```

The problem comes when we tried to use the models as if they where extending directly from the ORM, use some of the most basic functionality:

```<code>$product = Product::factory();
$product->name = 'foo';
$product->price = 9.99;
$product->save();
</code>```

This code should have worked well but it failed because now the factory method requires a list of parameters.

I think that as long as the models works well within the context of our product we are good; but I also have mixed feelings about not supporting some of the basic core functionality of the parent class.

Thoughts?


问:
Does Text Editor Sign The Files?
As images have EXIF data which provide info about where and how they are created, do any Text Editors append such kind of descriptive details to code files? For example I use Coda for my programming works. Does Coda sign any files created by itself? Is it possible to find out the author of two different projects by just looking at the inners of the files?</p>

答:
EXIF files (as well as JPEG, PNG, and other image formats) contain lots of metadata in addition to images. Text files contain text. If your code is stored as a text file, there's probably nothing in there except your code. Even if you tried to hide data with non-printing characters, there's usually a way to reveal them in most editors.

Many IDEs will store metadata about your code files seperately, usually in XML files (though it could also be done as a binary file) somewhere else. In Eclipse, there's a .metadata directory in your workspace folder that contains XML files which store information about your code (such as when you last synced with source control, any markers in the file for IDE-specific tools, which regions are folded, how far you've scrolled, etc...). Coda might have a similar system, I'm not sure.

As far as "signing" a text file, the closest thing I've ever seen that does this is placing special text in a file, such as $Author: $ or $Date: $ and then some other tool will replace these tokens with the appropriate values (usually on check-in) such as Author: Some Coder. This is still visible as text.

I suppose it would be possible to store code in a binary format (or as an XML file) that merged code and code metadata into a single file. I don't know of any specific systems that do that, but it certainly could be done.

Title: Does Text Editor Sign The Files?


问:
How do I evaluate programming interview preparation websites?
I ran across the CareerCup website which says they can help prepare you for programming interviews with various US based top tech companies. They don't "guarantee" anything, and the site appears to be backed by a well reviewed book*.

*The reviews are on Amazon

I have been an active member on StackOverflow so according to me best resource for preparation would be StackOverflow.  But I saw that CareerCup has collected interview questions from various companies. So the key difference is that I would have to dig for interview questions within SO versus having questions already aggregated by the other site.

How do I go about evaluating the credibility of a website like this?

How can I evaluate if their interview preparation offerings are worthwhile?

答:
May be it helps to get this job, but in the long-term it's more important to be honest. If that really helps to get that job, the expectations on you seem to be higher, than you really can fulfill them. And what's a job worth, if you can't perform? Either you may lose it, or if not you still won't be satisfied, because you're not a good match for the company.

And like I already mentioned in a question some days before: a big part of these tests is not about how good you can solve them, it's more about how you do it, how you react, what happens if the stress level raises and so on.

What I want to point to is, that I think it's not useful to specially train for an interview, because of two reasons: The expectation in your person may be wrong, because you specially trained for it and people just want to see your current state of knowledge. And the other point is that in these interviews a big part is not about the answer itself, it's how you react, work and communicate.


答:
Building a project upon a library is never free, including a library also means including that library's bugs and download size.

Sometimes one may be able to consider the library an independent piece of code that need no maintaining and doesn't really count towards the complexity of the project, but often that is not the case. As a professional developer the only way I can really justify using some small found-on-the-internet library is if I take care of that code as if it were my own. Maybe the original develop will fix a bug if I find one, maybe he won't and I'd have to do it.

Ultimately an included library is part of the codebase, and as such count in every negative way like any other code. It may be good relatively bug-free code with a clean interface that thus doesn't weigh much relative to its size, but the weight is never zero.

If library A depend on library B then including library A in my project implicitly adds the weight of both libraries.

You always want a library to be as lightweight as possible, including another library will almost always work against this goal. In some cases this will be a small extra weight added for a large benefit in saved work, in other cases it is a lot of weight for very little benefit.

Conclusion

Usually you should avoid library dependencies in libraries, but there are cases where the cost to gain ratio is low and it is acceptable. The following conditions in general make the use of a sub-library more acceptable:

The library used is a widespread one that generally has few bugs and is well supported.

All or most of the functionality of the library is being used, if the needed functionality were to be re-implemented the combined code-size would not be a lot smaller for it.

The library deals with issues that would be hard to solve without it.

Title: Is it a good idea to build a library on top of somebody else's library?

Body:
Is it a good idea to use somebody else's library as a base and build your own library over that.

I want to make a JavaScript Canvas framework for a animation player on top of KineticJS. Should I do it? Do I need permission from the author of KineticJS? Do I just say to users to donwload KineticJS before my library, or do I just copy paste the kineticJS code in my library?


问:
"Too object-oriented"
I come from a strong OO background, and I have recently started working in an organization which, although the code is written in Java, has a lot less emphasis on good OO design than what I am used to. I have been told that I introduce "too much abstraction", and that I should instead code the way it has always been done, which is a procedural style in Java.

TDD is also not very much practiced here, but I want to have testable code.  Burying business logic in static private methods in large "God-classes" (which seems to be the norm for this team) is not very testable.

I struggle in clearly communicating my motivation to my co-workers.  Does anyone have some advice on how I can convince my coworkers that using OO and TDD leads to more easily maintained code?

This question about technical debt is related to my question.  However, I am trying to avoid incurring the debt in the first place, as opposed to paying it down after the fact which is what the other question covers.

答:
You can only convince them by taking on a small chunk of code and implementing TDD and better OO practices on it to realize the benefits.  You have lead them to the promised land, not just show nice post cards of it.

Certainly, I think there are cases of over abstraction in use in many code bases today. Only put in what you need, and that includes abstractions as well.

Title: "Too object-oriented"


答:
Sites like that are about as effective as SAT prep classes (and other similar things) are.  In other words: They can't guarantee you anything at all, but by going through their system you become more familiar with the process and can find areas of weakness to improve on.

Specifically:

By looking at questions that candidates were actually asked, you can familiarize yourself with the style of the question and the thought processes you need to answer it, so that you can answer that type of question easier.  However, memorizing the answers won't help, because you then get more flustered if you get asked something you didn't memorize or one you forgot the "correct" answer to.

By looking at the types of skills that candidates needed to demonstrate, you can compare your own skill levels to them and see whether you need to go learn more.  However, studying the specific things that got asked about in the past won't help you answer if you haven't used them enough to be fluent in them.

By improving your comfort level you can present better in an interview.  If you're skilled but uncomfortable under pressure, this can help.  If you're not skilled, it won't.  If you're in between, you can use it to direct your improvement.

Title: How do I evaluate programming interview preparation websites?

Body:
I ran across the CareerCup website which says they can help prepare you for programming interviews with various US based top tech companies. They don't "guarantee" anything, and the site appears to be backed by a well reviewed book*.

*The reviews are on Amazon

I have been an active member on StackOverflow so according to me best resource for preparation would be StackOverflow.  But I saw that CareerCup has collected interview questions from various companies. So the key difference is that I would have to dig for interview questions within SO versus having questions already aggregated by the other site.

How do I go about evaluating the credibility of a website like this?

How can I evaluate if their interview preparation offerings are worthwhile?


问:
About Artificial Intelligence
I am interested in starting a career in artificial intelligence.

Can anyone suggest how I could prepare for this?

What languages should I study that would be best for this career choice?

答: You can code with whatever language you are comfortable in, provided it's object oriented.. Python, C++ o Java.. it's upto you.. There's good course on udacity.com in AI by Sebastian Thrun, The course is based on making robotic car using AI in all fields like computer vision, sensing, pattern recognition, learning etc.. Its a good course to get started...!</p>

Title: About Artificial Intelligence


答:
You mentioned one: area of expertise. Maybe the structure of the database isn't too intensive, so you decide to offload some of the logic development to a team member that is more database centric. May not be ideal, but if you're crunched for time...

The database hardware has significantly more resources than other servers and you can't change this. This may not apply to this specific situation, but may need to be considered.

There are other applications that may need the logic outside of your code. Some report writing tools may not be able to utilize a web service or an API. You could duplicate the logic or if you feel the requirements may diverge.

Title: When is it better to offload work to the RDBMS rather than to do it in code?

Body:
Okay, I'll cop to it: I'm a better coder than I am at databases, and I'm wondering where thoughts on "best practices" lie on the subject of doing "simple" calculations in the SQL query vs. in the code, such as this MySQL example (I didn't write it, I just have to maintain it!) -- This returns the username, and the users age as of the last event.

```<code>SELECT u.username as user,
       IF ((DAY(max(e.date)) - DAY(u.DOB)) < 0 ,
       TRUNCATE(((((YEAR(max(e.date))*12)+MONTH(max(e.date)))
       -((YEAR(u.DOB)*12)+MONTH(u.DOB)))-1)/12, 0),
       TRUNCATE((((YEAR(max(e.date))*12)+MONTH(max(e.date))) -
       ((YEAR(u.DOB)*12)+MONTH(u.DOB)))/12, 0)) AS age
FROM users as u
JOIN events as e ON u.id = e.uid
...
</code>```

Compared to doing the "heavy" lifting in code:

Query:

```<code>SELECT u.username, u.DOB as dob, e.event_date as edate
FROM users as u
JOIN events as e ON u.id = e.uid
</code>```

code:

```<code>function ageAsOfDate($birth, $aod)
{    //expects dates in mysql Y-m-d format...
     list($by,$bm,$bd) = explode('-',$birth);
     list($ay,$am,$ad) = explode('-',$aod);

     //Insert Calculations here
     ...
     return $Dy; //Difference in years
}

echo "Hey! ". $row['user'] ." was ". ageAsOfDate($row['dob'], $row['edate']) . " when we last saw him.";
</code>```

I'm pretty sure in a simple case like this it wouldn't make much difference (other than the creeping feeling of horror when I have to make changes to queries like the first one), but I think it makes it clearer what I'm looking for.

Thanks!


答:
Reading your question, I remembered one tip of book Pragmatic Programmer.

One of its tips is Be a Catalyst for Change:

You may be in a situation where you know exactly what needs doing and
  how to do it. The entire system just appears before your eyes—you know
  it's right. But ask permission to tackle the whole thing and you'll be
  met with delays and blank stares. People will form committees, budgets
  will need approval, and things will get complicated. Everyone will
  guard their own resources. Sometimes this is called "start-up
  fatigue."

It's time to cook Stone Soup. Work out what you can reasonably ask for.
  Develop it well. Once you've got it, show people, and let them marvel.
  Then say "of course, it would be better if we added…." Pretend it's not
  important. Sit back and wait for them to start asking you to add the
  functionality you originally wanted. People find it easier to join an
  ongoing success. Show them a glimpse of the future and you'll get them
  to rally around.

So, I think If you start to do a good job with your OO and TDD knowledge, soon
they'll start to look and ask about your job.

Title: "Too object-oriented"

Body:
I come from a strong OO background, and I have recently started working in an organization which, although the code is written in Java, has a lot less emphasis on good OO design than what I am used to. I have been told that I introduce "too much abstraction", and that I should instead code the way it has always been done, which is a procedural style in Java.

TDD is also not very much practiced here, but I want to have testable code.  Burying business logic in static private methods in large "God-classes" (which seems to be the norm for this team) is not very testable.

I struggle in clearly communicating my motivation to my co-workers.  Does anyone have some advice on how I can convince my coworkers that using OO and TDD leads to more easily maintained code?

This question about technical debt is related to my question.  However, I am trying to avoid incurring the debt in the first place, as opposed to paying it down after the fact which is what the other question covers.


答:
The language matters little. Study the algorithms and the logic behind the AI concepts. If you are able to understand that, implementing it is possible in any language. I myself have been using Java, but that's just a personal choice.

Also, try the book:
Artificial Intelligence: A Modern Approach
Stuart Russel, Peter Norvig, Prentice Hall, 3rd edition, 2009

Title: About Artificial Intelligence

Body:
I am interested in starting a career in artificial intelligence.

Can anyone suggest how I could prepare for this?

What languages should I study that would be best for this career choice?


答:
Basically you should look at two things:  CPU usage and network traffic.  You should not generate enormeous responses, transfer them over the network and then summarize in the frontend, as the database can do this much better.

For data manipulation it is a trade-of.  If the database spends comparable amount of cpu cycles to your frontend code doing the same thing - given that the amount of data transferred is roughly equivalent), then it doesn't matter where.  Then do it where you have the largest amount of programming expertise.   Frequently, you can get a VERY long way with a careful select and that might be very useful.


问:
Should a developer create test cases and then run through test cases?
I work for a company where the development manager expects a developer to create test cases before writing any code.  These test cases have to then be maintained by the developers.  Every-so-often a developer will be expected to run through the test cases.

From this you should be able to gather that the company in question is rather small and there are no testers.

Coming from a Software Architect position and having to write / execute test cases wearing my 'tester' hat is somewhat of a shock to the system.  I do it anyway but it does seem to be a rather expensive exercise :)

EDIT:

I seem to need to elaborate here:  I am not talking about unit-testing, TDD, etc. :)

I am talking about that bit of testing a tester does.  Once I have developed a system (with my unit tests / tdd / etc.) the software goes through a testing phase.  Should a developer be that tester and developer those test cases?

I think the misunderstanding may stem from the fact that developers, typically, are not involved with this type of testing and, therefore, assumed I am referring to that testing we do do: unit testing.  But alas, no.

I hope that clears it up.

答:
There are reasons why developer should never test his own code (bias to positive tests, influence of white box knowledge and assumptions like "this cannot ever happen because the component is like that..", creative instead of destructive thinking), yet I think it is not that big a deal, if we are not talking about mission-critical software.
I find it very odd even for small company not to have any quality control personnel. It is just not really good idea when person should find problems in his/her own work, in general.</p>