答:
it is inconvenient to do all that procrastination when there are two
  of you sitting together.

I disagree. I worked with a group of smokers and they all managed to take their break together for extended periods because "everyone was doing it."

common to slack off in the first three weeks

This is a sign of poor management regardless of methodology. Even if a huge chunk is due in a month, I would expect to see something at the end of the first week.

you have nothing to say you may actually feel ashamed.

If you're willing to jerk-off for three weeks, you'll think of some bullshit to say.

4) Testing and feedback - again, it prevents you from keeping tasks
  "99% ready" (when it's actually around 20%) until the deadline
  suddenly happens.

Waterfall projects can have testing and daily builds.

Personally, I would hate to write code and not have anything done with it for a month. I prefer the shorter-feedback loop on my code whether it is a coded review or user sign-off. Having others approve of my work is rewarding. It's like the cat the drops a mouse off on your doorstep just to let you know she's doing her job.

Title: Does Agile force developers to spend more time actually working?

Body:
Looking at common Agile practices it seems to me that they (intentionally or unintentionally?)  force developers to spend more time actually working as opposed to reading blogs/articles, chatting, coffee breaks and just plain procrastinating.

In particular:

1) Pair programming - the biggest work-forcer, just because it is inconvenient to do all that procrastination when there are two of you sitting together.

2) Short stories - when you have a HUGE chunk of work that must be done in e.g. a month, it is pretty common to slack off in the first three weeks and switch to OMG DEADLINE mode for the last one.

And with the little chunks (that must be done in a day or less) it is exact opposite - you feel that time is tight, there is no space for maneuvering, and you will be held accountable for the task pretty soon, so you start working immediately.

3) Team communication and cohesion - when you underperform in a slow, distanced and silent environment it may feel ok, but when at the end of the day at Scrum meeting everyone boasts what they have accomplished and you have nothing to say you may actually feel ashamed.

4) Testing and feedback - again, it prevents you from keeping tasks "99% ready" (when it's actually around 20%) until the deadline suddenly happens.

Do you feel that under Agile you work more than under "conventional" methodologies? Is this pressure compensated by the more comfortable environment and by the feeling of actually getting right things done quickly?


问:
How to talk about anonymous methods/lambdas
I realised the other day that I don't know how to talk about anonymous methods. It's easy enough to talk about named methods (The X method takes a Y1, Y2 and Y3) and classes (The X class has A, B and C methods), but it's harder with anonymous methods.

How does one go about talking (and writing) about them? From the number of parameters they take, to the types of those parameters to the method signature?

For this anonymous method signature, how would you read it aloud?

```<code>int -> int -> bool -> double
</code>```

I would say "int, int, bool to double". What about calling it? How would you read this?

```<code>(A ,B) => A*B;
</code>```

I would say "A B goes/is to A times B".

答:
If

The X method takes P1, P2, P3 and returns R

is good enough, why is

An anonymous method that takes P1, P2, P3 and returns R

insufficient?

In my experience, the best way to talk about anonymous methods is the same way you'd talk about named methods.

For

(A, B) => A*B;

I would read it as "an anonymous method that multiplies two numbers" (or whatever A*B means in context).

ContentLicense: CC BY-SA 3.0


问:
Language that can statically ensure a map's fields are present
If data is simple and objects are complex, I'm curious if there are any existing statically typed languages that would be able to augment(?) a map type into a type with guaranteed fields. I realize that at runtime, in any language this type of check is pretty doable. But in theory I also believe this should be possible to check with a compiler. To do everything below in Java, would be an explosion of interfaces (HasComplete, HasTitle, HasTitleAndComplete)

So has anyone done it? If not, how come? If so, how was it implemented?

This would allow you to read in data but then manipulate it with at least some type safety:

```<code>// User input is often simply converted to a Map
function parse(json) -> Map {...}

// result still has all user input fields,
// but this would be a runtime exception
// if specified fields are missing
function cast(Map, Map<fields...>) -> Map<fields...> { ... }

input = "{title:'do it', complete: false, rank: 5, subtitle: 'now'}"

// Would throw class cast exception if complete or title were missing
todo = cast(parse(input), Map<title:str, complete:bool>)

// Runtime introspection
todo instanceOf Map -> true
todo instanceOf Map<title:str, complete:bool> -> true
todo instanceOf Map<title:str> -> true
todo instanceOf Map<complete:bool> -> true
todo instanceOf Map<complete:date> -> false
todo instanceOf Map<rank:int> -> false because cast() did not specify rank
todo instanceOf Map<title:str, complete:bool, author:str> -> false

// Typed methods based on map with certain fields
function capitalize_title(Map<title:str>) {...}
function finish_task(Map<complete:bool>) {...}
function finish_and_rename(Map<title:str, complete:bool>, newTitle) {...}
function increase_rank(Map<rank:int>) {...}

// Static Check compile pass
todo = capitalize_title(todo)
todo = finish_task(todo)
todo = finish_and_rename(todo, "[complete]")

// Static Check Compile Fail because cast() did not specify rank
increase_rank(todo)

// Methods could return a type with added (or removed) fields
function add_uuid(Map) -> Map<+id:int> {...}
todo_with_id = add_uuid(todo)
todo_with_id instanceOf Map<title:str, complete:bool, id:int> // true
</code>```

答:
In theory, an object is just a type-checked, static map, which means any OOP language offers a kind of static checking for map fields.  However, I think what you're asking for is impossible.

Your code sample is, in brief, 1. Deserialize JSON into a map 2. Statically verify that the map is "proper".  Since you can't deserialize JSON until you are running, you can't verify its structure until runtime.  Even if you runtime create an object (or even a "strongly-typed map") using reflection, you are still verifying it at runtime.

A more practical approach to this than dependent typing (not that DT isn't practical or awesome, just not much support for it yet) might be code generation though templates of some kind.  Most ORMs do something like this.  They read in a schema from a database, then generate objects based on that schema.  The same could be applied to arbitrary JSON to generate objects prior to compilation.


问:
Does Agile force developers to spend more time actually working?
Looking at common Agile practices it seems to me that they (intentionally or unintentionally?)  force developers to spend more time actually working as opposed to reading blogs/articles, chatting, coffee breaks and just plain procrastinating.

In particular:

1) Pair programming - the biggest work-forcer, just because it is inconvenient to do all that procrastination when there are two of you sitting together.

2) Short stories - when you have a HUGE chunk of work that must be done in e.g. a month, it is pretty common to slack off in the first three weeks and switch to OMG DEADLINE mode for the last one.

And with the little chunks (that must be done in a day or less) it is exact opposite - you feel that time is tight, there is no space for maneuvering, and you will be held accountable for the task pretty soon, so you start working immediately.

3) Team communication and cohesion - when you underperform in a slow, distanced and silent environment it may feel ok, but when at the end of the day at Scrum meeting everyone boasts what they have accomplished and you have nothing to say you may actually feel ashamed.

4) Testing and feedback - again, it prevents you from keeping tasks "99% ready" (when it's actually around 20%) until the deadline suddenly happens.

Do you feel that under Agile you work more than under "conventional" methodologies? Is this pressure compensated by the more comfortable environment and by the feeling of actually getting right things done quickly?

答:
more working is still not semantically correct or relevant to Agile, the goals is to be more productive. It specifically focusing on working less on the wrong thing, and more on the working normally on the correct thing; which doesn't mean working more, just more productively.

A side effect, is it does expose slackers and those that are in-efficient or in-competent very quickly. Which sounds more like what you are getting at.

Methodology is irrelevant on whether or not a developer is not working. Process is, even in waterfall, management reviews and code reviews can expose these do nothings as well, just not as transparently as most Agile methodologies.


答:
Lambas assist C#'s ability to support functional programming.  In functional programming we declare what we are going to do without defining how we are going to do it.  The concentration is not on the algorithm or implementation, rather on the action to be performed.  E.G. In SQL we do not define how SELECT is to be performed, we simply declare that we want a SELECT to occur.

Where(), Select(), OrderBy() are actions named in the API.  Like SQL, the name describes the function without describing the implementation.  The way they go about their business is delegated (in this case to a Lamba/Func<>/Action<>).  The delegate is just a variable to be passed in.

=> in .NET is called the goes to operator.  I would read (A ,B) => A*B; aloud as "In this expression, the parameters A and B goes to A times B"

Title: How to talk about anonymous methods/lambdas

Body:
I realised the other day that I don't know how to talk about anonymous methods. It's easy enough to talk about named methods (The X method takes a Y1, Y2 and Y3) and classes (The X class has A, B and C methods), but it's harder with anonymous methods.

How does one go about talking (and writing) about them? From the number of parameters they take, to the types of those parameters to the method signature?

For this anonymous method signature, how would you read it aloud?

```<code>int -> int -> bool -> double
</code>```

I would say "int, int, bool to double". What about calling it? How would you read this?

```<code>(A ,B) => A*B;
</code>```

I would say "A B goes/is to A times B".


问:
How does agile estimate the time required for a "research phase"?
According to canonical agile development, what is the appropriate amount of learning that an engineer should engage in before implementing a solution to a problem?

If an engineer knows she is too ignorant of a given topic (say, compression) to start implementing, she goes and learns what she thinks she needs to know, and then implements a solution.

Clearly a deeper understanding of said topic could result in a better implementation, but at the cost of agility. On the flip side if an engineer learns too little about a topic, there is a danger she will implement a significantly insufficient / broken implementation that negatively affects customers in the immediate or near future. In some cases, not a lot of research is required, and in some cases developers are faced with a topic even the senior-most developer knows little to nothing about, so the answer to this question includes an element of scalability to meet both situations.

Towards which end of this scale, if any, do guiding principles of agile lead an engineer? Or does agile leave this as a sliding scale, where the answer may be different in any given situation?

In other words, I'm looking to understand not when/how inside agile development research happens, but moreover how to estimate a "good" amount of time to spend learning a topic in the research phase before moving on to implementing a solution.

答:
When I worked in Agile, we used something called "Technical Spikes" to handle this type of work.

The concept is simple:
You put a period of time in your sprint to research the technical issue at hand (such as what it will take to work with a certain technology that is new to your team).  You then assign this to someone with an estimate.  This estimate becomes part of your sprint plan.

This works really really well. Or at least it did in the context of how we were using it, which was mostly to research using a certain API to do a task.  Certainly there are limitations - it would not work well if the learning task was too large (like learning c++ from scratch or something crazy like that).


答:
Anonymous methods are always declared in a context, so I use that context to name it:  the document ready handler, the link click handler, the lambda returned from functionX, etc.

If you add arguments into the mix, it's something like, "Make a lambda that multiplies its two arguments."  Describe what it does, the same as you would when making an explicit name for it.  The more formal descriptions rarely need to be spoken.


问:
Any recognized convention for repository changelogs?
We use TortoiseSVN, but we have no bug tracking system. I know, lame, but beyond my control.

There were times when svn wasn't in daily use.
Now I've had succeeded in pressing for using it regularly, with proper merging, branching, tagging etc.

As you could expect,  the number of revisions increased in result, which makes browsing repository log a bit troublesome now.

I thought about utilizing some convention based on keywords ("[bugfix]", "[feature]", "[refactored]", "[minor]", "[merged-from-trunk]"... :) so as to make it more searchable.

It feels like reinventing the wheel, though. Is there any established convention for that?
Or is my approach wrong from the beginning? Any better, alternative solution?

答:
If you have a unique ID for bugs or tickets, then a common pattern is to add #123 to a commit message if it fixes the bug with ID 123 or implements feature 123.

Oftentimes bug trackers have commit hooks that will add the commit log in the bug tracker or ticketing system based on this 'tag'. That allow you to find commit logs 'in context'

Also, did you search open source repositories to find common patterns for other scenarios? You could search Github for project of the same type and/or platform to see if there's a common denominator when people are merging or fixing bugs.


问:
Where and how to mention Stackoverflow participation in the résumé?
I think I have good enough reputation on SO now. Well, this may not be that much as compared to so many other users out there but I am happy with mine.

So, I was thinking of adding my profile link on my résumé - just the profile link and not that "I have this much reputation on SO". Those who haven't seen, can see this question Would you put your Stack Overflow profile link on your CV / Resume?

How would this look like?

Forums/Blogs/Miscellaneous others

No blogging as yet but active
  participant in Stackoverflow. My
  profile link -
  http://stackoverflow.com/users/userId/username

I think of putting this section after Project Details and Technical Expertise sections. Any tips/advice?

Update

MKO has made a very good point -

do you really want a potential
  employer to be able to evaluate in
  detail everything you've ever written
  on SO

I thought of commenting but it would be too long -

 In my questions/answers I put a lot of statements like - "AFAIK ...", "following are my assumptions so far ...", "am I correct to conclude that... ?", "I doubt if it is possible to ..." etc. when I am not sure about something and I rarely involve in fights with other users. However I do argue on topics sometimes if I feel it is necessary and if I have a valid point. I do accept my mistakes and apologize for the same. As we all know nobody is perfect. I must have written many things which may be judged as wrong by a potential employer. But what if the same employer notices that I have improved in the quality of content by comparing old content with new one? Isn't that great?

I also try to go back to older questions/answers and put corrective comments etc. when I feel I was wrong or if I can improve my post.

Of course there are many employers who want you (potential employees) to be correct each and every time. They immediately remove you from consideration when you say a single incorrect thing. I have personally met such an interviewer few months back. He didn't even care to listen to any good thing I had done after he found a single wrong thing.

Now the question is do you really care to work with such people? Or do you like those people who give value to the fact that you are striving to improve every day. I personally prefer the latter.

答:
The following is a section on my resume at the bottom of the first page.

Writings & Public Work

Personal Site – http://storyinmemo.com

Sysadmin background: https://serverfault.com/users/3139/jeff-ferland

Security background: https://security.stackexchange.com/users/836/jeff-ferland


问:
Code duplication with no obvious abstraction
Have you ever encountered a case of code duplication where, upon looking at the lines of code, you couldn't fit a thematic abstraction to it that faithfully describes its role in the logic? And what did you do to address it?

It is code duplication, so ideally we need to do some refractoring, like for example making it its own function. But since the code doesn't have a good abstraction to describe it the result would be a strange function that we can't even figure out a good name for, and whose role in the logic is not obvious just from looking at it. That, to me, hurts the clarity of the code. We can preserve clarity and leave it as it is but then we hurt maintainability.

What do you think is the best way to address something like this?

答: Personally I ignore it and move on.  Chances are if it is that odd a case it is better to have it duplicated, you could spend ages refactoring and the next dev will take one look and undo your change!</p>

ContentLicense: CC BY-SA 2.5


答: Anonymous methods are often used like values, so talk about them the same way you'd talk about other values or objects. In Objective-C they're known as blocks, and it's typical to assign them to variables or pass them as parameters to other methods. In either case, you can then use the name of the variable or parameter to refer to them. You might say "the block passed in the completionHandler parameter," or more simply just "the completionHandler." If you need to describe a block outside this kind of context, you can describe what it does: "a block that cleans up after the connection is closed."


问:
Developing a mobile interface for Website
I have a website developed in ASP.NET MVC.

Now, I am looking forward to getting up a mobile interface for it. My knowledge in this regard isn't that great, so I will explain what is needed to be done. It's much like on the lines of StackOverflow or Programmers and following are the few points that need to be addressed.

Much like Stack Overflow, if a site is visited from mobile, auto-detection should happen and the mobile version should be displayed.

Do I need to setup some sub-domain like m.mysite.com and should I have the mobile site installed for this domain (SE sites don't do this now but Facebook does that)

Lastly, How to design the website that is easily readable on all sized of screens for mobile.

答:
If you are using MVC 3, there is very little code to write to detect a mobile client and subsequently display the mobile view.  The two small additions you'll have to make are:

Override the RazorViewEngine.FindView, and check the Request.UserAgent to determine what browser is sending the request.

Create a "Mobile" folder under the Views folder for a particular area, and create your mobile-styled views there.

Complete the work to tell "FindView" where to get the mobile views

This separates your regular browser views from your mobile views, and eliminates the need to change your controller code.

To get started with this, you could start rolling your own (perfectly fine - you learn a lot that way), or you could leverage what others have started.  I personally used a template on NuGet called "Mobile Ready HTML5", which is an MVC project that includes the pieces I described above, including HTML 5 support.  Check it out, it helped me a ton:

http://tekprolixity.blogspot.com/2012/04/instant-mvc-3-mobile-app.html


问:
Should I ask for advance payment on custom work?
...for project-based work.

So far I didn't, and always got paid when work was complete and didn't ran into any problems.
Does this make me look unprofessional? :)

Should I ask like 25% - 50% advance before I start working?

The work I usually do also includes graphic design to some extent (user inteface for my app)

答: I'm on the opinion that from complete strangers (no recommendation from known people etc.) it is OK to ask advance payment if the project size/anticipated length warrants it. And no, it's not unprofessional, quite the contrary. Just be reasonable: for small&cheap projects you can take the risk if you feel comfortable.</p>


答: I think a good policy would be to always ask for half immediately for first-time clients.  After the first time, I think you can safely assume he'll pay you at the end.  The only risk that you could take that would make you look unprofessional is to ask for all of it up front. </p>

Title: Should I ask for advance payment on custom work?

Body:
...for project-based work.

So far I didn't, and always got paid when work was complete and didn't ran into any problems.
Does this make me look unprofessional? :)

Should I ask like 25% - 50% advance before I start working?

The work I usually do also includes graphic design to some extent (user inteface for my app)


答:
As we have to think from the sides of both customer and us , I think it will not be good idea to ask for the payment immediately before you start working. But you can break the tasks into smaller milestones and ask for the payment as soon as each milestone is delivered.

For example: (break the milestones as per your convenience and nature of the project)

Requirement analysis delivered : 20% of payment

Data model delivered : 20% of payment

First user story delivered : 20% of payment

etc and so on ( I made up the tasks but feel free to negotiate the milestones).

Make sure the first deliverable is small so you will know the customer soon rather than waiting till the end.

This will put both customer and you in a comfortable position. And both parties will know  if one of the party is not honoring the contract very soon.

My 2 cents.


问:
Where do you draw the line between quantity and quality?
My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still feel like I have a lot to learn. Which route do I take (or is there another?):

Quantity: If they want crap, I can give them lots of it.

Quality: Ignore the request, and hope that my productivity will increase with experience.

答:
If you are currently writing good code, I guarantee you that you will get faster and faster as you get more experience.

If you are currently writing code quickly, there is absolutely no guarantee that you will ever write higher quality code.

So I would say that you are on the right track.


问:
Dealing with change requests from clients for an old system that only take 5 minutes to implement

Possible Duplicate:

  How should I charge for programming things which take two minutes to fix?

On some systems I created, every now and then I get tiny change requests from clients that are very easy for me to do, but the client can not do it themselves.

For example:

Hey, we made a new logo, could you please upload it to our website?

Can you check how many users we had this month?

Most of them basically just requires me to log on to the FTP server and upload a file which takes 2 minutes max. Sometimes even answering the email or writing the bill takes longer!

How do I charge the client for these changes? I could easily do it for free, because at the moment I don't get them frequently at all, maybe once per month. If the initial cost of the system is big it would seem like a nice gesture to the client to give and take a bit. What I'm afraid of is that they will become more and more frequent and then the client will get used to getting these changes for free. Also where do I draw the line for what to give away, 2 minutes? 5 minutes? 15 minutes? I want to be consistent in the pricing so it doesn't seem like I charge whatever I feel for at the moment.

Some ideas:

Charge per started hour/half hour/quarter, that is, 1 minute counts as 1 hour, 61 minutes as 2 hours (at least for the first hour).

Accumulate small changes into a pool of time. Instead of sending out bills for 2 minutes each they add up to a sum at the end of every 3 months or something.

Only charge if they want the fix NOW. Otherwise say they'll get it once I have time, within the next weeks.

Be an ass and pretend it's a big fix.

答:
Always remember that while it might take you 5 minutes, it took a long time for you to learn to do it in 5 minutes.

If you're doing a load of them maybe accumulate them and send an itemised invoice when it amounts to more than a couple of hours.


问:
Open source custom work
Many of the custom projects I take include things that could be useful to the open source community. I'd like them to open Github repos with them :)

Most of them are jQuery plugins. I'm almost always ending up creating my own jQuery plugins for features I need to implement in the project, for example autocomplete, edit-in-place functionality etc.

Would it be a good idea to offer a "discount" for people that accept to let me open-source part of the project? Like -15%, -25% etc?

Do you think it would be unprofessional to ask them this?

答:
This very much depends on what you contract with your customer states, but I think you may be thinking of it the wrong way around.

Instead of thinking what discount should I give, think how much can I charge for support on an open source license that I have licensed then to use on their application.

Pick an appropriate license for your open source release and look into dual licensing, then write it into your future contracts that some of the functionality will be provided through an open source license which you are licensing them to use on a commercial basis in that project.

For more information, have a look at my answer to the question Preparing to release code as open-source.

Title: Open source custom work


答:
A lot has to do with how much of an interuption this is and what is their expectation for the timing of this change. Any level of urgency on their part or increased frequency needs to be settled.

Be upfront about charging. If they can't wait for the new logo because they want to show the site to an investor in half an hour, they should pay. If not, what is the point in picking up the phone when they call? If they don't expect you to have other clients, they need to pay you to be on call full time.

Also, try to make the billing simple on yourself. Ask them to buy a block of 5 or 10 requests. Offer a discount for them to pay up front. You don't want to keep tracking every single bill and payment for this little stuff.

This can also be a part of negotiating a large contract.

Title: Dealing with change requests from clients for an old system that only take 5 minutes to implement

Body:
Possible Duplicate:

  How should I charge for programming things which take two minutes to fix?

On some systems I created, every now and then I get tiny change requests from clients that are very easy for me to do, but the client can not do it themselves.

For example:

Hey, we made a new logo, could you please upload it to our website?

Can you check how many users we had this month?

Most of them basically just requires me to log on to the FTP server and upload a file which takes 2 minutes max. Sometimes even answering the email or writing the bill takes longer!

How do I charge the client for these changes? I could easily do it for free, because at the moment I don't get them frequently at all, maybe once per month. If the initial cost of the system is big it would seem like a nice gesture to the client to give and take a bit. What I'm afraid of is that they will become more and more frequent and then the client will get used to getting these changes for free. Also where do I draw the line for what to give away, 2 minutes? 5 minutes? 15 minutes? I want to be consistent in the pricing so it doesn't seem like I charge whatever I feel for at the moment.

Some ideas:

Charge per started hour/half hour/quarter, that is, 1 minute counts as 1 hour, 61 minutes as 2 hours (at least for the first hour).

Accumulate small changes into a pool of time. Instead of sending out bills for 2 minutes each they add up to a sum at the end of every 3 months or something.

Only charge if they want the fix NOW. Otherwise say they'll get it once I have time, within the next weeks.

Be an ass and pretend it's a big fix.


答:
Typically, an anonymous method is being used to do something, so I would talk about it in the context of its purpose.  If I absolutely must discuss the lambda without context, I'd refer to it like others have, ie, "the anonymous function taking two int and returning the multiplication of them."

But that's rare. More commonly it would be with a context, such as the following examples talking about LINQ: "The Select function gives back the names and IDs as a new object" or "The Where function filters out even numbered IDs."  Lambdas are to aid in declarative program, so I'd be talking about what I'm trying to do.


问:
Should a git commit message mention the file that was modified?
In the first line of a git commit message I have a habit of mentioning the file that modified if a change doesn't span multiple files, for example:

```<code>Add [somefunc] to [somefile]
</code>```

Is this a good thing to do or is it unnecessary?

答: No. There are plenty of ways to examine the contents of a commit. The comment should describe the purpose of the commit.

OwnerDisplayName: Matty


答:
I do that type of thing when I'm committing e.g. the fix for a defect that required changes to multiple files. This makes it a bit easier to tell what actually changed without looking at individual files in the changeset.

For single file changesets, this is unnecessary.

The first line is always a high-level description of the changeset, like a link to the defect or user story.

Title: Should a git commit message mention the file that was modified?

Body:
In the first line of a git commit message I have a habit of mentioning the file that modified if a change doesn't span multiple files, for example:

```<code>Add [somefunc] to [somefile]
</code>```

Is this a good thing to do or is it unnecessary?


答:
Version control tools are powerful enough to let the person see what files were modified, and what methods were added. It means that in general, log messages which plainly duplicate what already exists are polluting the log.

You added somefunc method to fulfill a requirement, i.e.:

to add a feature,

to remove a bug or

to refactor the source code.

This means that your log messages must rather explain what features/bugs were affected or what was the purpose of the refactoring.


问:
Effective programming of data layer management/access
Short Version: What is the term/concept which describes the efficient design of programming the data layer for efficient data access and what are some sources/books/articles/website which discuss this concept?

Long Version: So I had a recent conversation with the senior developer at my small company about how and why we access data the way we do.  He told me that it was the single most important aspect of the program and explained how it is the largest bottleneck in efficiency if done incorrectly.  He also said he had never learned about it from the courses he took and he never read about it in any books, despite the fact that he thinks it's the first thing he chooses to teach others.

I should explain that this is my first year at a job programming, that I have a degree in Electrical Engineering, but not in CS, so I wouldn't know if it was covered in school.  Also, the language I work in is Java, but this question was meant to ask about any language's access to data in a general sense.

So what am I talking about?  I'll explain through an example.  We work with a lot of data, so the data layer is a bit complicated.  It uses a combination of singleton pattern and factory design pattern to achieve different access.

For example, an Object, let's say Customer would be most often instantiated as follows:

```<code>Customer customer = Customer.getDefaultInstance(CustomerAccessType.LIST)
</code>```

OR

```<code>Customer customer = Customer.getDefaultInstance(CustomerAccessType.ONE_RECORD)
</code>```

OR

```<code>Customer customer = Customer.getDefaultInstance(CustomerAccessType.LIST_BY_ACCOUNT)
</code>```

As you may have already guessed, each access type accesses the database in a different manner.  The LIST access type most of the time has very few columns, so even though it's grabbing many rows of data, in some cases up to tens of thousands of records (maybe not with customers, but maybe something like orders from a website you can imagine that becoming very large), it might only contain the primary keys on the table and some other very specific information.  But when you edit specific data you access using type "ONE_RECORD" and with only a single row you have all the columns of the table (and most probably joins to a lot of other tables).

This is more apparent than ever when you're looking at a screen that is painting information in front of tellers and the information is changing constantly.  The information shown may be from a table that has as previously mentioned, tens of thousands of records currently being worked on.  A LIST type object will grab only the primary keys from the table, then only the records that require painting are accessed, one row at a time, and the information is painted to the screen.

So I have two questions as a result of all this:

What is the term/concept which describes the efficient design of programming the data layer for efficient data access?  Most large programs that have to deal with a lot of data access must have to deal with these same issues.  Surely others have coined a term for it?

What are some good resources to learn more about what else is out there on this subject?  Again, surely others have dealt with these same issues/bottlenecks we are dealing with.  Surely other brilliant minds have tackled the problem and written extensively on it, no?

What are other ways that perhaps your personal experience has shown you in dealing with this problem, even if you've never read it anywhere else?

Your help and knowledge is much appreciated,

-Asaf

答:
I have been asked to write the same type of interfaces and this is
what I have been told/learned.

I believe what you are referring to is the "database layer of an application".

I have seen this called the "Data access layer (of an application) also:

http://en.wikipedia.org/wiki/Data_access_layer

http://www.paulgrenyer.com/Integration_Testing_A_Java_Enterprise_Application_Data_Access_Layer.pdf

1. In order to have efficient data access

the underlying database objects
themselves have to not have performance related issues.
E.G. If you are using tables, the tables should have appropriate
indexes, the statistics on the tables have to be up-to-date,
and if you don't need the most recent data in the table,
it is a good idea to consider using materialized views.

This seems obvious, but make sure you have access to the database
itself and the database doesn't have any problems of its own,
E.G. too many outstanding sessions, I/O problems, etc.

2. In the code for the database access,

it is a good idea to
avoid hard parsing and using bind variables
will help avoid this.

3. If the work that is done in your data access layer

consists mostly of short lived transactions it may be a good idea
to use connection pooling.  I have

http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html

I am not sure whether the class you are using will work/is designed
for connection pools but if you are using a Session object (usage
of getDefaultInstance leads me to believe this might be a Session
object) and you are using this for Hibernate then this URL does state
it will work with a connection pool

http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html

I have a feeling you could be using a different object - the object
documentation should state whether it uses/is compatible with
connection pooling

4. This URL states getDefaultInstance will always create

a new object and there are alternatives.  I am not sure if that is
what you want - it is something to consider

https://stackoverflow.com/questions/4184204/what-is-the-difference-between-getdefaultinstance-and-getinstance-in-session

Again I apologize I am not sure if this document is actually for the
class you are using - this is just a best guess.


答:
Don't forget to add TICKET/ISSUE NUMBER .

If you have any feature or issue tracking system with a ticket # or issue #, be sure to put that ID # in the commit. That will help anyone who wants to know more about the feature or issue that you were working on.

In my last project, there was a macro which was developed to make sure that the first  7 digits of the comment was a valid issue number from clear quest (our issue/feature tracking system).


问:
Are C and/or C++ viable/practical options for web development?
I am proficient in C, and I am learning C++ right now. I always played with websites (HTML/CSS), and I was wondering if it would be viable/practical to create some simple web apps using C and/or C++.

For C it would be via CGI scripts, as explained in this tutorial for example -> http://www.cs.tut.fi/~jkorpela/forms/cgic.html

For C++ it could be via a web toolkit like Wt -> http://www.webtoolkit.eu/wt

Notice that I know it's possible (as explained in this previous question -> Can C++ be used as a server-side web development language? ).

What I am asking is if it's viable/practical (i.e., not a nightmare). I am not keen on picking up another language yet as I just started with C++, but if it would make web dev incredibly easier I will consider it (or I'll postpone my web dev projects until I am ready to pick up a new language).

Also, in case you think it's viable/practical, recommendations on the route to follow would be highly appreciated (i.e., forget C and go with C++, what framework to use and so on).

答:
IIRC eBay is built upon ISAPI which was written in C++ using the Microsoft Active Template Library server modules.

It's possible they made an early bet on it but now have no compelling business reason to move off it. Indeed, Facebook is compiled into a single large C++ binary but they develop in PHP and use HipHop compiler to transliterate:

HipHop cross-compiler:
https://developers.facebook.com/blog/post/2010/02/02/hiphop-for-php--move-fast/

Single binary:
http://en.wikipedia.org/wiki/HipHop_for_PHP#HPHPc


问:
Appropriate programming language to design music software
I want to design a software for my musical instrument which is a rhythmic one (there is no melody).
All I want these software to do is :

make the user able to compose music

play what user has composed

for that purpose I need to record diffrent sounds of that instrument and match each sign with the appropriate sound .

Which programming language is adequate for this purpose ?

答:
Read about these languages and decide which one suits your need:

SuperCollider

SuperCollider is an environment and programming language for real time
  audio synthesis and algorithmic composition. It provides an
  interpreted object-oriented language which functions as a network
  client to a state of the art, realtime sound synthesis serve

Pure Data

Pd (aka Pure Data) is a real-time graphical programming environment
  for audio, video, and graphical processing. It is the third major
  branch of the family of patcher programming languages known as Max
  (Max/FTS, ISPW Max, Max/MSP, jMax, etc.)

ChucK

is a new (and developing) audio programming language for real-time
  synthesis, composition, performance, and now, analysis - fully
  supported on MacOS X, Windows, and Linux. ChucK presents a new
  time-based, concurrent programming model that's highly precise and
  expressive (we call this strongly-timed), as well as dynamic control
  rates, and the ability to add and modify code on-the-fly. In addition,
  ChucK supports MIDI, OSC, HID device, and multi-channel audio. It's
  fun and easy to learn, and offers composers, researchers, and
  performers a powerful programming tool for building and experimenting
  with complex audio synthesis/analysis programs, and real-time
  interactive control.


问:
How do you organize your projects folders?
Good afternoon

I would like to know how do you guys organize your project folders?

I had once a boss that suggest me to organize by Customers.

```<code>Projects
|
|----Customer 1
     |---- A Cool Solution 1
           |---- source
                 |---- version1.0
                 |---- version1.1
           |---- docs
                 |---- analysis
                 |---- meetings
                 |---- manuals
|----Customer 2
|----Customer 3
</code>```

A friend of mine told me to organize tem by Technology

```<code>Projects
|
|----.NET
     |---- C#
          |---- Customer 1
                |---- A Cool Solution 1
                      |---- source
                            |---- version1.0
                            |---- version1.1
                      |---- docs
                            |---- analysis
                            |---- meetings
                            |---- manuals
|----Ruby
|----PHP
</code>```

And you? Do you have a clever way to organize your project folders?

答:
I also have a flat structure.

/Projects

Agreeing with Wyatt Barnett, real deal lives in source control anyway.

Just want to add that there shouldn't be anything special about folder structure anyway, since many IDEs provide shortcuts to recent projects/files anyway.  And how many projects does anyone work on anyway?  Truly, only by definition, the recent ones.

Also, I only add recent projects into top level folder anyway.  I archive all the older and completed stuff into:

/Projects/Old_stuff

or something like that. I archive what I generally won't be working on again.


问:
What makes a hashing algorithm "secure"?
After reading this interesting question, I felt like I had a good idea of which insecure hashing algorithm I'd use if I needed one, but no idea why I might use a secure algorithm instead.

So what is the distinction?  Isn't the output just a random number representing the hashed thing?  What makes some hashing algorithms secure?

答:
Secure means that someone wanting to induce you into error by using a collision (i.e. the fact that two sources are hashed to the same value) will have difficulties.

Some characteristics:

knowing the hash, building a file who hash to that value is difficult (variant, part of the new file is given as well as the desired hash)

building two different files which hash to the same value is difficult (variant, part of the files is given)


问:
Rotate, Scale and Transform in video games
IF a 3 dot vector and a 3x3 matrix can rotate, scale and transform things in a virtual 3D space, could you use a 3x3x3 matrix and a 3.3.3 vector to do something to the games sense of time?</p>

答:
technically you need a 4x4 matrix to rotate scale and transpose in a 3D space (with the bottom row [0,0,0,1] and last dimension 1 on the points (0 for vectors))

these are called affine transforms and can be easily applied to more dimensions (you just need a (n+1)x(n+1) matrix for points in n dimensions)


问:
Should OO design, or database design, drive the coding of my @Entity classes?
I have two classes that I want related to each other in an JEE application using JPA2. In an OO world, I would say that a Chatroom has an attribute List messages. In the relational world composition doesn't exist like this. If I weren't involving a database at all, I would definitely code these two things as a composition the messages inside of the Chatroom. But since I'm using ORM with the JPA2 spec I've decided to try to create the @Entity objects as written below with the fact that they'll be mapped to the database in mind.

My question is: Should I be doing this? Is it appropriate to break out the @Entity classes to support what feels like the more relational approach? Or should I just design from an OO perspective, and try to ignore the fact that there's an ORM driving it from below? Right now I'm driving my design from the database side, but should I be doing it the other way? Are there implications I'm missing about doing it this way?

```<code>package org.janp.castlerock;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Chatroom {
    private String name;

    @Id
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

package org.janp.castlerock;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Message {
    private int id;
    private Chatroom chatroom;
    private Date timestamp;
    private String text;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getTimestamp() {
        return timestamp;
    }
    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }

    @ManyToOne
    @JoinColumn(name="name")
    public Chatroom getChatroom() {
        return chatroom;
    }
    public void setChatroom(Chatroom chatroom) {
        this.chatroom = chatroom;
    }
}
</code>```

答:
I am currently working with an ORM (Doctrine 2 in PHP) and I work like this :

For example I had to build a media library management component with the following associated entities :

Media (contains the actual media description and path)

MediaType (video, image or audio)

MediaExtension [by type] (.mp4, .jpg, .mp3, etc.)

These entities are used to define my DB structure and relation between object (an entity could be managing a junction table as well, so they don't map 1 to 1 with my database)

These three entities where then injected in the model that contained all the logic and since all these entities were relating with each other to manage the library, all the required code in contained is my model class.

So in your case, you could build a model that would manage the chat with the following entities :

Room (define the actual chatroom (rules, admins, topic, name, etc.)

Message (messages exchanged between users)

Users (this will only manage the part where a user create a new message and maybe a few options like the display name. This entity would also be present in your user model which manage user creation and in depth modification)

This would be closer to a Domain Driven Design (the data management is mapped to fit application requirements, gives a more user friendly feel to the application) as opposed to a Data Driven Design (where the database structure guide how the application requirement are implanted)


答: Most games don't use 4D matrices to represent elements of the game. The time "dimension" is usually controlled by some sort of  timer call-back function. It's probably possible to do it with 4D matrices, I just haven't seen it. Of course, to store a complete time dimension for a game might take up a lot of space.</p>

Title: Rotate, Scale and Transform in video games

Body: IF a 3 dot vector and a 3x3 matrix can rotate, scale and transform things in a virtual 3D space, could you use a 3x3x3 matrix and a 3.3.3 vector to do something to the games sense of time?</p>


答:
Read this http://www.codinghorror.com/blog/2012/04/speed-hashing.html it will explain everything much better than I could ever explain it.  Here are the two most important headers in the article that directly address your question:

Secure hashes are designed to be tamper-proof

changes its output radically with tiny single bit changes to the input data

Secure hashes are designed to be slow

His TL;DR section at the end:

If you are a user:

Make sure all your passwords are 12 characters or more, ideally a lot more. I recommend adopting pass phrases, which are not only a lot easier to remember than passwords (if not type) but also ridiculously secure against brute forcing purely due to their length.

If you are a developer:

Use bcrypt or PBKDF2 exclusively to hash anything you need to be secure. These new hashes were specifically designed to be difficult to implement on GPUs. Do not use any other form of hash. Almost every other popular hashing scheme is vulnerable to brute forcing by arrays of commodity GPUs, which only get faster and more parallel and easier to program for every year.

Title: What makes a hashing algorithm "secure"?

Body:
After reading this interesting question, I felt like I had a good idea of which insecure hashing algorithm I'd use if I needed one, but no idea why I might use a secure algorithm instead.

So what is the distinction?  Isn't the output just a random number representing the hashed thing?  What makes some hashing algorithms secure?


问:
One man company looking to expand already built in PHP. Is now the time to switch to Ruby?
I'm a website owner and I develop in Yii so in short, I think I'm working with more or less the "best" PHP has to offer (e.g. PDO, OOP...etc). My primary website (which is not built in any framework just native PHP) of 2.5 years is finally making enough money I can hire my first employee who I want to be a developer to convert it over to Yii. I've also started a new site which is just four weeks into development built with Yii but instead of building anything this week I'm going through RubyKoans because I keep wrestling with the idea that now there is no better time to convert to using Ruby on Rails...

I go through Yii and a lot of the most awesome stuff is ported from Rails (e.g. scopes). A lot of really great websites are built in rails (e.g. Twitter, GitHub, Hulu). Rails developers are "more" expensive but if you hire one are you not guaranteed a certain level of quality where as with PHP there's a lot of crummy devs out there? If I ever do make the switch, is it not better to do it now when it will be less painful? If I want to create a company that attracts talented developers, why not work in ruby so my company stands out?

At the same time PHP is fast, reliable, and when you're working with the "best" (e.g. Yii, Symfony2) I think it's a pretty nice and maintainable language. A lot of big sites are built in it too (Facebook, Digg, Craigslist, Hootsuite) plus all the porn sites which we all must admit deal with tons of traffic. Also there is way more PHP devs out there so as long as I use good interview practices will it not be easier to find some good PHP devs? Or would it be easier knowing every dev who came in for an interview already used ruby? Also a big part of me just wants to get started and not spend six months wading through ruby till I'm confident enough I want to port my existing projects over to it.
Any thoughts?

答:
I think you should focus on what tool you are most comfortable with to meet your goals.

I wouldn't let the hiring process affect your choice of tool.  Any good developer you are going to hire should be able to figure out how to work in whatever language you use.  If he can't then he isn't a good developer.  Languages are tools.

Say your goal is to build something faster, with better quality.  Only you will know what tool will help you accomplish this goal.

If you have a goal to start working in Ruby, then it might be a good idea to start your new project in that.

One thing you probably don't want to do is re-do an existing product in a different language "just because".


答:
The primary difference is pretty simple: a normal hash is meant to minimize the number of accidental collisions, to the extent that it can without slowing down a whole lot in the process.

A secure hash it intended to prevent collisions, even when somebody's doing their best to cause one. You generally don't want to trade any possibility of a collision for faster operation. In fact, making operation intentionally slow has some security benefits in itself, even if doesn't make finding collisions any harder.

For an example of the latter: if computing a hash takes 50 ms, it won't have an material affect on a normal user's login (i.e., most users won't notice a difference of 50ms when they login). At the same time, if an attacker wants to do a dictionary attack, being able to produce only 20 hashes a second is a serious handicap. In other words, within some kind of reason, for a secure hash, slower is better.


答:
Write your objects as objects. Let the mapper handle the relational side of things. I'd much rather given a chatroom say:

```<code>Collection messages=chatroom.getMessages();
</code>```

instead of having to do a new query of Messages where the ChatroomId == chatroom.getId() especially seeing that Java doesn't have a LINQ equivalent

Title: Should OO design, or database design, drive the coding of my @Entity classes?

Body:
I have two classes that I want related to each other in an JEE application using JPA2. In an OO world, I would say that a Chatroom has an attribute List messages. In the relational world composition doesn't exist like this. If I weren't involving a database at all, I would definitely code these two things as a composition the messages inside of the Chatroom. But since I'm using ORM with the JPA2 spec I've decided to try to create the @Entity objects as written below with the fact that they'll be mapped to the database in mind.

My question is: Should I be doing this? Is it appropriate to break out the @Entity classes to support what feels like the more relational approach? Or should I just design from an OO perspective, and try to ignore the fact that there's an ORM driving it from below? Right now I'm driving my design from the database side, but should I be doing it the other way? Are there implications I'm missing about doing it this way?

```<code>package org.janp.castlerock;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Chatroom {
    private String name;

    @Id
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

package org.janp.castlerock;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Message {
    private int id;
    private Chatroom chatroom;
    private Date timestamp;
    private String text;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getTimestamp() {
        return timestamp;
    }
    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }

    @ManyToOne
    @JoinColumn(name="name")
    public Chatroom getChatroom() {
        return chatroom;
    }
    public void setChatroom(Chatroom chatroom) {
        this.chatroom = chatroom;
    }
}
</code>```

Body:
Write your objects as objects. Let the mapper handle the relational side of things. I'd much rather given a chatroom say:

Collection messages=chatroom.getMessages();

instead of having to do a new query of Messages where the ChatroomId == chatroom.getId() especially seeing that Java doesn't have a LINQ equivalent


问:
What kind of problems does MapReduce solve?
I have been reading about MapReduce for a while -- but what I can't understand is how someone would make a decision to use (or not use) MapReduce.

I mean, what are the problem patterns that signal that MapReduce could be used.

答:
in effect, it's a generic "divide and conquer" pattern, so that solutions for distributing the computation can be written generically.

a simple example is like a large document. the problem is you want to count the number of letters in that document. instead of running on a single machine, you can break it down into an array of all words in the document. then you can process each word individually, and the results back together.

the pattern is useful, because once you get a generic map/reduce implementation working you can solve any problem using that same software layer, you just need to express your problem in terms of it.


问:
What are the Agile initial conditions?
First let me say that I think that an agile process can work because of the following underlying principles:

It brings focus

Limits the noise which really brings focus

Secondly I am wondering what are the initial conditions needed so that an Agile process can succeed?  For example do we need to have:

No existing bugs

Fully automated test process or at least a highly automated test process

People dedicated to the project

More clearly defined new development

Development that is not make it faster or more stable

?

So what do you need to make it successful?  Are there different Agile implementations that better handle not having some of these initial conditions?

答:
People at all levels of the business who truly and utterly believe in the Agile Manifesto

We are uncovering better ways of developing software by doing it and
  helping others do it. Through this work we have come to value:

Individuals and interactions over processes and tools

Working software over comprehensive documentation

Customer collaboration over contract negotiation

Responding to change over following a plan

That is, while there is value in the items on the right, we value the
  items on the left more.

And when I say believe in the Agile Manifesto, I mean all of the Agile Manifesto. You cannot ignore the last part. There is still value in the items on the right.

If you have those people, as programmers, as managers, as customers, you can make some variation of Agility work. If you don't, you will struggle.

Title: What are the Agile initial conditions?


答: The only time I could see this being useful for a single file checkin is if you've made changes to a function used in many places within the file with the result that the diff is cluttered.  Even then I'd put the change tracker # and a plain text description of the change first.</p>


答:
Just my two cents here. Since starting to work with asp.net mvc along with entity framework, that even though it's real easy to get me a database representation of a table, that really may not be what I need.

I've found that creating what some people call a ViewModel, a class that has everything you need to represent the actual object you're going to work with, has actually been a pretty good idea. While it seems that you're creating extra work, what with a base model which looks like a table, and second model that just recreates those properties (and/or adds more depending on the situation) I think the flexibility is a better trade off.

So I'm going to agree with the others here and say, write your 'viewModels' to match what you really need, and just map those properties off to an 'entity' model when you need to either save or access them from the database.

Hope this helps some, and good luck on your project.


问:
Code duplication with no obvious abstraction
Have you ever encountered a case of code duplication where, upon looking at the lines of code, you couldn't fit a thematic abstraction to it that faithfully describes its role in the logic? And what did you do to address it?

It is code duplication, so ideally we need to do some refractoring, like for example making it its own function. But since the code doesn't have a good abstraction to describe it the result would be a strange function that we can't even figure out a good name for, and whose role in the logic is not obvious just from looking at it. That, to me, hurts the clarity of the code. We can preserve clarity and leave it as it is but then we hurt maintainability.

What do you think is the best way to address something like this?

答:
Sometimes code duplication is the result of a "pun": Two things look the same, but aren't.

It is possible that over-abstracting can break the true modularity of your system. Under the regime of modularity, you have to decide "what is likely to change?" and "what is stable?". Whatever is stable gets put in the interface, while whatever is unstable gets encapsulated in the module's implementation. Then, when things do change, the change you need to make is isolated to that module.

Refactoring is necessary when what you thought was stable (e.g. this API call will always take two arguments) needs to change.

So, for these two duplicated code fragments, I would ask: Does a change required to one necessarily mean the other must be changed as well?

How you answer that question might give you better insight into what a good abstraction might be.

Design patterns are also useful tools. Perhaps your duplicated code is doing a traversal of some form, and the iterator pattern should be applied.

If your duplicated code has multiple return values (and that's why you can't do a simple extract method), then perhaps you should make a class that holds the values returned. The class could call an abstract method for each point that varies between the two code fragments. You would then make two concrete implementations of the class: one for each fragment. [This is effectively the Template Method design pattern, not to be confused with the concept of templates in C++. Alternatively, what you are looking at might be better solved with the Strategy pattern.]

Another natural and useful way to think about it is with higher-order functions. For example, making lambdas or using anonymous inner classes for the code to pass to the abstraction. Generally, you can remove duplication, but unless there really is a relation between them [if one changes, so must the other] then you might be hurting modularity, not helping it.


答:
At a minimum

First and foremost, you must have top down sponsorship that understands the principals and believes in them enough to enforce them down the chain, and believes that Agile is applicable to your situation.

Having senior management that doesn't believe in the process, will ultimately undermine it because they will allow subordinates to pervert, distort, pollute, undermine or worse sabatoge the process.

If senior management don't understand the principals they will start demanding short cuts and compromises that pervert the process. Then when things break down, the naysayers can say "I told you so, Agile doesn't work!" back to the death march!

This is worse than not adopting Agile, it is typically referred to as "Agile But ...". Management uses the Agile term, "But ..." throws out all the actual principals and continues to do what they were doing before, "But ..." now call it Agile. Which gives Agile a bad name to those that don't know any better.

nice side effects

The things you list like, no bugs, automated tests, clearly defined development, dedicated people, etc. are all nice positive side effects to Agile.

Agile, isn't a silver bullet or panacea, but it does promote transparency at all levels ( customer <-> management <-> developers ) and makes those people that are problems to productivity stand out quickly; especially specific implementations of Agile like Scrum.

Title: What are the Agile initial conditions?

Body:
First let me say that I think that an agile process can work because of the following underlying principles:

It brings focus

Limits the noise which really brings focus

Secondly I am wondering what are the initial conditions needed so that an Agile process can succeed?  For example do we need to have:

No existing bugs

Fully automated test process or at least a highly automated test process

People dedicated to the project

More clearly defined new development

Development that is not make it faster or more stable

?

So what do you need to make it successful?  Are there different Agile implementations that better handle not having some of these initial conditions?


答:
A few things that come to mind:

Professional team cohesion - Are these people that are open to playing well with others?  Are they mature, responsible people that can be given some autonomy in their work?

Communication culture and policies - How well do people express concerns, thoughts, and opinions in the organization?

Understanding what Agile is and isn't - Do those external stakeholders know enough about the process to accept the responsibility on their end?  If not, then this can make for pseudo-agile.  Similarly, is there a clearly defined Product Owner and ScrumMaster to help organize some things?

Title: What are the Agile initial conditions?


问:
A question on nature of generated assembly in C++ and code Algebra
I wrote this code:

```<code>#include <iostream>
int main()
{
    int a;
    std::cin >> a;
    if(a*a== 3){
        std::cout << a;
    }
    return 0;
}
</code>```

On MSVC I turned ON all optimization flags. I expected that since a*a can never be 3, so compiler should not generate code for the section:

```<code>if(a*a== 3){
    std::cout << a;
}
</code>```

However it generated code for the section. I did not check GCC or LLVM/CLang.

What are the limits of expectation from a C++ compiler in these scenarios?

答:
Consider what happens if input fails. a can be left with an undefined value, and hilarities may ensue.

Try initializing it first.


问:
How To Explain To My Dad What I have Programmed

Possible Duplicate:

  My Dad is impatient with the pace of my learning to program. What do I do?

I am 14 and have been studying programming for 4 months now (3 months Python, 1 Month of Ruby). I haven't been pushed by my parents to do it, I took it up on my own. Whenever I try to show something I made to my dad, he says he finds no value in it. At first, I wrote simple text games, like a text version of rock paper scissors, roulette, blackjack, etc. When that got too easy, I tried to make them as advanced as possible. I made a roulette game in Ruby based off instance_eval and method_missing. I showed them to him, and he said that was "childish" to make games. After games got too easy, I have started extending the features of the languages, I made a module for a "Changeable Range" in Python, where one could just write:

```<code>j = crange.CRange(5)
</code>```

then

```<code>j.shift(10)
</code>```

to shift the start and stop up ten and

```<code>j.reverse()
</code>```

to create a reversed range. I showed it to him and he said "There is no value in that." Is there a way to explain to him that there is value in my programs, or am I just moving at a very slow pace in my learning?

答:
As someone who is highly skeptical of modern society's fascination with video games, I can still say that when you are a programmer, no program has no value. It has value in the experience and the things you learned in writing it. If you are ever to write anything useful, it will be because you cut your teeth writing "useless" programs.

That is about like me deriding my two year old for stacking blocks. Yes it has no real use, but it does have use in his personal development.


答:
If you broke down all the different things that you learned in making your programs then he may see some value.  For example, what skills did you develop in writing those programs?  What kinds of ideas or knowledge is now with you that wasn't there previously?  That would be what I'd do assuming you want to beat the dead horse even more.  The reason I call this a dead horse is to imagine anyone's first few lines of poetry, attempts at singing a pop song, or other artistic expressions that may not be great initially but with practice and persistence things can really change.

The other way to move forward here would be to ask your dad for something he'd like a program to do and make that for him.  That way you know why he would want it, he asked for it.  Granted this does presume some trust and faith in his part in coming up with something realistic yet simple, but that would likely be far better.

Title: How To Explain To My Dad What I have Programmed

Body:
Possible Duplicate:

  My Dad is impatient with the pace of my learning to program. What do I do?

I am 14 and have been studying programming for 4 months now (3 months Python, 1 Month of Ruby). I haven't been pushed by my parents to do it, I took it up on my own. Whenever I try to show something I made to my dad, he says he finds no value in it. At first, I wrote simple text games, like a text version of rock paper scissors, roulette, blackjack, etc. When that got too easy, I tried to make them as advanced as possible. I made a roulette game in Ruby based off instance_eval and method_missing. I showed them to him, and he said that was "childish" to make games. After games got too easy, I have started extending the features of the languages, I made a module for a "Changeable Range" in Python, where one could just write:

```<code>j = crange.CRange(5)
</code>```

then

```<code>j.shift(10)
</code>```

to shift the start and stop up ten and

```<code>j.reverse()
</code>```

to create a reversed range. I showed it to him and he said "There is no value in that." Is there a way to explain to him that there is value in my programs, or am I just moving at a very slow pace in my learning?


答:
My daddy knew a lot of guitar players, and most of them didn't work,
  so he said, "You should make your mind up to either be a guitar player
  or an electrician, but I never saw a guitar player that was worth a
  damn." - Elvis Presley

Considering the above quote, what qualifies your fathers opinion to mean so much?

I started out when I was 13, but my weapon of choice was self taught 6502 ASM and BASIC on a Apple ][ and Commodore C=64. My parents thought me saving up all my allowance and side work money to by my first C=64 and 5.25 Floppy drive was crazy. That as in 1980.

To this day my father has no idea what I do either, he quit school in the 5th grade to run the family farm, he owned his own company building roads and highways for 38 years, he is now 77. He was what you would call an Individual Contributor his entire life, he drove a truck, my mother ran the company. Other than telling him, programming is giving detailed instructions to the computer on what to do to make something happen, he doesn't really care past that.

He definitely didn't understand what I thought I was going to do with a college degree in art either, but he helped pay for that and supported me in that as well.

I am in management now, that probably has even less perceived value to him; now I tell people what to tell the computers to do and don't do any individual contributor anymore.

He is proud I can take care of myself and my family, and him if he ever needs it; that is all the validation I need to have.

Beyond that I feel little need for him to understand or find value in the physical act of me sitting at a desk all day long typing code into a computer; or now sitting in endless conference calls and responding to hundreds of emails a day on the projects I over see.

The point here is Elvis didn't let his father get him down or discourage him; you should not either. Go ahead and be the next Steve Jobs; that job isn't taken anymore.


答:
Checking for a few fairly specific literal values like if (0), if (1), if (LOG_LEVEL > 1)`, etc., is pretty routine.

Checking that a number is a perfect square so that squaring an integer could produce that value? I'd be surprised to see a compiler do that. It undoubtedly could be done -- it's actually simpler than a lot of things that are done. At the same time, most such optimization makes the compiler run at least a tiny bit slower, and I doubt anybody wants to slow the compiler at all for something that's likely to be used anywhere close to as rarely as that.

Title: A question on nature of generated assembly in C++ and code Algebra

Body:
I wrote this code:

```<code>#include <iostream>
int main()
{
    int a;
    std::cin >> a;
    if(a*a== 3){
        std::cout << a;
    }
    return 0;
}
</code>```

On MSVC I turned ON all optimization flags. I expected that since a*a can never be 3, so compiler should not generate code for the section:

```<code>if(a*a== 3){
    std::cout << a;
}
</code>```

However it generated code for the section. I did not check GCC or LLVM/CLang.

What are the limits of expectation from a C++ compiler in these scenarios?


答:
Theoretically, neither of the these approaches is truly 'OO', since you're exposing all of the internal state outward (there is no encapsulation). So, from this perspective, your question really becomes: should I add Collection attributes/getters/setters to my DAO (Data Access Objects). As this will further expose internal state, I'm tempted to answer with 'no'.

Moreover, because you are making assumptions on the expected use of your objects (asking for the list will retrieve all the messages, without any selection), you might actually inspire programmers to bypass the optimization strategies a database might give you. To elucidate this by example; you might bypass an efficient index by retrieving all objects and sorting or selecting them afterwards.

On the practical side, adding these list accessors is often useful. It allows for a more natural way of navigating through your object graph and often is more efficient for small sets, since you have more control over caching.

I would like to end by giving a piece of sound advice. Create a clear delineation between your DAO's and your models. Try not to work directly on DAO's from a GUI and consider adding a business logic layer in between. It might be slightly more difficult at the start, but it will reduce complexity and promotes reusability. Perhaps, when your business logic layer is complete, you'll find you don't need many of those pesky DAO's after all. You might actually find data storage solutions which operate more efficiently by bypassing the overhead of DB calls.


答:
When you encounter a situation like this, it's best to think about "non-traditional" abstractions.  Maybe you have a lot of duplication within a function and factoring a plain old function doesn't fit very well because you have to pass too many variables.  Here, a D/Python style nested function (with access to the outer scope) would work great.  (Yes, you could make a class to hold all that state, but if you're only using it in two functions, this is an ugly and verbose workaround for not having nested functions.)  Maybe inheritance doesn't quite fit, but a mixin would work well.  Maybe what you really need is a macro.  Maybe you should consider some template metaprogramming or reflection/introspection, or even generative programming.

Of course, from a pragmatic point of view, these are all difficult if not impossible to do if your language doesn't support them and doesn't have enough metaprogramming capabilities to implement them cleanly within the language.  If this is the case, I don't know what to tell you except "get a better language".  Also, learning a high-level language with lots of abstraction capabilities (like Ruby, Python, Lisp or D) might help you program better in lower-level languages where some of the techniques might still be usable, but less obvious.

Title: Code duplication with no obvious abstraction

Body:
Have you ever encountered a case of code duplication where, upon looking at the lines of code, you couldn't fit a thematic abstraction to it that faithfully describes its role in the logic? And what did you do to address it?

It is code duplication, so ideally we need to do some refractoring, like for example making it its own function. But since the code doesn't have a good abstraction to describe it the result would be a strange function that we can't even figure out a good name for, and whose role in the logic is not obvious just from looking at it. That, to me, hurts the clarity of the code. We can preserve clarity and leave it as it is but then we hurt maintainability.

What do you think is the best way to address something like this?


答:
Computer programming is a way to solve problems. People pay you money to solve their problems.

You need to make the connection between some code you wrote and a potential problem that could be solved with that. It doesn't have to be too fancy or complex, but this connection will be clearer to your dad than showing him a game or library method.
Examples:

A simple web application.  Work through a tutorial of a programming book, and it will show how to make a web-app for a pretend store.

Make a simple calculator program

Make an address book program that keeps your contacts

Make a calendar program

Make a Math equation program. I don't know what level of Math you are on, but one of the first programs I made was for finding the hypotenuse of a triangle.

After you do something like that (or simpler), you can show that you can customize these programs yourself with your programming knowledge.


答:
Parental approval is always nice, but is much more likely that your dad simply doesn't understand what you are doing.  All he sees is the final product, which in and of itself really may not have value.  For example, Video Games do not actually have value, but they are technical masterpieces.  The specific algorithms, caching, load balancing and, of course, rendering are often pure genius.  Instead of showing him the final product, try show him how much work went into it, the studying you had to do, the understanding of numerical progression, the trial and error and so forth.

Every programming task requires that you either learn something (or many things) or learn how to see something in a different way. While your father might not understand the specifics of programming, he would almost certainly welcome seeing all of the different things that you are learning while going through the process. A child's personal growth is very high on the list of things that makes parents glow :)

If you like programming, stick with it and learn everything you can because it will certainly take good care of you.  Feel free to show him some of the recent Salary Surveys for experienced developers and point out that, even though he might not see the value, the marketplace definitely does.  Software Developers make decent money - money that can let you get your own apartment, pay for your own college, Food, car, insurance, etc.  I'm sure your dad will see the value in that!


问:
Has whitespace in identifiers ever been idiomatic?
C# style suggests using CamelCase in identifiers to delimit words. Lisp tradition suggests using-dashes-instead.

Has there ever existed a programming language where using spaces in identifiers was not only allowed, but a commonly used idiom when employing multi-word identifiers?

It's possible to have identifiers with spaces in some Scheme implementations, but it's not a widely seen practice. Here's an example:

```<code>Petite Chez Scheme Version 8.4
Copyright (c) 1985-2011 Cadence Research Systems

> (define |hey there| 100)
> (define |x y z| 200)
> (list |hey there| |x y z|)
(100 200)
</code>```

答: If you you count it as a real language, JMP scripting language ( http://www.jmp.com/support/downloads/pdf/jmp_scripting_guide.pdf ). It allows identifiers to have whitespace (to make them more "readable") and more or less encourages such.</p>


答:
In an extremely narrow sense your father is right: no one is going to trade you money, food, or shelter for your programming exercises. The same is true for learning the alphabet, learning the multiplication tables, or learning to play 'Twinkle, Twinkle, Little, Star" on the piano.

However, this is an absurdly short-sighted point of view. None of those activities is valuable to anyone but yourself, but for you they are essential. They are the building blocks that create the skills that you must have to begin your adult life. Just as no one becomes an accountant without having learned the multiplication tables, or a concert pianist without learned the equivalent of "Twinkle, Twinkle",  no one becomes a professional programmer without having gone through exercises like writing a 'rock, paper, scissors" game.


答:
I am often asked by adults to teach them how to program. It never goes very far becasue I alsways ask them after the first lesson what do they want to write. If they don't have any idea, I know they will not become a programmer.

If they can qucikly see the value in the first lesson, they start making these small fun programs. They experiment, investigate, and explore on their own.

Most programers have made these types of programs. Are they worth money? No. On their own were they worth the effort? No. But as the first steps towards a rewarding hobby or career? Priceless.


答: In addition to the other good answers here, I suspect that your dad won't see any of the programs you make as having value when it has no direct value to him. Suppose you coded a mortgage calculator that could tell him how much he had paid and how much remained, based on inputs of interested rates, ammortization period, initial amount, etc.. That might be something he can see value in if he has ever had to pay a mortgage.


答:
I showed it to him and he said "There is no value in that."

That's like saying that there's no value in playing with Lego bricks, doing puzzles, reading, fooling around with a guitar, etc. It's true, nobody is going to pay you to do those things. But you don't become a mechanical engineer or a concert musician by being instantly endowed with a great deal of knowledge. You build the skills that you'll need to do those things over years. You start with the very simple and build from there.

The value is not in what you've created, it's in what you've learned.

It's impossible for us to guess what would convince your dad that what you're doing is worthwhile. Maybe he thinks that all of software development is a sham, that it's not real work because you don't get your hands dirty. Who knows? But if he agrees that there's value in software at all, he should be able to see that what you're doing is helping to prepare you for building bigger, better things in the future.

And frankly, as a father, he should be looking for ways to support you in what you do and in what makes you happy, not tear you down. Perhaps there's some deeper issue that's making that difficult for him to do that. The best you can do is to try to understand him and do your best to relate. Part of growing up is figuring out that your parents don't know everything after all.


答:
If you really wanted to try to impress him, ask him: "What do you wish your computer would do?" Then write a script that will do that thing (or something similar), maybe with a slick interface. Given what I know about Python, that might be quite possible for you.

One thing non-programmers don't really appreciate is that programming gives you control over a machine, allowing you to do exactly what you want it to. Making an app that lets a user do something he wants give some insight into that.


答:
There are three properties one wants from every cryptographic hash function H:

preimage resistance: Given h, it should be hard to find any value x with h = H(x).

second preimage resistance: Given x1, it should be hard to find x2 != x1 with H(x1) = H(x2).

collision resistance: It should be hard to find two values x1 != x2 with H(x1) = H(x2).

With hash functions as used in common programming languages for hash tables (of strings), usually none of these is given, they only provide for:

weak collision resistance: For randomly (or "typically") selected values of the domain, the chance of collision is small. This says nothing about an attacker intentionally trying to create collisions, or trying to find preimages.

The three properties above are (among) the design goals for every cryptographic hash function. For some functions (like MD4, SHA-0, MD5) it is known that this failed (at least partially). The current generation (SHA-2) is assumed to be secure, and the next one ("Secure Hash Algorithm 3") is currently in the process of being standardized, after a competition.

For some uses (like password hashing and key derivation from passwords), the domain of actually used values x is so small that brute-forcing this space becomes feasible with normal (fast) secure hash functions, and this is when we also want:

slow execution: Given x, it takes some minimum (preferably configurable) amount of resources to calculate the value H(x).

But for most other uses, this is not wanted, one wants instead:

fast execution: Given x, calculating the value of H(x) is as fast as possible (while still secure).

There are some constructions (like PBKDF2 and scrypt) to create a slow hash function from a fast one by iterating it often.

For some more details, have a look at the hash tag on our sister site Cryptography Stack Exchange.


问:
Merge sort versus quick sort performance
I have implemented merge sort and quick sort using C (GCC 4.4.3 on Ubuntu 10.04 running on a 4 GB RAM laptop with an Intel DUO CPU at 2GHz) and I wanted to compare the performance of the two algorithms.

The prototypes of the sorting functions are:

```<code>void merge_sort(const char **lines, int start, int end);

void quick_sort(const char **lines, int start, int end);
</code>```

i.e. both take an array of pointers to strings and sort the elements with index i : start <= i <= end.

I have produced some files containing random strings with length on average 4.5 characters. The test files range from 100 lines to 10000000 lines.

I was a bit surprised by the results because, even though I know that merge sort has complexity O(n log(n)) while quick sort is O(n^2), I have often read that on average quick sort should be as fast as merge sort. However, my results are the following.

Up to 10000 strings, both algorithms perform equally well. For 10000 strings, both require about 0.007 seconds.

For 100000 strings, merge sort is slightly faster with 0.095 s against 0.121 s.

For 1000000 strings merge sort takes 1.287 s against 5.233 s of quick sort.

For 5000000 strings merge sort takes 7.582 s against 118.240 s of quick sort.

For 10000000 strings merge sort takes 16.305 s against 1202.918 s of quick sort.

So my question is: are my results as expected, meaning that quick sort is comparable in speed to merge sort for small inputs but, as the size of the input data grows, the fact that its complexity is quadratic will become evident?

Here is a sketch of what I did.
In the merge sort implementation, the partitioning consists in calling merge sort recursively, i.e.

```<code>merge_sort(lines, start, (start + end) / 2);
merge_sort(lines, 1 + (start + end) / 2, end);
</code>```

Merging of the two sorted sub-array is performed by reading the data from the array lines and writing it to a global temporary array of pointers (this global array is allocate only once). After each merge the pointers are copied back to the original array. So the strings are stored once but I need twice as much memory for the pointers.

For quick sort, the partition function chooses the last element of the array to sort as the pivot and scans the previous elements in one loop. After it has produced a partition of the type

```<code>start ... {elements <= pivot} ... pivotIndex ... {elements > pivot} ... end
</code>```

it calls itself recursively:

```<code>quick_sort(lines, start,          pivotIndex - 1);
quick_sort(lines, pivotIndex + 1, end);
</code>```

Note that this quick sort implementation sorts the array in-place and does not require additional memory, therefore it is more memory efficient than the merge sort implementation.

So my question is: is there a better way to implement quick sort that is worthwhile trying out? If I improve the quick sort implementation and
perform more tests on different data sets (computing the average of the running times on different data sets) can I expect a better performance
of quick sort wrt merge sort?

EDIT

Thank you for your answers.

My implementation is in-place and is based on the pseudo-code I have found
on wikipedia in Section In-place version:

```<code>function partition(array, 'left', 'right', 'pivotIndex')
</code>```

where I choose the last element in the range to be sorted as a pivot, i.e. pivotIndex := right.
I have checked the code over and over again and it seems correct to me.
In order to rule out the case that I am using the wrong implementation
I have uploaded the source code on github (in case you would like
to take a look at it).

Your answers seem to suggest that I am using the wrong test data. I will look into it and try out different test data sets. I will report as soon as I have some results.

答:
Your result is most definitely not expected. In fact, quicksort is used because it tends to be quite a bit faster than mergesort in the average case, i.e. if quicksort doesn't degenerate due to badly chosen pivot elements.

This caveat also hints towards the first thing you should try: choose the pivot element for quicksort randomly, thereby eliminating problems with (partially) presorted data. "tuned" quicksorts will even choose 3 or 5 random elements and take the median for the early runs, since the choice of pivot has a disproportional impact there.

And of course it could be that your implementation of quicksort is simply flawed (it's more difficult to implement really correctly than it sounds).


答:
To try to put this in perspective, let's consider what you can expect from the standard library. To get an idea, I wrote this in C++:

```<code>#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <string>
#include <time.h>

std::string gen_random() {
    size_t len = rand() % 25 + 5;

    std::string x;

    std::generate_n(std::back_inserter(x), len, rand);
    return x;
}

static const int num = 10000000;

int main(){
    std::vector<std::string> strings;

    std::generate_n(std::back_inserter(strings), num, gen_random);

    clock_t start = clock();
    std::sort(strings.begin(), strings.end());
    clock_t ticks = clock() - start;

    std::cout << ticks / (double)CLOCKS_PER_SEC;

    return 0;
}
</code>```

This generates and then sorts the specified number of strings (each between 5 and 30 characters long). On my machine (which is probably somewhat slower than yours) I'm getting a time of ~14 seconds for the sort, which I'd guess is implemented as an Introsort. In the normal case, I'd expect pretty much the same performance from Introsort as Quicksort.

Bottom line: the result you're getting for merge sort is fairly reasonable, but the result you're getting from Quicksort indicates that your implementation has a serious problem.

Title: Merge sort versus quick sort performance

Body:
I have implemented merge sort and quick sort using C (GCC 4.4.3 on Ubuntu 10.04 running on a 4 GB RAM laptop with an Intel DUO CPU at 2GHz) and I wanted to compare the performance of the two algorithms.

The prototypes of the sorting functions are:

```<code>void merge_sort(const char **lines, int start, int end);

void quick_sort(const char **lines, int start, int end);
</code>```

i.e. both take an array of pointers to strings and sort the elements with index i : start <= i <= end.

I have produced some files containing random strings with length on average 4.5 characters. The test files range from 100 lines to 10000000 lines.

I was a bit surprised by the results because, even though I know that merge sort has complexity O(n log(n)) while quick sort is O(n^2), I have often read that on average quick sort should be as fast as merge sort. However, my results are the following.

Up to 10000 strings, both algorithms perform equally well. For 10000 strings, both require about 0.007 seconds.

For 100000 strings, merge sort is slightly faster with 0.095 s against 0.121 s.

For 1000000 strings merge sort takes 1.287 s against 5.233 s of quick sort.

For 5000000 strings merge sort takes 7.582 s against 118.240 s of quick sort.

For 10000000 strings merge sort takes 16.305 s against 1202.918 s of quick sort.

So my question is: are my results as expected, meaning that quick sort is comparable in speed to merge sort for small inputs but, as the size of the input data grows, the fact that its complexity is quadratic will become evident?

Here is a sketch of what I did.
In the merge sort implementation, the partitioning consists in calling merge sort recursively, i.e.

```<code>merge_sort(lines, start, (start + end) / 2);
merge_sort(lines, 1 + (start + end) / 2, end);
</code>```

Merging of the two sorted sub-array is performed by reading the data from the array lines and writing it to a global temporary array of pointers (this global array is allocate only once). After each merge the pointers are copied back to the original array. So the strings are stored once but I need twice as much memory for the pointers.

For quick sort, the partition function chooses the last element of the array to sort as the pivot and scans the previous elements in one loop. After it has produced a partition of the type

```<code>start ... {elements <= pivot} ... pivotIndex ... {elements > pivot} ... end
</code>```

it calls itself recursively:

```<code>quick_sort(lines, start,          pivotIndex - 1);
quick_sort(lines, pivotIndex + 1, end);
</code>```

Note that this quick sort implementation sorts the array in-place and does not require additional memory, therefore it is more memory efficient than the merge sort implementation.

So my question is: is there a better way to implement quick sort that is worthwhile trying out? If I improve the quick sort implementation and
perform more tests on different data sets (computing the average of the running times on different data sets) can I expect a better performance
of quick sort wrt merge sort?

EDIT

Thank you for your answers.

My implementation is in-place and is based on the pseudo-code I have found
on wikipedia in Section In-place version:

```<code>function partition(array, 'left', 'right', 'pivotIndex')
</code>```

where I choose the last element in the range to be sorted as a pivot, i.e. pivotIndex := right.
I have checked the code over and over again and it seems correct to me.
In order to rule out the case that I am using the wrong implementation
I have uploaded the source code on github (in case you would like
to take a look at it).

Your answers seem to suggest that I am using the wrong test data. I will look into it and try out different test data sets. I will report as soon as I have some results.

Body:
To try to put this in perspective, let's consider what you can expect from the standard library. To get an idea, I wrote this in C++:

#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <string>
#include <time.h>

std::string gen_random() {
    size_t len = rand() % 25 + 5;

    std::string x;

    std::generate_n(std::back_inserter(x), len, rand);
    return x;
}

static const int num = 10000000;

int main(){
    std::vector<std::string> strings;

    std::generate_n(std::back_inserter(strings), num, gen_random);

    clock_t start = clock();
    std::sort(strings.begin(), strings.end());
    clock_t ticks = clock() - start;

    std::cout << ticks / (double)CLOCKS_PER_SEC;

    return 0;
}

This generates and then sorts the specified number of strings (each between 5 and 30 characters long). On my machine (which is probably somewhat slower than yours) I'm getting a time of ~14 seconds for the sort, which I'd guess is implemented as an Introsort. In the normal case, I'd expect pretty much the same performance from Introsort as Quicksort.

Bottom line: the result you're getting for merge sort is fairly reasonable, but the result you're getting from Quicksort indicates that your implementation has a serious problem.


答:
One of the best things a computer can do for the average person is save them time.  See if you can find a way to save your dad some time on something he does regularly.

Time is ALWAYS valuable.