答:
I'm betting the programmer was just annoyed with the counter-intuitiveness of a 0 based array in day to day thinking and was arguing for a more intuitive means of describing arrays. I find it ironic that as humans we spent so much time to come up with "classes" so that we could describe things in a more human way in our code, but then when looking at 0 vs 1 arrays we seem to get hung up on the logic of it alone.

As far as the computer is concerned and mathematically 0 is going to probably be better, but I feel a point is being missed here. If we wanted to describe things in a more human way (e.g. classes), why wouldn't we want the same for other parts of the language? Is that not equally logical or valid (or take higher priority for that matter...) to make a language more easily understandable and usable to humans and thus, by extension, less prone to scenarios that tend to create logic-bugs and more prone to faster production of a usable creation. PHP Example:

```<code>array(1 => 'January', 'February', 'March');
</code>```

gives a 1 based array per our request.

Why not have the norm:

```<code>array('January', 'February', 'March');
</code>```

And the exception be:

```<code>array(0 => 'Value for scenario where 0 *has* to be used as the key',
      'value2', 'value3');
</code>```

In the case of say PHP, my bet is 80% of the time a 1 based array being the default syntax-wise would decrease logic-bugs in real world use cases, or at least not cause more on average, while making it a lot easier on the coder to produce usable code quicker. Remember, I'm assuming there would still be the option of, array(0 => 'value') for when it's needed, but also assuming the majority of the time it's practical to have something closer to a real world description.

This really doesn't sound too far fetched of a request when looking at it from that perspective. When approaching an interface, be it an OS or a language for a programmer, the closer to human thinking and habits we design it around, the happier in most cases we will be and the less misunderstandings between the human and the computer(human logic-bugs), and the faster production, etc. we will have. If 80% of the time in the real world I describe things with 1 when making lists or counting, then the computer should ideally interpret my meaning into a way it understands with as little information or change from my normal way of describing something as possible. In short the closer we can model the real world, the better quality the abstraction. So what he wants is by no means stupid since that is the ultimate goal and would be evidence of a need for more abstraction. The computer can still ultimately see it as a special use of a 0 based array. I could care less how the computer interprets it so long as it's a simpler and more intuitive way for me to describe what I want to it with less bugs over time.

So, that's my two cents. I seriously doubt what he was saying, or what was interpreted, was what he meant. What he probably meant was, "I hate having a less-intuitive way of telling the computer what I want." :) Don't we all? lol.

Title: Why are zero-based arrays the norm?

Body:
I'm betting the programmer was just annoyed with the counter-intuitiveness of a 0 based array in day to day thinking and was arguing for a more intuitive means of describing arrays. I find it ironic that as humans we spent so much time to come up with "classes" so that we could describe things in a more human way in our code, but then when looking at 0 vs 1 arrays we seem to get hung up on the logic of it alone.

As far as the computer is concerned and mathematically 0 is going to probably be better, but I feel a point is being missed here. If we wanted to describe things in a more human way (e.g. classes), why wouldn't we want the same for other parts of the language? Is that not equally logical or valid (or take higher priority for that matter...) to make a language more easily understandable and usable to humans and thus, by extension, less prone to scenarios that tend to create logic-bugs and more prone to faster production of a usable creation. PHP Example:

array(1 => 'January', 'February', 'March');

gives a 1 based array per our request.

Why not have the norm:

array('January', 'February', 'March');

And the exception be:

array(0 => 'Value for scenario where 0 *has* to be used as the key',
      'value2', 'value3');

In the case of say PHP, my bet is 80% of the time a 1 based array being the default syntax-wise would decrease logic-bugs in real world use cases, or at least not cause more on average, while making it a lot easier on the coder to produce usable code quicker. Remember, I'm assuming there would still be the option of, array(0 => 'value') for when it's needed, but also assuming the majority of the time it's practical to have something closer to a real world description.

This really doesn't sound too far fetched of a request when looking at it from that perspective. When approaching an interface, be it an OS or a language for a programmer, the closer to human thinking and habits we design it around, the happier in most cases we will be and the less misunderstandings between the human and the computer(human logic-bugs), and the faster production, etc. we will have. If 80% of the time in the real world I describe things with 1 when making lists or counting, then the computer should ideally interpret my meaning into a way it understands with as little information or change from my normal way of describing something as possible. In short the closer we can model the real world, the better quality the abstraction. So what he wants is by no means stupid since that is the ultimate goal and would be evidence of a need for more abstraction. The computer can still ultimately see it as a special use of a 0 based array. I could care less how the computer interprets it so long as it's a simpler and more intuitive way for me to describe what I want to it with less bugs over time.

So, that's my two cents. I seriously doubt what he was saying, or what was interpreted, was what he meant. What he probably meant was, "I hate having a less-intuitive way of telling the computer what I want." :) Don't we all? lol.

OwnerDisplayName: Brian Chandler


问:
Why are zero-based arrays the norm?
A question asked here reminded me of a discussion I had with a fellow programmer. He argued that zero-based arrays should be replaced with one-based arrays since arrays being zero-based is an implementation detail that originates from the way arrays and pointers and computer hardware work, but these sort of stuff should not be reflected in higher level languages.

Now I am not really good at debating so I couldn't really offer any good reasons to stick with zero-based arrays other than they sort of feel like more appropriate. Why is zero the common starting point for arrays?

答:
Using 1-based arrays, transform a single-dimension array into a multi-dimensional array:

```<code>int w = 5, h = 5, d = 5;

int[] a1 = new int[w * h * d], new a2 = int[w,h,d];

for (int z = 1; z <= d; z++)

  for (int y = 1; y <= h; y++)

    for (int x = 1; x <= w; x++)

      a1[x + (y - 1) * w + (z - 1) * h] = a2[x,y,z];
</code>```

Note that your y and z indexes are 0-based (y - 1, z - 1) even when your array is 1-based. Under some circumstances, you can't avoid 0-based indexes. For consistency, why not always use 0-based indexes?

OwnerDisplayName: DrJokepu

ContentLicense: CC BY-SA 3.0

Title: Why are zero-based arrays the norm?

Body:
Using 1-based arrays, transform a single-dimension array into a multi-dimensional array:

int w = 5, h = 5, d = 5;

int[] a1 = new int[w * h * d], new a2 = int[w,h,d];

for (int z = 1; z <= d; z++)

  for (int y = 1; y <= h; y++)

    for (int x = 1; x <= w; x++)

      a1[x + (y - 1) * w + (z - 1) * h] = a2[x,y,z];

Note that your y and z indexes are 0-based (y - 1, z - 1) even when your array is 1-based. Under some circumstances, you can't avoid 0-based indexes. For consistency, why not always use 0-based indexes?

OwnerDisplayName: enjerth

ContentLicense: CC BY-SA 2.5


答:
Because there is a strong correlation between arrays and pointers in C

```<code>char* p = "hello";
char q[] = "hello";

assert(p[1] == q[1]);

assert(*p == *q)
</code>```

*p is the same as *(p + 0)

having a starting index of 1 will give you headache later

Title: Why are zero-based arrays the norm?

Body:
A question asked here reminded me of a discussion I had with a fellow programmer. He argued that zero-based arrays should be replaced with one-based arrays since arrays being zero-based is an implementation detail that originates from the way arrays and pointers and computer hardware work, but these sort of stuff should not be reflected in higher level languages.

Now I am not really good at debating so I couldn't really offer any good reasons to stick with zero-based arrays other than they sort of feel like more appropriate. Why is zero the common starting point for arrays?

Body:
Because there is a strong correlation between arrays and pointers in C

char* p = "hello";
char q[] = "hello";

assert(p[1] == q[1]);

assert(*p == *q)

*p is the same as *(p + 0)

having a starting index of 1 will give you headache later

OwnerDisplayName: Anders K.


答:
Why do you want arrays to start at one?

When you say a[x][y], the compiler translates this into: a+(x*num_cols+y).  If arrays started at one, this would become a+(x*num_cols+y-1).  This would be an extra arithmetic operation every single time you want to access an array element.  Why would you want to slow down programs?

Title: Why are zero-based arrays the norm?

OwnerDisplayName: Borealid


答:
The reason it starts at 0 and not 1 is that the you can think of the offset as how far from the beginning of the array's memory is this element.  It's not saying give me the 0th element -- it's saying, give me the element who is 0 elements from the start.

Another way to look at it is that these are (for the most part) equivalent:

```<code>array[n]

*(array + n)
</code>```

The reason the standard won't ever be changed is because C has been around for about 40 years now.  There is no compelling reason to change it and if they did, all of the existing code that depends on the start of the array being at 0 would be broken.

Title: Why are zero-based arrays the norm?

Body:
The reason it starts at 0 and not 1 is that the you can think of the offset as how far from the beginning of the array's memory is this element.  It's not saying give me the 0th element -- it's saying, give me the element who is 0 elements from the start.

Another way to look at it is that these are (for the most part) equivalent:

array[n]

*(array + n)

The reason the standard won't ever be changed is because C has been around for about 40 years now.  There is no compelling reason to change it and if they did, all of the existing code that depends on the start of the array being at 0 would be broken.

OwnerDisplayName: Dennis Munsie


答:
It is possible if you take care while writing your "own" code. You can assume your index starts from n for all n>=0 and program accordingly.

Regarding standard, Borealid has a great argument.

Title: Why are zero-based arrays the norm?

OwnerDisplayName: Praveen S


答:
It's because of how arrays are constructed.  It doesn't make a lot of sense for them to start from one.  An array is a base address in memory, a size, and an index.  To access the nth element, it's:

```<code>base + n * element_size
</code>```

So 0 is obviously the first offset.

Title: Why are zero-based arrays the norm?

Body:
It's because of how arrays are constructed.  It doesn't make a lot of sense for them to start from one.  An array is a base address in memory, a size, and an index.  To access the nth element, it's:

base + n * element_size

So 0 is obviously the first offset.

OwnerDisplayName: Gian


答:
An array in C is shorthand for pointer arithmetic. Consider this case:

```<code>struct Foo *foo;
struct Foo foos[10];

foo = &(foos[1]);
foo = foos + (1 * sizeof(struct Foo));
</code>```

The last two lines mean the same thing. Changing the initial offset would break this correlation, making many things in C much more difficult.

Some languages with a very strict Array type, like Pascal, allow you to start counting in other ways. But in C, and in many languages derived from C, arrays are just shorthand for pointer arithmetic, so you can't mess with their starting index.

Title: Why are zero-based arrays the norm?

Body:
An array in C is shorthand for pointer arithmetic. Consider this case:

struct Foo *foo;
struct Foo foos[10];

foo = &(foos[1]);
foo = foos + (1 * sizeof(struct Foo));

The last two lines mean the same thing. Changing the initial offset would break this correlation, making many things in C much more difficult.

Some languages with a very strict Array type, like Pascal, allow you to start counting in other ways. But in C, and in many languages derived from C, arrays are just shorthand for pointer arithmetic, so you can't mess with their starting index.

OwnerDisplayName: Rob Napier


答:
If you insist on having your arrays start at 1...

```<code>type real_foo[COUNT], *const foo=real_foo-1;
</code>```

If you're really sadistic, you could even make a preprocessor macro to do this for you...

```<code>#define CONCAT(x,y) x ## y
#define ARRAY1(name,size) CONCAT(real_, name), *const name=CONCAT(real_, name)-1
type ARRAY1(foo, COUNT);
</code>```

Hope I didn't screw up those macros...

Title: Why are zero-based arrays the norm?

Body:
If you insist on having your arrays start at 1...

type real_foo[COUNT], *const foo=real_foo-1;

If you're really sadistic, you could even make a preprocessor macro to do this for you...

#define CONCAT(x,y) x ## y
#define ARRAY1(name,size) CONCAT(real_, name), *const name=CONCAT(real_, name)-1
type ARRAY1(foo, COUNT);

Hope I didn't screw up those macros...


答:
C is a very simple language (or so they say). Its design was based strongly on available hardware features, i.e. on ease of implementing the compiler. Indexing an array translates directly into pointer arithmetic, so:

```<code>int array[256];
int i = 10;
...
array[i] = 12;
</code>```

translates into something like:

```<code>*(array + i*sizeof(int)) = 12;
</code>```

or in imaginary intermediate machine language:

```<code>load value of array into register Ra
load value of i into register Rb
right shift Rb by X number of bits
add value in Rb to value in Ra
store value 12 at address in Ra
</code>```

(Note: here array is the address fixed at load time, so I say "load value of array" - it's a bit different for indexing a pointer, one more indirection is required to obtain the base address.)

With this in mind zero-based indexing is only natural.

Title: Why are zero-based arrays the norm?

Body:
C is a very simple language (or so they say). Its design was based strongly on available hardware features, i.e. on ease of implementing the compiler. Indexing an array translates directly into pointer arithmetic, so:

int array[256];
int i = 10;
...
array[i] = 12;

translates into something like:

*(array + i*sizeof(int)) = 12;

or in imaginary intermediate machine language:

load value of array into register Ra
load value of i into register Rb
right shift Rb by X number of bits
add value in Rb to value in Ra
store value 12 at address in Ra

(Note: here array is the address fixed at load time, so I say "load value of array" - it's a bit different for indexing a pointer, one more indirection is required to obtain the base address.)

With this in mind zero-based indexing is only natural.

OwnerDisplayName: Nikolai N Fetissov


答:
It's certainly possible but the C language does not support this.  Many other languages such as Fortran, PL/1, Pascal, Modula2, Ada support this.

It was part of the C language design to keep the compiler simple and small and it would break too many things to change it now.

Title: Why are zero-based arrays the norm?

OwnerDisplayName: progrmr


答:
because array names are constant pointers to array starting positions. For example In C array[2] is turned into array + (sizeof(array)*2), which will give you two elements beyond the starting element(third element:)).
so if you want to reach the starting element, with the same math, you should do

array + (sizeof(array)*i) = array

(sizeof(array)*i) = 0

i = 0

simple equation math.

Title: Why are zero-based arrays the norm?

OwnerDisplayName: LostMohican


答:
You can, but compiler optimizations are free to create invalid results (gcc and msvc won't, but clang will).

```<code>char* myArray = malloc(100) - 1;
/* now myArray[1] is the first element, and myArray[100] is the last. */
free(myArray + 1);
</code>```

But, as other people have mentioned, don't do this. Un-learn your bad habits of starting at 1.

Another solution: Just ignore the first element of the array.

Title: Why are zero-based arrays the norm?

Body:
You can, but compiler optimizations are free to create invalid results (gcc and msvc won't, but clang will).

char* myArray = malloc(100) - 1;
/* now myArray[1] is the first element, and myArray[100] is the last. */
free(myArray + 1);

But, as other people have mentioned, don't do this. Un-learn your bad habits of starting at 1.

Another solution: Just ignore the first element of the array.

OwnerDisplayName: Clark Gaebel


问:
Why is PHP so frequently used on web servers?
My web server uses PHP as do 77.7% of web servers according to W3Techs, as of 14/03/2022.

The reason I use PHP is an inertia born out of seeing everyone else using it on web servers. What is it about PHP that would make it so ubiquitous on web servers?

(Note that this question is similar to the following question but takes it in a different direction: Why isn't Java used for modern web application development?)

答: If you look around, most folks running PHP these days are running Wordpress, Drupal, Joomla and the like. Or one of 10,000 free, popular apps that pretty much work out of the box with a cheap PHP host and a little configuration. Many times it gets installed not because anyone is making something that runs on PHP so much as the easiest option is to use something built on PHP. </p>

ContentLicense: CC BY-SA 4.0


问:
Using a CMS that I'm not familiar with just for the sake of the job?
I've been designing and developing with Wordpress for about two years (and I love it). Recently, a respectable designer told me that I could work for him. He works with Joomla! My job was to create a Joomla! template. I didn't feel myself comfortable using it. I don't like the back-end's UI, the way you add elements and content (I don't even like Joomla!'s logo). I'm used to simple interfaces and Joomla! seems too cluttered to me.

That's why I started to wonder if I'm better off just finding clients and  using the CMS that I love or making an effort to learn a CMS that I don't like using?

答:
You're being a sissy here. Even if Joomla turns out to be utter garbage (which I doubt), approaching it open-mindedly and working on a project that uses it can only expand your horizon. Learning a framework isn't hard, it shouldn't take you more than a week or so to get the basics down, all the while you get paid for doing so. And complaining about the logo is plain out silly - vim, one of the best text editors in the world has a horrible logo, and let's face it, Tux isn't exactly a masterpiece either.

Imagine yourself on the other side - you have this project, and there's two candidates you think you might be hiring. One says, "I haven't used the stuff you're using before, but I'd love to get my hands dirty with new things", the other goes "Woohoo, why won't you let me use the shiny fluffy things that make me feel comfy!" - who do you hire?


问:
Average size of in-house web development team for U.S. companies?
When I graduated, I thought getting into a web development job meant I get to work in a group of at least a handful of developers, and seniors can teach this young Padawan their tricks of the trade. In my experience, when I get hired as a junior web developer I'm usually have really limited contact and collaboration with one or two other developers (because we seldom work on the same projects), or sometimes I'm the only one that knows how to code.

I've grown to hate these "lone wolf" positions and would rather work in a highly collaborative environment full of other programming geeks. Most of these places tend to outsource technical work, and I prefer face-to-face communication with peers in my dept.

I like the small-company culture but at the same time, there's such a thing as too small, to the point where there's little actual technical work done in-house so I can't get any expert advice.

Because my experience is anecdotal, I don't think I am getting the big picture as to the sizes and structures of web dev companies. So my related questions...

Is my lack of experience with large in-house teams due to the fact that I mostly get hired by consulting firms that do client work?

Do companies that create their own products have a vastly different structure?

What should I look for in a company if I want to get into a larger, in-house development team?

答:
The difference you notice is between a company that views the software as a Cost Center vs. a Profit Center.

If the bread and butter of the company is the software or SaaS that they are selling then they are more likely to invest the large sums of money into the software that would be necessary to employ a large team.

On the other hand if you are contracted to do a project for internal clients then it is viewed as overhead and it is a lot harder to justify a large SD team.


问:
What are some good tasks to assign co-op students/interns?
My company is investigating hiring a University Computer Science co-op student (BSc year 3) for a 4- or 8-month work term. (I'm not sure how internationally-recognized the term co-op is - it's essentially a paid internship, after which the student returns to their studies.) My team develops a web application in ASP.NET and handheld thick clients on iOS, BlackBerry, and Android.

For any of you that have brought interns into an experienced development team, what kind of tasks did you find for them to do? I realize that's a hard question to ask since any answer can be quite specific to an individual business.

I'd expect the following:

Tasks that require mentoring but not babysitting

Tasks that will take a few weeks to finish (so the mentor can remain productive)

Tasks that expand the student's understanding of software development

I've considered things like expanding code coverage in our unit tests, or developing a feature that's been designed, or improving/writing missing requirements documentation from features that were added without any supporting documentation.

I never did an internship so I don't know what sort of tasks are valuable to both the student and the company. Any recommendations?

Edit: These are all excellent and thoughtful answers that have helped me a great deal. Thank you all very much. I can only choose one answer, so I'll go along with the crowd and accept the most popular one.

答:
I'm going to have to say, it depends both on the co-op and how much time they will be with the company.

We employ co-ops here at my company that range from 4 month terms to 18 month terms. We often invite our co-ops back for another term as well.

You want to treat a co-op like a member of the team. Don't punt grunt work off on them if you can help it. It will not make an enjoyable term for them and could be wasting their skills.

To start off, they are like any other new employee, just without the extra work experience. What would you give a new hire their first week? Assume it will take the co-op two weeks to finish, with some extra guidance.

If they preform well on that task, see if you can give them something more. We have found here that if you give a co-op a task or ticket that is theirs, and make them apart of the team while working on it, it is often beneficial for the co-op and the company. We get actual work done and they learn a lot about how to work in the real world.

Don't throw a co-op at QA unless you hired them to be a QA. Nothing is worse for a co-op coming into a company thinking that they will be developing than to find out that they are just a tester. Unless you put in the posting that is what they will be doing, don't put them on that just b/c it's easy for you.

Of your ideas I would say "developing a feature that's been designed" would be the best one for a co-op. Test cases might work too, depending on the co-op.

At the end of the term, make them feel like they can look at something and say I did that, and I learned a lot doing it. Not, I spent 4 months writing documentation...I hated that place.


问:
Is agile more than just small waterfalls?
I've mostly used the waterfall methodology on my projects, but now I'm expanding my horizons into agile methodologies. From what I've read so far, and maybe I've read the wrong things, agile means small waterfalls. Instead of a big waterfall spread over one or two years, you have small waterfalls that last weeks or maybe a few months at most.

Is my understanding correct or is there more to it than that? What are the agile philosophies?

答:
Forget Agile a minute, think what is meant by "waterfall".

There is a requirements phase, in which everyone tries to figure out WHAT problems the end product needs to solve.  Folks argue about this for a while, and then they all sign off on a set of requirements.  At this point your scope is defined, contracts are signed, and the customer can wander off and wait for you to come up with a product that solves those defined requirements.

Next there is one (or maybe two) design phase(s).  The designers (who may or may not be the developers), argue about HOW the system must go together to meet the signed-off requirements.  Problems may occur if they don't quite understand a requirement, which may mean they have to go back to the customer, potentially re-opening the requirements phase (and getting another round of sign offs) or at least setting change-management into action.  Often, the designers simply make their best guess.  They may come up with a logical data model, and lots of UML describing a new system and how it should work.  Then they sign off on it.

Now the developers get to actually start coding, based on the signed-off design.  Problems may occur if they don't quite understand the design, which may mean they have to go back to the designer, potentially re-opening the design phase (and getting another round of sign offs) or at least setting change-management into action.  The designers may in turn realize that the confusion really goes back to the requirements, meaning that they have to re-open requirements discussions, sign-offs, and further change management.  Often, the programmers (who have a deadline looming) simply make their best guess.  They do what they can to make functional code.  Then they release it to testing.

Now the system testing phase sets in.  Testers test based on their understanding of the requirements and design, and register what they perceive as defects into a bug tracking/change management system, causing the developers to start developing again, unless they see the issue as a design flaw, which sends it back to design, etc...  Eventually the system  tests pass and are signed off on.

Finally, the customer comes back and does user acceptance tests on the new system.  This is where they decide whether the solution the testers tested, developers developed, and designers designed is actually what they want.  If it isn't, you potentially have to revert back to the design phase or even revisit requirements.

The idea behind waterfall is that it is difficult (and very undesirable) to go back once a phase is complete.  Different people are generally involved in different phases, so there are multiple hand-offs--each of which introduces a lot of risk for misinterpretation and information loss.  There is also a significant gap between when the customers say what they want and when they see what has been built, in which time the real requirements may very well have changed.

Agile methodologies focus on strong communication and cooperation between all the interested parties.  The principle "Customer collaboration over contract negotiation" means that you should not have to go through a series of sign-offs and hand-offs, but instead should simply work together with the customer, each iteration determining the requirements for a piece of the puzzle and immediately forming tests, a design, and working code--with all the players communicating as directly as possible (eliminating hand-off costs and risks).  The working code is quickly testable by the customer, eliminating time lag risks.  All the activities happen in a collaborative swirl, not in a downward flow.

For an excellent overview of what agile methodologies try to do, I'd highly recommend Allistair Cockburn's Agile Software Development: The Cooperative Game.


问:
What's a neat project to help me get used to the modern environment?
I haven't been programming for almost a decade. I used to be able to program in QBasic, Turbo Pascal, C, C++, Visual Basic and Assembly. I have no knowledge in any other programming language (other than HTML).

I want a project (in some programming language) to help me acquaint myself with the new environment (unix, python, perl, java, flash?) in a way that would give me the feeling that I've gained a mini-super-power. By that I mean something that give me the feeling of hacking (not actually learn about hacking, but just like learning C for the first time feels like hacking). Something that would put my programming skills to use in a way that the programming languages I do (did) know don't.

答:
this is my standard answer

I've implemented either a betting pool or a Baccarat game in almost every language I've learned. This should wake up your dormant programmer neurons.

This type of software covers

Dates and times, with calculations

Currency types and things that can be converted to and from currency

A discrete set of rules that is easy to test

States, transition between states and multiple entities responsible for state transition

Multiple users with different views of the same model

Multiple end conditions

I like this project because it has tons of small parts that can be written interdependently but won't be done-done until all the parts are done.

Multiple player blackjack and poker would work also.

This is assuming you are looking to learn the following:

Modern strongly typed dynamic language

Web app programming

Modern dev workflow with unit testing, automated build & deploy, version control

Current trends in UI

Current IDE & VCS etc

I would recommend ruby or python as the language with either Django (python) or Sinatra (ruby) as the web tier. Sinatra apps look (and can act like) command line apps so there is that advantage.

Both Ruby and python have really nice unit testing options. With ruby you can start with the basic test:unit and then learn RSpec. With python, start with unittest then look at Pyramid or Cheese Shop.

Use subversion as the VCS. All the new DVCS borrow from svn for their syntax. Learn SVN (it should be very similar to the old VCS you used) and then look at git and mercurial.

Use Eclipse if you want and IDE. If you used to know vi really well, try VIM. if you're on a Mac, try textmate. On windows, notepad++ is pretty good.

One caveat is that in my day job I work on financial systems and there is a huge overlap between things to consider when writing a multiplayer game of chance and a trading system.

OwnerDisplayName: Shannon

LastEditorDisplayName: Shannon


答:
I did an internship during my university days (for 14 months).

I was basically treated the same as all other full time members of staff. I was given similar tasks and I did pretty much the same work as everyone else.

It was exactly like I hoped it would be as I find I learn best when tossed in at the deep end.

If I had instead been given menial tasks or expected to just test other developers work I would not have enjoyed it and it would not have left me with a good impression.

Title: What are some good tasks to assign co-op students/interns?

Body:
My company is investigating hiring a University Computer Science co-op student (BSc year 3) for a 4- or 8-month work term. (I'm not sure how internationally-recognized the term co-op is - it's essentially a paid internship, after which the student returns to their studies.) My team develops a web application in ASP.NET and handheld thick clients on iOS, BlackBerry, and Android.

For any of you that have brought interns into an experienced development team, what kind of tasks did you find for them to do? I realize that's a hard question to ask since any answer can be quite specific to an individual business.

I'd expect the following:

Tasks that require mentoring but not babysitting

Tasks that will take a few weeks to finish (so the mentor can remain productive)

Tasks that expand the student's understanding of software development

I've considered things like expanding code coverage in our unit tests, or developing a feature that's been designed, or improving/writing missing requirements documentation from features that were added without any supporting documentation.

I never did an internship so I don't know what sort of tasks are valuable to both the student and the company. Any recommendations?

Edit: These are all excellent and thoughtful answers that have helped me a great deal. Thank you all very much. I can only choose one answer, so I'll go along with the crowd and accept the most popular one.


答:
I'm a current student of Computer Science, currently doing a 4-month co-op work term. After this term I will start my 3rd year of study, so I guess I'm a year under your target student audience. Regardless, I'd still like to share a little of my (and older acquaintances') experience.

Companies provide different roles to students with different skillsets. Programming in general has a versatile pool of tasks to choose from: for me, I do server maintenance on an internal file management server using VB.NET and C#, building on 7 previous years of other co-op student work. Others have gotten testing (QA) jobs, along with generic programmer descriptions. Like you said, it depends heavily on the business, but depending on the student's skill level, it is highly common to involve them (us) with web app development as well. Whether they're internal or for client use is largely irrelevant to the student's interest, since either way, they'll get the experience they want. Start off with easy tasks drawn from your business's needs, and assign them more / less / harder / easier work based on performance. This makes us valuable to your company in the time we're there, and as far as making the experience valuable to the students, just programming outside of school is useful. Give us code and we'll be happy (as long as it's not Turing or something).


答: Small, completable, modular projects are, to me, the ideal. Something where they can see their project through from start to finish, but get the experience of working with something that will be part of a larger project, rather than just an example toy.</p>


问:
Release Planning in Agile/Extreme Programming
I've been studying couple of books of how to exactly implement agile. I am confused about release planning.

Our application is a Insurance System consisting of different modules (Quoting, Policy Management, Claims management etc). During the first phase we are just planning to release Quoting and we are estimating approximately 4 months for it.

Now my question is, do we have to identify user stories for overall system (including all the other modules) first before start working on our first release (i.e quoting)? Or is release planning is an iterative process too?

答:
Agile == Iterative.

That's all there is to it.  Everything is iterated.  Requirements.  Design.  Code.  Test.  Development Sprints.  Release Sprints.

Every day is an iterative process of daily stand-up followed by work.

The Whole Point is to avoid the cost and risk of attempting to foresee the future and magically plan everything.  It cannot be planned, so don't try.

Do we need to explore features for entire system during the initial phase?

You can't.  So don't try.

You can't foresee the future.  After you start releasing parts your users learn -- and you learn -- and you realize that what you originally thought was wrong.

Agile == Learning.  Learn as you go.  Allow the project plan to reflect learning as you go.

During the first phase we are just planning to release Quoting

Why?  Is this highest business value to the stakeholders?   Is this the most important part?  Does this create the most immediate, short-term, "right-now" value for the users?


答:
I'd treat a co-op/intern student like any other junior employee. Mostly they are probably there to gain experience working in a software development enviroment, and will need plenty of mentorship on things including 1) source control and codebase structure, 2) bug triage and handling, 3) producing production code with attention to code quality and readability. These are things that probably don't get covered much in CS/engineering school curricula (lots of math though!).

I'd definitely emphasize any tasks that require getting to know bug reporting systems or source control since these are great toolsfor a co-op student to get to know well. They also will indirectly force students to improve technical reading/writing/communication skills and to become more organized. Maintenance programming comes to mind as another task that will be beneficial ("Refactor some the ChildClass methods to better integrate with the new GUIObject interface").

Testing and QA is something else which is good for co-op students. Testing is a good way to get co-op students familiar with the application and the general processes of your workplace, but it may create the impression that testing is "easy" and just something that people who start out with "have to deal with".

Most importantly, as mentioned by other answers here, be honest with co-op students: don't hire one on the promise of being a developer writing code and stick them with a support position or coffee gopher. If you wouldn't do this to a regular new hire, don't do it to a co-op student.


答:
I think it all boils down to the size of the projects/sites. Not all sites require a team of developers.

When building websites is not the company's line of business, they're more likely to hire someone outside to build it rather than have to hire 5 devs from day one. Some start with one dev and grow a larger team because they've become accustomed and can utilze an in house team.

A niche site can survive with one dev, but I'm guessing to get some scale and make money requires a bigger group. If software is your business, I can't imagine farming the whole thing out unless you're a dev and you feel you have the expertise to manage several independant contractors.

Look for jobs that require candidates to be able to work with a team. It's not a guarantee that you'll be on muli-developer websites, but it's a start.

Title: Average size of in-house web development team for U.S. companies?

Body:
When I graduated, I thought getting into a web development job meant I get to work in a group of at least a handful of developers, and seniors can teach this young Padawan their tricks of the trade. In my experience, when I get hired as a junior web developer I'm usually have really limited contact and collaboration with one or two other developers (because we seldom work on the same projects), or sometimes I'm the only one that knows how to code.

I've grown to hate these "lone wolf" positions and would rather work in a highly collaborative environment full of other programming geeks. Most of these places tend to outsource technical work, and I prefer face-to-face communication with peers in my dept.

I like the small-company culture but at the same time, there's such a thing as too small, to the point where there's little actual technical work done in-house so I can't get any expert advice.

Because my experience is anecdotal, I don't think I am getting the big picture as to the sizes and structures of web dev companies. So my related questions...

Is my lack of experience with large in-house teams due to the fact that I mostly get hired by consulting firms that do client work?

Do companies that create their own products have a vastly different structure?

What should I look for in a company if I want to get into a larger, in-house development team?


答:
The further away something is on the horizon, the less granular the planning should be.

For example:

Ensure you have acceptance criteria specified for all the stories the team might get to in the next 2 weeks of work (e.g. in the Given/When/Then form).

Ensure you have identified stories for the next 10 weeks of work. Just one sentence will do (e.g. using the As a ... I want .... So that form).

Ensure you have high-level epics/features listed in a roadplan covering next 6 months and beyond

Title: Release Planning in Agile/Extreme Programming

Body:
I've been studying couple of books of how to exactly implement agile. I am confused about release planning.

Our application is a Insurance System consisting of different modules (Quoting, Policy Management, Claims management etc). During the first phase we are just planning to release Quoting and we are estimating approximately 4 months for it.

Now my question is, do we have to identify user stories for overall system (including all the other modules) first before start working on our first release (i.e quoting)? Or is release planning is an iterative process too?


问:
My customer wants me to record a video of how I develop his software product
Working as a freelancer, I often see strange requests from my customers, some of which can negatively affect my daily work¹, and others trying to set some sort of control. I usually encounter those things during preliminary negotiations, so it's easy enough at this stage to explain to the customer that I do care about my work and productivity and expect my customers to trust my work.

Things were much harder² on a project I just accepted, since it's only after the end of the negotiations (the contract has already been signed and did not mention anything about video tracking) and after I started to work on the project that my customer requested that I record a video of all I do on my machine when working on his project, that is, a video which will show that I move the cursor, type a character, open a file, move a window, etc.

I work in my own company, using my own PCs.

I answered to this customer that such request cannot be accepted, since:

Hundreds of hours of work on a dual-screen PC will require a large amount of disk space for the recorded videos. If I don't care about space, I do care about this customer wasting my bandwidth downloading those videos.

Recording a video can affect the overall performance and decrease my productivity (which is not actually true, since the machine is powerful enough to record this video without performance loss, but, well, it still looks like a valid argument).

I can't always remember to turn the video recording on before starting the work, and off at the end.

It may be a privacy concern. What if I switch to my mails when recording the video? What if, to open the directory with the files about this customers project, I first open the parent directory containing the list of all of my customers?

Such video cannot be a reliable source to track the cost of a project (I'm paid by the hour), since some work is done with just a pencil and a paper (which is actually true, since I do lots of draft work without using the PC).

Despite those points, the customer considers that if I don't want to record the video, it's because I have something to hide and want to lie about the real time spent on his project³.

How to explain to him that it is not usual practice for freelancers to record videos of their daily work, and that such extravagant requests must be reserved for exceptional circumstances⁴?

¹ The most frequent example is to be requested to work through Remote Desktop on a more-than-slow server which uses a more-than-slow Internet connection, or to be forced to use outdated software such as Windows Me without serious justification such as legacy support.

² In fact, I already did a lot of management and system design related work, which is essential, but usually misunderstood by customers and perceived as a waste of time and money. Observing the concerned customer, I'm pretty sure that he will refuse to pay a large amount of money for what was already done, since there is actually zero lines of code. Even if legally I can easily prove that there was a lot of work undertaken on the design level, I don't want to end my relation with this customer in a court.

³ Which is not as risky as it could be, since I gave this customer the expected and the maximum cost of the project, so the customer is sure to never be asked to pay more than the maximum amount, specified in the contract, even if the real work costs more.

⁴ One case when I effectively record on my own initiative the video of actions is when I have to do some manipulations directly on a production server of a customer, especially when it comes to security issues. Recording those steps may be a good idea to know precisely what was done, and also ensure that there were no errors in my work, or see what those errors were.

First update

Since the question attracted much more attention and had many more answers than I expected, I imagine that it can be relevant to other people, so here is an update. First, to summarize the answers and the comments, it was suggested to (ordered randomly):

Suggest other ways of tracking, as shown in Twitter Code Swarm video, or deliver a "short milestone with a simple, clear deliverable, followed by more complex milestones", etc.

Explain that video is not a reliable source and can be faked, and that it would be difficult to implement, especially for support.

Explain that video is not a reliable source since it shows only a small part of the work: a large amount of work is done without using a computer, not counting the extra hours spent thinking about a solution to a problem.

Stick with the contract; if the customer wants to change it, he must expect new negotiations and a higher price.

Do the video, "but require that the customer put [the] entire fee into an escrow account", require a lawyer to video tape all billable time, etc., in other words, "operate in an environment void of trust", requiring the customer to support the additional cost.

Search for the laws which forbid this. Several people asked in what country I live. I'm in France. Such laws exist to protect the employees of a company (there is a strict regulation about security cameras etc., but I'm pretty sure nothing forbids a freelancer to sign consciously a contract which forces him to record the screen while he works on a project.

Just do it and send the videos: the customer will "watch a few ten second snippets of activity he won't understand", then throw those videos away.

Say no. After all, it's my business, and I'm the only one to decide how to conduct it. Also, the contract is already signed, and has nothing about video tracking.

Say no. The processes and practices I employ in my company can be considered as trade secrets and are or can be classified.

Quit. If the relation starts like this, chances are it will end badly sooner or later. Also, "if he's treating you like a thief - and that is what he's suggesting - then it's just going to get worse later when XYZ feature doesn't work exactly the way he envisioned".

While all those suggestions are equally valuable, I've personally chosen to say to my customer that I accept to do the videos, but in this case, we must renegotiate the contract, keeping in mind that there will be a considerable cost, including the additional fee for copyright release. The new overall cost would be on average three times the actual cost of the project. Knowing this customer, I'm completely sure that he would never accept to pay so much, so the problem is solved.

Second update

The customer effectively declined the proposal to renegotiate the original contract, taking into account the considerable additional cost. He agreed to continue the project without video recording.

The project continued without video recording. Eventually, the customer seemed satisfied by the final result and cost, so the video recording was not mentioned again.

答:
I've run a consulting firm (12 people) and been a freelancer for 16 years.  I've dealt with many, many sizes, shapes, and kinds of firms.

Believe me on this one: any firm that makes such a request has control & trust issues, and this can only end badly.  The relationship is already precarious, I would even say damaged.

If you have the luxury, I'd consider running away from the client & the project as fast as you can.  If financial or contractual concerns take "firing the customer" off the table, I feel for you.  As others have said, this is a new contract: negotiate more money, etc. or just say that you cannot continue under any terms not stipulated in the original contract.

Some of the best business decisions I've made in my life have been when I've fired unreasonable/extremely difficult/impossible to satisfy customers.  Doesn't happen often, especially now (my radar is more finely-tuned than it was when I started), but you have to know when to "cut bait".


问:
How exactly do we go from Binary/Hex to Assembly Instruction sets?
So i've been trying to learn some Embedded/Assembly programming for a bit here lately, as well as going far as trying to learn the lowest level (gates and such).

One thing puzzles me though....is how do we "get" instruction sets. I understand somewhat how gates/TTL and such works, but I don't see how we get from that to mov,add,clr etc...?

It's probably a stupid question....but I mean I think back to the first micro-processors/controllers and think....how exactly did they design an instruction set and make it work?

edit: I guess for Clarity, pretend im talking about the first microprocessor, how did they go from Binary to actually creating an Instruction Set?

答:
A computer at a very low level can be represented by a data path and control.  Googling these together may give you a lot of reading as it is fundamental in digital architecture/design.

I'll do my best to summarize:

As mentioned here, at the heart we have an ALU - what needs to be known about the ALU (and other parts of the CPU) is that it is reconfigurable for different operations.  More specifically, we have the ability to reconfigure the data path, which is how parameters are fetched, what operation to do, and where they are stored afterwards.  Imagine being able to manipulate these three things - this is our control.

So how do we accomplish this?  As mentioned already again, we can take advantage of low level digital logic and create multiplexers for different paths.  Multiplexers are controlled using a set of bits for input - where are these bits taken from?  Encoded from the instructions themselves.  The takeaway: Instructions like mov, add, etc are just a set of bits that tell a CPU how to configure its datapath for a particular operation.  What you're reading (mov, add) is the human readable form (assembly language) and our program defines a procedure of datapaths and operations.

I apologize if this is an oversimplification of more complex processes to those who are more knowledgable in this area.  FYI, the electrical engineering stack-exchange would be a great place to ask this question as it deals with very low level logic.


问:
What is the most egregious waste of money you have seen, and what did you do about it?
Often we as programmers see large organisations wasting huge sums of money on bloated and inefficient solutions to problems. This pains me greatly because I like organisations to benefit from best of breed solutions. However, my abilities as a programmer are limited when it comes to influencing the key decision makers and often my perspective on the matter is constrained to my own little technical world.

So, my question is this. After encountering an egregious waste of money on some software and/or hardware that really got your goat, what did you do about it to get it fixed or were you doomed to bite the bullet and mutter forever under your breath? I'm interested in hearing your overall experiences and especially what lessons you learned about how to tackle this sort of thing in the future. Let's not name names, the experience of how to tackle the problem is more important than the actual offending product.

答:
I know that this is an old question & I'll be lucky if 3 people read this answer, but it's a fun story to tell, so what the hell.

I came into a project (embedded systems, safety-critical firmware, very high stakes) and I was appalled by what I found.  People using C (especially pointers) incorrectly, no static analysis, no code reviews, no testing other than "integrate it together, run it, beat on it, see what breaks."

I wrote a very long email my first week there (as a consultant).  It was dicey because I was basically saying it was mis-managed, the developers were in over their heads, no process was being followed, etc.  It should have gone to the corporate VP, but instead I sent it to the development manager who hired me.  He was not entirely defensive about it, in fact he acknowledged many of the shortcomings & told me I wasn't the first to point them out (no kidding, right?)

To answer the crux of the original question: I offered to spend AT MOST 1 man-week getting Gimpel's Lint (PC-Lint / Flexelint) static analysis tool configured & running on their platform, and to run a full report of everything that was found.  I told them I was absolutely sure that we'd find several lurking "timebombs" as a result.

They calculated my hourly rate, multiplied it by 40, and determined it was "too expensive to do that."  Long story short, I left there within 60 days.  About 3 years later, I learned of a product recall, the cost approached 9 figures ($100M), not to mention damage to the company's reputation.

I won't mention the company, the product, or the industry, but I still keep in touch with one of the engineers there, and when he explained to me what caused the recall, my eyes rolled - it was a problem that would have been caught by even a basic static analysis tool (accessing an array out of bounds).  In fairness, I cannot say with certainty that the problem was in the code when I was there, but I'm sure if they'd spent the money on some kind of static analysis tool, that bug would not have escaped.

So they saved $295 by not buying PC-Lint (OK, they also saved a week of paying me, at most) - but I'm nowhere good enough to charge $100M for a week.

That's what I call a pretty damn big waste of money.

Reminds me of a joke that many of you may have already heard:

Ever heard the story of the giant ship engine that failed? The ship’s owners tried one expert after another, but none of them could figure but how to fix the engine. Then they brought in an old man who had been fixing ships since he was a youngster. He carried a large bag of tools with him, and when he arrived, he immediately went to work. He inspected the engine very carefully, top to bottom.

Two of the ship’s owners were there, watching this man, hoping he would know what to do. After looking things over, the old man reached into his bag and pulled out a small hammer. He gently tapped something. Instantly, the engine lurched into life. He carefully put his hammer away. The engine was fixed! A week later, the owners received a bill from the old man for $10,000.

"What?!" the owners exclaimed. "He hardly did anything!"

So they wrote the old man a note saying, "Please send us an itemized bill."

The man sent a bill that read:

```<code>  Tapping with a hammer ........ $ 2.00

  Knowing where to tap ......... $ 9998.00
</code>```

Effort is important, but knowing what you're doing makes all the difference.

Body:
I know that this is an old question & I'll be lucky if 3 people read this answer, but it's a fun story to tell, so what the hell.

I came into a project (embedded systems, safety-critical firmware, very high stakes) and I was appalled by what I found.  People using C (especially pointers) incorrectly, no static analysis, no code reviews, no testing other than "integrate it together, run it, beat on it, see what breaks."

I wrote a very long email my first week there (as a consultant).  It was dicey because I was basically saying it was mis-managed, the developers were in over their heads, no process was being followed, etc.  It should have gone to the corporate VP, but instead I sent it to the development manager who hired me.  He was not entirely defensive about it, in fact he acknowledged many of the shortcomings & told me I wasn't the first to point them out (no kidding, right?)

To answer the crux of the original question: I offered to spend AT MOST 1 man-week getting Gimpel's Lint (PC-Lint / Flexelint) static analysis tool configured & running on their platform, and to run a full report of everything that was found.  I told them I was absolutely sure that we'd find several lurking "timebombs" as a result.

They calculated my hourly rate, multiplied it by 40, and determined it was "too expensive to do that."  Long story short, I left there within 60 days.  About 3 years later, I learned of a product recall, the cost approached 9 figures ($100M), not to mention damage to the company's reputation.

I won't mention the company, the product, or the industry, but I still keep in touch with one of the engineers there, and when he explained to me what caused the recall, my eyes rolled - it was a problem that would have been caught by even a basic static analysis tool (accessing an array out of bounds).  In fairness, I cannot say with certainty that the problem was in the code when I was there, but I'm sure if they'd spent the money on some kind of static analysis tool, that bug would not have escaped.

So they saved $295 by not buying PC-Lint (OK, they also saved a week of paying me, at most) - but I'm nowhere good enough to charge $100M for a week.

That's what I call a pretty damn big waste of money.

Reminds me of a joke that many of you may have already heard:

Ever heard the story of the giant ship engine that failed? The ship’s owners tried one expert after another, but none of them could figure but how to fix the engine. Then they brought in an old man who had been fixing ships since he was a youngster. He carried a large bag of tools with him, and when he arrived, he immediately went to work. He inspected the engine very carefully, top to bottom.

Two of the ship’s owners were there, watching this man, hoping he would know what to do. After looking things over, the old man reached into his bag and pulled out a small hammer. He gently tapped something. Instantly, the engine lurched into life. He carefully put his hammer away. The engine was fixed! A week later, the owners received a bill from the old man for $10,000.

"What?!" the owners exclaimed. "He hardly did anything!"

So they wrote the old man a note saying, "Please send us an itemized bill."

The man sent a bill that read:

  Tapping with a hammer ........ $ 2.00

  Knowing where to tap ......... $ 9998.00

Effort is important, but knowing what you're doing makes all the difference.


答:
The company I work for paid $800 for a CHART FX License - It's not even my money yet I feel robbed.

http://www.softwarefx.com/sfxNetProducts/ChartFX/

Just for kicks, their software will place files all over the place including the registry and program files.... yep all that for some naff looking charts.

Title: What is the most egregious waste of money you have seen, and what did you do about it?

Body:
Often we as programmers see large organisations wasting huge sums of money on bloated and inefficient solutions to problems. This pains me greatly because I like organisations to benefit from best of breed solutions. However, my abilities as a programmer are limited when it comes to influencing the key decision makers and often my perspective on the matter is constrained to my own little technical world.

So, my question is this. After encountering an egregious waste of money on some software and/or hardware that really got your goat, what did you do about it to get it fixed or were you doomed to bite the bullet and mutter forever under your breath? I'm interested in hearing your overall experiences and especially what lessons you learned about how to tackle this sort of thing in the future. Let's not name names, the experience of how to tackle the problem is more important than the actual offending product.


问:
How do I learn Concurrency in Ruby?
Yesterday I read this great article about Concurrency in JRuby from EngineYard and I realise I need to leverage my skills about concurrency in Ruby, by mentioning Ruby here I mean it could be all implementations of Ruby : JRuby, Ruby MRI, Rubinius, Ruby on Parrot / Cardinal except IronRuby, I don't code in Windows Environment.

What I learned from Haskell world, especially from Simon Peyton-Jones, he said on his video that OOP is all about state.

Note: I'm very very inexperienced when I mention Haskell, I only watched some good videos about Haskell, solved very few (less than 10) euler project in Haskell, read some good Haskell books and tutorials, I've never coded in Haskell professionally, I just read some source codes in Haskell, ex. pugs, Darcs, and some other Haskell codes I don't remember the source.

I might want to use Jaskell to trick concurrency as long as I use jruby, but that's for my long term learning plan, I want to maximise my concurrency skill in ruby first, do you have any suggestions for me to learn concurrency in ruby? I wish there were a kind of Head First book for me to learn Concurrency in Ruby. Things like strategies / how to tackle concurrency problem in ruby, inspired from EngineYard article and Haskell. Maybe some good downloadable videos that explain step by step to strengthen my fundamental about concurrency generally and then move to concurrency in ruby specifically.

Advice? Thank you.

答:
To get you started, first read Ruby concurrency explained to get an overview.  Do note that the Ruby community, in general, seems to find concurrency to be a new and controversial topic and that folks argue vehemently and incessantly over many details regarding how it should be implemented in or via Ruby.  Seek fundamentals and do not get caught up in argumentative trivia!

One recommendation towards clarity is to mentally separate the idea of concurrency from multi-threading, which is only one implementation method.  Threading is one way of implementing concurrency but there are others; in particular, look at process parallelism as mentioned in Concurrency is a Myth in Ruby.

the Actor Model approach to concurrency is implemented through many languages, now, and Ruby Concurrency with Actors gives a gentle introduction to how actors may be implemented via Ruby.  Actors can simplify concurrency in many cases and can help you avoid some of the nastier pitfalls.

The Ruby community has implemented a Fiber class to provide "light weight cooperative concurrency" in Ruby.  You will definitely want to follow some of the links in Ruby Fibers: 8 Useful Reads On Ruby’s New Concurrency Feature to understand this new addition to the language.

Be aware that, as Engine Yard explained, JRuby and Ruby operate on different virtual machines and that these differences may have huge implications for concurrency implementations, in terms of what both what may be possible as well as how it may be achieved.

Yours is a valuable question as Ruby is just now entering the concurrent domain and you can be an "early adopter!"  Good luck on your worthy quest!

Title: How do I learn Concurrency in Ruby?


答:
I will take your question literally and discuss mostly microprocessors, not computers in general.

All computers have some sort of machine code. An instruction consists of an opcode and one or more operands. For example, the ADD instruction for the Intel 4004 (the very first microprocessor) was encoded as 1000RRRR where 1000 is the opcode for ADD and RRRR represented a register number 0-15 (0000-1111 in binary).

All other instructions that reference one of the 16 4-bit registers (such as INC, ISZ, LD, SUB, XCHG) also use the low 4-bits to encode the register number, and various encodings of the top 4-bits to specify the opcode. For example, ADD, SUB, LD and XCHG use opcodes 1000, 1001, 1010, and 1011 (all in binary) combined with the register field.  So you can see how a pattern is used to simplify the logic.

The very first computer programs were written by hand, hand-encoding the 1's and 0's to create a program in machine language. This was then programmed into a ROM (Read-Only Memory).  Now programs are generally written into electrically-erasable Flash memory, in the case of microcontrollers, or run out of RAM, if microprocessors.  (The latter still needs some sort of read-only memory for booting.)

Machine language gets tedious real fast, so assembler programs were developed that take a mnemonic assembler language and translate it, usually one line of assembly code per instruction, into machine code. So instead of 10000001, one would write ADD R1.

But the very first assembler had to be written in machine code. Then it could be rewritten in its own assembler code, and the machine-language version used to assemble it the first time. After that, the program could assemble itself (this is called bootstrapping).

Since the first microprocessor was developed long after mainframes and minicomputers were around, and the 4004 wasn't really suited to running an assembler anyway, Intel probably wrote a cross-assembler that ran on one of its large computers, and translated the assembly code for the 4004 into a binary image that could be programmed into the ROM's.

Title: How exactly do we go from Binary/Hex to Assembly Instruction sets?

Body:
So i've been trying to learn some Embedded/Assembly programming for a bit here lately, as well as going far as trying to learn the lowest level (gates and such).

One thing puzzles me though....is how do we "get" instruction sets. I understand somewhat how gates/TTL and such works, but I don't see how we get from that to mov,add,clr etc...?

It's probably a stupid question....but I mean I think back to the first micro-processors/controllers and think....how exactly did they design an instruction set and make it work?

edit: I guess for Clarity, pretend im talking about the first microprocessor, how did they go from Binary to actually creating an Instruction Set?


答:
a really simple solution.

tell him everything the above people have told you.
BUT,
at the end, tell him, YOU trust him. and you WILL DO exactly as he asked.
and you will not charge him a cent more.

BUT!

you want a video recording of everything he does since YOU start to work on the project,
and until it ends.

basicly you both should have a same time amount recorded.

if he can do that, you will accept he's request.

Title: My customer wants me to record a video of how I develop his software product

Body:
Working as a freelancer, I often see strange requests from my customers, some of which can negatively affect my daily work¹, and others trying to set some sort of control. I usually encounter those things during preliminary negotiations, so it's easy enough at this stage to explain to the customer that I do care about my work and productivity and expect my customers to trust my work.

Things were much harder² on a project I just accepted, since it's only after the end of the negotiations (the contract has already been signed and did not mention anything about video tracking) and after I started to work on the project that my customer requested that I record a video of all I do on my machine when working on his project, that is, a video which will show that I move the cursor, type a character, open a file, move a window, etc.

I work in my own company, using my own PCs.

I answered to this customer that such request cannot be accepted, since:

Hundreds of hours of work on a dual-screen PC will require a large amount of disk space for the recorded videos. If I don't care about space, I do care about this customer wasting my bandwidth downloading those videos.

Recording a video can affect the overall performance and decrease my productivity (which is not actually true, since the machine is powerful enough to record this video without performance loss, but, well, it still looks like a valid argument).

I can't always remember to turn the video recording on before starting the work, and off at the end.

It may be a privacy concern. What if I switch to my mails when recording the video? What if, to open the directory with the files about this customers project, I first open the parent directory containing the list of all of my customers?

Such video cannot be a reliable source to track the cost of a project (I'm paid by the hour), since some work is done with just a pencil and a paper (which is actually true, since I do lots of draft work without using the PC).

Despite those points, the customer considers that if I don't want to record the video, it's because I have something to hide and want to lie about the real time spent on his project³.

How to explain to him that it is not usual practice for freelancers to record videos of their daily work, and that such extravagant requests must be reserved for exceptional circumstances⁴?

¹ The most frequent example is to be requested to work through Remote Desktop on a more-than-slow server which uses a more-than-slow Internet connection, or to be forced to use outdated software such as Windows Me without serious justification such as legacy support.

² In fact, I already did a lot of management and system design related work, which is essential, but usually misunderstood by customers and perceived as a waste of time and money. Observing the concerned customer, I'm pretty sure that he will refuse to pay a large amount of money for what was already done, since there is actually zero lines of code. Even if legally I can easily prove that there was a lot of work undertaken on the design level, I don't want to end my relation with this customer in a court.

³ Which is not as risky as it could be, since I gave this customer the expected and the maximum cost of the project, so the customer is sure to never be asked to pay more than the maximum amount, specified in the contract, even if the real work costs more.

⁴ One case when I effectively record on my own initiative the video of actions is when I have to do some manipulations directly on a production server of a customer, especially when it comes to security issues. Recording those steps may be a good idea to know precisely what was done, and also ensure that there were no errors in my work, or see what those errors were.

First update

Since the question attracted much more attention and had many more answers than I expected, I imagine that it can be relevant to other people, so here is an update. First, to summarize the answers and the comments, it was suggested to (ordered randomly):

Suggest other ways of tracking, as shown in Twitter Code Swarm video, or deliver a "short milestone with a simple, clear deliverable, followed by more complex milestones", etc.

Explain that video is not a reliable source and can be faked, and that it would be difficult to implement, especially for support.

Explain that video is not a reliable source since it shows only a small part of the work: a large amount of work is done without using a computer, not counting the extra hours spent thinking about a solution to a problem.

Stick with the contract; if the customer wants to change it, he must expect new negotiations and a higher price.

Do the video, "but require that the customer put [the] entire fee into an escrow account", require a lawyer to video tape all billable time, etc., in other words, "operate in an environment void of trust", requiring the customer to support the additional cost.

Search for the laws which forbid this. Several people asked in what country I live. I'm in France. Such laws exist to protect the employees of a company (there is a strict regulation about security cameras etc., but I'm pretty sure nothing forbids a freelancer to sign consciously a contract which forces him to record the screen while he works on a project.

Just do it and send the videos: the customer will "watch a few ten second snippets of activity he won't understand", then throw those videos away.

Say no. After all, it's my business, and I'm the only one to decide how to conduct it. Also, the contract is already signed, and has nothing about video tracking.

Say no. The processes and practices I employ in my company can be considered as trade secrets and are or can be classified.

Quit. If the relation starts like this, chances are it will end badly sooner or later. Also, "if he's treating you like a thief - and that is what he's suggesting - then it's just going to get worse later when XYZ feature doesn't work exactly the way he envisioned".

While all those suggestions are equally valuable, I've personally chosen to say to my customer that I accept to do the videos, but in this case, we must renegotiate the contract, keeping in mind that there will be a considerable cost, including the additional fee for copyright release. The new overall cost would be on average three times the actual cost of the project. Knowing this customer, I'm completely sure that he would never accept to pay so much, so the problem is solved.

Second update

The customer effectively declined the proposal to renegotiate the original contract, taking into account the considerable additional cost. He agreed to continue the project without video recording.

The project continued without video recording. Eventually, the customer seemed satisfied by the final result and cost, so the video recording was not mentioned again.


问:
How does event bubbling generally work and is it synonym to event propagation?
I'm trying to wrap my head around the general workings and principles of event dispatching in event-driven (sub-)systems.

Although I have used it on quite a few occasions in for instance Javascript, Flash (Actionscript 2 and 3) and have even made a simple event dispatching system in PHP for myself at one time, I've never really understood event bubbling and/or propagation that well.

First question:

Is event bubbling synonym to event propagation?

Second question:

Am I correct in my understanding that when an event "bubbles", this means that it gets "moved" up the hierarchy of objects?

Third and most important question:

If my understanding in question 2 is correct; how is this "moving" up the hierarchy of objects generally implemented?

Does it generally mean that the parent object "redispatches" the same event to its parent (until it reaches the root object)? And if so; do all these objects in the hierarchy need to listen to their children for these events, or am I missing something vital principle in my understanding about event bubbling, where there's no need to let parent object register them selfs as listeners of child object events?

If you could illustrate these basic principles by means of some simple pseudo code, I'd be more than grateful.

答:
First answer:

Event bubbling is one specific algorithm guiding event propagation.

Second answer:

No, bubbling is not necessarily related to any hierarchy. How objects are represented internally or elsewhere doesn`t really matter for the algorithm to work properly. Ideally, when an event bubbles, it expands outwards from the innermost visible element on the screen, through to the outermost visible element on the screen.

Third answer:

The implementation details can vary a lot depending on how the internals of each (browser) are implemented. The bubbling algorithm depends on the visuals on the screen. If an encapsulating element is higher on the inheritance hierarchy than an inner element, the bubbling might be implemented using standard inheritance mechanisms in the language, for example. But that`s not necessarily true - you may have a specialized mechanism which can interpret both internal structures and their visibility on the screen, and propagate events according to the algorithm while ignoring internal organization.


答:
First question: Is event bubbling synonym to event propagation?

No. Bubbling is a form of event propagation, but it can't be used as a synonym. Propagation is a general term for passing an event around. Bubbling is a specific strategy of event propagation.

Second question: Am I correct in my understanding that when an event
  "bubbles", this means that it gets "moved" up the hierarchy of
  objects?

Yes. Bubbling means it goes up the hierarchy, as opposed to tunneling, which means it goes from the top element down or routing, which means the next object to receive the event can be anything you choose.

Third and most important question: If my understanding in question 2
  is correct; how is this "moving" up the hierarchy of objects generally
  implemented?

Pretty easy. In your visual hierarchy the controls have a reference to their parent/their top level visual or can obtain it somewhere. So when they capture an event, they just notify its parent about it, which notifies its parent about it etc.

Pseudo Code is like this for any UI control:

```<code>OnEvent(SomeEvent event)
{
   CallHandlersForEvent(event);
   if(HasParent && event.ContinueBubbling == true)
   {
       Parent.OnEvent(event);
   }
}
</code>```

Like blueberryfields said it needn't be the direct parent who receives the event next. You could implement like this, too:

```<code>OnEvent(SomeEvent event)
{
    CallHandlersForEvent(event);
    NextControl = VisualTree.GetVisualParent(this);
    if(NextControl != null && event.ContinueBubbling == true)
    {
       NextControl.OnEvent(event);
    }
}
</code>```

Title: How does event bubbling generally work and is it synonym to event propagation?

Body:
I'm trying to wrap my head around the general workings and principles of event dispatching in event-driven (sub-)systems.

Although I have used it on quite a few occasions in for instance Javascript, Flash (Actionscript 2 and 3) and have even made a simple event dispatching system in PHP for myself at one time, I've never really understood event bubbling and/or propagation that well.

First question:

Is event bubbling synonym to event propagation?

Second question:

Am I correct in my understanding that when an event "bubbles", this means that it gets "moved" up the hierarchy of objects?

Third and most important question:

If my understanding in question 2 is correct; how is this "moving" up the hierarchy of objects generally implemented?

Does it generally mean that the parent object "redispatches" the same event to its parent (until it reaches the root object)? And if so; do all these objects in the hierarchy need to listen to their children for these events, or am I missing something vital principle in my understanding about event bubbling, where there's no need to let parent object register them selfs as listeners of child object events?

If you could illustrate these basic principles by means of some simple pseudo code, I'd be more than grateful.

Body:
First question: Is event bubbling synonym to event propagation?

No. Bubbling is a form of event propagation, but it can't be used as a synonym. Propagation is a general term for passing an event around. Bubbling is a specific strategy of event propagation.

Second question: Am I correct in my understanding that when an event
  "bubbles", this means that it gets "moved" up the hierarchy of
  objects?

Yes. Bubbling means it goes up the hierarchy, as opposed to tunneling, which means it goes from the top element down or routing, which means the next object to receive the event can be anything you choose.

Third and most important question: If my understanding in question 2
  is correct; how is this "moving" up the hierarchy of objects generally
  implemented?

Pretty easy. In your visual hierarchy the controls have a reference to their parent/their top level visual or can obtain it somewhere. So when they capture an event, they just notify its parent about it, which notifies its parent about it etc.

Pseudo Code is like this for any UI control:

OnEvent(SomeEvent event)
{
   CallHandlersForEvent(event);
   if(HasParent && event.ContinueBubbling == true)
   {
       Parent.OnEvent(event);
   }
}

Like blueberryfields said it needn't be the direct parent who receives the event next. You could implement like this, too:

OnEvent(SomeEvent event)
{
    CallHandlersForEvent(event);
    NextControl = VisualTree.GetVisualParent(this);
    if(NextControl != null && event.ContinueBubbling == true)
    {
       NextControl.OnEvent(event);
    }
}


答:
Actually, I'd think some consulting firms would be what you want, e.g. Thoughtworks.  The idea here being to find those companies that are bragged within development circles and held as a high-end place to work.  Granted there are probably some consulting places that may be more like sweat shops so some care has to be done to find the right kind of place.

I'd imagine companies creating their own products can vary between various extremes.  In some cases you may have little structure and be dealing with taming the wild west at one end while the other may be oodles of bureaucracy if the company is used to doing everything with a ton of paperwork.

My suggestion would be to find local user groups and see how people will talk about various companies.  Does there seem to be a general high regard for some companies or people?  While it may not be easy, this could be a way to get various opinions on companies by talking to those in the trenches.


问:
git / other VCS - how often to commit?
I've been a programmer now for over 11 years, and am just starting to get into version control for real. The places I've worked at have never really used version control (one committed at the end of each day, the others simply haven't bothered).

I am not happy with the way that I've been taught to version control (programme.js, programme.js.bak, programme.js.bak.20110901 etc) and so have been teaching myself to use git.

I currently use it along with github to keep my .vimrc file current across 4 machines, but I'm never sure when I should consider a change a commit, and when it's just a change which should be included along with another commit. I have started to use it for javascript development too and find it awesomely useful :)

My question is: At what point do changes become a commit? As I said, the only company I've worked for who used version control did it at the end of the day - this doesn't seem sensible to me. I feel that they should be more atomic. But my question is how atomic?

Is a bug fix for a function enough for a commit? Should I fix three (unrelated) functions and commit them all at once? Should I commit after changing the condition in an if statement?

On personal projects, I commit after any change. I personally find that useful, but I don't know if it's bad practice or annoying.

How do you do it, how does the industry do it, and what are best practices?

(I'm a web developer so work on short projects - perhaps a month long)

答:
I always strive for having my commit log looking like the changelog for my program. That's not an achievable goal, but something to strive for. It pretty much defines that I want a separate commit for each new feature and each bugfix, but not too many.

Additionally when working in a team, I think of a commit as a letter to a fellow developer, describing the change I have made. I don't want to spam my fellow with every little commit I make when developing a new feature. It will leave a lot better impression if I just produce one larger commit, as if I had written the feature flawlessly on my first attempt.

But on the other hand I don't want to fall into lonely darkness... spending a month crafting one huge perfect commit. I want to keep my fellow developers aware of my progress. Any big feature can usually be split into meaningful pieces. So as a rule of thumb, one public commit per day should be the minimum.

Title: git / other VCS - how often to commit?


问:
How is fundamental mathematics efficiently evaluated by programming languages?
As I get more and more involved with the theory behind programming, I find myself fascinated and dumbfounded by seemingly simple things..
I realize that my understanding of the majority of fundamental processes is justified through circular logic

Q: How does this work?

A: Because it does!

I hate this realization! I love knowledge, and on top of that I love learning, which leads me to my question (albeit it's a broad one).

Question:

How are fundamental mathematical operators assessed with programming languages?

How have current methods been improved?

Example

```<code>var = 5 * 5;
</code>```

My interpretation:

```<code>$num1 = 5; $num2 = 5; $num3 = 0;
while ($num2 > 0) {
    $num3 = $num3 + $num1;
    $num2 = $num2 - 1;
}
echo $num3;
</code>```

This seems to be highly inefficient. With Higher factors, this method is very slow while the standard built in method is instantanious. How would you simulate multiplication without iterating addition?

```<code>var = 5 / 5;
</code>```

How is this even done? I can't think of a way to literally split it 5 into 5 equal parts.

```<code>var = 5 ^ 5;
</code>```

Iterations of iterations of addition?
My interpretation:

```<code>$base = 5;
$mod = 5;
$num1 = $base;
while ($mod > 1) {

    $num2 = 5; $num3 = 0;
    while ($num2 > 0) {
        $num3 = $num3 + $num1;
        $num2 = $num2 - 1;
    }
    $num1 = $num3;
    $mod -=1;
}
echo $num3;
</code>```

Again, this is EXTREMELY inefficient, yet I can't think of another way to do this.
This same question extends to all mathematical related functions that are handled automagically.

答:
It's done in picoseconds by electronic circuits.  Google 'hardware multiplier' etc. for details.  Modern CPUs are the extremely complex result of decades of continuous improvement.  </p>

<p>BTW, Since you don't multiply by repeated addition, why would you imagine a computer would?  </p>

Body:
It's done in picoseconds by electronic circuits.  Google 'hardware multiplier' etc. for details.  Modern CPUs are the extremely complex result of decades of continuous improvement.

BTW, Since you don't multiply by repeated addition, why would you imagine a computer would?


答:
basic arithmetic instructions are performed with assembly instructions which are highly efficient.

More complex (or abstract) instructions are either done in assembly with looping mechanisms or are handled in std libs.

As you study mathematics in college you will start studying things like Lambda Calculus and Big-O notation. All of these, and many more, are used by programmers to evaluate and to create efficient algorithms. Anyways, the basic stuff is usually accomplished at the low-level such as in assembly or in c with pointers.

A great introduction to this topic is "Code" by Charles Petzold.

Title: How is fundamental mathematics efficiently evaluated by programming languages?

Body:
As I get more and more involved with the theory behind programming, I find myself fascinated and dumbfounded by seemingly simple things..
I realize that my understanding of the majority of fundamental processes is justified through circular logic

Q: How does this work?

A: Because it does!

I hate this realization! I love knowledge, and on top of that I love learning, which leads me to my question (albeit it's a broad one).

Question:

How are fundamental mathematical operators assessed with programming languages?

How have current methods been improved?

Example

```<code>var = 5 * 5;
</code>```

My interpretation:

```<code>$num1 = 5; $num2 = 5; $num3 = 0;
while ($num2 > 0) {
    $num3 = $num3 + $num1;
    $num2 = $num2 - 1;
}
echo $num3;
</code>```

This seems to be highly inefficient. With Higher factors, this method is very slow while the standard built in method is instantanious. How would you simulate multiplication without iterating addition?

```<code>var = 5 / 5;
</code>```

How is this even done? I can't think of a way to literally split it 5 into 5 equal parts.

```<code>var = 5 ^ 5;
</code>```

Iterations of iterations of addition?
My interpretation:

```<code>$base = 5;
$mod = 5;
$num1 = $base;
while ($mod > 1) {

    $num2 = 5; $num3 = 0;
    while ($num2 > 0) {
        $num3 = $num3 + $num1;
        $num2 = $num2 - 1;
    }
    $num1 = $num3;
    $mod -=1;
}
echo $num3;
</code>```

Again, this is EXTREMELY inefficient, yet I can't think of another way to do this.
This same question extends to all mathematical related functions that are handled automagically.


答:
In the end, basic arithmetic operations are done in hardware. More specifically, in the CPU (or actually, a subpart thereof)

In other words, it's electronic circuits. Set the appropriate bits as input and you will get the appropriate bits as output. It is a combination of basic logic gates.

http://en.wikipedia.org/wiki/Adder_%28electronics%29

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


问:
Does it makes sense to implement an event dispatching system that allows event bubbling for non GUI related objects?
Following up on this question of mine, where I wanted to know the general principles of implementing an event dispatching system that allows for events to bubble (and capturing I've come to learn); does such an implementation make any sense for non-GUI related objects?

I'm asking, because I want to try and build a general purpose event dispatching framework in PHP (be it just for practice or for real use), but can't figure out whether event bubbling (or capturing) is in anyway useful in such an environment (not talking about PHP-GTK or similar environments here).

答:
Of course it does make sense. Just because you can't see something visually does not mean it can't use event bubbling, much less events in general.

An illustrating example:

Imagine you have some sort of tree model, for example an organigram of a company and you want to notify the higher ups when a node is inserted (new employee) or something has changed. You could then, for example, raise the event "Developer Jane just married, her surname changed to Smith". Some of the higher ups (such as her deparment lead) might be interested in such an event and send a greeting card, raise her salary or simply congratulate her. Just bubble it up, so the higher ups needn't subscribe to the surname change event of every person in the company, but get it anyway and can handle it, if they want to.

The logic would be much more complicated when they had to subscribe events from each individual. Whenever an individual was added, you'd have to traverse the tree for people interested in the new individual and subscribe to any events of interest explicitly. From a programmer's perspective, this is much more complicated then just receiving the event and then deciding whether you're interested in it or not. It'd lead to a pretty complex net of interconnections that is more difficult to manage and maintain. The first thing that comes to my mind are possible serialization troubles.

Now I am sure there're better examples out there, this was just the best one I could come up with in 30 seconds. But as you're intending to build an event dispatching system, I'd like to point you to the event aggregator pattern, which is a nifty little multipurpose tool that such a framework should not miss, best implemented like Microsoft does it in my opinion.


答:
Do not identify user stories for the overall system.  The time and effort will be wasted because the Customer will ask for changes as soon as they see the first demo from you.

Instead, work with the customer to define user value Quoting stories for each iteration within the first release.  Deliver user value stories as early in the release as practical so the customer can try out your work.

Say for example, that your product must provide quotes for both auto insurance and homeowners insurance.  You might create one user value story for each and then first deliver the one the Customer says is most important.  After seeing your work, they might decide that the Auto-Quote module is so good that they want you to deliver the Auto-Claims model next instead of homeowners.  Hopefully you get the point that it's about delivering value to customers early to help them make informed decisions and help you improve the product efficiently.


答:
Get a book like Fundamentals of Digital Logic..., which I think is still pretty standard for Freshman/Sophomore EE students, and work your way through it (ed: it costs a small fortune, so look for a used or prior edition of it).  That will take you up through the adders and multipliers, and give you enough of a background to start understanding some of the principles behind what the hardware is doing.

Your answer will, in the short term, become "because it fits together umpteen pieces of simpler logic to evoke this complex behavior" instead of "because it does."

If you want to try to understand all of the principles of how programs are compiled and run, go for that in conjunction, so you can ultimately see how everything meets in the middle.


答:
This isn't meant to be a thorough answer by any means but it should give you some idea how things are implemented. As you probably know numbers are represented in binary. For instance a computer could represent the number 5 as 00000101. A very basic operation a computer can do is shift left, which would give 00001010 which is decimal 10. If it were shifter right twice it would be 00010100 (decimal 20). Every time we shift the digits left 1 time we double the number. Say I had a number x and i wanted to multiply it by 17. I could shift x to the left 4 times and then add x to the result (16x + x = 17x). This would be an efficient way to multiply a number by 17. This should give you some insight into how a computer can multiply large numbers without just using repeated addition.

Division can use combinations of addition, subtraction, shift right, shift left, etc.
There are also numerous tricks for raising numbers to exponents.


答:
If you are building your own system you would be wise to study how the tk toolkit handles bindings. It associates a list of tags (or bindtags) for eAch widget. When an event comes in on a widget, the library gets the list of tags and looks for and applies each binding in order.

By default tne order is most specific (ie: the widget itself) to least specific (ie: the topmost window). The beauty of the system is, you can define whatever order you want. 98% of the time the default order is what you want, but sometimes you need something different.

The other feature of this system is that each binding can choose to have the event bubble or not. If a handler wants complete control it can handle the event then break the chain. Or, it can do what it needs to do then let other handlers have their turn.

I've never worked with a more powerful, flexible and simple method of handling events.

Oh, and there is no limitation that tags have to represent visible objects, or even objects at all. You can have tags that represent abstractions (for example, by default every widget includes the tag "all", which means you can bind to "all" and it will fire no matter where the event originally occurs.

Title: Does it makes sense to implement an event dispatching system that allows event bubbling for non GUI related objects?

Body:
Following up on this question of mine, where I wanted to know the general principles of implementing an event dispatching system that allows for events to bubble (and capturing I've come to learn); does such an implementation make any sense for non-GUI related objects?

I'm asking, because I want to try and build a general purpose event dispatching framework in PHP (be it just for practice or for real use), but can't figure out whether event bubbling (or capturing) is in anyway useful in such an environment (not talking about PHP-GTK or similar environments here).


答:
This is all covered with thorough patience in Don Knuth's
The Art of Computer Programming.

Efficient algorithms for add, subtract, multiply and divide are all described in complete detail.

You can read things like this that cover division nicely.

http://research.microsoft.com/pubs/151917/divmodnote.pdf