答:
I think one problem here is that the length of a function says nothing about its complexity. LOC (Lines of Code) are a bad instrument to measure anything.

A method should not be overly complex, but there are scenarios where a long method can be easily maintained. Note that the following example does not say it could not be split into methods, just that the methods would not change the maintainability.

for example a handler for incoming data can have a large switch statement and then simple code per case. I have such code - managing incoming data from a feed. 70 (!) numerically coded handlers. Now, one will  say "use constants" - yes, except the API does not provide them and I like to stay close to "source" here. Methods? Sure - just sadly all of them deal with data from the same 2 huge structures. No benefit in splitting them off except maybe having more methods (readability). The code is intrinsically not complex - one switch, depending on a field. Then every case has a block that parses x elements of data and publishes them. No maintenance nightmare. There is one repeating" if condition that determiens whether a field has data (pField = pFields [x], if pField->IsSet() { blabla }) - same pretty much for every field...

Replace that with a much smaller routine containing nested loop and a lot of real switching statements and a huge method can be more easy to maintain than one smaller one.

So, sorry, LOC is not a good measurement to start with. If anything, then complexity / decision points should be used.


问:
How should I choose the right documentation for my team?
I've asked this question a few days ago about how much documentation should be made and now I realize I may have been asking only half of the question.

My goal is to promote some sort of documentation in order to increase continuous knowledge inside the team.

My team is working mainly on server-side services which extends proprietary devices which are distributed locally (national not global)

In addition we supply APIs and administration web apps to those services.

What would be the best types of documentation for my team?

Should we focus on DFDs, sequence diagrams, class diagrams, just plain text... ?

Are some documentation methodologies better for specific industries or are there some  which are just a waste of time?

I fear this last question would be put down as too subjective, but I do hope there are some standard answers for this question, similarly to when someone asks about good OOP techniques and gets directed to design patterns and SOLID principles.

答:
In Agile Software Development, Uncle Bob once wrote his First Law of Documentation "Produce no document unless it's need is immediate and significant." As has been typical of such comments in the Agile world, this has been misquoted and misinterpreted many times. So he later went on to clarify.

Agile Methods require two kinds of documentation: Requirements and Design Documents. All other kinds of documents are optional within Agile Methods; but optional does not mean absent.

Requirements. In Agile Methods, the requirements are documented one iteration at a time. Requirements are often identified long in advance of their development, but they are not fleshed out until the iteration in which they are developed begins. Moreover, they are written as automated acceptance tests. Other kinds of requirements documentation, such a narratives, workflows, and storyboards may also optionally be created.

Design Documents. In Agile Methods the design is documented by creating unit tests using Test Driven Development. These unit tests are working examples of how to use each part of the code. Other kinds of design documents, such as class diagrams, interaction diagrams, state charts, ER diagrams, etc. may optionally be created too.

Note the last paragraph in particular. It is sometimes ridiculous for developers to write documentation for other developers in English. Never forget that there is another common language that developers speak: code. Unlike English, code is self-validating.

Using unit tests to document the intent of the application code is a brilliant way of writing documentation. Why? Because they're guaranteed to remain up-to-date.

Further, and perhaps more relevant to your situation, he writes:

Documents that the development team decides they need, are simply created as and when they are needed. Documents that the business decides they need, and that the development team does not need for their own purposes, are written as story cards, and estimated, planned and scheduled as all story cards are. If they never get selected for an iteration, then they must not have been all that valuable to the business. If, however, they get scheduled for an iteration, the business must have considered them important enough to schedule.

This is a technique I use all the time for figuring out what is genuinely useful documentation. If the development team feels they need it, just give them the means (a wiki) and they will write it, without being asked. If the business feels they need it, queue it up as a job next to everything else, and see if they decide they need it more than they need other work.

ContentLicense: CC BY-SA 3.0


问:
What is the ideal length of a method for you?
In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what you think.

In Clean Code: A Handbook of Agile Software Craftsmanship, Robert Martin says:

The first rule of functions is that they should be small. The second
  rule of functions is that they should be smaller than that. Functions
  should not be 100 lines long. Functions should hardly ever be 20 lines
  long.

and he gives an example from Java code he sees from Kent Beck:

Every function in his program was just two, or three, or four lines
  long. Each was transparently obvious. Each told a story. And each led
  you to the next in a compelling order. That’s how short your functions
  should be!

This sounds great, but on the other hand, in Code Complete, Steve McConnell says something very different:

The routine should be allowed to grow organically up to 100-200 lines,
  decades of evidence say that routines of such length no more error
  prone then shorter routines.

And he gives a reference to a study that says routines 65 lines or long are cheaper to develop.

So while there are diverging opinions about the matter, is there a functional best-practice for you?

答:
I stepped into a project which hasn't had any care about coding guidelines. When I look into the code I sometimes find classes with more than 6000 lines of code and less than 10 methods. This is a horror scenario when you have to fix bugs.

A general rule of how big a method should be at maximum is sometimes not so good. I like the rule by Robert C. Martin (Uncle Bob): "Methods should be small, smaller than small". I try to use this rule all the time. I am trying to keep my methods simple and small by clarifying that my method does only one thing and nothing more.

OwnerDisplayName: iPhoneDeveloper


问:
Can web technologies, like PHP, HTML, and CSS, be used for desktop development?
I have to develop an application for a gas agency where a database will store consumer numbers, names, addresses, and date delivered for a town with nearly 20,000 people. I only know PHP, MySQL, CSS, jQuery, and other web based technologies. Is it possible to deliver a package to the client using these technologies that can be installed on a computer and used locally?

This application will run on a single PC for a single user. I'm familiar with tools such as XAMPP, but I do not want to run a web server locally. Both the application and database will be securely running on a particular computer. In the future, if this application must be on multiple computers, I want the database and application to be portable.

I have searched for similar questions on Stack Overflow and I did find some recommendations like Jetty, Adobe Air and the recent Web SQL database. Is PHP GTK also a viable tool for building professional applications?

I would like a recommendation specific for this kind of app.

答:
If your database is not online (I mean you database is not updated), you can use JavaScript, HTML and CSS to make your offline app (jQuery is a library of JavaScript).
If your database is updated, you can make a website to display it to your clients. And you can ask your clients to add bookmark to your website to update info, or you can make Chrome apps (if your clients use Chrome as web browser) for you clients install directly on their Chrome web browser.</p>


问:
How do I make sense of the javascript frameworks explosion ? Should I learn them all?
For a beginner web developer who is still doing web development the conventional way (PHP/J2EE/Struts on server side, HTML/CSS/Javascript on client side), I was bowled over by the recent blog post on Trello technology stack.

I can't help feeling overwhelmed by the list of new technologies and frameworks mentioned in this post and specifically the ubiquitousness of Javascript frameworks.

My question is, is this the future of web development? Are there any articles, websites or resources that can help me make sense of where each of these new frameworks fit in a modern web application ?

答:
In my opinion, I think that core web technology should know is:

GUI: HTML and CSS to style HTML

Control the Client Side: JavaScript is best your choice, with many library like jQuery, Prototype... (you can learn pure JavaScript or learn JavaScript but with jQuery approach, for easier to apply to your project rapidly)

Control the Server Side: there are many server sides technology like: PHP, ASP.NET, JSP, Ruby on Rails, Django Python, CodeFusion... choose one of them to start to learn. (I suggest to use Ruby on Rails or Django Python for easy and powerful framework/technology)

Data: JSON or XML

After you conquer all I lists below, according to your work, you can learn new technology easily because all new technology derive from them.


问:
Does it make sense to avoid a framework when building a large webapp with PHP?
Being a PHP web application developer for several years now, I've had my share of MVCs and frameworks. At first I thought they were the best thing since sliced bread; everything seemed to be very easy to implement.

Now however, it seems that the more complex the application gets, the more hassle the framework introduces, so I have to develop workarounds to overcome them. Such workarounds are usually pretty daunting and complex since I have to delve down into the framework core code and make changes so that it behaves the way I want.

For example, in one of my projects where I use Slim(C)+Idiorm(M)+Twig(V) (which I believe is very flexible), I have to create a custom function just to display dynamic data in parent templates; without a framework I could have simply executed mysql_query() in the included file.

Okay, frameworks are cool if I'm creating a simple company profile website; I can just whip some code in one night and they're usually ready by the morning, and the amount of good coding practice and design patterns I've learned from them is very valuable.

But really, for a complex web application like an all-in-one web based school management system, frameworks usually get in the way of my business process like in the example above.

So my question is: is it okay to just go back to basics, and use standard PHP code and libaries for doing my next project where there might be a gazillion frameworks and libraries, provided I can sufficiently use good coding practices and follow sensible design patterns like MVC? My development team is pretty small: only 2 programmers and 1 designer. The other programmer agrees with my thoughts above.

答:
A well-designed framework should be an aid to the programmer, not a hindrance.  If the framework you've used is getting in your way too much, I would suggest looking at a different framework.  Each has its own coding style, and its own pros and cons.

Having said that, the Zend framework seems to be wildly popular these days, and honestly?  I struggle to see why sometimes.  I've had to work with it in the past and I haven't liked its architecture one little bit.  The Zend_Form class is ridiculously overengineered, its decorator system is utterly horrid in use, and the decorators tie forms to views, breaking a fundemental concept of OOP stating that objects should be loosely coupled.  It also has a lot of code implemented as Singletones (which are bad for reasons that are well documented so I wont reiterate) and the Registry object also contributes to encouraging a sloppy coding style.

I've heard that Zend Framework 2 (currently in beta) is a much better product, but the bad taste Zend 1 left in my mouth means I'm not in any hurry to try it out.

Still, at this point I'm just ranting. :)  There are plenty of frameworks out there, each with their pros and cons, I'd suggest evaluating a few of them.


答:
MySQL is definetly a reasonable choice for your case, I don't think it's a problem to install on customer side.

If you prefer a 'no installation' database, you can go for SQLite (which works with
PHP)

Title: Can web technologies, like PHP, HTML, and CSS, be used for desktop development?

Body:
I have to develop an application for a gas agency where a database will store consumer numbers, names, addresses, and date delivered for a town with nearly 20,000 people. I only know PHP, MySQL, CSS, jQuery, and other web based technologies. Is it possible to deliver a package to the client using these technologies that can be installed on a computer and used locally?

This application will run on a single PC for a single user. I'm familiar with tools such as XAMPP, but I do not want to run a web server locally. Both the application and database will be securely running on a particular computer. In the future, if this application must be on multiple computers, I want the database and application to be portable.

I have searched for similar questions on Stack Overflow and I did find some recommendations like Jetty, Adobe Air and the recent Web SQL database. Is PHP GTK also a viable tool for building professional applications?

I would like a recommendation specific for this kind of app.


答:
A web application intended to be used by one person can be hosted locally, since a personal computer can act as a server, hosting:

A web server.

IIS is very easy to setup on any Windows machine and you don't need to download anything; Apache must be downloaded, but is very easy to setup too.

PHP.

Once you have Apache/IIS, downloading and installing PHP is not very hard.

An SQL database.

Most databases are ordinary products which can be installed on personal computers. The only problem would be the cost, but this doesn't concern you if you choose SQLite or a free version of Microsoft SQL Server or a free version of MySQL.

SQLite would be probably the easiest. One less product to install is always better when you deal with a personal computer, and not a strictly controlled, protected and documented server environment.

A web application can also be used locally. Instead of entering an URI of a remote server, like http://example.com/, you'll use http://localhost/. While some browsers will refuse to run JavaScript of an HTML file you open from disk (file://.../Desktop/Example.htm), this is not a problem with localhost URIs.

Now, how the web application will be used? You said:

I have to develop an app for a gas agency where a database will store consumer numbers, names, addresses, and date delivered for a town

So if I understand well, you'll have several employees of the agency using the same application, right? In this case, you can't just install your web application on personal computers. They must share the same database, which requires to host it on a machine which will be accessed from others, i.e. a server. From that point, you have several approaches:

Host an SQLite file on a shared drive (it may even be a NAS, not a real server) and access it from several PCs. This approach is fundamentally bad.

Since you're actually accessing the file itself, directly, if several users will perform an action at the same time, bad things will happen: the file will be locked by one user, or maybe some user will overwrite the changes made by another, etc. Don't do it.

Host an SQL database on a server, i.e. a simple PC of the agency that they will call a server, and everything else on PCs. Technically, you can do it. For example in server environments, it's not unusual to host the database and the application itself on different machines, mostly for performance reasons (some servers would be optimized for data manipulation, others - for computation).

While particularly relevant in server environment, this approach must be avoided when possible in a context like yours, for security reasons. By providing a direct access to your database from any machine of the agency, you reduce the safety of your data. You may configure the security properly to protect the data from a malicious user, but you'll spend a few months doing it, and with some SQL products, it's not even possible.

Host everything on a server (i.e, again, a simple PC of the agency). This is probably the most viable solution. You'll have to access the web application by typing something like http://192.168.1.13/, which is ugly, or the name of the machine, which is, in most companies, even uglier. But still:

The data of the agency is protected from malicious employees,

When fixing a bug, you have to push the update to one machine only, not to  PCs. The same applies to PHP itself. Would you rather update to PHP 5.3.11, once it's released, on one server, or you prefer doing it on  PCs?

Your source code is visible only by people who can access the server. You don't want any employee being able to read your PHP source code.

There is only one version of your code. If you host your app on every PC, what will happen if one is actually broken while you push the update? Or what happens if an employee decided to modify the source code of your application?

There is only one configuration to take in account, the server's one. PHP abstracts quite well the underlying hardware and configuration, but still. What if you need to store a temporary file, and you decide to write it to C:\Windows\Temp, and later you discover that on a precise PC, this part of your code crashes, because there is no C: on this PC?


答:
First of all don't get too worried about not knowing everything. It takes years to learn all the items on that list to a good level.

Pick one technology set, (ie PHP Javascript CSS and MySql) and get comfortable with that. Once your comfortable you can start picking up extra technologies one at a time.

You don't need to be comfortable with a huge list of things to be a competent developer. View that list as something to work towards not something you need before you can start.

Title: How do I make sense of the javascript frameworks explosion ? Should I learn them all?

Body:
For a beginner web developer who is still doing web development the conventional way (PHP/J2EE/Struts on server side, HTML/CSS/Javascript on client side), I was bowled over by the recent blog post on Trello technology stack.

I can't help feeling overwhelmed by the list of new technologies and frameworks mentioned in this post and specifically the ubiquitousness of Javascript frameworks.

My question is, is this the future of web development? Are there any articles, websites or resources that can help me make sense of where each of these new frameworks fit in a modern web application ?


答:
It is not about number of lines, it is about SRP.
According to this principle, your method should do one and only one thing.

If your method does this AND this AND this OR that => it is probably doing to much. Try to look at this method and analyse: "here I get this data, sort it and get elements I need" and "here I process these elements" and "here I finally combine them in order to get the result". These "blocks" should be refactored to other methods.

If you simply follow SRP most of your method will be small and with clear intention.

It is not correct to say "this method is > 20 lines so it is wrong". It can be an indication that something may be wrong with this method, no more.

You may have a 400 lines switch in a method (often happens in telecom), and it is still single responsibility and it is perfectly OK.

Title: What is the ideal length of a method for you?

Body:
In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what you think.

In Clean Code: A Handbook of Agile Software Craftsmanship, Robert Martin says:

The first rule of functions is that they should be small. The second
  rule of functions is that they should be smaller than that. Functions
  should not be 100 lines long. Functions should hardly ever be 20 lines
  long.

and he gives an example from Java code he sees from Kent Beck:

Every function in his program was just two, or three, or four lines
  long. Each was transparently obvious. Each told a story. And each led
  you to the next in a compelling order. That’s how short your functions
  should be!

This sounds great, but on the other hand, in Code Complete, Steve McConnell says something very different:

The routine should be allowed to grow organically up to 100-200 lines,
  decades of evidence say that routines of such length no more error
  prone then shorter routines.

And he gives a reference to a study that says routines 65 lines or long are cheaper to develop.

So while there are diverging opinions about the matter, is there a functional best-practice for you?


答:
There is no absolute rules about method's length, but the following rules have been useful:

Function's primary purpose is to find the return value. There is no other reason for it's existence. Once that reason is fullfilled, no other code should be inserted to it. This necessarily keeps functions small. Calling other functions should only be done if it makes finding the return value easier.

On the other hand, interfaces should be small. This means you either have large number of classes, or you have large functions -- one of the two is going to happen once you start to have enough code to do anything significant. Big programs can have both.


问:
Is studying more than one programming language as a beginner confusing?
Intuitively it seems like this might be the case. Is there real research or authoritative anecdotal data (yes, please) supporting (or contradicting) this theory?</p>

答:
I would say no! Because your aim is to grasp the concepts of programming. It is advantageous to learn programming languages with different syntaxes and styles. As a beginner, it is good to learn Python/Visual Basic and Java if you are totally new and naive to programming (also depends what age group you fall into).

If you are like to pursue programming as a career then it is best to start with C and/or C++ and then learn Java as in C you come to know about memory management using pointers and C++ is a multi-paradigm language besides being OOP language.

Essentially programmer should concentrate on logic and skills rather than just the syntax and constructs of the language.


答:
Keep in mind that most developers have to be able to at least read and patch multiple languages. It would be rare to find a developer that uses only one main language for multiple years.

By looking at more than one language in short order you will begin to see the similarities and differences between the languages. Once you have been exposed to your first language there is no need to struggle to understand the different types of loops, or what is a class.

Title: Is studying more than one programming language as a beginner confusing?

Body: Intuitively it seems like this might be the case. Is there real research or authoritative anecdotal data (yes, please) supporting (or contradicting) this theory?</p>


问:
What are the steps involved in creating a testing process?
I've been asked this question as part of an assignment.

The question is a bit vague, and after searching the Internet, I cannot seem to find any particular set of steps related to this question. The best I could find are the following:

Design test cases

Prepare test data

Run program with test data

Compare results to test data

Are these valid steps which can be done to create a test process? Or am I misinterpreting the question?

答:
In addition to the steps you've already mentioned, you can add:

Determine what specifically needs to be tested.

Determine what tools you will use for testing.

Determine who will be responsible for testing.

Determine how the test results will be utilized as part of the entire development process.


答:
It is not necessarily confusing to teach beginners two different ways to program if done correctly.

The curriculum at ASU's Robotic Camp introduces middle and high school students to programming and robotics. In a two week period, it covers two programming environments, Alice and Microsoft's Robotic Studio Visual Programming Language (VPL). I have participated (as a teacher) in this camp, and we have survey data and empirical evidence that shows that most students learn enough about these two different languages to be able to produce their own creations in each language, and they feel much more comfortable about programming after the camp is over.


答:
In a modern software development environment, I would say that writing unit tests is part of any good test plan. The unit tests represent your first line of defense against defects.

This is especially true when working with a piece of software that has no real user interaction and is unlikely to be tested (or even testable) by the person requesting the change.

Your last two bullet points represent user acceptance testing, which is fine, but with reasonably well-written unit tests and appropriate code coverage, UAT should really be more focused on whether or not the change has correctly captured the requirements and is usable.

Title: What are the steps involved in creating a testing process?

Body:
I've been asked this question as part of an assignment.

The question is a bit vague, and after searching the Internet, I cannot seem to find any particular set of steps related to this question. The best I could find are the following:

Design test cases

Prepare test data

Run program with test data

Compare results to test data

Are these valid steps which can be done to create a test process? Or am I misinterpreting the question?


答:
Proper testing requires a multi-tiered approach. Your testing process should take these tiers into consideration.

There are at least a couple of ways to look at this. One is called the testing triangle, and describes a structure where numerous unit tests are at the bottom, and a few manual tests are at the peak. Between those two extremes are integration tests and acceptance tests.

Another approach to looking at how to focus your testing efforts is through the agile testing quadrant. This approach has you organizing your test by what they test -- whether they are business facing or technology facing (Y axis), and whether they serve to critique the product or support the programming team (x axis).

(Note: these two ways of looking at testing aren't mutually exclusive -- they are just two ways to look at the problem)

So, your first step should be to decide how you are going to test. Are you going to focus on manual testing? Unit testing? Can you automated your user acceptance tests? If you are like most programming teams, you have limited resources so you will need to decide how much effort to put into each type of test.

Each of those types of tests will then require their own plan, though you don't necessarily need a formal, written plan. For example, the plan for unit testing would be simply that developers should write unit tests for any code they write, and they should be run after every build.


问:
Recommended Java source code reading
Like every author needs to read a lot of classical literature to develop his own style, and like every chess player read and analyze former champions games before, I think also every programmer needs to read a lot  of high quality code.

When it comes to Java source code, what are your recommendations as "reading". Which open source projects, libraries in the past you found yet easier to grasp and easy to read but also very good examples of what "high quality" code looks like?

答: The Spring framework core source code is excellent to read. It has been recommended to me several times and I read some of it myself. Jürgen did a good job here.</p>

Title: Recommended Java source code reading


问:
Unit/Integration Testing my DAL
So I've done some research on this but I couldn't quite come to a conclusion, so I figured I'd ask you guys to see if I could get some other opinions.

All of my database access is currently done through stored procedures. I am going to make no direct calls using custom queries. Because of this, my DAL is going to be pretty simple. It's basically going to just contain a bunch of methods that more or less interface out the different stored procedures in the database. It will always be in sync with the procedures that are there, and never call into the database any other way.

I'm not sure if this is the greatest way to do things, and I am aware of the advantages and disadvantages of only using stored procedures, but it's just the way I've chosen. I think it will be the cleanest in the long run.

But I want to test this DAL. I want to test this at a low level opposed to only testing it via the Business Objects that are going to be tied to these calls. I figure doing that will give me confidence that the procedures are working correctly, and than at a high level I can just mock this out and test business logic - but I'm fighting with how I test this stuff.

If I write unit tests by the book, I would mock out the actual calls to the database and just make sure that they are getting called, or create some stubs or whatever that return fake data and do it that way (both make sure the function is actually called). However, what good is this if the only thing these methods are doing are taking parameters and calling a stored procedure? All my mocks would be doing would be making sure I'm calling the method from the test more or less, and that seems like a huge waste of time and not really that effective.

Now if I integration test this stuff, I could be dealing with real test data, real database calls, which is fine, but then it wouldn't be 100% considered a unit test, and since within the Business Objects I'm mocking these calls out, I'd technically never have official unit tests for this stuff, only integration ones. Does this all make sense?

Basically, this seems fine to do for me. Have integration tests for the DAL, and have that be the only time the DAL itself is tested. When I unit test the business logic and mock out the DAL, I'd know it handles data correctly, and that would be comforting enough for me. What I'm asking is, am I approaching this correctly? Is there anything else you guys do that I am missing here that would shine some light on this stuff?

Any feedback is much appreciated :)

答:
Your approach sounds correct. Just be aware that integration tests still need to be repeatable, so you'll have to have a fairly static test database that has all of the tables/views/stored procedures synched to your production codebase. It can be a pain to maintain that, especially with multiple developers. You'll end up with situations where a previous integration tests breaks because someone else went and added a row to a table for one of their integration tests.

One approach I've seen to handle that is, rather than having a "fairly static" database, you have a completely empty database that has all of its objects and data constructed as part of the test setup, and cleared out as part of the teardown. That represents a higher maintenance cost and a non-trivial amount of initial setup work, but may work better if your database schema changes frequently.

Title: Unit/Integration Testing my DAL


答: The best source is the language inventor's own books. Search for a good book written by James Gosling. Also you can find a lot of great examples on Java's official website. </p>

Title: Recommended Java source code reading

Body:
Like every author needs to read a lot of classical literature to develop his own style, and like every chess player read and analyze former champions games before, I think also every programmer needs to read a lot  of high quality code.

When it comes to Java source code, what are your recommendations as "reading". Which open source projects, libraries in the past you found yet easier to grasp and easy to read but also very good examples of what "high quality" code looks like?


问:
How to remove duplicate code (in general)?
In an OO language (e.g. but not limited to Java) how do you fix duplicate code depending on the scope of it's occurrence? I would start with (for example)

in the same class (scope) perform the Extract Method refactoring (fix)

in classes of the same hierarchy (scope) perform Extract Method and Pull Up (fix)

...

答:
Recently I found a good answer to my question in Uncle Bob's "Clean Code", which I want to share. He differentiates three types of duplication

Pieces of identical code should be replaced with a single method. So the fix would be to extract the method and delegate to common behaviour.

in the same method, perform Extract Local Variable and reuse it.

in the same class perform the Extract Method refactoring.

in classes of the same hierarchy Extract Method and Pull it Up. A hierarchy might be created to find a place for the methods.

in classes of separate hierarchies use delegation to new objects.

If the methods do not need any enclosing state, then the "lib" pattern might be applied (that is a container for static methods, usually called SthUtil or SthLib).

cases of switch/case and if/else that always test for the same set of conditions.

These should be replaced with polymorphism.

Modules that implement similar algorithms. These are hardest to find, as no clone detector can find them.

As the scope is larger design patters are used. Template Method design pattern might be applied for algorithms inside a class hierarchy.

Strategy design pattern might be applied for any algorithm that is used in different places.

Also a valid point mentioned by Oded, when dealing with different versions of libraries

consolidate on a single version. Facade design pattern might help here.

In the end the best one sentence to answer my question is by stimms:

code reuse method used in OO languages is objects.


问:
Conflicting Java Styles within a Team
I am part of a Java development team with a 6 week deadline. This necessitates writing a good deal of code very very quickly. However our development team has different styles of coding. Everything from name conventions to methods of abstraction differ among our team. Does anyone know of any documents that dictate "standards" for java?

To clarify, I was wondering if there was an organization that would dictate proper naming convention for variables and functions for example. This is paramount as with such a short deadline we can't afford to spend time trying to comprehend each others code.

答:
Uncle Bob shows a more modern and current coding style in his book "Clean Code". Unfortunately it contains no list of items. You have to read it. He says himself that to see his conventions, you have to read his code. Uncle Bob is without doubt a kind of institution.
The book is an excellent read anyway, so even if it's too late to read it now, read it asap.</p>

Title: Conflicting Java Styles within a Team


答: I can recommend the source code of Guice, Bob Lee et al made a lovely clean code base there</p>

Title: Recommended Java source code reading


答:
Don't worry about picking some perfect universal standard. All you need is for your team to agree to one standard and stick to it. Make up your own if you wish, but be consistent.

Consistency improves collaboration, collaboration improves code.

Even if actual consistency doesn't help, the fact that your team worked together to come to an agreement is a Good Thing. Their inability to agree to something as simple as coding conventions says there may be bigger teamwork problems lurking under the surface.

Title: Conflicting Java Styles within a Team

Body:
I am part of a Java development team with a 6 week deadline. This necessitates writing a good deal of code very very quickly. However our development team has different styles of coding. Everything from name conventions to methods of abstraction differ among our team. Does anyone know of any documents that dictate "standards" for java?

To clarify, I was wondering if there was an organization that would dictate proper naming convention for variables and functions for example. This is paramount as with such a short deadline we can't afford to spend time trying to comprehend each others code.


问:
Hard-copy approaches to time tracking
I have a problem: I suck at tracking time-on-task for specific feature/defects/etc while coding them.  I tend to jump between tasks a fair bit (partly due to the inherit juggling required by professional software development, partly due to my personal tendancy to focus on the code itself and not the business process around code).

My personal preference is for a hard-copy system.  Even with gabillions of pixels of real-estate on-screen I find it terribly distracting to keep a tracking window convienient; either I forget about it or it gets in my ways.

So, looking for suggestions on time-tracking.  My only requirement is a simple system to track start/stop times per task.  I've considered going as far as buying a time-clock and giving each ticket a dedicated time-card.  When I start working on it, punch-in; when done working, punch-out.

答:
Pomodoro might help you out. The gist of it is that you get a timer (can be software, can be a physical timer) and you work on a task for 25 minutes, then take a 5 minute break, and take a longer break after repeating that pattern four times.

The system provides ways for you to deal with interruptions and distractions as well, so you can manage those and stay focused.

While it is mostly a time management system, it is in its pure form paper-based and you could tally up all your pomodoros at the end and arrive at the time spent on a given issue.

ContentLicense: CC BY-SA 2.5

Title: Hard-copy approaches to time tracking


问:
Should we adopt an agile methodology when rewriting an existing application from scratch?
I work for a small product based company. We are about to re-write our existing product from scratch. We are planing to adopt Agile methodology for our development. Now my question is as we have all the requirements even before start of project (as we are re-writing the existing product), is it worth to dive into Agile world? Isn't agile more useful when you don't have all the requirement upfront and you get your requirement in phases?

Secondly, let's say if we jump into Agile, whats the best practice to design database? Let's say in our first iteration we just create a login system (user can login, logout etc). Do we just need to create Users table without worrying about other tables? And other tables would be evolved as our product would progress?

答:
We've been using Agile on a project that entails moving from an old application to a new set of applications and a new architecture.  Our situation is a little different in that we are trying to not only redo the existing application (used internally by our sales, finance, sourcing and warehouse departments), but we are trying to improve each department's experience along the way.  One challenge that we've seen using agile is that the business value for moving parts of the functionality for a given business unit is high, but other parts is low.  We therefore find ourselves making new applications and keeping the old application running while we transition.  We are having trouble getting the business to see the value in concentrating on moving one "customer" to a completely new application.  We are however getting a lot of high value stories into our sprints.  I think soon we are going to come to a pint soon, when we have to convince the business that we need to focus on one unit at a time.

So, to answer the original question, yes agile is a good way to go.  Be prepared for some dependencies to crop up and guid some of the teams decisions along the way.

OwnerDisplayName: TK Lee


问:
What is the best way to handle product versioning and branching of long term projects?
In a general sense, for long term projects that may have multiple releases during the products life cycle and require support of previous products, what is the best way to handle product versions and branching of the code base?

In a more specific sense, assume that proper distributed version control is in place (i.e. git) and that the teams are small to large in size and that developer may be working on multiple projects at once. The major issue that is being faced is that there is a contractual obligation to support old versions as they existed at the time which means that new development can not patch old code (Microsoft Office products could be an example of this, you only get patches for the feature year you own).

As a result the current product versioning is a touch convoluted as each main product has multiple dependencies, each with their own versions which may change between annual releases. Likewise, while each product has its own repository, most of the work is not done on the main source trunk but rather on a branch for that years product release with a new branch being made when the product is released so that it may be supported. This in turn means that getting a product's code base isn't a simple matter as one might think when using version control.

答:
Git is a version control tool - it manages versions of files. What you are after is a configuration management tool. Theres pleantly of these avalible, but mostly at high $$$ from the likes of IBM.

Version control tools provide branching and tagging, which enables rudementy configuration management without additional tool support, hence menay developers do not understand the difference. Your needs probably extend beyond what GIT is designed to do.

I am not aware of, but am certain it will exist, a CM tool addtion for Git.


答:
If I write unit tests by the book, ... However, what good is this if the only thing these methods are doing are taking parameters and calling a stored procedure?

Get a better book.

Now if I integration test this stuff, I could be dealing with real test data, real database calls, which is fine, but then it wouldn't be 100% considered a unit test,

By whom?

You're testing stored procedures.  Those are your unit.  It's not an integration test, except in the sense that you have to "integrate" the database with something else to test it.

[Also, the very fact that you need to ask this question is a hint that important code in stored procedures is a bad idea.  Your testing is made much harder by putting code in to the database.  "I think it will be the cleanest in the long run." is countered by your question on how to properly test them.  If you get
rid of them, you don't have the question on how test them.]

Here's the point "Unit" does not have a single, standard, formal definition.

Store procedures can be the unit of unit testing.

You can use unit testing techniques to test your database.  Just be sure that it's a completely repeatable, fully automated test.  The test must include a standard database configuration that's loaded prior to the test so that the test works with one set of data -- and only one set of data.

It's still unit testing, because you've defined your unit of code to be the so

Title: Unit/Integration Testing my DAL

Body:
So I've done some research on this but I couldn't quite come to a conclusion, so I figured I'd ask you guys to see if I could get some other opinions.

All of my database access is currently done through stored procedures. I am going to make no direct calls using custom queries. Because of this, my DAL is going to be pretty simple. It's basically going to just contain a bunch of methods that more or less interface out the different stored procedures in the database. It will always be in sync with the procedures that are there, and never call into the database any other way.

I'm not sure if this is the greatest way to do things, and I am aware of the advantages and disadvantages of only using stored procedures, but it's just the way I've chosen. I think it will be the cleanest in the long run.

But I want to test this DAL. I want to test this at a low level opposed to only testing it via the Business Objects that are going to be tied to these calls. I figure doing that will give me confidence that the procedures are working correctly, and than at a high level I can just mock this out and test business logic - but I'm fighting with how I test this stuff.

If I write unit tests by the book, I would mock out the actual calls to the database and just make sure that they are getting called, or create some stubs or whatever that return fake data and do it that way (both make sure the function is actually called). However, what good is this if the only thing these methods are doing are taking parameters and calling a stored procedure? All my mocks would be doing would be making sure I'm calling the method from the test more or less, and that seems like a huge waste of time and not really that effective.

Now if I integration test this stuff, I could be dealing with real test data, real database calls, which is fine, but then it wouldn't be 100% considered a unit test, and since within the Business Objects I'm mocking these calls out, I'd technically never have official unit tests for this stuff, only integration ones. Does this all make sense?

Basically, this seems fine to do for me. Have integration tests for the DAL, and have that be the only time the DAL itself is tested. When I unit test the business logic and mock out the DAL, I'd know it handles data correctly, and that would be comforting enough for me. What I'm asking is, am I approaching this correctly? Is there anything else you guys do that I am missing here that would shine some light on this stuff?

Any feedback is much appreciated :)


问:
std::shared_ptr as a last resort?
I was just watching the "Going Native 2012" streams and I noticed the discussion about std::shared_ptr. I was a bit surprised to hear Bjarne's somewhat negative view on std::shared_ptr and his comment that it should be used as a "last resort" when an object's life-time is uncertain (which I believe, according to him, should infrequently be the case).

Would anyone care to explain this in a bit more depth? How can we program without std::shared_ptr and still manage object life-times in a safe way?

答:
I think what he's getting at is that it's becoming common for everyone to write shared_ptr whenever they might have written a standard pointer (like a kind of global replacement), and that it's being used as a cop-out instead of actually designing or at least planning for object creation and deletion.

The other thing that people forget (besides the locking /updating/unlocking bottleneck mentioned in the material above), is that shared_ptr alone doesn't solve cycle problems.  You can still leak resources with shared_ptr:

Object A, contains a shared pointer to another Object A
Object B creates A a1 and A a2, and assigns the a1.otherA = a2; and a2.otherA = a1;
Now, object B's shared pointers it used to create a1,a2 go out of scope (say at the end of a function).  Now you have a leak- no one else refers to a1 and a2, but they refer to each other so their ref counts are always 1, and you've leaked.

That's the simple example, when this occurs in real code it happens usually in complicated ways.  There is a solution with weak_ptr, but so many people now just do shared_ptr everywhere and don't even know of the leak problem or even of weak_ptr.

To wrap it up: I think the comments referenced by the OP boil down to this:

No matter what language you're working in (managed, unmanaged, or something in-between with reference counts like shared_ptr), you need to understand and intentionally decide on object creation, lifetimes, and destruction.

edit: even if that means "unknown, I need to use a shared_ptr," you've still thought of it and are doing so intentionally.

OwnerDisplayName: ronag

Title: std::shared_ptr as a last resort?


答:
What really matters in code is low cyclomatic complexity, small scope, high cohesion and choice of expressive identifiers. Given those, code becomes easy to grasp and such code is good.

I suggest you look into Spartan Programming.

Most coding standards tell you how to make poorly written code look pretty and most discussions on "coding style" are actually about formatting. Code formatting is about visually representing the structure of your code. It is trivial and automatable and has barely to do anything with coding style, because coding style is not about how you represent code structure, but about how you structure code.

There's a also a lot of religious wars about naming conventions, although really they are just a hack to work around poor design. A name is good, if it says what it means. The smaller and clearer your scopes, the easier it is to choose such a name.

Title: Conflicting Java Styles within a Team


答:
I would say, learning more than one programming language from the beginning is not the best thing you could do. I've taught C# at my university for two years. Some people always thought that they were able to learn java and c#, without any preknowledge, from scratch at the same time, let me tell you they were not able :D

Learning a programming language is more than learning some vocabulary. It's more than that, it's a step to have a complete new look on objects and progresses. Learning C# or Java isn't very hard, but learning the right way to develop and to analyze problems to find a solution is the problem.

And that's the point when it becomes difficult for beginners. You have to keep algorithm in mind together with a complete new vocabulary, or grammar ;-). And java and c# or php or or or are sometimes similar but not completely. So start with one language and after that you can try to learn more than once.

I think it's the same like development. Working in one project is fast with a good quality. Working in more projects at the same time is bad for quality and you need much time for all the projects.


答:
I agree with both DBM and S.Lott.

The unit under test can be anything that needs testing.
Defining that only classes can be units is narrow minded.

I suggest either connecting to an empty DB and filling with data in the test set-up phase, then either emptying it or deleting it in the test clean-up phase. or creating a copy of a constant DB, connecting to it in the test set-up phase, then deleting in the test clean-up phase.

It is important to do this per test, so that the tests are truly independent.

Title: Unit/Integration Testing my DAL


问:
Writing Testable Code vs Avoiding Speculative Generality
I was reading some blog posts this morning, and stumbled across this one:

If the only class that ever implements the Customer interface is
  CustomerImpl, you don't really have polymorphism and substitutability
  because there is nothing in practice to substitute at runtime. It's
  fake generality.

That makes sense to me, as implementing an interface adds complexity and, if there is only ever one implementation, one might argue that it adds needless complexity.  Writing code that is more abstract than it needs to be is often considered to be code smell called "speculative generality" (also mentioned in the post).

But, if I'm following TDD, I can't (easily) create test doubles without that speculative generality, whether in the form of interface implementation or our other polymorphic option, making the class inheritable and its methods virtual.

So, how do we reconcile this tradeoff?  Is it worth it to be speculatively general to facilitate testing/TDD?  If you're using test doubles, do these count as second implementations and thus make the generality no longer speculative?  Should you consider a more heavyweight mocking framework that allows mocking of concrete collaborators (e.g. Moles versus Moq in the C# world)?  Or, should you test with the concrete classes and write what could be considered "integration" tests until such time as your design naturally requires polymorphism?

I'm curious to read other people's takes on this matter -- thanks in advance for your opinions.

答: I went and read the blog post, and I agree with a lot of what the author said. However, if you're writing your code using interfaces for unit testing purposes, I'd say that the mock implementation of the interface is your second implementation. I'd argue that it really doesn't add much in the way of complexity to your code, especially if the trade-off of not doing so results in your classes being tightly coupled and hard to test.


问:
In the context of semantic versioning, does a change in the default configuration warrant a new major version?
My module is enabled by default (i.e. when you add the module). There's also a configuration you can optionally use, which supports an enabled="true|false" setting. This way the module can be disabled after it's been added, without the need to remove the module.

But I realized the module doesn't play nicely with another module that is also enabled by default. I am considering changing my module so it's not be enabled by default. This would break for anyone that has not explicitly enabled it with the enabled="true" configuration setting.

Should I wait for v2.0 for this? semver.org mentions the public API and breaking changes, not configuration. Is it generally accepted that configuration is part of the public API?

答:
It's not a semantic change, so you're fine changing this (it's really not a breaking change forcing people to recompile and test).  This is basically a toggle and your users have the ability to change it to suit their needs.  That's why you made it configuration to begin with.  You didn't change the nature of what the true/false means.

Just be nice and add it to notes that its off by default, hehe.


答:
Does the language you use have a way to "mock" an object for testing? If so these annoying interfaces can go away.

On a different note there can be reasons to have a SimpleInterface and a sole ComplexThing that implements it. There could be pieces of the ComplexThing that you don't want accessible to the SimpleInterface user. It's not always because of an over-exuberant OO-ish coder.

I'll step away now and let everyone jump on the fact that code that does this "smells bad" to them.

Title: Writing Testable Code vs Avoiding Speculative Generality

Body:
I was reading some blog posts this morning, and stumbled across this one:

If the only class that ever implements the Customer interface is
  CustomerImpl, you don't really have polymorphism and substitutability
  because there is nothing in practice to substitute at runtime. It's
  fake generality.

That makes sense to me, as implementing an interface adds complexity and, if there is only ever one implementation, one might argue that it adds needless complexity.  Writing code that is more abstract than it needs to be is often considered to be code smell called "speculative generality" (also mentioned in the post).

But, if I'm following TDD, I can't (easily) create test doubles without that speculative generality, whether in the form of interface implementation or our other polymorphic option, making the class inheritable and its methods virtual.

So, how do we reconcile this tradeoff?  Is it worth it to be speculatively general to facilitate testing/TDD?  If you're using test doubles, do these count as second implementations and thus make the generality no longer speculative?  Should you consider a more heavyweight mocking framework that allows mocking of concrete collaborators (e.g. Moles versus Moq in the C# world)?  Or, should you test with the concrete classes and write what could be considered "integration" tests until such time as your design naturally requires polymorphism?

I'm curious to read other people's takes on this matter -- thanks in advance for your opinions.


答:
I would consider any change that forces a user to modify their code/configuration as a result to be a breaking change.

So, in this particular case, I would wait till v2 to introduce the default of enabled=false and would instead add a note in the next minor release that explains this known scenario, that you should explicitly set enabled=false to avoid it and that the next major release will fix it.

Title: In the context of semantic versioning, does a change in the default configuration warrant a new major version?

Body:
My module is enabled by default (i.e. when you add the module). There's also a configuration you can optionally use, which supports an enabled="true|false" setting. This way the module can be disabled after it's been added, without the need to remove the module.

But I realized the module doesn't play nicely with another module that is also enabled by default. I am considering changing my module so it's not be enabled by default. This would break for anyone that has not explicitly enabled it with the enabled="true" configuration setting.

Should I wait for v2.0 for this? semver.org mentions the public API and breaking changes, not configuration. Is it generally accepted that configuration is part of the public API?


问:
How to do locking and not use a database?
I have a project which involves re-writing pretty much all the back end of a legacy application. It uses XML for persistence and was originally written as a single user system.

With one large XML file that could be accessed by multiple users and hence get corrupted, I was thinking about introducing a SQL database where a user could work on his resource and let the database worry about concurrency.

With the short deadlines, I was wondering if we could keep the xml persistence (as well as all the business logic) and introduce locking in some other way. Is this possible?

答:
Absolutely.  All platforms have some sort of "file locking" facility.  On Unix, flock and fcntl locking are available.  On Windows, similar facilities exist.

http://en.wikipedia.org/wiki/File_locking has a good summary, and pointers to the implementations, as well as problems that you might encounter.


答:
This may sound naive, overly simpleton even, but you can buy a chess clock and measure your spend time on two tasks with it.

Know a few people who do that ... however, they are also chess players, so ... ;-)

Looks nice on the table however (and most people will stop and ask why do you need two clocks and in what timezone is the second one).

Title: Hard-copy approaches to time tracking

Body:
I have a problem: I suck at tracking time-on-task for specific feature/defects/etc while coding them.  I tend to jump between tasks a fair bit (partly due to the inherit juggling required by professional software development, partly due to my personal tendancy to focus on the code itself and not the business process around code).

My personal preference is for a hard-copy system.  Even with gabillions of pixels of real-estate on-screen I find it terribly distracting to keep a tracking window convienient; either I forget about it or it gets in my ways.

So, looking for suggestions on time-tracking.  My only requirement is a simple system to track start/stop times per task.  I've considered going as far as buying a time-clock and giving each ticket a dedicated time-card.  When I start working on it, punch-in; when done working, punch-out.


答:
If you listen to some of these answers you are trading one devil for the other.

The way most people are recommending, file locking just serializes writes to the file and does not in any way address logical corruption of the structure of the XML file. It would just create a last in wins situation where previous writes are not taken into account at all.

There are transaction engines that can be added at the logical ( application ) level but unless your logic is extremely complex and ill suited to what a real RDBMS already provides they will be even more of a learning curve and even more of a maintenance issue.

Bite bullet and do it the correct way, the quick and dirty way got you in the mess you are in apparently.

Title: How to do locking and not use a database?

Body:
I have a project which involves re-writing pretty much all the back end of a legacy application. It uses XML for persistence and was originally written as a single user system.

With one large XML file that could be accessed by multiple users and hence get corrupted, I was thinking about introducing a SQL database where a user could work on his resource and let the database worry about concurrency.

With the short deadlines, I was wondering if we could keep the xml persistence (as well as all the business logic) and introduce locking in some other way. Is this possible?


答:
My experiences with server side "frameworks" have been pretty unpleasant, for example:

A) Jar file hell where frameworks conflict with each other or the app server for mutually incompatible versions of stuff you don't want and don't know anything about and are not in a position to dictate anyway as it will prevent you from deploying on multiple servers.

B) Catastrophic explosion of the simplest object creation into thousands of unnecessary SQL executions.

C) The bizarre notion that coding 100 lines of XML is somehow easier or more reliable than coding 2 lines of Java.

D) The need to write 100s of lines of completely unnecessary server side POJOS to map onto client side objects in another, or sometimes multiple other languages  (C# JS etc)

E) Not having a clue what really happened when you get a 30-level deep stack trace that doesn't even include the line of code you used to call the framework.

Be a renegade, write your own framework... you won't regret it as long as you plan first to eliminate all the unnecessary stuff the others fool you into thinking you need. Then you will understand all of it, it will ship in Kb instead of Mb and it probably will "run anywhere" which was one of the founding principles of Java wasn't it?

Try thinking this way "why do I need this... is it just to keep the framework happy?" .. If I don't need that, then what else don't I need?

Title: Does it make sense to avoid a framework when building a large webapp with PHP?

Body:
Being a PHP web application developer for several years now, I've had my share of MVCs and frameworks. At first I thought they were the best thing since sliced bread; everything seemed to be very easy to implement.

Now however, it seems that the more complex the application gets, the more hassle the framework introduces, so I have to develop workarounds to overcome them. Such workarounds are usually pretty daunting and complex since I have to delve down into the framework core code and make changes so that it behaves the way I want.

For example, in one of my projects where I use Slim(C)+Idiorm(M)+Twig(V) (which I believe is very flexible), I have to create a custom function just to display dynamic data in parent templates; without a framework I could have simply executed mysql_query() in the included file.

Okay, frameworks are cool if I'm creating a simple company profile website; I can just whip some code in one night and they're usually ready by the morning, and the amount of good coding practice and design patterns I've learned from them is very valuable.

But really, for a complex web application like an all-in-one web based school management system, frameworks usually get in the way of my business process like in the example above.

So my question is: is it okay to just go back to basics, and use standard PHP code and libaries for doing my next project where there might be a gazillion frameworks and libraries, provided I can sufficiently use good coding practices and follow sensible design patterns like MVC? My development team is pretty small: only 2 programmers and 1 designer. The other programmer agrees with my thoughts above.


答:
Testing code in general isn't easy.  If it were, we'd have been doing it all a long time ago, and not making such a bit deal of it only in the last 10-15 years. One of the biggest difficulties has always been in determining how to test code that has been written cohesively,  and well factored, and testable without breaking encapsulation. The BDD principal suggests we focus almost entirely on behavior, and in some ways seems to suggest that you don't really need to worry about the inner details to such a large degree, but this can often make things quite difficult to test if there are a lot of private methods that do "stuff" in a very hidden way, as it can increase the overall complexity of your test to deal with all the possible outcomes at a more public level.

Mocking can help to a certain extent, but again is fairly externally focused. Dependency Injection can also work quite nicely, again with mocks or test doubles, but this can also require that you expose elements either via an interface, or directly, that you might have otherwise preferred to remain hidden - this is particularly true if you wish to have a nice paranoid level of security about certain classes within your system.

For me, the jury is still out about whether to design your classes to be more easily testable. This can create problems if you find yourself needing to provide new tests while maintaining legacy code. I accept that you should be able to test absolutely everything in a system, yet I don't like the idea of exposing - even indirectly - the private internals of a class, just so that I can write a test for them.

For me, the solution has always been to take a fairly pragmatic approach, and combine a number of techniques to suit each specific situation. I use a lot of inherited test doubles to expose inner properties and behaviors for my tests.  I mock everything that can be attached to my classes, and where it won't compromise the security of my classes, I'll provide a means to override or inject behaviors for the purposes of testing. I'll even consider providing a more event-driven interface if it will help improve the ability to test code

Where I find any "untestable" code, I look to see if I can refactor to make things more testable. Where you have a lot of private code doing hidden behind the scenes stuff, often you'll find new classes waiting to be broken out. These classes might be used internally, but can often be tested independently with less private behaviors, and often subsequently less layers of access and complexity. One thing I do take care to avoid however is writing production code with test code built in.  It can be tempting to create "test lugs" that result in including such horrors as if testing then ..., which indicates a testing problem not fully deconstructed and incompletely solved.

You might find it helpful to read Gerard Meszaros' xUnit Test Patterns book, which covers all of this sort of stuff in much greater detail than I can go into here. I probably don't do everything he suggests, but it does help to clarify some of the trickier test situations to deal with.  At the end of the day, you want to be able to satisfy your testing requirements while still applying your preferred designs, and it helps to have a better understanding of all of the options in order to better to decide where you might need to compromise.


问:
What does it mean to be agile?
We have a project that everyone says we will be doing in a agile way but I doubt we have clearly understood what agile is.

In previous projects we had planning meetings, then defined the product back log and allocated the work to developers in 2 to 3 week sprints. Every morning we had scrum meetings (which seemed to go on for 1/2 an hour each time) and each developer got on with it after that. Hardly anyone wrote any tests until at the end of sprint and work that was not completed was added on to the next sprint.

Developers hardly spoke to each other and there was no TDD involved in development. In fact most developers had a spec at the start and just got on with it for the 2 or 3 weeks the sprint was arranged for. There was hardly any communication with the client/stake holder.

QA got involved usually a few months later and by then we found missing requirements which further increased the amount of work we had to do. Clearly there was no feedback loop.

So my question is, where did we go wrong and how can I prevent the team from making the same mistakes.

答:
Jarrod provided a good answer (+1 to that) and I'd like to extend on that a little.

Agile isn't just about rapid failures and feedback between product owner(customer) and the team; it is about rapid feedback between all stakeholders involved. To be truly agile (and this is directly from the manifesto) is to recognize that process exists only to help developers in delivering better product. People above process means that as soon as the team recognizes your existing process doesn't work, you change it and make it work.

"Scrum but..." is also an issue, but there's both sides to this coin. If you look at the manifesto you'll see that it's about the team and making tools/processes work for you. No two teams are the same and therefore each will operate slightly differently and that's ok. You could certainly, take the entire Scrum methodology and try to follow it to the letter and see if that works for your team.

Another alternative is instead of pushing another process onto the team and making everyone follow what Scrum tells you to do, try the agile approach: Communicate with the team and see if together you can identify problem areas and solutions for each one. Then gradually introduce changes in the way you work so that problems are addressed.

It might take a little while, but...

You will fix biggest issues first which will have the largest impact on your teams ability to deliver product

By identifying immediate problems and participating in coming up with solutions, your team members will understand why certain practices are important and won't simply do them because they are told to do them.

If we draw an analogy between Scrum and a design pattern, working the way I proposed would be similar to coding into a pattern, where you keep code as simple as possible and only converge on a design pattern when needed. As opposed to just picking a design pattern and rolling with it (i.e. blindly selecting Scrum and all its processes as one set), which sometimes makes the code more complex and harder to maintain than it could have been otherwise.

The key to understand is that agile is not about coming up with a new process for doing things; it's about continuous change and constant adjustment to existing processes/practices.

Title: What does it mean to be agile?


问:
Source/Version control for application used by multiple companies
Do you find it easier to keep a branch for each company that uses software you support/develop? Each company will want "customizations" and I am just trying to figure out the best way to handle those changes. A branch for each company makes sense in the short term but I could see how this could cause issues with upgrades when a new version is developed.

Is better to have a branch for each company or to setup customizations so that they are always merged to a main branch to minimize issues with future releases?

答:
The last thing you want is different versions of your source code for different clients. Keeping all those versions synchronized as you add features and fix bugs is going to be a huge pain, and the longer you operate that way, the more difficult it'll be to fix the problem.

A much better solution is to make you software configurable in all aspects that your clients want to customize, and the create separate configuration files for each client. You don't necessarily have to deliver the config files to the clients -- the configurations might be source files that get built into each version that you deliver to a client, if you do separate builds for each client. Eventually, though, as your client list grows, it'll probably be easier to build a single binary that you deliver to all clients along with customized config files.