问:
how to break up feature requests into work units
Im not a paid developer, I spend two or three hours a day working on a development project as a hobby.  As time goes by, I come up with "good-ideas" for the project, that are generally features or bug reports.  I would like to manage them using a ticket database.  My question is about the "scope" of a ticket.  I see from looking at other projects ticketing db that tickets are generally high level features to be implemented, and that these get loosely associated with a feature branch in a VCS.

How do you manage the "To do list" associated with a ticket ?  Is it better to "re-write" the original ticket into smaller tasks ?  How small of a task rates a ticket ?

答:
This is going to vary from person to person and business to business, the model I see most often breaks the Request into deliverable units (one or many based on the scope of the request) Those units become the tickets, and the tickets will have a generalized task list created by an analyst.  That ticket will be assigned to a developer who will then look at the tasks, sigh a little, and then break them into a detailed coding unit task list.

Said developer will then be asked to assign an arbitrary % complete number to the ticket and update that arbitrary number by an arbitrary guesstimate every X arbitrary days or arbitrary Project Manager will annoy them or worse yet… pull them into a status meeting

```<code>Request (from Customer)
   |
   |-- Deliverable Unit 1(Ticket Item -from analyst - distinct publishable item)
   |-- Deliverable Unit 2
   |-- Deliverable Unit 3
            |
            |---Generalized Task Item 1(from analyst - generic to-do list item needed to complete Deliverable Unit)
            |---Generalized Task Item 2
            |---Generalized Task Item 3
            |---Generalized Task Item 4
                              |
                              |-- Detailed Coding Task 1(developer created - breaking down problem into small testable tasks)
                              |-- Detailed Coding Task 2
                              |-- Detailed Coding Task 3
                              |-- Detailed Coding Task 4
                              |-- Detailed Coding Task 5
</code>```

Body:
This is going to vary from person to person and business to business, the model I see most often breaks the Request into deliverable units (one or many based on the scope of the request) Those units become the tickets, and the tickets will have a generalized task list created by an analyst.  That ticket will be assigned to a developer who will then look at the tasks, sigh a little, and then break them into a detailed coding unit task list.

Said developer will then be asked to assign an arbitrary % complete number to the ticket and update that arbitrary number by an arbitrary guesstimate every X arbitrary days or arbitrary Project Manager will annoy them or worse yet… pull them into a status meeting

Request (from Customer)
   |
   |-- Deliverable Unit 1(Ticket Item -from analyst - distinct publishable item)
   |-- Deliverable Unit 2
   |-- Deliverable Unit 3
            |
            |---Generalized Task Item 1(from analyst - generic to-do list item needed to complete Deliverable Unit)
            |---Generalized Task Item 2
            |---Generalized Task Item 3
            |---Generalized Task Item 4
                              |
                              |-- Detailed Coding Task 1(developer created - breaking down problem into small testable tasks)
                              |-- Detailed Coding Task 2
                              |-- Detailed Coding Task 3
                              |-- Detailed Coding Task 4
                              |-- Detailed Coding Task 5


问:
Using the decorator pattern in a deep class hierarchy
How would one use the Decorator design pattern for anything other than trivial toy problems, in a deep class hierarchy?  For example, let's say you have the class

```<code>class Decorated
: public Foo, Bar, Baz
{
public:
  void operation();
};
</code>```

You would decorate it like this

```<code>class Decorator
: public Decorated
{
  void operation() { d.operation(); }
private:
  Decorated d;
};
</code>```

The issue I'm having is that Decorated can have many inherited methods (from Foo, Bar and Baz) and the Decorator needs to "redirect" them all to its inner object or the object's state will be split between the decorator and the decorated object.  How can one make sure the a Decorator correctly decorates another object and that no methods are called on the decorator instead of the decorated?

答:
A solution is to define a common interface that both Decorator and
Decorated must implement. This interface should contain all the methods
that must be decorated.

Additionally, Decorator must not be a subclass of Decorated, so that nothing is inherited from Decorated and Decorator must provide its own implementation for
each method in the interface.

It is OK to have an instance of Decorated as a member variable of Decorator
(strong aggregation): Decorator redirects all method calls to Decorated, as
appropriate.

ContentLicense: CC BY-SA 3.0


问:
Is there an optimal number of lines of code per function?
Functions are not only used to minimize duplication of code - they are also used to split up a long function into smaller ones to increase readability, as well as making the code self-commenting. Yet this gain is not directly inversely proportional to the number of LOCs per function or method; otherwise we would have tonnes of functions, all of which only contains a single line or two of code.

This lead me to wonder: Does there exist an optimal number of LOCs per function? If so, what is it, and does it deviate between languages?

答:
Here are some clues:

If you are having trouble writing the comment explaining the purpose and usage of the function, it is too long.

If you are tempted to write a comment explaining the activity of a section of code in the function, then the function is too long.

If you are pasting code from another function, then they are both too long (extract that code as a separate function).

If you need a coding convention to separate class data members from local variables, then the function is too long, and the class has too many members.

If you need to take notes while reading a function, it is too long.

Having 'tonnes' of functions, each only one or two lines long, is not necessarily a bad thing.  I found that those little functions were reused much more than I initially expected.

ContentLicense: CC BY-SA 2.5


问:
Parser combinator that looks like BNF
Is it possible to construct a parser combinator library that reads like a BNF grammar? I don't know of any, so I started wondering if there are reasons it's impossible or undesirable to do so. It seems to me it would be the best of both worlds.

Functional languages such as F# allow operator overloading. Is it just a matter of providing the right syntax, or is there more to it?

答: The various versions of Parsec / AttoParsec, for the Haskell programming language, are pretty close: a Parsec parser definition looks almost like BNF, with a few minor differences (where BNF uses |, Parsec has <|>; BNF := is = in Parsec; Parsec adds error reporting and the try function for arbitrary look-ahead).

Title: Parser combinator that looks like BNF


答:
In a very large project - one may keep a Big Functional block as one ticket and so many (development as well testing) tasks continue to evolve till the ticket is finally closed.

In your purpose such a thing won't serve any useful purpose. In your setup, you should focus on one-step-at-a-time (a.k.a. incremental work) which can be tested and be useful after every step.

The size of the ticket should be smallest unit of implementable/testable and useful work. This should itself be as small as a task so that you don't have to really manage tasks separately. Also, after each some atomic activity (feature/task) your build is back to stable before you proceed with any other activity.

Title: how to break up feature requests into work units

Body:
Im not a paid developer, I spend two or three hours a day working on a development project as a hobby.  As time goes by, I come up with "good-ideas" for the project, that are generally features or bug reports.  I would like to manage them using a ticket database.  My question is about the "scope" of a ticket.  I see from looking at other projects ticketing db that tickets are generally high level features to be implemented, and that these get loosely associated with a feature branch in a VCS.

How do you manage the "To do list" associated with a ticket ?  Is it better to "re-write" the original ticket into smaller tasks ?  How small of a task rates a ticket ?


答:
The ideal number of lines of code in a method is variable.  Basically, you only want to write just enough code to do what needs to be done within the context of the function's definition.
I think of this as a kind of Single Responsibility Principle, only applied to a method instead of a class.

Where a method has a lot of logic, and a number of steps to complete, then it makes sense to break the method up into several discrete steps.  Each of these steps would be extracted into new methods as required.

"otherwise we would have tonnes of functions, all of which only contains a single line or two of code."

The less each method does, the more easily defined it is, and the simpler to understand and manage.  There is nothing wrong with having hundreds of methods if you need them.  Also, in keeping with the SRP I mentioned earlier, it becomes easier to extract new classes when the methods have been teased apart into smaller and more manageable pieces.

Title: Is there an optimal number of lines of code per function?

Body:
Functions are not only used to minimize duplication of code - they are also used to split up a long function into smaller ones to increase readability, as well as making the code self-commenting. Yet this gain is not directly inversely proportional to the number of LOCs per function or method; otherwise we would have tonnes of functions, all of which only contains a single line or two of code.

This lead me to wonder: Does there exist an optimal number of LOCs per function? If so, what is it, and does it deviate between languages?


问:
Best method of communication between your app and your website? PHP, Web service, etc
I am creating an application which I would like to have communicate with my website. The app will have to get data for a particular app user from the website's database. I am unclear as to the best way to do this.

I have seen one way of doing this for example is creating a login page on the app which then hits a login.php logic on my website. This is convenient because I can use one code base to handle sign in for both the website and the app.

Another solution I've seen is using JSON requests to handle the communication between app and website. This is convenient because JSON objects are easy to create and parse.

I would basically like to know the best/common way to have this communication occur, what are the pros and cons to having one over the other, and any other security issues to consider.

For example, is there a risk of exposing sensitive user data when using one method over the other? If so how can this be prevented? How and where does encryption and user validations come into play here?

答:
The biggest disadvantage of an API is that you are putting the responsibility to make JSON requests, convert the answers, and display them on the page the responsibility of the browser.  Not all browsers may be up to this, either intrinsically or because users have turned off java-script.

These concerns have been diminishing over time, however, and now affect relatively few clients.  However, it might be worth doing extra work to support all the clients.

The advantages of an API are that it's much easier to separate the API logic from the details of the display and it's easier to directly access the API by means other than a browser (such as from another application). This automatically makes testing the API separate from testing the client, which is good.

It's also somewhat more secure against page injection attacks (such as cross site scripting attacks) because it's easier to properly parse and escape JSON than it is for an HTML document (which could include script tags containing java-script).  This assumes that on the client you parse JSON with a JSON parser and don't just use some form of eval(), which is not at all secure.

Another possible advantage is that you can all but eliminate the "web framework" layer.  Instead of ASP, JSP, Django, Zend, or whatever, you really just need a thin layer to relay JSON back and forth from your client to your server.  So at minimum you could port that piece between frameworks in a trivially easy way if you wanted to.  That can eliminate one big moving part from your application.

I think encryption and validation basically work the same way either way.  I think if you have an API you are more likely to remember not to trust the client than if you have a web page, since it's possible to forget that attackers don't need to use a browser as a client but can send you any headers, query parameters and post data they want.  This is more of a psychological than technical issue though, and might not apply to you.


问:
Taking an open source project to closed source
How is it legally possible to take a project initially released as open source back to closed source? Especially one licensed with the GPL any version.</p>

答:
IANAL but:

I think that if you own all the copyrights to the code base i.e. all contributors have given you (or your company as may be more likely) the copyrights to all of their contributions, then you can re-release that code base under a different licence (which may be a closed source one) if you choose. Some projects (like jQuery) release their code under two different licences simultaneously (one of which is the GPL).

This does not change the licence of any existing versions of the code though and when doing so you may find your contributors feeling quite upset, forking the project and continuing to develop it under a different name. Don't quote me on this but I think that was the kind of thing that has resulted in Libre Office vs. Open Office.


问:
What other patterns can I use for this singleton?
I have a bit of code which uses a plugin and core model, revolving around four major objects: the Core, Server, Logger, and Parser, in slightly particular order.

The Core acts as the central factory, with a catch: it's bound to a single render context (much of this is graphics related, but the other details are not important). The objects it creates and manages are specific to that core, and multiple cores can be created with different contexts. Cores can never share resources with each other. The Core is initialized from a configuration file; more on this later. The Core must have, from its creation, a Server, Parser, and Logger.

The Server handles loading and initializing all the plugins, as well as creating objects from them. It acts as a single, in-process plugin server and object registry, similar in many ways to a STA in-process COM server. As plugins are loaded into the process, not a particular Core, I'm fairly sure this is appropriate. The Server must have a Parser and Logger.

The Logger handles logging messages, particularly errors, to disk. It does very simple pre-formatted file writing, with some basic "log level" filtering. The Logger requires a Parser for resolving file paths.

The Parser handles variable replacement, particularly in paths. For example, a plugin may request the file $(root)/resources/a.txt and the Parser will replace that with the application's root directory; or $(startup)/a.txt for the startup directory. Simple stuff. Variables are contained in the Parser itself, and many are specific to the thread. However, a few are tied to a single Core, and thus enters the...

Config file. Each Core is initialized from a config file, which contains a multitude of settings: plugins for the Server, variables for the Parser, and a file for the Logger. Each Core can use a different config file, and most likely will.

In my current model, the Server, Logger, and Parser are singletons. They all must provide a single global instance, accessible from the core and plugins (and each other), potentially before a Core has been created. All handle process-level functions, but the Logger and Parser do handle some Core-level functionality.

The issue with this is that, in order to make the Logger and/or Parser Core-specific, the Server would then need its own instances, which would be potentially lacking important characteristics (like what file to use for the Logger). The Server also handles work that is very clearly common to the whole process: there's just no way to load a plugin into a single Core, that's not how shared libraries work.

In a previous version, I had all four of these created when a Core was created, and belong to a specific Core. This caused some issues and oddities, however: the Core loads itself as a "plugin" when it starts up, but the Server had the same lifetime as the Core, making this seem odd. The Parser has a number of variables that belong to the process: the initial directory, root directory, and so on. The Logger must precede the Core in some way, particularly the plugin-loading stage, so errors can be accurately logged.

My questions then are:

Is this setup too over-engineered? The separation of responsibility between objects seems good, but perhaps too split.

What design pattern(s), be it singleton or otherwise, is/are appropriate in this case, for these objects?

答:
Here are my points:

There is a difference between having only one instance of the object in the entire application vs. an object becoming singleton so that any one calling new() will magically find theInstance.

In your case, there is no benefit of having server being singleton because no one is creating server other than main(). It's just plain simple to have it as ordinary object. Even if it is singleton, it will be called only once!

Parser should never be singleton either for a different reason here. If i understood correctly, parser's only role is when core is launched; Ideally it should follow use-and-throw pattern rather than singleton

Even parser continues to serve some specific queries till core wants it, by design parser should be one instance per core because same instance of parser should never share information about various different cores. It makes parser dedicated per core.

Most people design logger as a singleton. It is not really much big deal, however, if you are a multi-threaded system a singleton logger is a big villain. First off, every singleton needs to be threadsafe. Suppose even if you make it thread safe, every time a thread x calls logger it is busy doing printf for thread y so as a result thread x waits whereas ideally you should be worrying about getting the maximum out of your quad-Core system and serve as many requests as possible.

Ideally the only genuine case where logger should be centralized or singleton is where the exact order of events must be registered one-by-one. For most purposes, different files and messages with their own timestamps are usually better even for debugging.

So for me Server (which is one instance) is created by main() and core, parser and logger are a tuple that is born and dies per request (always together). Each tuple doesn't know the state or existence of other such tuples, and that is good so that arbitrary number of threads can be instantiated in parallel, (one thread per tuple) without losing scalability but preserving loose coupling.

Only thing is - it means you are not using any design pattern! But that's not a bad thing. It is not necessary that including a design pattern makes your design necessarily better.

Remember:

There are really rare reasons where using singleton becomes must;
  everywhere else, using singleton is always an invitation to problems.


答:
There are two things here:

revoking the open source license which has been given.  It will probably depend on the text of the license. If the license has no provision, I'm not sure it is possible if the licensee hasn't infringed it. And some license like GPL version 3, are explicit in that:

All rights granted under this License are granted for the term of
  copyright on the Program, and are irrevocable provided the stated
  conditions are met.

re-licensing under other terms. It is possible as long as you get the agreement of all copyright holders. If you had the foresight to get it before accepting the contributions (some GNU projects like GCC ask you to assign the copyright to the FSF for instance) it is easy. If you didn't, it will be difficult (some project do that voluntarily so that a change of license is in practice impossible, getting the agreement of everybody or tracking and removing the contributions of those who didn't being impractical).

(Mandatory mention: I'm not a lawyer, see yours, and some aspect may be localised and depend on your jurisdiction).

Title: Taking an open source project to closed source

Body: How is it legally possible to take a project initially released as open source back to closed source? Especially one licensed with the GPL any version.</p>


答:
Speaking from an Agile perspective, you generally want to create tickets describing stories/features that take you between 1-3 average weeks to complete.  This of course may vary from methodology to methodology, however you do want to be able to complete your tickets fairly quickly in order to provide you with real, reportable, and traceable data for later analysis.

If the ticket is too complex, or too large, there is nothing wrong with spawning two or more new tickets, and closing the original ticket off.  If your issue tracker has the option to create links between ticket items, then you have the options of referring newly spawned tickets back to their originating issue.

In general, I would start with my features/stories, and list all of the tasks that are required to implement each story. I would provide estimates based on each individual tasks, which collectively would determine the estimate for an entire story/feature.


答:
If you are copy right holder of the project, you have right to set (unique) license to each party you distribute your source to.

Now given that you have already given someone a code with GPL, what he/she now possess cannot be revoked unless the code was distributed under some condition.

For example, Open Office was open source (and still is). But since Oracle acquired Sun, people felt that OO might be too tight now so they can begin modifying that code independently under the name of Libre Office and Oracle cannot revoke that right.

However, there are two things you can always do:

Attach license under some condition.
For example you can have commercial license different from Open source which is only if you are yourself an Open source project (or NGO / Academia).

For all new version you can still discontinue old license and provide a new one.
For example REDHAT 7 (or 8) was all open source. After that they created RHEL which was licensed commercially. This is how Fedora was born.


答:
You can't take one user's rights of using given-software v1.5 away
once he obtained it trough GPL/OSS licensing.

BUT.

You can contact the author of given-software v1.5 and

buy a commercial license with right of modification and closed source redistribution

buy his rights on the software from him

(this does not apply in all jurisdictions - in many countries some rights are inalienable - this means the author always retains those and he can only license them to you)

Ah, as you're already there, you may also be interested in buying rights to the name of the product.

Then you could release further versions (say given-software 2.0) under a commercial license and leave only the previous version free. (as in free speech)

Some OSS projects keep selling new versions, and release the previous one as opensource, at every major version upgrade.

(I'm thinking Ghostscript here, but also Android has been known to do something like that, pre-releasing stuff to interested partners, for hefty prices)

What could go wrong

Competition. A major OSS fork + rename could simply kill the new commercial product, (it's a free market)

The maintainer may not have all the rights he needs to re-license given-software 1.5

The original author could not be available: the current maintainer could be the second, or third, or fourth maintainer after the original one.

The project could have received too many external bug-fixes, or feature additions, and the maintainer never bothered asking for waivers, so the software now is really owned by the maintainer and everybody that ever contributed any code. Under undetermined terms.

A real inextricable mess that's only waiting for a lawyer with some time to burn and a corporation that's worth milking for money. (in fact, even the GNU project always asks for waivers that remise all copyrights to the GNU foundation)

Waivers could have been signed, but the terms on them could precisely state the license on the code can never be changed.

In those last two situations the only way out of OSS is an hard, huge, gory and sad rewrite of all the contributed code. And even if done right and well, it could still be challengeable, (by that lawyer, yes) so... it really ain't worth it.

Disclaimer: IANAL.


问:
How can I organize fast and comfortable solution compilation in VS 2010?
Most of programmers who are involved into development of more or less large project(s) know how annoying the process of compilation can be. There are some other things which are dependent on compilation, for example unit tests. TDD requires tests to execute fast, otherwise developers tend to run them rarely.

The process of compilation of whole solution my team is working with takes about 5 minutes.  Our Visual Studio solution consists of many projects, so we usually don't have to recompile all of them. Normally, this 'partial' compilation requires about 2 minutes. It's easy to calculate that compiling the solution 10 times we lose 20+ minutes! The situation is even worse when we have to rebuild whole solution often. For this reason I unload a lot of projects manually very often but it scarcely helps.

1. How can we accelerate the process of compilation?

2. Can you recommend any Visual Studio [2010] extension which allows continuous background solution compilation?

答:
The most effective technique that I know of is to build referenced projects into compiled assemblies, so that you're only compiling the project you're currently working on, and not a dozen others.

Yes, you do lose access to the source code for those assemblies, but presumably they're not changing every five minutes, and presumably someone else is working on that code, not you.  When a new revision for that assembly gets released, you can simply copy it over to your project/solution.


答:
Use the "unload project" feature to unload projects that you aren't ready to remove from the solution, but don't want to run/compile them everytime you need to debug or if you want to periodically click "compile solution" without hitting the slow project.

If you are using a distributed version control, you might want to check your code into your local repo frequently & then have a personal build server pull & compile code throughout the day. Then when your entire solution compiles, push your repo to the team's central repo.  Or you could occasionally xcopy your code to a separate machine with a build server that doesn't pull from a repo.  In both cases, this assumes you have a spare machine and a build server (TeamCity is a good one & has a free version)

Title: How can I organize fast and comfortable solution compilation in VS 2010?

Body:
Most of programmers who are involved into development of more or less large project(s) know how annoying the process of compilation can be. There are some other things which are dependent on compilation, for example unit tests. TDD requires tests to execute fast, otherwise developers tend to run them rarely.

The process of compilation of whole solution my team is working with takes about 5 minutes.  Our Visual Studio solution consists of many projects, so we usually don't have to recompile all of them. Normally, this 'partial' compilation requires about 2 minutes. It's easy to calculate that compiling the solution 10 times we lose 20+ minutes! The situation is even worse when we have to rebuild whole solution often. For this reason I unload a lot of projects manually very often but it scarcely helps.

1. How can we accelerate the process of compilation?

2. Can you recommend any Visual Studio [2010] extension which allows continuous background solution compilation?


问:
How to estimate sprint velocity with varying team capacity?
We are a small team of 4 devs rather green in Scrum. Coming from all over the country, we often take odd days off or whole weeks off to go home. Therefore our team capacity changes dramatically from one iteration to another due to annual leaves, which leads to very different velocities from one iteration to another. How do we account for team capacity when estimating velocity at the Planning Meeting? Historical data will reflect very different capacities and we cannot wait one whole year to derive an average for our estimate velocity.</p>

答:
Velocity is a guide, not a measure. Just take the average of all your sprints (account for standard deviation) and the average of your worst three, the average of your best three and say "We'll definately get these done, we might get these done, we won't get these done." By drawing three lines through your (fully estimated) backlog using these three velocities and your rough deadline (pretend it's 12 sprints and 12x your worst velocity is 75, 12x your best is 120 and 12x your average is 90. In a backlog of 100 points, even at your worst, you could do three quarters of it, at your best you'd nail the whole thing and on average, you'd deliver most of it).

With this data, your PO can make all the decisions he needs in what he MUST have, we he would like to have and what he doesn't mind leaving out.

Ultimate, things change, requirements are emergent and, well, things will change again. Don't bust your chops on maths to get a specific figure, accurate ranges are enough for this kind of thing. Bust your chops on software problems, not on backlog maths.


问:
Organizing single page code well with Notepad++
I've a c# file that will contain, most likely 10,000+ lines of code. I'd like to break this file into tabbed segments, so I can organize each method into a certain tab and label the tab something like : initial setup, helper functions,execution logic,list structures,global variables, etc.

If I were using PHP I would have separate files and use include(); to include the separate files. What can be done, following the same style, with c#?

答: C# allows for partial classes, which lets you split a class definition across multiple physical files, exactly as you could do it in PHP. Whether or not that is a good idea is a different question...


问:
Are debugging skills important to become a good programmer?
Along with the other qualities should a programmer need good debugging skills? If I have an applicant who was not able to find the error in the given program, but was able to solve all puzzles and programs, should I consider him for the job? </p>

<p>EDIT :- The puzzles are normal red,blue and red-blue balls like. The programs are like  finding continuous k zeros in an array. The debugging program is something which fails because of condition which should be >=, but instead is >. Everything is on paper. </p>

答:
Debugging is a critical skill. Actually I would say more that troubleshooting is the crtitical skill. Someone should know how to define the problem (including what user information to ask for and what logs to look at), how to reproduce it, what data sources he has available to diagnose the problem and how to debug and then how to fix one thing without breaking something else.   However, determining that during an interview is difficult.

I would give him a real problem to find and the opportunity to use the tools available and then ask what steps he took to find the issue or what else he might do if he was unable to find the issue in the time allotted. You are really looking for someone who attacks the problem somewhat systematically and who has more tools in his toolkit than just the debugger and google (except at the Junior level when he should at a minimum try both of those (someone who can't think to try those two things is probably not competent or at least I wouldn't take the chance on him) but probably doesn't have a lot of advanced troubleshooting tools yet).

I would give more weight to troublshooting skills than the answers to puzzles (well I wouldn't ask those at all) or to demonstated programming skill. I have rarely seen a developer who can troubleshoot well who can't also write good code or do the needed fixes. I've seen plenty of people who can cobble some code together to geta  "Working" product but couldn't fix a problem if their life depended on it. Mostly becasue they don;t actually understand what they are doing  or understand the problem they are trying to solve. Good troublshooters know how to identify the real problem not just the symptom. An das such they know what questions to ask to define the problem for new development as well.


答:
First, since you are talking about C# and Notepad++, have you considered Visual C# 2010 Express? It's free, and is much more powerful for C#, especially when it comes to visualizing source code in other forms (like class diagrams) or refactoring it.

Second, there are two possible cases for the C# file to have 10,000+ LOC:

Either there is something wrong with it, i.e. the code lacks architecture and, for example, was written in a procedural way, with 10,000+ LOC in a single method with plenty of goto. In this case, you need to create the architecture, than refactor the source code to match your architecture.

Or the file contains just dozens of classes, combined in a single file for an unknown reason. If this is the case, you can separate them by putting one class per file in the same project. If you keep the namespace the same, it will magically work (if there are no classes inside other classes).

Also, you could separate class members into several files using partial classes.

Third, if you don't want to refactor the code and can't split it into several files, a temporary solution would be to add #region blocks to be able to collapse code you don't work on at the moment.

Title: Organizing single page code well with Notepad++

Body:
I've a c# file that will contain, most likely 10,000+ lines of code. I'd like to break this file into tabbed segments, so I can organize each method into a certain tab and label the tab something like : initial setup, helper functions,execution logic,list structures,global variables, etc.

If I were using PHP I would have separate files and use include(); to include the separate files. What can be done, following the same style, with c#?


答:
Well, in notepad++ you could roll up the tree if you put curly brackets or an #ifdef preprocessor around your various sections. That's that a tabbed list, but it will make moving about

This is non-functional extra code purely for the sake of readability though, which is a bad idea in general.

Otherwise, you could bite the bullet and split up your massive file.


答:
There are 4 to 5 key skills in any job and programming is no different.  At the professional level you have to be good in all the key fundamental skills.  If you have 4 out of 5 it will still hold you back.

Can you imagine a salesperson that can present, convince, articulate, qualify customers, but can't close the deal?  They are out there and you don't want them on your sales team.

Debugging is definitely a core skill that a programmer can't be without.

Title: Are debugging skills important to become a good programmer?

Body:
Along with the other qualities should a programmer need good debugging skills? If I have an applicant who was not able to find the error in the given program, but was able to solve all puzzles and programs, should I consider him for the job? </p>

<p>EDIT :- The puzzles are normal red,blue and red-blue balls like. The programs are like  finding continuous k zeros in an array. The debugging program is something which fails because of condition which should be >=, but instead is >. Everything is on paper. </p>


问:
Agile unified process vs. agile lifecycle process
I wanted to know the difference between agile lifecycle and agile unified process(AUP). I do understand that AUP is a modified version of RUP using agile methodology. Can you please elaborate on the differences between the two</p>

答:
The agile methodologies are a collection of iterative and incremental software development methodologies. The emphasis is on increasing collaboration and communication while reducing project risk and the impact of risks that do materialize. Common, but not required, characteristics include timeboxed iterations, frequent released (or possible releases), cross-functional teams, heavy interaction with the customer or customer/user representatives, and a drive toward maximizing value-added. Common implementations of agile methods include Crystal Clear, Scrum, Extreme Programming, and the Agile Unified Process.

The Agile Unified Process (AUP) is a particular process methodology framework that is modeled after IBM's Rational Unified Process (RUP). Although RUP is an iterative and incremental software development methodology, it is missing some aspects of agile development, such as frequent customer interaction and and increase in collaboration. RUP is artifact-driven, often relying on documentation, formal UML modeling, and verification and validation of the various work products. Entire suites of IBM/Rational tools are built to support this process.

AUP focuses on delivering value to the customer by moving the focus away from work products to working software. The emphasis moves away from following the process to tailoring the process and the outputs to deliver only the products in a "good enough" state to the right people. In addition, the use of the simplest tools is encouraged. In other words, it takes the heavier toolchains and workflows of RUP and makes it accessible to organizations that desire more agile approaches.


问:
How do I learn algorithms and data structures?
This is in continuation to my previous question where I asked is it necessary to learn algorithms and data structures. I feel yes it is.

Now I work in an environment where I won't ever get the chance to learn it by experimenting or practically or in any assignment. What is the right approach like the right books, right kind of problems, right kind of resources that I can go through to give six months or a year or two to learn algorithms and data structures?  And also mold my mind in a way that it can relate problems to data structures and algorithms.

答:
Buy this book, Loan this or Steal this! Rest will follow :)

Introduction to Algorithms by Rivest and Cormen. It will be very hard to follow initially once you get past the explanation of the Mergesort in the introduction. Everything unfolds to you beautifully.

Plus you will get more better if you solve the problems given in the book. I never really wanted to part with the book even after graduating from grad school. It's that good.


问:
How do programmers quit a job?
I'm thinking about leaving my current employer and wondering how one goes about that process in the programming world. We have a lot of projects on the go at the moment and I'm the only developer. We have 4-5 projects that are fairly big and need to be done in the next few months and even a few longer than that.

I'm leaving because I'm the only employee and that's doing me no good. I'm young and want to learn, so a team would be nice. It's also too much work and the company is managed horribly.

I have no contract to worry about so I could theoretically quit and just not come back without notice. Just wondering how this is normally handled.

Should I write a resignation letter

How much notice should I give

Should I give a reason for leaving

Should I go to my boss who is the main reason I'm leaving or go to his boss?

Overview of replies

From the feedback here, it looks as though it's best to give 2-4 weeks of notice, and present a written resignation. Don't go into detail explaining why you're leaving in most cases. Don't burn bridges. Be professional.

答:
Submit your resignation in writing making sure to include date of notice and final day. If they want you to stay longer, try and negotiate. I would turn my present employer into a client. You won't be able to work for them full time, but could finish a project or work the new hire.

Do not "burn this bridge." This manager, as bad as he may seem, could end up anywhere or be in contact with any one else who is hiring.

You prefer to work at a place with more programmers; this job can not accommodate that. Very simple, no emotions. Don't put your supervisor down. If you have an exit interview try to give some constructive feedback.

Make sure you help out the next person taking your job. I always feel I leave positions better off than when I started. You may end up doing nothing but documentation your last few days/weeks. Let your supervisor know where all current projects stand. He may start to get an idea of what you've been doing and if he has half a brain will recognize that this may be the problem. It will help in finding your replacement.

Title: How do programmers quit a job?


问:
Rewriting a Procedural PHP App - Should we use a framework?
We have an app that's currently only got about 120 users. The userbase will probably grow by 50% over the next 12 months - but we're going to have to separate storage etc. because we're looking at several TB of data. Later this year, we will move to cluster based hosting. The app will also be provided in multiple languages.

I'm at a stage with the project now where we sometimes need to add additional features rather quickly, and whilst the building the app the way it is was a business decision (time and money was short then and we had to have something running fast), now we need to have multiple developers working on the application, and it's a little tough, even though we have everything templated and documented well.

I have the opportunity to rewrite the application - we can build one team to simultaneously redo the codebase, whilst one team manages the existing application. Once the new version is caught up, we'll switch over to it.

The question is: should we use a framework for this application? I've looked at Symfony and CodeIgnitor, and obviously the latter is easier with a smaller learning curve for our team. On the other hand, if we just re-architecture the application and build our own 'framework' and classes (I know, no need to reinvent the wheel, but we already have hundreds of functions written which seamlessly talk to our database).

Now I've seen comments like 'if you want have an app you want to make a living with, use Symfony', but I just don't know how that works. I've made a living with WordPress websites before too, so that statement is, well, not helpful!

Any advice, please. Developer resource is not a problem for us, but I don't particularly like the restrictions Symfony imposes in terms of directory names, etc. (but I guess this is just a matter of getting used to things).

The thing is, I now have to make a business decision, ultimately, and I'd like to be able to justify it to my team. At this point, from my point of view, the only major benefit is that when we hire new developers, if they are familiar with the framework, their learning curve will be smaller. This logic supports Symfony, but to me it is not enough.

Qualified opinions will help.

答:
No one can answer it definitively, but here is a framework, if you will for deciding the business value of a framework.

Does your current project have a lot of duplication that needs to be refactored anyhow?  The cost of fixing the foo functionality in n places is non-trivial.

Does the current system make no sense anyhow to a fresh set of eyes?

Does framework x elegantly solve a burning problem for us?

If you said yes to to 2/3 (particularly item #3) then I think you have a case for using a framework.  If it helps, you don't need to eat the elephant in one bite.  I've been gradually refactoring a system toward using Symfony by gradually changing out a proprietary template system for twig and using Doctrine for fresh parts of the application.

I think the learning curve angle is a bit over emphasized about frameworks.  Compared to the learning curve for most domains the time spent learning the CI or Symfony way is trivial.

OwnerDisplayName: Asif N

OwnerDisplayName: Duane Gran


答:
This depends on which language you've chosen. For C++ apps, its easy - split your solution into components and build them separately, then link against the lib files (I recommend copying the compiled lib file into a single directory for the entire project, and keep all shared headers in a single directory too - use the Project Settings to set the path to these). This means you don't need to hold the entire thing in a single solution. You can create a new 'master' solution to build everything for use in a build server, but TBH its easier just to get the build server to build each component one after the other.

For .NET apps, its slightly different, once you have dependencies to assemblies that change, you need to rebuild everything (or get into the use of policy files, or stop using version numbers :) ). Microsoft recommends using a single, huge solution for all your project and only split it if it becomes "too large to load in Visual Studio". However, they describe how to use "partitioned solutions" and "multiple solutions" - you want the latter. this is the most complex as it requires careful handling of references. In summary, you should use file references only and create a script to build each solution in turn, in the correct order.

I wish MS had added a 'reference path' like you can have for C+ libs, then you could build them and copy them to a staging area ready to reference against, but as VS use relative paths, this becomes difficult unless everyone puts their solutions in the same tree structure, though there is a work-around if you use a drive-letter mapped to a directory, VS falls back to using absolute paths.


答:
I would recommend building a REST API for your application and your website.

Building a web service is more work but I think it's a lot cleaner.  If you do it this way, neither your website nor your application has to worry about how to connect to and query the database since all of those details will be abstracted by the API.  Also, another benefit is security:  if your website ever gets hacked, they won't necessarily have access to your database since the website is only making API calls (and not database calls.)  Of course there are a lot of things to consider with security, but that's one less thing you have to worry about.

Here is a great starter guide on how to create a REST API in PHP:

http://www.gen-x-design.com/archives/create-a-rest-api-with-php/

Title: Best method of communication between your app and your website? PHP, Web service, etc

Body:
I am creating an application which I would like to have communicate with my website. The app will have to get data for a particular app user from the website's database. I am unclear as to the best way to do this.

I have seen one way of doing this for example is creating a login page on the app which then hits a login.php logic on my website. This is convenient because I can use one code base to handle sign in for both the website and the app.

Another solution I've seen is using JSON requests to handle the communication between app and website. This is convenient because JSON objects are easy to create and parse.

I would basically like to know the best/common way to have this communication occur, what are the pros and cons to having one over the other, and any other security issues to consider.

For example, is there a risk of exposing sensitive user data when using one method over the other? If so how can this be prevented? How and where does encryption and user validations come into play here?


答:
You are looking at this the wrong way.

Your code needs to be refactored from being a big ball of mud to something with a proper design.

You don't just need to think about what "tabs" have what code. You need to think about what classes contain what methods, which perform some "object oriented" task.

Sure, C# partial units could be a help to you. But you're approaching this the wrong way around.

Learn to code, and improve your code and learn to refactor and rewrite your code. Surely you have a huge 10K line unit and it needs to be broken up into separate units.  That's called "making your code better", or "refactoring".


问:
Is MySQL viable for small-medium business applications
After having worked with a Microsoft stack - VB.Net, ASP.Net, SQL Server - for the past 10 years, we are now faced with having to develop an application for both Windows and Mac environments.

It has been suggested that MySQL, for the database, is available on both platforms.

I've been under the impression that MySQL is an open source project, but has recently been bought? / taken over? by Oracle.

The MySQL web site seems to indicate that unless it is being used in another open source project, there are licencing fees to be paid, and the fees are in the order of other database costs - eg. SQL Server, Filemaker.

Somebody has suggested that MySQL is free to use in a LAMP environment (but what about for a Windows Server?). Can somebody with deployed MySQL experience confirm or explain this, along with any other gotchas that might be pertinent?

答:
I've recently used MySQL (downloaded from an Oracle website) in a real project, hosted on windows. This is a closed source, proprietary project.

I didn't download it myself or read any legalese. But my impression is the database is free to use even from Oracle. They sell support. Now I'm interested in this as well because we might be unknowingly violating a license.

Regardless we haven't paid any $$$. If it's really a concern you could always download a "non-Oracle" version of MySQL.


答: I haven't looked at the mysql licensing recently but if you want a drop-in replacement you could also consider MariaDB, which is a fork by the original MySQL developer based on a (IIRC) pre-Oracle MySQL source tree.</p>

Title: Is MySQL viable for small-medium business applications

Body:
After having worked with a Microsoft stack - VB.Net, ASP.Net, SQL Server - for the past 10 years, we are now faced with having to develop an application for both Windows and Mac environments.

It has been suggested that MySQL, for the database, is available on both platforms.

I've been under the impression that MySQL is an open source project, but has recently been bought? / taken over? by Oracle.

The MySQL web site seems to indicate that unless it is being used in another open source project, there are licencing fees to be paid, and the fees are in the order of other database costs - eg. SQL Server, Filemaker.

Somebody has suggested that MySQL is free to use in a LAMP environment (but what about for a Windows Server?). Can somebody with deployed MySQL experience confirm or explain this, along with any other gotchas that might be pertinent?


答: In 2012, I would probably craft something more along the lines of a web service application backed by whatever data store worked best with thick clients communicating entirely over the services rather than directly to the data storage. That said, any well supported database you can backup is appropriate. MySql is well supported and easy to backup. Need I say more?</p>


答:
A feature can be pretty big. I start with formulating what I would expect to see if that feature is complete; acceptance criteria.

This makes the features more actionable because the outcome is expressed in concrete terms. Usually in this process it turns out the feature is really a composition of multiple sub-features.

From there I can typically pick a sub-feature that is really the core or something everything else depends on. I start there and until that bit is done I forget about the rest.

When I have a bite of work I comprehend the further breakdown I do is really low tech, sketches, bullet points on notepaper and lots of yellow stickies.

Yellow stickies are my main external memory and "work breakdown" while working on a (sub)feature. I make and discard them progressively, I don't create a pile beforehand.

If due to time constraints I have to cut scope of a feature I usually convert my undone yellow stickies into new 'issues' or 'stories' for possible feature implementation.

I don't really like the "Create GUI", "Build DB storage" kind of breakdown. Those things are just too obvious.


答:
MySQL is Free Software licensed under the GPL, and it changing owners isn't going to affect that (that's pretty much the entire point of the GPL).

Where you need to pay is if you're distributing MySQL as part of a binary that you expect people to install, but don't want to license the entire binary under the GPL. Because of the way copyleft licenses work, you'd usually be forced to release the complete binary under the same license as the copylefted component you include.

Oracle is willing to sell you a non-GPL license to use MySQL. With that license, you can distribute it as part of a non-GPL application that you're developing (and of course, they're also happy to sell you a support contract besides).

If you don't actually distribute MySQL under a non-GPL license (for instance, if you were to use it on the back end of a web server, or if you ship MySQL server separately from your main application and instruct your clients on where to get their hands on the appropriate source code), you don't actually need to pay anything.

If you're really, really worried about it, look into using Postgres (released under an expat-like license) or SQLite (in the public domain) instead.


问:
Which notification pattern is preferable?
I'm working on a view model for a view that presents a dialog with export options. The user selects options then clicks Export. When the view model completes the Export, the calling view model receives notification.

I'm curious which is the better practice for implementing the notification: a traditional event or an Action callback that gets passed in when the dialog is opened.

Traditional Event

```<code>public class ExportDialogViewModel : ViewModelBase
{
    private readonly ICommand _exportCommand;
    private readonly ICommand _cancelCommand;

    public event EventHandler Finished;

    public ICommand ExportCommand
    {
        get { return _exportCommand; }
    }

    public ICommand CancelCommand
    {
        get { return _cancelCommand; }
    }

    public ExportDialogViewModel()
    {
        _exportCommand = new RelayCommand(Export);
        _cancelCommand = new RelayCommand(Cancel);
    }

    public void Initialize()
    {
        //set the initial conditions
    }

    public void Export()
    {
        //perform export
        OnFinished();
    }

    public void Cancel()
    {
        OnFinished();
    }

    private void OnFinished()
    {
        if (Finished != null) Finished(this, EventArgs.Empty);
    }
}
</code>```

Callback

```<code>public class ExportDialogViewModel2 : ViewModelBase
{
    private readonly ICommand _exportCommand;
    private readonly ICommand _cancelCommand;

    private Action _callback;

    public ICommand ExportCommand
    {
        get { return _exportCommand; }
    }

    public ICommand CancelCommand
    {
        get { return _cancelCommand; }
    }

    public ExportDialogViewModel2()
    {
        _exportCommand = new RelayCommand(Export);
        _cancelCommand = new RelayCommand(Cancel);
    }

    public void Initialize(Action callback)
    {
        _callback = callback;
        //set the initial conditions
    }

    public void Export()
    {
        //perform export
        _callback();
    }

    public void Cancel()
    {
        _callback();
    }
}
</code>```

My initial thoughts are that the traditional event is a little more flexible: it allows more than one subscriber to be notified, and it also allows zero subscribers to be notified. The callback, on the other hand, enforces a particular way of interacting with the dialog--the callback must be passed in during initialization. The callback is also simpler to implement and use, though perhaps less familiar than events.

Which of the two notification patterns do you recommend and why?

答:
You basically answered your own question in your last paragraph.  Each option behaves similarly to a certain degree, is programmed differently, and presents trade-offs in terms of flexibility and simplicity.

With Actions, you can implement them so that you don't require any sort of initialization step.  They can be passed into a function, and triggered under certain conditions within the method called.  You can also use actions to behave exactly like an event, by assigning an action to a property and triggering the action when needed. As you've already stated though, the Action will only allow you to notify one single handler.  Under some circumstances, this may be useful if your intention is to limit notification to only a single handler.  I can't think of many circumstances off the top of my head where this would really be worth the effort so to speak.

Events are beautiful things.  I remember writing my first Event driven code in Delphi many years ago, and it occurred to me at the time (and with my worldly 6-months of experience) that there really wasn't much of a reason not to make all application code event-driven.  when I eventually cam across the MVC pattern a few years later, I wasn't surprised to see that it was essentially an event-driven pattern. There is a great elegance and simplicity to simply connecting a whole bunch of individual event handlers to a simple notifier, and having all of those handlers simply do their own little thing, rather than needing to write a big long method full of edge-case logic do do the same thing. Even better is the ability to replace or add to functionality simply by changing or adding to the list of handlers registered to a particular event.

For these reasons I'd be tempted to go out on a limb and say that events are better to a degree, but as with all things there is a time and place for everything, and sometimes an action will serve just as well, though perhaps not as any reasonable replacement for an event.


答:
A large class is generally a code smell which indicates that the class is most likely trying to take responsibility for doing too many things. If you ever hope to write good SOLID code, then you need to start thinking about your class as being a single purpose type as per the Single Responsibility Principle - aka the first initial of the "SOLID" acronym.

Here's another principle that you may find useful. DRY, or Don't Repeat Yourself.  It has been my experience that when you have very bloated classes with more than a few hundred lines of code, it is most likely that you will have a lot of repetition within the code.  This is usual the result of Cut-And-Paste coding that often occurs when developers are in a hurry to hack together something that works, with little thought to the design and future maintenance of the code.

Large classes are often indicators of a large accrual of Technical Debt that will likely be very costly to maintain, and difficult to change.

So with all of these issues I've bombarded with you, what can you do about it?  First of all, looking at ways to reorganize your code is an admirable task, but using IDE tricks such as tabbing, regions, or something else to hide the mess will not help you ti fix your problem, and will most likely end up making your situation worse.  I would recommend instead that you look to refactoring your code.

Break your long methods out into a collection of smaller ones.

Use these smaller methods to help you to remove duplication.

Identify what the class is intended to do, and move all of those methods that don't do what the class intended out into other classes.

Move your new classes into new source files, and this will give you all of the benefits you are hoping to gain from the IDE tricks I mentioned earlier, as well as making it easier for an entire team to work on the same code base while minimizing the number of 3-way merges you are likely to encounter if you leave everything in a single file.

Keeping lots of little classes in their own files would also achieve the ability to add functionality through "includes" (or using statements in C#) in exactly the same way as you would in other languages.


问:
What advantages does developing applications for smartphones have over developing the same application as a web application?
Let's take the Facebook application as an example. Why did they develop an application when the users could just access to their page and do the same? For me that represents more maintenance and more cost because for each feature added to the web application that feature will have to be added to the smartphone application as well.

So why would I want to develop more than once (for each patform iOS, Android, etc) when I could just have one web application? What benefits do I get? The only one that comes to my mind is GPS feature.

EDIT:

My question is more oriented towards business applications that are going to be used only by some members of the company, it's not about selling the application (private use). So contrary to what some answers say about that by developing as a smartphone application it will benefit from more sells because of the "smartphone stores" for me this point is not important because the application is for private use.

By developing the application as a web application it means that it can be accessed through smartphone browser and also in a PC (any capable browser), but developing as a native application would limit this to only some kind of smartphone so we would be limiting  the use.  On the other hand developing it as a web application means that in order to access the application an Internet connection must be available.

So keeping this in mind how would you convince your boss to write the application for a given smartphone platform (iOS/Android) vs developing it as a web application?

答:
I'm going to expand on Chris's excellent answer by mentioning another important aspect from the businessman's point of view.  Market Appeal. Think about it for a moment. You've just acquired your latest trendy gadget (smart phone, tablet, whatever), and you want to fill it with lots of interesting apps and gadgets which appeal to you.  You're an avid social media user, but you don't like how slow the browser on you phone renders the pages, or you are getting really geeky and looking into issues such as battery monitoring etc. You wan't to use your facebook, or google without needing the browser, and you don't like how small the links are on the screen which cause you to keep bringing up the wrong pages.  Would you rather have an application purposely built for your device, or keep using your phones browser?

Big companies like facebook and Google know there user demographic very well, and they know the appeal and hype that are likely to be generated around the release of apps for mobile devices.  They create purpose built apps because they can afford to do so, and because it will result in a viral hype that will be worth more to the company than the money actually invested in creating these apps.

From a technical point of view, you also need to consider usability. Web pages work well in an environment where a user has fine control over where the pointer is positioned.  when you are clicking on hyperlinks, you don't want to click on the wrong one, because it wastes your time. I've lost count of the number of times I found myself swearing at my bank for not providing a nice and easy to use app for my phone and leaving me to use a web interface. The paradigms not gel well between a touch interface, and a web page. This may be because the web hasn't yet caught up to the new generation of touch devices that have become available over the last 5 years.  It might also be because the technical obstacles are quite large.  Whatever the reason it becomes clear in your first 5 minutes that allow you to swipe, touch, and access menus without losing valuable screen real estate, you will instantly be happier with a dedicated app than with a web interface.

This situation may possibly change as developers become more adept at implementing clever HTML5 interfaces, but for now it makes a lot of sense to duplicate your GUI efforts to a certain degree, or risk potentially alienating a part of your target demographic.


问:
In MVC, what is the difference between controller and router?
Do they mean the same thing (attaching URLs to actions, or actions to URLs) or is there any difference I'm missing?

Example: http://github.com/dannyvankooten/PHP-Router vs. http://konstrukt.dk

答: The route maps a URL to a controller, which is the action. Sometimes the roles are not really separated very well depending on the framework.</p>


答: To my belief you can download and use mysql server free of charge - but if you want any type of real time support you need to purchase the server. If you are developing software that deploys the server, you will need to then purchase it as well. I have been using mysql in a small-medium sized retail environment for around for years and have not had any issues with it. Do not cheap out on the server however, many make that mistake and regret it in the long run.</p>


答:
Router:

Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request.

Controller:

Controller implements a »Controller pattern, in which all requests are intercepted by controller and dispatched to individual Action Controllers based on the URL requested(that is routing request from Router).

Title: In MVC, what is the difference between controller and router?

Body:
Do they mean the same thing (attaching URLs to actions, or actions to URLs) or is there any difference I'm missing?

Example: http://github.com/dannyvankooten/PHP-Router vs. http://konstrukt.dk


问:
Is there a difference between the terms "Open Source" and "Open Source Software"?
Until today, I have always used the terms open source and open source software interchangeably. But then I read Phil Haack's blog post in which he suggests that the two terms are not necessarily referring to the same thing. He proposes the following definitions:

Open Source Software is source code which is licensed under a license that meets the Open Source Definition.

Open Source is a development methodology which includes certain characteristics:

Developed in the open with community involvement

The team accepts contributions that meet its standards

The end product has an open source license. This encompasses open source software, open source hardware, etc.

So Phil argues that the end product of open source development is open source software, but open source software is not necessarily the product of open source development. Since he also mentions that there are many different understandings of what open source means, what do you think about these definitions? Do you agree with the distinction he has made?

答:
Phil is right in the sense that open source software is a result of open source development and for that very reason your source code must be made available in public. Open source's canonical is free software, free as in speech, not in beer. There are cases where a open source project can be extended and turned into a proprietary product. And there are a lot of open source license methods GPL, LGPL, MIT, FreeBSD to name a few that create confusion among newcomers (I am still to understand, perceive and evaluate them).

Plus, free software and open source software are used interchangeably in web contexts that further the confusion. Free software, most often, are only free to use and not free to modify and distribute. On top of this, there are intellectual property rights(IPR) that differ from country to country that makes the situation more confusing. That's the reason my answer is a bit ambiguous.

If you just want to create a open source software, create it with open source tools and license it under GPL3. If you are more concerned about IPR, you need to do a decent bit of research on the internet to get a hold of how things would pan out.


问:
Percent or Pixels HTML/CSS
Coding a new website. Basically, for position elements using CSS I would use percents and figured that was the best thing to do since everyone's monitor was a different size. But I noticed a lot of big websites use pixels.

I don't understand how you can use pixels to position things since we all have a different size screen?

答:
The fluid layout provides, in general, better user experience, but is not without flaws. When using fluid layouts, you are testing them on medium-small to medium-large screens, but you certainly can't do complicated fluid layouts with CSS2 (no JavaScript, no HTML5/CSS3) which works perfectly well on any device, from a small mobile phone to a 30-inches full-screen mode.

The fluid layout is also more expensive in most cases. This is true for the visual design, the ergonomics and the HTML/CSS development.

The fixed layout gives the ability for a developer to say:

I gathered the statistics about the browsers of my visitors, and know that 95% of users of my website have a resolution width between 1024 and 1920 pixels. Instead of spending a month designing a fluid layout, I will target the resolution of my 95% of users, and spend the free time to implement some cool features instead.

If I have enough time and resources, I'll do a dedicated version for mobile phones.

The fact that fixed layouts are easier to implement is important here. I have a choice: either I do a fluid layout which will in all cases look bad on very small or very large screens, or I spend the same amount of time and money creating two or three layouts for different resolutions.

Aside the cost, fluid layouts have also some issues you can't solve without HTML5/CSS3 or JavaScript.

Example 1: Programmers.SE has a fixed layout. This means that on any resolution, the main text I read (the questions and the answers) will be no longer than, say, 800 pixels in width. Given the current font size and the line spacing, this is ok to be able to read fast.

If Programmers.SE moves to fluid layout, your current question would we 1 600 pixels width on my screen at this moment. This will be totally unusable, and I wouldn't be able to read a long text without requiring to minimize the browser window and adjust it for the website.

Example 2: in a recent project, I split the text in two columns for the browsers which support this. Given the font size and the line spacing, one column is not really readable, but two are perfect. Since I know the width of the page, I know how the text will appear in 93 to 94% cases: the other 5% are using browsers that don't support text columns, and the final 1 to 2% are using custom font sizes (i.e. people who don't see well and enlarge the fonts by default and/or people who don't have the font I use on the page).

With a fluid layout, I wouldn't be able to do that without HTML5: on a 30-inches monitor full-screen, two columns would still be unreadable: it would require four or five columns instead. On a screen of a large mobile phone, two columns would be unreadable neither, since there will be one to three words per line.

Example 3: you have a topmost menu with the parts of your website. There are five parts, and the elements are float:lefted. With a fixed layout, it magically works, and fails if the user specifies the larger font for accessibility reason. With a fluid layout, what will happen with those elements if the user resizes the page to a width smaller than the total width of those five elements?

Title: Percent or Pixels HTML/CSS


答:
There are a couple situations when I will use pixel based positioning.

The first being when I am creating absolute positioned menus or items.

The other situation I can think of is when I create webapps. I want the environment to give a desktop like appearance utilising all of the space. The layout is dynamic in sizing(some times I use YUI2's layout which is really helpful. See here: http://developer.yahoo.com/yui/layout/). So on window resizes the layout also resizes.

Pixel based positioning gives you more control and the look will remain static however as mentioned when switching resolutions everything will be displayed larger or smaller.

Title: Percent or Pixels HTML/CSS

Body:
Coding a new website. Basically, for position elements using CSS I would use percents and figured that was the best thing to do since everyone's monitor was a different size. But I noticed a lot of big websites use pixels.

I don't understand how you can use pixels to position things since we all have a different size screen?


答:
Open Source Software is Open Source but not all Open Source is Open Source Software.

There is Open Source Hardware, Open Source Robotics, etc. It is a philosophy that can be applied to almost anything. http://en.wikipedia.org/wiki/Open_source

Title: Is there a difference between the terms "Open Source" and "Open Source Software"?

Body:
Until today, I have always used the terms open source and open source software interchangeably. But then I read Phil Haack's blog post in which he suggests that the two terms are not necessarily referring to the same thing. He proposes the following definitions:

Open Source Software is source code which is licensed under a license that meets the Open Source Definition.

Open Source is a development methodology which includes certain characteristics:

Developed in the open with community involvement

The team accepts contributions that meet its standards

The end product has an open source license. This encompasses open source software, open source hardware, etc.

So Phil argues that the end product of open source development is open source software, but open source software is not necessarily the product of open source development. Since he also mentions that there are many different understandings of what open source means, what do you think about these definitions? Do you agree with the distinction he has made?


问:
Problems (such as maintenance) in development with unpopular language
I'm developing some application with clojure(lisp) alone in my team. It starts as small application. No problem. But as it's having features and extending the area, it's becoming important program.

I worried about maintenance or something. No one in my team knows clojure or lisp nor is interested in languages such as them.

So, isn't it wrong to do programming in unpopular languages? (for my own fun?) Should I use more popular languages? (at least such as python)

I'm sure if I leave the team, --not saying I'm leaving. :)-- no one would maintain it. This program will be destroyed and some will develop with other language.

I'm very enjoying developing with clojure though, I came across with that this might be not for my team.

What do you think about this? I think many programmers loving unpopular languages have been concerning similar issue.

答: Organize a tutorial or a training session. If your team members don't want to act like professionals and increase their knowledge, especially if the program is becoming more important, than it's out of your hands. In the worst case, you can talk to management and they can maybe mandating this kind of training session. You might look like a jerk, but at least you won't be the only one that has to maintain the program. The other option is to suggest that a 2nd programmer who knows clojure be added to the team.</p>

OwnerDisplayName: Hybrid


问:
Parser combinator that looks like BNF
Is it possible to construct a parser combinator library that reads like a BNF grammar? I don't know of any, so I started wondering if there are reasons it's impossible or undesirable to do so. It seems to me it would be the best of both worlds.

Functional languages such as F# allow operator overloading. Is it just a matter of providing the right syntax, or is there more to it?

答: You should be looking at Scala's Parser combinator. It's built ground up to match BNF's syntax.</p>

Title: Parser combinator that looks like BNF


答: Regarding question number 2 NCrunch or Continuous Test may help. Both run builds and test continuously. With NCrunch you can control how threads and cores are used for building and running tests and you control which you want to include in your current session. I would imagine Continuous Test has similar features but I haven't tried it. </p>


问:
Best method of communication between your app and your website? PHP, Web service, etc
I am creating an application which I would like to have communicate with my website. The app will have to get data for a particular app user from the website's database. I am unclear as to the best way to do this.

I have seen one way of doing this for example is creating a login page on the app which then hits a login.php logic on my website. This is convenient because I can use one code base to handle sign in for both the website and the app.

Another solution I've seen is using JSON requests to handle the communication between app and website. This is convenient because JSON objects are easy to create and parse.

I would basically like to know the best/common way to have this communication occur, what are the pros and cons to having one over the other, and any other security issues to consider.

For example, is there a risk of exposing sensitive user data when using one method over the other? If so how can this be prevented? How and where does encryption and user validations come into play here?

答:
Depending on the complexity of your requirements either REST/JSON or SOAP web services.

For simple requirements REST is simpler to understand and implement, especially if you favor JSON over XML.

However if your requirements include authentication, message verification, discovery, non repudiation, or, complex message schema you may be better of diving into the complexities of SOAP as nearly every issue is covered. Although SOAP is more complex and harder to understand it does deal with nearly every architectural permutation and variation possible in a messaging system, plus, it has a very mature and comprehensive set of tools to help you through the maze of APIs. But if you don't need this level of sophistication stick with REST.


问:
Interface and Inheritance: Best of both worlds?
I 'discovered' interfaces and I started to love them. The beauty of an interface is that it is a contract, and any object that fulfills that contract can be used wherever that interface is required.

The problem with an interface is that it can't have a default implementation, which is a pain for mundane properties and defeats DRY. This is also good, because it keeps the implementation and the the system decoupled. Inheritance, on the hand, maintains a tighter coupling, and has the potential of breaking encapsulation.

Case 1 ( Inheritance with private members, good encapsulation, tightly coupled)

```<code>class Employee
{
int money_earned;
string name;

public:
 void do_work(){money_earned++;};
 string get_name(return name;);
};

class Nurse : public Employee:
{
   public:
   void do_work(/*do work. Oops, can't update money_earned. Unaware I have to call superclass' do_work()*/);

};

void HireNurse(Nurse *n)
{
   nurse->do_work();
)
</code>```

Case 2 (just an interface)

```<code>class IEmployee
{
     virtual void do_work()=0;
     virtual string get_name()=0;
};

//class Nurse implements IEmployee.
//But now, for each employee, must repeat the get_name() implementation,
//and add a name member string, which breaks DRY.
</code>```

Case 3: (best of both worlds?)

Similar to Case 1. However, imagine that (hypothetically) C++ did not allow overriding methods except those methods that are pure virtual.

So, in Case 1, overriding do_work() would cause a compile-time error. To fix this, we set do_work() as pure virtual, and add a separate method increment_money_earned(). As an example:

```<code>class Employee
{
int money_earned;
string name;

public:
 virtual void do_work()=0;
 void increment_money_earned(money_earned++;);
 string get_name(return name;);
};

class Nurse : public Employee:
{
   public:
   void do_work(/*do work*/ increment_money_earned(); ); .
};
</code>```

But even this has problems. What if 3 months from now, Joe Coder creates a Doctor Employee, but he forgets to call increment_money_earned() in do_work()?

The question:

Is Case 3 superior to Case 1? Is it because it of 'better encapsulation' or 'more loosely coupled', or some other reason?

Is Case 3 superior to Case 2 because it conforms with DRY?

答:
Is Case 3 superior to Case 1? Is it because it of 'better
  encapsulation' or 'more loosely coupled', or some other reason?

From what I see in your implementation, your Case 3 implementation requires an abstract class which can implement pure virtual methods which can then later be changed in the derived class. Case 3 would be better as the derived class can change the implementation of do_work as and when required and all the derived instances would basically belong to the base abstract type.

Which Case is the best for a software project which might have 40,000
  lines of code.

I would say it purely depends on your implementation design and the objective that you want to achieve. Abstract class and Interfaces are implemented based on the problem that has to be solved.

Edit on question

What if 3 months from now, Joe Coder creates a Doctor Employee, but he
  forgets to call increment_money_earned() in do_work()?

Unit tests can be performed to check whether each class confirms to the expected behavior. So if proper unit tests are applied, bugs can be prevented when Joe Coder implements the new class.


答:
Interfaces can have default implementations in C++. There is nothing saying that a default implementation of a function does not solely depend on other virtual members (and arguments), so doesn't increase any kind of coupling.

For case 2, DRY is superseding here. Encapsulation exists to protect your program from change, from different implementations, but in this case, you have no different implementations. So YAGNI encapsulation.

In fact, run-time interfaces are usually considered inferior to their compile-time equivalents. In the compile-time case, you can have both case 1 and case 2 in the same bundle- not to mention it's numerous other advantages. Or even at run-time, you can simply do Employee : public IEmployee for effectively the same advantage. There are numerous ways to deal with such things.

```<code>Case 3: (best of both worlds?)

Similar to Case 1. However, imagine that (hypothetically)
</code>```

I stopped reading. YAGNI. C++ is what C++ is, and the Standards committee is never, ever, going to implement such a change, for excellent reasons.

Title: Interface and Inheritance: Best of both worlds?

Body:
I 'discovered' interfaces and I started to love them. The beauty of an interface is that it is a contract, and any object that fulfills that contract can be used wherever that interface is required.

The problem with an interface is that it can't have a default implementation, which is a pain for mundane properties and defeats DRY. This is also good, because it keeps the implementation and the the system decoupled. Inheritance, on the hand, maintains a tighter coupling, and has the potential of breaking encapsulation.

Case 1 ( Inheritance with private members, good encapsulation, tightly coupled)

```<code>class Employee
{
int money_earned;
string name;

public:
 void do_work(){money_earned++;};
 string get_name(return name;);
};

class Nurse : public Employee:
{
   public:
   void do_work(/*do work. Oops, can't update money_earned. Unaware I have to call superclass' do_work()*/);

};

void HireNurse(Nurse *n)
{
   nurse->do_work();
)
</code>```

Case 2 (just an interface)

```<code>class IEmployee
{
     virtual void do_work()=0;
     virtual string get_name()=0;
};

//class Nurse implements IEmployee.
//But now, for each employee, must repeat the get_name() implementation,
//and add a name member string, which breaks DRY.
</code>```

Case 3: (best of both worlds?)

Similar to Case 1. However, imagine that (hypothetically) C++ did not allow overriding methods except those methods that are pure virtual.

So, in Case 1, overriding do_work() would cause a compile-time error. To fix this, we set do_work() as pure virtual, and add a separate method increment_money_earned(). As an example:

```<code>class Employee
{
int money_earned;
string name;

public:
 virtual void do_work()=0;
 void increment_money_earned(money_earned++;);
 string get_name(return name;);
};

class Nurse : public Employee:
{
   public:
   void do_work(/*do work*/ increment_money_earned(); ); .
};
</code>```

But even this has problems. What if 3 months from now, Joe Coder creates a Doctor Employee, but he forgets to call increment_money_earned() in do_work()?

The question:

Is Case 3 superior to Case 1? Is it because it of 'better encapsulation' or 'more loosely coupled', or some other reason?

Is Case 3 superior to Case 2 because it conforms with DRY?

Body:
Interfaces can have default implementations in C++. There is nothing saying that a default implementation of a function does not solely depend on other virtual members (and arguments), so doesn't increase any kind of coupling.

For case 2, DRY is superseding here. Encapsulation exists to protect your program from change, from different implementations, but in this case, you have no different implementations. So YAGNI encapsulation.

In fact, run-time interfaces are usually considered inferior to their compile-time equivalents. In the compile-time case, you can have both case 1 and case 2 in the same bundle- not to mention it's numerous other advantages. Or even at run-time, you can simply do Employee : public IEmployee for effectively the same advantage. There are numerous ways to deal with such things.

Case 3: (best of both worlds?)

Similar to Case 1. However, imagine that (hypothetically)

I stopped reading. YAGNI. C++ is what C++ is, and the Standards committee is never, ever, going to implement such a change, for excellent reasons.


答:
The problem with an interface is that it can't have a default implementation, which is a pain for mundane properties and defeats DRY.

In my own opinion, interfaces should have only pure methods - without a default implementation. It doesn't break the DRY principle in any way, because interfaces shows how to access some entity.
Just for references, I am looking at the DRY explanation here :

 "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."

On the other hand, the SOLID tells you that every class should have an interface.

Is Case 3 superior to Case 1? Is it because it of 'better encapsulation' or 'more loosely coupled', or some other reason?

No, the case 3 is not superior to case 1. You have to make up your mind. If you want to have a default implementation then do so. If you want a pure method then go with it.

What if 3 months from now, Joe Coder creates a Doctor Employee, but he forgets to call increment_money_earned() in do_work()?

Then Joe Coder should get what he deserves for ignoring failing unit tests. He did test this class, didn't he? :)

Which Case is the best for a software project which might have 40,000 lines of code?

One size doesn't fit all. It is impossible to tell which one is better. There are some cases where one would fit better then the other.

Maybe you should learn some design patterns instead of trying to invent some of your own.

I just realized that you are looking for non-virtual interface design pattern, because that is what your case 3 class looks like.


问:
Job hopping, is it a problem?
How would you, as someone involved in the hiring process (manager,interviewer, etc) feel about a candidate that has changed jobs every 1-2 years?

update
Thanks for all the input everybody, some really great responses, and good info in every post.  I asked it because I'm currently at my 3 job in the last 5 years and I'm feeling like my position is going nowhere (like the position should have been contract in the first place, not full-time).

My only options here seem like transition to a different team doing something I'm not really interested in or look for new work, but I'm a little afraid my recent job history is all short stints.

答:
I've had 16 jobs in the space of nearly 7 years. Do the math.

I am a contractor and I exclusively target that market, so I'm typically not looking for a permanent role.

I don't think I'll ever go permanent unless I either have to or am presented with a job that's so suitable and interesting that I'd want to do it for the next 5 years.

But at the moment, this is what I love doing, and I'll stick to it as long as I can.

Title: Job hopping, is it a problem?


答:
One way to solve the forgetting-to-call-the-superclass problem is to give the control back to the superclass! I've re-jiggered your first example to show how (and made it compile ;)). Oh, I also assume that do_work() in Employee was supposed to be virtual in your first example.

```<code>#include <string>

using namespace std;

class Employee
{
    int money_earned;
    string name;
    virtual void on_do_work() {}

    public:
        void do_work() { money_earned++; on_do_work(); }
        string get_name() { return name; }
};

class Nurse : public Employee
{
    void on_do_work() { /* do more work. Oh, and I don't have to call do_work()! */ }
};

void HireNurse(Nurse* nurse)
{
    nurse->do_work();
}
</code>```

Now do_work() cannot be overridden. If you want to extend it you have to do it via on_do_work() which do_work() has control over.

This, of course, can be used with the interface from your second example as well if Employee extends it. So, if I understand you correctly I think that makes this Case 3 but without having to use hypothetical C++! It's DRY and it has strong encapsulation.

Body:
One way to solve the forgetting-to-call-the-superclass problem is to give the control back to the superclass! I've re-jiggered your first example to show how (and made it compile ;)). Oh, I also assume that do_work() in Employee was supposed to be virtual in your first example.

#include <string>

using namespace std;

class Employee
{
    int money_earned;
    string name;
    virtual void on_do_work() {}

    public:
        void do_work() { money_earned++; on_do_work(); }
        string get_name() { return name; }
};

class Nurse : public Employee
{
    void on_do_work() { /* do more work. Oh, and I don't have to call do_work()! */ }
};

void HireNurse(Nurse* nurse)
{
    nurse->do_work();
}

Now do_work() cannot be overridden. If you want to extend it you have to do it via on_do_work() which do_work() has control over.

This, of course, can be used with the interface from your second example as well if Employee extends it. So, if I understand you correctly I think that makes this Case 3 but without having to use hypothetical C++! It's DRY and it has strong encapsulation.


答:
I'm going to address some things you should do before submitting your resignation letter. First, take any personal files off your computer as you may not have access once you resign. BE careful of taking company code though. Legally the code belongs to the company not you.  I would also quietly, the night before I hand in the resignation lette,r and after everyone is mostly gone so you don't get questions, pack up my personal things. Some companies will terminate you on the spot when you resign.

I also have always created a document that summarizes my projects, where things can be found, what has been done and not done yet, etc. I hand that to my boss when handing in the resignation letter. This tells them you are going to be professional about the resignation and may ease their fears a bit. I also usually suggest to them what tasks would be the best use of my time in the period before my last day. If you promise to deliver something before your last day, then be sure to really deliver it. Don't promise anything you don't think you can get done. All of this is especially true since you are the only programmer. Think what you would want in this situation if you were the replacement and that is the info you should prepare in advance of resigning.

If you so desire, many people have offered to be paid as a consultant on their own time to train a replacement or to do some urgent tasks until the replacement is hired. You are under no obligation to do this, but if you do want to do it, make sure you are paid the going rate for consultants (not your current pay rate) to do work. Make sure it is clear you will be doing this work outside your normal work hours at your new job and put a deadline on how long you are willing to do it (or they may never hire your replacement!). Be prepared to tell them what you want moneywise if they offer this as an option.

Title: How do programmers quit a job?

Body:
I'm thinking about leaving my current employer and wondering how one goes about that process in the programming world. We have a lot of projects on the go at the moment and I'm the only developer. We have 4-5 projects that are fairly big and need to be done in the next few months and even a few longer than that.

I'm leaving because I'm the only employee and that's doing me no good. I'm young and want to learn, so a team would be nice. It's also too much work and the company is managed horribly.

I have no contract to worry about so I could theoretically quit and just not come back without notice. Just wondering how this is normally handled.

Should I write a resignation letter

How much notice should I give

Should I give a reason for leaving

Should I go to my boss who is the main reason I'm leaving or go to his boss?

Overview of replies

From the feedback here, it looks as though it's best to give 2-4 weeks of notice, and present a written resignation. Don't go into detail explaining why you're leaving in most cases. Don't burn bridges. Be professional.