问:
Alternate approaches to creating custom forms in a web application
We are putting together some distribution software, selling about 150K SKU's. Some of our items have additional requirements in order to be sold that are dictated by our vendors. For instance one type of product that we sell are prosthetic feet. Some vendors require that we capture the users weight, activity level, and some other information. This is just one example there are many different kinds of products that might have this kind of requirement (a custom set of information collected from the customer to complete the sale).

The direct approach is to just create custom forms for each requirement and create new forms when new requirements are needed. This works. It's straightforward, but its also a PIA. I would like to be able to kick this back to our product team that handles entering in new items rather than having to have them always come back to us.

The project is a web application based on python (Turbogears). Not sure if this was relevant as the question is more general than this but put it here just in case.

How would you approach this situation to minimize or remove your involvement with creating/adding these forms after site moves to production?

答:
You could make a form-creating wizard and package it with the product.  Essentially, it would allow the vendor(or product team) to create any number of forms of all shapes and sizes.  Upon creation of the form, any necessary backend changes would be automatically scripted out and executed.

So, the vendor(or product team) would go to an area of the application called something like "All Forms" or "My Forms" to see the forms they or someone else has created.  Or, they could choose "Create New Form" to use the wizard.


问:
How to structure process description documentation?
I'm writing a document describing process improvement recommendations. I have some best practices I've learned so far. I use those practices most of the time. But I suppose there are other ways to approach the task of writing formal process description document.

So, how do you usually structure your documentation? As you could already find out, I'm especially interested in structuring formal process description documents which are usually created by QA and sometimes Project Managers. What sections should it contain?

My documents usually contain following sections:

Content

Goal

Scope

Terms and abbreviations

Inputs

Process description

Artifacts

Outputs

What else should there be? Did I forget something? Are there other approaches for structuring formal documents? Link to best practices descriptions are greatly appreciated.

答:
My only recommendation is to remember the old adage "a picture is worth a thousand words", especially when describing a process.  Make liberal use of flowcharts and such instead of long, wordy process descriptions that no one will want to read.  The people who use the document will thank you.

Here is some good information on some of the elements that make up a good process flow diagram.

A simple flow chart:

ContentLicense: CC BY-SA 3.0


问:
Migrating from Python to Scala wise when a lot of work is already done in Python?
Me and my friend are developing a web-app in Python + Flask + PostgreSQL. We have been working on it for the past few months and have developed a lot of schema/use-cases specific to Python + Flask + PostgreSQL. Now, all of a sudden, we plan to move to another NoSQL database (Neo4j) because it somehow fits better to what the core of our web-app is going to be. Python supports Neo4j through embedded/rest api bindings, but uses a technology JPype, which is rather unmaintained, to say the least.

So, this question of using Scala arose today. Ours is going to be next-to-realtime application, so we can't afford to have the lag/overhead of having intermediate steps of Python->Java requests (Neo4j standalone server is based on embedded Neo4j). So, whereas I am in favour of spending a month or two and learning Scala/Lift, he is in favour of carrying on with Python and porting to Scala whenever need arises, even though when we know that Python+bindings will be a bit slower as compared to the native Neo4j support for Java.

In the past few months, we had done a lot of work in Python + Flask + PostgreSQL already. If we port to Scala, we will need to port all of it to Scala.

Would it be wise to port now? Are there any personal experiences or advices from you all? Or is this just premature optimization?

P.S.: I am aware of the learning curve of Scala/Lift.

答:
Another option, if you don't use many Python 2.6+ features might be to use Jython. Since this targets the same JVM as Scala, it should allow tighter, more efficient integration.

We provide a Jython console inside our Eclipse application so users can write their own scripts which have full access to the power of our Java back end. We can use Jython and Java classes interchangeably and seamlessly move between them. I find it a really flexible environment to work in.

The only real downside is that Jython is stuck at Python 2.5, so subsequent innovations in the language are not yet available.


问:
Is it a good idea to do UI 100% in Javascript and provide data through an API?
My primary day job is making HTML applications. With that I mean internally used CRUD-type applications with lots of editable gridviews, textboxes, dropdowns, etc. We're currently using ASP.NET webforms, which do get the job done, but the performance is mostly dismal, and quite often you have to jump through hoops to get what you need. Hoops which are hung from the ceiling and set aflame.

So I'm wondering if it perhaps would be a good idea to move all UI to the JavaScript side. Develop a strong set of reusable controls which are tailored specifically to our needs, and only exchange data with the server. Yes, I like the "control" (aka "widget") paradigm, its quite well suited to such applications. So on the server side we would still have a basic layout simliar to our current ASPX markup, but that then would get sent to the client only once, and the Javascript part would take care of all the subsequent UI updates.

The problem is I've never done this before, and I've never seen anyone doing this either, so I don't know what the problems would be. In particular, I'm worried about:

Performance still. Benchmarking shows that currently the main delay is on the client side, when the browser tries to re-render most of the page after an AJAX update. ASP.NET webforms generated markup gives a new meaning to the word "web", and the rich Devexpress controls add their own layer of Javascript complexity on top of that. But would it be faster to recalculate all the necessary changes on Javascript side and then update only what needs to be updated? Note that I'm talking about forms that have several editable gridviews, lots of textboxes, many dropdowns each with half-a-zillion filterable items in them, etc.

Ease of development. There would be a lot more Javascript now, and it would probably mix with the HTML markup of the page. That or some kind of new view engine would have to be produced. Intellisense for Javascript is also a lot worse than for C# code, and due to the dynamic nature of Javascript it can't be expected to get a lot better. Coding practices can improve it a bit, but not by much. Also, most of our developers are primarily C# developers so there will be some learning curve and initial mistakes.

Security. A lot of security checks will have to be done twice (server-side and UI-side), and the data-processing server side will have to include a lot more of them. Currently, if you set a textbox to be read-only on server side, you can depend on its value not changing through the client roundtrip. The framework already has enough code to ensure that (through viewstate encryption). With the data-only approach, it gets harder, because you have to manually check everything. On the other hand, maybe security holes will be easier to spot, because you will have only data to worry about.

All in all, will this solve our problems, or make them worse? Has anyone ever attempted this, and what were the results? Are there any frameworks out there that help in this sort of endeavor (jQuery and moral equivalents aside)?

答:
If you can afford to not support scriptless users, and search engines do not concern you, then yes, it is a perfectly viable approach. Here's a short rundown of the pros and cons:

Pros:

everything in one place (javascript)

you can load data from the server, not markup, which can save a lot of bandwidth if done right

easier to get a responsive application (network latency is still there, but the initial response to a user's input comes faster)

the web server doesn't need to render any HTML or expand any templates (i.e., processing effort is moved from the server to the client)

Cons:

everything needs to be in javascript (may or may not be an issue)

critical logic needs to be duplicated on the server

state needs to be maintained on client and server, and synchronized between both

security can be harder to get right (considering how anything in the client-side code can be manipulated by malicious users)

you expose a large part of your codebase (code that runs on the server cannot be seen from outside)

Personally, I think if you go this route, ASP.NET UpdatePanels are not the right way. They're great for partially ajaxifying existing web applications, but they still send HTML over AJAX, and managing state this way can be pretty hairy. You better go all the way, serving just a static HTML document, and then use a javascript template library to do the HTML rendering; the server doesn't serve any dynamic HTML at all, instead, the client makes business-logic level calls into the server and receives raw data.


问:
PHP and performance
I always hear that PHP is for medium and small websites whereas .NET and Java for enterprise applications. My question is about PHP. Why is PHP not a good option for enterprise web applications? Is it because if the web application becomes bigger then PHP will be slower as it is an interpreted language?

I know that corporate world will choose .NET or J2EE because of the integration with their products and because of back end services, etc. However, if we just have PHP for building sites and web applications then how can we use it to perform well with big sites?

In short, Is there a relationship between the performance of PHP and the size of the website?
What are the factors that make PHP not appropriate option for big sites?

答:
I would say that the problems with PHP stem less from performance than a history of security vulnerabilities. While it's undoubtedly possible to write a web site of any particular size or complexity in PHP and still maintain security, as complexity increases, maintaining security tends to become more difficult.

Java, on the other hand, was designed with at least some ideas about security from day one. Although those don't fit entirely with most current deployment (the original thinking was primarily around applets, not servelets) that emphasis does mean its features tend to fit better with producing secure code. And, of course, it hasn't stood still either -- since applets are mostly a dead issue now, Java has been re-defined to emphasize the server-side role it now (mostly) occupies.

Since .NET at least tries to compete nearly directly with Java, it provides much the same sort of features and capabilities in this regard. You can argue (and adherents to both camps do) over whether Sun or Microsoft does a better job in this regard, but the simple fact that both have teams of people really trying to work on it gives them a fairly serious advantage over PHP in this respect.

Title: PHP and performance


问:
How is CoffeeScript influenced by Haskell?
I've been using CoffeeScript for a while now. On Wikipedia, it is said that CoffeeScript is influenced by Haskell. But after I check out the syntax of Haskell, I have found little resemblance from CoffeeScript.

Which aspect of CoffeeScript is influenced by Haskell?

答:
Building on Elf Sternberg's answer, you can actually make quicksort even a little more "Haskell-like" with Coffeescript's destructuring:

```<code>quicksort = ([x, xs...]) ->
  return [] unless x?
  smallerOrEqual = (a for a in xs when a <= x)
  larger = (a for a in xs when a > x)
  (quicksort smallerOrEqual).concat(x).concat(quicksort larger)
</code>```

It's not quite pattern matching, but it's a little closer. ;-)

OwnerDisplayName: lightblade

Body:
Building on Elf Sternberg's answer, you can actually make quicksort even a little more "Haskell-like" with Coffeescript's destructuring:

quicksort = ([x, xs...]) ->
  return [] unless x?
  smallerOrEqual = (a for a in xs when a <= x)
  larger = (a for a in xs when a > x)
  (quicksort smallerOrEqual).concat(x).concat(quicksort larger)

It's not quite pattern matching, but it's a little closer. ;-)


答:
Performance is probably not one of the factors. For a dynamic language, PHP actually performs pretty well; depending on the task, it might or might not beat other technologies. The application model simply is too different to compare it directly against Java or ASP.NET. Even if there is a measurable speed difference, it is not big, and it's probably linear, which means it can be solved by throwing more hardware at it. Also, the programming language itself is seldom the bottleneck - algorithms, database access, network bandwidth, and I/O in general are the usual culprits, unless you are writing somehing truly CPU-intensive.

Reasons for using ASP.NET or Java over PHP that are more likely include:

Platform integration. ASP.NET offers extensive integration with .NET and the underlying Windows OS.

General purposeness. PHP was designed specifically for the web, while .NET and Java are general-purpose platforms. Using Java or .NET, you can tack both desktop and web frontends onto the same shared code with little effort, while PHP isn't very suitable for writing desktop applications.

Code organization features. Java and .NET were designed for OOP from the start, while OOP in PHP is somewhat of an afterthought. PHP introduced namespaces very recently, and they are limited and clumsy compared to what .NET and Java have to offer. Enterprise-style programming usually relies heavily on OOP, which makes PHP the lesser candidate.

Another reason for the perceived effect is that PHP is free (as in beer) and ubiquitous - every cheap shared web hosting company has PHP in their standard package, but a .NET or Java server is going to cost you significantly more. Consequently, a huge mass of small websites uses PHP, not because it's the best tool for the job, but the only one at hand.

That's not to say PHP is unsuitable for large projects - it just doesn't go well with the 'enterprisey' kind of programming. Its strengths lie elsewhere, and if you can leverage them, you can just as easily build large-scale applications as you could with any other web technology.

Title: PHP and performance

Body:
I always hear that PHP is for medium and small websites whereas .NET and Java for enterprise applications. My question is about PHP. Why is PHP not a good option for enterprise web applications? Is it because if the web application becomes bigger then PHP will be slower as it is an interpreted language?

I know that corporate world will choose .NET or J2EE because of the integration with their products and because of back end services, etc. However, if we just have PHP for building sites and web applications then how can we use it to perform well with big sites?

In short, Is there a relationship between the performance of PHP and the size of the website?
What are the factors that make PHP not appropriate option for big sites?


答:
You could allow the customer to define custom attributes.  Basically, the customer would define the name, type, acceptable values, etc. and that information would be stored in the datastore.

For example:

Weight, Integer, Weight must be greater than zero.

In addition to your main application, there would be a custom tab(s) or screen(s) where needed.  They get built dynamically based on the defined attributes, type, etc.  In this case, since it is a number, some sort of numeric interface control would be used.

Then the custom screens are different based on customer needs.

So, your team does the main application and allows the customer to extend it as needed.  Your team will have to make decisions on whether to include the field as part fo the main application or let it be a customer specific attribute.

Title: Alternate approaches to creating custom forms in a web application

Body:
We are putting together some distribution software, selling about 150K SKU's. Some of our items have additional requirements in order to be sold that are dictated by our vendors. For instance one type of product that we sell are prosthetic feet. Some vendors require that we capture the users weight, activity level, and some other information. This is just one example there are many different kinds of products that might have this kind of requirement (a custom set of information collected from the customer to complete the sale).

The direct approach is to just create custom forms for each requirement and create new forms when new requirements are needed. This works. It's straightforward, but its also a PIA. I would like to be able to kick this back to our product team that handles entering in new items rather than having to have them always come back to us.

The project is a web application based on python (Turbogears). Not sure if this was relevant as the question is more general than this but put it here just in case.

How would you approach this situation to minimize or remove your involvement with creating/adding these forms after site moves to production?


问:
Servicing background tasks on a large site
We're dealing with an interesting problem on StackOverflow.

We've got a whole bunch of little "needs to be done soon-ish" tasks.  An example is updating "Related Questions" lists.  What we've done in the past is to piggy-back those tasks onto some users' page loads.

This was never ideal, but it wasn't really noticeable.  Now that SO has passed the 1,000,000 question mark, those unlucky users are starting to feel it.

The natural solution is to actually push these tasks into the background.  There are two broad ways of doing this I'm considering.

1. In IIS as a custom Thread-Pool/Work-Queue

Basically, we spin up a few (non-ThreadPool, so as to not interfere with IIS) threads and have them services some collections we're shoving Funcs into.

The big pro here is simplicity.  We don't have to worry about marshaling anything, nor do we have to make sure some external service is up and responding.

We also get access to all of our common code.

The con is, well, that we shouldn't use background threads.  The objections I know of are all centered around starving IIS (if you use ThreadPool) and the threads dieing randomly (due to AppPool recycling).

We've got existing infrastructure to make the random thread death a non-issue (its possible to detect a task has been abandoned, basically), and limiting the number of threads (and using non-ThreadPool threads) isn't difficult either.

Am I missing any other objections to in IIS process thread-pooling/work-queues?

Moved to StackOverflow, as it wasn't really addressed here.

2. As a Service

Either some third-party solution, or a custom one.

Basically, we'd marshal a task across the process boundary to some service and just forget about it.  Presumably we're linking some code in, or restricted to raw SQL + a connection string.

The pro is that its the "right way" to do this.

The cons are that we're either very restricted in what we can do, or we're going to have to work out some system for keeping this service in sync with our code base.  We'll also need to hook all of our monitoring and error logging up somehow, which we get for free with the "In IIS" option.

Are there any other benefits or problems with the service approach?

In a nutshell, are there unforseen and insurmountable problems that make approach #1 unworkable and if so are there any good third-party services we should look into for approach #2?

答:
Do Both

Add a optional parameter to the question path that does the work you are currently piggybacking on user requests:

Servicing background tasks on a large site

Create a console app that runs on each server and opens the IIS log shared binary and reads it to the current end of the file.  Use a filesystemwatcher or a timed interval to read forward to collect updates as IIS flushed the log.

Use this information to determine what pages have been currently viewed.

Use the page urls from the parsed log to call the "extrastuff" version of the url on localhost with a webclient object.

Add in some code to switch files at the end of each log period or restart the process each log period.

ContentLicense: CC BY-SA 2.5


问:
What is meant by a primitive data type?
My understanding of a primitive datatype is that

It is a datatype provided by a language implicitly (Others are user defined classes)

So different languages have different sets of datatypes which are considered primitive for that particular language. Is that right?

And what is the difference between a "basic datatype" and "built-in datatype". Wikipedia says a primitive datatype is either of the two.

PS - Why is "string" type considered as a primitive type in SNOBOL4 and not in Java ?

答:
I came across some information and felt it would aid the other answers . So want to share it -

Wikipedia says -

In computer science, primitive data type is either of the following:

A basic type is a data type provided by a programming language as a basic building block. Most languages allow more complicated composite types to be recursively constructed starting from basic types.

A built-in type is a data type for which the programming language provides built-in support.

In most programming languages, all basic data types are built-in. In addition, many languages also provide a set of composite data types("string" type in Java).

I would like to say it this way -

A basic datatype is a datatype which cannot be further broken down ("string" type can be made from "char", but char cannot be 'broken down' into any datatype (In most of Programming languages) . So it is basic datatype)

String type , in SNOBOL4 is considered primitive .Though I dont know the exact reason why . It's both basic as well as built-in in SNOBOL4 .

Java specification clearly mentions the list of datatypes it considers to be primitive type . Because the string type is not in their specification , it's not a primitive datatype in Java , inspite of being a built-in type .

Title: What is meant by a primitive data type?


问:
What's the role of a Project Manager in Scrum?
What's the role of a Project Manager in Scrum?

I have heard that it is not advisable for the PM to be a SCRUM Master which I can see as making sense as the PM oversees the project whereas the SCRUM Master is more concerned with managing the work packages.

To my mind it would seem that having a PM as SCRUM Master goes against managin by exception, one of the principles of PRINCE2.

The PM should be more concerned with:

establishing the scope of the project, ensuring the business case for
the project remains valid

planning the number of iterations

maintaining the overall project plan including software release dates

acquiring external resources needed by the Scrum team e.g. users for
User Acceptance Testing

managing risks and issues which are escalated by the Scrum team

communicating with the executive including reporting progress

Could any PM's (or SCRUM Masters) experienced in managing agile projects using SCRUM give their experience/opinion on whether the two roles could/should be combined?

答:
My perspective on this as a developer is that a Project Manager can be a good thing to have in Scrum, if you're in the kind of organization that has Project Managers. The role of this person in Scrum is to help the rest of the business understand Scrum, and act as someone that the Scrum Master and Product Owner can go to if they are running into problems reconciling Scrum with the typical software development process in the organization. As such, she needs to have a deep understanding both of Scrum and of the organization's typical process so that she can act as a buffer between the two.

As the business as a whole more fully embraces Scrum, I think the role becomes less and less important because fewer of these problems come up, to the point where Project Managers should probably concentrate on moving into a Product Owner, Scrum Master, or Agile Coach role.


问:
Is it proper to have Investigation task in sprint
I have been practicing agile for more than a year now. As part of our sprint, some times we will have Investigation Tasks. We skip poker planning for theses tasks, and adds blanket numbers.

Theses are tasks like investigating some tricky defects or technical feasibility of some features etc..

Is this proper or is there any alternative ways to tackle it?

答:
Good idea - some people call it a Spike

If, when you say "skip poker planning for these tasks and adds blanket numbers", you mean that you time-box them, then you are talking about a regular practice in scrum called a Spike:

A spike is an experiment that allows developers to learn just enough
  about something unknown in a user story, e.g. a new technology, to be
  able to estimate that user story. A spike must be time-boxed. This
  defines the maximum time that will be spent learning and fixes the
  estimate for the spike.

ContentLicense: CC BY-SA 4.0


答: There is no such thing as agile police that are going to come to your office and arrest you for not following an implementation of the methodology exactly to the letter. If having investigation tasks is working for you there is no reason to change it because someone wrote a paper or a book that says differently. </p>

Title: Is it proper to have Investigation task in sprint

Body:
I have been practicing agile for more than a year now. As part of our sprint, some times we will have Investigation Tasks. We skip poker planning for theses tasks, and adds blanket numbers.

Theses are tasks like investigating some tricky defects or technical feasibility of some features etc..

Is this proper or is there any alternative ways to tackle it?


问:
Does giving a developer a slower development machine result in faster/more efficient code?
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards

答:
Hardware is less costly than time of development.

Most bottlenecks are in the database not in the client PC, but that doesn't excuse testing on
slower machines than the developer. Use testing tools to test optimization.


答:
We call these stories "Spikes" and allocate up to three days to each. Once the time is up work stops on the spike and the findings are discussed in the team. Based on those discussions the team then decides about the next steps.

Typically we use spikes for tricky tasks as you call them such as new technologies, new designs, challenging bugs, performances issues, trialing new tools, user interface prototypes, and many more. This list is far from complete.

We create a spike when we are unsure about the content or size of a particular item. In other words the item comes with a lot of uncertainty. We use the spike to reduce or eliminate the uncertainty.

So in that sense I think you use them the "proper" way. You just use a different label for this type of task than we do.


问:
How do I dive deep into code that does not have a single entry point?
I work on enterprise Java projects that do not have a single entry point from where I can trace the flow of execution. Some of the projects have hundreds of classes, and when I'm asked to add a feature to a project, I often find myself at a loss as to where to start looking at code.

What's the best way to dive into such projects so that I can implement the feature quickly without wasting time.

答:
There are ALWAYS entry-points, you just have to find them. If it's a schedule-driven batch application, there are tasks configured somewhere. If it's a web-application (using Spring) there are mappings and Controllers. If it's a web services application, there are service endpoints. If it's a Swing application, there are event handlers or somesuch. And if it's a big ol hairy command line application, there is a main() method.

Regarding "diving in quickly" - well, how long it takes to find the entry-points is really individual. If the system is written according to established patterns and you are familiar with the frameworks and the underlying business rules and processes - then you should be able to figure them out very fast indeed. If not, it may take longer. But there is no universal "trick". You accumulate experience, you learn to recognize patterns and understand how the frameworks are built up and organized and you get better.


问:
Our version of Agile isn't working. Tips?
I work on a small team of 4 developers. We are implementing a version of Agile that seems to continuously provide us with the same difficulties, week after week, and I'm looking for suggestions that can help us improve our process.

The background:

We generally do 2 week sprints, and each sprint we tend to underestimate our work, and we get in trouble with our manager because we're behind schedule.

We start off each sprint by tasking out the stories that our manager creates for us. Sometimes he throws in the tasks too and we estimate them. We don't use story points. We use the software Urban Turtle to "manage our sprints", which is essentially just stories and tasks, and the associated burn down. We don't plan for a release at the end of a sprint.

The most common issue that occurs is that we plan for a task in the beginning of a sprint only to discover it's much larger in scope, but still high in the priority, so we need to work additional hours on it. The second most common issue is that one of us runs into a technical problem that slows down the hours burned, causing a roadblock.

The only suggestion provided to us is to be more proactive in adjusting our estimates and providing updates during standups in the morning so we can adjust for the extra time needed.

However, there seems to be something fundamentally wrong with the way we're doing things. Perhaps there's a disconnect between the expectations of the manager on a project level and the expectations on a sprint level. Because we're making these sprint iterations according to a project plan, and therefore extending a sprint or deferring items screws up the project plan. So as developers we are being encouraged to perform Agile by extending estimates when necessary but also complete the sprint on time, which is confusing.

This can't be an uncommon problem, so I'm hoping those wiser than I out there have a suggestion or two on how we can stop running into this same problem every sprint. It's frustrating.

答:
Acceptance criteria poorly defined at start of sprint?

Initial estimates are often too low because story cards have poor acceptance criteria (if any) when they are estimated. What about shifting to Acceptance-Test-Driven Development (ATDD) aka storytesting to help the team get really clear on what the card is?

Stories too big?

Another reason you find out mid-sprint that your stories take longer than expected may be that they are too large. Have you seen the Agile in a Flash flashcard deck? They have a flashcard called "Shrink XL stories to Fit". It gives strategies to spliting stories like deferring edge cases, side effects, nonfunctional aspects, or error handling to later stories.

Can't estimate because you don't have sufficient information?

@sleske makes a good suggestion about spikes. Try and identify technical unknowns at estimation time. If there are any, see if you can defer the story into a later sprint and instead do a time-boxed investigation (spike) this sprint to try and learn what it would take to be able to estimate. Don't get carried away and solve the original story - the spike is done when you know enough to estimate the story.

Fail faster

And I agree with @Patrick Hughes - consider moving to 1-week sprints so you can see problems faster.

OwnerDisplayName: letsgetsilly


问:
How should code "Goal Tending" be handled by a Development Manager?
First allow me to coin a term:

code goal-tending: Checking out code in the morning, then silently reviewing all of the changes made by the other developers the previous day
  file by file, (especially code files you originally developed), and
  fixing formatting, logic, renaming variables, refactoring long
  methods, etc., and then committing the changes to the VCS.

This practice tends to have a few pros and cons that I've identified:

Pro: Code quality/readability/consistency is often maintained

Pro: Some bugs are fixed due to the other developer not being too familiar with the original code.

Con: Is often a waste of time of the goal-tending developer.

Con: Occasionally introduces bugs which causes hair-pulling rage by developers who thought they wrote bug-free code the prior day.

Con: Other developers get aggravated with excessive nitpicking and begin to dislike contributing to the goal-tender's code.

Disclaimer: To be fair, I'm not actually a development manager, I'm the developer who is actually doing the "goal tending".

In my defense, I think I'm doing this for good reason (to keep our extremely large code base a well oiled machine), but I'm very concerned that it's also creating a negative atmosphere.  I am also definitely concerned that my manager will need to address the issue.

So, if you were the manager, how would you address this problem?

UPDATE:  I don't mean for this to be too localized, but some have asked, so perhaps some background will be illuminating.  I was assigned a giant project (200K LoC) three years ago, and only recently (1 yr ago) were additional developers added to the project, some of which are unfamiliar with the architecture, others who are still learning the language (C#). I generally do have to answer for the overall stability of the product, and I'm particularly nervous when changes are surprisingly made to the core architectural parts of the code base.  This habit came about because at first I was optimistic about other developer's contributions, but they made way too many mistakes that caused serious problems that would not be discovered until weeks later, where the finger would be pointed at me for writing unstable code.  Often these "surprises" are committed by an eager manager or a co-worker who is still in the learning phase.  And, this probably will probably lead to the answer: we have no code review policy in place, at all.

答: It sounds like what you're doing is basically equivalent to a code review except that rather than providing feedback to the developer, you're making all the changes that you would suggest in a code review.  You'd almost certainly be better off doing an actual code review where you (or someone else) provides feedback to the original developer about code quality issues and obvious bugs and ask the original developer to fix them.  That keeps code quality up but it also helps the developer become more familiar with the original code and its pitfalls and helps improve future code changes.  Plus, it doesn't have the downside of causing "hair-pulling rage" when a bug gets silently introduced or cause other developers to think that they're being talked about behind their back.</p>


答:
To be frank, IMHO, this is a terrible idea.

I would expect morale to drop into the gutter, if it hasn't already.

To be fair to you, you do acknowledge this.

Peer code reviews are fine, it puts the onus on the devs all at one level, instead of it being a "them versus us" scenario. (where them is management/leads).

There may be some developers that you may need to keep an eye on more than others, but blanket forcing all code to come through you first is ridiculous.

And despite how good you think you are, there will be times when you are wrong, or "nit picking" and this will just make things even worse.

Title: How should code "Goal Tending" be handled by a Development Manager?

Body:
First allow me to coin a term:

code goal-tending: Checking out code in the morning, then silently reviewing all of the changes made by the other developers the previous day
  file by file, (especially code files you originally developed), and
  fixing formatting, logic, renaming variables, refactoring long
  methods, etc., and then committing the changes to the VCS.

This practice tends to have a few pros and cons that I've identified:

Pro: Code quality/readability/consistency is often maintained

Pro: Some bugs are fixed due to the other developer not being too familiar with the original code.

Con: Is often a waste of time of the goal-tending developer.

Con: Occasionally introduces bugs which causes hair-pulling rage by developers who thought they wrote bug-free code the prior day.

Con: Other developers get aggravated with excessive nitpicking and begin to dislike contributing to the goal-tender's code.

Disclaimer: To be fair, I'm not actually a development manager, I'm the developer who is actually doing the "goal tending".

In my defense, I think I'm doing this for good reason (to keep our extremely large code base a well oiled machine), but I'm very concerned that it's also creating a negative atmosphere.  I am also definitely concerned that my manager will need to address the issue.

So, if you were the manager, how would you address this problem?

UPDATE:  I don't mean for this to be too localized, but some have asked, so perhaps some background will be illuminating.  I was assigned a giant project (200K LoC) three years ago, and only recently (1 yr ago) were additional developers added to the project, some of which are unfamiliar with the architecture, others who are still learning the language (C#). I generally do have to answer for the overall stability of the product, and I'm particularly nervous when changes are surprisingly made to the core architectural parts of the code base.  This habit came about because at first I was optimistic about other developer's contributions, but they made way too many mistakes that caused serious problems that would not be discovered until weeks later, where the finger would be pointed at me for writing unstable code.  Often these "surprises" are committed by an eager manager or a co-worker who is still in the learning phase.  And, this probably will probably lead to the answer: we have no code review policy in place, at all.


答:
No idea why people claim PHP is for small and medium websites. To best of my knowledge, this isn't true. I know some PHP backed websites that started small, then grew to be top100 websites in my country. They still use PHP and have no plans to change anything about it.

The thing, that might drive people to such conclusion is that in case of Java (and i guess also with .NET) application scalling is a term frequently brought up in documentation and literature. Most application servers out there support some form of clustering which allows rapid addition of "horsepower" along with the popularity growth. In case of PHP you have to build up cluster yourself. You can do it many ways, using different components and you have to know a bit or two about PHP inner workings. This probably makes people think, that with PHP single server (and thereby small or medium website) is a dead end for PHP.

Title: PHP and performance


答:
You're confusing traffic ("small and medium website" usually means a website with small to medium traffic), with the degree of business logic complication (simple website vs enterprise solution). In the second case performance is not the key factor.

For example Facebook is high traffic website, but it's not an enterprise app. On the other hand there are plethora of intranets based on Java application servers, that wouldn't be able to handle traffic of even midsize website.

Performance-wise PHP is not the best option, but it's not that bad either. Especially comparing with other dynamic languages. However, again, raw performance is not the most important factor. Creating high-traffic websites is more about optimizing for scalability on architectural level.

Why is PHP so despised by enterprise? There are few causes, first would be it's terrible security reputation. Second is that it perceived as a language for amateurs creating ugly, unmanageable HTML-PHP spaghetti code. That perception persist, even though there are mature MVC frameworks. I guess having PHP's original author argue that you don't need a framework doesn't help. Fact that these clueless amateurs with little to none programming skills call themselves "PHP programmers" doesn't help either. Third reason is that any experienced programmer will agree, that PHP is just badly designed as a language. You can clearly see that it was designed by a webmaster, while most modern dynamic languages were designed by post-grad academics specializing in compilers and language design.

And yes, in enterprise it's all about system integration, where PHP doesn't shine either. With enough effort you can create C modules. There is PHP-Java bridge, which is quite tedious to use. Beyond that you don't have much. Attempts to create Boost::PHP (integration with C++) have failed. PHP-clones running on JVM are far from being anything close to 100% compatibility with PHP (as a side note, there is no formal PHP language definition, the only reference is the default implementation).

Title: PHP and performance


答:
If I were the manager, to address this problem:

Review code standards and practices with team, hand them a copy of
the coding standards

Peer review code on a regular basis to reinforce the standards and practices that are to be followed

Enforce nitpicking/formatting with an automation tool so that developers are
forced to follow the standards

Get rid of any bad teammates who refuse to follow standards

Stop being the goaltender

Your intentions are good, but the implementation is terrible and as others have pointed out, will cause poor morale and sniping among team members.

If the project never had any standard to begin with, try to ease in the new standard in stages instead of just flipping a switch.


答:
1) Performance: several answers here are being mislead on that point.

The Phalanger project (which i used successfully in the past) allows you to use C# code within PHP and vice-versa, or to completely switch from one to the other language. You will probably have to make some changes, but as they keep working on it, it gets better and better.

My point is, they found out that there is an average factor of 2.5 speed in favor of C# (or .NET in general, VB would do the same, it's MSIL in the end).

Check out their tests with Wordpress, it attracted a lot of developpers.

Now we haven't seen him yet, but there's always the dude who's going to tell you that FaceBook is written in PHP. Wrong. It was, originally, until they realized their mistake, and wrote HipHop to transform it to C++.

EDIT: Apparently that last block is unclear, so what I meant is FaceBook IS written in PHP, but HipHop makes it RUN as C++, to improve overall speed, BECAUSE PHP is slow.

2) Security: As it has already been stated, PHP has a long history of security issues.

3) Developper time: Making a website in PHP tends to be easier, especially with the frameworks and all the "site-builders" available. Making a good, reliable and secure PHP website is another story.

Title: PHP and performance


问:
Knowledge and skills required for Sharepoint
I was just wondering what skills and technologies I need to know to in order to start a career path in Sharepoint. I know that it primarily depends on the job I am applying for but there must be a number of baseline skills that are common among most Sharepoint jobs.

Btw, I'm currently a CS student who has only learnt Java.

答:
I've been developing for SharePoint 2007 (MOSS) for around 4 years or so with almost all of that time being custom code (not skinning, not creating lists but rather writing custom web parts, workflows, list templates with event receivers, timer jobs, etc.) I haven't had much opportunity to work with 2010 yet but from what I've seen, it's much the same in terms of parts and pieces to customize though the actual code content can be more complex given the presence of sandbox solutions, etc.

In general, this is what I've needed to be successful:

Patience.

Tenacity.

Comfort with reflecting tools like Red Gate Reflector or ILSpy.

Strong OOP [Event and Feature Receivers, Timer Jobs, Workflows, Reflection]

Strong ASP.NET Web Forms Development [Web Parts, Custom ASPX Pages, etc.]

Good Knowledge of XML [Features, Content Types, Field Definitions]

Good JavaScript [jQuery SPServices, Custom Field Types, etc.]

Willingness to Seek Out and Follow Best Practices

SharePoint development is, at the best of times, frustrating. The MSDN documentation is often wrong or misleading regarding the XML structures for creating fields, content types, etc. I use a tool from CodePlex called WSP Builder which helps but is itself plagued with things that aren't right. From experience I've learned where the mines are hidden and I can quickly step around them but I watch new person after new person get blown up. SharePoint is not a very easy system to jump into and be off and running in days. The more comfortable you are with concepts like OOP reading other peoples' code the faster you will be able to pick it up but it is still an uphill battle.

On the other hand, doing SharePoint administration is a bit easier if there isn't a need for complex solutions. Creating lists, setting up alerts, using SharePoint Designer shudder to do some tweaking of the layout and look of pages, activating basic workflows - these are much easier and can be picked up from some classes. Every SharePoint environment needs these people, not all environments want developers like me. While I can write code that is more tailored to an in-house need, it means there is now more code that has to be supported by staff rather than COTS products which come with their own support.

Speaking as a person that does interview technical screenings of candidates, someone with SharePoint knowledge but no development background or experience will not pass. It is much more important to have the knowledge and experience with development concepts than SharePoint specifically. You can pick up the quirks of SharePoint while working with it - you can't pick up mature development practices the same way. In short, I wouldn't want to work with a company that would have a non-developer developing for SharePoint.


问:
Finding an agile coach
I'm hoping that this is the right place to ask this question, but my company has recently started a process to look at how we build software, from the tools we use to the methodology. As you can imagine we have the kind of endless meetings where we sit around a table and split hairs.

In an effort to actually get something done I've suggested we hire in a professional to take a look at how we do what we do and maybe guide us into a more agile approach to delivering software.

My problem is that I'm not sure how to find a consultant we could bring in and get us started?

I was thinking of approaching someone like ThoughtWorks, but I think finding someone who isn't going to push an agenda or product on us would be better.

In the meantime I've picked up a few books and will do a bit of reading on the beach over the holiday vacation.

答:
Where are you now?

Find someone who offers a fixed-price "agile readiness assessment" with the option to purchase additional coaching / consulting in "agile transformation". Ask for case studies or talk to past clients that they helped to achieve more a agile culture and practices.

With an assessment, you may learn that there are institutional barriers that you'll want to remove before you can even hope to succeed with agile.

Join a user group to find a coach or consultant

If you are having difficulty finding coaches/consultants, join an agile user group in your area and start attending. Meetings usually start or end with a networking session. Introduce yourself to lots of attendees and tell them what you are looking for.

Wait on the big tools

Generally it's the big firms that want to sell you agile process management software with their consulting. Such tools work great when needed, but I agree you don't want to start there.

Title: Finding an agile coach


问:
Why is Python used for high-performance/scientific computing (but Ruby isn't)?
There's a quote from a PyCon 2011 talk that goes:

At least in our shop (Argonne National Laboratory) we have three
  accepted languages for scientific computing. In this order they are
  C/C++, Fortran in all its dialects, and Python. You’ll notice the
  absolute and total lack of Ruby, Perl, Java.

It was in the more general context of high-performance computing. Granted the quote is only from one shop, but another question about languages for HPC, also lists Python as one to learn (and not Ruby).

Now, I can understand C/C++ and Fortran being used in that problem-space (and Perl/Java not being used). But I'm surprised that there would be a major difference in Python and Ruby use for HPC, given that they are fairly similar. (Note - I'm a fan of Python, but have nothing against Ruby).

Is there some specific reason why the one language took off? Is it about the libraries available? Some specific language features? The community? Or maybe just historical contigency, and it could have gone the other way?

答:
When the BDFL (Guido van Rossum) first wrote Python the goal was that it be as understandable as plain English (DARPA funding proposal) which would eliminate common coding errors.

One issue that is highly visible is the use of indent to delimit blocks. In languages that have explicit complex statement delimiters (e.g. C braces, Pascal BEGIN/END) whitespace would be collapsed to a single space character before feeding the code to the lexer. This would allow great variation in how code is laid out.

For professional programmers this is not an issue because they have trained themselves to deal with it from 30 or more hours a week of practice.

For other professionals where programming is a tool this issue becomes a major problem. This group includes mathematicians, physicists, chemists, engineers, etc.

Since Python reduces errors for non-professional programmers it allows them to think about the problem they are trying to solve and don't have to deal with the mechanics of the language as much.

This is a single example of why it is popular outside the programming profession. There are other examples that can be used to illustrate the same point such as batteries included, The Zen of Python (import this), the use of Monty Python humor, and so forth.


答:
Bad juju.

I'm not a development manager, but if I were I would not want any of my developers to touch code that isn't part of a defect or feature assigned to them.  Period.  If you see a problem with someone else's code, then by all means bring it to the attention of the developer(s) responsible, but do not just dive in and fix it yourself, especially if you haven't coordinated with the other developer(s) first.

Cleanup tasks should only be executed after a formal code review by the team, and only by the developer(s) to whom those tasks have been assigned.

Initiative is good in general, but sometimes it can bite you in the ass.  If you introduce any bugs into what was working code, you may rapidly be wishing you'd chosen a different career path.


问:
What are the warning signs of impending doom to watch out for on a project?
Having worked on a failed project is one of the few things that most programmers have in common, regardless of language used, industry or experience.

These projects can be great learning experiences, soul-crushing disasters (or both!), and can occur for a multitude of reasons:

upper management change of heart

under-skilled / under-resourced team

emergence of superior competitor during dev cycle

over/under management

Once you've worked on a couple of such projects, is it possible to recognise at an early stage exactly when a project is doomed to fail?

For me, a big sign is having a hard & fast external deadline combined with feature creep. I've seen projects which were well planned out and proceeding right on schedule go horribly off the rails once the late feature requests started to roll in and get added to the final "deliverable". The proposers of these requests earned the nickname of Columbo, due to rarely leaving the room without asking for "just one more thing".

What are the warning signs you look out for that set off the alarm bells of impending doom in your head?

答:
If the project plan calls for a single iteration of design, development, testing and deployment - the classic waterfall - for a project longer than 1 month, I'd run a mile.

You don't need to be fully agile, but having short development cycles allows you to demonstrate progress to everyone (customer, management and developers themselves) and cope with changed requirements when the inevitable happens.


问:
As a Europe-based company, is it possible to write a custom iPad application for a customer?
Our customer wants us to write a custom application for him that he can use on a handful of iPads in his company. This application is probably only useful for this one customer (maybe for two or three more in the future, but only after additional customization).

I read that if the customer subscribes to Apple's Volume Purchasing Program, we are able to provide him with a custom B2B application. This, however, seems to be restricted to US developers (or customers? or both?).

What are the alternatives for Europe-based (or, more generally, non-US) software developers and their local customers?

答: What I'm doing in a similar situation is creating a web based intranet app that mimics tablet functionality. There are a number of JQuery frameworks that will work for this, like Sencha Touch. This would allow you to avoid the Apple "pay wall" and work with Android based tablets and even webkit based browsers on desktop/laptops as well.</p>


问:
Alternate approaches to creating custom forms in a web application
We are putting together some distribution software, selling about 150K SKU's. Some of our items have additional requirements in order to be sold that are dictated by our vendors. For instance one type of product that we sell are prosthetic feet. Some vendors require that we capture the users weight, activity level, and some other information. This is just one example there are many different kinds of products that might have this kind of requirement (a custom set of information collected from the customer to complete the sale).

The direct approach is to just create custom forms for each requirement and create new forms when new requirements are needed. This works. It's straightforward, but its also a PIA. I would like to be able to kick this back to our product team that handles entering in new items rather than having to have them always come back to us.

The project is a web application based on python (Turbogears). Not sure if this was relevant as the question is more general than this but put it here just in case.

How would you approach this situation to minimize or remove your involvement with creating/adding these forms after site moves to production?

答:
Depending on how sophisticated you want to get, you can allow the users to build a list of potential fields for each product type and store that in your database. To create the form, read from the database and just stack all the fields on top of each other dynamically (leave some space and apply a label and try to make it as clean as possible).

Each field could have a setting for: required, datatype (date, currency, int, etc.). Having drop-down lists may not work because of the nature of these data. Someone at your company will need to review the input and probably do some cleanup.

I've done something similar with parameteer requirements for reports. Each report had specific inputs.


问:
What are the pros and cons of implementing this requirement in different layers?
I have a CRUD app for <DomainObject>s.  They are persisted in a database.

There is a new requirement:  keep track of the <DomainObject>s that have been created since the app was opened, so that the user can see what he/she has done.

I see three ways to implement this:

every time the app is opened, create a new sessionid (for lack of a better name) and store it in the database.  Store the sessionid as a foreign key for each <DomainObject>.  Use a custom query to access the data (i.e. select * from DomainObject where sessionid = "currentSessionId")

same as 1., except perform the filtering in the business layer

don't keep track of this data in the database.  Instead, have the model keep track of the new <DomainObject>s

The problem: I don't have enough experience to understand the consequences of each approach.  For example, it seems like 1. puts business logic in the database.  But 3. doesn't persist some of the data.

What are the pros and cons of each approach?

答:
There is a new requirement: keep track of the s that
  have been created since the app was opened, so that the user can see
  what he/she has done.

I Don't fully understand you three ways But the correct way to do this is as follows.
Every table in your system (The you want yo track) should have the following four fields on them:

```<code>CreateDateTime
CreateUser
ModifyDateTime
ModifyUser
</code>```

These fields should be updated by your business layer based on various events (OnInsert, OnUpdate ect..)

If you need more logging create an Audit table with the Structure similar to the following:

```<code>TableName
RowID
FieldName
User
DateTime
OldValue
NewValue
</code>```

Data should be inserted into this table from your business layer (you should have some mechanism for marking the fields that you would like to have changes logged for, so you are not needlessly logging everything)

EDIT : I reread you question and better understand it now. Keep with the model I am showing above. When the user logged in Store the UserID and CurrentTimeStamp in session.

Then you can :

```<code>Select x from Table
where Userid=[SessionUserID] and ModifyDateTime>=[SessionTimestamp]
</code>```

Note: you don't need to check CreateDate because you ModifyDate should be populated on create.

Body:
There is a new requirement: keep track of the s that
  have been created since the app was opened, so that the user can see
  what he/she has done.

I Don't fully understand you three ways But the correct way to do this is as follows.
Every table in your system (The you want yo track) should have the following four fields on them:

CreateDateTime
CreateUser
ModifyDateTime
ModifyUser

These fields should be updated by your business layer based on various events (OnInsert, OnUpdate ect..)

If you need more logging create an Audit table with the Structure similar to the following:

TableName
RowID
FieldName
User
DateTime
OldValue
NewValue

Data should be inserted into this table from your business layer (you should have some mechanism for marking the fields that you would like to have changes logged for, so you are not needlessly logging everything)

EDIT : I reread you question and better understand it now. Keep with the model I am showing above. When the user logged in Store the UserID and CurrentTimeStamp in session.

Then you can :

Select x from Table
where Userid=[SessionUserID] and ModifyDateTime>=[SessionTimestamp]

Note: you don't need to check CreateDate because you ModifyDate should be populated on create.


答:
Maintaining an Audit table of denormalized DomainObject records with various user actions is the best bet.

By flattening the object tree of DomainObject and storing all the data in an Audit table with user information and timestamps, then you have a complete history of all changes to DomainObject's regardless of Create, Update or Delete operations.

By flattening the data in the Audit table you ensure that if children of DomainObject are deleted or modified then you will also have a history of what those children were as of the given timestamp and all of that without violating any foreign key constraints.

Title: What are the pros and cons of implementing this requirement in different layers?

Body:
I have a CRUD app for <DomainObject>s.  They are persisted in a database.

There is a new requirement:  keep track of the <DomainObject>s that have been created since the app was opened, so that the user can see what he/she has done.

I see three ways to implement this:

every time the app is opened, create a new sessionid (for lack of a better name) and store it in the database.  Store the sessionid as a foreign key for each <DomainObject>.  Use a custom query to access the data (i.e. select * from DomainObject where sessionid = "currentSessionId")

same as 1., except perform the filtering in the business layer

don't keep track of this data in the database.  Instead, have the model keep track of the new <DomainObject>s

The problem: I don't have enough experience to understand the consequences of each approach.  For example, it seems like 1. puts business logic in the database.  But 3. doesn't persist some of the data.

What are the pros and cons of each approach?


答: All the projects I work on have audit data like you describe and its all handled through audit tables/composite keys with version numbers that are managed through SPs. It may seem like you are putting business logic in the database, but rules for maintaining history are more data management issues than true business logic and databases exist to manage data.</p>


问:
Can NoSQL databases be used in e-commerce companies for order management?
Is it possible to use a non relational database be in an Order management system for an e-commerce company with a large number of orders everyday, like Amazon? Can the benefits of Non Relational databases (scalability, reliability etc) be exploited in this scenario, or, is it impossible to give up ACID properties and hence mandate that only a relational DB be used for this purpose?  </p>

答:
It sounds like you're asking whether a NoSQL database can feature ACID. For that, we'll look at the CAP theorem, which states that a distributed system can provide at most two of the following three properties:

Consistency

Availability

Partition Tolerance

If you have a system that is geographically distributed, like Amazon's Dynamo, then the communication latency between partitions already means you have #3 above. Therefore, you must choose between consistency and availability.

For an eCommerce company, an unavailable website leads to lost revenue and irritated customers. So many dot-coms instead aim for "eventual consistency". Therefore, they give-up ACID.


答:
It's certainly possible. Whether it is a good idea or not is another matter.

I personally wouldn't use nosql in the use case you described for two major reasons:

Interoperability - chances are your order system will have to interface with multiple back end systems all written around the relational database model. Mapping back from nosql to relational will be extra work and can introduce bugs.

reporting - reporting is a big feature of an ordering platform. You will regularly need to pull reports based on the ordering data to fine-tune the sales process. Reporting is much harder to do well in a nosql database.

Title: Can NoSQL databases be used in e-commerce companies for order management?

Body: Is it possible to use a non relational database be in an Order management system for an e-commerce company with a large number of orders everyday, like Amazon? Can the benefits of Non Relational databases (scalability, reliability etc) be exploited in this scenario, or, is it impossible to give up ACID properties and hence mandate that only a relational DB be used for this purpose?  </p>


答:
Can NoSQL databases be used in e-commerce companies for order management?

YES

You can always normalizes it once it gets to your order processing systems.

You need to optimize your e-commerce site for performance (if noSql is your way to do that, so be it). Then you can push/pull all you order data in to your order into Order processing/accounting systems normalizing it at at that time. All your financials and other reporting will be based off your accounting systems, NOT the eCommerce site.


问:
how to deal with controller mutations
During development process, things are constantly changing (especially in early phases). Requirements change, UI changes, everything changes. Pages that clearly belonged to specific controller, mutated to something completely different in the future.

For example. Lets say that we have website for managing Projects. One page of the website was dedicated to managing existing, and inviting new members of specific project. Naturally, I created members controller nested under projects which had proper responsibility.

Later in the development, it turned out that it was the only page that was "configuring the project" in some way, so additional functionalities were added to it:

editing project description

setting project as a default

...

In other words, this page changed its primary responsibility from managing project members to managing project itself. Ideally, this page should be moved to "edit" action of "projects" controller. That would mean that all request and controller specs need to refactored too. Is it worth the effort? Should it be done?

Personally, I am really starting to dislike the 1-1 relationship between views and controllers. Its common situation that we have 1 page (view) that handles 2 or more different resources. I think we should have views completely decoupled from controllers, but rails is giving us hard time to achieve this.

I know that AJAX can be used to solve this issue, but I consider it an improvisation. Is there some other kind of architecture (other than MVC) that decouples views from controllers?

答:
Applying composition over inheritance to controllers is one of those approaches with which you just can't go wrong.

The idea is to have as thin of a controller as possible. The controller should just define the request/response processes, but anything substantial happening in between is going to be defined outside of the class.

For instance, if you had a controller that filtered a collection of Product instances by a certain criteria, apply the VAT to the base price and then produce a tabular representation, CSV or JSON response, you'd end up with the following classes:

A class that takes the request object and returns an appropriate collection of Product instances; this class is concerned with knowing how to construct an appropriate query based on the incoming request (like querying products based on a mix of attribute values).

A class that takes a Product collection, processes each entry and returns the resulting collection; this class is concerned with taking a product's specified VAT and applying it on the base price.

A class that takes the incoming request object and a Product collection and produces an appropriate response; this class is concerned with figuring out whether to produce an HTML, CSV or JSON response of the collection.

Your actual controller that simply creates a network of communication between the three classes; this class finally specifies the notion of collecting, processing and displaying the Product model appropriately.

The thing is that controllers often end up exhibiting a lot of complex behavior, but this way that behavior is factored into several different components that are defined and tested independently. By simply mixing in different classes and changing a few lines of code, your controller's behavior changes dramatically. I don't really have any experience with Ruby, but from what I know this can be achieved by including and mixing different modules and perhaps even a macro or two for seasoning.

One good example of this approach are Django's generic controllers. They're just types composed of different mixins where each mixin defines certain behavior and exposes class attributes and instance methods that can be specified/overriden to configure their behavior. The generic controllers provided are just a particular combination of existing mixins that are suited for a particular problem.

Another good example is Android with it's controllers. An Acitivty is called by the instrumentation framework whenever the activity needs to respond to a certain kind of request (create yourself, start yourself, destroy yourself) with certain input, but it's all happening on a UI thread that expects these methods to be snappy. Anything substantial, such as number crunching, retrieving data over HTTP, collecting data from the DB, so forth, is actually managed by objects of some external types that communicate some data back to the calling controller. Sometimes, this communication is generic enough that it can structured by implementing interfaces and the behavior pertaining to each is specified in an anonymous class. Again, you end up with a simple controller that only wires a network of communication between different objects to define some complex behavior, but the behavior is defined in a compact form from which you can readily figure out what's going on.

This is the code reuse promised by the composition principle: if your controller's behavior needs to be migrated to a different controller or if a certain kind of behavior needs to be shared between multiple controllers, composition over inheritance provides you with the ability to do so. And what's best, by applying Liskov substitution principle, the possibilities become endless!

OwnerDisplayName: Milovan Zogovic

Title: how to deal with controller mutations


答:
I don't think anyone's ordering has outgrown most RDBMS ability to scale. The data are structured, so there is no benefit to NoSQL there. Unlike a Facebook or Twitter post, millions of people don't need to see every step of your transaction in real time.

I think a NoSQL database may be an advantage in a bidding/auction situation, but trasnfer to SQL when you process the bill. I'd like to think my bank is a little more rigid in processing my checking account than my chats with support.


问:
Is MongoDB the right choice in my case?
I'm going to build my first real project in Rails that consist in a web app made of 3 main parts:

The static part where no database is used

The User registration part which will require a database and I can use MySQL since each user's row will have the same fields

The "App" where users will be able to create, organize, edit... items in collections and share them with other users

There will be several item types and each one will have different options for example I may have "video" items with the following options:

id

user_id

collection_id

title

platform (if embedded)

url (if embedded)

file name (if hosted on my app)

file size (id hosted on my app)

and "map" items:

id

user_id

collection_id

title

platform (google maps, bing maps...)

location

url

map size

As you can while for users I may use MySQL for items the flexibility of MongoDB may be useful since each item may need different options then another item

Up to now I've always used PHP and MySQL (always on shared hosting for small projects) and scalability is a totally new word for me.

I have time to learn but I would like to be able to do something concrete in something like 1 month.

I've read a lot about MongoDB and NoSQL vs RDMS and MySQL and after trying it I have to say that I like how MongoDB works: no tables, no rows and its documents JSON like so:

In my situation what would you raccomend? why?

About scalability there may be problems with MongoDB? if yes when (in term of DB size) and may these problems slow down my app considerably?

Edit: how the app will work

Since many asked this is how I'd like the app to work:

A user sign up

He's logged in

He create his first collection iside which he can create infinite items

Items are of various type and each type need different data to be saved in the database and type of items may be added or modified

Users may create other collections and items inside it.

So we have CRUD for collections and items inside of them and each collection/item is referred to a specific user

The main problem with MySQL is that it hasn't a flexible schema, there is way to solve this (a workaround?)?

Thinking about NoSQL the only doubt I have is about join, for example given a certain colection I want to retrieve datas related to the User with id = user_id field in the collection

EDIT: Idea to keep using MySQL

Create a field in the "items" table with optional settings, each setting divided by a | or another symbol.

Then I will save somewhere a structure of each item optional settings, for example the "notes" item type need two optional settings "colour" and "strange_setting", when I get the data from MySQL i will split the field for optional settings into an array knowing that the first item in the array is for "colour" and so on.

What do you think? there are problem with that solution? do you have other ideas?

答:
I do see a lot of valid arguments here for NoSQL vs MySQL. One missing link though is about scale: If you want to really scale and want to do it with an in house database, you will be needing a LOT of knowledge about databases. There are too many horror stories out there where people have failed in trying to implement a system that will scale infinitely.

If you really choose to go the NoSQL route (and are ready to take the costs that come with it - like no joins), Do consider AWS DynamoDB (http://aws.amazon.com/dynamodb/). Here you can forget about the whole database scaling part of it, and concentrate on your application. Good luck.

Disclaimer: I am a developer in AWS DynamoDB team, but I truly believe in our product. Do try it out:)

Title: Is MongoDB the right choice in my case?


问:
What is the optimal minimum time to work on tasks for a single project?
As I'm getting more organized, and getting more projects, I'm starting to wonder how to best manage time between them.  Especially in regard to how I give estimates to the PHBs.

So if the project is broken up into small tasks, say 2-3 hours each, then is it just as productive to work on one task per day as opposed to spending 6 hours a day and working through a good portion of 3 tasks.

I realize that to a certain extent this depends on the project, but I also think that it might be better in general to work on components together so that things stay fresh in your mind.

That said, it means pushing back other projects a week or two in order to devote 6 hours a day towards those tasks.

Just trying to think this through, and thought I'd get some input.

答:
There are big picture people (ones who see the interconnections and what the end result will be) and little picture people (ones who need to understand each and every phase until the "big picture" comes together).
It is best to take advantage of both of these personalities.The lp will be more focused and detail oriented for the small parts of the program and the BP will have a better idea of how things will need to be tied together so as to not leave out any crucial steps. Like any good organizations, tiers are the best. I would have 2 persons focused on the big picture and end result, 3 coaches managing 3 little picture people who are focused on every detail in their scope. The coaches help the 3 specialists to collaborate there sections to fit the bigger scope and transfer the information for the overall picture to them. The coaches also work with one of the big picture people to bring the 3 groups together. The one remaining BP will be the one who goes down the punch list, ensures everything went as planned, no missed information and provides the finishing touch.</p>


答:
Regarding dealing with legacy code:

The book from Michael Feathers gives some good practices on how to approach legacy software.

Regarding flow of execution:

It's a Spring project, so expect the control flow to do magic tricks. It might do lots of calling methods by reflection, or even AOP. Trying to understand the "flow of execution" using a debugger may cause frustration.

It's a Spring project, so the structure of the project is rather homogeneous. Learn Spring (if you haven't already) so you understand the concepts of beans and wiring. This tells you what classes work together.

Regarding entry point:

Let me guess: it's a web application. Let me guess again: it's using Spring MVC. Learn this one, too, so you know how to find the controller classes for the pages. These are the entry points into your application. There are called by reflection, so you won't find them using static analysis of the source code.

Title: How do I dive deep into code that does not have a single entry point?

Body:
I work on enterprise Java projects that do not have a single entry point from where I can trace the flow of execution. Some of the projects have hundreds of classes, and when I'm asked to add a feature to a project, I often find myself at a loss as to where to start looking at code.

What's the best way to dive into such projects so that I can implement the feature quickly without wasting time.


答:
There's a significant discussion going on about the effects on your brain when you do a context shift between disparate tasks in Pragmatic Thinking and Learning, something that inevitably takes place when you work on one project and then jump to working on another project.

You should read up the Human multitasking wiki, but from a perspective that your not doing multiple tasks at the same time, rather that your taxing your brain to load up several large contexts in a single work session.

Here's some excerpts taken from the Wiki:

Some believe that multitasking can result in time wasted due to human context switching and apparently causing more errors due to insufficient attention.

When people attempt to complete many tasks at one time, “or [alternate] rapidly between them, errors go way up and it takes far longer—often double the time or more—to get the jobs done than if they were done sequentially,”... This is largely because “the brain is compelled to restart and refocus”.

People have a limited ability to retain information, which worsens when the amount of information increases.

Without much background info, PT&L defined this analogy of your brain's context as fast and accessible storage for your consciousness where you could say that your current context is something like a page file. Dumping a large page file and loading a new, significantly large page file is described as a physical feat that can be performed for a limited number of times per day and that performances degrade every other time. Basically, you end up with  a fragmented context, neither are you on the current project, nor the previous one.

Title: What is the optimal minimum time to work on tasks for a single project?

Body:
As I'm getting more organized, and getting more projects, I'm starting to wonder how to best manage time between them.  Especially in regard to how I give estimates to the PHBs.

So if the project is broken up into small tasks, say 2-3 hours each, then is it just as productive to work on one task per day as opposed to spending 6 hours a day and working through a good portion of 3 tasks.

I realize that to a certain extent this depends on the project, but I also think that it might be better in general to work on components together so that things stay fresh in your mind.

That said, it means pushing back other projects a week or two in order to devote 6 hours a day towards those tasks.

Just trying to think this through, and thought I'd get some input.


问:
SOLID vs. static methods
Here's a problem I frequently run into: Let there be a web shop project that has a Product class. I want to add a feature which allows users to post reviews to a product. So I have a Review class which references a product. Now I need a method that lists all reviews to a product. There's two possibilities:

(A)

```<code>public class Product {
  ...
  public Collection<Review> getReviews() {...}
}
</code>```

(B)

```<code>public class Review {
  ...
  static public Collection<Review> forProduct( Product product ) {...}
}
</code>```

From looking at the code, I'd choose (A): It's not static and it doesn't need a parameter. However, I sense that (A) violates the Single Responsibility Principle (SRP) and the Open-Closed Principle (OCP) whereas (B) doesn't:

(SRP) When I want to change the way reviews are collected for a product, I have to change the Product class. But there should be only one reason why to change the Product class. And that's certainly not the reviews. If I pack every feature that has something to do with products in Product, it'll soon be clattered.

(OCP) I have to change the Product class to extend it with this feature. I think this violates the 'Closed for change' part of the principle. Before I got the customer's request for implementing the reviews, I considered Product as finished, and "closed" it.

What is more important: following the SOLID principles, or having a simpler interface?

Or am I doing something wrong here altogether?

Result

Wow, thanks for all of your great answers! It's hard to pick one as official answer.

Let me summarize the main arguments from the answers:

pro (A): OCP is not a law and readability of the code matters as well.

pro (A): the entity relationship should be navigable. Both classes may know about this relationship.

pro (A)+(B): do both and delegate in (A) to (B) so Product is less likely to be changed again.

pro (C): put finder methods into third class (service) where it's not static.

contra (B): impedes mocking in tests.

A few additional things my colleges at work contributed:

pro (B): our ORM framework can automatically generate the code for (B).

pro (A): for technical reasons of our ORM framework, it will be necessary to change the "closed" entity in some cases, independently from where the finder goes to. So I won't always be able to stick to SOLID, anyway.

contra (C): to much fuss ;-)

Conclusion

I'm using both (A)+(B) with delegation for my current project. In a service-oriented environment, however, I'll go with (C).

答:
I have a slightly different take on this than most of the other answers.  I think that Product and Review are basically data transfer objects (DTOs).  In my code I try to make my DTOs/Entities avoid having behaviors.  They are just a nice API to store the current state of my model.

When you talk about OO and SOLID you're generally talking about an "object" that doesn't represent state (necessarily), but instead represents some kind of service that answers questions for you, or to which you can delegate some of your work.  For instance:

```<code>interface IProductRepository
{
    void SaveNewProduct(IProduct product);
    IProduct GetProductById(ProductId productId);
    bool TryGetProductByName(string name, out IProduct product);
}

interface IProduct
{
    ProductId Id { get; }
    string Name { get; }
}

class ExistingProduct : IProduct
{
    public ProductId Id { get; private set; }
    public string Name { get; private set; }
}
</code>```

Then your actual ProductRepository would return an ExistingProduct for the GetProductByProductId method, etc.

Now you're following the single responsibility principle (whatever inherits from IProduct is just holding on to state, and whatever inherits from IProductRepository is reponsible for knowing how to persist and rehydrate your data model).

If you change your database schema, you can change your repository implementation without changing your DTOs, etc.

So, in short, I guess I would choose neither of your options.  :)

Title: SOLID vs. static methods

Body:
I have a slightly different take on this than most of the other answers.  I think that Product and Review are basically data transfer objects (DTOs).  In my code I try to make my DTOs/Entities avoid having behaviors.  They are just a nice API to store the current state of my model.

When you talk about OO and SOLID you're generally talking about an "object" that doesn't represent state (necessarily), but instead represents some kind of service that answers questions for you, or to which you can delegate some of your work.  For instance:

interface IProductRepository
{
    void SaveNewProduct(IProduct product);
    IProduct GetProductById(ProductId productId);
    bool TryGetProductByName(string name, out IProduct product);
}

interface IProduct
{
    ProductId Id { get; }
    string Name { get; }
}

class ExistingProduct : IProduct
{
    public ProductId Id { get; private set; }
    public string Name { get; private set; }
}

Then your actual ProductRepository would return an ExistingProduct for the GetProductByProductId method, etc.

Now you're following the single responsibility principle (whatever inherits from IProduct is just holding on to state, and whatever inherits from IProductRepository is reponsible for knowing how to persist and rehydrate your data model).

If you change your database schema, you can change your repository implementation without changing your DTOs, etc.

So, in short, I guess I would choose neither of your options.  :)


问:
How to cure the "can not deliver"/ "cannot deliver on time syndrome"
I am an above average programmer (I take interest in the development of languages, frameworks and technology in general and have a good grasp of systems), but I constantly find my self not being able to deliver things (on time). This does not affect my day to day work as it has good control process (bite sized tasks with shame driven development) But it definitely hurts me in my personal projects.

Some of the reasons that I think are at play.
-I make things more complicated than they need to be. Often a lot more than I admit to my self.
-I am not very good at making the tasks smaller at times.
-I wander off into obscure corners when I encounter them instead of keeping a laser focus.

The result is often that I don't deliver. Now I may know at the back of my head that what I need to do, but I would appreciate your strategy on how to be the guy who "delivers".

答:
Few points come to mind:

Set a specific achievable goal.

Make simplicity an objective to strive for.

Put a realistic project plan and try to stick to it.

Isolate research from delivery.

Analyze your performance (as you are doing here).

Put time upfront into design.


问:
Is it a good idea to do UI 100% in Javascript and provide data through an API?
My primary day job is making HTML applications. With that I mean internally used CRUD-type applications with lots of editable gridviews, textboxes, dropdowns, etc. We're currently using ASP.NET webforms, which do get the job done, but the performance is mostly dismal, and quite often you have to jump through hoops to get what you need. Hoops which are hung from the ceiling and set aflame.

So I'm wondering if it perhaps would be a good idea to move all UI to the JavaScript side. Develop a strong set of reusable controls which are tailored specifically to our needs, and only exchange data with the server. Yes, I like the "control" (aka "widget") paradigm, its quite well suited to such applications. So on the server side we would still have a basic layout simliar to our current ASPX markup, but that then would get sent to the client only once, and the Javascript part would take care of all the subsequent UI updates.

The problem is I've never done this before, and I've never seen anyone doing this either, so I don't know what the problems would be. In particular, I'm worried about:

Performance still. Benchmarking shows that currently the main delay is on the client side, when the browser tries to re-render most of the page after an AJAX update. ASP.NET webforms generated markup gives a new meaning to the word "web", and the rich Devexpress controls add their own layer of Javascript complexity on top of that. But would it be faster to recalculate all the necessary changes on Javascript side and then update only what needs to be updated? Note that I'm talking about forms that have several editable gridviews, lots of textboxes, many dropdowns each with half-a-zillion filterable items in them, etc.

Ease of development. There would be a lot more Javascript now, and it would probably mix with the HTML markup of the page. That or some kind of new view engine would have to be produced. Intellisense for Javascript is also a lot worse than for C# code, and due to the dynamic nature of Javascript it can't be expected to get a lot better. Coding practices can improve it a bit, but not by much. Also, most of our developers are primarily C# developers so there will be some learning curve and initial mistakes.

Security. A lot of security checks will have to be done twice (server-side and UI-side), and the data-processing server side will have to include a lot more of them. Currently, if you set a textbox to be read-only on server side, you can depend on its value not changing through the client roundtrip. The framework already has enough code to ensure that (through viewstate encryption). With the data-only approach, it gets harder, because you have to manually check everything. On the other hand, maybe security holes will be easier to spot, because you will have only data to worry about.

All in all, will this solve our problems, or make them worse? Has anyone ever attempted this, and what were the results? Are there any frameworks out there that help in this sort of endeavor (jQuery and moral equivalents aside)?

答:
My site is still in its infancy but 100% js ui has been fine for me so far.  The only server logic that exists on the front end is model mappings and ajax urls.  The server has no knowledge about the ui at all, which to me is very easy to maintain.  If you are interested you can checkout my site which is written in ExtJS http://coffeedig.com/coffee/ .  My site doesn't really have any security issues but the client helps the normal user by simple validation.  I know that a malicious user could really send any ajax to the server so all of "security" logic is done on the server. </p>

<p>I think the biggest problem for you is that you are going be doing a complete reversal of what your team is used to, there will be a steep learning curve.  I think the best approach would be to experiment with some js frameworks and try to get the feel of it by writing some simple screens.  </p>

Body:
My site is still in its infancy but 100% js ui has been fine for me so far.  The only server logic that exists on the front end is model mappings and ajax urls.  The server has no knowledge about the ui at all, which to me is very easy to maintain.  If you are interested you can checkout my site which is written in ExtJS http://coffeedig.com/coffee/ .  My site doesn't really have any security issues but the client helps the normal user by simple validation.  I know that a malicious user could really send any ajax to the server so all of "security" logic is done on the server.

I think the biggest problem for you is that you are going be doing a complete reversal of what your team is used to, there will be a steep learning curve.  I think the best approach would be to experiment with some js frameworks and try to get the feel of it by writing some simple screens.


答:
What works for me is writing about 5 to 10 bite-sized tasks on my whiteboard at the beginning of the day. Nothing too ambitious.  My primary goal is crossing those tasks off before the end of the day.  If nothing else, just get those tasks done.

Of course I'll get off on tangents and work on many other things, but if the day is drawing to a close, I'll drop those tangents and jump back on that list.  My motivation is that I want the satisfaction of seeing that whole list crossed off and starting a whole new list the next day.

It's amazing how much more productive I am when I do this.

Title: How to cure the "can not deliver"/ "cannot deliver on time syndrome"

Body:
I am an above average programmer (I take interest in the development of languages, frameworks and technology in general and have a good grasp of systems), but I constantly find my self not being able to deliver things (on time). This does not affect my day to day work as it has good control process (bite sized tasks with shame driven development) But it definitely hurts me in my personal projects.

Some of the reasons that I think are at play.
-I make things more complicated than they need to be. Often a lot more than I admit to my self.
-I am not very good at making the tasks smaller at times.
-I wander off into obscure corners when I encounter them instead of keeping a laser focus.

The result is often that I don't deliver. Now I may know at the back of my head that what I need to do, but I would appreciate your strategy on how to be the guy who "delivers".


答:
For personal projects this level of procrastination is fine. They are more to have fun and learn than produce end products. If you were talking about client projects this would be a very different matter.

If your worried about your productivity on personal projects I would set yourself achievable goals with rewards. You also have to accept thAt shipping is a feature.its better to have an imperfect product now than a perfect product in the fa future


答:
A couple of observations:

Apply the processes that are working to your personal projects.

Are you self-motivated, or externally-motivated?  Become self-motivated.  Self-motivation is required to advance to leadership positions.

According to Seth Godin, the way you ship on time and on budget is this: when you run out of time or you run out of money, you ship.  That's it.

He also says that people tend to gold-plate things; they develop the itch to fix just one more bug, or add just one more feature.  They do this, not because they really need that new feature or fix to ship, but because they are afraid of scrutiny; so long as the product doesn't ship, they can avoid criticism.

People gain a reputation as being valuable because they know how to get things done, not just because they have good ideas.  They have the ability to finish.  It's not about a strategy.  It's about a mindset.  Use that mindset to surround yourself with the tools you need (both mental and physical) to make yourself as productive as possible.

All that said, there is one technique that I do advocate, and that is short bursts of high-level productivity.  Give yourself 20 or 30 minute periods where you decide you are going to be as productive as possible during that brief burst.  Set a timer.   When that timer ends, take a 5 minute break.  Stretch, walk around.  Empty your mind.  Do not think about work during that time.

Lather, rinse, repeat.


答:
There is a big difference between being late of a fixed, well defined task and being late because the task changes. At work it is the client that asks for changes, and everyone understands that the schedule will change accordingly.

At home you are both the client and the programmer. When you are working on something and the idea pops into your head "Gee, if I change A or re-write B the project will be better" that is a change, not being late. In business a client would weight the alternatives and make a decision, at home you are doing the same.

Consider building a website at work and half way through the client calls up and asks "I know you are building part of it in Flash, but could we use HTML5 instead?" You would think and respond something like "Well yes but it will make the project take an extra 3 weeks and add x dollars to the cost."

At home the difference is that we generally have a duh! moment where we realize "Gee, this would be better if I were using HTML5". The part we skip is the stopping to think about the implications of the change in terms of schedule; in other words we generally don't pause to think about the change. Instead we generally just go ahead and do it because we "know" or "think" it to be the best way. We don't fire up Excel and do a financial calculation like a bean counter would do at work when deciding if a change should be made.

Personally I like this at home, not all development should be driven by bean counters ;-)

Don't beat yourself up, mearly understand what is going on.