问:
Good Version Control Guidelines from a Development/Collaboration Perspective?
At our company we have started outsourcing some of our development.

This has worked somewhat well. However, we are having a hard time getting them to properly use version control. They are familiar with SVN and know how to use it. However, for some reason they don't commit regularly, instead they work with 16 things simultaneously and make a huge commits every 2 weeks, if we are lucky maybe with a few comments. Which makes it very difficult to both following and review their work, collaborate and also fix bugs. I have tried to explain to them to do their work as one small task at a time and regularly commit each of these with appropriate comments. Without much success, either they don't understand the concept or they are lazy.

My question is, what would be good guidelines describing how one should work with version control, not from a technical perspective (they know SVN), which seems to be the only thing I'm finding online, but from a development/collaboration/project perspective?

答:
The firm is an outside company, so you can't really dictate that they follow a certain philosophy, workflow, etc. internally.

However, you have hired them, so what you can control is the requirements for what they produce.  You don't need to convince them "this is a good process for programming"; all you need to say is "this is our company's process, and we expect what you deliver to conform to it".

Clearly outline your expectations, such as:

The frequency of commits you require.

Limitations on the number of changes in a single commit.

The way changes must be documented.

You don't really have to justify why you want to do these things.  However, it is likely that they will discover the benefit of these practices once they start using them.

Update I think Karl Bielefeldt makes some good points as well.  Ultimately, it depends on what kind of role the outside developers are playing.  There is a continuum: from contractors who work on site and are practically indistinguishable from employees, to an outside company that simply delivers a finished product to your specification.


问:
Keeping test and release version numbers in sync
I'm currently beta-testing an iPhone app. Right now I have sent out the first beta-test for my users and I have labeled that release as 1.0 for my testers.

Now since the testers have tested the app we have discovered some bugs that I have fixed and I'm ready to send out a new beta-test for my users. Should I label the release as 1.0.1 then?

Another question related to this is, when my testers have tested this 1.0.1 release and they do not find any bugs it would be a good time to release this version to the public in the App Store. What version number should I release this under in the App Store? First thought is that since it's the first release to the App Store it should have version number 1.0 but then it will be "out of sync" with the version that has been tested (1.0.1).

答:
Right now I have sent out the first beta-test for my users and I have labeled that release as 1.0 for my testers.

I would name it 1.0-beta1.

Should I label the release as 1.0.1 then?

I would definitely do that.

What version number should I release this under in the App Store?

Since nothing's changed after fixing discovered bugs, it should remain the same - 1.0.1.

First thought is that since it's the first release to the App Store it should have version number 1.0 but then it will be "out of sync" with the version that has been tested (1.0.1).

Not version numbers are out of sync, but versions themselves - thay are now different because of fixed bugs. They are different, so the numbers must be different.

I find semantic versioning scheme the most clear one: http://semver.org/

ContentLicense: CC BY-SA 3.0


问:
Why do some of object oriented languages let programmer use primitive types?
Why do some object oriented languages let the programmer use primitive data types? </p>

<p>Aren't classes like Integer, Boolean, etc. enough? </p>

答:
Sometimes you need full control of the size a number takes in memory. Or you may want to directly process binary data you read from a file, or copy from video memory if you process a screenshot or grab from some port, network connection, whatever.

In theory you could add more classes that are specialized in processing binary data, but depending on the actual history of a certain language and what exactly its usage intentions were at some time.

Performance may be a reason too in some cases. Especially with highly optimized compiled languages.

There are quite some languages that don't have primitives and are "object only".


问:
Should dependency relationships always be shown on class diagrams
I recently started using the Object aid UML generator plugin for Eclipse and noticed that by default adding of dependency relationships is switched off.

This made me wonder if in most cases they should not be shown or rather that most people don't want to show them, seeming as this is the default setting.

How do I decide whether to show dependency relationships or not?

答:
Show them if and only if they help understanding whatever aspect of the system that diagram is supposed to show.

UML is a tool for communication. If you can't say what a diagram communicates, you shouldn't have that diagram.


问:
How can I evaluate a candidate's knowledge of Html/CSS during an interview?
I am trying to determine some good interview questions to assess the ability of people coming in for a Html/CSS job, however that topic is extremely broad, and I'm not sure what sort of questions I can ask to properly evaluate someone's HTML/CSS knowledge.

What sort of questions can I ask to evaluate a candidate's Html/CSS abilities during an interview?

Ideally I would like to ask few questions and then give them a real life scenario to combat.

答:
One type of test which is applicable to programming languages and markup languages is a code review. Create a small sample (20 or 30 lines) with a mixture of syntax errors, logic errors, corner cases, arguably bad style... Then ask the candidate to identify anything which strikes them as suspicious.

It's important to use this kind of test correctly: as with any interview question, the way the candidate approaches the task is important, and not just the results.

I'm not going to post my test, but some hints for how to apply this to CSS:

Syntax errors: miss some semicolons. As a bonus, you can miss some optional ones (arguable style) and see whether the candidate comments.

Logic errors: put a prefixed property after the non-prefixed one. This also tests for familiarity with CSS3 and can provoke a discussion about the way in which the standard is developed.

Corner cases: e.g. a margin with 3 values - you'd be surprised how many people aren't aware that it's possible. If the candidate doesn't comment, you can ask how it's interpreted to check that they ignored it out of knowledge rather than ignorance.

Another corner case: exercise your favourite two or three IE7 bugs. This will distinguish those with battle scars (who should spot at least one of them) from the inexperienced or the Webkit-only.

Style: excessive specificity, missing em and px, etc. Someone who studied the syntax for the interview probably won't catch many of these.


问:
What is the Ken Thompson Hack?
I read some stuff like cm bell labs but i couldn't get it all. How does it work really? What is the logic in that?   </p>

答:
Reflections on Trusting Trust is a lecture by Ken Thompson in which he explains the hack. Briefly:

he hacked /bin/login to introduce a backdoor.

he did this by hacking the compiler to introduce the backdoor into a binary whenever it detected that it was compiling the login source code.

he also hacked the compiler to introduce the backdoor-producing code into the compiler whenever it detected it was compiling that.

His point was that you might think "I don't trust this binary, I'll build it from source" but now you're in a state of recursive paranoia. If you don't trust the binary, why do you trust the compiler binary? You don't, so you build the compiler: but why do you trust the compiler binary to produce a trustworthy compiler?

Title: What is the Ken Thompson Hack?


问:
What is the difference in a developer's years of experience with a language?
As stated by the title, what is the difference in years of experience in given language in terms of developers? For example, if one developer has had five years working with language A and the other developer has had two years working with language B followed by three years working with language A, would there be perceivable difference between them?</p>

答:
Expertise and deliberate practice.

If you don't practice deliberately, you will not gain expertise.
(You must examine your errors and correct them, practice what you are weak at, and having an expert to tell you what you are doing wrong helps too.)

If you don't try to improve, you can be a newbie forever!

After ten thousand hours of deliberate practice, you'll achieve expertise.
(This finding from education/training is all over the net.)

If your programmer A hasn't been deliberately practicing, they never get better.

If your programmer B hasn't been deliberately practicing, they never get better.

One other finding from the same research: that if I've got 15000 hours and you've got 10000, and I keep practicing and so do you, you will never be better than me.

Knowing two languages will probably make B a better programmer (subject to practice rules).

ContentLicense: CC BY-SA 2.5


答:
The ultimate reason is performance. There's a modern-day problem where people have gotten used to the very high level abstractions some languages provide and think that that's all there is to computing, unfortunately computer hardware still works like it used to back in the 70s.

This means that, whilst you may like to think that an elegant language should not support primitives, and that everything needs a default base class and every type needs to be a class, the level of abstraction involved would absolutely kill performance of your programs - simply because the computer still operates on the primitive types. Does this mean that your OO apps are slower than low level ones? Why yes - and they are, there's a reason things like device drivers are still written in C and not Ruby or Java (and its not just down to the programmers involved)

For the most part, OO apps don't notice too much performance problems when written as OO apps (even though I have seen some programs go into a massively convoluted mode where there are so many calls between objects the system spends all its time looking up vtables!) simply because the vast majority of the data processing is performed on primitive types. Replace then with objects and you'll see an entirely different performance characteristic. eg, just look at questions like this one where the questioner explains that using a double instead of a Decimal class made his program run "about 15x faster".

Title: Why do some of object oriented languages let programmer use primitive types?

Body:
Why do some object oriented languages let the programmer use primitive data types? </p>

<p>Aren't classes like Integer, Boolean, etc. enough? </p>


答:
In effect you are asking them to share unfinished work in progress with you, their customer.  That's not very common in outsourcing arrangements, and comes off as micromanagement.  Even if it's only partial outsourcing, like they are considered employees of your company, but are located in another country, remote sites usually have a lot of autonomy with work in progress.  Also, some cultures are especially sensitive about presenting a good face.

On the other hand, smaller commits are easier to work with after the fact.  You might have better luck with a different branching model.  With a DVCS, the remote team can have their own private branch to commit all their work in progress, but they can choose not to merge that branch until the task is presentable, i.e. at the end of the iteration.  You then get all the history, but they save face by not having to share incomplete work.  I don't know if that's technically feasible with svn or not.

Title: Good Version Control Guidelines from a Development/Collaboration Perspective?

Body:
At our company we have started outsourcing some of our development.

This has worked somewhat well. However, we are having a hard time getting them to properly use version control. They are familiar with SVN and know how to use it. However, for some reason they don't commit regularly, instead they work with 16 things simultaneously and make a huge commits every 2 weeks, if we are lucky maybe with a few comments. Which makes it very difficult to both following and review their work, collaborate and also fix bugs. I have tried to explain to them to do their work as one small task at a time and regularly commit each of these with appropriate comments. Without much success, either they don't understand the concept or they are lazy.

My question is, what would be good guidelines describing how one should work with version control, not from a technical perspective (they know SVN), which seems to be the only thing I'm finding online, but from a development/collaboration/project perspective?


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

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

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

I tried to find out the the cause of it by

Including log files

Debugging

Repeating the same environment.

But it wont repeat.

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

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

答:
I'm going to make an off-the-wall suggestion.

Go to the factory manager and ask to see the power line monitor records for that tool, or that area, for the times when the malfunctions occurred.  Also ask him if there was any welding, or any other unusual activity, at around those times.

Several decades ago, my father was having a hell of a time with a minicomputer that was crashing for no reason at all.  They called the manufacturer's customer rep.

The rep came into their office, in the factory area, and plugged a voltmeter into the wall, next to the mini, and then said "Watch this."

A few minutes later, the voltmeter suddenly sagged, significantly, then came back.  The rep said "That was him striking his test arc.  Wait a minute."  Shortly after that, the voltmeter sagged again, and this time it stayed sagged.

The rep said "That's your problem.  You've got a guy welding on the factory floor, and he's on the same power leg you are.  I saw him setting up as I was walking in."

They had to run a completely separate power feed to the office.

Title: Bug once in a while, but high priority


问:
Is storing types in the database an anti pattern?
A little background on where this question is coming from. In my current .NET application I'm working on some features related to archiving a certain type of business entity called a "Project". Depending on the situation what has to be archived, and the exact actions involved in archiving can vary wildly. My basic idea is to create an entity called an ArchiveSchedule which basically stores data saying this kind of project should be archived after this amount of time.

I want to encapsulate my queries for selecting all the objects to archive and the commands for actually archiving off into their own objects that inherit from some common interfaces. There will be multiple archive queries(select items based on various properties, or whether they've been archived before and later restored, etc), and multiple archive commands(ie commands that send data to different interfaces, some that perform deletes, etc.). What I'm considering doing is including on the ArchiveSchedule, references to the actual .NET type corresponding to the query and command I want to use for this schedule. Then when I want to actually run the queries and commands I use reflection to build up the object and execute the command or query.

Is this basic strategy of storing type information in the database and then using reflection to create the objects and inject dependencies an antipattern? Or is there a better way to do it?

Note:I know there are some issues with just storing the type name or namespace, because those might change during refactoring, but I believe those could be mitigated fairly easily using a GuidAttribute on the class definition and storing the guid instead, so I'm curious if there are more fundamental issues beyond that.

答:
This sounds like a possible candidate for a document database like Raven or MongoDB rather than a relational database.

With document databases you are not locked into a schema, you can store anything of any structure which could fit more with your data in that you don't necessarily know exactly what you want to store up front.


答:
A reflection system like this can be really brittle and it's not always clear why it's failing when it does fail.

It obviously fails when the type name isn't correct but there's no indication of why or how it's incorrect. For example, you could simply not have the appropriate assembly reference and then it'll fail. You can infer that based on having a proper type name (it works somewhere else when you do Type.GetType(typename)), but that's quite a bit of testing and poking around you have to do compared to other classes of bugs. In order to find the Guid, you'll have to search the appropriate assemblies which only partially mitigates the surface area for problems.

Your problem also isn't specific to the database, but any time you attribute type information to a persistent source. One issue is how you'll deal with changing properties (removing or adding) and other changes like that.

Another potential issue is performance, reflection is relatively slow but it's not likely to matter unless you're using it in a way that you probably shouldn't be.

Overall, I don't think I would call this type of thing an antipattern. There are DBs that are designed for object orientation which would be ideal here but then you'd have two DBs to maintain if the rest of your application fits better in a relational context. It can really save development time and reduce errors if used properly, but it can also cost a lot of development time and increase errors if this code is going to be modified a lot or the people consuming the code don't really understand it. It comes down to using tools properly.

Title: Is storing types in the database an anti pattern?

Body:
A little background on where this question is coming from. In my current .NET application I'm working on some features related to archiving a certain type of business entity called a "Project". Depending on the situation what has to be archived, and the exact actions involved in archiving can vary wildly. My basic idea is to create an entity called an ArchiveSchedule which basically stores data saying this kind of project should be archived after this amount of time.

I want to encapsulate my queries for selecting all the objects to archive and the commands for actually archiving off into their own objects that inherit from some common interfaces. There will be multiple archive queries(select items based on various properties, or whether they've been archived before and later restored, etc), and multiple archive commands(ie commands that send data to different interfaces, some that perform deletes, etc.). What I'm considering doing is including on the ArchiveSchedule, references to the actual .NET type corresponding to the query and command I want to use for this schedule. Then when I want to actually run the queries and commands I use reflection to build up the object and execute the command or query.

Is this basic strategy of storing type information in the database and then using reflection to create the objects and inject dependencies an antipattern? Or is there a better way to do it?

Note:I know there are some issues with just storing the type name or namespace, because those might change during refactoring, but I believe those could be mitigated fairly easily using a GuidAttribute on the class definition and storing the guid instead, so I'm curious if there are more fundamental issues beyond that.


答:
Yes, generally. You're then binding the type name to outside data, limiting your refactoring capabilities and making people change stuff in two places when they make a new class. Further, you're (or at least someone is...) going to be a world of hurt in ~10 years when C# becomes out of date. New implementations might not have the same classname, let alone idioms for instantiation.

I would tend towards not including this in the database, and even if you did, storing some implementation agnostic form of the command. That might be more work, but is a bit more flexible and robust design overall.


问:
Functional Reactive/Relational Programming – Is there a difference?
I've been using Reactive Cocoa (by GitHub), a Functional Reactive Programming API for use with the Cocoa libraries for a while now, but have just read "Out of the Tar Pit", the paper that supposedly presents the concepts behind it, and I am a little confused.

The paper presents (as I understand it) Functional Relational Programming, where relations between data are created with conditions that should be enforced by the FRP system to reduce the amount of 'accidental' logic and state needed.

My question is, are these two concepts - FR(eactive)P and FR(elational)P essentially the same thing (with the former just being an implementation of the latter) or is there a core difference between the two? Unfortunately at the moment my knowledge of the area isn't good enough for me to differentiate them enough.

If there is a difference, it appears to be something to do with, as the name suggests, reacting to changes in data. Certainly, Reactive Cocoa (and Rx in C#) have the concept of creating signals which are triggered on changes in data, and can be used to continuously modify a value over time.

Is this the difference? If not, what is?

(Please excuse the poor tagging, I can't find relevant tags and can't create them yet - please update the tags to something more appropriate if you can.)

答:
A reaction can propogate a change without involving a relational model. C = A + B  Change A and/or B and C will react to the change (but could end up with the same value).
On p. 42

The approach of functional relational programming (FRP16) derives its
  name from the fact that the essential components of the system (the
  logic and the essential state) are based upon functional programming
  and the relational model (see Figure 2).

footnote 16

Not to be confused with functional reactive programming [EH97] which
  does in fact have some similarities to this approach, but has no
  intrinsic focus on relations or the relational model


问:
Unit Testing and "Fit"
I am reading Cristopher Alexander's "Notes on the Synthesis of Form", and he is describing a solution to a problem as having good fit, when there is an absence of bad fit; we can't describe all of the qualities of good fit because it's too complex, but we can identify the bad qualities that stick out.

The complexity of software means that we can't understand all the possible relationships - the qualities of good fit, but we can identify when code isn't doing what it's supposed to - the bad fit.

I'm wondering then, is the purpose of unit tests to identify a "bad fit" in the solution?

答:
Not exactly.  They can but generally I would say no.

The tests show that certain functionality is in the solution.  They do not show how well the solution has been written but only that the functionality works.  As an example, tests do not show how maintainable your code is.

Some of the tests, that overall requirements (also called functional tests) would help demonstrate that the solution is a "good fit" to the problem.  However, there are other aspects of the solution that the tests do not cover (maintainability, extensibility, etc).

OwnerDisplayName: teabee

Title: Unit Testing and "Fit"


答:
Because 90% or more of the time you use primitive objects with primitive semantics anyway, not typical object semantics.  The compiler has to carve out special privileges and restrictions for primitive objects, like:

They are automatically instantiated for a literal.

They must be immutable, in order to allow it to optimize down to a computer architecture's native types.

They have value semantics for assignment, when other objects usually have reference semantics for assignment.

They are allowed to overload or define operators, even if other objects aren't allowed to do so.

They can be used as constants and as part of constant expressions at compile time.

If you're going to make a primitive object that the compiler treats differently than every other kind of object, some language designers feel you may as well provide separate and explicit syntax for primitives.  In other words, if an int and an Integer have different behavior and are used in different contexts, it makes sense to make them different types.

It makes the language more internally consistent, and makes translation to native instructions much easier.  It's also more consistent with the mental model of most programmers.  Even in languages where primitives are objects, most programmers don't consider a statement like int a = 0; to have all the overhead of regular objects, and they would be right.

In other words, primitive objects aren't "just like" other objects, no matter how big of a superficial resemblance.  Some languages just don't try to hide the differences from the programmer.


问:
What is LPCTSTR?
what is LPCTSTR and LPCTSTR-like (for instance HDC) and what it does stand for?

答:
Quoting Brian Kramer on the MSDN forums

LPCTSTR = Long Pointer to a Const
  TCHAR STRing  (Don't worry, a long pointer is the same as a pointer. There were two flavors of pointers under 16-bit
  windows.)

Here's the table:

LPSTR = char*

LPCSTR = const char*

LPWSTR = wchar_t*

LPCWSTR = const wchar_t*

LPTSTR = char* or wchar_t* depending on _UNICODE

LPCTSTR =  const char* or const wchar_t* depending on _UNICODE

Title: What is LPCTSTR?


问:
Where can I get free public raw data?
In web development, a mashup is a web page or application that uses and combines data, presentation or functionality from two or more sources to create new services.

There are many sources for getting data (raw information). Governments are good examples.

However many of those cost and have complicated licensing.
For instance SMHI in Sweden sells temperature data meanwhile our neighbor country Norway gives it away for free.

One would say what kind of application are you building and what data do you need?  I would say give me some interesting data and I will do a good mashup of it. I could just plot it on Google maps for instance.

So the question is: Where can I get free data?

Note: I'm not interested in data mining using a webcrawler!

Please share your sources with me.

答:
USA

New York Times API

Title: Where can I get free public raw data?

Body:
USA

New York Times API


问:
What to do when your colleagues don't value code maintainability
I've been working in the same software development department for a few years now.  In that time, the average stay of a developer has been 6-9 months.  A handful have been around for over 2 years, but the majority of our 20 or-so developers come and go at a relatively high rate.

As a result, the majority of our projects have become maintenance nightmares.  Contractors will come in, code a few patch releases, and leave.

Our department has development guidelines (we do TDD) but they aren't enforced.

Recently, I've been pushing for our department to produce more maintainable code.  I've been asking for mandatory code reviews and mandatory TDD.  Management fully agrees with me... in theory.

In practice TDD always goes out the window.  The justification is always that, in our domain, we need to deliver NOW.

I keep going on and on to colleagues that we're just digging a hole for ourselves, and that our current approach to software development is costing our department a lot of money... but it seems to fall on deaf ears.

What can I do to get my colleagues to see the value of code maintainability?  How can I explain that short-term wins without a long-term vision is not sustainable?

答:
It's not your colleagues that you need to convince.

If management truly agreed with you, they'd be enforcing the code reviews and TDD.  As it is, they're just nodding their head to make you stop bothering them.

I see two options here:

Make a pitch to senior management about how high employee turnover and lots of client facing bug reports are costing them money.  Include in your pitch a viable solution that involves enforced code reviews, TDD, etc.  Wrap a time frame around it and promise to deliver.  They might make you a manager in charge of fixing it.

Leave.  If you know it's going to collapse, why stick around?


答:
You are overthinking your problem. Most O/RM's support what's called Object Hierarchy Mapping. Using the Strategy Pattern, you can encapsulate the logic for archiving your Project into a ProjectArchiver hierarchy. Provide an Id for the Archiver and map it to the database.

The base class should have a virtual Archive() function, that all the child classes implement.

When the object is retrieved from the database, it will create an instance of the appropriate subclass with the correct implementation of Archive. And all you have to do is call it.


问:
Design Patterns for Javascript
A lot of web frameworks have a MVC-style layout to code and approaching problems. What are some good similar paradigms for JavaScript? I'm already using a framework (jQuery) and unobtrusive js, but that still doesn't address the problem I run into when I have more complex web apps that require a lot of javascript, I tend to just end up with a bunch of functions in a single, or possibly a few files. What's a better way to approach this?</p>

答:
From a practical standpoint, take a good look at AngularJS and KnockoutJS.  These frameworks solve real problems that you encounter when building JS heavy applications.  Angular is a more "all inclusive" solution with many advanced freatures, whereas Knockout only tackles the problem of realtime UI updating.  Both are very nice, and when used correctly can help structure your application in an MVC style while actually being productive.  There are a plethora of other "JavaScript MVC libraries" out there, but frankly, most of them just try to shoehorn an MVC pattern without actually solving any real world problems.

As commented, JavaScript Patterns is a very useful book that takes a lower level look at what patterns are actually useful in the language.

Title: Design Patterns for Javascript


问:
How the Compatibility View in IE works behind the scenes
When I remote connect to my work PC, in IE10, the juniper remote client service which is basically a plugin executed in the browser does not run. I need to turn on compatibility view to see it. My question is what exactly is happening behind the scenes in compatibility view such that such a large number of compatibility problems can be fixed with it? What did they do...make a list of deprecated APIs that was running ok in ie8 but deprecated in ie10 and then on clicking compatibility view, those APIs are supported again?</p>

答:
Basically, IE attempts to find the best compatibility mode first before rendering the page with the newest version of its engine, IE10 in your case. But before, IE more or less follows the given flow:

Checks if there is the meta-tag in the header of the page: <meta http-equiv="X-UA-Compatible" content="IE=IEX" />, where "X" is either 7, 8, or 9. When a page includes this meta it instructs IE to display it with the standards mode of the given browser version, which means that it will use the standard engine of that version.

Checks if the content of this meta-tag is something like <meta http-equiv="X-UA-Compatible" content="IE=EmulateIEX" />, agian, where "X" is either 7, 8, 9. This instruction is for displaying the page with the compatibility mode of the given browser. The difference from the standards mode is that here you basically tell him to use the compatibility engine of that version.
It may be useful if you want to display a page as if it were Internet Explorer 5.5, by specifying (IE=Emulate7), since IE7 compatibility mode made it possible to display old legacy pages designed for IE 5.5

If no X-UA-Compatible meta tag is found, the browser renders the page with the newest engine, UNLESS you explicitly chose to load it in compatibility mode... I think that it's your case, because let's face it 99.9999999999999999999% web pages do not specify any compatibility mode :-)

To sum it up, IE either uses the standard mode of the specified engine, OR it completely emulates the rendering of the page with a previous engine, thus allowing for legacy pages to be displayed properly. Since they use a different engine, it may explain why a plugin works in one case and does not in another.

For much more detailed information, check the MSDN article on that subject.

Edit: found that practically the same question is available in Pro Webmasters SE!


答:
An extension on RalphChapin's answer:

Over the years I have had to hunt a fair number of bugs that only showed themselves on systems I couldn't duplicate because of attached hardware.

In addition to logging like crazy one other thing I found useful:  Putting information on the screen showing where the code was and values of some relevant variables.  When the problem showed up even the factory floor workers could read me the information.

It usually took a few rounds of refinement to pin it down exactly but it was very effective.

Title: Bug once in a while, but high priority

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

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

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

I tried to find out the the cause of it by

Including log files

Debugging

Repeating the same environment.

But it wont repeat.

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

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


问:
Are SMART goals useful for programmers?
Several organisations I know use SMART goals for their programmers. SMART is an acronym for Specific, Measurable, Achievable, Relevant and Time-Bound. They are fairly common in large corporations.

My own prior experience with SMART goals has not been all that positive. Have other programmers found them an effective way to measure performance? What are some examples of good SMART goals for programmers (if they exist).

答: The trouble with SMART goals is that they have to pick what is measurable. Since what is measurable and what important to organization success are often not the same thing  (And virtually never are in programming), SMART goals always fail in performance appraisals in my experience. And sometimes things appear measurable but are not without far too much effort (Like the SMART goal I had one time to answer all emails within 4 hours.   Really who wants to try to go through the thousands of emails I get a year, determine if it was informational or needed an answer and then look at my sent emails to see if I did answer it and then listen to recordings of all phone calls to see if I answered it, check my IM log to see if I answered it,  etc. And what about that email that got sent to me on Saturday night at midnight...) </p>

Title: Are SMART goals useful for programmers?


问:
Setting up and syncing a developer (local) version and a public version of a website
What is the best and most efficient way to set up two versions of the same website?

I want one version that is online and open for everyone to use but I also want a developer version where I can develop and test new things instead of doing that against the ftp.

Currently I have MAMP setup on my developing machine and I use Git for version control.

In MAMP/XAMPP the location for the files are localhost/example/ and on the ftp it is the host's (Dreamhost's in this case) file structure. Something like /home/username/example.com/. That results in having multiple versions of pretty much the same file. This isn't that efficient but I can't come up with a good solution for it. Are there any?

It would be perfect if I wanted to add a new feature to the website I could do that in MAMP and when i commit the changes with Git it uploads the changes to the ftp.

答:
what I do with XAMP is that I have on my local an entry called a.com that points to my 127.0.0.1

so i reference pages as a.com/....

Keep the same files in both the places.  have some custom include that checks if the current page has a.com and makes root links differently. Something like :

```<code>if( $_SERVER['SERVER_NAME'] == 'a.com'){
    $filePath = 'images/'
    $url = "http://a.com";
    $env = 'd';
}else{
    $imgPath = '/home/sites/example/images/'
    $path2 = "http://example.com";
    $env = 'p';
}

    //now this can be an include file in other files
    //in the other files just use the previously initialized variables when making paths and URLs. This keeps the code in the main files simple and the details in one file
</code>```

Body:
what I do with XAMP is that I have on my local an entry called a.com that points to my 127.0.0.1

so i reference pages as a.com/....

Keep the same files in both the places.  have some custom include that checks if the current page has a.com and makes root links differently. Something like :

if( $_SERVER['SERVER_NAME'] == 'a.com'){
    $filePath = 'images/'
    $url = "http://a.com";
    $env = 'd';
}else{
    $imgPath = '/home/sites/example/images/'
    $path2 = "http://example.com";
    $env = 'p';
}

    //now this can be an include file in other files
    //in the other files just use the previously initialized variables when making paths and URLs. This keeps the code in the main files simple and the details in one file


问:
What is the difference, if any, between Model and QA environments?
I have worked for various organizations many of whom call their environment that comes after the test/developer environment and before the staging and/or production environment either model or QA.

They all seem to use this term interchangeably, however, is there any technical difference or should there be a difference in these terms? Or are should they be completely interchangeable terms?

答:
I think its just different isolated environments where you can test different things. we have a QA that has all the features of the next version. A pre prod that mirrors the prod for a week before a release and at least a week after.

And we have many dev and local instances of our apps.

The pre prod systems are used for patches and other security related updates. So is the QA if they systems guys want to test something before putting it even in pre prod (if they have 2 different ways to go and do not want to pollute the pre prod before knowing more).
Its more up to the people you work with to come up with 'jargon' that helps you all understand things easier and faster.

A firm can decide:-
Model -> what is prod/ pre prod

QA  ->  more bleeding edge, could have some features broken (especially if you do not have automated suites/ large junit/ selenium/ other test coverage) and some features wired differently then production or being planned for production.


问:
Where's the separation between Presentation and Logic in Javascript MVC frameworks?
I had learned that following piece of code is bad because it is obstrusive javascript and mixes presentation with logic:

```<code>archive
</code>```

The best practice was to add some sort of identifier to the link element and then bound an event to it on a separate file. Something among those lines

```<code>$("#archive").click(function() {
    //do stuff
});
</code>```

See: Why is using onclick() in html a bad practice

How come now most Javascripts MVC frameworks like Backbone.js, Angular.js, etc now encourage pieces of code like this:

```<code>archive
</code>```

Taken from: http://angularjs.org/#todo-html

Why is this now ok?

答:
To be honest, I consider it ugly because of the () which look too much like eval'd code.

However, the reason why it's still "clean" is that you are not dealing with a global function or are able/encouraged to put arbitrary code in that attribute. Instead you specify that the element will use the method with the given name in the controller.

Body:
I had learned that following piece of code is bad because it is obstrusive javascript and mixes presentation with logic:

```<code><a href="" onclick="archive()">archive</a>
</code>```

The best practice was to add some sort of identifier to the link element and then bound an event to it on a separate file. Something among those lines

```<code>$("#archive").click(function() {
    //do stuff
});
</code>```

See: Why is using onclick() in html a bad practice

How come now most Javascripts MVC frameworks like Backbone.js, Angular.js, etc now encourage pieces of code like this:

```<code><a href="" ng-click="archive()">archive</a>
</code>```

Taken from: http://angularjs.org/#todo-html

Why is this now ok?


答:
I'm no expert, but I would assume the answer has to do with the fact that you don't want your view model knowing anything about the view. Backbone and Angular are considered MVVM frameworks, often using a sort of "command" pattern where the view most notify the VM that an event has occurred.

Not all MVVM frameworks use the same syntax. Knockout "looks" like it provides a bit more separate, even though it does roughly the same thing as the other frameworks.. http://knockoutjs.com/examples/helloWorld.html

Title: Where's the separation between Presentation and Logic in Javascript MVC frameworks?


答:
I see this happen a lot when one developer works on a project exclusively for a long period of time. They know where the pitfalls are and how to work around them, and so they generally don't care that they exist. The number one way to convince developers to employ common coding standards and best practices is to get them to work on other developer's code from time to time. They will see pretty quickly the value of self-documenting code, proper exception handling, cleaning up dead code, etc. Do this once or twice and your fellow developers will be happy to adopt these practices.

With managers, it's usually a different story. Good managers will respond to complaints from developers and proactively look for ways to improve your company's coding practices. Bad managers won't care, as long as the product gets out the door on time. For these types of managers, you will have show them what's wrong with how you're doing things. Explain that it takes twice to three times as long as it should to train a new developer, or that it takes a days to find bugs which could be fixed in a matter of minute, all because the code base is a mess. If possible show real, concrete cases of the costs associated with poorly maintained code.

Title: What to do when your colleagues don't value code maintainability

Body:
I've been working in the same software development department for a few years now.  In that time, the average stay of a developer has been 6-9 months.  A handful have been around for over 2 years, but the majority of our 20 or-so developers come and go at a relatively high rate.

As a result, the majority of our projects have become maintenance nightmares.  Contractors will come in, code a few patch releases, and leave.

Our department has development guidelines (we do TDD) but they aren't enforced.

Recently, I've been pushing for our department to produce more maintainable code.  I've been asking for mandatory code reviews and mandatory TDD.  Management fully agrees with me... in theory.

In practice TDD always goes out the window.  The justification is always that, in our domain, we need to deliver NOW.

I keep going on and on to colleagues that we're just digging a hole for ourselves, and that our current approach to software development is costing our department a lot of money... but it seems to fall on deaf ears.

What can I do to get my colleagues to see the value of code maintainability?  How can I explain that short-term wins without a long-term vision is not sustainable?


答:
Screw explaining things to people.

It might be easier to get management/other devs onboard with some type of Continuous Integration. Then, if the tests don't pass, the code doesn't ship. End of story.


答:
Forget about FTP.

Setup a bare repository on the server

Add it as remote to your development environment.

Clone the bare repo to the webspace, adapt the configuration files.

Add a post-commit hook on the bare repo, starting a shell script on the webspace that pulls from the bare repo.

With that, you just push your changes to remote, and it is automagically drawn into the webspace.

Any environment specific constants do not belong to the code, but into configuration files, which are added to .gitignore.

Title: Setting up and syncing a developer (local) version and a public version of a website

Body:
What is the best and most efficient way to set up two versions of the same website?

I want one version that is online and open for everyone to use but I also want a developer version where I can develop and test new things instead of doing that against the ftp.

Currently I have MAMP setup on my developing machine and I use Git for version control.

In MAMP/XAMPP the location for the files are localhost/example/ and on the ftp it is the host's (Dreamhost's in this case) file structure. Something like /home/username/example.com/. That results in having multiple versions of pretty much the same file. This isn't that efficient but I can't come up with a good solution for it. Are there any?

It would be perfect if I wanted to add a new feature to the website I could do that in MAMP and when i commit the changes with Git it uploads the changes to the ftp.


问:
Why doesn't git merge adjacent lines without conflict?
I recently learned that when merging two branches in git, if there are changes on two adjacent lines git declares this a conflict. For example, if file test.txt has this content:

```<code>Line 1: A
Line 2: B
Line 3: C
Line 4: D
</code>```

and in branch master we change this to

```<code>Line 1: A
Line 2: B1
Line 3: C
Line 4: D
</code>```

while in branch testing we change this to

```<code>Line 1: A
Line 2: B
Line 3: C1
Line 4: D
</code>```

and then attempt to merge testing into master, git declares a merge conflict. My naive expectation was that the merge would happen without conflict and yield this:

```<code>Line 1: A
Line 2: B1
Line 3: C1
Line 4: D
</code>```

I am sure there is a good reason why git doesn't merge this way. Can someone explain this reason?

答:
I'm mostly guessing, but I think it has to do with line 2 being used as context for the line 3 change.

Git can't just say that "The line with C became a line with C1" because there could be another line with "C", so it says "The line with C, that's right after the start of the file, the line with A, and the line with B, is now C1"

If "the line with B" is no longer there, then some of the context is lost, and git can only tell roughly where the new line has to go.


问:
Should a web developer understand TCP/IP and how routers manage requests?
I had a job interview today for a Job position as developer on an important site. They asked tonnes of programming language related questions, which I managed to answer without problems, but then they started asking question about how TCP/IP requests were made once I made a request on my PC to a web server. I did received those contents as a student, but I dont remember them well, because I'm working mostly in web development, my question is:

As a software developer, mainly working on web applications, do I need to have extensive knowledge of TCP/IP and how routers manage requests or it's just black box knowledge to me?

答:
Few things are more frustrating than folks who don't understand the fundamentals of what is going on around them. It leads to asking the same questions over and over again (in slightly different form, of course.)

When you find yourself asking repeat questions, it's time to hit the books. Recent examples of questions I've received:

"How do I configure the network if xyz?"...

"How do I configure the network if abc?"...

Repeat...

In fact, I got so many repeat questions from folks who found it easier to ask again than learn, I started keeping track of them and making Powerpoint slides. Now, every six months or so, I run a hands-on class. Folks are then able to reference the slides I made. Later, when they ask something we covered in class, I gently refer to it, and they usually recall that we covered it and go re-read the slides for themselves. Those who do so actually learn the subject better and find it valuable. It has made a remarkable difference in the form of fewer interruptions to my workday.

One other thought:
In the real world, real systems have so many quirks and issues, it's incredibly limiting to not know more than just your domain-specific knowledge. Any idea how the underlying fundamentals work can only help you.

Now, if it truly is out of scope for what you should know, then fine, don't worry about it. But if you find yourself asking the question more than once, learn it. You'll not regret it.

Bravo for asking the question. Never stop learning.


问:
Can a lone programmer become a mid or senior level programmer without a mentor?
Question:

Can a mere entry level programmer become a mid or senior level programmer working in a company as the only programmer without a mentor?

Background:

I was hired as an entry level programmer for a mid size company that does not do programming except for internally.  I am regarded as a genius inside the company with a decent salary but after 2 years I decided I wanted to move to an actual software company.  The interview processes have been extremely demoralizing because even though I have wrote intra-company enterprise applications these interviews have made me aware of how little I actually know.

答:
Mid-level, yes though you will need significant study time of the industry you're in to know what is common. This stuff is usually picked up bit by bit by all the engineers in a company and shared amongst them. You're going to have to do the research and study of all those engineers yourself just to know and meet industry standards.

Senior-level however includes mentoring, leadership, and organizational skills you simply won't learn without teamwork.


答:
While it is possible, I'm not sure I'd see it as that probable.  Consider that if you did make the next killer application you could possibly make a lot of money but the chances of making something that will take off like that is rather small.

While you don't have a mentor at your workplace, couldn't you network with other programmers and find a mentor that way?  I'd suggest that to improve your skills where you may now realize you have gaps is to reach out to others within a community and it may be worthwhile to find those groups where other programmers may frequent.

Title: Can a lone programmer become a mid or senior level programmer without a mentor?

Body:
Question:

Can a mere entry level programmer become a mid or senior level programmer working in a company as the only programmer without a mentor?

Background:

I was hired as an entry level programmer for a mid size company that does not do programming except for internally.  I am regarded as a genius inside the company with a decent salary but after 2 years I decided I wanted to move to an actual software company.  The interview processes have been extremely demoralizing because even though I have wrote intra-company enterprise applications these interviews have made me aware of how little I actually know.


问:
Do system background services affect languages benchmarking?
Today I was looking at some blogs on Ruby and Python. A Python loyalist wrote a few lines of code with a loop to show how Python is faster than Ruby, with a similar code. I also found a blog of a Ruby disciple who says that it is wrong and he too submitted a code sample and benchmarking results.

I am wondering whether background programs or background processes may sometime hinder the results and we may not get exact benchmarking scenario.

Please correct me if I am wrong.

答:
Yes they can.

Normally just common sense in taking results from a couple of benchmarking runs, having some idea of what to expect, and being aware of what background services might fire up on your machine (beware indexing/search services in particular) and slow it down will generally avoid being seriously mislead by results.  I've found this to be more of a problem with automated performance testing where there is no human in the loop to go "WTF... ?  Oh the stupid foo service just started an update".

For purely compute benchmarks, I've found running the benchmark process at a higher than normal priority can usefully give more consistent, stable results on "busy" machines.  This may not work if I/O is a factor though (depends whether your OS' notion of priority just affects CPU scheduling or I/O too).


问:
Which should I be learning, HTML or XHTML?
I'm just learning HTML, but some say XHTML is better. The W3C recommends XHTML, and I know W3C is more credible, right? </p>

答:
HTML is standard,  XHTML is old XML based anachronism...

Since you are begginer good start at learning HTML would be to analyse existing Web pages around the web, by either using web dev tools inside browsers or some web-app that let's you analyse layout of a web-page and all HTML tags on it like webdeconstructor.com for instance ....

be persistent and results will come


答:
Mentor Yourself

sometimes the only choice is to teach yourself

fortunately, the Internet makes that extraordinarily easy these days

pick the areas you want to learn about, google for tutorials, and go

for deeper dives, explore nearby university libraries for ACM and IEEE publications


答:
Mentors are overrated in software development.

Certainly, if you can find someone who really knows what they're doing and who is willing and has time to help you improve your programming skills, you'd be foolish not to take advantage of their help. Some organizations try hard to set up those kinds of relationships, both to help you become more productive and also to keep an eye on what you're producing.

However, I think it's much more common that people learn from a variety of sources, including:

teammates: not just a single mentor, but everyone you work with

code reviews: there's nothing like having your code (or even someone else's) picked over by a group to sharpen your sense of what's considered good and not good in your organization

existing code: the more time you spend maintaining other people's code, the more you'll learn how to (and how not to) write your own code

books: reading is fundamental

internet: reading blogs and sites like Programmers.SE and Stack Overflow will expose you to lots of opinions about the "right" way to do things, and you'll start to develop your own opinions

experience: most important; you really can't appreciate the benefits and/or drawbacks of a given idea unless you try it out; write lots and lots of code

friends: having some friends who are also programmers is a huge help even when they're not your "mentors" but just people to chat with

If you can learn from some or all of these sources, having a mentor is helpful but not required for you to improve your skills.

If you want to climb the corporate ladder more quickly, talk to your supervisor about what you need to improve. Make it clear that you're working hard to improve, and show them that helping you improve will be worthwhile. You may be able to take classes, go to conferences, connect with other developers in the company, etc.


问:
Using oAuth as a complement to an existing authentication system?
I am hoping this is the correct stack exchange to be asking this, here goes.

I am building a new website whereby it implements its own custom login system. You simply register your username, email password etc. Then you're free to log in with the option of clicking "remember me" to save the hassle of logging in every time. For simplicity, let's call this the Custom Login System and an account a Custom Account.

However, I am very interested in integrating some 3rd party login systems via oAuth that are offered by the likes of Facebook, Google and Twitter.

My question is, is it feasible to have a mechanism whereby:

you log in via Google, for example

my script confirms the tokens and all that good stuff to ensure you authorised the login

I then ask you to either link your Google account to:

an existing Custom Account or

a new Custom Account by asking to register one after logging in with Google

once you've logged in to your Custom Account, I treat you like any other user except I assume the "remember me" option was ticked and set a cookie that logs you in from here on as if you were using a normal Custom Account the whole time.

This could essentially mean that I don't need to constantly query Google's servers, only during login. Then from there on, as long as they have a valid cookie they will stay logged in.

Is this possible? Are there any obvious flaws that I am missing out?

答:
It doesn't look wrong at the level you are describing; there are certainly sites that offer both types of login (e.g., SourceForge). When you're dealing with this sort of thing, you're absolutely right to cache the information in the session; re-querying the oAuth provider on every operation would suck in terms of performance, and it would also be tricky to do given that these advanced web-based auth schemes are actually based off doing quite a bit of form processing.

However, you probably need to take some care to ensure that you don't open you clients to attacks by the nefarious. In particular, as the session cookie is now a real security token (after auth) you must make sure it is HTTPS-only and that it is only ever sent from one address (unless the client explicitly says “I know my IP address is liable to change”; some people are stuck with poxy proxies like that). You probably also need to make the auth-ness expire after a while, at least for more sensitive operations. There's probably more you need to think of as well, but I don't know the detailed state of the art in this area.

Getting all this right is a bit tricky as there are so many gotchas, so you should look for a library that handles the low-level details for you. I don't know the world of libs for PHP at all, so I can't mention anything specific. (Were you using Java I could help more…)


问:
How to end my dependency on .NET?
I have been developing Windows GUI applications since many years and jumped into .NET in early 2005. .NET is a undoubtedly a remarkable platform and I am still using it, but with a variety of technologies out there, I don't want to remain dedicated to this camp. I want to learn new languages with which I can develop GUI applications.

I am learning Ruby and just installed Python. I read about WxRuby, a framework for developing Windows GUI app. in Ruby. I am searching for a similar framework for Python.

Apart from that I want to know which language is more suitable for a production-level GUI app. I doubt that Ruby is more focused on Web platform with it's glamor, Ruby on Rails.

I know that I may not get those rich .NET classes and that impressive Visual Studio IDE, but still I want to follow the road less traveled. I don't want to go with IronPython and IronRuby, however sometime later, I may dip hands to explore them.

答:
Look into other programming languages that work with the .Net runtime, like IronRuby and IronPython. Next, check out the mono project.

These steps will get you out of your .Net comfort zone and developing on Linux. From there, it's a small leap to full-on UNIX-style development.

Title: How to end my dependency on .NET?


问:
Why validate XML?
I am looking for an explanation on just why XML needs to be validated. I have been testing DTD's and Schema's for the past month and recently tried to find out why I am doing this. I know it makes the XML better and more Semantic but what are the overall benefits of validating XML?</p>

答:
To make sure that it works. Sure, if you only write out some data for your own application to read it may be enough if it just works. If you send a file to somebody else matters may be different. But even within your application you may later choose to switch the parsing library and the new one may complain about errors the old one accepted and ignored like not properly escaping some characters.

Or, depending on the kind of data you store, some new characters may appear (maybe a user with a foreign name) and from that moment proper character set definitions may be important. Same if you just send an XML file from Windows to a Linux system. The closer you keep to definitions and validations the less likely you run in unexpected trouble when things change.

Title: Why validate XML?


答:
It depends on how you're using the XML.

For example if you wish to pick out one or two pieces of data out the XML then move on then it would be best just to extract them and move on.

However if you need the whole XML document, so for example you want to transform it to some other XML format that needs all the fields, then I would get a schema involved.

It also depends on the relationship you have with the person sending you the XML : if you're receiving XML from a party you need to be formal with (e.g. another business) then having XML schemas allows you to establish a contract about what you will accept as input and give as output.

On the other hand if you have an informal relationship with then you can be generous with what you will accept / reject.

Title: Why validate XML?

Body: I am looking for an explanation on just why XML needs to be validated. I have been testing DTD's and Schema's for the past month and recently tried to find out why I am doing this. I know it makes the XML better and more Semantic but what are the overall benefits of validating XML?</p>


问:
Writing your own framework or using an existing one?
I know there are similar questions to this one, and I've read most of them. Most of the answers to these questions are talking about "cost-effectiveness" and "time-saving" aspects of the frameworks, which are huge reasons in favor of using frameworks.

I'm a pretty new .NET developer and I'm trying to learn stuff like WPF, MVVM, layered architecture design, dependency injection, logging, database access, test-driven development, and many more different technologies/techniques.

Most of the resources that I find regarding such topics start with an extremely simple example to "show" why you should use given technology/technique, which honestly looks quite ok with that simple example, but doesn't really make sense for someone who didn't deal with real-world problems these technologies/techniques help with.

After the simple example that makes me wonder what that specific technology/technique really solves, they usually go on and say "Hey, you know what, there's a framework for that called ..., let's just use it for the rest of the examples." Dependency injection? Just use Ninject. You want to fake stuff? C'mon just use Moq. MVVM? You're kidding me? just use MVVM Light Toolkit!

Which is great, really. All these tools, I'm sure, make the life easier for all the developers out there. But my problem is,

I'm trying to use TDD, but I have never experienced the problems people experienced while they were developing stuff without TDD, which in the end made them come up with such a technique. I understand the concept behind, theoretically I can see why it was created, but in practice I am not experienced enough to see a code that would benefit from TDD. Because I haven't seen much.

I have never had problems developing a huge application that I needed to de-couple stuff and went "Oh my god! That is ridiculous! I need to find a technique so that I won't have this much trouble next time." and found out about "Dependency Injection". All the small things that I have developed so far worked fine without the need of dependency injection.

I have never written a WPF application that made me feel like things should be easier, presentation layer should be separate, there should be data binding. Hell, I haven't even written one WPF application!

So all these things make me think like I am going to use all these tools, without experiencing first-hand any real world situation that cultivated the creation of them.

But at the same time, I can't try to write a huge business application in WPF without using MVVM or a good layered-design and experience all the problems people experienced in the past to appreciate all these new technologies/techniques. Because there are people out there developing stuff, getting further ahead, releasing things that work. I'll be left behind because of my obsession with trying to learn everything out there to learn. And besides, these things are not easy to learn without first experiencing the problems yourself.

But then, at the same time I have those nightmares that I start working in a new company and people tell me "You can't code your own MVVM framework? You always need to use Prism? Hahahahaha!" and they go around pointing and laughing at me in circles.

I feel like I'm a lesser programmer. I feel like I don't have what it takes to create a framework on my own. I feel like I am only able to put things together, which are created by other "better" people.

I would like to ask all the experienced people out there, what strategies have you used throughout your career? Do you always use existing frameworks? Do you create pet projects to learn about why those frameworks exist?

To make a long story short, what constitutes the thin line between using a framework and creating your own? And more importantly, how do you close the knowledge gap that automatically comes up if you use a technology/technique without seeing the real-world problems they help with?

答:
Like all good programmers you're going to be continuously doing three things: learn something new, discover new problems, build solutions. The more time you spend writing code (building solutions), the better you'll get at the other two because you'll unravel new problems and learn something new that is useful.

You want to know how or when to use a new framework or methodology, but think about something a little simplier like the comment writing life-cycle:

Notice all published code examples comment everything.

Because of time constraints, useless comments, and no one reviews your code and forces you to write comments, you don't write any at all.

Return to old code and discover it's difficult to understand.

Research the best way to write comments and discover all the schools of thought: must write them or else, use a commenting tool, write self-commenting code because comments go stale, etc.

Maybe the comments aren't the problem? Like everything else, you won't get it right the first time. This is why mentors are so important (and often lacking) in the development process of new programmers. There is too much going on to trial and error everything. You could spend your whole career and never need an ORM because you never write an app that uses a database.

Wanting to learn things is a great tool for a developer as long as it is a healthy curiosity and not an obsession that prevents you from getting something built. TDD may help you since you focus on only fulfilling the requirment by coding enough to pass the test. Eventually, you'll be coding something and come to the conclusion, "There's got to be a better way of doing this." Go find a framework or just write your own.


答:
Practicing doing a skill the wrong way doesn't help you learn it.  You will have plenty of chances when you do it wrong by accident, or to maintain code that was done poorly by someone else.

I also find it fascinating that in these sorts of questions people only worry about the highest layer of abstraction.  You're building on decades of programming language research, design paradigms, operating systems, databases,  computer architecture, CMOS technology, on down, yet are only worried about not understanding the reasons for innovations in the last 10 years or so.

When people started making web pages, there was no such thing as frameworks.  In another ten years, there will be improvements to things you learned the hard way, and a newbie will wonder if they understand the underlying reasons for those improvements enough, and completely take TDD, dependency injection, MVVM, etc. as a given.  There are people still working who remember when there was this new-fangled notion that they should break things into relatively small functions.

In other words, don't worry about lacking the experience of the previous ten years.  In the next ten years a whole new kind of experience will be required.

Title: Writing your own framework or using an existing one?

Body:
I know there are similar questions to this one, and I've read most of them. Most of the answers to these questions are talking about "cost-effectiveness" and "time-saving" aspects of the frameworks, which are huge reasons in favor of using frameworks.

I'm a pretty new .NET developer and I'm trying to learn stuff like WPF, MVVM, layered architecture design, dependency injection, logging, database access, test-driven development, and many more different technologies/techniques.

Most of the resources that I find regarding such topics start with an extremely simple example to "show" why you should use given technology/technique, which honestly looks quite ok with that simple example, but doesn't really make sense for someone who didn't deal with real-world problems these technologies/techniques help with.

After the simple example that makes me wonder what that specific technology/technique really solves, they usually go on and say "Hey, you know what, there's a framework for that called ..., let's just use it for the rest of the examples." Dependency injection? Just use Ninject. You want to fake stuff? C'mon just use Moq. MVVM? You're kidding me? just use MVVM Light Toolkit!

Which is great, really. All these tools, I'm sure, make the life easier for all the developers out there. But my problem is,

I'm trying to use TDD, but I have never experienced the problems people experienced while they were developing stuff without TDD, which in the end made them come up with such a technique. I understand the concept behind, theoretically I can see why it was created, but in practice I am not experienced enough to see a code that would benefit from TDD. Because I haven't seen much.

I have never had problems developing a huge application that I needed to de-couple stuff and went "Oh my god! That is ridiculous! I need to find a technique so that I won't have this much trouble next time." and found out about "Dependency Injection". All the small things that I have developed so far worked fine without the need of dependency injection.

I have never written a WPF application that made me feel like things should be easier, presentation layer should be separate, there should be data binding. Hell, I haven't even written one WPF application!

So all these things make me think like I am going to use all these tools, without experiencing first-hand any real world situation that cultivated the creation of them.

But at the same time, I can't try to write a huge business application in WPF without using MVVM or a good layered-design and experience all the problems people experienced in the past to appreciate all these new technologies/techniques. Because there are people out there developing stuff, getting further ahead, releasing things that work. I'll be left behind because of my obsession with trying to learn everything out there to learn. And besides, these things are not easy to learn without first experiencing the problems yourself.

But then, at the same time I have those nightmares that I start working in a new company and people tell me "You can't code your own MVVM framework? You always need to use Prism? Hahahahaha!" and they go around pointing and laughing at me in circles.

I feel like I'm a lesser programmer. I feel like I don't have what it takes to create a framework on my own. I feel like I am only able to put things together, which are created by other "better" people.

I would like to ask all the experienced people out there, what strategies have you used throughout your career? Do you always use existing frameworks? Do you create pet projects to learn about why those frameworks exist?

To make a long story short, what constitutes the thin line between using a framework and creating your own? And more importantly, how do you close the knowledge gap that automatically comes up if you use a technology/technique without seeing the real-world problems they help with?


答:
I'm a pretty new .NET developer and I'm trying to learn stuff like WPF, MVVM, layered architecture design, dependency injection, logging, database access, test-driven development, and many more different technologies/techniques.

I've seen a great talks once about how to learn something quickly (sorry, can't find it):

Follow the 20-80 rule: learn just the 20% you need that cover 80% of the use cases. Do not get stuck in details. Understand the basics and work with those until you hit a wall. And you probably will hit the wall at some point. But you will have covered a lot of ground by then. If there's no way to cover most of your use case with little use of the tool, then it's the wrong tool for the job and chances are, there's a better one out there.

Do not learn too many things at a time. You say right now you don't need any of the tools you think are good. That's ok. Your next step is not to try them all out at once. Pick one. The one that seems most useful for the task at hand. Apply it. When you get a grasp of it, proceed by recursion.

But then, at the same time I have those nightmares that I start working in a new company and people tell me "You can't code your own MVVM framework? You always need to use Prism? Hahahahaha!" and they go around pointing and laughing at me in circles.

I feel like I'm a lesser programmer. I feel like I don't have what it takes to create a framework on my own. I feel like I am only able to put things together, which are created by other "better" people.

A few advices, although not all are specific to programming:

Get rid of your ego. That's a life time challenge tackled step by step. But you will need it. If you're less worried about the image of yourself you're trying to project, you'll have more time for thinking about what you have to say. Most people will return the favor with respect.

The question that's really important is: What can you do? How you do it, is completely irrelevant. All that matters to your boss, your users and people who build their code on yours is how quickly you can do it (i.e how much it costs), how flexible it is in the face of changing requirements and how usable it is (from a user perspective or when interfacing from other code). Whether you use a 3rd party tool or reinvent the wheel every time from scratch doesn't matter. The perceivable consequences do.

Do not be bothered by assholes. The vast majority of those who have acquired noteworthy skills as developers (or any area) know how much time and work it takes. Most will go out of their way to help you if you ask them (and then really let them help you). Only a few will try to demean you. More often than not, those are the people who feel a need to compensate for their own lack of skill.

Do not assume that there are many people who successfully put together a "general purpose frameworks" on their own. By "successfully", I mean that people will use it and contribute to it and the mainstream will largely consider it as one of the out-of-the-box solutions for a particular problem. By that time, the project has usually been iterated for at least half a decade, having undergone constant review and enhancement by many people and with feedback of literally thousands - most of all the involved people being quite experienced. And most of the time, it's a successor or knock-off of some other technology that went through the whole maturation process already. There's no shame in using that. To the contrary: if it solves your problem, not using it is a waste of resources. It's often a sign of arrogance or ignorance or the combination of both.

That being said: there's a lot of bloated "frameworks" out there that suck. As Douglas Adams once pointed out the titchyness of the human brain is best illustrated with how amazed it is by big things. When people see a big framework with a lot of documentation, they assume it must be good. The opposite is often true. It's often an indicator of over-engineering.
But usually, for any given common problem you will often find a well-tested well-designed solution already available.

To make a long story short, what constitutes the thin line between using a framework and creating your own? And more importantly, how do you close the knowledge gap that automatically comes up if you use a technology/technique without seeing the real-world problems they help with?

When a tool get's the job done, use it. Understanding "the job" is the tricky thing. That's the first and most important step. Then you need to pick your tools. And then do it. And then you might realize that your understanding of "the job" just got better, so you need to add/substitute some tools and parts of the program. The likelihood of this happening is part of "the job" and is an important factor in choosing your initial toolset.

Would you rather have a crash in a 50 year old car to appreciate all the safety built into a modern one? I don't think so. You have your own slices of hell coming anyway. There's absolutely no need to ask for more trouble.

You must always choose what to know, but also what not to know. This is the foundation of information hiding, which is the divide and conquer of complex systems. Your programming language already is already a big white cloud high up in the abstractosphere of planet ugglydetailia. You look at things from an abstract level, because your brain can actually only function this way. It's how you deal with the real world and it's quite sensible to apply that to programming.

Also, knowledge in itself is worthless. Value comes from understanding. Which quite often involves the knowledge of what not to know ;)


问:
When to separate a project in multiple subprojects
I'd like to know if it makes sense to divide the project I'm working on in two repositories instead of one.

From what I can say:

Frontend will be written in html+js

Backend in .net

The backend doesn't depend on frontend and the frontend doesn't depend on the backend

The frontend will use a restful api implemented in the backend.

The frontend could be hosted on any static http server.

As of now, the repository has this structure:

root:

frontend/*

backend/*

I think it's a mistake to keep both project in the same repository. Since both project do not have dependencies between each others, they should belong in individual repositories and if needed a parent repository that has submodules.

I've been told that it's pointless and that we won't get any benefit from doing that.

Here are some of my arguments:

We have two modules that don't depend between each others.

Having source history of both projects in the long term may complicate things (try searching in the history for something in the frontend while you have half of the commits that are completely unrelated to the bug you're looking for)

Conflict and merging (This shouldn't happen but having someone pushing to the backend will force other developer to pull backend changes to push frontend changes.)

One developer might work only on the backend but will always have to pull the frontend or the other way around.

In the long run, when it will be time to deploy. In some way, the frontend could be deployed to multiple static server while having one backend server. In every case, people will be forced to either clone the whole backend with it or to make custom script to push to all servers the frontend only or to remove the backend. Easier to just  push/pull only the frontend or backend than both if only one is needed.

Counter argument (One person might work on both projects), Create a third repo with submodule and develop with it. History is kept seperated in individual modules and you can always create tags where version of backend/frontend do really work together in sync. Having both frontend/backend together in one repo doesn't mean that they will work together. It's just merging both history into one big repo.

Having frontend/backend as submodules will make things easier if you want to add a freelancer to the project. In some case, you don't really want to give full access to the codebase. Having one big module will make things harder if you want to restrict what the "outsiders" can see/edit.

Bug introduction and fixing bug, I inserted a new bug in the frontend. Then someone fix a bug in the backend. With one repository, rolling back before the new bug will also rollback the backend which could make it difficult to fix. I'd have to clone the backend in a different folder to have the backend working while fixing the bug in the frontend... then trying to remerge things up... Having two repository will be painless because moving the HEAD of one repo won't change the other. And testing against different version of backend will be painless.

Can someone give me more arguments to convince them or at least tell me why it is pointless (more complicated) to divide the project in two submodules. The project is new and the codebase is a couple of days old so it's not too soon to fix.

答:
Some of your arguments are valid and some are not.

We have two modules that don't depend between each others.

That is actually not entirely true. To be able to communicate, both front-end and back-end need to have a common interface (description).
That makes it a weak argument in favour of having both in a common repository. But only a weak argument as it does not make that much of a difference.

Having source history of both projects in the long term may complicate things (try searching in the history for something in the frontend while you have half of the commits that are completely unrelated to the bug you're looking for)

This is a bogus argument. If you want to look up how a particular bug got fixed, you look in the bug-tracker for which commit contains the fix.
And if you want to know how a particular piece of code evolved, you look at the history of a single file  (or at most a handful). In either case, having other files, possibly from other modules, in the repository should not complicate things in any way.

Conflict and merging (This shouldn't happen but having someone pushing to the backend will force other developer to pull backend changes to push frontend changes.)

This is a bogus argument. I am not aware of any (half decent) VCS where you need to synchronize the entire repository before you can commit/push your changes. At most you need to synchronize the folders that contain the changed files (and often only the files themselves).

One developer might work only on the backend but will always have to pull the backend or the other way around.

This is the same bogus argument as the previous one.

In the long run, when it will be time to deploy. In some way, the frontend could be deployed to multiple static server while having one backend server. In every case, people will be forced to either clone the whole backend with it or to make custom script to push to all servers the frontend only or to remove the backend. Easier to just push/pull only the frontend or backend than both if only one is needed.

Depending on how people envision that the deployment will be done, this can be a valid argument.
If the deployment will be done by unpacking a zip file/tarbal on the server, then it does not matter how your repositories are organized.
If the deployment will be done by checking out (part of) a repository on the server, then it can be a good idea to use separate repositories for modules that get deployed separately.

Counter argument (One person might work on both projects), Create a third repo with submodule and develop with it. History is kept seperated in individual modules and you can always create tags where version of backend/frontend do really work together in sync. Having both frontend/backend together in one repo doesn't mean that they will work together. It's just merging both history into one big repo.

This is a valid argument, but it is not that strong.

Having frontend/backend as submodules will make things easier if you want to add a freelancer to the project. In some case, you don't really want to give full access to the codebase. Having one big module will make things harder if you want to restrict what the "outsiders" can see/edit.

This is a valid argument.

Bug introduction and fixing bug, I inserted a new bug in the frontend. Then someone fix a bug in the backend. With one repository, rolling back before the new bug will also rollback the backend which could make it difficult to fix.

That is a bogus argument, because it would mean that after two bugfixes to one module, you would not be able to revert the first one. Any half-decent VCS will allow you to roll back just about any old commit (although it will often mean that you make a new commit that reverses those changes, sometimes even for the top of HEAD).

I'd have to clone the backend in a different folder to have the backend working while fixing the bug in the frontend... then trying to remerge things up... Having two repository will be painless because moving the HEAD of one repo won't change the other. And testing against different version of backend will be painless.

This is actually quite a good argument.
Having two repositories makes it easier to test the scenarios where the deployed front- and back-ends might become (slightly) out of sync.

ContentLicense: CC BY-SA 4.0


问:
Use client to access database or server to access database
I' creating a client server application in which I need to update a particular database. I'm using python with MySQL. There are two options:

I use a client.py and server.py, the client.py can send data packed into JSON to the server, the server.py will handle the database and send query data back in the form of JSON.

The second option is that there is no server.py file, instead the client accesses databases and queries directly with the MySQL server.

Is there any benefits to using one method to another?

EDIT:

There can be atmost about 100 clients and they will be sending data throught the day with a delay of about about 20 seconds.

答:
The benefit of having client.py connect to port 3306 directly is you don't need to write (and debug) any JSON marshaling code. And you won't need to deploy and maintain instances of server.py. Keep it simple, implement, and write down some timing measurements.

You didn't describe latency or throughput requirements for your application. Number of hosts running client.py matters. Speed of light delay between client and server matters. DB connection pooling might prove useful. Implement the simplest thing that could possibly work, take measurements, and iterate from there.


问:
How to find local maxima in matrices?
I need to develop an algorithm for finding all the local maxima in a two-dimensional array: how to search for local maxima in the the most efficient way? Are there algorithms about it?

Moreover, the algorithm should be able to handle even the "flat" peaks, that is it should find the central coordinates of each peak. Here's an example with a one-dimensional array: some consecutive elements have the same peak value, so the algorithm should return the central location.

```<code>                       |       flat peak       |
                       |-----------------------|
array = [...  0.8  0.9  1.0  1.0  1.0  1.0  1.0  0.9  0.8  ...]
                                   |
                            desired result
</code>```

How to handle the problem of the flat peaks in a two-dimensional array? In the flat peaks, the neighbor elements are equal to each other and form a single local maximum, so I would like to get the central coordinates of this neighborhood.

答:
Determining whether a point is a local maximum is straightforward, just query its 4-neighborhood (or perhaps Moore neighborhood if you're concerned about saddle points). Return true if value is >= value of each neighbor.

Your "desired result" remark puts a slight wrinkle on this. You might choose to populate a new dst matrix from your src matrix. You could smooth out values with Gaussian blur or by sliding a window across the data for a moving average. Or consider identifying contour lines with ConRec or Marching Squares. Adding a little noise could leave you with a much simpler problem.

If you really want to operate on unmodified values, you'll need more than one pass. Fill dst matrix with zeros. Fill in one in positions corresponding to local maxima in your src matrix. Set color=2. Now scan the entire dst matrix from the top, looking for ones. As soon as you find a one, flood fill with color, increment color, then keep scanning. At the end you can see all the local maxima, each with a distinct color. Find the average (x,y) position of all color 2 values, and so on for each color.

You can do this with a single bit per source value. In first pass, set boolean dst values so they correspond to local maxima in src matrix. In second pass, scan for set bits, flood fill, clearing them, and compute average (x,y) during flood fill.

Title: How to find local maxima in matrices?


问:
Manage version control with a central development server (LAMP)
I'm working in a small team with up to 5 (web)developers. Because our team is growing frequently and we ran into problems with multiple people working on the same code we decided to set up a VCS.

Current Situation

Currently we are working with a central development server (LAMP). So every developer works on the same code base and if the code is tested and ready for our live server we just copy it via ftp. I know this is some sort of an anno 1600 workflow but yeah - it is what it is and also the reason for this question.

On the development server our directory structure looks like this:

```<code>/var/www
      /Project1
      /Project2
      /Project3
      ...
</code>```

Additionally there are some small non-webapplications - Android/iPhone/Windows 8 etc. apps and some C# tools which also should be included in the VCS.

Goal and problems

Our goal is to get a clean setup for a VCS, which works together with an issue tracking software, enables us to work togheter on the same project at the same time without overwriting our codes and simply gives us the advantage of version-control.

I think the first question for us is, which technology should we use. Some of us have allready experienced subversion. But because git is some sort of becoming the "standard" and there are a lot of "pro git" arguments among the web users we tend to using git.

There starts our uncertainty. For using git - a decentralised VCS - it looks like we have to start using seperate development servers on each developer's computer. The problems with that are:

Some times we work on different computers, so when we forget to push our code we have a problem.

We would have to work with virtual machines because the dev servers should be the same as our live server (This would simply not be enforceable in our environment, believe me it's not possible).

The development server usually also served as a "tryout" or "presentation" server where non-developers had a look at what's going on.

Is there another possible setup with git so that we are able to benefit from the system while still using a single(!) development server? Maybe with different directories for each developer. Or can we still work on the same code base with maybe locking the files we are working on and then commit them to a repository. It's maybe important to say that while it became a factor for us it is still uncommon that multiple developers work on the same part of an application at the same time.

答:
You're on the right track, here.

Maybe with different directories for each developer.

Yes, definitely different directories for each developer.

The machine you're on is is pretty uninteresting. Just ensure that each developer logs in as himself, and checks out a copy of the git repo under his own home directory. You'll wind up with several copies of the code living in your filesystem, but hey, disk is free.

It's true that git supports decentralized operation. But you won't be using it that way in your typical workflow. Just make sure that a bare repo is available on some convenient server, and have everyone pull from that. Access it via http, ssh, or even via the filesystem if you like.

You mentioned a "tryout" area as part of your workflow. Do yourself a favor. Hire another developer, named Jenkins, who also checks out your code using git. He's implemented here:  http://jenkins-ci.org/  (and runs under http://tomcat.apache.org/download-70.cgi). That way every push to the central repo will immediately make an updated version of your website available under Jenkins' home directory, where you can quickly try it out and run sanity checks. We call this Continuous Integration, and it will definitely improve your workflow.


问:
Linear probing hashing collision resolution
So I have a quick question about the linear probing method of collision resolution in hash tables. So by definition a linear probing method would look like:

```<code>while (hashTable[hash] != null)
    hash = (hash(key) + step) % tableSize;
</code>```

But in my case I know exactly what the table size will be, I know all the keys, so I'm wondering if this is a valid alternative implementation:

```<code>while (hashTable[hash] != null) {
    if (++hash == hashTable.length)
        hash = 0;
}
</code>```

I'm sorry if I made it too confusing, but I'm a little confused myself... If you can't get what I'm asking, a simple explanation of how linear probing would be implemented would be very helpful, and ps: I'm working in java. Thanks alot

答:
If you know all the keys, then you should use a perfect hash function; gperf can help with that. With a perfect hash, collisions needn't be handled, since they cannot happen.

This does not quite make sense:  "hash = (hash(key) + step) % tableSize"
Either you meant "hash = (hashFunction(key) + step) % tableSize", which looks like double hashing,
or you mean "hash = (hash + step) % tableSize", which is indeed linear probing.

Your second code fragment makes sense, and is valid.

The trouble with linear probing, especially with step size of one, is it encourages clustering, so O(1) operations degenerate to O(n) operations even at moderate load factors.


问:
algorithm to create all possible column vectors of size N containing only ones and zeroes
I am a mathematics student and am just starting to learn about programming. I am stuck on a particular program I am trying to write for fun. I want to find an algorithm to create all possible column vectors of size N containing only ones and zeroes and combine them in one large matrix by putting all the columns after each other. The order of the columns is of no importance. For instance if N=3 I want to get the matrix:

0 1 1 1 1 0 0 0

0 0 1 0 1 1 1 0

0 0 0 1 1 0 1 1

which vertically contains all possible combinations of ones and zeroes of length 3. Does anyone have any idea how to do this? I am not necessarily looking for a very efficient or clever way to do this because the value I will be using for N is 14, so my matrix will be 14 x 2^14 which is 14 x 16384 which is not too big. Also, sorry for the formatting of my question, I am used to the math stackexchange where you can use LaTeX text to make your matrices and equations look nice. Thanks to anyone who can help me along!

答: In your example you are just writing down all numbers from 0 to 7 = 2^3 in binary form (the columns of your matrix). So, for a mathematician, the generalization for the general case should be obvious. You'll need to have big int to your avail to pursue that idea, though. Which should not really be a problem, though.</p>


答:
It's a bit like asking, why do we test our programs. We do it in case they are wrong.

Of course there are scenarios where you know the data isn't wrong, because the program that generates it is well tested and well trusted. In that case you don't need to validate the data. It's not compulsory.

Title: Why validate XML?


问:
Is it reasonable to use Javascript MVC Frameworks for closed source paid web applications?
I am wondering if it is reasonable to write closed source, paid web apps in Javascript (JS MVC Frameworks like AngularJS, Backbone, Knockout, ...)? I'm concerned because in this type of frameworks you use typically a REST backend for CRUD operations and the majority of business and application logic happens in Javascript which can be looked up by anyone using my app. He can see how i do things.

When I use for example PHP or Java (Wicket) most of the logic is happening on the server and so a lot less of my source code is exposed. This seems to me a lot safer if I want to have an edge over my competitors, so potentially I earn more money.

So is it reasonable to use JavaScript MVC Frameworks for paid applications? Does it depend on something and if yes on what?

答:
There is at least one major error in your question: In an REST backend the business logic still is on the server. It has to and having business logic in the browser would be pure madness.

From there we can go on and see that the most complex part of any serious web app rests on the server anyway. The browser can only take the View part of the MVC, maybe a few elements from Controllers. Main Controller functionality and especially Model are just to security relevant.

Beyond that: What do you want to write as web apps? If I want to do something smart, I don't look at my competitors, I use Google and StackExchange to find that it was done before a hundred times or at least something similar. There are libraries for mostly everything. The times when keeping your code a trade secret are gone, at least when we are talking about the user interface.