答:
What is important in any test strategy, is Test Coverage - ie being able to show that all functionality is being tested.

I general, and unless you have specific requirements to the contrary (eg DO178 Level A, IEC61508 SIL 4 etc) which does not appear to be the case in your situation, then if you can test the full function of class or a module (and demonstrate that you have) at system level, then system level testing is adequate. And so on down. Unit testing is only necessary when you haven't covered the testing further up.

Where exactly should I draw the line between unit tests and
  integration tests?

Given intergration testing is usually easier, quicker and cheaper, draw the line as far along as you can...

Should I only test one class at a time(as much as possible) with unit
  tests?

It depends on scope, again... by definition, a unit test is testing a single unit.  But if you can fully test a full module in one go, then if you wish, do so.  You are in effect fulfilling several unit tests in one hit.

Also, should integration tests be placed in the same testing project
  as my unit testing project?

No fundamental reason why not... unless the higher level testing is performed by an independent tester, at which point you should only be issuing an executable and minimal instrumentation.

Title: Where should I draw the line between unit tests and integration tests? Should they be separate?

Body:
I have a small MVC framework I've been working on. It's code base definitely isn't big, but it's not longer just a couple of classes. I finally decided to take the plunge and start writing tests for it(yes, I know I should've been doing that all along, but it's API was super unstable up until now)

Anyway, my plan is to make it extremely easy to test, including integration tests. An example integration test would go something along these lines:

Fake HTTP request object -> MVC framework -> HTTP response object -> check the response is correct

Because this is all doable without any state or special tools(browser automation etc), I could actually do this with ease with regular unit test frameworks(I use NUnit).

Now the big question. Where exactly should I draw the line between unit tests and integration tests? Should I only test one class at a time(as much as possible) with unit tests? Also, should integration tests be placed in the same testing project as my unit testing project?


问:
Where should I draw the line between unit tests and integration tests? Should they be separate?
I have a small MVC framework I've been working on. It's code base definitely isn't big, but it's not longer just a couple of classes. I finally decided to take the plunge and start writing tests for it(yes, I know I should've been doing that all along, but it's API was super unstable up until now)

Anyway, my plan is to make it extremely easy to test, including integration tests. An example integration test would go something along these lines:

Fake HTTP request object -> MVC framework -> HTTP response object -> check the response is correct

Because this is all doable without any state or special tools(browser automation etc), I could actually do this with ease with regular unit test frameworks(I use NUnit).

Now the big question. Where exactly should I draw the line between unit tests and integration tests? Should I only test one class at a time(as much as possible) with unit tests? Also, should integration tests be placed in the same testing project as my unit testing project?

答:
Integration vs. unit tests

You should keep your unit tests and your integration tests completely separated. Your unit tests should test one thing and one thing only and in complete isolation of the rest of your system. A unit is loosely defined but it usually boils down to a method or a function.

It makes sense to have tests for each unit so you know their algorithms are implemented correctly and you immediately know what went wrong where, if the implementation is flawed.

Since you test in complete isolation while unit-testing you use stub and mock objects to behave like the rest of your application. This is where integration tests come in. Testing all units in isolation is great but you do need to know if the units are actually working together.

This means knowing if a model is actually stored in a database or if a warning is really issued after algorithm X fails.

Test driven development

Taking it a step back and looking at Test Driven Development (TDD) there are several things to take into account.

You write your unit test before you actually write the code that makes it pass.

You make the test pass, write just enough code to accomplish this.

Now that the test passes it is time to take a step back. Is there anything to refactor with this new functionality in place? You can do this safely since everything is covered by tests.

Integration first vs Integration last

Integration tests fit into this TDD cycle in one of two ways. I know of people who like to write them beforehand. They call an integration test an end-to-end test and define an end to end test as a test that completely tests the whole path of a usecase (think of setting up an application, bootstrapping it, going to a controller, executing it, checking for the result, output, etc...). Then they start out with their first unit test, make it pass, add a second, make it pass, etc... Slowly more and more parts of the integration test pass as well until the feature is finished.

The other style is building a feature unit test by unit test and adding the integration tests deemed necessary afterwards. The big difference between these two is that in the case of integration test first you're forced to think of the design of an application. This kind of disagrees with the premise that TDD is about application design as much as about testing.

Practicalities

At my job we have all our tests in the same project. There are different groups however. The continuous integration tool runs what are marked as unit tests first. Only if those succeed are the slower (because they make real requests, use real databases, etc) integration tests executed as well.

We usually use one test file for one class by the way.

Suggested reading

Growing object-oriented software, guided by tests This book is an extremely good example of the integration test first methodology

The art of unit testing, with examples in dot.net On unit testing, with examples in dot.net :D Very good book on principles behind unit-testing.

Robert C. Martin on TDD (Free articles): Do read the first two articles he linked there as well.

ContentLicense: CC BY-SA 3.0


问:
What does "Human Readable" mean? Is it a misnomer?
Two examples spring to mind:

One of the reasons that .Net programmers are encouraged to use .config files instead of the Windows Registry is that .config files are XML and therefore human-readable.

Similarly, JSON is sometimes considered human-readable compared with a proprietary format.

Are human-readable formats actually readable by humans? In the example of configuration data:

The format doesn't change the underlying meaning of the information - in both cases, the data represents the same thing.

Both registry and .config file are stored internally as a series 0s and 1s. To that extent, the underlying representaion is equally unreadable by humans.

Both registry and .config file require a tool to read, format and display those 0s and 1s and convert them into a format that humans can read. In the case of configuration stored in the Windows Registry, this is a Registry Editor. In the case of XML it could be a text editor or XML reader. Either way, the tool makes the data readable, not the data format.

So, what is the difference between human-readable data formats and non-human-readable formats?

答:
One big difference between human-readable formats and non-human-readable formats is robustness.  In a Linux system, all sorts of information will be scattered around in various text files.  You do need to learn where they are, but you can always find the information and read and change it with a text editor.  If a file disappears, you can generally replace it.  If a file becomes corrupt, you can often figure out what it should be and fix it.

In a MS Windows system, most of this will be in the Registry, which is, from the users' point of view, one big opaque system, accessible in part through various tools (much like some config files in Linux systems), and overall with a registry editor.  As long as everything goes well, this is okay.  If it breaks, there's nothing that can be done without specialist knowledge.

ContentLicense: CC BY-SA 2.5


问:
Debugging: understanding details on why certain fixes worked?
When debugging, I sometimes find that I make some changes and I am not 100% sure why those changes correct some bug in the program. Is it essential to understand every single detail about why some bugs were occurring and why certain changes eliminated those bugs? Or is it common among developers to sometimes get the program working without really knowing the details about why the fix worked?</p>

答:
Or is it common among developers to sometimes get the program working
  without really knowing the details about why the fix worked?

I for one think it is very very common these days. That's because of Google and Stackoverflow. You have a problem with your code, just google it, find solution, fixed, move on to the next problem.


问:
When must arbitrary precision arithmetic functions be used in PHP?
My colleague uses the Binary Calculator functions in bandwidth calculations; as much as terrabytes, and with percentage splitting on allocation. His usage of these functions appears correct in order not to lose a byte; although he seems to be using them now for everything.

The manual only says:

For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.

How much is any size? Is it really necessary? How big is the default float in PHP? Are there any good advice regarding this or things to keep in mind?

答:
I find bcmath much more friendly to use than GMP. So far I have not even been able to find out how to deal with floating point calculations with GMP in PHP. All floating point stuff seems to have been omitted in the PHP release. So I stick with bcmath (for now).

GMP on PHP seems to be geared towards number theory calculations and not numerical calculations like decimals of pi (or e) and similar.


问:
Does this happen in Common Lisp?
From Steve Yegge's "Lisp is Not an Acceptable Lisp":

```<code> Lisp has a little syntax, and it shows up occasionally as, for instance, '(foo)
 being expanded as (quote foo), usually when you least expect it.
</code>```

What is he talking about with '(foo) being expanded into (quote foo) in some situations?  (As opposed, I would imagine, to (quote (foo))).

答:
'(foo) is not "expanded" into (quote foo).
The two forms are precisely the same; the lisp reader READS
'(foo) as (quote foo).

To think they are somehow different is to completely misunderstand
how lisp reads forms internally.

Title: Does this happen in Common Lisp?


问:
Quickly compute added and removed lines
I'm trying to compare two text files. I want to compute how many lines were added and removed. Basically what git diff --stat is doing. Bonus points for not having to store the entire file contents in memory.

The approach I'm currently having in mind is:

read each line of the old file

compute a hash (probably MD5 or SHA-1) for each line

store the hashes in a set

do the same for each line in the new file

every hash from the old file set that's missing in the new file set was removed

every hash from the new file set that's missing in the old file set was added

I'll probably want to exclude empty and all white space lines. There is a small issue with duplicated lines. This can either be solved by additionally storing how often a hash appears or comparing the number of lines in the old and new file and adjust either the added or removed lines so that the numbers add up.

Do you see room for improvements or a better approach?

Edit

I'm currently using Java and the SVNKit library.

答:
Since this is something quite common among diff tools, why not use a tried-and-tested diff library to do the work efficiently instead of rolling out your own code?

Searching for "diff library" or "diff tools" with the name of the language would provide some easier ways.

Title: Quickly compute added and removed lines


问:
How to deploy a single website to multiple physical servers?
Edit: I asked this question 3 or 4 years ago when I was new to web-development, the question looks a bit stupid to me today. I wanted to create a server setup of my own without relying on other hosting providers.
I wanted to delete this question, but it have some nice answers, so I'm leaving it.

I want to deploy my website to multiple physical servers.

Is there possible methods to save files and setting (and also the user input), on all physical servers, so that servers do the following jobs:

Servers used as a network, speeding up the process giving a robust thing to the end user.

Data to be stored on all the servers' hard drivers, and

Every server have the internet connection from different provider, so for example

if any of the internet providers gets down, or

there occur any hardware or power failure,

the website still runs, without a break and without any data loss.

Does anyone know about some online course or some comprehensive tutorials about this topic ?

答:
A CDN may do what you want if your website is caching friendly (a lot of repeated reads).

However if it is not then I'd set it up like this multiple internet connections -> Firewall -> Router -> Load balancer -> Multiple web servers -> Shared SAN, this way all the web servers are saving to the same location. If you want to distribute your servers over a large area you have to be aware that there will be a latency of some sort between the servers and so will not match perfectly.


问:
Difference between a socket and a port
Could someone please explain quite clearly the difference between a port and a socket. I know that a port serves as a door into the network for an application
process and that the application process uses a socket connection to the given port number to handle network communication but when you have multiple processes listening on a single port number, I am finding it difficult to understand the difference between the socket and the port and how they all fit together.</p>

答:
A port is part of the address in the TCP and UDP protocols. It is used to help the OS identify which application should get the data that is received. An OS has to support ports to support TCP and UDP because ports are an intrinsic part of TCP and UDP.

A socket is part of the interface the OS presents to applications to allow them to send and receive network data. Most socket implementations support many protocols beyond TCP and UDP, some of which have no concept of ports. An OS does not have to support sockets to support TCP or UDP; it could provide a different interface for applications to use. A socket is simply one way of sending and receiving data on a specific port.

Title: Difference between a socket and a port


问:
What is meant by namespaced content and what advantages does it have?
I was reading this blog by  James Bennett regarding HTML vs XHTML . He writes :

I don’t have any need for namespaced content; I’m not displaying any
  complex mathematical notation here and don’t plan to, and I don’t use
  SVG for any images. So that’s one advantage of XHTML out the window. I
  also don’t have any need for XML tools; all the processing I need to
  do can be handled by HTML-parsing libraries like BeautifulSoup. That’s
  the other advantage gone.

What does he mean by namespaced content and what advantage does it provide us ?

答:
XML namespaces allow including XML elements defined in a schema other than that of the main document. Specifically, the article talks about MathML and SVG, which are XML-based formats that can be directly embedded in an XHTML document using namespaces, looking like this:</p>

```<code><html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:m="http://www.w3.org/1998/Math/MathML">
  XHTML content goes here
  <m:math>
      MathML content goes here
  </m:math>
  more XHTML content
</html>
</code>```

Body:
XML namespaces allow including XML elements defined in a schema other than that of the main document. Specifically, the article talks about MathML and SVG, which are XML-based formats that can be directly embedded in an XHTML document using namespaces, looking like this:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:m="http://www.w3.org/1998/Math/MathML">
  XHTML content goes here
  <m:math>
      MathML content goes here
  </m:math>
  more XHTML content
</html>


答:
Think of your machine as an apartment building:

A port is an apartment number.

A socket is the door of an apartment.

An IP address is the street address of the building.

Title: Difference between a socket and a port

Body:
Could someone please explain quite clearly the difference between a port and a socket. I know that a port serves as a door into the network for an application
process and that the application process uses a socket connection to the given port number to handle network communication but when you have multiple processes listening on a single port number, I am finding it difficult to understand the difference between the socket and the port and how they all fit together.</p>


问:
Clarify the Single Responsibility Principle
The Single Responsibility Principle states that a class should do one and only one thing.  Some cases are pretty clear cut.  Others, though, are difficult because what looks like "one thing" when viewed at a given level of abstraction may be multiple things when viewed at a lower level.  I also fear that if the Single Responsibility Principle is honored at the lower levels, excessively decoupled, verbose ravioli code, where more lines are spent creating tiny classes for everything and plumbing information around than actually solving the problem at hand, can result.

How would you describe what "one thing" means?  What are some concrete signs that a class really does more than "one thing"?

答:
I look at it more along the lines of a class should only represent one thing.  To appropriate @Karianna's example, I have my Dog class, which has methods for walk(), run() and bark().  I'm not going to add methods for meaow(), squeak(), slither() or fly() because those aren't things that dogs do.  They are things that other animals do, and those other animals would have their own classes to represent them.

(BTW, if your dog does fly, then you should probably stop throwing him out of the window).


问:
Is Perl still a useful, viable language?
I know it may have been asked before, but here goes nothing...

Is Perl still something that would be considered useful? If someone was a new programmer (either completely new to programming or just a few month/years of experience) would Perl be something to be considered worthwhile to learn?

Is Perl still used with frequency? Is it still popular?

Or is Perl dying out compared to languages like Python, Ruby, PHP, ASP.NET, etc.?

Basically it boils down to this:

Is it still used/is it still used frequently? If yes, is it dying? If no, will it make a come back?

Is it something that would be worth learning?

How does it compare in demand to languages like Python in both popularity and usability/viability? Could languages like Python or Ruby be considered replacements for Perl?

Also, will newer versions of Perl really bring a large improvement to the Perl community, and perhaps bring Perl back to centerstage compared to other languages?

EDIT:

Okay, I suppose here's a better, reworded question:

Is Perl still growing, or is it "dying"? Is it still a language worth learning and using? What projects does it really "shine" in compared to other languages? What makes Perl a language to choose? Essentially: is Perl growing obsolete compared to other languages, and if so, do you expect that to change, or to continue?

And thank you to everyone who has answered so far, the discussion has been really interesting!

答:
Grant McLean just uploads a short movie based on evolution of mapofcpan.org, showing the way the CPAN evolves along time with a map-style visual way. It's pretty self-explanatory about the aliveness of the community. Not dying.

Perl is surely suffering of it's bad reputation, because of many legends and because it's community don't want and don't try to make it to be the-hippest-programming-language-in-the-world. It's very difficult to understand why so many people are absolutely convinced that it's an horrible language. You can write creepy code with any language. Perl got best practices as any other language, you just need to implement it int the more than one way to do it base philosophy.

I can see a very sad reason for this bad reputation: for a long time, Perl communities websites got very ugly UI designs (just like perlmonks.org for example). Personally, I really don't care about this, maybe I even come to Perl because for this reason: not a lot of fashionable websites UI, but you can trust the tools, the community with much more faith because it don't tries to be more beautiful than it is. However, quality tools don't mean that you should not focus on the appearance, and it's eventually a kind of mistake to not take care of the look.

For example, a friend of mine (who likes more fashionable languages) told me that the current Perl6 logo is horrific and it will be a problem to attract young flesh to Perl. Much more a problem than with a bright stone or any other well-designed logo.

I believe it's a very sad reason for unpopularity, but that's what rules the world.


问:
Overwhelmed by complex C#/ASP.NET project in Visual Studio 2008
I have been hired as a junior programmer to work on projects that extend existing functionality in a very large, complex solution. The code base consists of C#, ASP.NET, jQuery, javascript, html and xml.

I have some knowledge of all these in addition to fair knowledge of object-oriented programming and its fundamental concepts of inheritance, abstraction, polymorphism and encapsulation. I can follow code up through its base classes, interfaces, abstract classes and understand a large part of the code that I read while doing this.

However, this solution is so humongous and so many things get tied together whenever I navigate through the code that I feel absolutely overwhelmed. I often find myself unable to fully follow everything that is going on with objects being serialized, large amounts of C# and javascript operating on the same pages and methods being called from template files that consist mainly of markup.

I love learning about code, but trying to deal with this really stresses me out.

Additionally, I do know that a significant amount of unit testing has been done but I know nothing about unit testing or how to utilize it.

Any advice anyone could offer me regarding dealing with a large code base while using Visual Studio 2008 would be greatly appreciated. Are there tools that I can use to help get a handle on what is going on? Perhaps there are things even in Visual Studio that I am not aware of. How can I follow the code to low level functionality in order to get a better grasp of what is going on at a high level?

答:
Most overwhelming systems, in my experience, have at least a few key parts that seem scariest. I pick one and try to understand just that one. Knowing that key part makes it easier to understand its related parts.

My favorite approach to doing this is to use a sequence diagram. To me, a sequence diagram provides me with the picture I need to understand how a key part works.

Keep in mind too that your anxiety & stress may mean that the system isn't architected and/or documented very well, so don't beat yourself up for being confused.


问:
Managing JS and CSS for a static HTML web application
I'm working on a smallish web application that uses a little bit of static HTML and relies on JavaScript to load the application data as JSON and dynamically create the web page elements from that.

First question:  Is this a fundamentally bad idea?  I'm unclear on how many web sites and web applications completely dispense with server-side generation of HTML.  (There are obvious disadvantages of JS-only web apps in the areas of graceful degradation / progressive enhancement and being search engine friendly, but I don't believe that these are an issue for this particular app.)

Second question:  What's the best way to manage the static HTML, JS, and CSS?  For my "development build," I'd like non-minified third-party code, multiple JS and CSS files for easier organization, etc.  For the "release build," everything should be minified, concatenated together, etc.  If I was doing server-side generation of HTML, it'd be easy to have my web framework generate different development versus release HTML that includes multiple verbose versus concatenated minified code.  But given that I'm only doing any static HTML, what's the best way to manage this?  (I realize I could hack something together with ERB or Perl, but I'm wondering if there are any standard solutions.)

In particular, since I'm not doing any server-side HTML generation, is there an easy, semi-standard way of setting up my static HTML so that it contains code like

```<code><script src="js/vendors/jquery.js"></script>
<script src="js/class_a.js"></script>
<script src="js/class_b.js"></script>
<script src="js/main.js"></script>
</code>```

at development time and

```<code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/entire_app.min.js"></script>
</code>```

for release?

答:
If, as you specified, it doesn't matter in this particular case to support users with JavaScript disabled, as well as the search engines, then the only drawback I can see might be the performance.

I deliberately use might.

In theory:

Servers are much more powerful then clients and

Server-side languages are faster then JavaScript,

In practice, on the other hand:

Most beliefs of developers that one thing should be faster than another one are wrong. Only a profiler knows the truth.

I'm pretty sure that there are plenty of people who have computers much faster than the ones some hosting providers use for all but the most expensive offers,

If JavaScript was slow ten years ago, it's not the case any longer with the recent versions of normal browsers. Even in IE, JavaScript is pretty fast in the latest versions.

By sending only the JSON instead of HTML, you may reduce the bandwidth usage (even if this strongly depends on your particular case, the caching techniques you use, etc.)

As for your question about minification and the fact that you cannot do it on runtime, do it when deploying the application to the server. For example, before you test your app in staging environment or deploy it into production, transform the JavaScript code with Closure Compiler, minify your CSS with similar tools (or transform your LESS into a minified CSS if this is the case), etc.

You can easily automate this process too.

The difficult part would be to transform the HTML code as well to replace the calls to multiple CSS or JavaScript files by the calls to one minified CSS and one minified JavaScript. Since you don't want to use templates (for example you could use SSI, but then, you couldn't use your app locally without a local server), a dirty hack would be to modify the HTML code itself before deploying it.

Warning: dirty hack.

Let's say you have:

```<code><!--Start calls to JavaScript-->
<script src="js/vendors/jquery.js"></script>
<script src="js/class_a.js"></script>
<script src="js/class_b.js"></script>
<script src="js/main.js"></script>
<!--End calls to JavaScript-->
</code>```

in your source HTML, and:

```<code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/entire_app.min.js"></script>
</code>```

in js-compact.txt.

Your automated tool could search for  and , remove the whole block, including the comments, and then replace it by the contents of js-compact.txt.

In a more elaborate version, you could parse your HTML, find and remove all the calls to JavaScript and replace them by the calls to minified code.

Body:
If, as you specified, it doesn't matter in this particular case to support users with JavaScript disabled, as well as the search engines, then the only drawback I can see might be the performance.

I deliberately use might.

In theory:

Servers are much more powerful then clients and

Server-side languages are faster then JavaScript,

In practice, on the other hand:

Most beliefs of developers that one thing should be faster than another one are wrong. Only a profiler knows the truth.

I'm pretty sure that there are plenty of people who have computers much faster than the ones some hosting providers use for all but the most expensive offers,

If JavaScript was slow ten years ago, it's not the case any longer with the recent versions of normal browsers. Even in IE, JavaScript is pretty fast in the latest versions.

By sending only the JSON instead of HTML, you may reduce the bandwidth usage (even if this strongly depends on your particular case, the caching techniques you use, etc.)

As for your question about minification and the fact that you cannot do it on runtime, do it when deploying the application to the server. For example, before you test your app in staging environment or deploy it into production, transform the JavaScript code with Closure Compiler, minify your CSS with similar tools (or transform your LESS into a minified CSS if this is the case), etc.

You can easily automate this process too.

The difficult part would be to transform the HTML code as well to replace the calls to multiple CSS or JavaScript files by the calls to one minified CSS and one minified JavaScript. Since you don't want to use templates (for example you could use SSI, but then, you couldn't use your app locally without a local server), a dirty hack would be to modify the HTML code itself before deploying it.

Warning: dirty hack.

Let's say you have:

<!--Start calls to JavaScript-->
<script src="js/vendors/jquery.js"></script>
<script src="js/class_a.js"></script>
<script src="js/class_b.js"></script>
<script src="js/main.js"></script>
<!--End calls to JavaScript-->

in your source HTML, and:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/entire_app.min.js"></script>

in js-compact.txt.

Your automated tool could search for <!--Start calls to JavaScript--> and <!--End calls to JavaScript-->, remove the whole block, including the comments, and then replace it by the contents of js-compact.txt.

In a more elaborate version, you could parse your HTML, find and remove all the calls to JavaScript and replace them by the calls to minified code.


问:
What is the best objective way to measure language popularity trends? (What's better than TIOBE?)
The best way to get data on computer language popularity that I know is the TIOBE index.  But everyone knows that TIOBE is hopelessly flawed.  (If someone provides a link to support this, I'll add it here.)

So is there any data on programming language popularity that is generally considered meaningful?  The only other option I know is to look at the trends at indeed.com, which is inherently flawed, being based on job postings.

It isn't like I would make a future language decision solely based on an index, but it might provide a useful balance to the skewed perspective one obtains by talking to ones friends and colleagues.

To illustrate that bias, I'll point out that based on the experience of those I personally know, the only languages used professionally today (in order of popularity) are Java, C#, Groovy, JavaScript, Ruby, Objective C, and Perl.  (Though it is evident that C, C++ and PHP were used in the past.)

So my question is, everyone bashes TIOBE, but is there anything else?  If so, can anyone explain how we know the alternative has better methodology?  Thanks.

答:
One alternative would be to look at the number of questions for each programming language tag on StackOverflow.

I set up a Quick Query to do that: Post Counts By Tag

Unurprisingly, given the nature of that community,  C# has a considerable lead.

Of course this also is biased against languages that because of ease of use might have fewer people asking questions.


问:
What is the most effective order to learn SQL Server, LINQ, and Entity Framework?
I am trying to get some advice on what order I should learn about SQL Server, LINQ, and Entity Framework to be able to better work with ASP.NET Webforms and MVC.

From what I've been able to learn so far, many recommend learning LINQ or Entity Framework before learning SQL Server. It also appears that many companies are looking for people with knowledge in LINQ-to-SQL and Entity Framework without mentioning SQL Server. However, my understanding is that LINQ-to-SQL and Entity Framework translate code into SQL Server queries, making this a poor approach.

Is there a correct or best order in which to learn these technologies?

答:
You are correct - you should learn SQL Server either before or along with the other skills. I've seen plenty of entity-framework queries blow up because SQL Server couldn't handle the SQL that was passed to it.

I believe we should use the right tool for any job.  Often, SQL Server is the best tool to perform a particular task.

It's true that "he who has a hammer treats everything like a nail".  If you only learn LINQ-to-Entities, you'll occasionally use LINQ-to-Entities when you should have used a stored proc on SQL Server.


答:
One tool that appears to do part of what you need, at least for Java webapps, is Web Resource Optimizer for Java (wro4j).

Free and Open Source Java project which brings together almost all the modern web tools: JsHint, CssLint, JsMin, Google Closure compressor, YUI Compressor, UglifyJs, Dojo Shrinksafe, Css Variables Support, JSON Compression, Less, Sass, CoffeeScript and much more. In the same time, the aim is to keep it as simple as possible and as extensible as possible in order to be easily adapted to application specific needs.

Easily improve your web application loading time. Keep project web resources (js & css) well organized, merge & minify them at run-time (using a simple filter) or build-time (using maven plugin) and has a dozen of features you may find useful when dealing with web resources.

You might also check into RequireJS to see if that would help you define which js files the client should download in a particular environment.

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

Title: Managing JS and CSS for a static HTML web application

Body:
I'm working on a smallish web application that uses a little bit of static HTML and relies on JavaScript to load the application data as JSON and dynamically create the web page elements from that.

First question:  Is this a fundamentally bad idea?  I'm unclear on how many web sites and web applications completely dispense with server-side generation of HTML.  (There are obvious disadvantages of JS-only web apps in the areas of graceful degradation / progressive enhancement and being search engine friendly, but I don't believe that these are an issue for this particular app.)

Second question:  What's the best way to manage the static HTML, JS, and CSS?  For my "development build," I'd like non-minified third-party code, multiple JS and CSS files for easier organization, etc.  For the "release build," everything should be minified, concatenated together, etc.  If I was doing server-side generation of HTML, it'd be easy to have my web framework generate different development versus release HTML that includes multiple verbose versus concatenated minified code.  But given that I'm only doing any static HTML, what's the best way to manage this?  (I realize I could hack something together with ERB or Perl, but I'm wondering if there are any standard solutions.)

In particular, since I'm not doing any server-side HTML generation, is there an easy, semi-standard way of setting up my static HTML so that it contains code like

```<code><script src="js/vendors/jquery.js"></script>
<script src="js/class_a.js"></script>
<script src="js/class_b.js"></script>
<script src="js/main.js"></script>
</code>```

at development time and

```<code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="js/entire_app.min.js"></script>
</code>```

for release?


问:
Java code documentation in a separate docs file somehow mapped to a source file?
What would be a good alternative to inline Java documentation, i.e. can one have a separate docs file somehow mapped to a java source file?

I have never liked huge comment sections littered in code.

答:
I have been using Javadoc feature of package comments to avoid littering source code with verbose documentation comments:

Package-Level Comments

With Javadoc 1.2, package-level doc comments are available. Each package can have its own package-level doc comment source file that The Javadoc tool will merge into the documentation that it produces. This file is named package.html (and is same name for all packages). This file is kept in the source directory along with all the *.java files. (Do not put the packages.html file in the new doc-files source directory, because those files are only copied to the destination and are not processed.)

The file package.html is an example of a package-level source file for java.text and package-summary.html is the file that the Javadoc tool generates.

The Javadoc tool processes package.html by doing three things...

Using above feature, I had detailed verbose documentation for classes and methods in the package stored separately of code, in a dedicated html file. As for Javadoc comments in java files, I just wrote brief explanations there, adding text like

If needed, refer to package documentation for more details.

One thing I particularly liked about this was that although docs were in the separate file and in a format more convenient for large docs (html), it has been stored close enough to related source code and all the updates in it were automatically picked up during the build.

Starting from Java 1.5, you can alternatively put a package-info.java along with the classes of the package. This file should look like this:

```<code>/**
 * Javadoc for your package here
 */
package com.yourpackage;
</code>```

JLS documentation suggests that this is preferred way:

The following scheme is strongly recommended for file-system-based implementations: The sole annotated package declaration, if it exists, is placed in a source file called package-info.java in the directory containing the source files for the package...

It is recommended that package-info.java, if it is present, take the place of package.html for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the package documentation comment immediately preceding the (possibly annotated) package declaration in package-info.java. In this way, package-info.java becomes the sole repository for package-level annotations and documentation. If, in future, it becomes desirable to add any other package-level information, this file should prove a convenient home for this information.

Body:
I have been using Javadoc feature of package comments to avoid littering source code with verbose documentation comments:

Package-Level Comments

With Javadoc 1.2, package-level doc comments are available. Each package can have its own package-level doc comment source file that The Javadoc tool will merge into the documentation that it produces. This file is named package.html (and is same name for all packages). This file is kept in the source directory along with all the *.java files. (Do not put the packages.html file in the new doc-files source directory, because those files are only copied to the destination and are not processed.)

The file package.html is an example of a package-level source file for java.text and package-summary.html is the file that the Javadoc tool generates.

The Javadoc tool processes package.html by doing three things...

Using above feature, I had detailed verbose documentation for classes and methods in the package stored separately of code, in a dedicated html file. As for Javadoc comments in java files, I just wrote brief explanations there, adding text like

If needed, refer to package documentation for more details.

One thing I particularly liked about this was that although docs were in the separate file and in a format more convenient for large docs (html), it has been stored close enough to related source code and all the updates in it were automatically picked up during the build.

Starting from Java 1.5, you can alternatively put a package-info.java along with the classes of the package. This file should look like this:

/**
 * Javadoc for your package here
 */
package com.yourpackage;

JLS documentation suggests that this is preferred way:

The following scheme is strongly recommended for file-system-based implementations: The sole annotated package declaration, if it exists, is placed in a source file called package-info.java in the directory containing the source files for the package...

It is recommended that package-info.java, if it is present, take the place of package.html for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the package documentation comment immediately preceding the (possibly annotated) package declaration in package-info.java. In this way, package-info.java becomes the sole repository for package-level annotations and documentation. If, in future, it becomes desirable to add any other package-level information, this file should prove a convenient home for this information.


答: A computer has an IP address that identifies it as a separate entity on the network.  We add an additional number to that to allow us to differentiate between connections to that computer.  This is the port number.  On the OS side of the connection you need buffers, connection state, etc.  This logical object is the socket.  </p>

Title: Difference between a socket and a port


答:
Is it a good idea to move code from web server to browser?

Smallish web application that uses a little bit of static HTML and
relies on JavaScript to load the application data as JSON and
dynamically create the web page elements from that.

I see nothing wrong with this.  Most of gmail works this way.  I deliberately build pages from JavaScript as an optimization technique when there is a lot of HTML around a little bit of data.

Security

One thing to keep in mind is that you cannot implement any security on the client side.  All security must be done on the server side, even if some of that (such as input validation and error messages) is duplicated on the client side.

Even Wikipedia which lets anyone edit anything, tracks all activity and makes backups so that changes are easy to undo.  They now also prevent anonymous users from creating new articles.  If your application does any updates, you need a server side component that controls permissions.  This component almost certainly needs a way of tracking who is using the system for any given request.  That is not something you can trust the client side for because anyone could build a client that did something malicious (heck, they have your code on their machine).

Compression

"Waste Not Want Not" would be my first approach to CSS and JavaScript compression.  The first image you download may be bigger than all your CSS and JavaScript put together.  If you are using HTTPS, I find it's faster to build CSS and JavaScript into every page because HTTPS disables browser caching and it saves one request to the server.  Even then, you can put common routines in a frame and call them from each page as parent.myMethod(x).  For HTTP, you can put common JavaScript and CSS into separate files that the browser will cache.  I would only use compression tools to optimize when everything else as at the bleeding edge, and then I would time your page creation to be sure it's making a difference.

A return after every } makes compressed CSS quite readable.  Sometimes the optional final trailing ; prevents bugs when you add an additional attribute.  For styles that require many attributes you could add line breaks, but no unnecessary spaces.  This gives you 95-98% of the maximum possible compression without using a compression utility.

If you are careful with your JavaScript, it should be smaller than the HTML that would be used to build the same page.  I would leave it readable.  Use tabs instead of spaces, or indent 2 spaces at a time.  Whitespace won't account for more than 20% of your code.  Maybe readable variable names add another 5%.  When you have a bug, it will be so much easier to be able to see what you are doing, that it's probably worth the slight extra size.

The most common reasons for slowness are server-side issues and downloading images.  Optimizing your queries should take page loads from 30+ seconds down to less than 1 second.  Unless it's a game, people just aren't very sensitive to total response times of less than one second.  Also, most people's internet connection isn't reliable for response times < 1/2 second, so there's definitely a point of diminishing returns.  It's not worth it to shave off 0.01 seconds of processing time by making your code totally unreadable.  Also, your server may take 0.005 seconds to do the compression, so pre-compress or make sure that the act of compressing your CSS and JavaScript on the fly does not eat up the performance gains of doing so.


答:
I'm going to go against the grain and suggest LINQ->EF->SQL Server. Here's why:

LINQ is much more than just writing queries, or converting C#/VB to SQL. It's also a door to functional programming (.Select() => Map(), .Aggregate() = fold(), .Where() = filter() .SelectMany() = bind()) and thus applies to many more domains and problems outside of just getting data from some source. SQL itself is more of a one-trick-pony. It's a huge, important, trick but it's still just getting data from a database. (I'm not saying that you can't write full fledged software mostly in SQL, or write incredibly complex SQL queries, I'm arguing that it's usually stupid and you'd be better suited learning to write better LINQ queries instead).

You'll get more done faster. Learning SQL first is more of a "start from the foundations and work your way up" approach, which is a good idea if you're in school, or otherwise have a bunch of time on your hands, but I don't get that impression. You'll only get less from this approach if you duck out early and forgoe learning SQL/SQL Server. Don't do that.

If, and when, SQL Server craps the bed because you've written a horrible LINQ query, you can get help with that query and move on. TBH... although it happens, in my experience, it's much less common than people let on.

Considering that you don't write SQL now, I'm assuming that you're a student or self taught. For now you can continue to lean on DBAs and people who know SQL to tackle the performance problems that require stored procs while you get better at what you're doing now - application code. I think that this instantly improves your quality and usefulness to your/a employer.

SQL Server is a beast. I don't suspect that you're looking to learn it all, but it is truly massive once you get into all that it can do. I can easily see someone getting lost in SQL pretty easily if they have zero experience with declarative languages (that is, you might not know where SQL ends and SQL Server begins).

Neither is LINQ or SQL a subset of the other, but there is an intersection, so knowning one is good help when learning the other. Thus, I don't think that learning either first better helps you learn the other more.

Some will disagree, and I welcome their arguments, but this is what I think.

Title: What is the most effective order to learn SQL Server, LINQ, and Entity Framework?

Body:
I am trying to get some advice on what order I should learn about SQL Server, LINQ, and Entity Framework to be able to better work with ASP.NET Webforms and MVC.

From what I've been able to learn so far, many recommend learning LINQ or Entity Framework before learning SQL Server. It also appears that many companies are looking for people with knowledge in LINQ-to-SQL and Entity Framework without mentioning SQL Server. However, my understanding is that LINQ-to-SQL and Entity Framework translate code into SQL Server queries, making this a poor approach.

Is there a correct or best order in which to learn these technologies?


问:
Most logically consistent way to create methods of the form a affects b?
I have a common scenario where I have an object (a) that logically affects another object (b), like a makes a note on b, or a marks b as disabled (usually a is a user object of the system and b is some kind of business object like a customer or an appointment).

In the past, the method was on the affected object like:

```<code>customer.Disable(user); // user is marking the customer as disabled
</code>```

... but it doesn't read well (it appears backwards). The opposite:

```<code>user.Disable(customer);
</code>```

... reads better, but there's something about it that I can't put my finger on that just doesn't seem right. The only other option is to have a static intermediary:

```<code>ThirdPartyClass.DisableCustomer(customer, user);
</code>```

... but the domain objects end up becoming more like DTOs and I prefer the domain model approach because it makes more sense.

So the question is: which makes the most sense? Is there an option I haven't considered? Who actually owns an operation like this?

Edit

With the second option, the actionable objects in the system (users usually) end up becoming huge because the users of the system are the ones that pretty much do and affect everything.

答:
user.Disable(customer) almost seems like it's saying that user is being disabled, since   user.Disable() would read like it's acting on the user, not the customer.

user.DisableCustomer(customer) reads a little better, I think, as it makes it clear that the customer is being disabled.  It also means you don't need an extra class just for the sake of it.


问:
Client-Side V.S. Server-Side Searching?
I am currently helping to design a web site and application in HTML. We would like the user to be able to search the site/app for desired content via a search bar. We would also like to include an advanced search ability to allow for different search options and more concentrated searches.

We are having trouble deciding whether to program the search function on the Client-Side (with JavaScript) or on the Server-Side (with PHP). What are the pros and cons of both and what would you recommend?

答:
I think this is leaning more towards a user experience sort of question, but I want to mention one thing before I go into that.  If you're searching things that you have already loaded into the page, then using JS will probably be your best bet since you'll be searching records that the server side has already fetched and given to the page.  Now if that isn't the case, then I think your issue is more UX.

If the content your searching isn't already on the page, then you could have the call to the search on the client side, but you'll still need some server-side logic to fetch the records for the client to render.  The big question is, do you want the user to sit through a page load, or would you rather render the results on the same page?

At work, we have both types of searches being used.  We have a search box to search for users and it retrieves minimal amount of info about the users and constructs a dropdown based on the text in the input.  But you can also submit that search, and you will be directed to a page that displays more information about the search results.

This is really less of a, which one is better for performance/developments/etc. and more about how you want the user to interact with your search.  I believe that either way, you'll need some sort of server-side code, but how you display that is completely up to you and your UX goal.

Title: Client-Side V.S. Server-Side Searching?


答:
I think that SQL and LINQ are two different things that you need to learn as a .NET programmer. I also think you can learn them somewhat concurrently, depending on what you know about DB and SQL basics already.

SQL is going to be more portable knowledge that, in addition to new development, you can use on legacy projects and reporting tasks. When there's a lack of DBAs (and there almost always is), you'll probably be called up to generate a quick report for accounting/marketing/etc. with the latest numbers on this or that. Or, you might get handed a legacy VB6 app as your responsibility that has inline SQL. Understanding the SQL will be essential to almost all .NET programming jobs.

LINQ is essential to know if you're going to do something other than legacy (Framework 2.0 or 1.1) .NET programming. Sure, you can write code without using it but this won't be acceptable in organizations that don't have a huge investment in 'ancient' code.

Entity Framework brings SQL and LINQ together. So, once you have a sufficient understanding of both of them you can move forward to EF rather quickly. Remember that EF can be done with straight diagramming of DB ojects, by creating your own objects in code or by a hybrid of these techniques via partial classes. There is tremendous flexibility in it with the 4.0 and 5.0 EF versions.


答:
Learning SQL Server (T-SQL) will give you a deeper understanding of all databases and will allow you to easily pick up concepts from other relational databases (Oracle, MySql, Postgres, etc). In the long run you'll be a more employable person.

A more practical approach might be to learn both. EF's output is T-SQL.  Using a tool such as EF Profiler, the raw T-SQL can be viewed and learned.

At the end of the day, T-SQL is much more powerful with data than any ORM (EF, nHibernate or LLBGen)and eventually you'll encounter an problem that can only be solved in the database.


问:
Big Oh notation does not mention constant value
I am a programmer and have just started reading Algorithms. I am not completely convinced with the notations namely Bog Oh, Big Omega and Big Theta. The reason is by definition of Big Oh, it states that there should be a function g(x) such that it is always greater than or equal to f(x). Or f(x) <= c.n for all values of n >n0.

Why don't we mention the constant value in the definition? For example, let's say a function 6n+4, we denote it as O(n). But it's not true that the definition holds good for all constant value. This holds good only when c >= 10 and n >= 1. For lesser values of c than 6, the value of n0 increases. So why we do not mention the constant value as a part of the definition?

答:
The whole notion of Big-Oh notation is specifically to ignore constants and present the most important part of the function describing the run-time of an algorithm.

Forget the formal definition for a moment. Which is the worse (faster growing) function, n^2 - 5000 or 5000 n + 60000? For n less than around 5000, the linear function is greater (and thus worse). Beyond that (exact value 5013?), the quadratic equation is bigger.

Since there are more (quite a few more) positive numbers greater than 5000 than less, we take the quadratic to be the 'bigger' (worse) function in general. Order notation (Big-Oh etc) enforces that (you can always eliminate an additive and a multiplicative constant using those definitions).

Of course, things aren't always simple. Sometimes you do want to know those constants. Which is better Insertion sort or Bubble sort? Both are O(n^2). But one really is better than the other. With more elaborate analysis one can get constants like you are wondering about. It's usually much easier to compute the Big-Oh function than a more exact function.

Big-Oh ignores these constants to simplify and make the most important comparisons easier. We like the notation because usually we don't want to know about the (mostly irrelevant) constants.


问:
Writing algorithm on 2D data set in plain english
I have started an introductory Java class and the material is absolutely horrendous and I have to get excellent grades to be accepted into the master's degree, hence my very beginner question:

In my assignment I have to write algorithms (no pseudo-code yet) to solve a board game (Sudoku). Essentially, the notes say that an algorithm is specification of the input(s), the output(s) and the treatments applied to the input to get the output. My question lies on the wording of algorithms because I could probably code it but I can't seem to put it on paper in a coherent way.

The game has a 9x9 board and one of the algorithms to write has to find the solution by looking at 3 squares (either horizontal or vertical) and see if one of the three sub-squares match the number you are looking for. If none match then the number you are looking to place is in one of the other 2 set of 3 sub-squares (see image to get a better idea).

Note: The task is not to write a complete solver. Only an algorithm to solve the particular case I have described.

I really can't get my head around how to formulate the solution into the terms described above or maybe it's just too simple, here's what I was thinking:

Input: A 2-dimensional set of data of size 9 by 9 to be solved and a number to search for.

Ouput: A 2-dimensional set of data of size 9 by 9 either solved or partially solved.

Treatment: Scan each set of 3x9 and 9x3 squares. For each line or column of a 3x3 square check if the number matches a line (or column). If it does then move to the next line (or column). If not then proceed to the next 3x3 square in the same line (or column). Rinse and repeat.

Does that make sense as an algorithm written in plain english ? I'm not looking for an answer to the algorithm per se but rather on the formulation of algorithms in plain english.

Note: Apparently this isn't clear: this is not about solving for all possible solutions. This is about solving only this very particular set of rules. I did not make the assignment. In any case, this is not even remotely relevant as this is not the focus of my question.

答:
Be annoyingly complete.  For instance you don't describe how you take the 9x9 input and create the set of smaller squares.  Also that first sentence talks about 9x3, 3x9 squares the second looks at 3x3 squares typo or missed step?  It may help to write the pseudo-code(or real code) first then work backwards to a detailed description until you get the hang of it.

It ought to be something like: Break 9x9 input into a set of 9 sub squares by taking the intersection of the first 3 rows, and columns then the next three columns etc.  Then examine each sub square for the following property zzz. If it holds preform transformation xyz and continue with the next sub square. If it doesn't hold skip it and continue. etc. Reassemble the 9x9 square from the 3x3 sub squares by this transformation and return it.


问:
Diminishing Returns on Additional Developers
Is there a term to describe the point at which adding more developers to a software project will provide diminishing returns?

I realize that at a high level, it is more complicated that just a number of developers at which the project will be at productive capacity (ex/ state of the project, quality of the added developer), but I am trying to come up with a way to relate this to non-technical management through repetition. I'm basically looking for a term which invokes a strong mental image like "terminal velocity", except for Brook's Law.

答: A reasonably close term would be the "range of elasticity": the analogy to hitting the price inelasticity region, when further reducing the price does not increase your sales, should ring a bell with management.</p>


答:
(since this is a longer answer, read the bolds for a summary)

Let's take your example and walk through it step-by-step, understanding the purpose behind what we are doing.  We start with your function and the goal of finding its Big Oh notation:

```<code>f(n) = 6n+4
</code>```

First, let O(g(n)) be the Big Oh notation we are trying to find for f(n).  From the definition of Big Oh, we need to find a simplified g(n) where there exists some constants c and n0 where c*g(n) >= f(n) is true for all n's greater than n0.

First, let's choose g(n) = 6n + 4 (which would yield O(6n+4) in Big Oh).  In this case we see that c = 1 and any value of n0 will meet the mathematical requirements from our definition of Big Oh, since g(n) always equals f(n):

```<code>c*g(n)      >=  f(n)
1*(6n + 4)  >=  6n + 4    //True for all n's, so we don't need to pick an n0
</code>```

At this point we've met the mathematical requirements.  If we stopped at O(6n+4), it's clear that this is no more helpful than writing f(n), so it would miss the true purpose of Big Oh notation:  to understand the general time-complexity of an algorithm!  Thus, let's move on to the next step:  simplification.

First, can we simplify out of the 6n so the Big Oh is O(4)?  No!  (Exercise for the reader if they don't understand why)

Second, can we simplify out the 4 so that the Big Oh is O(6n)?  Yes!  In that case, g(n) = 6n, so:

```<code>c*g(n)    >=  f(n)
c*6n      >=  6n + 4
</code>```

At this point, let's choose c = 2 since then the left side will increase faster (by 12) than the right side (by 6) for each increment of n.

```<code>2*6n      >=  6n + 4
</code>```

Now we need to find a positive n0 where the above equation is true for all n's greater than that value.  Since we already know that the left side is increasing faster than the right, all we have to do is find one positive solution.  Thus, since n0 = 2 makes the above true, we know that g(n)=6n, or O(6n) is a potential Big Oh notation for f(n).

Now, can we simplify out the 6 so that the Big Oh is O(n)?  Yes!  In that case, g(n) = n, so:

```<code>c*g(n)      >=  f(n)
c*n         >=  6n + 4
</code>```

Let's pick c = 7 since the left would increase faster than the right.

```<code>7*n         >=  6n + 4
</code>```

We see that the above will be true for all n's greater than or equal to n0 = 4.  Thus, O(n) is a potential Big Oh notation for f(n).  Can we simplify g(n) anymore?  Nope!

Finally, we've found that the simplest Big Oh notation for f(n) is O(n).  Why did we go through all this?  Because now we know that f(n) is linear, since it's Big Oh notation is of linear complexity O(n).  The nice thing is that now we can compare the time-complexity of f(n) to other algorithms!  For example, we now know that f(n) is of comparable time-complexity to the functions h(n) = 123n + 72, i(n) = n, j(n) = .0002n + 1234, etc; because using the same simplification process outlined above they all have linear time-complexity of O(n).

Sweet!!!

Title: Big Oh notation does not mention constant value

Body:
I am a programmer and have just started reading Algorithms. I am not completely convinced with the notations namely Bog Oh, Big Omega and Big Theta. The reason is by definition of Big Oh, it states that there should be a function g(x) such that it is always greater than or equal to f(x). Or f(x) <= c.n for all values of n >n0.

Why don't we mention the constant value in the definition? For example, let's say a function 6n+4, we denote it as O(n). But it's not true that the definition holds good for all constant value. This holds good only when c >= 10 and n >= 1. For lesser values of c than 6, the value of n0 increases. So why we do not mention the constant value as a part of the definition?

Body:
(since this is a longer answer, read the bolds for a summary)

Let's take your example and walk through it step-by-step, understanding the purpose behind what we are doing.  We start with your function and the goal of finding its Big Oh notation:

f(n) = 6n+4

First, let O(g(n)) be the Big Oh notation we are trying to find for f(n).  From the definition of Big Oh, we need to find a simplified g(n) where there exists some constants c and n0 where c*g(n) >= f(n) is true for all n's greater than n0.

First, let's choose g(n) = 6n + 4 (which would yield O(6n+4) in Big Oh).  In this case we see that c = 1 and any value of n0 will meet the mathematical requirements from our definition of Big Oh, since g(n) always equals f(n):

c*g(n)      >=  f(n)
1*(6n + 4)  >=  6n + 4    //True for all n's, so we don't need to pick an n0

At this point we've met the mathematical requirements.  If we stopped at O(6n+4), it's clear that this is no more helpful than writing f(n), so it would miss the true purpose of Big Oh notation:  to understand the general time-complexity of an algorithm!  Thus, let's move on to the next step:  simplification.

First, can we simplify out of the 6n so the Big Oh is O(4)?  No!  (Exercise for the reader if they don't understand why)

Second, can we simplify out the 4 so that the Big Oh is O(6n)?  Yes!  In that case, g(n) = 6n, so:

c*g(n)    >=  f(n)
c*6n      >=  6n + 4

At this point, let's choose c = 2 since then the left side will increase faster (by 12) than the right side (by 6) for each increment of n.

2*6n      >=  6n + 4

Now we need to find a positive n0 where the above equation is true for all n's greater than that value.  Since we already know that the left side is increasing faster than the right, all we have to do is find one positive solution.  Thus, since n0 = 2 makes the above true, we know that g(n)=6n, or O(6n) is a potential Big Oh notation for f(n).

Now, can we simplify out the 6 so that the Big Oh is O(n)?  Yes!  In that case, g(n) = n, so:

c*g(n)      >=  f(n)
c*n         >=  6n + 4

Let's pick c = 7 since the left would increase faster than the right.

7*n         >=  6n + 4

We see that the above will be true for all n's greater than or equal to n0 = 4.  Thus, O(n) is a potential Big Oh notation for f(n).  Can we simplify g(n) anymore?  Nope!

Finally, we've found that the simplest Big Oh notation for f(n) is O(n).  Why did we go through all this?  Because now we know that f(n) is linear, since it's Big Oh notation is of linear complexity O(n).  The nice thing is that now we can compare the time-complexity of f(n) to other algorithms!  For example, we now know that f(n) is of comparable time-complexity to the functions h(n) = 123n + 72, i(n) = n, j(n) = .0002n + 1234, etc; because using the same simplification process outlined above they all have linear time-complexity of O(n).

Sweet!!!


问:
How to develop a menu for Linux apps
I want to create a python panel for Linux like pypanel or tint2 just for fun and to do practice with python development.

Now the problem is:

I want to create an auto-generated menu, but I don't know where to start.

Where can I find all user's installed software in a Linux distro? I know I should look in the /usr/bin folder, but I don't know if it's really the best thing to do.

Is there a way to filter installed apps to avoid dependecies programs?

答:
There is a somewhat standardized way of doing this that many Linux desktop environments follow. Look in the directories /usr/share/applications and ~/.local/share/applications for files with names that end in .desktop. Each of these files will correspond to one program and should look something like this:

```<code>[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Sample Application Name
Comment=A sample application
Exec=application
Icon=application.png
Terminal=false
</code>```

You can parse these files to get the information to populate your menu.

For more infomation, see http://developer.gnome.org/integration-guide/stable/desktop-files.html.en

Title: How to develop a menu for Linux apps

Body:
There is a somewhat standardized way of doing this that many Linux desktop environments follow. Look in the directories /usr/share/applications and ~/.local/share/applications for files with names that end in .desktop. Each of these files will correspond to one program and should look something like this:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Sample Application Name
Comment=A sample application
Exec=application
Icon=application.png
Terminal=false

You can parse these files to get the information to populate your menu.

For more infomation, see http://developer.gnome.org/integration-guide/stable/desktop-files.html.en


问:
What kind of programs/solutions can only be written with OOP or are too hard to achieve without it?
Paraphrasing a recent question: https://softwareengineering.stackexchange.com/questions/52608/what-is-object-oriented-programming-ill-suited-for

I would like to ask the opposite question:

What kind of programs cannot be written unless you use OOP?

What kind of programs are not recommended to be written using non-OOP techniques?

What kind of programs need OOP in order to even be written?
What kind of programs would be too hard to write without OOP ?

The answer to this question can help sell the idea of OOP to project leaders that have no special interest in code quality. At least they could buy the idea if one shows them the kind of things that are not even possible unless you use OOP.

答:
OO is a way to organize programs. To make the case for OO, you need a big enough program that its organization is important (yes beginners are now drilled into OO way of thinking without any experience of programs big enough for it to matter, but those I meet often are like you, unable to explain why it is good, and thus unable to see when it isn't).

Obviously it doesn't depend only of the size of the program (with which metric BTW), but also a lot of what the program do.  The easiest case of OO is probably simulators, there the OO way of thinking maps so cleanly to the problem domain that it is difficult to argue against. As a matter of fact, it was one of the use cases behind OO (Simula is one of the first OO language and it brought language support for techniques already in used but not formalized, and C++ started with the intention to reduce Simula's overhead).

Now, you'll have a very hard time to sell OO to a project leader experienced enough to see that what you are working on is a case where OO brings just overhead without compensating benefits.


问:
Should I use AND or should I use OR
An order can be in the "status" of Completed, Corrected or some other status.

I saw some code that is checking it like this, the purpose is to disable some stuff when the status is in Completed or Corrected status.

```<code> if (model.CurrentStatus != DSRHelper.OrderStatusEnum.Complete && model.CurrentStatus != DSRHelper.OrderStatusEnum.Corrected)
</code>```

I can't get it why the engineer has used "AND" for this, shouldn't it be an "OR"?

答:
No, the AND is correct: if you put OR, you'd get a condition that is always true, because the status cannot be Complete and Corrected at the same time.

To understand why, use De Morgan's Laws to convert your proposed condition to an equivalent. You start with

```<code>NOT(status is complete) OR NOT(status is corrected)
</code>```

and convert to

```<code>NOT((status is complete) AND (status is corrected))
</code>```

this is always false.

Title: Should I use AND or should I use OR

Body:
No, the AND is correct: if you put OR, you'd get a condition that is always true, because the status cannot be Complete and Corrected at the same time.

To understand why, use De Morgan's Laws to convert your proposed condition to an equivalent. You start with

NOT(status is complete) OR NOT(status is corrected)

and convert to

NOT((status is complete) AND (status is corrected))

this is always false.


答:
No, AND appears to be correct here. If you switched it to OR, the condition would always be true. If it was Completed, then the second condition would be true. If it was Corrected, then the first would be true.

Keep in mind that the condition currently used is equivalent to

```<code>!(model.CurrentStatus == DSRHelper.OrderStatusEnum.Complete || model.CurrentStatus == DSRHelper.OrderStatusEnum.Corrected)
</code>```

Title: Should I use AND or should I use OR

Body:
An order can be in the "status" of Completed, Corrected or some other status.

I saw some code that is checking it like this, the purpose is to disable some stuff when the status is in Completed or Corrected status.

```<code> if (model.CurrentStatus != DSRHelper.OrderStatusEnum.Complete && model.CurrentStatus != DSRHelper.OrderStatusEnum.Corrected)
</code>```

I can't get it why the engineer has used "AND" for this, shouldn't it be an "OR"?

Body:
No, AND appears to be correct here. If you switched it to OR, the condition would always be true. If it was Completed, then the second condition would be true. If it was Corrected, then the first would be true.

Keep in mind that the condition currently used is equivalent to

!(model.CurrentStatus == DSRHelper.OrderStatusEnum.Complete || model.CurrentStatus == DSRHelper.OrderStatusEnum.Corrected)


答:
If the condition used OR, the condition would always be true. In English, the current condition says "If the Current Status is not Complete and is not Corrected then..." implying that any state but those two will cause the condition to be true.

If you used OR, then absolutely any state would cause the condition to be true. If the current status is Complete, then the first half of the condition will be false, but the second half will be true, so the condition is true. If the current status is Corrected, the first half of the condition will be true so without even checking the second half, the entire condition is true (some languages or will still check the second half, but the condition will still be true if they do). If you use OR and the current status is neither Complete or Corrected then both halves of the condition are true. So OR will always be true.

Title: Should I use AND or should I use OR


问:
What makes a project big?
Just out of curiosity what's the difference between a small, medium and large size project? Is it measured by lines of code or complexity or what?

Im building a bartering system and so far have about 1000 lines of code for login/registration. Even though there's lots of LOC i wouldnt consider it a big project because its not that complex though this is my first project so im not sure. How is it measured?

答: A project's size is measured by the degree of unmaintainability.</p>

Title: What makes a project big?


答:
Technically, there are no problems in the field of computer science that cannot be solved without OOP. Object-oriented principles generally define the layout and architecture of source code; once the code is compiled into assembly language for consumption by the CPU, most of the patterns of OOP disappear.

However, since so many modern languages are designed to be object-oriented, a program written in such a language that doesn't make use of the built-in support for OOP may actually require more effort than simply building the program using the tools available. Managed-memory environments like the Java/Dalvik VM and .NET CLR typically use languages designed from the ground up to be O-O, and there's no way to escape it; at the very least, you need the object that contains the main() method (and any subroutines it calls).

As far as programs that require object-oriented architecture, I think the ones that come closest are event-driven GUI programs. The frameworks given by the GUI SDKs are object-oriented, and while I'm sure you can write a CLR program composed entirely of hooks into unmanaged Windows API code to create and display windows and react to the user's input in those windows, the overarching question I would pose faced with any such attempt is, "WHY!?", when the framework presents you with the objects representing all the GUI controls, each one handling the basics and most of the advanced usage scenarios in a neat, tidy package?

That's the strength of object-oriented programming; the "black-box concept". You don't have to care how anything is actually done; you simply care that it is done when you want it to. Why hook into a dozen Windows API functions and make hundreds of calls to display a window on the screen, when you can just call Form.Show()?

As far as convincing management that OOP is a good thing, the argument is all about time. OOP was designed to save the developer's time by increasing code reuse. General-purpose code-objects, which already exist so you don't have to rewrite them, are derived and combined into the specific solution to your particular programming problem. Those objects are also modular (if you follow the Gang of Four design patterns which encourage adherence to design principles like GRASP or SOLID), meaning if a piece of software has a problem (doesn't have to be a bug; programs get updated based on new requirements all the time, and the reason for a software update is a "problem", otherwise you wouldn't be updating the software), the line(s) of code responsible for the current behavior and which must change to exhibit the new behavior are easy to find, easy to change, and, if necessary, easier to replace wholesale than lines of procedural "spaghetti code".

In software development, time is money; there are few if any direct materials costs for a software solution (mostly start-up costs), so the primary driver of the cost of a piece of software is how many developer-hours it takes to create it. Following OOP, I guarantee you, will require fewer developer-hours for any non-trivial program than ignoring it.

Title: What kind of programs/solutions can only be written with OOP or are too hard to achieve without it?

Body:
Paraphrasing a recent question: https://softwareengineering.stackexchange.com/questions/52608/what-is-object-oriented-programming-ill-suited-for

I would like to ask the opposite question:

What kind of programs cannot be written unless you use OOP?

What kind of programs are not recommended to be written using non-OOP techniques?

What kind of programs need OOP in order to even be written?
What kind of programs would be too hard to write without OOP ?

The answer to this question can help sell the idea of OOP to project leaders that have no special interest in code quality. At least they could buy the idea if one shows them the kind of things that are not even possible unless you use OOP.


问:
Quickly compute added and removed lines
I'm trying to compare two text files. I want to compute how many lines were added and removed. Basically what git diff --stat is doing. Bonus points for not having to store the entire file contents in memory.

The approach I'm currently having in mind is:

read each line of the old file

compute a hash (probably MD5 or SHA-1) for each line

store the hashes in a set

do the same for each line in the new file

every hash from the old file set that's missing in the new file set was removed

every hash from the new file set that's missing in the old file set was added

I'll probably want to exclude empty and all white space lines. There is a small issue with duplicated lines. This can either be solved by additionally storing how often a hash appears or comparing the number of lines in the old and new file and adjust either the added or removed lines so that the numbers add up.

Do you see room for improvements or a better approach?

Edit

I'm currently using Java and the SVNKit library.

答:
There is a diffstat command (usually in the diffstat package in most Linux distros), that can help you achieve this:

```<code>svn diff | diffstat
</code>```

This outputs more or less the same as git diff --stat

If this is not an option for you, then maybe a good alternative is to parse the output of svn diff: count the lines starting with + and -, keep in mind that for each affected files there will be lines starting with +++ and ---.

Title: Quickly compute added and removed lines

Body:
There is a diffstat command (usually in the diffstat package in most Linux distros), that can help you achieve this:

svn diff | diffstat

This outputs more or less the same as git diff --stat

If this is not an option for you, then maybe a good alternative is to parse the output of svn diff: count the lines starting with + and -, keep in mind that for each affected files there will be lines starting with +++ and ---.


问:
Application of LGPL license on a simple algorithm
The "scope" of the GNU license is troubling me : I know it has been answered many times ( here, here, ... ) but shouldn't we take into consideration the complexity and originality of a code before using GPL license ?

I explain : I'm working on a pet project using the DTW algorithm that I have written in C using the pseudo-code given on the wikipedia page .

At one point I decided to change it for a C++ implementation ( just for hone my c++ skill ) . After doing so, I've looked for an existing implementation on the web, to compare the "cleanliness" of it, and I found this one : Vectored DTW implementation, which is part of limproved, a C++ library licensed under GPL v3 .

Personnally, I don't mind the GNU license because it is a personnal project, which will never led to any kind of commercial purpose, but I wonder if this implementation can abide a company using it to open their code ( and other FOSS permissions ).

Theoretically, I think it can ( I may be wrong :p ), but the algorithm in question is so simple (and old) that it should not.

答:
If I understand you.

You have implemented an algorithm after studying the source of an (L)GPL implementation ?

And your question is - is your own implementation now a derived work of that implementation - and so subject to the (L)GPL?

Basically it's a legal, rather than a licensing, question. Is your implementation the obvious simple way to do it - and so is the same as the GPL source simply because they also used the obvious simple way to do it.  Or do they have a clever, novel way of doing it which wasn't at all obvious to you until you saw their work?

Since it's in GPL code it is unlikely to be patented by the author (although the algorithm may have been patented by somebody else without them knowing). It remains their copyright - but that only covers the actual implementation, ie the exact choice of variables etc. Copyright doesn't normally cover the algorithm ( whatever the authors of Numerical Recipes claim).

The minimum you should probably do (for the good of your programming soul) is to understand the algorithm from their code, then put away their code and write your own from scratch.

If it's simple enough that you can just look at it and write it later from memory - then it's probably a trivial algorithm and that is the obvious way to do it. If you need to copy it directly from the source then it's probably a sufficiently novel invention that it deserves some protection.


问:
Difference between a socket and a port
Could someone please explain quite clearly the difference between a port and a socket. I know that a port serves as a door into the network for an application
process and that the application process uses a socket connection to the given port number to handle network communication but when you have multiple processes listening on a single port number, I am finding it difficult to understand the difference between the socket and the port and how they all fit together.</p>

答:
S is a server program: let's say it's an HTTP server, so it'll use the well-known port number for HTTP, which is 80. I run it on a host with IP address 10.0.0.4, so it will listen for connections on 10.0.0.4:80 (because that's where everyone will expect to find it).

Inside S, I'm going to create a socket and bind it to that address: now, the OS knows that connections coming into 10.0.0.4:80 should be routed to my S process via that particular socket.

netstat output once socket is bound:

```<code>$ netstat --tcp -lan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address            State
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN
</code>```

NB. the local address is all zeroes because S doesn't care how its clients reach it

Once S has this socket bound, it will accept connections - each time a new client connects, accept returns a new socket, which is specific to that client

netstat output once a connection is accepted:

```<code>$ netstat --tcp -lan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address            State
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN
tcp        0      0 10.0.0.4:80                 10.0.0.5:55715             ESTABLISHED
</code>```

10.0.0.4:80 represents S's end of the connection, and is associated with the socket returned by accept

10.0.0.5:55715 is the client's end of the connection, and is associated with the socket the client passed to connect. The client's port isn't used for anything except routing packets on this TCP connection to the right process: it's assigned randomly by the client's kernel from the ephemeral port range.

Now, S can happily go on accepting more client connections ... each one will get its own socket, each socket will be associated with a unique TCP connection, and each connection will have a unique remote address. S will track client state (if there is any) by associating it with the socket.

So, roughly:

the IP address is for routing between hosts on the network

the port is for routing to the correct socket on the host

I nearly said correct process, but it's actually possible to have multiple (usually child) processes all accepting on the same socket ...

however, each time one of the concurrent accept calls returns, it does so in only one process, each incoming connection's socket is unique to one instance of the server

the socket is the object a process uses to talk to the OS about a particular connection, much like a file descriptor

as mentioned in comments, there are plenty of other uses for sockets that don't use ports at all: for example socketpair creates a pair of sockets connected together that have no addressing scheme at all - the only way to use that pipe is by being the process which called socketpair, being a child of that process and inheriting one, or being explicitly passed one of the sockets from that process

Title: Difference between a socket and a port

Body:
S is a server program: let's say it's an HTTP server, so it'll use the well-known port number for HTTP, which is 80. I run it on a host with IP address 10.0.0.4, so it will listen for connections on 10.0.0.4:80 (because that's where everyone will expect to find it).

Inside S, I'm going to create a socket and bind it to that address: now, the OS knows that connections coming into 10.0.0.4:80 should be routed to my S process via that particular socket.

netstat output once socket is bound:

$ netstat --tcp -lan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address            State
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN

NB. the local address is all zeroes because S doesn't care how its clients reach it

Once S has this socket bound, it will accept connections - each time a new client connects, accept returns a new socket, which is specific to that client

netstat output once a connection is accepted:

$ netstat --tcp -lan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address            State
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN
tcp        0      0 10.0.0.4:80                 10.0.0.5:55715             ESTABLISHED

10.0.0.4:80 represents S's end of the connection, and is associated with the socket returned by accept

10.0.0.5:55715 is the client's end of the connection, and is associated with the socket the client passed to connect. The client's port isn't used for anything except routing packets on this TCP connection to the right process: it's assigned randomly by the client's kernel from the ephemeral port range.

Now, S can happily go on accepting more client connections ... each one will get its own socket, each socket will be associated with a unique TCP connection, and each connection will have a unique remote address. S will track client state (if there is any) by associating it with the socket.

So, roughly:

the IP address is for routing between hosts on the network

the port is for routing to the correct socket on the host

I nearly said correct process, but it's actually possible to have multiple (usually child) processes all accepting on the same socket ...

however, each time one of the concurrent accept calls returns, it does so in only one process, each incoming connection's socket is unique to one instance of the server

the socket is the object a process uses to talk to the OS about a particular connection, much like a file descriptor

as mentioned in comments, there are plenty of other uses for sockets that don't use ports at all: for example socketpair creates a pair of sockets connected together that have no addressing scheme at all - the only way to use that pipe is by being the process which called socketpair, being a child of that process and inheriting one, or being explicitly passed one of the sockets from that process

ContentLicense: CC BY-SA 4.0


答:
If it does not exceed the threshold of originality, it cannot be copyrighted. Thus, the GPL (or any other license) might not apply to simple or obvious pieces of code.

Whether a particular piece of code exceeds this threshold or not is up to the judges to decide. Personally, I don't think the "obvious" translation of some algorithm to some language X requires enough creativity to be copyrightable, but I'm not a lawyer, so my opinion does not count here.

Title: Application of LGPL license on a simple algorithm

Body:
The "scope" of the GNU license is troubling me : I know it has been answered many times ( here, here, ... ) but shouldn't we take into consideration the complexity and originality of a code before using GPL license ?

I explain : I'm working on a pet project using the DTW algorithm that I have written in C using the pseudo-code given on the wikipedia page .

At one point I decided to change it for a C++ implementation ( just for hone my c++ skill ) . After doing so, I've looked for an existing implementation on the web, to compare the "cleanliness" of it, and I found this one : Vectored DTW implementation, which is part of limproved, a C++ library licensed under GPL v3 .

Personnally, I don't mind the GNU license because it is a personnal project, which will never led to any kind of commercial purpose, but I wonder if this implementation can abide a company using it to open their code ( and other FOSS permissions ).

Theoretically, I think it can ( I may be wrong :p ), but the algorithm in question is so simple (and old) that it should not.


答:
What kind of programs cannot be written unless you use OOP?

Because of Turing completeness there are none.

What kind of programs are not recommended to be written using non-OOP techniques?
  What kind of programs need OOP in order to even be written? What kind of programs would be too hard to write without OOP ?

OOP is a good when you have "natural" objects: GUI buttons, files, sockets, locks, etc.  In pretty much every non OO language out there you see these opaque object wannabes called handles.

OOP is a mismatch when the design turns towards data transformation processes and doing things.  You get stuck in Yegge's Kingdom of Nouns.  Basically anytime you have a verb-able, or a verb-er you have strayed past the bounds of good taste in OO land.

That is why multi-paradigm languages are the way to go  OO isn't the best tool for every job nor is any other approach.  Not only that but there are relatively few applications that are single approach appropriate. So what we currently do is look at which approach is best for 70% of your app then shoe horn the other 30% into some horrible against the grain swamp monster of poor design.


答:
I don't know of a standard term for the point of diminishing returns on manpower; since the object is to convince people, try turning a phrase instead:

"limits of decomposability" might be especially relevant for a medium-sized project.

"communications overhead barrier" evokes the classic Brook's Law for large projects.

"the design iteration requirements" as a fancy way of saying "if you want something that isn't crap, it will take some amount time to do it halfway right."

Title: Diminishing Returns on Additional Developers

Body:
Is there a term to describe the point at which adding more developers to a software project will provide diminishing returns?

I realize that at a high level, it is more complicated that just a number of developers at which the project will be at productive capacity (ex/ state of the project, quality of the added developer), but I am trying to come up with a way to relate this to non-technical management through repetition. I'm basically looking for a term which invokes a strong mental image like "terminal velocity", except for Brook's Law.


答: "Adding manpower to a late software project makes it later. A man-month is a concept of a unit of work proportional to the number of people working multiplied by the time that they work; Brook's law says that this relation is a myth, and is hence the centerpiece of the book." - Source: Wiki-Mythical_Man_Month.


答:
Complexity.

The more complexity, the harder it is to learn everything in the project.

Title: What makes a project big?

Body:
Just out of curiosity what's the difference between a small, medium and large size project? Is it measured by lines of code or complexity or what?

Im building a bartering system and so far have about 1000 lines of code for login/registration. Even though there's lots of LOC i wouldnt consider it a big project because its not that complex though this is my first project so im not sure. How is it measured?


答: Your question includes the answer: the point of diminishing returns. This is the point where adding more resources costs more than the productive effect of these resources. That's a basic economic concept so your management is expected to know this by heart...</p>


问:
Are nested classes under-rated?
I'm not trying to say I know something everyone else doesn't but I've been solving more and more designs with the use of nested classes, so I'm curious to get a feeling for the acceptablilty of using this seemingly rarely used design mechanism.

This leads me to the question: am I going down an inherintly bad path for reasons I'll discover when they come back to bite me, or are nested classes maybe something that are underrated?

Here are two examples I just used them for: https://gist.github.com/3975581 - the first helped me keep tightly releated heirarchical things together, the second let me give access to protected members to workers...

答:
Consider for a moment that you're writing a class inside another class, that will never be used anywhere else in your program.  Because if you were using it elsewhere, you'd make it an ordinary public class, just like all the others.

So the thing that is supposed to make OOP great (reusability) is absent here.  Besides, what could you achieve with a nested class that you couldn't achieve with ordinary methods and private members within the parent class?

For a useful software pattern utilizing nested classes, look here.

Title: Are nested classes under-rated?


答:
I would not call this a "rarely used design mechanism" - at least, not universally: although there are shops where some contributors may frown upon using nested classes, this is not an obscure feature at all.

Although the existence of classes with assembly visibility and the introduction of lambdas has significantly reduced the need for nested classes*, they remain a valid design choice. Although there is some overlap with internal classes inside a namespace, the nested classes feature is unique in letting you hide a class entirely inside another class.

* The use of a similar feature in Java is much higher, because other alternatives available in C# are not there in Java.

Title: Are nested classes under-rated?

Body:
I'm not trying to say I know something everyone else doesn't but I've been solving more and more designs with the use of nested classes, so I'm curious to get a feeling for the acceptablilty of using this seemingly rarely used design mechanism.

This leads me to the question: am I going down an inherintly bad path for reasons I'll discover when they come back to bite me, or are nested classes maybe something that are underrated?

Here are two examples I just used them for: https://gist.github.com/3975581 - the first helped me keep tightly releated heirarchical things together, the second let me give access to protected members to workers...