答:
This is not a problem of selected version control but the problem of product architecture. There is very similar question where you find that you are not the only one challenged with this problem.

General advice is avoid any copy-paste between implementations. This can be obviously done only if you have single branch for core of your product and customer specific features are implemented in separated branches (but without the core) or via configuration of your product. Once more than two customers want the same feature it is time to move the feature to the main branch and make it reusable and configurable (so it can be turned off for customers who don't want it).

As you can notice I mentioned "more than two". This is my own assumption about reusability to weight costs needed to transform feature to reusable and globally available. I consider two customers requiring the same feature still not feasible for this effort. Also two customers are usually not enough to define reusability but collecting requirements from three or more customers usually result in good set of requirements to define reusable and configurable feature.

There are other problems with multi-customer application. For example if you sell the application and customization instead of application or service you can have problems with this because implementing the new feature directly for customer (in time payed by customer) can lead to situation where the feature itself is property of your customer and you cannot use it for other customers (even if they want it) until the owner of the feature allow it - sell you a license (but this problem can already exists in your current situation as well if you don't have correct agreement with your customers).

Title: Workflow of sharing code for small teams

Body:
Problem is, we have developed a small CMS, that is different per implementation (currently).

Of course development of this is never complete. Sometimes, we are working on more than one project that implements it (by copying-pasting the code files of the CMS to each project), and we add a new feature that we want to share on other projects as well (these can be small ones too, ie a custom ajax JSON controller - we use MVC)

What we want to do is quickly and uniformly share the code with all other projects, via a version control system (or something similar), and generally organize the workflow as we know this isn't a very good workflow that we have. What would you suggest?

Also, at the momment, the software we use is Visual Studio 2010, so we are strongly considering TFS, but even if we get it we still don't know the ideal workflow, or even if TFS supports what we want to do.

Edit: Also note, we have specific implementations that have modifications over the CMS base that we want to KEEP only in the project area. (ie: a specific feature that we DONT want to share with the base CMS code)


问:
Building a complete program?
Reading books, watching videos, and reviewing tutorials is all very easy. Taking notes and actually learning the material may be slightly harder, but even then, anyone with a decent brain and a fair amount of interest, it's easy enough (not to mention, fun).

The thing is, it doesn't really prepare you to write a full program or website. Let's say you're those teens (only in highschool, no true (college level) computer science or programming courses, and no real world experience), and you come out with Groupon. Or even Mark Zuckerburg, sure he was a genius, and he was a very capable programmer... but how?

How do you recommend that people who are not necessarily new to programming, but new to programming real applications and real programmers go about developing it? What is the "development process" - especially for single programmers (or maybe 2-3 teens)?

Also, as far as web development goes, what is the process? Was something like Facebook or Groupon written with a framework (like CodeIgniter or Zend for PHP)? Or do they develop their own frameworks? I'm not asking how to come up with a great idea, but how to implement great ideas in an effective way? Does anyone have advice?

I've read a couple of books on both C and C++ (primarily the C Programming Language and the C++ Programming Language) and taken AP Computer Science (as well as read a few additional books on Java and OOP). I also have read a few tutorials on PHP (and CodeIgniter) and Python. But I'm still in highschool, and I'm technically not even old enough to work at an internship for a few more months.

答:
Sounds like your focusing too much on the implementation aspects of software, which is only a fraction of the entire software development process(see SDLC). You might need to look at some software methodologies and learn how to use one that you like. Other than that, read case studies, find out the pluses and minuses of each tool that you would consider using in your software as well, evaluate, and go from there. After a quick read through of your question, you might need to focus on the Analysis and Design areas of software, and learn about UML, decomposition and maybe some design patterns.. maybe..

Hope this helps..

ContentLicense: CC BY-SA 3.0

Title: Building a complete program?


问:
Modern programming language with intuitive concurrent programming abstractions
I am interested in learning concurrent programming, focusing on the application/user level (not system programming). I am looking for a modern high level programming language that provides intuitive abstractions for writing concurrent applications. I want to focus on languages that increase productivity and hide the complexity of concurrent programming.

To give some examples, I don't consider a good option writing multithreaded code in C, C++, or Java because IMHO my productivity is reduced and their programming model is not intuitive. On the other hand, languages that increase productivity and offer more intuitive abstractions such as Python and the multiprocessing module, Erlang, Clojure, Scala, etc. would be good options.

What would you recommend based on your experience and why?

EDIT: Thanks everybody for your interesting answers. It's hard to make a conclusion without actually trying since there are many good candidates: Erlang, Clojure, Scala, Groovy, and perhaps Haskell. I voted the answer with the most convincing arguments, but I'll try all the good candidates before deciding which one to pick :)

答: A plug for Ada is needed here, as it has all the top level abstractions for parallelism & concurrency. otherwise known as tasking. Also as OP asked for intuitive (a subjective criteria!) i think a different approach to the java-centric world might be appreciated.</p>


问:
Create my own database system
I need to learn how databases work in order to use them more efficiently, and my way of learning is by doing.

I want to create my own database system. I am not referring to creating a pseudo-database that would use query to parse files; this would simply be a filesystem interface with a query language. I am talking about the actual structure of a database engine. And since what I have in mind is neither relational nor document-oriented (it's "node-oriented", if that even exists), I would need any resource to be as abstract and high-level as possible.

So how would I go about creating that? What resources/tutorials/books can I read to understand?

The language does not matter in the slightest. Ideally, the code would be pseudo-code to illustrate the concept, not tied to a particular language, but anything would do. I was not able to find anything on the matter on google (since I am so illiterate on the subject, maybe I am just not entering the right search).

If such resources are not available, then I guess something about how to create a client would at least be a step in the right direction.

答:
"(it's "node-oriented", if that even exists)". - This may be why you are not finding much!

Dive in with version 0.1 and see where you get. You may learn more from trying to produce what you want that from asking what you "should" do. Give it a few days and then review where you've got.

About 18 years ago I wrote a basic database system (for fun, go figure) with btree indexes and learned an awful lot.

Title: Create my own database system


问:
How to develop complex applications
I want to know the approach in developing big complex application regardless of which programming language to use. I want to know how developers make such big applications such as internet banking, API's and big database management application. How should one approach to make  such applications. I have only 1 year programming experience so far and I work as a freelancer so when I saw such applications lots of questions came in my mind. How to understand the basic need of information technology. What actually it is? How it can be useful for common people of small towns. I want everyone to make use of technology no matter they are educated or not, rich or not. Please post some suggestions.</p>

答:
I would have a look to an existing similar project and see if it works well. You do't need the full code but java executable jar file could also be reversed. Be aware you are not allowed to reverse jar file in US, but you can do it in Europe and other countries so..

If the architecture is ok, then copy the static architecture (e.g. package, classes etc....) and then just code the business rules. A good start is to reverse engineer the existing project into an UML model and then generate again the code in java. There is no more code copyright if you do that.

Once you have a static architecture you check if the requirements are possible and add new classes at class diagram level. You show your class diagram to the project manager and talk about the architecture. Once this is validated then you start codding.
After the first stage codding you show the class diagrams and a small demo and ask the project manager if it is ok. You take into consideration his demands. You always use a graphical representation of your code in order to get all the team involved in decisions and possible changes.

One more iteratiion, class diagrams updated with a code merge and manager demo. Change again and again. After few week it will almost be perfect and everybody will be happy :-)

Title: How to develop complex applications


问:
Best practice for processing a list of items
I have a list of objects that need to be processed in some way. That way may not be correct for an item and thus raise an exception. In pseudo-code, it would look like:

```<code>proccessItems (list)
  error = new empty list
  for item in list:
    try:
      process_item(item)
    catch Whatever, err:
      error.append(err)
  return error
</code>```

Is there a pattern for doing this sort of things? Are there any anti-patterns to avoid?

A better code (exception not used for control flow), but still following the same logic would be:

```<code>proccessItems (list)
  error = new empty list
  for item in list:
    ret = process_item(item)
    if null != ret
      error.append(ret)
  return error
</code>```

答:
First of all, you shouldn't use exceptions for normal logic flow.

You should ask yourself why you are trying to iterate over items which you can't process in the first place. Probably designing the code in such a way you only have items in your list which you can process is a better idea.

In case you do feel like all those items belong in that one list. Instead of throwing an exception you should still opt to use a conditional check (or polymorphism) to see whether the item is suitable for processing.

I can't specify 'official' anti-patterns but I would consider the following:

Using exceptions for logic flow.

Using type checking or other conditional checks instead of proper design/polymorphism.


答:
I would pass the error list to the process_item function as well, then you'd have a simple iterator and you wouldn't need to throw exceptions to be caught by the proccessItems function.

That way maybe you could replace the exceptions for simple error messages ( like a string ) and avoid using them for control flow since that is not why they were designed in the first place. ( using them like this is a bad practice )

Keep in mind that exceptions ( depending on the language ) are expensive operations so given a large enough list the current example could be a problem.

Title: Best practice for processing a list of items

Body:
I have a list of objects that need to be processed in some way. That way may not be correct for an item and thus raise an exception. In pseudo-code, it would look like:

```<code>proccessItems (list)
  error = new empty list
  for item in list:
    try:
      process_item(item)
    catch Whatever, err:
      error.append(err)
  return error
</code>```

Is there a pattern for doing this sort of things? Are there any anti-patterns to avoid?

A better code (exception not used for control flow), but still following the same logic would be:

```<code>proccessItems (list)
  error = new empty list
  for item in list:
    ret = process_item(item)
    if null != ret
      error.append(ret)
  return error
</code>```


问:
Why isn't protection against SQL injection a high priority?
On Stack Overflow, I see a lot of PHP code in questions and answers that have MySQL queries that are highly vulnerable to SQL injection attacks, despite basic workarounds being widely available for more than a decade.

Is there a reason why these types of code snippets are still in use today?

答: When i was learning PHP i looked at some these PHP+MySQL books, and yeah i feel that it contributes to that bad practice. But i have sympathy, becuase they are teaching the language, not good programming practices. Otherwise where would it end?

OwnerDisplayName: Tomalak Geret'kal


问:
Architecture Question
I am writing a rules/eligibility Module.
I have 2 sets of data, one is the customer data and the other is the customer products data.
Customer data to Customer products data is one to many.

Now I have to go through a set of Eligibility rules for each of this Customer product data.
For each customer products data, I can say the customer is eligible for that product or decline the eligibility and should move on to the next product record.

So in all the rules, I need to have access to customer and customer product data(the particular record that the rules are being executed against).
Since all the rules can either approve a product or decline a product, I created an interface with those 2 methods and is implementing the this interface for all the rules.
I am passing the Customer data and one product data for all the rules (because rules should be executed on each row of customer product data). An Ideal situation would be having the customer and customer product data available for the rule instead of passing them to each rule.

What is the best way of doing this in-terms of architecture?

Edit: Here is what I am doing

```<code>public class CustomerContract
{
    public DateTime StartDate { get; set; }
    public DateTime endDate { get; set; }
    //Other Contract related details

}
public class Customer
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string state { get; set; }
}

public class CustomerInfo
{
    public CustomerInfo(int CustomerID)
    {
        Customer = new Customer();// Get Customer from DB
        AppliedProducts = new List<CustomerProduct>();// Get the customer products by customerID
        CurrentContract = new CustomerContract();//Get the contract by CustomerID, State
        declineReasons = new List<int>();// just intailizing. the decline codes are added by rules.
    }

    public CustomerContract CurrentContract { get; set; }
    public IList<CustomerProduct> AppliedProducts { get; set; }
    public IList<int> declineReasons { get; set; }
    public Customer Customer { get; set; }
}

public class CustomerProduct
{
    public decimal AmountCharged { get; set; }
    public int DeclineReasonID { get; set; }
    public int Product { get; set; }
    public decimal DiscountApplicable { get; set; }
    public decimal AmountQuoted { get; set; }
    public decimal Tax { get; set; }
}

public interface IRule
{
    // Since we need to have access to contracts when deciding the eligibility
    CustomerProduct ExecuteRule(CustomerProduct currentproduct, CustomerInfo customerInfo);

    //when denied,
    CustomerProduct DenyProduct(CustomerProduct currentProduct);
}

public class EligibityEngine
{
    List<IRule>  rules = new List<IRule>();
    private CustomerInfo c;

    public EligibityEngine(int CustomerID)
    {
        c = new CustomerInfo(CustomerID);
        LoadRules();
        foreach (var customerProduct in c.AppliedProducts)
        {
            ExecuteRules(customerProduct);
        }
    }

    private void ExecuteRules(CustomerProduct currentProductItem)
    {
        foreach (var rule in rules)
        {
            currentProductItem = rule.ExecuteRule(currentProductItem, c);
        }
    }

    private void LoadRules()
    {
        // add all the IRule types here
        //rules.Add();
    }
}
</code>```

When I execute the rule, I have pass the customer Product data and customer data. I have to pass the result of one rule execution to the other. In the above pattern, if the rule changes data in customerInfo class, it is not save unless it is passes as ref.

My question is I want the all rules to have access to this data with out passing them in. So I need not worry about capturing the out put of the rule.

I want the executeRule method to void.

答: The Specification pattern seems to suit your needs pretty well. The sample code given is precisely about Customers and Products.</p>

Title: Architecture Question


问:
What is minimalistic setup for Agile Development for a small team?
I have 10 developers and 3 Testes team and I want to setup CruiseControle as CI for automated builds, tests and deployment to production server and some repository for SCM ( Source Code Management).  I need something that would enable the team lead to create tickets (tasks) for each sprint in SCRUM and issue/bug tracking and task time tracking. I want to use simplest possible solution that just gets the job done with the minimum requirements specified in this SO question. I do not want to use heavy weight or feature rich software ( either free or costly), just the simplest possible setup.

Each developer is using Eclipse STS IDE. So it must be something that is integrated into STS (like available as STS plugin, again to keep things as simple as possible).

This is for development of Java web application.

答:
The best ticketing system by far is a white board with sticky notes.

This doesn't meet the requirement of integrating with STS, but I find sticky notes beat any software solution (as long as the team is not geographically dispersed).

They're extremely easy to visualize and work with.

Adding work to a sprint means physically adding a sticky to the board. This is a good barrier against scope creep.

The high visibility of progress is motivating.

It's easy to show nontechnical stakeholders what's going on.

The board becomes a meeting point where people talk to each other and exchange information.

It helps me get away from my desk and stretch my legs. As a desk jockey, I can use every health advantage I can get!

As for source control, use SVN or Git. If your employer demands you use some kind of heavyweight, bogged down "enterprise scm" that only gets in your way, use Git anyway and push to the central SCM on sprint boundaries.

Continuous Integration in Java projects is usually handled by Hudson/Jenkins these days. It's very quick to set up. Make sure you put up a radiator screen in a visible place!

OwnerDisplayName: ace

OwnerDisplayName: Barend


答:
I would recommend one of two approaches depending on your needs.

Firstly with a small fast team, where status reporting to your management can be done informally. In this scenario I would consider card based story boards, estimation poker (or what ever it's called), etc. Simply because in all the agile projects I've worked, the ones that have worked the best in terms of developers, testers and customers staying in sync and having a clear picture of what they are building and it's status, nothing beats the wall.

Secondly, if you have requirements for remote reporting, emailing status to others, and remote developers, then I would shift towards the Atlassian suite tools. They have a variety of online/offline tools and facilities, either free or reasonably priced. The reason I recommend their tools over the others I have seen and tried is simply because I think they are extremely well integrated, yet able to run standalone and play nice with others. This means that they are very flexible in how you use them. They are also very well built.

Title: What is minimalistic setup for Agile Development for a small team?

Body:
I have 10 developers and 3 Testes team and I want to setup CruiseControle as CI for automated builds, tests and deployment to production server and some repository for SCM ( Source Code Management).  I need something that would enable the team lead to create tickets (tasks) for each sprint in SCRUM and issue/bug tracking and task time tracking. I want to use simplest possible solution that just gets the job done with the minimum requirements specified in this SO question. I do not want to use heavy weight or feature rich software ( either free or costly), just the simplest possible setup.

Each developer is using Eclipse STS IDE. So it must be something that is integrated into STS (like available as STS plugin, again to keep things as simple as possible).

This is for development of Java web application.

OwnerDisplayName: Derek Clarkson


答:
I like Barend's approach.

If you have geographically dispersed teams, it is always a good idea to define them so they have as little overlap as possible. You can use architectural boundaries for this. Make sure each team is co-located and cross functional, then you get the best productivity.

Adding a ticketing system to a small team amounts to adding overhead. The nice thing of Scrum is that it only has a 10% overhead [Ivar Jacobson], which adds to the great productivity.

If you have tickets (bugs, work items, features etc) that cross team/architectural boundaries then an overall ticketing system might be useful, but then you should split these tickets up and create sub-tickets that are single team only.

You can then handle them in Barend's way, and you update/close them in the overall ticketing system when necessary/applicable.

Adding work during a Sprint is questionable, but if you do things a little more continuous, then you can use the ticketing system to represent the work backlog.

OwnerDisplayName: Sacha Oltmans


答:
(it's "node-oriented", if that even exists)

Start here. When dealing with a complex application like a database (even a simple database is a complex application), you should be familiar with the history of the domain and the proper terminology and have at least a very high level idea of the architecture. You could start from the Wikipedia article on Database. Spent a few days reading all the articles on the related concepts and the different database types.

And since what I have in mind is neither relational nor document-oriented

Next, you pick Relational or NoSQl. If you pick NoSQL, you should pick one type of NoSQL. That's extremely important, you won't find any architectural documents that discuss all different database families. It doesn't really matter which one you pick, just pick one and stick with it.

The language does not matter in the slightest.

Yes it does (unfortunately), because after you pick a database family you should start exploring code from open source databases of that family. There are a few generic guidelines on what to look for:

Relatively small codebase,

Architectural documents or at least a development blog,

The database you pick should be close to what's considered generic in the family, it'd be harder to learn from if it's highly specialised.

A few examples that fit:

redis,

flockdb, and

RavenDB.

Get the source, compile it and play around with it. You don't have to submit patches or anything that fancy, just explore the code and make small alterations here and there to see what happens. It's an incremental process, the more you play around with it the easier it'll be to understand what the code does. If the first project you picked seems extremely hard to understand, just move on to the next one.

Another great option would be to concentrate on building an engine for MySQL, as @N.B. suggests in an earlier answer.

If you do reach a point where you are able to do something useful with the codebase, get involved in the project's community, that's the easiest way to find more detailed resources on the concepts involved.

And then, finally, start working on your database. At first you could just write up an extremely scaled down clone of the code you've been exploring. It doesn't have to be original, quite a few great projects started out as clones or forks.

What resources/tutorials/books can I read to understand?

There are quite a few books:

Handbook of Relational Database Design

Oracle Database 11g R2: Architecture & Internals

Object-Oriented Database Systems: Concepts and Architectures

Time-Constrained Transaction Management: Real-Time Constraints in Database Transaction Systems

Understanding MySQL Internals

Object Management in Distributed Database Systems for Stationary and Mobile Computing: A Competitive Approach

Real-Time Database Systems - Architecture and Techniques

Architecture of a Database System

Foundations of Databases: The Logical Level

Readings in Database Systems

And a few hundred others, plus a myriad of academic papers you could easily trace via Google. You need to define what you want to do first, and then search for a book. Getting involved with a community of fellow database authors will also help you narrow down the list of books and perhaps get a lot better suggestions than the above.

Good luck! I'm expecting a comment with a link to your repository when you're done. And if you're never done, make sure you leave a comment reminding me that I still haven't finished that compiler I started writing in 2001.

Title: Create my own database system

Body:
I need to learn how databases work in order to use them more efficiently, and my way of learning is by doing.

I want to create my own database system. I am not referring to creating a pseudo-database that would use query to parse files; this would simply be a filesystem interface with a query language. I am talking about the actual structure of a database engine. And since what I have in mind is neither relational nor document-oriented (it's "node-oriented", if that even exists), I would need any resource to be as abstract and high-level as possible.

So how would I go about creating that? What resources/tutorials/books can I read to understand?

The language does not matter in the slightest. Ideally, the code would be pseudo-code to illustrate the concept, not tied to a particular language, but anything would do. I was not able to find anything on the matter on google (since I am so illiterate on the subject, maybe I am just not entering the right search).

If such resources are not available, then I guess something about how to create a client would at least be a step in the right direction.

ContentLicense: CC BY-SA 4.0


答:
Writing your own database “so as to understand how it all works” is the only good reason to do so (since databases are crazy hard to get right, and difficult to prove correct). You're crazy, but in a good way!

In order to see how it's done, I suggest looking at SQLite. The SQLite source is only about 1.3MB compressed, and it's a fully ACID-compliant transactional database. It's also public domain and the main author's a nice guy who I'm sure will be happy to answer your questions. (I think the trickiest bits come in how to truly commit information to disk; persuading OSes and hardware to stop lying and really write the transaction NOW is surprisingly difficult and why I'm so glad I never have to write a DB.)

Title: Create my own database system


答:
Short answer, set your goals and start.

There is no book or way to teach this to you but hands on experience.

You will make lots of mistakes and gradually gain experience. So if you run into a problem, think about it, try to come up with a solution and if you fail go to stackoverflow and get some help. Also have code reviews as early and much as possible.

After finishing your first project and have good grasp on the technical problems start looking into more abstract and higher lever topics of software engineering.

With your newly gained awareness of common problems you will get the books abstracts concepts of having clean and decoupled code, because your first project will be an unmaintainable mess.

Books (usual suspects):

Clean code

Code Complete

Head First Design Patterns

The Pragmatic Programmer

Title: Building a complete program?

Body:
Reading books, watching videos, and reviewing tutorials is all very easy. Taking notes and actually learning the material may be slightly harder, but even then, anyone with a decent brain and a fair amount of interest, it's easy enough (not to mention, fun).

The thing is, it doesn't really prepare you to write a full program or website. Let's say you're those teens (only in highschool, no true (college level) computer science or programming courses, and no real world experience), and you come out with Groupon. Or even Mark Zuckerburg, sure he was a genius, and he was a very capable programmer... but how?

How do you recommend that people who are not necessarily new to programming, but new to programming real applications and real programmers go about developing it? What is the "development process" - especially for single programmers (or maybe 2-3 teens)?

Also, as far as web development goes, what is the process? Was something like Facebook or Groupon written with a framework (like CodeIgniter or Zend for PHP)? Or do they develop their own frameworks? I'm not asking how to come up with a great idea, but how to implement great ideas in an effective way? Does anyone have advice?

I've read a couple of books on both C and C++ (primarily the C Programming Language and the C++ Programming Language) and taken AP Computer Science (as well as read a few additional books on Java and OOP). I also have read a few tutorials on PHP (and CodeIgniter) and Python. But I'm still in highschool, and I'm technically not even old enough to work at an internship for a few more months.


答:
Buy a book:

http://www.springer.com/computer/database+management+%26+information+retrieval/book/978-1-84628-394-9

Indexes are imho the most important aspect of databases today. Study the alternatives that exists like binary trees.

Also read about cartesian product which is a way to calculate how complex joins will be.

Title: Create my own database system


问:
What should a Python developer know while learning Ruby?
I have  been a Python programmer for about 18 months, consisting of one internship and a few side projects, and I consider myself pretty comfortable in the language.

However, there seems to be a lot of attention on Ruby in the programming field, but not a lot on Python anymore.

So in learning Ruby, are there going to be Pythonic things that are just bad practices in Ruby? What should I watch out for, and what should I avoid?

答:
Should I learn ruby ? Yes.

Learning a new language is always worth (especially if it enforces a different programming paradigm to the ones you know) and sometimes can make you more proficient even when programming in other languages. For example I picked up most of the functional programming I know from Lisp and I apply it when I need it to Python and Ruby.

Is it going to be difficult ? If you've learnt Python you can certainly learn Ruby too.

It's also useful if now you're looking for a job, it shows that you're curios about technology and that you can learn things on your own.

There's a good comparison between Ruby and Python on c2.com.


问:
CakePHP pair programming practise
We are on the stage of planning a CakePHP project.

It is a relatively a big project for us, as a developer+project manager, I want to hire someone
to work with me. But what I really want is to spend less time on actual coding, without losing control
of the code quality.

What I want to do is that I will design all the functions of the project in CakePHP, at least all the model's functions, and leave the implementation part to the coder who I am going to hire.

But my worry is still if I am going to lose control of the code quality using this approach? is it feasible to do so or it is going to turn this project to a chaos.

Thank you all in advanced for reading my question and give me answers.

答:
You could schedule daily code walkthroughs so the developer can explain to you the code they've written that day.

I'd recommend daily to begin with so the code base doesn't get too far ahead, you could probably lessen that to twice a week as the project progresses and you gain a bit more trust in your developer.

OwnerDisplayName: The-Di-Lab

Title: CakePHP pair programming practise

OwnerDisplayName: RichardAtHome


答:
You can do this through code reviews, but personally I think that you would be better off investing your effort in acquiring the right developer as opposed to controlling them. If you hire someone to implement code, but don't trust them, it's a recipe for bad feelings. They might well leave, or you might end up with a high turnover and a different brand of chaos will ensue than the one you're avoiding.

Good management is not an exercise in total control, rather in training your charges to manage themselves.

Title: CakePHP pair programming practise

Body:
We are on the stage of planning a CakePHP project.

It is a relatively a big project for us, as a developer+project manager, I want to hire someone
to work with me. But what I really want is to spend less time on actual coding, without losing control
of the code quality.

What I want to do is that I will design all the functions of the project in CakePHP, at least all the model's functions, and leave the implementation part to the coder who I am going to hire.

But my worry is still if I am going to lose control of the code quality using this approach? is it feasible to do so or it is going to turn this project to a chaos.

Thank you all in advanced for reading my question and give me answers.


问:
Getting from a user-story to code while using TDD (scrum)
I'm getting into scrum and TDD and I think I have some confusion which I'd like to get your feedback about. Let's assume I have a user-story in my backlog, in order for me to start developing it as part of TDD I need to have requirements, right so far?

Is it true to say that the product manager and the QA should be responsible for taking the user-story and breaking it down to acceptance tests?

I think the above is true since the acceptance tests need to be formal, so they can be used as tests, but also human readable so that the product can approve they are the requirements, right?

Is it also true that I later take these acceptance tests and use them as my requirements, i.e. they are a set of use-cases which I implement (through TDD)? I hope I'm not making too much of a mess but that's the current flow I have in mind right now.

Update

I think my initial intentions were unclear so I'll try to rephrase. I want to know more details about the scrum flow of turning a user-story into code while using TDD.

The starting point is obvious, a user surfaces a need (or the user's representative as the product) which is a short 1-2 lines description in the known format and that is added to the product backlog.

When there is a spring planning meeting user-stories are taken from the backlog and assigned to developers.

In order for a developer to write code they need requirements (especially in TDD since the requirements are what the tests are derived from).

When, by whom and to which format are the requirements compiled?

What I had in mind was that the product and QA define the requirements via acceptance tests (I'm thinking of automatic using FitNesse or the sort but that's not the core I think) which help to serve 2 purposes at the same time:

They define "Done" properly.

They give a developer something to derive tests from.

I wasn't sure when these were written (before the sprint they're picked then that might be a waste since additional information will arrive or the story won't be picked, during the iteration then the developer might get stuck waiting for them...)

答:
I'm going to answer you from the perspective of Extreme Programming (XP) regarding the acceptance tests.

When I was first getting into  (and reading the books), I read that it's really the developer's role to work with the client/user to develop/document the acceptance tests. One of the goals of XP is to increase direct communication between the user/client and the developer. This is often ideal, because it reduces the possibility of coding errors due to miscommunication of the requirements.

I have been doing TDD for about 8 years, and have been following the above approach. I think it has improved the speed of development, and satisfaction with the system because client/users see how they are directly influencing development of the application.

The main difficulty I have run into (with smaller clients), is that it is very hard to get them to participate in specifying acceptance tests. (Usually I have to do it for them, and send it to them for review.)  The larger clients I have worked with, have usually had this mindset, so they were prepared to provide specific acceptance tests.

From what I've read of scrum, I'm not sure it defines which role is responsible for defining/writing acceptance tests. I assume it can vary from team to team.

My advice is that, you as a developer, you should participate as much as possible in the test definition process.  And the goal is to get the results of the sprint in front of the users as quickly as possible, so they can tell you everything they forgot to think of (or what they incorrectly told you) as quickly as possible.


答:
I need to learn how databases work

Learn relational algebra.

Find a small DB engine, learn the source.

in order to use them more efficiently

Nope. You need to learn how to efficiently use a database. You might be a better driver if you understand how your car works, but you'll be a much better driver if you really focus on driving.

Take the traditional routes: take a course, read a book, peer review, ask questions, use the index luke.

Title: Create my own database system


问:
Next in Concurrency
For past year I have been working a lot on concurrency in Java and have build and worked on many concurrent packages. So in terms of development in the concurrent world, I am quite confident. Further I am very much interested to learn and understand more about concurrent programming.

But I am unable to answer myself what next? What extra should I learn or work on to inherit more skills related to Multi-core processing. If there is any nice book (read and enjoyed 'concurrency in practice' and 'concurrent programming in java') or resource's related to Multi-core processing so that I can go to the next level?

答:
Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors discusses concurrent programming in Scala, Clojure, JRuby and Groovy.

You will get a pretty solid understanding of different approaches for concurrency.

Where is your smile?

Title: Next in Concurrency


答:
Reading a lot about swimming does not make one a swimmer. Of-course it prepares one with the required knowledge, to become a swimmer you got to jump into the water.

I see that many people who just did it than thought/read about doing it are the ones who succeed.

If you want to be be a swimmer just jump into the water and learn swimming, if you want to be a programmer just start programming with an idea and learn programming.

I believe peter norvig's essay relevant here: Teach yourself programming in 10 years

Title: Building a complete program?


答:
At this point you need to stop reading about programming and start programming.  If you want to build a website, then go through a tutorial for the framework of your choice.  Just pick one that appeals to you.  Work through the tutorial to learn how to use the framework, then start building your own web application.

After you have written some code, then books about programming techniques will have a lot more meaning.

Title: Building a complete program?


问:
How can I make sure my evening project code is mine?
I'm a physicist with a CS degree and just started my PhD at a tech company (wanted to do applied research). It deals with large scale finite element simulations.

After reviewing their current approach, I think that a radically different method has to be applied (they are using a commercial tool which is very limited).

I'd rather base my research on an open source finite element solver and write a program which makes use of it. I'd like to develop this idea in the evenings, because that's the time that best suits me for programming (during the day I prefer reading and maths) and use it at a late stage of my PhD.

I'd like to have the option to release my program as open source on my website as a reference, for future personal or even commercial (e.g. consulting) use.

How can I make sure that my company doesn't claim the code ownership?

I thought that a version control system could help (check out only in the evening). This would document that I programmed not during regular office hours (documented elsewhere). But these data can be easily manufactured. Any other ideas?

I want to stress that I'm not interested in selling software and neither is my company.

Very interesting responses so far. This clearly helps me. Some remarks:

I'm not restrained by my work contract. National law says that the company owns anything I produce during working hours and no special agreement has been made (my employer is not selling software and may be a bit naive on this side). They mostly use software and non of my colleagues is a serious programmer.

Secondly, I need to rethink the point raised by @Mark about trade secrets. This is quite serious in the particular industry.

Thirdly, I care a lot about no to upset my supervisor/ boss. But, and this is the motivation for this question, I'd like to keep the innovative part of my work a bit separated so I can reuse it or at least demonstrate it as a reference work.

答:
I am not a lawyer, but if you were employed in my company and start working on some open source project where the project touches my business, then I would not be happy. Especially when you give something to the world for free which otherwise could be selled by us.

That would be even when you work only in the evening, using your own hardware or software, at home. So I suggest you better talk to your boss.


答:
When you are going out and try to write some programs you want to sell, I recommend you read this essay of Joel Spolsky about "The Development abstration layer".

http://www.joelonsoftware.com/articles/DevelopmentAbstraction.html

Title: Building a complete program?


答:
I had similar issue once, on a far smaller scale... Some comments:
I do not think that source code commits to a remote repository service (codesion, github, bitbucket etc) can be fabricated. An approach that I followed was to commit with a friend watching the repository on the other end of a MSN session (we discussed that and he would testify in court if needed).

A good read on how someone talked over with their company is (I believe) dropbox's Y-combinator application, quoting:

Are any of the founders covered by noncompetes or intellectual property agreements that overlap with your project? Will any be working as employees or consultants for anyone else?

Drew: Some work was done at the Bit9 office; I consulted an attorney and have a signed letter indicating Bit9 has no stake/ownership of any kind in Dropbox

What I would do if I was you, would be to proceed and be ready to prove any given moment that whatever you commit, is not related in any way to material available in your "morning" job...

Title: How can I make sure my evening project code is mine?

Body:
I'm a physicist with a CS degree and just started my PhD at a tech company (wanted to do applied research). It deals with large scale finite element simulations.

After reviewing their current approach, I think that a radically different method has to be applied (they are using a commercial tool which is very limited).

I'd rather base my research on an open source finite element solver and write a program which makes use of it. I'd like to develop this idea in the evenings, because that's the time that best suits me for programming (during the day I prefer reading and maths) and use it at a late stage of my PhD.

I'd like to have the option to release my program as open source on my website as a reference, for future personal or even commercial (e.g. consulting) use.

How can I make sure that my company doesn't claim the code ownership?

I thought that a version control system could help (check out only in the evening). This would document that I programmed not during regular office hours (documented elsewhere). But these data can be easily manufactured. Any other ideas?

I want to stress that I'm not interested in selling software and neither is my company.

Very interesting responses so far. This clearly helps me. Some remarks:

I'm not restrained by my work contract. National law says that the company owns anything I produce during working hours and no special agreement has been made (my employer is not selling software and may be a bit naive on this side). They mostly use software and non of my colleagues is a serious programmer.

Secondly, I need to rethink the point raised by @Mark about trade secrets. This is quite serious in the particular industry.

Thirdly, I care a lot about no to upset my supervisor/ boss. But, and this is the motivation for this question, I'd like to keep the innovative part of my work a bit separated so I can reuse it or at least demonstrate it as a reference work.


答: If you want to code something on your own and use it for your company you will want to clear that with your boss first making it clear your working on it outside of work hours.  You would have to consult your software usage policy to see if you can use open source programs as a company solution.  For my company as long as the program is developed outside of company hours and not on company systems we could distribute it to the open source community and use it internally.</p>


答:
Your specific problem cannot be answered without knowing the details of your contract of employment and details of local employment laws, but an answer to your general problem can be suggested.

It seems to me that your work divides into four distinct categories:

Work you do on your PhD thesis.

Work you do to create and maintain the finite element analysis library you use for your PhD work.

Work you do applying your finite element solver to problems at your place of work.

Work you do to create and maintain the finite element analysis library you use for your companies work.

It is clear that all work done for 3 is owned by the company you work for and is probably confidential and proprietory.

It is also clear that morally, you should own all work done on 1, but that may not legally be the case unless you get it written explicitly into your contract of employment.

It is the matter of 2 and 4 which are trickiest. Ideally you want to combine them, so I can see three options here:

The worst option is that you keep them completely seperate and have to repeat the coding you do at work when you get home or vice versa. Even then, you may not own the rights to your personal library, even if you do make it open source.

The next option is that the company keep ownership of the library, but you get them to grant you a license, in perpetuity, to use it for your PhD work. Unfortunately that means you won't be able to release it as open source.

Finally, and this is probably the hardest sell, you get your company to sponsor your open source library.

This final case is the most interesting, but all three require you to negotiate with your employer.

By sponsoring your work on an open source library, your company gets to be the good guy, it gains the benefit of your un-remunerated time, and potentially it gets even more value as other people help to test, debug and enhance the library.

Now you will have to be careful to keep domain specific enhancements relating to company trade secrets in a company local branch, or structure your library in an extensible manner, so that they don't leak into your library, but this is not an unsurmountable problem.


问:
Searching for entity awareness in 3D space algorithm and data structure
I'm trying to do some huge AI system just for the fun and I've come to this problem.
How can I let the AI entities know about each other without getting the CPU to perform redundant and costly work? Every entity has a spatial awareness zone and it has to know what's inside when it has to decide what to do.

First thoughts, for every entity test if the other entities are inside the first's reach. Ok, so it was the first try and yep, that is redundant and costly. We are working with real time AI over 10000+ entities so this is not a solution.

Second try, calculate some grid over the awareness zone of every entity and test whether in this zones are entities (we are working with 3D entities with float x,y,z location coordinates) testing every point in the grid with the indexed-by-coordinate entities. Well, I don't like this because is also costly, but not as the first one.

Third, create some multi linked lists over the x's and y's indexed positions of the entities so when we search for an interval between x,y and z,w positions (this interval defines the square over the spatial awareness zone) over the multi linked list, we  won't have 'voids'. This has the problem of finding the nearest proximity value if there isn't one at the position where we start the search.

I'm not convinced with any of the ideas so I'm searching for some enlightening. Do you people have any better ideas?

答:
I'm not sure if I understood your problem but you may try to partition your space into an octree.

This will help making your search for near elements more efficient (see an example of octree search here).


答:
Binary space partitions is one scalable option. It can be parallelized if you do it correctly as well; there's an article on GPU Gems that explains how.

Another one is Bounding Volume Hierarchies.

A lot of applications and games actually combine the two, making BSP trees of BVH trees.

Interesting that you ask this question though, I asked a question on SO yesterday regarding the implementation of BVHs... having a bit of trouble figuring it out :(

Title: Searching for entity awareness in 3D space algorithm and data structure

Body:
I'm trying to do some huge AI system just for the fun and I've come to this problem.
How can I let the AI entities know about each other without getting the CPU to perform redundant and costly work? Every entity has a spatial awareness zone and it has to know what's inside when it has to decide what to do.

First thoughts, for every entity test if the other entities are inside the first's reach. Ok, so it was the first try and yep, that is redundant and costly. We are working with real time AI over 10000+ entities so this is not a solution.

Second try, calculate some grid over the awareness zone of every entity and test whether in this zones are entities (we are working with 3D entities with float x,y,z location coordinates) testing every point in the grid with the indexed-by-coordinate entities. Well, I don't like this because is also costly, but not as the first one.

Third, create some multi linked lists over the x's and y's indexed positions of the entities so when we search for an interval between x,y and z,w positions (this interval defines the square over the spatial awareness zone) over the multi linked list, we  won't have 'voids'. This has the problem of finding the nearest proximity value if there isn't one at the position where we start the search.

I'm not convinced with any of the ideas so I'm searching for some enlightening. Do you people have any better ideas?


问:
Reading source code to learn
As you develop as a programmer, software developer, or coder, IMHO, you begin to see different (best or worst) practices, different algorithms, and "more than one way to do it". Seeing this code can be a great learning experience for you, even though you did not write the code. But is doing this only going to confuse you?

For example, let's say you have a library in any language that was created by a colleague, and you have been using it for a while. You decide to look at the actual source code, regardless of how extensive it is, and get a better look at how this library is written. For the sake of example, the function you use most often from this library is the max function, which finds the largest of two numbers. But this function is a lot more complicated than it needs to be. The way it is written is confusing the heck out of you, and you don't know how this works.

Will this make you a better programmer, because you realize how complicated it is for such a simple function, or will it make you a worse coder because you feel less confidant?

So my question, in general, is does reading source code make you a better programmer and if so how? If not why do people still do it?.

答:
In addition to the answer provided by FrustratedWithFormsDesign,

There I don't think there are a great number of people out there who just spin the wheel and start reading source code of random programs.

But in the interest of continuing education, generally what I do is pick one of the games I like (I use Ubuntu on my Desktop so most of the games I play are available as source), and try to run through in my head how it works. How would I do it if I were to write it from scratch without seeing the code first? Not just generalized but think about the interactions between the characters and the world, or the characters and each other, or perhaps how the map is dynamically generated or displayed to the screen, or how the AI works.

Then, with that in your head, see how close you were. In comparing the way you would have done it with the way it is currently written, you will see other ways of programming it, and it will be more engaging than just picking a program and diving in as if it were a sci-fi novel or the like.

Title: Reading source code to learn


问:
Why are part-time jobs in programming an anomaly?
I've recently quit my full time developing job at mega-corp, and I decided that I'll look for a part time job. Since then I've talked to half a dozen potential employers, and every one of them had the same reaction when I said the magic words "part-time" - they all closed up and became suspicious. Now, I understand that it might just be me, so as control I asked every one of them what if I were willing to work full time, and they all said I would probably get an offer.

My question is two fold:

Why, as an employer, would you give up a competent, even great, developer, simply because he wants to work 3 days a week and not 5?

How do I sell the story of part time job better? I usually just list my reasons which are that I prefer that balance currently in my life and that I want to work on my own projects, but it leaves them even more suspicious - am I going to start something myself and quit? Am I just lazy?

答:
Everyone seems to be quoting Brooks and making efficiency arguments, none of which are particularly wrong, mind you, but I think they've missed a rather essential point.  Programming is, generally speaking, a lot more art than science.  Oh sure, you can get a CS degree and learn a heck a lot about algorithms and solving "typical problems" at a good school and thus increase your knowledge of the science side substantially, but the only CS grads I've ever seen go on to truly become Software Engineers (vs taking detours into marketing, sales or non-engineering management) were the ones who truly loved it and considered 40 hours a week to be insufficient, if anything, because they loved to create things and writing software was a particularly satisfying way of doing just that.  I'm not saying that all software engineers need to be artists at heart, but the very best ones are, and no employer will ever say "I'm looking for the 2nd or 3rd best over here!  Keep those resumes coming, please!"

By saying you only want to work part-time, you're essentially telling a prospective employer that you're just not that into it in comparison to the other candidates who are devoting every waking hour to software and contributing their work to various open source projects when no better outlet for their creativity is available.  If an analogy will help, imagine your next restaurant meal:  Who do you want to make it?  Somebody who doesn't really care about cooking and is just slapping your meal together or a chef who really loves cooking?


答:
Don't listen to anyone who says "your own time is your own time, just don't tell anyone!" because that's incredibly bad advice that is almost certain to land you in trouble, if not at your current job then at some future one.

Not only do employment contracts vary too widely and significantly for any kind of generic advice to be useful, but different countries (including in the EU) or even different states within a single country (US) have different rules regarding how much of your work an employer owns, and even if you think you're on safe ground you can still get sued regardless, depending on how annoyed your employer is.  Who has the deeper pockets for legal fees, you or your employer?  I thought so.

Get permission first and get it in writing, so that your butt is covered should it become an issue later (even years later, with some completely different set of management who suddenly freaks out over what the previous management was totally relaxed about - you can't predict the future!)


问:
How does fair use apply to code snippets?
Is there a size where you can copy under fair use for code you don't have a license for the purpose? For example, what if I copy a snippet that is (normally) 3 lines of code? Is that fair use? If it is fair use, what length is required before I need a license?</p>

答:
I am not a lawyer.

However, you are absolutely free to use the following 3 lines of code in anything that you write:

```<code>for (i = 0; i < 5; i++) {
    printf("I am not a lawyer!\n");
}
</code>```

.... That's purely functional code (not functional in the sense you might think, but functional by what it does). It doesn't actually accomplish anything; it simply exercises the constructs of the language. It supports stuff that does actual work, you type it often enough that you have a macro to produce it. But what you're talking about isn't 'fair use', it's is this even copyrightable or licensable in the first place?

The only correct answer here is ask a lawyer. Ten lines of code from what? A highly specialized sorting algorithm? Some kind of firmware? One of the millions of configuration file parsers that have been floating around since the dawn of usenet? Code generated by another program that generates database classes based on your DB schema?

But, prove to me that you wrote that for loop, or switch statement, and didn't just copy mine. At the point where assertions stop sounding absurd, you're probably at the point where you should talk to a lawyer, or at least your engineering manager / PM / etc.

I participate in several free/open source projects, some of them require a copyright assignment for anything not 'trivial'. All of them that have this requirement define 'trivial' to be ten lines of code added or modified. But that's just an arbitrary litmus test to establish some kind of standard; one line of mind-bending byte comparison is much more likely to be subject to copyright than a 10 line switch.

My snippet gallery consists of hundreds of functions, all of them have the original author's information in doxygen style comments, as well as license info (if any, most are just public domain).

Unless clearly trivial (as in my humorous example), I would not re-use code unless I know that I have permission to do so. I also, always, follow the rules of whatever license applies. And to help my future self (or future maintainers), I like leaving a link to where I found stuff in a comment, even if that's the name of a tar ball I turn in on a USB stick if I leave the company.

ContentLicense: CC BY-SA 2.5

Body:
I am not a lawyer.

However, you are absolutely free to use the following 3 lines of code in anything that you write:

for (i = 0; i < 5; i++) {
    printf("I am not a lawyer!\n");
}

.... That's purely functional code (not functional in the sense you might think, but functional by what it does). It doesn't actually accomplish anything; it simply exercises the constructs of the language. It supports stuff that does actual work, you type it often enough that you have a macro to produce it. But what you're talking about isn't 'fair use', it's is this even copyrightable or licensable in the first place?

The only correct answer here is ask a lawyer. Ten lines of code from what? A highly specialized sorting algorithm? Some kind of firmware? One of the millions of configuration file parsers that have been floating around since the dawn of usenet? Code generated by another program that generates database classes based on your DB schema?

But, prove to me that you wrote that for loop, or switch statement, and didn't just copy mine. At the point where assertions stop sounding absurd, you're probably at the point where you should talk to a lawyer, or at least your engineering manager / PM / etc.

I participate in several free/open source projects, some of them require a copyright assignment for anything not 'trivial'. All of them that have this requirement define 'trivial' to be ten lines of code added or modified. But that's just an arbitrary litmus test to establish some kind of standard; one line of mind-bending byte comparison is much more likely to be subject to copyright than a 10 line switch.

My snippet gallery consists of hundreds of functions, all of them have the original author's information in doxygen style comments, as well as license info (if any, most are just public domain).

Unless clearly trivial (as in my humorous example), I would not re-use code unless I know that I have permission to do so. I also, always, follow the rules of whatever license applies. And to help my future self (or future maintainers), I like leaving a link to where I found stuff in a comment, even if that's the name of a tar ball I turn in on a USB stick if I leave the company.


问:
Scalable solution for website polling
I'm looking to add push notifications to one of my iOS apps. The app is a client for a website which doesn't offer push notifications.

What I've come up with so far:

App sends a message to home server when transitioning to background, asking the server to start polling the website for the logged in user.

The home server starts a new process to poll for that user. Polling happens every so many seconds / minutes.

When the user returns to the iOS app, the app sends a message to the home server to stop polling.

The home server kills the process polling for the user.

Repeat.

The problem is that this soon becomes stupid: 100s of users means 100s of different processes. It's just not scalable in the slighest.

What I've written so far is in PHP, using CURL to do the polling and I started with PHP a few days ago, so maybe I'm missing something obvious that could help me with this.

Some advice would be great.

答:
It sounds like you're using a short-polling algorithm.  You could use a long-polling algorithm in order to only send information when the information that is being polled is updated.  See the following: http://blog.samshull.com/2010/10/ajax-push-in-ios-safari-and-chrome-with.html

Also, why are you opening a separate process for each user? You should be able to send appropriate responses back to each user without opening extra apache processes.

Title: Scalable solution for website polling


问:
How to become an expert in Python, PHP and Javascript?
So I've been programming for about 9ish months now, and I've taught myself some Python, some PHP and some Javascript.

I want to become better at these languages - I can hack something out, but a lot of things like OOP, using lists in the most effective ways, etc, is lost on me.

What are the best ways to become an "expert" programmer? Does it depend on the nuances of the language, or is it more general? Is there any math I should be studying alongside it? Obviously a lot depends on what you want to do with it - so far I've mostly done small scale internal applications as well as web programming. How do I find out about good program design?

答:
The only solution is Experience. You'll become an expert when you will have coded a lot (like really a lot) in these languages. Developing projects will make you face problems, so you gonna have to find the solutions, and one day you'll have seen enough solutions to problems that you will call yourself an expert.

Coding, reading code, reviewing code, all of these will help you know how to code with a good design. You can't just rely on one snippet of code you see on the Internet to say that you know what is the good design for what you're trying to achieve. You need to look at a lot of them to know what would be the best solution to your problem.

OwnerDisplayName: Andrew Alexander


答:
1) You're in the right place.  Community forums like stack exchange are an excellent way to find information.

2) Figure out OOP before moving on.  It's a necessity before moving on from scripting to more advanced development.  net.tutsplus.com is a good site for reference and I found this guide here: http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/

3) Once you've learned OOP and practiced using it, download a framework with good documentation and follow a "Getting Started" guide (a framework is a collection of tools that help you develop faster in a language).  Symfony is a good one for PHP and you can follow the guide here: http://www.symfony-project.org/getting-started/1_4/en/.  They also have a "Jobeet" tutorial for you to follow along with

4) Along with #3, learn the MVC (Model View Controller) pattern.  This is a popular programming pattern that is used in a variety of frameworks.  It is a must if you want to move from beginner to intermediate.

Good luck!

Title: How to become an expert in Python, PHP and Javascript?

Body:
So I've been programming for about 9ish months now, and I've taught myself some Python, some PHP and some Javascript.

I want to become better at these languages - I can hack something out, but a lot of things like OOP, using lists in the most effective ways, etc, is lost on me.

What are the best ways to become an "expert" programmer? Does it depend on the nuances of the language, or is it more general? Is there any math I should be studying alongside it? Obviously a lot depends on what you want to do with it - so far I've mostly done small scale internal applications as well as web programming. How do I find out about good program design?


答:
Being an expert programmer is probably a general ability to reason and solve programming problems, both common and uncommon tasks. This is probably language independent, but I'd say you should also be very fluent with at least a couple of programming languages and their tools.

There is no magical recipe to become an expert, except with hard work: read tutorials, google a lot, listen to experts, work on problems, code a lot, work in existing projects with other people, and generally acquire lots of real world experience.

All this is language independent advice.


答:
First of all it's important to understand programming at an agnostic level. Knowing the principles, concepts, methodologies and such will help you in the long term. Here are some links to some good books to help you:

Books:

Clean Code: A Handbook of Agile Software Craftsmanship

Code Complete (2nd Ed) by Steve McConnell

The Mythical Man-Month

Design Patterns: Elements of Reusable Object-Oriented Software

Just remember when you kiss it's also better dry if you want a more solid relationship with programming. :)


问:
To what extent could Java be used over C++ for ultra high frequency systems?
Could Java ever match C++ with regards to programming ultra high frequency systems? Has the JVM improved enough to allow this? From a theoretical or practical point is it possible?

Is C++ used in most UHF systems simply because out of habit?

If you agree/disagree, what parts to Java/C++ is the basis for your viewpoint?

答:
Yes it can if you design your data structures, objects and architecture properly (which is true under any platform).  The Disruptor has more than proven this recently.

That said, C and C++ still offer natively lower level constructs than Java (which probably needs something like tuples to help push it over the edge)

Your Mileage May Vary (YMMV) with all of this.


答:
Expertise, like friendship, is a product of time. My favourite quote on the subject (I forget the source):

"Good judgment is the result of experience.
Experience is the result of bad judgment."

Put the hours in, study your craft. Strive not only for immediate solutions, but for beauty and efficiency.


答:
The inherent problem is the garbage collector. It's non-deterministic- something that UHF can never cope with. Working around this issue is basically equivalent to re-inventing native allocators. Moreover, the language carries a lot of intrinsic overhead that cannot be reduced, where C++'s constructs are directly more efficient- for example, a Java member variable has to be another reference, even if in reality it could be allocated as part of the block, which is how it's done in C++. This enforces extra indirection/cache overhead/etc. This means that a Java UHF program would be inherently significantly harder to write, for poorer results, than a C++ equivalent.

Fundamentally, high performance determinism is in the design of C++. It's not in the design of Java.

Edit: What I meant by "part of the block". In C++, a class or struct is allocated as one, single, big chunk- effectively, it's an array. This means that indexing into that array almost arbitrarily is pretty much free- that is, accessing a member variable in C++ is equivalent to an array index, for any nesting. In Java, however, every member variable of class type must be pointed to. This means that classes in Java necessarily form linked lists, which are massively slower to access. Every member variable you access in Java is a pointer de-reference, which is terribly slow in comparison. Now, in C++, if you need it, you can make pointers members and access through them, but in Java there's no equivalent option to make members into an array. This means that Java enforces the slower, linked-list access semantics. The same principle applies for many other similar cases.

And a concurrent GC is only going to help with a non-maximally-concurrent program. If you have a program that's using 100% CPU, there's no way to GC it without reducing the amount available for the program.

Title: To what extent could Java be used over C++ for ultra high frequency systems?

Body:
Could Java ever match C++ with regards to programming ultra high frequency systems? Has the JVM improved enough to allow this? From a theoretical or practical point is it possible?

Is C++ used in most UHF systems simply because out of habit?

If you agree/disagree, what parts to Java/C++ is the basis for your viewpoint?


答:
If nothing else works, then maybe you can publish the code under the name of someone else you trust (a good friend, girlfriend, your mother) and make a "contract" that you own the code or let him/her "licence" it to you or something similar.

I'm not saying this is sane, but similar schemes are used worldwide for all sort of stuff and maybe can help you protect you legally from your company. I'm not sure, how it would work for you if at all and don't take me too seriously.


答:
There are of course several approaches that will lead to success. As already said Experience is the most important one, but it depends on you how much time you need to call yourself an expert. However the timespan will be measured in years or even decades.

I began learning programming 15 years ago, and I think the best improvements in my skills were due to the following reasons:

Pressure is bad. Keep a good mood and forget unsolvable problems today just to return to them tomorrow (and wondering why it seemed so complicated the day before).

I began programming when I was a kid and no one forced me to learn anything. Do not get me wrong: You do not need to start as a kid to master a programming language. Your very own motivation - without forcing yourself to achieve an unrealistic goal in a too short amount of time - will be the key to success.

You also will not have to write your own operating system like Linus did. Neither does anyone expect you to have a successful website visited by hundreds of users a day. Simple excerpts of your projects will show (your boss, your customer, your colleagues ... ) that you know what you do.

Stick to a topic until you (almost) mastered it. Learn the basics.

Mastery is something which is not achievable. It is unlikely to know everything. But be sure to learn the basics, and do not underestimate the concepts of programming languages, paradigms or certain syntactic rules or best practices.

But please: do not just accept it if you hear or read NEVER or ALWAYS. Whenever someone talks about never doing something, do not hesitate to ask why. There is a reason why there are rules. But only the reason will tell you if it is a good thing for your situation or not. What is good in one language can be problematic in another.

Keep moving forward.

Do not stay at the same topic for decades. After 10 years of Javascript, there will be very few people who can teach you something new. But in 10 years no one will be talking about Javascript ... why? ah now you got me. Predictions concerning the future are always prone to errors ;)

However after some months or years of collecting experience in one field you will see that the stuff you learn will not be as much as at the beginning of your "mission". There will be a time when people start to ask you for help when they have problems (real problems, not the please do my homework stuff).

This is a good indicator that you have become some sort of an expert. At this point ask yourself if there is still the potential to develop yourself. Or maybe there is something new you want to lay your hands on, but no one lets you because you are just the perfect chicken for this cage.

Go out with your friends, wife, dog ...

It will give your mind a rest. Problems like Android vs. Iphone, Flash vs. Silverlight, App vs Program ... will become a matter of what is best for your needs and not the center of your existence.

Having a social life (do not confound with Facebook though) will also help keeping or even improving your soft skills. If you know how to get your colleagues to agree to the best (not necessarily your) solution can be worth more than knowing hundreds of programming languages.

Use your brain

Do not write me a letter in 10 years telling me that I messed up your life. If you are happy with a totally different strategy or find out becoming a farmer or president of the USA is worth it spending the rest of your time: do it.


答:
Work on a code project with programmers who are better than you

Protip: this seems to work for anything you want to get better at, not just code!

But seriously, if you can find talented people who are willing to tell you when you're doing it wrong, try to work on a project with them.

Read things written by programmers who are better than you

Daveo linked to some good books.  You can also find many blogs written by people who care about becoming better programmers (and are usually pretty awesome programmers themselves).


答:
Regarding "How do I sell the story of part time job better"
you might think of a two stepped approach:
First find a small company where HR policy is flexible.
Work there for a year as a full time.

After a year, when they had a chance to get a positive impression of you and your work habits, ask to reduce your workload (e.g. 'I plan on doing a degree part time')

Title: Why are part-time jobs in programming an anomaly?

Body:
I've recently quit my full time developing job at mega-corp, and I decided that I'll look for a part time job. Since then I've talked to half a dozen potential employers, and every one of them had the same reaction when I said the magic words "part-time" - they all closed up and became suspicious. Now, I understand that it might just be me, so as control I asked every one of them what if I were willing to work full time, and they all said I would probably get an offer.

My question is two fold:

Why, as an employer, would you give up a competent, even great, developer, simply because he wants to work 3 days a week and not 5?

How do I sell the story of part time job better? I usually just list my reasons which are that I prefer that balance currently in my life and that I want to work on my own projects, but it leaves them even more suspicious - am I going to start something myself and quit? Am I just lazy?


答:
I suggest becoming a member of sites like Topcoder or Usacogate, where you can step by step learn and solve algorithmic problems. For example, completing Usacogate training won't make you a computer science professional, but it gives you tons of skill for tackling many real-life problems. It teaches you testing and requires you to provide efficient solutions.

Yet another option to gain more experience is to learn a language of a different paradigm. For example, Haskell is a functional programming language. Learning it can help you approach problems from a different point of view even in other languages. For example, Python can be programmed in a very functional style.


问:
Multiple Zend application code organisation
For the past year I have been working on a series of applications all based on the Zend framework and centered on a complex business logic that all applications must have access to even if they don't use all (easier than having multiple library folders for each application as they are all linked together with a common center).

Without going into much detail about what the project is specifically about, I am looking for some input (as I am working on the project alone) on how I have "grouped" my code. I have tried to split it all up in such a way that it removes dependencies as much as possible.

I'm trying to keep it as decoupled as I logically can, so in 12 months time when my time is up anyone else coming in can have no problem extending on what I have produced.

Example structure:

```<code>applicationStorage\ (contains all applications and associated data)
applicationStorage\Applications\ (contains the applications themselves)

applicationStorage\Applications\external\ (application grouping folder) (contains all external customer access applications)
applicationStorage\Applications\external\site\ (main external customer access application)
applicationStorage\Applications\external\site\Modules\
applicationStorage\Applications\external\site\Config\
applicationStorage\Applications\external\site\Layouts\
applicationStorage\Applications\external\site\ZendExtended\ (contains extended Zend classes specific to this application example: ZendExtended_Controller_Action extends zend_controller_Action )
applicationStorage\Applications\external\mobile\ (mobile external customer access application different workflow limited capabilities compared to full site version)

applicationStorage\Applications\internal\ (application grouping folder) (contains all internal company applications)
applicationStorage\Applications\internal\site\ (main internal application)
applicationStorage\Applications\internal\mobile\ (mobile access has different flow and limited abilities compared to main site version)

applicationStorage\Tests\ (contains PHP unit tests)

applicationStorage\Library\
applicationStorage\Library\Service\ (contains all business logic, services and servicelocator; these are completely decoupled from Zend framework and rely on models' interfaces)
applicationStorage\Library\Zend\ (Zend framework)
applicationStorage\Library\Models\ (doesn't know services but is linked to Zend framework for DB operations; contains model interfaces and model datamappers for all business objects; examples include Iorder/IorderMapper, Iworksheet/IWorksheetMapper, Icustomer/IcustomerMapper)
</code>```

(Note: the Modules, Config, Layouts and ZendExtended folders are duplicated in each application folder; but i have omitted them as they are not required for my purposes.)

For the library this contains all "universal" code. The Zend framework is at the heart of all applications, but I wanted my business logic to be Zend-framework-independent. All model and mapper interfaces have no public references to Zend_Db but actually wrap around it in private.

So my hope is that in the future I will be able to rewrite the mappers and dbtables (containing a Models_DbTable_Abstract that extends Zend_Db_Table_Abstract) in order to decouple my business logic from the Zend framework if I want to move my business logic (services) to a non-Zend framework environment (maybe some other PHP framework).

Using a serviceLocator and registering the required services within the bootstrap of each application, I can use different versions of the same service depending on the request and which application is being accessed.

Example: all external applications will have a service_auth_External implementing service_auth_Interface registered.

Same with internal aplications with Service_Auth_Internal implementing service_auth_Interface Service_Locator::getService('Auth').

I'm concerned I may be missing some possible problems with this.

One I'm half-thinking about is a config.ini file for all externals, then a separate application config.ini overriding or adding to the global external config.ini.

If anyone has any suggestions I would be greatly appreciative.

I have used contextswitching for AJAX functions within the individual applications, but there is a big chance both external and internal will get web services created for them. Again, these will be separated due to authorization and different available services.

```<code>\applicationstorage\Applications\internal\webservice
\applicationstorage\Applications\external\webservice
</code>```

答:
Ultimately some code will be specific to your application's "business logic", and some is "library code". For example, something that validates form input can generally be regarded as "library", whereas something that helps you calculate the offers available for client X in a given month are clearly "business logic".

This is more of a version control issue, and there are many ways you can skin this particular cat. Tools like Maven (and to some extent Phing/Ant) are built to assemble applications from various, disparate sources - based on some sort of external configuration file (generally XML). This means you can maintain separate repos for library code and import it into Application X if you need it.

If you have control over your host, then you could think about moving library stuff into the include path - and maintain that as a separate long term project.


问:
Data Structures: What are some common examples of problems where "buffers" come into action?
I was just wondering if there were some "standard" examples that everyone uses as a basis for explaining the nature of a problem that requires the use of a buffer. What are some well-known problems in the real world that can see great benefits from using a buffer?

Also, a little background or explanation as to why the problem benefits from using a buffer, and how the buffer would be implemented, would be insightful for understanding the concept!

答:
Probably the most well known example is file buffers. Since disk I/O (especially disk access) is way slower than memory I/O, it is worth reading from / writing to disk in large chunks at once, but processing typically happens in smaller steps. So a buffer collects the many smalll bytes into a large chunk for writing, or provides the data byte by byte from memory instead of turning to the disk each time.

But the same idea can be used in network / database traffic, basically anywhere where access to a specific source / sink of data has high latency or overhead, so it is worth reading /writing large amounts of data at once, but processing happens in smaller portions. Buffers can close the gap between these conflicting needs.

Buffers also play (or at least used to play) a role in graphic cards. Rendering a large image onto screen is a complex process, and even with a fast graphic card, it may take a noticeable amount of time, while the viewer could observe the flickering of new and changing graphical elements on the screen. To avoid this, and to make the switch between contiguous frames smoother, the graphic card uses double buffering: one of the buffers contain the actual frame shown on the screen, while the next frame is prepared in the other buffer, which is not visible. Once the new frame is ready, the buffers are switched: buffer 2 becomes the active, visible buffer and buffer 1 is freed for rendering the next frame. This technique was used in all graphic cards a decade ago or so - I don't know if it is still used though.

The implementation of a buffer is fundamentally very simple: you need a memory array storing the fundamental units of data (typically bytes / chars), and a pointer or iterator to keep track of where you are reading from / writing to inside the buffer. After every read / write, the pointer is moved forward accordingly. A read buffer is filled with data from the source prior to starting the processing, then once all the data has been processed, a new chunk of data is read and the pointer is reset to the beginning of the buffer again, so the processing can start over. This is all transparent to the caller of the buffer, often such a buffer is implemented as a delegate / proxy, providing the same interface as the real data source, so all the caller sees is that it is reading data from the source (a file, a network socket, a DB table). Of course, the caller may observe timeouts between subsequent reads/writes when the source is being accessed in the background.

A related concept is queues. A queue is a more structured collections containing elements of a specific type. The main difference between a buffer and a queue is that a queue may be accessed by multiple threads in parallel, some of which are pushing data into it, others are popping elements out of it. For a queue, elements are typically pushed to the end, and popped from the beginning, thus queues are often referred to as LIFO (Last In First Out) data structures. The typical usage of queues are in "producer-consumer" systems, where one or more threads / processes are producing some data, and other thread(s) are consuming the data. The queue serves to decouple producers from consumers and to simplify their interactions.


答:
Contrary to some of the answers, experience is not the only requirement to becoming an "expert". I think most people in every industry (not just programming) do not become expert in their field. They become competent and efficient, but they do not become anywhere near as good as they could be.

The reason is that experience is not enough. You need expert advice. You need to learn how to do things from someone who is an expert.

Fortunately for us, there are many resources for programmers to become expert. Probably the best one is books. Another outstanding resource is programmers.StackExchange.

Spend most of your time writing code, but also spend some of it reading and integrating the knowledge from books like Clean Code http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882. You can find the best books by analyzing the reviews on Amazon, checking this site, and Stack Overflow.

If you invest enough time to learn and use the information in 2 or 3 books per year, it will greatly increase your skill. Also, figure out a way to record and remind yourself of everything that you learn. Otherwise it will be difficult to really know and use the information.

Pay attention to the topics that expert programmers are interested in: design patterns, unit testing, career choice, etc. Look at the world (or at least your job) from the perspective of an expert programmer.

When you are given a task to code, stop and think about it for a little while. Ask yourself some questions. What have I learned that can help me? What are the risks? What is the best approach? What are some different algorithms I can use? How much time will it take for the program to execute? What is likely to be the CPU bottleneck? What functionality could change or be added?

Hope this helps.


答:
Strings store their data in a buffer. Garbage-collected memory, and stack memory, comes out of a buffer. I/O goes into and comes out of a buffer.

Buffers occur whenever you need to group actions or data for higher efficiency, or because you need an amount of memory more than one word size of the machine.

Title: Data Structures: What are some common examples of problems where "buffers" come into action?

Body:
I was just wondering if there were some "standard" examples that everyone uses as a basis for explaining the nature of a problem that requires the use of a buffer. What are some well-known problems in the real world that can see great benefits from using a buffer?

Also, a little background or explanation as to why the problem benefits from using a buffer, and how the buffer would be implemented, would be insightful for understanding the concept!


问:
Why should you document code?

Possible Duplicate:

  “Comments are a code smell”

I am a graduate software developer for an insurance company that uses an old COBOL-like language/flat-file record storage system. The code is completely undocumented, both code comments and overall system design and there is no help on the web (unused outside the industry). The current developers have been working on the system for between 10 and 30 years and are adamant that documentation is unnecessary as you can just read the code to work out what's going on and that you can't trust comments.

Why should such a system be documented?

答:
Theres several aspects to this question.

There is an issue with comments in code, is that they introduce an overhead on maintanence programmers, in that when they change code, they also have to change comments.  Now Sometimes comments are in the code that calls a function/method about how that method behaves, so does the maintanence programmer even know about these comments to update them?   probably not.

In this case, is seems that all the other existing programmers find reading the code easier than trusting out of date comments.

Is it possible the difficulty you are having understanding the code is that the programming languange is not familiar?  and its not comments that are needed, but training, practice and experience in this programming language is the real issue?

Title: Why should you document code?


答:
This is of course depending on the complexity, but in general I would say the answer is quite easy... Yes! You say it is a COBOL-like language, how many people knows this language?

If this developer have a heart attack or becomes unavailable, who will be able to explain when someone new needs information about the design?

Time is money, to get up to speed and start do something that makes profit. It goes quicker to browse through the documentation to understand how things are supposed to work before messing up the code.

If you need to bring in some external help, it would be both cheaper and quicker if they can read the documentation.

There are other things you can't see by looking at the code itself. Thoughts about future expansion. Some code might look really stupid but is designed in a way for a coming feature or expansion.

If the company's business is relying on this program, you really want it to be documented so you can fix problems fast if something happens (for example if the key designer get pissed and leaves).

We all find it a pain in the 'A' to write documentation. I can recommend auto generated documentation such as Doxygen, a great free tool that reads your code and draws call diagrams and collects comments into either a Help file or a HTML manual. I don't know if it can handle your Cobol-like language, but there are scripts and variants that extends it to handle more languages.

We usually made a lose design document before starting a project, then we document with Doxygen style comments in the code. That was effective enough to bring in new people up to speed quickly...

Title: Why should you document code?

Body:
Possible Duplicate:

  “Comments are a code smell”

I am a graduate software developer for an insurance company that uses an old COBOL-like language/flat-file record storage system. The code is completely undocumented, both code comments and overall system design and there is no help on the web (unused outside the industry). The current developers have been working on the system for between 10 and 30 years and are adamant that documentation is unnecessary as you can just read the code to work out what's going on and that you can't trust comments.

Why should such a system be documented?


问:
Is duck typing a subset of polymorphism
From Polymorphism on WIkipedia

In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface.

From duck typing on Wikipedia

In computer programming with object-oriented programming languages, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface.

My interpretation is that based on duck typing, the objects methods/properties determine the valid semantics. Meaning that the objects current shape determines the interface it upholds.

From polymorphism you can say a function is polymorphic if it accepts multiple different data types as long as they uphold an interface.

So if a function can duck type, it can accept multiple different data types and operate on them as long as those data types have the correct methods/properties and thus uphold the interface.

(Usage of the term interface is meant not as a code construct but more as a descriptive, documenting construct)

What is the correct relationship between ducktyping and polymorphism ?

If a language can duck type, does it mean it can do polymorphism ?

答:
I think that:

Both duck typing and polymorphism are means of indirection/abstraction. Polymorphism is a concept founded on types and typing whereas duck typing is founded on contracts.

With polymorphism it is important what the THING is and not how it behaves (it behavior may be the consequence of what it is).

In duck typing it is important how a THING behaves. Duck typing is more tied to the concept of objects as actors that exchange messages, rather than objects which have some defined properties.

Title: Is duck typing a subset of polymorphism


答:
Duck typing is not quite a subset of polymorphism, since polymorphism requires explicitness, which is lost in duck typing.  So duck typing has the chance of "implementing" an "interface" not because it makes semantic sense but because you have the same signature.  If duck typing were a subset of polymorphism then it would have all the properties of polymorphism, including explicit declaration.

Duck typing also isn't really an implementation of polymorphism, it's part of a different type system.  Usually you associate duck typing with a dynamic language that goes ahead and passes a message to an object without knowing whether the object can handle it - if it can then it has effectively passed the duck typing test.  Usually you think of polymorphism as being implemented at compile time by setting up vtables (and itables if interfaces are different than classes).  But there are LOTS of languages out there and lots of ways to implement these features.

To some extent this is a philosophical question.  Can you think of duck typing as interfaces that are automatically declared implicitly?  I can't think of any reason that's wrong, exactly, but I don't think it's probably the most productive way to look at it.  I think duck typing and interfaces are both commonly encountered features of programming language's type systems, both have fairly similar ways of behaving, and both are important for programmers to understand.

Title: Is duck typing a subset of polymorphism

Body:
From Polymorphism on WIkipedia

In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface.

From duck typing on Wikipedia

In computer programming with object-oriented programming languages, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface.

My interpretation is that based on duck typing, the objects methods/properties determine the valid semantics. Meaning that the objects current shape determines the interface it upholds.

From polymorphism you can say a function is polymorphic if it accepts multiple different data types as long as they uphold an interface.

So if a function can duck type, it can accept multiple different data types and operate on them as long as those data types have the correct methods/properties and thus uphold the interface.

(Usage of the term interface is meant not as a code construct but more as a descriptive, documenting construct)

What is the correct relationship between ducktyping and polymorphism ?

If a language can duck type, does it mean it can do polymorphism ?