答:
Add this to the list:

The presented scenario is simple (even more simple as I will present
  it here than it was originally!):
   1.A WinForms TextBox sits on a Form, empty. It has a MaxLength set to 20.

2.The user types into the TextBox, or maybe pastes text into it.

3.No matter what you type or paste into the TextBox, you are limited to 20, though it will sympathetically beep at text beyond the 20 (YMMV
  here; I changed my sound scheme to give me that effect!).

4.The small packet of text is then sent somewhere else, to start an exciting adventure.

Now this is an easy scenario, and anyone can
  write this up, in their spare time. I just wrote it up myself in
  multiple programming languages using WinForms, because I was bored and
  had never tried it before. And with text in multiple actual languages
  because I am wired that way and have more keyboard layouts than
  possibly anyone in the entire freaking universe.

I even named the
  form Magic Carpet Ride, to help ameliorate the boredom.

This did not
  work, for what it's worth.

So instead, I entered the following 20
  characters into my Magic Carpet Ride form:

0123401234012340123

Uh oh.

That last character is U+20000, the first Extension B
  ideograph of Unicode (aka U+d840 U+dc00, to its close friends who he
  is not ashamed to be disrobed, as it were, in front of)....

And now we have a ball game.

Because when TextBox.MaxLength talks
  about

Gets or sets the maximum number of characters that can be manually
  entered into the text box.

what it really means is

Gets or sets
  the maximum number of UTF-16 LE code units that can be manually
  entered into the text box and will mercilessly truncate the living
  crap out of any string that tries to play cutesy games with the
  linguistic character notion that only someone as obsessed as that
  Kaplan fellow will find offensive (geez he needs to get out more!).

I'll try and see about getting the document updated....

  Regular
  readers who remember my UCS-2 to UTF-16 series will note my
  unhappiness with the simplistic notion of TextBox.MaxLength and how it
  should handle at a minimum this case where its draconian behavior
  creates an illegal sequence, one that other parts of the .Net
  Framework may throw a

System.Text.EncoderFallbackException: Unable
  to translate Unicode character \uD850 at index 0 to specified code
  page.*

exception if you pass this string elsewhere in the .Net
  Framework (as my colleague Dan Thompson was doing).

Now okay,
  perhaps the full UCS-2 to UTF-16 series is out of the reach of many.

  But isn't it reasonable to expect that TextBox.Text will not produce a
  System.String that won't cause another piece of the .Net Framework to
  throw?   I mean, it isn't like there is a chance in the form of some
  event on the control that tells you of the upcoming truncation where
  you can easily add the smarter validation -- validation that the
  control itself does not mind doing.   I would go so far as to say that
  this punk control is breaking a safety contract that could even lead
  to security problems if you can class causing unexpected exceptions to
  terminate an application as a crude sort of denial of service.   Why
  should any WinForms process or method or algorithm or technique
  produce invalid results?

Source : Michael S. Kaplan MSDN Blog

Title: Should UTF-16 be considered harmful?

OwnerDisplayName: Yuhong Bao


问:
Should UTF-16 be considered harmful?
I'm going to ask what is probably quite a controversial question: "Should one of the most
popular encodings, UTF-16, be considered harmful?"

Why do I ask this question?

How many programmers are aware of the fact that UTF-16 is actually a variable length encoding? By this I mean that there are code points that, represented as surrogate pairs, take more than one element.

I know; lots of applications, frameworks and APIs use UTF-16, such as Java's String, C#'s String, Win32 APIs, Qt GUI libraries, the ICU Unicode library, etc.  However, with all of that, there are lots of basic bugs in the processing of characters out of BMP (characters that should be encoded using two UTF-16 elements).

For example, try to edit one of these characters:

𝄞 (U+1D11E) MUSICAL SYMBOL G CLEF

𝕥 (U+1D565) MATHEMATICAL DOUBLE-STRUCK SMALL T

𝟶 (U+1D7F6) MATHEMATICAL MONOSPACE DIGIT ZERO

𠂊 (U+2008A) Han Character

You may miss some, depending on what fonts you have installed.  These characters are all outside of the BMP (Basic Multilingual Plane).  If you cannot see these characters, you can also try looking at them in the Unicode Character reference.

For example, try to create file names in Windows that include these characters; try to delete these characters with a "backspace" to see how they behave in different applications that use UTF-16. I did some tests and the results are quite bad:

Opera has problem with editing them (delete required 2 presses on backspace)

Notepad can't deal with them correctly (delete required 2 presses on backspace)

File names editing in Window dialogs in broken (delete required 2 presses on backspace)

All QT3 applications can't deal with them - show two empty squares instead of one symbol.

Python encodes such characters incorrectly when used directly u'X'!=unicode('X','utf-16') on some platforms when X in character outside of BMP.

Python 2.5 unicodedata fails to get properties on such characters when python compiled with UTF-16 Unicode strings.

StackOverflow seems to remove these characters from the text if edited directly in as Unicode characters (these characters are shown using HTML Unicode escapes).

WinForms TextBox may generate invalid string when limited with MaxLength.

It seems that such bugs are extremely easy to find in many applications that use UTF-16.

So... Do you think that UTF-16 should be considered harmful?

答:
Unicode defines code points up to 0x10FFFF (1,114,112 codes), all applications running in multilingual environment dealing with strings/file names etc. should handle that correctly.

Utf-16: covers only 1,112,064 codes. Although those at the end of Unicode are from planes 15-16 (Private Use Area). It can not grow any further in the future except breaking Utf-16 concept.

Utf-8: covers theoretically 2,216,757,376 codes. Current range of Unicode codes can be represented by maximally 4 byte sequence. It does not suffer with byte order problem, it is "compatible" with ascii.

Utf-32: covers theoretically 2^32=4,294,967,296 codes. Currently it is not variable length encoded and probably will not be in the future.

Those facts are self explanatory. I do not understand advocating general use of Utf-16. It is variable length encoded (can not be accessed by index), it has problems to cover whole Unicode range even at present, byte order must be handled, etc. I do not see any advantage except that it is natively used in Windows and some other places. Even though when writing multi-platform code it is probably better to use Utf-8 natively and make conversions only at the end points in platform dependent way (as already suggested). When direct access by index is necessary and memory is not a problem, Utf-32 should be used.

The main problem is that many programmers dealing with Windows Unicode = Utf-16 do not even know or ignore the fact that it is variable length encoded.

The way it is usually in *nix platform is pretty good, c strings (char *) interpreted as Utf-8 encoded, wide c strings (wchar_t *) interpreted as Utf-32.

OwnerDisplayName: Artyom

ContentLicense: CC BY-SA 3.0

Title: Should UTF-16 be considered harmful?

OwnerDisplayName: Pavel Machyniak

ContentLicense: CC BY-SA 2.5


答:
Yes, absolutely.

Why? It has to do with exercising code.

If you look at these codepoint usage statistics on a large corpus by Tom Christiansen you'll see that trans-8bit BMP codepoints are used several orders if magnitude more than non-BMP codepoints:

```<code> 2663710 U+002013 ‹–›  GC=Pd    EN DASH
 1065594 U+0000A0 ‹ ›  GC=Zs    NO-BREAK SPACE
 1009762 U+0000B1 ‹±›  GC=Sm    PLUS-MINUS SIGN
  784139 U+002212 ‹−›  GC=Sm    MINUS SIGN
  602377 U+002003 ‹ ›  GC=Zs    EM SPACE

 544 U+01D49E ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL C
 450 U+01D4AF ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL T
 385 U+01D4AE ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL S
 292 U+01D49F ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL D
 285 U+01D4B3 ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL X
</code>```

Take the TDD dictum: "Untested code is broken code", and rephrase it as "unexercised code is broken code", and think how often programmers have to deal with non-BMP codepoints.

Bugs related to not dealing with UTF-16 as a variable-width encoding are much more likely to go unnoticed than the equivalent bugs in UTF-8. Some programming languages still don't guarantee to give you UTF-16 instead of UCS-2, and some so-called high-level programming languages offer access to code units instead of code-points (even C is supposed to give you access to codepoints if you use wchar_t, regardless of what some platforms may do).

Title: Should UTF-16 be considered harmful?

Body:
I'm going to ask what is probably quite a controversial question: "Should one of the most
popular encodings, UTF-16, be considered harmful?"

Why do I ask this question?

How many programmers are aware of the fact that UTF-16 is actually a variable length encoding? By this I mean that there are code points that, represented as surrogate pairs, take more than one element.

I know; lots of applications, frameworks and APIs use UTF-16, such as Java's String, C#'s String, Win32 APIs, Qt GUI libraries, the ICU Unicode library, etc.  However, with all of that, there are lots of basic bugs in the processing of characters out of BMP (characters that should be encoded using two UTF-16 elements).

For example, try to edit one of these characters:

𝄞 (U+1D11E) MUSICAL SYMBOL G CLEF

𝕥 (U+1D565) MATHEMATICAL DOUBLE-STRUCK SMALL T

𝟶 (U+1D7F6) MATHEMATICAL MONOSPACE DIGIT ZERO

𠂊 (U+2008A) Han Character

You may miss some, depending on what fonts you have installed.  These characters are all outside of the BMP (Basic Multilingual Plane).  If you cannot see these characters, you can also try looking at them in the Unicode Character reference.

For example, try to create file names in Windows that include these characters; try to delete these characters with a "backspace" to see how they behave in different applications that use UTF-16. I did some tests and the results are quite bad:

Opera has problem with editing them (delete required 2 presses on backspace)

Notepad can't deal with them correctly (delete required 2 presses on backspace)

File names editing in Window dialogs in broken (delete required 2 presses on backspace)

All QT3 applications can't deal with them - show two empty squares instead of one symbol.

Python encodes such characters incorrectly when used directly u'X'!=unicode('X','utf-16') on some platforms when X in character outside of BMP.

Python 2.5 unicodedata fails to get properties on such characters when python compiled with UTF-16 Unicode strings.

StackOverflow seems to remove these characters from the text if edited directly in as Unicode characters (these characters are shown using HTML Unicode escapes).

WinForms TextBox may generate invalid string when limited with MaxLength.

It seems that such bugs are extremely easy to find in many applications that use UTF-16.

So... Do you think that UTF-16 should be considered harmful?

Body:
Yes, absolutely.

Why? It has to do with exercising code.

If you look at these codepoint usage statistics on a large corpus by Tom Christiansen you'll see that trans-8bit BMP codepoints are used several orders if magnitude more than non-BMP codepoints:

 2663710 U+002013 ‹–›  GC=Pd    EN DASH
 1065594 U+0000A0 ‹ ›  GC=Zs    NO-BREAK SPACE
 1009762 U+0000B1 ‹±›  GC=Sm    PLUS-MINUS SIGN
  784139 U+002212 ‹−›  GC=Sm    MINUS SIGN
  602377 U+002003 ‹ ›  GC=Zs    EM SPACE

 544 U+01D49E ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL C
 450 U+01D4AF ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL T
 385 U+01D4AE ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL S
 292 U+01D49F ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL D
 285 U+01D4B3 ‹›  GC=Lu    MATHEMATICAL SCRIPT CAPITAL X

Take the TDD dictum: "Untested code is broken code", and rephrase it as "unexercised code is broken code", and think how often programmers have to deal with non-BMP codepoints.

Bugs related to not dealing with UTF-16 as a variable-width encoding are much more likely to go unnoticed than the equivalent bugs in UTF-8. Some programming languages still don't guarantee to give you UTF-16 instead of UCS-2, and some so-called high-level programming languages offer access to code units instead of code-points (even C is supposed to give you access to codepoints if you use wchar_t, regardless of what some platforms may do).

OwnerDisplayName: ninjalj


问:
Evaluating third-party libraries
At our company, we frequently use third-party libraries and frameworks in our products. Often, we are faced with the task of evaluating one or more libraries that full fill similar requirements (in a specific case we had to choose between some encryption libraries).
We often do a simple prototype to try to figure out, if the library somehow works for us. However, often the prototypes get really complex and when we are at a point where we figure out, that the library is not suited for our purposes, lots of time was spend, that we could have used to write the desired functionality ourselves.

My question would be, do you have or practice any guidelines when it comes to evaluating third-party libraries? More specifically, do you have something like a maximum time that will be spend on prototypes and do you have general requirements for libraries you use (license issues, support, documentation, ...)?

答:
The single most important guideline I always try to follow when choosing stuff like that is to have a documented checklist

for third party library my list may look like this: maven; maven - release version; code examples; open source; understandable javadoc; compact API; reference to specification used; reference to public spec used (like RFC, JSR etc); releases changelog; bug tracking; active; positive feedback (most recent version of the list documented and explained here: csv api for java:)

do you have something like a maximum time that will be spend on prototypes

In cases like you describe - yes. More generally, whenever I sense anything resembling a deadline, I immediately add it to my checklist. ...; tentative date to decide whether to accept or reject a prototype

Title: Evaluating third-party libraries


问:
Am I Over-Engineering If I Consider User's Intentional Wrongdoing?
Is it over-engineering if I add protection against a user's intentional wrongdoing (to put it mildly), if the harm the user can incur is not related to my code?

To clarify, I'm exposing a simple JSON RESTful service like this:

```<code>GET /items - to retrieve list of user's items
PUT /items/id - to modify an item
POST /items - to add a new item
</code>```

The service itself is not meant to be used trough a browser, but only from third party applications, controlled by the user (like phone apps, desktop app, etc.). Also, the service itself should be stateless (i.e. session-less).

The authentication is done with Basic Authentication over SSL.

I'm talking about one possible "harmful" behavior like this:

The user enters the GET url in a browser (no reason but...).
The browser asks for Basic Auth, process it, and stores the auth for the current browsing session.
Without closing the browser, the user visits malicious web site, which has a malicious CSRF/XSRF javascript which makes a POST to our service.

The above scenario is highly unlikely, and I know that from a business perspective I should not worry too much. But for the sake of improving the situation, do you think that if the username/password are required in the JSON POST data as well, will help?

Or should I drop Basic Auth altogether, get rid of the GET, and use only POST/PUT with authorization information in them? As the information retrieved trough GET can be also sensitive.

On the other side, does using custom headers considered pure REST implementation? I can drop the Basic Auth, and use custom headers. That way, at least CSRF attack from a browser can be avoided, and the applications which use the service will set the username/password in custom heather. Bad for this approach is, that now the service can not be consumed from a browser.

答:
You should consider all plausible eventualities, including the user being actively malicious and (successfully) reverse engineering any "security by obscurity" barriers.

But at the same time, you should be assessing the impact of a success hack, and the likelihood of an attempt taking place.  For instance:

An internal service protected by a solid firewall is less likely to be subject to attack than a service on the public internet.

The impact of someone taking down a customer discussion forum is less than the impact of them stealing customer credit cards.

My point is that "total security" is "infinitely expensive" ... and practically unachievable.  Ideally you should to make your decisions about where to draw the line based on a thorough cost-benefit analysis.


问:
Why isn't Java used for modern web application development?
As a professional Java programmer, I've been trying to understand - why the hate toward Java for modern web applications?

I've noticed a trend that out of modern day web startups, a relatively small percentage of them appears to be using Java (compared to Java's overall popularity).  When I've asked a few about this, I've typically received a response like, "I hate Java with a passion."  But no one really seems to be able to give a definitive answer.

I've also heard this same web startup community refer negatively to Java developers - more or less implying that they are slow, not creative, old.

As a result, I've spent time working to pick up Ruby/Rails, basically to find out what I'm missing.  But I can't help thinking to myself, "I could do this much faster if I were using Java," primarily due to my relative experience levels.

But also because I haven't seen anything critical "missing" from Java, preventing me from building the same application.

Which brings me to my question(s):

Why is Java not being used in modern web applications?

Is it a weakness of the language?

Is it an unfair stereotype of Java because it's been around so long (it's been unfairly associated with its older technologies, and doesn't receive recognition for its "modern" capabilities)?

Is the negative stereotype of Java developers too strong? (Java is just no longer "cool")

Are applications written in other languages really faster to build, easier to maintain, and do they perform better?

Is Java only used by big companies who are too slow to adapt to a new language?

答: Google App Engine supports Java, so that you can write your entire web app in Java, using Eclipse as the IDE and deployment interface, with a reasonably documented Google API --  so I wouldn't say it isn't used or isn't usable.</p>


问:
How can you measure your own daily contributions?
I've recently finished the The Three Signs of a Miserable Job by Patrick Lencioni and one of his core ideas is that you need to have some form of measurement.

I have a pretty standard internal developer job where I work on new tools and do some support/bug fixes for past tools I have written.

For purely personal fulfillment reasons, what things would you measure on a daily basis?  (This is not a report to managers and not something to game, just something to help me mark progress).

The goal is to find things that measure not just productivity, but how good of a job you are doing (so a customer service person might record positive interactions in addition to number of calls taken).

My stab at this would be to measure two things every day: support requests opened/closed and number of checkins to source control.

I understand if this gets closed, but once again this isn't a question about management, its about personal development as a programmer/software developer.

答:
I have a simple measure of progression:

when my co-workers/ clients say things like:

Stage 1:

"great working, loving it!"

Stage 2:

"that's awesome! I didn't even know you could do that!"

Stage 3:

"That's a life saver! the system would not be the same without it"

Stage 4:

"Absolutely yes, I trust you"

Stage 5:

"Its simply excellent, I don't know what more I could add"

Stage 6:

"You have changed us, changed this company, for the better"

Stage 7:

"thank you, you inspire me"


问:
How far can I push refactoring without changing external behavior?
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?

答:
The boundaries of a refactoring are specific to a given refactoring. There simply can't be one answer and encompasses everything. One reason is the term refactoring is itself non-specific.

You can refactor:

Source Code

Program Architecture

UI Design / User Interaction

and I am sure several other things.

Perhaps refactor could be defined as

"an action or set of actions which decrease the entropy in a
  particular system"


问:
How to model future iPhone application GUI?
Say you're working on designing the world's greatest iPhone app.

How do you decide what UI would be more effective, would be more intuitive etc? How do you take an idea and decide how to visually represent it?

Do you use any programs (on a mac) to model something like that?

答:
First keep Apple Human Interface Guidelines under your pillow.

Check also some of the most famous iOS apps and try to learn about their decisions.

But what is really important is to let many people outside of your team to try the application. Because your coworkers will become the masters of how to use the application even it has some flows.

I don't need any program, I use pencil and papers for sketching. This way I can sketch the UI very quickly without dropping tears when I need to get ride of it after spending a lot of time sketching it using a program.

But in case you need a program, check OmniGraffle, there are a lot of amazing stencils for prototyping iOS/Android and many other platforms interfaces.

Tapworthy is one of the best books about designing UI no matter what if it is an iOS or and Android app.

Tapworthy takes you from concept to polished interface design with plain-spoken principles and a rich collection of visual examples for designing exceptional interfaces for the iPhone and iPod Touch.


答:
I would take another tact, depending upon where you are in your career, but particularly if you're junior to mid. Obviously, you want to meet your employer's expectations, you want to get your tasks complete on schedule, sound appropriate alarms if things are going different than expected, do your check ins, collaborate with your peers... everything you need to do.

Beyond that, my strategy is this: Do better today than you did yesterday.

That's it. That's your goal.

This means that the code you wrote yesterday is bad and today, you'll do better. Today, you'll research, fill in some of those gaps, those things you didn't even know you didn't know. Today, you'll refactor. You'll take that method that you left a bit too messy and clean it up. You'll recognize that thing you left too tightly coupled. You'll write that test that you overlooked. You'll learn something new.

If you do these things and you get your other work done, you'll have had a good, productive day.

Title: How can you measure your own daily contributions?

Body:
I've recently finished the The Three Signs of a Miserable Job by Patrick Lencioni and one of his core ideas is that you need to have some form of measurement.

I have a pretty standard internal developer job where I work on new tools and do some support/bug fixes for past tools I have written.

For purely personal fulfillment reasons, what things would you measure on a daily basis?  (This is not a report to managers and not something to game, just something to help me mark progress).

The goal is to find things that measure not just productivity, but how good of a job you are doing (so a customer service person might record positive interactions in addition to number of calls taken).

My stab at this would be to measure two things every day: support requests opened/closed and number of checkins to source control.

I understand if this gets closed, but once again this isn't a question about management, its about personal development as a programmer/software developer.


答:
There's definitely some bounds on how far you can refactor.  See: When Are Two Algorithms the Same?

People usually regard algorithms as more abstract than the programs
  that implement them. The natural way to formalize this idea is that
  algorithms are equivalence classes of programs with respect to a
  suitable equivalence relation. We argue that no such equivalence
  relation exists.

So, don't go too far, or you won't have any confidence in the result. On the other hand, experience dictates that you can often replace one algorithm with another, and get the same answers, sometimes faster.  That's the beauty of it, eh?

Title: How far can I push refactoring without changing external behavior?

Body:
According to Martin Fowler, code refactoring is (emphasis mine):

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

What is "external behaviour" in this context? For example, if I apply move method refactoring and move some method to other class, it looks like I change external behaviour, doesn't it?

So, I'm interested in figuring out at what point does a change stop being a refactor and becomes something more. The term "refactoring" may be misused for larger changes: is there a different word for it?

Update. A lot of interesting answers about interface, but wouldn't move method refactoring change the interface?


答:
Learn at least one new language a year, and use it.

Dive into at least one new aspect of the huge world of programming/software engineering each year, and use it.

Push yourself to dive deep. You are not pushing yourself hard enough if you never get the feeling that you are in over your head.

Talk to your supervisor about how to advance your career. A good supervisor is always on the lookout for someone to replace him or her. Talk to your boss's boss, or even higher up the chain, about how to accomplish this end. This might take a bit of finesse; do not give the impression that you are going over your boss's head here.

You'd be surprised how many promotions are given just because someone had the gumption to ask for one.


问:
What is best practice on ordering parameters in a function?
Sometimes (rarely), it seems that creating a function that takes a decent amount of parameters is the best route.  However, when I do, I feel like I'm often choosing the ordering of the parameters at random.  I usually go by "order of importance", with the most important parameter first.

Is there a better way to do this?  Is there a "best practice" way of ordering parameters that enhances clarity?

答:
Similar to @Wyatt Barnetts' answer, anything more than a few parameters or very explicit parameters for the method, I'd recommend passing an object instead.  This is typically easier to update/maintain, clearer to read, and removes the necessity for worrying about ordering.  Also, too many parameters for a method is a code smell and there are common refactoring patterns you can follow to help correct it.

Explicit example:

```<code>public int add(int left, int right)
{
  return left + right;
}
</code>```

Since this is a pretty clearly defined example and addition is commutative (order doesn't matter) then just go with it.

However, if you add something more complex:

```<code>public SomeComplexReturnValue Calculate(int i, float f, string s, object o)
{
  // do work here
}
</code>```

Would become:

```<code>public class SomeComplexInputForCalculation
{
  public int i;
  public float f;
  public string s;
  public object o;
}

public SomeComplexReturnValue Calculate(SomeComplexInputForCalculation input)
{
  // do work here
}
</code>```

Hope this helps...

Body:
Similar to @Wyatt Barnetts' answer, anything more than a few parameters or very explicit parameters for the method, I'd recommend passing an object instead.  This is typically easier to update/maintain, clearer to read, and removes the necessity for worrying about ordering.  Also, too many parameters for a method is a code smell and there are common refactoring patterns you can follow to help correct it.

Explicit example:

public int add(int left, int right)
{
  return left + right;
}

Since this is a pretty clearly defined example and addition is commutative (order doesn't matter) then just go with it.

However, if you add something more complex:

public SomeComplexReturnValue Calculate(int i, float f, string s, object o)
{
  // do work here
}

Would become:

public class SomeComplexInputForCalculation
{
  public int i;
  public float f;
  public string s;
  public object o;
}

public SomeComplexReturnValue Calculate(SomeComplexInputForCalculation input)
{
  // do work here
}

Hope this helps...


问:
Is there an encyclopedia of algorithms?
Is there an encyclopedia of algorithms similar in style to the Handbook of Mathematics? It seems useful to have large numbers of them available in one place. I know the Art of Computer Programming is considered a good source but it does not seem encyclopedic so much as instructive.

Moderator Note

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

答: I'm not sure if this is what you're looking for but NIST has the Dictionary of Algorithms and Data Structures. It's a pretty comprehensive dictionary for data structures and algorithms (doh) and usually a good to place to look when I find something I never heard about before.</p>

Title: Is there an encyclopedia of algorithms?


问:
Effectiveness of "what is your greatest strength/weakness" interview questions
As someone who is now finding himself on the other end of the interview table, I'm wondering how useful these questions are from an employer's perspective. Some of my coworkers think they're good because you can see "how they respond," but I'm not convinced it tells you anything useful, for several reasons:

It's not a very comfortable question and can lead people to twist their answers, even if not on purpose

People may not fully know their greatest strengths or weaknesses (i.e. judge them by their peers)

Explaining what a strength is isn't as good as showing it

I still don't know any more about the candidate afterwards

The rationale of my coworkers is that it can help weed out people that give ridiculous responses, like one guy that said his greatest strength was "his intellect" or people that try to turn the weakness question into a strength like "I work too hard." But I think there's more effective ways to determine such things. If you want to see if someone's smart, ask them technical questions. If you want to see if someone is productive, look at their work history. If you want to see how someone reacts under stress or change, ask them how they've dealt with it and ask for concrete examples.

What are people's thoughts on these questions, from the perspective of an interviewer? What do they really tell you about a candidate, and what are better alternatives? How do I convince my colleagues of this?

答:
I will speak from a position of an interviewee. When I prepare for an interview, I always take time to think about these questions. "Your strengths" question may be easier to answer, because all of us are proud of our own accomplishments and can talk about them. In an interview people will almost always try to over-glorify their accomplishments to try to look better. When it comes to "your weaknesses" question, it is very hard to answer it completely honestly and say something constructive and negative about yourself. Either, an interviewee will pick a weakness that's pretty minor, and will not give an interviewer any useful information or try to turn a weakness into a "strength". For example, "I think my weakness is that I tend to overwork myself." Either way, all the weaknesses and strengths will become obvious during the probation period. That's what it's for - to see if the employee-employer relationship is mutually beneficial.

Previous employers may be a better source of information for these kind of questions. Ask for references and follow up.


答:
Structure and Interpretation of Computer Programs and the Art of Computer Programming are the closest I've seen to what you seek.

SICP walks through common data structures and algorithms. While it's not encyclodpedic, it is pretty good a covering a wide swath of territory in a limited amount of space.

What can be said about The Art of Computer Programming that hasn't been already. Be careful when you pick it up, you might go to it for a specific topic and hours later realize that you've read a volume from cover to cover. It's a great way to really take your programming to the next level.

Title: Is there an encyclopedia of algorithms?

Body:
Is there an encyclopedia of algorithms similar in style to the Handbook of Mathematics? It seems useful to have large numbers of them available in one place. I know the Art of Computer Programming is considered a good source but it does not seem encyclopedic so much as instructive.

Moderator Note

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


问:
What is a domain of automatic testing tools such as ScalaCheck?
I've seen not so many examples of testing with automatic tools, i.e.  serializing/deserializing of JSON (which was paired in the following way:
val actual = deserialize(serialize(string))), checking that appending symbols to string was done properly (and that's imho silly, cause it extremely hard to made a mistake in such plain operations).

Can you provide really useful examples/use cases for automatic testing with ScalaCheck that will unveil it advantages? Does it meant to be used mostly in paired style (straight/inverse functions like in JSON example above)?

答:
You can take a look at the tests that Scala itself is using at the moment.

To be honest, I had never seen the kind of paired test you mention. The scope of ScalaCheck is pretty simple: if there's a rule, property, invariant or condition your code must observe, then ScalaCheck is a great fit for it.

I'll state this in reverse to make it even clearer. The only place where you don't use ScalaCheck is for code that is composed solely of exceptions -- that is, there is no rule that apply over inputs which will tell you something about the outputs.

There's very few places I can think of where such a thing would happen.


答:
In graduate school in Physics I really enjoyed Numerical Recipes in C.  It does not cover all algorithms, of course, but gives excellent explanations of many that are incredibly useful in the sciences:

http://www.nr.com/

The book covers how to solve:

Linear equations

Linear Equations

Interpolation and Extrapolation

Integration of functions

Function Evaluation

Special functions including gamma function, beta function, factorials

Random numbers - including a good explanation of what this means

Sorting algorithms

Finding roots and nonlinear equations

Minimization and maximization of functions

Eigensystems

Fast Fourier Transforms

FFT and spectral analysis

Statistical description of data

Modeling of data

Integratoin of ordinary differential equations

Two point boundary problems

Integral equations and inverse boundary thory

Partial Differential equations

"Other" algorithms such as CRC checks and data compression

So it's all very mathematical, good for scientists as well as for people designing physics engines for games.  And it does not just give the algorithms but explains the whys behind them so that you can use them correctly.  Not your typical coding text, but exactly what you need when you need it.

I relied on it heavily when using the downhill simplex method in multidimensions (an amoeba walk) for data analysis.  Still has my pencil marks in it. Ahh, good times!

Title: Is there an encyclopedia of algorithms?


答:
The Skiena book is a good reference also: http://www.algorist.com/

The book covers everything from background through different problem areas (data structures, searching/sorting, graph problems, combinations/permutations/heuristics) and even the issues of P vs NP-complete problems.

The particularly relevant section of the book to this question is a catalog of ~70-75 different algorithms, the types of inputs they generally require, the overall description of the problem a particular algorithm solves, and specific examples of applications (for example, the section on suffix trees discusses its usage of tries, and its applicability to substring and searching).  Where possible the author also identifies existing implementations for various common languages (c, c++, Java, and some others.)

Title: Is there an encyclopedia of algorithms?


问:
How to retain student/intern programmers?
We have a small team in our department and typically employ 1-3 students/interns.  The problem we have is retention.  We like to hire a student that will stick around as part of the team for more than just a summer quarter.  The problem is though the last 4 students we hired, up front we discussed this with them and they all ended up leaving earlier than we would have liked.

The relationships all ended in a good fashion, the students either obtained teaching assistant or research positions within the university, or went on to bigger and better things.  This is all understandable and we do not hold it against them for doing what is best for them.

But my perspective is different as I worked within our department for 2 years during undergraduate at which point I was brought on full time upon graduation.

How can we retain students?  We give them hardware they need/want, we provide them with problems to solve in anyway they see fit (within reason).  All in all to me this type of job for a student programmer is so flexible and awesome I cannot see how anyone would want to leave.

Thoughts ?

答:
Why are they taking university positions over yours? They leave on good terms, so just ask them during the exit interview? Are they looking for careers in academe? Do they get 'brownie points' for working with a professor? Is spending time in these positions required to keep scholarship money?

Often on a big campus having a job there is a big benefit to having to commute to a job. Students also need flexible time. Let them work remotely some times. Give them a great laptop to use for the time they are employed.

Make them explain why they want to work for your company in the first place and maybe you'll find out what will make them stay. The short internship may be the minimum entry on their resume they need to go work somewhere else or complete their degree.


问:
How can I start shipping code?
I have just started learning how to program using LPTHW, and as my skill level develops I would like to start shipping code whether or not it's ready to be shipped, just to get into the habit of always shipping code, and not having the fear of shipping code.

Is there are a beginner friendly guide to shipping code?

答:
You mention shipping code versus shipping a product. Keep in mind that they're two very different things. If your true interest is shipping code:

Set up a github, bitbucket, google code or <favorite hosting here> account

Start a small project or, heck, start several

Commit your code to your public source repository

Publicly write about your experience and reference your repositories

Attend local user groups and share your experience

Look for feedback

Adapt, refactor, add features, start new projects

Share what you learn

Look for collaborators - it's hard to get better without collaborators

When you're ready, start shipping products

Title: How can I start shipping code?


答:
I don't think it's harmful if the developer is careful enough.

And they should accept this trade off if they know well too.

As a Japanese software developer, I find UCS-2 large enough and limiting the space apparently simplifies the logic and reduces runtime memory, so using utf-16 under UCS-2 limitation is good enough.

There are filesystem or other application which assumes codepoints and bytes to be proportional, so that raw codepoint number can be guaranteed to be fit to some fixed size storage.

One example is NTFS  and VFAT specifying UCS-2 as their filename storage encoding.

If those example really wants to extend to support UCS-4, I could agree using utf-8 for everything anyway, but fixed length has good points like:

can guarantee the size by length (data size and codepoint length is proportional)

can use the encoding number for hash lookup

non-compressed data is reasonably sized (compared to utf-32/UCS-4)

In the future when memory/processing power is cheap even in any embeded devices, we may accept the device being a bit slow for extra cache misses or page faults and extra memory usage, but this wont happen in the near future I guess...

Title: Should UTF-16 be considered harmful?


答:
Shipping code when it is not ready to be shipped is like juggling with nitroglycerin sticks in a bear cave during their seasonal nap. Something will fall down, there will be lots of noise and blood around and you will be stick with angry bears to deal with.

The best advice I can give is develop mindset and process of work that allows you to create a shipable code faster and more efficient.

http://www.codinghorror.com/blog/2006/07/what-is-modern-software-development.html

This is a start.

Title: How can I start shipping code?

Body:
I have just started learning how to program using LPTHW, and as my skill level develops I would like to start shipping code whether or not it's ready to be shipped, just to get into the habit of always shipping code, and not having the fear of shipping code.

Is there are a beginner friendly guide to shipping code?


答:
Keep a development journal and pay special attention to non-routine happenings. I'm excited by:

Using a new algorithm, pattern, library, data structure, or language

Collaborating with a new team or person

Fixing a bug that was considered especially difficult

Making a deep personal connection

Building small tools that make my job easier (and possibly my co-workers' jobs)

Getting blocked and then noticing exactly what happens to unblock me

Noticing improvements in productivity caused by diet, sleep, and attitude

Opportunities to share my passion

Beauty in unlikely places

As for routine happenings:

Watch the time required for routine tasks drop

Watch what you consider difficult diminish

Break out of routine interactions by giving someone your full attention and energy


问:
Should jQuery DOM manipulation be avoided in favor of JavaScript template engines?
From what I can tell, most developers will use heavy jQuery DOM manipulation tactics to deliver their updated AJAX views. Once things get out of hand, they may consider refactoring using template engines such as Mustache.js. Is this a valid assessment of a natural progression to use a template engine?

When I begin a new AJAX heavy project, is the best practice to use a template engine or is jQuery DOM manipulation good enough?

I have yet to find any negatives with using a template engine. The maintainability, efficiency and simplicity seem to be the redeeming qualities.

Please advise me on whether JavaScript template engines should be used or not by default.

答:
@Jason, these notes come to my mind:

JavaScript templates are handy, mostly when you have a list (or array) as the underlying datasource. For example, when you get the list of active employees in JSON format from the server, it's better to bind it to a JavaScript template on return (AJAX response) instead of looping over each employee and creating HTML elements by concatenating strings and employee properties together.

However, there are sometimes situations where JavaScript binding simply is an overhead. Most of the times, you don't have a list of records. Rather, you have a single value in your AJAX response. For example, when you vote-up on stackexchange sites, the return value is not a list, thus not suitable to be used with a JavaScript template.

Another situation that you may not be able to use JavaScript templates is the heterogeneous, instead of homogeneous, datasource. For example, in response to an AJAX request, you may return this JSON string:

```<code>"{"firstName":"Saeed","lastName":"Nemati","isEmployed":true,"interests":["computer","music","language","philosophy","mathematics","physics"],"voteDirection":"up","totalScore":5}"
</code>```

Which is a complex object of an employee and a vote action. In these scenarios also, you can't use JavaScript templates and should use DOM manipulation directly.

JavaScript refactoring or jQuery refactoring sometimes becomes a headache, as there are still not sophisticated tools out there to help you in a good level. Thus, for example if you create a

Saeed Nemati

 HTML fragment on an AJAX response in many places, and then you decide to create  tag instead of
 tag, you really need to concentrate on this.

Body:
@Jason, these notes come to my mind:

JavaScript templates are handy, mostly when you have a list (or array) as the underlying datasource. For example, when you get the list of active employees in JSON format from the server, it's better to bind it to a JavaScript template on return (AJAX response) instead of looping over each employee and creating HTML elements by concatenating strings and employee properties together.

However, there are sometimes situations where JavaScript binding simply is an overhead. Most of the times, you don't have a list of records. Rather, you have a single value in your AJAX response. For example, when you vote-up on stackexchange sites, the return value is not a list, thus not suitable to be used with a JavaScript template.

Another situation that you may not be able to use JavaScript templates is the heterogeneous, instead of homogeneous, datasource. For example, in response to an AJAX request, you may return this JSON string:

"{"firstName":"Saeed","lastName":"Nemati","isEmployed":true,"interests":["computer","music","language","philosophy","mathematics","physics"],"voteDirection":"up","totalScore":5}"

Which is a complex object of an employee and a vote action. In these scenarios also, you can't use JavaScript templates and should use DOM manipulation directly.

JavaScript refactoring or jQuery refactoring sometimes becomes a headache, as there are still not sophisticated tools out there to help you in a good level. Thus, for example if you create a <div class='employee'><h1>Saeed Nemati</h1></div> HTML fragment on an AJAX response in many places, and then you decide to create <a> tag instead of <h1> tag, you really need to concentrate on this.


答:
If you want some daily affirmation then the simplest metric you can use is to write yourself a task list, or a to-do for today.

Write down what you need to do.

Can you split up any of those tasks. Make it more granular.

Start working on a task.

If you need to add more tasks, start over from step 1.

When you're finished with the task, cross it out.

At the end of the day, look at all the tasks you've done and feel proud. Now that's personal fulfillment!


问:
Do you really have to do BDD/TDD in a test first manner?
Even though I haven't been in a TDD or BDD project, or I have been in some that say they are doing TDD but are pretty far from it, these are things that I think about and really try to read as much as I can about.

Back to the question. When you're doing BDD you should write your "test" first and make it fail, right? And then implement that feature or what you call it. But if you take this to the extreme couldn't this be some kind of top-down development? You're looking at your UI and says, "I would like to have this feature/behavior here". Then you fix your UI to implement that feature and the code that supports the UI. At this point you haven't implemented any business logic or data access logic, you have just implemented your behavior. What I'm aiming at instead of writing the test first you write your UI code first. In some cases it should result in the same code for the data access and business layer, since you use your UI code to define what your business needs to support.

Of course you should complement this with tests that is used to make sure that the feature is working as it should in the feature.

Any thoughts?

答:
You are talking about BDD from a high level perspective of testing your UI. Testing is a bit more fluffy at this level than lower down in your Javascript/server side code.

Several books I've read on TDD say you should write code as if the underlying systems exist, and just write enough to get your test to pass. You can write stubs on the server to get your UI behavioural tests pass. Then you start at this stub seam and write some unit tests for your server side code and work your way down to a full implementation.

I often code as if underlying layers exist to get a high level test to pass, it does feel like going down a rabbit hole and extracting many other classes to satisfy the high level test, and then writing tests for these lower levels. As you've already recognised, it helps to keep you focused starting with higher level tests.

As any seasoned programmer knows, there are many layers to software development. I tend to work lower than the UI and think about the data or behaviour my UI needs from the server and start there (maybe because I don't do much UI work these days).

If I'm really honest, extracting a class from the underlying layers means I'm not doing test first but ... within minutes or sometimes hours I'll have a test for that code. This still feel beneficial to me as I helps see where you might need to supply dependencies to a class and honour the single responsibility principle - if it's hard to test, you're doing too much in one place etc.


答:
Cormen, Leiserson, Rivest, Stein - "Intoduction To Algorithms"

Introduction to Algorithms, more commonly known as CLRS, is the standard algorithms textbook at a large number of universities. It covers a range of algorithms for a variety of applications, including sorting, searching, graph theory and basic numerical computation. It also includes a detailed discussion of Big O, Big Omega and Big Theta notation. A common criticism is that it doesn't really prepare one to design new algorithms, but as an encyclopedia or dictionary of algorithms, its is more than adequate.

I should also note that CLRS also gives advice on which algorithm to use when, and doesn't just present a generic index of algorithms and data structures. It's useful when you have a task that you want to accomplish and want advice on how best to go about it. There are better resources for when you know how you want to do what you're doing and you just need pseudo-code.

— from comments by @quanticle, below

Title: Is there an encyclopedia of algorithms?


问:
Hit the Upper Limit for Cross Platform API Capabilities
I am a junior programmer who works as an intern(8 mths into the internship) in a team of 1(myself only) creating mobile phone apps & websites.

I have created an App that works exactly how it should & has some pretty cool features but the App fails to run on Android(the main target platform for us, it works on the desktop emulator but not on Android) due to the memory problems with large apps in the Mosync API(see the links for more info on the memory problem). The most demoralising aspect of the problem is that(as explained in the links below) the app crashes randomly & not consistantly so you make a change run it on the platform a cple of times & where something worked before it will now freeze then cause the app to crash(Android OS kills my app).

http://www.mosync.com/content/android-how-much-memory-too-much-memory
http://usingimho.wordpress.com/2011/06/14/why-you-should-stay-away-from-appcelerators-titanium/

I have invested 4 weeks in developing the app(an interactive calendar) & 5 mths in learning the Mosync API for apps that wont work on the platform.

My Problem: I have to decide between dumping the app & starting the app again in Native Android Java(I know Java) or severely reducing the the number of resources(.pngs) & features of the app(polaroid effect it produces) to make it work in the android platform. The end result will be functional but low quality(in terms of graphics) & simple.

What would more experienced developers decide to do & how would you explain this decision/recommendation to your non-technical boss?

答:
I'd do a translation to Java. Save as much of the application architecture as you can. With mobile apps in the particular, presentation really matters and crisp visuals help a whole lot on a small screen. Take all the ideas that work and re-craft rather than tearing down the code base.

I did that with an iOS app and I didn't finish the second build before the class I was working on it finished. I wound up with a mockup movie done by manually manipulating the UI in the GIMP and then stringing each frame together. I don't recommend that method for real production code. I may have gotten an A for effort and a good report but I don't think you'd get the same reception.

So if you know Java, run it to Java as well as you can. Scaling down would likely be less effective in the long run than a slightly buggy but stable initial release that looks nice and runs mostly stably with some hitches than a  app that looks awful and runs smoothly. Bugs can be worked around, lousy design is harder to correct. Strip it to the bone if you have to but try not to throw it away completely.

As far boss goes, ask something like this question: Would you rather release a low quality product soon that might make us look shoddy or a more pristine app later that makes us look awesome?


问:
Introducing functional programming into your development environment
This is a long story but I will try to summarize it as best I can. We are a .NET shop that writes software for a variety of different types of funds. For example, we write health claims management software, pension management software, 401(k) software and some other financial-type things.

Now we are entering a new realm: derivatives and quantitative analytics type of work, which seems very exciting. This is something that is coming down in the next 8-12 months I've been told.

Now, I have learned some functional programming on my own, mainly just superficial glances at various languages via this book but never really dug deep into it. Now, since we are a .NET shop I was thinking F# might be a good choice, because we could potentially leverage some .NET libraries and existing knowledge possibly.

My question is, where to start? I am having an exceedingly difficult time trying to figure out if I should go with Haskell, Erlang, Scala, F#, etc. They all seem very interesting and capable and quite frankly this might be a good chance to break out being so Microsoft dependent.

Has anyone had a similar situation? If so, what was your experience making the jump to functional and what did you choose and why? I know this is kind of a big question but I don't know any developers that are using functional methods right now so I have nowhere else to turn other than Googling incessantly and finding flame wars everywhere on the best functional language.

答:
If all you want is to learn and understand functional programming, then just install IronPython and focus on the functional features in Python. At worst, you will learn a tool that can be integrated with C# to cut down the number of lines of code in an application and help you deliver more bugfree products ahead of schedule.

Have a look at DaBeaz's presentations about generators for an example of how functional approaches in Python can simplify complex things http://www.dabeaz.com/generators/

Other than that, I think that you would be wise to invest some time with Scala. It runs on .NET in beta mode, so you can install it and use it today for learning purposes, and by the autumn, it will be in release mode for .NET. This means that you can write code in Scala that is portable across the JVM and .NET. And, since Scala is based around Actors and message passing, it is very, very easy to build an application made out of several separate programs running on several separate machines. When you add the .NET/JVM portability to the mix, then there is another aspect to consider. You could have one application that leverages both 3rd party Java libraries and 3rd party .NET libraries without messing around with developing protocols to make them communicate. Both processes would be written in Scala, and would use Scala remote messaging (remote actors) to communicate. Check out the Akka, library which seems like it will eventually become part of Scala's standard library judging by what Typesafe.com are doing.


问:
Languages to complement C++
I primarily work in C++.  My question is, for a C++ developer, what languages are beneficial to learn, from a job-profile point of view.  For example, I see a lot of work combining C++ and Php these days.  Conversely, I don't see a lot of work combining Ruby and C++ (unfortunately).

Of course, learning another language is beneficial regardless of whether it compliments a language.

答:
Erlang

I recommend Erlang. C++ is mostly used for performance, but it doesn't have great support for large scale concurrency. With that in mind Elrang would be a great complement since it has great concurrency performance but not very good performance for number crunching. Erlang is often used together with C/C++ in distributed and embedded systems, specially in telecom. Erlang is good support for interfacing with C&C++.

Title: Languages to complement C++


问:
Is there an equivalent of mod_rewrite for Twisted web?
I've been programming in PHP for a long time, and I've just recently decided to make the switch to Python. Of all the Python web frameworks, I settled on Twisted Web to build the framework of my startup.

However (and I know it sounds nitpicky), mod_rewrite was something that I really appreciated about Apache. I want the entire system written in Python, and not just bits and pieces written in PHP and Python: while a PHP frontend could work, I'd avoid it if it was at all possible.

Is it possible to build such an application without resorting to ugly urls?

Note: I am aware of the fact that Django allows URL rewriting, but it kinda defeats the purpose of using Twisted by itself.

答: There's a section of the Twisted Documentation that mentions inspiration from Apache's mod_rewrite and lists some methods, specifically twisted.web.rewrite, to do similar things.</p>


答:
The Refactoring book is pretty strong in its message that you can only perform refactoring when you have unit test coverage.

Thus, you could say that as long as you're not breaking any of your unit tests, you're refactoring. When you break tests, you're not refactoring any more.

But: how about such simple refactorings such as changing the names of classes or members? Don't they break tests?

Yes they do, and in each case you'll need to consider whether that break is significant. If your SUT is a public API/SDK then a rename is, indeed, a breaking change. If not, it's probably OK.

However, consider that often, tests break not because you changed behavior that you actually care about, but because the tests are Fragile Tests.


问:
Do donations count as "commercial use"?
Lets say I'm building community that uses some webapp. These webapp uses a a modified version a a GPLv2 licensed theme. Additionally the community uses a donation mechanism to fund itself. Donation overheads will be given back to the community in some form, so there is no commercial goal behind it.

Questions:

Am I required to publish the modified version of the theme if I only use it?

Is this "commercial use" in terms of the GPL?

答:
1) No, but that depends on what you mean by "use".

2) The GPL says nothing about commercial use. So go ahead.

Title: Do donations count as "commercial use"?


问:
File shredder algorithm
As a part of learning system programming, I am looking to implement a file shredder. The simplest way (and probably seen as naive) would be to replace the data bytes with zeroes (I know OS splits the files and I'll replace bytes in all those chunks). But when I google on this topic, I am surprised to find multiple pass algorithms, some going as high as 35!

Could someone elucidate the benefit of multiple pass please? I couldn't find any explanation.

Thanks

答:
The multipass erase is necessary to destroy data on magnetic storage devices. Data can be recovered with the right equipment even if it was overwritten by another sequence of 1s and 0s from the layers below or in between.

However, there are voices on the internet which claim that multipass erasure is no longer necessary, as the areal density of data on modern harddrives has increased 10 000 fold.

Title: File shredder algorithm


答: It is said that experts with special equipment can reconstruct a formatted drive. Therefore the advise is to overwrite the data on the drive multiple times with differing (random) patterns.</p>

Title: File shredder algorithm

Body:
As a part of learning system programming, I am looking to implement a file shredder. The simplest way (and probably seen as naive) would be to replace the data bytes with zeroes (I know OS splits the files and I'll replace bytes in all those chunks). But when I google on this topic, I am surprised to find multiple pass algorithms, some going as high as 35!

Could someone elucidate the benefit of multiple pass please? I couldn't find any explanation.

Thanks


答:
Dunno about Android, but often you can resort to palette based PNGs (they come closer to GIF than to JPG), compression and that sort of things. See where you can reuse stuff. You don't need a whole button if you can combine it from ultra small PNGs. Some things can be generated dynamically, gradients etc...

How much memory does the stuff use? What's the target amount? How heavy is the code/resources?

Title: Hit the Upper Limit for Cross Platform API Capabilities

Body:
I am a junior programmer who works as an intern(8 mths into the internship) in a team of 1(myself only) creating mobile phone apps & websites.

I have created an App that works exactly how it should & has some pretty cool features but the App fails to run on Android(the main target platform for us, it works on the desktop emulator but not on Android) due to the memory problems with large apps in the Mosync API(see the links for more info on the memory problem). The most demoralising aspect of the problem is that(as explained in the links below) the app crashes randomly & not consistantly so you make a change run it on the platform a cple of times & where something worked before it will now freeze then cause the app to crash(Android OS kills my app).

http://www.mosync.com/content/android-how-much-memory-too-much-memory
http://usingimho.wordpress.com/2011/06/14/why-you-should-stay-away-from-appcelerators-titanium/

I have invested 4 weeks in developing the app(an interactive calendar) & 5 mths in learning the Mosync API for apps that wont work on the platform.

My Problem: I have to decide between dumping the app & starting the app again in Native Android Java(I know Java) or severely reducing the the number of resources(.pngs) & features of the app(polaroid effect it produces) to make it work in the android platform. The end result will be functional but low quality(in terms of graphics) & simple.

What would more experienced developers decide to do & how would you explain this decision/recommendation to your non-technical boss?


问:
Is the "Objects First" approach a good idea?
Do you think programming novices should learn objects from day 1, as seen in the book "Objects First With Java: A Practical Introduction Using BlueJ" by David Barnes? Or do you think this is a bad idea?

For those unfamiliar with the book, here is a list of the topics discussed in the chapters:

Chapter 1 deals with the most fundamental concepts of object-orientation: objects, classes and methods. It gives a solid, hands-on introduction to these concepts without going into the details of Java syntax. It also gives a first look at some source code. We do this by using an example of graphical shapes which can be interactively drawn, and a second example of a simple laboratory class enrolment system.

Chapter 2 opens up class definitions and investigates how Java source code is written to create behavior of objects. We discuss how to define fields and implement methods. Here, we also introduce the first types of statements. The main example is an implementation of a ticket machine. We also look back to the laboratory class example from chapter 1 to investigate that a bit further.

Chapter 3 then enlarges the picture to discuss interaction of multiple objects. We see how objects can collaborate by invoking each other's methods to perform a common task. We also discuss how one object can create other objects. A digital alarm clock display is discussed that uses two number display objects to show hours and minutes. As a second major example, we examine a simulation of an email system in which messages can be sent between mail clients.

In Chapter 4, we continue by building more extensive structures of objects. Most importantly, we start using collections of objects. We implement an electronic notebook and an auction system to introduce collections. At the same time, we discuss iterations over collection and have a first look at loops. The first collection being used is an ArrayList. In the second half of the chapter we introduce arrays as a special form of a collection, and the for loop as another form of a loop. We discuss an implementation of a web log analyzer as an example for array use.

Chapter 5 deals with libraries and interfaces. We introduce the Java standard library and discuss some important library classes. More importantly, we explain how to read and understand the library documentation. The importance of writing documentation in software development projects is discussed, and we end by practicing how to write suitable documentation for our own classes. Random, Set and Map are examples of classes that we encounter in this chapter. We implement an Eliza-like dialogue system and a graphical simulation of a bouncing ball to apply these classes.

Chapter 6, titled Well-behaved objects, deals with a whole group of issues connected to producing correct, understandable, and maintainable classes. It covers issues ranging from writing clear, understandable code - including style and commenting - to testing and debugging. Test strategies are introduced and a number of debugging methods are discussed in detail. We use an example of a diary for appointment scheduling and an implementation of an electronic calculator to discuss these topics.

In Chapter 7, we discuss more formally the issues of dividing a problem domain into classes for implementation. We introduce issues of designing classes well, including concepts such as responsibility-driven design, coupling, cohesion, and refactoring. An interactive, text-based, adventure game (World of Zuul) is used for this discussion. We go through several iterations of improving the internal class structure of the game and extending its functionality, and end with a long list of proposals for extensions that may be done as student projects.

Chapters 8 and 9 introduce inheritance and polymorphism with many of the related detailed issues. We discuss a simple database of CDs and videos to illustrate the concepts. Issues of code inheritance, subtyping, polymorphic method calls and overriding are discussed in detail.

In Chapter 10 we implement a predator/prey simulation. This serves to discuss additional abstraction mechanisms based on inheritance, namely interfaces and abstract classes.

Chapter 11 introduces two new examples: an image viewer and a sound player. Both examples serve to discuss how to build graphical user interfaces (GUIs).

Chapter 12 then picks up the difficult issue of how to deal with errors. Several possible problems and solutions are discussed, and Java's exception handling mechanism is discussed in detail. We extend and improve an address book application to illustrate the concepts.

Chapter 13 steps back to discuss in more detail the next level of abstraction: how to structure a vaguely described problem into classes and methods. In previous chapters we have assumed that large parts of the application structure already exist, and we have made improvements. Now it is time to discuss how we can get started from a clean slate. This involves detailed discussion of what the classes should be that implement our application, how they interact, and how responsibilities should be distributed. We use class-responsibilities-collaborators (CRC) cards to approach this problem, while designing a cinema booking system.

In Chapter 14, we try to bring everything together and integrate many topics from the previous chapters of the book. It is a complete case study, starting with the application design, through design of the class interfaces, down to discussing many important functional and non-functional characteristics and implementation details. Topics discussed in earlier chapters (such as reliability, data structures, class design, testing, extendibility, etc.) are applied again in a new context.

答:
I personally think that the easiest programming concepts to learn are the ones that follow simple procedural logic (e.g. Represent a flow diagram).  The next simplest to learn is basic objects as you can teach parallels to the real world (Car, Dog, Person etc).

So in short I think you should start day 1 by teaching them basic flow logic and then you can move onto objects fairly quickly after that.

Functional programming is probably the hardest to teach to new programmers unless they have a mathematical background or just think in that way.

YMMV with this answer :-)


答:
I'm not sure the state of BlueJ now, but I was taught by David Barnes and Michael Kölling and used that book and BlueJ in 2004-2006.

It's good to have the work bench and see how the objects interact with each other.

As Martijn said basic flow is the easiest way to understand a program, a problem with BlueJ and the Objects First approach is that you're insulated from Main() and how an application starts so you can focus on Objects and their interactions.

BlueJ is great for learning OO and the Java language, but once you're au fait with OO, I would move to e.g. Eclipse and start using that knowledge to build applications with an IDE designed for building applications rather than learning OO/Java.

Title: Is the "Objects First" approach a good idea?

Body:
Do you think programming novices should learn objects from day 1, as seen in the book "Objects First With Java: A Practical Introduction Using BlueJ" by David Barnes? Or do you think this is a bad idea?

For those unfamiliar with the book, here is a list of the topics discussed in the chapters:

Chapter 1 deals with the most fundamental concepts of object-orientation: objects, classes and methods. It gives a solid, hands-on introduction to these concepts without going into the details of Java syntax. It also gives a first look at some source code. We do this by using an example of graphical shapes which can be interactively drawn, and a second example of a simple laboratory class enrolment system.

Chapter 2 opens up class definitions and investigates how Java source code is written to create behavior of objects. We discuss how to define fields and implement methods. Here, we also introduce the first types of statements. The main example is an implementation of a ticket machine. We also look back to the laboratory class example from chapter 1 to investigate that a bit further.

Chapter 3 then enlarges the picture to discuss interaction of multiple objects. We see how objects can collaborate by invoking each other's methods to perform a common task. We also discuss how one object can create other objects. A digital alarm clock display is discussed that uses two number display objects to show hours and minutes. As a second major example, we examine a simulation of an email system in which messages can be sent between mail clients.

In Chapter 4, we continue by building more extensive structures of objects. Most importantly, we start using collections of objects. We implement an electronic notebook and an auction system to introduce collections. At the same time, we discuss iterations over collection and have a first look at loops. The first collection being used is an ArrayList. In the second half of the chapter we introduce arrays as a special form of a collection, and the for loop as another form of a loop. We discuss an implementation of a web log analyzer as an example for array use.

Chapter 5 deals with libraries and interfaces. We introduce the Java standard library and discuss some important library classes. More importantly, we explain how to read and understand the library documentation. The importance of writing documentation in software development projects is discussed, and we end by practicing how to write suitable documentation for our own classes. Random, Set and Map are examples of classes that we encounter in this chapter. We implement an Eliza-like dialogue system and a graphical simulation of a bouncing ball to apply these classes.

Chapter 6, titled Well-behaved objects, deals with a whole group of issues connected to producing correct, understandable, and maintainable classes. It covers issues ranging from writing clear, understandable code - including style and commenting - to testing and debugging. Test strategies are introduced and a number of debugging methods are discussed in detail. We use an example of a diary for appointment scheduling and an implementation of an electronic calculator to discuss these topics.

In Chapter 7, we discuss more formally the issues of dividing a problem domain into classes for implementation. We introduce issues of designing classes well, including concepts such as responsibility-driven design, coupling, cohesion, and refactoring. An interactive, text-based, adventure game (World of Zuul) is used for this discussion. We go through several iterations of improving the internal class structure of the game and extending its functionality, and end with a long list of proposals for extensions that may be done as student projects.

Chapters 8 and 9 introduce inheritance and polymorphism with many of the related detailed issues. We discuss a simple database of CDs and videos to illustrate the concepts. Issues of code inheritance, subtyping, polymorphic method calls and overriding are discussed in detail.

In Chapter 10 we implement a predator/prey simulation. This serves to discuss additional abstraction mechanisms based on inheritance, namely interfaces and abstract classes.

Chapter 11 introduces two new examples: an image viewer and a sound player. Both examples serve to discuss how to build graphical user interfaces (GUIs).

Chapter 12 then picks up the difficult issue of how to deal with errors. Several possible problems and solutions are discussed, and Java's exception handling mechanism is discussed in detail. We extend and improve an address book application to illustrate the concepts.

Chapter 13 steps back to discuss in more detail the next level of abstraction: how to structure a vaguely described problem into classes and methods. In previous chapters we have assumed that large parts of the application structure already exist, and we have made improvements. Now it is time to discuss how we can get started from a clean slate. This involves detailed discussion of what the classes should be that implement our application, how they interact, and how responsibilities should be distributed. We use class-responsibilities-collaborators (CRC) cards to approach this problem, while designing a cinema booking system.

In Chapter 14, we try to bring everything together and integrate many topics from the previous chapters of the book. It is a complete case study, starting with the application design, through design of the class interfaces, down to discussing many important functional and non-functional characteristics and implementation details. Topics discussed in earlier chapters (such as reliability, data structures, class design, testing, extendibility, etc.) are applied again in a new context.


答:
Imagine a physical disk storing the binary value 0101. Physically, on the disk, the charges exist as real values, which are rounded up or down by the disk controller

binary  ->   physical charge

0 1 0 1  ->  0.1 0.9 0.1 0.9

If you were to overwrite the data with zeros, some residual charge would remain from the previous values, so you could in this simple example, the new values being

binary  ->    physical

0 0 0 0  ->  0.01 0.09 0.01 0.09

Equipment that is sensitive enough to read these charges at high resolution, can then be used to extract this "shadow" of the overwritten data. That's why rewriting multiple times (and using random values) helps obscure the data.

Title: File shredder algorithm


问:
Is there any difference between Custom Control and User Control in .NET
As stated in the question, is there any difference in the meaning of the two as applied to the Controls of .NET. Or are they alias of one another?</p>

答: A user control is a composition of existing controls while a custom control is a control derived from one base control. This might be better in stackoverflow btw.</p>


答:
User Control These are the existing controls of the framework and are used in conjunction with other controls to facilitate certain actions like Login Control

Custom Control In this case you inherit from the available control and add features which are customized for that control and your needs. something like a datepicker Column in the DataGridView

Title: Is there any difference between Custom Control and User Control in .NET

Body: As stated in the question, is there any difference in the meaning of the two as applied to the Controls of .NET. Or are they alias of one another?</p>


问:
Why isn't Java used for modern web application development?
As a professional Java programmer, I've been trying to understand - why the hate toward Java for modern web applications?

I've noticed a trend that out of modern day web startups, a relatively small percentage of them appears to be using Java (compared to Java's overall popularity).  When I've asked a few about this, I've typically received a response like, "I hate Java with a passion."  But no one really seems to be able to give a definitive answer.

I've also heard this same web startup community refer negatively to Java developers - more or less implying that they are slow, not creative, old.

As a result, I've spent time working to pick up Ruby/Rails, basically to find out what I'm missing.  But I can't help thinking to myself, "I could do this much faster if I were using Java," primarily due to my relative experience levels.

But also because I haven't seen anything critical "missing" from Java, preventing me from building the same application.

Which brings me to my question(s):

Why is Java not being used in modern web applications?

Is it a weakness of the language?

Is it an unfair stereotype of Java because it's been around so long (it's been unfairly associated with its older technologies, and doesn't receive recognition for its "modern" capabilities)?

Is the negative stereotype of Java developers too strong? (Java is just no longer "cool")

Are applications written in other languages really faster to build, easier to maintain, and do they perform better?

Is Java only used by big companies who are too slow to adapt to a new language?

答:
An interesting answer is given by Dries Buytaert, who founded drupal. Although his PhD was about java, he chose php for drupal, and he didn't regret doing so.
You can read it (and some of his comments) here:
http://buytaert.net/why-php-and-not-java

It would have been very difficult to get critical mass if Drupal was written in Java.


答:
1) From the GPL faq :

Does the GPL require that source code of modified versions be posted
  to the public?

The GPL does not require you to release your modified version, or
  any part of it. You are free to make modifications and use them
  privately, without ever releasing them. This applies to organizations
  (including companies), too; an organization can make a modified
  version and use it internally without ever releasing it outside the
  organization.

But if you release the modified version to the public in some way,
  the GPL requires you to make the modified source code available to the
  program's users, under the GPL.

Thus, the GPL gives permission to release the modified program in
  certain ways, and not in other ways; but the decision of whether to
  release it is up to you.

In some sense, by using your modified theme for your webapp, I would consider that you are releasing your theme for something else than internal use, so you need to release your modified source code, at least to the person using the app.

2) GPL never forbid any kind of charging for the use of your app, so you have the right to make money of it, as long as you comply with the terms of the license.

Title: Do donations count as "commercial use"?

Body:
Lets say I'm building community that uses some webapp. These webapp uses a a modified version a a GPLv2 licensed theme. Additionally the community uses a donation mechanism to fund itself. Donation overheads will be given back to the community in some form, so there is no commercial goal behind it.

Questions:

Am I required to publish the modified version of the theme if I only use it?

Is this "commercial use" in terms of the GPL?


答:
User control: Any control inheriting from UserControl class; These types of controls have a markup associated with them and can have code-behind based on the type of project you have (whether your project is a website or a web application). These controls are not good for re-usability across projects. They are very good candidates to be used as Views in MVC (Model-View-Controller).

Custom control: Any control inheriting from Control, or WebControl or CompositeControl or DataBoundControl or some other base classes in .NET. These controls don't have associated markup with them. They are pretty good for being encapsulated inside a DLL and being reused across multiple projects. Custom controls usually need more understanding of how web works and you usually overwrite CreateChildren or Render method to determine the output of the control.


答:
C++: a kitchen-sink language, statically and manifestly typed.

Sounds like a good complement would be a language with a very few concepts, dynamically and latently typed. Sounds like Smalltalk!

Title: Languages to complement C++

Body:
I primarily work in C++.  My question is, for a C++ developer, what languages are beneficial to learn, from a job-profile point of view.  For example, I see a lot of work combining C++ and Php these days.  Conversely, I don't see a lot of work combining Ruby and C++ (unfortunately).

Of course, learning another language is beneficial regardless of whether it compliments a language.


答:
Java absolutely is used for modern web application development. Particularly once you get to the slighly larger / more complex / scalable end of the web application spectrum.

If you are interested in modern, productive tools and frameworks take a look at:

The Play framework

Google Web Toolkit

Vaadin

Tapestry 5

But I think most truly modern web development on the JVM platform is likely to be done in one of the new JVM languages rather than using Java directly, with Java simply providing the backbone in terms of underlying libraries and back-end infrastructure. There is a lot of web development happening in Groovy (Grails), Scala (Lift and Play), JRuby (JRuby on Rails) and Clojure (Noir, Ring/Enlive+lots of custom frameworks) to name but a few.

With all the innovation happening the new JVM language space, I personally suspect that Java will ultimately become the "assembler of server-side programming".

Title: Why isn't Java used for modern web application development?

Body:
As a professional Java programmer, I've been trying to understand - why the hate toward Java for modern web applications?

I've noticed a trend that out of modern day web startups, a relatively small percentage of them appears to be using Java (compared to Java's overall popularity).  When I've asked a few about this, I've typically received a response like, "I hate Java with a passion."  But no one really seems to be able to give a definitive answer.

I've also heard this same web startup community refer negatively to Java developers - more or less implying that they are slow, not creative, old.

As a result, I've spent time working to pick up Ruby/Rails, basically to find out what I'm missing.  But I can't help thinking to myself, "I could do this much faster if I were using Java," primarily due to my relative experience levels.

But also because I haven't seen anything critical "missing" from Java, preventing me from building the same application.

Which brings me to my question(s):

Why is Java not being used in modern web applications?

Is it a weakness of the language?

Is it an unfair stereotype of Java because it's been around so long (it's been unfairly associated with its older technologies, and doesn't receive recognition for its "modern" capabilities)?

Is the negative stereotype of Java developers too strong? (Java is just no longer "cool")

Are applications written in other languages really faster to build, easier to maintain, and do they perform better?

Is Java only used by big companies who are too slow to adapt to a new language?


答:
It depends or complexity (sometimes templating is a must and sometimes it's an overkill) and functionality you want to have.

As an example when functionality matters - consider the point that Mustache.js (and many other templating systems) don't know anything about DOM, so the won't really let you update the template, only re-render, thus, replace it. Sometimes you don't want to keep some state (like whenever "" element is expanded or not) in your models. Replacing the whole DOM subtree with newly-rendered template will lose this state. There are templating systems (for example, Knockout.js) which allow you to bind DOM nodes to values to combat this problem, though.

Title: Should jQuery DOM manipulation be avoided in favor of JavaScript template engines?

Body:
From what I can tell, most developers will use heavy jQuery DOM manipulation tactics to deliver their updated AJAX views. Once things get out of hand, they may consider refactoring using template engines such as Mustache.js. Is this a valid assessment of a natural progression to use a template engine?

When I begin a new AJAX heavy project, is the best practice to use a template engine or is jQuery DOM manipulation good enough?

I have yet to find any negatives with using a template engine. The maintainability, efficiency and simplicity seem to be the redeeming qualities.

Please advise me on whether JavaScript template engines should be used or not by default.

Body:
It depends or complexity (sometimes templating is a must and sometimes it's an overkill) and functionality you want to have.

As an example when functionality matters - consider the point that Mustache.js (and many other templating systems) don't know anything about DOM, so the won't really let you update the template, only re-render, thus, replace it. Sometimes you don't want to keep some state (like whenever "<details>" element is expanded or not) in your models. Replacing the whole DOM subtree with newly-rendered template will lose this state. There are templating systems (for example, Knockout.js) which allow you to bind DOM nodes to values to combat this problem, though.


问:
How can you measure your own daily contributions?
I've recently finished the The Three Signs of a Miserable Job by Patrick Lencioni and one of his core ideas is that you need to have some form of measurement.

I have a pretty standard internal developer job where I work on new tools and do some support/bug fixes for past tools I have written.

For purely personal fulfillment reasons, what things would you measure on a daily basis?  (This is not a report to managers and not something to game, just something to help me mark progress).

The goal is to find things that measure not just productivity, but how good of a job you are doing (so a customer service person might record positive interactions in addition to number of calls taken).

My stab at this would be to measure two things every day: support requests opened/closed and number of checkins to source control.

I understand if this gets closed, but once again this isn't a question about management, its about personal development as a programmer/software developer.

答:
I think like most knowledge-based professions, the answer is to keep a journal.  Write down goals for every day and see if you meet those.  Target a particular practice you want to improve on and record your progress.

For instance, I've always wanted to improve my estimation skills.  So I keep a backlog, make and revise estimates on it and then use those to both gauge my ability to complete similar tasks and to see if I've improved at estimating.

I initially started with this spreadsheet from Joel:
http://www.joelonsoftware.com/articles/fog0000000245.html

Simple, and a good place to start.  (Joel has moved on since then:

http://www.joelonsoftware.com/items/2007/10/26.html)

I do something a little less sophisticated now that fits my workflow better.

So if you're looking for a particular metric to track, estimate correctness is a fun one.  The ability to estimate accurately is pretty rare so you're gaining a useful skill, and it often feels like a game since you're trying to beat your "high score" from before.


答:
I don't know if there is a useful distinction between them in the winforms world, but in asp.net (web forms) this is the distinction:

A usercontrol can have declarative markup in a XXXX.ascx file whereas logic is placed in the corresponding XXXX.ascx.cs file. Whenever you want to use the usercontrol you must declare which ascx-file you want to use.

A Custom Control can't have declarative markup, but can be used by just specifying the namespace (for example globally in web.config)

or more succinctly: a usercontrol is mucht easier to write but slightly harder to use, a custom control is (potentially) much harder to write but slightly easier to use.

All the builtin controls shipped from MS are custom controls which makes them easier to use (you don't have to specify an ascx-file to use an asp:Label for instance)

Generally: if you are going to make a control which consists of many sub-controls you would want to go with usercontrol, but if you are extending a standard control with some new logic you'd want to go with custom control


答:
It depends, what problems do you need to solve to accomplish your main objective: delivering software?

For me, knowing Labview lets me maintain and extend our real-time data collection tools. These produce a lot of raw data, so having a scripting language to parse and reduce it is extremely useful.  I use Ruby.

Batch and/or shell scripting can also come in quite handy.

Title: Languages to complement C++


问:
restful web development in scala
I ve been a php developer for the past 4 years and worked in OO PHP and almost all sorts of PHP mvc frameworks. Ive joined a new company now and here we use scala for web development. We have a product which has a frontend developed in a js mvc and a backend in scala. Actually this kind of restful architecture itself is brand new for me. In PHP we just use PHP for both frontend and backend. So i started working in scala and did some basic console app stuff. But there are no articles on how i must use scala to do restful web development. There is a framework called lift developed in scala. But we havent used that. Ours is a pure scala app without lift stuff. I found out two blogs but it has too little information on implementation.

So can any one point me in the right direction on when to use the restful architecure as against mvc architecture and absolute newbie guides to creating a web app using restful architecture in scala.

答:
You should take a look at the libraries and tools mentioned here. There are some specifically targeted at REST.

As for Lift itself, if you are going to use that, then the Lift mailing list is your best resource. Also, Manning's Lift in Action by Tim Perrett is a very good book.

Title: restful web development in scala


问:
How to structure multiple overlapping solutions / projects in .Net?
I recently started out working for a new client with an old legacy codebase in which there are multiple .net solutions, each typically hosts some projects unique to that solution but then "borrows" / "links in" (add existing project) some other projects which technically belongs to other solutions (at least if you go by the folder structure in TFS)

I have never seen a setup this intertwined, there is no clear build order, sometimes a project in solution A just reference dlls directly from the output directory of a project hosted in solution B, sometimes the project has just been included directly even if it resides FAR away in the folder structure.

It looks like everything has been optimized for developer laziness.

When I confronted them with why they didn't have a CI server they responded that it is hard to set up with the code organized like it is. (I'm setting it up now and cursing this code-organization)

The solutions are organized around deployment artifacts (stuff that needs to be deployed together are in the same solution) which I think is a wise decision, but the contents of those solutions (the projects) are all over the place.

Is there a consensus of a best practice to use when reusing common class libraries across multiple solutions / deployment artifacts,

How to structure code in the VCS

How to facilitate sharing of business logic between separate deployment artifacts

答:
I have never been a fan of including existing projects that belong to other solutions. There are too many variables where making an edit to that project for 1 solution completely breaks something in another solution. Then by fixing that problem you end up breaking the original solution. Lather, rinse, repeat.

When this kind of dependency leaks into multiple solutions, I like to separate out the dependent code into its OWN solution and create a black-box library that is then included as a reference. My thinking is that your solutions were intertwined so that debugging could be done all the way into the shared project for every solution. If the library is built and tested properly, this kind of debugging really isn't necessary. The library should be able to stand on its own merits and should be tested thoroughly so that the expectations of any consumer project would be met consistently.