问:
Scrum for team split between two spoken languages
I have a team that without a single common language among all of the team members. The team is split across two locations (though the geography isn't the main issue). All team members in each location speak the same language and there are members in both locations that can speak both. I'd like to introduce scrum, but am struggling with the logistics of dealing with the language issue.

This isn't an offshore team. All team members are employees of the company, but located in two different offices in different countries. Fortunately, we don't have any issues with timezones; language is the primary barrier. While the team could be split into two teams, given the size and skillset of the people in each location as well as other external factors, it is more desirable to integrate as a single team.

I think it would be preferable to use video conferencing in order to have richer communication and help unite the team in being able to see each other and do the true stand-up approach. However, I am afraid this will be difficult to communicate between languages. Should bilingual members of the team translate verbally? Alternately, we could use instant message as recommended by the only reference I could find to language issues in distributed scrum. I'm concerned about the "poorer" communication and perhaps it is a poor introduction to the scrum concept.

From people that have experience in dealing with language differences in a team, how did you address the problem and how well did it work for you?

答:
Teams practicing agile are supposed to be open to experimenting don't they? You know, "people over processes" and such.

Try splitting to two teams per their languages and see how it works. If it turns out problematic, you can try one-team approach.

update, based on clarification provided in comments

I think the answer lies in what you said about "be open to experimenting"... ultimately we've been experimenting with a couple different approaches to find what works best

You got my idea 100% correctly, and I think you're approaching the issue the right way.

As they wrote in The Pragmatic Programmer more than ten years ago,

There are no easy answers. There is no such thing as a best solution...

This is where pragmatism comes in. You shouldn't be wedded to any particular technology, but have a broad enough background and experience base to allow you to choose good solutions in particular situations...

You adjust your approach to suit the current circumstances and environment. You judge the relative importance of all the factors affecting a project and use your experience to produce appropriate solutions. And you do this continuously as the work progresses...

One may say that Agile reinforces this olden-but-golden philosophy by making continuous adjustments an explicitly welcome part of development process.


问:
What do I need to do to NOT steal "Hello World" code with a GPL license?
In the project, I found a file, math.c, with a big GPL header and ...

```<code>//------------------------------------------------------------------------------
/// Returns the minimum value between two integers.
/// \param a  First integer to compare.
/// \param b  Second integer to compare.
//------------------------------------------------------------------------------
unsigned int min(unsigned int a, unsigned int b)
{
    if (a < b) {
        return a;
    }
    else {
        return b;
    }
}
</code>```

OK, cool so I need to get min value and ... this file!? So I need to open the whole project because of it? Or do I need to reinvent mathematics?

I don't believe it's just insane, so the question is: when we can just remove the GPL header?

Must I be a weirdo and do it?:

```<code>unsigned int min(             unsigned int
JEIOfuihFHIYEFHyigHUEFGEGEJEIOFJOIGHE,
unsigned int hyrthrtRERG            ) {  if
(JEIOfuihFHIYEFHyigHUEFGEGEJEIOFJOIGHE
< hyrthrtRERG            ) {  return JEIOfuihFHIYEFHyigHUEFGEGEJEIOFJOIGHE;  }
else {return hyrthrtRERG            ;    } }
</code>```

Seriously, do they want me to write code like the above?

答:
People seem to be forgetting that copyright law, both in spirit and letter, means that the act of actually copying is prohibited - not the act of expressing the same thought yourself, not even if the result turns out suspiciously similar.

If you take the GPL'd code, modify it, use it in a way that is against the license under which you received it, and claim it is not a derived work, then you are breaking the law. Even if you use your second version - you have changed the names of all variables, and altered the formatting, but it's still derived from the original.

If, however, you write your own version of min, and due to the triviality of the task, the fact that there are only so many ways you can sensibly write such a thing, and a bit of coincidence, your version ends up being exactly identical to the GPL'd code, then you haven't copied anything.

Whether or not either story would pass in court is a different matter though. If a larger or more complex code sample shows up somewhere else, complete with comments, formatting, and spelling errors, you'll have a hard time convincing anyone that you wrote it independently, more so if it can be shown that you knew the original source (which, given the fact that you have posted it here, should be fairly trivial).

ContentLicense: CC BY-SA 3.0


问:
In an MVC architecture, how closely coupled are the Model and View to the Controller?
I've got an app which uses MVC, but I'm struggling a little as to how the controller should be architected. For example, the View is only viewing some subset of the model's data at once. However, I'm unsure as to exactly how this should be arranged. Is it normal for the View or Model to directly call functions on the Controller, for example? Through some sort of interface? Or are they totally encapsulated and never know about the Controller or each other?

Just as an edit; this is a custom app not written in any web framework, so I'm not looking for framework-specific details here and have the freedom to make my own choice.

答:
The controller controls the flow of activity. The user performs this action, the controller passes the view data to the domain which does whatever it needs to do then, based on the response(s), the controller tells the framework which view to show next (and gives it enough data to do so).

The controller must thus be coupled to the domain model, to some extent. ie. You could put a service layer in between but, by strict definition, that becomes part of the domain.

It is also coupled to the view data but not the view itself. ie. it simply says "show the customer view using this customer detail." The framework then decides where it should find that view.

Now this should allow you to decouple the domain model from the view, by using a view model of the same data. Some developers do this, some don't, and I do think it's largely a matter of personal preference.

In Rails, you are very much encouraged to push the domain objects (ActiveRecord) to the view and trust that the view doesn't take advantage of that access (eg. you shouldn't call customer.save from the view, even though it would be available).

In the .NET world, we tend to reduce risk by not allowing things that shouldn't happen and, possibly for that reason, it seems to me that the detached view model is more popular.


答:
Coupling (the sort you want to avoid) involves a mutual dependency between two classes.  That is, a Foo depends on a Bar and a Bar depends on a Foo so that you can't really modify one without modifying the other.  That's a bad thing.

You can't really avoid having SOME dependencies, however.  Classes have to know a little bit about one another, otherwise they'd never communicate.

In the MVC pattern, the Controller controls communication between the domain Model and the presentation View.  As such, the Controller must know enough about the Model to ask it to do what it's supposed to do.  The Controller must also know enough about the View to be able to present it to the client or users.  So, the Model Controller has dependencies on both.  However, the View can exist perfectly well without the Controller--there is no dependency there.  Likewise the Model has no depencies on the controller--it simply is what it is.  Finally, the Model and View are completely separate from one another.

Essentially, the Controller is the level of indirection that decouples the View from the Model, so that they do not have to know about one another.

Title: In an MVC architecture, how closely coupled are the Model and View to the Controller?

Body:
I've got an app which uses MVC, but I'm struggling a little as to how the controller should be architected. For example, the View is only viewing some subset of the model's data at once. However, I'm unsure as to exactly how this should be arranged. Is it normal for the View or Model to directly call functions on the Controller, for example? Through some sort of interface? Or are they totally encapsulated and never know about the Controller or each other?

Just as an edit; this is a custom app not written in any web framework, so I'm not looking for framework-specific details here and have the freedom to make my own choice.


问:
Scope of work contents in freelance development
One of my clients demanded to append screen shots of UI in the SOW. Also, I was asked to give a workflow diagram for the same. The project I am about to take is relatively small and my question is,

Should we always provide UI snap shots before project begins? (at least basic). Personally I feel this is not possible as UI keeps changing until agreed upon by client, which is waste of time before development.

Is it necessary to provide both Data Flow Diagram (DFD) and UI screen shot before development begins?

答:
There's no "always" answer - you do what is necessary to fulfill the terms of the contract, deliver a working solution, make a happy customer and get paid! (Or you decide that the job isn't for you and decline the work, although I wouldn't let that become a habit...)

Workflow and UI can both evolve during the life of a project which may make any detailed documentation you do now redundant but there's nothing wrong with providing some prototype / mockup screens as long as you make them clear that's all they are.

The client may also want the documentation as a form of reassurance that you understand their problem and aren't going to go shooting off on a wild (and expensive) tangent. So do it, if it makes them happy.


问:
What is meaning of a HINT when used in software engineering?
I've seen this now in a number of places and a number of contexts, for example in SQL.

I cannot define the meaning of a "Hint" which it seems clear has some application as or part of a larger design pattern/technique.

What exactly is a Hint when used in software engineering?

答: It means the same thing that it means in English: a hint is a clue. For example, some processors improve their performance by predicting whether or not a given branch will be taken. If the processor guesses wrong, it has to back up and refill the instruction pipeline; if it guesses correctly, the code runs quickly because there are no pauses in the pipeline. The programmer or compiler can often tell whether a branch is likely or not, and can provide a hint to the processor to improve the accuracy of its guess and therefore improve performance. So, the processor will end up with the right result with or without the hint, and it'll even get the right result if its branch prediction is incorrect 100% of the time. But accurate branch prediction speeds things up, and providing a good hint can increase that accuracy.</p>


答:
The notion of hints is a particular way to express a specific API contract, or maybe more precisely, lack thereof. Basic idea is that application developer passes some information to the underlying system / library without any guarantees that it will be taken into account.

I personally like the way how this is described in OpenGL API docs for glHint:

specify implementation-specific hints... a symbolic constant indicating the desired behavior.

Note word desired - that's the point. Application developer expresses a desire for implementation to behave in a particular way. Desire is not a mandatory requirement, can be ignored.

Wikipedia article on SQL hints mentions:

Oracle implements hints by using specially-crafted comments in the query that begin with a + symbol, thus not affecting SQL compatibility.

Note above means practically the same "permission to ignore" since a database not supporting Oracle-specific hints will execute SQL statement without these.

Title: What is meaning of a HINT when used in software engineering?

Body:
I've seen this now in a number of places and a number of contexts, for example in SQL.

I cannot define the meaning of a "Hint" which it seems clear has some application as or part of a larger design pattern/technique.

What exactly is a Hint when used in software engineering?


答:
In my experience, generally the model only depends on a view, not a specific one, often as an observer...if it has any such coupling at all.

The view generally couples to whatever it's looking at, which makes sense.  Hard to come up with a view that could be decoupled from what it's viewing...but sometimes you can have a partial coupling or something.

The controller often tends to couple to both.  This also makes some sense since it's job is to turn view events into model changes.

Of course, this is only a tendency I've observed and doesn't really say anything about any specific example.

To understand what MVC is and what the coupling relationship tends to be you should look into how MVC came to be.  The environment in which MVC was created was one in which "widgets" as form elements you can build dialogs with did not exist.  A "view" was a box and it drew stuff.  A text view would be a box that would draw text.  A list view was a box that would draw a list.  The "controller" received all mouse and keyboard events from the UI system that took place in that view; there were no "textChanged" or "selectionChanged" events.  The controller would take all these low level events and generate interaction with the model.  The model, upon being changed would notify its views; we have since come to see this relationship as "observer" and it's used in other ways as its own pattern.

THAT is the essence of the MVC pattern.  Since this kind of low-level UI programming is generally not done anymore, the MVC has evolved in many different directions.  Some things that go by that name today are hardly anything at all like the MVC and should really be called something else.  It can still be used though in the sense of a dialog as a whole interacting with a larger object.  There's many better alternatives though.

Basically, everything the MVC was meant to solve happens inside of widgets now and is something we no longer have to use.

For those that think they know better:

http://www.codeproject.com/Articles/42830/Model-View-Controller-Model-View-Presenter-and-Mod

http://msdn.microsoft.com/en-us/library/ff649643.aspx

I'm sure there are more but those are just the top of the list in google.  As you can see, the model very much depends on a view interface in MANY implementations.  Generally a model is observable and the view is an observer.

But why let facts get in the way...

An article already posted in another answer also supports my statements:

http://martinfowler.com/eaaDev/uiArchs.html

If people want to continue saying that EVERYONE in the design industry is wrong then that's fine.


问:
Pythonesque global variable assignment
I'm designing a language with Pythonesque syntax, including casual creation of variables by assignment. I'm wondering at the moment exactly how to deal with assignment to global variables (and object/class variables, since I'm implementing classes as scopes). In Python itself, by default the attempt will create a local variable instead:

```<code>x = 1
def f():
    x = 2 # creates a local variable
</code>```

but you can override this with a global declaration:

```<code>x = 1
def f():
    global x
    x = 2 # updates the global variable
</code>```

I'm going to implement a prefix . for referring to variables in outer scopes (somewhat akin to prefix :: in C++, but will probably jump one scope instead of all), so that could be written as:

```<code>x = 1
def f():
    .x = 2 # updates the global variable
</code>```

Would it be better to have just that one way of doing things, or would it be clearer or more convenient to have the mechanism of declaring variables as global the way Python does it?

答:
Python 3.x introduces the nonlocal statement, which is described by its documentation:

The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope. This is important because the default behavior for binding is to search the local namespace first. The statement allows encapsulated code to rebind variables outside of the local scope besides the global (module) scope.

PEP 3104 provides more background information about the motivation behind this feature.

I would consider this an unusual thing to do, so I don't mind having an explicit declaration that I'm doing something out of the ordinary. Having a concise single-character notation for this would not be useful to me.

Title: Pythonesque global variable assignment


问:
Are trees organised by a "firstchild, nextsibling" structure? If not, why not?
Usually, tree data structures are organised in a way that each node contains pointers to all its children.

```<code>       +-----------------------------------------+
       |        root                             |
       | child1            child2         child3 |
       +--+------------------+----------------+--+
          |                  |                |
+---------------+    +---------------+    +---------------+
|    node1      |    |     node2     |    |     node3     |
| child1 child2 |    | child1 child2 |    | child1 child2 |
+--+---------+--+    +--+---------+--+    +--+---------+--+
   |         |          |         |          |         |
</code>```

This seems natural, but it comes with some problems. For example, when the number of child nodes varies, you need something like an array or list to manage the childs.

By using only (first)child and (next)sibling pointers instead, we get something that looks like that:

```<code>       +-------------------+
       |        root       |
       | child    sibling  +--->NULL
       +--+----------------+
          |
+----------------+    +----------------+    +----------------+
|    node1       |    |     node2      |    |     node3      |
| child  sibling +--->| child  sibling +--->| child  sibling +--->NULL
+--+-------------+    +--+-------------+    +--+-------------+
   |                     |                     |
</code>```

Oviously, this kind of structure can represent trees just as well, but it also offers some advantages. Most important is that we don't have to worry about the number of child nodes any more. When used for a parse tree, it offers a natural representation for a term like "a+b+c+d+e" without becoming a deep tree.

Do collection libraries offer tree structures like that? Do parsers use such a structure? If not, what are the reasons?

答:
Almost every project that has some editable model or document will have a hierarchical structure to it. It can come in handy to implement the 'hierarchical node' as a base-class for different entities. Often the linked-list (child sibling, 2nd model) is the natural way many class libraries grow, however the children may be of diverse types, and probably an "object model" is not what we consider when talking about trees in general.

My favorite implementation of a tree(node) of your first model is a one-liner (in C#):

```<code>public class node : List<node> { /* props go here */ }
</code>```

Inherit from a generic List of your own type (or inherit from any other generic collection-of-your-own-type). Walking is possible in one direction: form the root downward (items do not know their parents).

Parent only tree's

Another model you did not mention is the one where every child has a reference to it's parent:

```<code>               null
                 |
       +---------+---------------------------------+
       |       parent                              |
       | root                                      |
       +-------------------------------------------+
          |                   |                |
+---------+------+    +-------+--------+    +--+-------------+
|     parent     |    |     parent     |    |     parent     |
|     node 1     |    |     node 2     |    |     node 3     |
+----------------+    +----------------+    +----------------+
</code>```

Walking this tree is only possible the other way round, normally all these nodes will be stored in a collection (array, hashtable, dictionary etc..) and a node will be located by searching the collection on criteria other than the hierarchical position in the tree which would typically not be of primary importance.

These parent-only tree's are usually seen in database applications. It's quite easy to find the children of a node with "SELECT * WHERE ParentId=x" statements. However we seldom find these transformed into tree-node class objects as such. In statefull (desktop) applications they may be wrapped into existing tree-node controls. In stateless (web)applications even that may be unlikely. I've seen ORM-mapping class-generator tools throw stack overflow errors when generating classes for tables that have a relation with themselves (chuckle), so maybe these tree's are not that common after all.

bidirectional navigable trees

In most practical cases however, it's convenient to have the best of both worlds. Nodes that have a list of children and in addition know their parent: bidirectional navigable trees.

```<code>                          null
                            |
       +--------------------+--------------------+
       |                  parent                 |
       |        root                             |
       | child1            child2         child3 |
       +--+------------------+----------------+--+
          |                  |                |
+---------+-----+    +-------+-------+    +---+-----------+
|      parent   |    |     parent    |    |  parent       |
|    node1      |    |     node2     |    |     node3     |
| child1 child2 |    | child1 child2 |    | child1 child2 |
+--+---------+--+    +--+---------+--+    +--+---------+--+
   |         |          |         |          |         |
</code>```

This brings along many more aspects to consider:

Where to implement the linking and unlinking of parent's?

let the bussiness logic take care, and leave the aspect out of the node (they will forget!)

nodes have methods for creating children (does not allow re-ordering) (Microsofts choice in their System.Xml.XmlDocument DOM implementation, which almost drove me crazy when I first encountered it)

Nodes take a parent in their constructor (does not allow re-ordering)

in all add(), insert() and remove() methods and their overloads of the nodes (usually my choice)

Persistance

How to walk the tree when persisting (leave out parent-links for example)

How to rebuild the two-way linking after de-serializing (setting all the parents again as a post-deserialization action)

Notifications

Static mechanisms (IsDirty flag), handle recursively in properties?

Events, bubble up through parents, down through children, or both ways (consider the windows message pump for example).

Now to answer the question, bidirectional navigable trees tend to be (in my career and field so far) the most widely used. Examples are Microsofts implementation of System.Windows.Forms.Control, or the System.Web.UI.Control in the .Net framework, but also every DOM (Document Object Model) implementation will have nodes that know their parent as well as an enumeration of their children.
The reason: ease of use over ease of implementation. Also, these are usually base classes for more specific classes (XmlNode may be the base of Tag, Attribute and Text classes) and these base classes are natural places to put generic serialization and event-handling architectures.

Tree's lay at the heart of many architectures, and being able to navigate freely means being able to implement solutions faster.

Body:
Almost every project that has some editable model or document will have a hierarchical structure to it. It can come in handy to implement the 'hierarchical node' as a base-class for different entities. Often the linked-list (child sibling, 2nd model) is the natural way many class libraries grow, however the children may be of diverse types, and probably an "object model" is not what we consider when talking about trees in general.

My favorite implementation of a tree(node) of your first model is a one-liner (in C#):

public class node : List<node> { /* props go here */ }

Inherit from a generic List of your own type (or inherit from any other generic collection-of-your-own-type). Walking is possible in one direction: form the root downward (items do not know their parents).

Parent only tree's

Another model you did not mention is the one where every child has a reference to it's parent:

               null
                 |
       +---------+---------------------------------+
       |       parent                              |
       | root                                      |
       +-------------------------------------------+
          |                   |                |
+---------+------+    +-------+--------+    +--+-------------+
|     parent     |    |     parent     |    |     parent     |
|     node 1     |    |     node 2     |    |     node 3     |
+----------------+    +----------------+    +----------------+

Walking this tree is only possible the other way round, normally all these nodes will be stored in a collection (array, hashtable, dictionary etc..) and a node will be located by searching the collection on criteria other than the hierarchical position in the tree which would typically not be of primary importance.

These parent-only tree's are usually seen in database applications. It's quite easy to find the children of a node with "SELECT * WHERE ParentId=x" statements. However we seldom find these transformed into tree-node class objects as such. In statefull (desktop) applications they may be wrapped into existing tree-node controls. In stateless (web)applications even that may be unlikely. I've seen ORM-mapping class-generator tools throw stack overflow errors when generating classes for tables that have a relation with themselves (chuckle), so maybe these tree's are not that common after all.

bidirectional navigable trees

In most practical cases however, it's convenient to have the best of both worlds. Nodes that have a list of children and in addition know their parent: bidirectional navigable trees.

                          null
                            |
       +--------------------+--------------------+
       |                  parent                 |
       |        root                             |
       | child1            child2         child3 |
       +--+------------------+----------------+--+
          |                  |                |
+---------+-----+    +-------+-------+    +---+-----------+
|      parent   |    |     parent    |    |  parent       |
|    node1      |    |     node2     |    |     node3     |
| child1 child2 |    | child1 child2 |    | child1 child2 |
+--+---------+--+    +--+---------+--+    +--+---------+--+
   |         |          |         |          |         |

This brings along many more aspects to consider:

Where to implement the linking and unlinking of parent's?

let the bussiness logic take care, and leave the aspect out of the node (they will forget!)

nodes have methods for creating children (does not allow re-ordering) (Microsofts choice in their System.Xml.XmlDocument DOM implementation, which almost drove me crazy when I first encountered it)

Nodes take a parent in their constructor (does not allow re-ordering)

in all add(), insert() and remove() methods and their overloads of the nodes (usually my choice)

Persistance

How to walk the tree when persisting (leave out parent-links for example)

How to rebuild the two-way linking after de-serializing (setting all the parents again as a post-deserialization action)

Notifications

Static mechanisms (IsDirty flag), handle recursively in properties?

Events, bubble up through parents, down through children, or both ways (consider the windows message pump for example).

Now to answer the question, bidirectional navigable trees tend to be (in my career and field so far) the most widely used. Examples are Microsofts implementation of System.Windows.Forms.Control, or the System.Web.UI.Control in the .Net framework, but also every DOM (Document Object Model) implementation will have nodes that know their parent as well as an enumeration of their children.
The reason: ease of use over ease of implementation. Also, these are usually base classes for more specific classes (XmlNode may be the base of Tag, Attribute and Text classes) and these base classes are natural places to put generic serialization and event-handling architectures.

Tree's lay at the heart of many architectures, and being able to navigate freely means being able to implement solutions faster.


问:
Are there advantages to agile practices other than having a working build between sprints?
I recently became interested in agile practices in software development and I since have seen a lot of articles point out that these practices allow for reduced overall costs.

The logic behind that usually goes like this: if your requirements change, you can reflect this change in the next sprint backlog and this will lead to reduced cost, because designing the new feature and implementing it is close together in terms of time, so the cost goes down, according to the famous rule that the later you need to make a change to your requirements the more expensive it will be to satisfy that requirement.

But mid to big software projects are complex. A sudden change to requirements does not mean you won't have to touch other parts of your system in order to satisfy that requirement. In a lot of cases the architecture will need to be modified very significantly, which will also mean you'll need to re-implement all the features that relied on the older architecture. So the whole point of reduced costs kinda goes away here. Of course if a new requirement calls for a new independent part of the system, that's not a problem, the old architecture just grows, it doesn't need to be rethought and reimplemented.

And the opposite. If you are using waterfall and you suddenly realize that a new requirement has to be introduced, you can go and change your design. If it requires that existing architecture is altered, you redesign it. If it does not really mess with it but just introduces a new part of the system, then you go and do all the work, no problem here.

With that said, it seems to me like the only advantage agile development has is working feature complete builds between sprints, and for a lot of people and prjects this is not critical. In addition, agile seems like it results in bad software architecture overall, because features kinda get slapped one onto another, agile teams only care that a feature works, not how it works. This seems like that when systems grow in complexity with time, agile development practices actually increase chaos in the overall product architecture, thus eventually resulting in higher costs, since it will be increasingly more difficult to introduce changes, whereas waterfall allows you to perfect your architecture before you release anything.

Can somebody please point me as to where I'm going wrong here, because obviously a lot of people use agile in production environments, so I must be wrong somewhere.

答:
In response to the quote from the question, which is a fundamental misconception of anti-agile opponents

"... whereas waterfall allows you to perfect your architecture before you release anything." is a fallacy, let me fix it for you; "... whereas waterfall allows you to perfect your architecture so you never release anything."

The implication that Waterfall some how provides higher quality architecture is fundamentally false and completely disproved by empirical historical evidence.

If Facebook was designed in a waterfall fashion with 500 million users as a hard and fast requirement and not released until an architecture to support that was perfected no one would have ever heard of it today.

Same with YouTube, Twitter and countless other companies.

They got something that the customer could touch and respond to working and released it as quickly as possible. They got feedback and refined it and released it again; iterate. This is how in these three examples, they respond with only features customers accept and want and waste as little time as possible on things that customers find of little or no value.

Anyone with any significant years of software development experience will agree there is no such thing as a perfected architecture. Just one that starts out farther from entropy and big ball of mud than other alternatives. Agile acknowledges this and takes it into account. Building into the process, this as  technical debt, rapid re-prioritization and refactoring.


答:
In SQL you do not specify how to do things (in contrary to languages like Java, C#, VB); instead you specify what the result should be. Example, "I want all students with grade A"

```<code>SELECT * FROM students WHERE grade = 'A'
</code>```

This is a very simple situation; however in complex queries the database engine often does not know what the best way to perform the query would be. If you know, for instance, that a certain index would speed up the query much better than another one, you can give a hint, and tell the database engine to use this index.

This is not a standard way of writing SQL statements. It is an advanced technique for tuning slow queries. If you are new to SQL programming, you can safely ignore these hints to begin with.

UPDATE

A completely different example is the rendering of vector based fonts (like TrueType fonts). Rendering involves converting the vector based description of the shape of a character to a pixel pattern. A problem might occur if you render an "m" for instance. Depending on the resulting size, the two arcs of the "m" could get a different width, because of rounding effects. If the resulting width of the "m" has an even number of pixels, the two arcs cannot have the same width. Therefore the description of the "m" has a HINT, which tells the renderer to make the left and the right arc the same with. If the calculated width would measure 8 pixels, for instance, the renderer decides to make it either 7 or 9 pixels wide.

Three "m"s with 8, 9 and 7 pixels width

```<code>0·00·00·    0·00··00·    000·00·
00··0··0    00··00··0    0··0··0
0···0··0    0···0···0    0··0··0
</code>```

Body:
In SQL you do not specify how to do things (in contrary to languages like Java, C#, VB); instead you specify what the result should be. Example, "I want all students with grade A"

SELECT * FROM students WHERE grade = 'A'

This is a very simple situation; however in complex queries the database engine often does not know what the best way to perform the query would be. If you know, for instance, that a certain index would speed up the query much better than another one, you can give a hint, and tell the database engine to use this index.

This is not a standard way of writing SQL statements. It is an advanced technique for tuning slow queries. If you are new to SQL programming, you can safely ignore these hints to begin with.

UPDATE

A completely different example is the rendering of vector based fonts (like TrueType fonts). Rendering involves converting the vector based description of the shape of a character to a pixel pattern. A problem might occur if you render an "m" for instance. Depending on the resulting size, the two arcs of the "m" could get a different width, because of rounding effects. If the resulting width of the "m" has an even number of pixels, the two arcs cannot have the same width. Therefore the description of the "m" has a HINT, which tells the renderer to make the left and the right arc the same with. If the calculated width would measure 8 pixels, for instance, the renderer decides to make it either 7 or 9 pixels wide.

Three "m"s with 8, 9 and 7 pixels width

0·00·00·    0·00··00·    000·00·
00··0··0    00··00··0    0··0··0
0···0··0    0···0···0    0··0··0


答:
Well, there's a few advantages.  The first is that customers don't read spec documents.  Ever.  Waterfall assumes that everyone will nicely agree to a spec at the outset and then when the software is delivered to the customer a year later matching spec, they'll be happy.  In practice, customers only ever discover all the things they really need, really don't need, and really need to be something different when they are actively playing with the software itself.  Agile gets a working prototype in customers hands, so these disconnects are caught immediately.  Agile isn't just about reacting to changing requirements.  It's also about having those changing requirements occur early, when the cost of change is low, not at the end, when the cost of change is high.

A second advantage is that because Agile has highly visible deliverables often, projects are less likely to go off the rails.  With a large Waterfall project, it is all too easy to get way behind without even realizing it.  Waterfall produces multimonth death marches at the end of the project.  With Agile, because you are delivering to customers every couple weeks, everyone knows exactly where the project is and slips are caught (and adjusted for) quickly.  In my experience, Waterfall produces weeks or months of 100 hour weeks at the end.  Agile means that you might have to put in a couple 12 hour days at the end of the sprint.

A third advantage is that Agile projects tend to be more motivating.  It is very hard for people to have any sort of sense of drive in a year long project.  The deadline seems so far away and that lack of immediacy means that people tend to procrastinate, over-polish designs and otherwise just not work very productively.  This is especially true because the initial months are spent on things people don't like to do, like spec documents.  Because Agile always has a very immediate, concrete deadlines in the very near future, people tend to be more motivated.  It is much harder to procrastinate with a concrete deadline for a fixed set of tasks due next week.

Title: Are there advantages to agile practices other than having a working build between sprints?

Body:
I recently became interested in agile practices in software development and I since have seen a lot of articles point out that these practices allow for reduced overall costs.

The logic behind that usually goes like this: if your requirements change, you can reflect this change in the next sprint backlog and this will lead to reduced cost, because designing the new feature and implementing it is close together in terms of time, so the cost goes down, according to the famous rule that the later you need to make a change to your requirements the more expensive it will be to satisfy that requirement.

But mid to big software projects are complex. A sudden change to requirements does not mean you won't have to touch other parts of your system in order to satisfy that requirement. In a lot of cases the architecture will need to be modified very significantly, which will also mean you'll need to re-implement all the features that relied on the older architecture. So the whole point of reduced costs kinda goes away here. Of course if a new requirement calls for a new independent part of the system, that's not a problem, the old architecture just grows, it doesn't need to be rethought and reimplemented.

And the opposite. If you are using waterfall and you suddenly realize that a new requirement has to be introduced, you can go and change your design. If it requires that existing architecture is altered, you redesign it. If it does not really mess with it but just introduces a new part of the system, then you go and do all the work, no problem here.

With that said, it seems to me like the only advantage agile development has is working feature complete builds between sprints, and for a lot of people and prjects this is not critical. In addition, agile seems like it results in bad software architecture overall, because features kinda get slapped one onto another, agile teams only care that a feature works, not how it works. This seems like that when systems grow in complexity with time, agile development practices actually increase chaos in the overall product architecture, thus eventually resulting in higher costs, since it will be increasingly more difficult to introduce changes, whereas waterfall allows you to perfect your architecture before you release anything.

Can somebody please point me as to where I'm going wrong here, because obviously a lot of people use agile in production environments, so I must be wrong somewhere.


答:
Scrum by itself does not prescribe any technical practices because it is a general framework.

Agile software development requires technical excellence from the team. This comes from following technical practices from XP (extreme programming). For instance, you must learn about refactoring, tdd, whole team, pair programming, incremental design, ci, collaboration etc.

Doing it like that makes it possible to handle change quickly and safely,  which is also the primary reason for using agile development in the first place.

The one measurement of agile that matters is if you regularly (weekly, biweekly) manage to release valuable, working software to your customer. Can you do that? Then you're agile in my book.


问:
What algorithm(s) can be used to achieve reasonably good next word prediction?
What is a good way of implementing "next-word prediction"? For example, the user types "I am" and the system suggests "a" and "not" (or possibly others) as the next word. I am aware of a method that uses Markov Chains and some training text(obviously) to more or less achieve this. But I read somewhere that this method is very restrictive and applies to very simple cases.

I understand basics of neural networks and genetic algorithms(though have never used them in a serious project) and maybe they could be of some help. I wonder if there are any algorithms that, given appropriate training text(e.g., newspaper articles, and the user's own typing) can come up with reasonably appropriate suggestions for the next word. If not (links to)algorithms, general high-level methods to attack this problem are welcome.

答:
Take a look at n-grams. One n-gram is a sequence of n words. In your case you want n to be 3, since you need two query words and a resulting word. One 3-gram would be for example "I am tired", another one "I am happy".

What you then need is a collection of these 3-grams that are collected over your target language, say English. Since you cannot collect it over everything ever written in English you need to make a selection. That selection of representative texts is called a corpus. If your corpus is good it will tell you how often a sequence of three specific words occur together in English. From that
you can calculate the probability of a 3-gram.

Collecting this kind of data is the hardest part. Once you have the list of all 3-grams together with their probability you can filter your list to all 3-grams starting with "I am". Then you sort all this list by probability et voilà: your prediction.


问:
How can I bootstrap a software development community at my school?
I'm a student at the University of South Florida who's frustrated with the educational environment in the Computer Science program. Right now, I'm taking "Program Design." I should be learning how to organize my source code into functions and modules in order to make my programs readable and maintainable; instead, I'm learning about arrays and recursion in C. Next semester, I have to take "Object-Oriented Design," which is taught through C++ (shudder.)

Two years ago, I fell in love with programming, and I've been learning as much as I could since then. The prospect of taking another C++ class bores me almost to tears. For that reason, I thought I would start a programming club in order to meet similarly ambitious students, learn new languages, discuss software development topics, and work with other students developers.

However, I'm beginning to realize that there may not be any other students who share my software development experience. It's not because of a lack of motivation but a lack of opportunity: I know of only one other programming class ("Programming Languages") and no classes on real-world software development. Everybody else only has experience writing trivial scripts in C and C++.

I've realized that if I want to work with other student software developers, I'm going to have to train them myself. Now, I'm planning to make the club a software development bootcamp, teaching members how to develop software with modern tools and languages. Obviously, starting an unofficial software development course is a monumental task with many possible approaches. My question to you, dear reader, is

What's my plan of attack?

Should I

lecture the club myself, trying to balance club work with homework?

ask the CS faculty to teach on topics within their expertise which may be less than relevant to members?

try to find a sympathetic, experienced developer inside or outside the school who can share my workload?

show video lectures (from MIT OpenCourseWare, Google Tech Talks, etc)?

hold hands-on programming workshops?

assign homework?

do something else?

答:
This sounds like a networking opportunity, I'm sure there are a number of students interested in programming with a similar level of experience/training... you're just not finding them...

Have you attended one of the Code Camps (free developer related training) in the Tampa Bay area, or joined one of the local programming user groups?

Both of these resources will provide you with networking opportunities. And instead of feeling like you have to train your fellow students, you'll be able to invite your friends along with you and then discuss what was covered.

You'll also gain access to people who are programming as a career and can get an idea of what kinds of situations you're likely to come up with in "the real world".

Once you've explored these local resources you may still find that you opportunities to share your knowledge by doing your own presentations, which is great. Sharing what you've learned with a user group or as a speaker of a code camp presentation is a good way to get feedback on what you've learned and opens you up to learning more as well.

I grew up in the Tampa Bay area and attended a lot of free Microsoft sponsored events, your local user group should have information on how to get involved in those events as well.

Well, this was a long winded reply...

The next Code Camp in Tampa is on Nov. 13th 2010 according to the tampacodecamp website.

Here's a link to your local INETA/programming user group:

http://www.tampadev.org/

(I'm new to this group and was only able to include one link.)

ContentLicense: CC BY-SA 2.5


问:
Should I use the new C++11 'auto' feature, especially in loops?
What are the pros/cons to using the auto keyword, especially in for loops?

```<code>for(std::vector<T>::iterator it = x.begin(); it != x.end(); it++ )
{
   it->something();
}

for(std::map<T>::iterator it = x.begin(); it != x.end(); it++ )
{
   it->second->something();
}

for(auto it = x.begin(); it != x.end(); it++ )
{
   it->??
}
</code>```

Seems like if you don't know whether you have an iterator for a map or a vector you wouldn't know whether to use first or second or just directly access properties of the object, no?

This reminds me of the C# debate on whether to use the keyword var.  The impression I'm getting so far is that in the C++ world people are ready to adopt the auto keyword with less of a fight than var in the C# world.   For me my first instinct is that I like to know the type of the variable so I can know what operations I can expect to perform on it.

答: YES, you should! auto does not erase the type; even if you "don't know" what x.begin() is, the compiler knows and will report an error if you try to use the type wrongly.  Also, it is not unusual to emulate map with a vector<pair<Key,Value>>, so the code using auto will work for both dictionary representations.


问:
When and how to commit?
I'm getting used in working with git at the moment. And I'm touching an issue that is unclear to me.

I feel compelled, if I think of commiting after a change and making a documenting description. I don't know exactly when I should commit, because that's very relative and there's always something under construction.

I tend to commit, when I fear to hose something. But then the summaries look like "Backup before trying this and that" or just "Backup".

What do you do? Is there a better way, or is my practise common?

答: Whenever I start a project, I make a bullet point list of the different components that need doing, and often that includes subcomponents.  It doesn't have to be on paper, it can be in your mind (even if paper is easier to share than thoughts).  I always commit when I complete a component that took "some effort" and is something worthy of showing someone, even if that is a fellow developer and not a client.</p>

OwnerDisplayName: rynd

Title: When and how to commit?

OwnerDisplayName: Roman Ali


答:
Git is wonderful and scary because of it's flexibility.  While there is a lot of advice that will probably be given on this thread, I think the best advice that I can give is to keep two branches of your code:

1) master

2) stable

I commit like crazy on my master branch.  There is no guarantee of any functionality on it.  There is also a desire to have a version of your code that is stable... that's where the stable branch comes in.  Every time that you have a stable version of your code, you can merge your changes back in to the stable branch.

Depending on how big the project is, I might have several branches from the master.  I'll have one for each bit of functionality that I'm working on and I can merge the changes back in when they're stable.

So long story short.  In git you don't have to choose between committing often and having stable commits.  You can do both!  I like to use gitk or git-extensions to view my branches.  It helps me remember where I am and what I'm working on for each project.

Title: When and how to commit?

Body:
I'm getting used in working with git at the moment. And I'm touching an issue that is unclear to me.

I feel compelled, if I think of commiting after a change and making a documenting description. I don't know exactly when I should commit, because that's very relative and there's always something under construction.

I tend to commit, when I fear to hose something. But then the summaries look like "Backup before trying this and that" or just "Backup".

What do you do? Is there a better way, or is my practise common?


答:
You can do whatever is socially acceptable with your fellow programmers on the project you are working on. There are no rules really.

Personally I commit very often to keep change-sets really small and make sure they only do one thing, and then may or may not rearrange / squash those before publishing to the team.

When you realize you have git rebase -i to hand, it becomes less important how often you commit initially.

In terms of comments, I think it can be important that your commits are well described so that you can manage the changes you are working on.

Title: When and how to commit?

OwnerDisplayName: Tim Abell


答: Commit when you've completed a cohesive "unit of work". That could be fixing a typo in a comment, adding a new module to a project, adding some logging statements, writing a new unit test and the code to make it pass, or anything else that's easily understandable as a discrete change to a project. The key is "easily". Commits should be narrowly focused and able to be fully described in the commit message. The commit message is sentences or paragraphs, not books. In general, I'd say if you go more than an hour of solid coding without committing, you're doing something wrong.</p>

Title: When and how to commit?

OwnerDisplayName: Ryan Stewart


答:
Source control is a bit of a personal thing. Typically if you work with a group they will have their own procedures regarding when to commit and what your commit messages should look like. Typically you commit AFTER you complete some task, not before. Remember, you want to be able to access the most up-to-date code possible in case you lose your data.

Here are a few rules of thumb:

You should always, to the best of your ability, leave the commited code in a runnable state. Do not submit anything unless you tested it.

The commited code should be as up-to-date as possible without violating rule 1.

You should try to keep commits as small as possible. If you fix three bugs, it's best to have three separate commits (one for each bug). That way you can rollback one small change at a time. It also makes it easier to find where you introduced mistakes

Commit messages should be meaningful. Always write like someone else will read them (because you won't remember what you did a week after your commit)

Obviously, sometimes (esspecially when you're beginning a project) it's hard to follow these rules. Either the code isn't complete enough to be run or your changes overlap and it's too difficult to separate them. Use your own judgement.

Title: When and how to commit?

OwnerDisplayName: acattle


答:
First off, like others I'm assuming you're working on a local branch and that you have a master somewhere else.

I think a DVCS gives you a huge amount of freedom.  I try to commit each time I make a semantic step forward and the code compiles.  If I rename a variable, I commit.  If I improve a comment, I commit.  The advantage of a very fine-grained commit structure is that when you push to master there is a bundle of descriptive commits.

I tend to commit, when I fear to hose something. But then the summaries look like "Backup before trying this and that" or just "Backup".

Again, a DVCS gives you freedom.  I wouldn't say "backup before trying flux capacitor", I'd say "written flux capacitor".  If it turns out that this doesn't work, I'd back that particular change set out.  You have the freedom to do this because you only have to worry that your changes break other people when they either pull from you or you push to the master branch.

Title: When and how to commit?


问:
How do you decide how much your software will cost?
If you are a solo developer, or have a leading role in a software company, you might have to decide how much your software will cost one or another day...  What is your experience with calculating how much your software costs for your customer? Why does this method it work for you?</p>

答:
I actually wrote a couple of articles on the subject a few months back, but just stumbled over this question now.

The easy way out is to say it differs a lot depending on target audience, market, size of problem solved and so forth, which is all true - but I think you can divide software to 3 general categories:

Must-have software

Nice-to-have software

Nobody-needs-it software

Assuming you don't fall in the 3rd category, you need to figure out in what category are you. Nice-to-have software should generally be priced in the range of "why not?" (as Jeff calls it in his article), which means low enough that that a potential client doesn't mind opening his wallet, while must-have software have much more flexibility with the pricing.

What makes software a must-have? that's where all the different variables come in to play. The most important ones in my opinion are:

How big is the problem being solved? How much time / money are you saving the end-user? (time = money)

How unique is the solution? (i.e, can you just find a cheaper / free / better alternative by googling for it?)

When I price software, those are the main considerations I take. You can factor in additional parameters, such as market (you can price higher when selling to the enterprise as opposed to the private sector, for example).

Also, never be afraid to experiment after you set the price. Give some time for data to accumulate and try to test different pricing to see how it affects sales.


答:
You can take practical advice from big long-running open-source projects, like Chromium, there you send code for review first, so you can discuss your changes early and other engineers can point out your mistakes. When everyone agrees code is 'good enough', you can commit it.

This solves the backup problem (you have a separate branch on your machine, and code review server typically allows to download patch), and leads to better code in general.

Title: When and how to commit?


问:
When Business Object fields should not exactly reflect database columns
Main advantage with Hibernate annotations is the fact that a simple POJO (also called a Business Object the most of time) can become persistent through Hibernate annotations (or actually JPA) .

In the scenario where our conceptual domain model (business objects used by clients) does not exactly reflect the physical model (database), how to deal with? Should I create a "second" model that represents the "true" business objects used by clients AND a "data storage object" containing mapping Hibernate annotations? Of course, with this solution, DAOs will be responsible to convert each BO to Data Object and vice-versa.

答: Have a look at ibartis (mybartis.org)  When Im working with a database model that doesn't directly reflect the domain model then I usually use ibartis instead of Hibernate.</p>


答:
For me, the main benefit of agile is reducing risk in the project.

By delivering iteratively and getting lots of feedback from your user base, you're increasing the chance that you'll deliver something they actually want, and you'll do it by pragmatically delivering the most important features for them as early as possible.  In theory, this will be done with better estimates and planning.  This is obviously very appealing from the business perspective - much more so than just the releasable build.

You could argue that this constant change compromises your system and reduces quality, but I would say two things.  1)  This change happens anyway on more traditional software delivery projects - it's just unaccounted for and occurs later on in the project which is when, as you pointed out, things are harder and more expensive to change.  2) Agile has a lot to say about dealing with this change in terms of using experienced motivated people and practices such as TDD, pairing and code reviews.  Without that shift in mindset towards quality and continuous improvement, I accept that frequent change that agile implies could start to cause problems.


问:
Do you actually write 'clean code'?
I have seen some programmers tweaking their code over and over again not only to make it 'work good', but also to make it 'look good'.

IMO, 'clean code' is actually a compliment indicating your code is elegant, perfectly understandable and maintainable. And the difference comes out when you have to choose between an aesthetically appealing code vs. code that's stressful to look at.

So, how many of you actually write 'clean code'? Is it a good practice? What are the other benefits or drawbacks of this?

答:
I would disagree with the accepted answer on this question.

Your responsibility is obviously to ship, but usually you also have a responsibility to ship something that is maintainable as cost effectively as possible by yourself and future developers.

I've spent periods as that poor maintenance programmer or consultant on site who has to understand and debug some huge undocumented system, and I can tell you that poor designs and messy confusing code can lead to hours or even days of wasted effort. I can think of lots of situations where an extra N hours of effort by the initial developer could have lead to a 5N cost saving in terms of my time.

I know there is a statistic floating around about this, but in my experience across multiple projects, each line of code that is written is read 5-20 times during extension and maintenance.

So I would say to clean up code to within an inch of its life. It takes time, but it's likely a net cost saving over the life of the project.

Title: Do you actually write 'clean code'?


问:
Has test driven development (TDD) actually benefited a real world project?
I am not new to coding. I have been coding (seriously) for over 15 years now. I have always had some testing for my code. However, over the last few months I have been learning test driven design/development (TDD) using Ruby on Rails. So far, I'm not seeing the benefit.

I see some benefit to writing tests for some things, but very few. And while I like the idea of writing the test first, I find I spend substantially more time trying to debug my tests to get them to say what I really mean than I do debugging actual code. This is probably because the test code is often substantially more complicated than the code it tests. I hope this is just inexperience with the available tools (RSpec in this case).

I must say though, at this point, the level of frustration mixed with the disappointing lack of performance is beyond unacceptable. So far, the only value I'm seeing from TDD is a growing library of RSpec files that serve as templates for other projects/files. Which is not much more useful, maybe less useful, than the actual project code files.

In reading the available literature, I notice that TDD seems to be a massive time sink up front, but pays off in the end. I'm just wondering, are there any real world examples? Does this massive frustration ever pay off in the real world?

I really hope I did not miss this question somewhere else on here. I searched, but all the questions/answers are several years old at this point. It was a rare occasion when I found a developer who would say anything bad about TDD, which is why I have spent as much time on this as I have. However, I noticed that nobody seems to point to specific real-world examples. I did read one answer that said the guy debugging the code in 2011 would thank you for have a complete unit testing suite (I think that comment was made in 2008).

So, I'm just wondering, after all these years, do we finally have any examples showing the payoff is real? Has anybody actually inherited or gone back to code that was designed/developed with TDD and has a complete set of unit tests and actually felt a payoff? Or did you find that you were spending so much time trying to figure out what the test was testing (and why it was important) that you just tossed out the whole mess and dug into the code?

答:
This paper demonstrates that TDD adds 15-35% development time in return for a 40-90% reduction in defect density on otherwise like-for-like projects.

The article refers full paper (pdf) - Nachiappan Nagappan, E. Michael Maximilien, Thirumalesh Bhat, and Laurie Williams. “Realizing quality improvement through test driven development: results and experiences of four industrial teams“. ESE 2008.

Abstract Test-driven development (TDD) is a software development practice that has been
  used sporadically for decades.With this practice, a software engineer cycles minute-by-minute
  between writing failing unit tests and writing implementation code to pass those tests. Testdriven
  development has recently re-emerged as a critical enabling practice of agile software
  development methodologies. However, little empirical evidence supports or refutes the utility
  of this practice in an industrial context. Case studies were conducted with three development
  teams at Microsoft and one at IBM that have adopted TDD. The results of the case studies
  indicate that the pre-release defect density of the four products decreased between 40% and
  90% relative to similar projects that did not use the TDD practice. Subjectively, the teams
  experienced a 15–35% increase in initial development time after adopting TDD.

Full paper also briefly summarizes the relevant empirical studies on TDD and their high level results (section 3 Related Works), including George and Williams 2003, Müller and Hagner (2002), Erdogmus et al. (2005) , Müller and Tichy (2001), Janzen and Seiedian (2006).

OwnerDisplayName: James


答:
Objection! Loaded question.

Can you explain to me why the third code has ?? in it, yet the first and second don’t? For fairness’ sake, your code must read as follows:

```<code>for(std::vector<T>::iterator it = x.begin(); it != x.end(); i++)
{
   it->???
}

for(std::map<T>::iterator it = x.begin(); it != x.end(); i++)
{
   it->second->???
}
</code>```

There. Same problem even though you didn’t use auto.

And in all cases, the answer is the same: Context matters. You can’t meaningfully talk about a piece of code in isolation. Even if you hadn’t used templates but some concrete type, this would only have moved the problem somewhere else, since the reader of your code would have to know about the declaration of said type.

If use of auto in those situations render your code unreadable you should treat this as a warning sign that there’s something wrong with your code design. Of course, there are cases where low-level details matter (such as when dealing with bit operations or legacy API) in which cases an explicit type might aid readability. But in general – no.

Regarding var (since you explicitly mentioned it), there’s also a vast consensus in the C# community for using var. Arguments against its use are generally built on fallacies.

Title: Should I use the new C++11 'auto' feature, especially in loops?

Body:
What are the pros/cons to using the auto keyword, especially in for loops?

```<code>for(std::vector<T>::iterator it = x.begin(); it != x.end(); it++ )
{
   it->something();
}

for(std::map<T>::iterator it = x.begin(); it != x.end(); it++ )
{
   it->second->something();
}

for(auto it = x.begin(); it != x.end(); it++ )
{
   it->??
}
</code>```

Seems like if you don't know whether you have an iterator for a map or a vector you wouldn't know whether to use first or second or just directly access properties of the object, no?

This reminds me of the C# debate on whether to use the keyword var.  The impression I'm getting so far is that in the C++ world people are ready to adopt the auto keyword with less of a fight than var in the C# world.   For me my first instinct is that I like to know the type of the variable so I can know what operations I can expect to perform on it.

Body:
Objection! Loaded question.

Can you explain to me why the third code has ?? in it, yet the first and second don’t? For fairness’ sake, your code must read as follows:

for(std::vector<T>::iterator it = x.begin(); it != x.end(); i++)
{
   it->???
}

for(std::map<T>::iterator it = x.begin(); it != x.end(); i++)
{
   it->second->???
}

There. Same problem even though you didn’t use auto.

And in all cases, the answer is the same: Context matters. You can’t meaningfully talk about a piece of code in isolation. Even if you hadn’t used templates but some concrete type, this would only have moved the problem somewhere else, since the reader of your code would have to know about the declaration of said type.

If use of auto in those situations render your code unreadable you should treat this as a warning sign that there’s something wrong with your code design. Of course, there are cases where low-level details matter (such as when dealing with bit operations or legacy API) in which cases an explicit type might aid readability. But in general – no.

Regarding var (since you explicitly mentioned it), there’s also a vast consensus in the C# community for using var. Arguments against its use are generally built on fallacies.

ContentLicense: CC BY-SA 4.0


答:
Note: Robert C. Martin (aka Uncle Bob) explains this in a much better and humorous way in his keynote, Architecture the Lost Years. A bit long but teaches lots of good concepts.

tl;dr: Don't think and plan your app in terms of MVC. The MVC framework is just an implementation detail.

The most confusing thing about MVC is, developers tries to use all the components glued together.

Try thinking in the terms of a program, not in the terms of the framework.

Your program has a purpose. It takes some data, does things with data, and returns some data.

That way, the controller is the delivery mechanism of your program.

A user sends a request to your program (let's say, add a product to the shopping cart).

The controller takes that request (product info and user info), it calls the necessary part of your program that will handle this request $user->addToCart($product)

Your program (addToCart function of the user object in this case) does the work it's intended to do and returns a response (let's say success)

The controller prepares the response using the relevant view: eg. in the controller object $this->render($cartView('success')

This way, the controllers are decoupled from the program, and used as  delivery mechanism. They don't know how your program works, they just know which part of the program need to be called for the requests.

If you want to use another framework, your app won't need a change, you will just need to write relevant controllers to call your program for requests.

Or if you want to make a desktop version, your app will stay the same, you will just need to prepare a delivery mechanism.

And the Model. Think of it as a persistence mechanism.

In the OO way, there are objects in your program that holds the data.

```<code>class User {
    //...
    private $id;
    private $shoppingCart;
    //...
}

class Product {
    //...
    private $id;
    //...
}
</code>```

When you add a product to the shopping cart, you can add the the product::id to the user::shoppingCart.

And when you want to persist the data, you can use the model part of the framework, which generally consist using an ORM, to map the classes to the database tables.

If you want to change the ORM you use, your program will stay the same, only the mapping information will change. Or if you want to avoid the databases all together, you can just write the data to plain text files, and your app will stay the same.

So, write your program first. If you programming with the 'OO' way, use plain old objects of the language. Don't think in terms of MVC at first.

Body:
Note: Robert C. Martin (aka Uncle Bob) explains this in a much better and humorous way in his keynote, Architecture the Lost Years. A bit long but teaches lots of good concepts.

tl;dr: Don't think and plan your app in terms of MVC. The MVC framework is just an implementation detail.

The most confusing thing about MVC is, developers tries to use all the components glued together.

Try thinking in the terms of a program, not in the terms of the framework.

Your program has a purpose. It takes some data, does things with data, and returns some data.

That way, the controller is the delivery mechanism of your program.

A user sends a request to your program (let's say, add a product to the shopping cart).

The controller takes that request (product info and user info), it calls the necessary part of your program that will handle this request $user->addToCart($product)

Your program (addToCart function of the user object in this case) does the work it's intended to do and returns a response (let's say success)

The controller prepares the response using the relevant view: eg. in the controller object $this->render($cartView('success')

This way, the controllers are decoupled from the program, and used as  delivery mechanism. They don't know how your program works, they just know which part of the program need to be called for the requests.

If you want to use another framework, your app won't need a change, you will just need to write relevant controllers to call your program for requests.

Or if you want to make a desktop version, your app will stay the same, you will just need to prepare a delivery mechanism.

And the Model. Think of it as a persistence mechanism.

In the OO way, there are objects in your program that holds the data.

class User {
    //...
    private $id;
    private $shoppingCart;
    //...
}

class Product {
    //...
    private $id;
    //...
}

When you add a product to the shopping cart, you can add the the product::id to the user::shoppingCart.

And when you want to persist the data, you can use the model part of the framework, which generally consist using an ORM, to map the classes to the database tables.

If you want to change the ORM you use, your program will stay the same, only the mapping information will change. Or if you want to avoid the databases all together, you can just write the data to plain text files, and your app will stay the same.

So, write your program first. If you programming with the 'OO' way, use plain old objects of the language. Don't think in terms of MVC at first.


答:
Controller dispatches model to a view and it processes submitted model from the views, however it is not tightly coupled to a view or a model.

If controller was tightly coupled to a view, then we'll be in a world of web forms. You'd have a code behind which would be tied to a template file (Applicable to ASP.NET web forms)

Because of this, controller is not coupled to a model or a view. It's just a mechanism for processing requests and sending responses.

View is tightly coupled to a model. Make changes to your model (e.g. change its property) and you'll have to make changes to your view.

Model is not tightly coupled to a view. Make changes to a view, and it'll have no affect on a model.

Model doesn't know anything about controller or views where it may be used. Therefore model is not tightly coupled to a view or controller.

Another way to think about this:

Make changes to a controller - view and model will be unaffected

Make changes to a model - view will break as it relies on a model

Make changes to a view - model and controller will be unaffected

This loose coupling in MVC projects is what makes them easy to unit test.


答:
You may also think of an alternative representation. Consider the objects used by clients as an "interface objects". A DAO objects then may be used as a truly "business objects".

The business objects may (and usually have to) be tightly coupled with database to communicate with it in a most efficient way.

An interface objects, on the other hand, form an API. An API has it's own requirements, which don't necessarily suit well with what DAO provides:

A DAO object may expose the data, which should not be exposed to clients, such as passwords.

A DAO data representation may differ from what client needs. For example, the same password field can be hashed in database, while the client code operates with a non-hashed variant.

A DAO object may contain data not intended for direct manipulation by clients. Again, a password may be set during registration or checked for correctness, but not read.

An interface objects may often have additional requirements applied by the framework they used by, such as JSF or RMI.

Title: When Business Object fields should not exactly reflect database columns

Body:
Main advantage with Hibernate annotations is the fact that a simple POJO (also called a Business Object the most of time) can become persistent through Hibernate annotations (or actually JPA) .

In the scenario where our conceptual domain model (business objects used by clients) does not exactly reflect the physical model (database), how to deal with? Should I create a "second" model that represents the "true" business objects used by clients AND a "data storage object" containing mapping Hibernate annotations? Of course, with this solution, DAOs will be responsible to convert each BO to Data Object and vice-versa.


问:
Is it legal / moral to republish oss project of an author that does not respond?
I have found a small oss project (one file) in someone's blog a few months ago. The license is "Attribution-ShareAlike 2.5 Generic". I sent a mail to the author if I can put this in github but got no response back. Meanwhile his blog has been shut down.

I am not a lawyer, but this seems legal to republish the code (with appropriate attribution) in github. Am I right? Is this moral? Maybe the guy just wants to disappear for a while...

答:
If it's under a license that says you can share it around but you have to attribute it to the original author, then you can share it around but you have to attribute it to the original author.  It's really that simple.

I've seen more than one open-source project being hosted and maintained by someone other than the original author when the guy who wrote it lost interest (or just no longer had time to keep it running.)  There's no problem with you doing the same as long as the code's released under a license that allows you to do so.


答:
I do go to great length to clean code. I think it greatly helps the bugs stand out.

I don't agree with the "ship the fucking thing now" concept, because clean code is an investment to the future. Also too many software gets shipped with too many bugs. Resolving one bug in my opinion is better than implementing one new feature.

Also if you look at estimates of programmer productivity, I don't think I score very bad. Writing clean code is a habit, and the more experience as a programmer, the more efficient one becomes at it. If one never tries it, obviously, one will never get experience with it.

Another point to take into account, is that most developer time goes to reading code, so readable code greatly reduces the times spent reading. Understanding undocumented algorithms for example can be costly and invite new bugs.

One thing I definitely do miss and would like to have one day is an automatic code formatter that I could adapt to my style, that would really save me some time, especially when reading other people's code.

Clean coding does have a link to perfectionism, which does have a risk of never materializing, but I think that is mainly a problem when you start out, because you invest in later and when reusing your own elegant pieces of code, combined with your experience, growing older you will be very productive and a lot less haunted by bugs than the messy coders.

This is a piece of code demonstrating my coding style.

Title: Do you actually write 'clean code'?

Body:
I have seen some programmers tweaking their code over and over again not only to make it 'work good', but also to make it 'look good'.

IMO, 'clean code' is actually a compliment indicating your code is elegant, perfectly understandable and maintainable. And the difference comes out when you have to choose between an aesthetically appealing code vs. code that's stressful to look at.

So, how many of you actually write 'clean code'? Is it a good practice? What are the other benefits or drawbacks of this?


答:
It seems no one raises the point of what's in your company's best interest?

Often, if not always, programmers are just employees, and while the management decisions might frustrate us, we often do not have all of the data they do.

For example, say the company is contracted with a clause that if the software isn't ready in time, you won't get paid (it just happened to us, though I think we got the payment after all). Yeah, clean code is important, but more important is to have the code working by the payment day!

Another example - the company is in bad financial position and needs to raise some money. Guess who cares about quality? You can fix it later, if you have to, just ship it!

An argument might be "Why should I sell out and write crappy code?". Well, why should your company pay you a nice check each month? Choices, my friend. If you are after idealism, try the Free Software Foundation; I hear they're doing some pretty cool stuff (I mean this one, and I respect FSF and OSS).

On the other side of things, if you work on a project where an explosive growth in usage is expected (although such projections are almost never accurate), you better lay some solid foundation with the best code quality required, since it's almost certain maintenance will be the bigger cost for the project.

Programmers love 'clean' code, whatever that means. We can't even agree on what's clean, but we love it. However, sometimes it just doesn't matter that much as usability and correctness do. These might seem synonymous, but they aren't - if you've seen code written by a true Perl hacker in 4 hours with the intent to be used twice and thrown away, you would acknowledge it's not clean, but it works.

So sometimes, ego aside, we should just get it working. Note that I don't recommend writing bad code as a habit; I'm just pointing that it might be necessary. Perfection takes time your company might not have. So if your employer doesn't mind, craft software, but if you need to, just write working code, never mind the 'cleanliness'. It's just not a 'One size fits all' answer - you should prioritize.

Title: Do you actually write 'clean code'?


答:
I think there are some misconceptions about some of the terms you used:

Conceptual domain model is not "business objects used by clients". It is a "model" of that, of business domain.

"Physical model" is not clear, what does it mean. When someone says "physical", it is not necessarily the third phase of database design (after conceptual and logical). Typically if you are talking within the context "domain modeling", mismatch between the model and physical word, refers to conceptual model and business domain, not database.

If you are following a domain-driven-design approach (especially With Hibernate which can automatically create the database based on domain model and ORM), then you design youR Domain Model first, then built the rest of application based on it. In this case, your database will be driven by the domain-model and there won't be discrepancy between the two.


问:
How to teach Exception Handling for New Programmers?
How do you go about teaching Exception Handling to Programmers. All other things are taught easily - Data Structures, ASP.NET, WinForms, WPF, WCF - you name it, everything can be taught easily.

With Exception Handling, teaching them try-catch-finally is just the syntactic nature of Exception Handling.

What should be taught however is - What part of your code do you put in the try block? What do you do in the catch block?

Let me illustrate it with an example.

You are working on a Windows Forms Project (a small utility) and you have designed it as below with 3 different projects.

UILayer

BusinessLayer

DataLayer

If an Exception (let us say of loading an XDocument throws an exception) is raised at DataLayer (the UILayer calls BusinessLayer which in turns calls the DataLayer), do you just do the following

```<code>//In DataLayer
try {
    XDocument xd_XmlDocument = XDocument.Load("systems.xml");
}
catch(Exception ex)
{
    throw ex;
}
</code>```

which gets thrown again in the BusinessLayer and which is caught in UILayer where I write it to the log file?

Is this how you go about Exception Handling?

答:
I would imagine to understand exceptions you first need to understand the child/parent relationship of classes for example.  If you understand that a child can inherit functionality from a parent, they might be able to on an elementary level understand that if a child has a problem it cannot handle it will pass this problem (exception) up to its parent and let the parent deal with it.

This becomes a chained relation until you end up with a place where something knows how to handle the exception.

And as far as finally goes this is the trivial part... when a problem occurs something has to handle it so the program does not exit fatally, after that exception is handled the finally block is there which will always execute regardless of the try catch.

A good example of this might be with networking:

we make connection

connection is ok so we use it

when finished we close up and free resources

or in exception case:

make a connection

an exception occurs which something handles

at whichi point we free up connection and resources associated


答:
It's ok, and its one of the goals of open source, in case the original author (s) abandon the project.

Just don't forget to mention the original author, and in case you want to modify the code, ( YES, SOME OPEN SOURCE LICENSES ALLOW YOU TO MODIFY THE SOURCE CODE ), keep the license, and mention the original authors.

Title: Is it legal / moral to republish oss project of an author that does not respond?

Body:
I have found a small oss project (one file) in someone's blog a few months ago. The license is "Attribution-ShareAlike 2.5 Generic". I sent a mail to the author if I can put this in github but got no response back. Meanwhile his blog has been shut down.

I am not a lawyer, but this seems legal to republish the code (with appropriate attribution) in github. Am I right? Is this moral? Maybe the guy just wants to disappear for a while...


问:
Considering JCR as a NoSQL solution?
I'm evaluating some NoSQL solutions for a project of mine and JCR popped up during my searches as a document store. But it seems somehow of an obscure niche which didn't have the impact its designers hoped for.

I'm interested in the technology, but so far there does not seem to be a lot of resources out there to show it's potential (there is some info on the Jackrabbit site, but otherwise, pretty much scarce info).

Hopefully someone in the SE community could share from their experience with this technology.

What are its advantages/disadvantages? In what situations does this technology perform best?

答:
I studied a bit about JCR eons ago. It's a nifty Java API to model a document repository, with a hierarchy, metadata, versioning, etc., that is, a nice model for CMS backend. There are quite a few implementations, notably the open source JCR, but some "enterprise CMS companies" had their own products based on JCR. Jackrabbit for instance uses an underlying SQL database.

Unfortunately, the JCR ecosystem doesn't seem to be very lively. So probably the work it would save you would probably be offset by the difficulty of hiring people who know it, the maturity of the libraries, etc. Some promising stuff exists, such as Sling, which is a nice web framework on top of JCR which might be a good foundation to build CMS-ey sites.

I would take a look at JCR; if the things it implements are stuff you need, it might be worth adopting it if you find a decent opensource implementation (Jackrabbit).

Title: Considering JCR as a NoSQL solution?


问:
Client/Server App – Best online data storage/administration/communication library?
I work on some iphone/android apps and the “data stored on a centralized server” pattern seem fairly common.

So far, I have done one app like this, doing everything myself at a low level without using many libraries:

MySQL database

PHP/HTML web forms allowing the app manager to enter/update content with some validation

PHP scripts turning the SQL data into downloadable XML files

App code (java/objective-c) to download the XML files, parse them and turn them in some proper objects then displayed in the app UI

As you can imagine, that is very tedious and boring and there is lots of duplicated stuff.
Also, it was interesting to do it once that way to understand how it works but I’m sure some libraries do it much better that my own php/java/obj-c code.

Now, I will have to work on something similar and I’m looking for some sort of API/service that will do most of this work for me but still allow me to alter/customize what I need to (e.g.: web form validation so that the app manager doesn’t break the integrity of the database, e.g.: plugging with my own classes).

So I’m looking for the best generic solution that cover all the steps above plus the case when the app can insert/update data as well (download and upload). (Note the library shouldn’t have a licence that prevents me from selling the app)

Let’s say I have to build an app about cars, I want to store the car data in an online SQL database with some HTML forms allowing the app manager to add more cars (but only allowing him to enter validated data). I want the app user to be able to download the cars and insert new one in the online SQL database from his phone.

What library/API would you recommend? What service would save me the most time while still allowing flexibility?

答: Django's admin interface for the CRUD admin website, an RPC-like mechanism for communicating with a server-side API from the clients, probably there are decent libraries to export Django methods over XMLRPC (something like http://pypi.python.org/pypi/django-xmlrpc)</p>


问:
UI patterns in functional languages
I would like to start fiddling with ClojureScript, but I am puzzled about some points. My problem is what is a good way to deal with state changes coming from user interaction, when you trying to work functionally.

Let me give a couple of examples. I have in mind applications which run in the browser, but I think the issue is more general. Of course something will be changing - the DOM at least. But I would like to find out how to organize the rest of the code to work with immutable data structures.

1) Say I want to attach some events to some DOM object. This is not hard to do in a mostly functional way: when you create the node, you attach it a hash map with the various event handlers. But consider the case where you are using event delegation. Then when you create a new node, you may attach a event handler to some parent node that probably already exists. So you would have to change the hash associated to the already existing node.

2) Say I am designing an autocomplete module for an input field. Every time the user presses a key, I can make a call to a server to get the suggestions. This is easy. But now suppose I want to optimize it a bit. If I know all results matching foo there is no point in asking again for all results matching foobar; I can just filter the former. So I need to build some kind of cache. This cache will be updated every time the user inserts a new word which is not a superset of the words previously entered. Again: how do I model the cache? The most reasonable way seems to be a hash map mapping words to results, but it should be mutable.

Can you suggest some patterns that would make it easier to incorporate changes due to user interaction into a functional design?

答:
As mentioned in the comments you should look up "Functional Reactive Programming" and you should also read some of the posts at http://prog21.dadgum.com/archives.html. More specifically you should probably read "Don't Fall in Love With Your Technology", "Write Code Like You Just Learned How to Program", "Functional Programming Doesn't Work (and what to do about it)", and maybe a few other ones.

Completely avoiding mutability and side-effects is practically impossible. Even Haskell programmers will once in a while make use of unsafePerformIO to break out of the purely functional, side-effect free, statically typed paradigm to do certain things. If you are embarking on this project as a purely academic exercise then go right ahead and avoid mutability and side-effects as much as possible but if you are trying to build a usable product on a deadline then no pattern is going to save you.

Title: UI patterns in functional languages


答:
Yes, you may. The Creative Commons description of the license states:

You are free:

to Share — to copy, distribute and transmit the work

to Remix — to adapt the work

to make commercial use of the work

Under the following conditions:

Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

Which means you may use the code however you wish as long as what you make contains an attribution to the original author and is published under a similar license.


问:
I'm the .1x programmer at my company. How can I best contribute?
I work at a newly-minted startup of five people.  We have a Ph. D in machine learning, a former member of the RSpec core team, and the guy who compiles the Git binary for OS X.  That's just the employees; the founder has a Ph. D and was CTO for a multi-billion-dollar corporation before leaving to start a (successful) startup, and has now left that to start this one.  We also might get a guy with a Ph. D in math.

Aaaaaaaaand then there's me, college-dropout intern.  I think I'm pretty smart and I'm reading non-stop, but the delta of experience, skill, and knowledge between me and my co-workers is just breathtaking.

So put yourself in their shoes: you've got a bright young intern who has a lot to learn but is at least energetic.  What would be annoying?  What use would you hope to get out of him in the here and now?  What would be pleasantly surprising if it happened?

答:
Most important thing:

Don't be impressed by the titles. In a short time, you will realize that your Ph. D coworkers, too, are just humans. And some people with a Ph. D never really created anything practically usefull. Always remember that, don't feel inferior.

What I'd expect of you?
To write good code and get things done. Chances are that you are someone who is really working, as you describe yourself as energetic. I've seen lots of people with degrees who took like forever to achieve simple tasks because they were focussing too much on details etc. Put that to good use and deliver good code in a reasonable time and soon everyone will respect you.

But don't disrespect the others. They're most likely older and you can probably learn valuable things from them. But don't take anything over mindlessly. Always try to understand and think for yourself. I'd expect you to copy the behaviours and knowledge from them that really work.


答:
Short Answer: Find out what the team needs, and perhaps what you like best, and work toward providing that.

Longer answer: In the early stages of a start-up, most of the time, all work is "up for grabs"; whatever tasks need to be done or tasks that people want to do are available to all takers. Your preferences can literally shape the direction that the company goes.

Interested in HR? Take over the hiring tasks. Or maybe do the payroll. Interested in programming? Find out what language the team wants to use. Try writing some unit tests for some of the code. Hate writing reports? Then don't. See if you can delegate that task to someone else and work toward a constructive solution. Take a bit of time and think about what you might want to do, then try it out.

One thing to keep in mind that when it comes to very small early start-ups, there's much more to do than just programming. If you want to code, great! If you'd rather do something else, that's good too! Learn fast, ask lots of questions and challenge yourself.

Title: I'm the .1x programmer at my company. How can I best contribute?

Body:
I work at a newly-minted startup of five people.  We have a Ph. D in machine learning, a former member of the RSpec core team, and the guy who compiles the Git binary for OS X.  That's just the employees; the founder has a Ph. D and was CTO for a multi-billion-dollar corporation before leaving to start a (successful) startup, and has now left that to start this one.  We also might get a guy with a Ph. D in math.

Aaaaaaaaand then there's me, college-dropout intern.  I think I'm pretty smart and I'm reading non-stop, but the delta of experience, skill, and knowledge between me and my co-workers is just breathtaking.

So put yourself in their shoes: you've got a bright young intern who has a lot to learn but is at least energetic.  What would be annoying?  What use would you hope to get out of him in the here and now?  What would be pleasantly surprising if it happened?


答:
First off, the "waterfall" model was always a straw man describing how NOT to run a software development project.  Look it up.

Anyhow, most "waterfall" SDLC projects entail a "Change Management" process, for when people discover that the assumptions that were written into the specifications are no longer valid (and this always happens on large complex projects).  Unfortunately, the change management process is built as an exception handling measure, and is stupidly expensive, meaning the project will end up late, or of poor quality.

The idea behind Agile methodologies is that change is a given--it will happen.  Therefore, you must make "change management" standard operation rather than exception handling.  This isn't easy, but folks have found that if you use a lot of good design practices, you can do it.

Another major problem with front loaded design is that (most often) so much time is spent in requirements gathering and design, development and testing time suffers.  Also, if testing is the last phase, and a serious problem is discovered, it is highly unlikely to get fixed within your time frame.

Perhaps one of the best features of an Agile approach is that it demands  continued interaction (that is, real communication) between the team developing the solution, and the customer who needs it.  Priorities are made, so that the highest priority items are done first (and if time runs out, it's the low priority items that are cut).  Feedback comes quickly.

Going back to the question of dramatic changes--you really need to use methods that mitigate changes.  Good SOLID OO principals can play a good part of this, as can building solid automated test suites so that you can regression test your software. You should do these things regardless of your methodology, but they become truly essential if you are trying to be agile.