问:
How should I host our scalable worker processes?
We are designing a new architecture for an enterprise business. The principles we've followed so far is not to develop what you can (possible buy and) deploy, ie, don't reinvent any wheels.

In this way we've decided on CQRS, RabbitMQ, Riak and a bunch of other things. We still need to write /some/ business code though and these will be in the form of worker processes, which will consume commands from a message queue and after any side-effects, produce events onto another message queue. The idea behind this is that via the competing-consumers design we will have a scalable design right out of the box.

One option is of writing a management infrastructure that will know how to:

deploy code

instantiate processes

kill processes

update configuration

etc

IE provide fault tolerance and scalability. Also, this is exactly what something like GAE and Heroku does for you, but in a public setting and in our organization, public is bad.

My question is, is there an out-of-the-box solution that we can use to host our consumers in? Like a private cloud or private platform-as-a-service. Private Heroku or GAE. Is there some kind of software or software product with which we can do all of these things and thereby get scalability and fault tolerance over our consumers?

答:
It really depends on your scaling requirements.

If you don't have excessive "quick-scale" needs (i.e. growth is small, you can predict when you will need a new box to handle load and have time to provision it), don't worry much about it. You can do pretty well with just a mechanism to provision servers automatically (e.g. Puppet), make sure all your underlying technologies are easily clustered if required, or easy to failover if they don't need to scale.

On the other hand, if that's not enough... you've got a problem. Building a true cloud is not trivial, and it requires a considerable amount of resources. There are solutions in this area- Eucalyptus and OpenStack come to mind.

Fortunately, nearly no one needs the latter. Please evaluate carefully whether you need a true cloud solution with automatic dynamic scaling- you probably don't. If you don't need it and mistakenly implement one, chances are you'll never reach your goal or you'll reach it with an incredible overhead over the non-dynamic solution.

In any case, on the more pure software-side of things, you have stuff such as Celery which implements this very nicely; writing code in a "taskful" fashion is pretty simple and painless.


问:
What's the most appropriate duration of the video tutorial?
It is now more and more popular to have video tutorials of the software or technology instead of writing long articles. As for me, it makes perfect sense, especially for such areas like "Getting Started" or "What's New".

What do you think is the most appropriate duration for such a videos? If you record the video tutorial yourself, would you just touch main points to keep it brief, or rather split it into a number of parts to keep the same level of details? And why?

I know this question isn't implied to have one and only answer. I'd like to hear the reasoning behind various opinions.

I have personally come across a video tutorial 45 minutes long today, and I got tired at around minute 10... So, my own impression is it's better to keep it from 5 to 10 minutes to gain visitor's attention fully.

Thanks!

答:
I think the lenght doesn't really matter. I often watch Google Tech Talks, which last around 45 min - 1 hour. While I often can't sit through the whole hour, every 10 or 15 min I do a little break, grab some coffee or check e-mails, then continue.
Actually, what I hate more is having to switch between videos around the same topic every 5-10 minutes.</p>

ContentLicense: CC BY-SA 2.5


问:
Is it necessary to memorize code?
I am a new developer, who just got hired at a big company.  I don't know how but I guess they are desperate.  However, I am well-versed with HTML5/CSS3 though things change and new things are released and I keep up with as much as I can.  But this job required me to hand-code Javascript, know Jquery and Ajax.  I have been exposed to this a bit but I am not sure if I can hand-code Javascript.

My question is, is it necessary to memorize all there is about Javascript or are there a few key things that I should know how to hand-code because looking at javascript code it seems there are lots of lines code!

Please point me in the right direction.

答:
The most important thing you need to memorize is HOW to solve a problem and not WHAT to write. If you know how to solve problems, you can apply that knowledge in any language and technology.

I think memorizing code is just waste of time. You will forget it anyway if you don't use it properly. What comes to the essential things, as ThiefMaster said, with time you will memorize and use them automatically.

Its like that story about the fisher who can either give a single fish to a hungry man or teach him fishing. I think its definitely better to learn fishing.

ContentLicense: CC BY-SA 3.0

Title: Is it necessary to memorize code?


问:
Technology/Techniques to prevent offensive images on a website
I am planing to build a website which one of its main features is the usage of pictures. I was wondering what existing techniques are used to prevent offensive pictures (i.e pornography) to get loaded by users. i.e What does Facebook or Pinterest use?

As well I would like to know what your recommendations would be to control offensive pictures to get uploaded to the site (OpenSource tools maybe..) Taking into consideration this is a personal project and will be developed with a very small budget.

Thank you

答:
Some attempts at this exist as a concept against specific kinds of offensive based on edge detection.  I have seen research papers on it, but as a practical matter whatever you would be "detecting" would easily be gameable by tinting or anything that breaks up the obvious outlines of the objects.

Even if you could get a working implementation of this the internet would just upload you some smut with WWII navy style dazzle paint on the performers or performers in ghillie suits just to be difficult.

If you don't mean offensive as smut but as violent or off-color I don't even think you could come up with an automated way to rate it even if you had a perfect image detection process just due to the problem of nobody agrees when it crosses the line.


问:
How would one build a relational database on a key-value store, a-la Berkeley DB's SQL interface?
I've been checking out Berkeley DB and was impressed to find that it supported a SQL interface that is "nearly identical" to SQLite.

http://docs.oracle.com/cd/E17076_02/html/bdb-sql/dbsqlbasics.html#identicalusage

I'm very curious, at a high-level, how this kind of interface might have been architected. For instance:

since values are "transparent", how do you efficiently query and sort by value

how are limits and offsets performed efficiently on large result sets

how would the keys be structured and serialized for good average-case performance

答:
Berkeley DBs are not that distant from SQL databases. For instance, ISAM systems (which are similar to Berkeley DB) have been used to build relational databases (for instance, MySQL's MyISAM storage backend, warts et al.).

Basically, a Berkeley DB can store table rows. You can use Berkeley DB indexing to implement relational indexes on the stored rows- limit and offsets are implemented easily on top of that. Serialization is not a great concern (it is insignificant compared to IO).

The big difficulty is implementing joins and a decent query planner- the query planner is a crucial part of a relational database- it analyzes a query and decides how should it be executed; which tables need to be queried, in which order and using what indexes- and then the query needs to be executed in an efficient fashion (a naive approach will probably choke on the first join on two large tables- the naive approach is to materialize the full outer join, and that can have an untractable amount of rows). It doesn't sound like something very difficult, but there are lots of combinations and finding the best combination is difficult- and the different between the best combination and a "decent" one can be enormous.


问:
Parameterized Django models
In principle, a single Django application can be reused in two or more projects, providing functionality relevent to both. That implies that the same database structure (tables and relations) will be re-created identically in different databases, and most times this is not a problem (assuming the projects/databases are unrelated - for instance when someone downloads a complete app to use in their own projects).

Sometimes, however, the models must be "tweaked" a little to better fit the problem needs. This can be accomplished by forking the app, but I wondered if there wouldn't be a better option in cases where the app designer can anticipate the most common customizations.

For instance, if I have a model that could relate to another as one-to-one or one-to-many, I could specify the unique property as a parameter, that can be specified in the project's settings:

```<code>class This(models.Model):
    other = models.ForeignKey(Other, unique=settings.OTHER_TO_THIS)
</code>```

Or if a model can relate to many others, I could create an intermediate table for each of them (thus enforcing referential integrity) instead of using generic fks:

```<code>for related in settings.MODELS_RELATED_TO_OTHER:
    model_name = '%s_Other' % related
    globals()[model_name] = type(model_name, (models.Model,) {
        me:models.ForeignKey(find_model_class(related)),
        other:models.ForeignKey(Other),
        # Some other properties all intersection tables must have
    })
</code>```

Etc. Let me stress out that I'm not proposing to change the models at runtime nor anything like that; once the parameters were defined and syncdb called for the first time, those parameters are not to be changed again (unless you're doing a schema migration).

Is this a good design? Are there better ways to accomplish the same thing, or maybe drawbacks I coulnd't anticipate? This technique is meant to be used sparingly (only on apps meant to be reused in wildly different contexts, and only when a specific need of customization can be detected while the app model is being designed).

答:
I'm thinking the models should be abstract and users of the library should extend them into concrete classes which relate to their specific classes.

If some relationship needs to have different cardinality, you can handle that using model inheritance- have a base class which does not define the relationship and which has template methods for the code involved in the relationship and have subclasses define the different cardinality and implement the template methods. Unless you have lots of different variations within the same class (which doesn't seem like a common thing to me), this should work.

If this doesn't suit your requeriments, yea, you might have to build your models programatically, sounds doable but complex.

As a final comment, stay away from generic foreign keys. They might work somewhat if you never stray out of Django, but...

Title: Parameterized Django models


答:
Today, in our work as in our life, it is more important know how to find information rather than know the information itself. I mean that a good developer is a person able to find documentation, network, and that share with an open mind.

I am an experienced .NET developer and, believe me, for every project I work on I have to learn new things about the language and development environment. Our work is always more intricate so do not worry. Point your attention at problem solving and then look for help. All the solutions already exist; we must be able to find them.

Title: Is it necessary to memorize code?

Body:
I am a new developer, who just got hired at a big company.  I don't know how but I guess they are desperate.  However, I am well-versed with HTML5/CSS3 though things change and new things are released and I keep up with as much as I can.  But this job required me to hand-code Javascript, know Jquery and Ajax.  I have been exposed to this a bit but I am not sure if I can hand-code Javascript.

My question is, is it necessary to memorize all there is about Javascript or are there a few key things that I should know how to hand-code because looking at javascript code it seems there are lots of lines code!

Please point me in the right direction.


问:
GCC: assembly listing for IA64 without an Itanium machine
I need to try the following thing: I would like to compile some simple C code samples and see the assembly listing generated by GCC for IA64 architecture, i.e. I just want to run GCC with the -S switch and see the resultant .s file. I don't have an Itanium machine, so in order to do it myself I'll probably need a cross-compiling version of GCC built for x86 RedHat. I'm not interested in full cross-compilation, meaning that I don't need to generate the binaries at all.

The easiest way, of course, would be to find an Itanium machine with with GCC and just try it there. Unfortunately, I don't seem to have access to any. Another option is to build a cross-compiling version GCC on my RedHat, but apparently that's quite an endeavor for someone who hasn't done it before (I assume that the fact that I only need .s output doesn't make it simpler).

What other options are there, if any? Maybe there's some sort of a web front to an Itanium GCC compiler on the Net (something like Comeau Online or ideone.com, but with .s output)? Anything else? I would appreciate any help.

答: I believe VS2010 Ultimate comes with an IA64 compiler (you might have to install the Windows SDK).  It might be marginally easier than building the GCC toolchain (although I did this for the MSP430 on a Linux box and it wasn't too painful).</p>


答:
First, don't put yourself down. Unless you completely misrepresented your skillset and lied in the interview, you have something that they deem of value. You impressed them enough to get the job, and that's no small feat these days.

Second, I would concentrate on learning programming structures primarily, and how they would be implemented in javascript. A for next loop is a for next loop is a for next loop, etc. the only different is whether it's for x := 1 to 30, or for (i = 0; i < 30, i++) or some other thing.

Once you know the core concepts, you can apply those in just about any programming language with a little bit of tweaking, and you will start learning how to apply shortcuts, more esoteric solutions.

Then, somewhere down the line the company will say "We need someone to do X", and you can say "I can do that."

Title: Is it necessary to memorize code?


问:
How to choose a server side language / framework
I am trying to come up with a list / ranking system on determining which server language to choose for a particular website.  Assume that familiarity  with a certain language is not important and the implementation can be done in any language.   Here are some things that might be important but I am not sure how to rank them :

Maintainability.

Libraries.

For example, Memcached and NoSql support right out the box would be really nice addition to a particular framework.

3rd party SDK's.

For example, if I need Paypal on my site they openly provide SDK's for all senarios in Java, PHP and .Net.  If I choose Django I would have to rely on 3rd party libraries that are don't support everything and are not officially maintained.   Would that be dealbreaker for Django?

Performance

This one is tricky to put on a generic list because it can be a deal breaker but for many websites performance will not be an issue that the language/framework is responsible for.

Cost (hosting, open source).

edit -
Any reason for the votes to close?  I didn't see any duplicates mentioned and the question should not drum up a flame war.

答:
The question really depends on the type of site you are going to build, especialy on the complexity of the buisness logic and data (and the size of the data).

IMHO there are 3 major cases:

a) Small or Small->Medium

Interpreted language - Python using Django, PHP using Zend or Ruby using Rails.

Pro: This offers the best productivity, that is you can obtain a functional product very fast.

Con: The problem with this is the limited logic that can be applied on the data scalability and performance problems.

b) Medium

C# using .NET

Pro: Advantage in performance and security over the previous due to a compiled and typed language; also lots of advantages from Microsoft Visual Studio which automates very much, from deploying into cloud to object-relational mapping.

Con: Closed source, costs, Windows bounded;

c) Medium or Large - where middleware has a purpose of existence

Java using JSF, Struts or Spring MVC

Pro: Designed for scalability and platform independence; has many open source frameworks//APIs for many things (from Spring MVC as a web frameworks to Hadoop for distributed computing or JMS for middleware communication)

Con: Kind of complex

And now to argument my opinion why I believe Java is suitable for large applications while .NET is not. A large application is likely to be complex so it needs to be flexible and customizable; the technology for Java is mostly open source (and directly customizable) while most of the technology for .NET costs money and closed source. I also mentioned that .NET is good for the automizations that come with VS; but the problem with this automatizations is that it does not build flexible and elegant code. This kind of code is needed to be written by a real programmer; so the money paid for VS and other MS technologies are not worth to be paid for since the application is to be flexible and the code still needs to be written by real programmer. You can actually write complex applications using C#, it's just not profitable. And Java has also the advantage of platform independence.

Just a subjective opinion.

I sugest you choose something from the first category, since probably you are not speaking for a large enough organization so you have the money for Microsoft technology or for the manpower necesary for a complex Java application.


问:
Do Java applets have any place on the web today?
Many browsers now disable Java applets by default, requiring them to be enabled on a per-page basis. It seems like applets have not changed much in the past few years. In fact, it seems that client-side Java (applets, desktop applications, ...) is dying completely, and Java is primarily becoming a server-side language.

Except for the sake of compatibility, is there any place where applets are still useful on today's web? As a web developer who is familiar with Java and with JavaScript, why would I ever choose to use an applet instead of some JavaScript?

答:
all Java apps requires third party software to work which has to be updated for security reasons very rapidly, each time download is huge and you need to restart browser many times it causes the browser to hang. I used to think java software is must for best experience but then after being tired of all this trouble just removed it. I cannot recall using any Java apps anyway. IMHO Java only useful for some dumb online games.

Long life PHP and other web based stuff that dont make my system slow for no reason.

Besides OP "The JavaScript programming language, developed by Netscape, Inc., is not part of the Java platform."
Source http://www.java.com/en/download/faq/java_javascript.xml


答:
No, not much.

It might be useful if you don't want to use Flash (i.e. you don't have Flash knowledge and learning it is not worth it because you need to develop just a simple component and your users have Java installed) and need to do stuff which is not widespreadly supported by browsers (i.e. local filesystem access), or you have a significant amount of Java code you can reuse.

Really, with today's processors and RAM, Java is no longer that heavyweight (the F1 live timing app starts reasonably quickly on my Atom netbook, and there are certainly Flash apps which choke more my CPU), upgrades are differential IIRC and the initial install under today's network connections is a shade of what it was back in the day, but still, applets are not the answer to many questions.

Webstart, on the other hand... :-p

Title: Do Java applets have any place on the web today?

Body:
Many browsers now disable Java applets by default, requiring them to be enabled on a per-page basis. It seems like applets have not changed much in the past few years. In fact, it seems that client-side Java (applets, desktop applications, ...) is dying completely, and Java is primarily becoming a server-side language.

Except for the sake of compatibility, is there any place where applets are still useful on today's web? As a web developer who is familiar with Java and with JavaScript, why would I ever choose to use an applet instead of some JavaScript?


问:
Should i expect real world questions from interviewing agency?
I started coding almost a year ago. By "coding" I mean HTML(5), CSS(3), and only few times I implemented some AJAX and JavaScript.  I am interviewing for a position that expects me to know HTML, CSS, JS, JQuery, and AJAX. I feel confident in HTML5/CSS3 subject area and somewhat ok with javascript.

Will agency expect from me to write some code during the interview? I do have a live website as an example which contains snapshots of past projects which were sent to them.

I am little nervous, so any tips or recommendations are welcome.

答:
If i go for an interview, will they expect me to write code during the interview?

Maybe, maybe not.

It entirely depends on who is interviewing you. If it is a place that values good technical people, I would expect some code writing to be part of the interview.

This is more to see that you can do what you say you can and to see how you approach a coding problem.


答:
From personal experience, I have always written some code during an interview.  Mostly it is in the form of fizzbuzz type questions, but I was once asked to write a fairly lengthy piece of code (they allotted for 45 minutes and I didn't even finish in that length).

But they rarely want to see perfection, it's usually more about your thought process and if you can back up what you claim you know.

My advice, always go into a programming interview expecting to write some code.  If you don't have to, great.  But if you do, at least you'll be prepared. Also, as Andrew Finnell pointed out, in his comment, do not rely on an IDE, intellisence, etc.  There's no guarantee that you'll do the test in front of a computer.  I had to do FizzBuzz on the wall with a dry-erase marker (the walls were painted with whiteboard paint :) )

I would be a little worried if they didn't ask you to write some code.  That may be an indication that they don't value talent (or their people in general) and there's no telling who you may have to work with or what conditions you may have to work under.

For practice, try finding a site, such as Project Euler, that provides you with simple tests that you can answer in the language of your choice.  Then practice by going through the tests in the language that you will be using in the interview.

Title: Should i expect real world questions from interviewing agency?

Body:
I started coding almost a year ago. By "coding" I mean HTML(5), CSS(3), and only few times I implemented some AJAX and JavaScript.  I am interviewing for a position that expects me to know HTML, CSS, JS, JQuery, and AJAX. I feel confident in HTML5/CSS3 subject area and somewhat ok with javascript.

Will agency expect from me to write some code during the interview? I do have a live website as an example which contains snapshots of past projects which were sent to them.

I am little nervous, so any tips or recommendations are welcome.


答:
It all comes back to pattern recognition.  The reason we have facial recognition software is faces, for the most part, have similar traits, and most of the pictures we take of people have them facing the camera.  But that was still very difficult to develop.  Let us consider for a moment a picture of bomb striking a populated target.  How would you create a pattern for that?  The picture would have an explosion, fairly simple for a human to figure out, but rather hard to program for.  An explosion could be of various sizes, shapes and colors.  Let's say you create some sort of rule based system.  What if the picture is an explosion for avalanche control in the mountains?  That is not violent or offensive, but it would contain a lot of the same characteristics.

As many other people have pointed out, it is very hard to define obscene.  The US Supreme Court attempted to in the case of Miller vs. California, and as a result we have the so called Miller Test which consists of three parts:

Whether "the average person, applying contemporary community
standards", would find that the work, taken as a whole, appeals to
the prurient interest,

Whether the work depicts/describes, in a patently offensive way,
sexual conduct specifically defined by applicable state law,

Whether the work, taken as a whole, lacks serious literary, artistic,
political or scientific value

Nice and ambiguous, makes things a little hard to program for.  Most sites that allow you to upload images have some sort of human moderation.  For example, all pictures posted to online dating sites have to follow a set of rules and have to be approved manually.

Title: Technology/Techniques to prevent offensive images on a website

Body:
I am planing to build a website which one of its main features is the usage of pictures. I was wondering what existing techniques are used to prevent offensive pictures (i.e pornography) to get loaded by users. i.e What does Facebook or Pinterest use?

As well I would like to know what your recommendations would be to control offensive pictures to get uploaded to the site (OpenSource tools maybe..) Taking into consideration this is a personal project and will be developed with a very small budget.

Thank you


问:
Making Separate Assemblies For Different Types Of Tests For The Same Component?
I was told by a few members here that splitting up my unit tests into different assemblies for different components is the best way to structure unit tests.  Now, I have a few questions about that idea.

What are the advantages of this? Organization, and isolation of errors?

Let's say I have a component named "calculator", and I create an assembly for the unit tests on "calculator".  Would I create a separate assembly for the integration tests I want to run on "calculator"? Or is the definition of an integration test a test across multiple components, like "calculator" and whatever else, which would require a separate assembly to test both of them together? In that case, would I have one assembly to do all of the integration testing for every component combination?

答:
Answer to a similar question:

In my opinion, unit tests should be placed in a separate assembly from
  production code. Here are just a few cons of placing unit tests in the
  same assembly or assemblies as production code are:

Unit tests get shipped with production code. The only thing shipped
  with product code is production code. Assemblies will be unnecessarily
  bloated by unit tests. Unit tests can affect build processes like
  automated or continuous build. I don't really know of any pros. Having
  an extra project (or 10) isn't a con.

Edit: More Info On Build and Shipping

I would further recommend that any automated build process place
  production and unit tests into different locations. Ideally, the unit
  test build process only runs if the production code builds, and copies
  the product files into the unit tests directory. Doing it this way
  results in the actual bits being separated for shipping, etc.
  Additionally, it is fairly trivial to run automated unit testing at
  this point on all tests in a particular directory.


答:
For mature and active language + platform combinations, I'd recommend sticking with Java + Spring or GWT, .NET, Ruby on Rails, or Python + Django.  You can also go client-heavy with e.g. JavaScript + Ext and have a potentially very thin REST over JSON back end; that's a very different architectural style.  JavaScript + Node.js is a platform to watch and may be appropriate for smaller or bleeding-edge projects.

Beyond the language, for scalability you also may want to look at cloud platforms which can be orthogonal to the answers so far (including your answer in your question).  Those influence the language (Scala?) but also application architecture, potentially in a massive way.  Consider Google App Engine (Java, Python), Amazon EC2, Heroku (Ruby), Oracle cloud, Microsoft...  Where do you want to host this thing, and how much IT do you want to do?  These days you can outsource your whole development environment to somewhere like CloudBees or Cloud9.

Title: How to choose a server side language / framework

Body:
I am trying to come up with a list / ranking system on determining which server language to choose for a particular website.  Assume that familiarity  with a certain language is not important and the implementation can be done in any language.   Here are some things that might be important but I am not sure how to rank them :

Maintainability.

Libraries.

For example, Memcached and NoSql support right out the box would be really nice addition to a particular framework.

3rd party SDK's.

For example, if I need Paypal on my site they openly provide SDK's for all senarios in Java, PHP and .Net.  If I choose Django I would have to rely on 3rd party libraries that are don't support everything and are not officially maintained.   Would that be dealbreaker for Django?

Performance

This one is tricky to put on a generic list because it can be a deal breaker but for many websites performance will not be an issue that the language/framework is responsible for.

Cost (hosting, open source).

edit -
Any reason for the votes to close?  I didn't see any duplicates mentioned and the question should not drum up a flame war.


答:
I would go in expecting to write some code, so bone up on the languages and libraries they use, but don't worry too much about not knowing exact syntax off the top of your head. When you're not sure of some method name or syntax, just write the code as well as you can remember.

There is some value for an interviewer in identifying how familiar an applicant is with a particular language or feature, since in general, the more familiar they are, the more productive they can be.

For the most part though, familiarity with a particular language shouldn't be a big factor in a hiring decision, since it's more important to hire someone who is good at breaking down and solving problems than someone who has memorized an API.


答:
As others have pointed out there are some technological solutions but they only get you so far. This article from the NY Times discusses how large sites (like Facebook) filter content.

To answer your question: "What does Facebook or Pinterest use?"

People.


问:
flat files vs. RDBMS database, few read/writes, few changes
I have to handle data from long term (years, decades) climate monitoring stations. The data flow usually starts with raw data (voltages, etc.) plus quality check information (pressure, temperature, flow rate, etc.) generally recorded @ 1Hz. Then, the data are assigned a quality flag (human and/or program), processed (apply calibration curves) and flagged.

So, we basically end up with 2 datasets : raw and processed data. New data are typically added once a day (~500Ko/day/instrument). Simultaneous queries are not likely to ever happen.

I wanted to go for a RDBMS (we have a MySQL server) and have some experience in database design, but the IT guy keeps telling me that flat files will to the job just as well. I suspect him to try to make his life easier when it comes to backup/upgrade the MySQL.

There are not so many links between data, they don't change much, but the quality flags will change. A RDBMS is easier to compare data from different instruments on a "many days" scale, compared to daily text files.

Well, what would you advise ?

Thanks.

答:
Some of my co-workers use flat files and transfer processed data to a huge single MySQL table. Reprocessing is sometimes necessary and it is a hassle. Personally, I think it's really dirty, and they miss the beauty of RDBMS... So, I consider we are pretty much starting from scratch.

Alternatively, the IT guy proposed me to use the RDBMS to store meta data : where is what, and what is available for a given date. How about that ?

GrandmasterB : do you suggest to create a temporary database, for the lifetime of a processing run ?

kmote : your arguments about the learning curve and management consideration are interesting. I guess I can provide basic SQL queries or scripts, and who wants more will learn SQL. But I think I should anticipate and choose a reliable system ASAP. The later the change, the harder...

Another thing : RDBMS is attractive and elegant, but the initial design amount of work is quite big.

OwnerDisplayName: Bob Lapique


答:
There are so many options and so many "cost comparisons" involved you're going to have to ensure careful examination of the entire gamut of costs

You can either sign up for a startup program with Microsofts BizSpark and they'll give you everything for free for a few years (3). they do have express editions which you can download and deploy. Amazons cloud services all have a "FREE" tier, which are pretty nifty for getting something off the ground and offer all kinds of configurations.. etc.. technology will most likely be determined with initial budget allotments and who your developers are.

HOWEVER, technology costs and assumptions are only a small part of the equation. Development costs, implementation costs and maintenance costs are all going to vary depending on which platform you choose. Some get you off the ground quicker, but customization will hinder continued rapid growth, others will give you nothing up front, and will require a master dev to develop appropriately, however the ongoing costs could be minimal if designed correctly..

Then you have to be careful on scalability.. when your site becomes successful, is the platform going to scale? are there any costs associated with scaling that you have to be aware of.. will you need to deploy a new webserver, purchase new hardware? or can you just pay for an increased "instance" bandwidth?

Then the logistics of the matter.. are you hosting yourself? what about disaster recovery and CDN delivery systems to ensure rapid response times?

So you're just barely scratching the surface with those questions.. the server-side language choice will definitely push you in certain directions, however, you can host C# on Apache (mono), and you can host PHP on IIS..

you can plug in some NoSQL databases into just about any codebase, so that's going to be a preference.. is Reporting important?

the questions and implications go on and on.. I would say before going any further..

```<code>What are the requirements for your website?

-what's your budget now and ongoing?
-high traffic?
-mostly reads or lots of updates?
-how important is data integrity (banking precise?)
-reporting?
</code>```

...too many to list..

Body:
There are so many options and so many "cost comparisons" involved you're going to have to ensure careful examination of the entire gamut of costs

You can either sign up for a startup program with Microsofts BizSpark and they'll give you everything for free for a few years (3). they do have express editions which you can download and deploy. Amazons cloud services all have a "FREE" tier, which are pretty nifty for getting something off the ground and offer all kinds of configurations.. etc.. technology will most likely be determined with initial budget allotments and who your developers are.

HOWEVER, technology costs and assumptions are only a small part of the equation. Development costs, implementation costs and maintenance costs are all going to vary depending on which platform you choose. Some get you off the ground quicker, but customization will hinder continued rapid growth, others will give you nothing up front, and will require a master dev to develop appropriately, however the ongoing costs could be minimal if designed correctly..

Then you have to be careful on scalability.. when your site becomes successful, is the platform going to scale? are there any costs associated with scaling that you have to be aware of.. will you need to deploy a new webserver, purchase new hardware? or can you just pay for an increased "instance" bandwidth?

Then the logistics of the matter.. are you hosting yourself? what about disaster recovery and CDN delivery systems to ensure rapid response times?

So you're just barely scratching the surface with those questions.. the server-side language choice will definitely push you in certain directions, however, you can host C# on Apache (mono), and you can host PHP on IIS..

you can plug in some NoSQL databases into just about any codebase, so that's going to be a preference.. is Reporting important?

the questions and implications go on and on.. I would say before going any further..

What are the requirements for your website?

-what's your budget now and ongoing?
-high traffic?
-mostly reads or lots of updates?
-how important is data integrity (banking precise?)
-reporting?

...too many to list..


答:
This should be a comment, but I can't do that yet.

You may not be asked to write code, but you may be asked to look at a piece of code and explain what it does. You'd be surprised how many people just look at something like that and immediately say "Beats me", or "I can't do that". I got my first job because I was one of the few who looked at a language I'd never seen and said "Well, I think this does this and this over here does that".

One of the questions that I throw at interviewees is before the interview when they are filling out information, is I ask them to explain in detail how to fix an egg. Or how to change a light bulb. I could care less about what the answer is, what I'm looking for is the detail approach. For example, if I am asking them to change a light bulb, I want them to consider things like ceiling height to get an appropriate ladder, bulb wattage, how to remove the light cover, down to the proper disposal of the bulb and cleanup of the leftover packaging. The last interviewee that I hired did nearly two pages on changing a lightbulb.

Also, while you may not be able to code in it, at least be prepared to discuss it intelligently. Know what AJAX actually stands for, etc. Don't lie about your qualifications, but if they ask about it, say "I haven't done this specifically, but I've done that which will translate over".

Be honest, relaxed and confident. That speaks more than you know. (Ok, maybe that was a bit more than a comment.)


答:
Applets are still useful in some circumstances - they are an easy way to embed small Java programs in web pages that might well make sense in the following circumstances:

You have Java Swing or AWT skills and don't want to learn yet another language / GUI framework

You don't particularly care if the some users get an applet warning

But nowadays anyone wanting to develop this kind of application in Java would probably use either:

A proper Java client-side application launched through WebStart

JavaFX 2.x - for rich media applications


问:
Version control implementation advice on legacy websites?
Assuming no experience with version control systems, just local to live web development. I've been dropped in on a few legacy website projects, and want an easier and more robust way to be able to quickly push and revert changes en masse. I'm currently the only developer on these projects, but more may be added in the future and I think it would be beneficial to set up a system that others can use.</p>

答:
Joel Spolsky wrote a nice Mercurial tutorial:

http://hginit.com/

And it does not really matter if you are going to apply version control to a legacy website or the source code of an arbitrary program.


问:
Should I use a relational datamodel or Cassandra with ColumnFamily based indexes?
Currently we are working on some storage problems for log data from various servers and communication message logs (HTTP(S), XMPP). There will be many write operations and for read operations we will use search queries with filters.

Should we stick with the classic relation database schema solution or concentrate on Cassandra with ColumnFamily based indexes?

答: If all you're going to be doing is searching the records once they're stored, then I don't think there's going to be much difference.  If you need to re-process them (or a large chunk thereof) they you might see some advantage from the NoSQL approach.  If you know what fields you're going to be searching on, I'd recommend compressing the data into a BLOB and storing that along with the searchable fields in a relational table, in order to cut down on your storage requirements (I don't know if that's possible with Cassandra).</p>


问:
How compilers know about other classes and their properties?
I'm writing my first programming language that is object orientated and so far so good with create a single 'class'.  But, let's say I want to have to classes, say ClassA and ClassB. Provided these two have nothing to do with each other then all is good. However, say ClassA creates a ClassB--this poses 2 related questions:

-How would the compiler know when compiling ClassA that ClassB even exists, and, if it does, how does it know it's properties?

My thoughts thus far had been: instead of compiling each class at a time (i.e scan, parse and generate code) each "file (not really file, per se, but a "class") do I need to scan + parse each first, then generate code for all?

答:
Different languages (and thus compilers) approach this differently.

In the C family, the different modules have a corresponding header file that is used while building the object.  The header files provide information on the size of the object and what functions or methods exists that may be invoked.  This allows for the necessary information for memory allocation and "does that method/function/procedure exist?" that is used when doing compilation of a single unit that doesn't need to have access to the source itself.

In Java, the compiler is aware of things on its classpath and inspects those object to link against them (verifying that methods exists, have the right number of arguments, etc...).  Java may also link dynamically at runtime loading in other classes that it doesn't know anything about when it was compiled.  See Class.forName for one example of dynamic loading.

Both options are quite valid and have their own set of advantages and disadvantages.  Providing header files some see as cumbersome and violating DRY.  On the other hand, if you don't have header files libraries need to be inspectable by the compiler and linker - a .so or .dll likely won't have enough information in it to properly instantiate the objects or validate the method calls (and would be machine dependent).


问:
Efficient way to compare scene-graph trees
I'm designing a scene graph system, where it is required to compare two trees. The trees are populated with individual objects, each with varied number of children; and they have a root.

Eg: Parent: Scene, Children: Bullet1, Bullet 2, Player

What is a good way to compare two such tree? I'm using C++ for the code.

Also, this question is an off-shoot from this question

答:
Depends rather what you mean by "compare", but if you can (effectively) serialize your trees (or at least the properties of them you care about) to strings then the "Levenshtein distance" (or some other related "edit distance" or "string metric") between a pair of strings ought to tell you something useful about the similarities between them.

You can also have some fun with compression-based similarity metrics: if strings A and B compress to size a and b, but compressing the file C created by concatenating A and B compresses to size c, then c/(a+b) tells you something about how much duplicate information there was in the two files: the nearer to 1.0, the less benefit there was from compressing the files together and so the less similar they are (subject to caveats re file size and the maximum window your compressor works over anyway).  Think this sort of approach is used by bioinformatics people but with it's information theoretic roots it ought to be more generally applicable.


答:
Not sure about agency, but your potential interviewer may ask you to write some code/pseudo code on a white board or paper. They might be interested to know how good you understand your primary development language without IDE and intellisense tools (Visual Studio, Eclipse, etc.)

Most important thing is just train yourself to be cool and calm, no panic. If you forget some technical details, just explain it in your own words. Bottom line - your potential employer wants to see how you solve problems and what is your approach and reasoning.


问:
How do you handle measuring Code Coverage in JavaScript
In order to measure Code Coverage for JavaScript unit tests, one needs to instrument the code, run the tests and then perform post-processing.

My concern is that, as a result, you are unit testing code that will never be run in production. Since JavaScript isn't compiled, what you test should be precisely what you execute.

So here's my question, how do you handle this? One thought I had was to run Unit Testing on the production code and use that for my pass fail. I would then create a shadow of my production code, with instrumentation and run my unit tests again; this would give me my code coverage stats.

Has anyone come across a method that is a little more graceful than this?

EDIT
I don't want to use browser plugins, because I then need to use a browser in order to run my unit tests.

答:
Read this on code-coverage tools for JavaScript, which has some links, though most are indeed browser extensions.

However, do consider JsTestDriver, which has code coverage support and allows for testing outside of the browser by connecting with another test tool (like HtmlUnit).


问:
Licensing a JavaScript library
I am developing a free, open-source (duh) JavaScript library, and wondering how to license it.

I was considering the GNU GPL, but I heard that I must distribute the license with the software, and I'm not sure anymore.

I would like the library to be available much like jQuery: In a free, downloadable script, preferably in either original or minified form. Am I mistaken about the GNU GPL license terms? jQuery is dual licensed under GNU GPL or MIT licenses.

How does the GPL apply to single script files like that? Can I license my library with nothing more than a few sentences in the script file? Is there another license that better suits my needs?

What would be nice is a license that allows you to put the URL in the source, for people to read if they want. I don't know that many do, unless I am mistaken.

I am generally looking to release the library as free software like the GPL specifies, but don't want to have to force licensees to download the full license unless they wish to read it.

答:
Don't overthink this.

The license file is small.  Even the GPL is only 34KB, and it's the largest of the F/OSS licenses.  ZIPped, that's only 13KB.  Whoever uses your library will only download it once.  They don't need to feed the license to browsers that their users use, so the bandwidth is only consumed once per download, not on every use.

Title: Licensing a JavaScript library


问:
Understanding hand written lexers
I am going to make a compiler for C and looking up on how compilers work on Wikipedia has told me a lot. However, after reading up on lexers has confused me. The Wikipedia page states that:

the GNU Compiler Collection (gcc) uses hand-written lexers

I have tried googling what a hand written lexer and have come up with nothing except for "making a flowchart that describes how it should function", however, isn't that how all software development should be done?

So my question is: "What is a hand written lexer?"

答: It's a lexer written by a human instead of generated from a series of regular expressions, like those usually expressed in lex (a lexer generator). </p>

ContentLicense: CC BY-SA 4.0

Title: Understanding hand written lexers


答:
A hand-written lexer is a lexer that was written (and fine-tuned) by an actual person, as opposed to being automatically generated from a formal definition by a tool such as LEX.

They're really not that hard to create, TBH.  Creating a parser is a lot trickier, but any programmer with a decent background in the theory involved should be able to write up a lexer by hand in a couple hours, tops.

Title: Understanding hand written lexers

Body:
I am going to make a compiler for C and looking up on how compilers work on Wikipedia has told me a lot. However, after reading up on lexers has confused me. The Wikipedia page states that:

the GNU Compiler Collection (gcc) uses hand-written lexers

I have tried googling what a hand written lexer and have come up with nothing except for "making a flowchart that describes how it should function", however, isn't that how all software development should be done?

So my question is: "What is a hand written lexer?"


答: Oftentimes programs such a flex or bison are used to automatically generate the code for the lexer from the grammar of the language. In the handwritten case, these were not used and it was all written manually.</p>

Title: Understanding hand written lexers


问:
What's your strongest opinion against functional programming?
Functional programming is one of the oldest programming paradigms. However it isn't used much in the industry compared to more popular paradigms. But it have largely been emphasized in academia.

What's your strongest opinion against functional programming?

答:
first of all i don't accept any of the arguments regarding state-ful programming and fp. look into the State monad in haskell and you will find a number of interesting new ways to assess the impact of state on your code.

if i was to make a meaningful argument against fp, it would be that learning a serious functional language like haskell is like learning to drive a formula one car....exhilarating and educational, but sadly useless for everyday industrial coding because, on average, your coworkers are driving camrys and are quite happy to do so. it is still extremely difficult to find work in an fp-friendly environment, and i don't see this changing unless one is willing to strike out on their own or seek out some of the well-known practitioners of fp.

i suppose my answer shows me up as a fp fanboy. i suggest giving a real fp language like haskell a serious spin before worrying about finding reasons why you shouldn't.


答:
Keep it Simple

Use the MIT/X11 License.

open and permissible,

no-brainer / simple,

allows both free and commercial re-use,

short,

clearly gives you copyright,

well-known and widely used.

I rarely recommend anything else if I don't have a specific reason or am not bound by another license.

Copyright (C)

Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Or Just Hyper-Link It...

Many JavaScript libraries simply provide:

a copyright notice,

and a URL of a publicly hosted verbatim of the license.

This can be an alternative, which allows you to have still a very clear license and keep it short.

IANAL Disclaimer

Though, IANAL and I'm not entirely sure this hyper-link theory really holds, as links are not really perennial resources (though you might argue you could try to prove what they pointed to or contained at a time T).

Laws regulating software, both national or international, are pretty much still in their infancy. This is all rather gray. So you could just go with it, as for now it's a bit obscure what flies and what doesn't.

Title: Licensing a JavaScript library

Body:
I am developing a free, open-source (duh) JavaScript library, and wondering how to license it.

I was considering the GNU GPL, but I heard that I must distribute the license with the software, and I'm not sure anymore.

I would like the library to be available much like jQuery: In a free, downloadable script, preferably in either original or minified form. Am I mistaken about the GNU GPL license terms? jQuery is dual licensed under GNU GPL or MIT licenses.

How does the GPL apply to single script files like that? Can I license my library with nothing more than a few sentences in the script file? Is there another license that better suits my needs?

What would be nice is a license that allows you to put the URL in the source, for people to read if they want. I don't know that many do, unless I am mistaken.

I am generally looking to release the library as free software like the GPL specifies, but don't want to have to force licensees to download the full license unless they wish to read it.


答:
We started asking interviewees to write code on a white board because as my manager said "You can't BS your way through it."  Any flaw that you have as a programmer will come to light fairly quickly.  And while syntax is important, we also look at how well the interviewees follow directions and are able to think on their feet.

Also, be prepared to talk about your previous projects, not enough detail to reveal trade secrets, but enough to talk about some of the more technical challenges you had to overcome and how you overcame it.  For example, let's say for a second you used JQuery to create a modal window that when closed would use AJAX to send back information to a server and the AJAX call would error out when a certain condition was met.  Walking through that is a big help to get us a good picture of your technical skills.

Finally, if you include something in your resume be prepared to talk about it.  It is shocking the number of people who don't understand that.


问:
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.

答:
If you look at your code for swapping you:

```<code>// If current element is lower than pivot
// then swap it with the element at store_index
// and move the store_index to the right.
</code>```

But, ~50% of the time that string you just swapped needs to be moved back, which is why faster merge sorts work from both ends at the same time.

Next if you check to see if the first and last elements are the same before doing each of the recursive call you avoid wasting time calling a function only to quickly exit it.  This happens 10000000 in your final test which does add noticeable amounts of time.

Use,

if (pivot_index -1 > start)
  quick_sort(lines, start, pivot_index - 1);

if (pivot_index + 1 < end)
  quick_sort(lines, pivot_index + 1, end);

You still want an outer function to do an initial   if (start < end) but that only needs to happen once so that function can just call an unsafe version of your code without that outer comparison.

Also, picking a random pivot tends to avoid N^2 worst case results, but it's probably not a big deal with your random data set.

Finally, the hidden problem is QuickSort is comparing strings in ever smaller buckets that are ever closer together,

(Edit: So, AAAAA, AAAAB, AAAAC, AAAAD then AAAAA, AAAAB.  So, strcmp needs to step though a lot of A's before looking the useful parts of the strings.)

but with Merge sort you look at the smallest buckets first while they are vary random.  Mergsorts final passes do compare a lot of strings close to each other, but it's less of an issue then.  One way to make Quick sorts faster for strings is to compare the first digits of the outer strings and if there the same ignore them when doing the inner comparisons, but you have to be careful that all strings have enough digits that your not skipping past the null terminator.

Body:
If you look at your code for swapping you:

// If current element is lower than pivot
// then swap it with the element at store_index
// and move the store_index to the right.

But, ~50% of the time that string you just swapped needs to be moved back, which is why faster merge sorts work from both ends at the same time.

Next if you check to see if the first and last elements are the same before doing each of the recursive call you avoid wasting time calling a function only to quickly exit it.  This happens 10000000 in your final test which does add noticeable amounts of time.

Use,

if (pivot_index -1 > start)
  quick_sort(lines, start, pivot_index - 1);

if (pivot_index + 1 < end)
  quick_sort(lines, pivot_index + 1, end);

You still want an outer function to do an initial   if (start < end) but that only needs to happen once so that function can just call an unsafe version of your code without that outer comparison.

Also, picking a random pivot tends to avoid N^2 worst case results, but it's probably not a big deal with your random data set.

Finally, the hidden problem is QuickSort is comparing strings in ever smaller buckets that are ever closer together,

(Edit: So, AAAAA, AAAAB, AAAAC, AAAAD then AAAAA, AAAAB.  So, strcmp needs to step though a lot of A's before looking the useful parts of the strings.)

but with Merge sort you look at the smallest buckets first while they are vary random.  Mergsorts final passes do compare a lot of strings close to each other, but it's less of an issue then.  One way to make Quick sorts faster for strings is to compare the first digits of the outer strings and if there the same ignore them when doing the inner comparisons, but you have to be careful that all strings have enough digits that your not skipping past the null terminator.


答:
are my results as expected?

Merge sort has the following performance characteristics:

Best case: O(n log n)

Average case: O(n log n)

Worst case: O(n log n)

Quicksort has the following performance characteristics:

Best case: O(n log n)

Average case: O(n log n)

Worst case: O(n^2)

Remember: Big-O Notation states the asymptotic bounds ignoring constant factors.

Quicksort has best-case performance when the pivot elements it chooses tend evenly to partition sub-ranges. It has a worst-case quadratic performance when the the opposite holds, such as when the input is sorted in reverse, or nearly sorted in reverse. There are many varieties of quicksort and they vary, in part, in how they choose pivot elements.

Merge sort performance is much more constrained and predictable than the performance of quicksort. The price for that reliability is that the average case of merge sort is slower than the average case of quicksort because the constant factor of merge sort is larger. However, this constant factor greatly depends on the particular details of the implementation. A good merge sort implementation will have better average performance than a poor quicksort implementation.

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.


问:
Are there any good use-cases for variable variables?
Today I encountered this little PHP gem called variable variables.

```<code>$literal = "Hello";
$vv = "literal";
echo $$vv; // => prints "Hello"
</code>```

Are there actually any real use-cases for this language feature?

答:
Assuming a url of http://example.com/hello/world, and the following .htaccess:

```<code>RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?/$1 [L]
</code>```

router.php, an overly simplistic router, would be:

```<code><?php

$request = explode("/", $_SERVER["REQUEST_URI"]);

$controllerClass = $request[0];
$controllerActionMethod = $request[1];

$controller = new $controllerClass();
$controller->$controllerActionMethod(); // hello::world();

?>
</code>```

That's a pretty standard practical use of variable variables. Neat trick, but you should be extremely careful when using it, over/abusing it will certainly lead to horribly unmaintainable code.

Disclaimer: The code presented in the answer is only intended to illustrate the use of the feature.  It does not cover proper design, security, maintainability, or sanity. Do not use.

Body:
Assuming a url of http://example.com/hello/world, and the following .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?/$1 [L]

router.php, an overly simplistic router, would be:

<?php

$request = explode("/", $_SERVER["REQUEST_URI"]);

$controllerClass = $request[0];
$controllerActionMethod = $request[1];

$controller = new $controllerClass();
$controller->$controllerActionMethod(); // hello::world();

?>

That's a pretty standard practical use of variable variables. Neat trick, but you should be extremely careful when using it, over/abusing it will certainly lead to horribly unmaintainable code.

Disclaimer: The code presented in the answer is only intended to illustrate the use of the feature.  It does not cover proper design, security, maintainability, or sanity. Do not use.


答:
As others have said, the article is contrasting it to a lexer generated by a program such as Flex.

What the other answers haven't mentioned is that a lexer is basically a finite state machine. Which is a building block in comp sci theory. If you learn how state machines work, you will notice many, many applications which you can apply them, one of which is a lexer. Or even a parser!

Title: Understanding hand written lexers


问:
How to get motivation and time to learn outside of work?
I work 40 hours as a programmer, and by the time I get home, the last thing I want to do is code some more. However, I feel like I am not getting better, and I do love software engineering. So how do you guys find the time/motivation to improve your craft outside of work?</p>

答:
I think motivation is a KEY. As a start you may get involved to a local developer community events. Speaking/networking with the actual developers can bring new things and ideas to your ordinary developer life. Question is where to find them?

There is a number of local user groups where you can meet geek developers. Most of them will be passionate about things that they do. Depending in which area are you living, there are different local interest groups.
Here you are some info that might be helpful.

Community Megaphone

User groups - Find a group in Your Area

User Groups: Meet and learn with your peers


答: Find a non-programming topic that you love, and build around it.  Love pro wrestling?  Write the comprehensive database of Wrestlemania results in whatever technology you want to learn.  Love birds?  Create a program that identifies birds based on photos taken.  Love french literature?  Write a parser that improves upon Google Translate.</p>

Title: How to get motivation and time to learn outside of work?

Body: I work 40 hours as a programmer, and by the time I get home, the last thing I want to do is code some more. However, I feel like I am not getting better, and I do love software engineering. So how do you guys find the time/motivation to improve your craft outside of work?</p>


答:
Don't code as soon as you get home then. Take a little break and then when you've recouped a little, then start into it. Make it fun.

But honestly, I know plenty of programmers that work 40 hours plus and have no problem finding the time for personal projects. If you love it then you'll find the time.


问:
web server response code 500
I realize that this may spur a religious discussion, but I discussed this with friends and get great, but conflicting answers and the actual documentation is of little help.

What does the 500 series response codes mean from the webserver? Internal Server Error, but that is vague. My assumption is that it means that something bad happened to the server (file system corruption, no connection to the database, network issue, etc.) but not specifically a data driven error (divide by zero, record missing, bad parameter, etc).

Something to note, there are some web client implementations (the default Android and Blackberry httpclients) that do not allow access to the html boddy if the server response is 500 so there is no way to determine what caused the issue from the client.

What I have been been implementing recently is a web service that returns a json payload wrapped in a response object that contains more specific error information if it is data related, but the server response will be 200 since it finished the actual processing.

Thoughts?

答:
In general, 500 means something went wrong on the server-side at no fault of the users. This could be any unexpected exception from your back-end, including the "data driven" errors you talked about.

If the user did something wrong to cause a failure, a 400-level error code should be returned.

Title: web server response code 500


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

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

If so, what did their code look like?

答: Yeah, we do. I'm from Uruguay and we usually code with variable names in English. Some people leave comments in Spanish, but I find that a bit awkward. In a previous job we were forced to use Spanish for variables and methods, and I hated it. </p>


问:
A programmer should concentrate on at least how many languages?
For me I am C# and Java person. I find these 2 languages are quite similar so its easier for me to crossover each other. I'm not sure if its good idea to pick up other different languages. Any thoughts?</p>

答:
well first of all there are a number of languages that are very hard to avoid for most programmers: javascript, sql, c, etc. so you might as well get acquianted with them, they aren't going away.

it is also a good idea to know a duck-typed scripting language...e.g. one of perl, python, ruby, lua etc. these are incredibly useful for a huge array of problems including automating much of your own daily drudgery

for better or for worse you will also likely run into c# and/or java at some point too, they're quite pervasive.

in any case, don't limit yourself artificially. those coders i know who explicitly avoid picking up interesting tools seem to have cloistered worldviews and limited impact.


问:
Best practices for including open source code from other public projects?
If I use an existing open source project that is hosted for example on github within one of my projects, should I check in the code from the other project into my public repo or not? I have mixed feelings about this, #1 I want to give proper credit and attribution to the original developer, and if appropriate I will contribute back any changes I need to make. However given that I have developed / tested against a specific revision of the other projects code, that is the version that I want to distribute to users of my project.

Here is the specific use case to illustrate my point. I am looking for a more generalized answer than this specific case. I am developing simple framework using rabbitmq and python for outbound messages that will allow for sending sms, twitter, email, and is extensible to support additional messaging buses as well. There is a project on github that will make the creation and sending of SMS messages developed by another person. When I create my own repo how do I account for the code that I am including from the other project?

答:
Absolutely, unequivocally, if you are legally able to do so check the code into your repo.

You want your builds to be hermetic, meaning that you can just type "build" in the command line and not require any additional tools, libraries, SDKs, etc.

You want to insulate your build from random breaks.

You want things to keep working tomorrow like they do today. This is the same as #2 but more sinister.

The best way I have seen this done is to create a third_party folder in the root of your repo, and have all references go to that. Give each third party project its own folder, and inside of it put a LICENSE and README file explaining where you got it and what you can do with it.

For example:

```<code>/third_party/
    /WidgetLibrary1/
        README
        LICENSE
        /v1.0/
            ... all of its source

    /SuperAwesomeFramework/
        README
        LICENSE
        /v3.0/
        /v3.1/
            ... all of its source
/src/
    ... all of your source
</code>```

Body:
Absolutely, unequivocally, if you are legally able to do so check the code into your repo.

You want your builds to be hermetic, meaning that you can just type "build" in the command line and not require any additional tools, libraries, SDKs, etc.

You want to insulate your build from random breaks.

You want things to keep working tomorrow like they do today. This is the same as #2 but more sinister.

The best way I have seen this done is to create a third_party folder in the root of your repo, and have all references go to that. Give each third party project its own folder, and inside of it put a LICENSE and README file explaining where you got it and what you can do with it.

For example:

/third_party/
    /WidgetLibrary1/
        README
        LICENSE
        /v1.0/
            ... all of its source

    /SuperAwesomeFramework/
        README
        LICENSE
        /v3.0/
        /v3.1/
            ... all of its source
/src/
    ... all of your source


答: From a technical point of view, Git has a feature called submodules that lets you incorporate a specific version of some external project into your repository. Other people who clone your repository will also get a copy of the correct version of the external project.

Title: Best practices for including open source code from other public projects?

Body:
If I use an existing open source project that is hosted for example on github within one of my projects, should I check in the code from the other project into my public repo or not? I have mixed feelings about this, #1 I want to give proper credit and attribution to the original developer, and if appropriate I will contribute back any changes I need to make. However given that I have developed / tested against a specific revision of the other projects code, that is the version that I want to distribute to users of my project.

Here is the specific use case to illustrate my point. I am looking for a more generalized answer than this specific case. I am developing simple framework using rabbitmq and python for outbound messages that will allow for sending sms, twitter, email, and is extensible to support additional messaging buses as well. There is a project on github that will make the creation and sending of SMS messages developed by another person. When I create my own repo how do I account for the code that I am including from the other project?


答:
As everyone said you gotta find the thing that you enjoy.  I have never been able to just go home and program as a hobby so for years I didn't do any of that.  Then one day I found something that I was interested in and then it was simply a case of doing it.  Rather than watching television, or surfing the internet I found myself wanting to work on my project.

Another solution I found interesting (and find it easy to get motivated) was creating my own website blog etc  It's amazing how you can find yourself interesting and have the time to write all about yourself and your amazing attributes :)


答:
Where I think your analysis is also failing is your not considering your data.

What happens to Merge sort and Quick sort when every element in the array is exactly the same? Can you solve this problem or this 'edge' case keep their running times the same? Who's performance is better?

What if the data is completely random? Who's performance is better?

So my question is: is there a better way to implement quick sort that
  is worthwhile trying out?

Have you considered running Insertion Sort within Quick sort when your arrays are < 100 Elements? What value is most efficient to start using Insertion Sort?

How the pivot is chosen is key to Quick Sorts run time. How are you choosing the pivot? Which way is better?

There are actually two ways to implement Quick sort, have you discovered both?

I think you will be well served to think about these questions.


答: One small tip I've got that I find useful is to incorporate some learning into either your commute time or into a daily exercise routine. E.g. you could watch some free online courses or screencasts on the way to or from work, or listen to a podcast while you are doing some exercise.</p>


问:
Equivalent of Domain Driven Design for functional programming languages
I really love the idea of domain driven design, however, as I'm learning Go, I'm wondering if there's the equivalent of DDD that's aimed at an effectively more functional language?</p>

答:
I believe DDD is not about OOP design itself, but more about how you approach the whole development process. Iterative development, ubiquitous language, close cooperation of business experts and developers are all language and paradigm agnostic.

Design of objects in DDD is not something new. The patterns that are described in DDD existed long before DDD saw light of the world. Agregate roots, strategy pattern, value objects were only good fit for describing the business logic. So your question should be more like "How to express business logic and persists it's state in functional language". You are probably looking in design patterns for functional programming languages.


问:
Quality of Code in unit tests?
When writing unit tests, is it worth spending the extra time to make the code have good quality and readability?

When writing tests I often break the Law of Demeter, for faster writing and to avoid using so many variables. Technically, unit tests are not reused directly - they are strictly bound to the code so I do not see any reason for spending much time on them; they only need to be functional.

答:
The test code should receive just as much love as your production code. For readability, maybe even more. If anyone else than you(including you two weeks after leaving the code) is supposed to understand what is going on, then you should make your code nice an crisp.

This means:

Extract building of test data into builder classes.

Extract multible assertions into separate assertion methods.

Be very precise in your naming. Assert.That(x4,
Is.EqualTo(y16*2*SOME_VALUE), ASS_ERR_TXT_56) makes very little sence to
most readers.

Taken to the extreme, tests can be written so they are almost as easy to read AND understand as prose. The extreme tester would probably say that a unit test more than 10 lines long is a bad one.

Title: Quality of Code in unit tests?


问:
C++ Iterator lifetime and detecting invalidation
Based on what's considered idiomatic in C++11:

should an iterator into a custom container survive the container itself being destroyed?

should it be possible to detect when an iterator becomes invalidated?

are the above conditional on "debug builds" in practice?

Details: I've recently been brushing up on my C++ and learning my way around C++11.  As part of that, I've been writing an idiomatic wrapper around the uriparser library.  Part of this is wrapping the linked list representation of parsed path components.  I'm looking for advice on what's idiomatic for containers.

One thing that worries me, coming most recently from garbage-collected languages, is ensuring that random objects don't just go disappearing on users if they make a mistake regarding lifetimes.  To account for this, both the PathList container and its iterators keep a shared_ptr to the actual internal state object.  This ensures that as long as anything pointing into that data exists, so does the data.

However, looking at the STL (and lots of searching), it doesn't look like C++ containers  guarantee this.  I have this horrible suspicion that the expectation is to just let containers be destroyed, invalidating any iterators along with it.  std::vector certainly seems to let iterators get invalidated and still (incorrectly) function.

What I want to know is: what is expected from "good"/idiomatic C++11 code?  Given the shiny new smart pointers, it seems kind of strange that STL allows you to easily blow your legs off by accidentally leaking an iterator.  Is using shared_ptr to the backing data an unnecessary inefficiency, a good idea for debugging or something expected that STL just doesn't do?

(I'm hoping that grounding this to "idiomatic C++11" avoids charges of subjectivity...)

答:
In C++ it's idiomatic to make anything that

can be prevented by careful coding and

would incur runtime cost to protect against

an Undefined Behaviour.

In particular case of iterators, the documentation of each containers says which operations invalidate iterators (destruction of the container is always among them) and access to invalid iterator is Undefined Behaviour. In practice it means that runtime will blindly access the no longer valid pointer. Usually it crashes, but it might corrupt memory and cause completely unpredictable outcome.

Providing optional checks that can be turned on in debug mode (with #define that defaults to on if _DEBUG is defined and disabled if NDEBUG is) is good practice.

However remember that C++ is designed to handle cases where one needs every bit of performance and the checks can be quite costly sometimes, since iterators are often used in tight loops, so don't enable them by default.

In our work project I had to disable iterator check in Microsoft standard library even in debug mode, because some containers use other containers and iterators internally and just destroying one huge one was taking half an hour because of the checks!


答:
Beware the BSD license!

Its is very "business friendly" in that it allows anyone to copy, modify sell or otherwise steal your code and claim it as thier own. Consider the case where Microsoft made a very small amendment to Kerebros, copyrighted it, patented it and charged the original authors at MIT fot the use their own software.

The GPL is wordy and verbose but it protects you from such abuse.

Title: Licensing a JavaScript library


答:
Small Steps

I'd recommend to either:

find something you want to code and/or need in your daily life at home,

or to train at work, either by way of:

attending company-paid training sessions (they're important too!),

developing small tools for small tasks.

Those 2 approaches mainly work for me, especially the second one.

It's Not Just by Programming...

... that you get interested in programming. Maybe some other stuff can get your motivation going. These are amazing books to inspire you to do great things and learn how others got into it before you, and built and modelled the computers and their systems you use today.

For more on this, read my answer (and others') to What are some things you have read that inspired and guided you as a programmer?, where I detail this a lot more. But my top-list for this would be:

Books (both hyper inspirational, extremely educative, and deeply humbling):

Hackers: Heroes of the Computer Revolution, by Steven Levy;

Dealers of Lightning: Xerox PARC and the Dawn of the Computer Age, by Michael Hitzlik;

Essays:

Teach Yourself Programming in 10 Years, by Peter Norvig;

Many Coding Horror articles and posts.


问:
Are unit tests really used as documentation?
I cannot count the number of times I read statements in the vein of 'unit tests are a very important source of documentation of the code under test'. I do not deny they are true.

But personally I haven't found myself using them as documentation, ever. For the typical frameworks I use, the method declarations document their behaviour and that's all I need. And I assume the unit tests backup everything stated in that documentation, plus likely some more internal stuff, so on one side it duplicates the documentation while on the other it might add some more that is irrelevant.

So the question is: when are unit tests used as documentation? When the comments do not cover everything? By developers extending the source? And what do they expose that can be useful and relevant that the documentation itself cannot expose?

答:
They're NOT an ABSOLUTE Reference Documentation

Note that a lot of the following applies to comments as well, as they can get out of sync with the code, like tests (though it's less enforceable).

So in the end, the best way to understand code is to have readable working code.

If at all possible and not writing hard-wired low-level code sections or particularly tricky conditions were additional documentation will be crucial.

Tests can be incomplete:

The API changed and wasn't tested,

The person who wrote the code wrote the tests for the easiest methods to test first instead of the most important methods to test, and then didn't have the time to finish.

Tests can be obsolete.

Tests can be short-circuited in non-obvious ways and not actually executed.

BUT They're STILL an HELPFUL Documentation Complement

However, when in doubt about what a particular class does, especially if rather lengthy, obscure and lacking comments (you know the kind...), I do quickly try to find its test class(es) and check:

what they actually try to check (gives a hint about the most important tidbits, except if the developer did the error mentioned above of only implementing the "easy" tests),

and if there are corner cases.

Plus, if written using a BDD-style, they give a rather good definition of the class's contract. Open your IDE (or use grep) to see only method names and tada: you have a list of behaviors.

Regressions and Bugs Need Tests Too

Also, it's a good practice to write tests for regression and for bug reports: you fix something, you write a test to reproduce the case. When looking back at them, it's a good way to find the relevant bug report and all the details about an old issue, for instance.

I'd say they're a good complement to real documentation, and at least a valuable resource in this regard. It's a good tool, if used properly. If you start testing early in your project, and make it a habit, it COULD be a very good reference documentation. On an existing project with bad coding habits already stenching the code base, handle them with care.


答:
One interpretation is that unit tests are "executable documentation".  You can run the unit tests against the code and it will tell you whether it's still performing as it was when the tests were written to pass, or not.  In that way the unit tests "document" the functionality of the system at some point in time, in an executable way.

On the other hand I have also only rarely actually read unit test code as "documentation" to understand functionality.  A single unit test is too localized, specific and abstract in a way to be able to tell you much about the actual system that's behind the class being tested.

Title: Are unit tests really used as documentation?

Body:
I cannot count the number of times I read statements in the vein of 'unit tests are a very important source of documentation of the code under test'. I do not deny they are true.

But personally I haven't found myself using them as documentation, ever. For the typical frameworks I use, the method declarations document their behaviour and that's all I need. And I assume the unit tests backup everything stated in that documentation, plus likely some more internal stuff, so on one side it duplicates the documentation while on the other it might add some more that is irrelevant.

So the question is: when are unit tests used as documentation? When the comments do not cover everything? By developers extending the source? And what do they expose that can be useful and relevant that the documentation itself cannot expose?


答:
TL;DR Unit tests and API comments are complementary - some things are best described in code, and others in prose.

Unit tests are mainly useful to document special cases and edge conditions which are hard (and cumbersome) to describe in API comments. Also, the API comments are usually directed to people who want to use the API.

If you want to modify the code, there's typically a lot more you need to know, and some of that is difficult to put into comments (and these comments go stale quickly). In that case a unit test also works as documentation.

An example: You have a method m(a, b) that performs a certain calculation. Due to backward compatibility requirements, it must special-case inputs of a=0 and a=-1, but only if b is NULL. Putting that into a comment is complicated, verbose, and likely to go stale if the requirement is later removed.

If you make some unit tests that checks the behaviour of m(0, NULL), m(-1, x) you get several benefits:

The description of correct behaviour is clear, misunderstandings are reduced

People cannot overlook the requirement when they change the code, unlike a comment


答:
If by documentation you mean I want something to find out how the code works then unit tests are perfect little examples of how units of the code works in both expected, edge cases, and mistakes (aka bugs) cases.  Also, your tests could be created before the code is written thus underlying what the code should do from a business/requirement point of view.

Are they replacing documentation?  No.

Are they a useful addendum to documentation?  Yes.


答:
I see unit tests as:

a way to prove the documentation is correct (assuming the documentation matches the api implementation).

a way to demo to a developer how to use a particular feature; unit test fixtures/unit test themselves are usually small enough that one can quickly learn from it.

and obviously to spot any regression bug.

To some extend they can be seen as a complement to an existing documentation but not as the documentation.


问:
Am I getting Scheme wrong?
Inspired by the numerous posts about the importance of learning Lisp/Scheme I started to learn Scheme two days back, I am using the book "The little Schemer" and have completed half of it.

But I still haven't learned anything new, the book teaches about recursion which I already understand and uses lambda (which I can think of a way to define a function in C). I still haven't got the concept of functional programming (please point to some example of functional compared to normal programming methods in C/C++ so I can get it).

Am I learning in the wrong way? or is "The little Schemer" for a newbie in programming and I should look for some other books?

答:
Wait until you'll get to the lexical closures.

Than try to grasp the homoiconic property of the language - this is what makes it really different from the C-likes.

And make sure you'll learn a Scheme with a proper define-macro implementation (I'd recommend Racket or Bigloo), not just standard hygienic macros (the latter would not surprise you at all if you're familiar with the C++ templates). Most Scheme textbooks would skip this stuff, unfortunately, but I'd argue that there is nothing nearly as important in Lisps as the proper macros.

It is also important to try to understand the purely functional subset of Scheme and learn how to solve all the possible programming problems with it. "Little Schemer" is a good starting point, but not nearly sufficient. Go through "Structure and Interpretation of Computer programs" after it.

Title: Am I getting Scheme wrong?


答:
The only reason for using hand-written lexers (and, more important, parsers) in the production compilers is in better and smarter error messages and error recovery. It was necessary back in 80s, but pretty much pointless now, with all that new and shiny parsing techniques (that you would not find in the totally outdated, but for some unknown reason still revered Dragon Book).

I'd recommend you to omit the lexing stage and use one of the lexerless parsing techniques. Packrat could be sufficient, it works really well with a C syntax, and it is extremely flexible, you can mix a high level, declarative parsing logic with low level imperative recipes for recovering from errors and giving comprehensive and useful error messages.

In short: there is no point in following the outdated practices of GCC, Clang and alike, and you'd better avoid reading the Dragon Book.

Title: Understanding hand written lexers


问:
Who owns the code, who owns the algorithm, who owns the idea?
This question got me thinking what products of the programming effort belong to the employer, and what don't.

The two extremes are (0) the code - it apparently belongs to the employer and (1) the learned personal and technical skills. But what is in between? Who owns the pseudocode/algorithm? Who owns the general idea of the algorithm? Who owns the know-how that such an algorithm may serve some useful purpose (e.g. on this site questions are values, as well as answers)?

Also: Who owns an idea on the web?

答:
In my contract I have a point saying that I own every algorithm that I developed by myself, and might use it whenever and wherever I want. The same thing is for the ideas which I suggested and which were used. Of course this doesn't mean that I can take the code with myself. But I'm free to use pseudocode/algorithm elsewhere.

This doesn't include anything that I developed with someone else, I guess. So apparently if I developed smth together with another member of our team, it doesn't belong to any of us, but only the company.

Such things should be written in the contract to avoid future problems.

EDIT: as PBrando said, you can use any algorithm and idea used by you in the company after some amount of time. In may case it is 3 years.


答:
About the time:

I started writing my "hobby" code in the evening, after dinner: back then I was "almost" single with no kids. And having a GF that works nightshifts helped a lot.

Now that I have kids the time dedicated to my evening projects is much smaller.

I don't code every evening, and I code more during the winter and rainy days: the summer I mostly enjoy the outdoor places.

Motivation:

In the beginning I wanted to do some extra money, but then it became
an open source project (little money, I just pay part of the rent with that) where I experimented new things, IDEs, profilers, tools, etc.

Some experiments were reused in my regular workplace.

Also, it turned out to be a massive help when you need a new job. People could see my code, my documentation, my interest in learning something after work, etc.