问:
Single Responsibility Principle Implementation
In my spare time, I've been designing a CMS in order to learn more about actual software design and architecture, etc.

Going through the SOLID principles, I already notice that ideas like "MVC", "DRY", and "KISS", pretty much fall right into place. That said, I'm still having problems deciding if one of two implementations is the best choice when it comes to the Single Responsibility Principle.

Implementation #1:

```<code>class User
    getName
    getPassword
    getEmail
    // etc...

class UserManager
    create
    read
    update
    delete

class Session
    start
    stop

class Login
    main

class Logout
    main

class Register
    main
</code>```

The idea behind this implementation is that all user-based actions are separated out into different classes (creating a possible case of the aptly-named Ravioli Code), but following the SRP to a "tee", almost literally.

But then I thought that it was a bit much, and came up with this next implementation

```<code>class UserView extends View
    getLogin //Returns the html for the login screen
    getShortLogin //Returns the html for an inline login bar
    getLogout //Returns the html for a logout button
    getRegister //Returns the html for a register page
    // etc... as needed

class UserModel extends DataModel implements IDataModel
    // Implements no new methods yet, outside of the interface methods
    // Haven't figured out anything special to go here at the moment
    // All CRUD operations are handled by DataModel
    //   through methods implemented by the interface

class UserControl extends Control implements IControl
    login
    logout
    register
    startSession
    stopSession

class User extends DataObject
    getName
    getPassword
    getEmail
    // etc...
</code>```

This is obviously still very organized, and still very "single responsibility". The User class is a data object that I can manipulate data on and then pass to the UserModel to save it to the database. All the user data rendering (what the user will see) is handled by UserView and it's methods, and all the user actions are in one space in UserControl (plus some automated stuff required by the CMS to keep a user logged in or to ensure that they stay out.) I personally can't think of anything wrong with this implementation either.

In my personal feelings I feel that both are effectively correct, but I can't decide which one would be easier to maintain and extend as life goes on (despite leaning towards Implementation #1.)

So what about you guys? What are your opinions on this? Which one is better? What basics (or otherwise, nuances) of that principle have I missed in either design?

答:
I've always considered the single responsbility principle more of a philosophy than principle.

Robert C. Martin (Uncle Bob) restates the Single Responsibility Principle (linked to PDF):

There should never be more than one reason for a class to change

Quoted from the reply you got your post.

When we try to appease the SPR, we focus on the implementation rather than on the purpose.

Major mistake.

My understanding of the SRP is this,  when an addition blurs the responsibility of an implementation, the focal point should be reconsidered.

For me, it is all about the relationships between purposes.

Sure, a user has to be authenticated and authorized regarding actions to take - but the authentication and authorization should be separated from the user.

It's not like you are going to try to authorize/authenticate a non-user anyway?

And thus, you should consider splitting implementation when the responsibilities of a class outgrows it purpose. After all, design patterns have purposes too.

Take a look at GRASP when you get a chance.


问:
What's the best way to learn image processing?
I'm a senior in college that hasn't done much image processing before (except for some basic image compression on smartphones). I'm starting a research project on machine learning next semester that would require some biomedical image processing. What's the best way to get up to speed with the basics of image processing in about two months? Or is this impractical?

It's my impression that once I'm good with the basics learning more from other resources would be easier.

答:
I don't think you can learn much in 2 months. Image processing is really broad field, and to get better in it you'll need at least several years.

Some of the very basics stuff you can do :

take a look into 2d filters (or better yet find a book describing 2d image filtering).

get octave and try to play with some filters. Try to process images on your own

join processing group, and follow sci.image.processing news group

try to play with opencv filters, although I think it is an advanced field

By the way, I hope your math is really good.

ContentLicense: CC BY-SA 3.0


问:
What should I mock in tests of an application with service tier and DAO tier?
My classes are following this structure

Service Tier (creates and maps InputDTO to DB Data)

DAO Tier (actually executes DB calls)

When I write service tier JUnit tests, the DAO tier is called, and this expects an actual DB connection and getting data from the DB.

Should I be mocking the DAO tier completely from the service tier, or should I be mocking the DB connection and data received from the DB?

Secondly, the app expects certain data from a cache.

For JUnit run time, there is no cache, so how should this be handled? The service tier method includes looking up the cache to get the details.

答:
I'm going to talk about Test Doubles, if you haven't run across this term then you'll probably wan to read Martin Fowler's article link first.

For the Database testing - If you are following a pure Unit testing approach then you would use a Stub or a Mock type of Test Double to mock out the DB connection and its responses. If you are using a Mock then I would recommend using Mockito, JMock or your other favourite mocking tool.  However, this is quite laborious when it comes to testing a large third party resource such as a database.

For the Database testing - If you are following a slightly looser definition of unit testing, then you could use a Fake Test Double. In your particular case, this would be an in memory database such as HSQL.  This is a very popular way of 'unit' testing your database layer. Some will argue that this is not unit testing, and that it is integration testing instead. I think that's actually OK - the fact of the matter is, you have some tests excising your code :-)

For the cache testing - A Stub style of Test Double is likely to be your friend here - depending on how complex the cache API is.

HTH!


答:
Books are good if you are already knowledgeable about something. But if you are just starting out, a real course is better. For the human brain, is easier to learn something from another person, rather than from an inanimate book.

Anyhow it is not always possible to follow a course at your local college, or maybe you want to have the best possible education, without having to pay for the most expensive tuition.

This is why I love to follow courses online. I prefer american colleges, but Lecture 1 Introduction to Digital Image Processing seems good too.

Luckily, there are online courses for almost everything in the IT, and for most of the scientific courses: You don't need to be at MIT to get an MIT-grade education, without paying a cent. This is  Great way to improve your skills and thus your market value.

Take your time to have a look here:

MIT OpenCourseWare

Columbia Interactive

Harvard online courses

Youtube

Title: What's the best way to learn image processing?

Body:
I'm a senior in college that hasn't done much image processing before (except for some basic image compression on smartphones). I'm starting a research project on machine learning next semester that would require some biomedical image processing. What's the best way to get up to speed with the basics of image processing in about two months? Or is this impractical?

It's my impression that once I'm good with the basics learning more from other resources would be easier.


答:
It's hard to tell what exactly you want to test because judging from the question you're all over the place. Thus it is hard to give you any practical example on how to proceed other than lead you to articles on how to mock stuff. So you need to be more specific and split things up a bit:

Do you want to test so that the cache works properly?

Do you want to test some DB call in particular?

Do you want to test the app so that it is using the cache correctly?

Once you decide exactly what the unit is that you want to test, then selecting what to mock becomes easy: in a pure unit test, everything but the "unit under test" should be mocked. The rationale behind this is that you can be sure from your set up expectations on the mocks that the tested unit works as it should.

Other than that, you might want to write some tests in JUnit that are integration tests, i.e. use less mocks. Even if they're used as sanity checks to see if the software design is correct you should be aware that they will be brittle and won't always give any indicator on what exactly is wrong with your app or system.

Title: What should I mock in tests of an application with service tier and DAO tier?

Body:
My classes are following this structure

Service Tier (creates and maps InputDTO to DB Data)

DAO Tier (actually executes DB calls)

When I write service tier JUnit tests, the DAO tier is called, and this expects an actual DB connection and getting data from the DB.

Should I be mocking the DAO tier completely from the service tier, or should I be mocking the DB connection and data received from the DB?

Secondly, the app expects certain data from a cache.

For JUnit run time, there is no cache, so how should this be handled? The service tier method includes looking up the cache to get the details.


问:
What kind of test should be given to Java EE programmers?
I'm looking to hire developers and I wish to test them. I have been especially told by my boss that we should have programmers on board that can consult on banking sector software and I'm to come up with the test. Now I've never done Java EE development in depth and my knowledge of it isn't the greatest but I've not had any trouble understanding what I've read so far.

Now I'm wondering how to construct a test to test candidates for Java EE knowledge as well as experience. And if I should make the test more conceptual like logical reasoning and pattern detection etc.

答:
Just listen ;)
They explain it to you in depth: Roundup '11 - Interviewing and Hiring Software Engineers Fully

http://javaposse.com/java-posse-368-roundup-11-interviewing-and-hiring
http://www.developerfusion.com/media/132147/roundup-11-interviewing-and-hiring/


答:
RESTful FizzBuzz

Give them a computer, full access to the Internet, and a fresh install of Eclipse. Say to them that you'd like them to implement the FizzBuzz program. Once they've completed that, ask them if they could create a RESTful web service that provides the FizzBuzz answer using a JAX-RS URI definition like this:

http://localhost:8080/FizzBuzz/{value}

Then sit with them as they go about it, asking and answering questions. If they can do that reasonably efficiently then you've got most of what you need to know.

Title: What kind of test should be given to Java EE programmers?

Body:
I'm looking to hire developers and I wish to test them. I have been especially told by my boss that we should have programmers on board that can consult on banking sector software and I'm to come up with the test. Now I've never done Java EE development in depth and my knowledge of it isn't the greatest but I've not had any trouble understanding what I've read so far.

Now I'm wondering how to construct a test to test candidates for Java EE knowledge as well as experience. And if I should make the test more conceptual like logical reasoning and pattern detection etc.


问:
How many are too many interfaces on a class?
I would probably consider it a code smell or even an anti-pattern to have a class that implements 23 interfaces. If it is indeed an anti-pattern, what would you call it? Or is it simply just not following the Single responsibility principle?</p>

答:
23 is Just a number! In most likely scenario, it is high enough to alarm. However, if we ask, what is the highest number of methods/interfaces before it can get a tag to be called as an "anti-pattern"? Is it 5 or 10 or 25? You realize that number is really not an answer because if 10 is good, 11 can also be - and then any integer after that.

The real question is about complexity. And we should point out that lengthy code, number of methods or large size of the class by any measures is actually NOT the definition of complexity. Yes, a larger and bigger the code (larger number of methods) does make it difficult to read and grasp for a new beginner. It also handles potentially varied functionality, large number of exceptions, and quite evolved algorithms for various scenarios. This doesn't mean it is complex - it is only difficult to digest.

On the other hand, relatively small size code which one can hope to read out in a few hours in and out- can still be complex. Here is when I think the code is (unnecessarily) complex.

Every piece of wisdom of Object-oriented design can be put in here to define "complex" but I would restrict here to show when "so many methods" is an indication of complexity.

Mutual Knowledge. (a.k.a coupling)
Many a times when things are written as classes, we all think it is "nice" object oriented code. But assumption about the other class essentially breaks the real needed encapsulation. When you have methods which "leak" deep details about the internal state of the algorithms - and the application is built with key assumption about the internal state of the serving class.

Too many repeats (breaking in )
When methods which have similar names but do contradicting work - or contradicting names with similar functionality. Many a times codes evolve to support slightly different interfaces for different applications.

Too many roles
When class keeps adding side functions and keep expanding more as people like it, only to know that the class indeed is now a two class. Surprisingly these all start with genuine requirements and no other class exist to do this.
Consider this, there is a class Transaction, which tell details of transaction. Looks good so far, now someone requires format conversion on the "time of transaction" (between UTC and like), later on, people add rules to check if certain thing were on certain dates to validate invalidate transactions. - I wont write the whole story but eventually, the transaction class builds the entire calender with in it and then people start using "only the calender" part of it! This is very complex (to imagine) why will I instantiate "transaction class" to have functionality that a "calender" would provide me!

(In)consistency of API
When I do book_a_ticket() -  I book a ticket! That's very simple irrespective of how many checks and processes it goes to make it happen. Now it becomes complex when time flow starts effecting this. Typically one would allow "search" and possible available/unavailable status, then to reduce back-n-forth you start saving some context pointers inside the ticket an then refer that to book the ticket. Search is not the only functionality- things become worse after many such "side functionality". In the process the meaning of book_a_ticket() implies book_that_ticket()! and that can be unimaginably complex.

Probably there are many such situations you would see in a very evolved code and I am sure that many people can add scenarios, where "so many methods" just doesn't make sense or doesn't do what you would obviously think. This is the anti-pattern.

My personal experience is that when projects that starts reasonably bottom up, many things for which there should have been genuine classes on their own -remains buried or worse still remains split between different classes and coupling increases. Most often what would have deserved 10 classes, but has only 4, it is likely that many of them have multi-purpose confusing and large number of methods. Call it a GOD and DRAGON, this is what is BAD.

BUT you do come across VERY LARGE classes which are neatly consistent, they do have 30 methods - and are still very CLEAN. They can be good.


答:
One way I like to do this is to start building your classes ignoring your entire structure.

And then follow a general rule of 3.

If you end up with more than 3 public functions, break them up into separate classes.

If you end up with more than 3 internal variables, break it up into separate classes.

If you end up with more than 3 functional lines in your function, separate it into different functions.

This way you don't have to angst over whether or not you have your structure correct.  You can be fluid with your development.  This process of coding is easier if you have unit tests or do TDD in general, but it is not 100% required. It also removes some mental overhead for your brain.

I find I will sometime worry so much about the structure and agonize over it so much, that as time goes on, I'm too attached to the structure and I'm less willing to adapt when I need to.

Title: Single Responsibility Principle Implementation

Body:
In my spare time, I've been designing a CMS in order to learn more about actual software design and architecture, etc.

Going through the SOLID principles, I already notice that ideas like "MVC", "DRY", and "KISS", pretty much fall right into place. That said, I'm still having problems deciding if one of two implementations is the best choice when it comes to the Single Responsibility Principle.

Implementation #1:

```<code>class User
    getName
    getPassword
    getEmail
    // etc...

class UserManager
    create
    read
    update
    delete

class Session
    start
    stop

class Login
    main

class Logout
    main

class Register
    main
</code>```

The idea behind this implementation is that all user-based actions are separated out into different classes (creating a possible case of the aptly-named Ravioli Code), but following the SRP to a "tee", almost literally.

But then I thought that it was a bit much, and came up with this next implementation

```<code>class UserView extends View
    getLogin //Returns the html for the login screen
    getShortLogin //Returns the html for an inline login bar
    getLogout //Returns the html for a logout button
    getRegister //Returns the html for a register page
    // etc... as needed

class UserModel extends DataModel implements IDataModel
    // Implements no new methods yet, outside of the interface methods
    // Haven't figured out anything special to go here at the moment
    // All CRUD operations are handled by DataModel
    //   through methods implemented by the interface

class UserControl extends Control implements IControl
    login
    logout
    register
    startSession
    stopSession

class User extends DataObject
    getName
    getPassword
    getEmail
    // etc...
</code>```

This is obviously still very organized, and still very "single responsibility". The User class is a data object that I can manipulate data on and then pass to the UserModel to save it to the database. All the user data rendering (what the user will see) is handled by UserView and it's methods, and all the user actions are in one space in UserControl (plus some automated stuff required by the CMS to keep a user logged in or to ensure that they stay out.) I personally can't think of anything wrong with this implementation either.

In my personal feelings I feel that both are effectively correct, but I can't decide which one would be easier to maintain and extend as life goes on (despite leaning towards Implementation #1.)

So what about you guys? What are your opinions on this? Which one is better? What basics (or otherwise, nuances) of that principle have I missed in either design?


问:
Is a MSDN subsciption worthwhile for personal use?
I code primarily in .net at work, but was wondering if home MSDN subscriptions were available/worthwhile as a tool to stay in touch with the latest technology for Microsoft development?</p>

答:
Probably not, unless you're actively working on long-term projects and/or making money on the side.

For everything else, there's the express versions of most of the software.

ContentLicense: CC BY-SA 2.5


问:
How do I develop in more languages with less IDEs
I would like to set up my computer so that I can develop in .net, C#, Java, ActionScript,  JS/CSS, and functional languages such as Scala or Haskell.  However, I want to do this with the least amount of full-featured IDEs to learn / programs taking up harddrive space on my computer / running multiple IDEs simultaneously.

Which programs can I use to minimize the amount of full-featured IDEs I have to learn/use.  (For example, if Eclipse could handle all of these frameworks, that would be a valid answer)

Edit:  Seems this question is still getting hits many years later. Today, (2018) I use Visual Studio Code as my "one IDE to rule em".

答:
I wouldn't try to use one less-than-optimal IDE for all my development. I would rather spend my time learning the best IDE for the language instead of hacking/tweaking a single IDE so that you can use it for something that it wasn't meant to be used for.

There is no silver bullet here.

You will need Visual Studio for .NET development.
You will need Adobe tools for Flash development.

For Java and JS/CSS I recommend Jetbrains IntelliJ IDEA and Webstorm.
There tools are made by the same vendor so they are similar, pretty feature rich yet the learning curve is quite ok. They also do not take that much disk space, if that is really one of your concerns.

As pointed out by FinnNk, you can configure most (all?) of the IntelliJ IDEs to use Visual Studio keyboard shortcuts...or you can configure Visual Studio to use IntelliJ keyboard shortcuts.

ContentLicense: CC BY-SA 4.0


答:
Eclipse can handle most of the languages you mention:

C# with the Improve C# plugin (Dead since 2004),

ActionScript with the Eclipse IDE for ActionScript3 and AS Development Tools plugins

CSS with the CSS Editor,

Haskell with the EclipseFP plugin

Scala with Scala IDE,

And Java is Eclipse's core target language

Regardless Eclipse is not a valid option, as most of the aforementioned plugins are in various alpha states and running an Eclipse instance with all of them would enormously stress your hardware.

Even with great hardware, the plugins will rarely offer everything a specialize IDE will offer. Also I don't see any valid reason to running multiple IDEs, how many platforms can you code for simultaneously? If what you need is mostly to read code written in different languages or write fairly small programs you could choose Notepad++, that supports syntax highlighting on an impressive number of languages.

But to actually program in the languages you mention, I'd recommend to use different IDEs:

Eclipse for Java, Haskell and Scala,

Visual Studio for everything related to .Net,

Adobe Flash Builder for ActionScript,

Aptana Studio for HTML, CSS, JavaScript, PHP, and Ruby

Adobe Flash Builder and Aptana Studio are based on Eclipse so if you go with those you will at least get similar IDEs.

Title: How do I develop in more languages with less IDEs

Body:
I would like to set up my computer so that I can develop in .net, C#, Java, ActionScript,  JS/CSS, and functional languages such as Scala or Haskell.  However, I want to do this with the least amount of full-featured IDEs to learn / programs taking up harddrive space on my computer / running multiple IDEs simultaneously.

Which programs can I use to minimize the amount of full-featured IDEs I have to learn/use.  (For example, if Eclipse could handle all of these frameworks, that would be a valid answer)

Edit:  Seems this question is still getting hits many years later. Today, (2018) I use Visual Studio Code as my "one IDE to rule em".


问:
Is it normal to think about a design problem for days with no code written?
Sometimes I stare blankly into space or sketch ideas and write some pseudo codes on paper. Then I scratch it out and start again, then when I think I have the correct solution for the problem I begin writing the code.

Is it normal to think for days without writing any code? Is this a sign that I am approaching the problem entirely wrong? It makes me nervous to not getting any tangible code written in my IDE.

答:
Depending on the problem you are trying to solve, the design phase can take weeks and months (if not years), not just days.

It takes experience to not start bashing out code immediately. Thinking about the architecture and high level design should take days if not longer - definitely something that should happen before you start writing your code.


答: This is completely common.  However if you take a "Test first" or TDD approach, it is less common and might help you formulate your ideas better.</p>

Title: Is it normal to think about a design problem for days with no code written?

Body:
Sometimes I stare blankly into space or sketch ideas and write some pseudo codes on paper. Then I scratch it out and start again, then when I think I have the correct solution for the problem I begin writing the code.

Is it normal to think for days without writing any code? Is this a sign that I am approaching the problem entirely wrong? It makes me nervous to not getting any tangible code written in my IDE.


答:
It's very common and i feel it's a better way to handle and understand things. While working on a project, I get stuck many a times and it take a day or two to understand as to how can i approach it better. Even after the problem is solved, i wait for a day to pass. This makes me more refreshed and get going.

It's a natural phenomenon and good for a developer to intercept his mind time and between.


问:
Is cloud computing just a way of renting resources?
The company I work at recently hosted a web service in Windows Azure and announced that. Now trade online magazines say lots of meaningless stuff like "company X moves to the cloud", "company X drops desktops for the cloud", etc.

Looks like there're lots of materials out there (starting with Wikipedia) that are very lengthy and talk a lot about "services" and "low entry price" and other stuff but I've read all that and don't see how they could be helpful for a layman in drawing a line between a service in a cloud and Stack Exchange that is also a service but is run on brick-and-mortar servers in a colocation.

Now from my experience with Windows Azure the real difference is the following. With a cloud the service owner rents hardware, network bandwidth and right to use the middleware (Windows 2008 that is used in Azure roles for example) on demand and also there's some maintenance assistance (like if the computer where a role is running crashes another computer is automatically found and the role is redeployed). Without a cloud the service owner will have to deal with all that on his own.

Will that be the right distinction?

答:
Yes, pretty much.

With the "cloud" (as in "cloud providers"), you are renting the diskspace, bandwidth, CPU and memory owned by the provider and the means to use them from your software. They give you the infrastructure and you don't own the hardware.

There are other forms of cloud computing that don't involve these providers, where you (the organisation) owns the hardware as well.

In either regard, this mostly means that your software is running on a distributed network of computers, available on the Internet.


答:
Habits are usually a result of trial and error approaches to things and continuing what gives us the desired results and avoiding what doesn't. Doing what we like and avoiding what we dislike comes into play as well. That works up to a point because eventually, we'll do something we don't like in order to get the rent paid.

It depends what lead you to this and your reasons. Here are a few:

Too often, you've had to change code because of design changes

You don't change a poor design because the lesser solution was already coded

You would rather draw and design than write code-procrastination

having to worry about the syntax and details of coding, distracts you from thinking about better designs.

Hopefully, you've discovered that if you design longer, your code is better. If you can look back and see that it doesn't matter how long you spend on design, you may want to change. Another consideration is how often you are discovering problems after you've written code compared to working with your designs. If you are not finding issues until after you write some code, you should consider a balance and get to coding something sooner rather than later. Maybe this approach could be applied to the use of newer technologies or a very complex feature.

I don't know if I have the discipline to stick with one approach or the other even when I discover one works better than the other. Sometimes I feel a need to go to the white board; others the keyboard.


答:
For languages that have them you're best off using best of class IDEs - they're not really that different. See other answers for suggestions.

For the ones that don't then I suggest you use a more heavyweight text editor - such as emacs (which also doubles up as a file system browser, mail and news reader, gaming platform, birthday greetings generator, etc, etc, etc). These will often have decent plugins/settings/modes that get you most of what a simpler IDE will give you.


问:
Should a developer adhere to the class diagrams produced during system design?
The class diagram is modeled on the system requirements, and it is important to create solutions based on those requirements. If I have said class diagram should I strictly adhere to it? What about refactoring? What if the diagram did not provide some design principle that I feel were left out?</p>

答:
The following points are presented for you to consider before making your decision, the idea is to examine the factors that would generally affect a case such as yours.

Point 0: You need to implement all the business rules whatever your implementation style may be.

Point 1: In UML, Class Diagrams are only part of the entire model. There are other diagrams that utilize defined classes such as Use Case, Sequence, etc.

Point 2: In OO applications using RDBMS you need to decide whether your application is built using an Object First Approach or a Data First Approach. Based on this the domain model is built. The two types of model may be very different. See: Object Relational Imp. Missmatch.

Point 3: In OO and partially as a result of point #3, objects representing the database layer may be different from objects that are used in other application layers or services. If you are using web services, then chances are the API would even define objects in a different way than you business layer definition and the data layer definition.

Point 4: UML models have phases, usually defined by a methodology as in Mapping Models to Dev. Process, each phase may produce a different model. Changing an implementation phase model is of course, the least desirable and most critical due to its impact.

Point 5: You should consider the impact of change on the project life cycle stage, its existing data if any and on other fellow workers and DBAs.


答:
For personal use? Most likely. A MSDN subscription usually pays for itself over time. Aside from getting the latest version of Windows for free, there's plenty of other software/perks available (Free 1 year XNA Creators Club premium subscription).

For development purposes? Unless you want to develop for Windows Mobile/Phone 7, you're better off using express versions of Visual Studio since Windows and Visual Studio Professional are the common reasons why people have MSDN subscriptions

Title: Is a MSDN subsciption worthwhile for personal use?

Body: I code primarily in .net at work, but was wondering if home MSDN subscriptions were available/worthwhile as a tool to stay in touch with the latest technology for Microsoft development?</p>


答:
Cloud computing says absolutely nothing about who owns the resources. Cloud computing is an architecture for developing distributed, network-based applications. There are a number of cloud computing service providers out there, such as Azure Services Platform, Amazon Web Services, Google App Engine, and a number of others. However, using someone else's service is not a prerequisite for developing a cloud computing infrastructure.

The idea behind cloud computing is that you put services and applications on networked devices. You could utilize a hosting service, which would shift maintenance and support to other entities. You could also create your own infrastructure for cloud computing. In addition, there is nothing that says that cloud computing must be public. Yes, you can put your applications and services on the public Internet (with the appropraite security for your applications), but you can also create private clouds within your organization.

In the end, with cloud computing, you don't know where or what you are accessing. You see a service or application without any knowledge of what is behind that service or application. The entire cloud is of no consequence to clients - you know that things that you can use exist, are accessible, and use them. They could be in a "server room", or you could be accessing a distributed grid of sensors and workstations. It really doesn't matter.

Title: Is cloud computing just a way of renting resources?

Body:
The company I work at recently hosted a web service in Windows Azure and announced that. Now trade online magazines say lots of meaningless stuff like "company X moves to the cloud", "company X drops desktops for the cloud", etc.

Looks like there're lots of materials out there (starting with Wikipedia) that are very lengthy and talk a lot about "services" and "low entry price" and other stuff but I've read all that and don't see how they could be helpful for a layman in drawing a line between a service in a cloud and Stack Exchange that is also a service but is run on brick-and-mortar servers in a colocation.

Now from my experience with Windows Azure the real difference is the following. With a cloud the service owner rents hardware, network bandwidth and right to use the middleware (Windows 2008 that is used in Azure roles for example) on demand and also there's some maintenance assistance (like if the computer where a role is running crashes another computer is automatically found and the role is redeployed). Without a cloud the service owner will have to deal with all that on his own.

Will that be the right distinction?


问:
How can I test PHP skills in a interview?
My company needs to hire a PHP developer, but nobody has PHP knowledge in my company and we find difficult to test for PHP skills. If it were a C/Java developer I would ask him to write a quick implementation of the Game of Life, but PHP is a completely different language.

I saw this test with interest:

http://vladalexa.com/scripts/php/test/test_php_skill.html

Anyone else has more suggestions?

答:
While Yannis Rizos's answer is a good one - I know I wouldn't pass that test and I might use that answer as a resource to determine where to focus to improve my PHP chops, I think it would be worth your while to find a programming buddy who knows PHP to sit in on the interview process.  All the questions in the previous answer are good, but without some domain knowledge it's going to be hard to assess the quality of the answers.

That said, depending on what you need as others have said general programming facility and team fit are probably more important than language-specific knowledge.


答:
No. Cloud computing is not merely a way to rent resources.

Cloud is all about services that:

are delivered over the network (possibly the Internet)

are fully controlled by API

are fully automatable and automated

require no human interaction for control

are delivered as a commodity

are billed like a utility: for measured usage

require no capital expenditure or up-front payment

have seemingly infinite capacity

permit at-will immediate allocation of arbitrarily many units of the service

permit at-will immediate disposal of arbitrarily many units of the service

NIST has a full definition of what a cloud service is.


答:
This is commonly referred to as "Analysis Paralysis"

It's common but wrong. At some point you need to test out the various ideas to see what will work best for you, then incrementally improve on it.

Recommended reading the Pragmatic programmer Specifically Chapter 2 the section on "Tracer Bullets"


答: When I took a course in project management, one of the things the instructor related to us about planning, that stuck in my head, was that the rule of thumb that they taught in the military was to figure 1/3 of the time for planning.  So if you had an operation that required you to be complete 3 months from now, figure on spending one month on planning before you start execution.</p>


问:
Multiuser System With Encrypted Database
I am currently developing a hosted solution in ASP.NET using MVC3 and Entity Framework. This product will then be made available to a number of clients as a hosted solution.

As the data stored by each client will be critical to their business, we anticipate that many of them will insist that the data is stored in an encrypted form in the database. We are therefore designing the system with this in mind.

Are there any recommended procedures for doing this? How would one go about encrypting the clients data in such a way that even us with root access to the database cannot possibly access their data?

I believe there is no built in support in EF for encrypted data, is this true? And if so, how would one encrypt/decrypt the data?

答:
In a purely technical sense, encrypting the database such that the admins can't read the data is pretty tricky -- somewhere something has to decrypt something to show it to users so the key tends to live somewhere in the system so someone with root access could always decrypt the data.

Insofar as encrypting the data, if you can swing an Sql Enterprise license Sql server could do it for you. But that really doesn't get you much unless your database server is on an untrusted network in the first place. I would focus my efforts on designing the app so each customer had a separate database as well as building a strong audit trail to discourage nefarious behavior.


答:
.Net has encryption libraries

Give each Client their own encryption key, that is stored on there servers. The Client encrypts the data then sends it to you for insertion. The DB returns encrypted Data that the Client has to decrypt.

Problem is... You can't help the client if they lose the Key, NOBODY CAN.

But that seems to be the business case (from what I am reading) so...

(You can also encrypt the data again after the client sends you the data so there is essentially a "2 Key" lock on the data.)

Title: Multiuser System With Encrypted Database

Body:
I am currently developing a hosted solution in ASP.NET using MVC3 and Entity Framework. This product will then be made available to a number of clients as a hosted solution.

As the data stored by each client will be critical to their business, we anticipate that many of them will insist that the data is stored in an encrypted form in the database. We are therefore designing the system with this in mind.

Are there any recommended procedures for doing this? How would one go about encrypting the clients data in such a way that even us with root access to the database cannot possibly access their data?

I believe there is no built in support in EF for encrypted data, is this true? And if so, how would one encrypt/decrypt the data?


答:
Learn vim or emacs. You can program just about any language with either of those. You won't have the crutches provided by some IDEs, but you really don't need them. You can become a better programmer when you rely on your brain more and intellisense less.

Both vim and emacs have a big lot of features and extensions (or plugins) to facilitate coding (including things related to APIs, that you won't need to "memorize blindly"). Many programming languages (even academic ones) have their emacs mode and/or vim plugins or extensions. And many Linux distributions are packaging these.


问:
Using static classes as namespaces
I have seen other developers using static classes as namespaces

```<code>public static class CategoryA
{
    public class Item1
    {
        public void DoSomething() { }
    }
    public class Item2
    {
        public void DoSomething() { }
    }
}

public static class CategoryB
{
    public class Item3
    {
        public void DoSomething() { }
    }
    public class Item4
    {
        public void DoSomething() { }
    }
}
</code>```

To instantiate the inner classes, it will look like the following

```<code>CategoryA.Item1 item = new CategoryA.Item1();
</code>```

The rationale is that namespaces can be hidden by using the "using" keyword. But by using the static classes, the outer-layer class names have to be specified, which effectively preserves the namespaces.

Microsoft advises against that in the guidelines. I personally think it impacts the readability. What are your thoughts?

答:
First of all, every class should be in a namespace, so your example would actually more be like:

```<code>SomeNamespace.CategoryA.Item1 item = new SomeNamespace.CategoryA.Item1();
</code>```

That said, I see no benefit of this kind of code gymnastics when you can just as well define such a namespace:

```<code>namespace SomeNamespace.CategoryA { ... }
</code>```

If you are maybe some day thinking of storing some static methods on upper class level, this could make sense, but still is not what C# creators have in mind, and might just make it less readable to others — I would waste a lot of time thinking WHY you did this, and thinking if I am missing some source file that would provide explanations.

Title: Using static classes as namespaces

Body:
First of all, every class should be in a namespace, so your example would actually more be like:

SomeNamespace.CategoryA.Item1 item = new SomeNamespace.CategoryA.Item1();

That said, I see no benefit of this kind of code gymnastics when you can just as well define such a namespace:

namespace SomeNamespace.CategoryA { ... }

If you are maybe some day thinking of storing some static methods on upper class level, this could make sense, but still is not what C# creators have in mind, and might just make it less readable to others — I would waste a lot of time thinking WHY you did this, and thinking if I am missing some source file that would provide explanations.


答:
Cloud computing begins with Renting hard disks to servers. However, it goes beyond that much more. This is not to say that there isn't any hype about it; but i am trying to define what is the key difference between being in cloud and not so!

In my office we have a set of servers, which i can access from anywhere. Does this qualify to be a cloud? NO! And so is true for many data centers as is.

The core element that forms cloud computing is of course, the hardware infrastructure (servers and disk space) used exclusively through public internet. However, what is important is how this being managed. A critical infrastructure element (though i doubt if people would disagree if you say must) is the visualization.

In, (what i think) a real cloud, all these servers are combined to become pool of resources tied together over a framework where virtual machines are created. One can create, archive and delete machines. Transfer hard disk space from one machine to another like how you mount them in real machines. These technologies allows that one can shift the data and OS of these machines to move from one physical server to another seamlessly and it comes with various redundancy options and management consoles for services.

Understand, in good old days (as well as today), one used to get personal homepages and company websites - on hosting space. This isn't quite a cloud.

Though, i agree that now-a-days anyone who got a static ip - think he has created a cloud- and indeed the word cloud has been misused to an extent that there is no real definition to it now!


问:
Where did the notion of "one return only" come from?
I often talk to programmers who say "Don't put multiple return statements in the same  method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's confusing." When they show me solutions with a single return statement, the code looks uglier to me. For example:

if (condition)
   return 42;
else
   return 97;
```

<p>"<em>This is ugly, you have to use a local variable!</em>"</p>

<pre class="lang-c prettyprint-override"><code>int result;
if (condition)
   result = 42;
else
   result = 97;
return result;
</code>```

How does this 50% code bloat make the program any easier to understand? Personally, I find it harder, because the state space has just increased by another variable that could easily have been prevented.

Of course, normally I would just write:

return (condition) ? 42 : 97;
```

But many programmers eschew the conditional operator and prefer the long form.

Where did this notion of "one return only" come from? Is there a historical reason why this convention came about?

答:
I wrote a blog post on this topic a while back.

The bottom line is that this rule comes from the age of languages that don't have garbage collection or exception handling. There is no formal study that shows that this rule leads to better code in modern languages. Feel free to ignore it whenever this will lead to shorter or more readable code. The Java guys insisting on this are blindly and unquestioning following a outdated, pointless rule.

This question has also been asked on Stackoverflow


答:
I am not sure this is such a great idea. Switching from one language to another is usually a complete context switch and the cost of this can only be compensated by an IDE that is streamlined to work with that language.

Of course there's emacs, but unless you're willing to invest half a decade into really understand it, you will have trouble finding a multi-language IDE that is mediocre at best in respect to most of the languages.

My suggestion:

SharpDevelop for C# and FlashDevelop for ActionScript (and haXe if you're so inclined). FlashDevelop is mostly written using SharpDevelop, so you will find behaviour is relatively consistent between them. Especially FD has a very low footprint, has a blazing fast autocompletion and UI and boots in a little over 5 seconds on my machine.

Java and Scala work perfectly in one IDE. Whether that's IntelliJ, NetBeans or Eclipse is more a matter of personal preference or religion.

Support for CSS exists in most IDEs in fact. You'd probably want to use an HTML editor that allows zen coding (FD does), preferably one of the editors you're using anyway and write your CSS in the same editor. At the same time you might want to look which of the IDEs in your toolset support LESS css, because it's really a time saver. If the choice is between writing less or writing more but with the support of an IDE, the former is favorable IMHO.

JS is also supported by all IDEs to a certain extent. You might do this in FlashDevelop. Or you might actually use haXe instead, which is well supported by FD. Or you might want to take a look at CoffeeScript and find an IDE which is suitable for it (Eclipse does have a decent plugin, possibly other IDEs do as well).


答: I'd recommend taking something like the jTDS driver and adding encryption to it.  You would have to have some method of mapping client names to encryption keys, but that shouldn't be hard.  And this way, you don't have to do anything in your application itself -- all the encryption and decryption is handled by the driver.  Doing it this way also means you can use third-party database management tools to examine the database -- just make sure they connect to the database using your driver.  It's a non-trivial task, but I think it offers a nice clean solution.  You can do your development using a standard driver, so you can still look at the data once its in the database, and then switch to using the encrypting driver in production.</p>


问:
As the team leader/manager, what kind of role should I seek when we switch to Scrum?
My company wants to start using Scrum, and in real scrum there is no place for a real team leader (manager).

What is the next step for the dev team leader? Should I be a (chief) system architect/tech leader  or search for another job in management?

I like the management part and the technical part and the target is VP R&D/CTO.

答:
...in real scrum there is no place for a real team leader (manager).

Are you interested in having control or leading a team?

There is plenty of room for leadership in "real" scrum.

In scrum, leaders emerge, they are not ordained.

Here are two easy ways to lead in a scrum environment:

When a difficult problem presents itself, weigh in with an informed opinion.

When a team member is blocked or is struggling with an assignment, help out.

at is the next step for the dev team leader? Should I be a (chief) system architect/tech leader or search for another job in management?

  I like the management part and the technical part and the target is VP R&D/CTO.

Titles... They once counted for something. [If you don't believe me, just look at how many VPs work at banks!]

Software professionals change jobs so frequently.
You should focus on acquiring skills, not titles.

Titles will come as a byproduct of your hard work and your recognition as a leader.


答:
Using static classes as namespaces defies the purpose of having namespaces.

The key difference is here:

If you define CategoryA, CategoryB< as namespaces, and when application uses two namespaces :

```<code>CategoryA::Item1 item = new CategoryA::Item1();
CategoryB::Item1 item = new CategoryB::Item1();
</code>```

Here if the CategoryA or CategoryB is a static class rather than namespace, the usage for the application is almost same as described above.

However, if you define it as a namespace and application uses only 1 namespace (doesn't include CategoryB), in that case application can actually use following

```<code>using namespace CategoryA;
Item1 item = new Item1();
</code>```

But had you define CategoryA as a static class the above is undefined!
One is forced to write CategoryA.something every time.

Namespaces should be used to avoid naming conflicts whereas class hierarchy should be used when class grouping has some relevance to the system model.

Title: Using static classes as namespaces

Body:
I have seen other developers using static classes as namespaces

```<code>public static class CategoryA
{
    public class Item1
    {
        public void DoSomething() { }
    }
    public class Item2
    {
        public void DoSomething() { }
    }
}

public static class CategoryB
{
    public class Item3
    {
        public void DoSomething() { }
    }
    public class Item4
    {
        public void DoSomething() { }
    }
}
</code>```

To instantiate the inner classes, it will look like the following

```<code>CategoryA.Item1 item = new CategoryA.Item1();
</code>```

The rationale is that namespaces can be hidden by using the "using" keyword. But by using the static classes, the outer-layer class names have to be specified, which effectively preserves the namespaces.

Microsoft advises against that in the guidelines. I personally think it impacts the readability. What are your thoughts?

Body:
Using static classes as namespaces defies the purpose of having namespaces.

The key difference is here:

If you define CategoryA, CategoryB< as namespaces, and when application uses two namespaces :

CategoryA::Item1 item = new CategoryA::Item1();
CategoryB::Item1 item = new CategoryB::Item1();

Here if the CategoryA or CategoryB is a static class rather than namespace, the usage for the application is almost same as described above.

However, if you define it as a namespace and application uses only 1 namespace (doesn't include CategoryB), in that case application can actually use following

using namespace CategoryA;
Item1 item = new Item1();

But had you define CategoryA as a static class the above is undefined!
One is forced to write CategoryA.something every time.

Namespaces should be used to avoid naming conflicts whereas class hierarchy should be used when class grouping has some relevance to the system model.


问:
Getting non-programmers to understand the development process
When starting a project for a company that's not primarily a programming company, one of the expectations is that there's a finished product at the end free of all bugs and does everything needed right away. However, that's rarely the case.

What are some ways to manage expectations and explain to non-programmers how software development differs from other types of product development?

答: I've answered a similar question in more detail, but the gist is, "Programming is like building a factory or an assembly line."</p>


问:
Is DDD-Lite a pattern language for dependency injection?
I stumbled upon Greg Young's talk 7 Reasons why DDD Projects Fail where he mentions something he calls DDD-Lite at 7:20.

Summarizing, he basically says some use DDD as a pattern languages (entities, repositories, value objects, services, etc) without doing anything else related to DDD. He postulates 60% or more of domain models in .Net are DDD-Lite. He thinks DDD-Lite is basically building up a language around dependency injection, something you don't really need to do. He says either do DDD entirely or do something simpler. Otherwise he claims a person is putting forth all of this work in building good abstractions, but without any real benefits.

I must admit I don't know as much about DDD as I would like, and have not tried to use it yet. I also haven't read Eric Evan's book either. I am much more interested in Dependency Injection and many, many books and blogs on this subject use terms and reference concepts from Eric Evans' DDD book. This is where I've been exposed to DDD concepts. Books I've been reading that do this include:

Dependency Injection in .NET

Microsoft .Net: Architecting Applications for the Enterprise

Brownfield Application Development in .NET

If one wants to do Dependency Injection, what are simpler alternatives over doing "DDD-Lite?" It sounds like to me building good abstractions are quite useful regardless of if one is using concepts from DDD in a "DDD-Lite" way. (see Mark Seemann's blog posts: Interfaces are not abstractions, and Towards better abstractions). I have a hard time believing everyone doing Dependency Injection happens to also be doing (or needs to do) full fledged DDD. Did I somehow misunderstood Greg Young's argument about DDD-Lite?

答:
I bet Greg is referring to the simple application if a subset of Domain-Driven Design patterns instead of the whole DDD approach. The term DDD-Lite implicitly refers to the book http://www.infoq.com/minibooks/domain-driven-design-quickly that used to be popular among DDD newbies, but sot of misses the whole picture by focusing only on the local modeling design patterns.

Though Dependency Injection is considered a good thing, there is no strong correlation between DDD and DI.

OwnerDisplayName: Matt Spinelli


答:
The Jetbrains company has a suite of IDEs with the same ergonomic principles and same keyboard shortcuts and so on.
They cover all the languages you're talking about.
But most of them are not free though.

So my suggestion is:

Resharper for C# and .Net: http://www.jetbrains.com/resharper/

IntelliJ IDEA for the rest: http://www.jetbrains.com/idea/


答:
I hold opinion that it's best to have a separate tool for each language / language bundle. But for some (css+js for example) - there's no point even having an IDE - a text editor with syntax highlighting will suffice.

For Windows - try Notepad++ . On Linux - emacs, vim (which have a learning curve of their own) - or even just gedit.

Have a look at latest NetBeans - it's cross-platform supports a number of languages, but can be a bit sluggish; Aptana Studio is what I currently use for web development.


答:
Whatever is going on here certainly isn't idiomatic C# code.

Maybe these others are trying to implement the module pattern - this would let you have functions, actions and so on as well as classes in the 'namespace' (i.e. static class in this case)?

Title: Using static classes as namespaces


答: While it's hyped as something new, cloud computing really a new marketing twist on the time-sharing distributed computing model emerged in the mid-to-late 1960's. Of course, there are huge technical improvements but, when you look at it closely, it's not too much different from hooking up to a mainframe via an acoustic coupler and a teletype terminal to access applications and data. These systems were huge moneymakers back in their day but the Apple II and IBM PC put an end to it. Now, through cloud computing, this business model is seeing a renaissance.</p>


问:
Should you abandon an ORM framework when you need to implement a bulk operation?
Here's a common situation:

You need to implement a bulk operation in an application that uses an ORM framework.

After the first pass, you've noticed significant performance problems.

Here's my question:

In this situation, should you favor a solution that includes raw SQL?

Or are there well-known design patterns that can help you mitigate problems that are commonly associated with bulk operations with ORM frameworks?

EDIT:

I'm not asking if you should remove the ORM framework from the entire application.

I'm asking: Should you forgo the ORM framework for this small slice of the application?

答:
Well there aren't any design patters that I'm aware of. My guess is that you made the decision for the ORM for a reason, so abandoning the ORM is likely not what you want. However, in these cases I think there is room for mixing both solutions. There's nothing wrong with that, as long as you do it conciously and document why you deviate from the default use of the ORM in you software.
Next to that, some ORM frameworks have some facilities for doing bulk operations. I know nHibernate (ORM for the .NET framework) has socalled StatelessSessions, which have a lot less overhead, but this might still not give you the perfomance boost you're looking for. In that case, just use raw SQL.</p>


问:
How do I deal with a problem that will pop up in a later iteration
This is an Agile development project and I do not have the ability to change that.

The design that will be the fastest and most obvious for the first phase of our project will not be compatible with the needs of our second phase.  The change would not be difficult to implement now but it would take a little more time to implement.

Our PM is pushing for the quick phase 1 approach saying we will deal with the problem in phase 3 when we get there.  Making the change at phase 3 will require refactoring and data transformation will be very intensive.  Is there anything I can or should do now that fits in the agile methodology?

答:
I can understand this sentiment where you know a great deal of refactoring will need to happen in a later iteration based on the user stories of the current iteration.  It is a tough feeling and it drives me nuts sometimes too.

I would generally take a bigger picture of the situation.  If it is not a great deal of work extra in the later sprint then by all means do what you need to do to deliver exactly what is planned for the current iteration.  You can plan accordingly for the refactoring effort later.

If it will likely be an extraordinary amount of work later then I will start asking around about how important this particular sprint is to the stakeholders.  Customers and other stakeholders sometimes don't necessarily care about every single sprint.  Believe it or not Agile methodology tends to be a political pursuit in MANY organizations making sprints a shallow artificial deadline, Eg. Wanting to attract clients and good talent with buzz words like Agile.

If the stakeholders don't have a vested interest in the current sprint then it may be possible to convince them of reprioritizing some of the user stories to where it makes more sense.  I highly urge against extending sprints if possible though.  That sets a dangerous precedent.


答:
You're practicing Scrumerfall. The reference to phases, PM's, etc... leads me to believe that the team has embraced Agile where it feels like it fits, versus changing previous notions and conceptions on how the process works.

In either case, do what you need to do to complete the backlog item. You're theorizing that priorities wont shift in N months. This is one of the concrete concepts of Agile; delivering value in an iterative manner with the possibility to shift direction at a given point in time.

You can and should certainly take a smart approach to your code base, keeping it modular, loose coupling, etc... to aid in the re-factoring effort but the re-factoring effort is something that should exist throughout the process. It's ongoing. It's iterative. It's about making things better. Don't concern yourself with theorizing done, look at the backlog item and allow it to define done.

You can't always build Rome in a day but you can certainly lay the foundation for the future.

Title: How do I deal with a problem that will pop up in a later iteration

Body:
This is an Agile development project and I do not have the ability to change that.

The design that will be the fastest and most obvious for the first phase of our project will not be compatible with the needs of our second phase.  The change would not be difficult to implement now but it would take a little more time to implement.

Our PM is pushing for the quick phase 1 approach saying we will deal with the problem in phase 3 when we get there.  Making the change at phase 3 will require refactoring and data transformation will be very intensive.  Is there anything I can or should do now that fits in the agile methodology?


答:
I use an ORM (nHibernate) in an application that requires high performance and handles billions of records. With time we noticed that most significant performance problems were related to our own way of using the ORM rather than due to the ORM alone.

The ORM should not replace your mandatory database knowledge. It's a tool you use to get more productivity and flexibility in your code, but you'll need to know underlying processes to optimize your performance.

You did not specify a specific ORM so here are the things we did to improve performance:

We used an ORM profiler. (we used nhprof)

We used a database profiler. (we used SQL Server Profiler)

We read as many articles as we can on the subject. (Many were available for nHibernate in addition to the entire chapter on the subject in the documentation)

We bought specific books on performance & scalability.

We created benchmarking system to test our own optimisations.

and more importantly, we were able to test our code with real life customers with huge data. That last thing alone helped us spot most problems in our application.

Title: Should you abandon an ORM framework when you need to implement a bulk operation?

Body:
Here's a common situation:

You need to implement a bulk operation in an application that uses an ORM framework.

After the first pass, you've noticed significant performance problems.

Here's my question:

In this situation, should you favor a solution that includes raw SQL?

Or are there well-known design patterns that can help you mitigate problems that are commonly associated with bulk operations with ORM frameworks?

EDIT:

I'm not asking if you should remove the ORM framework from the entire application.

I'm asking: Should you forgo the ORM framework for this small slice of the application?


答: We managed to do it with Entity Framework, but our application did a lot of batch-style operations (we'd write large numbers of records to individual tables), so it was a good fit.  I'd definitely see if it would be possible to retain the ORM framework if possible, just to reduce the amount of special-purpose code in your app.  Is it possible to buffer writes, then execute them as a group?  You lose transaction semantics, but if you're going with bulk operations I assume you've already come to terms with that.</p>


答: ORMs are not intended to completely take over access to your database.  Use them for that 80% of code that's CRUD, the stuff that's too tedious to write on your own.  Use stored procedures, dynamic SQL, or whatever you want for the remaining 20% that needs to be carefully optimized.</p>


问:
How do you share your craft with non programmers?
Sometimes I feel like a musician who can't play live shows. Programming is a pretty cool skill, and a very broad world, but a lot of it happens "off camera"- in your head, in your office, away from spectators.

You can of course talk about programming with other programmers, and there is peer programming, and you do get to create something that you can show to people, but when it comes to explaining to non programmers what is it that you do, or how was your day at work, it's sort of tricky.

How do you get the non programmers in your life to understand what is it that you do?

NOTE: this is not a repeat of Getting non-programmers to understand the development process, because that question was about managing client expectations.

Body: I've answered a similar question in more detail, but the gist is, "Programming is like building a factory or an assembly line."


答:
I personally find Eclipse is the best multi-language IDE.... apart from the excellent Java support Java there is pretty mature development support for most other major languages available as plug-ins.

There's a long list here of languages which I'm sure has been extended since that article was written.

Also it's not just the languages that are important: you also need to consider:

Build / dependency management tools like Ant and Maven

Source code control (git, CVS, SVN etc.)

Resource file management (XML config, images etc.)

Project management tools (backup, documentation, task management etc.)

Taking all these into account, it's definitely a win to stick to a single primary IDE.


问:
Avoiding inline JavaScript with dynamic content
I read here that you should avoid coding JavaScript inline (see item #1).

It sounds like a great idea; however, I'm not sure how to use js to select dynamic content without setting the id in the function call inline.

For example, I have a simple blog. The comments are hidden, but can be displayed by clicking an anchor (generated dynamically) that calls a JavaScript function to toggle the comments for that specific post:

```<code>$commentsButton = "id . "' href='#comments" . $post->id . "'> comments (" . count($comments) . ")";
</code>```

toggleComments() function:

```<code>function toggleComments(id) {
    $('#' + id + ' .commentsContainer').toggle(500);
}
</code>```

How do you keep from doing this kind of thing? Is it always appropriate to avoid inline JavaScript? Or is this a case where it's necessary?

Update:

I ended up using this:

```<code>$('.commentButton').each(function() {
    $(this).click(function() {
        $(this).parents('.post').find('.commentsContainer').toggle(500);
    });
});
</code>```

with this:

```<code>$commentButton = " comments (" . count($comments) . ")";
</code>```

答:
Inline javascript is the devil. Never use it, there is never an excuse for breaking seperations of concerns other then "I'm a bad developer".

In this case you just want to bind a click handler to all your toggle comment anchors that hides the comment container.

```<code>var as = document.getElementsByClassName("toggleComments");
[].forEach.call(as, function (a) {
  var container = a.getElementsByClassName("commentsContainer")[0];
  a.addEventListener("click", function (ev) {
    container.classList.toggle("hidden");
  });
});
</code>```

Rather then dynamically creating javascript inline just attach a handler to all toggle comments links.

You will have to add a class to all your toggle comments anchors though.

Legacy platform support: Yes standards compliant code doesn't run on legacy platforms. Use the DOM shim and the ES5 shim. Problem solved.

Body:
I read here that you should avoid coding JavaScript inline (see item #1).

It sounds like a great idea; however, I'm not sure how to use js to select dynamic content without setting the id in the function call inline.

For example, I have a simple blog. The comments are hidden, but can be displayed by clicking an anchor (generated dynamically) that calls a JavaScript function to toggle the comments for that specific post:

```<code>$commentsButton = "<a name='comments" . $post->id . "' href='#comments" . $post->id . "'> comments (" . count($comments) . ")</a>";
</code>```

toggleComments() function:

```<code>function toggleComments(id) {
    $('#' + id + ' .commentsContainer').toggle(500);
}
</code>```

How do you keep from doing this kind of thing? Is it always appropriate to avoid inline JavaScript? Or is this a case where it's necessary?

Update:

I ended up using this:

```<code>$('.commentButton').each(function() {
    $(this).click(function() {
        $(this).parents('.post').find('.commentsContainer').toggle(500);
    });
});
</code>```

with this:

```<code>$commentButton = "<a class='commentButton'> comments (" . count($comments) . ")</a>";
</code>```

Body:
Inline javascript is the devil. Never use it, there is never an excuse for breaking seperations of concerns other then "I'm a bad developer".

In this case you just want to bind a click handler to all your toggle comment anchors that hides the comment container.

var as = document.getElementsByClassName("toggleComments");
[].forEach.call(as, function (a) {
  var container = a.getElementsByClassName("commentsContainer")[0];
  a.addEventListener("click", function (ev) {
    container.classList.toggle("hidden");
  });
});

Rather then dynamically creating javascript inline just attach a handler to all toggle comments links.

You will have to add a class to all your toggle comments anchors though.

Legacy platform support: Yes standards compliant code doesn't run on legacy platforms. Use the DOM shim and the ES5 shim. Problem solved.


答:
As Satchel Paige said, "Sometimes I sits and thinks, and sometimes I just sits."

I guess what he was getting at is that it's sometimes good to clear your mind since it may lead you to think about your problem in a different way. So, if you're not banging away at code you may come up with a solution or idea that might have evaded you otherwise. So, yes, it's normal and a good practice to not jump right into coding.

There are two ways I do this process myself. I create a folder where I have a text file and any drawings related to the project. I jot down my ideas there and try and save the entire thought process as best I can. I'll also create a scratchpad project where I can quickly test out simple ideas from algorithms to CSS layouts.


问:
Use Google Analytics to track visitor/download stats for a Google Code Project?
Can you use Google Analytics to track visitors/downloaders for a Google Code project?

I've searched google for an answer but I get results about Google Analytics as a Google Code project itself and not for applying it to a Google Code project for visitor/download data.

答:
You can use Analytics to track visits and views of Code projects but not downloads as far as I know.

If you look under your project's Administer tab, you'll see towards the bottom that there is a box into which you an enter an Analytics tracking code. That's all there is to it.


问:
Why am I seeing so many for(;;) constructs?
To my way of thinking, a for loop is used to iterate over a known or determinable range.

```<code>String[] names = //something;
for ( int i = 0; i < names.length; i++ ) { //do stuff }
</code>```

which is equivalent (scoping of i aside) to :

```<code>String[] names = //something;
int i = 0;
while (i < names.length )
{
   // do stuff
   i++;
}
</code>```

In other words, the for loop is simply a (highly useful) syntactic sugar for a commonly used while construct.

However, I'm seeing a lot of for(;;) constructs on the web which are functionally equivalent to while(true)

What is the reasoning for this?  Why would the infinite for loop be preferred over the infinite while loop?

// I even saw a java textbook that didn't use while loops at all!  Leading to such monstrous constructs as:

```<code>String input = getInput();
for( ; !inputIsValid(input) ; )
{
   //redo;
}
</code>```

答: It's a habit acquired from C programming where there isn't a boolean type. While(1) would be the equivalent potentially but For(;;) is often used as it shows up in K&R if I remember correctly. I suspect that there was a hardware reason in there somewhere as well.</p>


答: Better to spend a month thinking and designing than to whip up a quick prototype based on a substandard design that you then have to beat into shape.  Especially if you're on a team; once others start depending on your code it's much harder to implement a better design with a different API.</p>


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
Virtual Machine Software!

Depending on what you're developing you might also want some virtual machine software like VMWare or Parallels. For instance if you develop websites and do so on a Mac there is no way to run Internet Explorer on a Mac anymore. You either have to reboot into Bootcamp, which is a huge waste of time, or you can have a tiny VM running with Windows in it that you can use to test IE. Some people claim to use WineBottler, an API wrapper, to run IE but it never worked for me and the moment IE gets an update the wine bottle breaks. It's easier just to have a TinyXP distro in a VM.

Of course you could spend a couple grand on a second computer or have a test machine set up with Windows but that's a huge pain in the rump. When we did that someone was always breaking it and then you couldn't test. Using a VM made testing instantaneous and put the power back in the programmers' hands.

OwnerDisplayName: Pickle Pumper


答:
It's a hold-over from old programming practices on the PDP-11 (yes, I said old).  It used to save a single instruction, which was useful for making loops run faster.

See the following for additional information:  http://www.flounder.com/exceptions.htm

Title: Why am I seeing so many for(;;) constructs?

Body:
To my way of thinking, a for loop is used to iterate over a known or determinable range.

```<code>String[] names = //something;
for ( int i = 0; i < names.length; i++ ) { //do stuff }
</code>```

which is equivalent (scoping of i aside) to :

```<code>String[] names = //something;
int i = 0;
while (i < names.length )
{
   // do stuff
   i++;
}
</code>```

In other words, the for loop is simply a (highly useful) syntactic sugar for a commonly used while construct.

However, I'm seeing a lot of for(;;) constructs on the web which are functionally equivalent to while(true)

What is the reasoning for this?  Why would the infinite for loop be preferred over the infinite while loop?

// I even saw a java textbook that didn't use while loops at all!  Leading to such monstrous constructs as:

```<code>String input = getInput();
for( ; !inputIsValid(input) ; )
{
   //redo;
}
</code>```


答: some compilers will give a warning (something like conditional expression is constant) when using while( 1 ) but with for( ; ; ) there's nothing to warn about. Programmers want code without warnings, so they use the for variant.


答:
Trick to using GA to track downloads is to use javascript to fire off an event (or a pageview) when someone clicks the download link.

No idea how much javascript one can push into a google code page.

Title: Use Google Analytics to track visitor/download stats for a Google Code Project?

Body:
Can you use Google Analytics to track visitors/downloaders for a Google Code project?

I've searched google for an answer but I get results about Google Analytics as a Google Code project itself and not for applying it to a Google Code project for visitor/download data.


问:
Is it normal to think about a design problem for days with no code written?
Sometimes I stare blankly into space or sketch ideas and write some pseudo codes on paper. Then I scratch it out and start again, then when I think I have the correct solution for the problem I begin writing the code.

Is it normal to think for days without writing any code? Is this a sign that I am approaching the problem entirely wrong? It makes me nervous to not getting any tangible code written in my IDE.

答: I'm going to disagree with the consensus on this one.  I'd rather start prototyping something as soon as I have even the vaguest written-on-a-napkin idea of how I want my system to work.  It's nearly impossible for me to think of all of the little details that might cause problems unless I'm specifying things in a very precise way.  If I'm just discussing design with people, it's too easy to just hand-wave around some of the more complex problems.  Once I'm specifying things like this, it may as well be directly in source code rather than some other means of expression that's just as precise and formal but can't be compiled and executed.</p>


答:
If you are truly doing agile, then your team should be fully empowered as to the implementation details and your PM shouldn't have a say in it.

On one hand, agile is all about delivering some value quickly, rather than waiting until every wanted feature is perfectly in place.  This occasionally means reducing short term effort at the expense of additional long term work.  That is one of the hardest habits to break.  I know it has been for our team.

On the other hand, it is a myth that being agile requires foregoing all long term planning.  It's perfectly fine, even encouraged, to think about "phase 3," as long as you recognize that business priorities may change to never implement it.  That means if two weeks of extra work now could prevent two weeks of extra work in phase 3, no question you do it in phase 3.  If one week of extra work now prevents two months of work in phase 3, there's little question about doing it now.

Between those extremes, your team must use their best judgement, but I would lean toward postponing the work when you could go either way.  The reason is that by the time you get to phase 3, you will know a lot more about what you need.  Perhaps you will need a large refactor anyway to incorporate some feature you haven't even thought about today, and all your work now is essentially wasted.


答:
Don't let scrum define your role. Scrum is one of the many tools to build better software.
As a team leader/manager, your role is to be a teacher/mentor to the others in the team, and also to be a better programmer.

Even if the methodology you chose(scrum, kanban,  ) changes, your role as a teacher/mentor never changes.

You can chose to guide the team (both with soft skills and/or tech skills ), or guide the product.

Title: As the team leader/manager, what kind of role should I seek when we switch to Scrum?

Body:
My company wants to start using Scrum, and in real scrum there is no place for a real team leader (manager).

What is the next step for the dev team leader? Should I be a (chief) system architect/tech leader  or search for another job in management?

I like the management part and the technical part and the target is VP R&D/CTO.


答:
ORMs do nothing magical. They translate object access methods into SQL. The SQL statements they execute are not necessarily slower than the SQL you'd write manually. Having said that, there are a few issues that you might stumble upon:

Transactions: One large bulk operation is almost always faster than many small transactions that together accomplish the same thing. Hence, if your ORM method calls use fine-grained transactions (the active record-style methods in Spring Roo entities for example are annotated as @Transactional by default), bulk operations will be slow. If that is the case in your application, you should look at your transaction logic.

Caching: In Hibernate, a first-level cache allows your entity manager to avoid unneccesary round-trips to the database. Good thing in general, but bad for bulk inserts, where it leads to unneccessary cache-clogging, resulting in degrading application performance. If that's your problem, you should look at the Batching pattern suggested above by ChrisAnnODell. We use it in our importers and it speeds up bulk inserts a lot.

There is nothing wrong with using native SQL to improve performance. But first make sure you understand what is slowing you down.


问:
Why would you create a deployment script in PowerShell when you have TFS?
I'm experimenting with automatic deployment / continuous integration and had a talk with my team lead.

I told him I'm investigating creating build/deployment scripts in PowerShell and he said automatic deployment is very easy to set up in TFS using a GUI and I should research that instead. I have zero experience with TFS except for commiting to source control from VS.

In which situations would TFS fail and would you be better off with PowerShell for automatic deployment?
What other reasons and advantages are there to choose PowerShell instead of TFS?

And another thing: Could I run a third party tool that, for example, minifies JS files from TFS?

Some advantages of PowerShell I could think of:

PowerShell offers maximum flexibility

You can easily switch to another source control system such as Mercurial

The scripts will be easier to maintain than what TFS generates

PowerShell is light weight: you can run the script on any PC

答: I think you hit the nail on the head with the advantages you listed.  Powershell gives you mobility and lets you move from source control to source control, but more importantantly lets you move from build server to build server, like Jetbrains' TeamCity.  Since the scripts are independent and can be run from the command line, you can fire them off from anywhere, including (like you said) your local machine.


答:
It depends on what do you mean for "normal". Speaking about myself, I think code is a great learning tool. So, when facing a complex problem, I do sketches on paper but I also do some Test-driven coding. Code tells me thinks that a whiteboard can't say and vice-versa, and maybe the result is insight or the need to a couple more questions to the domain expert.

So the real advice is: "Use every learning tool needed to get closer to the problem definition", but also "remember that these are learning tools, so don't fall in love with them" both code and sketches are meant to be throwaway.


答: In this era of RAD and agile programming, you should start developing as soon as you can identify major parts of the system, details will come along. Since Softwares are getting bigger, focusing prematurely on every single detail will lead you nowhere.</p>


答:
In my view, there are three approaches, each suited for a specific coding situation

I've seen a similar problem before so I have a pretty good idea of the patterns to apply, and its clear how the solution should behave and respond.

=> Use BDD/TDD starting from the desired solutions and working in to the code. (Ok, sometimes I cheat and write the a bit of code and then the test - kind of a nested 2. -> 1. approach).

I have a good idea of patterns to apply, but I'm not sure what the solution should look like.

=> Prototype to see what kinds of interesting things pop out.
Move to 1. when I figure out which interesting things are desired.

I'm not sure what patterns to apply.

=> Think about it the problem and how the various ways of approaching the problem influence the code.  Move to 2) or 1) depending on the outcome of that exercise.

In other words, the answer is the engineer's favorite: It depends.


问:
Analyzing a programming language
In SICP, the authors state (Section 1.1) that there are three basic "mechanisms" of programming languages:

primitive expressions, which represent the simplest entities the language is concerned with

means of combination, by which compound elements are built from simpler ones

means of abstraction, by which compound elements can be named and manipulated as units

How can I analyze a mainstream programming language (Java, for example) in terms of these elements or mechanisms?

答:
Here is my basic categorization. I'm trying to draw a paralel with LISP.

Primitive expressions

All primitive values, things you can represent using literals (numbers, booleans, ...)

Parallel in LISP: atoms, numbers and lists.

Means of Combination (Ways you can build compound data-structures)

Arrays

Objects / structs.

Parallel in LISP: Cons cells, lists

Means of Abstraction

All control flow syntax (if, while for)

All builtin operators (+, -,  *,  /, ...)

All functions (in this category we include classes and methods)

Parallel in LISP: Functions, syntactic sugar like let, define

Title: Analyzing a programming language


答:
Testers, Sysadmins and Tech Support

Obviously in some shops these will be a given, but for smaller setups, programmers are an order of magnitude more productive if they don't have to deal with anything other than their code.

Title: Stuff every programmer needs while working

Body:
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed


问:
Best Practices for Handing over Legacy Code
In a couple of months a colleague will be moving on to a new project and I will be inheriting one of his projects. To prepare, I have already ordered Michael Feathers' Working Effectively with Legacy Code.

But this books as well as most questions on legacy code I found so far are concerned with the case of inheriting code as-is. But in this case I actually have access to the original developer and we do have some time for an orderly hand-over.

Some background on the piece of code I will be inheriting:

It's functioning: There are no known bugs, but as performance requirements keep going up, some optimizations will become necessary in the not too distant future.

Undocumented: There is pretty much zero documentation at the method and class level. What the code is supposed to do at a higher level, though, is well-understood, because I have been writing against its API (as a black-box) for years.

Only higher-level integration tests: There are only integration tests testing proper interaction with other components via the API (again, black-box).

Very low-level, optimized for speed: Because this code is central to an entire system of applications, a lot of it has been optimized several times over the years and is extremely low-level (one part has its own memory manager for certain structs/records).

Concurrent and lock-free: While I am very familiar with concurrent and lock-free programming and have actually contributed a few pieces to this code, this adds another layer of complexity.

Large codebase: This particular project is more than ten thousand lines of code, so there is no way I will be able to have everything explained to me.

Written in Delphi: I'm just going to put this out there, although I don't believe the language to be germane to the question, as I believe this type of problem to be language-agnostic.

I was wondering how the time until his departure would best be spent. Here are a couple of ideas:

Get everything to build on my machine: Even though everything should be checked into source code control, who hasn't forgotten to check in a file once in a while, so this should probably be the first order of business.

More tests: While I would like more class-level unit tests so that when I will be making changes, any bugs I introduce can be caught early on, the code as it is now is not testable (huge classes, long methods, too many mutual dependencies).

What to document: I think for starters it would be best to focus documentation on those areas in the code that would otherwise be difficult to understand e.g. because of their low-level/highly optimized nature. I am afraid there are a couple of things in there that might look ugly and in need of refactoring/rewriting, but are actually optimizations that have been out in there for a good reason that I might miss (cf. Joel Spolsky, Things You Should Never Do, Part I)

How to document: I think some class diagrams of the architecture and sequence diagrams of critical functions accompanied by some prose would be best.

Who to document: I was wondering what would be better, to have him write the documentation or have him explain it to me, so I can write the documentation. I am afraid, that things that are obvious to him but not me would otherwise not be covered properly.

Refactoring using pair-programming: This might not be possible to do due to time constraints, but maybe I could refactor some of his code to make it more maintainable while he was still around to provide input on why things are the way they are.

Please comment on and add to this. Since there isn't enough time to do all of this, I am particularly interested in how you would prioritize.

Update: As the hand-over project is over I have expanded this list with my own experiences in this answer below.

答:
Though you have not mentioned about a backend database but assuming there is one you should

Get the data model documented especially the columns and PK-FK

Setup a sql trace and record all the queries which are fired while using the application.The order of execution of queries will give you a good idea about the flow of the application and also help in debugging

OwnerDisplayName: PersonalNexus


问:
Why does Java not permit the use of headers as in C++
I have a question that I did not find an answer for except the following answer that does not meet my requirements:

"Because James Gosling didn't want to"

I know that Java can have interfaces (only pure virtual functions, no attributes), but it is not the exact same thing as class definitions.

答:
There is no real need in C++ to have the class definitions and declarations in separate files. It just means that you could, at least back in the C days, do the parse in a single top-bottom scan of the code.  On machines without random access storage this was a big deal!

Having headers also allowed you to publish the interface to your code library by supplying the header without needing to reveal the source code. Unfortunately in C++ you also have to reveal the private data members which has led to solutions like the horror of pimpl.

There have been attempts to make a C++ environment where everything was stored in a database type structure and there are no files but it didn't catch on.


答:
Program = Algorithm + Data Structure

IMHO, the design(problem solving) process totally rules. Implementation(technical issue) details follow and solve naturally.


答:
The following answer that does not meet my requirements: "Because
  James Gosling didn't want to."

That's the right answer, though. The language design team (Gosling, Sheridan, Naughton, later Bill Joy, Ken Arnold, etc.) decided headers caused more problems than they solved. So they designed them out, and demonstrated that they could create a perfectly useful language without the need for them.

From Section 2.2.1 of the Java Language Environment white paper:

Source code written in Java is simple. There is no preprocessor, no
  #define and related capabilities, no typedef, and absent those features, no longer any need for header files. Instead of header
  files, Java language source files provide the definitions of other
  classes and their methods.

Redundant definitions, keeping files in sync, conflicting definitions, hidden definitions--none of these occur in Java, because you don't have headers. If you want to see a bare class definition, you can generate one from a .java file directly--e.g. most IDEs will show you the structure of a class in a sidebar, which amounts to the same thing.

Title: Why does Java not permit the use of headers as in C++

Body:
I have a question that I did not find an answer for except the following answer that does not meet my requirements:

"Because James Gosling didn't want to"

I know that Java can have interfaces (only pure virtual functions, no attributes), but it is not the exact same thing as class definitions.


答: Because of the DRY principle. In Java, the information needed to use classes in a package (or class) are contained inside the .class file. Creating separate header files that contain the same information would involve repeating it in two places.</p>


问:
working on open source project is bad from a programmer view?
I am working in a software company where we are mostly working on websites which are based on open source like dotnetnuke or nopcommerce or any other

and i am totally bored with all this as there is no scope for doing something new as most of the code is already done in these open source

i know the open source are good for company as they save their time and earn more money

but working on open source project is bad from a programmer view ?

i learn some good things from these open source also...like entity framework from nopcommerce 1.9

答:
Why not take your boredom and your experience with the open source applications that you work with and make a new and exciting addition for one of those projects and share it with the community? That way you'll be doing something new and helping that open source community at the same time. </p>

<p>I know for a fact that nopcommerce users are always looking for some functionality that is not built in to the standard application. </p>

Body:
Why not take your boredom and your experience with the open source applications that you work with and make a new and exciting addition for one of those projects and share it with the community? That way you'll be doing something new and helping that open source community at the same time.

I know for a fact that nopcommerce users are always looking for some functionality that is not built in to the standard application.


答:
Effectively the interfaces and includes are the headers; the definitions
are therefore identical to the binaries, and can't be out of synch.  This
is one of the best design decisions in Java, but it is a minor annoyance
that there's no way to bundle these declarations for compactness and
consistency.</p>


答:
How do you keep from doing this kind of thing?

In browser based javascript, this is set to the DOM element that triggered the event in the event handler. You can take advantage of that to re-use a function for any DOM element.

```<code>function toggleComments() {
    $(this).find('.commentsContainer').toggle(500);
}
</code>```

Then you don't have to emit the ID into the javascript.

Title: Avoiding inline JavaScript with dynamic content

Body:
How do you keep from doing this kind of thing?

In browser based javascript, this is set to the DOM element that triggered the event in the event handler. You can take advantage of that to re-use a function for any DOM element.

function toggleComments() {
    $(this).find('.commentsContainer').toggle(500);
}

Then you don't have to emit the ID into the javascript.


问:
What's wrong with circular references?
I was involved in a programming discussion today where I made some statements that basically assumed axiomatically that circular references (between modules, classes, whatever) are generally bad.  Once I got through with my pitch, my coworker asked, "what's wrong with circular references?"

I've got strong feelings on this, but it's hard for me to verbalize concisely and concretely.  Any explanation that I may come up with tends to rely on other items that I too consider axioms ("can't use in isolation, so can't test", "unknown/undefined behavior as state mutates in the participating objects", etc.), but I'd love to hear a concise reason for why circular references are bad that don't take the kinds of leaps of faith that my own brain does, having spent many hours over the years untangling them to understand, fix, and extend various bits of code.

Edit: I am not asking about homogenous circular references, like those in a doubly-linked list or pointer-to-parent.  This question is really asking about "larger scope" circular references, like libA calling libB which calls back to libA.  Substitute 'module' for 'lib' if you like.  Thanks for all of the answers so far!

答:
A circular reference is twice the coupling of a non-circular reference.

If Foo knows about Bar, and Bar knows about Foo, you have two things that need changing (when the requirement comes that Foos and Bars must no longer know about each other). If Foo knows about Bar, but a Bar doesn't know about Foo, you can change Foo without touching Bar.

Cyclical references can also cause bootstrapping problems, at least in environments that last for a long time (deployed services, image-based development environments), where Foo depends on Bar working in order to load, but Bar also depends on Foo working in order to load.

Title: What's wrong with circular references?