答:
I got a degree in computer systems engineering, so I did study assembly, microprocessors, VHDL, what the logic gates are and how to create a flip-flop out of them, I studied electrical circuits, operational amplifiers, low-pass filters, amplitude modulation, built a circuit in a lab that would sound like a telephone keypad, messed with a logic analyzer, took some physics classes. On the Linux side - I recompiled a kernel before, wrote a tiny device driver, and a homework file system.

But then I realized that I like more high-level stuff a lot more. I prefer Python over C. I like C# and I love the garbage collector. I like math and algorithms and data structures, but I am not a particular fan of pointers - I can mess with them; I just do not want to.

So, you think that the university should teach more C, less Java. Someone else thinks that they should teach everything in Scheme. Spolsky will take both.

Yes, it is true that a university degree is merely a piece of paper, but "do not let schooling get in the way of your education". There is always Wikipedia, Stack Overflow, Coursera.org, etc. Looks like the traditional universities will become less important.

If I could do undergrad all over, then I would have gone to a different school, I would not have studied any of the electrical engineering stuff, but rather Math, CS + minor in Physics and French. Scratch French; I should have studied abroad in Switzerland and learned 5 natural languages while at it. I would also go back and find a person who convinced me that I absolutely must take some intro to economics classes in college in order to survive it in the real world and smack him on the head with my collection of Milton Friedman's books (the only few books on the subject of economics that I read which do not suck). I also would not pay money for the book Freakonomics 1 or a book about Perl language.

In a hindsight, I would have done many things differently. All I can do now, and I recommend this to you, is choose your own adventure: http://www.codinghorror.com/blog/2008/03/choosing-your-own-adventure.html

Having hindsight I would have made 100 billion dollars on the stock market by now, and I would have invested it in cancer research, I would have hired scientists to rid the world of plastic waste; I would have donated enough cash to Ron Paul campaign so that the war in Middle East would be over 3 years ago.

Recognize now that you will never get your time back, so try to spend it wisely.

Title: Why is Java the lingua franca at so many institutions?

Body:
EDIT: This question at first seems to be bashing Java, and I guess at this point it is a bit. However, the bigger point I am trying to make is why any one single language is chosen as the one end all be all solution to all problems. Java happens to be the one that's used so that's the one I had to beat on here, but I'm not intentionality ripping Java a new one :)

I don't like Java in most academic settings. I'm not saying the language itself is bad -- it has several extremely desirable aspects, most importantly the ability to run without recompilation on most any platform. Nothing wrong with using the language for Your Next App ^TM. (Not something I would personally do, but that's more because I have less experience with it, rather than it's design being poor)

I think it is a waste that high level CS courses are taught using Java as a language. Too many of my co-students cannot program worth a damn, because they don't know how to work in a non-garbage-collected world. They don't fundamentally understand the machines they are programming for. When someone can work outside of a garbage collected world, they can work inside of one, but not vice versa. GC is a tool, not a crutch. But the way it is used to teach computer science students is a as a crutch.

Computer science should not teach an entire suite of courses tailored to a single language. Students leave with the idea that all good design is idiomatic Java design, and that Object Oriented Design is the ONE TRUE WAY THAT IS THE ONLY WAY THINGS CAN BE DONE. Other languages, at least one of them not being a garbage collected language, should be used in teaching, in order to give the graduate a better understanding of the machines.

It is an embarrassment that somebody with a PHD in CS from a respected institution cannot program their way out of a paper bag.

What's worse, is that when I talk to those CS professors who actually do understand how things operate, they share feelings like this, that we're doing a disservice to our students by doing everything in Java. (Note that the above would be the same if I replaced it with any other language, generally using a single language is the problem, not Java itself)

In total, I feel I can no longer respect any kind of degree at all -- when I can't see those around me able to program their way out of fizzbuzz problems.

Why/how did it get to be this way?


问:
What's the benefit of a singleton over a class in objective-c?
They both seem to take about the same amount of effort to use:

Singleton: needs a .h and .m file, has to be imported into any class you want to call it from and then has to be instantiated

How is that any different than a class?

答:
A singleton isn't really the same as a class, it is more commonly known as a design pattern.  Usually a singleton is a class such that only one instance of it can exist at a time.

Practically speaking, you could write a class with nothing special about it, create one instance at the beginning, and throughout your code, just use the same instance, and you could still call it a singleton.  Normally, people add a little overhead code, so that an object is instantiated as per normal, but when someone tries to instantiate a second object from it, it returns the first object instead.  This allows global data (some argue this is bad), it allows the object to be instantiated by what ever code needs it first by allowing all parts of code to reference it as if they were creating an object, and if you implement the destructors appropriately, you can even destroy and recreate the object if you need to do that for some reason.

You can check out https://en.wikipedia.org/wiki/Singleton_pattern for more information and sample code to enforce how the singleton will be used.

Design patterns are a topic addressed in the book called, "Design Patterns", by a group known as the "Gang of Four", which is a bit of a classic in the programming world.  It looks at several different design patterns, and goes in to much more detail not only the implementation, but also why you would or should use one pattern for what kind of scenario.  You can also look at https://en.wikipedia.org/wiki/Software_design_pattern for a briefer overview.

ContentLicense: CC BY-SA 3.0


问:
Why is the use of abstractions (such as LINQ) so taboo?
I am an independent contractor and, as such, I interview 3-4 times a year for new gigs.  I am in the midst of that cycle now and got turned down for an opportunity even though I felt like the interview went well.  The same thing has happened to me a couple of times this year.

Now, I am not a perfect guy and I don't expect to be a good fit for every organization.  That said, my batting average is lower than usual so I politely asked my last interviewer for some constructive feedback, and he delivered!

The main thing, according to the interviewer, was that I seemed to lean too much towards the use of abstractions (such as LINQ) rather than towards lower-level, organically grown algorithms.

On the surface, this makes sense--in fact, it made the other rejections make sense too because I blabbed about LINQ in those interviews as well and it didn't seem that the interviewers knew much about LINQ (even though they were .NET guys).

So now I am left with this question: If we are supposed to be "standing on the shoulders of giants" and using abstractions that are available to us (like LINQ), then why do some folks consider it so taboo?  Doesn't it make sense to pull code "off the shelf" if it accomplishes the same goals without extra cost?

It would seem to me that LINQ, even if it is an abstraction, is simply an abstraction of all the same algorithms one would write to accomplish exactly the same end.  Only a performance test could tell you if your custom approach was better, but if something like LINQ met the requirements, why bother writing your own classes in the first place?

I don't mean to focus on LINQ here.  I am sure that the JAVA world has something comparable, I just would like to know why some folks get so uncomfortable with the idea of using an abstraction that they themselves did not write.

UPDATE

As Euphoric pointed out, there isn't anything comparable to LINQ in the Java world.  So, if you are developing on the .NET stack, why not always try and make use of it?  Is it possible that people just don't fully understand what it does?

答:
There is one valid concern I've heard from those who don't use Linq, and it's one I take to heart: "Just because you can't see the implementation doesn't mean it isn't expensive".

Take the following snippet:

```<code>var resultList = inputList.Where(i=>otherInputList.Count(o=>o.Property == i.OtherProperty) > 0);
</code>```

The LINQ-initiated here are cringing. Why? Because just because this code looks nice and elegant doesn't mean it's not horrendously inefficient. Count(), with a predicate, evaluates every element of its parent enumerable, and sums up the times the predicate returned true. So, not only is this N^2 (when inputList and otherInputList are of roughly equal cardinality N), it's the absolute worst-case N^2; EVERY element of otherInputList is traversed for EVERY element of input. Instead, the first step is to use Any() instead of Count, because that's really what you want to know, and it will quit as soon as the answer's known to be "yes". Setting up a HashSet that stores distinct values of otherInputListObject.OtherProperty might help you out too; access becomes O(1) instead of O(N), so for an initial linear setup cost you reduce the entire operation to linear worst-case complexity instead of quadratic best-case complexity.

Thus we see that these nice elegant methods have serious costs behind them, and if you don't know what those costs are, you can very easily code an O(my G-D)-complexity algorithm into your prospective employer's high-performance central file servicer or main landing portal page the next time they might need a tweak. Firing you after you do that doesn't undo what you did, but not hiring you if they think you'd do it would prevent it. So, to avoid this, you have to prove them wrong; discuss what those methods do (meaning you have to know yourself) and their complexity, and how to arrive at the answer in an efficient (NlogN or better) time.

Another concern is the good old "When your only tool is a hammer" argument. Put yourself in the place of the interviewer interviewing this Linq fanboy. The candidate likes Linq, wants to use it, thinks it's the best thing ever. It might even seem that the candidate couldn't code without it, since every programming problem given was solved with Linq. Well what happens when it can't be used? Plenty of .NET 2.0 code still out there, that if it were upgraded would require painful upgrades to servers, user workstations, etc etc, all so you can use your fancy extension methods. As the interviewer, I'd try to get you to show that you could code an efficient sort or use the 2.0 sorting methods if you had to, no matter how much I might agree with you that the Linq libraries and similar extension methods are pretty sweet. An interviewer who doesn't see the point might not even bother trying to get you to show aptitude for anything else; they'll assume you don't have it and move on.

Body:
There is one valid concern I've heard from those who don't use Linq, and it's one I take to heart: "Just because you can't see the implementation doesn't mean it isn't expensive".

Take the following snippet:

var resultList = inputList.Where(i=>otherInputList.Count(o=>o.Property == i.OtherProperty) > 0);

The LINQ-initiated here are cringing. Why? Because just because this code looks nice and elegant doesn't mean it's not horrendously inefficient. Count(), with a predicate, evaluates every element of its parent enumerable, and sums up the times the predicate returned true. So, not only is this N^2 (when inputList and otherInputList are of roughly equal cardinality N), it's the absolute worst-case N^2; EVERY element of otherInputList is traversed for EVERY element of input. Instead, the first step is to use Any() instead of Count, because that's really what you want to know, and it will quit as soon as the answer's known to be "yes". Setting up a HashSet that stores distinct values of otherInputListObject.OtherProperty might help you out too; access becomes O(1) instead of O(N), so for an initial linear setup cost you reduce the entire operation to linear worst-case complexity instead of quadratic best-case complexity.

Thus we see that these nice elegant methods have serious costs behind them, and if you don't know what those costs are, you can very easily code an O(my G-D)-complexity algorithm into your prospective employer's high-performance central file servicer or main landing portal page the next time they might need a tweak. Firing you after you do that doesn't undo what you did, but not hiring you if they think you'd do it would prevent it. So, to avoid this, you have to prove them wrong; discuss what those methods do (meaning you have to know yourself) and their complexity, and how to arrive at the answer in an efficient (NlogN or better) time.

Another concern is the good old "When your only tool is a hammer" argument. Put yourself in the place of the interviewer interviewing this Linq fanboy. The candidate likes Linq, wants to use it, thinks it's the best thing ever. It might even seem that the candidate couldn't code without it, since every programming problem given was solved with Linq. Well what happens when it can't be used? Plenty of .NET 2.0 code still out there, that if it were upgraded would require painful upgrades to servers, user workstations, etc etc, all so you can use your fancy extension methods. As the interviewer, I'd try to get you to show that you could code an efficient sort or use the 2.0 sorting methods if you had to, no matter how much I might agree with you that the Linq libraries and similar extension methods are pretty sweet. An interviewer who doesn't see the point might not even bother trying to get you to show aptitude for anything else; they'll assume you don't have it and move on.


答:
To play devil's advocate, the reason is many developers just don't care about new things and think everything has to be solved with homegrown (usually inferior) tools.  There's nothing wrong with using abstractions.  Hell, there usually is no good reason not to use those abstractions.

It sounds like you just interviewed with a poor developer that doesn't keep up to date with things and takes the hammer and nail approach to everything.  These are the types of developers that don't know anything about helpful open source tools like NUnit, or NHibernate, or the various IoC containers; the ones who try to solve every problem with a massive stored proc in the database; the ones that know absolutely nothing about MVC despite it being out for several years now.

Title: Why is the use of abstractions (such as LINQ) so taboo?

Body:
I am an independent contractor and, as such, I interview 3-4 times a year for new gigs.  I am in the midst of that cycle now and got turned down for an opportunity even though I felt like the interview went well.  The same thing has happened to me a couple of times this year.

Now, I am not a perfect guy and I don't expect to be a good fit for every organization.  That said, my batting average is lower than usual so I politely asked my last interviewer for some constructive feedback, and he delivered!

The main thing, according to the interviewer, was that I seemed to lean too much towards the use of abstractions (such as LINQ) rather than towards lower-level, organically grown algorithms.

On the surface, this makes sense--in fact, it made the other rejections make sense too because I blabbed about LINQ in those interviews as well and it didn't seem that the interviewers knew much about LINQ (even though they were .NET guys).

So now I am left with this question: If we are supposed to be "standing on the shoulders of giants" and using abstractions that are available to us (like LINQ), then why do some folks consider it so taboo?  Doesn't it make sense to pull code "off the shelf" if it accomplishes the same goals without extra cost?

It would seem to me that LINQ, even if it is an abstraction, is simply an abstraction of all the same algorithms one would write to accomplish exactly the same end.  Only a performance test could tell you if your custom approach was better, but if something like LINQ met the requirements, why bother writing your own classes in the first place?

I don't mean to focus on LINQ here.  I am sure that the JAVA world has something comparable, I just would like to know why some folks get so uncomfortable with the idea of using an abstraction that they themselves did not write.

UPDATE

As Euphoric pointed out, there isn't anything comparable to LINQ in the Java world.  So, if you are developing on the .NET stack, why not always try and make use of it?  Is it possible that people just don't fully understand what it does?


问:
Why is OOP difficult?
When I started using an object-oriented language (Java), I pretty much just went "Cool" and started coding. I've never really thought about it until only recently after having read lots of questions about OOP. The general impression I get is that people struggle with it. Since I haven't thought of it as hard, and I wouldn't say I'm any genius, I'm thinking that I must have missed something or misunderstood it.

Why is OOP difficult to understand? Is it difficult to understand?

答:
Terminologies were my bump in the road when learning the principles of object oriented programming (POOP). It's when you get a grasp of the fundamentals that  pieces start to fall into place. Just like all things learning new concepts are a little hard.

Agreed that design patterns should be tought at least parallel to OOP.

ContentLicense: CC BY-SA 2.5

Title: Why is OOP difficult?


答:
My take on this (and TBH I'm guessing because none of us can tell what those interviewers were thinking) is that often you go to an interview to explain why they should hire you to fit in with their team, their way of working.

You can be the perfect developer, a rock start code god, but that means absolutely nothing if what you want to do (emphasised by you talking excessively and too enthusiastically about some cool technology gubbins) simply tells them about you, and that you would not fit in with what they want. If they have an old-style data-access system, that cannot be upgrade for whatever reason, they do not need someone who'd forgotten how to maintain it. If they are developing new stuff, and you really really want to put that cool new tech everywhere, then its obvious they will have a big issue with future code maintenance and/or staff training.

As a freelancer, this is much more of a problem that if they were hiring a permie. With a permie, training and development of new ways of working are not bad things, within the scope of existing code and practises - you'll be there for a long while to make things better. With a freelancer, they really don't give a hoot what you want, you're there solely to do their job the way they want it done, and its not your job to do anything else. (disagree - become a permanent employee)

Its probably got nothing to do with LINQ itself, I've rejected a candidate who turned up and explained how much better everything would be written in Haskell. We don't do Haskell. The same applies for any tech that isn't used by the company, usually its not a problem if you mention it as something good. The problem comes when you are too enthusiastic and keen on it.


问:
What are some feasible ideas for building a smart-device/console development portfolio?
I would like to start getting more contracts in the mobile, smart-device, and console development space and, having little prior work experience in the field, I need to build a portfolio of example projects.

Most of my professional experience is based on the .NET stack, so that is helpful in covering Windows Phone, Windows Metro, and  XBOX (non-game) development such as Kinect UI development, media applications, etc.  But I also need to demonstrate that I can handle Android development, Linux development (i.e. Smart TV apps), possibly Arduino development and so forth.

I have the tools and the knowledge to at least knock out some Android and Arduino examples, though iOS and Linux is stretching a bit out of my comfort zone.

In any case, what are some ways in which I could demonstrate that I understand and can code for these platforms?  Media search and filter apps?  Kinect navigation?  Android app that gets you the location of the nearest Starbucks based on GPS coordinates?

Any ideas would be greatly appreciated.

答:
I think it's always good to have a 'look at the puppy' type presentation for mobile stuff.

Why not a simple app that shows off communication?

Chinese whispers, peering from app/os to app/os.... Any fancy throw accelerator craftsmanship the better, and of course make it funny.

Wins over any social media app for me.


问:
TDD: Mocking out tightly coupled objects
Sometimes objects just need to be tightly coupled. For example, a CsvFile class will probably need to work tightly with the CsvRecord class (or ICsvRecord interface).

However from what I learned in the past, one of test-driven development's main tenets is "Never test more than one class at a time." Meaning you should use ICsvRecord mocks or stubs rather than actual instances of CsvRecord.

However after trying this approach, I noticed that mocking out the CsvRecord class can get a little hairy. Which leads me to one of two conclusions:

It's hard to write unit tests! That's a code smell! Refactor!

Mocking out every single dependency is just unreasonable.

When I replaced my mocks with actual CsvRecord instances, things went much more smoothly. When looking around for other peoples' thoughts I stumbled across this blog post, which seems to support #2 above. For objects that are naturally tightly coupled, we should not worry so much about mocking.

Am I way off track? Are there any downsides to assumption #2 above? Should I actually be thinking about refactoring my design?

答:
If you really need coordination between those two classes, write a CsvCoordinator class that encapsulates your two classes, and test that.

However, I dispute the notion that CsvRecord is not independently testable.  CsvRecord is basically a DTO class, is it not? It's just a collection of fields, with maybe a couple of helper methods.  And CsvRecord can be used in other contexts besides CsvFile; you can have a collection or array of CsvRecords, for example.

Test CsvRecord first.  Make sure that it passes all of its tests.  Then, go ahead and use CsvRecord with your CsvFile class during test.  Use it as a pre-tested stub/mock; fill it with relevant test data, pass it to CsvFile, and write your test cases against that.


答: No. #2 is fine. Things can be, and should be tightly coupled if their concepts are tightly coupled. This should be rare, and generally avoided, but in the example you provided it makes sense.

Title: TDD: Mocking out tightly coupled objects

Body:
Sometimes objects just need to be tightly coupled. For example, a CsvFile class will probably need to work tightly with the CsvRecord class (or ICsvRecord interface).

However from what I learned in the past, one of test-driven development's main tenets is "Never test more than one class at a time." Meaning you should use ICsvRecord mocks or stubs rather than actual instances of CsvRecord.

However after trying this approach, I noticed that mocking out the CsvRecord class can get a little hairy. Which leads me to one of two conclusions:

It's hard to write unit tests! That's a code smell! Refactor!

Mocking out every single dependency is just unreasonable.

When I replaced my mocks with actual CsvRecord instances, things went much more smoothly. When looking around for other peoples' thoughts I stumbled across this blog post, which seems to support #2 above. For objects that are naturally tightly coupled, we should not worry so much about mocking.

Am I way off track? Are there any downsides to assumption #2 above? Should I actually be thinking about refactoring my design?


问:
What software models are appropriate for daily builds and continuous integration?
On reading the joel test and about daily builds, a discussion with a few tech-lead friends of mine in various companies revealed that they never did daily builds or continuous integration because according to them:

Daily builds were meant for projects following Agile practices. It does not work for the waterfall model.

Continuous integration required automated testing which their OpenGL/OGRE/OSG type-of graphics project couldn't use, because apparently automated testing is impractical for projects where the graphics part is under (re)development.

One of them believes that it's not necessary to have configuration management. It's just enough to follow the philosophy of it, by defining small 2-3 day tasks, perform all activities of the development cycle for each task (code, code-review, unit test, integration), deliver to integration stream and build and generate the setup.

Even if they created scripts for the entire build and burn-to-cd process, creating automated tests were a problem because in any program you create, you can't always know what tests you'd have to run and scripting a test case for it takes up too much time and automated testing tools may not always support the specific kind of tests you might want to make.

Is daily builds and continuous integration really practical for non-agile projects? Is it meant only for test driven development? And is it really sufficient to follow the point 3 (above) kind of philosophy? I was talking to them about the build-in-one-step kind of scripted automation that Joel talks about, but they weren't willing to buy the idea.

p.s: I've been through the questions on this site about daily builds etc, but I believe this question is different.

EDIT: Point 3 should've started with "One of them believes it isn't necessary to integrate configuration mangaement with development tools"

答:
RE: Testing difficult-to-specify & difficult-to-test systems such as graphics systems.

In my experience, testing is not just (even?) about testing the output of the system that you are building. It is about verifying that the assumptions that you have made are correct, and continuing to verify those assumptions as the project evolves and situations change.

To this end, the placement of a moderate number of assertion statements at various points in the code has enormous benefit when combined with a continuous integration regime.

The system does not even need to be exercised with a comprehensive suite of unit tests (although these are a good thing if you have the time), Even a small set of vigorous system-level exercises will provide tremendous utility in uncovering bugs and building confidence.


问:
Mod lines in Java code
Often in C code (and some other languages as well) I have seen a section in the top-level comments for mod lines. These include the date a modification to the file was made, the user who made the modification, and a brief description of what was changed.

I have not yet seen an equivalent of this in Java. I think this information is useful, especially when trying to track down bugs in code I did not write. Is this because Java code is often under version control, or are there other reasons? Are there any suggestions as to how to include the information in the code file?

答: I see no reason to have those useless comments in any source file. Its just reinventing version control extremely poorly.</p>

Title: Mod lines in Java code


问:
Sencha Ext JS run time license
Do you need to buy a run time license from Sencha if your application code written is developed in Ext JS and deployed on a web server?

http://www.sencha.com

答:
If your server app is open source, no... I.e. you give the code away freely

If you don't want to give the code away, you need a license per developer working on the site.

Title: Sencha Ext JS run time license


问:
How do you organize highly customized software?
I'm working on a large software project which is highly customized for various customers arround the world. This means that we have maybe 80% code which is common between the various customers, but also a lot of code which has to change from one customer to the other. In the past we did our development in separate repositories (SVN) and when a new project started (we have few, but large customers) created another repository based on whatever past project has the best code basis for our needs. This has worked in the past, but we ran into several problems:

Bugs which are fixed in one repository are not patched in other repositories. This might be a problem of organization, but I find it difficult to fix and patch a bug in 5 different repositories, keeping in mind that the team maintaining this repository might be in another part of the world and we don't have their test environment, neither know their schedule or what requirements they have (a "bug" in one country might be a "feature" in another).

Features and improvements made for one project, which might also be useful for another project are lost or if they are used in another project often cause big headaches merging them from one code base to another (since both branches might have been developed independently for a year).

Refactorings and code improvements made in one development branch are either lost or cause more harm than good if you have to merge all these changes between the branches.

We are now discussing how to solve these problems and so far came up with the following ideas on how to solve this:

Keep development in separate branches but organizing better by having a central repository where general bug fixes are merged into and having all projects merge changes from this central repository into their own on a regular (e.g. daily) basis. This requires huge discipline and a lot of effort for merging between the branches. So I'm not convinced that it will work and we can keep this discipline, especially when time pressure puts in.

Abandon the separate development branches and have a central code repository where all our code lives and do our customization by having pluggable modules and configuration options. We are already using Dependency Injection containers to resolve dependencies in our code and we are following the MVVM pattern in most of our code to cleanly separate business logic from our UI.

The second approach seems to be more elegant, but we have many unsolved problems in this approach. For example: how do handle changes/additions in your model/database. We are using .NET with Entity Framework to have strongly typed entities. I don't see how we can handle properties which are required for one customer but useless for another customer without cluttering our data model. We are thinking of solving this in the database by using satellite tables (having a separate tables where our extra columns for a specifiy entity live with a 1:1 mapping to the original entity), but this is only the database. How do you handle this in code? Our data model lives in a central library which we would not be able to extend for each customer using this approach.

I'm sure that we are not the only team struggling with this problem and I'm shocked to find so little material on the topic.

So my questions are the following:

What experience do you have with highly customized software, what approach did you choose and how did it work for you?

What approach do you recommend and why? Is there a better approach?

Are there any good books or articles on the topic that you can recommend?

Do you have specific recommendations for our technical environment (.NET, Entity Framework, WPF, DI)?

Edit:

Thanks for all the suggestions. Most of the ideas match those that we already had in our team, but it is really helpful to see the experience you had with them and tips to better implement them.

I'm still not sure which way we will go and I'm not making the decision (alone), but I will pass this along in my team and I'm sure it will be helpful.

At the moment the tenor seems to be a single repository using various customer specific modules. I'm not sure our architecture is up to this or how much we have to invest to make it fit, so some things might live in separate repositories for a while, but I think it's the only longterm solution that will work.

So, thanks again for all responses!

答:
I am afraid that I do not have direct experience of the problem that you describe, but I do have some comments.

The second option, of bringing the code together into a central repository (as much as practicable), and architecting for customization (again, as much as practicable) is almost certainly the way to go in the long term.

The problem is how you plan to get there, and how long it is going to take.

In this situation, it is probably OK to (temporarily) have more than one copy of the application in the repository at a time.

This will enable you to gradually move to an architecture that directly supports customization without having to do it in one fell swoop.


问:
What is a legitimate reason to use Cucumber?
I've worked in several contracts where the client used Cucumber and I've often felt that the testing suite didn't really have a place in our stack. </p>

<p>From what I understand, business analysts/non-technical coworkers write up the tests and the developers make the step definitions work. My problem with this approach is the tests are never valid or terse enough to be used without rewriting the whole file. </p>

答:
You're right that it's a myth that non-technical people can write Gherkin (Cucumber, SpecFlow, Cuke4Duke) tests without help.

However, they can write requirements in a Given-When-Then format and they should still be able to read it after you've tidied them up, confirm that this is their intent and give more info/test cases, where necessary.

It's certainly legitimate in that sense.

But there are certainly times when the effort expended outweighs the benefits and you need to watch out for that.


答:
I have only built one such application. I'd say that 90% of the units sold were sold as is, no modifications. Each customer had their own customized skin and we served up the system within that skin. When a mod did come in that affected the core sections we tried using IF branching. When mod #2 came in for the same section we switched to CASE logic whiched allowed for future expansion. This seemed to handle most of the minor requests.

Any further minor custom requests were handled by implementing Case logic.

If the mods were two radical, we built a clone (separate include) and wrapped a CASE around it to include the different module.

Bug fixes and modifications on the core effected all users. We tested thoroughly in development before going to production. We always sent out email notifications that accompanied any change and NEVER, NEVER, NEVER posted production changes on Fridays... NEVER.

Our environment was Classic ASP and SQL Server. We were NOT a spaghetti code shop... Everything was modular using Includes, Subroutines and Functions.

Title: How do you organize highly customized software?

Body:
I'm working on a large software project which is highly customized for various customers arround the world. This means that we have maybe 80% code which is common between the various customers, but also a lot of code which has to change from one customer to the other. In the past we did our development in separate repositories (SVN) and when a new project started (we have few, but large customers) created another repository based on whatever past project has the best code basis for our needs. This has worked in the past, but we ran into several problems:

Bugs which are fixed in one repository are not patched in other repositories. This might be a problem of organization, but I find it difficult to fix and patch a bug in 5 different repositories, keeping in mind that the team maintaining this repository might be in another part of the world and we don't have their test environment, neither know their schedule or what requirements they have (a "bug" in one country might be a "feature" in another).

Features and improvements made for one project, which might also be useful for another project are lost or if they are used in another project often cause big headaches merging them from one code base to another (since both branches might have been developed independently for a year).

Refactorings and code improvements made in one development branch are either lost or cause more harm than good if you have to merge all these changes between the branches.

We are now discussing how to solve these problems and so far came up with the following ideas on how to solve this:

Keep development in separate branches but organizing better by having a central repository where general bug fixes are merged into and having all projects merge changes from this central repository into their own on a regular (e.g. daily) basis. This requires huge discipline and a lot of effort for merging between the branches. So I'm not convinced that it will work and we can keep this discipline, especially when time pressure puts in.

Abandon the separate development branches and have a central code repository where all our code lives and do our customization by having pluggable modules and configuration options. We are already using Dependency Injection containers to resolve dependencies in our code and we are following the MVVM pattern in most of our code to cleanly separate business logic from our UI.

The second approach seems to be more elegant, but we have many unsolved problems in this approach. For example: how do handle changes/additions in your model/database. We are using .NET with Entity Framework to have strongly typed entities. I don't see how we can handle properties which are required for one customer but useless for another customer without cluttering our data model. We are thinking of solving this in the database by using satellite tables (having a separate tables where our extra columns for a specifiy entity live with a 1:1 mapping to the original entity), but this is only the database. How do you handle this in code? Our data model lives in a central library which we would not be able to extend for each customer using this approach.

I'm sure that we are not the only team struggling with this problem and I'm shocked to find so little material on the topic.

So my questions are the following:

What experience do you have with highly customized software, what approach did you choose and how did it work for you?

What approach do you recommend and why? Is there a better approach?

Are there any good books or articles on the topic that you can recommend?

Do you have specific recommendations for our technical environment (.NET, Entity Framework, WPF, DI)?

Edit:

Thanks for all the suggestions. Most of the ideas match those that we already had in our team, but it is really helpful to see the experience you had with them and tips to better implement them.

I'm still not sure which way we will go and I'm not making the decision (alone), but I will pass this along in my team and I'm sure it will be helpful.

At the moment the tenor seems to be a single repository using various customer specific modules. I'm not sure our architecture is up to this or how much we have to invest to make it fit, so some things might live in separate repositories for a while, but I think it's the only longterm solution that will work.

So, thanks again for all responses!


答:
I'd suggest letting the BAs write test requirements using Gherkin, and developers write the Unit Test.

I've had excellent luck using SpecFlow and having interested parties write the Business Case skeleton, and me just implementing it.  That way, I can just pay attention to the code and not have to do a QA Lead's job as a programmer (I've been both in my career, and I don't like doing them both at the same time.)

Title: What is a legitimate reason to use Cucumber?

Body:
I've worked in several contracts where the client used Cucumber and I've often felt that the testing suite didn't really have a place in our stack. </p>

<p>From what I understand, business analysts/non-technical coworkers write up the tests and the developers make the step definitions work. My problem with this approach is the tests are never valid or terse enough to be used without rewriting the whole file. </p>


问:
Justification for bidirectional relationship
I typically try and avoid bidirectional relationships at all costs.  Recently I've been trying to follow a more domain centric design philosophy and I'm looking for advice in the best way to solve a specific problem.

I am implementing a basic 2d grid.  There are 3 basic classes, Item, Tile (has a list of Items), and World (has a 2d array of Tiles).

I am struggling with where to put the move() method which moves an item from one tile to a neighboring tile.  My initial inclination would be to place the move method in the Item class since it is the item that is actually moving.

However, that would create a circular dependency.  In the past I always worked with dumb objects in which case the move() method was in a higher layer (some kind of WorldManager or MoveManager) which knows about both tiles and items. I'm interested in what proposals others might have that can avoid the circular dependency while maintaining the domain-centric philosophy.

答:
Hmm, I like the MoveManager idea better.

Any object that moves itself would also require knowledge of the underlying surface on which it is moving, so you would have to pass the tileset to your Item anyway.  There goes your loose coupling.

Seems to me like it makes more sense to have a MoveManager object that has knowledge of the tileset and the items.  This is how the real world works; the chess pieces and the chess board don't have any built-in intelligence of their own.


答:
To answer your question directly:

A player would tell (by picking it up) an item to move from one tile to another. So logically, the move method goes on Item and receives the two Tiles as parameters.

Now having said that:

Don't let DDD get in the way of single-responsibility principle. It's ok to have non-entity items, such as MoveManager, and call it part of your domain. Just because you don't persist it anywhere, doesn't make it less a part of the domain.

People often confuse the data model with the behaviour (or business domain) model when talking about DDD. Anything can be an entity. In fact, one could argue that anything persisted already has its single responsibility and shouldn't be given any more.

From MSDN:

I, for one, am not disturbed by the need to involve other, non-entity classes, and I would try to avoid lifting the central behavior outside of my entity. You should always remember that entities are intrinsically behavioral units. Often that behavior will be implemented as a kind of state machine—when you invoke a command on an entity, it is responsible for changing its internal state—but sometimes it's necessary for you to obtain additional data or impose side-effects upon the outside world.

Title: Justification for bidirectional relationship

Body:
I typically try and avoid bidirectional relationships at all costs.  Recently I've been trying to follow a more domain centric design philosophy and I'm looking for advice in the best way to solve a specific problem.

I am implementing a basic 2d grid.  There are 3 basic classes, Item, Tile (has a list of Items), and World (has a 2d array of Tiles).

I am struggling with where to put the move() method which moves an item from one tile to a neighboring tile.  My initial inclination would be to place the move method in the Item class since it is the item that is actually moving.

However, that would create a circular dependency.  In the past I always worked with dumb objects in which case the move() method was in a higher layer (some kind of WorldManager or MoveManager) which knows about both tiles and items. I'm interested in what proposals others might have that can avoid the circular dependency while maintaining the domain-centric philosophy.


答:
Often in Java I see these types of lines, but it's not entered manually.  Most VCSs can tag any text file with that data, as long as a template is left in the file to insert that information into.

For instance, in the VCS I use, if I include $Id: ... $ anywhere in the file, the ... will be replaced with the file name, version number, last editor, edit date, etc.

Some people think they're useless in light of VCSs (which store all of that information), but I don't.  It's quick access to that information which you would have to mine for (or at least leave your file editor) by going through the VCS.

Edit: By the way, nobody's highlighted my main reason for disliking them (remember, I said they're not useless, not that I like them).  I hate that they add textual changes to the file at each checkin.  You either need a highly configurable diff client to ignore those changes, or you're faced with boilerplate changes at each revision which make it more cumbersome to see what actually changed.

Title: Mod lines in Java code

Body:
Often in C code (and some other languages as well) I have seen a section in the top-level comments for mod lines. These include the date a modification to the file was made, the user who made the modification, and a brief description of what was changed.

I have not yet seen an equivalent of this in Java. I think this information is useful, especially when trying to track down bugs in code I did not write. Is this because Java code is often under version control, or are there other reasons? Are there any suggestions as to how to include the information in the code file?


问:
Should I represent special cases (like errors / exceptions) in UML diagrams?
Let's say you write a program that, when started, reads its configuration file to know which modules to start-up etc. If that configuration file is missing, an error will probably show up. This is an important situation that must always be handled.

I read a statistic once which said that about 70 % of the code in a typical program is there to deal with corner cases (like check that file is not missing, catch an Exception, check that I don't divide by 0, check that a person's age is a positive number etc.).

I don't believe this (i.e. the 70 % claim) to be very accurate, but then again, a lot of the code that I write contains a lot of ifs that check for valid parameters and stuff like that. I doubt I'm the only one who does this. So that statistic does have some truth in it.

If a big part of a program's code is represented by these checks, then shouldn't these cases be represented in UML diagrams ? (like sequence diagrams etc.). I can't remember if I ever saw such things.

Should I include them in my diagrams ? Will that enlighten or disturb/confuse another programmer who looks at those diagrams ? Would the diagrams then become too big because of this ?

答:
INMO, you should define why are you using UML in your situation. If you are providing specification for someone to code from, then you may have to do that. If you want to specify step-by-step flow, use pseudo code not UML diagram.

If you are showing part of a flow as an example, yes, you could show all details (within a page or so). Also, if you have a tool that generates code from your definition then you need to do that.

If you are describing a process flow, then you may want to be generic about such details and represent all validation errors in 1 spot  say, by using a comment that would apply to several of operations such as all file reads. The point here is to focus on the main scenarios not the exceptions.

In general, when you add low level details to diagrams, they become hard to read and take away the visual advantage a picture has over text. Also, with the exception of the Class Diagrams, UML diagrams are almost always presented in high level.

Whatever your choice is, follow it across all your diagrams. Consistency is important.


问:
How can I organize personal Git repositories?
I'm in the process of setting up a GitHub account with the plan of making a pair of libraries I developed as parts of some recent iOS projects freely available for other iOS devs to use.

I don't currently have off-site backup for most of my code, so as part of this, I originally thought I would upload all of my personal projects, or at least all of my iOS projects, to a private GitHub-hosted repository.  However, I have a lot of projects sitting around, many of which are fairly low-value (i.e., adapted from books and written for the learning experience).  Not only does GitHub charge by the private repository, it doesn't seem to have any way of organizing repositories hierarchically.

Is there something I'm missing that would allow me to use a git repository with a hierarchy and check out pieces as I need them / work with them, the way I currently do with SVN?

Does GitHub (or a competitor, like BitBucket) have some project organization features that I'm missing?

Failing that, what's the generally accepted "Git way" of handling this situation (discard projects not intended for release, store them offline, bundle them together somehow, etc., etc.)?

As far as I can tell, my options are:

Put libraries on GitHub, continue hosting my own SVN for all other projects, use a non-VCS solution for off-site backup (blech),

Put libraries and software I plan to release on GitHub (as public and private, respectively), continue hosting my own SVN for projects I don't care about as much and am only likely to revisit to refresh my memory on how to implement XYZ, decide that I'm willing to write them off if my house implodes (double blech),

Put everything on [GitHub and/or BitBucket], deal with having some ridiculous number of repositories by searching for what I need / maintaining some offline set of pointers into my [GitHub and/or BitBucket] account (triple blech)

答:
bitbucket.org lets you create unlimited private repos.

Git does not let you check out just some pieces of code. So you would need to create a repo for each project, or deal with cloning all the projects. In reality I don't see a problem with putting all our small projects in a single repo. You clone it once and you are done.

With Git you don't ever have to "checkout" the code again unless you blow away your local repo or move to another machine. You'll just synchronize all your changes.

I have a simular issue with a large number of repositories. The reason I cannot store them all in a single repository is that I need to branch different versions off of each and every repository. It is very difficult to manage.


答:
"Coupled" classes are mutually dependent on one another.  This should not be the case in what you are describing--a CsvRecord should not really care about the CsvFile containing it, so the dependency only goes one way.  That's fine, and is not tight coupling.

After all, if a class contains the variable String name, you would not claim it is tightly coupled to String, would you?

So, unit test the CsvRecord for its desired behavior.

Then use a mocking framework (Mockito is great) to test if your unit is interacting with the objects it depends on correctly.  The behavior you want to test, really--is the CsvFile handles CsvRcords in the expected fashion.  The inner workings of CvsRecord shouldn't matter--it's how CvsFile communicates with it.

Finally, TDD is not only about unit tests.  You certainly can (and should) start with functional tests that look at the functional behavior of how your larger components work--that is, your user story or scenario. Your units tests set the expectations and verify the pieces, the functional tests do the same for the whole.


答:
I've often seen Java files with a header including the original date created and the author, but not "mod lines". Version control would make that rather superfluous, as it tracks changes on a per-line basis by user.

As for why they're used in C, perhaps it's an old custom from before the days of VC.

Title: Mod lines in Java code


答:
The gherkin language (In order to.. I want .. so that ...; Given ... When ... then ...) used by cocumber and bdd is a way to write specs that a non technical business expert can understand and a software tool (like cucumber) can verify.

What is a legitimate reason to use Cucumber?

Using these is usfull to define acceptance criteria for your work: Definition of done

In my opinion these automatic verifyable acceptance criteria must be written by a team of businessexperts and softwaredeveloppers.

I agree to @pdr that a businessexpert writing the spec alone makes not sensce.


答:
The reason for testing one class at a time is that you don't want tests for one class to have dependencies on the behaviour of a second class.  That means that if your test for Class A exercises any of the functionality of Class B, then you should mock Class B to remove the dependency on particular functionality within Class B.

A class like CsvRecord seems to me that it's mostly for storing data - it's not a class with too much functionality of its own.  That is, it may have constructors, getters, setters, but no methods with real substantial logic.  Of course, I'm guessing here - maybe you've written a class called CsvRecord that does numerous complex calculations.

But if CsvRecord doesn't have real logic of its own, there's nothing to be gained by mocking it.  This is really just the old maxim - "don't mock value objects" .

So when considering whether to mock a particular class (for a test of a different class), you should take into account how much of its own logic that class has, and how much of that logic will be executed in the course of your test.


问:
How to teach Exception Handling for New Programmers?
How do you go about teaching Exception Handling to Programmers. All other things are taught easily - Data Structures, ASP.NET, WinForms, WPF, WCF - you name it, everything can be taught easily.

With Exception Handling, teaching them try-catch-finally is just the syntactic nature of Exception Handling.

What should be taught however is - What part of your code do you put in the try block? What do you do in the catch block?

Let me illustrate it with an example.

You are working on a Windows Forms Project (a small utility) and you have designed it as below with 3 different projects.

UILayer

BusinessLayer

DataLayer

If an Exception (let us say of loading an XDocument throws an exception) is raised at DataLayer (the UILayer calls BusinessLayer which in turns calls the DataLayer), do you just do the following

```<code>//In DataLayer
try {
    XDocument xd_XmlDocument = XDocument.Load("systems.xml");
}
catch(Exception ex)
{
    throw ex;
}
</code>```

which gets thrown again in the BusinessLayer and which is caught in UILayer where I write it to the log file?

Is this how you go about Exception Handling?

答: IMO, you should think that exception handling and flow control statements are basically the same. You use them to control the flow of your programs based on what condition they are currently in. The difference is exception handling only will react when an error (or exception) occurs.</p>

OwnerDisplayName: denny


问:
Why is Java the lingua franca at so many institutions?
EDIT: This question at first seems to be bashing Java, and I guess at this point it is a bit. However, the bigger point I am trying to make is why any one single language is chosen as the one end all be all solution to all problems. Java happens to be the one that's used so that's the one I had to beat on here, but I'm not intentionality ripping Java a new one :)

I don't like Java in most academic settings. I'm not saying the language itself is bad -- it has several extremely desirable aspects, most importantly the ability to run without recompilation on most any platform. Nothing wrong with using the language for Your Next App ^TM. (Not something I would personally do, but that's more because I have less experience with it, rather than it's design being poor)

I think it is a waste that high level CS courses are taught using Java as a language. Too many of my co-students cannot program worth a damn, because they don't know how to work in a non-garbage-collected world. They don't fundamentally understand the machines they are programming for. When someone can work outside of a garbage collected world, they can work inside of one, but not vice versa. GC is a tool, not a crutch. But the way it is used to teach computer science students is a as a crutch.

Computer science should not teach an entire suite of courses tailored to a single language. Students leave with the idea that all good design is idiomatic Java design, and that Object Oriented Design is the ONE TRUE WAY THAT IS THE ONLY WAY THINGS CAN BE DONE. Other languages, at least one of them not being a garbage collected language, should be used in teaching, in order to give the graduate a better understanding of the machines.

It is an embarrassment that somebody with a PHD in CS from a respected institution cannot program their way out of a paper bag.

What's worse, is that when I talk to those CS professors who actually do understand how things operate, they share feelings like this, that we're doing a disservice to our students by doing everything in Java. (Note that the above would be the same if I replaced it with any other language, generally using a single language is the problem, not Java itself)

In total, I feel I can no longer respect any kind of degree at all -- when I can't see those around me able to program their way out of fizzbuzz problems.

Why/how did it get to be this way?

答: A few years ago I read somewhere that, in the UK, the Java decision was made to entice more students into programming. Apparently it was easier on the brain because of the lack of nasty pointers and memory management etc... I'd guess that this is the reason why Python is being quickly adopted as the new 'learning tool.' I'd be of the opinion that your typical uni course is not going to make you into a programmer. All it is meant to do is arm you with a certain amount of knowledge and prime you for programming. The day that one can call oneself a programmer generally comes a fair bit of time after uni and when that time comes, pointers, garbage collection and programming paradigms other than OOP, should not be a problem.</p>


问:
How could you reconcile declarative database development and non-trivial data 'motions'?
Coming back to SQL Server after several years away, I find the Visual Studio Database projects (and now SSDT) very exciting, as they are aiming to offer a way to develop databases declaratively, rather than having to mess around with change scripts.

However, the elephant in the room is the 'data motions' (I'm not too sure whether that's an official term): it's not too hard to automatically script a simple change in one table, but if you're normalising/denormalising, things get hairy very quickly.

Gert Drapers said as much in this TechEd video, and that they're trying to work out a way of working with these complex data migrations too.

The question: This got me thinking. How could you do this? Is there a way - even in theory - to define these data migrations declaratively? Or even a non-declarative way which could be combined elegantly with the declarative bits? Does anything like this already exist in other frameworks (I've vaguely heard something about Ruby/Rails?)

(I wondered whether to post this on dba, but I'm not sure whether they like 'good subjective questions (if this is one), feel free to migrate if necessary)

答:
After searching a little bit, I found this patent reference from 2002 for a "Declarative data transformation engine":

http://www.google.com/patents/US20070220022

(Disclaimer: that kind of patents are the reason why I think the american software patent system is totally flawed and needs to be changed).

However, I don't know if someone made a product based on this patent for the usage you described above. In theory, that should be possible, by performing those steps:

create a new database schema as a copy of your existing one (version 1)

apply schema transformations to transform it into "version 2"

apply data migration from database version 1 into database version 2

replace database version 1 by version 2

If this is a good idea to solve your "data movement" problem this way, depends a lot on your circumstances and your database system, since it involves making a whole copy instead of applying the migration in-place. Where it works, you can solve step 3 by any "Extract-Transform-Load" tool available on the market. AFAIK, tools like Microsoft SSIS or Oracle ODI seem to offer declarative definitions of transformation rules as well as non-declarative.


问:
Programming language trends
Are there some statistics out there that show the approx. number of users that popular programming languages have and the rate this number increases over time?</p>

答:
Programming language trends are notoriously hard to make sense of, and all available statistics & metrics should be taken with a grain of salt.

One of the most oftenly quoted indexes is the TIOBE Programming Community Index, that rates programming languages by counting hits on the most popular search engines. As for job trends, Jobs Tractor published monthly trends, based on listings for developer jobs.

If you are looking to compare specific languages against each other, Ohloh provides a very handy language compare tool, which counts monthly commits by open source developers. You can also use Google Trends, for example here's a comparison of Haskell vs Scheme.

You can always look at Stack Overflow, and more specifically at the language tags, or popular code hosting services like Github, that maintains a "top languages" page. And if you are a Redditor, look no further than /r/programming's FAQ.

As you may have noticed, all the available data seem quite unreliable, and that's understandable, popularity is extremely hard to measure. And, at the end of the day, popularity and trends are rather irrelevant metrics. Who cares which language is the more popular, programming languages are tools, if it does what I need it to do, it's fine by me.

Title: Programming language trends


问:
How to create interest in programming?
I am student of 3rd year software engineering, and I find myself nowhere in field of programming.

I know basics of programming languages like C, C++, Java, Visual Basic, HTML, JAVAScript, CSS and PHP. But every time I sit in front of my computer and start coding in any of the languages, I feel frustrated and distracted and I just shut it down.

I have lost interest in everything and I am worried about my future. I am worst at creating logics.

So can anyone help me or guide me to make me create my interest in programming?

答:
Having reached 3rd year and having learned all these technologies show that you probably have the right IQ skills (this is a crude judgement), so making this assumption, part of your problem may be either:

Physical/psychological issue, this can be determined by tests at the doctor's office. The unbalance of some hormones can exhibit such symptoms.

The bad choice of the problem to solve. Don't sit in front of the computer and start doing whatever. Instead, pick simple tasks that can get you results. Have a goal you can fulfill.

Work with others on a simple project. This may motivate you if you are a social type of person.

If you feel challenged by complex sort logic or the likes, relax, most business applications don't require such level of complexity.

Find a mentor to help you when you are stuck.

If none of the above works, it is not too late to investigate other careers you may want to do. 99%+ on this planet don't code and some have Rolls Royces :). In fact, most of the rich people never coded a single line and will never do that.

Title: How to create interest in programming?


答: I think many programmers have difficulty with upfront design and planning to begin with. Even if someone does all the design for you, it is still possible to break away from OOP principles. If I take a bunch of spaghetti code and dump it into a class, is that really OOP? Someone who doesn't understand OOP can still program in Java. Also, don't confuse difficulty to understand with not willing to follow a certain methodolgy or disagreeing with it.</p>

Title: Why is OOP difficult?

Body:
When I started using an object-oriented language (Java), I pretty much just went "Cool" and started coding. I've never really thought about it until only recently after having read lots of questions about OOP. The general impression I get is that people struggle with it. Since I haven't thought of it as hard, and I wouldn't say I'm any genius, I'm thinking that I must have missed something or misunderstood it.

Why is OOP difficult to understand? Is it difficult to understand?


答:
First, you seems smarter than the most, given you know how to use so many languages technologies. If you're worried that you're not smart enough, I disagree.

I had the same issue a while back, and everything seemed too complicated and stressful. I suggest, you start building something interesting, something you're motivated to do. Since you know all these technologies, try building something with them. If you get stuck when trying to use a technology, just google it, ask it on Stackoverflow or your fellow friends. If you feel stressed, just stop what you're doing, and take a walk. You can't work when you're stressed. Then come back and take a fresh look at the problem. I've worked in projects where I'm getting a NullPointerException and trying to solve it for days, and one day I realize I didn't set a variable.

Reality is, when writing software, you will get stuck, you will get frustrated, you will find road blocks. But when you overcome those and your code finally works the way you want, it is worth the trouble. I personally write code, just for that feeling. If I don't get these problems when I write code, it's feels easy at first, but feels boring quickly. When they say software developer's life is never boring, this is what they mean. You are expected to come up with logic, and solve problems. Yes, it's painful sometimes, but it doesn't have to be. When you feel stressed, take a break, listen to music, log in to Facebook, what ever you like.

But then again, it's one of the many ways to make money at some point. It's not the only way. If you don't feel like you're not up for it, you can go find something that you enjoy. If you don't enjoy it, just find your passion. As Steve Jobs said “We don’t get a chance to do that many things, and every one should be really excellent. Because this is our life. Life is brief, and then you die, you know? And we’ve all chosen to do this with our lives. So it better be damn good. It better be worth it.” If writing software doesn't worth it, find something else that you'll enjoy, otherwise you'll suffer for you life.

Also, keep in mind that you spent the last 3 years learning all that. There must've beed a motivation for you to start learning this. Is that motivation still there ? What has changed ? If you go do something else, it will make the last 3 years of your life a waste.

If you think software is too complicated, keep in mind that, best things in the world, are not complicated. Including iPhone, Facebook, Spotify and more, are not complicated. May be you're looking at it differently.

Title: How to create interest in programming?

Body:
I am student of 3rd year software engineering, and I find myself nowhere in field of programming.

I know basics of programming languages like C, C++, Java, Visual Basic, HTML, JAVAScript, CSS and PHP. But every time I sit in front of my computer and start coding in any of the languages, I feel frustrated and distracted and I just shut it down.

I have lost interest in everything and I am worried about my future. I am worst at creating logics.

So can anyone help me or guide me to make me create my interest in programming?


答:
I had the same problem few years ago. I knew Java, C++, HTML, CSS, Visual Basic, C# and Flash (circa 2005). I was also in the third year of college. I also had some family problems (father in hospital for six months), and on top of that I had to start working (no money for anything, the costs for health were sky high in my country). I faced multiple issues:

I was not able to sit in front of the computer too much!

I found no joy in programming.

I was not able to focus.

I was not able to finish any middle sized programming project (say
anything more than few thousand lines).

I had no working knowledge of the market.

I had no clear idea on what to do with my life (as a programmer or
otherwise).

In the end, my boss noticed these problems. He was not a bright programmer or anything, just a great human being, and he advised me to first think about what to do with my life, and then try to focus and solve the other problems. I listened to his advice, and then I attacked each problem.

All I knew back then is that I was a good writer, and I was lucky enough to read 2-3 good programming books (one of them being Bruce Eckel's Programming in Java) and I decided that programming is not such a bad job for a writer. Then I started to work on the next problems:

Time in front of the computer: try to find the best interval that works for you (30 minutes, 1 hr, 2 hrs).

To regain interest in programming, try to solve some small problems that might excite you (it can be something as simple as a different version of Tetrix, or a new website). Learning new frameworks like Ruby on Rails, Grails, Python + Django, also works.

To regain the ability to focus: Again, same advice like earlier - try to find an algorithm to split your working time into small pieces, easy to digest pieces. For example, I discovered that in my case, I would be able to focus in the next situations: either split everything into small tasks (20 to 45 minutes), and take short breaks between them (5 to 15 minutes) or larger blocks for 4 to 8 hours (half a day or one day). If breaks are taken in such a way as to help you regain focus and also celebrate the fact that you finished your task, it is likely that you will be more productive in time. Each celebration break also comes with some great ideas about improving your program!

To finish bigger projects: try to apply the knowledge you were exposed during the learning new frameworks phase to your diploma or master projects. For example try something 3 or 4 times bigger than your usual semester project.

Knowledge of the market: you will get it in time by working at different companies, reading the Internet, meeting new people, going to workshops, conferences, etc.

As I said, first step should be to decide if this is really what you want to do, and then to try to solve each of the smaller problems one by one. This strategy helped me a lot, and I thankful to my former boss even to this day (I am now living in another country and doing research, and meeting lots of elite programmers from all the big cities in Europe). I knew I took the right decision few years ago, when in the 37 signals book (the book by the creators of Ruby), one of the advices was Always hire the better writer! Just google this phrase and read that small book :). It might help you get through this difficult phase. It also addresses all the issues I detailed in this short post, and many others.

Another advice would be to try to understand which part of software engineering you like: programming, project management, documentation, testing, etc? Try to understand what makes you happy when working at a programming project of any kind.

Title: How to create interest in programming?


问:
Why would more CPU cores on virtual machine slow compile times?
[edit#2] If anyone from VMWare can hit me up with a copy of VMWare Fusion, I'd be more than happy to do the same as a VirtualBox vs VMWare comparison. Somehow I suspect the VMWare hypervisor will be better tuned for hyperthreading (see my answer too)

I'm seeing something curious. As I increase the number of cores on my Windows 7 x64 virtual machine, the overall compile time increases instead of decreasing. Compiling is usually very well suited for parallel processing as in the middle part (post dependency mapping) you can simply call a compiler instance on each of your .c/.cpp/.cs/whatever file to build partial objects for the linker to take over. So I would have imagined that compiling would actually scale very well with # of cores.

But what I'm seeing is:

8 cores: 1.89 sec

4 cores: 1.33 sec

2 cores: 1.24 sec

1 core: 1.15 sec

Is this simply a design artifact due to a particular vendor's hypervisor implementation (type2:virtualbox in my case) or something more pervasive across more VMs to make hypervisor implementations more simpler? With so many factors, I seem to be able to make arguments both for and against this behavior - so if someone knows more about this than me, I'd be curious to read your answer.

Thanks
Sid

[edit:addressing comments]

@MartinBeckett: Cold compiles were discarded.

@MonsterTruck: Couldn't find an opensource project to compile directly. Would be great but can't screwup my dev env right now.

@Mr Lister, @philosodad: Have 8 hw threads, using VirtualBox, so should be 1:1 mapping without emulation

@Thorbjorn: I have 6.5GB for the VM and a smallish VS2012 project - it's quite unlikely that I'm swapping in/out trashing the page file.

@All: If someone can point to an open source VS2010/VS2012 project, that might be a better community reference than my (proprietary) VS2012 project. Orchard and DNN seem to need environment tweaking to compile in VS2012. I really would like to see if someone with VMWare Fusion also sees this (for VMWare vs VirtualBox compartmentalization)

Test details:

Hardware: Macbook Pro Retina

CPU : Core i7 @ 2.3Ghz (quad core, hyper threaded = 8 cores in windows task manager)

Memory : 16 GB

Disk : 256GB SSD

Host OS: Mac OS X 10.8

VM type: VirtualBox 4.1.18 (type 2 hypervisor)

Guest OS: Windows 7 x64 SP1

Compiler: VS2012 compiling a solution with 3 C# Azure projects

Compile times measure by VS2012 plugin called 'VSCommands'

All tests run 5 times, first 2 runs discarded, last 3 averaged

答:
There is only one possible reason for this to be happening, which is that your overhead is exceeding your gains.

You may be emulating the multiple cores, rather than assigning actual cores or even processes or even threads from the host machine. That seems pretty likely to me, and obviously is going to give you negative speedup.

The other possibility is that the process itself doesn't parallelize well, and even attempting to parallelize it is costing you more in communication overhead than you're gaining.


问:
TFS non-chronological deployment?
We have the following scenario:

Changeset #1 is some unfinished buildable checkin

Changeset #2 is a completed small task

..

Changset #5 completes the work done at CS#1

They all affect the same output dll.

How do we deploy changes done at CS#2 without the other work? Also how can we avoid this situation happening again in the future?

答: Use a feature branch or a shelveset. Both will allow you to store the work in progress on the server and run a Team Build. A feature branch is a bit more heavyweight but can also be more flexible.</p>

Title: TFS non-chronological deployment?


问:
How do you name your private variables in C#?
What is the best practice, most commonly accepted naming conventions for private variables in C#?

private int myInteger;

private int MyInteger;

private int mMyInteger;

private int _myInteger;

private int _MyInteger;

Mysterious other option

Which do you use and why?  (My company is fairly new to C# and I would like to pick the most "industry accepted" method to try and get into our coding standard.)

答:
I wouldn't call it "my" anything!

But I'd say

```<code>class C
{
     int VariableName { get; set; }
}
</code>```

quite often this is nicer than having explicit variables.  If I had an explicit private variable i'd call it int _variableName;

Body:
I wouldn't call it "my" anything!

But I'd say

class C
{
     int VariableName { get; set; }
}

quite often this is nicer than having explicit variables.  If I had an explicit private variable i'd call it int _variableName;

ContentLicense: CC BY-SA 4.0


答:
Why is Java used?

Three reasons:

Java uses C-style syntax. Many programmers are familiar with it, so it reduces the learning curve.

Money was spent to market Java as cool and modern.  But compared to lisp, java is living in the stone age.

The JVM. JVM is the one cool thing about java that is legit, not just marketing hype. Although the JVM should be praised as a platform for running programs, it does not by itself merit the existence of the Java language.  You can theoretically and practically compile many different languages for the JVM.


问:
Should Android development be done on Windows or OSX? Is there any difference?
I have the option to install the Android SDK on Windows or OSX.  Which platform provides a better (easier) development experience?

To keep this constructive, I'm looking for any difference that eliminates compatibility issues, ease of debugging, or compatibility with 3rd party utilities.

答:
Both Windows and OS X support Java at the moment, but in the long term I heard that Apple will be dropping Java support on OS X.

Edit

It seems that Oracle will provide direct support for Java on OS X.


问:
What is the best way to use inheritance with ORMs?
If I have a People table and those people can be at different addresses, and each address can have more than one person, thats a many-to-many relationship.

So, using ORMs like Entity Framework and Django, I've got the hang of doing that. But my problem is that there are different types of people, like employees and customers and other clients that all have these fields also.

This would leave me with a top level class called Person which has a many-to-many relationship with Address and then these other classes (Customers, etc.) that inherit from person.

I read that there are different types of inheritance, so what would be the best approach?

答:
Single-table inheritance is probably the easiest to understand and to maintain. That said, if you have a large number of differences between the inherited objects, you're going to end up with an equally large number of null fields all over your table. When that becomes apparent, you can (relatively easily) switch to using multi-table inheritance.

Links refer to Entity Framework.


答:
I've had an experience of developing for Android with Eclipse both on Windows and on OS X (on Intel 5i processor).

OS X had some advantages: the emulator worked faster, Eclipse didn't have those weird things which often appear on Windows. So if you have a chance to develop on OS X and you're going to use Eclipse, I think it's easier and will save your nerves.

Title: Should Android development be done on Windows or OSX? Is there any difference?

Body:
I have the option to install the Android SDK on Windows or OSX.  Which platform provides a better (easier) development experience?

To keep this constructive, I'm looking for any difference that eliminates compatibility issues, ease of debugging, or compatibility with 3rd party utilities.


答:
I think you should consider the complete list of 3rd party tools you'll be needing. Android, Java, Eclipse, VCS (at least bzr, git, svn) should not be a problem.

For example I have an Android project which has a small python scripting part in it too, and I could not get libxml working on Mac OS X, even though it's working out of the box on Windows or Linux.


答:
You are not alone ...

Same thing has happened to me before with Java using Maven 3.x to compile on an i3. Letting it default to "4" threads was much slower, near 50% slower, than telling it explicitly to only use 2 cores.

I think it has something to do with the hyper-threading context switching and overlapping I/O.

It makes sense when you start thinking about it. You can prove what is causing the degeneration of results with a good system wide profiling tool.

Title: Why would more CPU cores on virtual machine slow compile times?

Body:
[edit#2] If anyone from VMWare can hit me up with a copy of VMWare Fusion, I'd be more than happy to do the same as a VirtualBox vs VMWare comparison. Somehow I suspect the VMWare hypervisor will be better tuned for hyperthreading (see my answer too)

I'm seeing something curious. As I increase the number of cores on my Windows 7 x64 virtual machine, the overall compile time increases instead of decreasing. Compiling is usually very well suited for parallel processing as in the middle part (post dependency mapping) you can simply call a compiler instance on each of your .c/.cpp/.cs/whatever file to build partial objects for the linker to take over. So I would have imagined that compiling would actually scale very well with # of cores.

But what I'm seeing is:

8 cores: 1.89 sec

4 cores: 1.33 sec

2 cores: 1.24 sec

1 core: 1.15 sec

Is this simply a design artifact due to a particular vendor's hypervisor implementation (type2:virtualbox in my case) or something more pervasive across more VMs to make hypervisor implementations more simpler? With so many factors, I seem to be able to make arguments both for and against this behavior - so if someone knows more about this than me, I'd be curious to read your answer.

Thanks
Sid

[edit:addressing comments]

@MartinBeckett: Cold compiles were discarded.

@MonsterTruck: Couldn't find an opensource project to compile directly. Would be great but can't screwup my dev env right now.

@Mr Lister, @philosodad: Have 8 hw threads, using VirtualBox, so should be 1:1 mapping without emulation

@Thorbjorn: I have 6.5GB for the VM and a smallish VS2012 project - it's quite unlikely that I'm swapping in/out trashing the page file.

@All: If someone can point to an open source VS2010/VS2012 project, that might be a better community reference than my (proprietary) VS2012 project. Orchard and DNN seem to need environment tweaking to compile in VS2012. I really would like to see if someone with VMWare Fusion also sees this (for VMWare vs VirtualBox compartmentalization)

Test details:

Hardware: Macbook Pro Retina

CPU : Core i7 @ 2.3Ghz (quad core, hyper threaded = 8 cores in windows task manager)

Memory : 16 GB

Disk : 256GB SSD

Host OS: Mac OS X 10.8

VM type: VirtualBox 4.1.18 (type 2 hypervisor)

Guest OS: Windows 7 x64 SP1

Compiler: VS2012 compiling a solution with 3 C# Azure projects

Compile times measure by VS2012 plugin called 'VSCommands'

All tests run 5 times, first 2 runs discarded, last 3 averaged


问:
How to get started in opensource projects and programs
I am interested in starting to learn how to contribute to open source projects and Linux in general. I am a first year B.Sc. Computer Science student this year and we use c++ as our main programming language.

Where can I learn how a typical GPL application should be structured? By this I mean the layout of the source files, what should be included in all the files etc. to make it compliant with GPLv3 for instance?

How does one find out what projects need coders, and what exactly needs to be done? I would really like to get involved but have no clue as to how to get involved. If I could be the tea boy I would ;)

答:
How to find a project you are interested in?

Ask yourself:

Is there a particular software that you just love so much?

Is there a software that you would like to have but does not exist?

Is there a software that is almost what you want but just almost?

How to find a suitable project that needs you?

Based on your answers above, get on Google and find the homepage of a similar project that is interesting to you. Some factors to look for:

When was the last commit?

How many active committers are there?

Which VCS do they use and how can you submit branches?

How you evaluate these factors is entire up to you. Personally I prefer small-ish projects where my work will be noticeable, but not too small where the developers might not be interested in accepting new faces.

How to get involved?

Do NOT send an introductory mail saying "hey I'm here I want to work on X". Just pick something you can improve. It can be anything, but preferably very small and clearly an improvement. Send a patch or merge request, along with a brief and humble introduction. Keep doing small things, gradually bigger and bigger.

Especially in the beginning, adopt the coding style used by the others. If you disagree with it you can contest it later after you become a core contributor.

Caution

Be patient. Don't get your hopes high early. It takes time to get to know the members, and it is impossible to know in advance if your personalities are compatible or not. For sure there are plenty of projects out there that are well suited for you, you don't have to fall for the 1st or the 2nd.

OwnerDisplayName: georgelappies


问:
What's a good light-weight source repository for local development?
I'm doing some prototyping locally that I would like to keep in source control (for backup and revert purposes) but I don't necessarily want to publish it as open-source or make available online for others to view.

What source control system would you recommend for local development?  Any setup or walk through for my scenario is greatly appreciated.

I'm looking for:

Easy setup and administration. As this is my local machine, I'm constrained to Window OS and would really like to minimize the amount of environment configuration changes and necessary learning curve. There will only be one user, so I don't want to configure access rights, etc.

Low resource overhead, I want to host locally on my developer machine, so I don't want it sucking up my CPU.  I don't plan on storing massive amounts of data, either.

Familiar. I've used SVN clients before.  Visual Studio integration is a nice-to-have.

Portable. If I have to move it to a external drive or to another machine.

Free. Yes I want it all and don't want to have to pay for it.

答:
Putting a project in version control using Bazaar is as easy as:

```<code>bzr init
bzr add
bzr commit -m 'added files'
</code>```

If you are familiar with Subversion, then you should feel right at home with Bazaar: the most common svn commands work exactly the same way in Bazaar too.

Bazaar is very easy to learn, which is no accident considering that usability was part of its main design goals. Bazaar is a tool that's intuitive and easy to understand, and it doesn't get in your way. Bazaar is consistent throughout, there should be few or no bad surprises (I had tons of good ones).

It fits the bill as you described your needs, with the one exception of Visual Studio integration. The last time I evaluated it in 2010, it was not ready for adoption at my workplace, but things may have changed since then. (In any case you wrote this is a nice-to-have.)

Body:
Putting a project in version control using Bazaar is as easy as:

bzr init
bzr add
bzr commit -m 'added files'

If you are familiar with Subversion, then you should feel right at home with Bazaar: the most common svn commands work exactly the same way in Bazaar too.

Bazaar is very easy to learn, which is no accident considering that usability was part of its main design goals. Bazaar is a tool that's intuitive and easy to understand, and it doesn't get in your way. Bazaar is consistent throughout, there should be few or no bad surprises (I had tons of good ones).

It fits the bill as you described your needs, with the one exception of Visual Studio integration. The last time I evaluated it in 2010, it was not ready for adoption at my workplace, but things may have changed since then. (In any case you wrote this is a nice-to-have.)


问:
How to quickly adapt to a project?
Suppose my favourite open source application has a bug. Now I want to contribute to the application by fixing its bug and submit the patch to the development team. What's the most effective way to do this? Do you actually read the whole source code of the project (or most of it) to understand the logic before start fixing it?</p>

答:
No you fix the very small detail - the smaller and more local the patch the simpler it is for the owners of the project to understand, test and accept.

You should try and match their coding standards and ideally supply any small test code if possible

Title: How to quickly adapt to a project?


问:
What is better for coding - desktop or laptop?
Use of desktops are decreasing day by day in daily life but for coding purpose are there any reasons for using desktop over laptop? </p>

答: I agree with EpsilonVector, the big issue is monitor space. A laptop can usually support a second monitor. But a desktop can support three or four monitors. The more, the better.</p>


问:
How to achieve a loosely coupled REST API but with a defined and well understood contract?
I am new to REST and am struggling to understand how one would properly design a REST system to both allow for loose coupling but at the same time allow a consumer of a REST API to understand the API.

If, in my client code, I issue a GET request for a resource and get back XML, how do I know what to do with that xml? e.g. if it contains <fname>John</fname><lname>Smith</lname> how do I know that these refer to the concept of "first name", "last name"? Is it up to the person writing the REST API to define in documentation some place what each of the XML fields mean? What if producer of the API wants to change the implementation to be <firstname> instead of <fname>? How do they do this and notify their consumers that this change occurred? Or do the consumers just encounter the error and then look at the payload and figure out on their own that it changed?

I've read in REST in Practice that using a WADL tool to create a client implementation based on the WADL (and hide the fact that you're doing a distributed call) is an "anti-pattern". But I was planning to do this-- at least then I would have a statically typed API call that, if it changed, I would know at compile time and not at run time. Why is this a bad thing to generate client code based on a WADL?

And how do I know what to do with the links that returned in the response of a POST to a REST API? What defines this contract and gives true meaning to what each link will do?

Please help! I dont understand how to go from statically-typed or even SOAP/RPC to REST!

答:
Having a loosely coupled architecture, like in the case of a REST API server and its corresponding client, implies that both parties understand and respect a common protocol and semantics.

If the API modifies the semantics of its response, the client needs to be aware of it, and acd on the response accordingly.

Having said that, tools evolve and change. Because of the nature of decoupled architecture, any modifications on the API producer should be reflected on the consumer. However, for practical reasons this is not always possible. Usually for really radical modifications, the producer will expose different API endpoints, reflecting the old and new API functionality. This basicall buys the consumer time, up to the point that the old API is completely deprecated.


答:
If you're using Entity Framework Code first to manage your database schema, there is a migrations api (similar to Ruby on Rails' migrations). Although you are using C#, you essentially "declare" the migrations in code. And the framework handles the mechanics for you. In many cases, just the act of creating a new migration snapshot is enough for the system to automatically discover and make the migration work for you. Here are some references that discuss how it works

Visual Studio Magazine Article

ADO.NET Team Blog

Title: How could you reconcile declarative database development and non-trivial data 'motions'?

Body:
Coming back to SQL Server after several years away, I find the Visual Studio Database projects (and now SSDT) very exciting, as they are aiming to offer a way to develop databases declaratively, rather than having to mess around with change scripts.

However, the elephant in the room is the 'data motions' (I'm not too sure whether that's an official term): it's not too hard to automatically script a simple change in one table, but if you're normalising/denormalising, things get hairy very quickly.

Gert Drapers said as much in this TechEd video, and that they're trying to work out a way of working with these complex data migrations too.

The question: This got me thinking. How could you do this? Is there a way - even in theory - to define these data migrations declaratively? Or even a non-declarative way which could be combined elegantly with the declarative bits? Does anything like this already exist in other frameworks (I've vaguely heard something about Ruby/Rails?)

(I wondered whether to post this on dba, but I'm not sure whether they like 'good subjective questions (if this is one), feel free to migrate if necessary)


问:
Does custom created code for a client imply copyright ownership?
I know of a potential customer that has been paying for website development work on an hourly basis for several years by several independent contractors, but has never signed an agreement as to terms or ownership for it. They just get a bill and pay it.

So, does this mean that there is implied ownership by the developer(s) who wrote the software and I can't modify the code without something in writing?  Who owns the source code in this case as there are two other developers that worked on it?

By the way, I'm a developer in the USA, working in Missouri.

I did find this useful link that confirmed some suspicions I had about copywrite ownership of software.  They also have a free IP(intellectual property) ebook download.  No registration required either.

Disclaimer: I understand that any answers are not to be construed as legal advise perse, but I'm wondering if someone else has run into this issue and knows by firsthand experience.

答:
I'm not sure how it is in other countries, but here are some notes for US Copyright Law. I will prefix this with the inferred "I Am Not a Lawyer"

As an independent contractor, by default you own the copyright to anything you create. Unless you explicitly transferred the copyright to another party, you retain those rights...including the right to sell the work product you contracted to create for another party.

Many people believe stating that the software was written as work for hire is enough, but it's not. You still have to explicitly have the contractor transfer over the copyright


问:
When you won't need a language anymore, should you still use it?
My first main language was Java.  However, over the years I've dropped Java in favor for Python, JavaScript, bash, etc.  I still have advanced reading knowledge of Java, but since I haven't coded in it for so long, my writing knowledge is intermediate at most.  The other day, while looking at some old code written in Java, I got inspiration to re-write it as a learning experience to reacquaint myself.

It was at that point that I stopped to think that if I wrote this in Java, it would be nice, but when the renewed inspiration had hit me, I wanted to implement it as a web app (it was a game), so other people could play it.

So now here's the dilemma: Do I re-write (and heavily refactor) the code I've previously written in Java, and then in JavaScript (for the web version), or do I just forget about Java altogether and re-write it in JavaScript?

EDIT: I have no problem writing in Java first and then JavaScript, but I'm more likely than not going to need Java anymore for a long while.  What I'm trying to ask is whether or not I should rewrite the old code in Java first, to practice a skill I may not need in the future.  The actual languages are less important than that question.

答: Even if you don't use the "old" language directly, you will always find practical uses of it, either indirectly (ideas used originally in that language pushed in newer languages) or directly (in the case of Java you can see already how many languages are built on top of the JVM and encourage interoperability with existing Java libraries -- Scala, JRuby, Clojure, etc.). Using another JVM language means that you don't even need to rewrite your code: Just reuse it and write only the new parts in your favorite language.</p>