问:
Tomcat 7 vs. ehCache Standalone Server (Glassfish) Configuration with RESTful Web Services
My requirements consist of using ehCache to send and store data via RESTful web service calls. The data can be stored in-memory or via the filesystem...

Never used ehCache before so I am having some issues deciding on which bundle to use.

Have downloaded the following bundles:

ehcache-2.6.2

ehcache-standalone-server-1.0.0

(1) What is the difference between the two?

It seems the ehcache-2.6.2 contains src and binaries, which essentially enables one to bundle it with their webapps (by putting the compiled jar or binaries inside the webapp's WEB-INF/lib folder). But it doesn't seem that it has support for Restful web services.

Whereas, ehcache-standalone-server-1.0.0 (comes with an embedded Glassfish server and has support for REST & SOAP) can be used to run as a standalone server. If I my answers to my own question are correct, then that means, I should just use the standalone server?

(2) My requirements are to setup ehCache (with REST support) on Tomcat 7. So, how could I setup ehCache on Tomcat 7 as a separate app with REST & SOAP support?

Thank you for taking the time to read this...

答:
thats right, the first package is to include ehcache into your own application (this application could also be just a REST Interface for the cache )

the second one bundels already an application server with it, because you need to run it on dedicated hardware which more memory, you need a shared cache for many webservers, or you dont have java client. .....

to run it on tomcat just download the distribution modul which is a simple WAR file, which can be deployed to tomcat or any other webserver. a REST Interface is included.


问:
Web App vs Portal Platform - convincing the customer
We're evaluating a set of requirements for a customer who wants Liferay which mainly has AAA and Web CMS requirements, and allowing user to upload their own content. Also all inetgration is via web services.

However there is no need for other features such as actual "portlets", i18n, mashups, skins, themes, tagging, social presence, no collaboration etc

So we feel we can do this as a standard JEE web app and not use Liferay (or any other portal product) since these are overheads we dont need.

The customer feels the Web CMS requirements + user upload justify the "portal" product.

Can anyone help me with some points to convince the customer? Assuming our point of view is right.

答:
you should check the requirements of your costumer now and in one year,
depending on that, you should then know, if a CMS or a Portal, or a Portal with CMS integration best fits the costumer needs, now and in one year.

between CMS and Portal is a big difference.
where CMS is just about Content Management, means there are just special users who are able to add end edit the content displayed on the website. each user will see the same content (maybe without rights a bit less)

a portal is something where users can login and either just use available content as they want. iGoogle as example is a portal. each user decide what content so see where.

a Portal with CMS is a portal, but now the users have the option to add and edit content to the portal which can be used by other users.

and also a benefit of good portal like Liferay is, it used portlets, so if you dont need some content / features you can remove this portlets.

and if a produkt brings such features like i18n or themes skins fro free, its not bad, you dont need to use it.

also why in that case you should prefer an existing solution over own development is: the existing solution is proven that it works for what your costumer need, your own doesn't.

ContentLicense: CC BY-SA 3.0


问:
Why can't WARs share session info?
I have seen several developers looking for a solution for this problem: accessing session information from a different WAR (even when inside the same EAR) - here are some samples: Any way to share session state between different applications in tomcat?, Access session of another web application, different WAR files, shared resources, Tomcat: How to share data between two applications?, What does the crossContext attribute do in Tomcat? Does it enable session sharing? and so on...

From all I have searched, there are some specific solutions depending on the container, but it is somehow 'contrary to the specification'. I have also looked through Java EE specification without any luck on finding an answer.

Some developers talk about coupling between web applications, but I tend to disagree. What is the reason one would keep WARs inside the same EAR if not coupling? EJBs, for instance, can be accessed locally (even if inside another EJB JAR within the same EAR).

More specifically, one of my WARs handles authentication and authorization, and I would like to share this information with other WARs (in the same EAR). I have managed to work around similar problems before by packaging WARs as JARs and putting them into a singular WAR project (WEB-INF/lib). Yet I do not like this solution (it requires a huge effort on servlet naming and so on).

And no solution has answered the first (and most important) question: Why can't WARs share session information?

答:
Well, AFAIKS, there's no real reason why you'd like to do this. A WAR is a self contained web application, with it's own (web application specific) scopes (like session scope).
If you need to share functionality (Java code, JSP pages, CSS files), between multiple WARs you have the far more sensible option of packaging them as JAR files and deploying them in your application server.
A WAR package is a more complex packaging solution, and one designed to encapsulate something different than simple "common code/functionality". The JAR is a simpler format AND is designed for packaging and sharing code and functionality. Why would you want to use a more complex and not-specificaly-designed-for-that packaging to share something, when you have have a simpler and more-suited-to-that package format already available.
Think of JSTL Tags, Struts JQuery Plugin, Spring security, they all come as JARs. </p>

Title: Why can't WARs share session info?


问:
Should we hire a new developer now, or wait until the code is refactored to make it suitable for a team environment?
I support and develop a large system that uses various technologies e.g. c++,.net,vb6 etc.  I am a sole developer.

I am debating whether now is the right time to approach my  manager (who is not a developer) to ask if another developer can be recruited.

I don't have any experience working in software teams.  I have always been a sole developer.

The concerns I have are:

There is still a lot to do.  Training another developer would take time and distract me from my duties.

The company does not invest heavily in tools e.g. source control

The code in this system needs to be refactored to introduce concepts such as interfaces, polymorphism etc, which are supported by methodologies such as Agile (I inherited the system about 12 months ago).  I am gradually trying to refactor the code.

I believe I have two options:

Approach my manager now

Wait until I have had time to refactor the code so it is more suitable for a team environment.

Which option is best? I am hoping to hear from other developers who have been in my situation.

答:
You need to ask WHY you need to add a new developer and what the goal is. Fred Brooks wrote about this in Mythical Man Month. Adding a new developer to  a late project will make it later. If you are trying to solve a short term problem, forget the idea and put in extra hours. If you are thinking longer term, then your concerns about a short term hit in productivity are mute. If you have a short term problem that is not going away - best to take the pain of training a new recruit now, rather than defer it till later.

Your bosses first response will be about ROI and Budgets. What will he get for the extra salary and additional pain he will suffer. You need to "sell" him the benefits and rewards. Do not gloss over the costs - direct and indirect, and risks (What if you recruit an idiot). In business terms, he will need the cash flow as well as ROI before he even starts to think about it.  If you go to him with "I want to hire another programmer", he is likely to say "I want a new Porsche, now get back to work". If you take it to him with "We have X months work on the books, and more coming in every day. I cannot keep up, but if we recruit a new developer we can. If we don't, we won't be able to finish this by then and likely lose out on that revenue worth Y dollars"......

What ever you do, DO NOT us any of the words in 3) of you question. What your boss will hear is "buzz word, technobable, buzzword, buzzword, technobable.... playtime on company money with shiny new toys and no cost benefit..... technobable, technobable", and he will (rightly?) respond "That's nice, now get back to work".


答:
Absolutely ask for the budget for a second developer. I was a sole developer myself a year ago, and over the past few months have brought on two new people who have made massive contributions - one with setting up our API and the other with being able to handle a lot of grunt work that used to suck my own time into a black hole. We're just much more productive now. Try to find people with different skill sets that can contribute to where you want to be in two years.

I ended up working with one of them to implement our source control (with Git). And that meant everyone got to beef up their resumes.

Title: Should we hire a new developer now, or wait until the code is refactored to make it suitable for a team environment?

Body:
I support and develop a large system that uses various technologies e.g. c++,.net,vb6 etc.  I am a sole developer.

I am debating whether now is the right time to approach my  manager (who is not a developer) to ask if another developer can be recruited.

I don't have any experience working in software teams.  I have always been a sole developer.

The concerns I have are:

There is still a lot to do.  Training another developer would take time and distract me from my duties.

The company does not invest heavily in tools e.g. source control

The code in this system needs to be refactored to introduce concepts such as interfaces, polymorphism etc, which are supported by methodologies such as Agile (I inherited the system about 12 months ago).  I am gradually trying to refactor the code.

I believe I have two options:

Approach my manager now

Wait until I have had time to refactor the code so it is more suitable for a team environment.

Which option is best? I am hoping to hear from other developers who have been in my situation.


问:
KISS principle applied to programming language design?
KISS ("keep it simple, stupid" or "keep it simple stupid", see e.g. here) is an important principle in software development, even though it apparently originated in engineering. Citing from the wikipedia article:

The principle is best exemplified by the story of Johnson handing a team of design engineers a handful of tools, with the challenge that the jet aircraft they were designing must be repairable by an average mechanic in the field under combat conditions with only these tools. Hence, the 'stupid' refers to the relationship between the way things break and the sophistication available to fix them.

If I wanted to apply this to the field of software development I would replace "jet aircraft" with "piece of software", "average mechanic" with "average developer" and "under combat conditions" with "under the expected software development / maintenance conditions" (deadlines, time constraints, meetings / interruptions, available tools, and so on).

So it is a commonly accepted idea that one should try to keep a piece of software simple (or simple stupid, in case you omit the comma) so that it easy to work on it later.

But can the KISS principle be applied also to programming language design? Do you know of any programming languages that have been designed specifically with this principle in mind, i.e. to "allow an average programmer under average working conditions to write and maintain as much code as possible with the least cognitive effort"?

If you cite any specific language it would be great if you could add a link to some document in which this intent is clearly expressed by the language designers. In any case, I would be interested to learn about the designers' (documented) intentions rather than your personal opinion about a particular programming language.

答:
Java Wikipedia - although not explicitly stated in Wikipedia, simplifaction is mentioned a number of times and was an original design goal, as the only serious OO capable (Term used loosely) language in those days was C++, which as we all know, is powerful but has more than a few traps for the unwary.

The JVM was intended as a way to simplify cross platform development, and "Write once Run anywhere" became a Java mantra for a few years - again, the intent was the framework was simple to deploy.

I believe C# falls into that category of simplification of the language.


问:
Location of development solutions on disk - Common or upto the individual
In our team meeting today a senior member brought up the proposal that we should be having a common location/structure for our development solutions.

A couple of his points were:

Making it common meant when talking about projects and emailing stuff everyone is on the same wavelength and knows where to look.

If there is ever the need to hard code a location path then it will work across all developers pc's.

He had a more few points to back up his suggestion but I unfortunately got distracted during the discussion and so didn't hear all of them.  I have no issue with the idea and can see it's merits but I was wondering if it is common or even recommended that all developers place their code in the same folder structure.  Or do developers like to have the flexibility of location solutions where-ever they want?  We currently use SVN for our version control.

In this case his recommendation was to place all code in:

```<code>c:\Work\Development\<Customer>\<project>\Code\<solution>\ the code
</code>```

I guess actual path is irrelevant for this question but added for completeness.

答:
I don't think it really matters where a given developer's working set goes.  The source control system can still keep track of it.   Visual Studio puts them in

```<code>c:\documents and settings\<user name>\My Documents\Visual Studio 20xx\Solution folder
</code>```

Where <user name> differs for each developer machine.

Body:
I don't think it really matters where a given developer's working set goes.  The source control system can still keep track of it.   Visual Studio puts them in

c:\documents and settings\<user name>\My Documents\Visual Studio 20xx\Solution folder

Where <user name> differs for each developer machine.


问:
Why can't we write nested shorthand functions in Clojure?
I tried to evaluate a Clojure expression with nested shorthand functions today, and it wouldn't let me.

The expression was:

```<code>(#(+ % (#(+ % (* % %)) %)) 5) ; sorry for the eye bleed
</code>```

The output was:

```<code>IllegalStateException Nested #()s are not allowed  clojure.lang.LispReader$FnReader.invoke (LispReader.java:630)
...and a bunch of other garbage
</code>```

答: You can have nested anonymous functions of the (fn [params] (body)) sort. Only the # syntax doesn't support nesting.</p>


答:
I'd say that the developer's particular set-up is down to the developer. I'm not sure if I agree with the "everyone being on the same wavelength idea" - it seems a little vague to me, and this has never been brought up at any company I have ever worked at. But none of that particularly mattered to me, until I read this:

If there is ever the need to hard code a location path then it will work across all developers pc's.

I have never found the need to hard-code a location path, aside from in prototype code, which would never normally get committed (or at least not to the shared development branch). Every standard programming language library should have a method to get the location of the currently executing binary.

Sometimes, that's just not possible, like a document store for a web application for example. In which case, you can use a configuration file to direct your application to the correct location. Once again, most standard programming language libraries will have something appropriate to solve this issue with minimal fuss.

Hard-coding paths will only lead to issues later on. What if your application will be deployed to a server which has it's massive RAID array on the D: drive? Will you maintain two separate branches for this? Will you remember to edit a source file every time you deploy a new version? I'd be very interested to hear about a use case that would demand this.

Title: Location of development solutions on disk - Common or upto the individual

Body:
In our team meeting today a senior member brought up the proposal that we should be having a common location/structure for our development solutions.

A couple of his points were:

Making it common meant when talking about projects and emailing stuff everyone is on the same wavelength and knows where to look.

If there is ever the need to hard code a location path then it will work across all developers pc's.

He had a more few points to back up his suggestion but I unfortunately got distracted during the discussion and so didn't hear all of them.  I have no issue with the idea and can see it's merits but I was wondering if it is common or even recommended that all developers place their code in the same folder structure.  Or do developers like to have the flexibility of location solutions where-ever they want?  We currently use SVN for our version control.

In this case his recommendation was to place all code in:

```<code>c:\Work\Development\<Customer>\<project>\Code\<solution>\ the code
</code>```

I guess actual path is irrelevant for this question but added for completeness.


答:
I would suggest you not enforce or enact such a standard because the only benefit will be that it allows you to hide problems in the code base where everything works using this hard coded path right up until the program is deployed to a clients site and they keep getting an error

FileNotFoundException 'c:\work\Development\...

People say it will help building the system because you can hard code these paths, but what you end up with when you have hard coded stuff in your build system is a slow-growth of fixed garbage making it harder for you to restructure or refactor your system. Ultimately these hard-coded bits in build systems always have to be replaced over time, and are unnecessary.

So there's one risk, and the potential benefits are exactly ? I've seen this tried at places I've worked and I have seen these errors crop up and I have yet to see a single benefit whatsoever in those places...


答:
You would know that % belongs to the inner function. The drawback is that you would lose access to the % in the outer function.

Use the fn [x] syntax instead.

Title: Why can't we write nested shorthand functions in Clojure?

Body:
I tried to evaluate a Clojure expression with nested shorthand functions today, and it wouldn't let me.

The expression was:

```<code>(#(+ % (#(+ % (* % %)) %)) 5) ; sorry for the eye bleed
</code>```

The output was:

```<code>IllegalStateException Nested #()s are not allowed  clojure.lang.LispReader$FnReader.invoke (LispReader.java:630)
...and a bunch of other garbage
</code>```


问:
Has the syntax of any programming language been usability tested?
Before being release to the public, has the syntax of any programming language undergone usability testing? If so, what kinds of testing was performed, what were the results, and what impact did the testing results have on the design of the language?</p>

答:
From Robert Harvey's comment I found this interesting quote from C# designer Anders Hejlsberg:

Anders Hejlsberg: Most of it was actually usability studies of IDE
  features. We might ask, "Can people understand that they right click
  to do this or that?" We did some usability studies for the pure
  language syntax itself—I think we did some with properties and events,
  for example—but it was not necessary really.

I don't think that you get as high a yield from usability studies for
  language features as for IDE features. IDEs are very interactive. You
  can watch users right click menu items and get good feedback. For
  programming languages, the question is more, "Is it conceptually
  understandable?" That's done very well by having a customer advisory
  councils, sounding boards. You want places where you can say, "Here's
  what we're thinking about doing for this particular new feature. What
  do you all think?" And you actually urge them to shoot as many holes
  in it as possible, because you'd much rather know before you put in
  the feature than after. So unless a language feature is a complete
  slam dunk, we tend to make use of those kinds of sounding boards.


问:
Extracting useful information from free text
We filter and analyse seats for events.  Apparently writing a domain query language for the floor people isn't an option.  I'm using C# 4.0 & .NET 4.0, and have relatively free reign to use whatever open-source tools are available.  </background-info>

If a request comes in for "FLOOR B", the sales people want it to show up if they've entered "FLOOR A-FLOOR F" in a filter.  The only problem I have is that there's absolutely no structure to the parsed parameters.  I get the string already concatenated (it actually uses a tilde instead of dash).  Examples I've seen so far with matches after each:

101WC-199WC  (needs to match 150WC)

AAA-ZZZ   (needs to match AAA, BBB, ABC but not BB)

LOGE15-LOGE20  (needs to match LOGE15 but not LOGE150)

At first I wanted to try just stripping off the numeric part of the lower and upper, and then incrementing through that.  The problem I have is that only some entries have numbers, sometimes the numbers AND letters increment, sometimes its all letters that increment.  Since I can't impose any kind of grammar to use (I really wanted [..] expansion syntax), I'm stuck using these entries.

Are there any suggestions for how to approach this parsing problem?

答:
Tighten the requirements.

In the specification as described, there is a significant amount of ambiguity in the grammar.  The range A100-A200 has more than two valid strings.  The question is does the 00 part of the range described in this example designate a character class (any digit) or a constant string?

No matter which way you chose, there is the possibility that you will be wrong for some intended range.

The options are you can guess, you can try a natural language library (and have it guess instead of you), or you can tighten the requirements to remove such ambiguities.

I would strongly advise trying to tighten the requirements.  Alternatives to this will have perceived bugs and unclear documentation for the end user.


问:
How do people read big technical books?
I see that most of the good programmers have the habit of reading big books for learning about technology.

What does it really take to read technical books, apart from the real interest on the technology?

How can I improve my ability to read these books?

答:
Time, effort, and persistence. For example, it took me months (maybe 6 months, 30 minutes per day) to crawl through Code Complete initially. Be sure to highlight important things and make personal notes so that you can revise the essential points later on. You won't learn much by merely staring at the text.

See how to Teach Yourself Programming in Ten Years.

Title: How do people read big technical books?

ContentLicense: CC BY-SA 2.5


答:
The only pattern I can see is that you have either letters followed by digits, or digits followed by letters, or letters only.

From this point, the first step would be to separate the string into the beginning and the end, then to separate each part into a group of one or two entities:

```<code>"AB12-ZZ789" → ["AB12", "ZZ789"] → [["AB", "12"], ["ZZ", "789"]]
</code>```

The numeric entities can be then converted to numbers:

```<code>[["AB", "12"], ["ZZ", "789"]] → [["AB", 12], ["ZZ", 789]]
</code>```

Then, letters can be converted to their respective numeric representation. For example, if "A" is mapped to 0, "B" - to 1, etc., "AB" is 0 × 26 + 1, while "ZZ" is 25 × 26 + 25.

```<code>[["AB", 12], ["ZZ", 789]] → [[26, 12], [675, 789]]
</code>```

Once you do this conversion, it's pretty simple to know if the value is in a range. For example,

```<code>"HC52" → ["HC", "52"]
       → ["HC", 52]
       → [(7 × 26 + 2), 52]
       → [184, 52]
</code>```

26 ≤ 184 ≤ 675 and 12 ≤ 52 ≤ 789, so the value is in the range.

```<code>"HC999" → ["HC", "999"]
        → ["HC", 999]
        → [(7 × 26 + 2), 999]
        → [184, 999]
</code>```

26 ≤ 184 ≤ 675, but (12 ≤ 999 ≤ 789) is false, so the value is outside of the range.

Title: Extracting useful information from free text

Body:
We filter and analyse seats for events.  Apparently writing a domain query language for the floor people isn't an option.  I'm using C# 4.0 & .NET 4.0, and have relatively free reign to use whatever open-source tools are available.  </background-info>

If a request comes in for "FLOOR B", the sales people want it to show up if they've entered "FLOOR A-FLOOR F" in a filter.  The only problem I have is that there's absolutely no structure to the parsed parameters.  I get the string already concatenated (it actually uses a tilde instead of dash).  Examples I've seen so far with matches after each:

101WC-199WC  (needs to match 150WC)

AAA-ZZZ   (needs to match AAA, BBB, ABC but not BB)

LOGE15-LOGE20  (needs to match LOGE15 but not LOGE150)

At first I wanted to try just stripping off the numeric part of the lower and upper, and then incrementing through that.  The problem I have is that only some entries have numbers, sometimes the numbers AND letters increment, sometimes its all letters that increment.  Since I can't impose any kind of grammar to use (I really wanted [..] expansion syntax), I'm stuck using these entries.

Are there any suggestions for how to approach this parsing problem?

Body:
The only pattern I can see is that you have either letters followed by digits, or digits followed by letters, or letters only.

From this point, the first step would be to separate the string into the beginning and the end, then to separate each part into a group of one or two entities:

"AB12-ZZ789" → ["AB12", "ZZ789"] → [["AB", "12"], ["ZZ", "789"]]

The numeric entities can be then converted to numbers:

[["AB", "12"], ["ZZ", "789"]] → [["AB", 12], ["ZZ", 789]]

Then, letters can be converted to their respective numeric representation. For example, if "A" is mapped to 0, "B" - to 1, etc., "AB" is 0 × 26 + 1, while "ZZ" is 25 × 26 + 25.

[["AB", 12], ["ZZ", 789]] → [[26, 12], [675, 789]]

Once you do this conversion, it's pretty simple to know if the value is in a range. For example,

"HC52" → ["HC", "52"]
       → ["HC", 52]
       → [(7 × 26 + 2), 52]
       → [184, 52]

26 ≤ 184 ≤ 675 and 12 ≤ 52 ≤ 789, so the value is in the range.

"HC999" → ["HC", "999"]
        → ["HC", 999]
        → [(7 × 26 + 2), 999]
        → [184, 999]

26 ≤ 184 ≤ 675, but (12 ≤ 999 ≤ 789) is false, so the value is outside of the range.


问:
When should one use "out" parameters?
In Objective-C, there are several methods like initWithContentsOfFile:encoding:error: where one passes in a reference to an NSError object for the error: parameter. In this example, the value of the NSError object passed in can change based on what goes on at runtime when the method is being called and whether the body of the method was executed in a certain way successfully. In a way I think of this NSError object as sort of like a second return value from the method, and only differs from an object anObject in the statement return anObject; in that when this statement is called, execution leaves the method.

So my question is, not only in the context of error handling in Objective-C, but in general, when should one use an "out" parameter in place of returning said value in a return statement?

答:
This, to me, just looks like a poor initial API design choice that couldn't have been fixed without breaking a lot of existing binaries.

It's pretty much standard that if a function does something that may fail, then the success/failure is flagged through the return value, and if anything else needs to be returned it's done through a parameter that's passed by reference.

The way your example is defined does nothing (that I can see) to make the developer's life easier, unless it's the type of developer who assumes nothing can go wrong. I'm not sure how static analysis tools would cope with this convention either.

Title: When should one use "out" parameters?


问:
How do I prove or disprove "God objects" are wrong?
Problem Summary:

Long story short, I inherited a code base and a development team I am not allowed to replace and the use of God Objects is a big issue.  Going forward, I want to have us re-factor things but I am getting push-back from the teams who want to do everything with God Objects "because its easier" and this means I would not be allowed to re-factor.  I pushed back citing my years of development experience, that I'm the new boss who was hired to know these things, etc,  and so did the third party offshore companies account sales rep, and this is now at the executive level and my meeting is tomorrow and I want to go in with a lot of technical ammunition to advocate best practices because I feel it will be cheaper in the long run (And I personally feel that is what the third party is worried about) for the company.

My issue is from a technical level, I know its good long term but I'm having trouble with the ultra short term and 6 months term, and while its something I "know" I can't prove it with references and cited resources outside of one person (Robert C. Martin, aka Uncle Bob), as that is what I am being asked to do as I have been told having data from one person and only one person (Robert C Martin) is not good enough of an argument.

Question:

What are some resources I can cite directly (Title, year published, page number, quote) by well known experts in the field that explicitly say this use of "God" Objects/Classes/Systems is bad (or good, since we are looking for the most technically valid solution)?

Research I have already done:

I have a number of books here and I have searched their indexes for the use of the words "god object" and "god class". I found that oddly its almost never used and the copy of the GoF book I have for example, never uses it (At least according to the index in front of me) but I have found it in the two books below, but I want more I can use.

I checked the Wikipedia page for "God Object" and its currently a stub with little reference links so although I personally agree with that it says, it doesn't have much I can use in an environment where personal experience is not considered valid.  The book cited is also considered too old to be valid by the people I am debating these technical points with as the argument they are making is that "it was once thought to be bad but nobody could prove it, and now modern software says "god" objects are good to use".  I personally believe that this statement is incorrect, but I want to prove the truth, whatever it is.

In Robert C Martin's "Agile Principles, Patterns, and Practices in C#" (ISBN: 0-13-185725-8, hardcover) where on page 266 it states "Everybody knows that god classes are a bad idea.  We don't want to concentrate all the intelligence of a system into a single object or a single function.  One of the goals of OOD is the partitioning and distribution of behavior into many classes and many function." -- And then goes on to say sometimes its better to use God Classes anyway sometimes (Citing micro-controllers as an example).

In Robert C Martin's "Clean Code: A Handbook of Agile Software Craftsmanship" page 136 (And only this page) talks about the "God class" and calls it out as a prime example of a violation of the "classes should be small" rule he uses to promote the Single Responsibility Principle" starting on on page 138.

The problem I have is all my references and citations come from the same person (Robert C. Martin), and am from the same single person/source.  I am being told that because he is just one view, my desire to not use "God Classes" is invalid and not accepted as a standard best practice in the software industry.  Is this true?  Am I doing things wrong from a technical perspective by trying to keep to the teaching of Uncle Bob?

God Objects and Object Oriented Programming and Design:

The more I think of this the more I think this is more something you learn when you study OOP and it's never explicitly called out; Its implicit to good design is my thinking (Feel free to correct me, please, as I want to learn), the problem is I "know" this, but but not everybody does, so in this case its not considered a valid argument because I am effectively calling it out as universal truth when in fact most people are statistically ignorant of it since statistically most people are not programmers.

Conclusion:

I am at a loss on what to search for to get the best additional results to cite, since they are making a technical claim and I want to know the truth and be able to prove it with citations like a real engineer/scientist, even if I am biased against god objects due to my personal experience with code that used them.  Any assistance or citations would be deeply appreciated.

答:
You could always ask Uncle Bob himself.

The thing is, it's so obvious to people with any sense that once it's spelled out, it doesn't need to be re-referenced by a multitude of authors. There need only be one source.

Other terms you might want to start with when looking for sources are:

SOLID

Law of Demeter

Big Ball of Mud

All of these express related concepts that might yield viable reference sources, even though they don't actually name it as such.

Ultimately though, you're the boss. The reason for doing it is because you say so, and although to be considered a good manager you really should be prepared to justify your decisions; you've done that, and if there is still resistance, the correct course of action is for your team to do as they're told.

OwnerDisplayName: honestduane

OwnerDisplayName: Tom W


答:
The case for any change of practice is made by identifying the pain points created by the existing design. Specifically, you need to identify what is harder than it should be because of the existing design, what is fragile, what is breaking now, what behaviors can't be implemented in a simple manner as a direct (or even somewhat indirect) result of the current implementation, or, in some cases, how performance suffers, how much time it takes to bring a new team member up to speed, etc.

Second, working code trumps any arguments about theory or good design. This is true even for bad code, unfortunately. So you're going to have to provide a better alternative, which means you, as the advocate for better patterns and practices, will need to refactor to tease out a better design. Find a narrow, tracer-bullet style plane through the existing design, and implement a solution that, perhaps, for iteration one, keeps the god object implementation working, but defers actual implementation to the new design. Then write some code that takes advantage of this new design, and show off what you win because of this change, whether it's performance, maintainability, features, correction of bugs or race conditions, or reduction of cognitive load for the developer.

It's often a challenge to find a small enough surface area to attack in poorly architected systems, it may take longer than you'd like to deliver some initial value, and the initial payoff may not be that impressive to everybody, but you can also work on finding some advocates of your new approach if you pair on it with team members that are at least slightly sympathetic.

Lamenting the God Object only works when you're preaching to the choir. It's a tool for naming a problem, and only works for solving it when you've got a receptive audience that's senior and motivated enough to do something about it. Fixing the God object wins the argument.

Since your immediate concern appears to be executive buy-in, I think you're best off making a case that replacing this code needs to be a strategic goal and tie those to the business objectives that you're responsible for. I think you can make a case that you can provide some technical direction by first working on a technical spike on what you think should be done to replace it, preferably involving resources from one or two technical people that have reservations about the current design.

I think you've found enough resources to justify your argument; people in such meetings will only pay attention to summary of your research, and they'll stop listening after you mention two or three corroborating sources. Your focus initially should be in getting buy-off to work the problem you see, not necessarily proving someone else wrong or yourself right. This is a social problem, not a logical one.

In a technology leadership role, you need to tie any of your initiatives to business goals, so the most important thing for making your case to executives is what the work will do for those objectives. Because you're also considered the "new guy," you can't just expect people to throw away their work or expect to rapidly fall in line; you need to build some trust by proving that you can deliver. As a long term concern, in a leadership role, you also need to learn to become focused on results, but not necessarily be attached to the specifics of the outcome. You're now there to provide strategic direction, remove tactical obstacles from progress by your team, and offer your team mentorship, not win battles of credibility with your own team members.

Making a top-down decision will rarely be credible unless you have some skin in the game; if you are in a similar situation all over again, you should focus more on consensus building within your organization rather than escalating once you feel the situation is out of control.

But considering where you are now, I'd say your best bet is to argue that your approach will bring measurable long-term benefits based on your experience and that it's in line with the work by well-known practitioners like uncle Bob and co., and that you'd like to spend a few days/weeks leading by example on a narrow refactoring of the highest bang-for-buck aspect, to demonstrate what your view of good design should look like. You'll need to align whatever your case is to specific business goals beyond your personal preferences, however.

Title: How do I prove or disprove "God objects" are wrong?

Body:
Problem Summary:

Long story short, I inherited a code base and a development team I am not allowed to replace and the use of God Objects is a big issue.  Going forward, I want to have us re-factor things but I am getting push-back from the teams who want to do everything with God Objects "because its easier" and this means I would not be allowed to re-factor.  I pushed back citing my years of development experience, that I'm the new boss who was hired to know these things, etc,  and so did the third party offshore companies account sales rep, and this is now at the executive level and my meeting is tomorrow and I want to go in with a lot of technical ammunition to advocate best practices because I feel it will be cheaper in the long run (And I personally feel that is what the third party is worried about) for the company.

My issue is from a technical level, I know its good long term but I'm having trouble with the ultra short term and 6 months term, and while its something I "know" I can't prove it with references and cited resources outside of one person (Robert C. Martin, aka Uncle Bob), as that is what I am being asked to do as I have been told having data from one person and only one person (Robert C Martin) is not good enough of an argument.

Question:

What are some resources I can cite directly (Title, year published, page number, quote) by well known experts in the field that explicitly say this use of "God" Objects/Classes/Systems is bad (or good, since we are looking for the most technically valid solution)?

Research I have already done:

I have a number of books here and I have searched their indexes for the use of the words "god object" and "god class". I found that oddly its almost never used and the copy of the GoF book I have for example, never uses it (At least according to the index in front of me) but I have found it in the two books below, but I want more I can use.

I checked the Wikipedia page for "God Object" and its currently a stub with little reference links so although I personally agree with that it says, it doesn't have much I can use in an environment where personal experience is not considered valid.  The book cited is also considered too old to be valid by the people I am debating these technical points with as the argument they are making is that "it was once thought to be bad but nobody could prove it, and now modern software says "god" objects are good to use".  I personally believe that this statement is incorrect, but I want to prove the truth, whatever it is.

In Robert C Martin's "Agile Principles, Patterns, and Practices in C#" (ISBN: 0-13-185725-8, hardcover) where on page 266 it states "Everybody knows that god classes are a bad idea.  We don't want to concentrate all the intelligence of a system into a single object or a single function.  One of the goals of OOD is the partitioning and distribution of behavior into many classes and many function." -- And then goes on to say sometimes its better to use God Classes anyway sometimes (Citing micro-controllers as an example).

In Robert C Martin's "Clean Code: A Handbook of Agile Software Craftsmanship" page 136 (And only this page) talks about the "God class" and calls it out as a prime example of a violation of the "classes should be small" rule he uses to promote the Single Responsibility Principle" starting on on page 138.

The problem I have is all my references and citations come from the same person (Robert C. Martin), and am from the same single person/source.  I am being told that because he is just one view, my desire to not use "God Classes" is invalid and not accepted as a standard best practice in the software industry.  Is this true?  Am I doing things wrong from a technical perspective by trying to keep to the teaching of Uncle Bob?

God Objects and Object Oriented Programming and Design:

The more I think of this the more I think this is more something you learn when you study OOP and it's never explicitly called out; Its implicit to good design is my thinking (Feel free to correct me, please, as I want to learn), the problem is I "know" this, but but not everybody does, so in this case its not considered a valid argument because I am effectively calling it out as universal truth when in fact most people are statistically ignorant of it since statistically most people are not programmers.

Conclusion:

I am at a loss on what to search for to get the best additional results to cite, since they are making a technical claim and I want to know the truth and be able to prove it with citations like a real engineer/scientist, even if I am biased against god objects due to my personal experience with code that used them.  Any assistance or citations would be deeply appreciated.

OwnerDisplayName: JasonTrue

ContentLicense: CC BY-SA 4.0


问:
Is Extreme Programming (XP) the best way of learning from experts?
I have been involved in many development models, and have found XP to be the best for a new programmer from the aspect of learning, as the collaboration between the team members is very high and the opportunities to share knowledge are great.

What are the expert opinions on this?

答:
Yes it will helps a lot. Thanks to pair programming and highly self managing team.

Other systems like Scrum are also very well suited to work with XP.


答:
First, you need to present that any measurable organisation need to adopt industry best practices. Saying that "it just works for us!" cannot be measured, neither in time or in resource as it is simply unpredictable. Software engineering is a science as much as any other fields of science, and these concepts have been studied, researched, tested, and documented.

the God Object is an anti-pattern which states that

In software engineering, an anti-pattern (or antipattern) is a pattern
  used in social or business operations or software engineering that may
  be commonly used but is ineffective and/or counterproductive in
  practice.

In the Google IO conference of 2009, this subject was partially explained when the MVP pattern was explained. It may not be relevant to the God Object, but may give you some ammo.

Also, using this anti-pattern violates the single responsibility principle in object-oriented designs, which states that :

every class should have a single responsibility, and that
  responsibility should be entirely encapsulated by the class. All its
  services should be narrowly aligned with that responsibility.

The Decaying Code blog also talks about this and about it's solution.

We cannot talk about the single responsibility principle without talking about object coupling.

[...] coupling or dependency is the degree to which each program module relies on each one of the other modules.

Where having a tightly coupled system may cause assembly of modules [to] require more effort and/or time [to maintain] due to the increased inter-module dependency. A higher level of object couping means less cohesion, and vice versa. God objects are a good example of tight coupling as they know more than they should, thus overloads them with responsibility, thus limit greatly code reusability.

When designing a complex application, simplicity must come to mind. Big problems must be decomposed into smaller ones, which are easier to manage, test, and document. This is especially true in an object-oriented paradigm.

With this argument, we do loop back to the anti-pattern argument, but this paradigm is all about patterns, real world object representation and, ultimatly, data encapsulation.

You are part right when you say that these "good practices" are more existent in classrooms. However, I do have teaching experiences in college (and some university) and I only saw these principles being taught in universities, especially in engineering faculties. Which is sad. But like any good practice, those who strive to better themselves usually learn some basic design patterns, and eventually understand how to jungle between coupling and cohesion.

What I usually teach to students is that, it may seem to require more efforts to adopt good programming standards, but it always pay off in the long run. A good example would be someone asking a programmer to write a sorting function. The programmer has two choices; 1) write a quick bubble sort function (less than 5 minutes) that will not be sustainable as the list of elements grow, or 2) write a more complex (aka optimized) sorting algorithm (quick sort, etc.) that will scale better with bigger lists.

OwnerDisplayName: Yanick Rochon


问:
Can I maintain copyright of the name/logo of an otherwise copyleft (GPL) application?
I'd like to release an application that basically has the license of "the code is GPLd but forks cannot use the name or logo", with the intent of avoiding confusion to users.

Is that possible or is it an all or nothing deal?

答:
You can trademark the name and release the code as open-source. "Common Law" trademarks are free, you just have to say that it is trademarked, but not as easy to enforce.

Keep in mind I am not a lawyer and could be wrong. Talk to a professional for legal advice.


答:
In the case of the NSString initWithContentsOfFile:encoding:error: method that you cite, an error is handled by returning nil from the initializer. If this happens, then you can interrogate the error object (if you provided one) to get details about the error.

```<code>NSError *error = nil;
NSString *someString = [[NSString alloc] initWithContentsOfFile:somePath encoding:someEncoding error:&error];
if (!someString) {
    // oops - check out the error
} else {
    // continue using the string
}
</code>```

Basically, this method design pattern needs to be in place because the return value can't be used to provide error information. The return type needs to be the initialized object (or nil). So the only option for getting more detailed error information is to provide the "out" parameter for the error.

To answer your more general question, the only time I've ever used an "out" parameter is when the method needs to return a primary value but you also need a secondary return value.

I can't think of any void methods that have "out" parameters (in the iOS SDK).

NSString gives us a non-error example with the initWithContentsOfFile:usedEncoding:error: initializer. The usedEncoding parameter is an  "out" parameter. The primary return value is the string. The secondary return value is the encoding that was used to convert the file to a string.

Title: When should one use "out" parameters?

Body:
In Objective-C, there are several methods like initWithContentsOfFile:encoding:error: where one passes in a reference to an NSError object for the error: parameter. In this example, the value of the NSError object passed in can change based on what goes on at runtime when the method is being called and whether the body of the method was executed in a certain way successfully. In a way I think of this NSError object as sort of like a second return value from the method, and only differs from an object anObject in the statement return anObject; in that when this statement is called, execution leaves the method.

So my question is, not only in the context of error handling in Objective-C, but in general, when should one use an "out" parameter in place of returning said value in a return statement?

Body:
In the case of the NSString initWithContentsOfFile:encoding:error: method that you cite, an error is handled by returning nil from the initializer. If this happens, then you can interrogate the error object (if you provided one) to get details about the error.

NSError *error = nil;
NSString *someString = [[NSString alloc] initWithContentsOfFile:somePath encoding:someEncoding error:&error];
if (!someString) {
    // oops - check out the error
} else {
    // continue using the string
}

Basically, this method design pattern needs to be in place because the return value can't be used to provide error information. The return type needs to be the initialized object (or nil). So the only option for getting more detailed error information is to provide the "out" parameter for the error.

To answer your more general question, the only time I've ever used an "out" parameter is when the method needs to return a primary value but you also need a secondary return value.

I can't think of any void methods that have "out" parameters (in the iOS SDK).

NSString gives us a non-error example with the initWithContentsOfFile:usedEncoding:error: initializer. The usedEncoding parameter is an  "out" parameter. The primary return value is the string. The secondary return value is the encoding that was used to convert the file to a string.


答:
Yes:

"However, some licenses had requirements that weren't really restrictive, because they were so easy to comply with. For example, some licenses say that they don't give you permission to use certain trademarks. That's not really an additional restriction: if that clause wasn't there, you still wouldn't have permission to use the trademark. We always said those licenses were compatible with GPLv2, too."

http://www.gnu.org/licenses/quick-guide-gplv3.html

Title: Can I maintain copyright of the name/logo of an otherwise copyleft (GPL) application?

Body:
I'd like to release an application that basically has the license of "the code is GPLd but forks cannot use the name or logo", with the intent of avoiding confusion to users.

Is that possible or is it an all or nothing deal?


问:
SQL RDBMS : one query or multiple calls
After looking around the internet, I decided to create DAOs that returned objects (POJOs) to the calling business logic function/method.

For example: a Customer object with a Address reference would be split in the RDBMS into two tables; Customer and ADDRESS. The CustomerDAO would be in charge of joining the data from the two tables and create both an Address POJO and Customer POJO adding the address to the customer object. Finally return the fulll Customer POJO.

Simple, however, now i am at a point where i need to join three or four tables and each representing an attribute or list of attributes for the resulting POJO. The sql will include a group by but i will still result with multiple rows for the same pojo, because some of the tables are joining a one to many relationship. My app code will now have to loop through all the rows trying to figure out if the rows are the same with different attributes or if the record should be a new POJO.

Should I continue to create my daos using this technique or break up my Pojo creation into multiple db calls to make the code easier to understand and maintain?

答:
You should put correctness first.  Create your data structures so that they model the domain in question in a correct and effective way that makes it easy for your code to work with.

Beyond that, try to minimize database calls, especially if the database is not local (residing on the same machine as the program calling it).  Network latency is a real consideration here, and it can be non-trivial.

Let's say you have an operation that requires 10 database calls.  If your network latency is 100 ms, this operation will take 1 second of pure overhead just communicating with the server, in addition to whatever amount of time it takes to actually do the work involved.  If your latency is 1 second, it will waste 10 seconds on network latency alone.  But if you get that down from 10 calls to 1, suddenly even in really ugly latency conditions, you're not wasting much time on network overhead.

As a general rule of thumb, if you're just retrieving data simply (and not doing heavy processing of the data inside the database server or on the client), the biggest bottleneck by far in a system with a non-local database will be network latency.  So if you can reduce the number of calls, even if it means you need to do extra work on the client side once you've retrieved it, you'll still probably come out ahead.

As always, remember the most important rule of optimization: measure first!  Optimize by hard data, not by rules of thumb like the one I just described, or you could easily end up doing a lot of hard work that slows things down!  But in general, keeping the number of queries down is usually the best route.

Title: SQL RDBMS : one query or multiple calls


答: How to eat an elephant? One bite at a time.</p>

Title: How do people read big technical books?

Body:
I see that most of the good programmers have the habit of reading big books for learning about technology.

What does it really take to read technical books, apart from the real interest on the technology?

How can I improve my ability to read these books?


问:
Is there a perf hit using mule as a container vs. standard JEE container like Weblogic?
Our team is considering using Mule in a large scale medium volume internal facing transactional banking application.

At first Mule would just be used as an application server although it is possible some of its esb/orchestration features would be used in the future.

I have no experience with mule, being new on the team. But my gut says Mule would not be as performant as Weblogic or Glassfish as a deployment container.

Does anyone have any comparison stories to share that might shed light?

答:
It's largely impossible to determine performance without actually measuring - I can't say that I've noted WebLogic or Glassfish applications to suddenly become "high performance" simply because of the container.

A few other items you might want to consider (after I took a look at Mule deployment):

Mule appears to be capable of running 'standalone' (assuming running a process from a JVM?) or within a container (like Glassfish, etc. - seems to be a 'web container' app.)  You might want to look at the pros/cons of running Mule in standalone vs. container.

There does seem to be quite a bit of clustering / load balancing available with Mule - you might also want to consider how easy it is to set up and monitor clustered applications versus WebLogic/Glassfish.

You might also take a look at how apps are 'deployed' with Mule - that part wasn't immediately clear when scanning the documentation.


答: You could cite some of the most basic OOP principals such as loose coupling and high cohesion. A "God object" sounds like it couples unrelated classes and has low cohesion.</p>


答:
If the query is returning more rows than expected then the query if badly written.

You have to run a query to get the data for Customer POJO. That query should return a single row, so the DAO populates a single POJO.

Then a second query is run to get the rows from the "many" table , given the foreign key ( customer ID ) and create as many POJOS as rows are found. Then that list of address objects is assigned to the customers POJO.

Customer class has a member of type List<Address>.

If the DB access is expensive, you can do it lazily, that's to say, fetch the addresses only when getAddress of getAddressList is first called.

That same technique can be used to all aggregations or compositions in your Customer class that are read from the DB.

EDIT:

About performance: Customer table must have a PK, maybe customerID, so retrieving the row must be lightning fast if you are using a modern RDBMS. Also the child tables must have a PK, and a FK pointing to the PK of parent table. That FK is also indexed. That's like the very basic task a RDBMS is made for.

Regarding the network traffic between the app server (or client app) and the DB server involved, that can also be optimized.

The point is:

Hardware and transport issues can be solved by trowing money at then.

Complexity problems derived from writing code to do things the RDBMS does more efficiently, cannot be solved by throwing money at them.

Hardware is cheap, programmers are expensive.

Title: SQL RDBMS : one query or multiple calls

Body:
After looking around the internet, I decided to create DAOs that returned objects (POJOs) to the calling business logic function/method.

For example: a Customer object with a Address reference would be split in the RDBMS into two tables; Customer and ADDRESS. The CustomerDAO would be in charge of joining the data from the two tables and create both an Address POJO and Customer POJO adding the address to the customer object. Finally return the fulll Customer POJO.

Simple, however, now i am at a point where i need to join three or four tables and each representing an attribute or list of attributes for the resulting POJO. The sql will include a group by but i will still result with multiple rows for the same pojo, because some of the tables are joining a one to many relationship. My app code will now have to loop through all the rows trying to figure out if the rows are the same with different attributes or if the record should be a new POJO.

Should I continue to create my daos using this technique or break up my Pojo creation into multiple db calls to make the code easier to understand and maintain?


问:
Software Manager who makes developers do Project Management
I'm a software developer working in an embedded systems company.
We have a Project Manager, who takes care of the overall project schedule (including electrical, quality, software and manufacturing) hence his software schedule is very brief.

We also have a Software Manager, who's my boss.
He makes me write and maintain the software schedule, design documents (high and low level design), SRS, change management, verification plans and reports, release management, reviews, and of course the software.

We only have one Test Engineer for the whole software team (10 members), and at any given time, there are a couple of projects going on.

I'm spending 80% of my time making these documents. My boss comes from a Process background, and believes what we need is better documentation to improve software:

He considers the design to be paramount, coding is "just writing the design down", it shouldn't take too long, and "all the code should be written before the hardware is ready".

Doesn't understand the difference between a Central & Distributed Version control, even after we told him its easier to collaborate with a distributed model.

Doesn't understand code, and wants to understand every bug and its proposed solution.

Believes verification should be done by developer, and validation by the Tester. Thing is though, our verification only checks if implementation is correct (we don't write unit tests, it's never considered in the schedule), and validation is black box testing, so the units tests are missing.

I'm really confused.

Am I responsible for maintaining all these documents? It makes me feel like I'm doing the Software Project Management, in essence. I'm ok with technical documentation, but I believe scheduling/planning should not be done by the developer.

I don't really like creating documents, I want to solve problems and write code. In my experience, creating design documents only helps to an extent, its never the solution to better or faster code.

I feel the boss doesn't really care about making better products, but only about being a good manager in the eyes of the management.

What can I do? This whole year I've done 3 months of actual coding, the rest just spent in making documents and waiting for bug reports from clients.

答:
You're talking about medical systems... so safety is paramount - and therefore the documentation (specifically traceability) is essential.

One tester seems a bit light, but other than that, yes - you are responsible for ensuring the documentation is in place.

My experience in the medical world is limited, but over in the aerospace/defence world we have Do-178B (now C) which prescribes a lifecycle model that specifies the documentation and level of testing necessary (depending on the safety criticality [more specifically, the design assurance level] of the software), and in the automotive world we have ISO26262 which does likewise.

If the documentation is not in place, the product doesn't get certificated.

But the important thing is to work with the required documentation to make your product better... do not try and reverse-engineer the documentation as an after-thought because then it serves no real-world purpose.


答: One could argue that a "usability test" of Fortran II leaded to a complete new language:  BASIC, which was designed to be more usable (especially for beginners) than its predecessor. If you want to know more about the origins and design goals, there is a whole chapter in this book concerning that topic.

Title: Has the syntax of any programming language been usability tested?

Body: Before being release to the public, has the syntax of any programming language undergone usability testing? If so, what kinds of testing was performed, what were the results, and what impact did the testing results have on the design of the language?</p>


问:
What is development automation?
When someone refers to "Development Automation", what is it exactly?

What are some frameworks for development automation?

My boss asked me to develop a strategy for implementing such in the company but I have not found much information related to the matter. Google seems to think I am referring to testing automation, which is not the case.

答:
While "development automation" is not a commonly used and recognized term of the software dev. industry, I have heard it many times in my life.

Business people normally use it to refer to "anything that can speed up the development process and allow the company to bypass most, if not all, of the software development process, jumping from a simple business-level wish list to a ready-for-the-market product (writing as little code as possible and hiring as little programmers as possible)". In other terms: "any technology/methodology that can reduce software development to the most complicated thing the average business guy can understand: Lego (TM)". ;-)

Given this definition, there are three technologies/methodologies that fit into it:

RAD (Rapid Application Development)

Code generation

MDA/MDD (Model-Driven Architecture/Developement)

These techniques can be used only if/when it is possible to make a few strong assumptions about the nature of the project at hand.

For example, Ruby-on-Rails and Django can do a lot of code generation ("software development automation") because they take for granted that what the programmer wants to produce is a web application mainly involved in exposing a database (a model) to the end user through a business-logic layer (a controller) and a web page (a view).

If you can make such strong assumptions, you can automate a lot. Have a look at these tools to get a feeling:

http://en.wikipedia.org/wiki/DaDaBIK

http://www.dadabik.org/

http://www.andromda.org/docs/index.html

And, of course, have a look at the powerful code-generation tools used by RoR and Django.

BTW: A special case of "code generation" is build automation. That is: the kind of build-time tricks you can do with Maven, Ant, Rake, Scon, Rake, etc.

In the general software development arena, these tools have seen very little success because (normally) you cannot do such assumptions about the nature of the project at hand. When you are developing something new or something that is strongly custom-tailored usually you need to work with the finest "logical granularity" allowed by your tools, that is the same granularity allowed by your programming language. Anything else would be just to rough for the task at hand.

Title: What is development automation?


答:
I suggest you consider using DTOs after you have performed the correct join on the data source using SQL (if you are using RDBMs). In addition, you can also utilize the Multiple Result Sets concept to return different sets of objects in 1 server call if necessary.

DTO is not POJO (see:Difference-between-DTO-and-POCO - I know you are not asking about .NET but the concept is likely to be similar for this argument.)

Using this approach you will communicate less data between the server and the client and you will not have to do joins in the client logic manually specially, that to my knowledge, Java does not provide an equivalent of .Net's LINQ.

Also, consider using (or getting to know about) a good ORM. A good ORM will most likely offer you a practical approach.

Title: SQL RDBMS : one query or multiple calls


答:
It's something that I think is missing functionality from the JEE EAR specification - the ability to share web sessions across multiple web archives bound within an EAR.

App servers such as Weblogic have non std implementations for this functionality.

Title: Why can't WARs share session info?

Body:
I have seen several developers looking for a solution for this problem: accessing session information from a different WAR (even when inside the same EAR) - here are some samples: Any way to share session state between different applications in tomcat?, Access session of another web application, different WAR files, shared resources, Tomcat: How to share data between two applications?, What does the crossContext attribute do in Tomcat? Does it enable session sharing? and so on...

From all I have searched, there are some specific solutions depending on the container, but it is somehow 'contrary to the specification'. I have also looked through Java EE specification without any luck on finding an answer.

Some developers talk about coupling between web applications, but I tend to disagree. What is the reason one would keep WARs inside the same EAR if not coupling? EJBs, for instance, can be accessed locally (even if inside another EJB JAR within the same EAR).

More specifically, one of my WARs handles authentication and authorization, and I would like to share this information with other WARs (in the same EAR). I have managed to work around similar problems before by packaging WARs as JARs and putting them into a singular WAR project (WEB-INF/lib). Yet I do not like this solution (it requires a huge effort on servlet naming and so on).

And no solution has answered the first (and most important) question: Why can't WARs share session information?


答: I think this was done on purpose, to avoid different web apps accidentally overwriting each others session information. It might come handy in your case, but in general, you don't want users to make the app crash or escalate their privileges just because they use two web apps at the same time. It's not exactly difficult to explicitely share information between web apps; just make a class with a static HashMap, use GUIDs as keys and transfer them as part of the URL or HTTP parameter.</p>

Title: Why can't WARs share session info?


问:
Benefits of TOGAF or similar?
I can read the website blurb and be impressed by the alleged benefits, but I haven't worked anywhere or with anyone who followed the TOGAF (or any alternative) architecture framework.

Our organisation has declared itself dedicated to moving from what is currently a fairly shambolic design & development model towards something approaching a modern structured process.

Things like TOGAF have been mentioned as helping achieve a world-class enterprise development environment (!) but I'm convinced that no-one here really understands the real-world benefits that wholesale adoption might bring and, perhaps more importantly, the effort/pain required to achieve the same.

Do you have experience in using TOGAF or similar to wrestle control in an organisation?  Do you think that use of the framework brought any benefit?

Edit:  For clarification TOGAF is "The Open Group Architecture Framework", a detailed method and set of tools for developing an enterprise architecture.  See: http://www.opengroup.org/architecture/togaf8-doc/arch/

答:
Well, I have seen a couple of companies that were trying to adopt methodologies/frameworks similar to TOGAF (but not TOGAF) and in all of these cases I just witnessed failures.

As long as I have seen, there are at least three reasons for such failures:

These metodologies/frameworks were so complicated that required a team by themself to be managed/adopted/implemented. The company ended up in doing only that. No time/people left for the real job. Even worse: this stuff interfered heavily with the day-to-day work.

These metodologies/frameworks do not actually try to make the enterprise architecture and its business processes more manageable or more reliable. They just try to organize them (in a very academic way). This makes the whole thing more understandable/palatable from the (external) point of view of the management/business people but do not make it any better for the  people who do the real work.

These metodologies/frameworks take for granted that the management/business people know what they want to produce/provide beforehand. This is often not true. Making a marketable product/service is often a matter of experimenting and changing. The real nature of the product/service being produced/provided is really known only at the end of a long R&D process, not at the beginning. Trying to formalize/organize such an explorative process is just plain unrealistic.

As jkhollhepp said, If you have to re-organize a complicated architecture, it could be very hard to start from a blank page. In this case, using TOGAF or a similar framework as a starting point can be helpful. Despite this, I have the feeling that you should use TOGAF as a theoretical/conceptual model only. Any attempt to actually use it should be avoided until someone is able to demonstrate that it is actally required or unavoidable.

Title: Benefits of TOGAF or similar?


问:
Project Management - Asana / activeCollab / basecamp / alternative / none
I don't know whether this should be on programmers - I've been looking at the above three apps over the past few weeks just for myself and I'm in two minds. All three look good, are easy to use, and I came to this conclusion;

Asana is the easiest to use

ActiveCollab is the feature rich and easiest flow

BaseCamp is the best UX / design

But I didn't really find my workflow was any more quicker / efficient, in fact it was a bit slower and organized.

Is there a realistic place for them in workflow - should programmers use them for themselves, or only when a project manager can take control of it?

答:
I think Wrike would also be a good alternative.

It is really flexible and easy to customize for your own work flow. For instance, I think it might be handy for bug tracking. You can create separate tags for each bug priority level, as well as categorize them by status, for example opened, in progress, need to test, resolved etc.  It is really helpful to have all the files, like screenshots, stored in one place together with the task, so that every team member can have access to the most up-to-date info.


问:
What is the best practice, point of view of well experienced developers
My manager pushes me to use his self defined best practices. All of these practices are based on is own assumptions. I disagree with them and I would like to have some feedback of well experienced people about these practices. I would prefer answers from people involved in the maintenance of huge products and people whom have maintained the product for years. Developers with 15+ years of experience are preferred because my manager has that much experience himself. I have 7 years of experience.

Here are the practices he wants  me to use:

never extends classes, use composition and interface instead because extending classes are unmaintainable and difficult to debug.

What I think about that

Extend when needed, respect "Liskov's Substitution Principle" and you'll never be stuck with a problem, but prefer composition and decoration. I don't know any serious project which has banned inheriting, sometimes it's impossible to not use that, i.e. in a UI framework. Design patterns are just unusable.

In PHP, for simple use cases (for example a user needs a web interface to view a database table), his "best practice" is: copy some random php code wich we own, paste and modify it, put html and php code in same file, never use classes in PHP, it doesn't work well for small jobs, and in fact it doesn't work well at all, there is no good tool to work with. Copy & paste PHP code is good practice for maintenance because scripts are independent, if you have a bug somewhere you can fix it without side effects.

What I think about that:

NEVER EVER COPY code or do it because you have five minutes to deliver something,  you will do some refactoring after that. Copy & paste code is a beginners error, if you have errors you'll have the error everywhere any time you have pasted it's a nightmare to maintain. If you repsect the "Open Close Principle" you'll rarely get edge effects, use unit test if you are afraid of that. For small jobs in PHP use at least something you get or write the HTML separately from the PHP code and reuse it any time you need it. Classes in PHP are mature, not as mature as other languages like python or java, but they are usable. There is tools to work with classes in PHP like Zend Studio that work very well. The use of classes or not depends not on the language you use but the programming paradigm you have choosen. I'm a OOP developer, I use PHP5, why do I have to shoot myself in the foot?

When you find a simple bug in the code, and you can fix it simply, if you are not working on the code where you have found it, never fix it, even if it takes 5 seconds.

He says to me his "best practices" are driven by the fact that he has a lot of experience in maintaining software in production (14 years) and he now knows what works and what doesn't work, what the community says is a fad, and the people advocating such principles as never copy & paste code, are not evolved in maintaining applications.

What I think about that:

If you find a bug fix it if you can do it quickly inform the people who've touched that code before, check if you have not introduced a new bug, ideally add a unit test for it.

I currently work on a web commerce project, which serves 15k unique users per day. The code base has to be maintained and has been maintained this way since 2005.

Ideally you include a short description of your position and experience in terms of years effectively maintaining an application which has been in production for real.

答:
O my...

Inheritance vs composition

About inheritance versus composition. Both have their use cases, it is as simple as that. There is no good reason never to use inheritance or never to use composition.

If you have a different types of webshop products: say basic (can of coke, can of sprite), configurable (a sandwhich with an option to choose type of bread and toppings) they are bound to have things in common like title, price, etc. There are also things (predominantly in the configurable product probably) that are unique to the implementation. I would always use inheritance for this.

If you have serious webshop with prices, discounts, different vat percentages,etc, I would always make Price a seperate object since you're bound to do a lot of calculating that you want to isolate and unit-test. I would never extend Product from Price however. So this example is part composite (Price) and part inheritance (Product type tree). Common sense and use case are keywords here.

Copy/paste vs creating

Again, there is no right and wrong here. I hardly ever copy anything, but using something as a template to quickly setup something else might be worth the time. I agree with you however, that since you need to change function names, class names, variable names and slightly change the algorithm, the time you gain is very little at best. If you do not need to change things by the way the function should be re-used. If you change a little the function should be more robust and be re-used.

What can be convenient is the following. At my job we have a large system that consists of loads of modules. Each module has an index, some basic folders, a setup file, a plugin registry, etc. Creating a new module with all those files isn't something we do manually. There is a script that takes some parameters and does the work for you. Copy and pasting a small module and working from there is a no no, generating exactly what is necessary is great.

By the way, copying and pasting is NEVER good for maintenance. It means if you have a bug somewhere you're likely to have copied to other unknown places as well. I'd rather fix a bug in one location only. Most certainly since I'll write a test and it will never occur again.

Mix HTML and PHP

Please. Do. Not. Do. it.

We're currently in the process of migrating to twig as a template engine. This is so much better for development and design. For development it means cleaner readable code without for loops and tricks to add classes (odd, even, first, last), for design it means they have simple html like template files that they can maintain themselves.

I am truly happy with that change and we see the fruits of this migration on a daily basis.

To class or not to class

This is style related. But the fact that it doesn't work at all, that there are no good tools is plain nonsense. PHP OO has come a long way. I'd say about 70% of our current code base is object oriented and about 98% of newly written code is. Everything is functioning just fine.

I can imagine that you wouldn't write a class, instantiate it and call the single method that it holds for a simple operation. I do it, but this is heavily personal preference related. I agree with you, if you're used to OO and have php 5 available, why not use it. The only reason I can come up with is the rest of the development team doesn't know or understand OO. If you alone in a team codes a specific way, you can't expect the rest to adapt.

There are brilliant editors around, I love PHPStorm. But even vim can be configured to work with PHP like a bliss. I do not know what kind of tools your manager wants but I can't say I miss something.

Fixing bugs

I can't figure out why you'd not fix a bug you encountered. I can imagine if the code is complex you'd get the person who wrote it originally involved, but ignoring it altogether is plain stupid. Not fixing a simple bug if it right in your face is even negligent to your customers.

Concerning me

I work on a codebase of 2000000 lines of code that is used by tens of thousands of users. I work in a team with 10 other developers. I'm coding professionally for somewhere around 5 years but ever since my first contact with BASIC (about15 years ago) for fun. I would like to take this opportunity to state that experience isn't everything. I'm certainly not all knowing, absolutely not done learning but it sounds to me that your manager, 15 years experience or not, isn't either.

Also I do agree with the first comment on your post. Trying to get your manager to agree with you might a waste of time, it seems he made up his mind. Hopefully good arguments might help you a bit though :)

I would like to end with a sincere: Good Luck!


答:
If by language usability you mean how the syntax and semantics of a programming language influences productivity, some studies have been conducted to evaluate the average productivity (time needed to implement a given program and quality of the solution) of programmers using several languages.

You can find some information (with citations of further articles) on this page.
The page has been written by a Lisp programmer so one might argue that it is biased (i.e. that it presents information that is favorable to Lisp). Still I find it interesting to look at how such experiments can be conducted and what one can try to measure. Also, the cited articles may provide more links to related studies.


答: I would say regardless of methodology, the group must have the right attitude when sharing their knowledge. Where participants don't worry about prestige, and dare to ask questions from each other.</p>

Title: Is Extreme Programming (XP) the best way of learning from experts?

Body:
I have been involved in many development models, and have found XP to be the best for a new programmer from the aspect of learning, as the collaboration between the team members is very high and the opportunities to share knowledge are great.

What are the expert opinions on this?


问:
How do you balance between "do it right" and "do it ASAP" in your daily work?
I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, what I end up doing is writing patch upon a patch; just because there is no time, clients are waiting, a bug should be fixed overnight, the company is losing money on this problem, a manager is pressing hard etc., etc.

I know perfectly well that in the long term I am wasting more time on these patches, but as this time spans months of work, nobody cares. Also, as one of my managers used to say: "we don't know if there will be a long term if we don't fix it now."

I am sure I am not the only one entrapped in these endless real/ideal choice cycles. So how do you, my fellow programmers, cope with this?

UPDATE:
Thank you all for this interesting discussion.
It is sad that so many people have to choose daily between a quantity and a quality of their code. Still, surprisingly many, people think it is possible to win this battle, so thank you all for this encouragement.

答: When in emergency create the patching solution. Create a new bug in bug tracking mentioning this. Make it right, whenever you have apt time. </p>


答:
Actually, this is a very difficult question because there is no absolutely right answer. In our organization we have been putting better processes in place to produce better code. We updated our coding standards to reflect how we, as a group, write code, and we have instituted a very strong test/refactor/design/code loop. We deliver continually or at least try to. At the very least, we have something to show the stakeholders every two weeks. We feel that we are software craftsmen and morale is high. But, despite all these checks and balances, we suffer from the same problem you do.

At the end of the day, we are delivering a product to a paying customer. This customer has needs and expectations, realistic or not. Often the sales team gets us into trouble just to get a commission. Sometimes the customer has go-live expectations that are unrealistic or demand change even though we have a contract in place. Timelines happen. PTO and lost days during a sprint can happen. All sorts of little things can culminate in a situation where we are forced into the conundrum of "do it right" or "do it ASAP." Almost always, we are forced to "do it ASAP."

As software craftsmen, developers, programmers, people who code for a job -- it is our natural inclination to "do it right." "Do it ASAP" is what happens when we work to survive, as most of us do. The balance is hard.

I always start by approaching executive management (I am Director of Software Development and an active developer in that group) to defend the schedule, team and work being done. Usually at that point I'm told the customer has to have it now and it has to work. When I know there is no room for negotiation or give, I go back and work with the team to see what corners can be cut. I won't sacrifice quality in the feature that is driving the customer's need to get it ASAP, but something will go and it will get pushed into another sprint. This is almost always OK.

When you are unable to deliver because there are so many bugs, code quality is bad and getting worse, and timelines are getting shorter, then you are in a different situation than what I describe. In that case, current or past mismanagement, bad development practices that led to poor code quality, or other factors may be taking you on a death march.

My opinion here is to do your best to defend good code and best practices to start pulling your company out of the trenches. If there isn't a single colleague willing to listen or go to bat for the group against management, then it might be time to start looking for a new job.

In the end, real life trumps all. If you are working for a company that needs to sell what you are developing, then you will encounter this trade-off daily. Only by striving to achieve good development principles early on have I been successful at staying ahead of the code quality curve.

The push and pull between developers and salesmen reminds me of a joke. "What's the difference between a used car salesman and a software salesman? At least the used car salesman knows he is lying." Keep your chin up and try to "do the right thing" as you go.

Title: How do you balance between "do it right" and "do it ASAP" in your daily work?

Body:
I find myself pondering over this question from time to time, again and again. I want to do things the right way: to write clean, understandable and correct code that is easy to maintain. However, what I end up doing is writing patch upon a patch; just because there is no time, clients are waiting, a bug should be fixed overnight, the company is losing money on this problem, a manager is pressing hard etc., etc.

I know perfectly well that in the long term I am wasting more time on these patches, but as this time spans months of work, nobody cares. Also, as one of my managers used to say: "we don't know if there will be a long term if we don't fix it now."

I am sure I am not the only one entrapped in these endless real/ideal choice cycles. So how do you, my fellow programmers, cope with this?

UPDATE:
Thank you all for this interesting discussion.
It is sad that so many people have to choose daily between a quantity and a quality of their code. Still, surprisingly many, people think it is possible to win this battle, so thank you all for this encouragement.


问:
Why can't WARs share session info?
I have seen several developers looking for a solution for this problem: accessing session information from a different WAR (even when inside the same EAR) - here are some samples: Any way to share session state between different applications in tomcat?, Access session of another web application, different WAR files, shared resources, Tomcat: How to share data between two applications?, What does the crossContext attribute do in Tomcat? Does it enable session sharing? and so on...

From all I have searched, there are some specific solutions depending on the container, but it is somehow 'contrary to the specification'. I have also looked through Java EE specification without any luck on finding an answer.

Some developers talk about coupling between web applications, but I tend to disagree. What is the reason one would keep WARs inside the same EAR if not coupling? EJBs, for instance, can be accessed locally (even if inside another EJB JAR within the same EAR).

More specifically, one of my WARs handles authentication and authorization, and I would like to share this information with other WARs (in the same EAR). I have managed to work around similar problems before by packaging WARs as JARs and putting them into a singular WAR project (WEB-INF/lib). Yet I do not like this solution (it requires a huge effort on servlet naming and so on).

And no solution has answered the first (and most important) question: Why can't WARs share session information?

答:
Treat an EAR like a pseudo-virtual machine

An EAR is simply a collection of WAR files that share common configuration and libraries, usually from JARs. This enables a collection of inter-dependent services to be managed more easily within an application container. Thus you can think of an EAR as a simple form of virtual machine once it is deployed into its container.

In the same way that one process on a virtual machine cannot affect another, the same is true for an EAR. All the WARs are isolated to protect their internal state.

Scaling authentication

In general web applications need to be stateless to scale well. Having a lot of information in the session is an anti-pattern that prevents this. This leads to a conflict between the stateless nature of HTTP and the need to maintain a speedy, customised user experience. Authentication is a classic use case, and is prevalent in chatty APIs that require a lot of authenticated requests to deliver end-user functionality.

Single Sign On and Single Sign Off need careful signalling to work correctly (consider partial Sign Off), particularly when horizontal scaling is in place. Simply sharing session state is almost never a good solution and a better approach is to use a single point of reference for the user information that all nodes in the cluster have access to.

Concentrating on speedy cached access to relevant information will yield far more scalable results than some complex, fragile session sharing solution.

Title: Why can't WARs share session info?


答:
Whenever you have time for doing something right, use it - write the best code you can, and improve it steadily. Don't make your job harder by beeing sloppy and introducing technical debt when there is no need to.

Emergency calls for fixing a severe bug are no things you can control by yourself, when they occur, you have to react ASAP, that's life. Of course, if you are under the impression that your whole job consists of emergency calls, and you have never enough time for doing things right, then you are on a road to burn-out and should talk to your boss.

If that does not help, there is still "Scotty's strategy" to get enough time for doing things right: multiply all your estimates by a factor of 4:

http://blogs.popart.com/2007/07/what-scotty-from-star-trek-can-teach-us-about-managing-expectations/


答:
I often skim the book a couple times, reading sections that catch my eye. After that I have a good idea what's in the book and can grab it later when I need to learn more about something. Then, as time permits, I'll read through it more methodically.

I've been developing over 30 years, and taught myself the majority of what I know by reading and trying what I've read. I'm very much a hands-on learner and like to tinker and tweak as I try out sample code if I'm unsure about something.

It's essential to keep learning if you want to make a decent living in programming. What technologies you know now and think are hot will be stale and over crowded in five years so you have to keep learning. Developers don't have the luxury of learning one thing and then relaxing. That's partly good and partly bad because the burden is on us to keep learning, but I think most developers love the creative challenge so we accept that price.

Title: How do people read big technical books?


问:
How to reduce errors in dynamic language such as python, and improve my code quality
I post the origin question in stackoverflow, some people suggest me to post here

I've always have trouble with dynamic language like Python.

Several problems:

Typo error, I can use pylint to reduce some of these errors. But there's still some errors that pylint can not figure out.

Object type error, I often forgot what type of the parameter is, int? str? some object? Also, forgot the type of some object in my code.

Unit test might help me sometimes, but I'm not always have enough time to do UT. When I need a script to do a small job, the line of code are 100 - 200 lines, not big, but I don't have time to do the unit test, because I need to use the script as soon as possible. So, many errors appear.

So, any idea on how to reduce the number of these problems?

答:
For the object type problem you could use Hungarian Notation. Most programmers I know (including myself) think it's ugly, but if that's often recurring problem for you, this would most likely work.

For typo errors a IDE or Texteditor with syntax highlighting, code completion and similar functionality could help if you don't use this already.