问:
What does this point about first normal form mean?
I'm reading the Wikipedia page on first normal form, and am confused about the last bullet point:

5) All columns are regular [i.e. rows have no hidden components such as row IDs, object IDs, or hidden timestamps].

Does this mean "all information about a row is contained in its values" (my words)?

I understand the rest of the points about 1NF; it's only this one that I'm confused about.

答:
I think that's basically true. The core of 1NF is that a table is strictly relational, i.e., all values in the table are some description of what the primary key identifies. Lots of RDBMSs use 'hidden' columns that don't describe the relation, they exist for some sort of internal housekeeping, yet are part of the table instead of being kept elsewhere in the schema (or some other mechanism the DB engine can use). Oracle, for instance, has 'hidden' rowID's everywhere.

The problem with this, as I understand it, is that because you have non-relational data skulking about your relations (i.e., tables), you create the possibility of reasoning about your data (i.e., creating SQL statements) which do not conform to relational algebra.


答:
First normal form means that each column has exactly one meaningful thing in it. An easy way to tell is if: data from a single column is broken up into multiple values before it is used; or, conversely, if multiple values are concatenated and then stored in one column, then first normal form is broken.

This is a somewhat poor example, but I'm stuck on thinking of a better one.
Storing names as a single column that is first and last name concatenated it would break 1NF, because you are storing more than a single meaningful value in that column. This is a poor example though because it's not 100% true, if names are always used as first+last together then it wouldn't break 1NF, though this generally isn't the case.

To address this point specifically, it is not part of Codd's original definition, its an addition that Date feels is important and is further explained in his book Date On Database. This basically means that the spirit of points 1-4 are not violated by special ways to access additional information about a row. RDMSs have started adding features that can violate this point if used.

ContentLicense: CC BY-SA 3.0

Title: What does this point about first normal form mean?

Body:
I'm reading the Wikipedia page on first normal form, and am confused about the last bullet point:

5) All columns are regular [i.e. rows have no hidden components such as row IDs, object IDs, or hidden timestamps].

Does this mean "all information about a row is contained in its values" (my words)?

I understand the rest of the points about 1NF; it's only this one that I'm confused about.


问:
Is Object Oriented stuff really that important?
For years, I have been doing Algorithmic stuff, writing scalable data structures for internet search, for example Randomized Binary Search Trees for Auto Recommendation, BitMaps, Wisdom of Crowd based Algorithms using Graphs, writing some interesting Machine Learning Algorithms like Clustering, Anomaly Detection, working on Information Retrieval stuff and so on

There is a common thing in the things that I have mentioned above. All the above stuff;each if coded in a language like C++ requires handful of classes. I mean they are interesting problems but they are not complex in terms of heavily loaded Object Oriented stuff. I have never used Inheritance, virtual stuff etc. Though I have heavily used Generic Programming, Templates and so on.

I love C++ (- Bulky OO stuff, As I like what Joe Armstrong's, creator of Erlang says, In OO World if you ask for a banana you get a big jungle alongwith gorilla holding the banana). I enjoy coding in other languages like Java, Python too.

Now my question is since I am enjoying the kind of projects/Algorithms I am working on do I need to really learn OO stuff, will I be a better coder/designer just by using the stuff like Inheritance, Dynamic Polymorphism (virtuals)? OR can I move to the world of Functional Programming (I have not done it till now) which attracts me more as I can just focus on tasks/algorithms and not let Kingdom Of Noun based OO stuff, has-a, is-a rule me?

In short will/can OO stuff help me at all for the kind of projects/Algorithms that I have mentioned above?

EDIT:

One extremely interesting link to add here:

http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html

答:
OO gained traction because it was a big improvement for handling complexity, as before it structured/procedural programming also was.

The benefits of using OO increase as the size of the project increases. For a 1KLOC program, it doesn't matter much which paradigm you use, all of them will work OK. But for a 200KLOC+ program, there's simply no viable competition for OO. That doesn't mean you can't write a 200KLOC program in C, just that you'll have to be a lot more disciplined to avoid ending up with a mess that no one (not even you) can understand. That doesn't mean that OO will prevent such mess, just that it'll make your life easier in order to prevent it.

Functional programming is a paradigm that somewhat deviated from the previous pattern, because it didn't come to help handle even more complexity than OO did, but to address a different sort of problems: parallel programming. That was the first time, also, that a programming paradigm attempted to do so: all the mechanisms that existed before in OO and/or SP/PP were not part of the paradigm, but just OS entities (threads, mutexes, etc.) encapsulated according to the paradigm rules.

In that regard, FP is a lot more natural than the others, but that comes at the cost of reversing the way we usually think about the problems. And due to that, it has a limited capacity to handle the very same complexity at the same scale that OO does.

My guess is that this will limit the adoption of FP in the near future to very specialized systems, in general not much big, or specialized sections of bigger systems. And the rest will still be made using OO. Which of those you plan to develop (or learn about the development) will determine what should be your learning focus, IMO.


问:
What are the drawbacks of elastic tabstops?
Look here: a typical holy war on tabs vs spaces.

Now look here: elastic tabstops. All problems solved, and a bunch of very useful new behaviours added.

Are elastic tabstops even mentioned in that tabs vs spaces discussion? Why not? Are there drawbacks to the elastic tabstop idea so serious that nobody has ever implemented them in a popular editor?

EDIT: I apologise for putting too much emphasis on "why aren't they mentioned". That wasn't really what I intended; that question is possibly even off topic. What I really mean is, what are the biggest drawbacks of this that prevent wider adoption of an obviously beneficial idea? (in an ideal world where everything supports it already)

(Turns out there's already a request on the Microsoft Connect for a Visual Studio implementation of elastic tabstops, and a request in Eclipse too. Plus there's a question asking about other editors that implement elastic tabstops)

答:
One drawback is that it doesn't work if you want alignment on one group of lines and then indentation on the next, since it groups the tab stops of adjacent lines.

```<code>def foo( bar,
         xyzzy ):
         wibble() # Too much indentation
</code>```

What I wanted:

```<code>def foo( bar,
         xyzzy ):
    wibble()
</code>```

For curly-brace languages this might be less of a problem, as you can usually solve this by putting the opening brace on a line of its own (like in the animation), but for whitespace-sensitive languages, this quickly becomes a pain, and you end up having to fall back to using spaces.

Body:
One drawback is that it doesn't work if you want alignment on one group of lines and then indentation on the next, since it groups the tab stops of adjacent lines.

def foo( bar,
         xyzzy ):
         wibble() # Too much indentation

What I wanted:

def foo( bar,
         xyzzy ):
    wibble()

For curly-brace languages this might be less of a problem, as you can usually solve this by putting the opening brace on a line of its own (like in the animation), but for whitespace-sensitive languages, this quickly becomes a pain, and you end up having to fall back to using spaces.


问:
Servicing background tasks on a large site
We're dealing with an interesting problem on StackOverflow.

We've got a whole bunch of little "needs to be done soon-ish" tasks.  An example is updating "Related Questions" lists.  What we've done in the past is to piggy-back those tasks onto some users' page loads.

This was never ideal, but it wasn't really noticeable.  Now that SO has passed the 1,000,000 question mark, those unlucky users are starting to feel it.

The natural solution is to actually push these tasks into the background.  There are two broad ways of doing this I'm considering.

1. In IIS as a custom Thread-Pool/Work-Queue

Basically, we spin up a few (non-ThreadPool, so as to not interfere with IIS) threads and have them services some collections we're shoving Funcs into.

The big pro here is simplicity.  We don't have to worry about marshaling anything, nor do we have to make sure some external service is up and responding.

We also get access to all of our common code.

The con is, well, that we shouldn't use background threads.  The objections I know of are all centered around starving IIS (if you use ThreadPool) and the threads dieing randomly (due to AppPool recycling).

We've got existing infrastructure to make the random thread death a non-issue (its possible to detect a task has been abandoned, basically), and limiting the number of threads (and using non-ThreadPool threads) isn't difficult either.

Am I missing any other objections to in IIS process thread-pooling/work-queues?

Moved to StackOverflow, as it wasn't really addressed here.

2. As a Service

Either some third-party solution, or a custom one.

Basically, we'd marshal a task across the process boundary to some service and just forget about it.  Presumably we're linking some code in, or restricted to raw SQL + a connection string.

The pro is that its the "right way" to do this.

The cons are that we're either very restricted in what we can do, or we're going to have to work out some system for keeping this service in sync with our code base.  We'll also need to hook all of our monitoring and error logging up somehow, which we get for free with the "In IIS" option.

Are there any other benefits or problems with the service approach?

In a nutshell, are there unforseen and insurmountable problems that make approach #1 unworkable and if so are there any good third-party services we should look into for approach #2?

答:
I think the con with the pure service approach is that you have code scattered into the service and away from the core app.

Here's what we've done with large background non time-sensitive jobs, which keeps the code together and simplifies the service:

Create a jobs queue (either in-memory or DB, whatever persistence is needed for the types of jobs)

Create a web service that will execute the queued jobs

Dead simple service app that calls the web service at a specified interval, leave all the complex stuff (job retrieval and execution) to the web service in your core codebase.

Even simpler, just make the call in a console app and use Task Scheduler or VisualCron to turn it into a "service".

ContentLicense: CC BY-SA 2.5


问:
How to swap out a DB from MySQL to SQL Server in a multiple large projects?
Is there a sane way / best practices way to swap out a DB from MySQL to SQL Server in a multiple large projects?  Some of the projects are ASP projects, some of them are windows services, some are standalone windows apps.  I don't think any ORM is used.  I think its just SQL statements all over the place.  </p>

答:
Nope, no sane way.  It will require an insane amount of work, testing, unexpected bugs and missed deadlines.
I would recommend:

Start polishing those tests now.  Or start writing them.

Look for a commercial product that will help with the data transfer.

Set up your new area asap and start doing the mapping, just to get an idea of what's involved.

talk (or post here and Stack Overflow) to folks who know these issues.  Post specific questions about primary keys, indexes, triggers, etc. to start getting a handle on it.

Make it a project that gets enough resources (several people and several months) to do it.  Make sure you communicate how much work it is - once you yourself a got a better idea (right now you don't).


答:
Yes, it is important, for this single reason: understanding OOP makes you a better programmer. As a rule of thumb: understanding always makes you a better programmer.

It should be noted that neither is-a, nor classes let alone inheritance have anything to do with OOP. What OOP is really about is decoupling through indirection, as formulated by the dependency inversion principle. One can argue that this is also an important aspect of FP. If study both OOP and FP, you will increasingly become aware that they are actually two sides of a continuum. The broader and deeper your understanding of it, the better you will become.

To get an understanding of OOP try Io and maybe Smalltalk and Ruby.

Title: Is Object Oriented stuff really that important?

Body:
For years, I have been doing Algorithmic stuff, writing scalable data structures for internet search, for example Randomized Binary Search Trees for Auto Recommendation, BitMaps, Wisdom of Crowd based Algorithms using Graphs, writing some interesting Machine Learning Algorithms like Clustering, Anomaly Detection, working on Information Retrieval stuff and so on

There is a common thing in the things that I have mentioned above. All the above stuff;each if coded in a language like C++ requires handful of classes. I mean they are interesting problems but they are not complex in terms of heavily loaded Object Oriented stuff. I have never used Inheritance, virtual stuff etc. Though I have heavily used Generic Programming, Templates and so on.

I love C++ (- Bulky OO stuff, As I like what Joe Armstrong's, creator of Erlang says, In OO World if you ask for a banana you get a big jungle alongwith gorilla holding the banana). I enjoy coding in other languages like Java, Python too.

Now my question is since I am enjoying the kind of projects/Algorithms I am working on do I need to really learn OO stuff, will I be a better coder/designer just by using the stuff like Inheritance, Dynamic Polymorphism (virtuals)? OR can I move to the world of Functional Programming (I have not done it till now) which attracts me more as I can just focus on tasks/algorithms and not let Kingdom Of Noun based OO stuff, has-a, is-a rule me?

In short will/can OO stuff help me at all for the kind of projects/Algorithms that I have mentioned above?

EDIT:

One extremely interesting link to add here:

http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html


问:
Patterns for Versioning Relational Data in a MySQL database?
I am trying to find an approach for a project, where A user can edit records, and be able to see past versions of those records. Here is a simlified example schema, using a list:

```<code>TABLE list (
  id int auto_increment primary key,
  user_id int,
  title varchar(255)
);

TABLE list_tasks (
  id int auto_increment primary key,
  list_id int,
  title varchar(255),
  order int,
  is_complete tinyint
);
</code>```

So a user may come in, and make several edits to the list, (i.e., add or remove tasks, re-order tasks, mark some complete, rename some, etc.), Then save them. At this point, I'd like to generate a 'version 2' of the list and tasks, and have them be able to view previous versions, but when they access the list, always get the latest version.

Is there a common approach / design pattern for dealing with versioning data in this way in a MySQL database?

答:
Its pretty common to want do that in a db.  Though you are putting a twist on it in that you want to track a revision for a list of items.

One way to do this might be to alter the structure such as

```<code>Alter table lists add revision_id integer;
Alter table list_tasks add revision_id integer;

Create Table revisions
{
   id int autoincrement... (revision id)
   list_id int...
   revdate datetime...
}
</code>```

When the user saves their list, create a new revision in the revisions table above and assign that value to the list items in list_tasks and then to the revision id in lists to mark that id as the 'current' revision.  When the user edits the items, dont edit the existing items - rather, insert new ones with a new revision id and update the list table with that revision to mark it as the current one.

Then to list the current items, list the items from the current revision id specified in the lists table.  To browse previous versions, you can get a list of previous revisons of the lists from the revisions table, and then list the individual items based on that id.

Body:
Its pretty common to want do that in a db.  Though you are putting a twist on it in that you want to track a revision for a list of items.

One way to do this might be to alter the structure such as

Alter table lists add revision_id integer;
Alter table list_tasks add revision_id integer;

Create Table revisions
{
   id int autoincrement... (revision id)
   list_id int...
   revdate datetime...
}

When the user saves their list, create a new revision in the revisions table above and assign that value to the list items in list_tasks and then to the revision id in lists to mark that id as the 'current' revision.  When the user edits the items, dont edit the existing items - rather, insert new ones with a new revision id and update the list table with that revision to mark it as the current one.

Then to list the current items, list the items from the current revision id specified in the lists table.  To browse previous versions, you can get a list of previous revisons of the lists from the revisions table, and then list the individual items based on that id.


问:
Coding Guideline : Methods shouldn't contain more than 7 statements?
I was looking through the AvSol Coding Guidelines for C# and I agree with nearly everything but I'm really curious to see what other think of one specific rule.

AV1500

Methods should not exceed 7 statements  A method that requires more
  than 7 statements is doing too much, or has too many responsibilities.
  It also requires the human mind to analyze the exact statements to
  understand what the code is doing. Break it down in multiple small and
  focused methods with self-explaining names.

Do most of you follow this rule? Even if there's little to be saved from creating a new method (Your code is still DRY) aside from greatly increasing readability?  And is your number still as low as 7?    I would tend more toward 10.

I'm not saying I violate this rule all over the place--on the contrary, my methods are 95% small and focused but saying you should never violate this rule really blew me away.

I really just want to know what everyone thinks of NEVER violating this rule (It's a '1' on the coding standard--meaning NEVER do this).  But I think you'd have trouble finding a codebase that doesn't.

答:
Wow! I never expected to find such an intense discussion on a simple guideline that roughly says that your methods should be very small. Because they're always developers who want their guidelines to be explicit, I choose 7 because that sounded like a nice threshold.

Some of you have already quoted the disclaimer at the beginning of the document. But just to be clear, this document represents a collection of guidelines which try to help you write better code and design better systems. I've never stated that anything should be a rule, even though a guideline is marked as a level 1. Those levels are simply the collective opinion of the many people who have been using this document for a while.

I have also never claimed to be an expert. But I've been in this profession for 15 years now, with about 4 years of C++ experience and 11 years of C# experience. It was originally based on Industrial Strength C++, but I have been refining it since then with input from the community.

Regardless, the point I was trying to raise is that you should keep thinking for yourself. If you think the 7 statements guideline is not useful, than just make it longer. Heck, I even violate that guideline once in a while. I just violate it consiously and accept the consequences.


答:
I have been reading the Steve Jobs book and in there is a story about how Steve saw SmallTalk at the Xerox PARC labs.  That was one of the earliest OO languages.  Without OO it would have been horrendous to develop something like a Graphical User Interface (GUI).  With all the asynchronous input and being able to jump from task to task while working with one "Object" or another.

So while you can do a lot with a functional language and it definitely has it's use cases.  When you start dealing with more complex systems that interact more with real world problems you find OO to be a superior design.


问:
Reasons to Use a VM For Development
Background:

I work at a start-up company, where one team uses Virtual Machines to connect to a remote server to do their development, and another team (the team I'm on) uses local IIS/SQL Server 2005/Visual Studio installations to conduct work.

Team VM is located about 1000 miles from Team Non-VM, and the servers the VMs run off of are located near Team VM (Latency, for those that are wondering, is about 50ms).

A person high in the company is pushing for Team Non-VM to use virtual machines for programming, development, and testing.

The latter point we agree on -- we want Virtual Machines to test configurations and various aspects of the web application in a 'clean' state.

The Problem:

What we don't agree on is having developers using RDP to connect to a desktop remotely that contains Visual Studio, SQL Server, and IIS to do the same development we could do locally on our laptops.

I've tried the VM set-up, and besides the color issue, there is a latency issue that is rather noticeable, not to mention that since we're a start-up, a good number of employees work from home on occasion with our work laptops, and this move would cut off the laptops. They'd be turned in.

Reasons to Use Remote VMs for Development (Not Testing!):

Here are the stated reasons that this person wants us to use VMs:

They work for TeamVM.

They keep the source code "safe".

If we want to work from home, we could just use our home PCs.

Licenses (I don't know what the argument is, only that it's been used).

Reasons not to use Remote VMs for Development:

Here are the stated reasons why we don't want to use VMs:

We like working from home. We get a lot done on our own time.

We're not going to use our Home PCs to do work related stuff.

The Latency is noticeable.

Support for the VMs (if they go down, or if we need a new VM) takes a while.

We don't have administrative privileges on the VM, and are unable to change settings as needed.

What I'm looking for from the community is this:

What reasons would you give for not using VMs for development? Keep in mind these are remote VMs -- this isn't a VM running on a local desktop. It's using the laptop (or a desktop) as a thin client for a remote VM. Also, on the other side of the coin:  Is there something we're missing that makes VMs more palatable for development?

Edit: I think 'safe' is used in term of corporate espionage, or more correctly if the Laptop gets stolen, the person who stole would have access to our source code.  The former (as we've pointed out, is always going to be a possibility -- companies stop that with litigation, there isn't a technical solution (so far as I can see)).  The latter point is ( though I don't know its usefulness in a corporate scenario) mitigated by Truecrypt'ing the entire volume.

答:
I worked in a shop where we had a VM setup for development and it was primarily due to the complexity of the configuration.  We actually ran the VM locally on our systems (this company for some reason was still living in the 90's when it came to developer workstations and didn't have laptops either).

I ended up building out my own development environment on my main system and it worked much better.

As others have said, the latency and convenience is a big drawback.  Someone upstairs is being pitched, probably by IT people, how much savings they will have by going this route.  If you have a say, go with a 10% drop in productivity due to latency and not being able to work remotely.  Average total compensation of the team is probably somewhere around $100k conservative, then take that times the number of team members and you are proabably looking at some serious money.  Not to mention turnover costs because you will loose all the "good" people who will go work for a startup that "gets it" and doesn't try to let IT dictate to their shining star developers.

OwnerDisplayName: George Stocker

Title: Reasons to Use a VM For Development


问:
What do you do when you can't seem to understand a certain part of programming?
I'm learning new languages as I go along, I write code for very basic programs in multiple languages, and I go to classes. I've read books, articles, lessons, videos, you name it, however I can't seem to get the hang of certain things.

For example I never understood pointers - what they are good at. (NOT PART OF THE QUESTION - retagging with "Pointers" is not required...)

My question however, is not what pointers do, but instead how can I understand things like that? If, after reading a book or an article about a certain part of programming, and I don't understand, what do I do? Writing code in a certain feature of programming surely helps, however it doesn't actually help with understand that much. The theoretical part is important in understanding.

答:
This is a common problem in learning and teaching. And as others have said, there is no sure way to work around this. It’s a fundamental truth that we all learn differently since our brains are wired differently in subtle but crucial ways.

Learning generates new neuronal connections. Without going too much into neuroscience (which I know next to nothing about), generating new connections requires different kinds of exposure to a concept for different people. Try many different angles, read / hear / watch different explanations. Practice!

If that doesn’t work, put the problem aside: you might simply be missing another part of the puzzle that, once acquired, makes the original problem seem obvious.

Do you know these aha! moments? This is when your brain just made a new connection. This is how learning happens.

Incidentally, any good teacher knows this. Guidelines for technical writing often state that every concept should be explained at least twice, using different words (and perhaps with some text between them). If you pay attention you will be able to spot that all the good science writers follow this rule.

Alas, all too many teachers ignore it, and explain things only once. And even if they succeed in finding an elegant explanation with a great metaphor this simply isn’t enough.


答:
This solution uses a separate auditing table. It has pros and cons. You may prefer to eliminate the old records from your main table. Performance improvement may be negligible.

Add the following fields to each audited table:

```<code>AddUserID      int <whatever your system uses>
AddDateTime    datetime
UpdateUserID   int <whatever your system uses>
UpdateDateTime datetime
CurrentVersion int
IsDeleted      bit
</code>```

You will need to update these fields each time the data change. CurrentVersion gets incremented by 1 (It could be used as a way to lock a record, but that is another question.) IsDeleted provides a "soft delete" so it can be referenced in the future.

Separate Audit Tables
Each table should have a corresponding _Archive or _History version of the table. These probably don't need to be indexed in the same way. Obviously a single primary key field will not apply. You should be able to make a composite key out of the ID field and UpdateDateTime.

Using a trigger (This will address changes made inside or outside your code. You can decide if this works for your situation.)  or other coding, when a record is appended, updated or deleted,  a copy of the record is placed in the archive/history table. All of the versions and other auditing fields are maintained. This will tell you what users did what when. The table can be compared to itself to see when a record was changed or to see trends.

I've seen this work well over the last few years. I would like to hear about drawbacks I may not be considering.

Title: Patterns for Versioning Relational Data in a MySQL database?

Body:
I am trying to find an approach for a project, where A user can edit records, and be able to see past versions of those records. Here is a simlified example schema, using a list:

```<code>TABLE list (
  id int auto_increment primary key,
  user_id int,
  title varchar(255)
);

TABLE list_tasks (
  id int auto_increment primary key,
  list_id int,
  title varchar(255),
  order int,
  is_complete tinyint
);
</code>```

So a user may come in, and make several edits to the list, (i.e., add or remove tasks, re-order tasks, mark some complete, rename some, etc.), Then save them. At this point, I'd like to generate a 'version 2' of the list and tasks, and have them be able to view previous versions, but when they access the list, always get the latest version.

Is there a common approach / design pattern for dealing with versioning data in this way in a MySQL database?

Body:
This solution uses a separate auditing table. It has pros and cons. You may prefer to eliminate the old records from your main table. Performance improvement may be negligible.

Add the following fields to each audited table:

AddUserID      int <whatever your system uses>
AddDateTime    datetime
UpdateUserID   int <whatever your system uses>
UpdateDateTime datetime
CurrentVersion int
IsDeleted      bit

You will need to update these fields each time the data change. CurrentVersion gets incremented by 1 (It could be used as a way to lock a record, but that is another question.) IsDeleted provides a "soft delete" so it can be referenced in the future.

Separate Audit Tables
Each table should have a corresponding _Archive or _History version of the table. These probably don't need to be indexed in the same way. Obviously a single primary key field will not apply. You should be able to make a composite key out of the ID field and UpdateDateTime.

Using a trigger (This will address changes made inside or outside your code. You can decide if this works for your situation.)  or other coding, when a record is appended, updated or deleted,  a copy of the record is placed in the archive/history table. All of the versions and other auditing fields are maintained. This will tell you what users did what when. The table can be compared to itself to see when a record was changed or to see trends.

I've seen this work well over the last few years. I would like to hear about drawbacks I may not be considering.


问:
Is it possible to get a job in a high-demand company without having hobby projects?
I was curious if the recruitment team at high-demand companies such as Google takes a lack of hobby projects into consideration when evaluating candidates.

I'm a straight 40 hour/week programmer, who is lucky to spend an hour or two a month outside of work on anything programming related. I love hanging out on SO/SE during my breaks at work, and love answering questions, but after work I leave the programming world and go back to my life.

I already understand that you don't need hobby projects to be a good programmer, but does this lack of hobby projects affect my chances getting a job at a company that always has a long list of candidates trying to get in?

答:
I've recently been interviewing senior CS students for software developer positions.

The graduate who can show he worked on an outside project has a big leg up with me, especially if their outside project delivered some sort of product that somebody else used.

It's not that I want a developer with 'no life', it's that new CS graduates who only take CS courses and does nothing else lack a lot of valuable experience that a graduate who has actually delivered some kind of product to someone else has.

For new graduates an outside project is a major positive factor.

For more senior position it still impresses if the candidate has done 'outside' projects, but it's not a show stopper if their work experience is fairly relevant to the open position.


问:
normal order evaluation -vs- applicative order evaluation
I am going through Abelson and Sussman (Structure and Interpretation
of Computer Programs) and I am a little confused about when normal order evaluation is used and when applicative order evaluation is used.

This sentence throws me off:

Lisp uses applicative-order evaluation partly because of the additional efficiency obtained from avoiding multiple evaluations of expressions suich as those illustrated with (+5 1) and (*5 2) above and, more significantly, because normal-order evaluation becomes much more complicated to deal with when we leave the realm of procedures that can be modeled by substitution. [emphasis added]

on page 17 paragraph 1.

However, in exercise 1.6, the implication is that Lisp uses normal order evaluation for primitives but applicative order evaluation for complex procedures.

Could someone clarify?

答:
First:  there are multiple implementations of Lisp, each of which may have different evaluation models.  I believe SICP mostly uses Scheme.

Exercise 1.6 does not imply that Scheme uses normal order -- it's about a special form (if).  For special forms, the evaluation can be neither of applicative or normal.

I believe Scheme always uses applicative order except in the case of special forms.

For example:

```<code>(cond (x 1)
      (y 2)
      (else 3))
</code>```

cond is a special form.  This would evaluate by evaluating x, and if it's true, then return 1, otherwise evaluate y, returning 2 if it's true, otherwise returning 3.

I'm a little rusty on the Scheme -- hope I didn't forget any parentheses!  I'm also aware that there are multiple versions of Scheme, but not sure which one is used by the book.

Body:
First:  there are multiple implementations of Lisp, each of which may have different evaluation models.  I believe SICP mostly uses Scheme.

Exercise 1.6 does not imply that Scheme uses normal order -- it's about a special form (if).  For special forms, the evaluation can be neither of applicative or normal.

I believe Scheme always uses applicative order except in the case of special forms.

For example:

(cond (x 1)
      (y 2)
      (else 3))

cond is a special form.  This would evaluate by evaluating x, and if it's true, then return 1, otherwise evaluate y, returning 2 if it's true, otherwise returning 3.

I'm a little rusty on the Scheme -- hope I didn't forget any parentheses!  I'm also aware that there are multiple versions of Scheme, but not sure which one is used by the book.


问:
Should I use title case in URLs?
We are currently deciding on a consistent naming convention across a site with multiple web applications. Historically, I've been an advocate of the 'lowercase all the letters!' when creating URLs:

```<code>http://example.com/mysystem/account/view/1551
</code>```

However, within the last year or two, specifically since I began using ASP.NET MVC & had more dealings with REST based URLs, I've become a fan of capitalizing the first letter of each section/word within the URL as it makes it easier to read (imho).

```<code>http://example.com/MySystem/Account/View/1551
</code>```

We're not in a situation where people need to read or be able to understand the URLs, so that's not a driver per se. The main thing we are after is a consistent approach that is rational and makes sense.

Are there any standards that declare it good to do one way or another, or issues that we may run into on (at least realistically modern) setups that would choose a preference over another? What is the general consensus for this debate currently?

答:
As long as users can type it however they want, it really does not matter.  Personally, I prefer TitleCase, but there are many who disagree.  If you are consistent, no one will mind.

If your web server cannot, for some reason, show me http://foo.com/HelloWorld when I try to go to http://foo.com/helloworld, you should opt for all-lowercase.  While people rarely type full URLs these days, front-facing addresses should be accessible without having to fiddle around with capitalization.

Title: Should I use title case in URLs?


问:
What does mathematics have to do with programming?
I just started a diploma in software development. Right now we're starting out with basic Java and such (so right from the bottom you might say) - which is fine, I have no programming experience apart from knowing how to do "Hello World" in Java.

I keep hearing that mathematics is pertinent to coding, but how is it so? What general examples would show how mathematics and programming go together, or are reliant on one another?

I apologize of my question is vague, I'm barely starting to get a rough idea of the kind of world I'm stepping into as a code monkey student...

答:
A problem with your question is that "mathematics" and "programming" are both very wide and deep subjects about which there is more to know than anyone could master in a lifetime (no exaggeration).  I personally hold an MA degree in mathematics.  During my time in university, it seemed as if the more I learned, the less I knew compared to my peers; it felt is if I became less intelligent over the years.  When I presented my master's thesis to a group of professors, even most of them seemed to be largely unfamiliar with what I studied.

Likewise, I am now a database-driven web application developer.  If you compared me to someone who does embedded assembler language programming, you might think of us as two very talented professionals, but we would have vastly different expertise even though we're both "programmers".

As you progress in your study of higher mathematics (beyond freshman calculus), you will find that mathematics instills a discipline for abstract reasoning that will serve you well when you program.  I think that this discipline is very important because you will deal with abstract concerns as you program.

Sure, in freshman programming, you will likely learn about pointer arithmetic.  You will write short programs to illustrate this concept and your understanding of how it drives your computer obey your will.  However, learning about how pointer arithmetic works in the abstract will not make you good at using pointers in a real program.  When it comes time to take on a mess of 10K lines of code and make some changes to the pointer arithmetic, you will need to be able to reason at a very abstract level, making strategic decisions to balance different concerns about how your changes will affect the code.

As a programmer, you must balance "readability" of your code, performance of your code, ease-of-use of the resulting programs, among many other concerns.  You must be able to make very abstract comparisons to balance these concerns among one another.  You will make many of these comparisons every day.  I haven't even gotten started about time-management.  You will abstractly reason about the probability that something you do will affect your ability to do your tasks on time, and once again, you will make many decisions every day that will affect your work.

Finally, you must maintain your philosophical discipline to be able to assimilate new ideas and concepts in order to be able to continue on as old methodologies and practices fall out of use.  Once again, you will have to be able to evaluate the ideas that come along and make an abstract comparison to what you already know.

In short, programming, as most of us know it, doesn't have a whole lot to do with mathematics, as most of us know it; but when you look at it at an abstract level, they have a lot in common.


问:
PHP to SharePoint roadmap
I'm a PHP developer with familiarity with Rails and a focus on MVC development. My company is moving more and more to SharePoint and I feel I need to learn to build application within the SharePoint system.

I have some brief introduction to C# but that's about it. I've used some SharePoint Designer and the web interface but not that heavily (most of my "development" so far for SharePoint has been html/css/javascript page manipulation in SPDesigner).

What, and in what order should I be learning to eventually develop applications for SharePoint? Also, any good resources for each step?

答: Maybe ProcessMaker could be a starting point? It is a open source BPM system based on PHP and has some basic SharePoint triggers. You could start playing with those and take a look at the code?</p>

OwnerDisplayName: Daryl Gubler

Title: PHP to SharePoint roadmap

OwnerDisplayName: Roel Veldhuizen


问:
Is code pruning related to obfuscation?
From my research, many obfuscation/optimization packages include a feature called pruning where the software will remove dead code during processing.

The following packages include both obfuscation and code pruning as a feature (to name a few):

RedGate SmartAssembly (.NET)

Preemtive Dotfuscator (.NET)

Inquartos Obfuscator (.NET)

ProGuard (Java)

I see the common thread that both operations require scanning and analyzing an assembly, but I'm curious if the two features are or even could be fundamentally related.  The reason I am asking is that we are considering disabling code pruning in our environment (unrelated issue), but our concern is that it could potentially decrease the effectiveness of the obfuscation process and thus protect our Intellectual Property less.

Does or could code pruning influence obfuscation, and how?

答:
The existence of dead code would not increase the obfuscation, when decompiling/deobfuscating code, the flow of the program is always lost, the functions are not ordered in the way that the would naturally be laid out by a developer, so once the output is rendered, the user is always hunting around for the entry points into objects/functions before they can begin to map the methods/functions and their relationships.

Additional, unused code, could be a source of confusion for the person(s) who are attempting to reuse your code after the code has been output, but it would not make the output of the code more difficult for the algorithms to create in the first place.  The tools would work the same, and it would offer no additional protection.

Some times dead code is actually added to increase the obfuscation (so not eliminating it sounds like it would be better) but it is actually done to avoid detection.  As seen here:
http://isyou.hosting.paran.com/papers/bwcca10-2.pdf

Title: Is code pruning related to obfuscation?


答:
Obfuscation has to do with hiding or disguising the original intent of the code from being easily comprehended by humans.

Removing dead code ( code that is proven to never be executed regardless of the inputs ) is an optimization technique which has to do with making the executable use less time or space or both.

Most, if not all the packages you list are not just about obfuscation, but do lots of things to make the code take less time or space or both along with other features.

Some of those optimization's could be considered to make the deduction of the logic flow of the code harder to deduce for a human. Removing dead code probably isn't one of those optimizations.

Title: Is code pruning related to obfuscation?

Body:
From my research, many obfuscation/optimization packages include a feature called pruning where the software will remove dead code during processing.

The following packages include both obfuscation and code pruning as a feature (to name a few):

RedGate SmartAssembly (.NET)

Preemtive Dotfuscator (.NET)

Inquartos Obfuscator (.NET)

ProGuard (Java)

I see the common thread that both operations require scanning and analyzing an assembly, but I'm curious if the two features are or even could be fundamentally related.  The reason I am asking is that we are considering disabling code pruning in our environment (unrelated issue), but our concern is that it could potentially decrease the effectiveness of the obfuscation process and thus protect our Intellectual Property less.

Does or could code pruning influence obfuscation, and how?


问:
If competition is using 'lingua obscura' for development (why) should I be worried?
I was reading Paul Graham's essay - Beating The Averages (2003) and here's what he had to say:

The more of an IT flavor the job descriptions had, the less dangerous
  the company was. The safest kind were the ones that wanted Oracle
  experience. You never had to worry about those. You were also safe if
  they said they wanted C++ or Java developers. If they wanted Perl or
  Python programmers, that would be a bit frightening-- that's starting
  to sound like a company where the technical side, at least, is run by
  real hackers

Now, this is a dated essay. However, I fail to see how using a non-commonplace language (C/C++/Java, C#) would be 'less dangerous'. If the programmers of an organization are very fluent with the development language they should be equally adept at cranking out code at a decent pace. In fact if you do use a non-commonplace language won't maintenance/enhancement problems hit you in the face since not too many programmers would be available, in the long run?

For making quick-n-dirty systems I agree, that some languages allow you to take off relatively sooner than others. But does Paul Graham's essay/comment make sense in 2012 and beyond? If a startup were to use typical IT languages for development, why should it's competition be less worried?

I fail to see how the language itself makes a difference. IMHO it's the developers experience with the language that matters and the availability of frameworks so that you DRY (do not repeat yourself) not just coding in a particular language.

What is it that I'm missing? Does it imply that startups better choose non IT-flavored languages (even if the developers may be extremely adept at them)? What are the (programming) economic/market-forces behind this claim?

PS: 'lingua obscura' is not meant to hurt anyone's feelings :)

答:
Let's see what languages were first used by successful startups. An unscientific list, off the top of my head. Proper randomized research would be better, if anyone had the energy.

Facebook: PHP

Stackexchange: C#

Google: Java and Python

Twitter: Ruby on Rails

So, presumably, we conclude that Facebook and Stackexchange posed no threat to their competitors. Not very convincing.

Let's see whether Paul Graham believes it nowadays. He cofounded YCominator which funds startups. The homepage lists some of their succesful startups. I've gone through them in order, very quickly trying to research the languages they used in the early days.

reddit: Common Lisp

wufoo: classic asp and php

scribd: Flash

dropbox: Python

Heroku: Ruby

Well, there are some signs of a preference for relatively obscure and arguably powerful languages. But Flash, PHP and classic ASP are listed too.

It's an essay. It's a hyperbolic boost for a relatively obscure language that he loves, with underlying advice that startups should love their technology and move as fast as they can. Fair enough.


问:
Convince a lone developer to use a separate build tool instead of the IDE one-click build
In my years of programming Java and more recently Scala, I've never used Ant, Maven, Gradle or any of those build tools for Java.  Everywhere I've worked there was a build manager who took care of all of that -- I'd compile locally with the IDE for development and unit testing, then check in the source code and notify the build manager who did what was necessary to compile everybody's files for the shared environment.

Now that I'm between contracts I've been working on my own self-funded project and it's getting to the point where it could be good enough to actually make money.  I even have a potential investor lined up and plan to show them a beta version in the next few weeks.

But all along I just click the build button on the IDE, and it creates the Jar file and it works just fine.  Of course, the conventional wisdom suggests that I "should" be writing my own Ant/Maven/Gradle scripts and using that instead of the IDE, but what are the concrete advantages of that in my situation (working alone)?

I've done some reading about how to use those build tools, and it just looks like I'd be writing hundreds of lines of XML (or Groovy or whatever) to do to what the IDE does in one click (the IDE-generated Ant XML for the project is over 700 lines).  It just looks error-prone and time-consuming and unnecessary for my situation.  Not to mention the learning curve, which would take away time from all the other work I'm doing to get the product ready to show people.

答:
I'd suggest you look into using Maven as opposed to Ant.  If your IDE can build your project in one click, then it's likely that Maven can also build your project with virtually no custom configuration.

And to answer the question, simplifying the deployment process is one concrete example.  If you're building a distributable locally that means that you have to manually deploy that distributable on your production system, and implies that you probably had to do a fair bit of manual configuration on the production system to get it ready for deployment (installing Tomcat, perhaps, or copying over dependencies and resources required by your application).  This can be time-consuming, and may make deploying updates become a tedious, manual process.  It also allows the potential for any minor configuration differences between your production platform and your development environment to cause obscure, difficult to track down errors.

So anyhow, what I do to get rid of this manual drudgery is that I configure my project to build with Maven, and I configure my pom.xml file with all the information required to (in the case of a Java web-app) find and download the correct version of Tomcat, install it locally, set up the correct Tomcat configuration files, deploy any project dependencies and the project WAR file itself, and then start Tomcat.  I then create a simple shell script (and also a .bat version for Windows) that uses Maven to build and start the server:

```<code>mvn clean install cargo:start -Dcargo.maven.wait=true
</code>```

So instead of packaging up a deployable on my dev environment and then manually pushing it up to production, all I have to do is sync from the version-control system onto the production server, and then the production system itself builds, installs, and runs the deployable (and does it in a way that is identical to how it is done on any development system, minimizing the possibility of platform-specific errors or misconfigurations).  And whether in the development or production environment, all I do to build and start the server is:

```<code>./startServer.sh #or startServer.bat for Windows
</code>```

And to deploy an update to the production environment the process is just:

Stop the running server instance, if any.

Run svn update -r<target_release_revision>.

Run ./startServer.sh.

It's simple, easy to remember, and not at all possible to do if I were to rely on using my IDE to build the deployable for me.  It also makes reverting to the last-known good deployment a snap, should a rollback ever be necessary.

I can't even count the amount of time this approach has saved me over attempting to manually manage the deployment and configuration process.

And of course, another answer to your question is automatic dependency management, but I believe that's been covered already by other answers.

OwnerDisplayName: Gigatron

Body:
I'd suggest you look into using Maven as opposed to Ant.  If your IDE can build your project in one click, then it's likely that Maven can also build your project with virtually no custom configuration.

And to answer the question, simplifying the deployment process is one concrete example.  If you're building a distributable locally that means that you have to manually deploy that distributable on your production system, and implies that you probably had to do a fair bit of manual configuration on the production system to get it ready for deployment (installing Tomcat, perhaps, or copying over dependencies and resources required by your application).  This can be time-consuming, and may make deploying updates become a tedious, manual process.  It also allows the potential for any minor configuration differences between your production platform and your development environment to cause obscure, difficult to track down errors.

So anyhow, what I do to get rid of this manual drudgery is that I configure my project to build with Maven, and I configure my pom.xml file with all the information required to (in the case of a Java web-app) find and download the correct version of Tomcat, install it locally, set up the correct Tomcat configuration files, deploy any project dependencies and the project WAR file itself, and then start Tomcat.  I then create a simple shell script (and also a .bat version for Windows) that uses Maven to build and start the server:

mvn clean install cargo:start -Dcargo.maven.wait=true

So instead of packaging up a deployable on my dev environment and then manually pushing it up to production, all I have to do is sync from the version-control system onto the production server, and then the production system itself builds, installs, and runs the deployable (and does it in a way that is identical to how it is done on any development system, minimizing the possibility of platform-specific errors or misconfigurations).  And whether in the development or production environment, all I do to build and start the server is:

./startServer.sh #or startServer.bat for Windows

And to deploy an update to the production environment the process is just:

Stop the running server instance, if any.

Run svn update -r<target_release_revision>.

Run ./startServer.sh.

It's simple, easy to remember, and not at all possible to do if I were to rely on using my IDE to build the deployable for me.  It also makes reverting to the last-known good deployment a snap, should a rollback ever be necessary.

I can't even count the amount of time this approach has saved me over attempting to manually manage the deployment and configuration process.

And of course, another answer to your question is automatic dependency management, but I believe that's been covered already by other answers.


问:
Why are strings so slow?
Ever since my very first programming class in high school, I've been hearing that string operations are slower — i.e. more costly — than the mythical "average operation." Why makes them so slow? (This question left intentionally broad.)</p>

答:
The phrase "average operation" is probably shorthand for a single operation of a theoretical Random-Access Stored-Program machine.  This is the theoretical machine it's customary to use to analyse the running time of various algorithms.

The generic operations are normally taken to be load, add, subtract, store, branch.   Maybe also read, print and halt.

But most string operations require several of these fundamental operations.   For example, duplicating a string normally requires a copying operation, and hence a number of operations which is proportional to the length of a string (that is, it's "linear").   Finding a substring inside another string also has linear complexity.

Title: Why are strings so slow?


问:
How close have we gotten to automating code writing?
And I don't mean Autocomplete or automatic code snippets as inserted by modern day editors, or polymorphic code. But what is the state-of-the-art in programs that can go through given inputs and types and information of the desired outputs and output a valid piece of code in a language of choice. I am aware of Genetic Programming, Gene Expression Programming but I don't know of any other efforts. Also googling doesn't turn up much.

Is anyone aware of any advancements on this front?

Edit: When i say "output a valid piece of code", I mean an AI or something similar working out the logic and the flow of control and implement it in an imperative language. Imperative language only, since that's the tough part. Nevertheless, if you know of any new languages being developed to support this kind of idea, please do mention, as maybe our current set of languages are not suitable for the kind of early AI we may first chance upon.

答: I've heard murmurs of attempts to derive programs from specifications expressed using dependent types in systems like Coq. I have no idea what kind of progress has been made, though.</p>


答:
A non-IDE build makes it easy to rebuild old versions without worrying about reconfiguring your IDE the way it was at the time, lets you perform the build non-interactively so you can maintain a nightly build for people to test, or find out quickly if you broke tests without having to remember to run them and wait for them to complete.

It also lets you perform builds in non-GUI environments, e.g., ssh'ing to a server, and allows you to switch IDEs without worrying about losing the ability to build your software.

Some build tools help you to automate tagging and deploying releases, come with decent defaults for generating code coverage reports, etc.

When you add more people, a build tool will make sure you're not vulnerable to someone else's poor IDE configuration.  I regularly do screenshares to fix colleagues' Eclipse installations because they don't use build tools (working on that).

The ultimate reason though is that it is something that doesn't need to be done manually, so don't do it manually.  Everything else falls out from that.

Title: Convince a lone developer to use a separate build tool instead of the IDE one-click build

Body:
In my years of programming Java and more recently Scala, I've never used Ant, Maven, Gradle or any of those build tools for Java.  Everywhere I've worked there was a build manager who took care of all of that -- I'd compile locally with the IDE for development and unit testing, then check in the source code and notify the build manager who did what was necessary to compile everybody's files for the shared environment.

Now that I'm between contracts I've been working on my own self-funded project and it's getting to the point where it could be good enough to actually make money.  I even have a potential investor lined up and plan to show them a beta version in the next few weeks.

But all along I just click the build button on the IDE, and it creates the Jar file and it works just fine.  Of course, the conventional wisdom suggests that I "should" be writing my own Ant/Maven/Gradle scripts and using that instead of the IDE, but what are the concrete advantages of that in my situation (working alone)?

I've done some reading about how to use those build tools, and it just looks like I'd be writing hundreds of lines of XML (or Groovy or whatever) to do to what the IDE does in one click (the IDE-generated Ant XML for the project is over 700 lines).  It just looks error-prone and time-consuming and unnecessary for my situation.  Not to mention the learning curve, which would take away time from all the other work I'm doing to get the product ready to show people.


答:
It completely depends on the operation, how strings are represented, and what optimizations exist. If strings are 4 or 8 bytes in length (and aligned), they wouldn't necessarily be slower - many operations would be just as fast as primitives. Or, if all strings have a 32-bit or 64-bit hash, many operations would also be just as fast (though you pay the hashing cost up front).

It also depends on what you mean by "slow". Most programs will process strings plenty fast for what is needed. String comparisons might not be as fast as comparing two ints, but only profiling will reveal what "slow" means to your program.

Title: Why are strings so slow?

Body: Ever since my very first programming class in high school, I've been hearing that string operations are slower — i.e. more costly — than the mythical "average operation." Why makes them so slow? (This question left intentionally broad.)</p>


问:
Technical interview and programmer ability
What I will say might be a tad controversial in nature but I am very disheartened today - and so I will ask this.

I just had an interview with a major tech firm for an internship position, where I was asked a lot of typical algorithm oriented interview questions. Now, given my background, I consider myself to be strong in algorithms (I have also got good grades in graduate level algorithms -stuff involving NP-completeness and beyond (approximation and randomized algorithms), but unfortunately I flunked the interview. I could not think of a very efficient method of solving a string problem in approximately ~10 minutes. Once the interview was over, I had a glass of water, ate a banana and relaxed for a while and tried the problem again. And vola! there is the answer I could arrive in under 5 minutes. And the worst of it all - I was actually on that track and the interviewer did hint about it, but too much pressure cooked me. My entire experience got me thinking about tech interviews. I had some questions and I wanted to pose them in this forum -

Is it really possible to judge someone's technical ability in half an hour? Honestly? Or is it just a throw of dice?

Do technical interview questions measure problem solving ability? This point is very debatable? As a PhD student I know that Mathematical problem solving involves solving something that you have never heard about before. On the other hand questions like - merging two linked lists in sorted order, or printing all the elements of a binary tree in the kth level become "mere exercises" once someone has seen the solution or solved the problem beforehand?

Do people who come out with flying colors in these interview go on to become great programmers? Do they go on and design a sleek game engines, graphics libraries, write fast fork-join frameworks? Is there any evidence to point to a positive co-relation between doing well in technical interviews and actual programming ability? Or are these interviews more geared towards finding "getting things done" type of person (Spolsky)?

I can bet that lots of academics publishing ground breaking ideas in - ICML, VLDB, Mobicom -  will flunk these interviews. But I can assure you that they are some of the smartest people you will find on this planet.

I am mainly in academia (grad student) - so I will greatly appreciate some perceptive from someone in the other side of the fence. Someone who actually conducts these interviews?

[Ok everyone. Thanks for all the nice and thoughtful responses. Since I do not want to ask another question, I will ask you to answer this question for me.

Suppose candidate X has a good public portfolio of works where he has contributed to some known open source project where - you can actually go and verify his patches, verify the bugs he has closed and take a look at the designs he has created. In that case, the question is how much weightage are you willing to give to his publicly available/verifiable work versus how well he does in answering some very contrived binary tree interview question in under 15 minutes?]

答:
Is it really possible to judge someone's technical ability in half and hour?

Not exactly.  It is possible to weed out the folks who can't program at all, and those who can't explain the stuff on their CV.  Beyond that I'm usually just trying to gauge general intelligence and interest in the field.  It's hard to comment on your situation further without knowing the problem you were asked to solve.

Do technical interview questions measure problem solving ability?

That's not the goal of my technical questions.  Instead I am trying to discover whether the candidate has a grasp of the fundamentals of computer science.  To gauge problem-solving ability, I ask a candidate to tell about an interesting problem they worked on.

Do people who come out with flying colors in these interview go on to become great programmers? Or are these interviews more geared towards finding "getting things done" type of person (Spolsky)?

That's about it.   Greatness is rare.  I'm happy to find someone competent.


答:
Yes. Yes, honestly. This is not to say that 30 minutes is enough time to get a complete picture of what a person is capable of. The interviewer's job is to do there best to get a feel for who the interviewee is and what they can do. Finding the people that put something on their resume that they didn't really know is straight forward. Finding out exactly what the interviewee can do, including all their skills and strengths is not.

Yes. They let you see how the interviewee thinks. Getting the correct answer is not always necessary. Seeing someone deal with a problem they struggle with is just as beneficial as seeing someone answer a problem correctly without much trouble. I always ask a question that I think the interviewee might not be able to answer.

I don't know of any empirical proof that says technical interviews find the best candidates, but it is the best thing I have tried. Different people are good at different things and getting technical answers correct is not the only thing that decides if someone get hired. Being a good fit for the company is also very important.

Based on your question, I think the biggest thing you need to understand is that the days clearly defined feedback like a letter grade are over. Getting the right answer is only part of the result. Writing good code, communicating your ideas and listening to others is just as important. However, these areas are more subjective and need to be treated as such.

Just like how you solved the problem, take a step back and clear your head. A lot goes into an interview and the interviewer knows that it is not a perfect system. They are trying to do the best they can for the company, just like you are trying to do the best for you.

Title: Technical interview and programmer ability

Body:
What I will say might be a tad controversial in nature but I am very disheartened today - and so I will ask this.

I just had an interview with a major tech firm for an internship position, where I was asked a lot of typical algorithm oriented interview questions. Now, given my background, I consider myself to be strong in algorithms (I have also got good grades in graduate level algorithms -stuff involving NP-completeness and beyond (approximation and randomized algorithms), but unfortunately I flunked the interview. I could not think of a very efficient method of solving a string problem in approximately ~10 minutes. Once the interview was over, I had a glass of water, ate a banana and relaxed for a while and tried the problem again. And vola! there is the answer I could arrive in under 5 minutes. And the worst of it all - I was actually on that track and the interviewer did hint about it, but too much pressure cooked me. My entire experience got me thinking about tech interviews. I had some questions and I wanted to pose them in this forum -

Is it really possible to judge someone's technical ability in half an hour? Honestly? Or is it just a throw of dice?

Do technical interview questions measure problem solving ability? This point is very debatable? As a PhD student I know that Mathematical problem solving involves solving something that you have never heard about before. On the other hand questions like - merging two linked lists in sorted order, or printing all the elements of a binary tree in the kth level become "mere exercises" once someone has seen the solution or solved the problem beforehand?

Do people who come out with flying colors in these interview go on to become great programmers? Do they go on and design a sleek game engines, graphics libraries, write fast fork-join frameworks? Is there any evidence to point to a positive co-relation between doing well in technical interviews and actual programming ability? Or are these interviews more geared towards finding "getting things done" type of person (Spolsky)?

I can bet that lots of academics publishing ground breaking ideas in - ICML, VLDB, Mobicom -  will flunk these interviews. But I can assure you that they are some of the smartest people you will find on this planet.

I am mainly in academia (grad student) - so I will greatly appreciate some perceptive from someone in the other side of the fence. Someone who actually conducts these interviews?

[Ok everyone. Thanks for all the nice and thoughtful responses. Since I do not want to ask another question, I will ask you to answer this question for me.

Suppose candidate X has a good public portfolio of works where he has contributed to some known open source project where - you can actually go and verify his patches, verify the bugs he has closed and take a look at the designs he has created. In that case, the question is how much weightage are you willing to give to his publicly available/verifiable work versus how well he does in answering some very contrived binary tree interview question in under 15 minutes?]


问:
Simple questions about apache and cgi
I'm just learning about using cgi in html files. I've read a lot of stuff on the web, but most of it is all about the trees and not enough about the forest. I'm a top-down learner and I'm having trouble understanding what's going on with cgi, apache, and html. At the moment I'm using python as my cgi scripting language, but if you'd care to answer using perl, I can handle that. Here's a MWE for a failed test I ran.

HTML: (file is getname.html)

```<code><html>
<head></head>
<body>
<form method="POST" action="./test.py">
  <p>Your First Name: <input type="text" name="firstname">
  <p>Click here to submit form: <input type="submit" value="Submit">
  <input type="hidden" name="session" value="1f9a2">
</form>
</body>
</html>
</code>```

Python: (file is test.py)

```<code>#!/usr/bin/python
import sys, os, os.path, shutil, string, fileinput
import cgi, cgitb

print "Content-type: text/html\n"
form = cgi.FieldStorage()
f = open('./testOutput', 'w')
if form.has_key("firstname"):
    f.write(form["firstname"])
else:
    f.write("Failure")
f.close()
</code>```

So, it looks like what's happening is that the info the user enters into the form is put into a variable called 'firstname' (actually it's a key-value pair put into a hash-like thing in the scripting language. In python it's a dictionary). This variable is then sent as input to the cgi script (test.py), and the script is run.

But, that isn't what's happening. When I hit the 'Submit' button in the html file, the test.py script is displayed in the browser and the script isn't run. BTW, the reason that I have the script write to a file is so I can see whether it gets run. When I run test.py from the command line, it works fine.

The fact that test.py is displayed in my browser indicates, I think, that apache isn't running or is misconfigured or has permission problems. As far as I can see, none of those things is true, but I could be wrong. So here are my questions:
   1) why is apache involved at all? Is it needed to send the variables gathered in the html form to the script? If so, why? I know that html is just a markup language, but I thought the 'form' tag had the ability to send a variable to a script and run the script.
   2) Is there a way to test an apache configuration? Is it possible for apache to use 127.0.0.1 as the 'ServerName' (i.e. ServerName 127.0.0.1:80 in my httpd.conf file)

Basically, I just want to write cgi scripts for some webpages I'm hand-coding and test them on my home laptop. I don't seem to know how to do that and I could use some help.   TIA.

答:
You need to tell apache that files ending in ".py" are scripts and not just plain text files.

To do this you need to modify the "httpd.conf" file the line in question probaly looks like:

```<code>AddHandler cgi-script .cgi .pl .asp
</code>```

You need to add the '.py' python extension to this line:

```<code>AddHandler cgi-script .cgi .pl .asp .py
</code>```

There may be more to this depending on which distribution of Apache you installed full details are here:-
How To

If you intend to develop this further I would recommend you install apache's "mod_python"
which will run your scripts inside apache and keep a python interpreter ready and waiting for new requests, rather, than firing up a python script in separate process for every request.

Title: Simple questions about apache and cgi

Body:
You need to tell apache that files ending in ".py" are scripts and not just plain text files.

To do this you need to modify the "httpd.conf" file the line in question probaly looks like:

AddHandler cgi-script .cgi .pl .asp

You need to add the '.py' python extension to this line:

AddHandler cgi-script .cgi .pl .asp .py

There may be more to this depending on which distribution of Apache you installed full details are here:-
How To

If you intend to develop this further I would recommend you install apache's "mod_python"
which will run your scripts inside apache and keep a python interpreter ready and waiting for new requests, rather, than firing up a python script in separate process for every request.


问:
Should I care about Junit redundancy when using setUp() with @Before annotation?
Even though developers have switched from junit 3.x to 4.x I still see the
following 99% of the time:

```<code>@Before
public void setUp(){/*some setup code*/}

@After
public void tearDown(){/*some clean up code*/}
</code>```

Just to clarify my point... in Junit 4.x, when the runners are set up correctly, the framework will pick up the @Before and @After annotations no matter the method name. So why do developers keep using the same conventional junit 3.x names? Is there any harm keeping the old names while also using the annotations (other than it makes me feel like devs do not know how this really works and just in case, use the same name AND annotate as well)?

Is there any harm in changing the names to something maybe more meaningful, like
eachTestMethod() (which looks great with @Before since it reads 'before each test method') or initializeEachTestMethod()?

What do you do and why?

I know this is a tiny thing (and may probably be even unimportant to some), but it is always in the back of my mind when I write a test and see this. I want to either follow this pattern or not but I want to know why I am doing it and not just because 99% of my fellow developers do it as well.

答:
People use the same method names because it is a convention and people know it already. There is nothing exactly wrong with using a different name, it makes things a little harder. I don't think your examples are any clearer than just using setUp().

At the end of the day, people do it because 99% of their fellow developers do it. If you have a test class that is doing something very distinctive in it's setup method that you think a more specific name helps, then you can do that. However, at the same time, I would consider taking a second look at the test if it's setup method is doing enough work that setUp() isn't descriptive enough. Does the test have too many dependencies? Can you break it down into smaller units?


答:
I agree with soe of the comments above. 7 for me is arbitary and may be useful in some languages where ruby, but for languages like C#, Java, C++ I doubt this "7 line" convention. Let me give you an example.My current application has 22 text fields and I do server side validation. The method is called validateInput() and my preference is validate all the fields in one method itself unless I have validate something complex like checkEmailFormat(). So basically my validateInput method code is 108 lines with occasional calls to complex validation.

Now imagine if I called 25 methods to validate each field. If a new developer comes in he will have to go in and out of the main method to jump through 25 methods which in turn might be calling a few other. He is bound to get lost in big projects.

What I really do to make my code clear is provide clean comments which basically say what these 4 lines are doing ex -

validateInput(UserObj user){

//Validate first name
.......
......

//validate last Name
......
......

//validate email
..... //too complex to check email format regular expresion
checkEmailFormat();
....
.....

and so on..
}

Title: Coding Guideline : Methods shouldn't contain more than 7 statements?

Body:
I was looking through the AvSol Coding Guidelines for C# and I agree with nearly everything but I'm really curious to see what other think of one specific rule.

AV1500

Methods should not exceed 7 statements  A method that requires more
  than 7 statements is doing too much, or has too many responsibilities.
  It also requires the human mind to analyze the exact statements to
  understand what the code is doing. Break it down in multiple small and
  focused methods with self-explaining names.

Do most of you follow this rule? Even if there's little to be saved from creating a new method (Your code is still DRY) aside from greatly increasing readability?  And is your number still as low as 7?    I would tend more toward 10.

I'm not saying I violate this rule all over the place--on the contrary, my methods are 95% small and focused but saying you should never violate this rule really blew me away.

I really just want to know what everyone thinks of NEVER violating this rule (It's a '1' on the coding standard--meaning NEVER do this).  But I think you'd have trouble finding a codebase that doesn't.


答:
"1) why is apache involved at all? Is it needed to send the variables gathered in the html form to the script? If so, why? I know that html is just a markup language, but I thought the 'form' tag had the ability to send a variable to a script and run the script"

CGI is a form of server-side scripting, a CGI script runs on the web server, not on the web client. There is also client-side scripting. These days that usually takes the form of Javascript embedded in script tags in HTML documents. This is unrelated to CGI.

At root, your web browser really only has two jobs: requesting data from other computers via a network protocol called HTTP, and rendering the data it gets back in some pretty fashion on your screen. The only thing your browser knows about your web form is that is that when you press the submit button, it should send a request to some Internet address with the name of the script and the data from the form. The browser doesn't know anything about Python, or where in the file system the document 'test.py' lives. It doesn't even know that 'test.py' is a script.

Another piece of software has to be running to receive the browser's requests, look up the data it asks for, and send it back to the browser. That other piece of software is the web server, in this case Apache. Apache has to be configured so that when it gets the request for 'test.py" from the browser, it knows where test.py is in the file system, that when it sees a request for a file ending in ".py" it shouldn't just transmit the contents of the file back to the browser, but rather that is should start a copy of the python interpreter using that script, pass it the form data that came with the request, and then send the output of the script back to the browser.

One issue that may be making this more confusing for you: I ove-simplified when I said your browser really only has two jobs. As a convenience, most browsers can also act as local file viewers, that is, you can do an "File Open" on a local file, and the browser will render that file, without having requested it from a web server. The browser still won't know anything about running scripts unless they're embedded in a script tag as part of an HTML document.

Title: Simple questions about apache and cgi

Body:
I'm just learning about using cgi in html files. I've read a lot of stuff on the web, but most of it is all about the trees and not enough about the forest. I'm a top-down learner and I'm having trouble understanding what's going on with cgi, apache, and html. At the moment I'm using python as my cgi scripting language, but if you'd care to answer using perl, I can handle that. Here's a MWE for a failed test I ran.

HTML: (file is getname.html)

```<code><html>
<head></head>
<body>
<form method="POST" action="./test.py">
  <p>Your First Name: <input type="text" name="firstname">
  <p>Click here to submit form: <input type="submit" value="Submit">
  <input type="hidden" name="session" value="1f9a2">
</form>
</body>
</html>
</code>```

Python: (file is test.py)

```<code>#!/usr/bin/python
import sys, os, os.path, shutil, string, fileinput
import cgi, cgitb

print "Content-type: text/html\n"
form = cgi.FieldStorage()
f = open('./testOutput', 'w')
if form.has_key("firstname"):
    f.write(form["firstname"])
else:
    f.write("Failure")
f.close()
</code>```

So, it looks like what's happening is that the info the user enters into the form is put into a variable called 'firstname' (actually it's a key-value pair put into a hash-like thing in the scripting language. In python it's a dictionary). This variable is then sent as input to the cgi script (test.py), and the script is run.

But, that isn't what's happening. When I hit the 'Submit' button in the html file, the test.py script is displayed in the browser and the script isn't run. BTW, the reason that I have the script write to a file is so I can see whether it gets run. When I run test.py from the command line, it works fine.

The fact that test.py is displayed in my browser indicates, I think, that apache isn't running or is misconfigured or has permission problems. As far as I can see, none of those things is true, but I could be wrong. So here are my questions:
   1) why is apache involved at all? Is it needed to send the variables gathered in the html form to the script? If so, why? I know that html is just a markup language, but I thought the 'form' tag had the ability to send a variable to a script and run the script.
   2) Is there a way to test an apache configuration? Is it possible for apache to use 127.0.0.1 as the 'ServerName' (i.e. ServerName 127.0.0.1:80 in my httpd.conf file)

Basically, I just want to write cgi scripts for some webpages I'm hand-coding and test them on my home laptop. I don't seem to know how to do that and I could use some help.   TIA.


答:
Very few people know whether their interview techniques really work, because they never learn more about those who failed.  But when nothing disproves their hypothesis they take it as confirmation that they are true.  So there is a definite element of throwing the dice.

If the economic theories saying markets are rational and efficient were true, then companies would look to hire people that were bad an interviewing in ways that would not make them bad at their job.  So someone who wore an ill-fitting suit, sweated, appeared very nervous, and had trouble doing technical problems under the pressure of an interview - if there was outside evidence they could otherwise do technical problems and the pressures of the job were not like those of an interview (as they generally are not) - would represent a company's best chance of getting a candidate better than it could otherwise attract and it would act accordingly.  (Think Money-ball for the corporate world).  Eventually interview biases would vanish.

In practice this goes against human nature.  Interviewers like confident extroverts, no matter what the position, and even if the technical interview provides worse information than the resume and references (as perhaps is true in your case) they will take it into account.

As to your questions:

Somewhat.  The tests have a poor signal to noise ratio but can be tuned to weed out the completely unqualified at the expense of the qualified-but-bad-at-technical-interviews.

See #1.  Part of the noise comes from variation in whether people have seen the problem before.

See #1.  There is probably a tiny positive correlation between these tests and becoming a great programmer.

My advice - Study some sample technical questions to get a basic familiarity.  Remember it's a bit of a roll of the dice, so during the interview try to be confident.  If you can explain what you are thinking without distracting yourself from actually thinking then do so.  If it's really going badly, admit you get nervous at interviews and let them know it seems like something you normally wouldn't have trouble with - possibly giving an example of a similar but harder problem you did solve.


答:
Keep in mind that...

The main goal of an interview process is not to arrive at absolute truth about each interviewees personal ability but to select few candidates from a pool of many.

It is MUCH, MUCH more expensive to hire a bad developer than it is to pass on a good one.

So a lot of times when interviewing, imperfect shortcuts (such as technical quizzes) are taken because as you mentioned, there's no perfect process for being able to judge a person in 30 minutes. But since most don't have the luxury of working with you side-by-side, you should just accept that it is what it is, an odds game that everyone plays.


问:
Should I require users to register to use my app?
So I'm very close to releasing an app I've been working on, and the server I integrate with allows me to register users.  So I was wondering if I should require users to register with the app before they use it.  The app wouldn't "need" the registration for any of the features (although I have some ideas about future updates where the user's data could be saved to their account in the cloud), but it would still be nice to have a list of registered users.

One reason I think I should require users to register is because when the app launches for the first time, the user must accept my privacy policy and terms of use; so if I made a registration screen, it might be an easier and more straightforward, rather than bombarding the user with the thick legal language.

But I'm afraid requiring the user to register will cost me some users.  I once downloaded an app, and it wanted me to register, but I was lazy never did.  Is that a legitimate fear with requiring registration?

Thanks!

Edit:
To clearify, if I was to require registration, what info should I collect: name, email, password?  other?  And we wouldn't be spamming them with emails at all.  We also have a very strong privacy policy and would store all data securely.

答:
But I'm afraid requiring the user to register will cost me some users.

Yup.  There's no doubt about that.

I once downloaded an app, and it wanted me to register, but I was lazy never did.

That's one reason to not want to register.

Another reason is that people have no way of knowing what you'll do with any personal information they provide you.  For instance, everyone knows that each time you give out your email address, you risk increasing the amount of unwanted email in your inbox.  And much worse things than that can happen.

Is that a legitimate fear with requiring registration?

Yup.

Your edits don't change anything:

To clearify, if I was to require registration, what info should I collect: name, email, password? other?

My vote would be for none of the above ... unless it was an entirely optional registration.  Even then, you should never collect passwords.  NEVER.

And we wouldn't be spamming them with emails at all. We also have a very strong privacy policy and would store all data securely.

That's what you say.  But why what reason has the user got to believe you / your company?  And what happens when your company is take over or liquidated by some other entity that has a different view on privacy issues?


问:
Should developers enter bugs into the bug tracking system?
While developing (either features or bug fixes) I sometimes happen to discover bugs that are not directly related to what I'm working on.  What should I do in that situation.  Just fix it?  Try to remember to fix it later?  Write it down somewhere?  Or enter it into the bug tracking system?

I generally enter it into the bug tracking system and let the process play itself out (i.e. triaging, assigning, etc.).  However I have hardly ever seen another developer enter a bug.  (Why is that?)

答:
If you see something then say something!

I even enter bug reports about my own modules because I do not want to interrupt my current task.  And I can ensure all the steps to reproduce are included :-)

And it's even better when someone else can see that you've listed something as a known bug. They like to know someone else has found it too.


问:
Can't I just use all static methods?
What's the difference between the two UpdateSubject methods below? I felt using static methods is better if you just want to operate on the entities. In which situations should I go with non-static methods?

```<code>public class Subject
{
    public int Id {get; set;}
    public string Name { get; set; }

    public static bool UpdateSubject(Subject subject)
    {
        //Do something and return result
        return true;
    }
    public bool UpdateSubject()
    {
        //Do something on 'this' and return result
        return true;
    }
}
</code>```

I know I will be getting many kicks from the community for this really annoying question but I could not stop myself asking it.

Does this become impractical when dealing with inheritance?

Update:

Its happening at our work place now.
We are working on a 6 month asp.net web application with 5 developers. Our architect decided we use all static methods for all APIs. His reasoning being static methods are light weight and it benefits web applications by keeping server load down.

答:
The reason people argue that 'static methods show bad design' isn't necessarily due to the methods, it's actually static data, implicit or explicit.  By implicit I mean ANY state in the program that isn't contained in the return value(s) or parameters.  Modifying state in a static function is a throwback to procedural programming.  However if the function does not modify state, or delegates state modification to component object functions, it's actually more a functional paradigm than procedural.

If you're not changing state, static methods and classes can have many benefits.  It makes it much easier to ensure a method is pure, and thus free of side effects and any errors are fully reproducible.  It also ensures that different methods in multiple applications using a shared library can be assured they will get the same results given the same input, making both error tracking and unit testing much easier.

Ultimately there's no difference in practice between oversized objects commonly seen such as 'StateManager' and static or global data.  The benefit of static methods used correctly is they can indicate the author's intent to not modify state to later revisers.

Title: Can't I just use all static methods?


问:
Users creating instances from a template - is there a software pattern that corresponds to this use case?
I am looking into designing a system where users build a template item and then create many instances based on this template.They then need to be able customise each instance but I also need for them to be able to make changes to the template and have all instances updated. These items are fairly complex, each consisting of many components that will be stored in numerous database tables.

I see two implementation paths.

Store complete copies of the templates to create the instances and
migrate updates to the instances.

Store records only for the changes and build each instance from a combination of the template and instance changes.

I believe the first option would create a lot of unneeded extra data however the 2nd way introduces complexities in querying the data.

This seems like it has probably been implemented many times before but I am having trouble finding much reading material. Are there common names for data models or pattern options used in implementations of such systems?

Any advice on benefits or pitfalls of each option, other options, or implementation guidance would be useful too.

edit:

Sorry I may not have been clear. I was looking more for a name for the general architecture not a design pattern. It is the end users who create instances not developers.

For example the system might allow users to define templates to model manufacturing processes of many items. Then at different sites where facilities or requirements are different, the end user would would use one of these templates to define a process specific for that site. Things will be added, removed and modified for each site.

I believe I will go with option two mentioned above - storing only delta changes, not complete copies.

答:
When I first read your question, GoF's Prototype Pattern came to mind.

However, in general design patterns apply to relatively low levels (most of them involve relationships between just few classes).  Also when you use patterns, you only use the idea but implement your own code.  That idea simply lets you implement your code faster because you are coding something that has already been thought out to some degree by someone else.

What you are looking for is not really a design pattern because the scale/scope of what you are achieving to do is much larger.  And as far as I understand, you are actually curious if someone out there has something that does what you want.  In other words, you are looking for a framework.

I'm not aware of any generic frameworks that you could reuse, but if you are curious if anyone out there did anything similar, I think Microsoft's Dependency Property framework that is part of WPF fits the bill.  Each object, which has to derive from DependencyObject root class, has a set of properties and in some cases these sets are very big.  Property values can come from object itself (what you call instance values), or they can come from styles, templates, themes, or system defaults.

Dependency objects implement your option (2). They only store locally what was modified on that instance and each property value is calculated at runtime by walking a set of sources where the property value could possibly come from.

Although I never thought about it, but I guess you could derive your own set of classes from DependencyObject and take advantage of the entire framework while not coding anything WPF-specific.


问:
What are hooks?
I keep coming across this term hooks in various programming articles. However I don't understand what they are, and how can they be used. So I just wanted to know what is the concept of hooks; if someone could link me to some examples, particularly in the context of web development, it would be great.</p>

答:
My answer pertains to WordPress which is written in PHP, but this is a general development mechanic so it shouldn't really matter, despite the fact that you put 'python' in your question title.

One good example of usage of hooks, coincidentally in web development, are WordPress' hooks.

They are named appropriately in that they allow a way to 'hook into' certain points of the execution of a program.

So for example, the wp_head is an 'action' that is emitted when a WordPress theme is being rendered and it's at the part where it renders the part that's within the  tags. Say that you want to write a plugin that requires an additional stylesheet, script, or something that would normally go within those tags. You can 'hook into' this action by defining a function to be called when this action is emitted. Something like:

```<code>add_action('wp_head', 'your_function');
</code>```

your_function() could be something as simple as:

```<code>function your_function() {
    echo '<link rel="stylesheet" type="text/css" href="lol.css" />';
}
</code>```

Now, when WordPress emits this action by doing something like do_action('wp_head');, it will see that your_function() was 'hooked into' that action, so it will call that function (and pass it any arguments if it takes any, as defined in the documentation for any particular hook).

Long story short: It allows you to add additional functionality at specific points of the execution of a program by 'hooking into' those points, in most cases by assigning a function callback.

Title: What are hooks?

Body:
My answer pertains to WordPress which is written in PHP, but this is a general development mechanic so it shouldn't really matter, despite the fact that you put 'python' in your question title.

One good example of usage of hooks, coincidentally in web development, are WordPress' hooks.

They are named appropriately in that they allow a way to 'hook into' certain points of the execution of a program.

So for example, the wp_head is an 'action' that is emitted when a WordPress theme is being rendered and it's at the part where it renders the part that's within the <head> tags. Say that you want to write a plugin that requires an additional stylesheet, script, or something that would normally go within those tags. You can 'hook into' this action by defining a function to be called when this action is emitted. Something like:

add_action('wp_head', 'your_function');

your_function() could be something as simple as:

function your_function() {
    echo '<link rel="stylesheet" type="text/css" href="lol.css" />';
}

Now, when WordPress emits this action by doing something like do_action('wp_head');, it will see that your_function() was 'hooked into' that action, so it will call that function (and pass it any arguments if it takes any, as defined in the documentation for any particular hook).

Long story short: It allows you to add additional functionality at specific points of the execution of a program by 'hooking into' those points, in most cases by assigning a function callback.