答:
It should be noted that I am an avid speed cuber, but I have never tried to programatically represent a Rubik's cube in an algorithm or data structure.

I would probably create separate data structures to capture the unique aspects of each block in a cube.

There are 3 distinct types of blocks on a cube:

Corner Block - It has three color faces and three adjacent pieces that it will share a side with at any time.

Edge Block - It has two color faces and has 4 adjacent pieces that it will share a side with at any time.  In 3x3 blocks it always has 2 center pieces and 2 corner pieces.

Center block - In a 3x3 cube this piece is not movable, however it can be rotated.  It will always have 4 adjacent edge blocks.  In larger cubes there are multiple center blocks that could share with another center block or an edge piece.  Center blocks never are adjacent to a corner block.

Knowing this, a Block can have a list of references to other blocks that it touches.  I would keep another list of lists, which would be a list of blocks that represent a single cube face and a list that keeps references to every cube face.

Every cube face would be represented as a unique face.

With these data structures it would be pretty easy to write an algorithm that performs a rotation transformation on each face, moving the appropriate blocks into and out of the appropriate lists.

EDIT: Important note, these lists must be ordered of course but I forgot to mention that.  For example, if I flip the right side, then the left corner right side block moves to the right corner of the right side and is rotated clockwise.


问:
Should injecting dependencies be done in the ctor or per method?
Consider:

```<code>public class CtorInjectionExample
{
    public CtorInjectionExample(ISomeRepository SomeRepositoryIn, IOtherRepository OtherRepositoryIn)
    {
        this._someRepository = SomeRepositoryIn;
        this._otherRepository = OtherRepositoryIn;
    }

    public void SomeMethod()
    {
        //use this._someRepository
    }

    public void OtherMethod()
    {
        //use this._otherRepository
    }
}
</code>```

against:

```<code>public class MethodInjectionExample
{
    public MethodInjectionExample()
    {
    }

    public void SomeMethod(ISomeRepository SomeRepositoryIn)
    {
        //use SomeRepositoryIn
    }

    public void OtherMethod(IOtherRepository OtherRepositoryIn)
    {
        //use OtherRepositoryIn
    }
}
</code>```

While Ctor injection makes extension difficult (any code calling the ctor will need updating when new dependencies are added), and method level injection seems to remain more encapsulated from the class level dependency and I can't find any other arguments for/against these approaches.

Is there a definitive approach to take for injection?

(N.B. I have searched for information on this and tried to make this question objective.)

答: It's depends, if the injected object is used by more than one method in the class, and inject in it on each method does not make sense, you need to resolve the dependencies for every method call, but if the dependency is used only by one method inject in it on the constructor is not good, since you are allocating resources that could never be used.</p>

ContentLicense: CC BY-SA 3.0

ContentLicense: CC BY-SA 4.0


问:
Introducing Agile development after traditional project inception
About a year and a half ago, I entered a workplace that claimed to do Agile development. What I learned was that this place has adopted several agile practices (such as daily standups, sprint plannings and sprint reviews) but none of the principles (just in time / just good enough mentality, exposing failure early, rich communication).

I've now been tasked with making the team more agile and I've been assured that I have complete buy-in from the devs and the business team. As a pilot program, they've given me a project that just completed 15 months of requirements gathering, has a 110 page Analysis & Design document (to be considered as "written in stone"), and where I have no access to the end users (only to the committee made up of the users' managers who won't actually be using the product).

I started small, giving them a list of expected deliverables for the first 5 sprints (leaving the future sprints undefined), a list of goals for the first sprint, and I dissected the A&D doc to get enough user stories to meet the first sprint's goals.

Since then, they've asked why we don't have all the requirements for all the sprints, why I haven't started working on stuff for the third sprint (which they consider more important but is based off of the deliverables of the first 2 sprints) and are pressing for even more documentation that my entire IT team considers busy-work or un-related to us (such as writing the user manual up-front, documenting all the data fields from all the sprints up front, and more "up-front" work).

This has been pretty rough for me as a new project manager, but there are improvements I have effectively implemented such as scrumban for story management, pair programming, and having the business give us customer acceptance tests up front (as part of the requirements documentation).

So my questions are:

What can I do to more effectively introduce change to a resistant
business?

Are there other practices that I can introduce on the
IT side to help show the business the benefits of agile?

The burden of documentation is strangling us - the business still sees
it as a risk management strategy instead of as a risk. What can we
do to alleviate their documentation concerns and demands
(specifically the quantity of documentation and their need for all
of it up front)?

We are in a separate building from our business, about 3 blocks away and they refuse to have their people on the project co-habitate b/c that person "won't be able to work on their other projects while they're at our building." They expect us to always go over there and to bundle our questions so that we can ask them all at once and not waste that person's time with "constant interruptions." What can we do to get richer communication from them?

Any additional advice would also be appreciated.

Thanks!

答:
Agile isn't for everyone, it sounds like your business just likes saying agile because its the hottest buzzword.  First of all it probably would have been a good idea to push for a brand new project or smaller maintenance projects to start making their process more like true agile methodologies. Trying to redesign a methodology using a project that is already underway is like trying to change a tire in the middle of an 8 lane highway. You need a way to show your business agile can work, but you need an environment where it has a chance of working, but based on what you have said agile is unlikely to work well with their established culture.

Depending on what they want for documentation you may be able to show them that this is generated automatically from a tool you are using, or is redundant and document B has the information document A was requested to show. You also need to adjust your plans for documentation, let them know why your estimates are changing, and ask them to reduce the amount of requested documentation or dedicate resources like a business analyst to create the documentation.


问:
What is the abstract name for Drive, Directory and file?
I want to give nice name to my function while returns drive, directory and file. Can you please suggest a good abstract name for this trio?

This is the function.

```<code>  static IEnumerable<string> GetDriveDirectoriesAndFile(string path)
  {
     if (path.Contains('/'))
     {
        path = path.Replace('/', '\\');
     }
     if (path.Contains('\\'))
     {
        return path.Split('\\');
     }
     return null;
  }
</code>```

Thanks,
Omkar

答: How about calling your method GetPathComponents(string path)?


答:
Build in the time/resource/cost of the documentation they want and let them see how far it pushes the schedule out.

This may help show them just how much work they are pushing onto the project team, and how this could be reduced if they weren't doing that.

Title: Introducing Agile development after traditional project inception

Body:
About a year and a half ago, I entered a workplace that claimed to do Agile development. What I learned was that this place has adopted several agile practices (such as daily standups, sprint plannings and sprint reviews) but none of the principles (just in time / just good enough mentality, exposing failure early, rich communication).

I've now been tasked with making the team more agile and I've been assured that I have complete buy-in from the devs and the business team. As a pilot program, they've given me a project that just completed 15 months of requirements gathering, has a 110 page Analysis & Design document (to be considered as "written in stone"), and where I have no access to the end users (only to the committee made up of the users' managers who won't actually be using the product).

I started small, giving them a list of expected deliverables for the first 5 sprints (leaving the future sprints undefined), a list of goals for the first sprint, and I dissected the A&D doc to get enough user stories to meet the first sprint's goals.

Since then, they've asked why we don't have all the requirements for all the sprints, why I haven't started working on stuff for the third sprint (which they consider more important but is based off of the deliverables of the first 2 sprints) and are pressing for even more documentation that my entire IT team considers busy-work or un-related to us (such as writing the user manual up-front, documenting all the data fields from all the sprints up front, and more "up-front" work).

This has been pretty rough for me as a new project manager, but there are improvements I have effectively implemented such as scrumban for story management, pair programming, and having the business give us customer acceptance tests up front (as part of the requirements documentation).

So my questions are:

What can I do to more effectively introduce change to a resistant
business?

Are there other practices that I can introduce on the
IT side to help show the business the benefits of agile?

The burden of documentation is strangling us - the business still sees
it as a risk management strategy instead of as a risk. What can we
do to alleviate their documentation concerns and demands
(specifically the quantity of documentation and their need for all
of it up front)?

We are in a separate building from our business, about 3 blocks away and they refuse to have their people on the project co-habitate b/c that person "won't be able to work on their other projects while they're at our building." They expect us to always go over there and to bundle our questions so that we can ask them all at once and not waste that person's time with "constant interruptions." What can we do to get richer communication from them?

Any additional advice would also be appreciated.

Thanks!


答: I'm going to suggest "FileSystemObjects", Or if you want to shorten it: "FSObjects", or "FSOs", or some variant of that.</p>

Title: What is the abstract name for Drive, Directory and file?

Body:
I want to give nice name to my function while returns drive, directory and file. Can you please suggest a good abstract name for this trio?

This is the function.

```<code>  static IEnumerable<string> GetDriveDirectoriesAndFile(string path)
  {
     if (path.Contains('/'))
     {
        path = path.Replace('/', '\\');
     }
     if (path.Contains('\\'))
     {
        return path.Split('\\');
     }
     return null;
  }
</code>```

Thanks,
Omkar


问:
Is mentioning my blog on my resume helpful or hurtful to a job search?
I have a blog that I use mostly to record solutions to problems I have had, that I had some trouble finding an answer to. Mostly problems where the online doc I googled provided too much info, and I found the answer to my question on the fifth page of my third google hit.

(Or if I asked the question here, I either didn't get an answer or I got slammed for asking a question that "the answer could be easily googled.")

I frequently look up stuff on this blog to remind myself of how I solved a problem, and it gets a decent amount of hits from others as well.

Anyway, I was wondering if mentioning this blog on my resume would help or hurt me in a job search? The topics are all over the map.

What I would hope it shows is that

I am a person who finds solutions to problems

I have used many different technologies in my work

I am not afraid to tackle a challenge

What I am concerned it shows is that

This person had trouble with something that simple?

Why is this person bothering to blog this stuff?

答:
If someone puts down that they have a blog on their CV I will always look at it - either before interviews if a URL is given or after if not (as I will ask for it in the interview). I'm guessing I must be unusual in doing this as almost always the blog does not exist/is offline, has a single entry and/or hasn't been updated for eons.

I don't take this as a negative by itself as it's unfortunately so common, but I would take it as a big positive if a blog makes interesting reading. It shows that you care enough about things to keep a blog in the first place (note to self - I really should start a blog sometime) but even more importantly if you have difficulty doing something once that you've taken steps to make it easier on yourself the second time around.

ContentLicense: CC BY-SA 2.5


问:
Deprecated Methods in Code Base
A lot of the code I've been working on recently, both professionally (read: at work) and in other spheres (read: at home, for friends/family/etc, or NOT FOR WORK), has been worked on, redesigned and re-implemented several times - where possible/required. This has been in an effort to make things smaller, faster more efficient, better and closer to spec (when requirements have changed).

A down side to this is that I now have several code bases that have deprecated method blocks (and in some places small objects). I'm looking at making this code maintainable and easy to roll back on changes. I'm already using version control software in both instances, but I'm left wondering if there are any specific techniques that have been used by others for keeping the superseded methods without increasing the size of compiled outputs?

At the minute, I'm simply wrapping the old code in C style multi line comments.

Here's an example of what I mean (C style, psuedo-code):

```<code>void main ()
{
  //Do some work
  //Foo();  //Deprecated method call
  Bar();    //New method
}

/***** Deprecated code *****
/// Summary of Method
void Foo()
{
  //Do some work
}
***** Deprecated Code *****/

/// Summary of method
void Bar()
{
  //Do some work
}
</code>```

I've added a C style example, simply because I'm more confident with the C style languages. I'm trying to put this question across as language agnostic (hence the tag), and would prefer language agnostic answers, if possible - since I see this question as more of a techniques and design question.

I'd like to keep the old methods and blocks for a bunch of reasons, chief amongst them being the ability to quickly restore an older working method in the case of some tests failing, or some unforeseen circumstance.

Is there a better way to do this (that multi line comments)? Are there any tools that will allow me to store these old methods in separate files? Is that even a good idea?

答:
Is there a better way to do this (that multi line comments)? Are there any tools that will allow me to store these old methods in separate files? Is that even a good idea?

You should track and remove all commented code block. You are already using versioning, so the old code will be available whenever you feel nostalgic or if you have broken something while refactoring.

Commented code is just useless clutter.

Title: Deprecated Methods in Code Base


答:
I've been assured that I have complete buy-in from the devs and the business team [...] I have no access to the end users [...]

One thing to be quite clear on is the difference between being verbally assured that you "have buy-in", on one hand, and on the other hand the actual commitment from whoever is sponsoring your work.

My best advice to you is to set aside the label "Agile" altogether. Ban the word from conversation insofar as possible. Instead, focus on the following things:

What results you are asked to deliver (you specifically, not the team)

What the success criteria for your mission are (again, yours rather than the team's)

What means you have at your disposal (including people, access to people, time, information, training budget, whatever)

"Making the team more agile" is not an actionable goal. It's not specific enough, it's not measurable, it has no end condition. What you need is something specific: a target expressed in terms of X percent fewer defects, or Y percent of your feature delivery dates actually honored, by Z date.

To reach these goals you may need to introduce changes. Now a few rules of thumb apply. Every improvement is a change, but not every change is an improvement. It's often said that people resist change, but actually people resist being changed and not knowing whether the change will be an improvement.

Focus on practices which you think will be easy wins, low-hanging fruit. Focus on the practices that establish a framework not just for implementing change, but for assessing the effects of change, and reassuring people that they are resulting in improvement rather than regression. "Information radiators" are good, as are retrospectives.

Some of these changes may be both necessary and perceived as threatening, like having more access to people who have key information. Don't compromise on these: "buy in" means a process of negotiation where you actually stand a chance of delivering what you're asked to, not being led like a lamb to political slaughter.

Try to set things up so that it's hard to shift the blame to you if things don't go right (and plenty will probably go wrong). Be aware that this might happen, and be prepared if it does happen: know your exit strategy.


答:
Source control is fine for this. You don't need to leave your code base cluttered up with old methods/classes that shouldn't be used.

Tag or branch at any milestone.

You can get back to any "last working copy" you like this way.

Title: Deprecated Methods in Code Base

Body:
A lot of the code I've been working on recently, both professionally (read: at work) and in other spheres (read: at home, for friends/family/etc, or NOT FOR WORK), has been worked on, redesigned and re-implemented several times - where possible/required. This has been in an effort to make things smaller, faster more efficient, better and closer to spec (when requirements have changed).

A down side to this is that I now have several code bases that have deprecated method blocks (and in some places small objects). I'm looking at making this code maintainable and easy to roll back on changes. I'm already using version control software in both instances, but I'm left wondering if there are any specific techniques that have been used by others for keeping the superseded methods without increasing the size of compiled outputs?

At the minute, I'm simply wrapping the old code in C style multi line comments.

Here's an example of what I mean (C style, psuedo-code):

```<code>void main ()
{
  //Do some work
  //Foo();  //Deprecated method call
  Bar();    //New method
}

/***** Deprecated code *****
/// Summary of Method
void Foo()
{
  //Do some work
}
***** Deprecated Code *****/

/// Summary of method
void Bar()
{
  //Do some work
}
</code>```

I've added a C style example, simply because I'm more confident with the C style languages. I'm trying to put this question across as language agnostic (hence the tag), and would prefer language agnostic answers, if possible - since I see this question as more of a techniques and design question.

I'd like to keep the old methods and blocks for a bunch of reasons, chief amongst them being the ability to quickly restore an older working method in the case of some tests failing, or some unforeseen circumstance.

Is there a better way to do this (that multi line comments)? Are there any tools that will allow me to store these old methods in separate files? Is that even a good idea?


问:
How to represent a Rubik's Cube in a data structure
If I am attempting to simulate a Rubik's Cube, how would you create a data structure to store the cube's state in memory, with X number of tiles per side?

Things to consider:

the cube can be of any size

it is a Rubik's cube, so layers can be rotated

答:
The first condition that it be solveable would be that each piece be present and that colors on each piece can be used to assemble a "sovled" cube. This is a relatively trivial condition whose truth can be determined with a simple checklist. The color scheme on a "standard" cube is defined, but even if you're not dealing with standard cube there are only 6! possible combinations of solved faces.

Once you have all the pieces and colors right, then it is a matter determining if any given physical configuration is solvable. Not all of them are. The most naive way to check this is to run a cube-solving algorithm and see if it terminates with a solved cube. I don't know if there are fancy combinatorial techniques to determine solvability without actually trying to solve the cube.

As for what data structure... that almost doesn't matter. The tricky part is getting the transformations right and being able to represent the cube state in a way that allows you to neatly work with available algorithms in the literature. As Maple-shaft indicated there are three types of pieces. Literature on rubik's cube solving always refer to pieces by their type.  Transformations are also represented in common ways (look up Singmaster notation). Also, all solutions that I've seen always refer to one piece as a reference point (usually putting the white center piece on bottom).


问:
Approached to build app centered around new API and suddenly API is abandoned
This isn't a huge deal, but I was approached by colleagues/friends to build an app using their new API. There was some potential for pecuniary gain for me depending on app usage. I spent a considerable amount of time polishing the mobile app, based on my assumption that, having been approached in a serious way, that the company would not suddenly shift focus and abandon the API. I wasn't even given so much as a heads up that the API was dead even though I had an app in production that relied on it...

For the most part, building the app was a learning experience which I enjoyed, but I don't think I'd have expended all the effort if I knew that the company wasn't as serious about the API as their reaching out to me clearly indicated.

How, if at all, would you react?

答: If you have not signed any contracts, there is nothing you can do to either force maintainance of the API, or get a refund of your expenses. Like @mcfinnigan said, next time if a company approaches you, draw up some kind of contract which formalizes the expectations from both sides. You mention that the people you used the API of are friends/colleagues (friends don't let friends use an API that is no longer supported :)). In that case I would approach them and explain the situation, and express that you are not happy with the way you where treated. In this way they are aware of your feelings in this regard (which they might not have though of) and you could try and prevent such a thing form occuring again with these people.</p>


问:
Alternatives to using  cookies?
Whate are alternatives to using cookies/client-side storage for a PHP/MySQL based site on Apache.

Scenario/Requirements:

I want to try using some anti-bot code to prevent specific scrapers etc. from accessing the site.

I would like to run this code before launching the rest of the site (before DB access etc.).

I don't want to constantly run the same code on every page-load after a visitor has passed the initial check.

I'd like to avoid the use of Cookies/Client side storage if at all possible.

The only solution I can currently think of is to write files to the server based on the visitors IP/UA, or to write a list of them to a single file.

Yet this has the limitation of multiple users through a proxy/same connection, etc ...

So, any ideas/suggestions?

Or am I simply over working the issue?

答:
In a stateless environment you will have to persist the value somewhere; database, cookies, even a text file on disk.  Some ways of persisting are better than others.

It sounds like you are more concerned about the performance hit of retrieving the persisted value.  I would pick a solution and log how long that section of code takes per page load to test if the solution is acceptable.  You can further refine your tests to see how much network/disk IO is used to retrieve the persisted value.

You may consider approaching the problem differently as well.  You could add a user authentication element with captcha to reduce automated site access if the sites requirements allow for it.

Have you considered how to address if elements of your site such as images stored on disk are accessed directly and bypass the code check?

Title: Alternatives to using  cookies?


问:
Bug once in a while, but high priority
I am working on a CNC (computer numerical control) project which cuts shapes into metal with help of laser.

Now my problem is once in a while (1-2 times in 20 odd days) the cutting goes wrong or not according to what is set.

But this causes loss so the client is not very happy about it.

I tried to find out the the cause of it by

Including log files

Debugging

Repeating the same environment.

But it wont repeat.

A pause and continue operation will again make it to run smoothly without the bug reappearing.

How do I tackle this issue? Should I state it as a Hardware Problem?

答:
I had a bug in a game that happened only 1 time in a billion.  Fortunately this meant I was seeing it every 15 to 30 minutes, but stepping through the code in the debuggger was not going to work.  I ended up putting in debug messages.  They needed to use fancy if-statements because I only wanted something when there was a problem.  In most cases the debugging code was repeating calculations in the regular code but using different techniques.  The repeats did not have to be precise.  If I knew a number should always be under 10,000 and it seemed to hit 150,000 on occasion, I'd just check for a value over 100,000.  Each time the bug occurred, I'd study my results, devise more elaborate debugging messages (or more precisely, more elaborate checks to see if I should display a message), and wait for the problem to arise again.

Your cycles are going to be a lot longer than mine were, but you will eventually close in on the problem.  I do hope you can find the solution by some other, faster method, but this will catch it eventually if nothing else does, and will give you a sense that you are doing something until you come up with a better idea.

(In case it's helpful, I finally solved my problem by cleaning up the few lines of code I finally identified as the problem.  I'll swear there was nothing wrong with them, but I think both the optimizer and the CPU were reordering instructions for performance, and I think once in a while they were taking chances to get a bit of extra speed.  Even a single core multi-processes these days, and I think every great once in a a while a register got read before it was written to.  I switched all calculations to work with local variables.  "Instance field" values were moved to local variables right at the start, and the local values were moved back only at the very end, inside synchronization blocks.  And I used a local value for the method return value rather than the "instance field" I had been using.)

Title: Bug once in a while, but high priority


答:
When I think of this problem, I think of a static cube with the colors moving across it in known patterns.  So....

A Cube object contains 6 Side objects that remain fixed indexed 0-5.
Each side contains 9 position objects that remain fixed indexed 0-8.
Each position contains a color.

For simplicity, handle every action in quarter turn increments. There are 3 axes of rotation, each in 2 possible directions for a total of 6 possible actions on the cube. With this information, it becomes a fairly simple task to map out the 6 possible actions on the cube.

So the color green in side 6, position 3, may move to side 1 position 3, or side 2 position 7, amongst others, depending on the action taken.  I haven't explored this enough to find any mathematical translations, but patterns will probably emerge that you can take advantage of in code.

Using the data structure, how can I know if a certain cube in a
  certain state is solvable? I have been struggling with this question
  myself and haven't quite found the answer yet.

To do this, never begin with a random cube state. Instead, start with a solved state, and perform n actions programmatically to get the cube into a random starting state. Since you only took legal actions to get to the current state, the cube must be solvable.

Title: How to represent a Rubik's Cube in a data structure

Body:
If I am attempting to simulate a Rubik's Cube, how would you create a data structure to store the cube's state in memory, with X number of tiles per side?

Things to consider:

the cube can be of any size

it is a Rubik's cube, so layers can be rotated


问:
How do you name sprints in your projects?
Some Scrum software management tools give you this option to explicitly name your sprints.

Do you have a preferred way of naming your sprints or do you just use a simple scheme like 1, 2, 3, ...?

答:
For us we enjoy putting funny names, internally anyway, to our numbered releases and larger projects to break up the monotony a little.  We are always looking for funnier/more creative names for our larger projects and releases,however we also obviously use a traditional numbering (1.0, 1.1) or date based system to keep track from a code perspective
our best to date is old school rappers. No one says scrum development can't be a bit funny

Ex. Beastie Boys,
    Coolio,
    DJ Jazzy Jeff,
    Eazy-E,
    Flavor Flav,
    Etc.


问:
What class structure allows for a base class and mix/match of subclasses? (Similar to Users w/ roles)
I have a set of base characteristics, and then a number of sub-types. Each instance must be one of the sub-types, but can be multiple sub-types at once. The sub-types of each thing can change. In general, I don't care what subtype I have, but sometimes I do care.

This is much like a Users-Roles sort of relationship where a User having a particular Role gives the user additional characteristics. Sort of like duck-typing (ie. If my Foo has a Bar, I can treat it like a ThingWithABar.)

Straight inheritance doesn't work, since that doesn't allow mix/match of sub-types. (ie. no multi-inheritance).

Straight composition doesn't work because I can't switch that up at runtime.

How can I model this?

答:
Start with your main class, User.  Then have it contain a list of objects, call them Role instances or implementations.  Your Role's all have to look alike to the User so it can talk to them, but their implementations can be very different.  (And in fact they can have powers (methods) the User knows nothing about.  Each just has to be Role, whatever else might be.)  Essentially, when the User is told to do something that it cannot do itself, directly, it will go through the list asking each Role if it can do it.  When it finds one that can, it calls that Role's doIt method.  And you can swap Role instances in and out of the User at any time.

The User might want to pass a Role instance back to a caller, because the caller might know that a Role with an ID of 6 implements the DatabaseReader interface and has methods the User object knows nothing about.

I'm not sure exactly what you need, but hopefully this will give you some ideas, even if it doesn't solve your problem.


答:
In order to introduce a new thing smoothly, you need to make sure the people will not see it as a threat and permanent.

Many of us are naturally wired to avoid any sort of new things. It's biological. People usually seeking for novelty will never cause you any problem. You need to make sure more anxious people will not see your suggestion as a threat for their current comfort.

The ideal way for a team to adopt a practice or idea is to make sure the idea is coming from them, and not any external people such as the management, or worse, some random consultants. To make this happen, create brainstorming meetings with the whole team with only one topic. The topic should be the problem. In the meeting, you will have to bring carefully the ideas and come with arguments and facts.

We don't like to take decision on permanent stuff. We are already anxious by the effect of a potential change. That behavior is well know by pet shops. Buying a dog is a very big decision and will likely radically change your life. When you are at the store, the salesman will often propose you to take it back home, and return it if you change your mind. As you may expect, there are very few returns. The proposal has only one objective: reduce the anxiety that prevent people from taking decisions. Suggest to your team practice that you try for a fixed amount of time after what you'll evaluate its effect.

Regarding your second question, I highly suggest you to bring one thing at a time.

Your documentation problem deserve it's own post here on P.SE and I don't see any problem with the fact you are in two different building if both are willing to meet regulary. There are situation in which one of the side don't want to meet at all ;)


答: Not sure what language this is run in, but if I experience erratic bugs in my code (C++), I will use a tool like valgrind or cppcheck to ensure nothing is going on memory-wise.</p>

Title: Bug once in a while, but high priority

Body:
I am working on a CNC (computer numerical control) project which cuts shapes into metal with help of laser.

Now my problem is once in a while (1-2 times in 20 odd days) the cutting goes wrong or not according to what is set.

But this causes loss so the client is not very happy about it.

I tried to find out the the cause of it by

Including log files

Debugging

Repeating the same environment.

But it wont repeat.

A pause and continue operation will again make it to run smoothly without the bug reappearing.

How do I tackle this issue? Should I state it as a Hardware Problem?


问:
Anyone know of any resources for someone who wants to learn WPF and F#
It's easy to find resources for learning WPF, similarly it's pretty easy to find resources for F#. </p>

<p>But I feel that I could save some time if I could learn them both at the same time. So can anyone recommend any books, blogs, articles , something else? </p>

<p>(I'm familiar with functional programming, winforms and c#)  </p>

答:
Learning WPF through F#, and vice versa, by John Liao

 Link


答:
Since it looks like you are using .NET, if possible I would suggest using the terminology in the System.IO.Path class:

Root (Drive letter such as C:\ or UNC such as \server\share)

Directory Name

File Name

Also, if possible, I would suggest using the Path, FileInfo, and DirectoryInfo classes when working with file system paths, rather then attempting to do the splitting, combining, and parsing on your own.


答:
Dates!

Our process uses a release branch for each sprint we do, so the sprint and release branch names align. We use the planned release date as the name of the branch and sprint.

This makes understanding history a bit easier at the same time -- e.g. if you're looking at an old email about a bug that you thought was fixed, based on the date of the email, you can easily jump to the closest branch name(s) to get a better idea of the change. (Sure, you should hopefully have this tracked in your bug tracker as well / instead, but we all know that's not always the case.)

It's also really nice that our entire team always knows exactly what the name is, so we're always on the same page when referring to a sprint or branch. (There's never any confusion of "Is 'badger' this week's release or last week's?".)

In my opinion, using numbers for the name doesn't really provide any value. For that matter, while it may be fun to do, neither do abstract names. Using goal-oriented names might be a nice addition (e.g. "2012-04-03: Updated customer widgets"), but I wouldn't go back to just using abstract names.

Title: How do you name sprints in your projects?

Body:
Some Scrum software management tools give you this option to explicitly name your sprints.

Do you have a preferred way of naming your sprints or do you just use a simple scheme like 1, 2, 3, ...?


答:
As far as books are concerned I think you'll struggle to find anything - I have most (all?) of the currently available F# books and did a very quick check without much success. Expert F# has about 10 pages on WPF, Beginning F# slightly more. The other books have a couple of mentions of WPF and that's about it.

So...your best bet is probably the series of blog posts by Don Syme (which I see Robert has already linked to in his answer).

Title: Anyone know of any resources for someone who wants to learn WPF and F#

Body:
It's easy to find resources for learning WPF, similarly it's pretty easy to find resources for F#. </p>

<p>But I feel that I could save some time if I could learn them both at the same time. So can anyone recommend any books, blogs, articles , something else? </p>

<p>(I'm familiar with functional programming, winforms and c#)  </p>


问:
Making money from a custom built interpreter?
I have been making considerable progress lately on building an interpreter.  I am building it from NASM assembly code (for the core engine) and C (cl.exe the Microsoft compiler for the parser).  I really don't have a lot of time but I have a lot of good ideas on how to build this so it appeals to a certain niche market.  I'd love to finish this but I need to face reality here ... unless I can make some good monetary return on my investment, there is not a lot of time for me to invest.  So I ask the following questions to anyone out there, especially those who have experience in monetizing their programs:

1)  How easy is it for a programmer to make good money from one design?  (I know this is vague but it will be interesting to  hear from those who have experience or know of others' experiences).

2)  What are the biggest obstacles to making money from a programming design?

3)  For the parser, I am using the Microsoft compiler (no IDE) I got from visual express, so will this be an issue?  Will I have to pay royalties or a license fee?

4)  As far as I know NASM is a 2-clause BSD licensed application.  So this should allow me to use NASM for commericial development unless I am missing something?

It's good to know these things before launching into the meat and potatoes of the project.

答: Your project seems like an ideal fit for http://www.kickstarter.com/. Design your kickstarter campaign to mirror a pre-order of your software, and advertise to your potential audience before you build the tool.</p>


答:
For each release we choose a big city codename alphabetically (e.g. Atlanta, Boston, Chicago, Dallas ...)

And some college names in that city become our sprint names (Morehouse, Spelman, ..., Harvard, Cambridge etc)


答: What you experienced is the exact reason that many experienced developers are very reluctant to jump on the "new technology" bandwagon. They would rather have the people like you to make the new technology functional, reliable and with a shelf life. In the meantime they spend their time working with established products getting their products delivered and making money, while the new adopters are kicking themselves for their wasted efforts as the new technology turns into a dud.</p>

Title: Approached to build app centered around new API and suddenly API is abandoned

Body:
This isn't a huge deal, but I was approached by colleagues/friends to build an app using their new API. There was some potential for pecuniary gain for me depending on app usage. I spent a considerable amount of time polishing the mobile app, based on my assumption that, having been approached in a serious way, that the company would not suddenly shift focus and abandon the API. I wasn't even given so much as a heads up that the API was dead even though I had an app in production that relied on it...

For the most part, building the app was a learning experience which I enjoyed, but I don't think I'd have expended all the effort if I knew that the company wasn't as serious about the API as their reaching out to me clearly indicated.

How, if at all, would you react?


答:
At least in my experience, the chances of making money are closely (and directly) related to the degree to which the tool is specialized. Generalized tools are a much more difficult place to make money.

Competition. There are so many excellent implementations of such good languages already available for free, that you need something that's substantially superior to anything else (within its niche) before you have any chance of making money at all. If you're developing a new interpreter for an existing language, the existing implementations are obviously competition. If you're developing a new language as well, you have to sell not only your implementation, but your new language as well. Failing to supply a full development stack (IDE, compiler, run-time library, debugging capability, etc.) adds even more to an already difficult task.

I'm not sure I follow. Do you mean you used Visual Studio Express to develop a parser than you compiled with their compiler, or do you mean you're actually using their compiler?

Yes, at least as I read it, NASM's license only places restrictions on re-distribution of NASM itself. Using NASM to assemble some code does not (as I read it) place that code under any restrictions from NASM's license at all.

As long as you read and follow the license agreement, chances of being sued by Microsoft strike me as minimal. As long as you're developing for Windows, you're basically helping them out, so they're unlikely to sue unless you do something blatantly and obviously wrong.

As far as stealing your ideas goes, chances are that if you start to make much money, somebody will at least try. Many software people don't like it/them, but about the only protection available against that is patents, assuming you have something that can be patented. Getting a patent doesn't really protect you directly though -- it just gives you a tool to protect yourself.

Title: Making money from a custom built interpreter?

Body:
I have been making considerable progress lately on building an interpreter.  I am building it from NASM assembly code (for the core engine) and C (cl.exe the Microsoft compiler for the parser).  I really don't have a lot of time but I have a lot of good ideas on how to build this so it appeals to a certain niche market.  I'd love to finish this but I need to face reality here ... unless I can make some good monetary return on my investment, there is not a lot of time for me to invest.  So I ask the following questions to anyone out there, especially those who have experience in monetizing their programs:

1)  How easy is it for a programmer to make good money from one design?  (I know this is vague but it will be interesting to  hear from those who have experience or know of others' experiences).

2)  What are the biggest obstacles to making money from a programming design?

3)  For the parser, I am using the Microsoft compiler (no IDE) I got from visual express, so will this be an issue?  Will I have to pay royalties or a license fee?

4)  As far as I know NASM is a 2-clause BSD licensed application.  So this should allow me to use NASM for commericial development unless I am missing something?

It's good to know these things before launching into the meat and potatoes of the project.


答:
You say that you're "not concerned about it being in demand from customers," but you should be very concerned about exactly that. How many customers are there that would be willing to pay for your work? How much would they be willing to pay? How will they find you and your product, or how will you find them? The answers to these questions exactly determine the answers to your other questions: How easy is it for a programmer to make good money from one design? and What are the biggest obstacles to making money from a programming design?

Take a look at mobile applications, for just one example. The iTunes App Store makes it easy for customers to buy and for developers to sell. Same with Google's Android Marketplace. There are a great many customers in both markets, but not many of them are willing to pay more than a few bucks per app. In general, it's not too hard for a competent developer to make some money on a project using these markets, but making a lot of money requires investing heavily in both development and marketing.

On the flip side, it's not hard to imagine a market where there are only a handful of customers, but the customers have deep pockets and are willing to pay handsomely for the right tool. Lots of businesses, especially small businesses, work on this model. To be successful in this realm, you need some real understanding of your customers, you need to be able to make contacts with those customers, and you need to show them clearly why they need your product. Without that, there is no demand and making money from your project will be exceedingly difficult.


问:
git, maven and jenkins - versioning, dev and release builds workflow
What is the preferred way to do the following with git, maven and jenkins:

I am developping an application, which I would like to maintain "dev" and "release" branches. I would like jenkins to build both. It could be so that the release-artifacts would have versions like 1.5.2 and the dev-builds would just be 0.0.1-SNAPSHOTs. I would like to not have to have 2 different pom.xml files.

I looked into profiles, but they don't seem to be able to change artifact versions. One way I looked at could be adding a 'qualifier' to the test-builds. Of course I could just rename the file, because the real artifact-information on this is not important, because the app is a standalone one.

What would be the preferred way to doing this? Or how would you do this?

答:
I would imagine there should be an inherent relationship between these branches that ought to address the problem of version numbers.

Releasing

I would envision you might do something like merge production-ready code from the dev branch to the release branch, then perform a Maven release (via Jenkins or manually). This automatically rolls the version numbers to the next build. So you merge code 1.4.7-SNAPSHOT to this branch, perform the release and cut version 1.4.7, and Maven automatically rolls your working copy to 1.4.8-SNAPSHOT.

Updating Baseline (optional)

If you're not already using your trunk (or baseline branch, etc) as a place for your releases, you should be updating the trunk as soon as you complete a release. This means your version numbers are getting updated as well. This step might be moot if you just consider the release branch to be the baseline.

Up-merge from Baseline to Dev Branch

It's essential that your development branch stay up to date with the actual production code. You need to merge the code from the baseline (or release branch, depending on implementation) up to your development branch. This is important in your case because it means the pom changes that occurred during the release process, which changed the version to 1.4.8-SNAPSHOT, are brought to this branch.

Based on reading I've done (as well as processes with in my organization), this seems to be a pretty standard and effective use of Maven releases and snapshots, and rather than maintaining completely disconnected version numbers on different branches, it's easy to tell that any 1.4.7-SNAPSHOT build was in fact an immediate predecessor of the 1.4.7 release. They're related. I would go so far as to say if you're not merging back and forth between these branches, you're doing both SCM and Maven versioning wrong, and you're putting yourself at risk for developing against code that doesn't match production, re-introduces bugs to production, etc.


问:
Best practices for team workflow with RoR/Github for designer + coder?
My friend and I have started to try to collaborate on some projects. For background, I come from a PHP/Wordpress/Drupal coding background, but recently I've become more experienced with the RoR framework, while he is more experienced as an HTML/CSS designer, working with PHP and WordPress.

We're both relatively new to RoR I think, and so we're trying to figure out our collaborative workflow, but we have no idea where to start.

For instance, we were trying to figure out how he could do some minor edits to the CSS file without having to do a full RoR deploy on his box. We still haven't figured out a solution, so I think it's best if we start to set some sort of workflow based on best practices.

I was wondering if you guys have any insight or links to articles/case studies regarding this topic?

答:
I'm not familiar with RoR, but as far as git goes I would start with the Pro Git book: http://progit.org/book/ which is free online or you can order a copy.

Once you are both comfortable with git you can work together online through https://github.com/ (if you don't mind the code being public - or you can pay for private repositories).

Don't be scared of branches either, they are a great feature, make as many as you want since they don't duplicate code by having them around.

OwnerDisplayName: Josh


问:
When does pair programming work? When to avoid it?
Rather than slavishly pair program all the time, we use pair programming selectively on our team. I think it works best in the following circumstances:

Ramping up brand new team members on a project (instead of letting them wade through documentation or code on their own).

Having junior and senior people work together (helps to show some of the skills and tricks of the more experienced developers, plus it allows the old dogs to learn new tricks sometimes).

When someone is trying to track down a defect, it often helps to pair with a fresh set of eyes.

When to use pair program and why?

When to avoid pair programming? Why?

答:
We have been experimenting with Pair programming in our team for the last few months. I feel its pretty useful when you are working on something new (new technology, new feature etc) as you can quickly bounce ideas with another person of the team and have them validated/invalidated. Also, a side by side peer review helps in keeping bugs out.

Another teammate tried using pair programming with a test to do ATDD and they were quite happy with the results (according to his calculations a increase in 20% dev cost led to a decrease of about 50% in test time)


问:
Achieving forward compatibility with C++11
I work on a large software application that must run on several platforms.  Some of these platforms support some features of C++11 (e.g. MSVS 2010) and some don't support any (e.g. GCC 4.3.x).  I expect this situation to continue for for several years (my best guess: 3-5 years).

Given that, I would like set up a compatibility interface such that (to whatever degree possible) people can write C++11 code that will still compile with older compilers with a minimum of maintenance.  Overall, the goal is to minimize #ifdef's as much as reasonably possible while still enabling basic C++11 syntax/features on the platforms that support them, and provide emulation on the platforms that don't.

Let's start with std::move().  The most obvious way to achieve compatibility would be to put something like this in a common header file:

```<code>#if !defined(HAS_STD_MOVE)
namespace std { // C++11 emulation
  template <typename T> inline T& move(T& v) { return v; }
  template <typename T> inline const T& move(const T& v) { return v; }
}
#endif // !defined(HAS_STD_MOVE)
</code>```

This allows people to write things like

```<code>std::vector<Thing> x = std::move(y);
</code>```

... with impunity.  It does what they want in C++11 and it does the best it can in C++03.  When we finally drop the last of the C++03 compilers, this code can remain as is.

However, according to the standard, it is illegal to inject new symbols into the std namespace.  That's the theory.  My question is: practically speaking is there any harm in doing this as a way of achieving forward compatibility?

答: This is fundamentally impossible. Consider std::unique_ptr<Thing>. If it was possible to emulate rvalue references as a library, it would not be a language feature.


答:
Rethink your approach.

It is very common to use e.g. 1.4.2 for a release version and then 1.4.3-SNAPSHOT for the development to the next.

When you need to maintain release 1.4.2 THEN branch it from the commit that originated your 1.4.2 artifact.

Then you tell Jenkins the location of your repository and the branch name, resulting in a file set being checked out, and then you tell Jenkins to use maven on your project to build it.

Note:  I've found that it is very beneficial to use a single pom.xml to build the actual artifact and another pom.xml to create the actual bits to go to the customer.

Title: git, maven and jenkins - versioning, dev and release builds workflow

Body:
What is the preferred way to do the following with git, maven and jenkins:

I am developping an application, which I would like to maintain "dev" and "release" branches. I would like jenkins to build both. It could be so that the release-artifacts would have versions like 1.5.2 and the dev-builds would just be 0.0.1-SNAPSHOTs. I would like to not have to have 2 different pom.xml files.

I looked into profiles, but they don't seem to be able to change artifact versions. One way I looked at could be adding a 'qualifier' to the test-builds. Of course I could just rename the file, because the real artifact-information on this is not important, because the app is a standalone one.

What would be the preferred way to doing this? Or how would you do this?


答:
I like the idea of @maple_shaft to represent different pieces (mini-cubes) differently: central, edge, and corner pieces carry 1, 2, or 3 colors, respectively.

I'd represent the relationships between them as a (bidirectional) graph, with edges connecting adjacent pieces. Each piece would have an array of slots for edges (connections): 4 slots in central pieces, 4 slots in edge pieces, 3 slots in corner pieces. Alternatively, center pieces may have 4 connection to edge pieces and 4 for corner pieces separately, and/or edge pieces may have 2 connection to center pieces and 2 to corner pieces separately.

These arrays are ordered so that iterating over graph edges always represent 'the same' rotation, modulo the cube's rotation. That is, e.g. for a center piece, if you rotate the cube so that its face is on top, the order of connections is always clockwise. Similarly for edge and corner pieces. This property holds after face rotations (or so it seems to me now).

Finding pieces belonging to an edge is trivial.

Finding pieces belonging to a face is trivial.

Finding faces that are at given direction to given face, or an opposite face, is traversing 2 or 3 well-defined links.

To rotate a face, update connections of all pieces connected to the face's central piece.

Detection of clearly unsolvable conditions (swapped/flipped edges, swapped corner) if hopefully easy, too, because finding pieces of particular type and their orientation is simple.


问:
I'm going to quit my job because of our platform: how can I leave a productive explanation of this?
I'm planning on leaving my current job because we're locked into using Blub, with an enterprise Blub framework and a Blub-level web server, on mediocre shared hosting. My coworkers are friendly and my boss is an average small business owner - I want to leave entirely because of the technical reasons. I feel like being soaked in Blub is bad for my brain and making me a worse programmer.

When I leave, how can I explain this to my boss and coworkers? How can I phrase my complaints about Blub productively? What kind of warning can I and should I leave for my successor in documentation?

(trying to make sure I meet the standards)

答:
This happens and the fact is we are living in a very "non-blub" world anymore. In addition due to the explosion in the non-blub technology field you have options so I'd say you're safe.

What I do caution, however, is fooling yourself into believing this is the primary reason, you're unhappy, and trying to make others believe that.

That's a very silly reason to quit much less an argument point with any hope of foreseeing a change.

Don't tell your boss that's the reason. Make it a standard blurb "Career move." And just know that if you are having difficulty now, don't expect to be happy elsewhere. There is always going to be some sort of annoying ridiculous issue programmers have with their jobs, because it's our jobs to point out problems and find solutions.

Good Luck!


问:
Continuous integration - build Debug and Release every time?
Is it standard practice when setting up a Continuous Integration server to build a Debug and Release version of each project?  Most of the time developers code with a Debug mode project configuration set enabled and there could be different library path configurations, compiler defines, or other items configured differently between Debug/Release that would cause them to act differently.

I configured my CI server to build both Debug & Release of each project and I'm wondering if I'm just overthinking it.  My assumption is that I'll do this as long as I can get quick feedback and once that happens, then push the Release off to a nightly build perhaps. Is there a 'standard' way of approaching this?

答:
It depends on your project. In my current project we only build debug (and run unit tests) on every commit while we do build release version as part of the "deployment build".

At the last company I worked we had a few issues with release version working a bit differently so we did build debug and release on every commit and run unit tests on both.


答:
It depends on the quality of the blog. Same for a authoring a book.

When I interview candidates, if they have a blog, I take a look. The content of the blog directly effects the bias I have towards the candidate.

Title: Is mentioning my blog on my resume helpful or hurtful to a job search?

Body:
I have a blog that I use mostly to record solutions to problems I have had, that I had some trouble finding an answer to. Mostly problems where the online doc I googled provided too much info, and I found the answer to my question on the fifth page of my third google hit.

(Or if I asked the question here, I either didn't get an answer or I got slammed for asking a question that "the answer could be easily googled.")

I frequently look up stuff on this blog to remind myself of how I solved a problem, and it gets a decent amount of hits from others as well.

Anyway, I was wondering if mentioning this blog on my resume would help or hurt me in a job search? The topics are all over the map.

What I would hope it shows is that

I am a person who finds solutions to problems

I have used many different technologies in my work

I am not afraid to tackle a challenge

What I am concerned it shows is that

This person had trouble with something that simple?

Why is this person bothering to blog this stuff?


答:
Release only.

Assume the developers are doing debug builds anyway and the worst bugs are the 'it works in debug' ones.   The quicker you can spot those and narrow down the changes that may have caused them the happier everyone will be!

Title: Continuous integration - build Debug and Release every time?

Body:
Is it standard practice when setting up a Continuous Integration server to build a Debug and Release version of each project?  Most of the time developers code with a Debug mode project configuration set enabled and there could be different library path configurations, compiler defines, or other items configured differently between Debug/Release that would cause them to act differently.

I configured my CI server to build both Debug & Release of each project and I'm wondering if I'm just overthinking it.  My assumption is that I'll do this as long as I can get quick feedback and once that happens, then push the Release off to a nightly build perhaps. Is there a 'standard' way of approaching this?


问:
Interfaces: profit of using
First of all, my ubiquitous language is PHP, and I'm thinking about learning Java.

So let me split my question on two closely related parts.

Here goes the first part.

Say I have a domain-model class. It has some getters, setters, some query methods etc. And one day I want to have a possibility to compare them. So it looks like:

```<code>class MyEntity extends AbstractEntity
{
    public function getId()
    {
        // get id property
    }

    public function setId($id)
    {
        // set id property
    }

    // plenty of other methods that set or retrieve data

    public function compareTo(MyEntity $anotherEntity)
    {
        // some compare logic
    }
}
</code>```

If it would have been Java, I should have implemented a Comparable interface. But why? Polymorphism? Readbility? Or something else? And if it was PHP -- should I create Comparable interface for myself?

So here goes the second part.

My colleague told me that it is a rule of thumb in Java to create an interface for every behavioral aspect of the class. For example, if I wanted to present this object as a string, I should state this behaviour by something like implements Stringable, where in case of PHP Stringable would look like:

```<code>interface Stringable
{
    public function __toString();
}
</code>```

Is that really a rule of thumb? What benefits are gained with this approach? And does it worth it in PHP? And in Java?

答:
From my experience, these are the top points I would go for interfaces during my coding.

- Interfaces can make the code flexible by acting as a contract
    between the implementations.

```<code>Stringable string =new StringFromMe();
</code>```

Then, later, if you decide that you want to use a different kind of string (maybe there's another library, with a better kind of string ), you switch your code to:

```<code>Stringable string =new OtherKindOfString();
</code>```

the reason is, for example, if you want to create a list of strings and perform some operation on each one, but you want the list to contain different kinds of Strings. On each string you could do:

```<code>**string .toString()**
</code>```

Or You can pass the both types of strings to a method which takes the common interface type.

```<code>dosomething(Stringable string)
</code>```

This concept is also called as polymorphism.

-  Ease of unit testing/ mocking.

For example, Your string needs some data from database to computer the toString ( just assume for the sake of explanation)  which makes the code not unit testable. Now you can provide a simple implementation of the string

```<code>**Stringable string =new TheDummyStringWithoutDBConnection();**
</code>```

Then you can go ahead with your unit testing of other parts of the code so the unit tests are not dependent on the database or any other external systems per se.

Title: Interfaces: profit of using

Body:
From my experience, these are the top points I would go for interfaces during my coding.

- Interfaces can make the code flexible by acting as a contract
    between the implementations.

Stringable string =new StringFromMe();

Then, later, if you decide that you want to use a different kind of string (maybe there's another library, with a better kind of string ), you switch your code to:

Stringable string =new OtherKindOfString();

the reason is, for example, if you want to create a list of strings and perform some operation on each one, but you want the list to contain different kinds of Strings. On each string you could do:

**string .toString()**

Or You can pass the both types of strings to a method which takes the common interface type.

dosomething(Stringable string)

This concept is also called as polymorphism.

-  Ease of unit testing/ mocking.

For example, Your string needs some data from database to computer the toString ( just assume for the sake of explanation)  which makes the code not unit testable. Now you can provide a simple implementation of the string

**Stringable string =new TheDummyStringWithoutDBConnection();**

Then you can go ahead with your unit testing of other parts of the code so the unit tests are not dependent on the database or any other external systems per se.


答:
I would strongly recommand to build and test both if it can be done in one night.

you may detect some heisenbugs

you make sure that your client will get the behavior you have tested and validated


答:
In my opinion, the main points of interfaces are abstraction and type-safety. Implementing an interface forces you to expose some functionality to others, while other components do not need to know about your specific type and its implementation.

For example, a generic sorting algorithm can expect a list of objects implementing the Comparable interface. This way, the algorithm does not need to know about the implementation detail of entities, list items, or whatever you want to sort. But by definition, items implementing the Comparable interface must provide a certain functionality which the sort algorithm can rely on.

Interfaces are a good way to decrease coupling in your architecture, but you shouldn't overuse them because this can reduce the maintainability and readability of your code due to the level of abstraction. If the functionality of classes implementing an interface is very similar, think about a common base class.

In one of our projects, we have a runtime which can host several services which do whatever they want to do. Because our runtime needs to manage those services, it requires the services to implement the interface IRuntimeService with methods like Start or Stop. This way, the runtime can host and manage every possible service, as long it implements this interface. This example might give you an idea about why interfaces can be very useful.

I'm sorry that I can't tell you much about PHP, because I did not do much OOP there.

Title: Interfaces: profit of using

Body:
First of all, my ubiquitous language is PHP, and I'm thinking about learning Java.

So let me split my question on two closely related parts.

Here goes the first part.

Say I have a domain-model class. It has some getters, setters, some query methods etc. And one day I want to have a possibility to compare them. So it looks like:

```<code>class MyEntity extends AbstractEntity
{
    public function getId()
    {
        // get id property
    }

    public function setId($id)
    {
        // set id property
    }

    // plenty of other methods that set or retrieve data

    public function compareTo(MyEntity $anotherEntity)
    {
        // some compare logic
    }
}
</code>```

If it would have been Java, I should have implemented a Comparable interface. But why? Polymorphism? Readbility? Or something else? And if it was PHP -- should I create Comparable interface for myself?

So here goes the second part.

My colleague told me that it is a rule of thumb in Java to create an interface for every behavioral aspect of the class. For example, if I wanted to present this object as a string, I should state this behaviour by something like implements Stringable, where in case of PHP Stringable would look like:

```<code>interface Stringable
{
    public function __toString();
}
</code>```

Is that really a rule of thumb? What benefits are gained with this approach? And does it worth it in PHP? And in Java?


答:
Having MyEntity implement Comparable<MyEntity> allows you to use Collections.sort(...), and any other operation that acts on Comparable. From the doc:

Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.

Using the MyEntity parameter on Comparable simplifies your compareTo method in that you don't need to do any type checking or casting in your code.

```<code>public int compareTo(MyEntity other) {
    if (other == null) return -1;
    return getSomeProperty().compareTo(other.getSomeProperty());
}
</code>```

If you ever need to sort on someOtherProperty, you can do so easily:

```<code>List<MyEntity> entityList = someService.getEntities();
Collections.sort(entityList, new Comparator<MyEntity>()
{
    public int compare(MyEntity e1, MyEntity e2)
    {
        if(e1 == null) return e2 == null ? 0 : 1;
        if(e2 == null) return -1;
        return e1.getSomeOtherProperty().compareTo(e2.getSomeOtherProperty());
    }
});
</code>```

Title: Interfaces: profit of using

Body:
Having MyEntity implement Comparable<MyEntity> allows you to use Collections.sort(...), and any other operation that acts on Comparable. From the doc:

Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.

Using the MyEntity parameter on Comparable simplifies your compareTo method in that you don't need to do any type checking or casting in your code.

public int compareTo(MyEntity other) {
    if (other == null) return -1;
    return getSomeProperty().compareTo(other.getSomeProperty());
}

If you ever need to sort on someOtherProperty, you can do so easily:

List<MyEntity> entityList = someService.getEntities();
Collections.sort(entityList, new Comparator<MyEntity>()
{
    public int compare(MyEntity e1, MyEntity e2)
    {
        if(e1 == null) return e2 == null ? 0 : 1;
        if(e2 == null) return -1;
        return e1.getSomeOtherProperty().compareTo(e2.getSomeOtherProperty());
    }
});


问:
How do you track bugs in your personal projects?
I'm trying to decide if I need to reassess my defect-tracking process for my home-grown projects.  For the last several years, I really just track defects using TODO tags in the code, and keeping track of them in a specific view (I use Eclipse, which has a decent tagging system).

Unfortunately, I'm starting to wonder if this system is unsustainable.  The defects I find are typically associated with a snippet of code I'm working on; bugs which are not immediately understood tend to be forgotten, or ignored.  I wrote an application for my wife which has had a severe defect for almost 9 months, and I keep forgetting to fix it.

What mechanism do you use to track defects in your personal projects?  Do you have a specific system, or a process for prioritizing and managing them?

答: Fogbugz (free individual license) if its a longish project or a simple to do list (using Google tasks)</p>


答:
Interfaces add a layer of abstraction to your code. (like a seam). It means you can then change concrete implementations in dependent classes without breaking your existing code. Its great for decoupling code and makes things like unit testing feasible.

My colleague told me that it is a rule of thumb in Java to create an
  interface for every behavioral aspect of the class.

He is wrong. There are plenty of use cases where there is no point implementing interfaces. Often its better to go with the KISS approach.  Interfaces add complexity and for small simple classes/applications it may not be worth it.

You should be using interfaces to achieve something (ie implementing a pattern or for unit testing) just blindly implementing something "because its good" will only lead to code bloat

Title: Interfaces: profit of using


答: In PHP, you do not have rigid type controls like in Java. So in many cases where you had to use interfaces in Java you can use something like is_callable in PHP. PHP does not have compile-time type enforcement, which means you don't gain as much by defining a lot of interfaces, so I would use an interface in cases where there's a non-trivial functionality behind it. E.g., if you wanted to express a file functionality - having open, close, read, write, etc. - you may want an interface. If however you want just one function having an interface may be an overkill.

Title: Interfaces: profit of using


问:
Is there a term for quasi-open source proprietary software?
Say a company wants to keep development of new features of a piece of software internal, but wants to make the source code for previous versions public, up to and including existing public features, so that other people can benefit from using and modifying the software themselves, and even possibly contribute changes that can be applied to the development branch.

Is there a term for this sort of arrangement, and what is the best way of accomplishing it using existing version control tools and platforms?

答:
I don't know the name but for implementation following setup might work: </p>

<p>Create two repos on github (replace with any other platform doing the same), one public, one private. Keep latest version X in private one, and v.X-1 on public one. When releasing new version, update public one from private one. This way you will be able to easily use version control, and also allow users of public repo send you their contributions via pull requests, and then be able to merge it to you private repo, submit issues, etc. This also will give you the options to allow paid users to do the same for your private code - give them either read-only or even read-write access. </p>

Body:
I don't know the name but for implementation following setup might work:

Create two repos on github (replace with any other platform doing the same), one public, one private. Keep latest version X in private one, and v.X-1 on public one. When releasing new version, update public one from private one. This way you will be able to easily use version control, and also allow users of public repo send you their contributions via pull requests, and then be able to merge it to you private repo, submit issues, etc. This also will give you the options to allow paid users to do the same for your private code - give them either read-only or even read-write access.


问:
Which is a better design pattern for a database wrapper: Save as you go or Save when you're done?
I know this is probably a bad way to ask this question. I was unable to find another question that addressed this.

The full question is this: We're producing a wrapper for a database and have two different viewpoints on managing data with the wrapper.

The first is that all changes made to a data object in code must be persisted in the database by calling a "save" method to actually save the changes. The other side is that these changes should be save as they are made, so if I change a property it's saved, I change another it's save as well.

What are the pros/cons of either choice and which is the "proper" way to manage the data?

To provide more information, we're using Node.js, and we're writing our own wrapper for Neo4j because we feel that the current one available is not complete, or have run into issues where we need more functionality. That being said, an example of the save as you go method (these examples are in Javascript):

```<code>// DB is defined as a connection to the database via HTTP(REST)
// "data" being an object that would represent new data
var node;
db.getNodeById(data.id, function(err, result) {
  node = result;
  // This function task an optional callback as a third parameter because in
  // in addition to setting the property on the "node" object it saves the
  // new value to the database by making an HTTP request.
  node.set("firstName", data.newFirstName);
  // auto saved as well
  node.set("lastName", data.newLastName);
  // end here as the node has already been updated with your changes.
});
</code>```

And the opposing example would be:

```<code>// DB is defined as a connection to the database via HTTP(REST)
// "data" being an object that would represent new data
var node;
db.getNodeById(data.id, function(err, result) {
  node = result;
  // This changes the value for the node object only, nothing in the
  // database is changed.
  node.set("firstName", data.newFirstName);
  node.set("lastName", data.newLastName);
  // Save all your changes
  node.save();
});
</code>```

答:
If you need transactions in your application, you will need to offer some kind of explicit "Save" option.   If the applications don't need transactions, using a database (as opposed to, say, a NoSQL technology) may be redundant.

This also means that the "Save" operation should not be a method called on the mutated object.   It should be a method on the transaction object, or the session.


答:
I don't know of a term for this.

Perhaps it should the called the Padlocked Barn Door model.  Instead of "shutting the barn door after the horse has bolted" (i.e. attempting to regain exclusivity after releasing software under a too-liberal license), you padlock the barn door and hope that the horse doesn't die of starvation in the stable.  :-)

Seriously though, if the company management thinks that this is needed to make a buck from open source, you can't really argue.  After all, they are responsible for managing the resource investment they are making.

However this is not a model that is good for the paying customer.  (If the customer can't get source code for the premium version he / she is running, what it the point of paying the premium?)  It is not likely to encourage contributions from the user community, and is going to make those contributions of less value ... because they will always be against an old version of the codebase.  Indeed, you could argue that it is more likely to encourage forking.

Title: Is there a term for quasi-open source proprietary software?

Body:
Say a company wants to keep development of new features of a piece of software internal, but wants to make the source code for previous versions public, up to and including existing public features, so that other people can benefit from using and modifying the software themselves, and even possibly contribute changes that can be applied to the development branch.

Is there a term for this sort of arrangement, and what is the best way of accomplishing it using existing version control tools and platforms?


答:
I'd go for explicitly calling the save() method.  Otherwise you'll get redundant saves when you don't need them. What if you have some sort of "onKeyUp" event.  Do you really want to save as the user is typing each character? You'd be locked into that model.

In a multi-tiered app it's good for the code to be "aware" of the tier it's on. You don't need to hide it by having a bunch of state saving magic going on behind the scenes. Why is being "aware" good? Because hiding it is obfuscating how it works, not abstracting. (my opinion).

On another topic...... instead of Node.save(); use save(Node n); Actually save could still be a method of an object, just not the Node object. Why? Saving is not something that a node does. And this functionality literally is different depending on which tier your on, suggesting it's a behavior of the tier, not the node.

For example lets say you have Node.Draw(); This method doesn't even make sense on the serverside. Instead do something like GameBoard.Draw(Node n);

I'm probably getting too far off topic, but that's my 2 cents.

Title: Which is a better design pattern for a database wrapper: Save as you go or Save when you're done?

Body:
I know this is probably a bad way to ask this question. I was unable to find another question that addressed this.

The full question is this: We're producing a wrapper for a database and have two different viewpoints on managing data with the wrapper.

The first is that all changes made to a data object in code must be persisted in the database by calling a "save" method to actually save the changes. The other side is that these changes should be save as they are made, so if I change a property it's saved, I change another it's save as well.

What are the pros/cons of either choice and which is the "proper" way to manage the data?

To provide more information, we're using Node.js, and we're writing our own wrapper for Neo4j because we feel that the current one available is not complete, or have run into issues where we need more functionality. That being said, an example of the save as you go method (these examples are in Javascript):

```<code>// DB is defined as a connection to the database via HTTP(REST)
// "data" being an object that would represent new data
var node;
db.getNodeById(data.id, function(err, result) {
  node = result;
  // This function task an optional callback as a third parameter because in
  // in addition to setting the property on the "node" object it saves the
  // new value to the database by making an HTTP request.
  node.set("firstName", data.newFirstName);
  // auto saved as well
  node.set("lastName", data.newLastName);
  // end here as the node has already been updated with your changes.
});
</code>```

And the opposing example would be:

```<code>// DB is defined as a connection to the database via HTTP(REST)
// "data" being an object that would represent new data
var node;
db.getNodeById(data.id, function(err, result) {
  node = result;
  // This changes the value for the node object only, nothing in the
  // database is changed.
  node.set("firstName", data.newFirstName);
  node.set("lastName", data.newLastName);
  // Save all your changes
  node.save();
});
</code>```


答:
Building both configurations won't hurt, but if you have to choose (especially due to build time constraints) then build the Release configuration.

You ultimately want to build, test, package and deploy the configuration that your customers will be using and find any issues with it before they do.


问:
What software development model has worked best for software teams with heavy dependancy on hardware teams?
There are a number of competing best practices for software development. From what I have found, many teams have benefited from Agile practices in some cases. However, in some other cases, using the Unified Process has been championed by large companies like IBM.

The common themes that I find seemed to work well for teams that mainly develop software.

I am interested to know what has worked best for people who have worked in shops where there is a team on the other side that produce the hardware that your software is running on. For example, one team puts together a crate with several custom hardware on it; while you need to develop the software that would run on those crates. I can't find a development model (agile, spiral ...) that works best in this case.

Any wisdom is this area will be well appreciated.

答:
One of Agile's main tenants is "fail early". With hardware, this couldn't be more true. Mass producing hardware is extremely expensive. Moreover, physical hardware cannot simply be "patched" like software can. Exacerbating these problems, hardware teams tend to be less customer facing then software teams in practice, and tend to be used to the "big bang" model of development.

For these reasons not catching hardware problems as soon as possible is typically orders-of-magnitudes more expensive then failing to catch software issues early. Customers expect to require software updates, they may stop working with you entirely if they have to deal with a hardware recall.

In short, not expecting and preparing for hardware problems early is a development model's single biggest challenge when developing software and hardware in parallel.

You absolutely must anticipate failure. Get a prototype early. Use the prototype to develop against. Expect it to be a failure. Learn from the failure. Rinse. Repeat. Make sure its expected by everyone that the hardware prototypes are to be revised/critiqued/redesigned based on feedback from stakeholders.


答:
It sounds like Shared Source which is a term used by Microsoft to describe the way they allow customers to get a copy of their source code for reasons like security auditing or reference. Microsoft retains full control of the codebase for new development.

The licenses associated with the offerings range from being closed-source, allowing only viewing of the code for reference, to allowing it to be modified and redistributed for both commercial and non-commercial purposes.


答:
I am probably biased, having worked more on the hardware side of large software-hardware product development teams.  Hardware can be very costly to revise if it's architected or designed wrong.  Often an error in the hardware design is so costly it means canceling the entire project.  Fixing a chip mask error can cost more than the annual salary of dozens of engineers.  So I see the primary purpose of the software team for the first 50%+ of the development cycle is to make sure the hardware team does not fail.  This may mean forgetting about the final application code and it's design at first, and just working on hardware architectural and performance simulations, tools to help the hardware team complete and verify their design, and code to test and exercise all the various necessary components of the earliest partially functionally hardware prototypes.

Expect to be agile, not only about the customer spec, but also about various surprising quirks/bugs in the hardware platform, where a software workaround may have far less impact on the schedule than a hardware spin.

Title: What software development model has worked best for software teams with heavy dependancy on hardware teams?

Body:
There are a number of competing best practices for software development. From what I have found, many teams have benefited from Agile practices in some cases. However, in some other cases, using the Unified Process has been championed by large companies like IBM.

The common themes that I find seemed to work well for teams that mainly develop software.

I am interested to know what has worked best for people who have worked in shops where there is a team on the other side that produce the hardware that your software is running on. For example, one team puts together a crate with several custom hardware on it; while you need to develop the software that would run on those crates. I can't find a development model (agile, spiral ...) that works best in this case.

Any wisdom is this area will be well appreciated.


答:
It really depends on how your hardware team will deliver useful artifacts that your software team can use to develop against, and how the teams are set up to communicate with each other.

Typically, you'll find the hardware team will build a product, get it to a prototype stage for testing, and only then will the software team get any sort of requirements documentation from the hardware team. Needless to say this isn't always the best way to go, as the software is usually developed very late in the process, and you generally find yourself with little choice but to work with a waterfall-based methodology. On the upside from the hardware team's point of view, if they suddenly need to change something, the software team won't need to modify their software.  The problem here of course is that your average hardware guy needs to develop products in this way, and expects that anything that will benefit him with help out the software team.

As an alternative, if your hardware team is building a product and updating the software requirements as they go, and even better, if they involve the software team early on as each hardware feature is being planned and simulated, then you have the opportunity for the software team to work in a much more Agile manner.  Naturally by this I mean that the hardware team is the customer, and gives the software team a list of problems that need to be solved in software. The software team can discuss with their customer the relative priorities of each requirement, and as soon as the hardware prototype is ready, the software will likely be available in an early release form, and can be used to help in testing the hardware. If the requirements change, the software team will hopefully have the agility to change the software as they go, and can provide early feedback to the hardware team before the hardware design is committed to prototype. The software team also have direct access to the customer very early in the project, which means that they can get a better idea about what they need to mock out - and how to do it - while waiting for hardware to test against.

Realistically, you won't find an ideal methodology that just fits off the shelf, and I can guarantee that you will have a lot of tweaking to do no matter which methodology you choose to adopt, or develop.  The real issue is that you want to try and make the synchronization between the teams easy to manage, and means that you need to find a way to increase the amount of contact and input between the two teams as early as you can in the process, even if it seems "wasteful" or "counter-intuitive" to do so. This is a big problem in the company that I am presently working with. Our European "parent" is struggling with this exact problem, while the team here in Oz seems to be able to keep things running a little more smoothly, and it's really all due to giving the software team more involvement early in the design and simulation stages of the hardware development.


问:
Why do HDFS clusters have only a single NameNode?
I'm trying to understand better how Hadoop works, and I'm reading

The NameNode is a Single Point of Failure for the HDFS Cluster. HDFS is not currently a High Availability system. When the NameNode goes down, the file system goes offline. There is an optional SecondaryNameNode that can be hosted on a separate machine. It only creates checkpoints of the namespace by merging the edits file into the fsimage file and does not provide any real redundancy. Hadoop 0.21+ has a BackupNameNode that is part of a plan to have an HA name service, but it needs active contributions from the people who want it (i.e. you) to make it Highly Available.

from http://wiki.apache.org/hadoop/NameNode

So why is the NameNode a single point of failure? What is bad or difficult about having a complete duplicate of the NameNode running as well?

答: The NameNode keeps track of what data is stored where. If it goes down, the data still exists, but it's impossible to find. It's a single point of failure because Hadoop does not support having two of them running cooperatively. Just having a secondary NameNode running isn't enough to provide high availability because there is no way to ensure consistency when the main one goes down (the secondary NameNode may be missing recent changes).</p>


问:
Submitting software to a competition, it becomes their property?
So I'm about to submit a game to a competition, but as I looked through the rules a chunk grabbed my attention:

All Entries become the sole and exclusive property of Sponsor and will not be acknowledged or returned. Sponsor shall own all right, title and interest in and to each Entry, including without limitation all results and proceeds thereof and all elements or constituent parts of Entry (including without limitation the Mobile App, the Design Documents, the Video Trailer, the Playable and all illustrations, logos, mechanicals, renderings, characters, graphics, designs, layouts or other material therein) and all copyrights and renewals and extensions of copyrights therein and thereto.  Without limitation of the foregoing, each Eligible Entrant shall and hereby does absolutely and irrevocably assign and transfer all of his or her right, title and interest in his or her Entry to Sponsor, and Sponsor shall have the right and may authorize others to use, copy, sublicense, transmit, modify, manipulate, publish, delete, reproduce, perform, distribute,  display and otherwise exploit the Entry (and to create and exploit derivative works thereof) in any manner, including without limitation to embody the Entry, in whole or in part, in apps and other works of any kind or nature created, developed, published or distributed by Sponsor and to and register as a trademark in any country in Sponsor’s name any component of the Entry, without such Eligible Entrant reserving any rights or claims with respect thereto.  Sponsor shall have the exclusive right, in perpetuity, throughout the Territory to change, adapt, modify, use, combine with other material and otherwise exploit the Entry in all media now known or hereafter devised and in any manner, in its sole and absolute discretion, without the need for any payment or credit to Entrant.

So the game will become the sponsor's property; however, they don't ask for source code. So will I still own the rights to the source code, whatever that means? And if it doesn't win said competition, will I be able to publish it myself without their trademarks? I am very new to software legality stuff, so I would appreciate any clarification.

Since there's a possibility I won't even own the source, is it possible to make the game core engine open source software with a not-very-restrictive license and include that in the project, so I at least still own the game engine? Or does it not work that way?

答:
You need a lawyer...

But it certainly sounds like it becomes their property in the entirety. If you've spent a lot of time developing this game I would question wisdom of submitting it unless you are happy to loose all rights to it.

You need a lawyer...

Edit re needing a lawyer:

Lots of advice saying a lawyer is unnecessary based on cost. Whilst probably true, surely that depends on a number of things:

the value of the competition vs the amount of time invested in the game

the country you are living/the competition is being held. It may contravene local copyright laws and is therefore invalid irrespective of what it says

the cost of the lawyer. Many countries have free legal advice services of one kind or another. So it might not cost anything, other than a couple of hours at the legal service.


答:
I'm not sure you'd even still own the source code any more -- it looks to me like if they want it, they can probably demand it. In any case, they have all rights to the game itself, so even if you don't turn the source code over to them, you can't use it in any way without their permission.

If it were my game, I wouldn't bother with a lawyer -- I wouldn't need to pay anybody for advice to stay a long ways away from this one.

Title: Submitting software to a competition, it becomes their property?

Body:
So I'm about to submit a game to a competition, but as I looked through the rules a chunk grabbed my attention:

All Entries become the sole and exclusive property of Sponsor and will not be acknowledged or returned. Sponsor shall own all right, title and interest in and to each Entry, including without limitation all results and proceeds thereof and all elements or constituent parts of Entry (including without limitation the Mobile App, the Design Documents, the Video Trailer, the Playable and all illustrations, logos, mechanicals, renderings, characters, graphics, designs, layouts or other material therein) and all copyrights and renewals and extensions of copyrights therein and thereto.  Without limitation of the foregoing, each Eligible Entrant shall and hereby does absolutely and irrevocably assign and transfer all of his or her right, title and interest in his or her Entry to Sponsor, and Sponsor shall have the right and may authorize others to use, copy, sublicense, transmit, modify, manipulate, publish, delete, reproduce, perform, distribute,  display and otherwise exploit the Entry (and to create and exploit derivative works thereof) in any manner, including without limitation to embody the Entry, in whole or in part, in apps and other works of any kind or nature created, developed, published or distributed by Sponsor and to and register as a trademark in any country in Sponsor’s name any component of the Entry, without such Eligible Entrant reserving any rights or claims with respect thereto.  Sponsor shall have the exclusive right, in perpetuity, throughout the Territory to change, adapt, modify, use, combine with other material and otherwise exploit the Entry in all media now known or hereafter devised and in any manner, in its sole and absolute discretion, without the need for any payment or credit to Entrant.

So the game will become the sponsor's property; however, they don't ask for source code. So will I still own the rights to the source code, whatever that means? And if it doesn't win said competition, will I be able to publish it myself without their trademarks? I am very new to software legality stuff, so I would appreciate any clarification.

Since there's a possibility I won't even own the source, is it possible to make the game core engine open source software with a not-very-restrictive license and include that in the project, so I at least still own the game engine? Or does it not work that way?


问:
Secure Open Source?
I want to make a delicate application of mine (an antivirus actually) open source but I want to have a control on who really obtains the source or not. Preferably they should apply and I or administrators approve their applications. Is there any online platform for this?

The main reason for the control/security is to possibly prevent malware makers to easily discover how to bypass the stealth checking methods it utilizes for malware detection.

Edit: I am looking for advice - possibly to hear from someone who has done something similar.

Thanks!

答:
Probably you want to take a look at GitHub's Micro/Small/Medium account, which allows you to have private repositories; and you have the control on selecting who can access to your repository.
See https://github.com/plans for details.

(Note that this private repository hosting service is not free. However, if you are a teacher/student, you can always apply for the free plan, click here https://github.com/edu)

Title: Secure Open Source?


答:
The way I read that, they're demanding All Rights to Everything, including all copyrights.  I am not a lawyer, but I can't see any way to construe that as NOT including the source code.

It is your call, to consult an attorney, or not.  If it were my game, and I wanted to keep any rights to it, I would not spend the money to have an attorney tell me what I am already pretty sure of.