问:
Mercurial Repository structure with heavyweight corporate comms, configuration management & test requirements
I am yet another Subversion user struggling to re-educate myself in the Tao of distributed version control.

When using Subversion, I was a big fan of the project-minor approach, and, with most of my former employers, we would structure our repository branches; tags & trunk as follows:

```<code>branches-+
         +-personal-+
         |          +-alice-+
         |          |       +-shinyNewFeature
         |          |       +-AUTOMATED-+
         |          |                   +-shinyNewFeature
         |          +-bob-+
         |                +-AUTOMATED-+
         |                            +-bespokeCustomerProject
         +-project-+
                   +-shinyNewFeature
                   +-fixStinkyBug
tags-+
     +-m20110401_releaseCandidate_0_1
     +-m20110505_release_0_1
     +-m20110602_milestone
trunk
</code>```

Within the actual source tree itself, we would use (something like) the following structure:

```<code>  (src)-+
        +-developmentAutomation-+
        |                       +-testAutomation
        |                       +-deploymentAutomation
        |                       +-docGeneration
        |                       +-staticAnalysis
        |                       +-systemTest
        |                       +-performanceMeasurement
        |                       +-configurationManagement
        |                       +-utilities
        +-libraries-+
        |           +-log-+
        |           |     +-build
        |           |     +-doc
        |           |     +-test
        |           +-statistics-+
        |           |            +-build
        |           |            +-doc
        |           |            +-test
        |           +-charting-+
        |           |          +-build
        |           |          +-doc
        |           |          +-test
        |           +-distributedComputing-+
        |           |                      +-build
        |           |                      +-doc
        |           |                      +-test
        |           +-widgets-+
        |                     +-build
        |                     +-doc
        |                     +-test
        +-productLines-+
        |              +-flagshipProduct-+
        |              |                 +-coolFeature
        |              |                 +-anotherCoolFeature
        |              |                 +-build
        |              |                 +-doc
        |              |                 +-test
        |              +-coolNewProduct
        +-project-+
                  +-bigImportantCustomer-+
                  |                      +-bespokeProjectOne
                  |                      +-bespokeProjectTwo
                  +-anotherImportantCustomer-+
                                             +-anotherBespokeProject
</code>```

The idea was (and still is) to use the structure of the repository to help structure communication between the engineering team; the customer-facing part of the business and various other stakeholders & domain experts.

To wit: Source documents that sit in one of the "project" directories get used (and earn money) only once. Documents that sit in one of the "productLines" directories earn money as many times as a product from that particular line gets sold. Documents that sit in one of the "libraries" directories earn money as many times as any of the products that use them get sold.

It makes the notion of amortization of costs explicit, and helps build support for source document reuse across the business.

It also means that there is a common structure over which our build automation tools can operate. (Our build scripts walk the source tree looking for "build" folders within which they find configuration files specifying how each component is to be built; a similar process happens for documentation generation and testing).

Significantly, the products on which I work typically take a LONG time to run performance measurement & characterization tests; from 20 to 200 hours; generating somewhere between several GB to several TB of processed test results/intermediate data (that must be stored and tied to a particular system configuration so performance improvement over time can be measured). This issue makes configuration management an important consideration, and also imposes some requirement for centralisation, as typically the computational resources needed to run the performance measurement and characterization tests are limited; (a small cluster of 64-128 cores).

As one final note; the continuous integration system knows that it needs to trigger a build; static analysis; smoke test & unit test run each time trunk is modified, each time any "tag" branch is modified, and each time any "AUTOMATED" branch branch is modified. This way, individual developers can use the CI system with their personal branches, an important capability, IMHO.

Now, here is my question: How can I replicate all of the above (and improve upon it, if possible), with Mercurial.

--edit:

My current line of thinking is to use a central Subversion Repository, to define the overall structure, but to allow the use of hg as a client so developers can have repos available locally.

答:
Spoike's answer is excellent, but there are a few things I think it would be worth adding which are too large for comments.

Branch organisation

With Mercurial you can happily ignore the whole of your first organisational chart. As Spoke says, each repository has it's own set of tags, branches (named and anonymous) and can be organised according to business need.

If bespokeProjectTwo needs a special version of the charting library, then you would branch charting, add the new facilities and use it in bespokeProjectTwo. The new facilities (and their bugs) would not be used by other projects which would reference the standard charting library. If the main charting library had bugs fixed, you could merge those changes into the branch. If other projects also needed these facilities, you could either get those projects to use the special branch, or merge the branch up into the main-line and close the branch.

Also, there is nothing stopping you having a policy to structure branch names to provide specific facilities like your AUTOMATION branches.

Directory organisation

There is no reason why you can't keep your source directory exactly as it is with Mercurial. The only difference is that whereas with Subversion you have a single monolithic (src) repository, with Mercurial you are better off splitting into repositories which are logically grouped. From your source tree structure, I would probably extract out each of the following as individual repositories:

```<code>src-+
      +-(developmentAutomation)
      +-libraries-+
      |           +-(log)
      |           +-(statistics)
      |           +-(charting)
      |           +-(distributedComputing)
      |           +-(widgets)
      +-productLines-+
      |              +-(flagshipProduct)
      |              +-(coolNewProduct)
      +-project-+
                +-bigImportantCustomer-+
                |                      +-(bespokeProjectOne)
                |                      +-(bespokeProjectTwo)
                +-anotherImportantCustomer-+
                                           +-(anotherBespokeProject)
</code>```

This allows any product or bespoke project to use any combination of libraries, at any revision. Have a look at mercurial sub-repositories for an easy way to manage which libraries are used for any given version of a product or project.

Workflow

An alternative to Spoike's suggested workflow (developer pulls from blessed repo, works locally, issues a pull request and finally the integrator pulls those changes & merges them) would be to use the continuous integration system as an intermediary.

As before, the developer pulls from blessed repo and works locally, but when done, they pull from the blessed repo again and merge themselves before pushing to an unblessed repo. Any changes to the unblessed repo are then reviewed (either manually or automatically) and moved to the blessed repo only if they are approved.

This means that the integrator only has accept or reject a change, not do the merge. In my experience it is almost always better for the developer who wrote the code to perform the merge than for someone else to do it.

As suggested in the mercurial book, hooks can be used to automate this procedure:

When someone pushes a changeset to the server that everyone pulls from, the server will test the changeset before it accepts it as permanent, and reject it if it fails to pass the test suite. If people only pull changes from this filtering server, it will serve to ensure that all changes that people pull have been automatically vetted.

Other issues

The problem of large test datasets can also be solved by putting that test data into a mercurial sub-repository. This will prevent the code repository getting bloated with test data, while still keeping the test data under revision control.

Body:
Spoike's answer is excellent, but there are a few things I think it would be worth adding which are too large for comments.

Branch organisation

With Mercurial you can happily ignore the whole of your first organisational chart. As Spoke says, each repository has it's own set of tags, branches (named and anonymous) and can be organised according to business need.

If bespokeProjectTwo needs a special version of the charting library, then you would branch charting, add the new facilities and use it in bespokeProjectTwo. The new facilities (and their bugs) would not be used by other projects which would reference the standard charting library. If the main charting library had bugs fixed, you could merge those changes into the branch. If other projects also needed these facilities, you could either get those projects to use the special branch, or merge the branch up into the main-line and close the branch.

Also, there is nothing stopping you having a policy to structure branch names to provide specific facilities like your AUTOMATION branches.

Directory organisation

There is no reason why you can't keep your source directory exactly as it is with Mercurial. The only difference is that whereas with Subversion you have a single monolithic (src) repository, with Mercurial you are better off splitting into repositories which are logically grouped. From your source tree structure, I would probably extract out each of the following as individual repositories:

src-+
      +-(developmentAutomation)
      +-libraries-+
      |           +-(log)
      |           +-(statistics)
      |           +-(charting)
      |           +-(distributedComputing)
      |           +-(widgets)
      +-productLines-+
      |              +-(flagshipProduct)
      |              +-(coolNewProduct)
      +-project-+
                +-bigImportantCustomer-+
                |                      +-(bespokeProjectOne)
                |                      +-(bespokeProjectTwo)
                +-anotherImportantCustomer-+
                                           +-(anotherBespokeProject)

This allows any product or bespoke project to use any combination of libraries, at any revision. Have a look at mercurial sub-repositories for an easy way to manage which libraries are used for any given version of a product or project.

Workflow

An alternative to Spoike's suggested workflow (developer pulls from blessed repo, works locally, issues a pull request and finally the integrator pulls those changes & merges them) would be to use the continuous integration system as an intermediary.

As before, the developer pulls from blessed repo and works locally, but when done, they pull from the blessed repo again and merge themselves before pushing to an unblessed repo. Any changes to the unblessed repo are then reviewed (either manually or automatically) and moved to the blessed repo only if they are approved.

This means that the integrator only has accept or reject a change, not do the merge. In my experience it is almost always better for the developer who wrote the code to perform the merge than for someone else to do it.

As suggested in the mercurial book, hooks can be used to automate this procedure:

When someone pushes a changeset to the server that everyone pulls from, the server will test the changeset before it accepts it as permanent, and reject it if it fails to pass the test suite. If people only pull changes from this filtering server, it will serve to ensure that all changes that people pull have been automatically vetted.

Other issues

The problem of large test datasets can also be solved by putting that test data into a mercurial sub-repository. This will prevent the code repository getting bloated with test data, while still keeping the test data under revision control.


问:
Evidence of Bad Design: Updating feature A breaks/interferes with existing feature B
I am working on a Javascript Web App & I am finding as I expand the program & add new features(new animations) it causes existing features to break or work differently than prior to adding that new feature. So as I continue to finish the app, it keeps breaking old features & I have to go back & redo/update those features. So it seems I never complete a feature because I am always coming back to it so I can get it to work nicely with other features.

Is this indicative of bad application design? Or is this a normal feature of computer programming, ie just like how in any program you will spend 20% of time developing the program & 80% of the time fixing bugs(or is it maintaining the program?)?

Are there design &/or any other techniques I can employ to avoid having this problem occur?

The application is a renderer (which takes an XML file which contains information about objects that perform animations - move around, fade etc.) that creates HTML elements & animates them.

The design is OOP, with as close as you can get to classes in Javascript by using prototype. It employs ALOT of multiple inheritence. It also makes use of the anonymous functions where possible so I think it would be very much like a Java project because they both have OOP, anon functions & inheritence. There is a class purely dedicated towards animation called AnimatedObject & many objects inherit from this class. You just perform an animation by simply calling a function from that class such as myAnimObj.performFade() or myAnimObj.performRotate().

答:
Are there design &/or any other techniques I can employ to avoid
  having this problem occur?

When you say that updating feature A breaks/interferes with existing feature B, it sounds like the code is written non-orthogonaly. Generally you want to have youre code written orthogonally (see this question for good reasons for why).

ContentLicense: CC BY-SA 3.0


问:
Years experience over unfinished degree?
I'm currently in my placement year and working for a great software development company. It was always my intention of getting to this stage through university, getting enough academic experience as well as the year’s placement and then try to get a full time programming job without the need to finish my degree. I decided this from an early stage as I have never really liked the whole university environment. I was so unhappy at university and I’m so happy now I’m on my placement year, I really don’t know if I can go back.

My question is, do you think companies will take me on if I apply for other jobs after my placement year and not penalize me for not finishing my degree?

I guess at the end of the day I don't want to look back on my life and think "god, why didn't I just spend one more year being unhappy to have a job I love" but I know that even if I get a degree I could still end up without a programming job and this worries me more than anything.

答:
1)University degrees are overrated. Who taught the first photographer to take pictures? Expertise is gained over time and with passion/love forr what you do.

Don't believe me?

In 1997 I wanted to be a developer. I was not able to go to university and had to go through a correspondence college to learn basic Java and OOP concepts. I was presented with out of date material and had to find my own resources through Oreilly/online materials.

Unkowingly I had a brain tumor at the time which was discovered in 2010. The size of an orange! Yet I managed to pass SCJP, SCJD, SCBCD, and SWCD. My grades weren't perfect and I evn tempted to get a job, but was unable to cope due to the tumor.

In 2011 After 5 brain surgeries (2 were major 5 hour surgeries). I continue to develop and learn programming. Mostly thanks to online communities and Oreilly.

I don't know if I can continue in this field given my ongoing battle, but surely drive/passion must mean more than a degree?


问:
Best way to get programmers to ask for help when they get stuck
What is the best way to ensure that programmers ask for help when they get stuck on a problem, rather than spending too much time trying to figure something out when they've hit a wall?

I'm especially interested in how to optimize this with a distributed team.

Some ideas that come to mind:

pair programming

co-locating the team

timeboxes (after expiration, must ask for help)

Things (goals) to think about:

avoid developing dependence on others

maximize learning & knowledge transfer

cost of developer A's time to help vs. developer B's time to figure it out him/herself

There is also the concern that even if a developer comes up with a solution, it may be of lower quality than if they had asked for help.  I believe code reviews are a good way to address this.

This question: When do you not give help to less experienced programmers? is good background reading for this one.

答:
Do you know why people are not asking for help? Is it because asking for help is seen as a weakness; an inability to do their jobs properly? Additionally, what about people asking for help and not getting effective support?

In my view, if that sort of culture exists, you're going to have problems changing it because that is a top down issue.


问:
What are concrete rules for using a linked list instead of an array?
A linked list can be used when you want cheap insertion and deletion of elements and when it doesn't matter that the elements aren't next to each other in memory.

This is very abstract and I would like a concrete explanation of why a linked list should be used rather than an array. I'm not very experienced with programming, so I haven't got much (if any) real-world experience.

答:
A linked list can be used to implement a message queue.

A message queue is a structure in which we store information about events for later processing. For example, when the user presses a key or moves the mouse, this is an event. An application might be busy at the moment when the event occurs, so it cannot be expected to process the event at the precise moment when it occurs. So, the event is placed in a message queue, (information about which key was pressed, or where the mouse has moved,) and when the application has some time to spare, it checks its message queue, fetches events from it, and process them. (This happens within a time frame of milliseconds, so it is not noticeable.)

From the usage scenario that I just described, it should be obvious that we never care to have random access to events stored in the message queue; we only care to be able to store messages in it, and retrieve them. So, it makes sense to use a linked list, which provides optimal insertion/removal time.

(Please do not butt in to point out that a message queue is likely, or more likely, or almost as likely, to be implemented using a circular array-list; that's a technical detail, and it has a limitation: you can only store a limited number of messages in it.)


答:
Hashtables that use chaining to resolve hash collisions typically have one linked list per bucket for the elements in that bucket.

Simple memory allocators use a free list of unused memory regions, basically a linked list with the list pointer inside the free memory itself

In a FAT filesystem, the metadata of a large file is organized as a linked list of FAT entries.

Title: What are concrete rules for using a linked list instead of an array?

Body:
A linked list can be used when you want cheap insertion and deletion of elements and when it doesn't matter that the elements aren't next to each other in memory.

This is very abstract and I would like a concrete explanation of why a linked list should be used rather than an array. I'm not very experienced with programming, so I haven't got much (if any) real-world experience.


问:
Licensing on forked projects
I forked a project that hasn't been maintained for a while now. I have a lot of changes I'd like to implement and want to actively maintain the project and keep it open source.

How does the licensing work for situations like this? The original project is licensed under MIT and I would like to keep it that way. Would I be able to change the licence's copyright holders or would it have to stay the same?

答:
It's great that you want to keep the license the same: that makes things easier. As far as copyright holders are concerned: you can add to the list of copyright holders, but do not remove any names from the list.

This changes (I believe) if at some point in the future you have removed all contributions from one of the holders: at that point you could remove that particular name from the list.

Title: Licensing on forked projects


问:
version control workflow for environment with shared code
I work at a company that is looking into "upgrading" our version control system. We have about 200 websites that operate in their own directories. However, all of these websites use the same shared code. We basically use the 200 directories for the display code (html/css) and then the shared code for the processing and database queries. Its a little more detailed but I'll leave it at that for now. We also have a backend system that primarily uses shared code only.

We currently have multiple programmers and multiple coders/designers that all need access to the code on a regular basis. Unfortunately our shared code isn't exactly modular, so it is hard to split something off into a "project" when something needs done since so many files are hit. I am basically looking for suggestions on the best workflow available for a version control system. As far as we can tell from research, git seems to be the way to go. But being the version control newbies that we are, we still have concerns on general workflow. Can anyone give me any advice on this topic?

Edit:
I'm trying to be a little more detailed, hopefully I answer some questions from the comments. Pretty much anyone is allowed to change any code at any time. If a change is made to shared code then it is immediately applied to the central code base. We don't really have a versioning scheme. We used to in the past but it was never enforced when new developers were brought on board. The shared code is clearly separated from the rest of the code. There are a few files in our system that get edited a lot. We are constantly "stepping on each other's toes" with these files. These files are very important to our system. I'll be the first one to say this is not an ideal work situation. We are well aware these files need to go. We are in the planning process of modularizing them but we would still need to consider them when choosing a versioning system. I guess another good thing to mention is the fact that we have a large number of files. This isn't ideal either but its happened primarily from not having a sound version control system put in place. Many developers over the years would just save a back up of a file if making a significant change. This is another reason we want to move away from the current scheme. Thanks for your responses already.

答:
First the workflow:

You will need a server that will act as the central storage for the code and install appropriate system there (more on choice later). It will have to be accessible by everybody who need to modify code and for security reasons should be separate from your regular web server. Unless you really need to make it visible from the internet, don't.

On the web server, make the data directories checkouts from the version control system. There will be one checkout for each site and than one or multiple checkouts of the shared code. If you currently have the shared code on the server just once, you can go with one checkout now and switch to per-site checkouts when you get into situation that some site will need new code and another will need to stay on the old one.

Well, if the sites are simple or very closely related anyway, you can just have everything in one big checkout and one big working tree.

Arrange for some mechanism to update the web server when changes are pushed to the version control. You can have either manual or automatic process or combination thereof. I would suggest automatic process for updating the test environment (so you can review your changes immediately after pushing them in) and manual for updating the live one (so only reviewed changes get published).

In either case you'll have a script on the web server, that will run appropriate update command on all the checkouts. The script shall be started either by the web server (by accessing special URL) or by ssh trigger (special ssh key bound to run the specific command only). Than you can start it manually or from "post-commit" hook.

Everybody who will be making changes will check the parts they need to work on on their local computers. The layout will be the same as on the server, but if they never touch some site, they don't need to check it out.

Now to make a change, you'll run appropriate update command on your local checkout, edit the files, test with your locally-installed web server if possible and commit and push to the central server. Trigger the update script on the test server if it's not done automatically and have the changes reviewed. When they are reviewed, you or the tester will trigger the update script on the live server, preferably explicitly telling it up to which version to update (the one reviewed).

The process should work as much the same as it does now except you'll use the version control system to deploy the files instead of whatever copying you are doing now.

"stepping on each other's toes":

Version control systems generally work with the "edit-merge-commit" cycle these days. That is you start editing the file and when you are satisfied with your modifications, you run a command to merge them with whatever other changes happened meanwhile and than commit the result.

The merge is a line-based text operation. It looks at what lines were added and removed (modify = remove + add) on each side and if the changes are to different parts of the file, it will apply both. If both modified the same part of the file, there is a conflict, which can be resolved using special editor that shows you all the versions and allows you to pick the version you want. There are e.g. kdiff3, meld and many other.

This simple approach works rather well for most kinds of files, but you should avoid unnecessary reformatting as it may cause conflicts. It however does not work for binary files, which includes images and video. There the version control tool will simply say the whole file is a conflict and you'll have to pick one or other version.

So if you happen to modify them a lot, you may want to use the "lock-edit-commit" cycle instead, i.e. the person wanting to modify such file will mark it as being edited and others will be told that they shouldn't touch it now. This is however only supported in centralized system. However in my experience those files are rarely modified by more than 1 person or with any significant frequency, so the very rare case of conflict simply isn't worth the extra work using the locks.

Choosing version control system:

The most modern and more flexible these days is distributed version control systems and of those the two most popular are git and mercurial. There are already some links to comparisons in comments, so I won't repeat them.

However if you happen to need locking, you'll have to use a centralized version control system. The most common option there is subversion. However it's branching support is really poor compared to git and mercurial and it's quite a bit slower. So only use if you really edit binary files a lot.

Note: Now I remember I worked with something that really needed the locking approach -- Adobe CreativeSuite 3 sources for Flash. I believe it's no longer such problem with the new tools, but we couldn't use that than, because it didn't support the Flash Lite target.


答:
The C-language "call stack" is implemented as a linked list in the x86 (and most other) binary APIs.

That is, C-language procedure calling follows a first-in, last-out discipline. The result of executing (possibly recursive) function calls gets referred to as a "call stack", or sometimes even just "the stack".

The CALL x86 instruction ends up implmenting a linked list using the "call stack". A CALL instruction pushes the contents of %EIP register, the address of the instruction after the CALL onto stack memory. The called-fuction prolog pushes the contents of the %EBP register, the lowest address of local variables in the calling functio, onto stack memory. Then the called function prolog sets %EBP to the current function's stack base.

That means that %EBP is a pointer to a memory location that holds the address of the calling function's %EBP value.  That's nothing more than a linked list, implemented partially in hardware via CALL.

As far as what this is good for, it's how x86 CPUs implement function calls, particularly function calls where the function has it's own copy of arguments, and variables local to the function. Every function call pushes some information on the "call stack" that allows the CPU to pick up where it left off in the calling function, without interference from the called function or the calling function.


答:
Here is something part way between an example and an analogy. You have some errands to do, so you grab a piece of paper and write:

bank

groceries

drop off drycleaning

Then you remember that you also need to buy stamps. Because of the geography of your town, you need to do that after the bank. You could copy your whole list onto a new piece of paper:

bank

stamps

groceries

drop off drycleaning

or you could scribble on the one you had:

bank    .......         STAMPS

groceries

drop off drycleaning

As you thought of other errands, you might write them at the bottom of the list, but with arrows reminding yourself what order to do them in. This is a linked list. It's quicker and easier than copying the whole list around every time you add something.

Then your cell phone rings while you're at the bank "hey, I got the stamps, don't pick up any more". You just cross STAMPS off the list, you don't rewrite a whole new one without STAMPS in it.

Now you could actually implement an errands list in code (maybe an app that puts your errands in order based on your geography) and there's a reasonable chance you would actually use a linked list for that in code. You want to add and remove lots of items, order matters, but you don't want to recopy the whole list after each insertion or deletion.


答:
It's definitely worth the time in the long run. Case and point is that I was someone that started programming without a degree and was making decent money. I would have graded myself as a pretty good programmer with decent chops; however, there were others that were better than me. Going through the program really forced me to think and learn some hard mathematical problem-solving skills which definitely made me a better thinker and ultimately a better programmer. I am moving into an MS in CS as well and I have to say that many more opportunities opened up after getting the degree.

In terms of the money, I went from being a run-of-the-mill programmer to being the CTO of a pretty awesome company in NYC. The pay went from 5 digits to 6 in about 6 months or so. So, my answer is that the degree is valuable both in terms of learning and in terms of earning the $Benjamins. It's hard and often times you will want to quit but, as they say, nothing easy in life is worth doing.

Title: Years experience over unfinished degree?

Body:
I'm currently in my placement year and working for a great software development company. It was always my intention of getting to this stage through university, getting enough academic experience as well as the year’s placement and then try to get a full time programming job without the need to finish my degree. I decided this from an early stage as I have never really liked the whole university environment. I was so unhappy at university and I’m so happy now I’m on my placement year, I really don’t know if I can go back.

My question is, do you think companies will take me on if I apply for other jobs after my placement year and not penalize me for not finishing my degree?

I guess at the end of the day I don't want to look back on my life and think "god, why didn't I just spend one more year being unhappy to have a job I love" but I know that even if I get a degree I could still end up without a programming job and this worries me more than anything.


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
Some flexibility in hours

Not everyone is most productive at the same time of day

ContentLicense: CC BY-SA 2.5


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

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

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

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

If you've ever hired programmers:2

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

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

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

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

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

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

答: You never have to stop programming, ever, as long as you are enjoying what you are doing. However, your organization might have a ceiling that you reach, and you simply can't go into a higher position or obtain a greater salary unless you leave the company or leave programming and move into a leadership role as a manager or technical lead.</p>

Title: How old is "too old"?


问:
How would you explain HTTP to a lay person
I got this question in one of the interviews I took. I started by explaining that it is like a set of rules that should be followed while moving resources around, but I did not feel convinced. Is there any other analogy or take on this question ?</p>

答:
it is like a set of rules that should be followed while moving resources around

Although not entirely inaccurate, that sounds closer to a description of REST to me.

I would describe HTTP as a communication protocol, originally designed for Hypertext (hence the name) but extended over time to include any form of file (where the type is defined in the header).

I would also go on to explain that it is a request/response communication, rather than being completely bi-directional, and that the verb in the header is intended to describe an action to be performed, usually on a specified resource.


答: If you love what you do why whould you ever stop doing it? If you don't like it you better stop today. But I guess there is no age or level of experience that will force you to stop coding. With so many new things to learn each year it will go on forever.</p>

Title: How old is "too old"?

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

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

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

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

If you've ever hired programmers:2

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

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

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

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

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

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


答:
For a layman I would explain it as:

A way of requesting and communicating back the information on the Internet(World Wide Web).

I don't know if any further details need to be provided unless asked.

Title: How would you explain HTTP to a lay person

Body: I got this question in one of the interviews I took. I started by explaining that it is like a set of rules that should be followed while moving resources around, but I did not feel convinced. Is there any other analogy or take on this question ?</p>


答:
"Should" is a vague, shifty expression. The useful thing to ask when making that decision is: What will happen if I stay anyway? There are a number of things I could think of.

I will gradually lose my touch and become unemployable if I ever lose my job. That's a tough one. No one wants to believe it could happen to them, so maybe it's true and everyone in the field is denial? On the other hand, Donald Knuth can program rings around me and you put together, and he's 73. This ties into the next point:

People (employers, colleagues) will think I am losing it and make work life much less enjoyable than now. That is also iffy, but easier to test: ask around! What do people who are younger/older than you have to report?

I will eventually get bored of the field altogether, because there is nothing new under the sun. I doubt that one very much, but if it happens, at least you can make a transition gradually without being under a lot of time pressure. (Unless it's in a direction that also discourages experienced individuals from joining...)

Overall I can't think of many reasons to quit the occupation preemptively, then.

Title: How old is "too old"?


问:
Killer semi-unique programming language features
When learning a new programming language you sometimes come across a language feature which
makes you wish you had it in your other programming languages that you know.

What are some language feature which were at the time of learning very new to you and that you wish your other programming languages had.

An example of this is generators in Python or C#.
Other examples may include list comprehensions in Python, template in C++ or LINQ in .NET or lazy evaluation in Haskell.

What other semi-unique language features have you come across which were completely new and enlightening to you?  Are there other features of older programming languages which were unique and have fallen out of fashion?

答:
The Binding Mechanism in JavaFX (R.I.P). The bind keyword enables you to bind the value of a variable to the value of an expression and getting you rid of all those ugly Listener whatsoever boilerplate code.

While JavaFX was quite a fail in many ways, I found many features of the scripting language quite nice.


答:
One reasonable analogy might be speaking to someone on the phone. After all TCP/IP is very similar to phone call. So something along the lines of:

HTTP is like a language that computers on the internet use to talk to each other.

If you want something from somebody on the other end of the world, you phone them up and ask them and you have to ask them in a language you both understand. Requesting a web page from the internet works similar—your computer calls (it often even uses the same wires as phone) one in the company that made the page as asks it for the content—and HTTP is the language both computers understand.


问:
What's the difference between "use case", "User Story" and "Usage Scenario"?
Is there an exact, but simple and understandable defintion of the distinction between "use case",  "User Story" and "Usage Scenario"?

there are quite a bunch of explanation, but right now, I see no one that explains the differences in a single sentence, or two...

(e.g. http://c2.com/cgi-bin/wiki?UserStoryAndUseCaseComparison very long and hard to get, full of discussion)

答:
A user story is always informal and describe a user's need. A use case can be either formal or informal, and describes system behavior.

It is possible to have "tech" user stories, the same is not true for use cases.

Once done, the user story is typically discarded. Use cases may be maintained during the product life cycle.

The scope is also different. User stories are typically smaller in scope, and consequently a use case comprises several user stories. A changed requirement for an existing system is described in a new user story, or an updated version of the use case.

The similarity between user stories and uses cases is that both of them are used for planning and scheduling.

OwnerDisplayName: Henning


问:
What is the best way to evaluate new programmers?
What is the best way to evaluate the best candidates to get a new job (talking merely in terms of programming skills)?  In my company we have had a lot of bad experiences with people who have good grades but do not have real programming skills.  Their skills are merely like code monkeys, without the ability to analyze the problems and find solutions.

More things that I have to note:

The education system in my country sucks--really sucks.  The
people that are good in this kind of job are good because they have talent for it
or really try to learn on their own.

The university / graduate /post-grad degree doesn't mean necessarily that you know exactly how to do the things.

Certifications also mean nothing here because the people in charge of the certification course also don't have skills (or are in low paying jobs).

We need really to get the good candidates that are flexible and don't have mechanical thinking (because this type of people by experience have a low performance).

We are in a government institution and the people that are candidates don't necessarily come from outside, but we have the possibility to accept or not any candidates until we find the correct one.

答:
Can they defend what they claim they know? They put it on the resume/CV as a skill or something they did on another project. See how in-depth they can go on the subject.

Can they learn something new? Talk about a high-level aspect of the technology you're using or something specific to the business domian you work in and see if they can grasp the subject. Do they ask intelligent questions? Can they come up with an analogy? Is it similar to something they've done in another industry or technology?

Would they rather be programming? It doesn't have to be number one on their list, but they have to show a preference to writing code. And I mean actually writing code and making something, not sitting around and talking about it or drawing on the board all day long. Not to minimize planning or to promote cowboy coding, but you gotta have code eventually. Avoid those who avoid the keyboard. This isn't a managment position.

You can do some scoring on a scale of one to ten thing or just rely on being able to smell your own kind.

ContentLicense: CC BY-SA 4.0


问:
Setting up a new developer system - how to speed up the process?
When I get a new laptop, it usually takes me about two weeks to reinstall all my developer programs, utilities and tweak the O/S settings to how I like them.

I know there are utilities out there to backup/restore systems, but this is usually if it is on the same hardware.

What would you recommend?

答:
You don't mention what OS you're using, so I'd like to mention that this is another argument in favor of MacOS as a development platform -- Apple's migration assistant makes it very easy to move all user accounts/customizations/installed apps to a new system at install time.

Beyond that, I'd second some of the points others have made here:

If it ain't broke, don't customize it -- this may be the sysadmin and past consultant in me speaking (when you have to go around to many clients' systems, you quickly learn that a little time spent on getting acclimated to the default way of doing things can be a lot better use of time than trying to carry your customizations everywhere you go).

If it is broke, customize it in a repeatable way.  For MacOS, this means using a system like homebrew or macports to install software, so you can run the same command on each box.  For Unix, this means using the native package manager on your system (yum, apt-get, etc).  For Windows, this means keeping installers around so you can re-run them later.

Share, share, share -- if you have files you'll need all over the place, use something like Dropbox, a local wiki install, or one of the many sync products out there to keep them available wherever you are (the usual caveats about trusting data to third parties apply, though -- be mindful of what you are and aren't willing to put on a service like Dropbox).


答:
One thing to consider is how many will hire a 50 or 60 year old programmer? If all you do is code I don't think there are nearly as many jobs available for an older coder as compared to a early twenties to late thirties coder. One reason I know this exists (I have asked others in charge of hiring) is that a 40 year old manager is a bit weary of someone 15 years his senior. Will they follow my directions? How set are they in their ways? Will other gravitate and follow this grandpa coder?

Almost all of the job offers I get these days (I am 43) do require me to fulfill a certain amount of managerial/supervisory duties.

So I do think at a certain age it would be wise to change your focus from "only coding" to coding and taking on more supervisory roles. It is simply expected in this world of ours that older people will take on a more leader type role. And, like I stated above, many seem to naturally defer to older people.

So you may be able to only focus on writing code but keeping and getting new jobs will become at least a bit harder as you age.

Title: How old is "too old"?


问:
Which language features are considered harmful?
Please, explain why and list which languages have the (mis)feature implemented As far you know.

Post what you consider a harmful feature, not what you dislike.

答: Arrays in AWK starting at index 1!

Body: Arrays in AWK starting at index 1!


答: I have to do this a fair amount due to the nature of the business I work for. There are some good short explanations listed already. But the beauty of HTTP is it is really understandable. So when I need to get more in depth than the short answers above, I typically fire up a browser, ask the user for a favorite site then fire up Fiddler or Firebug or whatever other http debugger is handy. Then we walk through requests and deconstruct HTTP while it is in action. </p>


问:
Code review approaches
Just going out on a limb here. Is doing a code review by sampling a few classes and units of code by a developer good enough to judge what he has done wrong to provide inputs? This is just in case you are pressed for time and can't review every single line written by them. I am working on the assumption that the developers might duplicate the same type of mistakes everywhere. Is this an effective approach? or partially effective, or not at all effective?

What other approaches are better? Sitting with each developer who has written the lines of code and asking them why they did that a particular way? or doing it by yourself and then sending a synopsis of your findings via email?

How do you approach reviewing code written by junior developers/peers when you have to review all the code base in a typical 15 day sprint?

答:
Aiming for 100% code review of every line of code produced is probably unrealistic. Doing so would require a great deal of developer/tester time, reducing the effort spent on actually producing software. There are two things that you need to decide upon - what you want to review and how you want to review it.

What you review depends on a lot of factors. For example, you probably want to review the code that is involved in your most critical features. If you have a new developer on the team, that's some other code that you want to review to ensure the new developer is following coding guidelines and is producing a quality product. Once you have a methodology for determining how important it is to conduct a code review on a given unit, that methodology should be documented (perhaps as a checklist) so that others can evaluate their own code and know when to ask for a review and when it's not necessary.

There are many methods of conducting a code review. They range from pair programming to formal inspections. The methods used often depend on how critical the code is. If it's a life-critical block, then perhaps you want to use a formal inspection process, with multiple reviewers who read the code, annotate it, then have a meeting with the developer. If it's a bug fix produced by a new developer, then one other person sanity checking it might be sufficient.

For your specific case of reviewing a new developer's code, I would use a lighter weight approach, such as an over-the-shoulder code reading. If you have the people, pair programming might be better, since it would not only accomplish the goals of ensuring they aren't making mistakes, but also let them work closely and get to know a member of the team. I would definitly try to go with something more personal, though, with human interaction and not just an email, to improve the team-bonding experience when still accomplishing the goals of the review.

The best approaches vary by team, but if you consider your options with regards to the criticality of the code, the purpose of the code review, and how much time and money you have, you can come up with a code review process. Also note that the same general guidelines can be applied to any work product - requirements, designs, user manuals...

Title: Code review approaches


答:
Look at the case of Grace Hopper. She continued to work with programming until her death at 85.  I remember seeing a 60 minutes special on her many years ago, she was a fascinating person.  If you have a passion for doing something, then age is not a factor.

For what it's worth, I'm over 50 and see no reason to stop doing what I enjoy.  There is still always a lot to learn and I enjoy that.

Title: How old is "too old"?


问:
Release cycle as a game
I thinking about how increase developer's commitment to release and create release cycle as a game for more fun in office.

Current suggestions

Building tower from bricks

Climbing on some hypothetical everest, where each camp is release stage

Some badges system, like StackExchange system

答: You can create a puzzle with an image representing your system in a visual way. And then after each release you will add pieces of puzzle to the appropriate parts of the system. That game would need clear vision of what you're building and work good designer. </p>

Title: Release cycle as a game


问:
Who is Configuration Manager?
I would like to ask members of the community about the role of Configuration Manager, as you see it. I'm not asking what Configuration Management is, as long it had been asked before. What I need to know is:

What tasks do you think Configuration Manager should perform (or performs) in your team?

What is primary responsibility of Configuration Manager?

What are secondary/auxiliary responsibilities of Configuration Manager?

Does Configuration Manager need to be in charge of development processes on the project/company or he should be told what to do?

What are relations between Configuration Manager, Build Manager, Release Manager, Deployment Engineer, CI Engineer roles? Aren't they all the same - Configuration Management?

Maybe term Configuration Management is redundant and Technical/Team Lead should do all the related work instead?

It would be really great if you could share your vision and experience.

答:
What tasks do you think Configuration Manager should perform (or performs) in your team?

Managing the build and release process, working with both the dev team and ops teams in their middle ground.

What is primary responsibility of Configuration Manager?

Constantly removing any manual processes from both build and release, to limit risk during production release.

What are secondary/auxiliary responsibilities of Configuration Manager?

Improving the relationship and inherent mistrust issues between the dev and ops teams.

Does Configuration Manager need to be in charge of development processes on the project/company or he should be told what to do?

Like any role, the better the CM is, the less he needs to be managed. But he should be servicing both the dev and ops teams' needs and resolving conflict from those needs, as opposed to making up problems that don't exist and "solving" them.

What are relations between Configuration Manager, Build Manager, Release Manager, CI Manager roles? Aren't they all the same - Configuration Management?

I would say that Configuration Management is comprised of all the others. You may have a CM team where different people have different roles. Or you may have one CM who does it all.

Maybe term Configuration Management is redundant and Technical/Team Lead should do all the related work instead?

No. The team lead should be managing the people and the technical lead should be managing the application. If you trust in CM to be done by either of these roles, it will simply never get done (except in very small companies ... maybe).

Title: Who is Configuration Manager?


答:
Everyone's career works out differently becasue we have different needs and make different choices. I know plenty of over 50 programmers, I work with a good number of them because we try to hire talent not age and frankly we place the highest value on in-depth experience which the younger people just don't have.

As you age you have to make choices. You can stay a programmer, but that comes at a cost of generally lower salary. You can transistion to a tech lead which generally still includes some programming but also some management tasks. You can become a specialist (BI, architecture, systems analyst, database, etc.) which often pays better but is limiting in terms of overall jobs avaliable. You can move to a project management role or business analyst role and leave programming entirely. You might even decide to open a restaurant  or buy a farm and leave the corporate world behind entirely. All of those options are open when you are young and eventually your choices will limit which ones are viable for you.

I personally have noticed that if you haven't transitioned to management by your mid-30's it is much harder to go there. But that may not hold true in other locations.

But the point I'm trying to make is that you control your career choices. You don't have to do what others do just because most people do that. Do what is best for you. And never think you have made an irrevokable choice. I have changed careers 5 or 6 times, life leads you to unexpected places sometimes. What you want at 20 is not likely what you will want at 50 and that's ok. Sometimes we make choices to keep food on the table and pay for our children's education. There are alot of programmers who have become managers for the pay. There are others who don't care how much they offer, they feel the stress of management is not worth it. And others are pure programmers who can't ever even consider anything else because it isn't so much what they do as who they are.

Title: How old is "too old"?


答:
Obviously those in charge have not provided the proper motivation to make everyone follow this standard. Punish one, teach a hundred. I'm not saying it's the same level, but this is one of those necessary evils like filling out a time sheet. You do it right and on time or you have to go.

Now, a game that encourages everyone to enter quality code for those release cycles would be fun. Maybe the code review process could be like stack overflow. Your code is basically the assumed question "how good is this code?" and everyone gets to review, comment, up/down vote with points and badges, tshirts and bragging rights. There can be some scoring to see if it is good enough to commit. Write code and get it evaluated along with taking responsibility for reviewing others is pretty much what programming is all about in a team environment. Teamwork is more than just cubicle location.

Title: Release cycle as a game

Body:
I thinking about how increase developer's commitment to release and create release cycle as a game for more fun in office.

Current suggestions

Building tower from bricks

Climbing on some hypothetical everest, where each camp is release stage

Some badges system, like StackExchange system


答:
I'm 59, and have worked as software developer every day since I retired from the US military in 1994.

What I've found is after about 45 there is no point to even trying to get a job with a company that has an HR department.  HR people are afraid that if the new older hire didn't work that they would be on the receiving end of an age discrimination lawsuit.  So they practice age discrimination up front.

The best bet for an older programmer looking for a job is to look for a small start up, preferable started by a former colleague, or at least a company small enough to not have an HR department. If you can talk to the actual development team there is a reasonable chance that they can see past your gray hair.  At least this has worked for me.

I plan to continue as a developer until I get tired of the job, which hasn't happened yet. My present gig is pretty stable, but if it goes away I'll either find another job or make my own job.

Title: How old is "too old"?


问:
Programmer-Tester-Ratio
Are there any substantiated recommendations how many testers a team should have per programmer? I'm more interested in opinions referring to an old-school development approach (no agile stuff) and larger projects. Sources are welcome.</p>

答:
My opinion would be that it depends very much on the nature of the project, because some projects lend themselves to more automated testing. For example, a hosted accounting package does not need to content with large number of environments, and the types of tests that need to happen are complicated scripts involving scenarios provided by the business side.

On the other hand, if you're developing an Android app, you'll probably want people to physically test on a wide variety of common phones, which isn't easy to automate.

I've worked at two places that I felt got tester ratio right. My current company has no testers -- everything is an automated test, JUnit, RSpec, Selenium or Capybara. This works for our processes and culture.

A previous company had about 1 tester per maybe 4 engineers writing code. This worked well because scheduling worked out so that some of the tests would float between projects depending on what part of the cycle they were on and we'd end up with 1 per 2-3 coders while stabilizing the code.

Some of the QA was in India which was also nice. We'd finish doing stuff at the end of the day, and when we come in the next day, we'd have new feedback from QA.

Title: Programmer-Tester-Ratio


问:
Computer security expert using pre-made tools or own?
As a digital security consultant when is it 'ok' to use tools someone else made (dumb to reinvent the wheel, right?) and when should I make my own?</p>

答: If I were hiring a consultant, I'd like to see someone who actively contributes to the open source tools. This goes for security, test frameworks, whatever. If someone were using their own tools, I'd see this more as a high value add enterprise sale rather than pure consulting, which means a lot more money in the long run.</p>


问:
Suggested HTTP REST status code for 'request limit reached'
I'm putting together a spec for a REST service, part of which will incorporate the ability to throttle users service-wide and on groups of, or on individual, resources.  Equally, time-outs for these would be configurable per resource/group/service.

I'm just looking through the HTTP 1.1 spec and trying to decide how I will communicate to a client that a request will not be fulfilled because they've reached their limit.

Initially I figured that client code 403 - Forbidden was the one, but this, from the spec:

Authorization will not help and the request SHOULD NOT be repeated

bothered me.

It actually appears that 503 - Service Unavailable is a better one to use - since it allows for the communication of a retry time through the use of the Retry-After header.

It's possible that in the future I might look to support 'purchasing' more requests via eCommerce (in which case it would be nice if client code 402 - Payment Required had been finalized!) - but I figure that this could equally be squeezed into a 503 response too.

Which do you think I should use?  Or is there another I've not considered?

答:
429 Too Many Requests

The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes. This code has been accepted in RFC 6585 Additional HTTP Status Codes.

```<code>   The 429 status code indicates that the user has sent too many
   requests in a given amount of time ("rate limiting").
</code>```

```<code>   The response representations SHOULD include details explaining the
   condition, and MAY include a Retry-After header indicating how long
   to wait before making a new request...
</code>```

```<code>   Note that this specification does not define how the origin server
   identifies the user, nor how it counts requests.  For example, an
   origin server that is limiting request rates can do so based upon
   counts of requests on a per-resource basis, across the entire server,
   or even among a set of servers.  Likewise, it might identify the user
   by its authentication credentials, or a stateful cookie.
</code>```

```<code>   Responses with the 429 status code MUST NOT be stored by a cache...
</code>```

Body:
429 Too Many Requests

The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes. This code has been accepted in RFC 6585 Additional HTTP Status Codes.

   The 429 status code indicates that the user has sent too many
   requests in a given amount of time ("rate limiting").

   The response representations SHOULD include details explaining the
   condition, and MAY include a Retry-After header indicating how long
   to wait before making a new request...

   Note that this specification does not define how the origin server
   identifies the user, nor how it counts requests.  For example, an
   origin server that is limiting request rates can do so based upon
   counts of requests on a per-resource basis, across the entire server,
   or even among a set of servers.  Likewise, it might identify the user
   by its authentication credentials, or a stateful cookie.

   Responses with the 429 status code MUST NOT be stored by a cache...


问:
Who's responsible for a master / slave switch?
We are introducing a master / slave replication schema in our web application. At certain scenarios we would prefer to explicitly direct reads to a slave and writes to the master, which to me is an obvious advantage of the schema.

Instinctually, I'd prefer for the switch to happen somewhere in the ORM, we use Doctrine and it offers a neat solution. But that's not really a solution for us, because we don't have a very practical way of distinguishing when a read is in reality a write (such as in update scenarios).

The next best thing would be to delegate the responsibillity for the switch to the controller and / or some custom libraries that in a cliche MVC approach could be considered as supercharged models. Although this is a very practical solution and probably the one that would require less time, I somehow fear there's something very important I'm missing and it will come back and bite me hard.

There are vague time constraints, and management support to feveresly refactor, but for this specific scenario we mostly agree that we should go with the practical approach, even if it means limit ourselves only where we've identifed the database as a major bottleneck.

To add to the confusion, I can't really say I'm experienced in replication schemes, when the issue was first discussed I thought a better solution would be to adopt a multi-master scheme, but when I started researching how easy those fail and how robust their implementation should be, it stopped feeling reasonable.

Help?

答:
You'll need to be able to identify the entire transaction as readonly or read-write. The transaction guarantees durability on the database you're operating on, not on another database.

That said, I think the controller is the right place to put this. You should maintain two sources for connections and use whichever is appropriate.

I don't think your proposed scenario is very common. Generally an entire service will either talk to the master or to the slave, but not to both.


答:
As every expert independent of the area of expertise security expert should be able to use both:

Advantages of pre-made tools.

Pre-made tools are usually well-established tools, their authors are known in the community and they have been already tested by many other experts. As long as the expert is requested to write something to support his opinion, the use of well-known tools will be a very good argument.

Pre-made tools are usually those available to every expert. Hence you can easily reproduce the results of secutiry audit performed with a pre-made tool just by re-running the analysis. This is hardly possible with some custom-made tool you don't have access to or you don't know how to use.

Using known tools for identifying common problems proves that expert is aware about these tools and doesn't try to reinvent the wheel while pinging your server or using telnet to check if any service is running on given port.

Advantages of self-made tools.

Self-made tools show your expertise not only in your area, but also in programming that is always seen as a benefit.

Self-made tools might grow into something bigger with time and ultimately become the standard tools in your area, contributing to your reputation as an expert.

Self-made tool distinguish you from the experts who use only the standard tools, showing a higher level of proficiency or expertise. Even clever combining of existing tools would already do here and you can get a better offer or higher salary here.

Title: Computer security expert using pre-made tools or own?

Body: As a digital security consultant when is it 'ok' to use tools someone else made (dumb to reinvent the wheel, right?) and when should I make my own?</p>


问:
How to handle large numbers?
Well, I've just started doing puzzles and it's so annoying to see puzzles which are easy to do but also need to handle very large numbers. That's the problem.

Say I have to deal with numbers like 10 ^ 6 / 2147483647 / etc. Need to do arithmetic operations on!

However, I feel that these shouldn't be handled in brute force way but the math theorems/ statements just don't click in my mind at times.

How could I possible handle such puzzles (shouldn't use external lib)

答: Large numbers are used in code challenges because they are hard to deal with, its the same reason they are used for encryption. There are BigInt classes for most languages that can help make them more manageable. Most code challenges can be solved while minimally dealing with large numbers though, there are clever solutions that find ways to avoid having to work with big numbers until absolutely necessary.</p>

Title: How to handle large numbers?


问:
Computation Program Not Running at 100% CPU Utilization
I have a program which has a GUI and performs some very heavy mathematical computations for a couple of minutes and then outputs a result. When I try to directly interface it through its DLL's, it runs fine, but it doesn't run at 100% CPU usage like the GUI does. Why is this?

I understand the reason why computational heavy program might not run at 100% is due to I/O that it might be doing but this program doesn't do any, not even a single printf(). Files are being generated at the end of execution in both the GUI and DLL versions of the program. The interface program makes mulitple calls to the DLL during execution as well.

It is written in C, compiled using VS2008 CL compiler running in Release mode. Running on Intel i5 CPU with 4GB RAM (60% utilization average, never above 70%). When I set affinity to the process to one CPU (in this case, 1/4 "CPU's", 2 cores with 2 threads each), the GUI uses 100% of that dedicated CPU for about 2 min. My interfacing application uses anywhere from 60-80% CPU for about 5 minutes. I use Window's Performance Tab upon performing CTRL+SHFT+ESC.

---EDIT---

I found that database calls (there are a few specific ones) are being preempted a lot for extended periods of time (usually 5 times slower). Using Process Explorer I was able to find out that each program uses exactly the same amount of CPU time -> leading to my conclusion about preemption. For anyone that doesn't know about this tool, download Process Explorer from SysInternals, very useful.

---EDIT---

I found that the GUI opens a single static connection to the database. While my interface doesn't do that, leading to opening and closing the connection thousands of times. Opening it once for the lifetime brought the CPU up to 100%.

答:
Profile it!

It's the only way to know exactly what is happening and what is using what resources and where it's being limited at.


答:
Many things may be causing this. One possibility is that there is some desynchronization logic involved in calling the DLL and receiving results from it, and this logic somewhere relinquishes a timeslice. (Sleep(0) will not relinquish the remainder of your timeslice; Sleep(1) will.)

If by any chance you are using an awful lot of memory, there may be some swapping going on; that would slow things down A LOT. Try disabling your swapfile, and see if you get an out of memory error.  I use WinXP with 4GB of RAM and no swapfile, and my machine is FAST!  (Though I run the danger of running out of memory, but I keep track of that.)

And, of course, the possibility that it is writing to a file as it works is worth checking. Could it be that as it is thinking, it is writing its thoughts down in a log file?

Also, instead of using the Windows Task Manager for looking at CPU utilization, do yourself a favor and get SysInternals' Process Explorer. It is much, much better, and it will give you a lot more information about your processes, your DLLs, the handles that are open, etc.

Title: Computation Program Not Running at 100% CPU Utilization

Body:
I have a program which has a GUI and performs some very heavy mathematical computations for a couple of minutes and then outputs a result. When I try to directly interface it through its DLL's, it runs fine, but it doesn't run at 100% CPU usage like the GUI does. Why is this?

I understand the reason why computational heavy program might not run at 100% is due to I/O that it might be doing but this program doesn't do any, not even a single printf(). Files are being generated at the end of execution in both the GUI and DLL versions of the program. The interface program makes mulitple calls to the DLL during execution as well.

It is written in C, compiled using VS2008 CL compiler running in Release mode. Running on Intel i5 CPU with 4GB RAM (60% utilization average, never above 70%). When I set affinity to the process to one CPU (in this case, 1/4 "CPU's", 2 cores with 2 threads each), the GUI uses 100% of that dedicated CPU for about 2 min. My interfacing application uses anywhere from 60-80% CPU for about 5 minutes. I use Window's Performance Tab upon performing CTRL+SHFT+ESC.

---EDIT---

I found that database calls (there are a few specific ones) are being preempted a lot for extended periods of time (usually 5 times slower). Using Process Explorer I was able to find out that each program uses exactly the same amount of CPU time -> leading to my conclusion about preemption. For anyone that doesn't know about this tool, download Process Explorer from SysInternals, very useful.

---EDIT---

I found that the GUI opens a single static connection to the database. While my interface doesn't do that, leading to opening and closing the connection thousands of times. Opening it once for the lifetime brought the CPU up to 100%.


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
A Water Cooler

I don't have one and I bring two water bottles with me every day.

Many other answers have covered things like dual monitors and recreation areas (music and the like).


答:
Every programming language supports the use of big numbers: some have this support directly in the standard library, others have special libraries written for this purpose (even several ones).

As long as you are fine with integer numbers you should look for something like BigInteger that is present in many languages. If you need real numbers, then you should look for arbitrary precision arithmetics libraries.

Here are some examples:

Java has a built-in BigInteger class, information about arbitrary precision can be found on StackOverflow.

.Net has BigInteger and W3b.Sine

Python also features BigInteger and mpmath for floats.

Title: How to handle large numbers?

Body:
Well, I've just started doing puzzles and it's so annoying to see puzzles which are easy to do but also need to handle very large numbers. That's the problem.

Say I have to deal with numbers like 10 ^ 6 / 2147483647 / etc. Need to do arithmetic operations on!

However, I feel that these shouldn't be handled in brute force way but the math theorems/ statements just don't click in my mind at times.

How could I possible handle such puzzles (shouldn't use external lib)


问:
Can we say objects have attributes, states and behaviors?
I was reading through Oracle's introduction to OOP concepts and I came across this description:

Real-world objects share two characteristics: They all have state and
  behavior. Dogs have state (name, color, breed, hungry) and behavior
  (barking, fetching, wagging tail). Software objects are conceptually
  similar to real-world objects: they too consist of state and related
  behavior.

My problem with that passage is that when describing state its mixes attributes there too. For instance, the name and color of a dog are its attributes, while it being hungry or thursty are its states.

So in my opinion it's more accurate to break the characteristics of objects into three parts: attributes, states and behaviors.

Sure, when translating this into a programming language I can see that the three-fold partition becomes a two-fold one, because both attributes and states will be stored into fields/variables, while behaviors will be store into methods/functions.

But conceptually speaking it makes more sense to have the 3 things separate.

Here's another example: consider a lamp. Saying that both the lamp size and whether or not it's turned on are states is a stretch in my opinion. The lamp size is an attribute, not a state, while it being turned on or off is a state.

Or did I miss something?

答: State is set of attributes and corresponding values, so from my point of view, you are not right (and you are creating unnecessary additional complexity to simple definition).</p>


答:
The state of an object is encoded in its attributes, either directly or indirectly. For instance, if you want your Dog to be thirsty, you can let it have a

```<code>private boolean thirsty;
</code>```

Alternatively, you can let it have something like

```<code>private Date lastDrinkAt;
</code>```

and conclude whether your instance of dog is thirsty by comparing the current time with the time it last drank something.

Either way, the state of your objects lies within its attributes.

Then there are classes that do not have attributes, mostly utility classes. But you usually don't want to create an instance of them either in this case.

For the sake of being able to reason about statements, scientists usually stick to the principle of minimality. I think that's why Oracle didn't mention state explicitly. It can be derived from the value of the attributes.

Title: Can we say objects have attributes, states and behaviors?

Body:
I was reading through Oracle's introduction to OOP concepts and I came across this description:

Real-world objects share two characteristics: They all have state and
  behavior. Dogs have state (name, color, breed, hungry) and behavior
  (barking, fetching, wagging tail). Software objects are conceptually
  similar to real-world objects: they too consist of state and related
  behavior.

My problem with that passage is that when describing state its mixes attributes there too. For instance, the name and color of a dog are its attributes, while it being hungry or thursty are its states.

So in my opinion it's more accurate to break the characteristics of objects into three parts: attributes, states and behaviors.

Sure, when translating this into a programming language I can see that the three-fold partition becomes a two-fold one, because both attributes and states will be stored into fields/variables, while behaviors will be store into methods/functions.

But conceptually speaking it makes more sense to have the 3 things separate.

Here's another example: consider a lamp. Saying that both the lamp size and whether or not it's turned on are states is a stretch in my opinion. The lamp size is an attribute, not a state, while it being turned on or off is a state.

Or did I miss something?

Body:
The state of an object is encoded in its attributes, either directly or indirectly. For instance, if you want your Dog to be thirsty, you can let it have a

private boolean thirsty;

Alternatively, you can let it have something like

private Date lastDrinkAt;

and conclude whether your instance of dog is thirsty by comparing the current time with the time it last drank something.

Either way, the state of your objects lies within its attributes.

Then there are classes that do not have attributes, mostly utility classes. But you usually don't want to create an instance of them either in this case.

For the sake of being able to reason about statements, scientists usually stick to the principle of minimality. I think that's why Oracle didn't mention state explicitly. It can be derived from the value of the attributes.


问:
Is there a technical reason why you can't develop iOS apps on a Linux computer?
I understand why you can't develop OS X apps on a Linux computer, but is there a good technical reason why you can't develop iPhone and iPad apps on Linux?  Why isn't it possible to compile iOS source code into an iOS executable and run it in an iOS simulator on Linux or install it on a development iOS device?

Is it just because the XCode IDE is a Cocoa application?

You can develop Android apps on any kind of platform, it seems. I don't see why the same can't be true of iOS.

答:
It depends on what you mean by "technical reason"

Strictly speaking I don't believe there's a technical reason that iOS Apps couldn't be developed on Linux. It would require some entity, be it Apple or a group of enterprising/talented hackers, to author a toolchain for it (compilers, maybe an IDE, something to get it on the phone).

So if by "technical reason" you mean "something special about the Macintosh that's impossible and couldn't possibly exist on another platform" then no, I don't believe there is. There's not some special chip on the Macintosh that is required for this, for example.

If by "technical reason" you mean "something preventing me from being able to do it today" then yes, the entire signed code bit doesn't exist on Linux and unless Apple ports it over then that's the ball game.


问:
How do lines of code get executed by the CPU?
I'm trying to really understand how exactly a high-level language is converted into machine code and then executed by the cpu.

I understand that the code is compiled into machine code, which is the low level code that a CPU can use. If I have an assignment statement say:

```<code>x = x + 5;
y = x - 3;
</code>```

Does the CPU execute each line one at a time? So it will first execute the x = x + 5; instruction and then the next instruction the CPU will execute is the y = x- 3; I'm really trying to understand the execution process and how the code I write is actually execute by the CPU.

答:
No, there is no one-to-one mapping between code lines / instructions in higher and lower level languages. In fact, both lines above are translated into multiple machine code instructions, like

load a value from a certain memory address into a register

modify the value

write it back to memory

The actual details of these instructions vary between platforms.

This is the basic view of things. However, to further complicate issues, modern CPUs apply techniques like execution pipelines, out-of-order execution and multiple cores, among others. These result in the CPU doing multiple things at once, e.g. pipelines process different phases of subsequent instructions in parallel within the same processing unit, while multiple cores may process independent instructions in parallel.


答:
You should look in great details in a book to find more details on how it works, possibly a compiler class as well.

Basically, your question is focusing on 2 different aspects.

1) How is the code translated into machine code?

2) When/how is the code computed using parallelization?

The answer to 1) depends on the language you use (although for your example is trivial so the output would be the same). The way the compiler does the translation to machine code is one of the force of the language. Besides, there are several concerns that need to be taken into account in your example, the code should load the data into memory, store it, etc.

Finally parallelization is a features that you can force from a programming point of view, but in a nutshell, some processors might try to think that some portion of code can be run at the same time, because they are independent. In your case, clearly, it's not the case, as you need to execute the statements sequentially, so no, it will not run at the same time.

Title: How do lines of code get executed by the CPU?

Body:
I'm trying to really understand how exactly a high-level language is converted into machine code and then executed by the cpu.

I understand that the code is compiled into machine code, which is the low level code that a CPU can use. If I have an assignment statement say:

```<code>x = x + 5;
y = x - 3;
</code>```

Does the CPU execute each line one at a time? So it will first execute the x = x + 5; instruction and then the next instruction the CPU will execute is the y = x- 3; I'm really trying to understand the execution process and how the code I write is actually execute by the CPU.


问:
Is it OK to use sample code from blogs, GitHub, etc... in commercial applications?
When searching the web for a solution to a particular problem, I often find a perfect solution posted on someone's blog, or in a public repository (GitHub, Google Code). Most of the time, the code has no copyright information, nor does the author mention any sort of attribution rules. </p>

<p>I'm pretty sure short snippets are fine, but what if I copy a handful of classes verbatim (again, no copyright notices, TOS, attribution requests, etc...)? Am I under any legal obligation to the original author? </p>

答:
First of all, legal questions should be directed to lawyers, not programmers. Second, whether there is a license included with the code or not, the original author retains copyright of their work. This of course depends on where you live in the world, but I would say this is likely the case. Third, if the license allows (i.e. explicitly specifies) commercial use of the code, you should be fine to use it wherever you want.

Again, consult a lawyer if you are concerned or take your chances!


答:
Never use code in your application if you are unclear on its licensing, you can't assume the code is in the public domain just because you failed to find its licence (and it seems to me that you didn't try hard enough).

Google Code doesn't even let you post code unless you specify a licence, so there's little chance (if any) you'll find code there without obvious licensing. Github doesn't have a similar requirement, but all code I've seen hosted there does, one way or the other (check their readme files).

If you found the code in a blog and you really tried to find out its licensing and failed, the best course of action would be to contact the author. Allow for a sensible amount of time for them to respond, and if they don't and you must use the code, consult with a lawyer first.

Title: Is it OK to use sample code from blogs, GitHub, etc... in commercial applications?

Body:
When searching the web for a solution to a particular problem, I often find a perfect solution posted on someone's blog, or in a public repository (GitHub, Google Code). Most of the time, the code has no copyright information, nor does the author mention any sort of attribution rules. </p>

<p>I'm pretty sure short snippets are fine, but what if I copy a handful of classes verbatim (again, no copyright notices, TOS, attribution requests, etc...)? Am I under any legal obligation to the original author? </p>


答:
It depends.

In the early days of really simple machines, yes, code executed one line at a time.  As machines got bigger, faster, and more complex, you started to see both the ability to execute multiple instructions simultaneously and memory reads and writes taking a lot longer than operations on registers.

Optimizing compilers had to take this into account, and the lines you give could be executed "more or less" in parallel, with one part of the processor working on the computation of y, while another part was storing the previously-computed new value of x (and the computation of y was using that new value from the register).

The Control Data 6600 was the first machine I know of that did this kind of things.  Integer addition took 300 nsec, memory reference (read or write) took 1000 nsec, multiplies and divides took a LOT longer.  Up to around ten instructions could all be executing in parallel, depending on which functional units were required.  The CDC 6600 FORTRAN compilers were VERY good at scheduling all of this.


答:
The lines of code have nothing to do with how the CPU executes it. I'd recommend reading up on assembler, because that will teach you a lot about how the hardware actually does things. You can also get assembler output from many compilers.

That code might compile into something like (in a made up assembly language):

```<code>load R1, [x] ; meaning load the data stored at memory location x into register 1
add R1, 5
store [x], R1 ; store the modified value into the memory location x
sub R1, 3
store R1, [y]
</code>```

However, if the compiler knows that a variable isn't used again, the store operation may not be emitted.

Now for the debugger to know what machine code corresponds to a line of program source, annotations are added by the compiler to show what line corresponds to where in the machine code.

Body:
The lines of code have nothing to do with how the CPU executes it. I'd recommend reading up on assembler, because that will teach you a lot about how the hardware actually does things. You can also get assembler output from many compilers.

That code might compile into something like (in a made up assembly language):

load R1, [x] ; meaning load the data stored at memory location x into register 1
add R1, 5
store [x], R1 ; store the modified value into the memory location x
sub R1, 3
store R1, [y]

However, if the compiler knows that a variable isn't used again, the store operation may not be emitted.

Now for the debugger to know what machine code corresponds to a line of program source, annotations are added by the compiler to show what line corresponds to where in the machine code.


答:
You are right in that objects consist of attributes, states, and behavior, if you define attributes to mean non-changing characteristics of an instance. As a matter of fact, it is important to make this distinction, because there exist objects which contain only attributes, (in your sense,) and no state; they are called immutable and they are very useful in programming.

This three-part definition is indeed represented in programming languages, for example using the final keyword in Java or the readonly keyword in C# to denote instance data which may not change throughout the lifetime of the instance.

I have to add, though, that non-changing instance data are usually not called attributes. We tend to speak of them as 'final' or 'readonly' or 'constant data' depending on which language we are using. The proper term for them would be 'invariants', but then this word is not frequently used in this sense; it is more often used for other things.


问:
How often is appropriate to destroy objects?
I know this is hard to answer without examples, so I'm looking for general principles or guidelines here. I'm thinking within the realm of small- to medium-sized mobile games and apps.

I've read a few times the object reuse is a touchstone of creating efficient programs. So, I generally strive to reuse everything possible. But, then I came to realize that every object I'm keeping around has to exist somewhere in memory, so it's begun to seem inefficient. I've thought it would be fine, as long as I'm not trying to render the objects' visual or auditory aspects. And I've feared that construction and re-construction of these objects would be too expensive to perform every time I just want to toggle their presence.

Let's say, for instance, I've got a GUI comprised of 30 different objects that each represent a screen state-- buttons, panes, text, a background, maybe some animated UI components. Does it seem more sensible to initialize and de-initialize these objects, keeping them around in memory, but disabling their rendering, animations, etc? Or should I just be destroying these things and re-creating them?

Other examples of things I keep around might be game objects like non-playable characters, weapons, items, etc.

答:
Premature Optimization - Just Say No!

Having multiple objects is an important abstraction over the raw memory access you would be left with if not for Object Oriented Programming.

Creating an object, is reasonably inexpensive operation on even the most modest hardware available. You should not avoid it by default.

The special case, where a new object creation is expensive justifies the use of Object Pool Pattern.

Sharing memory between similar objects, frequently found in games, can be helped with the Flyweight Pattern.

As a simple example, using a compiled language (C#, Java, C++) on a modern PC, you can create millions of simple objects in a single second.

Remember: Any optimization should be done only after you have determined that your code is slow, and only to the parts that are slow.


答:
Depending upon what you are doing, maxing out the CPU is not the best way go and thus, the numbers you are getting back now might actually mean that things are running faster than they were before even though the processor is not maxed out. Even extremely complicated algorithms may not max out the CPU utilization and this can be a good thing as it means you can do other tasks while running the program.

Remember that when a program is running not all of the data may be in the processor cache and the time it takes to go out to the RAM (short from the processors perspective) or to other storage (e.g. hard drive, NAS, etc) (long from the processors perspective) is time that the processor can be running other tasks. Computers are very good at task switching and generally we use that to our advantage as well.

In terms of your program, doing anything with a GUI tends to be very slow as the GUI has to wait for the screen to repaint when updates are done and this can take an extremely long time to run from the processors standpoint. Most computationally heavy operations are written in such a way that they are decoupled from a GUI to ensure that they focus solely on their task and other tricks are used to report their status if they take awhile to run.

In terms of making your code as fast as possible, as Malfist noted in their answer profiling the code is your best bet and seeing what is running slow. Likewise, if possible making the algorithm run some parts in parallel will ensure it runs subjectively faster as it can take advantage of multiple cores on the processor. Additionally, you might want to write some very basic logging that notes when certain parts of the code is entered and exited (showing running time) and how many times certain operations are performed. These are typically given to you in a good profiler, but it can be a useful exercise to do on your own as well.


问:
What does a code review look like?
I'm writing a code review process document for our team; we've never had a formal process in place although we do do some code review.

I've found lots of articles talking about how important code review is, but I have one question in particular that I haven't found the answer to on the web... is the programmer part of the code review? In other words, should a code review be 2 people sitting together, going over what's in the code, or should it be 1 person looking at another person's code?

Most often, our projects are done by a team of 2 people, so before it is sent to QA, should those 2 people just sit together and go over the entire project, including what each of them have written? Or, should they just both look at each other's code? I can see advantages to each.

Finally, what happens with issues found during code review? Are they noted, and then sent back to the programmer? Or should the reviewer note them and then just fix them? Or is it ever ok to make a change and not even tell the programmer specifically what you found?

答:
You're essentially asking two questions:

Should the author of the work being inspected be part of the review?

Should you track the feedback?

In my experience, including the author of the work is essential.

The author will have the opportunity to participate in and learn from
any discussion that happens.

The author is likely best suited to address any defects found in the work; if they only receive an action item list without being present for the review, they miss context of    any discussion.

The author may be called upon to defend the way in which an artifact was written.

As for tracking the feedback of the review:  Yes, it should be tracked.

Of the items found, which are training issues?

Which are best practices that should be followed for all future work?

Which defects were defects because the code is difficult to read, poorly documented, etc.?

Which defects speak to larger issues that require more work than a response to the inspection -- should they better be tracked as distinct bug tickets to be worked as resources allow?

Do you have plans to achieve CMMI compliance of any sort?

You'll want to track all defects that were found and the fact that each has been resolved.

Does your customer or contract require all code be reviewed?

You'll want to track issues and inspection materials so you can answer "YES" and demonstrate that if necessary.

Title: What does a code review look like?