答:
Cheating is the name of the game. You should always take the easiest route you can when making any sort of development decision. Call it cheating, call it "being productive"; it makes no difference. You should choose the tool that helps you get the job done with the least amount of effort (of course, do not forget about maintenance and scalability).

Now specifically with IB, you should weigh the time saved by IB vs the cost of having to maintain code that is sloppier and that you are less familiar with. This is really a case by case and person by person sort of decision. In many cases, tools and wizards allow you to get a lot more work done with a low added maintenance cost... and sometimes they introduce slop code and more leaky abstraction than you know what to do with. It sounds like you have made the decision for yourself that IB is worth any costs it adds to development, however, your friend might just as easily find that the tool hinders him more than it helps.

Body:
I have a friend who has a slightly greater amount of programming experience as me. We were talking about all the different programming technologies we use and Interface Builder came up in conversation.

Being of no programming background except for what I've taught myself, I personally believe that IB and all it's features (IBOutlets, IBActions) help coders of my skill level (and all skill levels, for that matter) complete projects of theirs in less time.

His view of IB is a little enthusiastic. He believes that coders that utilize Interface Builder are "cheating" in the fact that they don't have to lay out interfaces by hand.

Question:

Should using a GUI builder to lay out interface elements be considered "cheating" (since most programming originally required laying interfaces out by hand in code)? Why?


问:
Open Source Project: Company to register copyright
I'm releasing an open source project. I want to make it as inclusive as possible for any community that might embrace it. Specifically, I don't want the code copyrighted in my name when an entire community might work on it; that approach seems self-centred and alienating. My immediate thought to avoid this issue is to assign the copyright to a company rather than myself. How do I do this? Do I have to register a corporation? Can I just give the name of a group and call that a company? What legal hurdles are there? I honestly have no idea when it comes to this sort of thing.

(I'm in Canada and want to use the GPL, if that helps.)

答:
You have two issues that you are wrestling with here.  Licensing and Copyright.

Licensing is how you intend to allow others to use your code.  You stated you wish to use GPL.

Copyright is who owns the expression of the ideas that your code represents.

You may allow others to use your code (aka license their usage) without giving up ownership of that code.  Any modifications to the ideas (code) would subsequently be owned by the authors making the changes.

You need to answer what it is your truly are trying to accomplish.

If you just want others to be able to use your code, modify, and re-publish, then licensing is all you need to worry about.  And you're done in this case, since you've settled upon the GPL.

If in the future you want to be able to fork the project and re-license it under a different license, then you'll need to worry about copyright.  All copyright owners must agree to the re-licensing of the project.  And that's where things start to get tricky.

If you want others to be able to re-license the project without your intervention, then you would need to renounce your claim to copyright of the code.  Note that future users would still need all the other contributors to do the same thing, or they would have to get re-license permission from the other copyright owners.

If you plan to shepherd this project for some time, and reserve the right to re-license in the future, then you'll want to have contributors assign their copyright to you or provide some long term means of contacting them for future approval.

Based upon your question, I think you are looking at the simple case and just want others to use  your project freely.  That's a license question, and you're already done since you picked GPL.

ContentLicense: CC BY-SA 3.0


问:
Proper & Efficient Structure for an entity layer?

Context

Web application based on the .NET Framework written in C# and following the MVC design pattern.

Question

What is the most efficient way to structure an entity layer consisting on various data inputs?

Background

I am developing an application for a client that requires my reading and writing data from various sources and I would like to build a single entity layer/model to abstract the various data sources so that I only need to query the unified model from code.  Here is an example of the disparate sources:

MS SQL Data Warehouse (about 200 tables of enterprise-wide data

MS Dynamics AX web services

A new MS SQL database that is specific to the application being developed

MS Active Directory for authenticating users and for getting user profile and group information.

In some cases, SharePoint web services.

I have used ADO.NET a good bit (.edmx files and so forth) and fundamentally, I know how to do this but I am struggling a bit with a solid, clean approach.  Do I create two separate .edmx files for the two SQL DBs and then write object classes for the Active Directory, SharePoint and AX stuff?  Do I simply write one big model file?  A whole separarate project just to make the abstraction?

Many thanks!

答:
I have previously used the repository model in a project that sounds very similar to this. I captured entities as plain classes and then for the entities that were stored in SQL I used Entity Framework Code First to generate the tables in SQL for me. Also, if your information will be stored in multiple databases you will just need a DBContext class for each datasource. Using the repository model will allow you to point to any source to populate each repository of entities.

As far as web services, I generally split these out into another project to make a physical division between a service layer and a data layer.

So in this scenario I would have 2 projects. One for the data layer (this would implement the repository pattern, include related entities, and handle CRUD to datastores using EF or ADO.Net), and one for the service layer (this will talk to AD service, SharePoint services, and any other services. It will also contain the related entities for these services).


问:
Searching in a repository
I'm very new to source control management and one thing puzzles me: is it possible to search through the whole repository for a string? For example I'm tracking one file, which has 100 commits and I would like to see all the version of the file which contain "xyz" inside.

Is this possible? I'm using various GUI clients and non of them has this..? Yes, they can search trough commit messages but I want to find a version even when the commit message does not contain the string.

To put it differently, which GUI client has such a feature? I don't care about which SCM it uses - git, hg, bazaar, all are fine.

答:
Very crudely, you could

```<code>git log -p -- path/to/file
</code>```

Then search in there (using '/xyz') and find the commits you're looking for.  There's probably a better way, but that's a quick and dirty solution that doesn't take much thinking.

Update:  SourceTree from Atlassian allows you to search through mercurial and git repositories based on commit message or file changes.  I think this probably does just what you want.  The user interface for SourceTree is pretty complex, and I'm not a huge fan of it myself, but when you open your repo in it, you can click the search magnifying glass tab at the very top left of the window, then select search "File Changes" in the drop down to the right of the search box.  Hope this helps.

Title: Searching in a repository

Body:
Very crudely, you could

git log -p -- path/to/file

Then search in there (using '/xyz') and find the commits you're looking for.  There's probably a better way, but that's a quick and dirty solution that doesn't take much thinking.

Update:  SourceTree from Atlassian allows you to search through mercurial and git repositories based on commit message or file changes.  I think this probably does just what you want.  The user interface for SourceTree is pretty complex, and I'm not a huge fan of it myself, but when you open your repo in it, you can click the search magnifying glass tab at the very top left of the window, then select search "File Changes" in the drop down to the right of the search box.  Hope this helps.


问:
How to manage, in practice, licence files when combining GPL and BSD licensed code?
I am writing code that uses one library with GPL (not LGPL) license, and one with the 3-clause BSD license. Since I link to GPL-licensed library, my code will need to be GPL as well. How should I, in practice, deal with the original LICENSE.txt from the BSD-library?

(A) Can I distribute a project so that the main source code is GPL-licensed, and then some subdirectory is BSD-licensed?

(B) If I were not only to link to libraries, but to use and combine the BSD and GPL code in a more involved manner, what to do with the LICENSE.txt then?

The 3-clause BSD text tells: "Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer." so apparently I should retain the copyright notice, and that list of conditions, somewhere. But then I'll also need to put the GPL license txt-file somewhere.

Further, apparently I don't need to retain the "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:" part of the BSD license text, since it only tells me to retain the other parts.

So, how, and in which text files, should I in practice organize the GPL license text and the parts of the BSD license and copyrights that I retain?

EDIT: So in case B, I would be taking 3-clause BSD licensed code, and redistributing it under GPL, which is permitted, as 3-clause BSD license is (one-way) compatible with GPL. I am just asking how to deal with the license texts and textfiles in practice.

答:
For simplicity, it is probably best to release the entire thing under GPL. 3-clause BSD license has no form of copy-left, so you are well within your rights to rebrand it, as long as you maintain its notice.

You will end up with two kinds of files:

Originally BSD files: needs to have both headers, order isn't important to my knowledge, just that they are there

Your files and originally GPL files: need to have the GPL header

And of course for any binary release you will need to include a link to source and both headers in some form of another. I would recommend the standard GPL, followed by "Portions of this program were originally released under the following license" or something like that, you can likely find examples of this happening in the wild if you look for it.

Note that I am not a lawyer, nor do I specialize in either open source licensing, or licensing in general. I am simply relaying what my interpretation of the given licensing combined would look like.


问:
What's the difference between using RDFS/OWL versus XML?
I was wondering what advantages the ontology languages of RDFS/OWL has over using a tagging/markup system (such as http://www.schema.org/) for managing and creating metadata?</p>

答:
I would like to start by noting that this answer is not written by an expert in the field. Although I'm a proponent of semantic distributed systems, I think the applications of OWL are currently limited. Although describing precisely the niche in which OWL can be applied would be beyond the scope of this answer, I might be able to bring to light some pro's and con's.

OWL is basically a language which allows the expression of semantic constructs using classification, not unlike the classes you known from OOP and constraints between classes and their instances. One could see it as a more formal and higher-order way to describe relationships you know from a relational database.

To describe and communicate this language, it needs to be serialized to a certain format. There are several formats, of which RDF is just one.

There are three different levels of OWL, allowing for increasing expressiveness, but limiting computability (eg. whether you can find a possible solution to the questions you ask the knowledgebase described by an OWL definition). These are OWL Lite, DL and Full.

The most important advantage of using OWL/RDF is the exchange of knowledge between different knowledge bases (or classification hierarchies) and creating useful inferences without having to engineer all these bases beforehand to allow them to communicate. This is done in part by defining equivalence classes. Using namespaces allows the engineer to ascertain uniqueness; a useful paradigm.

Another advantage is the ever increasing amount of inference engines and query languages. In our networked world, there is a demand for distributed knowledge exchange.

Perhaps an important disadvantage is the relative high complexity of ascertaining the computability of inferences and their space and time constraints. Eg. in OWL full you might be able to ask for inferences which cannot be proven to terminate. Thus, there is certainly a limit to the power of OWL.

OWL knowledge is discrete... there are no half-truths or believe systems. Having these would most likely make the solutions way too complex.

But the most important disadvantage to my taste is that one simply cannot find many good engineers in the field. You'll need a knowledge engineer, one or two computer scientists and a small development team to build even a small knowledge base. Therefor, it is often much cheaper and effective to just use descriptive languages such as XML schema and describe the needed semantics in a human-readable document.


答:
This simply is not possible according to multiple interpretations of the license terms.

gnu.org says for version 2:

Because it imposes a specific requirement that is not in the GPL; namely, the requirement on advertisements of the program. The GPL states:

You may not impose any further restrictions on the recipients' exercise
     of the rights granted herein.

The advertising clause provides just such a further restriction, and thus is GPL-incompatible.

The revised BSD license does not have the advertising clause, which eliminates the problem.

and for GPL v3:

Why is the original BSD license incompatible with the GPL? (#OrigBSD)

Because it imposes a specific requirement that is not in the GPL; namely, the requirement on advertisements of the program. Section 6 of GPLv2 states:

You may not impose any further restrictions on the recipients' exercise of the rights granted herein.

GPLv3 says something similar in section 10. The advertising clause provides just such a further restriction, and thus is GPL-incompatible.

The revised BSD license does not have the advertising clause, which eliminates the problem.

Other lawyers/judges, of course, might have different opinions.

Title: How to manage, in practice, licence files when combining GPL and BSD licensed code?

Body:
I am writing code that uses one library with GPL (not LGPL) license, and one with the 3-clause BSD license. Since I link to GPL-licensed library, my code will need to be GPL as well. How should I, in practice, deal with the original LICENSE.txt from the BSD-library?

(A) Can I distribute a project so that the main source code is GPL-licensed, and then some subdirectory is BSD-licensed?

(B) If I were not only to link to libraries, but to use and combine the BSD and GPL code in a more involved manner, what to do with the LICENSE.txt then?

The 3-clause BSD text tells: "Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer." so apparently I should retain the copyright notice, and that list of conditions, somewhere. But then I'll also need to put the GPL license txt-file somewhere.

Further, apparently I don't need to retain the "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:" part of the BSD license text, since it only tells me to retain the other parts.

So, how, and in which text files, should I in practice organize the GPL license text and the parts of the BSD license and copyrights that I retain?

EDIT: So in case B, I would be taking 3-clause BSD licensed code, and redistributing it under GPL, which is permitted, as 3-clause BSD license is (one-way) compatible with GPL. I am just asking how to deal with the license texts and textfiles in practice.


问:
What's the most important, useful or enlightening thing you learnt in the last 12 months?
A lot of people in the coding community talk about continuous improvement, deliberate practice and so-on - but when they talk about their current practices it's almost like they 'sprang fully formed from the loins of Zeus' because you don't hear about how their opinions changed over time or what they learnt recently.

Every now and then though I go to a talk, or read a book, or talk to someone and they open up a bit more and I find that I learn a lot from these insights.

So, if you had to pick one thing from the last 12 months that you learnt what would it be?

答:
Learnt Basic Python (using it to write quick scripts sometimes)

Installed ArchLinux in VM (had Ubuntu in VM earlier, my PC is fast now!)

Started with MATLAB (especially for plotting graphs and quick numerical checks)

Switched to Mercurial (from SVN) (branching and merging!)

ContentLicense: CC BY-SA 2.5


问:
Can testers peer review the developers' design and code?
I am a junior developer for a small business using scrum / agile development.  A long-term goal of ours is to be appraised at CMMI lvl 2.  We have a team of 3 senior developers who implement user stories and a handful of junior developers for support.

We are moving towards a "three amigos" methodology, especially in regard to separating the duties of development and testing (the third amigo being the product owner / business stakeholders).  This way our senior developers can focus on implementation and our junior developers can focus as impartial testers.

We are using peer reviews as a specific practice for verifying work products, such as source code.  This paper, http://repository.cmu.edu/cgi/viewcontent.cgi?article=1208&context=sei, describes on p. 19 that an optimal peer review process for design and code ranges from 50-65% of the time spent designing and coding.

My question is this:  is it appropriate for our testers to peer review the developers' design and code?  An advantage would be that the developers can spend more time implementing user stories.  A disadvantage would be that the testers may sacrifice their objective/impartial view of the system, since peer reviewing creates a shared ownership of the code.

答:
The point of separating the tester from the developer is that you want to guarantee that more than one person has verified that the code does what it should.  The fact that the tester may have looked at the code already does not preclude this.  There's a big difference between coding and debugging a component as a developer, and running the component through a number of test cases as a tester.

So, go ahead and have as many eyes as are practical review your code and design.  Review is invaluable for preventing missteps.

BTW, from a scrum standpoint, you're breaking a few rules with your approach in that you are effectively creating roles within the team other than "team member".  This isn't the end of the world, but be aware that you should ALWAYS have shared ownership of the code--the entire team owns it.  Also, I would discourage the senior/junior differentiators here--you do want your junior developers to stick around for more than a few months, right?


答:
My preferred version control is Mercurial.  There are a lot of options available for searching via a graphical interface however these are the methods I've utilized most heavily.

In a terminal, you can hg serve.  Then, hop over to a browser for more of a GUI interface.  The address localhost:8000 is the default url for seeing a repository that you are serving.

Alternatively, you could use a 3rd party service such as kilnhg.com.  They have a great interface that integrates nicely with their bug/feature tracking software, fogbugz.com.

Lastly, you might like TortoiseHg.  It's a local application that provides a GUI for your repositories.

Title: Searching in a repository

Body:
I'm very new to source control management and one thing puzzles me: is it possible to search through the whole repository for a string? For example I'm tracking one file, which has 100 commits and I would like to see all the version of the file which contain "xyz" inside.

Is this possible? I'm using various GUI clients and non of them has this..? Yes, they can search trough commit messages but I want to find a version even when the commit message does not contain the string.

To put it differently, which GUI client has such a feature? I don't care about which SCM it uses - git, hg, bazaar, all are fine.


问:
Are the terms stable and reliable interchangeable?
Is there a difference between stability and reliability (at least in software engineering context) or can they be used interchangeably? If not, what would be some examples of reliable but not necessarily stable systems, and vice versa?

答:
Let's say for instance we have an app, it works perfectly, aside from it crashing every 5 minutes, but it's back up instantly without data loss.

That in my mind is reliable, but not stable.

I can rely on it not losing data and working correctly, despite it not being stable.

In fact, the internet is basically that.  It's far from stable—connections drop and reappear, packets collide and are lost, and all kinds of other unstable things happen.  However, it's pretty amazing how reliable it is given all the instability inherent in it.

ContentLicense: CC BY-SA 4.0


问:
Are unit tests really that useful?
I just graduated with a degree in CS and I currently have a job as a Junior .NET Developer (C#, ASP.NET, and web forms). Back when I was still in university, the subject of unit testing did get covered but I never really saw the benefits of it. I understand what it's supposed to do, namely, determine whether or not a block of code is fit for use. However, i've never actually had to write a unit test before, nor did I ever feel the need to.

As I already mentioned, I'm usually developing with ASP.NET web forms, and recently I've been thinking of writing some unit tests. But I've got a few questions about this.

I've read that unit testing often happens through writing "mocks". While I understand this concept, I can't seem to figure out how I'm supposed to write mocks for websites that are completely dynamic, and where almost everything depends on data that comes from a database. For example: I use lot's of repeaters who have ItemDataBound events etc. (again depending on data that is "unknown").

So question number 1: Is writing unit tests for ASP.NET web forms something that is done often, and if it is: how do I resolve the "dynamic environment" issue?

When I'm developing I go through a lot of trial-and-error. That doesn't mean I don't know what I'm doing, but I mean that I usually write some code, hit Ctrl F5 and see what happens. While this approach does the job most of the time, sometimes I get the feeling that I'm being a little clueless (because of my little experience). I sometimes waste a lot of time like this as well.

So, question number 2: Would you guys advise me to start writing unit tests? I think it might help me in the actual implementation, but then again I feel like it might slow me down.

答:
No.

The concept behind unit tests is based on a premise that has been known to be false since before unit testing was ever invented: the idea that tests can prove that your code is correct.

Having lots of tests that all pass proves one thing and one thing only: that you have lots of tests which all pass.  It does not prove that what the tests are testing matches the spec.  It does not prove that your code is free from errors that you never considered when you wrote the tests.  (And the things that you thought to test were the possible issues you were focusing on, so you're likely to have gotten them right anyway!)  And last but not least, it does not prove that the tests, which are code themselves, are free from bugs.  (Follow that last one to its logical conclusion and you end up with turtles all the way down.)

Djikstra trashed the concept of tests-as-proof-of-correctness way back in 1988, and what he wrote remains just as valid today:

It is now two decades since it was pointed out that program testing
  may convincingly demonstrate the presence of bugs, but can never
  demonstrate their absence. After quoting this well-publicized remark
  devoutly, the software engineer returns to the order of the day and
  continues to refine his testing strategies, just like the alchemist of
  yore, who continued to refine his chrysocosmic purifications.

The other problem with unit testing is that it creates tight coupling between your code and the test suite.  When you change code, you'd expect some bugs to show up that would break some tests.  But if you're changing code because the requirements themselves have changed, you'll get a lot of failing tests, and you'll have to manually go over each one and decide whether or not the test is still valid.  (And it's also possible, though less common, that an existing test that should be invalid will still pass because you forgot to change something that needed to be changed.)

Unit testing is just the latest in a long line of development fads that promise to make it easier to write working code without actually being a good programmer.  None of them have ever managed to deliver on their promise, and neither does this one.  There is simply no shortcut for actually knowing how to write working code.

There are some reports of automated testing being genuinely useful in cases where stability and reliability are of paramount importance.  For example, the SQLite database project.  But what it takes to achieve their level of reliability is highly uneconomical for most projects: a test-to-actual-SQLite-code ratio of almost 1200:1.  Most projects can't afford that, and don't need it anyway.

Title: Are unit tests really that useful?


答:
In my opinion: yes they are, and yes you should.

They give you confidence in the changes you make (everything else is
still working). This confidence is what you need to mold the code,
otherwise you might be afraid to change things.

They make your code better; most simple mistakes are caught early with the unit tests. Catching bugs early and fixing them is always cheaper than fixing them later, e.g., when the application is in production.

They serve as documentation for other developers on how your code works and how to use it.

The first problem you face is that ASP.NET in itself does not help you to write unit tests—actually it works against you. If you have any choice, start using ASP.NET MVC, which was created with unit testing in mind. If you can't use ASP.NET MVC, you should use the MVP pattern in ASP.NET so at least you can unit test your logic easily.

Besides that you just need to get proficient in writing unit tests. If you practice TDD, your code is created testable—in other words, nice and clean.

I would advise you to practice, and pair program. While reading:

Agile Software Development, Principles, Patterns, and Practices [Hardcover]

Head First design Patterns

GOF Design pattern bible

Roy osherove's first introduction to unit testing

unit test patterns bible

Or, for a first overview:

SOLID

Xunit test patterns

Title: Are unit tests really that useful?

Body:
I just graduated with a degree in CS and I currently have a job as a Junior .NET Developer (C#, ASP.NET, and web forms). Back when I was still in university, the subject of unit testing did get covered but I never really saw the benefits of it. I understand what it's supposed to do, namely, determine whether or not a block of code is fit for use. However, i've never actually had to write a unit test before, nor did I ever feel the need to.

As I already mentioned, I'm usually developing with ASP.NET web forms, and recently I've been thinking of writing some unit tests. But I've got a few questions about this.

I've read that unit testing often happens through writing "mocks". While I understand this concept, I can't seem to figure out how I'm supposed to write mocks for websites that are completely dynamic, and where almost everything depends on data that comes from a database. For example: I use lot's of repeaters who have ItemDataBound events etc. (again depending on data that is "unknown").

So question number 1: Is writing unit tests for ASP.NET web forms something that is done often, and if it is: how do I resolve the "dynamic environment" issue?

When I'm developing I go through a lot of trial-and-error. That doesn't mean I don't know what I'm doing, but I mean that I usually write some code, hit Ctrl F5 and see what happens. While this approach does the job most of the time, sometimes I get the feeling that I'm being a little clueless (because of my little experience). I sometimes waste a lot of time like this as well.

So, question number 2: Would you guys advise me to start writing unit tests? I think it might help me in the actual implementation, but then again I feel like it might slow me down.


答:
I just graduated with a degree in CS and i currently have a job as a
  junior .NET developer (in C# and usually ASP.NET, web forms - not
  ASP.NET MVC). Back when i was still in university, the subject of unit
  testing did get covered, but i never really saw the benefits of it.

That's because you never programmed big.

I understand what it's supposed to do -determine wether or not a block of code > is fit for use - but i've never actually had to write a unit test before. (nor > did i ever feel the need to ..)

Writing unit tests forces your code to conform to a given mental structure that is testable, well documented, and reliable. It's much more than what you claim.

-I've read that unit testing often happens through writing "mocks". While i understand this concept, i can't seem to figure out how i'm
  supposed to write mocks for websites that are completely dynamic, and
  where almost everything depends on data that comes from a database.

mock the database access with a mock class that returns model classes filled with well defined, hardcoded data. or, fill a test database with fixture data and work from there.

-Would you guys advise me to start writing unit tests ?

hell yes. Read Beck's "Test Driven Development" first.

I think it might help me in the actual implementation, but then again i feel like it might slow me down.

It slows you down now. But when you have to debug for hours instead of days, you will change your mind.

any advise will be appreciated :)

Test. Trust me. Unfortunately it must also be a management policy, but it's something that saves time. Tests stay, they are there, now and in the future. When you change the platform, and run the tests, and they still work, you know that your stuff works as expected.

Title: Are unit tests really that useful?


答:
is writing unit tests for ASP.NET webforms something that is done often, and if it is: how do i resolve the "dynamic environment" issue ?

It is not often done. Working with UI elements isn't what unit tests are good at, since there's no great way to programmatically verify that the right things end up on the screen at the right places.

Would you guys advise me to start writing unit tests ? I think it might help me in the actual implementation, but then again i feel like it might slow me down.

Where applicable, yes. They can be very helpful in verifying specific cases in a repeatable manner. They help act as 'friction' against troublesome changes, and as a failsafe when you're making better changes.

One thing to note is that they will usually slow you down.

This is okay.

Spending a little time now will (if done well) save you time in the future because they catch some bugs, prevent recurrance of some bugs, and allow you to be somewhat more comfortable doing other improvements in the code to keep it from rotting.

Title: Are unit tests really that useful?


问:
Is it wrong to push messages from server to client in a client-server application?
I practically never see any web application where server pushes messages to the client. While pushing messages from server to client is hugely used in multiplayer games, why this model is so underused in web apps?

Is it wrong? Does it destroy the client-server model?

答:
Request-response vs. message pushing

Some architectures and protocols were designed for request-response type of communication. In HTTP, the client asks the server to GET, POST, DELETE, HEAD etc. something, and the server responds (or fails to respond). In POP3, the server role is limited to answer the requests, nothing more.

Some others are designed in a way that the client and the server are communicating together, which enables scenarios which are hardly possible in a request-response model. IMAP, for example, has an advantage over POP3 to allow the new messages to be delivered immediately to the client. To achieve the same nearly-immediate behavior with POP3, the only thing you can do is to query the server for new emails once per second, which obviously raises performance and bandwidth usage issues.

Message pushing in practice

In general, pushing information from server to client may be totally acceptable in some cases. You quoted yourself an example of a type of products where this is a common practice: multiplayer games.

In a web applications, it is unusual to see the information to be sent by the server to the client for several reasons:

In many cases, you don't need such feature in a web application. For example, why would MSDN or Google Images start to push something to my browser? Or why would TheDailyWTF change its content on the fly while you're browsing it?

For a while, it was impossible to do it without using Java applets or similar non-HTML components, making it very complicate to implement in a website. If you were creating a chat application, using a Java applet wasn't probably too difficult, but for any other web app, it was an overkill. For example, I hardly imagine eBay creating a Silverlight app which would establish a two-way communication with the server in order to update the bids in real time.

Some people came with alternative solutions, but they had their own drawbacks (performance and bandwidth usage). For example, it was not unusual to see some bulletin boards making regular AJAX requests (every ten seconds for example) to see if something changed.

Today, things start to change with HTML 5 and WebSockets. Stack Exchange is an excellent example of a proper use of them: actually, when you see the notifications about new comments or answers or when you see the up and down votes in real time, it's done with WebSockets.

With WebSockets, you may imagine other valid uses of two-ways communication in browsers:

Real time information. Example: for large cities, Google Maps has Traffic feature. What about updating this information in real time, or notifying the drivers immediately when an road accident causes traffic jam?

Social interactions. Example: when posing a comment on a blog, what about the ability to see the comments of other people immediately after they are posted? Another example: what if, in a bug tracking system, I can see immediately the newly created bug reports?

Cases where immediate response is required. Example: a monitoring panel used by a system administrator may be written in HTML and with WebSockets, it may inform the sysadmin immediately if a server is down.

etc.


问:
Are there any design patterns that are unnecessary in dynamic languages like Python?
I've started reading the design pattern book by the GoF. Some patterns seem very similar with only minor conceptual differences.

Do you think out of the many patterns some are unnecessary in a dynamic language like Python (e.g. because they are substituted by a dynamic feature)?

答:
Peter Norvig demonstrates that 16 out of the 23 design patterns found in the GOF book are invisible or simpler in dynamic languages (he focuses on Lisp and Dylan).

Since you mentioned Python, there is a nice presentation by Alex Martelli about the topic. Also related with Python, there is a nice blog post demonstrating six design patterns in idiomatic Python.

I also keep a github repository with implementations (by other people) of the most common design patterns in Python.


答: The purpose of unit tests is to allow you to safely change your code (refactoring, improving etc.) without the fear that you can break something inside the system. This proves very useful for large applications, when you do not really know all the effects of your code change (despite loose coupling).</p>

Title: Are unit tests really that useful?


答:
These definitions come from the ISO 9126 Standard, which divides in characteristics and sub characteristics : this table , this pdf or wikipedia or article

Stability is : Characterizes the sensitivity to change of a given system that is the negative impact that may be caused by system changes.

Reliability is a main characteristic that contains:

maturity : This sub characteristic concerns frequency of failure of the software.

fault tolerance : The ability of software to withstand (and recover) from component, or environmental, failure.

recoverability : Ability to bring back a failed system to full operation, including data and network connections.

Title: Are the terms stable and reliable interchangeable?

Body: Is there a difference between stability and reliability (at least in software engineering context) or can they be used interchangeably? If not, what would be some examples of reliable but not necessarily stable systems, and vice versa?


答:
Goal: write a program to add two numbers

Reliable but unstable:

```<code>add(a,b):
    if randomInt mod 5 == 0:
        throw exception
    else
        print a+b
</code>```

Stable but unreliable:

```<code>add(a,b):
    if randomInt mod 5 == 0:
        print a+a
    else
        print a+b
</code>```

Body:
Goal: write a program to add two numbers

Reliable but unstable:

add(a,b):
    if randomInt mod 5 == 0:
        throw exception
    else
        print a+b

Stable but unreliable:

add(a,b):
    if randomInt mod 5 == 0:
        print a+a
    else
        print a+b


答:
It Depends

This is an answer that you will see a lot of when it comes to software development, but the usefulness of unit tests really depends upon how well they are written. A nominal number of unit tests that check over the functionality of the application for regression testing can be quite useful; however, a plethora of simple tests that check the returns of functions can be quite useless and provide a false sense of security because the application "has lots of unit tests."

Furthermore, your time as a developer is valuable and time spent writing unit tests is time not spent writing new features. Again, this is not to say you shouldn't write unit tests, but does every single public function need a unit test? I would submit that the answer is no. Does the code that is performing user input validation need unit testing? Quite likely as it is a common failure point in applications.

This is one of those areas where experience comes into play, over time you will recognize the parts of the application that could benefit from unit test, but it will be awhile before you reach that point.

Title: Are unit tests really that useful?


问:
How do I go from "here's the zip" to a good release strategy?
I can write code, resolve dependencies, and get my program to run on my computer; I have no idea where to go from here though.  How do I get the software ready for distribution?

The school environment has taught me to do a few random tests by hand, make sure nothing is obviously broken, then throw all the source files into a zip and send it off.  This is all that's needed to get a good grade is most CS courses.  Nobody taught me how to release to real users.

The only clues I have are a few phrases like "automated builds" and "continuous integration", but I don't know what these mean.  How can I properly distribute my work?  How can I make it easy for others?  How can I move beyond "here's the zip" releases?

答: This depends on the language, frameworks, IDE, Source Control and technologies used in general.  That being said you can typically create an installer package.</p>


答:
Unit tests are useful when used correctly; there are various problems with your logic.

"When I'm developing I go through a lot of trial-and-error" Said Kevin.

Look at programming by coincidence.  It's better to understand what a code should do and then prove that it does it via a unit test. Do not assume a code works simply because the UI didn't break when you ran the program!

s writing unit tests for ASP.NET web forms something that is done often

I have no knowledge of statistical data to say how often people test web forms.  It does not matter.  The UI is hard to test and Unit Tests should not be coupled to a UI either. Separate out your logic into layers, class libraries which can be tested.  Test the UI separately from the back-end logic.

So, question number 2: Would you guys advise me to start writing unit tests?

Yes.  Once you get used to them, they speed you up.  Maintenance is far more time consuming and costly than the initial development phase.  Maintenance is greatly assisted with unit tests, even with initial testing and bug repair.

Title: Are unit tests really that useful?


答:
If you've ever seen the benefit to writing a main method to test some small piece of code for school, unit testing is the professional/enterprise version of that same practice.

Also imagine the overhead of building the code, starting your local web server, browsing to the page in question, entering the data or setting the input to the proper test seed, submitting the form, and analyzing the results...vs building and hitting the nUnit run button.

Here is a fun image too...

I found this image here:

http://www.howtogeek.com/102420/geeks-versus-non-geeks-when-doing-repetitive-tasks-funny-chart/

Title: Are unit tests really that useful?


问:
How can programming ability be used to help people in poverty?
As a student studying Computer Science in college, I often hear from friends working on various humanitarian projects, and I want to do something myself. But it seems that programmers don't have as many obvious avenues to help out as, say, doctors or teachers. What are some ways in which programmers can put their talent to use for people in poverty?</p>

答:
Write software that helps people communicate freely and efficiently.

Efficient and unhindered communication is the key to a free world with no poverty and pollution? That's what causes dictatorships to fall, and that's why all dictatorships censor?

For example, you could contribute to the Tor Project, or build another helpful communication system like Twitter and Facebook. — You've read about how Twitter, Facebook and video streaming sites have been used in the Arab Spring?


答:
The original "Design Patterns" book documented and named some common idioms useful in imperative, object-oriented languages such as C++ and Smalltalk.  But Smalltalk is a dynamically typed language, so it can't be strictly a matter of being dynamic.

However, the answer to your question is still "yes":  some of these design patterns will be irrelevant to modern dynamically typed languages.  More generally, there will be different design patterns in different languages, especially in different kinds of languages.

To reiterate: a "design pattern" is simply a name for a programming idiom:  a common solution to a frequently encountered problem.  Different languages require different idioms, because what is a problem for one language may be trivial for another.  In this sense, design patterns tend to point out weaknesses in the languages they apply to.

So, you might look for other features which make modern dynamic languages (or ancient ones like Lisp) more powerful, rendering some of these classic design patterns irrelevant.

Title: Are there any design patterns that are unnecessary in dynamic languages like Python?

Body:
I've started reading the design pattern book by the GoF. Some patterns seem very similar with only minor conceptual differences.

Do you think out of the many patterns some are unnecessary in a dynamic language like Python (e.g. because they are substituted by a dynamic feature)?


问:
Function points measure for a business applications framework. Is that possible?
So, my boss wants to have a complexity measure for a framework developed internally in our company. Is that possible?

As far as I know, functions points do not apply to software that doesn't have persistence per se, and also doesn't have GUI's (it's a framework, built in C#, useful for crafting business applications, and it's used only internally). Also, function points tend to get less useful as the target software being assesed gets more complex.

If it is possible to do this, could someone give me some guidance? If not, how do I convince my boss to stop asking this? Is there a better metric for valuing such a complex software?

答:
first, read more about function points to dispel the misinformation implied in your question

second, the usefulness of a metric lies in how it is used; FP may or may not be useful, it depends on what the purpose of the measurement is


答:
Projects done for university classes differ vastly from business applications you'll write at your work. The difference is lifespan. How long does university project "live"? In most cases, it starts when you write first line of code and ends when you get your mark. You could say that, effectively it only lives for the time of implementation. "Release" is usually equal to its "death".

Software done for business surpasses that release-death point of university project and continues to live as long as business needs it to. Which is very long. When talking about money, nobody will spend a broken penny to have "cooler and neater code". If software wrote in C 25 years ago still works and is good enough (as understood by its business owner needs), expect to be asked to maintain it (adding new features, improving old ones - changing source code).

We come to one very important point - regression. At the place I work we have two teams maintaining two apps; one, wrote around 5-6 years ago with very little code tests coverage*, and second one, newer version of the first application with full-blown tests suite (unit, integration and what not else). Both teams have dedicated manual (human) testers. Want to know how long does it take to introduce a new, fairly basic feature for the first team? 3 to 4 weeks. Half of this time is "checking whether everything else still works". This is busy time for manual testers. Phones are ringing, people get upset, something is broken again. Second team usually deals with such issues in less than 3 days.

I by no means say that unit tests make your code error prone, correct or other fancy words you can come up with. Neither they make bugs magically disappear. But when combined with other methods of automated software testing, they make you applications much more maintainable than they would've been otherwise. This is a huge win.

And last but not least, comment by Brian which I think nails the whole issue:

(...) they do raise your confidence (or should...) that the code does what you designed it to do, and continues to do tomorrow what it does today.

Because between today and tomorrow, somebody might make tiny change which will cause the oh-so-important report generator code to crash. Tests push the odds that you'll find this out before your customer does a little bit to your side.

* They do slowly introduce more and more tests to their code base, but we all know how this stuff usually looks.

Title: Are unit tests really that useful?


问:
For Which Kind of Cache will this Program not run well? How can it be optimized?
Consider the following code fragment:

```<code>int a[8192], b[8192], c[8192];
int i;
for(i = 0; i < 8192; i++)
    c[i] = a[i] + b[i];
</code>```

For what kind of cache will this program not run well (set associative, direct, associative)? I've been thinking about how to optimize this, but can't really see how it can be done. How can I change this code to have fewer cache misses?

答:
I'd expect virtually nothing in terms of cache misses from the sample code. It has only three streams, and it's directly linear in memory.

The best that you can do to improve it's speed is align the arrays to a page boundary (4kb on x86) and attempt vectorization, loop unrolling, and possibly parallelism. Past that, there's not much more you can do.


答:
In the real world you really want to come as close to just hitting a button and having everything be automated as you can.  If you are installing yourself it's worth the effort because of the time it saves and because you want to make it very hard to make a mistake with live software.  If you aren't then it's worth the effort because in almost all cases few people will deal with a difficult installation process.

This can be quite a lot of work but it's conceptually pretty straight forward.  You have to write code that verifies that the transitive closure of all dependencies are satisfied and either fix anything missing or have a good error message.  If there are installation options that you can't know in advance you have to support setting those via a UI or script or both.  You have to play nicely with whatever standard installation mechanism(s) exist in your environment.

Dependencies might not just be files, but might be things like making sure windows registry entries the program relies on are present, configuring a web server for the program, etc.

Basically you have to do programatically everything someone would do by hand, handling all the different possible scenarios.

Automated build is a pretty self explanatory term.  A lot of times the build doesn't get quite all the love it needs, and the build process is written in a document with a lot of steps.  It's generally worth the effort to have some form of configuration driving a completely automated script.  That's an automated build.  Usually part of the build is running automated tests to make sure that not only does the build produce a program, but that at least the tested parts of the program actually work.

Continuous integration isn't feasible without an automated build, which is a big reason an automated build is worth doing.  It means that the build gets run automatically using some scheme (like "whenever new code has been checked in since I finished the last build I was working on").  Generally a big part of the value of this is that the build runs automated tests, so if code changes break some distant dusty corner of the program you find out automatically and fairly quickly.  There may be some value in just knowing it all still compiles though.

Distributing your work and making it easy for others would involve making an installer and following whatever conventions your audience might expect, like putting in an app store, or a source code repository.  There are a lot of tools in various environments that, given a name, go find code for you and install it.  Your code can participate in that if you follow all the rules needed for those tools to work.

I've been incredibly general because the gory details vary quite a bit in different environments, so a specific answer would depend greatly on exactly what you are doing.

Title: How do I go from "here's the zip" to a good release strategy?

Body:
I can write code, resolve dependencies, and get my program to run on my computer; I have no idea where to go from here though.  How do I get the software ready for distribution?

The school environment has taught me to do a few random tests by hand, make sure nothing is obviously broken, then throw all the source files into a zip and send it off.  This is all that's needed to get a good grade is most CS courses.  Nobody taught me how to release to real users.

The only clues I have are a few phrases like "automated builds" and "continuous integration", but I don't know what these mean.  How can I properly distribute my work?  How can I make it easy for others?  How can I move beyond "here's the zip" releases?


问:
DVCS blessed repo replication among geographically distributed teams
My company is exploring the move from Perforce to a DVCS and we currently use lots of Perforce proxies because the software development teams are spread over Germany, China, USA and Mexico and sometimes bandwidth from one place to another is not that great.

Speaking with IT, we started looking for a way to keep things running smooth from the geographically distributed perspective so that everyone gets the latest and greatest without determining what repo server is the source of truth (i.e. replicating transparently).

I thought that maybe we could emulate the DNS mechanism through pre-push and pre-pull hooks. For example, consider countries A, B, and C. Upon pulling from blessed A, A itself will pull for changes from B, which in turn will pull for changes in C. If B and C have new changes they will fall towards A. Conversely, when there is a push, it could be propagated to all blessed repositories.

I'm aware that generally you only have one blessed repo, however this may not scale globally and each blessed repository would just be applicable to the teams from a single country.

My question is: is the conception of DVCS repo replication something used in practice?, has anyone done it succesfully?, if so, what is the correct way to do it?

答:
This question asks about transparent replication, and I suspect there are no answers yet because people might be getting hung up on transparency. I'll take the liberty of setting aside transparency for the moment to focus on replication. I'll deal with (or finesse) transparency later, and in fact I don't actually think it's all that important in a DVCS.

First, let me run down a few key points about the way repositories work in a DVCS. (I'm most familiar with Mercurial, so that's what I'll use for examples, but I believe everything I say is also true of git.)

A. In a DVCS, any clone contains the same file contents and history as the original.

Providing you keep the repos properly in synch, this means you can use ordinary DVCS change propagation operations (clone, push, pull) and ordinary repos to build a replication system.

B. New changes don't have to be propagated to where they came from.

In particular, if I were to get changes from a particular repo, and add some changes of my own, my changes don't have to go back to that particular repo. They can go elsewhere. The utility of this should become clear from examples I'll show below.

C. Changes can be propagated via push or pull.

In a centralized system, new changes can pretty much (I think) only be pushed into the repo. In a DVCS, it's possible to set up a variety of change propagation topologies, some of which involve only pulling. This affords more flexibility in the setup.

Examples

For the sake of discussion let's say your distributed teams use systems in the domains duke.de, duke.us, duke.cn, and duke.mx, and further that duke.de is where we want to have the "blessed" repo. Given these assumptions, let me lay out a number of examples of different topologies you could set up, bearing in mind the three key DVCS points above.

0. Centralized Push Model

Have a single repo at hg.duke.de and have the developers in all locations clone and pull from here and push changes here. This might work for the folks in Germany, but it would probably be a problem for the people in the rest of the world. All clone, pull, and push operations would go across slow long-haul network links. This is using a DVCS just like a centralized system. This is the problem you're trying to solve.

1. Centralized Push with Replication

Have the blessed repo at hg.duke.de and have replicas at hg.duke.cn, hg.duke.mx, and hg.duke.us. Developers clone from their local replica and push changes to hg.duke.de. Whenever new changes appear in hg.duke.de, a hook runs that propagates them to the replicas. The replicas are otherwise read-only, thus there will never be any merges or conflicts.

If I'm a developer in Mexico, for instance, I'll clone from hg.duke.mx but push changes to hg.duke.de. If other changes are pushed into hg.duke.de before I can push my changes, my push will be blocked. The other changes will be replicated to hg.duke.mx, so I'll pull these changes locally, merge, and then attempt to push to hg.duke.de again.

This should provide some advantages, since the big clone operations are all done locally. Pushing to the central repo in another location might not be too bad, since changes are pushed relatively infrequently, incremental changes are generally fairly small. (Mercurial in particular essentially sends compressed diffs, not entire files and their histories.)

In Mercurial, you can set up a local repo to pull from one location and push to another by putting something like the following in the .hg/hgrc file:

```<code>[paths]
default = ssh://hg.duke.mx
default-push = ssh://hg.duke.de
</code>```

2. Simple Pull Model

Continuing with hg.duke.de as the blessed repo and the others as replicas, we can propagate changes via pull instead of push. Developers clone and pull from their local replica as usual. When a change is ready, a developer submits a pull request to some central service, which pulls from the developer's repo into hg.duke.de. A policy will need to be established for merges. For example, if there are merge conflicts, the request might be rejected, requiring the developer to pull (from the local replica), merge, and resubmit the pull request.

This approach has the advantage of not making the developer wait while changes are being propagated. Of course, the dev still has to wait for the pull request to be acted upon, but at least he or she can work on additional changes during that time.

Variations

There are a bunch of variations that can be applied.

The submission of a pull request is a perfect time for code review. The changes are published, in the sense that they're available to everyone, but they haven't yet been integrated into the blessed repo.

Pull requests can be acted upon manually or by some automated system. Processing a pull request might not merge changes directly into the blessed repo, but instead into a temporary staging area where a build and test cycle is done. Only after passing all the tests would the changeset be integrated into the blessed repo.

Those more comfortable with a push model might want to set up a local staging repo in each location, alongside the replica, e.g. hg-stage.duke.mx, hg-stage.duke.cn, etc. This requires a bit more work, though, as developers not only have to merge against other local changes, but somebody has to be responsible for merging changes from the staging repos into the blessed repo. This can work under the right circumstances, though, and can be aided by automation.

"Transparency"

Now to the issue of transparent replication.

Given the above scenarios I don't really see the need for transparent replication. All the repos are visible to everybody, and there are conventions for pulling/cloning from the local replica and pushing to a blessed repo or a local staging area.

If you want transparency, you could have people set up DNS search domains according to their location. The local replica and staging repos would simply be referred to as "hg" and "hg-stage" and the DNS setup would resolve these to hg.duke.cn and hg-stage.duke.cn for developers in China, and correspondingly for developers in other locations. But this is a bit of magic and can be confusing, and I really don't think it adds much.

I hope this answers your question. I took a number of liberties with the response, but it seems to me that your situation could be remedied through the use of techniques that I've described above.

Body:
This question asks about transparent replication, and I suspect there are no answers yet because people might be getting hung up on transparency. I'll take the liberty of setting aside transparency for the moment to focus on replication. I'll deal with (or finesse) transparency later, and in fact I don't actually think it's all that important in a DVCS.

First, let me run down a few key points about the way repositories work in a DVCS. (I'm most familiar with Mercurial, so that's what I'll use for examples, but I believe everything I say is also true of git.)

A. In a DVCS, any clone contains the same file contents and history as the original.

Providing you keep the repos properly in synch, this means you can use ordinary DVCS change propagation operations (clone, push, pull) and ordinary repos to build a replication system.

B. New changes don't have to be propagated to where they came from.

In particular, if I were to get changes from a particular repo, and add some changes of my own, my changes don't have to go back to that particular repo. They can go elsewhere. The utility of this should become clear from examples I'll show below.

C. Changes can be propagated via push or pull.

In a centralized system, new changes can pretty much (I think) only be pushed into the repo. In a DVCS, it's possible to set up a variety of change propagation topologies, some of which involve only pulling. This affords more flexibility in the setup.

Examples

For the sake of discussion let's say your distributed teams use systems in the domains duke.de, duke.us, duke.cn, and duke.mx, and further that duke.de is where we want to have the "blessed" repo. Given these assumptions, let me lay out a number of examples of different topologies you could set up, bearing in mind the three key DVCS points above.

0. Centralized Push Model

Have a single repo at hg.duke.de and have the developers in all locations clone and pull from here and push changes here. This might work for the folks in Germany, but it would probably be a problem for the people in the rest of the world. All clone, pull, and push operations would go across slow long-haul network links. This is using a DVCS just like a centralized system. This is the problem you're trying to solve.

1. Centralized Push with Replication

Have the blessed repo at hg.duke.de and have replicas at hg.duke.cn, hg.duke.mx, and hg.duke.us. Developers clone from their local replica and push changes to hg.duke.de. Whenever new changes appear in hg.duke.de, a hook runs that propagates them to the replicas. The replicas are otherwise read-only, thus there will never be any merges or conflicts.

If I'm a developer in Mexico, for instance, I'll clone from hg.duke.mx but push changes to hg.duke.de. If other changes are pushed into hg.duke.de before I can push my changes, my push will be blocked. The other changes will be replicated to hg.duke.mx, so I'll pull these changes locally, merge, and then attempt to push to hg.duke.de again.

This should provide some advantages, since the big clone operations are all done locally. Pushing to the central repo in another location might not be too bad, since changes are pushed relatively infrequently, incremental changes are generally fairly small. (Mercurial in particular essentially sends compressed diffs, not entire files and their histories.)

In Mercurial, you can set up a local repo to pull from one location and push to another by putting something like the following in the .hg/hgrc file:

[paths]
default = ssh://hg.duke.mx
default-push = ssh://hg.duke.de

2. Simple Pull Model

Continuing with hg.duke.de as the blessed repo and the others as replicas, we can propagate changes via pull instead of push. Developers clone and pull from their local replica as usual. When a change is ready, a developer submits a pull request to some central service, which pulls from the developer's repo into hg.duke.de. A policy will need to be established for merges. For example, if there are merge conflicts, the request might be rejected, requiring the developer to pull (from the local replica), merge, and resubmit the pull request.

This approach has the advantage of not making the developer wait while changes are being propagated. Of course, the dev still has to wait for the pull request to be acted upon, but at least he or she can work on additional changes during that time.

Variations

There are a bunch of variations that can be applied.

The submission of a pull request is a perfect time for code review. The changes are published, in the sense that they're available to everyone, but they haven't yet been integrated into the blessed repo.

Pull requests can be acted upon manually or by some automated system. Processing a pull request might not merge changes directly into the blessed repo, but instead into a temporary staging area where a build and test cycle is done. Only after passing all the tests would the changeset be integrated into the blessed repo.

Those more comfortable with a push model might want to set up a local staging repo in each location, alongside the replica, e.g. hg-stage.duke.mx, hg-stage.duke.cn, etc. This requires a bit more work, though, as developers not only have to merge against other local changes, but somebody has to be responsible for merging changes from the staging repos into the blessed repo. This can work under the right circumstances, though, and can be aided by automation.

"Transparency"

Now to the issue of transparent replication.

Given the above scenarios I don't really see the need for transparent replication. All the repos are visible to everybody, and there are conventions for pulling/cloning from the local replica and pushing to a blessed repo or a local staging area.

If you want transparency, you could have people set up DNS search domains according to their location. The local replica and staging repos would simply be referred to as "hg" and "hg-stage" and the DNS setup would resolve these to hg.duke.cn and hg-stage.duke.cn for developers in China, and correspondingly for developers in other locations. But this is a bit of magic and can be confusing, and I really don't think it adds much.

I hope this answers your question. I took a number of liberties with the response, but it seems to me that your situation could be remedied through the use of techniques that I've described above.


答:
You should do this incrementally.  The next step after giving someone a zipfile is giving them an installer that takes care of setup for them.

First, you should learn to manually build an installer.  Have a look at InnoSetup, a free program for building installers.  You give it a script file containing a list of the things that you want to install, (and other settings, if you need them,) and it produces a Setup.exe.  Learn how to use it (or another installer-creation tool) first.

Automated builds means running the entire process, from checking out the code from source control (have you learned how to use source control yet?) to building to creating the installer to uploading it to your server, from a script.  Do not try to automate anything until you first understand how to do it manually.  Automating something is always harder than doing it manually.  But once you understand all of the above steps, you can start to write build scripts.  A typical script would look something like this (pseudocode):

```<code>SVN Checkout (project folder)
command line compiler ("project folder\tests\test harness.project")
if run ("project folder\tests\output\test harness.exe") <> 0 then
  Abort ("tests failed")
command line compiler ("project folder\Full Build.projectgroup")
Installer Compiler ("project folder\installerScript.is")
FTP upload ("ftp://myServer.com/downloads", "project folder\output\setup.exe", username, password)
</code>```

This is greatly simplified, of course, but that's an overview of the general idea.

Continuous integration takes things a step further: it puts a hook into your source control server so that it will kick off an automated build process every time anyone checks code in.  This way, you get more-or-less immediate feedback if someone breaks the build.  It's not something that's particularly useful on small-scale projects, but at a larger scope it can be helpful.

Body:
You should do this incrementally.  The next step after giving someone a zipfile is giving them an installer that takes care of setup for them.

First, you should learn to manually build an installer.  Have a look at InnoSetup, a free program for building installers.  You give it a script file containing a list of the things that you want to install, (and other settings, if you need them,) and it produces a Setup.exe.  Learn how to use it (or another installer-creation tool) first.

Automated builds means running the entire process, from checking out the code from source control (have you learned how to use source control yet?) to building to creating the installer to uploading it to your server, from a script.  Do not try to automate anything until you first understand how to do it manually.  Automating something is always harder than doing it manually.  But once you understand all of the above steps, you can start to write build scripts.  A typical script would look something like this (pseudocode):

SVN Checkout (project folder)
command line compiler ("project folder\tests\test harness.project")
if run ("project folder\tests\output\test harness.exe") <> 0 then
  Abort ("tests failed")
command line compiler ("project folder\Full Build.projectgroup")
Installer Compiler ("project folder\installerScript.is")
FTP upload ("ftp://myServer.com/downloads", "project folder\output\setup.exe", username, password)

This is greatly simplified, of course, but that's an overview of the general idea.

Continuous integration takes things a step further: it puts a hook into your source control server so that it will kick off an automated build process every time anyone checks code in.  This way, you get more-or-less immediate feedback if someone breaks the build.  It's not something that's particularly useful on small-scale projects, but at a larger scope it can be helpful.


答:
Unit testing has something of a mystique about it these days.  People treat it as if 100% test coverage is a holy grail, and as if unit testing is the One True Way of developing software.

They're missing the point.

Unit testing is not the answer.  Testing is.

Now, whenever this discussion comes up, someone (often even me) will trot out Dijkstra's quote: "Program testing can demonstrate the presence of bugs, but never demonstrate their absence."  Dijkstra is right: testing is not sufficient to prove that software works as intended.  But it is necessary: at some level, it must be possible to demonstrate that software is doing what you want it to.

Many people test by hand.  Even staunch TDD enthusiasts will do manual testing, although they sometimes won't admit it.  It can't be helped: just before you go into the conference room to demo your software to your client/boss/investors/etc., you'll run through it by hand to make sure it will work.  There's nothing wrong with that, and in fact it would be crazy to just expect everything to go smoothly without running through it manually -- that is, testing it -- even if you have 100% unit test coverage and the utmost confidence in your tests.

But manual testing, even though it is necessary for building software, is rarely sufficient.  Why?  Because manual testing is tedious, and time-consuming, and performed by humans.  And humans are notoriously bad at performing tedious and time-consuming tasks: they avoid doing them whenever possible, and they often don't do them well when they're forced to.

Machines, on the other hand, are excellent at performing tedious and time-consuming tasks.  That's what computers were invented for, after all.

So testing is crucial, and automated testing is the only sensible way to ensure that your tests are employed consistently.  And it is important to test, and re-test, as the software is developed.  Another answer here notes the importance of regression testing.  Due to the complexity of software systems, frequently seemingly-innocuous changes to one part of the system cause unintended changes (i.e. bugs) in other parts of the system.  You cannot discover these unintended changes without some form of testing.  And if you want to have reliable data about your tests, you must perform your testing in a systematic way, which means you must have some kind of automated testing system.

What does all this have to do with unit testing?  Well, due to their nature, unit tests are run by the machine, not by a human.  Therefore, many people are under the false impression that automated testing equals unit testing.  But that's not true: unit tests are just extra small automated tests.

Now, what is the value in extra small automated tests?  The advantage is that they test components of a software system in isolation, which enables more precise targeting of testing, and aids in debugging.  But unit testing does not intrinsically mean higher quality tests.  It often leads to higher quality tests, due to it covering software at a finer level of detail.  But it is possible to completely test the behavior of only a complete system, and not its composite parts, and still test it thoroughly.

But even with 100% unit test coverage, a system still may not be thoroughly tested.  Because individual components may work perfectly in isolation, yet still fail when used together.  So unit testing, while highly useful, is not sufficient to ensure that software works as expected.  Indeed, many developers supplement unit tests with automated integration tests, automated functional tests, and manual testing.

If you're not seeing value in unit tests, perhaps the best way to start is by using a different kind of automated test.  In a web environment, using a browser automation testing tool like Selenium will often provide a big win for a relatively small investment.  Once you've dipped your toes in the water, you'll more easily be able to see how helpful automated tests are.  And once you have automated tests, unit testing makes a lot more sense, since it provides a faster turnaround than big integration or end-to-end tests, since you can target tests at just the component that you're currently working on.

TL;DR: don't worry about unit testing just yet.  Just worry about testing your software first.

Title: Are unit tests really that useful?


问:
Is Google's Page Speed not working fine?
I've been making small improvements to a public ASP.NET site that I have and have ran it through Google's online Page Speed several times. I have a specific problem, but something that really threw me off was that even if I didn't make any changes and just kept running it time after time (5 minutes intervals) I'd keep getting different scores by +-1 or 2 points. That is just weird in itself. Anyways,

The only medium priority item that I have left is that PageSpeed says that some of the images do not have an expiration date (or have the expiration date in a very near feature), which I cannot see how it's possible, since they are static resources (images), and I setup the expires to 60 days after the initial request. It's not even a week from now, and they are in the exact same location that the rest of my images are (and about 95% of them are not being marked as not having an expiration date)

So, how could it be that for Page SPeed, some of my images have an expiration date and others dont?

I also ran HttpWatch against my site, and I analyze the specific request of one of those images, and it does have the max-age=5184000 header.

any ideas are greatly appreciated. Thanks.

答:
Google ain't perfect, humans make mistakes, maybe you found a bug on Google Page Speed Insights or maybe you didn't.

Page speed's score is not consistent and yes it will be -1 or +1 of what you got from time to time. I think some of the reasons are some of the compression algos it uses and whatnot change slightly when telling how much savings can be had on image/css/js compression. Also cookie headers are different sizes from one request to another. Sometimes if you have 3rd party scripts they can alter the code slightly and give different results. Then there's network latency and other factors like TTFB. Run your tests on http://webpagetest.org using the 10 max test runs from various locations (dules, miami, new york, etc) to gather more data. It also gives you a page speed score. You can also use http://www.showslow.com/ and signup and submit your url for daily tests.

Basically find out what other tools say about your image caching headers. 60 days should be fine but maybe they are not setup right?

Run some of your image urls through http://redbot.org/ it gives some nice recomendations and you might have incorrect headers. A lot of places advise a format that is not standard and in fact are incorrect date formats.

I probably said this tons in other answers but this tutorial really helped me a lot and it's a good read for anyone interested in understanding web caches: http://www.mnot.net/cache_docs/

Other testing sites

http://webpagetest.org

https://browsermob.com/free-website-performance-test/

http://tools.pingdom.com/fpt/

http://gtmetrix.com/

http://site-perf.com/


问:
Adding new features to an old application
I wrote a .NET Windows application using framework 3.5. At that time, 3.5 was very new and I had knowledge of framework 2.0 only. Due to deadline, I didn't use any new features of version 3.5 and delivered the application. There was no time.

It is now two years and the app. is running fine, but my clients have requested new features. There is a major scaling needed. The new code that I wrote so far uses many new features of .NET 3.5 and I am concentrating on reducing the new code size.

The problem is that the new classes that I want to write are sometimes creating redundant methods for doing the same thing. I am not disturbing the old code.

How to manage? If I replace old classes with new ones, it risks functionality and need thorough testing again. If I don't, the project size is increasing.

答:
If you're worried about extensive testing then it probably means that your testing isn't automated at the code level. No automated testing = lots of pain (and I can speak from experience there). Your first step then should be to put some basic sensing tests around the existing code that you're thinking of modifying using something like NUnit. Now make the changes you want to make replacing the old code with the new code and ensure that everything continues to work.

Don't confuse these sensing tests with unit tests - they are there to verify that the code already in place is actually doing what you want it to do before you start and they don't need to follow the usual rules of testing. Hopefully as you change and update the code you will be introducing meaningful unit tests, at which point the sensing tests can (and should) be deleted.

The book Working Effectively with Legacy Code goes into a lot of detail about the various techniques you can use in your situation. You could also consider getting a lot of quick code coverage by using one of the acceptance testing frameworks such as Cucumber or Robot Framework - or even (if it's a web app) some quick and dirty record-playback selenium tests (again, be prepared to delete these initial tests once you have meaningful test coverage with more maintainable acceptance tests).

Finally don't crucify yourself on reducing the code size - concentrate on solving problems one at a time and refactor bad stuff away as you need to.


问:
When are multimethods useful in practice?
The Common Lisp Object System (CLOS) supports multiple dispatch (multimethods).  When is this a useful feature in practice?  I'm not just looking for an example of hypothetical functionality that would be easier to implement with multiple dispatch[1].  I'm looking for examples of where it's useful in real software, for any value of real that means it would  get written for something other than just an example.

[1] In programming tutorials, are examples contrived more often than not?

答:
Anytime you use the visitor pattern.

Anytime you have a binary operator that needs to dispatch on both params (eg. bullet hits rock vs bullet hits spaceship vs spaceship hits rock)

Anytime you want specialization based on the parameter (eg. C++'s vector<bool> specialization, component systems where the component may or may not exist)


问:
How Can I Improve my Workflow?
So I design and develop websites myself, mostly in WordPress. Once I'm happy with the site on my local server, I upload it and its database to the web server and let the client make whatever changes to the site. When he/she needs me to make changes to the code or the backend of WP, I usually work on the remote version of the site from then on, which is a pretty slow process compared to working locally.

I guess what I'm asking is, is there a way to work on a local version of the site which syncs any changes made to the remote version of the site? Is this version control by any chance?

Here's my typical workflow:

Set up local database

Code local WordPress site

Export local database

Import local database to remote server

Upload all files to remote server

Continue to make any changes post-launch remotely

Is there any way to improve my current workflow?

答:
git and svn/subversion are popular version control systems that can handle this. I would recommend git because it's now more widely used (it seems like everyone has a github these days). git allows you to choose which files you want to track and which you don't. In this case you would have two repositories, one remote and one local. When you make changes locally you can commit them and then push them to the remote server in a few commands. This will also track changes if your client ever decides they want to revert to a previous version or something goes wrong.

Also, vim is always my first suggestion for anyone wanting to improve workflow (or emacs if you're like that). If you get good at vim then you can often cut the man in the middle and develop remotely with great efficiency. Many editors also allow for remote editing. Vim coordinates well with git through the fugitive.vim plugin by Tim Pope. This streamlines git and vim efficiency.

There is also rsync which is what you're describing sounds like. It keeps directories, whether remote or local, in sync. It's relatively fast but doesn't have any version control options.

OwnerDisplayName: realph

Title: How Can I Improve my Workflow?

OwnerDisplayName: Conner


答:
Writing unit tests for ASP.NET Web forms application is NOT common and very hard to accomplish. However, it does not mean that the project should skip it.

Unit tests are corner stones of mission critical applications and they provide reliability and peace of mind that core functionality performs as expected.

Actually you may introduce unit testing much easier with a ASP.NET MVP pattern that could be used in your web forms development. It will introduce separation of concerns and ability to write essential unit tests.

Some references that might be helpful to look are:

Getting started with testing an ASP.NET Webforms Application (MVP Pattern)

Performing and Testing Redirects with ASP.NET Web Forms MVP

Model View Presenter with ASP.NET - CodeProject

Title: Are unit tests really that useful?


问:
What to do when a client has unrealistic expectations?
I've been working on a project for the past six months at a client site, since they require data confidentiality and didn't want us to work at our own office.

When I showed up alone to this client site, I was told that I needed to finish the project in two months.

Since the client is not a software company, and because of various policies, it took around 20-25 days just to give me rights on my machine to install stuff like Eclipse, Tomcat, etc. Even after the delay in getting the environment setup, they were still expecting me to complete the project in the same two month period.

They did not give me any requirement documents, but since I'm working at the client site, we used to have meeting regularly to discuss the requirements.

After six months the application is still not finished, and everyone is blaming me, but they fail to realize that we have added many more features than those discussed in the first few meetings.

I've had to redo many things during this period, e.g. separate a form into two sections; a few weeks later, they asked me to merge the two forms again as it's confusing, and so on.

The scope of the application is increasing every day but they still think it's a two month project that got delayed. When I told them that scope has increased they ask why I didn't ask for requirements at the beginning.

I already work 11-12 hours everyday and travel 3-4 hours, and now they expect me to come on Saturdays also.

I have to do everything here: take requirements, design, code and test.

Please advise me what to do in such a case?

Additional details:
We did have a list of deliverables, but then they added a few more things to it saying these are also important. They also changed a few deliverables. They don't even have their UAT server, they test on my development machine itself via its IP address.

答:
It is a serious issue in project management. It looks like your Project Manager should work on deliverable list and prioritize them with client.

Most important, your PM should discuss and agree with Client the time frame (including design and analysis of problem/solution) in your estimations.

Having clear estimation of your work load and deliverable items of the project will relieve you from stress, As well as, add peace of mind and confidence in your work.

Try to use Agile approach  by delivering your items in sprint (2-3 week) and making UAT (user acceptance test) with client. Remember, always do your sprint planning before starting the sprint.

Edit: From comments it is clear that this is indeed failure of your project manager. Not having proper testing and/or development environment set for a serious project like yours is a big Hole for the project and to SDLC process.


问:
If you could only have one programming related book on your bookshelf what would it be and why?
One per answer please. I'll add my favourite as an answer.</p>

答: It's one of the few programming books that I've kept from when I first started programming. I used to lend this out a lot to people who were first starting out. Now, not so much, since C isn't very many people's first programming language anymore. It does a wonderful job of describing what is happening behind the scenes and its descriptions about pointers brings real clarity to what is otherwise a very confusing topic for many.


答:
If you have SSH access to your servers and if you're familiar with Linux shell commands, you can use Capistrano to automate your deployment process. It's an automated deployment tool built in Ruby and is widely used in many Ruby on Rails projects. Of course, this isn't limited to just Ruby on Rails. You can also use Capistrano for other Ruby frameworks, and other languages as well.

The typical steps that Capistrano takes are the following:

Gets access to your SVN/Git/Mercurial repository

Clones your project into the remote server

Does additional tasks according to what you want (Like importing the database)

This means that you have to incorporate version control into your workflow as well, which is actually good for since it makes your life easier. Capistrano supports SVN, Git, and Mercurial, so you can use whatever you prefer.

Another note, Capistrano is originally built for deploying Ruby on Rails projects, so you have to customize it to work on PHP. This article demonstrates how you can use Capistrano for your PHP projects.

Title: How Can I Improve my Workflow?

Body:
So I design and develop websites myself, mostly in WordPress. Once I'm happy with the site on my local server, I upload it and its database to the web server and let the client make whatever changes to the site. When he/she needs me to make changes to the code or the backend of WP, I usually work on the remote version of the site from then on, which is a pretty slow process compared to working locally.

I guess what I'm asking is, is there a way to work on a local version of the site which syncs any changes made to the remote version of the site? Is this version control by any chance?

Here's my typical workflow:

Set up local database

Code local WordPress site

Export local database

Import local database to remote server

Upload all files to remote server

Continue to make any changes post-launch remotely

Is there any way to improve my current workflow?


问:
How much Ruby should I learn before moving to Rails?
Just a quick question..

I can never get a definitive answer when googling this, either. Some people say you can learn Rails without knowing any Ruby, but at some point you'll run into a brick wall and wish you knew Ruby and will have to go back to learn it..and some say to learn the "basics" of Ruby before learning Rails and it will make your life that much easier..

My current knowledge is low. I'm not a beginner, but I'm not pro, either. I went through the Learn Python The Hard Way online book in about a month, but I stopped once I got to the OOP side of Python (I know booleans, elif/if/else/statements, for loops, while loops, functions)

I agree with learning the "basics" of Ruby before learning Rails, but what exactly are the "basics" of Ruby? Would I need to learn the whole OOP side of Ruby before I went on to Rails? Or would I just need to learn the Ruby syntax up to where I learned Python (booleans, elif/if/else/statements, for loops, while loops, functions) before I went on to Rails?
Thanks!

答:
Most people would recommend that you finish reading a book about Ruby first before moving into Rails, but if you already have a solid understanding of basic programming concepts from other languages (such as OOP, control flow, etc.), you can study Rails and just pick up Ruby along the way.

Most Rails books that are aimed for beginners assume that the reader doesn't have knowledge in Ruby, so they tend to have a chapter dedicated to teaching the syntax of Ruby. Your mileage may vary. The key is to just dive in and see what works for you. You can study Rails right away and then study Ruby if you're having a hard time or you can go with plain Ruby first until you're comfortable enough to take on Rails.

If you ask me, I suggest you study Rails immediately since your motivation to study is to build web applications anyway. You'll lose motivation if you study just Ruby since it takes a pretty long time to finish a book and be fairly adept in the language.


答:
This is a failure of your manager.  You, as a contractor, should not have been placed into a situation with such a tight deadline by your company without a firm set of requirements up front, in writing.  None of this 'they added features' afterwards nonsense - each time that happened, they should have signed off on an updated schedule that you gave them.

Your manager, since they are planning on meeting with him, needs to get from the customer a specific set of requirements - the project should do A, B, C, D, and E.  And after it does, it is complete.  The customer's signature needs to be on that document agreeing to that list.  You should have had that from the beginning.

If your manager does not back you up and support you in this - and I don't say this very often - start looking for another job.  Because you'll probably end up being the scapegoat for the whole mess.  And if you are willing to work 11 hour days & 3 hour commute, it's apparent you're a very dedicated individual who deserves better.

Title: What to do when a client has unrealistic expectations?

Body:
I've been working on a project for the past six months at a client site, since they require data confidentiality and didn't want us to work at our own office.

When I showed up alone to this client site, I was told that I needed to finish the project in two months.

Since the client is not a software company, and because of various policies, it took around 20-25 days just to give me rights on my machine to install stuff like Eclipse, Tomcat, etc. Even after the delay in getting the environment setup, they were still expecting me to complete the project in the same two month period.

They did not give me any requirement documents, but since I'm working at the client site, we used to have meeting regularly to discuss the requirements.

After six months the application is still not finished, and everyone is blaming me, but they fail to realize that we have added many more features than those discussed in the first few meetings.

I've had to redo many things during this period, e.g. separate a form into two sections; a few weeks later, they asked me to merge the two forms again as it's confusing, and so on.

The scope of the application is increasing every day but they still think it's a two month project that got delayed. When I told them that scope has increased they ask why I didn't ask for requirements at the beginning.

I already work 11-12 hours everyday and travel 3-4 hours, and now they expect me to come on Saturdays also.

I have to do everything here: take requirements, design, code and test.

Please advise me what to do in such a case?

Additional details:
We did have a list of deliverables, but then they added a few more things to it saying these are also important. They also changed a few deliverables. They don't even have their UAT server, they test on my development machine itself via its IP address.


答: You can learn both at the same time.  To learn Ruby, you will have to write Ruby code.  You may as well be writing a Rails application as anything else.  I had a copies of Programming Ruby and Agile Web Development with Rails.  I skimmed Programming Ruby to get an idea of the language, then started following the tutorial in AWDWR.

Title: How much Ruby should I learn before moving to Rails?

Body:
Just a quick question..

I can never get a definitive answer when googling this, either. Some people say you can learn Rails without knowing any Ruby, but at some point you'll run into a brick wall and wish you knew Ruby and will have to go back to learn it..and some say to learn the "basics" of Ruby before learning Rails and it will make your life that much easier..

My current knowledge is low. I'm not a beginner, but I'm not pro, either. I went through the Learn Python The Hard Way online book in about a month, but I stopped once I got to the OOP side of Python (I know booleans, elif/if/else/statements, for loops, while loops, functions)

I agree with learning the "basics" of Ruby before learning Rails, but what exactly are the "basics" of Ruby? Would I need to learn the whole OOP side of Ruby before I went on to Rails? Or would I just need to learn the Ruby syntax up to where I learned Python (booleans, elif/if/else/statements, for loops, while loops, functions) before I went on to Rails?
Thanks!


答:
If you only learn conditionals, booleans, loops, and functions, you can get a certain amount of stuff done. And probably, yes, you can get things done with just that knowledge. However, most of the code you write will be very procedural because you won't know anything other than those procedural constructs. If you start writing a lot of recursive functions, one could argue you would be stepping up your knowledge.

However, if you really want to learn to program then you need to learn much more than just those things.


答:
Honestly, if it's possible for you to do this, the best solution is to quit. Situations like this one are toxic for you and they rarely get better with time, no matter how hard you try.

Best to cut your losses and find a different gig. But, do reflect on your experience and take the advice from other answers on this thread.


答:
We ship a number of windows applications. Some of the parts of each application use .NET2, some 3.5 and one application is still VB6. We have to make annual updates because the tax law changes every year (many of our users are accountants and actuaries). Refactoring code each year is a standard practice for us. When we added .NET 3.5, we were wanting WCF and Linq, and will be adding more stuff as time goes by (and we have time to learn what we want to add).

If I replace old classes with new ones, it risks functionality and need thorough testing again. If I don't, the project size is increasing.

I recommend adding unit testing to your solution. Many developers don't like to do testing, even automated testing. We have some who comment out tests that now fail due to their new code breaking some older edge case.

Three good books are:

Brownfield Application Development in .Net  and

Working Effectively with Legacy Code

Growing Object-Oriented Software, Guided by Tests

If you cannot afford the versions of Visual Studio that include unit testing, then I recommend another books on using external tools for testing:

Expert .NET Delivery Using NAnt and CruiseControl.NET

While this book was written for .NET 1.1, it still has some useful information.

One practice I recommend strongly is "continuous integration." The purpose of this is for some process that runs every time code is checked in to compile and test the code. While it is fiddly and annoying to set up in the beginning, it makes things very easy and very repeatable later on. If you are keeping score, continuous integration lets you answer "yes" to questions 2  & 3 on the Joel Test.

Title: Adding new features to an old application

Body:
I wrote a .NET Windows application using framework 3.5. At that time, 3.5 was very new and I had knowledge of framework 2.0 only. Due to deadline, I didn't use any new features of version 3.5 and delivered the application. There was no time.

It is now two years and the app. is running fine, but my clients have requested new features. There is a major scaling needed. The new code that I wrote so far uses many new features of .NET 3.5 and I am concentrating on reducing the new code size.

The problem is that the new classes that I want to write are sometimes creating redundant methods for doing the same thing. I am not disturbing the old code.

How to manage? If I replace old classes with new ones, it risks functionality and need thorough testing again. If I don't, the project size is increasing.