答:
That sounds like an eminently sensible decision to me. MVC is a presentation pattern, therefore business logic and persistence operations have no place in the UI layer of the application.

Ideally an MVC model is just the data you are presenting to be rendered by the view. This is not at all necessarily the same as an equivalent domain entity - for instance, the model may need to be tagged with UI validation attributes, may contain values for multiple selection, or may contain data transformed for display such as dates, currency values. or language translations. Because of this, it is sensible to make the M in MVC distinct from your business entities, and map from entities to models in your controller logic. A controller action should not really need to do anything more complicated than make calls to the underlying business logic layer and marshal the data returned into models for render.

Title: Business Logic Layer in MVC Application

Body:
In my ASP MVC application I decided to add another Business Layer and made the model only to have properties.

All other functionality like save to db, get from db is done on this new Business layer. So now the controller will be calling this business layer and model for various operations. Is it a good approach to design like this?

I decided not to use model for this purpose because I would need a number of models for different actions. (for eg, one for edit and other for create)


问:
Should my colleagues review each others code from source control system?
So that's my story: one of my colleagues uses to review all the code, hosted to revision system. I'm not speaking about adequate review of changes in parts that he belongs to. He watches the code file to file, line to line. Every new file and every modified. I feel just like being spied on!

My guess is that if code was already hosted to control system, you should trust it as workable at least. My question is, maybe I'm just too paranoiac and practice of reviewing each others code is good?

P.S: We're team of only three developers, and I fear that if there will be more of us, colleague just won't have time to review all the the code we'll write.

答: Code reviews within a team (using fisheye, crucible or other tools) are extremely important and useful.  the only thing better is direct pair programming to make sure that code that gets into the system the first time is well thought out and has gone through the brain of more than one person.</p>

ContentLicense: CC BY-SA 2.5


问:
What makes C so popular in the age of OOP?
I code a lot in both C and C++, but did not expect C to be the second most popular language, slightly behind Java.

TIOBE Programming Community Index

I'm curious as to why, in this age of OOP, C is still so popular? Note that 4 out of the top 5 popular programming languages are "modern", object-oriented capable languages.

Now, I agree that you can use OOP in C to some extent, but it's sort of painful and inelegant (well at least compared to C++ I guess). So, what makes C so popular?  Is it efficiency; being low-level; the vast majority of libraries that already exist or something else?

答:
Because C has a huge user base. Yes it is a bit of a catch-22, but when I ask a question about C over on StackOverflow, I get the answer almost instantly. The same question about Python could take hours to get answered.

With respect to C++, it's IMO more complicated to learn. Furthermore, after having tried OOP for 10 years, I find it's not always useful, and often times it's easier to use procedural programming instead.

ContentLicense: CC BY-SA 3.0


问:
How to avoid code duplication for a system which has logic that may change year wise?
What would be the way to design a system which has logic that may change year wise?
There is an application which conducts online exams.

There are five questions for a particular subject. The questions may (or may not) change year wise.

As per my current design, the questions in database are stored year wise. There are some year specific code logic as well. In order to enable the application for another year, the year specific database records and code will be copied or duplicated.

How to avoid this code duplication?

答:
The basic concept is to abstract out what changes.

If you have a set of logic that varies, consider the Strategy pattern.  This involves a number of classes that all implement a single interface (or extend a single type, depending on what language you are using).   The appropriate implementation is instantiated and injected into the calling object.  This is frequently implemented using a dependency injection framework such as Spring.

For example, you might have your controlling class, something like Questionnaire, which for question 1, calls a method in the IQuestionOne interface.  This interface is implemented by different classes depending on the year: QuestionOne2013 containing the 2013 logic and QuestionOne2014 containing the 2014 logic.   You could then build a Questionaire for 2013 and have it reference the QuestionOne2013 implementation of IQuestionOne.  Likewise, the Questionnaire for 2014 would use the QuestionTwo2014 implementation.

If the logic doesn't change, you can simply reuse the same implementation.  So, perhaps question 2 (abstracted as the interface IQuestionTwo) has the same logic for both years--simply use the same implementation for either questionnaire.


问:
Is sending data to a server via a script tag an outdated paradigm?
I inherited some old javascript code for a website tracker that submits data to the server using a script url:

```<code>var src = "http://domain.zzz/log/method?value1=x&value2=x"
var e = document.createElement('script');
e.src = src;
</code>```

I guess the idea was that cross domain requests didn't haven't to be enabled perhaps. Also it was written back in 2005. I'm not sure how well XmlHttpRequests were supported at the time. Anyone could stick this on their website and send data to our server for logging and it ideally would work in most any browser with javascript.

The main limitation is all the server can do is send back javascript code and each request has to wait for a response from the server (in the form of a generic acknowledgement javascript method call) to know it was received, then it sends the next.

I can't find anyone doing this online or any metrics as to whether this faster or more secure than XmlHttpRequests. I don't know if this is just an old way of doing things or it's still the best way to send data to the server when you are mostly trying to send data one way and you need the best performance possible.

So in summary is sending data via a script tag an outdated paradigm? Should I abandon in favor of using XmlHttpRequsts?

答:
I don't think there is anything wrong with it, per se, but XmlHttpRequests does it better.

Before Ajax, javascript was extremely limited. There was no real way to query a database, so you either had to frontload all the data you might need (with the attendant performance hit), or you had to make all the same data available through an external page, with most of the same performance problems.

Sourcing an external "script" to pass a GET header to a web application allowed you to generate a page, on demand, that contained only the data you needed. Very very cool, solved a lot of problems...But at it's root it's a hack. XmlHttpRequests was released by Microsoft (as a part of OWA) to expand that functionality, which it did well enough to be picked up by everyone else, and rolled into the spec in 2006.

I suppose you could lower your overhead by using the older method, but I doubt it's any quicker, and you'll lose all of the extra functionality.


问:
Business Logic Layer in MVC Application
In my ASP MVC application I decided to add another Business Layer and made the model only to have properties.

All other functionality like save to db, get from db is done on this new Business layer. So now the controller will be calling this business layer and model for various operations. Is it a good approach to design like this?

I decided not to use model for this purpose because I would need a number of models for different actions. (for eg, one for edit and other for create)

答:
If your Model is a plain retrieve and save to the DB, you don't need a separate Model class. It will be a overhead..

In case you are manipulating over your data and forming custom representation of your class to show on the View, It makes perfect sense to go with your approach. Additionally if in future you expect your Model to be filled from different sources, the approach will be a perfect case..

It totally depends upon your application design

Title: Business Logic Layer in MVC Application


问:
Running only some of the tests after a code change
Running the build can take a long time.

Why run all the tests when a given change probably only has the potential to break some of them?

You should be able to build a dependency graph of all the code that each test could possibly run, and then avoid running tests that couldn't possibly be affected.

Is there anything that does this?

答:
Infinitest does this for Java. From their website:

Each time a change is made on the source code, Infinitest runs all the tests that might fail because of these changes.

I use it as an eclipse plugin and any time I rebuild (I have it set to build on save) the project it runs any unit tests which cover the code I have modified.


答:
Visual Studio Team System has done this via Test Impact Analysis since VS 2010.

There's walkthrough of how to set up a build environment here that includes TIA.

It works with varying degrees of success depending on the structure of the codebase. For example: I don't know for sure, but I can only imagine that statically analyzing dependencies in a project that heavily depends on runtime DI isn't very easy.

In any event, for incremental builds/checkins, it makes sense to use it while daily builds run the whole suite.

Title: Running only some of the tests after a code change

Body:
Running the build can take a long time.

Why run all the tests when a given change probably only has the potential to break some of them?

You should be able to build a dependency graph of all the code that each test could possibly run, and then avoid running tests that couldn't possibly be affected.

Is there anything that does this?


问:
What is the right level of site blocking for you as a developer?
Almost all developers who work for a large corporation find themselves on the wrong side of site blocking software. It can be both frustrating ("Just let me read that damn blog!") and helpful ("Woah! Dodged a bullet with that site").

In your opinion, what is the right level of blocking to apply to developers and why?

答:
I suppose it depends on your reason for blocking.  If you want to block people purely because you’re afraid they’re going to waste company time, then you are not keeping your developers properly occupied.

I for one would much rather get into the zone with an exciting project than spend time on silly things on the web.  Oh, this is of course excluding Friday afternoons...


问:
MVC is a GUI Architecture or a Architecture to GUI and Domain?
Fowler refers to the MVC, as a GUI architecture:

There have been many different ways to organize the code for a rich client system. Here I discuss a selection of those that I feel have been the most influential and introduce how they relate to the patterns.

If MVC is a GUI architecture, then say that the M in MVC are the business rules or domain is not wrong?

答:
He is right.

The M in MVC says that there is some kind of "data", but it says nothing how those data are structured or retrieved. It can be practically anything from in-memory store to database to webservice.

There is also the V of MVC. Which is closely tied with UI. So if you use MVC for something else than UI, the V won't make much sense and then the whole thing won't make much sense.


答:
MVC isn't a GUI pattern, it's a common pattern to decouple a model from how it is viewed and controlled. I've seen it used for game servers where varied controllers (people, ai opponents, network players) and varied views (simulation mode, over a network, right to screen) need to share a common model (your game objects).

To take any tool and typecast it to only that one role will only prevent you from using it to solve other, similar problems.

Title: MVC is a GUI Architecture or a Architecture to GUI and Domain?

Body:
Fowler refers to the MVC, as a GUI architecture:

There have been many different ways to organize the code for a rich client system. Here I discuss a selection of those that I feel have been the most influential and introduce how they relate to the patterns.

If MVC is a GUI architecture, then say that the M in MVC are the business rules or domain is not wrong?


问:
Earliest use of Comments as Semantically Meaningful Things in a Program?
In certain corners of the PHP meta-programming world, it's become fashionable to use PHPDoc comments as a mechanism for providing semantically meaningful information to a program. That is, other code will parse the doc blocks and do something significant with the information encoded in those comments.

Doctrine's annotations and code generation are an example of this.

What's the earliest (or some early) use of this technique?  I have vague memories of some early java Design by Contract implementations doing similar things, but I'm not sure of those folks were inventing the technique, or if they got it from somewhere.

Mainly asking so I can provide some historical context for PHP developers who haven't come across the technique before, and are distrustful of it because it seems a little crazy pants.

答: Depending on just how far you stretch "semantically meaningfull", it's a concept at least 40 years old.  There was a day when Algol, FORTRAN, and COBOL were the only cross-platform languages, and many FORTRAN compilers had ways to declare things that influenced their behavior, usually expressed as comments.  The practice was so wide-spread that the Dennis Ritchie introduced the #pragma directive for C, specifically to separate such things from normal comments.


问:
Is there really anything to gain with complex design?
I've been working for a consulting firm for some time, with clients of various sizes, and I've seen web applications ranging in complexity from really simple:

MVC

Service Layer

EF

DB

To really complex:

MVC

UoW

DI / IoC

Repository

Service

UI Tests

Unit Tests

Integration Tests

But on both ends of the spectrum, the quality requirements are about the same.  In simple projects, new devs / consultants can hop on, make changes, and contribute immediately, without having to wade through 6 layers of abstraction to understand what's going on, or risking misunderstanding some complex abstraction and costing down the line.

In all cases, there was never a need to actually make code swappable or reusable - and the tests were never actually maintained past the first iteration because requirements changed, it was too time-consuming, deadlines, business pressure, etc etc.

So if - in the end -

testing and interfaces aren't used

rapid development (read: cost-savings) is a priority

the project's requirements will be changing a lot while in development

...would it be wrong to recommend a super-simple architecture, even to solve a complex problem, for an enterprise client?  Is it complexity that defines enterprise solutions, or is it the reliability, # concurrent users, ease-of-maintenance, or all of the above?

I know this is a very vague question, and any answer wouldn't apply to all cases, but I'm interested in hearing from devs / consultants that have been in the business for a while and that have worked with these varying degrees of complexity, to hear if the cool-but-expensive abstractions are worth the overall cost, at least while the project is in development.

答:
...would it be wrong to recommend a super-simple architecture, even to solve a complex problem, for an enterprise client?

It depends on the client. Many will be fine with a more straightforward approach. Some will think that you're incompetent because that simple approach will not solve their problems - the whole "that thing must be super cheap for a reason..." thing that causes some stuff to be way more expensive than it costs to make.

testing and interfaces aren't used

I would argue that there is no way in hell that you can cost effectively make non-trivial software without either of these. As a company, if you tried to sell me something without them, I would fear that you will saddle me with a completely inflexible, unmaintainable pile of steaming dog poo. (edit: to be clear I'm talking about interfaces here, not interfaces. Procedural and functional programs are not all piles of crap, even though they lack Java-style interfaces.)

if the cool-but-expensive abstractions are worth the overall cost

As program designers, we need to make educated guesses about where things will change, and draw lines there so that things that change can do so quickly, easily, and correctly. Good abstractions will save you money over time because inevitable change becomes cheap.

But make no mistake, the term "architecture astronaut" exists for a reason. You are not always building the space shuttle. Adding bad abstractions that either exist in the middle of things that need to change, or exist to support change that does not exist... they can cost you.

But in my experience, I've heard people complain about over abstracted code, but I've only seen projects fail due to under-abstracted code.


答:
MVC was originally designed to solve the problems in architecting GUIs. It decouples the process of extracting data from the model in order to present it from the process of presenting it. Basically it is an application of the Single Responsibility Principle to GUIs.

This has a number of large advantages: it takes away the need to have logic code from the presentation layer and it makes the controllers testable, thereby increasing quality and reliability. Early web GUIs, like classic ASP, had logic code embedded in HTML pages which was hard to maintain and just made you feel dirty.

The Model is basically a black box representing the application and its data, and will typically be an n-tiered application. The View is to display the data from the application and typically pass commands and data back to update the application. The Controller mediates between the Model and the View, presenting data to the View and commands to the Model.

So the Model is, as you say, the business rules or domain (or it could just be a database), but the entire architecture - Views to present data and Controllers to pass data and commands back and forth between the Model and the Views - is very much a GUI framework.


问:
Best Practices for serializing/persisting String Object Dictionary entities
I'm noticing a trend towards using a dictionary of string to object (or sometimes string to string), instead of strongly typed objects. For example, the new Katana project  makes heavy use of IDictionary<string,object>. This approach avoids the need to continually update your entity classes/DTOs and the database tables that persist them with new properties. It also avoids the need to create new derived entity types to support new types of entity, since the Dictionary is flexible enough to store any arbitrary properties.

Here's a contrived example:

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

class NetworkShare : StorageDevice {
    public string Path { get; set; }
    public string LoginName { get; set; }
    public string Password { get; set; }
}

class CloudStorage : StorageDevice {
    public string ServerUri { get; set }
    public string ContainerName { get; set; }
    public int PortNumber { get; set; }
    public Guid ApiKey { get; set; }
}
</code>```

versus:

```<code>class StorageDevice {
    public IDictionary<string, object> Properties { get; set; }
}
</code>```

Basically I'm on the lookout for any talks, books or articles on this approach, so I can pick up on any best practices / difficulties to avoid. Here's my main questions:

Does this approach have a name? (only thing I've heard used so far is "self-describing objects")

What are the best practices for persisting these dictionaries into a relational database? Especially the challenges of deserializing them successfully with strongly typed languages like C#.

Does it change anything if some of the objects in the dictionary are themselves lists of strongly typed entities?

Should a second dictionary be used if you want to temporarily store objects that are not to be persisted/serialized across a network, or should you use some kind of namespacing on the keys to indicate this?

答: If you're taking this approach, why stick with a traditional relational database? NoSQL databases like MongoDB let you apply "fuzzy schemas" to data which should allow different versions of the software to pick out documents that it expects and leave out the others (or fill it with nulls)</p>


答:
Welcome to consulting.

A great place to make a ton of money quickly delivering features to clients.

If you seek to work creating maintainable, adaptable, beautiful software that works well both now and in the future I recommend you work in a specific industry such as healthcare or government where you can carve out a
better niche for quality work.

Title: Is there really anything to gain with complex design?

Body:
I've been working for a consulting firm for some time, with clients of various sizes, and I've seen web applications ranging in complexity from really simple:

MVC

Service Layer

EF

DB

To really complex:

MVC

UoW

DI / IoC

Repository

Service

UI Tests

Unit Tests

Integration Tests

But on both ends of the spectrum, the quality requirements are about the same.  In simple projects, new devs / consultants can hop on, make changes, and contribute immediately, without having to wade through 6 layers of abstraction to understand what's going on, or risking misunderstanding some complex abstraction and costing down the line.

In all cases, there was never a need to actually make code swappable or reusable - and the tests were never actually maintained past the first iteration because requirements changed, it was too time-consuming, deadlines, business pressure, etc etc.

So if - in the end -

testing and interfaces aren't used

rapid development (read: cost-savings) is a priority

the project's requirements will be changing a lot while in development

...would it be wrong to recommend a super-simple architecture, even to solve a complex problem, for an enterprise client?  Is it complexity that defines enterprise solutions, or is it the reliability, # concurrent users, ease-of-maintenance, or all of the above?

I know this is a very vague question, and any answer wouldn't apply to all cases, but I'm interested in hearing from devs / consultants that have been in the business for a while and that have worked with these varying degrees of complexity, to hear if the cool-but-expensive abstractions are worth the overall cost, at least while the project is in development.


答:
Actually, I think the techniques for avoiding code duplication are the same as in any other system. For example, think about a function

```<code>CalcTax2013(){...};
</code>```

and let's assume you have to duplicate that function for the next year (perhaps with some changes)

```<code>CalcTax2014(){...};
</code>```

then you should immediately refactor all common parts out to a function used from both of them. Of course, you should have written some automatic tests before that to make sure refactoring does not break anything.

There could be of course a different situation: when CalcTax2013 does not have to be changed later any more, lets say for example from 01/01/2014. If that's the case, there is no need for any maintenance on that function, which makes the refactoring pointless.

If this does not apply to your question, please give a more elaborate example.

Title: How to avoid code duplication for a system which has logic that may change year wise?

Body:
What would be the way to design a system which has logic that may change year wise?
There is an application which conducts online exams.

There are five questions for a particular subject. The questions may (or may not) change year wise.

As per my current design, the questions in database are stored year wise. There are some year specific code logic as well. In order to enable the application for another year, the year specific database records and code will be copied or duplicated.

How to avoid this code duplication?

Body:
Actually, I think the techniques for avoiding code duplication are the same as in any other system. For example, think about a function

CalcTax2013(){...};

and let's assume you have to duplicate that function for the next year (perhaps with some changes)

CalcTax2014(){...};

then you should immediately refactor all common parts out to a function used from both of them. Of course, you should have written some automatic tests before that to make sure refactoring does not break anything.

There could be of course a different situation: when CalcTax2013 does not have to be changed later any more, lets say for example from 01/01/2014. If that's the case, there is no need for any maintenance on that function, which makes the refactoring pointless.

If this does not apply to your question, please give a more elaborate example.


答:
I do not fully agree with your statement that abstraction automatically increases complexity.
Abstraction is the primary reason why one nowadays doesn't have to resolve to machine code.

The problem sometimes with abstractions is that they tend to focus on the inner workings rather than hiding the complexity to its end users. Abstractions should isolate logic and promote reusability. Furthermore, I think testing is a great way to challenge the architectural design. Mainly because it forces you to look at your code from a user point of view.

The problems you mentioned about lack of time, is the primary cause for bad design.
Good design usually doesn't come instantly, but through iterations and refinement.
How we usually extract requirements from our customer is via user stories. This way the customer can think about what and how he wants to use the system. Furthermore, if the architect is aware of the intentions of the system then appropriate design decisions or abstraction techniques can be chosen to add the flexibility to the system. Not because they are cool or nice.


答:
The first time I saw it was some early Pascal compilers that used special comments to control compiler code generation. This was documented in the Pascal User Manual and Report at least as far back as 1974:

B. Compiler options

The compiler may be instructed to generate code according to certain options: in particular, it may be requested to insert or omit run-time test instructions. Compiler directives are written as comments and are designated as such by a $-character as the first character of the comment:

```<code>{$<option sequence><any comment>}
</code>```

Example:

```<code>{$T+,P+}
</code>```

[I'll omit the next ~1.5 pages of flags and options it supported.]

Citation: Pascal User Manual and Report, §14.B, pages 100, 101, copyright Springer-Verlag, 1974.

Title: Earliest use of Comments as Semantically Meaningful Things in a Program?

Body:
In certain corners of the PHP meta-programming world, it's become fashionable to use PHPDoc comments as a mechanism for providing semantically meaningful information to a program. That is, other code will parse the doc blocks and do something significant with the information encoded in those comments.

Doctrine's annotations and code generation are an example of this.

What's the earliest (or some early) use of this technique?  I have vague memories of some early java Design by Contract implementations doing similar things, but I'm not sure of those folks were inventing the technique, or if they got it from somewhere.

Mainly asking so I can provide some historical context for PHP developers who haven't come across the technique before, and are distrustful of it because it seems a little crazy pants.

Body:
The first time I saw it was some early Pascal compilers that used special comments to control compiler code generation. This was documented in the Pascal User Manual and Report at least as far back as 1974:

B. Compiler options

The compiler may be instructed to generate code according to certain options: in particular, it may be requested to insert or omit run-time test instructions. Compiler directives are written as comments and are designated as such by a $-character as the first character of the comment:

{$<option sequence><any comment>}

Example:

{$T+,P+}

[I'll omit the next ~1.5 pages of flags and options it supported.]

Citation: Pascal User Manual and Report, §14.B, pages 100, 101, copyright Springer-Verlag, 1974.


问:
Making Class Diagram for MVC Pattern Project
I have a question about making a class diagram for an MVC based college senior project.

If we have 2 actors of users in my system, lets say Undergrad and Graduate students are the children of abstract class called User. (Generalisation)

Each actor has his own features.

My question, in such case, do we need to have these two actors in separate classes which inherits from the abstract class User? even though, I'm going to implement them as roles using one Model called User Model ?

I think you can see my confusion here. I code using MVC pattern, but I've never made a class diagram for this pattern.
Thank you in advance!

答:
A class diagram should work as a graphical representation of the code you are intending to write. You can leave out implementation details that are not important for understanding the design of the code, but the elements that you do show in a class diagram should also be directly represented in the code.

This means that if your ' User Model' consists of one class that fills the roles of both the Undergrad and Graduate users, then it should also be depicted as one class in a class diagram.

But given your description, I would expect the model to contain at least two classes (Undergrad and Graduate) with a common interface or abstract base class.

Note that the fact that there are only three components to MVC does not mean that you can only show three classes in a class diagram. In a typical class diagram of an MVC application, the use of MVC may not even be obvious to the untrained eye. For example, it can be hidden in the naming of the classes and how they are grouped in the drawing. If you want to make the MVC pattern obvious in your class diagram, I would recommend using colours to indicate the classes that together form the Model, View or Controller parts of the MVC pattern.


问:
Can Dependency Injection used as an alternative to Reflection for creating instances
There is a piece of .net C# code which use Reflection to create an instance using Activator.CreateInstance(). This is an old piece of code and runs on the top of Enterprise Library. Is it a better idea to replace this with Dependency Injection to create objects? Is there any Pro's and Con's for either approach?

答:
As a general approach I think that you can replace a code that use Activator.CreateInstance with a Factory. The factory can accept a parameter that you can use to select the correct type to create and then resolve that type using the IoC container.
For example Castle Windsor as a feature called Typed Factory that can do all the work for your.

For example if you have the following code:

```<code>var component = (MyService)Activator.CreateInstnace(myImplementationType, [params]);
</code>```

You can replace with something like

```<code>var component = myFactory.Create(params);
</code>```

or

```<code>var component = myFactory.Create<MyService>([params]);
</code>```

Another approach that can be used is to invert the dependency (Inversion of Control) and let the main component decides what components to inject. This is the recommended approach in most situations. From the main you can register the correct implementation and let the Dependency Injection do it's work.

Body:
As a general approach I think that you can replace a code that use Activator.CreateInstance with a Factory. The factory can accept a parameter that you can use to select the correct type to create and then resolve that type using the IoC container.
For example Castle Windsor as a feature called Typed Factory that can do all the work for your.

For example if you have the following code:

var component = (MyService)Activator.CreateInstnace(myImplementationType, [params]);

You can replace with something like

var component = myFactory.Create(params);

or

var component = myFactory.Create<MyService>([params]);

Another approach that can be used is to invert the dependency (Inversion of Control) and let the main component decides what components to inject. This is the recommended approach in most situations. From the main you can register the correct implementation and let the Dependency Injection do it's work.


答:
It probably depends on a number of questions:

How many instances of the object do you create at runtime? If there is a small finite number I would tend towards DI, if there are a large number at different times I would tend towards reflection

What arguments does the objects constructor take? If they vary at runtime then reflection may be better but if they are always known up front then you may be better using DI.

What is wrong with the current implementation? Does it not meet requirements, is it hard to support, or are you just refactoring? What would you like to achieve and would DI help in those goals?

It's also worth pointing out that DI frameworks will just use reflection under the hood anyway to create objects at runtime.

Title: Can Dependency Injection used as an alternative to Reflection for creating instances

Body: There is a piece of .net C# code which use Reflection to create an instance using Activator.CreateInstance(). This is an old piece of code and runs on the top of Enterprise Library. Is it a better idea to replace this with Dependency Injection to create objects? Is there any Pro's and Con's for either approach?


答:
You should probably make this decision based on your actual data model. If it is relatively static then I think you would be better taking the hit of changing your schema and updating your classes and DTO's. It may sound like a lot of work but if you are C# and Sql land you will probably end up with a better solution in the long run.

You may also want to consider a hybrid approach where most of your properties are strongly typed but also have a dictionary for more dynamic or sparse properties.

Ideally to get a nice solution for your situation you'd either switch to a dynamic language or schemaless database or both.

Title: Best Practices for serializing/persisting String Object Dictionary entities

Body:
I'm noticing a trend towards using a dictionary of string to object (or sometimes string to string), instead of strongly typed objects. For example, the new Katana project  makes heavy use of IDictionary<string,object>. This approach avoids the need to continually update your entity classes/DTOs and the database tables that persist them with new properties. It also avoids the need to create new derived entity types to support new types of entity, since the Dictionary is flexible enough to store any arbitrary properties.

Here's a contrived example:

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

class NetworkShare : StorageDevice {
    public string Path { get; set; }
    public string LoginName { get; set; }
    public string Password { get; set; }
}

class CloudStorage : StorageDevice {
    public string ServerUri { get; set }
    public string ContainerName { get; set; }
    public int PortNumber { get; set; }
    public Guid ApiKey { get; set; }
}
</code>```

versus:

```<code>class StorageDevice {
    public IDictionary<string, object> Properties { get; set; }
}
</code>```

Basically I'm on the lookout for any talks, books or articles on this approach, so I can pick up on any best practices / difficulties to avoid. Here's my main questions:

Does this approach have a name? (only thing I've heard used so far is "self-describing objects")

What are the best practices for persisting these dictionaries into a relational database? Especially the challenges of deserializing them successfully with strongly typed languages like C#.

Does it change anything if some of the objects in the dictionary are themselves lists of strongly typed entities?

Should a second dictionary be used if you want to temporarily store objects that are not to be persisted/serialized across a network, or should you use some kind of namespacing on the keys to indicate this?


答:
I watch our version control system in a similar way. Our codebase is too large to watch every line, but I try to get a high level feel for most changes. I also watch for checkins that are most likely to have side effects and review those line by line. For the minimal time I spend doing this, the payoff is huge. (Also note: I am not the only developer on our team with this habit.)

This kind of review tends to catch bugs or invoke discussion on a weekly basis. That saves time when doing QA. The discussions range from best practices to algorithm design and more. The key on this front is that everyone views it as constructive.

Personally, it also gives me a greater understanding of what is going on in other parts of the codebase that I don't touch regularly. When others need help, I am able to jump in more quickly. Also, when new ideas appear I can take advantage of them sooner.

Title: Should my colleagues review each others code from source control system?

Body:
So that's my story: one of my colleagues uses to review all the code, hosted to revision system. I'm not speaking about adequate review of changes in parts that he belongs to. He watches the code file to file, line to line. Every new file and every modified. I feel just like being spied on!

My guess is that if code was already hosted to control system, you should trust it as workable at least. My question is, maybe I'm just too paranoiac and practice of reviewing each others code is good?

P.S: We're team of only three developers, and I fear that if there will be more of us, colleague just won't have time to review all the the code we'll write.


问:
Is there a difference between iterable and enumerable?
Many languages seem to have structures that are very similar called iterable or enumerable. These are structures that can be iterated or enumerated over, which seem to me extremely similar things.  Are these words synonymous or is there a subtle semantic difference between iterable and enumerable which justifies the choice of term?</p>

答:
IMHO this depends on the context, sometimes they are synonymous, sometimes they are not. For example, in C# you have a data type "IEnumerable", which classifies iterators, but you have also the "enum" declaration which is for symbolic constants, not specificially for iterations. In other programming languages (or other contexts) the situation may be similar or not.

If you mean the two words just as english verbs and not specifically as programming language keywords, then

iterating means to "loop over all elements of a set, one by one"

enumerating means to "give each element of a set an ordinal number, one by one"

And since iterating is needed for enumerating, and enumerating implies some kind of iteration, those two process descriptions can typically be interchanged.


答:
What you gain from a solid design, is a more reliable change cycle over the long term.  The cost is initially higher because you need properly trained programmers and a proper design, however the intent is to keep the cost of later changes from skyrocketing out of control.

Without a solid architecture changes are only cheaper at the beginning. As the project evolves, changes become more and more costly.  This, combined with a desire for cheaper labor and faster iteration, could kill the project as changes will eventually cost more than the company is willing to pay and take more time than the company can wait for.  Later changes that could have taken an average team and average time will instead require a superhuman team and a lengthy time to sift through the years of code and refactor enough to safely make changes.

If the client understands and wants to make this sacrifice, then make whatever changes are needed by whatever method is fastest.  But it is unwise (and possibly dishonest) to make those tradeoffs for them, as this process will affect their business decisions.

Part of the job is to understand all those abstractions you listed, not just to ask "Are these necessary?" but to understand when and why they are necessary, and to figure out how to apply those patterns as part of working with the software.

Another part of the job is to understand that clients often judge work by what they can see (the ui, the functionality), and they should be educated about what they can't see (the state of the codebase).

See this talk regarding the cost of poor design over time

See this talk regarding stable productivity

See this SO answer regarding the value of unit tests


答:
As others have said, the precise semantics depend on the programming language that uses the terms, so I'll give a purely linguistic appraisal.

"Iterable" is a rather new-coined word, obviously referring to "iterating" and the "iterators" that many languages have built in. Therefore, such types almost certainly support an iterator, but not necessarily anything else, and not necessarily anything beyond the most basic iterator functionality: processing every item once. Reversing, deleting, measuring distances etc. may or may not be supported.

"Enumerable" refers to enumerating things, which can mean the same as iterating, but only if the language doesn't already use "iterable" for that purpose. If a language has both, "enumerable" almost certainly means something else, probably something more powerful. Most likely, it will support the notion of connecting each element with a unique numeric index, and probably it will allow random access (e.g. retrieving the third element before the first and second ones).

That's about all the meaning you can reasonably infer from just the words. In any concrete situation, refer to the standard library API docs.

Title: Is there a difference between iterable and enumerable?

Body: Many languages seem to have structures that are very similar called iterable or enumerable. These are structures that can be iterated or enumerated over, which seem to me extremely similar things.  Are these words synonymous or is there a subtle semantic difference between iterable and enumerable which justifies the choice of term?</p>


问:
Updating password hashing without forcing a new password for existing users
You maintain an existing application with an established user base. Over time it is decided that the current password hashing technique is outdated and needs to be upgraded. Furthermore, for UX reasons, you don't want existing users to be forced to update their password. The whole password hashing update needs to happen behind the screen.

Assume a 'simplistic' database model for users that contains:

ID

Email

Password

How does one go around to solving such a requirement?

My current thoughts are:

create a new hashing method in the appropriate class

update the user table in the database to hold an additional password
field

Once a user successfully logs in using the outdated password hash, fill the second password field with the updated hash

This leaves me with the problem that I cannot reasonable differentiate between users who have and those who have not updated their password hash and thus will be forced to check both. This seems horribly flawed.

Furthermore this basically means that the old hashing technique could be forced to stay indefinitely until every single user has updated their password. Only at that moment could I start removing the old hashing check and remove the superfluous database field.

I'm mainly looking for some design tips here, since my current 'solution' is dirty, incomplete and what not, but if actual code is required to describe a possible solution, feel free to use any language.

答:
I would suggest adding a new field, "hash_method", with perhaps a 1 to signify the old method and a 2 to signify the new method.

Reasonably speaking, if you care about this sort of thing and your application is relatively long-lived (which it apparently already is), this is probably going to happen again as cryptography and information security is such an evolving, rather unpredictable field. There was a time when a simple run through MD5 was standard, if hashing was used at all! Then one might think they should use SHA1, and now there's salting, global salt + individual random salt, SHA3, different methods of crypto-ready random number generation...this isn't going to just 'stop', so you might as well fix this in an extensible, repeatable way.

So, lets say now you have something like (in pseudo-javascript for simplicity, I hope):

```<code>var user = getUserByID(id);
var tryPassword = hashPassword(getInputPassword());

if (user.getPasswordHash() == tryPassword)
{
    // Authenticated!
}

function hashPassword(clearPassword)
{
    // TODO: Learn what "hash" means
    return clearPassword + "H@$I-I";
}
</code>```

Now realizing there is a better method, you just need to give a minor refactoring:

```<code>var user = getUserByID(id);
var tryPassword = hashPassword(getInputPassword(), user.getHashingMethod());

if (user.getPasswordHash() == tryPassword)
{
    // Authenticated!
}

function hashPassword(clearPassword, hashMethod)
{
    // Note: Hash doesn't mean what we thought it did. Oops...

    var hash;
    if (hashMethod == 1)
    {
        hash = clearPassword + "H@$I-I";
    }
    else if (hashMethod == 2)
    {
        // Totally gonna get it right this time.
        hash = SuperMethodTheNSASaidWasAwesome(clearPassword);
    }
    return hash;
}
</code>```

No secret agents or programmers were harmed in the production of this answer.

Body:
I would suggest adding a new field, "hash_method", with perhaps a 1 to signify the old method and a 2 to signify the new method.

Reasonably speaking, if you care about this sort of thing and your application is relatively long-lived (which it apparently already is), this is probably going to happen again as cryptography and information security is such an evolving, rather unpredictable field. There was a time when a simple run through MD5 was standard, if hashing was used at all! Then one might think they should use SHA1, and now there's salting, global salt + individual random salt, SHA3, different methods of crypto-ready random number generation...this isn't going to just 'stop', so you might as well fix this in an extensible, repeatable way.

So, lets say now you have something like (in pseudo-javascript for simplicity, I hope):

var user = getUserByID(id);
var tryPassword = hashPassword(getInputPassword());

if (user.getPasswordHash() == tryPassword)
{
    // Authenticated!
}

function hashPassword(clearPassword)
{
    // TODO: Learn what "hash" means
    return clearPassword + "H@$I-I";
}

Now realizing there is a better method, you just need to give a minor refactoring:

var user = getUserByID(id);
var tryPassword = hashPassword(getInputPassword(), user.getHashingMethod());

if (user.getPasswordHash() == tryPassword)
{
    // Authenticated!
}

function hashPassword(clearPassword, hashMethod)
{
    // Note: Hash doesn't mean what we thought it did. Oops...

    var hash;
    if (hashMethod == 1)
    {
        hash = clearPassword + "H@$I-I";
    }
    else if (hashMethod == 2)
    {
        // Totally gonna get it right this time.
        hash = SuperMethodTheNSASaidWasAwesome(clearPassword);
    }
    return hash;
}

No secret agents or programmers were harmed in the production of this answer.


问:
Why do large IT projects tend to fail or have big cost/schedule overruns?
I always read about large scale transformation or integration project that are total or almost total disaster. Even if they somehow manage to succeed  the cost and schedule blow out is enormous. What is the real reason behind large projects being more prone to failure. Can agile be used in these sort of projects or traditional approach is still the best.

One example from Australia is the Queensland Payroll project where they changed test success criteria to deliver the project.

See some more failed projects in this SO question (on Wayback Machine)

Have you got any personal experience to share?

答:
Perception of Reality

Here is the best description of this problem I have ever found. Tree Swing From businessballs.com

I was introduced to the concept of "Perception of Reality" early on im my programming carreer. For this I  am truely grateful. I believe that this is the biggest reason that any project fails, not just IT projects.


问:
When do I need to use a framework?
I am new to web programming and at this time I am learning about PHP. I would like to know when do I need to use a PHP framework such as CakePHP? What are things that this and other similar PHP frameworks offer for me?  And is it really important to use a framework to be a professional?

And can I create my own framework to provide the features I like into it?

答:
When you're at ease with PHP, you can start using a framework. And you should always use them :

It is much, much faster than
re-coding everything

It makes modifications easier,
like changing databases or changing
views

Working with other people will
be easier too, as they are often
used to the MVC pattern frameworks
use

You can create your own framework, but I definitely wouldn't recommand it. It's complicated, there are already a lot of good frameworks out there, and it's not likely you will find a missing feature. Beside, they often provide ways to add your own features to them, without having to make a whole new one.

Title: When do I need to use a framework?


问:
Motivation for programming in a specific language
I'm 21 and didn't go to University and hence completely self-taught from tutorials, screencasts, books etc, but when it came to the decision of what languages to specifically learn, I thought, what's going to the most beneficial to learn, ie. for money, exposure, etc...  So I did the Sun Certified Java Programmer course, but have never used it since, I learned Objective C to make iPhone apps, I have used it lots, I used PHP for web stuff, I've used it lots.

So my question is, if you chose to learn a specific language, was it for money or for a certain job or because your employer needed you to get up to speed on a language for a specific project? I cant really think of any other motivations to be a programmer? Is that shallow??

答:
Hum... I learned some of them for school, some because my employer asked me to, and some because a needed them for personnal projects.

There are two exceptions though ! I learned Go and Javascript (for Ajax) because it seemed "hype". So there, another reason.


问:
Is Microsoft's Entity Framework a proprietary variant of NHibernate?
I have no knowledge of Entity Framework and NHibernate but definitely want to learn. I want to know how to start. Whether to first read documentation of NHibernate or the default Visual Studio Entity Framework?

Is Microsoft's Entity Framework a variant of NHibernate?

答:
This is personal opinion, and I must tell you I'm a huge fan of nHibernate.

I'm interested in all Microsoft's initiatives to standardize things. This include in ORM.

When they released the first version of Entity Framework, they were critized enough to call what happened The ADO.NET Entity Framework Saga. Read that blog post and all the link it points to.

Soon after that, the team leader of the project agreed that it got it wrong (I can't find his original blog post, maybe it has been removed).

Today EF framework is very close to nHibernate and I will consider it again in the future because:

Just like Unit Testing, MVC, Ajax, ... EF will eventually become the standard.

EF is commercially supported

nHibernate is powerful, but has only a few contributors.

While I'm too familiar with nHibernate to switch today, I would recommend you to go for Entity Framework without any hesitation.


答:
I've learned a bunch of languages (C, C++, Perl, Bash, SQL, VB, VBScript, JavaScript, Java, C#, Ruby, Python, a little bit of Lisp, ObjectiveC, a tiny bit of COBOL, a bit of Scala, a bit of Haskell, etc) -- most of them I learned on my own time, and not because of anything having to do with my career.

I just like to learn new languages.  I like to see how things are done in other languages.  I think it makes me a better programmer/designer in the languages I get paid to know; but my primary motivation is curiosity.  Usually, it is because I wanted to learn how to do something for myself and doing that thing required knowledge of a certain language (iPhone App development, for example).

Title: Motivation for programming in a specific language

Body:
I'm 21 and didn't go to University and hence completely self-taught from tutorials, screencasts, books etc, but when it came to the decision of what languages to specifically learn, I thought, what's going to the most beneficial to learn, ie. for money, exposure, etc...  So I did the Sun Certified Java Programmer course, but have never used it since, I learned Objective C to make iPhone apps, I have used it lots, I used PHP for web stuff, I've used it lots.

So my question is, if you chose to learn a specific language, was it for money or for a certain job or because your employer needed you to get up to speed on a language for a specific project? I cant really think of any other motivations to be a programmer? Is that shallow??


答:
I think most programmers started because they like to solve problems. Of course you won't spend 8 hours a day for free, but if you want big bucks, you'd be better off becoming a lawyer or something.

As for the language selection; everyone needs a job, and if all you have to offer is a knowledge of COBOL, then you already know in what kind of environment you will end up.

I'd say you'd have to balance pay/language demand with personal interest, if you want to keep programming for a while.


答:
I blame the bidding process.  It rewards the group that can make the deal look cheapest/quickest on paper.

The people putting together bids don't want to waste their time if they have no chance of winning, so their normal estimations get put on hold.  I know people who have specified normal switches instead of POE switches to save $80.  But the project needed POE because it had IP cameras.  That $80 needs to be spent, but now it is outside of the spec.

I have a firm belief that a 2 month $2,000,000 project will still take 2 months $2,000,000 no matter how many bids you get.  If you think doing it right is expensive, wait and see how expensive it is to do it wrong.

Title: Why do large IT projects tend to fail or have big cost/schedule overruns?

Body:
I always read about large scale transformation or integration project that are total or almost total disaster. Even if they somehow manage to succeed  the cost and schedule blow out is enormous. What is the real reason behind large projects being more prone to failure. Can agile be used in these sort of projects or traditional approach is still the best.

One example from Australia is the Queensland Payroll project where they changed test success criteria to deliver the project.

See some more failed projects in this SO question (on Wayback Machine)

Have you got any personal experience to share?


答:
I learned C# because I was familiar with the syntax (having learned C++/Java in school), the .NET framework has always offered a lot in the way of making certain annoying operations easier and there were (and are) lots of jobs for it.

The improvements to it have almost entirely been good, so I've stuck with it as my professional language of choice.


答:
Common from a person who spent years hacking out my own ways to talk to a database and talk to online API's and am only now starting to use frameworks, use them when you at least have an understanding of what their doing, if its possible.

Don't immediately jump for RedBean on your first time working with a database, work with the DB manually first. This way you have a thorough understanding of what your actually fetching and doing to the DB, which can really help with scalability. You also can then make your own solution when the framework your using doesn't do something you need to do.

Once you understand whats going on though, use a framework! It makes things so much easier. The crazyness with storing a query then looping over the results with mysql_fetch_assoc is all gone, reduced to a single call: $book = R::load( "book", $id ). You will be way more productive and can fix future bugs or add future features much easier.

Title: When do I need to use a framework?

Body:
I am new to web programming and at this time I am learning about PHP. I would like to know when do I need to use a PHP framework such as CakePHP? What are things that this and other similar PHP frameworks offer for me?  And is it really important to use a framework to be a professional?

And can I create my own framework to provide the features I like into it?


问:
Continuous Build server (cc.net, hudson, bamboo, etc...) remote build experience?
We currently use once cc.net server for our build process, which builds both .net (using msbuild & nant) and java (using maven and ant).

CC.net monitors source control, and triggers a remote build running on a separate server.  CC.net then collates the results.

When we run the remote build, it typically:

runs nunit or junit or similar using mocked data

optionally runs a DB script to create a fresh database instance or restore a database from a known position.

runs selenium or similar to test UI

runs emma or ncover for code coverage

builds the system for various deployment environments (test, acceptance, production)

We may have several builds running at a time, some .net and some java (from different project teams).

It's quite time consuming to get the remote builds working when we set up a new project and we feel that there must be something more suited to remote builds than cc.net.

Does anyone have any experience with remote builds with continuous integration systems?

I don't really want feature lists of CI servers, I'd more appreciate hearing about how you've used them in a multi language, multi server environment.

答:
We were facing this question some time ago and decided to go with TeamCity. We only looked at Hudson, CC and TeamCity. The choise was easy to make - TeamCity ended up being our build server. Please note that I am not a pro in this and it was my first experience with build servers at that time.

Hudson - I had no idea what to do and where to read about it. And even though I could understand something there it was not an option - too much work. I decided to take a look at CC.

Cruise control - same as Hudson, yet in a slightly different way. Absolutely nothing can be understood there without a manual and a ton of help from google. I just went on to take a look at TC.

TeamCity - TeamCity felt like heaven after the first two. It is the most usable out of those three. Install, go to admin panel, configure a project (show where the SVN is, point to build files, specify coverage/unit tests etc.) and start enjoying. And even though I cannot say that I did not google anything, still 95% of the setup process was very easy and clear. I highly recommend this tool. Go and take a look at it. It will save you a lot of nerves and time :)

I should also note that TC is not free. Though they do have a free edition that can be used in commercial projects with some limitations (max build configs 20) - take a look in their pricing page.

PS I sound like I work for TC, but I really don't :)


答:
We use CC.NET 1.4.

We are trying to upgrade to 1.6... what a nightmare.

Its powerful... but ONLY if you use it right and understand how everything fits together. Which is a lot to ask from the whole team. We have 'buildmasters' who have access to the server and can change the configs. Even so, there is a lot of Googling with regard to ccnet and the whole business has become a huge mess.

I personally want to move to TeamCity.

I recommend you steer clear of ccnet.

Title: Continuous Build server (cc.net, hudson, bamboo, etc...) remote build experience?

Body:
We currently use once cc.net server for our build process, which builds both .net (using msbuild & nant) and java (using maven and ant).

CC.net monitors source control, and triggers a remote build running on a separate server.  CC.net then collates the results.

When we run the remote build, it typically:

runs nunit or junit or similar using mocked data

optionally runs a DB script to create a fresh database instance or restore a database from a known position.

runs selenium or similar to test UI

runs emma or ncover for code coverage

builds the system for various deployment environments (test, acceptance, production)

We may have several builds running at a time, some .net and some java (from different project teams).

It's quite time consuming to get the remote builds working when we set up a new project and we feel that there must be something more suited to remote builds than cc.net.

Does anyone have any experience with remote builds with continuous integration systems?

I don't really want feature lists of CI servers, I'd more appreciate hearing about how you've used them in a multi language, multi server environment.


问:
As a software engineer, who should I be following on Twitter?
Who in the software engineering and software development fields uses Twitter to tweet about relevant happenings in the field?</p>

答: Scott Guthrie - @scottgu</p>

Body: Scott Guthrie - @scottgu


答:
People tend to think that software development is a predictive process, trying to measure and estimate things one year ahead. This is not possible! Building software is not bolt manufacture.

Following the same "trend", they try to do a huge analisys (again one year ahead) thinking that they'll cover all the possibilities, and later, turning programmer into mere typists. How come one think that this could work? This kind of behavior just leads to bad estimates and lots of bureaucracy.


问:
Writing the minimum code to pass a unit test - without cheating!
When doing TDD and writing a unit test, how does one resist the urge to "cheat" when writing the first iteration of "implementation" code that you're testing?

For example:

Let's I need to calculate the Factorial of a number.  I start with a unit test (using MSTest) something like:

```<code>[TestClass]
public class CalculateFactorialTests
{
    [TestMethod]
    public void CalculateFactorial_5_input_returns_120()
    {
        // Arrange
        var myMath = new MyMath();
        // Act
        long output = myMath.CalculateFactorial(5);
        // Assert
        Assert.AreEqual(120, output);
    }
}
</code>```

I run this code, and it fails since the CalculateFactorial method doesn't even exist.  So, I now write the first iteration of the code to implement the method under test, writing the minimum code required to pass the test.

The thing is, I'm continually tempted to write the following:

```<code>public class MyMath
{
    public long CalculateFactorial(long input)
    {
        return 120;
    }
}
</code>```

This is, technically, correct in that it really is the minimum code required to make that specific test pass (go green), although it's clearly a "cheat" since it really doesn't even attempt to perform the function of calculating a factorial.  Of course, now the refactoring part becomes an exercise in "writing the correct functionality" rather than a true refactoring of the implementation.  Obviously, adding additional tests with different parameters will fail and force a refactoring, but you have to start with that one test.

So, my question is, how do you get that balance between "writing the minimum code to pass the test" whilst still keeping it functional and in the spirit of what you're actually trying to achieve?

答:
A very good question...and I have to disagree with almost everyone except @Robert.

Writing

```<code>return 120;
</code>```

for a factorial function to make one test pass is a waste of time. It's not "cheating", nor is it following red-green-refactor literally. It is wrong.

Here's why:

Calculate Factorial is the feature, not "return a constant". "return 120" is not a calculation.

the 'refactor' arguments are misguided; if you have two test cases for 5 and 6, this code is still wrong, because you are not calculating a factorial at all:

```<code>if (input == 5) { return 120; } //input=5 case
else { return 720; }   //input=6 case
</code>```

if we follow the 'refactor' argument literally, then when we have 5 test cases we would invoke YAGNI and implement the function using a lookup table:

```<code>if (factorialDictionary.Contains(input)) {
    return factorialDictionary[input];
}
throw new Exception("Input failure");
</code>```

None of these are actually calculating anything, you are. And that's not the task!

Body:
A very good question...and I have to disagree with almost everyone except @Robert.

Writing

return 120;

for a factorial function to make one test pass is a waste of time. It's not "cheating", nor is it following red-green-refactor literally. It is wrong.

Here's why:

Calculate Factorial is the feature, not "return a constant". "return 120" is not a calculation.

the 'refactor' arguments are misguided; if you have two test cases for 5 and 6, this code is still wrong, because you are not calculating a factorial at all:

if (input == 5) { return 120; } //input=5 case
else { return 720; }   //input=6 case

if we follow the 'refactor' argument literally, then when we have 5 test cases we would invoke YAGNI and implement the function using a lookup table:

if (factorialDictionary.Contains(input)) {
    return factorialDictionary[input];
}
throw new Exception("Input failure");

None of these are actually calculating anything, you are. And that's not the task!


问:
External framework to fix code growth problems
I'm currently working on a project, and there are some "code growth" problems, that need a solution for. The deadline is not very far, and it would be advisable to stay within allocated time-frame.

Still, the code needs some restructuring, and here lies the question. Should we try to use a new framework to fix the current problem, or not.

My colleague is very open towards external frameworks and offers to restructure the code by finding an existing library something along the lines of WTL/boost/TinyXML/ATL.

I, on the other hand, am very cautions concerning new frameworks for existing code bases. The language is C++, and I have a fair amount of experience where libraries like MFC backfire with a huge flamethrower.

I am not saying my way is the right one, as I guess the truth is somewhere between, but I need to decide how to proceed.

The deadline is pretty close and the changes would touch a large part of the code-base, app logic layer. Restructuring the existing code base would require some peaceful thinking and some extra coding. But the code is not TDWTF kind, rather it has grown past the original requirements and needs new clothes.

The app is heavily asynchronous, and uses multiple threads, so it's not the trivial kind.

Can anyone tell me what is the general rule when you have to decide whether to use the premade wheel vs. reinventing a new one? What would be the acceptance criteria for new code?

答:
If you have a deadline which you need to meet, then don't introduce new, unknown stuff in your environment.

If the thing you need to fix is more important than the deadline, then strongly consider officially pushing the deadline if you are in doubt you will make it.

Note that for asynchronous applications with multiple threads Executors are your friends to tame the beasts.  Will they do, or do you need more than that?


答:
With your existing deadline I'd definitely let sleeping dogs lie.

Immediately after your deadline, sit down with your Mgmt and your team and explain that the code base has pretty much hit its maximum point of return.   e.g. It costs a huge amount of time and effort to add new features.

Then go away and identify areas that a 3rd party could take over for you and prototype using those 3rd party frameworks.

Title: External framework to fix code growth problems

Body:
I'm currently working on a project, and there are some "code growth" problems, that need a solution for. The deadline is not very far, and it would be advisable to stay within allocated time-frame.

Still, the code needs some restructuring, and here lies the question. Should we try to use a new framework to fix the current problem, or not.

My colleague is very open towards external frameworks and offers to restructure the code by finding an existing library something along the lines of WTL/boost/TinyXML/ATL.

I, on the other hand, am very cautions concerning new frameworks for existing code bases. The language is C++, and I have a fair amount of experience where libraries like MFC backfire with a huge flamethrower.

I am not saying my way is the right one, as I guess the truth is somewhere between, but I need to decide how to proceed.

The deadline is pretty close and the changes would touch a large part of the code-base, app logic layer. Restructuring the existing code base would require some peaceful thinking and some extra coding. But the code is not TDWTF kind, rather it has grown past the original requirements and needs new clothes.

The app is heavily asynchronous, and uses multiple threads, so it's not the trivial kind.

Can anyone tell me what is the general rule when you have to decide whether to use the premade wheel vs. reinventing a new one? What would be the acceptance criteria for new code?


答:
Motivations range from availability to curiosity to best-choice-for-job to no-choice-for-job:

I learned BASIC out of curiosity and because that's all that was available to me at the time (DG Nova 2) [1976]

I learned Pascal because that's what the university taught (Cyber). [1982]

I learned DataFlex because it was available and was sooooo much better than BASIC for PC business applications (IBM PC) [1983]

I learned Assembly Language because BASIC wasn't fast enough to get the job done (Apple ][). [1983]

I learned C because it had the best libraries to get the job done for the platform (80286) [1984]

I learned Prolog because it was there (curiosity) [1985]

I learned Lisp because academics kept using it to do cool things (curiosity) [1985]

I learned SmallTalk because it looked like fun (curiosity) [1985]

I learned C++ because I read Stroustrup's book [1985]

I learned Java because it was the best cross-platform solution available at the time for the job [1999]

I learned VB because that was the IT shop standard [2002]

I learned VB.NET because it was so much better than VB [2002]

I learned C# because VB.NET was too #@$% verbose [2003]

Addendum: Javascript, HTML, vbscript, powerbuilder, and several others all learned because that's what the job required


答:
I would suggest that your choice of test is not the best test.

I would start off with:

factorial(1) as the first test,

factorial(0) as the second

factorial(-ve) as the third

and then continue on with non-trivial cases

and finish up with an overflow case.

Title: Writing the minimum code to pass a unit test - without cheating!

Body:
When doing TDD and writing a unit test, how does one resist the urge to "cheat" when writing the first iteration of "implementation" code that you're testing?

For example:

Let's I need to calculate the Factorial of a number.  I start with a unit test (using MSTest) something like:

```<code>[TestClass]
public class CalculateFactorialTests
{
    [TestMethod]
    public void CalculateFactorial_5_input_returns_120()
    {
        // Arrange
        var myMath = new MyMath();
        // Act
        long output = myMath.CalculateFactorial(5);
        // Assert
        Assert.AreEqual(120, output);
    }
}
</code>```

I run this code, and it fails since the CalculateFactorial method doesn't even exist.  So, I now write the first iteration of the code to implement the method under test, writing the minimum code required to pass the test.

The thing is, I'm continually tempted to write the following:

```<code>public class MyMath
{
    public long CalculateFactorial(long input)
    {
        return 120;
    }
}
</code>```

This is, technically, correct in that it really is the minimum code required to make that specific test pass (go green), although it's clearly a "cheat" since it really doesn't even attempt to perform the function of calculating a factorial.  Of course, now the refactoring part becomes an exercise in "writing the correct functionality" rather than a true refactoring of the implementation.  Obviously, adding additional tests with different parameters will fail and force a refactoring, but you have to start with that one test.

So, my question is, how do you get that balance between "writing the minimum code to pass the test" whilst still keeping it functional and in the spirit of what you're actually trying to achieve?


答:
About half the languages I know are because it was what the school used and thus I got used to that,e.g. Watcom BASIC, Pascal, Commodore PET Assembler, Modula-3, C++, Scheme.  The other half are mostly on-the-job ones like VBScript, C#, JavaScript, and T-SQL.

I'm a programmer because I like building systems and solving problems.  Sometimes that may mean I'll learn some bits of a new language to help someone else.  For example, if someone in my office asked for my help on something, it may take me a little while but I would honestly try to help as best I can.


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

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

答: Object Orientation (from all statically typed languages). I'll wager this feature has, and will continue, to cost vastly more than null pointers. Object Orientation is only good in a dynamic message passing language. So it should be dropped from dynamic languages like Python too (since it doesn't use message passing but conventional subroutine calling).


问:
How do you manage your knowledge base?
As programmers we have a lot of inputs:

Ebooks

Code snippets

Interesting emails

Documents

Web articles

Blog posts

StackOverflow questions

Podcasts
...

Which tools do you use to store, organize, search and consult all of this stuff?

Is there a silver bullet solution to handle this huge amount of data?

答:
Trac

wiki, svn, bug tracker all integrated in one place.
cost: £40 per annum all set up, hosted and managed for me by http://hosted-projects.com/

I love it

With a mixture of 'wiki + tickets' you can store just about anything.

I have wiki pages for things like:

JobReports (write notes as I code)

How To's... (if i find myself repeating the same thing, I'd distil a previous job-report into a 'how-to' page)

Best Practices (add to the list of Epiphanies whenever I have one )

Incident Reports (if the server crashes, 1st thing I do is create a new Incident page, link it to new 'Job Report' wiki page and then write up my investigations, i.e. write the Linux commands first in the wiki and then paste it into SSH etc)

(Note: I have not been clinically declared OCD...yet!)

Title: How do you manage your knowledge base?


问:
How to deal with the "programming blowhard"?
So I'm sure everyone has run into this person at one point or another, someone catches wind of your project or idea and initially shows some interest. You get to talking about some of your methods and usually around this time they interject stating how you should use method X instead, or just use library Y. But not as a friendly suggestion, but bordering on a commandment. Often repeating the same advice over and over like a overzealous parrot.

Personally, I like to reinvent the wheel when I'm learning, or even just for fun, even if it turns out worse than what's been done before. But this person apparently cannot fathom recreating ANY utility for such purposes, or possibly try something that doesn't strictly follow traditional OOP practices, and will settle for nothing except their sense of perfection, and thus naturally heave their criticism sludge down my ears full force. To top it off, they eventually start justifying their advice (retardation) by listing all the incredibly complex things they've coded single-handedly (usually along the lines of "trust me, I've made/used program X for a long time, blah blah blah").

Now, I'm far from being a programming master, I'm probably not even that good, and as such I value advice and critique, but I think advice/critique has a time and place. There is also a big difference between being helpful and being narcissistic. In the past I probably would have used a somewhat stronger George Carlin style dismissal, but I don't think burning bridges is the best approach anymore.

Do you have any advice on how to deal with this kind of verbal flogging?

答:
Like most social situations, it depends on the context.

If this person is in a lead role (the context likely being a workplace), then you're kind of hosed unless you can convince them to use different techniques than the ones they choose. Hopefully they are open to critique from their team. In many cases I've found that presenting good, fact-based, solid arguments for why your particular approach is better for the project will often win them over. If they continue to be stubborn just because "that's how it's supposed to be done" (or some other silly reason), then they end up looking bad anyways and you look like you at least tried to be rational. In this case, I'd also recommend checking out careers.so ...

If this person is your peer, you can pretty much just ignore it and move on. Better would be to ask them to explain why they value a particular library or approach. Through discussion, they may realize that your constraints are different than they anticipated (for example, you don't need "awesome super-fast library X" because you don't need raw pedal-to-the-metal speed, or you don't want to use "prebuilt component Y" because you are aiming to minimize dependencies). You might also gain valuable insight into some of what they're suggesting. Usually in situations like these I end up going mostly my own way, but I'll usually also glean some helpful information from at least looking into whatever approach/technology/library they are advocating.

If this person is underneath you, then tell them to bug off :) Ok... maybe be a little more constructive than that (don't be the very type of person you are trying to deal with!), and again try to understand what's going on and communicate effectively.

In the end, if the person is really being a hardcore blowhard who doesn't want to compromise, isn't open-minded, and doesn't care to learn; then all you can really do is ignore it and try to make the best of the situation.


答: Replacing undefined variables by an empty string in shell without any warnings: rm -rf $nosuchvar/*.

Title: Which language features are considered harmful?

Body:
Please, explain why and list which languages have the (mis)feature implemented As far you know.

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


问:
Function overloading? Yes or no
I'm developing a statically- and strongly-typed, compiled language, and I'm revisiting the idea of whether to include function overloading as a language feature. I realized that I'm a little bit biased, coming mainly from a C[++|#] background.

What are the most convincing arguments for and against including function overloading in a language?

EDIT: Is there nobody who has an opposing opinion?

Bertrand Meyer (creator of Eiffel back in 1985/1986) calls method overloading this: (source)

a vanity mechanism that brings nothing to the semantic power of an O-O language, but hampers readability and complicates everyone's task

Now those are some sweeping generalizations, but he's a smart guy, so I think it's safe to say he could back them up if he needed to. In fact, he almost had Brad Abrams (one of the CLSv1 developers) convinced that .NET shouldn't support method overloading. (source) That's some powerful stuff. Can anyone shed some light on his thoughts, and whether his viewpoint is still justified 25 years later?

答:
I chose to provide ordinary overloading and multi-type type-classes in my language Felix.

I consider (open) overloading essential, especially in a language which as a lot of numeric types (Felix has all C's numeric types). However unlike C++ which abuses overloading by making templates depend on it, Felix polymorphism is parametric: you need overloading for templates in C++ because templates in C++ are badly designed.

Type classes are provided in Felix as well. For those that know C++ but don't grok Haskell, ignore those who describe it as overloading. It isn't remotely like overloading, rather, it is like template specialisation: you declare a template which you don't implement, then provide implementations for particular cases as you need them. The typing is parametrically polymorphic, the implementation is by ad hoc instantiation but it is not intended to be unconstrained: it has to implement the intended semantics.

In Haskell (and C++) you cannot state the semantics. In C++ the "Concepts" idea is roughly an attempt to approximate the semantics. In Felix, you can approximate the intention with axioms, reductions, lemmas and theorems.

The main, and only advantage of (open) overloading in a well principled language like Felix is that it makes it easier to remember library function names, both for the program writer and for the code reviewer.

The primary disadvantage of overloading is the complex algorithm required to implement it. It also doesn't sit very well with type inference: although the two are not entirely exclusive, the algorithm to do both is complex enough the programmer probably wouldn't be able to predict the results.

In C++ this is also a problem because it has a sloppy matching algorithm and also supports automatic type conversions: in Felix I "fixed" this problem by requiring an exact match and no automatic type conversions.

So you have a choice I think: overloading or type inference. Inference is cute, but it is also very hard to implement in a way that properly diagnoses conflicts. Ocaml, for example, tells you where it detects a conflict, but not where it inferred the expected type from.

Overloading is not much better, even if you have a quality compiler that tries to tell you all the candidates, it can be hard to read if the candidates are polymorphic, and even worse if it's C++ template hackery.

ContentLicense: CC BY-SA 4.0

Title: Function overloading? Yes or no


问:
How to keep your third party libraries up to date?
Let's say that I have a project that depends on 10 libraries, and within my project's trunk I'm free to use any versions of those libraries. So I start with the most recent versions. Then,  each of those libraries gets an update once a month (on average). Now, keeping my trunk completely up to date would require updating a library reference every three days.

This is obviously too much. Even though usually version 1.2.3 is a drop-in replacement for version 1.2.2, you never know without testing. Unit tests aren't enough; if it's a DB / file engine, you have to ensure that it works properly with files that were created with older versions, and maybe vice versa. If it has something to do with GUI, you have to visually inspect everything. And so on.

How do you handle this? Some possible approaches:

If it ain't broke, don't fix it. Stay with your current version of the library as long as you don't notice anything wrong with it when used in your application, no matter how often the library vendor publishes updates. Small incremental changes are just waste.

Update frequently in order to keep change small. Since you'll have to update some day in any case, it's better to update often so that you notice any problems early when they're easy to fix, instead of jumping over several versions and letting potential problems to accumulate.

Something in between. Is there a sweet spot?

答:
I'm shocked - and indeed appalled - at the number of answers here saying "don't update unless you have to". I've done that, and whilst it's easier in the short term, it burns like hell in the long run. More frequent, smaller updates are much, much easier to manage than occasional big ones, and you get the benefit of new features, bug fixes, and so on sooner.

I don't buy this idea that library changes are somehow more difficult to test than code changes. It's just the same - you're making a change to the codebase, and you need to validate it before you commit, and more deeply before you release. But you must already have processes to do this, since you're making code changes!

If you're working in iterations, of two to four weeks length, i would suggest making updating libraries a once per iteration task, to be done as soon as possible after the start, when things are a little more relaxed than just before an iteration deadline, and the project has more capacity to absorb change. Get someone (or a pair if you do pair programming) to sit down, look at which libraries have been updated, and try bringing each one in and running a rebuild and test. Budget half a day to a day for it each iteration, perhaps. If things work, check in the changes (i'm assuming you keep libraries in source control, as we do; i'm not sure how you'd propagate the change in a controlled way if not). This will obviously be a lot easier if you have automated tests than if testing is entirely manual.

Now, the question is what you do if an update breaks things - do you spend time fixing it, or leave it out? I'd suggest leaning towards the latter; if it can be fixed in an hour, do it, but if an update is going to take significant work to integrate, then raise it as its own development task, to be estimated, prioritised, and scheduled just like any other. The chances are that unless it brings in some very crucial fix or improvement, the priority will be low, and you'll never get round to it. But you never know, by the time the next iterationly update day rolls round, the problem might have fixed itself; even if not, at least now you know that there's a roadblock on the update path, and it won't catch you by surprise.

If you're not doing iterations of that length, i would set up some kind of standalone schedule for updates - no longer than monthly. Is there some other project rhythm you could tie it to, like a monthly status review, or an architecture board meeting? Payday? Pizza night? Full moon? Whatever, you need to find something a lot shorter than a traditional release cycle, because trying to update everything in one go every 6-18 months is going to be painful and demoralising.

Needless to say, if you do stabilisation branches before releases, you wouldn't apply this policy to them. There, you'd only update libraries to get critical fixes.


问:
Is there a good reason to use Java's Collection interface?
I've heard the argument that you should use the most generic interface available so that you're not tied to a particular implementation of that interface. Does this logic apply to interfaces like java.util.Collection?

I would much rather see something like the following:

```<code>List<Foo> getFoos()
</code>```

or

```<code>Set<Foo> getFoos()
</code>```

instead of

```<code>Collection<Foo> getFoos()
</code>```

In the last case, I don't know what kind of data set I'm dealing with, whereas in the first two instances I can make some assumptions about ordering and uniqueness. Does java.util.Collection have a usefulness outside of being a logical parent for both sets and lists?

If you came across code that employed Collection when doing a code review, how would you determine whether its usage is justified, and what suggestions would you make for its replacement with a more specific interface?

答:
The Collection interface, and the most permissive form Collection<?>, is great for parameters that you accept. Based on use in the Java library itself it's more common as a parameter type than a return type.

For return types, I think your point is valid: If people are expected to access it, they should know the order (in the Big-O sense) of the operation being performed. I would iterate over a Collection returned and add it to another Collection, but it would seem a bit crazy to call contains on it, not knowing if it's a O(1), O(log n), or O(n) operation. Of course, just because you have a Set doesn't mean it's a hashset or a sorted set, but at some point you will make assumptions that the interface has been reasonably implemented (and then you'll need to go to plan B if your assumption is shown to be incorrect).

As Tom mentions, sometimes you need to return a Collection in order to maintain encapsulation: You don't want implementation details leaking out, even if you could return something more specific. Or, in the case Tom mentioned, you could return the more specific container, but then you'd have to construct it.


答:
Like Niphra said, only start using a framework when you can use PHP without a framework (that is, access the database, send headers and content, string processing, data manipulation, etc.). As far as your questions are concerned:

When do I need to use a PHP framework such as CakePHP? When your project grows beyond a few PHP files; the moment you start strongly separating the logic into distinct elements and modularizing/sharing functionality (sessions, etc.) is when you should use a framework.

What are things that this and other similar PHP frameworks offer for me? Abstraction; instead of directly interacting with the database you can use an Object-Relational Mapping (ORM) to manage the structure and relationships between your data in the database. Most framework in many languages provide ORM's to make it easier to interact with the database layer of your application. Similarly, frameworks often separate the layers of responding to user interaction. The most common separation is the Model View Controller (MVC) paradigm, which, to be brief, abstracts database logic into the Model (an interface to the ORM, in many cases), processing requests and interacting with Models into the Controller, and the rendering of the actual HTML/PDF/image/etc. into the View. Frameworks often provide other tools such as routing (to allow for complex processing of the request URI (EG: Mapping the request "http://example.com/users/1" to the controller Users, which then looks up the user Model with the ID of 1) and an abstraction of sessions and other basic structures.

And is it really important to use a framework to be a professional? Not necessarily; frameworks make life easier; but you don't have to use one to be a professional. Frameworks provide handy abstraction and standardization, but they aren't a requirement in most cases.

Title: When do I need to use a framework?


答:
I'd look at it from the complete opposite point of view, and ask:

If you came across code that employed List<> when doing a code review, how would you determine whether its usage is justified?

It's quite easy to justify this. You use the List when you need some functionality that is not offered by a Collection. If you don't need that extra functionality - what justification do you have? (And I won't buy, "I'd prefer to see it")

There are plenty of cases where you will be using a collection for read-only purposes, populating it all at once, iterating through it entirely - do you ever need to index the thing manually?

To give a real example. Say I perform a simple query on a database. (SELECT id,name,rep FROM people WHERE name LIKE '%squared') I grab back the relevant data, populate Person objects and put em into a PersonList)

Do I need to access by index? - Would be meaningless. There's no mapping between index and ID.

Do I need to insert at an index? - No, the DBMS will decide where to put it, if I'm adding at all.

So what justification would I have for those extra methods? (which would be left unimplemented in my PersonList anyway)

Title: Is there a good reason to use Java's Collection interface?

Body:
I've heard the argument that you should use the most generic interface available so that you're not tied to a particular implementation of that interface. Does this logic apply to interfaces like java.util.Collection?

I would much rather see something like the following:

```<code>List<Foo> getFoos()
</code>```

or

```<code>Set<Foo> getFoos()
</code>```

instead of

```<code>Collection<Foo> getFoos()
</code>```

In the last case, I don't know what kind of data set I'm dealing with, whereas in the first two instances I can make some assumptions about ordering and uniqueness. Does java.util.Collection have a usefulness outside of being a logical parent for both sets and lists?

If you came across code that employed Collection when doing a code review, how would you determine whether its usage is justified, and what suggestions would you make for its replacement with a more specific interface?


答:
Abstractions live longer than implementations

In general the more abstract your design the longer it is likely to remain useful. So, since Collection is more abstract that it's sub-interfaces then an API design based on Collection is more likely to remain useful than one based on List.

However, the overarching principle is to use the most appropriate abstraction. So if your collection must support ordered elements then mandate a List, if there are to be no duplicates then mandate a Set, and so on.

A note on generic interface design

Since you're interested in using the Collection interface with generics you may the following helpful. Effective Java by Joshua Bloch recommends the following approach when designing an interface that will rely on generics: Producers Extend, Consumers Super

This is also known as the PECS rule. Essentially, if generic collections that produce data are passed to your class the signature should look like this:

```<code>public void pushAll(Collection<? extends E> producerCollection) {}
</code>```

Thus the input type can be E or any subclass of E (E is defined as both a super- and sub-class of itself in the Java language).

Conversely, a generic collection that is passed in to consume data should have a signature like this:

```<code>public void popAll(Collection<? super E> consumerCollection) {}
</code>```

The method will correctly deal with any superclass of E. Overall, using this approach will make your interface less surprising to your users because you'll be able to pass in Collection<Number> and Collection<Integer> and have them treated correctly.

Body:
Abstractions live longer than implementations

In general the more abstract your design the longer it is likely to remain useful. So, since Collection is more abstract that it's sub-interfaces then an API design based on Collection is more likely to remain useful than one based on List.

However, the overarching principle is to use the most appropriate abstraction. So if your collection must support ordered elements then mandate a List, if there are to be no duplicates then mandate a Set, and so on.

A note on generic interface design

Since you're interested in using the Collection interface with generics you may the following helpful. Effective Java by Joshua Bloch recommends the following approach when designing an interface that will rely on generics: Producers Extend, Consumers Super

This is also known as the PECS rule. Essentially, if generic collections that produce data are passed to your class the signature should look like this:

public void pushAll(Collection<? extends E> producerCollection) {}

Thus the input type can be E or any subclass of E (E is defined as both a super- and sub-class of itself in the Java language).

Conversely, a generic collection that is passed in to consume data should have a signature like this:

public void popAll(Collection<? super E> consumerCollection) {}

The method will correctly deal with any superclass of E. Overall, using this approach will make your interface less surprising to your users because you'll be able to pass in Collection<Number> and Collection<Integer> and have them treated correctly.


问:
What are non-programming mistakes that a programmer should avoid?
People make mistakes, even in the real life... Which should we, geeky programmers, avoid?</p>

答:
Biggest non-programming mistake I've ever seen:

Not learning how to communicate effectively, both orally and in writing.

Take two programmers of equal programming skill, one with good communication skills and one without. The former will go farther, faster every. single. time.


问:
Good example of complex code using TDD
What would be a good example of the use of TDD in large, real-life, complex, projects?  All the examples I've seen so far are toy projects for the purpose of a book or a paper...

Can you name an open-source project that heavily uses TDD? Preferably in C++ but I can read Java and C# or other similar languages.

答: If I recall FitNesse is written with TDD, and the main contributor to the project is Uncle Bob Martin, so, it's probably really clean code</p>

Title: Good example of complex code using TDD


答:
Build a few pages without a framework... you will essentially begin writing your own framework by trial and error. After you do that, move to a framework and enjoy how much time you save. Trying to build your own framework can teach you some things, and will help you appreciate the frameworks that are already out there.

When I first got into PHP, I thought frameworks were a complicated waste of time. Now, I use CodeIgniter for even simple projects. It takes about 1 minute to get up and running you already have a ton of great libraries available to you. And, as a previous poster mentioned, most frameworks are extensible, so you can always add whatever functionality you want.

Title: When do I need to use a framework?


答: From my discussions with the P&P Team at Microsoft, Enterprise Library was written with TDD.</p>

Title: Good example of complex code using TDD

Body:
What would be a good example of the use of TDD in large, real-life, complex, projects?  All the examples I've seen so far are toy projects for the purpose of a book or a paper...

Can you name an open-source project that heavily uses TDD? Preferably in C++ but I can read Java and C# or other similar languages.