问:
What you should do if your junior did not adopt your suggestion?
I am leading a team of 3-4 junior developers. My job-- besides writing code-- is to provide supervision and guidance for the juniors.

But, I fully understand how much developers cherish autonomy in their work, and I don't want to destroy their intrinsic motivation by spoon-feeding them with my thoughts and my algorithms; I want them to explore the problem in their own ways, and think about it themselves and only come to me when they are really facing insurmountable issues.

When they do come to me, sometimes I would have to propose a completely different algorithm to solve the problem because their algorithm isn't robust enough ( remember, I am the senior and I have seen more than them). Of course I would explain this in a nice manner so as not to hurt their feelings, and I would gently outline how my solution is vastly superior than theirs, no condescending tone or condemning words.

But still, they are sometimes reluctant to accept my suggestion, partly because they have invested so much in their own algorithm, or partly because of the fear that using a new method would entail more learning time and make them appear to the management as if they are going nowhere. But deep in my heart I know very well that my algorithm is much better than theirs and they should just adopt it.

What should I do if they didn't adopt my suggestion? Should I just ask them to follow my way, or should I just let them have their heads banged on the wall many many more times and wait for them to come back to me? Doing the former makes me into a dictator, but doing the later would cost us precious development time and incur bug fixing cost. I am really in a dilemma here.

答:
Everyone has a different style.  If you find 10 different people and present them with a nontrivial problem they're going to give you 10 different approaches using 10 different "coding standards" styles.

The point being: pick the stuff that matters.  If something is presented to you by a junior which doesn't produce the correct solution, does it grossly inefficiently (+1 order of magnitude, not an instruction here or there), or creates a security hole, then explain your issue and why.  If it's a "I would have done this" comment, well that's great, you would have done "that" and she did "something else" but the problem is still solved sufficiently (see the above points).  Move on to the next feature or fix.

Part of learning to be a good leader is learning to recognize what really matters and what really doesn't.  Plus you remove yourself as a potential bottleneck to your group's performance if they have to vet everything through you.

EDIT: make sure your suggestions are genuine and not veiled requirements.  A suggestion is just that- a suggestion which one is free to follow or not.  If it's a requirement, state it as such.


问:
How to deal with the trail of bugs?
Every release, our trail of bugs keeps on increasing. These are valid bugs however, we also have to write new features to stay in the competition. Also, those features will be more used than the bugfixes; and provide better ROI.

How are other engineers and product owners handling this situation?

答: Keep a database with all the bugs and bug reports and deal with them when new features stop being as relevant, while trying to focus the bugs that happen most often and with the most impact on the program.</p>

ContentLicense: CC BY-SA 3.0

Title: How to deal with the trail of bugs?


答:
At a technical level, bugs, features, it's all the same, a change request. Do you ever decide not to add a feature because it's not worth it? It's the same with bugs. The only difference between bugs and features is commercial - 'customers' pay for features, the 'company' pays for bug fixes, or something like that.

However, as with feature requests, every bug report needs a change tracking ticket. The ticket must be as easy to close as it is to open. That is the only way you will capture the data you need to make decisions.

Change requests should be closed as quickly as possible. The reason for this is open requests take time to analyze, clog up the system and add little value. You need to quick way to decide that you won't do it, and once that decision is made, close the ticket.  You should aim to never discuss if an item should be open or closed more than once. One of the biggest problems I see it the reluctance of people to close a ticket "Will not fix", so they leave it open. If you ain't gong to fix it, be honest to everyone and just say "We ain't going to fix that, get over it."

Have both Priority and Severity in your ticket. The effect of the defect on the system is it's severity, sales and marketing set the priority.

Other tips:
Use a figure (say 20%) from the budget of feature requests/enhancements for fixing bugs. (i.e. if I do 10 days adding features, I do 2 days fixing bugs). Bugs are fixed in Priority order till the budget is spent. This gets around the commercial drive for features only development.

The cost of a defect is exponentially proportional to the time between insertion of the defect and fix (Or decision not to fix) of that defect. To prevent those niggle bugs costing disproportionate amounts of $ because you don't fix them, and refuse to close them, open tickets have their priority raised on a regular basis (Say 5 priority levels - once a month), and cannot be lowered. That way, you will be forced to deal with it within say 6-12 months.

Title: How to deal with the trail of bugs?

Body:
Every release, our trail of bugs keeps on increasing. These are valid bugs however, we also have to write new features to stay in the competition. Also, those features will be more used than the bugfixes; and provide better ROI.

How are other engineers and product owners handling this situation?


问:
What Are the Cons of Publishing Beta Software in Android Market?
I've spent some time developing a little Android app to scratch my own itch. I'm considering publishing the current version as a beta in Android Market. Pros for publishing it now would be the potential to get feedback. It would also be a way to gauge interest in the app which could effect whether to develop it further at all.  What would be the cons of publishing beta in Android Market?</p>

答:
Imagine that you want to buy an app from Market. You enter some keywords and get a list of apps, sorted by rating. Some of them are free. What you pick first? Second? Probably not something that has average 2.5 stars and a lot of negative feedback. You probably stop looking before you get to 3-star ratings.

But a lot of negative feedback ("Force closes all the time!", "Lacks X, Y and even Z, useless") is what you get if you publish beta-quality software. It's easy to get initial negative feedback and low rating, and very hard to change the situation afterwards, see paragraph 1.

The only case that I can see when a beta-quality app is worth publishing is when it's something totally unique and unlike anything else. You can get earlier feedback without fear that competing apps will attract your users. If your app is like that ("The only teleportation app on the market!"), you can try. But be sure to add a big fat BETA VERSION disclaimer early in the description, so that people won't mistake it for the final product.


问:
What is a realistic way to handle customer-specific software patches?
I'm trying to gather effective ways that others have solved the following problem.  At work we've been forced to release a software patch (to be installed on end-user systems) that we only want visible to a specific customer.  The custom code is in its own source-control branch.  The problem is we have two parallel code lines (and build scripts) to keep in sync, and every time we patch the original code we have to patch and test the customer-specific code.

I'm curious, how do other organizations handle this scenario?  We're open to business solutions and not just technical (source-control related) ones.  For example, we've talked about telling the customer they can't receive updates on that branch.

Our branching strategy is like this (based on the Visual Studio TFS Branching Guide, although we're using Subversion for it)

答:
We use subversion as well - and we come across exact such scenario.

Here are some key points to remember:

While it is necessary one must avoid specific branches for customers the need must be minimized as possible; always ask whether it is possible to generalize the solution that might just work for all.

Customer specific branches must originate from a new release. Suppose you have a version 1.2 and than you have derived from version 1.2.1 till 1.2.11 - the customer branches should be allowed all patches hence customer branch must remain compatible with respect to main version.

Customer specific branch needs to be created a fresh when you start out a new  non-compatible version. The unfortunate part is that somehow you might require to re-do the work. One solution can be to create all patches from customer branches needs to be extracted and whatever happens to be still compatible can be applied to new customer branch.

Always, in no circumstances, should you push customer specific changes back to release branch or trunk. However, ideally one should try to generalize the work in such a way that such customer specific work is kept reduced.

I have tried to put these idea together to show in :


问:
In pseudo code what does := mean?
The section entitled Algorithmic Implementation has the following code:

```<code>// Return RC low-pass filter output samples, given input samples,
 // time interval dt, and time constant RC
 function lowpass(real[0..n] x, real dt, real RC)
   var real[0..n] y
   var real α := dt / (RC + dt)
   y[0] := x[0]
   for i from 1 to n
       y[i] := α * x[i] + (1-α) * y[i-1]
   return y
</code>```

what does := mean?

答:
Just a quick and pedantic note.  Pseudocode is quite informal, so ":=" means only what you want it to mean.  As others have said, specific languages such as Pascal use ":=" for assignment to avoid confusion with "=" for equality, whereas other languages use the combination of "=" and "==" for the same purpose.

As far as actual Pseudocode is concerned, you can use "=", "==", "equals", "is assigned to", ":=", "has", "receives", or whatever floats your boat, just so long as you are consistent, and the usage and context is within your pseudocode is clear.

Title: In pseudo code what does := mean?


问:
Source control workflow for managing a software platform
I'm in charge of a software platform, written in C, that is used to provide a variety of projects to clients.  I am trying to improve the workflow for people using this platform, and looking at whether source code control (Mercurial being the most likely candidate) can help.

The platform is only used internally for ~10 projects / year.  It's got a wide range of functionality, and lots of bits that are unused on most projects.  As a result, there are plenty of bugs hidden away.

I'm wondering if anyone has similar experience, either managing or using a constantly updated platform in this way.

The current situation

Platform development is done with a mercurial repository, but the releases of the platform are not done through mercurial.  For a release, the platform files are put into a tarball on a central server.  For any system connected to the core, the start of the build process copies the updated tarball and unpacks it into the application source code.  Application programmers can't edit the core files (various commands are aliased through shell scripts, and they get an error if they try).

What I'm after

It seems like it should be possible to somehow use Mercurial to manage this.  We could easily maintain a release branch of the platform, and have projects clone the release branch as their starting points.

But I'm not sure where it would go after that.  On a project, the functionality is completely up to the client.  If the core files are unlocked, people will immediately start editing them, even when there is a better way (this is what happened before the lockdown).  This is going to mean merging in new core changes becomes difficult, and I suspect will result in a lot of teams not bothering.

The draconian solution of locking the core files, and forcing automatic updates to all projects was really quite successful: we get more complaints and problems from the projects that are disconnected, than the ones receiving the forced updates.  However, as soon as projects go into testing, they have to be disconnected.  After that, short of manual merging, they get no more platform updates.

答:
I've dealt with similar issues with different flavors of commit-approval. Additionally using ACLs (and in some cases where security required) CheckGpgSig.

I've somewhat cheated in that for each project I setup, I force folks to use a setup.(csh|sh) script that when necessary will either (1) warn or (2) prompt them to update their tree.

OwnerDisplayName: synthesizerpatel


问:
Do you write bad code when under pressure?
When you are under pressure, the deadline is approaching, and a manager is breathing down your neck do you find yourself starting to write bad code? Do TDD and best practices slip by the wayside in order to get things done? What do you do in situations like that? What were your experiences?</p>

答:
I don't believe I personally write significantly worse code, but I do deliver a worse product.

When faced with an arbitrary and impossible deadline, we skimp on the development process.  We do more superficial code reviews (or skip them altogether).  We test less, bypass detailed unit testing for spot-check type integration tests, then try to count the integration test as a formal qualification.  We tend to overlook anomalies during testing if they are not directly tied to pass-fail criteria.  We skip documentation updates, don't double check release notes, forget to scrub the list of deliverables for files that are no longer needed.

The source code you write during a crunch may be of high quality, but it will almost certainly be shipped as part of a shoddy product.

ContentLicense: CC BY-SA 2.5


答:
I'm not a Mercurial or Subrepositories guru in any form, but I think I can use subrepositories (Aragost Kick-start and Wiki) in your work.

I.e:

Have platform in (separate?) repo

Link it to all project as subrepository (instead of direct copy)

This way you get

Easy publishing of releases to projects (update subrepository to needed cset, commit into main repo)

Platform code is effectively locked (if projects devs haven't rights to push into remote platform repo, they can't change and commit) - TBT!!!

Title: Source control workflow for managing a software platform

Body:
I'm in charge of a software platform, written in C, that is used to provide a variety of projects to clients.  I am trying to improve the workflow for people using this platform, and looking at whether source code control (Mercurial being the most likely candidate) can help.

The platform is only used internally for ~10 projects / year.  It's got a wide range of functionality, and lots of bits that are unused on most projects.  As a result, there are plenty of bugs hidden away.

I'm wondering if anyone has similar experience, either managing or using a constantly updated platform in this way.

The current situation

Platform development is done with a mercurial repository, but the releases of the platform are not done through mercurial.  For a release, the platform files are put into a tarball on a central server.  For any system connected to the core, the start of the build process copies the updated tarball and unpacks it into the application source code.  Application programmers can't edit the core files (various commands are aliased through shell scripts, and they get an error if they try).

What I'm after

It seems like it should be possible to somehow use Mercurial to manage this.  We could easily maintain a release branch of the platform, and have projects clone the release branch as their starting points.

But I'm not sure where it would go after that.  On a project, the functionality is completely up to the client.  If the core files are unlocked, people will immediately start editing them, even when there is a better way (this is what happened before the lockdown).  This is going to mean merging in new core changes becomes difficult, and I suspect will result in a lot of teams not bothering.

The draconian solution of locking the core files, and forcing automatic updates to all projects was really quite successful: we get more complaints and problems from the projects that are disconnected, than the ones receiving the forced updates.  However, as soon as projects go into testing, they have to be disconnected.  After that, short of manual merging, they get no more platform updates.

OwnerDisplayName: Lazy Badger


问:
What would you say to a bunch of software engineering students on their first day at college?
Next Friday I'm giving a short (30 min.) talk to a bunch of software engineering students who will be attending the same university I did.

Some context:

The place is Montevideo, Uruguay

The university is Universidad de la República (public, free university)

The Software Engineering programme takes 5 years (if you're very good and don't start working early). Around 800 new students per year, around 80 graduates per year. Conditions are harsh, particularly the first two years.

Most of them probably have no idea what software engineering or programming is.

My goal would be to somehow give them an idea of the field and hopefully motivate them to endure the hardships ahead to eventually become successful developers.

So the question is: what would you tell these people?

答:
All students must be given a positive but a realistic perspective of the IT industry so that it fosters interest in the field but at the same time keeps them aware of the reality.

So in my humble opinion, the following areas could be highlighted.

Pros

You get to do something new almost every day.

A good feeling at the end of the day when you have eradicated a couple of bug or completed a implementation.

Job satisfaction would be the biggest motivator as one third of our life is going to be spent on it.

Only certifications would not help. Good understanding of core concepts with certification would provide a synergistic effect.

Last but not the least, good pay on the long run.

Cons

Initial years after completing graduation may not be financially rewarding depending on the industry at that particular period of time until you gain enough experience in your specialized platform.

Recession can be an important point that can be highlighted but at moderate levels.

When taking up important roles in one’s organization, some personal sacrifices can be necessary although this is does not happen all the time.

Things to know

Working as a contractor is not a bad thing and your quality of work will eventually get you to permanent roles.

Nature of work is more important than the designation.


答:
I'd tell them:

You have three options, two of them are promising.

study hard, learn as much technologies as you can - then after you finish your studies, everything you have learned will be obsolete and you'll find yourself a nice job at Tesco. Actually what we'll teach you was obsolete 10 years ago :)

drink, party, make 5-10 part time projects and learn by yourself - maybe then studying will be anything more than a waste of time. If you think you'd rather skip vodka with friends today or scoring 3 chicks a week is too much - think twice, in a very short 5 years you'll be having job and a wife, or maybe even both.

leave now and take interior painting course. It's rewarding, easy, and you'll have cool friends that don't play World Of Warcraft.

Initial years after completing graduation may not be financially rewarding

Yes, that's 100% correct. If you only follow the lectures all your commercialy desired skills will be clicking next in Wordpress installation script or configuring email. In my opinion you could cut all the cr*p (80-90%), keep mathematics, algorithmics, maybe relational model or compiler theory (one of two up to your choice). You'd save a couple of years + you'd be as qualified as anyone that took full course because you can learn everything else yourself.

Ah i forgot very important By The Way point:
"Look around and remember - never, ever hang with them! It will limit your chances of becoming level 50 wizards but it's also more likely that at the end of the year more than 20% of you will no longer be a virgin"

Title: What would you say to a bunch of software engineering students on their first day at college?

Body:
Next Friday I'm giving a short (30 min.) talk to a bunch of software engineering students who will be attending the same university I did.

Some context:

The place is Montevideo, Uruguay

The university is Universidad de la República (public, free university)

The Software Engineering programme takes 5 years (if you're very good and don't start working early). Around 800 new students per year, around 80 graduates per year. Conditions are harsh, particularly the first two years.

Most of them probably have no idea what software engineering or programming is.

My goal would be to somehow give them an idea of the field and hopefully motivate them to endure the hardships ahead to eventually become successful developers.

So the question is: what would you tell these people?


问:
Working as a sole developer: getting code looked over
I have no choice but to work on my own, and can't find an adequate solution for getting my work looked over, sanity checked, having someone to brainstorm ideas with, discussing best practices and so on.

I thought I'd get an answer via Jeff Atwood's article: In Programming, One Is The Loneliest Number, the best I could find on the subject, but it turned out to just reiterate my question.

I know Stack Exchange sites such as this, and Code Review are an obvious potential answer, but as many would appreciate, it's FAR from ideal:

While I can't list all the pitfalls, often, formulating a question and boxing it up into a self-contained problem often takes so much work that by the time you've prepared it sufficiently, you've answered your own question in more time than it would have taken otherwise. Also, hiding away details to ask a well defined question eliminates the possibility of someone spotting problems you hadn't thought of. Also, while I can't quite put my finger on it, the responsiveness of free conversation can't be matched by the any form of textual internet discussion that I can think of. Last but not least, I don't want to post my whole project for the world to look at for the rest of eternity, for obvious reasons.

Are there any answers other than paying a consultant to look over my code?

答: A constructive feedback from my experience is that during the initial years of your development it would be very important although not mandatory that an experienced developer reviews your code to lay the foundation. Once your are experienced, you can follow the approach suggested by @ davidk01 i.e Reviewing your own code periodically to improve code quality.

ContentLicense: CC BY-SA 4.0


问:
Should I pass an object into a constructor, or instantiate in class?
Consider these two examples:

Passing an object to a constructor

```<code>class ExampleA
{
  private $config;
  public function __construct($config)
  {
     $this->config = $config;
  }
}
$config = new Config;
$exampleA = new ExampleA($config);
</code>```

Instantiating a class

```<code>class ExampleB
{
  private $config;
  public function __construct()
  {
     $this->config = new Config;
  }
}
$exampleA = new ExampleA();
</code>```

Which is the correct way to handle adding an object as a property? When should I use one over the other? Does unit testing affect what I should use?

答:
I've had this exact same discussion with our architecture team recently and there are some subtle reasons to do it one way or the other. It mostly comes down to Dependency Injection (as others have noted) and whether or not you truly have control over the creation of the object that you new in the constructor.

In your example, what if your Config class:

a) has non-trivial allocation, such as coming from a pool or factory method.

b) could fail to be allocated. Passing it into the constructor neatly avoids this issue.

c) is actually a subclass of Config.

Passing the object into the constructor gives the most flexibility.


答:
I am not a Mercurial user, too, but it seems that you are after something like what subversion users (like me) call "externals" - the possibility to pull a shared library (your "platform/core") into different projects, which may reside in different repos. Here is a link to a mercurial extension providing the same functionality

http://mercurial.selenic.com/wiki/HgExternals

Googling for "mercurial externals" will provide you with some more links.

Using the "external" feature allows you to

define exactly which revision of the lib you want to use in your project; even when new revisions of the lib are checked in, you are not forced to use them immediately

prevent changes to the lib directly to be commited back to the repo from the using project

There are, of course, some further things you can do, independently from your specific version control system.

If you don't want the users of your lib to edit the source code, why not provide a "binary only" version of it? That is a very effective way of preventing them to edit "the core". If that is not an option, perhaps you could add a "DO NOT EDIT" disclaimer to every source file. Actually, everyone can ignore that comment, but then it will be easier for you to  refuse assistance.

On the other hand, if you actually want (some) users of your lib to edit the source code of the lib, you should not give them a tarball, but create a special branch in your repository for them. This way it gets a lot easier to merge the changes back later.

One more thing: do you have automated tests (unit & integration tests) for your platform? That may be very (!) helpful in your situation. Before you merge back something to the trunk of your platform, you can run those tests to make sure the users of your platform won't get some bad surprises when they update to the latest release.


问:
Defining Rank names for employees
I want to create a list of ranks for the employees in my company. We are an open source integrator that works usually with existing solutions and also building custom solutions.

We don't want to name our employees as normal senior consultant, trainee and we would like give them ranks as forums do to the users.

Does anyone have any suggestion for this?

答: I think you should go with something feudal sounding, such as "Baron Bob of Iterations", or "Prince Larry of Encapsulation".  That would look awesome on business cards.

Title: Defining Rank names for employees


问:
Randomly generate directed graph on a grid
I am trying to randomly generate a directed graph for the purpose of making a puzzle game similar to the ice sliding puzzles from Pokemon.

This is essentially what I want to be able to randomly generate: http://bulbanews.bulbagarden.net/wiki/Crunching_the_numbers:_Graph_theory.

I need to be able to limit the size of the graph in an x and y dimension. In the example given in the link, it would be restricted to an 8x4 grid.

The problem I am running into is not randomly generating the graph, but randomly generating a graph, which I can properly map out in a 2d space, since I need something (like a rock) on the opposite side of a node, to make it visually make sense when you stop sliding. The problem with this is that sometimes the rock ends up in the path between two other nodes or possibly on another node itself, which causes the entire graph to become broken.

After discussing the problem with a few people I know, we came to a couple of conclusions that may lead to a solution.

Including the obstacles in the grid as part of the graph when constructing it.

Start out with a fully filled grid and just draw a random path and delete out blocks that will make that path work.

The problem then becomes figuring out which ones to delete to avoid introducing an additional, shorter path. We were also thinking a dynamic programming algorithm may be beneficial, though none of us are too skilled with creating dynamic programming algorithms from nothing. Any ideas or references about what this problem is officially called (if it's an official graph problem) would be most helpful.

Here are some examples of what I have accomplished so far by just randomly placing blocks and generating the navigation graph from the chosen start/finish. The idea (as described in the previous link) is you start at the green S and want to get to the green F. You do this by moving up/down/left/right and you continue moving in the direction chosen until you hit a wall.
In these pictures, grey is a wall, white is the floor, and the purple line is the minimum length from start to finish, and the black lines and grey dots represented possible paths.

Here are some bad examples of randomly generated graphs:

Here are some good examples of randomly generated (or hand tweaked) graphs:

I've also seemed to notice the more challenging ones when actually playing this as a puzzle are ones which have lots of high degree nodes along the minimum path.

答:
Maybe reverse engineering could help you if you are up for that.

If there is one and only one solution to each problem, you can probably generate a graph based on the unique answer. This won't require you to do dynamic programming or even skip brute force and opt for a methodical generation.

You can go about it by:

Keeping a MxN graph ready

creating one/multiple solution(s)

making a question around it if it is a singular solution problem

if there are multiple solutions to the problem, then you can repeat the
above procedure in a way so that the current iteration does not
inhibit another solution.

Though you will need to device a way according to the problem complexity and problem size that will generate this question for you. Don't just go for brute-force. Try some randomized algorithm instead. This could help you.


问:
typedefs and #defines
We all have definitely used typedefs and #defines one time or the other. Today while working with them, I started pondering on a thing.

Consider the below 2 situations to use int data type with another name:

```<code>typedef int MYINTEGER
</code>```

and

```<code>#define MYINTEGER int
</code>```

Like above situation, we can, in many situations, very well accomplish a thing using #define, and also do the same using typedef, although the ways in which we do the same may be quite different. #define can also perform MACRO actions which a typedef cannot.

Although the basic reason for using them is the different, how different is their working? When should one be preferred over the other when both can be used? Also, is one guaranteed to be faster than the other in which situations? (e.g. #define is preprocessor directive, so everything is done way earlier than at compiling or runtime).

答:
In addition to all valid remarks about scope and text replacement already given, #define is also not fully compatible with typedef! Namely when it comes to the case of function pointers.

```<code>typedef void(*fptr_t)(void);
</code>```

This declares a type fptr_t which is a pointer to a function of the type void func(void).

You cannot declare this type with a macro. #define fptr_t void(*)(void) will obviously not work. You would have to write something obscure like #define fptr_t(name) void(*name)(void), which really doesn't make any sense in the C language, where we have no constructors.

Array pointers cannot be declared with #define either: typedef int(*arr_ptr)[10];

And while C has no language support for type safety worth mentioning, another case where typedef and #define is not compatible is when you do suspicious type conversions. The compiler and/or astatic analyser tool might be able to give warnings for such conversions if you use typedef.

Title: typedefs and #defines

Body:
In addition to all valid remarks about scope and text replacement already given, #define is also not fully compatible with typedef! Namely when it comes to the case of function pointers.

typedef void(*fptr_t)(void);

This declares a type fptr_t which is a pointer to a function of the type void func(void).

You cannot declare this type with a macro. #define fptr_t void(*)(void) will obviously not work. You would have to write something obscure like #define fptr_t(name) void(*name)(void), which really doesn't make any sense in the C language, where we have no constructors.

Array pointers cannot be declared with #define either: typedef int(*arr_ptr)[10];

And while C has no language support for type safety worth mentioning, another case where typedef and #define is not compatible is when you do suspicious type conversions. The compiler and/or astatic analyser tool might be able to give warnings for such conversions if you use typedef.


问:
Is it good practice to keep the main function separate in its own file?
Is it good practice to have a main.c file that just has the main function in it and no other functions so that all other functions can be interfaced?

If there is no definitive rule, when is it good to do so and not to do so?

答:
There are two rules of thumb:

The reader shouldn't need to wonder where you have hidden main().

main() should not contain irrelevant clutter.

To implement a coding standard stating that main() should always be located in a file called main.c is both good and common practice. This file, as well as main() itself, should not contain unnecessary clutter.

Ideally main() and main.c should only contain the following

Includes of program-wide header files.

Argument parsing code of argv, argc.

On hostless systems: critical register setups, stack pointer setup etc. But only if main() is the first point of entry for the program.

Calls to start up the OS, or a loop calling the program's state machine, or in hosted desktop systems, creation and initialization of windows related to the main GUI thread.

Internal (static) functions that are called from main(), handling any of the above.

On a hosted system: return 0.


答:
How about another approach? Start with an empty maze and add blocks like this:

Randomly starting block and ending block.

Make 1-3 "sliding" steps in random (but not returning) direction and with random length (*). Place a block after each step (to stop the slide).

Find a shortest path to the exit. If there are too few segments (low level difficulty), take a random segment of the path and split it with a block. Otherwise, place a block as in step 1 and exit.

Repeat 1 with caution (*): when you choose the length of a sliding step, make it so that the block you put will not close the previous path.

Finishing touch: find the shortest route with the algorithm you provided. Take note of all cells that are used and start filling up the rest randomly, every time making sure the shortest route does not get shorter.

There is a caveat in step two, when you can't put the last block so that it does not cross the used paths, but I see two solutions to this: move the ending block earlier or undo a few steps and try once again.

And another thought for the random length of the sliding steps - you might want to choose it so that a block placed earlier is reused, as long as the paths don't overlap.

Title: Randomly generate directed graph on a grid

Body:
I am trying to randomly generate a directed graph for the purpose of making a puzzle game similar to the ice sliding puzzles from Pokemon.

This is essentially what I want to be able to randomly generate: http://bulbanews.bulbagarden.net/wiki/Crunching_the_numbers:_Graph_theory.

I need to be able to limit the size of the graph in an x and y dimension. In the example given in the link, it would be restricted to an 8x4 grid.

The problem I am running into is not randomly generating the graph, but randomly generating a graph, which I can properly map out in a 2d space, since I need something (like a rock) on the opposite side of a node, to make it visually make sense when you stop sliding. The problem with this is that sometimes the rock ends up in the path between two other nodes or possibly on another node itself, which causes the entire graph to become broken.

After discussing the problem with a few people I know, we came to a couple of conclusions that may lead to a solution.

Including the obstacles in the grid as part of the graph when constructing it.

Start out with a fully filled grid and just draw a random path and delete out blocks that will make that path work.

The problem then becomes figuring out which ones to delete to avoid introducing an additional, shorter path. We were also thinking a dynamic programming algorithm may be beneficial, though none of us are too skilled with creating dynamic programming algorithms from nothing. Any ideas or references about what this problem is officially called (if it's an official graph problem) would be most helpful.

Here are some examples of what I have accomplished so far by just randomly placing blocks and generating the navigation graph from the chosen start/finish. The idea (as described in the previous link) is you start at the green S and want to get to the green F. You do this by moving up/down/left/right and you continue moving in the direction chosen until you hit a wall.
In these pictures, grey is a wall, white is the floor, and the purple line is the minimum length from start to finish, and the black lines and grey dots represented possible paths.

Here are some bad examples of randomly generated graphs:

Here are some good examples of randomly generated (or hand tweaked) graphs:

I've also seemed to notice the more challenging ones when actually playing this as a puzzle are ones which have lots of high degree nodes along the minimum path.


问:
What is the best way to structure an Android application?
I am starting a new Android application. What is the best structure to use?

I am planning to make it a multi-package design as follows:

Main package, including the Activity

Service and data layer

Entity package, including entity class.

Any advice ?

答:
Yes it make easy to develop if you categories thing on base their work.You are in right direction.In android,if develop an application then i will use following structure, something will similar like you

Main package With all Screen Activity

Adapter classes if i am using ListView, GridView that need BaseAdapter etc

Parsing helper if used

Database

Entity Classes and Classes to store static variable

Service and Receiver


答:
You should have a triage and priorities meeting on a regular basis.

At my previous job we used to have a weekly meeting that consisted of product owners and the dev lead (me).  We would

review current priorites

prioritize new bugs

prioritize new features

The goal was to make sure there was a balance in what we worked on.  I would explain the cost of ignoring certain problems and how much they would cost down the line.  I would also explain the development cost for each change and offer up alternatives when appropriate.  In return I would get a sense of the importance of certain features to the business.  This provided both myself and the product managers with

a good idea of how resources were being spent

consensus on how to utilize the resources we have

a deeper understanding of the business as a whole

Once a rapport had been established, the meetings went by quickly with few disagreements.

Title: How to deal with the trail of bugs?


问:
What is the development workflow for an Android SIP application?
I want to build an Android SIP application, and I'm looking at csipsimple's source for inspiration. I am using:

Linux,

Eclipse 3.7,

Android sdk & ndk,

swig.

What are the development phases or steps for such an application? And what would be an appropriate licence?

I am not asking for code, but for an overview of the development workflow for such an application.

答:
Read these link.android developer has a best explanation for SIP

Sip Summary

SiP details with demo


答:
If the object has responsibility for managing the lifetime of the dependency, then it's OK to create the object in the constructor (and dispose it in the destructor).*

If the object is not responsible for managing the lifetime of the dependency, it should be passed into the constructor and managed from outside (eg by an IoC container).

In this case I don't think your ClassA should take responsibility for creating $config, unless it is also responsible for disposing it, or if the config is unique for each instance of ClassA.

*To aid in testability, the constructor could take a reference to a factory class/method to construct the dependency in its constructor, increasing cohesion and testability.

```<code>//Object which manages the lifetime of its dependency (C#):
public class ClassA : IDisposable
{
    public Config Config { get; private set; }

    public ClassA()
    {
        this.Config = new Config(); // Tightly coupled to Config class...
    }

    public void Dispose()
    {
        this.Config.Dispose();
    }
}

// Object which does not manage its dependency:
public class ClassA
{
    public Config Config { get; set; }

    public ClassA(Config config) // dependency may be injected...
    {
        this.Config = config;
    }
}

// Object which manages its dependency in a testable way:
public class ClassA : IDisposable
{
    public Config Config { get; private set; }

    public ClassA(IConfigFactory configFactory) // dependency may be mocked...
    {
        this.Config = configFactory.BuildConfig();
    }

    public void Dispose()
    {
        this.Config.Dispose();
    }
}
</code>```

Title: Should I pass an object into a constructor, or instantiate in class?

Body:
Consider these two examples:

Passing an object to a constructor

```<code>class ExampleA
{
  private $config;
  public function __construct($config)
  {
     $this->config = $config;
  }
}
$config = new Config;
$exampleA = new ExampleA($config);
</code>```

Instantiating a class

```<code>class ExampleB
{
  private $config;
  public function __construct()
  {
     $this->config = new Config;
  }
}
$exampleA = new ExampleA();
</code>```

Which is the correct way to handle adding an object as a property? When should I use one over the other? Does unit testing affect what I should use?

Body:
If the object has responsibility for managing the lifetime of the dependency, then it's OK to create the object in the constructor (and dispose it in the destructor).*

If the object is not responsible for managing the lifetime of the dependency, it should be passed into the constructor and managed from outside (eg by an IoC container).

In this case I don't think your ClassA should take responsibility for creating $config, unless it is also responsible for disposing it, or if the config is unique for each instance of ClassA.

*To aid in testability, the constructor could take a reference to a factory class/method to construct the dependency in its constructor, increasing cohesion and testability.

//Object which manages the lifetime of its dependency (C#):
public class ClassA : IDisposable
{
    public Config Config { get; private set; }

    public ClassA()
    {
        this.Config = new Config(); // Tightly coupled to Config class...
    }

    public void Dispose()
    {
        this.Config.Dispose();
    }
}

// Object which does not manage its dependency:
public class ClassA
{
    public Config Config { get; set; }

    public ClassA(Config config) // dependency may be injected...
    {
        this.Config = config;
    }
}

// Object which manages its dependency in a testable way:
public class ClassA : IDisposable
{
    public Config Config { get; private set; }

    public ClassA(IConfigFactory configFactory) // dependency may be mocked...
    {
        this.Config = configFactory.BuildConfig();
    }

    public void Dispose()
    {
        this.Config.Dispose();
    }
}


问:
Is using PhoneGap for your first ever mobile app a good idea?
I am a beginner programmer. I've gotten an AS degree in CS which exposed me to the basics of c++, data structures, and algorithms and have light experience with html/css/javascript from just messing around building my own basic websites. I am no where near a proficient professional programmer as of yet.

My question is, would using PhoneGap to attempt to develop my first "app" for android/ios/whatever be a good idea or should I start out making native apps first?

With all the hype over html5/javascript at the moment, PhoneGap seems too good to be true for a beginner like me.

Thoughts? pros/cons?

答:
It really depends on what you want to achieve. If it's just a hobby-project, you can choose what you like the most. If you want to build an app for a wide audience, Google on terms like 'mobile web vs. native'!

If you want to learn, you have the following options:

If you want to learn HTML5, Javascript and CSS, you can consider PhoneGap, but also develop a mobile website using Sencha Touch (more focus on Javascript), JqueryMobile (more focus on HTML combined with Javascript) or other frameworks. You can also look into Titanium, which builds real native apps, from one codebase (which is in HTML, Javascript and CSS).

If you are not interested in web development, you can choose to build a native app in one of the available platforms.


问:
Move from Curl to Aria2?
We have a crawling engine that uses curl and caters to about 400,000 ppl  / month. Although curl supports concurrent downloads, it does not support bandwidth limiting ( only in php 5.4.0 ) which is why my boss wants me to move to aria2. He also says Aria2 is faster ( which seems to be true to me as well )

Aria2 would require a large amounts of changes to the system. Right now we have crawling system which does not crawl in a conconrrent manner.

Would moving to aria2 be a good decision?

答: After running quiet a few test we found aria and curl/php/apache are running at almost the same speed. We decided to stick to curl as it has a php library libcurl. We are not sure about bandwidth limiting but are working on it. Changing our current code to crawl multiple pages simultaneously was not such a big hassle as of curl. Although there have been some things we need to work around e.g. https://stackoverflow.com/questions/8878546/curl-multi-crawling-issues</p>

Title: Move from Curl to Aria2?


问:
Efficient graph clustering algorithm
I'm looking for an efficient algorithm to find clusters on a large graph (It has approximately 5000 vertices and 10000 edges).

So far I am using the Girvan–Newman algorithm implemented in the JUNG java library but it is quite slow when I try to remove a lot of edges.

Can you suggest me a better alternative for large graphs?

答: For your problem here, I think you should think of a way to map vertices-edges to a set of coordinates for each vertex. I am not sure if there is a better way to do this. But, I think you could start off by representing each vertex as a dimension and then, the edge value to a particular vertex would become the value you need to work with for that particular dimension. After that you could do a simple Euclid distance and work with that.</p>

Title: Efficient graph clustering algorithm


问:
Is the MIT license suitable for an open source library that is only used in unit testing scenarios?
Some time ago I developed a small project for use in unit testing scenario's and published it on Codeplex. Back then I choose the GPL license but I didn't really understand it. Today I changed it to MIT, because it's a much simpler license that I can understand.

I like to be recognized as the copyright holder, but I want everybody to be able to use the library without worrying about license issues. I think MIT covers both, but not 100% sure. 'Virality' is not an issue for this project.

Would this license (MIT) in any way prevent a person to use my library for the unit testing of a closed-source commercial or private project? In this regard, is my recent change to MIT a change for the better?

答:
The answer to your question is right there in your license:

Permission is hereby granted, ... to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

...

So no, you have pretty much assigned the right for anyone to do as they please with your code, as long as they attribute you.

A great resource for determining which license is the right license for you is the very comprehensive, interactive license differentiator, from Oxford Universities OSS Watch.


问:
How to recognize a bad client before you start to work for him?
I'm sure that many of you have encountered a bad client. I'm also sure you took some measures to prevent such encounters in the future. What is the most influential characteristic of a client that warns you to walk away?</p>

答:
My list would include:

Doesn't have time to create real
requirements. Trust me if they won't
create the requirements anything you
deliver will not be as expected and
you will be expected to "fix" it for
free.

They balk at progress payments for a
large project or balk at having a
formal contract.

They keep refering to how Google does
things. If they aren't going to pay
for Google's servers and
infrastructure, you will never make
them happy.

Project details as specified and
timeframe for expected delivery bear
no relationship to each other. The
guy who wants a complex system in a
week is to be avoided at all costs.

Everything they say makes you feel
like they want this done "on the
cheap". Software development ain't
cheap and a client who thinks it
should be will never be happy.

The person is unpleasant to deal with
and/or treats his staff poorly in
your presence. If he treats them
badly, he will treat you badly.


问:
What is a proper term to describe a server running source control, bug tracking and CI tools?
I'm looking for a 'term' that describes holistically the set of various software development tools/services that most developers use on a day to day basis. While each tool by itself has a specific purpose and can be described, is there a plural term when they are grouped together and running as a holistic service.

If a person said a server was a production test box, I'd expect it to be running the application that company are writing. If a person said box A is the office ware server, I'd know to expect email/communication related services.

答:
SCM server (SCM stands for Software Configuration Management)

ALM server (ALM stands for Application Lifecycle Management). Actually, this one would be more appropriate for your stack of tools.


问:
Difference between DevOps and Software Configuration Management
What is the difference between Development Operations and Software Configuration Management?

For me it seems to be the same as long as both DevOps and Software Configuration Management are focused on:

Establishing development infrastructure - being in charge of version control, build management, deployment management, dependencies management, continuous integration and delivery, etc.

Using best practices for organizing developers environment.

Quality Assurance of development processes - gathering metrics of development effectiveness, working on eliminating bottlenecks of development process (running unit-tests, evaluating unit-tests coverage, running inspections, etc)

Infrastructure management - target platforms and its specifics.

Release management - making sure release has been delivered to customer/client in time.

Maybe I'm missing something? This link shows that usage of term 'Software Configuration Management' prevails. But still, what word combination would you rather use to describe listed range of activities: Development Operations or Software Configuration Management?

答:
You'd be hard-pushed to find a solid definition for DevOps. It's more of an idea than a job to be done. And it's too new an idea for everyone to agree on exactly what it means. Nonetheless, here's my take.

DevOps is really just a new term for configuration management, but it was chosen to show that the role is not a one-person role, it's a collaboration between the development team and the operations team.

Historically, configuration management would be done solely by the development team and then handed off to operations who would view it all with deep suspicion. Which is fair enough, to be honest. They're responsible for it. They're the first to get called at 4am when it goes wrong. They really should have some involvement in its development.


答:
First, it depends on what application you are doing.

you should do a textual or schematic description on how a user will work with application. Fix down every possible scenario. Put down examples that will be used later for tests.

Decide what belongs to the functionality and what - to the changeable configuration. Extract functionalities and data entities from scenarios.

From scenarios make decision what your app will be.  Is it service, activity, widget , even a content provider or a complex system, including some different components. Test your decision against scenarios.

In the case of the complex system, distribute functionalities and data entities among application components. Make a list of components and what they are (activities or smth else).

Make the list of UI components with description what they do (not HOW yet)
These will be widgets and activities or fragments or layouts later.

Make draft layouts for UI components. Make simple passes from one to another.
Look at the UI. Return to scenarios and play all of them them with your draft UI. All UI components and classes put into one hierarchy of packages or package.

Make a list of data entities. Decide what will be in what. Plan them as collections or tables in DB or different DBs. Make them as classes, put them into another hierarchy of packages or another package. Here also put DB helpers - classes that talk with DB by SQL.

Make a testing classes(JUNITs or better TestNG) for filling UI and data entities with test data and launching them.

Adapters needn't be public, for they are used in their parent GroupView only. So, no files for adapters usually.

Do not put all globals into special static classes - it is a bad practice. You are mixing so the code and the configuration. Use this very interesting solution. For now, it is the best I know for Android.

Configuration data should be put into resources. If some of them are complex, use XML sources and parser(s). Make readers of resource data into global variables. Not all of them will be static! They could belong to the main Activity instance, for example.

Do not use unconfigurable constants in the code! May be, your name only :-).
Every constant becomes non-constant sometimes.

On the other side, if some of you code is not normal java, but scripts - a mix of data and language, then you can and must mix data and code.

Always do so:write something - connect something to a bulk - add test(s) for this new thing -  test this new one - test the bulk - repeat. Small steps only!

Edit. You can also use the test driven development - write tests before appropriate code. This way, running tests before the code is ready, you have double testing - thus you check if the tests really react to incorrect code.

Title: What is the best way to structure an Android application?

Body:
I am starting a new Android application. What is the best structure to use?

I am planning to make it a multi-package design as follows:

Main package, including the Activity

Service and data layer

Entity package, including entity class.

Any advice ?


问:
Jump into Android or learn Java basics first?
I am quite proficient in C and know some C++, but never touched Java. Recently I got an idea for an app which I think has potential, and I want to develop it.

I am planning to go Android first, cause it doesn't require a mac/iPhone.

So my question is: can I go straight to learning Android development, picking up the Java syntax as I go along and need it (after all I don't think it's much different from C/C++), or should I take a couple of weeks to learn the basics of Java first and then start with Android development?

答:
I would have a play around with Java for a few days just to see if you like it, then just jump right in no better way to learn than get your hands dirty.

Your programming background will help you. There's a lot of good tutorial sites that can ease you into android and java at the same time just try googling for them. Most of all ENJOY!


答:
The terms describe very similar concepts and responsibilities, and in general they are somewhat synonymous. The term "DevOps" is a relatively new one, popularized by the Devopsdays Ghent 2009 conference and subsequent Devopsdays events. It's best described in this diagram:

On the other hand, Software Configuration Management is a far more established term within the profession, and derives from the non software specific term Configuration Management. Software Configuration Management is often referenced in a software engineering context, a simple definition is given by Roger Pressman in "Software Engineering: A Practitioner's Approach":

is a set of activities designed to control change by identifying the work products that are likely to change, establishing relationships among them, defining mechanisms for managing different versions of these work products, controlling the changes imposed, and auditing and reporting on the changes made.

Although all the terms you reference are vague, DevOps seems to be just a less formal way of describing more or less the same set of principles as Configuration Management, or Software Configuration Management if seen from a software developer's perspective, especially prioritizing tightly coupled teams:

DevOps is a response to the growing awareness that there is a disconnect between what is traditionally considered development activity and what is traditionally considered operations activity. This disconnect often manifests itself as conflict and inefficiency.

In the same article, the similarities with SCM are noted:

Adding to the Wall of Confusion is the all too common mismatch in development and operations tooling. Take a look at the popular tools that developers request and use on a daily basis. Then take a look at the popular tools that systems administrators request and use on a daily basis. With a few notable exceptions, like bug trackers and maybe SCM, it's doubtful you'll see much interest in using each others tools or significant integration between them. Even if there is some overlap in types of tools, often the implementations will be different in each group.

As for the usage of the terms, your comparison doesn't really makes sense:

SCM is a subset of CM, not a competitive term,

DevOps is a fairly new term, no point in comparing against established terms,

DevOps derives from Developer Operations (obviously) but is rarely expanded as such.

Title: Difference between DevOps and Software Configuration Management

Body:
What is the difference between Development Operations and Software Configuration Management?

For me it seems to be the same as long as both DevOps and Software Configuration Management are focused on:

Establishing development infrastructure - being in charge of version control, build management, deployment management, dependencies management, continuous integration and delivery, etc.

Using best practices for organizing developers environment.

Quality Assurance of development processes - gathering metrics of development effectiveness, working on eliminating bottlenecks of development process (running unit-tests, evaluating unit-tests coverage, running inspections, etc)

Infrastructure management - target platforms and its specifics.

Release management - making sure release has been delivered to customer/client in time.

Maybe I'm missing something? This link shows that usage of term 'Software Configuration Management' prevails. But still, what word combination would you rather use to describe listed range of activities: Development Operations or Software Configuration Management?


答:
I think you should just jump right in. Java is similar enough to C++ that all you will have to get over is the syntax hump.  You should just get a good reference like the dietel how to program book and just go for it. You will learn what you need as you go along. Your programming experience will help you get up to speed quicker on creating your apps.

I would also suggest The Busy Coder's Guide to Android and the newly designed Android Developer Guide

The book is worth purchasing as the writer of the book is very active and can help you alot through your learning curve.

Hope this helps

Title: Jump into Android or learn Java basics first?

Body:
I am quite proficient in C and know some C++, but never touched Java. Recently I got an idea for an app which I think has potential, and I want to develop it.

I am planning to go Android first, cause it doesn't require a mac/iPhone.

So my question is: can I go straight to learning Android development, picking up the Java syntax as I go along and need it (after all I don't think it's much different from C/C++), or should I take a couple of weeks to learn the basics of Java first and then start with Android development?


问:
Date as software version number
Software developers don't typically use date as version number, though YYYYMMDD format (or its variances) looks solid enough to use. Is there anything wrong with that scheme? Or does it apply to limited 'types' of software only (like in-house productions)?</p>

答:
The problem with using a date, is that specifications are written against the counting numbers rather than a date when it's due.

"This piece of functionality is due to be in release 1. The other piece of functionality is due to be in release 2."

You can't refer to a date in specs, since the release date could get missed.

If you don't have such a formal process that needs different releases identified in advance, using dates is fine; you don't need to add another number into the mix.

Version numbers are unlikely to contain dates, since their context is linked to specs.

Build numbers are likely to contain dates, since their context is linked to when the build took place.

Title: Date as software version number


答:
Versions are often used to convey information about how different a particular version of the software is from the previous one.  So for example, if you upgrade from 1.0 to 2.0 of Acme, that's a major upgrade, in theory carrying major changes.

An upgrade from 1.0 to 1.1, on the other hand, is a minor upgrade and in theory carries minor, incremental changes and bug fixes.

This would be difficult to represent in a date format, though you could use a mixture.  For example, v1.0.YYYY.MMDD

Title: Date as software version number

Body: Software developers don't typically use date as version number, though YYYYMMDD format (or its variances) looks solid enough to use. Is there anything wrong with that scheme? Or does it apply to limited 'types' of software only (like in-house productions)?</p>


答:
Using Version numbers is a way to show how BIG the change is

For example 2.4.3 may mean version 2 is the major change to the entire system. .4 is a minor update. and the last .3 is a small bug fix to that version. That way its easily recognisable how much has changed between each version.

Having said that I still see many people use dates or SCM revision numbers as version numbers so long as you have some way to track back to  supporting release notes and documentation of what was in-scope for that release there is no real problem.

Title: Date as software version number


答:
There are many software packages that do indeed use the date as a version. Ubuntu comes to mind, where their version is YY.MM. And the build numbers for Microsoft Office products are also an encoding of the build date. Jeff Atwood wrote an Coding Horror blog post about version numbering, including this recommendation:

Whenever possible, use simple dates instead of version numbers, particularly in the public names of products. And if you absolutely, positively must use version numbers internally, make them dates anyway: be sure to encode the date of the build somewhere in your version number.

In my opinion, it doesn't matter as long as you are consistant and are able to go from a build version number (whatever it is) and recall all artifacts that went into that build from your version control system. Users don't typically care about version information at all, but rather the functionality provided by the system. Versioning information is only of real value to the developers.

Title: Date as software version number


答:
Although this approach has benefits as you described, there are certain drawbacks if you use date as a version number:

Date based versions are flat. With v2.1.3 you can see the version number, sub-version number and sub-sub-version number. With 20110119 you can only see when it was written. You could group your date-based versions by month, but it still wouldn't tell you anything. You could have several slow months of small bug fixing and then two weeks of heavy coding resulting in a major release. Dates don't tell you that, regular version numbers do.

If you really really need to change the version on a daily basis and possibly release number it can indicate that you don't have a proper release process, but instead everyone wildly changes stuff and promotes it to production servers whenever they want. If so, you have a problem with the process, and using different version number schema isn't going to solve it.

Title: Date as software version number


问:
How to apply DRY to files shared by repositories?
I've got a few files which are used in several of my repos:

functions.sh, shell library to for example print a colored warning/error message or the documentation of a script file.

Makefile; a standardized one which installs the file $(CURDIR)/[dirname].sh to $(PREFIX)/[dirname] and references a test script.

LICENSE.

tools.mk; Makefile commands to for example print all the variable definitions in the parent Makefile.

These are more or less stable, and some are used in probably over a dozen repos. I've been thinking how to keep this DRY, but none of the options so far seem satisfactory:

Keep doing it like now, creating a copy for each new repo. This keeps the code together with all its dependencies (avoiding bugs when the general solution is not general enough), but changes which are applicable in multiple places have to be applied in each separately.

Add an executable to each of the repositories to download the files needed. This means that developers and end users will have to run an extra command to get all the relevant files, and it breaks the possibility for developers to modify and commit/push the included files.

Use git submodule or equivalent. This at least keeps the repositories connected, but in the Git case it seems like it's restricted to "a dedicated subdirectory", so no top-level files, and no mixing with parent repository files which belong in the same directory. This could be circumvented with symlinks, but that's an ugly workaround for the obvious ideal situation.

The ideal solution should:

Communicate with the correct repository when doing an operation on a file.

Allow includes in the same directories as the parent directory.

A single, simple command should be enough to update the entire repository and all includes, no matter how many or how deeply nested.

Allow includes in the top-level directory.

Not incur significant developer or user constraints (must be online while installing) or extra work (running a "pre-install" command separately from the "install" command).

Allow "cherry-picking" of files to include. Many projects might need a different Makefile, for example, and including one which is not used is just ugly (and would get uglier as more files are added).

Is this sort of thing possible with current software?

答:
One option is to have a separate repository for the shard files and then all repositories that use those files either fork from or merge in the shared file repository.

Here's an example with mercuiral. Say I've got a repo shared with the shared files and a repo project which has a project that uses the shared files. To get the shared files into the project repo I run the following commands from the project repo:

```<code>hg pull -f /path/to/shared/repo
hg merge
hg ci -m "merged shared repo"
</code>```

This pulls and merges everything from the shared repo into the project repo. I can also make any changes to the files merged from the shared repo (say a specific makefile rule) and those changes will remain local to the project repo.

Now say I've updated the shared repo with some new features or bug fix and want to include that in my project repo. Then from the project repo I simply run

```<code>hg pull /merge/to/shared/repo
hg merge
hg ci -m "merged updated shared files"
</code>```

And I have the updated versions. No -f flag was needed on the pull this time since the repos are now related.

For git the commands are almost identical. To merge the shared repo with the project repo I simply run

```<code>git fetch /path/to/shared
git merge FETCH_HEAD
</code>```

git also supports remote repos making it so I don't have to enter /path/to/shared whenever you want to merge. I can add shared as a remote repo with

```<code>git remote add shared /path/to/shared
</code>```

Then whenever I want to merge with it I enter

```<code>git fetch shared
git merge shared/master
</code>```

Where master is the name of the branch in the shared repo.

While this isn't a single command, I don't think two commands is so bad (the commit form mercural doesn't count :P). Also it allows you to easily "cherry-pick" files since the files merged in from shared are like any other tracked files in the project repository. The downside is it doesn't support requirement 1. If I change the shared repo's files in the project repo, these changes will not be reflected in the shared repo. Instead I have to change them in the shared repo and merge those changes in.

Body:
One option is to have a separate repository for the shard files and then all repositories that use those files either fork from or merge in the shared file repository.

Here's an example with mercuiral. Say I've got a repo shared with the shared files and a repo project which has a project that uses the shared files. To get the shared files into the project repo I run the following commands from the project repo:

hg pull -f /path/to/shared/repo
hg merge
hg ci -m "merged shared repo"

This pulls and merges everything from the shared repo into the project repo. I can also make any changes to the files merged from the shared repo (say a specific makefile rule) and those changes will remain local to the project repo.

Now say I've updated the shared repo with some new features or bug fix and want to include that in my project repo. Then from the project repo I simply run

hg pull /merge/to/shared/repo
hg merge
hg ci -m "merged updated shared files"

And I have the updated versions. No -f flag was needed on the pull this time since the repos are now related.

For git the commands are almost identical. To merge the shared repo with the project repo I simply run

git fetch /path/to/shared
git merge FETCH_HEAD

git also supports remote repos making it so I don't have to enter /path/to/shared whenever you want to merge. I can add shared as a remote repo with

git remote add shared /path/to/shared

Then whenever I want to merge with it I enter

git fetch shared
git merge shared/master

Where master is the name of the branch in the shared repo.

While this isn't a single command, I don't think two commands is so bad (the commit form mercural doesn't count :P). Also it allows you to easily "cherry-pick" files since the files merged in from shared are like any other tracked files in the project repository. The downside is it doesn't support requirement 1. If I change the shared repo's files in the project repo, these changes will not be reflected in the shared repo. Instead I have to change them in the shared repo and merge those changes in.


答:
In SVN the concept is called "vendor branches", ie you think of your shared files in much the same way as you think of a 3rd party library that you're using. You make a 'read-only' copy of the external files to your repo and use them. but never change them - that only occurs when you re-import the vendor files.

If you do make changes to a shared file in a project, you can (by branching it inside your repo). When you get a new import, you need to merge the changes again.

Title: How to apply DRY to files shared by repositories?

Body:
I've got a few files which are used in several of my repos:

functions.sh, shell library to for example print a colored warning/error message or the documentation of a script file.

Makefile; a standardized one which installs the file $(CURDIR)/[dirname].sh to $(PREFIX)/[dirname] and references a test script.

LICENSE.

tools.mk; Makefile commands to for example print all the variable definitions in the parent Makefile.

These are more or less stable, and some are used in probably over a dozen repos. I've been thinking how to keep this DRY, but none of the options so far seem satisfactory:

Keep doing it like now, creating a copy for each new repo. This keeps the code together with all its dependencies (avoiding bugs when the general solution is not general enough), but changes which are applicable in multiple places have to be applied in each separately.

Add an executable to each of the repositories to download the files needed. This means that developers and end users will have to run an extra command to get all the relevant files, and it breaks the possibility for developers to modify and commit/push the included files.

Use git submodule or equivalent. This at least keeps the repositories connected, but in the Git case it seems like it's restricted to "a dedicated subdirectory", so no top-level files, and no mixing with parent repository files which belong in the same directory. This could be circumvented with symlinks, but that's an ugly workaround for the obvious ideal situation.

The ideal solution should:

Communicate with the correct repository when doing an operation on a file.

Allow includes in the same directories as the parent directory.

A single, simple command should be enough to update the entire repository and all includes, no matter how many or how deeply nested.

Allow includes in the top-level directory.

Not incur significant developer or user constraints (must be online while installing) or extra work (running a "pre-install" command separately from the "install" command).

Allow "cherry-picking" of files to include. Many projects might need a different Makefile, for example, and including one which is not used is just ugly (and would get uglier as more files are added).

Is this sort of thing possible with current software?


问:
Any tips on getting hired as a software project manager straight out of college?
I graduated with a BS in compsci last September, and I've been trying (unsuccessfully) to find a job as a project manager ever since.

I fell in love with software engineering (the formal practice behind it all, not just coding) in school, and I've dedicated the last 3-4 years of my life to learning everything I can about project management and gaining experience.  I've managed several projects (with teams around 12 people) while in school, and I worked with my university's software engineering research lab.  My résumé is also decent - I worked as a programmer before I went to school (I'm 27 now), and I did Google Summer of Code for 3 summers.  I also have general "people management" experience via working as the photo editor for my university's newspaper for 2 years.

My first problem with the job hunt is not getting enough interviews.  I use careers.stackoverflow.com, which is awesome because I usually get contacted by non-HR people who know what they're talking about, but there's just not enough companies using it for me to get interviews on a regular basis.  I've also tried sites like monster.com, and in a fit of desperation, I sent out no less than 60 applications to project management positions.  I've gotten 3 automated rejection letters and that's it.  At least careers.stackoverflow gets me a phone interview with 8/10 places I apply to.

But the main (and extremely frustrating) problem is the matter of experience.  I've successfully managed projects from start to finish (in my software engineering classes we had real customers come in with a real software need and we built it for them), but I've never had to deal with budgets and money (I know this is why HR people immediately turn me away).  Most of these positions require 5+ years PM experience, and I've seen absurd things like 12+ years required.

Interviews are also maddening.  I've had so many places who absolutely loved me and I made it to the final round of interviews, and I left thinking things went extremely well and they'd consider me.  However, when I check in with them a week later, they tell me "We really liked you and your qualifications are excellent, but we're hoping to find someone with more experience."  The bad interviews I can understand - like the PM position that would have had me managing developers both locally and overseas - I had 3 interviews with them and the ENTIRE interview process was them asking me CS brainteasers and having me waste time on things like writing quicksort on paper or writing binary search trees.  Even when I tried steering the discussion towards more relevant PM stuff, they gave me some vague generic replies and went back to the "We want to be Google/MS" crap.

But when I have a GOOD interview, they say my "qualifications are excellent" but they want "more experience"...that makes me want to tear my hair out.  What else can I DO?  While I'm aiming for technically-involved PM positions (not just crunching budget numbers), I really don't want a straight development job because I like creating software from the very high-level vs. spending a lot of time debugging memory leaks.  In fact, I can't even GET development positions that I'm qualified for because I make the mistake of telling them that my future career goals are as PM (which usually results in them saying something like "Well we already have PMs and this position isn't really set up to get you there." - which I take to mean "No, that's my job, stay away.")

My apologies on the long rant, but I'm seriously hellbent on getting hired as a PM since it's both my career goal and the passion that keeps me awake at night.  Any suggestions on what the heck else I can do? I'm currently writing a blog where I talk about my philosophies about software engineering, and I'm writing up specs for an iOS app which I will design, code, and show employers, but this takes an awful lot of time that I don't have.

答: I've been a developer for ten years. Personally I would resign from any company in which would allow developers managed by random guy straight out of college. To be a good manager you need to EARN the respect of the people who will be doing the work.</p>


答:
Beyond the normal arguments against define, how would you write this function using Macros?

```<code>template <typename IterType>
typename IterType::value_type Sum(
    const IterType& begin,
    const IterType& end,
    const IterType::value_type& initialValue)
{
    typename IterType::value_type result = initialValue;
    for (IterType i = begin; i != end; ++i)
        result += i;

    return result;
}

....

vector<int> values;
int sum = Sum(values.begin(), values.end(), 0);
</code>```

This is obviously a trivial example, but that function can sum over any forward iterable sequence of a type that implements addition*.  Typedefs used like this are an important element of Generic Programming.

*I just wrote this here, I leave compiling it as an excercise for the reader :-)

EDIT:

This answer seems to be causig a lot of confusion, so let me draw it out more.  If you were to look inside of the definition of an STL vector, you would see something similar to the following:

```<code>template <typename ValueType, typename AllocatorType>
class vector
{
public:
    typedef ValueType value_type;
...
}
</code>```

The use of typedefs within the standard containers allows a generic function (like the one I created above) to reference these types.  The function "Sum" is templated on the type of the container (std::vector<int>), not on the type held inside the container (int).  Without typedef it would not be possible to refer to that internal type.

Therefore, typedefs are central to Modern C++ and this is not possible with Macros.

Title: typedefs and #defines

Body:
We all have definitely used typedefs and #defines one time or the other. Today while working with them, I started pondering on a thing.

Consider the below 2 situations to use int data type with another name:

```<code>typedef int MYINTEGER
</code>```

and

```<code>#define MYINTEGER int
</code>```

Like above situation, we can, in many situations, very well accomplish a thing using #define, and also do the same using typedef, although the ways in which we do the same may be quite different. #define can also perform MACRO actions which a typedef cannot.

Although the basic reason for using them is the different, how different is their working? When should one be preferred over the other when both can be used? Also, is one guaranteed to be faster than the other in which situations? (e.g. #define is preprocessor directive, so everything is done way earlier than at compiling or runtime).

Body:
Beyond the normal arguments against define, how would you write this function using Macros?

template <typename IterType>
typename IterType::value_type Sum(
    const IterType& begin,
    const IterType& end,
    const IterType::value_type& initialValue)
{
    typename IterType::value_type result = initialValue;
    for (IterType i = begin; i != end; ++i)
        result += i;

    return result;
}

....

vector<int> values;
int sum = Sum(values.begin(), values.end(), 0);

This is obviously a trivial example, but that function can sum over any forward iterable sequence of a type that implements addition*.  Typedefs used like this are an important element of Generic Programming.

*I just wrote this here, I leave compiling it as an excercise for the reader :-)

EDIT:

This answer seems to be causig a lot of confusion, so let me draw it out more.  If you were to look inside of the definition of an STL vector, you would see something similar to the following:

template <typename ValueType, typename AllocatorType>
class vector
{
public:
    typedef ValueType value_type;
...
}

The use of typedefs within the standard containers allows a generic function (like the one I created above) to reference these types.  The function "Sum" is templated on the type of the container (std::vector<int>), not on the type held inside the container (int).  Without typedef it would not be possible to refer to that internal type.

Therefore, typedefs are central to Modern C++ and this is not possible with Macros.


答:
This is something that you are going to have to take a look at from a couple of different angles as you need to take into account user needs as well as the needs of the software and developers.

In general, your customers aren't going to care very much about what the version number of the software is going to be as long as they know they are running something newer (i.e. Product 2012 is newer than Product 2010) and that they know it is up to date if there are patches that can be deployed (i.e. Product 2012, Update 10). As such, from a customer branding stand point I tend to prefer either a named releases (e.g. Windows XP, Windows Vista) followed by a strict sequence number of patches that may be installed by users.

That said though, writing software that checks things that are easy for the user tends to make the code under the hood much harder to write. Thus I tend to prefer the simple Major.Minor version scheme if only because you can do a simple number comparison to check to see something is up to date as in the following:

```<code>// Check to see if we can handle the file version
if (this.Version < fileVersion) {
   throw new UnsupportedFileException("The file version is " + fileVersion.toString() + " which is not supported");
}
// Do stuff ...
</code>```

To put this in a bit of context though, I generally don't care how big the minor number gets (i.e. 1.1024) which allows the above system to keep running successfully. Generally the revision numbers are only of interest to internal development and I actually haven't even really seen them affect things that much beyond just giving things an additional number to keep track of.

However, the above two schemes really only don't apply to environments where continuous deployment is being used (i.e. Stack Exchange) which is where I tend to prefer some sort of date followed by a revision number as appears to be used on the Stack Exchange sites. The reasoning for this being that versions are going to change too often in the continuous deployment environment and you may have multiple versions of the code going up in the same day which justifies the revision number and the current date is as good as any for breaking things out even more. In theory you could just use the revision number for everything but use of the current date allows you to keep track of major milestones internally that could make things a touch easier to discuss.

Title: Date as software version number

Body:
This is something that you are going to have to take a look at from a couple of different angles as you need to take into account user needs as well as the needs of the software and developers.

In general, your customers aren't going to care very much about what the version number of the software is going to be as long as they know they are running something newer (i.e. Product 2012 is newer than Product 2010) and that they know it is up to date if there are patches that can be deployed (i.e. Product 2012, Update 10). As such, from a customer branding stand point I tend to prefer either a named releases (e.g. Windows XP, Windows Vista) followed by a strict sequence number of patches that may be installed by users.

That said though, writing software that checks things that are easy for the user tends to make the code under the hood much harder to write. Thus I tend to prefer the simple Major.Minor version scheme if only because you can do a simple number comparison to check to see something is up to date as in the following:

// Check to see if we can handle the file version
if (this.Version < fileVersion) {
   throw new UnsupportedFileException("The file version is " + fileVersion.toString() + " which is not supported");
}
// Do stuff ...

To put this in a bit of context though, I generally don't care how big the minor number gets (i.e. 1.1024) which allows the above system to keep running successfully. Generally the revision numbers are only of interest to internal development and I actually haven't even really seen them affect things that much beyond just giving things an additional number to keep track of.

However, the above two schemes really only don't apply to environments where continuous deployment is being used (i.e. Stack Exchange) which is where I tend to prefer some sort of date followed by a revision number as appears to be used on the Stack Exchange sites. The reasoning for this being that versions are going to change too often in the continuous deployment environment and you may have multiple versions of the code going up in the same day which justifies the revision number and the current date is as good as any for breaking things out even more. In theory you could just use the revision number for everything but use of the current date allows you to keep track of major milestones internally that could make things a touch easier to discuss.


问:
What you should do if your junior did not adopt your suggestion?
I am leading a team of 3-4 junior developers. My job-- besides writing code-- is to provide supervision and guidance for the juniors.

But, I fully understand how much developers cherish autonomy in their work, and I don't want to destroy their intrinsic motivation by spoon-feeding them with my thoughts and my algorithms; I want them to explore the problem in their own ways, and think about it themselves and only come to me when they are really facing insurmountable issues.

When they do come to me, sometimes I would have to propose a completely different algorithm to solve the problem because their algorithm isn't robust enough ( remember, I am the senior and I have seen more than them). Of course I would explain this in a nice manner so as not to hurt their feelings, and I would gently outline how my solution is vastly superior than theirs, no condescending tone or condemning words.

But still, they are sometimes reluctant to accept my suggestion, partly because they have invested so much in their own algorithm, or partly because of the fear that using a new method would entail more learning time and make them appear to the management as if they are going nowhere. But deep in my heart I know very well that my algorithm is much better than theirs and they should just adopt it.

What should I do if they didn't adopt my suggestion? Should I just ask them to follow my way, or should I just let them have their heads banged on the wall many many more times and wait for them to come back to me? Doing the former makes me into a dictator, but doing the later would cost us precious development time and incur bug fixing cost. I am really in a dilemma here.

答:
As some of the others have pointed out, if you really are just proving the junior developers with suggestions and they are phrased as such then you really don't have much grounds for getting annoyed at them if they don't follow it because they may not see much reason for doing so. Likewise, you really can't go an berate them for not following your suggestion because they aren't actual direction to do things a certain way.

In regards to trying to get the junior developers to do things as you would prefer to do them:

Control your terminology, making a suggestion is not the same as making a recommendation which is definitively not the same as providing direction. Use terminology accordingly to get your point across and if you think that your way of doing something is a better way of doing it, tell them that it is your recommendation to do so. Likewise, if it absolutely critical that things be done a given way (i.e. can't withstand a time delay) then just be blunt and give them direction in how it should be done.

Junior developers are still going through the learning process regardless of how you are phrasing things, always provide some sort of reasoning behind what you are telling them unless there is a specific reason you cannot. Even in that case, most people will understand if you say something along the lines of "It has to be done this way, I don't care for it myself but the decision has already been made." they tend to be fairly reasonable.

If it is truly is just a suggestion then make sure that your idea is actually better than how did it. If you don't think it is the case then sit down with the developer and do a code and concept review so that they can justify their solution. It may be that once they start explaining it to someone else - and you ask the right questions - they will see a better way and want to recode things on their own.

Don't quibble over the details if their solution is similar to what you originally suggested, it may be that they took what you told them into account and did things slightly differently or changed their original concept based upon your suggestion.


答:
If files themselves put-together are independent (rather self dependent) - it does make sense to have them in separate repo and treat it as a dependency project for a give repo. This will minimize the copying files.

However, from the example you gave - these are things like Makefile, license etc. are not full fledged module by themselves. If you keep them separate - this will be random amalgamation and wont help as much as the pain it will put you in.

Also, given the same examples, i also don't see that to be a great resource saving exercise either. So overall, i don't quite see much value in this exercises.

I am not saying anything against DRY as a principle; but DRY or NOT DRY - will it have any significance here?


答:
Personally I suggest to study Java first so you won't spend a lot of time googling this and googling that. That will kill your productivity.

And if I'm allowed to suggest some books then I suggest Head First Android Development and/or Programming Android.

On the other hand and since you are proficient in C and knowledgeable in C++, iOS development should really be easier to you to pick since Objective-C is a minimal programming language built on C.  But of course, it is your call.


问:
How to use code from abandoned github projects
I've recently come across github projects that I could really use, but appear to have been abandoned, with lots of issues and important pull requests, perhaps 100+ forks. Often, there isn't an alternative project.

Do I use the code as is? Do I pick a fork and ignore the others? Do I manually pull in code from the pull requests? How? Is there any chance I or anyone else could somehow organize and take off where the original coder left off?

答:
You could send a message to the members of the network that is automatically created with anyone who is forking a project to begin with. (at least those who commited code after the fork, if there are so much)(Network\Members tab).

What you should do next is highly dependent on the project and its community (or lack of community) :

If no one seems active, become a leader for this project and start your own fork.

If you find existing members, see what needs to be done to have a solid fork that will revive the project with them.

Marketing Part : sometime a rename of the project when the reboot fork occur is a good way to attract new programmers and users, and give a second chance to the project to gain traction.

You should also check if anything that is done is allowed by the license, if you cannot find a way to communicate with the original programmers.


答:
First add an Issue to the main project about it being abandoned and ask to make yourself a contributor. If that doesn't work I would communicate with the network as Matthieu suggested and organize group work on a fork, depending on what the license allows on the project. At least by making a project public there is an implied license that the project may be forked according to the terms of Github.

Here is a related article: What are the ethics of forking Someone Else's Github Project

Title: How to use code from abandoned github projects

Body:
I've recently come across github projects that I could really use, but appear to have been abandoned, with lots of issues and important pull requests, perhaps 100+ forks. Often, there isn't an alternative project.

Do I use the code as is? Do I pick a fork and ignore the others? Do I manually pull in code from the pull requests? How? Is there any chance I or anyone else could somehow organize and take off where the original coder left off?


答:
First of all, do you know the real reason why your junior didn't adopt your suggestion?

Sometimes you know, a junior may actually write something better than his senior due to newer perspectives and a more up to date CS education. Although as a senior you may have seen more real world examples. But a bad trap I often see my seniors sometimes falls into is forgetting that best practices could change over time. I'm sure this does not apply to you however as you have been updating yourself on sites such as these. ;)

I would suggest try approaching your juniors without any (or little) "aura" of a senior, try to talk in level terms with them, show curiosity in the code they have written. Ask questions, hear their responses. Don't ask in an accusing manner such as:

"Your code is pretty inflexible, you need to change it to this..."

instead ask

"I'm just wondering, what if someone were to...does your code manage to handle that?...I think a strategy pattern might help here. what do you think?"

This I believe will help you in engaging with more healthy conversations with them than like a professor/lecturer looking down at them like a know it all. It will also help you to better see their reasoning and perspectives.

Title: What you should do if your junior did not adopt your suggestion?

Body:
I am leading a team of 3-4 junior developers. My job-- besides writing code-- is to provide supervision and guidance for the juniors.

But, I fully understand how much developers cherish autonomy in their work, and I don't want to destroy their intrinsic motivation by spoon-feeding them with my thoughts and my algorithms; I want them to explore the problem in their own ways, and think about it themselves and only come to me when they are really facing insurmountable issues.

When they do come to me, sometimes I would have to propose a completely different algorithm to solve the problem because their algorithm isn't robust enough ( remember, I am the senior and I have seen more than them). Of course I would explain this in a nice manner so as not to hurt their feelings, and I would gently outline how my solution is vastly superior than theirs, no condescending tone or condemning words.

But still, they are sometimes reluctant to accept my suggestion, partly because they have invested so much in their own algorithm, or partly because of the fear that using a new method would entail more learning time and make them appear to the management as if they are going nowhere. But deep in my heart I know very well that my algorithm is much better than theirs and they should just adopt it.

What should I do if they didn't adopt my suggestion? Should I just ask them to follow my way, or should I just let them have their heads banged on the wall many many more times and wait for them to come back to me? Doing the former makes me into a dictator, but doing the later would cost us precious development time and incur bug fixing cost. I am really in a dilemma here.