答:
IntelliSense sometimes likes to be a tiny bit overzealous with auto-completion. For example, if I want to write something IntelliSense doesn't know about yet (mostly because of some keys it uses for auto-completion not making a lot of sense).

Say I have a C# file where I want to use the File class to copy something. I have not included "using System.IO" yet.

I type "File." and as I hit the period, it immediately goes "Aha! I know what you want. You want FileStyleUriParser." Then I have to go delete the word and try typing it again. I forget that the period turns on auto-completion and accidentally do the same thing again. Eventually I press the ESC key at the correct time and type it.

This is just because I know what I want to type and I don't need IntelliSense for it. I also don't want to spend the time going to the top of the file to put the using statement in (yet).

Now, to be fair, you can turn off this behavior. I like this behavior sometimes and hate it others (which is why I haven't turned it off).

Title: Is there any evidence that Intellisense reduces productivity?

Body:
Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

I was having a conversation with another developer the other night about the pros and cons of Visual Studio. He was of the opinion that Intellisense reduces productivity. Of course I thought that was insane but I could be wrong. Is there any evidence to support the idea that Intellisense reduces productivity?


问:
Thoughts on Development using Virtual Machines
I'll be working as a development lead for a startup and I've suggested that we use VMs for development.  I'm not talking about each developer having a desktop with VMs for testing/development, I mean having a server rack where all VMs are managed and have the developers work from a microPC (ChromeOS anyone?) locally, or even remotely from their home computer.

To me, the benefits are the fact that it's extremely scalable, cheaper in the long run, easier to manage and that we utilize the hardware its maximum potential.  As for cons, I can't think of any particular showstoppers other than we'll need someone to setup/maintain said setup.

I was hoping that some of you might of had a similar setup at your place of employment and be able to weight in with your opinions.  Thanks.

答:
I have a decent desktop machine at the office which I can connect to from my laptop over VPN using screen sharing.

It works for out of hours support incidents and the occasional forced remote working. It is certainly better than maintaining a fully configured environment on a second machine, or for developing stuff that needs low latency to the datacenter across a WAN.

However, it is frustrating to work that way for long periods. I have on occasion driven in to work for the second half of the day once whatever it was that kept me at home has been got out of the way.

Latency and screen real estate are the two killers for me.

ContentLicense: CC BY-SA 3.0


问:
The worst anti-patterns you have came across
What are the worst anti-patterns you have came across in your career as a programmer?

I'm mostly involved in java, although it is probably language-independent.

I think the worst of it is what I call the main anti-pattern. It means program consisting of single, extremely big class (sometimes accompanied with a pair of little classes) which contains all logic. Typically with a big loop in which all business logic is contained, sometimes having tens of thousands of lines of code.

答:
IMO the worst anti-pattern I've seen is the "We don't need any stinkin' patterns" Anti-Pattern: The idea that design patterns are wastes of time and you can write code faster by just slopping it together and copy/pasting as needed.

Honorable mention goes to having code that loads an object from the database using the old VB6 style of:

```<code>Foobar oFoo = new Foobar();
oFoo.FooID = 42;
if (oFoo.Load()) {
    // do something with oFoo
}
</code>```

not really an anti-pattern, per se, but shows a lack of taking advantage of proper architecture and separation of concerns.

Also, things like this:

```<code>// this name is misleading, we may not always want to stand in fire,
// we may want to stand in slime or voidzones or ice patches...
public Foobar StandInFire() { }

// why is this here???
public string BeatWithNerfBat(string whom) { }

// ????
public int GivePony(string to) { }
</code>```

OwnerDisplayName: стривігор

ContentLicense: CC BY-SA 2.5

Body:
IMO the worst anti-pattern I've seen is the "We don't need any stinkin' patterns" Anti-Pattern: The idea that design patterns are wastes of time and you can write code faster by just slopping it together and copy/pasting as needed.

Honorable mention goes to having code that loads an object from the database using the old VB6 style of:

Foobar oFoo = new Foobar();
oFoo.FooID = 42;
if (oFoo.Load()) {
    // do something with oFoo
}

not really an anti-pattern, per se, but shows a lack of taking advantage of proper architecture and separation of concerns.

Also, things like this:

// this name is misleading, we may not always want to stand in fire,
// we may want to stand in slime or voidzones or ice patches...
public Foobar StandInFire() { }

// why is this here???
public string BeatWithNerfBat(string whom) { }

// ????
public int GivePony(string to) { }


答:
One of the worst behavioral anti patterns I have seen was a shop that only allowed code to be checked in to version control after it was in production.  Coupled with exclusive checkouts in VSS, this led to a convoluted process of undoing checkouts if a production defect needed to be corrected before the next release, let alone more than one person needing to change a given file for the upcoming release.

The fact that this was a departmental policy made it even worse than the case of a single developer behaving this way.

Title: The worst anti-patterns you have came across

Body:
What are the worst anti-patterns you have came across in your career as a programmer?

I'm mostly involved in java, although it is probably language-independent.

I think the worst of it is what I call the main anti-pattern. It means program consisting of single, extremely big class (sometimes accompanied with a pair of little classes) which contains all logic. Typically with a big loop in which all business logic is contained, sometimes having tens of thousands of lines of code.


答: One of my favorite development anti patterns is the use of a database "design" that requires continually adding additional columns to one or more tables programmatically.  This is a cousin of the "design" that creates a new table for each instance of an entity.  Both inevitably hit limitations of the database server, but usually not until the system has been in production for quite some time.


答:
Code sprinkled with:

```<code>// TODO:
</code>```

or

```<code>// TODO: implement feature
</code>```

with no additional information.

Body:
Code sprinkled with:

// TODO:

or

// TODO: implement feature

with no additional information.


问:
Can I develop GUI in MonoTouch and MonoDroid with a shared .NET backend?
Is it possible to create a shared backend logic using .NET and have the respective GUI front ends in MonoTouch and MonoDroid?</p>

答:
Yes, with some limitations due to the way MonoTouch works. Apple do not allow running of any background VM or service in order to JIT compile CLR applications, so all MonoTouch applications are AOT compiled, resulting in loss of dynamic abilities and reflection. The link will detail what is missing, and there's another link in there showing which libraries are available to MonoTouch apps.

MonoDroid does not suffer the same limitations because Android can run the full VM. So if you need to share a library between the two, you should build the library using the MonoTouch capabilities, and keep any dynamic related code in the MonoDroid projects only.


问:
What's a good way to store/load a word list with thousands of entries?
I'm working on a project that requires a simple dictionary for checking spelling; it will be large, but will lack definitions. The solution we're currently working on has the base word list in a text file, and customizations (extra words, excluded words) in the DB.

The entire list needs to be loaded (best cached I think) for paginated display and customization using an existing JS widget, so what's the best way to store and load the base word list?

My initial thought was to have a text file with one word per line and write my own loader and cache object, but my boss suggested using a ResourceBundle to leverage the built-in caching. I'm thinking that could be done by using the words as keys with empty values and using the keyset of the bundle.

What would be the best solution to this?

答:
In general, the data structure your are looking for is called TRIE.

If you are looking to implement this in javascript, be sure to read John Resig's blog on that subject. He evaluated several techniques for a similar problem, highly recommended.

Also, take a look at this stackoverflow.com question to find java implementations.


问:
Is a partially familiar scripting language desirable?
Given that a program (under development) needs a scripting language, and that for various reasons it's not possible to use an off-the-shelf one as is, I'm considering basing it on the syntax and some of the semantics of JavaScript, being something pretty much everyone is familiar with, including using the .js file extension so that e.g. editors will know how to syntax highlight scripts.

It's necessary to make some changes anyway, for certain technical reasons. It strikes me as reasonable to make some other changes that most people would consider improvements. For example, eliminating the 'semicolons are optional' rule that sometimes trips people up, and making a block within a function a new lexical contour. But I'm not certain this is what most people actually want. So of the following options:

Stick as close to JavaScript as I possibly can, even aspects of it that everyone agrees are mistakes in and of themselves, deviating only when technical considerations make it absolutely necessary. (There is no question of being able to use existing JavaScript code in any case, I'm talking purely about the benefits of familiarity from the user's viewpoint.)

Go with the plan currently under consideration, make something that looks pretty much like JavaScript but differs in various regards.

All or nothing, if I can't use actual JavaScript, create a new scripting language that is visibly completely different (e.g. not C-style syntax) so there's no possibility of confusing it with JavaScript.

Which option would generally be considered preferable? Is there a fourth option I'm missing?

答:
If you have to write your own scripting language, I wouldn't decide to write it similar to another one only because it's something already seen and programmers are familiar with.

First you have to consider the needs of this scripting language: Is it needed to make complex code structures or just small unrelated scripts and/or data changes on-the-fly? What functionalities you need? Is preferable for it to be more abstract, more fast, or with a more clear syntax?

What kind of data structures must be implemented? Which of these structures are best described using a particular syntax? Given a fairly complicated problem you may need to solve using your language, try to solve it using various syntaxes: what syntax is best at describing what the code does?

I think after you have found out what are the requirements of the language, and tried various syntax, you will have an idea of what syntax is best suited for the job.

Edit

As Spencer commented

This is a perfect example of a domain specific language. You don't
  want it to solve any problem, it just has to easily describe your
  specific problem set.


问:
How do you prevent the piracy of your software?
Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>

答:
No, not really. And depending on the used technology there may not even be a reasonable approach at all.

For example, there is nothing you can do to prevent decompilation of an SWF (e.g. with Sothink SWF Decompiler). It will give you pretty much exactly the source code you typed. Of course you can use code obfuscation, but that makes it only a tad more difficult to understand the code while doing nothing to e.g. prevent someone from decompiling your SWF, replacing your name and company logo and then recompile it again.

The same goes for JavaScript or ABAP (where you basically have to deliver the source code to the customer) and probably some other technologies as well.

On the other hand, copy-protection/DRM can seriously annoy your customers and give your company very bad publicity. Think of the various protection mechanisms employed by the gaming industry:

DRM components installing themselves as ring 0 drivers, making the system vulnerable to security and/or stability problems

protection software telling you to uninstall other applications before allowing the product to run

permanent online connection required to play a single-player game

limited installations or online activations, often used in combination with binding the product to a user account of some sort (usually this binding is irreversible)

etc.

Therefore you should always consider the negative impact any copy-protection measures you include in your product can have on your reputation and how much effort (development time, license costs, etc.) it requires to actually get that DRM stuff into your application. If you come to the conclusion that it's still worth the trouble then do it. But if you have any doubt that using DRM will actually hurt your business more than benefit it then simply don't do it.

Of course, requiring a CD key or employing a disc check to prevent John Doe from using Nero to provide his whole family with copies of your product is still reasonable. However, any measures that invade the customer's system by installing DRM drivers or something like that should be considered very carefully because of the previously stated reasons.


答:
Cart-Before-The-Horse -- aka YouMightNeedIt

For example:

Creating a RDMBs schema with abstract concepts, cross references -- in essence an over-generalized data cube... And THEN writing features around a does-everything model.


问:
Is it OK to Use Dropbox in a Web Installer?
So I'm working in a modding project and they gave me the installing part as to do. We plan to publish it between 30 Aug. - 01 Sept.

My question is; is it logical to use Dropbox to download files in the web installer? I saw Dropbox's public folder has 10 GB download bandwith limit daily, after reaching that; they lock the account. I can insert a quota function and can use more than one Dropbox accounts. But it seems (not sure but) it's illegal or opposite to company's politics.

I don't know is the same bandwith limit applies to downloading directly from the root folder.
Also total size of the packages reaches 1 GB. This why I'm afraid of the bandwith limit.

And, if you don't recommend using Dropbox, what would you advise? I think a simple web automator with Mediafire is a good choice but resuming download will not be possible. Also I have a Fileserve Premium Account (a friend of mine gave as a gift) but most probably it will be banned after using different IP's at the same time.

One more thing I'm writing it in C#.

Thanks...

答: If I was baking something into an installer, I would make sure the installer pointed towards a URL I had absolute control over even if the url redirected to dropbox or wherever.</p>


答:
Something that has caused me lots of grief is the "Big map in the sky" pattern.
Throwing around a map instead of using proper objects.
You have no idea of what "variables" it contains without debugging, and you don't know what it might contain without tracing the code backwards.
Typically maps Strings to Objects, or Strings to Strings, which you potentially are supposed to parse into primitives.</p>


答:
That really depends who "they" are. It seems unproffesional and penny pinching to use a consumer site like that. If you are only distributing it to other colligues then its fine but i wouldent use it to give to customers. </p>

<p>You can get ftp hosting for a pittance. Thats what i would use. Its faster with no limits on download (depending on how much you pay) and the file will stay there till you remove it. </p>

Title: Is it OK to Use Dropbox in a Web Installer?

Body:
So I'm working in a modding project and they gave me the installing part as to do. We plan to publish it between 30 Aug. - 01 Sept.

My question is; is it logical to use Dropbox to download files in the web installer? I saw Dropbox's public folder has 10 GB download bandwith limit daily, after reaching that; they lock the account. I can insert a quota function and can use more than one Dropbox accounts. But it seems (not sure but) it's illegal or opposite to company's politics.

I don't know is the same bandwith limit applies to downloading directly from the root folder.
Also total size of the packages reaches 1 GB. This why I'm afraid of the bandwith limit.

And, if you don't recommend using Dropbox, what would you advise? I think a simple web automator with Mediafire is a good choice but resuming download will not be possible. Also I have a Fileserve Premium Account (a friend of mine gave as a gift) but most probably it will be banned after using different IP's at the same time.

One more thing I'm writing it in C#.

Thanks...

Body:
That really depends who "they" are. It seems unproffesional and penny pinching to use a consumer site like that. If you are only distributing it to other colligues then its fine but i wouldent use it to give to customers.

You can get ftp hosting for a pittance. Thats what i would use. Its faster with no limits on download (depending on how much you pay) and the file will stay there till you remove it.


答: It's too risky, I'd recommend stumping up a bit of cash and getting a proper download server. Dropbox do frown on multiple accounts and people exploiting their bandwidth, plus it's got so many attached risks that you'd spend more time working round it than it'd cost to get a server for a month.</p>


问:
What are the steps in beginning a large project, when all I have is a big idea?
I am computer engineering student. I've been thinking about
how I can handle a big project. What should be my first step to reach my goal in a more efficient and effective way?

When I come up with a project, I don't know how I should start working on it. Many times, I just ignore it. However, I don't want to ignore my project ideas anymore.

Now, I am asking to all of you, can anyone share his/her experiences? How should I start a project when all I have is an idea?

答:
Since you're a student I'm going to assume you mean student-big and not professional-big.  The latter requires additional business and collaboration considerations.  I just started a new project last week, so the process is fresh in my mind.

The first thing I do is research existing solutions and libraries.  I don't like to reinvent the wheel whenever possible.  This research is also a big factor in choosing a language for the project.  Some languages have better existing code for certain tasks.

The next thing I do is create a folder and put it under source control.  This is as simple as a git init . nowadays.

Next I get "hello world" working.  This lets me know my development environment is set up properly.

Next I get "hello world" for third-party libraries working.  This is the bare minimum necessary to show I'm linking to and using the library correctly.  For a database library, it's connecting and running a simple query, for example.  For a GUI toolkit, it's displaying a window.

Next I set up build scripts and testing frameworks.  This is ant or makefiles or whatever, and is much easier to set up when your project is still small.

Next I create data structures.  Also called the "model" layer.  This is the part that stores everything your program needs to remember in order to do its job.  I do a lot of design on paper, then just add stubs in.  This part of the design is usually the easiest.  For example, a chess program is going to need objects to store the game grid, the players, the pieces, sequences of moves, etc.

At this point, I have a pretty good base for a program and it's usually fairly obvious what the next step is going to be for that particular project.  Then I just take it one small step at a time, with code that works to some degree all along the way.


问:
If you learned formal methods for software, how useful have you found it?
If you have been trained in the use of formal methods (FM) for programming:

How useful have you found it?

What did your FM training involve (e.g. a course, a book)?

What FM tools do you use?

What advantages in speed/quality has it given you compared to not using FM?

What kind of software do you create with FM?

And if you don't directly use FM now, was it at least worth learning??

I'm curious to hear as many experiences/opinions on FM as can be found in this community; I'm starting to read up on it and want to know more.

Background

Programming and software development/engineering are some of the newest human skills/professions on Earth, so not surprisingly, the field is immature — that shows in our field's main output, as code that is typically late and error-prone.  Industry immaturity is also shown by the wide margin (at least 10:1) in productivity between average and top coders.  Such dismal facts are well covered in the literature, and introduced by books like Steve McConnell's Code Complete.

The use of formal methods (FM) has been proposed by major figures in software/CS (e.g. the late E. Dijkstra) to address (one of) the root causes of errors: the lack of mathematical rigour in programming.  Dijkstra, for instance, advocated for students developing a program and its proof together.

FM seems to be much more prevalent in CS curricula in Europe compared to the US.  But in the past few years, new "lightweight" FM approaches and tools like Alloy have attracted some attention.  Still, FM is far from common usage in industry, and I'm hoping for some feedback here on why.

Update

As of now (10/14/2010), of the 6 answers below, no one has clearly argued for the usage of FM in "real world" work.  I'm really curious if someone can and will; or perhaps FM really does illustrate the divide between academia (FM is the future!) and industry (FM is mostly useless).

答:
Absolutely useless for anything nontrivial.

I had a course called, aptly, "Formal Methods" that focused on Alloy- I can't possibly see using that anywhere.  Had another class that focused on concurrency modeling with LTSA- equally useless.

The problem is that most bugs and problems in software (at least in my experience) arise from complexity that occurs below the level of abstraction of those tools.


答:
Create an Outline

You have a big idea, but don't know how you are going to go about accomplishing your task. Create an outline of what you are going to do. Write down the steps you will take, what you will need, what languages you will be using, etc.. Make sure you have everything organized, or the project will be a complete wreck.

Schedule Your Steps

I mentioned this before, but it is really important. If you have time mapped out, you can have an estimated finish date of when your project will be finished, and how long any steps of the project will take. This is, again, organization and will keep you running.

Find The Tools For The Job

If you are going to start a big project, you will need some help. For code organization, and a good Version Control System, Git is great because it keeps all of your code in a single repository. For more info on Git, see the link I gave you.

You will also need to make sure you are using languages that will help you do what you are trying to do. Make sure you are able to create your project before you start. I'm not saying don't learn anything new, but learn before you start.

Get Help

Big projects are not usually done alone. Contact fellow students, people in your community who can program, and anyone else you think can help you before starting. Do not be afraid to ask.

Get Started!

Don't lollygag around, waiting for someone else to start your project and then say " I had that idea!". It will forever haunt you...

Title: What are the steps in beginning a large project, when all I have is a big idea?

Body:
I am computer engineering student. I've been thinking about
how I can handle a big project. What should be my first step to reach my goal in a more efficient and effective way?

When I come up with a project, I don't know how I should start working on it. Many times, I just ignore it. However, I don't want to ignore my project ideas anymore.

Now, I am asking to all of you, can anyone share his/her experiences? How should I start a project when all I have is an idea?


答:
It's perfectly normal to be hit by the "blank paper" syndrome.

You have a great project in mind, which looks fantastic, but when you sit down at the desk trying to do something, you suddenly block and are not able to do anything. Then you open up solitaire and make a new record.

You actually need to start doing something related to the project, so that you feel like it's born.

You may not want to write code immediately. You can start by writing what your project actually must do, or you would like it to do. Take a pen and paper and start writing. You can start from the details or from a bigger picture. Try both, see what is best.

You can try to define the functionalities of the project, the different parts, how those parts communicate between them. I feel myself comfortable with post-it, they are fun and you can change them as you progress. Let them follow your mind and ideas.

Or maybe you can start prototype some function or classes. You can use whatever language you prefer for this, even one that doesn't exist and you just invented.

After some time you will have something to work on, and your project will be not only on your mind. You actually did something.

When you feel comfortable to actually start the development process, it's time for a careful planning, documenting, prototyping, gathering of all required technologies and software, and so on.

But don't start until you actually feel it's the right time!


答:
If all you have is a "Big Idea", you will need a lot of things (that are very well described in other answers), and particularly these 2 : time and motivation.

The biggest difficulty when you work alone on a personal project is that, usually, you don't have much time to spend on it every week and so you don't see much progress and quickly start loosing motivation.

So as it has already been said, take small steps, that's the key.

But this is not all, you have to take small and rewarding steps ! That is, steps that will bring you the biggest value and demonstrate the key concepts of your big idea.

For example, if you work on a new super todo list software with great user interactions. Don't start with the storage and database stuff until you really need it. Start with the innovative user interface : that is fun and has value. That'll make you proud, keep you motivated and allow you to check very soon is your idea really is good.


问:
Should Unit Testing be used in Prototypes?
When constructing prototypes, should we also create appropriate unit tests as if we were writing production code? Would it make a difference if we knew in advance that the code was or wasn't going to be re-used for the final solution?

答:
This depends on a number of things, including the expected longevity of the prototype environment.

For example, it is not so uncommon to prototype user interfaces for vending machines in flash (or similar technologies) and have them reimplemented in C or something to run on the actual machine.

In such cases the prototype itself has a long life during which it is subject to change, because it is used for user interaction testing and prototyping of interface enhancements. Given that in a scenario like this, drastic changes are to be expected, unit tests are very helpful.

Of course, if you write a piece of code to for example get a rough idea about how a software/hardware architecture will perform/scale by throwing some simulated user input at it, to determine whether it could suit your requirements (for example when comparing different data stores by filling them with loads of data and running frequently expected queries on them to determine which to choose), you will probably throw vast parts of the code away once you have your numbers.


问:
When are Getters and Setters Justified?
Getters and setters are often criticized as being not proper OO. On the other hand, most OO code I've seen has extensive getters and setters.

When are getters and setters justified? Do you try to avoid using them? Are they overused in general?

If your favorite language has properties (mine does) then such things are also considered getters and setters for this question. They are the same thing from an OO methodology perspective. They just have nicer syntax.

Sources for Getter/Setter Criticism (some taken from comments to give them better visibility):

http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html

http://typicalprogrammer.com/?p=23

http://c2.com/cgi/wiki?AccessorsAreEvil

http://www.darronschall.com/weblog/2005/03/no-brain-getter-and-setters.cfm

http://www.adam-bien.com/roller/abien/entry/encapsulation_violation_with_getters_and

http://www.yegor256.com/2014/09/16/getters-and-setters-are-evil.html

To state the criticism simply: Getters and Setters allow you to manipulate the internal state of objects from outside of the object. This violates encapsulation. Only the object itself should care about its internal state.

And an example

Procedural version of code:

```<code>struct Fridge
{
    int cheese;
}

void go_shopping(Fridge fridge)
{
     fridge.cheese += 5;
}
</code>```

Mutator version of code:

```<code>class Fridge
{
     int cheese;

     void set_cheese(int _cheese) { cheese = _cheese; }
     int get_cheese() { return cheese; }
 }

void go_shopping(Fridge fridge)
{
     fridge.set_cheese(fridge.get_cheese() + 5);
}
</code>```

The getters and setters made the code much more complicated without affording proper encapsulation. Because the internal state is accessible to other objects we don't gain a whole lot by adding these getters and setters.

The question has been previously discussed on Stack Overflow:

https://stackoverflow.com/questions/565095/java-are-getters-and-setters-evil

https://stackoverflow.com/questions/996179

答:
As a general rule, getters and setters are a bad idea. If a field isn't logically part of the interface and you make it private, that's fine. If it is logically part of the interface and you make it public, that's fine. But if you make it private and then turn around and make it effectively public again by providing a getter and setter, you're back to where you started except your code is now more verbose and obfuscated.

Obviously, there are exceptions. In Java, you might need to use interfaces. The Java standard library has backward compatibility requirements so extreme as to outweigh normal measures of code quality. It's even possible that you may actually be dealing with the legendary but rare case where there's a good chance you may later replace a stored field with on the fly calculation without otherwise breaking the interface. But these are exceptions. Getters and setters are an anti-pattern that needs special justification.

ContentLicense: CC BY-SA 4.0

Title: When are Getters and Setters Justified?


答: I have a background in CSP (Communicating Sequential Processes). Not to toot my own horn but I wrote my Master's thesis on Timed CSP, particularly "compiling" specifications written in formal methods into executable C++. I can say I have some experience with formal methods. Once I completed my degree and got a job in the industry, I have not been using formal methods at all. Formal methods is still too theoretical to be applied in the industry. Formal methods have found some practical application in the area of embedded systems. For example, NASA uses formal methods in their projects. I would speculate that formal methods are very far from being widely adopted in the industry. It simply does not make sense to write software specifications in formal methods and then "human interpret" them to your framework of choice. Plain English and diagrams work better for that, while unit and integration tests have been doing a pretty good job of "verifying" the correctness of code. I think formal methods will remain in the world of academia for some time.

Title: If you learned formal methods for software, how useful have you found it?

Body:
If you have been trained in the use of formal methods (FM) for programming:

How useful have you found it?

What did your FM training involve (e.g. a course, a book)?

What FM tools do you use?

What advantages in speed/quality has it given you compared to not using FM?

What kind of software do you create with FM?

And if you don't directly use FM now, was it at least worth learning??

I'm curious to hear as many experiences/opinions on FM as can be found in this community; I'm starting to read up on it and want to know more.

Background

Programming and software development/engineering are some of the newest human skills/professions on Earth, so not surprisingly, the field is immature — that shows in our field's main output, as code that is typically late and error-prone.  Industry immaturity is also shown by the wide margin (at least 10:1) in productivity between average and top coders.  Such dismal facts are well covered in the literature, and introduced by books like Steve McConnell's Code Complete.

The use of formal methods (FM) has been proposed by major figures in software/CS (e.g. the late E. Dijkstra) to address (one of) the root causes of errors: the lack of mathematical rigour in programming.  Dijkstra, for instance, advocated for students developing a program and its proof together.

FM seems to be much more prevalent in CS curricula in Europe compared to the US.  But in the past few years, new "lightweight" FM approaches and tools like Alloy have attracted some attention.  Still, FM is far from common usage in industry, and I'm hoping for some feedback here on why.

Update

As of now (10/14/2010), of the 6 answers below, no one has clearly argued for the usage of FM in "real world" work.  I'm really curious if someone can and will; or perhaps FM really does illustrate the divide between academia (FM is the future!) and industry (FM is mostly useless).


答:
Lack of dual screen support has always been the deal killer. I just can't imagine doing significant development work on a single screen.

Now, they do rock for testing/deployment/fiddling, so I don't think they should fall off the stack either.

Title: Thoughts on Development using Virtual Machines

Body:
I'll be working as a development lead for a startup and I've suggested that we use VMs for development.  I'm not talking about each developer having a desktop with VMs for testing/development, I mean having a server rack where all VMs are managed and have the developers work from a microPC (ChromeOS anyone?) locally, or even remotely from their home computer.

To me, the benefits are the fact that it's extremely scalable, cheaper in the long run, easier to manage and that we utilize the hardware its maximum potential.  As for cons, I can't think of any particular showstoppers other than we'll need someone to setup/maintain said setup.

I was hoping that some of you might of had a similar setup at your place of employment and be able to weight in with your opinions.  Thanks.


答:
VMs for development are worth looking at, but financial cost is the wrong reason.

This was covered briefly in Marc Holmes' Expert .NET Delivery using NAnt & CruiseControl.net - in short the argument for developing on a VM is that it discourages any aspect of the work from becoming dependent on the developer's particular configuration. You nuke your VM at the start of every project, and unless you actually need a particular tool, it doesn't keep kicking around. This minimises the likelihood that changes you make will be breaking on anybody's machine but yours. Developers might cry at having their toys taken away - but ultimately, reliance on tools is a weakness and anything you can't do intuitively in a clean environment is a smell.

Note that I don't necessarily believe the arguments presented above. I understand and to a certain extent align with them, but I'm making them for arguments' sake, to generate discussion.


问:
Drawing the line between models & libraries?
As my webapps increase in size, so does the complexity. In order to keep my classes & files structured and easy-to-access, I am starting to get more and more confused:

I have some very clearly defined data objects in my application - orders, invoices, products for example. All of those have their own entity object that handles enforcement of values and pure business logic along with a model that handles storage of each object to my  persistent storage of choice (database).

Ok - everything clear and separated that far. But what about a logic-heavy object like users?

Users log in and out, change password (with everything that means - hashing, encrypting and so forth) and do a whole lot of interaction both in the database and with Sessions.

Right now, I use an Authentication-class, a library, which carries all of these mentioned actions and a lot more. It does it's job, but It's kind of unclear to me what I should put into a model and what should be a Library?

答:
I do think you kind of answered you own question - Models should simply include basic data-related logic, and every other more abstract functionality should be handled by library classes (IMO - should be taken with a grain of salt, as there are a lot of definitions of MVC and the likes for the web).

So, to extend on your example: the User class, would have setUsername, getUsername, setPassword, getPassword, validate, destroy, hash, encrypt etc. While it is true that logIn can be considered a data-related function, and can be placed in the model (matter of style and taste I guess), to me it looks more specialized and I would place it in a separate class called Authentication, which takes care of all User related, not directly tied to the data functionality.

To sum it up, I consider this to be largely a matter of coding style. After all, it should make sense to you as long as you develop/maintain it. And of course, it should be well-documented so in case someone inherits said code, they wouldn't get lost :)


问:
How can one manage thousands of IF...THEN...ELSE rules?
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in any landscape. They are affected by things like the sun, wind, food source, sudden events etc.

How can such an application be managed? I imagine that after a few hundred IF-statements, it would be as good as unpredictable how the program would react and debugging what lead to a certain reaction would mean that one would have to traverse the whole IF-statement tree every time.

I have read a bit about rules engines, but I do not see how they would get around this complexity.

答: Make your application manageable by designing it well. Design your application by splitting up the various business logic into separate classes/modules. Write unit tests that test each of these classes/modules individually. This is crucial and will help you ensure that the business logic is implemented as expected.</p>


答:
Every large application contains thousands of if-then-else statements, not counting other flow controls, and those applications are still debugged and maintained, despite their complexity.

Also, the number of statements does not make the flow unpredictable. Asynchronous programming does. If you use deterministic algorithms synchronously, you'll have a 100% predictable behavior, every time.

You should probably explain better what are you trying to do on Stack Overflow or Code Review so that people could suggest you the precise refactoring techniques to use. You may also want to ask more precise questions, like "How do I avoid nesting too much if statements <given a piece of code>".

Title: How can one manage thousands of IF...THEN...ELSE rules?

Body:
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in any landscape. They are affected by things like the sun, wind, food source, sudden events etc.

How can such an application be managed? I imagine that after a few hundred IF-statements, it would be as good as unpredictable how the program would react and debugging what lead to a certain reaction would mean that one would have to traverse the whole IF-statement tree every time.

I have read a bit about rules engines, but I do not see how they would get around this complexity.


答: For $20/month, you can get a VPS that will provide 200GB of transfer.  I'm sure if you shop around you can find even cheaper prices for that.  Or, you might investigate something like Amazon, where you pay based on what you use.  There's no reason to abuse a free service.</p>


问:
Where does "isolating complexities" lie in the realm of design principles?
I was just curious, it's something I think most people are aware of as a technique:

You have some abominable data that simply must be parsed and you can do nothing to simplify the algorithm for doing it, so the best you can do is isolate the complexity of that algorithm to one place rather than having parts of the algorithm strewn all over. Then after isolating it, cementing the boundaries of it with some interface or contract to ensure the complexity in it does not leak out.

Where does this drive to isolate complexities live in the library of design principles? I don't think it is word for word one of the formally documented design principles, though I'm guessing there are one or two that overlap with this very closely.

答:
I would consider this a special case of the Single Responsibility Principle.

Essentially, you have a component dedicated to the implementation, execution, and consistency of the specified algorith - rather than distributing bits and pieces of the algorithm across several different components.

This both encapsulates the algorithm and ensures that if it needs to change over time, there's only a single area of the code that is impacted.


答:
Rules engines might help because if there are so many if/then rules it might be helpful to get them all in one place outside the program where users can edit them without needing to know a programming language.  Also, visualization tools might be available.

You could also look at logic programming solutions (like Prolog).  You can quickly modify the list of if/then statements and have it do things like look whether any combination of inputs would lead to certain outcomes, etc.  It also might happen be cleaner in first order predicate logic than as procedural code (or than as object oriented code).


答:
There probably won't be a single way to design your way out of your problem, but you can manage the complexity of it piece by piece if you try to separate out different areas where you find yourself writing large blocks of if statements and apply solutions to each of those smaller problems.

Look to techniques like the rules talked about in Refactoring for ways to break large conditionals into manageable chunks - multiple classes with a common interface can replace a case statement, for instance.

Exit early is a big help, too. If you have error conditions, get those out of the way at the beginning of the function by throwing an exception or returning instead of letting them nest up.

If you break your conditions into predicate functions, it may be easier to keep track of them. Also, if you can get them into a standard form, it might be possible to get them in a data structure that's built dynamically, instead of a hardcoded one.


问:
Is Silverlight only for eye-candy, or does it have a use in business?
Granted that Silverlight may make eye-popping websites of great beauty, is there any justification for using it to make practical web applications that have serious business purposes?  I'd like to use it (to learn it) for a new assignment I have, which is to build a web-based application that keeps track of the data interfaces used in our organization, but I'm not sure how to justify it, even to myself.

Any thoughts on this?  If I can't justify it then I will have to build the app using the same old tired straight ASP.NET approach I've used (it seems) a hundred times already.

答: A full-frame Silverlight line-of-business app is basically a rich .NET client that is run when a user browses to a web page. If you are familiar with rich client programming in XAML/WPF and you don't want to deal with web programming, Silverlight essentially provides a great deployment story - so great that it's making people wonder why they would ever develop WPF rich clients unless they needed really incredible performance, super-flashy 3D graphics or features unique to WPF and excluded from Silverlight, which most LOB apps don't.</p>


答:
It sounds like all these conditional statements that you're talking about should really be data that configures your program rather than part of your program itself. If you can treat them that way, then you'll be free to modify the way your program works by just changing its configuration instead of having to modify your code and recompile every time you want to improve your model.

There are a lot of different ways to model the real world, depending on the nature of your problem. Your various conditions might become rules or constraints that are applied to the simulation. Instead of having code that looks like:

if (sunLevel > 0.75) {
   foreach(cow in cows) {
       cow.desireForShade += 0.5;
   }
}
if (precipitation > 0.2) {
   foreach(cow in cows) {
       cow.desireForShelter += 0.8;
   }
}
```

<p>you can instead have code that looks like:</p>

<pre class="lang-cs prettyprint-override"><code>foreach(rule in rules) {
   foreach (cow in cows) {
      cow.apply(rule);
   }
}
</code>```

Or, if you can develop a linear program that models cow behavior given a number of inputs, each constraint might become a line in a system of equations. You might then turn that into a Markov model that you can iterate.

It's hard to say what the right approach is for your situation, but I think you'll have a much easier time of it if you consider your constraints to be inputs to your program and not code.

Body:
It sounds like all these conditional statements that you're talking about should really be data that configures your program rather than part of your program itself. If you can treat them that way, then you'll be free to modify the way your program works by just changing its configuration instead of having to modify your code and recompile every time you want to improve your model.

There are a lot of different ways to model the real world, depending on the nature of your problem. Your various conditions might become rules or constraints that are applied to the simulation. Instead of having code that looks like:

if (sunLevel > 0.75) {
   foreach(cow in cows) {
       cow.desireForShade += 0.5;
   }
}
if (precipitation > 0.2) {
   foreach(cow in cows) {
       cow.desireForShelter += 0.8;
   }
}

you can instead have code that looks like:

foreach(rule in rules) {
   foreach (cow in cows) {
      cow.apply(rule);
   }
}

Or, if you can develop a linear program that models cow behavior given a number of inputs, each constraint might become a line in a system of equations. You might then turn that into a Markov model that you can iterate.

It's hard to say what the right approach is for your situation, but I think you'll have a much easier time of it if you consider your constraints to be inputs to your program and not code.


问:
What is the difference between a prototype and a production level solution?
This question is purely for learning and to step-up my technical understanding.  I know there is no perfect solution and this question has possible never ending solution list but I think it's very important for every architect to understand the difference between demo and a live project.

I created many demo solutions in .Net in the past.  I now have been assigned to architect and implement a production level web solution so I wanted to ask - on a very high level, what is required to convert a demo into a production level solution.  From my understanding, this will require (other than functionally implementing clients' requirements):

Unit testing every method

Ensuring ~100% code coverage is achieved

Logging all exceptions and possible pointcuts - possible with AOP

Using interface design pattern, dependency injection, possibly by
using a framework e.g. spring.net

Using performance counters and
profilers for instrumentation

Applying appropriate security - i.e.
windows authentication (if that's whats required by client).

Transaction management on every single method

Back up of the web application files before new deployment of solution

What else?

My question is more related to technical side instead of functional/documentation because otherwise we will go into another path :-)

Thank you.

答:
There are two kinds of prototypes:

Quick-and-dirty "proof of concept" applications that get "cleaned up" and become production code. The "clean up" stage tends to either be a nightmare, or it is really a "sweep the problems under the rug" stage, resulting in massive technical debt.

"Mockup" prototypes or "wireframes". These can be paper-and-pencil UI sketches, or even interactive mockups done in a language where you can quickly throw this kind of stuff together without a whole lot of thought behind how it fits together. It should use fake data, no real architecture, etc. The point is that they give stakeholders an idea of what the system will be like, so that you can refine your requirements, but they CAN'T be used as part of your final solution.

I prefer the second kind. They get thrown out, because there isn't really a choice.

OwnerDisplayName: KnowledgeSeeker


答:
The most important feature of production quality solutions is - in my opinion - robustness.

Regardless of what happens, the solution handles the situation sensibly, notifies those needing to know, and keeps going (if the error is recoverable).

Title: What is the difference between a prototype and a production level solution?

Body:
This question is purely for learning and to step-up my technical understanding.  I know there is no perfect solution and this question has possible never ending solution list but I think it's very important for every architect to understand the difference between demo and a live project.

I created many demo solutions in .Net in the past.  I now have been assigned to architect and implement a production level web solution so I wanted to ask - on a very high level, what is required to convert a demo into a production level solution.  From my understanding, this will require (other than functionally implementing clients' requirements):

Unit testing every method

Ensuring ~100% code coverage is achieved

Logging all exceptions and possible pointcuts - possible with AOP

Using interface design pattern, dependency injection, possibly by
using a framework e.g. spring.net

Using performance counters and
profilers for instrumentation

Applying appropriate security - i.e.
windows authentication (if that's whats required by client).

Transaction management on every single method

Back up of the web application files before new deployment of solution

What else?

My question is more related to technical side instead of functional/documentation because otherwise we will go into another path :-)

Thank you.


问:
What is the most orthogonal programming language?
I find myself repeatedly annoyed by having to teach freshmen about special language rules (like array-to-pointer decay) that have absolutely nothing to do with programming in itself. So I wondered:

What is the programming language with the smallest number of special language rules, where everything is first class and can be composed without annoying technical restrictions? Wouldn't such a language be the perfect teaching language?

Moderator Note

We're looking for long answers that provide some explanation and context. Don't just list a language: please explain why you think the language answers the question. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information.

答:
I would propose both SML and Haskell.  Orthogonality has been a principal design point for both.  In particular, the core of SML (that is, the portion of the language not concerned with modularity) is pretty much a typed lambda calculus.  As a result, most language features are driven by types and the types in turn drive the introduction and elimination forms for the values.  This is pretty much ideal.

There are a few non-type-theoretic warts in both languages (eqtypes in SML, seq in Haskell) but they still beat the pants of anything else out there in terms of bizarre interactions of unrelated language features.


答:
I suggest you to consider a concept of MVC design (Model View Controller)

Models are for communication with a database,
controllers are for interaction with user actions and
Views are for visual interaction with a user (display, templates)

For instance: In your example, all user related operations would have 3 parts:
User controller which would consist of: adding, deleting, updating user info (but it would only accept parameters which it would send directly to user model which would be responsible for actual communictaion (operations) with database: add new user to database (on the basis of what paramenters has been sent by controller), delete user from database, update user info in the database...
And view, would be a template for displaying user info, for getting parameters for user info update etc...

That's why php developers use existing frameworks or contruct their own. An application becomes much more modular, much easier for updating, refactoring...

Title: Drawing the line between models & libraries?

Body:
As my webapps increase in size, so does the complexity. In order to keep my classes & files structured and easy-to-access, I am starting to get more and more confused:

I have some very clearly defined data objects in my application - orders, invoices, products for example. All of those have their own entity object that handles enforcement of values and pure business logic along with a model that handles storage of each object to my  persistent storage of choice (database).

Ok - everything clear and separated that far. But what about a logic-heavy object like users?

Users log in and out, change password (with everything that means - hashing, encrypting and so forth) and do a whole lot of interaction both in the database and with Sessions.

Right now, I use an Authentication-class, a library, which carries all of these mentioned actions and a lot more. It does it's job, but It's kind of unclear to me what I should put into a model and what should be a Library?


答:
No one has mentioned this, so I thought I'd say it explicitly:

Thousands of "If .. Then .. Else" rules is a sign of a badly designed application.

While the domain specific data representation might look like these rules, are you absolutely certain that your implementation should resemble the domain specific representation?


答:
I say build it like a project with no demo, but now you can include what you've learned from the demo in your design. Initial coding can be bad even once you start production. You're going to have to refactor much of it anyway.

The real problem to address is your time contraint. When the decision makers want you to continue working on the demo, they're under the impression that much of the application is ready, so it won't take as long. I've heard others use this logic on why they prefer to show sketches to clients instead of overly-realistic mockups. Pay attention to the demo code because it may have discovered issues you never thought of and probably didn't document in this process. You now have to consider them (Overly simplified, but yes, the database may not be accessible for example.).

All prototypes and demos are not created equal. The entire code could be worthless or certain parts may have been done very well. It doesn't matter if it is a demo you have to know the difference. You wouldn't just throw out a legacay app and start over would you?  Forget I asked.


答:
Tcl has 12 rules that govern the entire language.

```<code>[1] Commands.
[2] Evaluation.
[3] Words.
[4] Double quotes.
[5] Argument expansion.
[6] Braces.
[7] Command substitution.
[8] Variable substitution.
[9] Backslash substitution.
[10] Comments.
[11] Order of substitution.
[12] Substitution and word boundaries.
</code>```

There are very few special cases or reserved words or characters.

Title: What is the most orthogonal programming language?

Body:
I find myself repeatedly annoyed by having to teach freshmen about special language rules (like array-to-pointer decay) that have absolutely nothing to do with programming in itself. So I wondered:

What is the programming language with the smallest number of special language rules, where everything is first class and can be composed without annoying technical restrictions? Wouldn't such a language be the perfect teaching language?

Moderator Note

We're looking for long answers that provide some explanation and context. Don't just list a language: please explain why you think the language answers the question. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information.

Body:
Tcl has 12 rules that govern the entire language.

[1] Commands.
[2] Evaluation.
[3] Words.
[4] Double quotes.
[5] Argument expansion.
[6] Braces.
[7] Command substitution.
[8] Variable substitution.
[9] Backslash substitution.
[10] Comments.
[11] Order of substitution.
[12] Substitution and word boundaries.

There are very few special cases or reserved words or characters.


问:
What is the best way to exchange files via authenticated web service?
I'm not so much looking for code (although if you want to link to tutorials it would be appreciated) as I am trying to get an idea of what people in the know are doing. Our system is written in PHP.

As part of an Electronic Medical Record System, I need to be able to securely exchange documents (Word, PDF, etc.) with business partners. I also need to transmit identifying information with the documents (patient name, medical record number, etc.)

If I Google exchanging files in a web service, I am given a bunch of information about a variety of methods. But, what's not easy to see is how old the information is, how commonly the methods are used, and if there is something out there that if I just knew what I was looking for, would blow my socks off.

TLDR - If you were going to use a web service to exchange files, and your system was written in PHP, how would you go about doing it, and why?

答:
Use https and REST. Its secure, tested, and works on any platform. We have two formats that uses a file extension of either .xml or .json for easy consumption, when performing either a POST or GET request. we have http headers that identify if POST is actual a PUT, POST, or DELETE request since not all clients/servers/firewalls allow/recognize PUT and/or DELETE.

One gotcha with using REST is defining an API. The natural tendency is to use a uri style that mimics the familar RPC style. You need to work backwards, and define your uri with the object(s) being acted upon first, and use the verbs (GET,PUT,POST,DELETE) for your operations.

SOAP in comparison has more features, but about 95%(a measure I pulled out of the air) of the features are never used. It complicates understanding it, and adds overhead to development. I would only recommend using it if REST did not provide you with everything you need.


问:
What are linkers and loaders? How do they work?
I am trying to understand things like linkers and loaders better.

What area of computer science do they belong to? Compiler, Operating System, Computer Architecture?

Where do linkers and loaders come into play during development?

答:
Computers basicly work with binary numbers.

People speak their native languages.

Do, programming languages are for communication between people and computers.

If you say: Add 2 and 3 and then substract 1 from it, I doubt that computer would understand anything (maybe in some programming language it would).

So, you need to translate your source code into a format that computer understands, so you need a compiler, which translates a programming language to co called object code.
But object code is not yet the language a computer understands and executes directly. So it needs a linker which will make an executable file that containts instructions in so called machine language; a machine language is a set of operations coded into binary numbers which processor understands. All binary instructions have its structure and its published by a processor manufacturers. You can look for it on say Intel's site and see how do they look like.


答:
The principle that satisfies your description (as I understand it) is the Black Box principle - For example, see this link:
http://it.toolbox.com/blogs/enterprise-solutions/design-principles-black-boxes-16028</p>

Title: Where does "isolating complexities" lie in the realm of design principles?

Body:
I was just curious, it's something I think most people are aware of as a technique:

You have some abominable data that simply must be parsed and you can do nothing to simplify the algorithm for doing it, so the best you can do is isolate the complexity of that algorithm to one place rather than having parts of the algorithm strewn all over. Then after isolating it, cementing the boundaries of it with some interface or contract to ensure the complexity in it does not leak out.

Where does this drive to isolate complexities live in the library of design principles? I don't think it is word for word one of the formally documented design principles, though I'm guessing there are one or two that overlap with this very closely.


问:
ASP vs javascript vs jQuery vs User Controls vs AJAX
Increasingly when developing sites I find myself utilising more client side technologies such as Javascript, jQuery and AJAX.

For three different pages I measured the size of the HTML sent to the browser (excluding images and CSS).

What I found was:

A page that has normal ASP.NET controls + a little bit of jQuery: approx. size = 30kb

A page using some user controls that have AJAX and client side support: approx size = 50kb

A page that uses more complex user controls from a library with heavy client side support: approx. size = 110kb

As you can see the size of data transferred seems to increase as client side support and AJAX features are added.

This adds to the bandwidth requirements of the site and presumably the servers I/O load which may reduce the number of concurrent users that can be served.

Should I worry about balancing rich client side features and interactivity with server's load and bandwidth use?

What are the priorities, if any?

答:
You can't expect to get something for nothing. These libraries do require more initial bandwidth for the user, but once it's cached, browsers are smart enough not to keep refetching where they don't need to.

Content Delivery Networks (CDNs) offer the ability to share cached versions of these libraries across multiple site requests, so using a CDN to fetch jQuery for one site, means the browser won't bother fetching it again on another site that uses the same CDN.

To analyse your specific issues with page sizes, you'll have to analyse where the bandwidth is being spent. Grab something like Firebug (for Firefox), or any other developer tools (all the major browsers have them), and they provide you an interface to determine the appropriate costing for each resource (image, css, javascript, etc). From that, determine where you can make improvements:

Merging static resources (CSS, Javascript)

Image sprites (combining images into single images and using CSS to place them)

HTTP compression (gzip, deflate)

OwnerDisplayName: AtoMerZ

OwnerDisplayName: Matthew Abbott


答: What I think you havent thought about is  if you reference all of the js and controls files in your header, they will only be downloaded the first time, same as css. That way all of the rest of the pages will load only 30kb. do not put the actual control and js code in the html files.. just a reference that can run from the cache</p>

Title: ASP vs javascript vs jQuery vs User Controls vs AJAX

Body:
Increasingly when developing sites I find myself utilising more client side technologies such as Javascript, jQuery and AJAX.

For three different pages I measured the size of the HTML sent to the browser (excluding images and CSS).

What I found was:

A page that has normal ASP.NET controls + a little bit of jQuery: approx. size = 30kb

A page using some user controls that have AJAX and client side support: approx size = 50kb

A page that uses more complex user controls from a library with heavy client side support: approx. size = 110kb

As you can see the size of data transferred seems to increase as client side support and AJAX features are added.

This adds to the bandwidth requirements of the site and presumably the servers I/O load which may reduce the number of concurrent users that can be served.

Should I worry about balancing rich client side features and interactivity with server's load and bandwidth use?

What are the priorities, if any?

OwnerDisplayName: johnny craig


答:
The way that AJAX saves server resources is that users (ideally) make a full-page request exactly once. From there if the user starts browsing other web-pages, requests should typically be much smaller, because you're not reloading everything on the page, only the different content.

Assume the following made-up data (you'll have to do some testing for actual values)

```<code>Values    | AJAX  |  Normal
============================
First     | 120   |   30
Page Load |       |
----------|-----------------
Subsequent|  10   |   30
Page Load |       |

  | AJAX | Normal
==================
1 |  120 | 30
2 |  130 | 60
3 |  140 | 90
4 |  150 | 120
5 |  160 | 150
6 |  170 | 180
7 |  180 | 210
8 |  190 | 240
9 |  200 | 270
10|  210 | 300
</code>```

You'll still have to take into account caching, which is likely to reduce subsequent calls with AJAX and normal requests, but the general idea is that for repeat users over longer sessions, the total data usage will be significantly less than with a normal page (why keep reloading the sidebar when it hasn't changed?)

Additionally, JavaScript allows for significant code minification that just doesn't exist with pure HTML+CSS beyond stripping white-space.

Body:
The way that AJAX saves server resources is that users (ideally) make a full-page request exactly once. From there if the user starts browsing other web-pages, requests should typically be much smaller, because you're not reloading everything on the page, only the different content.

Assume the following made-up data (you'll have to do some testing for actual values)

Values    | AJAX  |  Normal
============================
First     | 120   |   30
Page Load |       |
----------|-----------------
Subsequent|  10   |   30
Page Load |       |

  | AJAX | Normal
==================
1 |  120 | 30
2 |  130 | 60
3 |  140 | 90
4 |  150 | 120
5 |  160 | 150
6 |  170 | 180
7 |  180 | 210
8 |  190 | 240
9 |  200 | 270
10|  210 | 300

You'll still have to take into account caching, which is likely to reduce subsequent calls with AJAX and normal requests, but the general idea is that for repeat users over longer sessions, the total data usage will be significantly less than with a normal page (why keep reloading the sidebar when it hasn't changed?)

Additionally, JavaScript allows for significant code minification that just doesn't exist with pure HTML+CSS beyond stripping white-space.

OwnerDisplayName: zzzzBov


答:
Are we supposed to use these features (javascript, jQuery, AJAX, etc..)?

Depends on your requirements for building an application.  Use the tools that provide acceptable solutions to your needs.

If so why does it make such big difference in the size of pages?

I'm not quite sure if you are looking at just the page or the entire request.  Most of the JavaScript I would assume is in separate files that can be cached by the browser.  So the first request might be big, but subsequent requests would be much smaller.  (Also to take more load off your server, look into using a CDN)

Is it the way I have used them or is it a common problem (I've heard so).?

Since you haven't provided us any code or examples, it could be the way you've used them.  Or it could be the controls you've attempted to use.  I've noticed that Telerik controls seem to be quite bloated, but that is my own opinion.

How do I balance page interactivity and server's load?

These are mostly independent from each other.  It is possible to create a very interactive page that can be either more or less load on the server (load I assume is CPU/Disk time).  In my opinion, AJAX for the most part simply reduces the number of times complete layouts have to be sent by the server to the client which; is less bandwidth and slightly less load on a server due to the lack "rendering" html.

What are priorities?

Highly depends on your application requirements.  It sounds like you've jumped off a diving board into a big pool of web based opportunities, but don't know where to swim to.

I am mostly using JQuery, which has a lot of very good useful features:

DOM element selections

DOM traversal and modification (including support for CSS 1-3)

Events CSS

manipulation Effects and animations

Ajax

Extensibility through plug-ins

Utilities - such as browser

version and the each function.

Cross-browser support

Granted I have to program features myself.

OwnerDisplayName: Erik Philips


答:
MVC as we all know, is composed of Model, View, and All the rest.

Where does authentication fit? everywhere.

It's fundamentally a layer on top of MVC, but then it also needs to get back down into MVC to integrate itself with the View, and the Model.

Authentication is such an ongoing problem with the MVC model and with object orientation in general, they practically invented new paradigms to tackle it: one is aspect-oriented programming.

The only sure thing about aspects, is that Auhentication is one of them; apart from that, actual implementations diverge slightly: most concetrate on injecting function bodies before or after some other objects' methods. Defining the order of injections, the exact point, (called junction points) and the precise scope of the injected code is pretty debatable ...and the stuff of theorists.

So, if you feel every approach you take to deal with authentication seems incomplete and inelegant, you are not alone.

At least knowing there isn't a definite solution should put off some steam: most approaches that will come to your mind are as good as everybody else's. (as long as they work)


答:
To find out more about linkers, I think they'll generally be discussed in combination with compilers.  They are for knitting your various modules together into a cohesive unit, finalizing addresses within that code.  Some may even try to perform optimizations.

To find out more about loaders, I think they'll generally be discussed in combination with writing compilers for particular architectures unless you mean loader as a synonym for linker.  I'm thinking of the loader as the part of the executable file header that tells the operating system how to open and execute your compiled software.

I agree that reading the Wikipedia articles will probably impart more information than you're looking for.  As to where they come into development ... generally they are beyond the control of the project, and are part of the selection of the operating system and the development package you choose to use.  It's very rare that you would use (for example) MSVC but want to run a GCC based linker ... might not even be possible.  The ONLY place I've ever used a non-standard linker was at IBM when we were using development copies.

If you have more particular, specific questions about these topics, I think you'll find a much better response.

Title: What are linkers and loaders? How do they work?

Body:
I am trying to understand things like linkers and loaders better.

What area of computer science do they belong to? Compiler, Operating System, Computer Architecture?

Where do linkers and loaders come into play during development?


答:
Linkers and loaders are two related but separate concepts.

Linkers are a part of compiler theory.  When you compile a project made up of more than one module (source code file), it's common for the compiler to output a single intermediary file for each source module.  This has several benefits, one of which is that if you only make changes to one file and then have to recompile, you don't have to rebuild the entire project when you've only made one local change.

But this means that if you have code in one module that calls a function in a different module, the compiler can't generate a CALL instruction to it, because it doesn't have the location of that other function.  It's in a different intermediary file, and the exact location of the function can change if you make a local change to that intermediary's source file and recompile it.  So instead, it inserts an "external reference token" (exactly what that is or what it looks like doesn't matter, just think of it as an abstract concept) that says "I need this function whose exact address I don't know at the moment."

Once everything has been compiled into intermediary files, the linker is what finishes the job.  It goes through all the intermediary files and links them together into a final binary.  Since it's putting things together, it does know the actual addresses of all the functions, and so it can replace the external reference tokens with actual CALL instructions to the correct locations in the binary.

The loader, on the other hand, belongs to the operating system, not the compiler.  Its job is to load the binary into memory so it can execute, and to finish up the linking process, since the linker can only resolve code it knows about.  If your program is using any DLLs, they are external even to the compiled binary, so the linker doesn't know their address.  It leaves external reference tokens in the final binary in a format that the OS's loader knows about, and then the loader goes through and matches these tokens to the actual function addresses in the DLLs once everything has been loaded into memory.


问:
How to tackle a boss/manager who likes to race the coders
After a recent restructuring happened in our corporation - I have got a new line manager. He is generally ok and not as sneaky as the previous one. By "sneaky" I don't mean he was an evil manager - I just refer by this term to someone who keeps most of the information to himself and doesn't share with other team members in order to be the only "go-to person" - you get the idea.

But nonetheless I had managed to maintain quite a good relationship with my previous manager - and I had been quite productive.

My new boss is more open, which is a good thing, but I really hate one his quality - he likes to race the coders - by giving the same task to a different developer in order to fix the issue ASAP. As you may have already understood the information does NOT flow freely in an environment like ours. So the person who my manager was talking to 10 minutes ago might be starting work on the same issue I am working on now. It happened a few times, and every time I overheard that there might be someone working on the same issue - I did go and ask my manager - who owns the issue - but he usually was very evasive in his answers.

So my question is - how to stop my manager from doing it? In our small team of half a dozen developers I am the most senior one and I am usually spared from the racing but when it hits me it really gets to my nerves.

And one more thing: I am not implying that my manager is a bad/evil boss, neither I believe in that the world is or should be fair, I just want to find a way to make him stop racing me. One thing at a time.

答:
You are not going to be able to solve this problem indirectly. There are too many possible reasons for why the manager is doing this, and many possible levels of awareness of his own actions, as well as their consequences.

From what you described, it sounds to me like the main cause for this problem is a lack of communication at your company. So, the solution I propose is to have you perform some of your manager's work for him:

Talk to your manager

You might have to do this multiple times. Try to find out what value he derives from the racing behaviour - there are lots of possible causes! Just off the top of my head - Is it efficiency? Is he trying to evaluate his employees? Does he realize that the racing programmers are not collaborating? Is he having trouble making sure that there's enough work to go around and trying to protect the team from downsizing by creating extra work? Etc...

Talk to your team members

Find out if anyone else has noticed this behaviour. Are they ok with it? Do they understand what your manager is trying to accomplish? Find ways to provide him with what he needs, while saving yourselves the aggravation. I'm sure you can all look busy even if there isn't much work, and only one of you is working on a problem. Maybe cooperate to finish work faster if he's trying to go for efficiency instead. And if he's racing you to help evaluate which one of you is the better coder, game the system.

Add transparency to the system

Introduce your manager and co-workers to bug tracking tools and the features that they contain to help track who is working on what, and at what time.


问:
Does it violate the license to use Windows XP Mode with Virtual Box?
I am working on a team developing a client-side application. We work in a Linux environment, but the server we work with can only be run from a Windows environment. As such, each developer is being set up with a virtual machine, running on Oracle VM Virtual Box.

Would it violate the terms of use or licensing for the developers to use the virtual hard drive from Windows XP Mode with Oracle VM Virtual Box?

答:
IANAL If you need legal advice, by all means seek it, this is not legal advice.

If you install a copy of XP licence into a VirtualBox on a machine that it would otherwise be legal to install that licence on, and the licence is not in use on another machine, and you are not using the virtual hard drive on more than one machine, I think you're ok.

For example you probably shouldn't use XP Home or XP Embedded Editions in a VirtualBox, but your copy of XP Professional on the shelf should be fine.

My reasoning is that it is legal to use software like Parallels to run Windows OSes on Mac hardware, I don't see a big difference here.

Again, this is strictly opinion.


问:
How do you prevent the piracy of your software?
Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>

答:
Depends on how valuable you deem your time and your IP.

Myself, if I was selling consumer-interesting software that would be likely to be pirated, I would work on an internet-based solution that would deliver encrypted binaries each program run-time.


答:
The exact relationship varies somewhat. To start with, I'll consider (nearly) the simplest possible model, used by something like MS-DOS, where an executable will always be statically linked. For the sake of example, let's consider the canonical "Hello, World!" program, which we'll assume is written in C.

Compiler

The compiler will compile this into a couple of pieces. It'll take the string literal "Hello, World!", and put it into one section marked as constant data, and it'll synthesize a name for that particular string (e.g., "$L1"). It'll compile the call to printf into another section that's marked as code. In this case, it'll say the name is main (or, frequently, _main). It'll also have something to say this chunk of code is N bytes long, and (importantly) contains a call to printf at offset M in that code.

Linker

Once the compiler is done producing that, the linker will run. It's normally considered part of the development tool chain (though there are exceptions -- MS-DOS used to include a linker, though it was rarely if ever used). Although it's not normally externally visible, it will normally be passed some command-line arguments, one specifying an object file containing some startup code, and another specifying whatever file contains the C standard library.

The linker will then look at the object file containing the startup code and find that it is, say, 1112 bytes long, and has a call to _main at offset 784 in that.

Based on that, it'll start to build a symbol table. It'll have one entry saying ".startup" (or whatever name) is 1112 bytes long, and (so far) nothing refers to that name. It'll have another entry saying "printf" is a current unknown length, but it's referred to from ".startup+784".

It'll then scan through the specified library (or libraries) to try to find definitions of the names in the symbol table that aren't currently defined -- in this case printf. It'll find the object file for printf saying that it's 4087 bytes long, and has references to other routines to do things like converting an int to a string, as well as things like putchar (or maybe fputc) to write the resulting string to the output file.

The linker will re-scan to try to find definitions of those symbols, recursively, until it reaches one of two conclusions: it's either found definitions of all the symbols, or else there's a symbol for which it can't find a definition.

If it's found a reference but no definition, it'll stop and give an error message typically saying something about an "undefined external XXX", and it'll be up to you to figure out what other library or object file you need to link.

If it finds definitions of all the symbols, it moves on to the next phase: it walks through the list of places that refer to each symbol, and it'll fill in the address where that symbol got put into memory, so (for example) where the startup code calls main, it'll fill in the address 1112 as the address of main. Once it's done all that, it'll write all the code and data out to an executable file.

There are a few other minor details that probably bear mentioning: it'll typically keep the code and data separate, and after each is complete, it'll put them all together at (more or less) consecutive addresses (e.g., all the pieces of code, then all the pieces of data). There will typically also be some rules about how to combine definitions for section/segments -- for example, if different object files all have code segments, it'll just arrange the pieces of code one after another. If two or more identical string literals (or other constants) are defined, it'll typically merge those together so all of them refer to the same place. There are also a few rules for what to do when/if it finds duplicate definitions of the same symbol. In a typical case, this will simply be an error. In a few cases, it'll have things like "weak external" symbols, that basically say: "I"m providing a definition of this symbol, but if somebody else also defines it, don't consider it an error -- just use that definition instead of this one.

Once it has entries for all the symbols, the linker has to arrange the "pieces" and assign addresses to them. The order in which it arranges the pieces will vary somewhat -- it'll typically have some flags about the types of different pieces, so (for example) all the constant data ends up next to each other, all the pieces of code next to each other and so on. In our simple MS-DOS-like system, most of this won't matter a whole lot though.

Loader

That brings us to the next phase: the loader. the loader is typically part of the operating system, which loads the executable. In ancient versions (e.g., CP/M, MS_DOS .com files, the loader just read data from an executable file into memory, then started executing at some address. Slightly more recent loaders (e.g., for MS-DOS .exe files) will start out (more or less) the same way: read a file into memory. In this case, however, based on the entries put there by the linker, it'll "fix up" any absolute references in the executable to refer to the correct address. In the example above, our startup code referred to main at address 1112, but the executable is being loaded at a base address of (say) 4000. In this case, the loader will fix that address up to refer to 5112. In this simple of a system, however, the loader is still a pretty simple piece of code -- basically just walking through the list of relocations, and adding the base address to each.

Now let's consider a bit more modern OS that supports something like shared object files or DLLs. This basically shifts some of the work from the linker to the loader. In particular, for a symbol that's defined in a .so/DLL, the linker will not attempt to assign an address itself.

Instead it'll create a symbol table entry that basically says "defined in .so/DLL file XXX". When the linker writes the executable, most of these symbol table entries will basically just get copied to the executable, saying "symbol XXX is defined in file YYY". It's then up to the loader to find file YYY, and the address of symbol XXX in that file, and fill in the correct address wherever it's used in the executable. Much like in the linker this will be recursive, so DLL A may refer to symbols in DLL B, which may refer to DLL C, and so on. Although the chain from executable to all the definitions may be long, the basic idea of the process is fairly simple -- scan through the list of external references, and find a definition for each. Also note that in most cases, it will be able to share a single executable across many processes, so the OS will normally have a list of loaded modules, and when/if it gets to a module that's already loaded, it'll just fill in entries for that, and be done rather than re-loading it from the beginning.

Again, there are some miscellaneous bits and pieces to consider. For example, the sharing will normally only happen on a section-by-section basis, not file-by-file. If a file has some code and some (non-constant) data, for example, all processes will share the same code sections, but each will get its own copy of the data.


答:
I would want to know how this factors into my evaulation. Is it a test? Is this his idea of a good time? If this is truly an "all hands on deck!" emergency excercise then suggest letting people collaborate to solve the problem quickly and with a better solution.

For the next challenge, let him put one person against a small team and see what happens.

Sorry you're bothers by this truly annoying practice, but you may get some relief if this isn't part of your evaluation. If it is, you'll just have to start beating everyone.

Title: How to tackle a boss/manager who likes to race the coders

Body:
After a recent restructuring happened in our corporation - I have got a new line manager. He is generally ok and not as sneaky as the previous one. By "sneaky" I don't mean he was an evil manager - I just refer by this term to someone who keeps most of the information to himself and doesn't share with other team members in order to be the only "go-to person" - you get the idea.

But nonetheless I had managed to maintain quite a good relationship with my previous manager - and I had been quite productive.

My new boss is more open, which is a good thing, but I really hate one his quality - he likes to race the coders - by giving the same task to a different developer in order to fix the issue ASAP. As you may have already understood the information does NOT flow freely in an environment like ours. So the person who my manager was talking to 10 minutes ago might be starting work on the same issue I am working on now. It happened a few times, and every time I overheard that there might be someone working on the same issue - I did go and ask my manager - who owns the issue - but he usually was very evasive in his answers.

So my question is - how to stop my manager from doing it? In our small team of half a dozen developers I am the most senior one and I am usually spared from the racing but when it hits me it really gets to my nerves.

And one more thing: I am not implying that my manager is a bad/evil boss, neither I believe in that the world is or should be fair, I just want to find a way to make him stop racing me. One thing at a time.


问:
When developing a piece of software, when do you start thinking/designing the concurrent sections?
Following along with the principle of not optimizing too early, I'm wondering at what point in the design / development of a piece of software do you start thinking about the concurrency opportunities?

I can well imagine that one strategy would be to write a single threaded application, and through profiling identify sections that are candidates to run in parallel.  Another strategy I've seen a little of is to consider the software by groups of tasks and to make the independent tasks parallel.

Part of the reason for asking is that of course, if you wait until the end and only refactor the software to operate concurrently, you may structure things in the worst possible way and have a major task on your hand.

What experiences have helped to determine when you consider parallelization in your design?

答:
It varies with the project. Sometimes it's very easy to see what can be made parallel: perhaps your program processes batches of files. Suppose that the processing of each file is completely independent of all the other files so it might be quite obvious that you could process 1 file at a time, or 10, or 100, and none of these jobs will impact the other.

It gets a little more complicated when the potential parallel jobs aren't the same. Processing an image file, you could have one job that creates a histogram, another that produces a thumbnail, and maybe another that extracts EXIF metadata and then a final job that takes the output of all of these jobs and stores them in a database. In this example, it's maybe not clear if these should be run in parallel, or if they should (the last job will have to wait for the prior jobs to all complete successfully).

In my experiences, the easiest way to parallelize something is to look for processes that could be run as independently as possible (like in the first example) and start with those. I'd only try to make the second example run in parallel if I thought I'd make a significant gain in performance with it.


问:
Pros/Cons for a Data Structure covering multiple databases?
I'm about to extend a system containing two separate systems. Or domains, if we see the system as a domain level.

Today

One domain is used internally. The other is public, which means it is more exposed to whatever can happen "out there". Services of some kind (few options apply) perform operations between the two separate systems. The public and internal system have separated database storages, and are not related to each other. Let's call the domains client and store.

Tomorrow

I'm into a new application that will have lots of more user-specific information at the client domain. The design may be comparable to a 'private database' that has a facebook-account-link as a key. This compares to a database that held user actions, but had no user specific data (such as address, date of birth, email and so on), just a key to the Facebook-server. On the other side, the STORE database (compared to Facebook-server in this case) doesn't know anything about the user actions.

Goal

Approximately 85-90% of the queries will be within their own domain (client if client, store if store). Though, there are some situations where the client need to get data from the STORE database and the STORE needs to create/handle users in the CLIENT database.

Questions out from my head

Is this a good way to go?

Pros/cons? Orphans? Database Performance? Problematic .NET coding?

Principles of the choice for the boundaries of data?

.. and other things you may know or think of

An example of structure

..dbStore.Users

userid (PK)

name

dateOfBirth

emailAddress
-> Wallet (another table)

..dbStore.Wallet

walletid (PK)

userid

createddate
-> BankAccount (another table, not typed)

..dbClient.users

storeUserId (unique, non-inc) <-- corresponds to dbStore.User, no restraint

accessLevel

lastLoggedIn

serviceXxEnabled

udpAccessKey

..dbClient.action

actionid (PK)

isSomething

someDate

anythingElse

..dbClient.installation

installationid (PK)

userid

We won't collect bank-account information, it just to give a picture of the data structure and its importance in keeping it in separate systems. I hope this Q is comprehensible enough.

答:
If it will remain 2 systems then changes to the implementation of one of them should not effect the other. That requires a clear separation and to do that I would:

Only allow access to each database by the system that owns it.

Access the other system through clearly defined interfaces.


答:
Logo: it's still alive and kicking!

```<code>; draws a triangle
FORWARD 100
RIGHT 120
FORWARD 100
RIGHT 120
FORWARD 100
RIGHT 120
</code>```

It might seem more like a toy then a programming language, but it wouldn't be a bad first step for a lot of people. The syntax is very simple, but the turtle provides a more concrete form of feedback than most languages/environments. Trying to create a specific shape is a great way to learn the process of thinking ahead to solve a problem.

If you have an aversion to turtles, though, I really think Scheme is the way to go.

Body:
Logo: it's still alive and kicking!

; draws a triangle
FORWARD 100
RIGHT 120
FORWARD 100
RIGHT 120
FORWARD 100
RIGHT 120

It might seem more like a toy then a programming language, but it wouldn't be a bad first step for a lot of people. The syntax is very simple, but the turtle provides a more concrete form of feedback than most languages/environments. Trying to create a specific shape is a great way to learn the process of thinking ahead to solve a problem.

If you have an aversion to turtles, though, I really think Scheme is the way to go.


问:
Is it "normal" for people to not work?
After graduating from college I was hired as a junior programmer a little over a year ago. I quickly noticed that I was degrees of magnitude faster than all the other programmers; this seems to be because I simply don't waste time "in general". The majority of other people however seem to enjoy staring at the ceiling, browsing YouTube, Facebook, and random websites, and in general doing in a day the work I usually do in an hour. I'm 100% sure they would be able to do that work in an hour too if they focused.

I've been quickly promoted to senior developer and more recently to team leader and now I replaced a lot of those people with new hires (still a couple to go). The situation is now more acceptable, but still I think it could be much better.

I can't help but notice though, that everyone seems to behave like this is "normal". All my bosses aren't concerned about this and they too seem to work little to nothing. I always have a very hard time finding them, they arrive much later than they are supposed to and leave early. Obviously there is nothing I can do in this case since they're above me, but is this is the "norm" in all companies, or did I simply end up in a very bad one (this is my first work experience)?

Also, will I "become like them" in a few years?

答:
You are very lucky. At my former employer, I was the most productive programmer, everyone else was playing video games, and guess what happened to me? First, I was shunned. Then they tried to make as much noise as possible around me. Then I had to find a new job.

All because I program quickly and well.

It almost makes me want to go to China and teach programming. Younger programmers in the West don't want to program. It's too hard. They are mostly incompetent and complacent. Not all... but most.

Title: Is it "normal" for people to not work?


问:
Classes naming: singular or plural?
It is always difficult for me to choose between singular and plural forms for classes names:

```<code>CustomerRepository vs. CustomersRepository
CustomerService vs. CustomersService
CustomerController vs. CustomersController
</code>```

And for composite names it is even more difficult:

OrderCustomerRepository vs. OrderCustomersRepository vs.
  OrdersCustomersRepository

What approach do you prefer and why?

答:
The only thing I pluralize is collections.

```<code>foreach (var customer in customers)
{
    // do something with customer
}
</code>```

All of your examples are individual objects, so they are not pluralized.  Yes, the names refer to objects that might have multiple instances, but all you need to know in the name is the object entity (i.e. customer).

So in all of your examples, the singular is the correct form.  Makes life much easier.

Title: Classes naming: singular or plural?

Body:
The only thing I pluralize is collections.

foreach (var customer in customers)
{
    // do something with customer
}

All of your examples are individual objects, so they are not pluralized.  Yes, the names refer to objects that might have multiple instances, but all you need to know in the name is the object entity (i.e. customer).

So in all of your examples, the singular is the correct form.  Makes life much easier.


答: You should buy a Windows XP OEM disk and set up your VM with that.  Use a different legal key for each developer's VM.</p>

Title: Does it violate the license to use Windows XP Mode with Virtual Box?

Body:
I am working on a team developing a client-side application. We work in a Linux environment, but the server we work with can only be run from a Windows environment. As such, each developer is being set up with a virtual machine, running on Oracle VM Virtual Box.

Would it violate the terms of use or licensing for the developers to use the virtual hard drive from Windows XP Mode with Oracle VM Virtual Box?