答:
If you have enough licences, there is NO need to setup a Virtual machine and development environment in both machines. What you would need is a cloud repository like Git where you would sync your work. Btw, you may also set a private free repo with bitbucket.org.

However, if you have only one licence for development environment tools then you definitely need to set up your Virtual machine (btw, VirtualBox is a good choice), and use it in both machines that you have in mind. What will be left is just network configuration of Virtual machines, in order to get a connectivity to your cloud repository.

Title: Mirror virtualized development environment

Body:
I work alone in some iOS projects in a local environment.

I have been thinking in a way to be able to share my development environment between my Mac Mini and my MacBook. I mostly work at home in the Mini but sometimes I need to do a demo or work outside and I would like to have the development environment mirrored in both.

I have think in using a virtual machine (via VirtualBox) with just my development tools installed. Then I could synchronize that VM with some software between both computers so I will always have the exact environment no matter what computer I use.

Is there any good reason not do do this way? I have not used virtualization too much so I have no background on the subject.

¿What about licenses?¿Is there need to have duplicated licenses in both VMs?

This are my requirements:

-Don't need to setup two environments. Just setup one and have the job done in the other(installing or updating apps, change settings, etc).

-Don't depend on having a connection when working away from my home.

My basic setup will be:

Mac Mini: i7 dual Core, 8Gb. OSX Mountain Lion Host OS:

MacBook: 2.4 Core 2 Duo. 4Gb. OSX Lion Host OS.

Virtual Box with Mountain Lion guest OS in both machines.

XCode5, Simulator, Texwrangler, MAMP, etc.


问:
Isn't MVC anti OOP?
The main idea behind OOP is to unify data and behavior in a single entity - the object. In procedural programming there is data and separately algorithms modifying the data.

In the Model-View-Controller pattern the data and the logic/algorithms are placed in distinct entities, the model and the controller respectively. In an equivalent OOP approach shouldn't the model and the controller be placed in the same logical entity?

答:
I believe you're confusing persistent data bound to a model object with the application data from the databases the model interacts with. A model contains business logic and rules for working with databases and conducting transactions. It might set and check internal state flags like whether there's a sale today, whether the user qualifies for VIP status and then branch logic accordingly when it comes time to access, set, or manipulate data or conduct a purchase. It's those flags we're talking about when we discuss objects in terms of encapsulation of a set of methods and persistent values or data.

Just as the model object maintains data for establishing what business rules are in play, a controller should, IMO, hold on to more general application state data pertinent to how the app should behave, like whether the user is logged in or they have valid credit card data in place. Model methods would determine the state of these things in the first place but it makes sense for the controller to maintain flags pertinent to general app flow if they don't apply to how the business is run or data transactions are conducted. Once you've determined they're not logged in, don't even bother the model with user state checks until it's clear another log-in attempt is being made.

Likewise with a proper view object vs. the more typical HTML templates you see in most server-side web frameworks. Once the user's color preferences are loaded up, it should be the view that holds on to that data and executes on it. Loading, validating and changing settings are all model problems but they should only be model problems once until changes happen.

IMO, nothing says controllers can't be composite objects with views and models as internal aggregate objects. This actually makes sense if you apply MVC on a smaller scale like a UI widget factory since the controller is the ideal place to expose an interface to higher level app objects while burying the data and logic details of how the View and Model interact. It doesn't really make sense for monolothic app objects where the controller is really the highest level object though.

ContentLicense: CC BY-SA 3.0

Title: Isn't MVC anti OOP?


问:
Convert plain text to a pdf template
I have some articles (more than 200 pages) in plain text. It needs to be converted to an given PDF markup. I got some Photoshop files for the headers for every page and a list of requirements for the different elements.

Which program would you use? And what would be your workflow?

答:
I don't think you would need a workflow.

There is already a very reliable tool to assist you with this task. Just look at this amazing ABCpdf tool. We have used it in three projects so far, and have no complains.

Title: Convert plain text to a pdf template


问:
Java default Integer value is int
My code looks like this

```<code>import java.util.Scanner;

public class StudentGrades {

public static void main(String[] argv)
{
    Scanner keyboard = new Scanner(System.in);
    byte q1 = keyboard.nextByte() * 10;
}
}
</code>```

It gives me an error Type mismatch: cannot convert from int to byte.

Why would Java store a literal operand that is small enough to fit in a byte, into an int type? Do literals get stored in variables/registers before the ALU performs arithmetic operations?

答:
The problem is the line byte q1 = keyboard.nextByte() * 10;. There are no arithmetic operations on byte or short. The value of keyboard.nextByte() is casted up to an int prior to multiplication with 10, which is also an int. The result of the multiplication is an int, which can not be stored into q1 if it's defined as a byte.

Possible solutions would be to cast the result of the multiplication to a byte using (byte) (keyboard.nextByte() * 10) or by changing the type of q1 to int.

Unfortunately, I'm not finding a reference to this in the tutorials. However, you can find an explanation in the Java Language Specification. Sections 5.6.2 Binary Numeric Promotion and 15.18.2 Additive Operators (+ and -) for Numeric Types define this behavior.

Title: Java default Integer value is int


答:
I am late to this party, and considering all the answers before mine, I admit I don't have much new to offer. But it seems to me that the question isn't about the pattern itself but about the implementation. MVC in and of itself does not lend itself to any particular methodology. In fact, I can easily envision procedure oriented code in an MVC pattern (which is what I felt like you were implying).

So, I think the real question is; are we more prone to procedural code when using the MVC pattern.

(and maybe I'll just get some down votes?)

Title: Isn't MVC anti OOP?

Body:
The main idea behind OOP is to unify data and behavior in a single entity - the object. In procedural programming there is data and separately algorithms modifying the data.

In the Model-View-Controller pattern the data and the logic/algorithms are placed in distinct entities, the model and the controller respectively. In an equivalent OOP approach shouldn't the model and the controller be placed in the same logical entity?


问:
How do programming languages benefit from being based on English?
I think the world now programs in English-based programming languages not only because of historical/economic circumstances, but because the English morphology in particular has some properties that suit algorithmic thinking best. But anyway it would be interesting to hear your opinions on this, especially if you are multilingual yourself.

I've seen some mentioning of German-based languages (see Plankalkul for example, in fact the first ever programming language we know very little about, thanks to WW2), also a Russian-based flavor of Algol which existed back in the 80's at least on paper, not sure if it ever existed in binary or not. Both looked a bit sluggish because there were more shortened words and weird abbreviations than full words like in the EN-based languages. So if you know of any other national language-based PL's, even completely archaic and irrelevant today, purely theoretical or whatever, would be interesting to take a look at them.

And back to the main question: so what, if any, makes the Shakespeare's language so good for programming?

(There is actually a list of Non-English-based programming languages on Wikipedia (of course, where else?), but it would be interesting to hear opinions of native speakers of those languages on how a given "national" programming languages really feels like.)

答:
In my opinion, English simply has a richer technical and mathematical vocabulary than many (but not all) other languages.  The languages that lack such vocabulary use English loan words to get the job done.  This alone is a compelling reason to orient programming languages toward English.

Regarding the languages that do have a sufficiently rich vocabulary to describe everything we need to describe without resorting constantly to English loan words, the tradition of English as the lingua franca (common tongue) for the sciences is in itself compelling, but our alphabet gives us another little leg up:

English can be represented in a smaller character set than, for example, Chinese, Japanese, Cyrillic, or even Romance languages that use accented Latin characters.

The English alphabet, largely due to its complete lack of accented characters, is very visually clear.  We have enough bugs due to mismatched brackets or missing semicolons, it would be foolish to add problems discerning between 'ē', 'ĕ', and 'ě'.

ContentLicense: CC BY-SA 2.5


问:
How would I use a browser as a GUI for Emacs apps?
I've started using Emacs, and love it. Naturally, I'm thinking about ways of extending it. I' m particularly fascinated by the thought of creating browser based GUIs for some stuff I would otherwise do in emacs, particularly reviewing fairly static data.

An example: I have a bunch of txt files (created and edited in Emacs) containing quotes and passages from my favorite books. It would be cool to present them in a more visually striking/engaging manner. For example with unique color schemes and typefaces for different authors, and several columns of text to use more screen real estate (like in Stanza, the .epub reader).

Are there simpler ways of rendering HTML derived from plain text files that are open in Emacs than browsers?

答: Perhaps Markdown or other such wiki-like markup languages would be useful.  Emacs could display those in visually pleasing manners.</p>


问:
Is there a way to publish IOS app from windows/Linux?
I have been using Linux (especially, Ubuntu) and Windows 7 for a long time.  I want to publish iOS apps, but I don't have a Mac or an iPhone.  I don't have anyone near me who will lend me a Mac, and I don't actually want to buy them either.

So my question is: how do I publish my iOS app from Windows or Linux? I am not referring to publishing programs for jailbroken iPhones, I want to publish through the Apple Store.

My search results indicate that there is no fool-proof way of publishing an iOS app from Windows or Linux. I also want to make it a paid app, and not give it away for free.

Does anyone know of a way to publish iOS apps from Windows or Linux?

答:
You might have to look at the tools you are utilising for the iOS development, there are platform independent tools like Microstrategy  mobile platform which simplifies the mobile app development and a single source can be used for multiple devices so have a look at it.

http://www.microstrategy.com/mobile/


问:
Hiring Developers - any tips on being more efficient?
I represent a software company that is in process of building a large software development team. We are picky in who we hire and have really good retention rate (most of the devs have been here for an average of 5-6 years).

We've been spending a lot of developers' and HR time and have a low applications to hire ratio. Here's the process we use:

HR Interview on phone - Involves asking basic behavioral and tech questions

Online test - Involves a 30 minute technical test

Technical Phone interview - A 60 minute interview by a developer

Onsite Interview - A 60-90 minute interview by several senior developers

Although this process has been working, we've been spending way too much time on interviews. Any thoughts on how this can be done differently? Our goal is to automate any tasks if possible still retaining the quality of talent.

UPDATE:
Thanks for the responses. Need to clarify a few things. Our aim is to reduce the number of applicants that go from one stage to the other. Here's our current numbers.

We receive 1000 resumes

800 resumes pass the HR interview

500 pass the online test

100 pass the initial phone screen

10 pass the onsite and get hired

As you can see, we need to do a better job of weeding out the candidates earlier on in the process. Can we do a better job in the way the online test evaluates people?

Here are more details on the process based on some responses:

HR Interview on phone - They ask very basic technical questions (What is a CLR?) to weed out as many people as possible

Online test - Have around 10 basic questions with 3 coding questions

Tech phone screen - Covers a variety of technologies. We don't care if the applicant doesn't know everything as long as they can demonstrate they will be able to pick up new technologies and come up to speed quickly

Onsite - Coding questions in front of the developers. More architectural level questions.

答: This is one situation where you don't want to be more efficient than you already are.  There are already too many applicant's who can't pass FizzBuzz.  Your current filtering process looks like it ensures developer quality.  You'd end up wasting even more time down the line if you eliminated any of the steps you're taking so far.</p>


答:
Sounds like a successful candidate takes about three to four hours.  I would not try to reduce that overall time.  If anything, I might add more time for the onsite interview to give plenty of time for the really great candidates to show their worth definitively, and decide if what you offer is interesting to them long term.  With your low turnover, you must be doing something right.

The low ROI in your process could be the first three steps.  Perhaps you can screen resumes more strictly or look for yet higher scores from the online test.  The phone technical screen might be a target for optimization if you set it to be 30 minutes, but allowed superior candidates to extend to 45 or 60 minutes.

If it is any consolation, I think the distraction and time cost, while a drag on project work, is some of the most valuable time you can spend.  Consider the costs and problems that come from hiring mistakes, and the great gains to the team and company when a good hire is made.

If you are taking point, working with almost all your candidates, you are something of a sacrificial lamb.  However, the global effect of the work you are doing has great value.   You should embrace the role and milk it for all the good will you can get among the new hires.  If the process goes well, your management will value your judgment about other things as well.

Title: Hiring Developers - any tips on being more efficient?

Body:
I represent a software company that is in process of building a large software development team. We are picky in who we hire and have really good retention rate (most of the devs have been here for an average of 5-6 years).

We've been spending a lot of developers' and HR time and have a low applications to hire ratio. Here's the process we use:

HR Interview on phone - Involves asking basic behavioral and tech questions

Online test - Involves a 30 minute technical test

Technical Phone interview - A 60 minute interview by a developer

Onsite Interview - A 60-90 minute interview by several senior developers

Although this process has been working, we've been spending way too much time on interviews. Any thoughts on how this can be done differently? Our goal is to automate any tasks if possible still retaining the quality of talent.

UPDATE:
Thanks for the responses. Need to clarify a few things. Our aim is to reduce the number of applicants that go from one stage to the other. Here's our current numbers.

We receive 1000 resumes

800 resumes pass the HR interview

500 pass the online test

100 pass the initial phone screen

10 pass the onsite and get hired

As you can see, we need to do a better job of weeding out the candidates earlier on in the process. Can we do a better job in the way the online test evaluates people?

Here are more details on the process based on some responses:

HR Interview on phone - They ask very basic technical questions (What is a CLR?) to weed out as many people as possible

Online test - Have around 10 basic questions with 3 coding questions

Tech phone screen - Covers a variety of technologies. We don't care if the applicant doesn't know everything as long as they can demonstrate they will be able to pick up new technologies and come up to speed quickly

Onsite - Coding questions in front of the developers. More architectural level questions.


答:
As I read it your system is working, and you are more than happy with the outcomes. Your teams are working well, are productive and everyone is happy. The only issue is you believe it is costing too much.

Consider the alternative - you  reduce the overhead of recruiting staff (though whatever method). As a result tenure drops from 6 years to 3. If you have spent 1/2 the time for each recruitment, then you have spent the same in total in recruitment alone. Now look at the cost of turnover - unlike manual labor (fence painting is a good example), it takes significant time to come up to speed, say 3- 6 months. So that means your recruitment savings have to recover 3 -6 months of wages, costs and lost profits for the business (call it 2.5* wages)
Now factor the disruption to the team, and the risk a new recruit has to team dynamics.

All in all - a recruitment on average will cost you 3-6 months salary. How much are you spending to fill a position - a week or two is my guess.

Way to reduce it: All I can see is the interview times - are you terminating them or padding them out once you have decided the candidate is a No (or a Yes)? If you have decided to make him an offer after the first 5 minutes- make the offer. If you need 90 to decide not to make an offer, ask why it took 90 to get to No (i.e. what did he do to blow it in the last 60 seconds).

Recruitment is at best a crap shoot - it seems you have successfully loaded the dice in your favor, I would be tempted to keep it that way......


答:
Have you thought of working with a recruiting agency to try and find people? You could sit down with an agency and tell them your process and what you're looking for in an applicant. They can then spend the time looking at the many resumes, doing the general technical test and administering the online test. Then, they pass the good applicants onto you for the phone and in person interview.

I have worked with a recruiting agency in the past as a developer looking for a job. I had to go through a long interview process to be in their pool, and then when potential jobs came up I had to do initial steps and if my code/answers were good, I got to meet the actual company.

I'm sure it cuts a lot of overhead out from your team, but there would be a cost. I have heard it can be a percentage of the employee's salary. So if you are offering 65k/year, you might offer them 60k and then pay the company 5k.


问:
Forced to write Stored Procedures
Can you think of some reasons that the management force the developers to write and call Stored Procedures instead of inline SQL statements directly?

Even a very simple CRUD statement, writing a stored procedure takes more time and create extra workload.

答:
Well, because you'd like to keep your job is always a pretty good reason. If that's the company's/team's/management's standard, it's your job to conform to it.

The Stored Procedure vs. Client Side query argument is quite old at this point and there enough pluses and minuses for each that it's a matter of preference as it fits in your technology ecosystem.

Now, to be fair, with the spotlight on ORMs lately, auto-generated client-side queries are vindicated against some of the criticism of days past.

My own personal opinion: easier to QA and deploy sproc fixes than compiled code.

Title: Forced to write Stored Procedures


问:
ASP.NET Webforms developers and web designers: how to interact?
I'm an ASP.NET Webforms developer, and I face some problems when I deal with designers.

Designers always complain about the asp.net server controls. They'd rather just have an html file and create css files along with the required images to go with those. Sometimes, if the design phase is done in advance, I get html files with related css files, but then we face many problems integrating the design with the aspx files (sever controls an telerik controls ... etc).

What I want to ask about is:

How do I overcome these problems? The designers prefer php- and mvc developers because of the problems with .net server controls. I need to know how to interact with the designers in the correct way.

Are there any tools or applications to provide the designers with the rendered (html
page) of the .aspx pages? By that I mean the page in runtime rather than the aspx in Visual Studio. They do use Web Expression but they want the rendered page in html as well.

答:
At my last job, the devs would build the application and then would pass it to the designers so that they could make it look like a bunch of software programmers didn't make it. :)

When we first started this process, there were a lot of back and forth between the devs and designers. They didn't understand the pages that they were given. Heaven forbid if we were building a page dynamically! It was much the same as the situation you are describing here.

I sat down with each designer and taught them how to install the web application on their local box. I showed them how to run it and everything. I explained to how the asp controls were rendered on the screen. And then we opened it up in the browser and used firebug to see the link between the asp controls and what was rendered.

This helped them, a lot. Once they could see it and run it on their boxes and use their design tools to tweak and play with styles, it made their lives easier.

After I did this, I had a meeting with the developers and let them know that they should be using the CssClass tag and making sure that styles were being defined. And anything that was being put on the screen dynamically need to have a css class attached to it b/c the designers wouldn't be able to add it.

It was a process. It took some time for both sides to get use to the arrangement. But it opened the lines of communication. Instead of complaining about the controls used, the designers were able to request styles be added to various elements.

So my suggestion would be to sit down with the designers and show them how the page renders. Use firebug to dissect the page and go through how the page if formed.


答:
One of the reasons might be due to the fact that old habits die hard.

In older databases, stored procedures used to usually perform better due to caching of the query plan for stored procedures in comparision to ad-hoc queries which did not usually get cached. A lot of newer (i mean databases in the last 5 - 6 years) versions of databases do provide caching of queries too - alleviating this drawback to a very large extent

Another possible use for SP's could be optimization. When you have SP's for every query, it is possible for DBA's to tweak the queries if needed to improve performance. If the queries lie in the code, the DBA cannot really optimize the queries themselves. Whether or not it was a good practice for DBA's to be doing such optimization is a very subjective thing but i have worked at companies where it worked very well.

Theres probably a lot more pros vs cons to this but these 2 throw some light on why it used to be mandated in the past.

As long as your current way of working alleviates the reason behind these points, then you can always point it out to your mgmt and ask them to relook at their standards..

Though, to be very honest, i wouldnt go with the argument of "It takes more time and effort". In my opinion, it only takes a negligible amount of effort to write Create Package .... and you could just write a small script or tool to take your query and convert it to a procedure. point here is that your argument of time / effort seem at best to be a thin one.

Title: Forced to write Stored Procedures

Body:
Can you think of some reasons that the management force the developers to write and call Stored Procedures instead of inline SQL statements directly?

Even a very simple CRUD statement, writing a stored procedure takes more time and create extra workload.


问:
How/where to run the algorithm on large dataset?
I would like to run the PageRank algorithm on graph with 4 000 000 nodes and around 45 000 000 edges.

Currently I use neo4j graph databse and classic relational database (postgres) and for software projects I mostly use C# and Java.

Does anyone know what would be the best way to perform a PageRank computation on such graph? Is there any way to modify the PageRank algorithm in order to run it at home computer or server (48GB RAM) or is there any useful cloud service to push the data along the algorithm and retrieve the results?

At this stage the project is at the research stage so in case of using cloud service if possible, would like to use such provider that doesn't require much administration and service setup, but instead focus just on running the algorith once and get the results without much overhead administration work.

答:
You can use some kind of clustering technique (eg MapReduce), but with this small size of data, you absolutely don't need to use clustering.

With this size of data, you should be able to do it all in memory. Assuming a naive approach:

15 mb - Scores from the previous iteration (4,000,000 32 bit floats)

15 mb - Scores from the next iteration  (4,000,000 32 bit floats)

190 mb - Web Graph, assuming a naive graph structure of {num outlinks, outlink 1, outlink 2, ... outlink n} made of 32 bit ints, the graph would fit in 45,000,000 * 32 bits + 4,000,000 * 32 bits,

About 250 mb. The naive approach would look something like this:

```<code> N <- size of graph
 c <- dampening factor

 source_scores[N] <- array of floats, initalised to 1 / N.
 dest_scores[N] <- array of floats

 repeat until convergence {
    for all n up to N { dest_scores[n] = 0 }

    for all source,dest links {
        dest_scores[dest] += source_scores[source] / num_outlinks of source
    }

    for all n up to N {
        dest_scores[n] = c * dest_scores[n] + (1 - c)/N
    }

    copy dest_scores to source_scores
 }
</code>```

"But I also have this other graph that WONT fit in memory!"

For in-memory pagerank computation on any size graph, check out this paper. It describes a multi-pass (per single pagerank iteration) technique that allows you to complete pagerank in memory, assuming stream access to the graph and scores from previous iterations.

It requires that you hold the current scores in memory. With 4,000,000 nodes, and assuming 32 bit floats, you're looking at about 15 megabytes of data, plus any array overhead. Your 48 gig server will be fine for this (and it will also be fine for the naive approach, see below).

You'll want a nice small representation of the graph that allows you to read it in in a stream. Since you're using Java, check out the WebGraph compression framework. It is described in detail in this paper. For a graph of 118,000,000 nodes and 1,000,000,000 links they quote a compression of 3.08 bits per link, which is amazing.

Note that there's also a C++ implementation of the WebGraph compression framework also available at that link, but it is MUCH SLOWER, mostly because it's a word for word port of the Java code, rather than a C++ implementation of the compression algorithm.

Using this approach, I had Java code for pagerank that achieved convergence in just under an hour on a single 2007-era desktop with 2 gig of ram, over an 80,000,000 node web graph. The C++ code for the same ran in about two hours (due to the speed differences in the compression implementation).

Let me know if you need any help.

Body:
You can use some kind of clustering technique (eg MapReduce), but with this small size of data, you absolutely don't need to use clustering.

With this size of data, you should be able to do it all in memory. Assuming a naive approach:

15 mb - Scores from the previous iteration (4,000,000 32 bit floats)

15 mb - Scores from the next iteration  (4,000,000 32 bit floats)

190 mb - Web Graph, assuming a naive graph structure of {num outlinks, outlink 1, outlink 2, ... outlink n} made of 32 bit ints, the graph would fit in 45,000,000 * 32 bits + 4,000,000 * 32 bits,

About 250 mb. The naive approach would look something like this:

 N <- size of graph
 c <- dampening factor

 source_scores[N] <- array of floats, initalised to 1 / N.
 dest_scores[N] <- array of floats

 repeat until convergence {
    for all n up to N { dest_scores[n] = 0 }

    for all source,dest links {
        dest_scores[dest] += source_scores[source] / num_outlinks of source
    }

    for all n up to N {
        dest_scores[n] = c * dest_scores[n] + (1 - c)/N
    }

    copy dest_scores to source_scores
 }

"But I also have this other graph that WONT fit in memory!"

For in-memory pagerank computation on any size graph, check out this paper. It describes a multi-pass (per single pagerank iteration) technique that allows you to complete pagerank in memory, assuming stream access to the graph and scores from previous iterations.

It requires that you hold the current scores in memory. With 4,000,000 nodes, and assuming 32 bit floats, you're looking at about 15 megabytes of data, plus any array overhead. Your 48 gig server will be fine for this (and it will also be fine for the naive approach, see below).

You'll want a nice small representation of the graph that allows you to read it in in a stream. Since you're using Java, check out the WebGraph compression framework. It is described in detail in this paper. For a graph of 118,000,000 nodes and 1,000,000,000 links they quote a compression of 3.08 bits per link, which is amazing.

Note that there's also a C++ implementation of the WebGraph compression framework also available at that link, but it is MUCH SLOWER, mostly because it's a word for word port of the Java code, rather than a C++ implementation of the compression algorithm.

Using this approach, I had Java code for pagerank that achieved convergence in just under an hour on a single 2007-era desktop with 2 gig of ram, over an 80,000,000 node web graph. The C++ code for the same ran in about two hours (due to the speed differences in the compression implementation).

Let me know if you need any help.


答:
I think there are a few places you're wasting time.

Drop the HR interview beyond just a simple first contact to setup follow-up interviews. Having HR people ask technical questions is a waste of time. For example, I had one ask me some unclear question about MVC and they couldn't clarify what was being asked.

Drop the online test, especially if you're hiring mid to senior level developers. It wastes their time plus your time and money. Also, some developers simply don't do well on this kind of test.

While a phone interview is good, it shouldn't require a full hour. Often 5-10 minutes is enough to determine if a person is a good fit or not. 30 minutes should be the most you'll need to determine if a face-to-face is warranted.

The face-to-face interview will be the most important. Just don't waste it on BS like HR personality tests, standardized online tests and the like. Take the time to get to know the person and see if they'll fit into your team. Ask good questions related to the work you expect them to do, not trick questions, not mind puzzles you heard they ask at Google/Microsoft/Apple/etc or obscure trivia.

You might also go through a recruiting firm that does contract-to-hire. Many of them will have done the preliminary screening and testing and, in some cases, will have worked with the person before. That way you can hire the best candidate(s) and determine if they're a good fit while their doing actual work for you. If things don't work out for whatever reason, let them go. If they're a good fit, keep them around as permanent employees.

Edit based on updated info...

If your HR is only screening out 200 out of 1000 the problem could lie there.

Your help wanted ad may be too generic and encouraging a lot of people to apply who would otherwise screen themselves out. You may want to target your ad better but don't over-target it.

With that many resumes, HR may do better outsourcing this phase to a pre-screening agency to narrow things down a bit, through the use of automation and/or pre-screen interviews and background checks. This could include an actual initial tech interview given by a real programmer. It might also include an online test but this will be of the tricks and trivia variety.

Like I said, I don't think you're getting a lot of value out of the HR and online test screens. I'd suggest rethinking these and you'll find that your numbers in the other phases will be more reasonable.


问:
Is it the job of a developer to suggest IT requirements?
I am the only developer working on a web application which is nearing to its end. Now we are looking into making it Live in maybe a couple of months time.

This is a web application for a non IT company. Though they have their own internal IT team, they have asked me on what will be the hardware requirements for the live servers eg. RAM, 32 bit or 64 bit.

Shouldn't the internal IT team be doing this or since I am the only person working on the project is it my resposiblity to let them know of the any specific hardware requirements which may impact the performance of the project?

The reason I am asking this question is that, I have not done this before. All the times I used to be given a server and asked to deploy apps on it. I never used to worry about the server configuration, etc.

答:
Though they have their own internal IT team, they have asked me on
  what will be the hardware requirements for the live servers eg. RAM,
  32 bit or 64 bit.

Hardware requirements don't mean anything.

While you, as a developer, may be thinking in these terms, be wary that nobody on the business end will actually care what answers you give to these questions. What will matter is how the web application performs. Based on this question, I suspect you do not have performance requirements (such as requests per second and average load time for a page). You should provide technical guidance in developing the answers to these questions before you worry about hardware requirements.

Ideally you should not have to do this alone: You, a business analyst, someone from IT who knows the cost of a server and the project manager should define the performance requirements and their impact on the scope/schedule/budget. Once that's agreed you and IT can work together to figure out exactly what that means, but there's a good chance you'll want to do some optimization on your end in addition to throwing hardware at it.

Even if you do have to do it by yourself, I recommend documenting your performance requirements in measurable terms that aren't arbitrary descriptions of hardware – this will also give you leeway to go back to IT later and ask for more if the application isn't performing up to snuff.


答:
The English language is favorable because:

Better fits the restrictions of current peripherals.

Ease of type. You can use a standard keyboard. I know this sounds like "llama dung", but have you tried typing in Chinese? There are 1000s of characters and since Chinese doesn't have an adequate "character" building technique to fit the concept of a keyboard, it wouldn't be easy to learn for a global audience.

Can be morphed into non-words that are equally recognizable. English favors abbreviations due to the lack of accent symbols.

Shortened English words are recognizable symbols. One doesn't have to learn the entire English language to code, thus people external to the language can learn fast.

And consider that common programming languages feature more mathematical symbols and less words.

Assembly used small words that had no sentence structure. Then came languages, like COBOL and FORTRAN, which attempted to accommodate the English sentence structure as much as possible. Newer languages implemented more reliance on universal algebraic symbols, because they had better predictability. (In COBOL Add X To Y, Subtract Y From X, Compute Y = X + A; Compute makes the previous statements unnecessary and reduces language parsing complexity). It wouldn't take much more for me to consider languages like C++ to be more symbolic than language based. There's a little bit of a return to word based programming with C#, but that's mostly to have baked in support for popular programming patterns.

Conclusion:

Ultimately, the peripherals limit to a character based language (like English). Also, western languages have better support for mathematical concepts (like the concept of 0, among others; China borrows numerals in lieu of their own representation of numeric values, to better convey numbers, because it's shorter to write (on average)). Other than numerical values, I would see symbol based languages (Chinese) as better suited to programming language morphology than English, as most of the modern languages already use symbols, and it would be universally equivalent to learn. However, we'd have to impose C++ like structure, having blocks of symbols would not be easy to read for most people in the world.

Title: How do programming languages benefit from being based on English?

Body:
I think the world now programs in English-based programming languages not only because of historical/economic circumstances, but because the English morphology in particular has some properties that suit algorithmic thinking best. But anyway it would be interesting to hear your opinions on this, especially if you are multilingual yourself.

I've seen some mentioning of German-based languages (see Plankalkul for example, in fact the first ever programming language we know very little about, thanks to WW2), also a Russian-based flavor of Algol which existed back in the 80's at least on paper, not sure if it ever existed in binary or not. Both looked a bit sluggish because there were more shortened words and weird abbreviations than full words like in the EN-based languages. So if you know of any other national language-based PL's, even completely archaic and irrelevant today, purely theoretical or whatever, would be interesting to take a look at them.

And back to the main question: so what, if any, makes the Shakespeare's language so good for programming?

(There is actually a list of Non-English-based programming languages on Wikipedia (of course, where else?), but it would be interesting to hear opinions of native speakers of those languages on how a given "national" programming languages really feels like.)


问:
why getMonth() starts with 0
I was coding a function to remove a day from a date value in javascript and i was kind of surprise that javascript's getMonth() starts from 0 for January to 11 for December. Why javascript's  getMonth() starts with 0?</p>

答: If one element in a struct starts with 0 then all elements should start with it too or none of them. I discovered that behaviour on my site a bit late.</p>

Title: why getMonth() starts with 0


问:
Any good resource on running a service software company?
A service software company is like an outsource company.
You give us the requirements, we band the result for you.

This is a unique situation where each project is short lived and vastly different from one to another.

I'm interested to learn if anybody is successful in running this kind of company and any good resource of setups like this.

Thank you!

答:
You have to provide some benefit. Most software development firms are fully capable of doing their own project management, so your value strictly as a middle-man is not particularly obvious to the client.

Instead, you need to fill some hole that isn't already being filled. Here are some things that will help you stand out and provide benefit:

Provide a local in-person presence to the client

This is by far and away the single most important and powerful thing you can do. There are tens of thousands of organizations on the Internet trying to do the exact same thing as you, and the probability is that half of them (if not more) are better at it than you are. What they aren't is local. By meeting in-person and face-to-face with the client, discussing their concerns, listening to their stories, responding to their questions, and most importantly giving them a tangible sense that you exist, you provide for a large percentage of clients a value-add that is worth, from my experience, up to around 50% of the project cost. The value of this is a personality thing that depends on the client's own disposition. So it doesn't always make a difference. But for those that need it, it's a huge difference.

Provide a guarantee

Outsourcing is risky. There's a very good chance that they'll put out tens of thousands of dollars and be left with nothing of value at all. By taking on some (or all) of that risk, you can help justify your cost. Part of your job is to sort through the mountains of contractors and find the good ones. Your field experience can help decrease your own personal risk allowing you to offer a better deal to the client than he'd otherwise get. Our firm offers a solid and unconditional "satisfied or you don't pay" guarantee. This has gained us much more than it's lost us. On risky jobs we may double-book development and build a backup solution at the same time just to be safe. On the surface that sounds expensive, but the certainty is part of our product.

Translate into tech-ese

Even if developers ostensibly speak the same language as the client, they rarely understand eachother. Part of your job, a large part of your job, is to speak to the client in terms the client understands, and speak to the developer in terms the developer understands. You need to find out what the client actually wants, and get that built, even if he can't articulate it. Developers work best with a black-and-white specification that leaves nothing implied. Clients typically lack the background knowledge to produce such a thing. That's your job.


答:
There is something like a de-facto standard for running IT service companies - ITIL. It is a collection of good practices for many aspects of IT service delivery - administrative organization, dealing with requirements and customer requests. I am sure you will find a ton of useful advice in those books.

It is compiled from experiences of successful service providers and kept up-to-date.

Title: Any good resource on running a service software company?

Body:
A service software company is like an outsource company.
You give us the requirements, we band the result for you.

This is a unique situation where each project is short lived and vastly different from one to another.

I'm interested to learn if anybody is successful in running this kind of company and any good resource of setups like this.

Thank you!


答:
We generally ask them to bring and explain some code that they wrote and are particularly proud of, preferably from an open-source project.

"Wait," you say, "Doesn't this bias you toward people who write software in their spare time?"

Yes. Yes it does. That's kind of the point.


问:
How should I create lo-fi (non-interactive) UI prototypes?
I'm currently working on throwing together some basic prototypes, partly to gather requirements and partly to design the final UI.

At the moment I'm trying building up the screen using Post-it notes, with yellow notes for information and pink for actions (buttons or menus). The idea being that you can easily move, remove and add information. But I'm sure there are more efficient methods out there.

What is the recommended way for developers to efficiently create non-interactive UI prototypes?

And why?

I tried some pen, paper and Post-it note versions and they went down like a lead balloon (likely my drawing skills). In the end I used Balsamiq, which thus far is liked by most users and they get it is prototype. Alas, some people are still having problems with the idea that first one should get an idea of what the application should do via some lo-fi prototypes and really want to "see something on the screen" before committing to anything.

答: Pen & paper / whiteboard, and you can also use Visio or something similar (Visio comes with UI templates for common controls).  Sometimes I take shots of existing (similar) UI that we have and cut and paste the new UI onto it using a paint program like Paint.NET.</p>


问:
What are algorithmic paradigms?
We generally talk about paradigms of programming as functional, procedural, object oriented, imperative etc but what should I reply when I am asked the paradigms of algorithms?

For example are Travelling Salesman Problem, Dijkstra Shortest Path Algorithm, Euclid GCD Algorithm, Binary search, Kruskal's Minimum Spanning Tree, Tower of Hanoi algorithmic paradigms? Or perhaps the paradigms are the data structures I would use to design these algorithms?

答:
Algorithmic paradigms are:

General approaches to the construction of efficient solutions to problems

Any basic, commonly used approach in designing algorithms could be considered an algorithmic paradigm:

Divide and Conquer

Idea: Divide problem instance into smaller sub-instances of the same problem, solve these recursively, and then put solutions together to a solution of the given instance.

Examples: Mergesort, Quicksort, Strassen’s algorithm, FFT.

Greedy Algorithms

Idea: Find solution by always making the choice that looks optimal at the moment — don’t look ahead, never go back.

Examples: Prim’s algorithm, Kruskal’s algorithm.

Dynamic Programming

Idea: Turn recursion upside down.

Example: Floyd-Warshall algorithm for the all pairs shortest path problem.

The word paradigm does translate to example, but that's not how it's used in a scientific context. Your examples are all examples of algorithms (except the travelling salesman problem, which is a NP-hard problem), none of which is trivial enough to be considered an algorithmic paradigm.

Title: What are algorithmic paradigms?


问:
Why does Eclipse need to be restarted after installing a plugin?
As Eclipse uses OSGi to handle modules and bundles, and therefore should be able to hot-deploy them, why does it suggest to restart after installing a plugin "for changes to take effect"?

Has Eclipse hit some OSGi limitation, or is its architecture such that even with hot-deploy, it cannot guarantee that deployments went smoothly and hence takes the safest route by offering a restart?

答:
The unfortunate reality is that once you have sufficiently interconnected modules, it is almost impossible to prove that all references to modules that you wish to unload will be removed in any circumstance.  Many libraries and even core JDK classes will hold references to objects or classes for long periods of time, or even forever, and even a single stray reference will prevent the ClassLoader that loaded a module from being garbage collected.

Such problems are very tedious to solve, hard to detect automatically, and are very easy to reintroduce.

This problem rears its ugly head also with redeployment of WARs in servlet containers such as Jetty or Tomcat.

Many developers choose a more pragmatic route and spend time developing new features and fixing bugs rather than ensuring that hot loading and unloading of code works 100% correctly.  So Eclipse recommends that you restart whenever you reconfigure its plugins, since it cannot guarantee that all plugins that you download will hot load or unload correctly.


答:
Rather than asking is our process wrong you should first ask are we failing to attract the best people available out there. Most organizations fail to promote themselves and the job prior to receiving any applications. I reckon is it also a mistake to have HR involvement at the first point of contact. There is a fundamental schism between the personality types employed in HR and high-end developers.

After much thought over the years on this subject I would use a 100% contractor/temp hiring policy and offer fulltime career positions to select contractors after a year. Some people interview very well with encyclopedic technical knowledge but spend their time writing the code they know you need but not what asked of them.

I have one specific interview hint, provide some code and give the candidate 10 minutes to review, then ask them to criticize the code.


问:
Node.js Or servlets?
I have heard a lot and read about the Javascript server side language i.e Node.js, and saw many comparisons in favor of Node.

I don't understand what makes it better or faster, or how it even relates to something as mature as Java Servlets.

But Servlets are built on top of a multithreaded programming language as opposed to Node.js. Then how can node.js be faster?

If suppose 1000K users query for a database records, then shouldn't Node.js be slower than Servlets.

Also Don't servlets have better security compared to Node.js?

答:
You're mixing apples and oranges, kind of.

Servlets (or inheriting from HttpServlet) let you access HTTP request parameters and respond with something, via (or on top of) an existing HTTP server implementation.

Although using Javascript as the language, Node.js is at a lower level than that. It starts from actually implementing the HTTP server. You can go on to doing more high-level stuff in it nonetheless, such as web applications.

About multi-threading, it's not necessary. Node.js servers aren't faster because of multi-threading, they're faster because they don't block on IO requests, so they can keep pumping them up in the queue, while doing other things. They only work when there's work to be done - they don't wait for it - and that causes a serious performance enhancement, as it turned out.

As for database queries, it's really more about constraints in the database model and API than it is about the client.

As for security - it's really a different topic, and is ultimately in the hands of any developer anyway, not so much in the library.

Title: Node.js Or servlets?


问:
Reusable VS clean code - where's the balance?
Let's say I have a data model for a blog posts and have two use-cases of that model - getting all blogposts and getting only blogposts which were written by specific author.

There are basically two ways how I can realize that.

1st model

```<code>class Articles {

    public function getPosts() {
        return $this->connection->find()
            ->sort(array('creation_time' => -1));
    }

    public function getPostsByAuthor( $authorUid ) {
        return $this->connection->find(array('author_uid' => $authorUid))
            ->sort(array('creation_time' => -1));
    }
}
</code>```

1st usage (presenter/controller)

```<code>if ( $GET['author_uid'] ) {
    $posts = $articles->getPostsByAuthor($GET['author_uid']);
} else {
    $posts = $articles->getPosts();
}
</code>```

2nd one

```<code>class Articles {

    public function getPosts( $authorUid = NULL ) {
        $query = array();

        if( $authorUid !== NULL ) {
            $query = array('author_uid' => $authorUid);
        }

        return $this->connection->find($query)
            ->sort(array('creation_time' => -1));
    }

}
</code>```

2nd usage (presenter/controller)

```<code>$posts = $articles->getPosts( $_GET['author_uid'] );
</code>```

To sum up (dis)advantages:

1) cleaner code

2) more reusable code

Which one do you think is better and why? Is there any kind of compromise between those two?

答:
Why not let an empty $query array indicate that there are no requirements on the posts to be retrieved? That way, the same function calls can be used for both pretty much throughout (only the outermost wrapper call need be different, if you don't want to hardcode dependencies on the array keys).

That is certainly the approach I would favor from both a reusability and cleanliness perspective, at least.


答:
I'm not so sure that programming languages themselves benefit from being based on English.  In explanation:

The name of a methods, variables, objects, etc. don't matter to the computer

The content of a comment doesn't matter to a computer

The logic of programming is expressible in most (and I assume ALL) spoken languages.

So, if English is of benefit to programming languages, it would be in helping to cause more people to use the programming language.  In that regard, here are a few thoughts:

Many people in foreign countries learn English whether or not they want to program

People designing a computer language and wanting many people to use it will generally pick the most well-known spoken language to describe it.

Summarizing these thoughts, I don't think English really helps programming languages in any significant way that most other languages could offer - other than that many people speak it.


答:
The trick is that you do not have to choose. One nice thing that many ORMs provide (for instance that of Django, Squeryl, SQLAlchemy and more) is composable queries. That is, you can not only query a table but query the results of another query. This is not as costly as it looks, as either the ORM or the DB query optimizer can reduce it to a combined SELECT under the hood.

So you would end up with something like (Django example)

```<code>class Article:
  @staticmethod
  def posts():
    return Article.objects.all()

  @staticmethod
  def author_posts(author):
    return Article.posts().filter(author=author)
</code>```

There you have - two separate methods and no repetition. :-)

When you have to choose between clean and reusable, there is often a third option: a little more sophisticated but both clean and reusable.

(By the way, the static methods are there just to mimic your structure. Actually one would have instance methods on the Article manager class. I should also add that this is a trivial example, as the default manager - named Article.objects - already provides the all method to retrieve all results. But this is not the point - the point is that you have obtained a more specific result set by querying a larger result set.)

Title: Reusable VS clean code - where's the balance?

Body:
Let's say I have a data model for a blog posts and have two use-cases of that model - getting all blogposts and getting only blogposts which were written by specific author.

There are basically two ways how I can realize that.

1st model

```<code>class Articles {

    public function getPosts() {
        return $this->connection->find()
            ->sort(array('creation_time' => -1));
    }

    public function getPostsByAuthor( $authorUid ) {
        return $this->connection->find(array('author_uid' => $authorUid))
            ->sort(array('creation_time' => -1));
    }
}
</code>```

1st usage (presenter/controller)

```<code>if ( $GET['author_uid'] ) {
    $posts = $articles->getPostsByAuthor($GET['author_uid']);
} else {
    $posts = $articles->getPosts();
}
</code>```

2nd one

```<code>class Articles {

    public function getPosts( $authorUid = NULL ) {
        $query = array();

        if( $authorUid !== NULL ) {
            $query = array('author_uid' => $authorUid);
        }

        return $this->connection->find($query)
            ->sort(array('creation_time' => -1));
    }

}
</code>```

2nd usage (presenter/controller)

```<code>$posts = $articles->getPosts( $_GET['author_uid'] );
</code>```

To sum up (dis)advantages:

1) cleaner code

2) more reusable code

Which one do you think is better and why? Is there any kind of compromise between those two?

Body:
The trick is that you do not have to choose. One nice thing that many ORMs provide (for instance that of Django, Squeryl, SQLAlchemy and more) is composable queries. That is, you can not only query a table but query the results of another query. This is not as costly as it looks, as either the ORM or the DB query optimizer can reduce it to a combined SELECT under the hood.

So you would end up with something like (Django example)

class Article:
  @staticmethod
  def posts():
    return Article.objects.all()

  @staticmethod
  def author_posts(author):
    return Article.posts().filter(author=author)

There you have - two separate methods and no repetition. :-)

When you have to choose between clean and reusable, there is often a third option: a little more sophisticated but both clean and reusable.

(By the way, the static methods are there just to mimic your structure. Actually one would have instance methods on the Article manager class. I should also add that this is a trivial example, as the default manager - named Article.objects - already provides the all method to retrieve all results. But this is not the point - the point is that you have obtained a more specific result set by querying a larger result set.)


答:
If it seems like an either/or case, it just means you haven't found the right solution yet.

I don't speak PHP, so my code example would likely be wrong, but to keep it abstract, the most obvious way to make your example both reusable and clean is to have your getPosts() function call your getPostsByAuthor() function with a null argument. Better yet, you simply refactor the code that does the search and use it directly from both other functions (one gets the search and executes it as it is, the other tacks on an extra condition first and then executes it). That way, you only define the code that does the work once (i.e. if it needs to be changed later on, it only needs to be changed in one place) and it's clean in terms of being able to call either method (which seemed to be your "clean" criterion, unless I'm misunderstanding you).


答:
I would also suggest something that I read here:
Effective Programming: More Than Writing Code:

It's nice to see if the candidate "fits" in the organization's culture and day to day life. This can be done by allowing the candidate to ask questions to current employees "off the record" or in some advanced level doing a contract job for a week or two (suggested by author).

In retrospective if some companies that I've worked for used this strategy, they would have never hired me, something that would be equally good for both parties.


答:
Like SomeKittens says, do the FizzBuzz test... only that do it live and preferably on paper, since what you want is to really see how much time they take doing the solution. Don't grade syntax, just the logic of the solution, in my case I even allow pseudocode and its not a problem, it works just as good.

It has worked like magic for me... I was able to weed out a so called 15-year-experienced-guy who talked big about him being so good that he would be willing to "step down" from his managerial position for a shot at a developer position in my company... oh boy, did he fail: 45 minutes (I even went for a soda and came back), did it in pseudocode, and he got it wrong. The guy had left a good impression with HR due to his resume, but given this result I was able to weed him out without a sweat.

The average is 15 minutes, less than that, doesn't mean you got a good programmer, more than that start worrying about having a bad programmer in front of you.

Read the article by Jeff Attwood "Why can't programmers program" to get a sense of the essence of the test.

Also, unfortunately I'm in Mexico and this is not popular enough to have where to choose from, but, maybe try careers.stackoverflow.com?, I mean, it is a specialized recruiting tool exactly for what you are looking for.


问:
Sample domain model for online store
We are a group of 4 software development students currently studying at the Cape Peninsula University of Technology. Currently, we are tasked with developing a web application that functions as a online store. We decided to do the back-end in Java while making use of Google Guice for persistence(which is mostly irrelevant for my question). The general idea so far to use PHP to create the website.

We decided that we would like to try, after handing in the project, and register a business to actually implement the website.

The problem we have been experiencing is with the domain model. These are mostly small issues, however they are starting to impact the schedule of our project. Since we are all young IT students, we have virtually no experience in the business world. As such, we spend quite a significant amount of time planning the domain model in the first place. Now, some of the issues we're picking up is say the reference between the Customer entity and the order entity. Currently, we don't have the customer id in the order entity and we have a list of order entities in the customer entity.

Lately, I have wondered if the persistence mechanism will put the client id physically in the order table, even if it's not in the entity? So, I started wondering, if you load a customer object, it will search the entire order table for orders with the customer's id. Now, say you have 10 000 customers and 500 000 orders, won't this take an extremely long time? There are also some business processes that I'm not completely clear on.

Finally, my question is: does anyone know of a sample domain model out there that is similar to what we're trying to achieve that will be safe to look at as a reference? I don't want to be accused of stealing anybody's intellectual property, especially since we might implement this as a business.

答:
I suggest you spend some time knowing about data modeling. I see that it is an essential skill to get acquainted with even if you don't use RDBMS.

we don't have the customer id in the order entity and we have a list of order entities in the customer entity.

This is clearly a design mistake. The business rule is:

Each Customer has 0,1,more Orders

And

Each Order is made by 1 Customer

This is a One-to-Many relationship that implies placing the Primary Key of Customer in the Order table acting as a Foreign Key, both these columns are physical columns in the database.

Lately, i have wondered if the persistence mechanism will put the client id physically in the order table, even if it's not in the entity.

No, the table design is static at run time. Your web application does not alter the database tables design during execution. Your web application only changes data and associations between tables (the values in the Foregoing Keys) if needed as well as delete rows, add rows and so on. The columns don't change.

if you load a customer object, it will search the entire order table for orders with the customer's id. Now, say you have 10,000 customers and 500,000 orders, won't this take an extremely long time?

It does not take time to locate an order given a customer id. This is because in your database design, you'd normally create an Index (a database structure sometimes used for searching the database fast) on the foreign key value. Good database design implies that you specify columns that you choose to build the index on to max. performance of the system.

does anyone know of a sample domain model out there that is similar to what we're trying to achieve that will be safe to look at as a reference?

As for an example, there must be some but I can't provide any except Adventure Works (find the colored picture in the page), which is not exactly what you want but has many tables in common with your objective, specially on the Sales subject area (Order, Credit Card, etc.).

Also note that there are components you could buy to handle some of this stuff but I am not a PHP guy and I can't recommend any now.

Title: Sample domain model for online store


答:
Answering from a developers perspective, relying on developer's technical skill so much does get quality developers but equally has chance to eliminate really good developers also.

I am involved in many programming backgrounds C#, Java, PHP etc. A lot of work experiences does ensure a person is expert in its field, but due to this a fact ignored is that other background are suppressed.

For example, majority of my experience involves around PHP and I know almost all tits and bits of the language, just because I can answer the question, it does not make me a quality programmer. And just because I dont remember the function name and definition in a XXXX library in Java does not make be a bad Java Coder.

I believe developers should be judged by potential and adaptability rather than what they can do.


问:
Is it ever ok to have an empty catch statement?
I thought about it and could not come up with an example. Why would somebody want to catch an exception and do nothing about it? Can you give an example? Maybe it is just something that should never be done.</p>

答:
I don't believe in not having some level of alert when an exception occurs - shouldn't one of the goals of programming be to improve code?  If an exception occurs 10% of the time, and you never know about it, then the exception will always be that bad, or worse.

However, I do see the other side, that if the exception does no real harm in the processing of code, then why expose the user to it.  The solution I typically implement is having it logged by my logger class (that is in every single class I ever write at work).

If it's a benign exception, then I make a call to my Logger's .Debug() method; otherwise, Logger.Error() (and (maybe) throw).

```<code>try
{
   doWork();
}
catch(BenignException x)
{
  _log.Debug("Error doing work: " + x.Message);
}
</code>```

By the way, in my implementation of my logger, making a call to the .Debug() method will only log it if I my App.Config file specifies that program execution log level is in Debug mode.

Body:
I don't believe in not having some level of alert when an exception occurs - shouldn't one of the goals of programming be to improve code?  If an exception occurs 10% of the time, and you never know about it, then the exception will always be that bad, or worse.

However, I do see the other side, that if the exception does no real harm in the processing of code, then why expose the user to it.  The solution I typically implement is having it logged by my logger class (that is in every single class I ever write at work).

If it's a benign exception, then I make a call to my Logger's .Debug() method; otherwise, Logger.Error() (and (maybe) throw).

try
{
   doWork();
}
catch(BenignException x)
{
  _log.Debug("Error doing work: " + x.Message);
}

By the way, in my implementation of my logger, making a call to the .Debug() method will only log it if I my App.Config file specifies that program execution log level is in Debug mode.


问:
Verfication vs validation again, does testing belong to verification? If so, which?
I have asked before and created a lot of controversy so I tried to collect some data and ask similar question again. E.g. V&V where all testing is only validation: http://www.buzzle.com/editorials/4-5-2005-68117.asp
According to ISO 12207, testing is done in validation:

•Prepare Test Requirements,Cases and Specifications

•Conduct the Tests

In verification, it mentiones.

The code implements proper event sequence, consistent interfaces,
  correct data and control flow, completeness, appropriate allocation
  timing and sizing budgets, and error definition, isolation, and
  recovery. and The software components and units of each software item
  have been completely and correctly integrated into the software item

Not sure how to verify without testing but it is not there as a technique.

From IEEE:

Verification: The process of evaluating software to determine whether
  the products of a given development phase satisfy the conditions
  imposed at the start of that phase. [IEEE-STD-610].

  Validation: The
  process of evaluating software during or at the end of the development
  process to determine whether it satisfies specified requirements.
  [IEEE-STD-610]

At the end of development phase? That would mean UAT..

So the question is, what testing (unit, integration, system, uat) will be considered verification or validation? I do not understand why some say dynamic verification is testing, while others that only validation.

An example: I am testing an application. System requirements say there are two fields with max. lenght of 64 characters and Save button. Use case say: User will fill in first and last name and save.
When checking the fields and Save button presence, I would say its verification. When I follow the use case, its validation. So its both together, done on the system as a whole.

答:
ISO 12207 has a rather non-standard (and very fuzzy!) distinction between verification and validation. In most circles, verification answers the question "did we build it right?" (does our product meet the requirements?), while validation means "was this the right thing to build" (do we have the right set of requirements?). ISO 12207 mentions requirements verification. How do you verify requirements, particularly the top level requirements? You don't. You validate them.

The product on which I spend the bulk of my time used to distinguish verification from validation. Problems with this distinction popped up on an annoyingly frequent basis. The distinction was clear to me, but my interpretation wasn't universally agreed upon. Is this a validation test or a verification test? Who cares? Why are we having this stupid fight? A rose by any other name smells just as sweet. The ultimate goal is to answer the question "Is it right?"

Our resolution to this ongoing imbroglio was to get rid of that distinction between verification and validation. We think of verification & validation as one word which together answer the question "Is it right?" We don't split V&V into arbitrary parts. What we split into parts is how we go about answering that singular question. Whether you're looking at our top level document or a detailed model document such as how we model gravity, chapter 5 is titled "Inspections, Tests, and Metrics". The old title, "Verification and Validation": It's gone. We don't split verification from validation. We instead split things into inspections, tests, and metrics. The chapter has typically has four sections, inspections, tests, traceability (typically automated), and metrics (also typically automated). Aside: Traceability analysis is just a specialized (but very important) kind of inspection. It's elevated as a separate section because of it's importance. We wrangled a tiny bit as to whether to call the chapter "Inspections, Tests, Traceability, and Metrics". The answer was no. No more religious wars over names. Traceability is a kind of inspection; the title still fits.

Things that answer the question "is it right" without actually using the product goes under the heading of "inspections". Requirements analysis, traceability analyses, analyses that demonstrate that the simplifying assumptions made by the model are acceptable for the model's intended use: They're all inspections  because we didn't use the product. Traceability, while an inspection, has a home of its own. Using the product to answer that question go under the rubric of "tests". Everything from unit tests to tests against some artificial setup with a known analytic solution to integrated tests where we're comparing the results from the product to real data collected from some previously flown vehicle: They're all tests. Along the way we collect lots of metrics, many of them automated. Different levels of documents have different kinds of boring but important numbers. SLOC count, complexity, code coverage, number of waivers granted, number of issues in the CM system. Those boring but important numbers go under the rubric of "metrics".

Our developers and testers love this change because now it's crystal clear where things go. Project management loves this change because its consistent and because it removes all that silly wrangling over nomenclature. Our CMMI overlords love it because we're still answering the right question ("Is it right") and because we have a well defined process for getting there. Bean counters love it because we're giving them lots of beans that they are very easy to find and very easy to count.


问:
Concurrency pattern of logger in multithreaded application
The context:
We are working on a multi-threaded (Linux-C) application that follows a pipeline model.

Each module has a private thread and encapsulated objects which do processing of data; and each stage has a standard form of exchanging data with next unit.

The application is free from memory leak and is threadsafe using locks at the point where they exchange data. Total number of threads is about 15- and each thread can have from 1 to 4 objects. Making about 25 - 30 odd objects which all have some critical logging to do.

Most discussion I have seen about different levels as in Log4J and it's other translations. The real big questions is about how the overall logging should really happen?

One approach is all local logging does fprintf to stderr. The stderr is redirected to some file. This approach is very bad when logs become too big.

If all object instantiate their individual loggers - (about 30-40 of them) there will be too many files. And unlike above, one won't have the idea of true order of events. Timestamping is one possibility - but it is still a mess to collate.

If there is a single global logger (singleton) pattern - it indirectly blocks so many threads while one is busy putting up logs. This is unacceptable when processing of the threads are heavy.

So what should be the ideal way to structure the logging objects? What are some of the best practices in actual large scale applications?

I would also love to learn from some of the real designs of large scale applications to get inspirations from!

======

EDIT:

Based on both the answers here is the question I am now left with :

What is the best practice about assigning loggers (logging queues) to the object: should they call some global_api() or should the logger be assigned to them in the constructor. When the objects are in some deep hierarchy this later approach becomes tedious. If they are calling up some global_api() it's kind of coupling with the Application, so trying to use this object in other application throws this dependency. Is there a cleaner way for this?

答:
an acceptable way it to use the singleton logger which delegates the actual logging to its own thread

you can then use any efficient producer-consumer solution (like a non-blocking linked list based on the atomic CaS) to gather the log messages without worrying that it is an implicit global lock

the log call will then first filter and build the log message and then pass it to the consumer, the consumer will then grab it and write it out (and free the resources of the individual message)


问:
Should we exclude code for the code coverage analysis?
I'm working on several applications, mainly legacy ones.
Currently, their code coverage is quite low: generally between 10 and 50%.

Since several weeks, we have recurrent discussions with the Bangalore teams (main part of the development is made offshore in India) regarding the exclusions of packages or classes for Cobertura (our code coverage tool, even if we are currently migrating to JaCoCo).

Their point of view is the following: as they will not write any unit tests on some layers of the application (1), these layers should be simply excluded from the code coverage measure. In others words, they want to limit the code coverage measure to the code that is tested or should be tested.

Also, when they work on unit test for a complex class, the benefits - purely in term of code coverage - will be unnoticed due in a large application. Reducing the scope of the code coverage will make this kind of effort more visible...

The interest of this approach is that we will have a code coverage measure that indicates the current status of the part of the application we consider as testable.

However, my point of view is that we are somehow faking the figures. This solution is an easy way to reach higher level of code coverage without any effort.
Another point that bothers me is the following: if we show a coverage increase from one week to another, how can we tell if this good news is due to the good work of the developers, or simply due to new exclusions?

In addition, we will not be able to know exactly what is considered in the code coverage measure. For example, if I have a 10,000 lines of code application with 40% of code coverage, I can deduct that 40% of my code base is tested (2). But what happen if we set exclusions? If the code coverage is now 60%, what can I deduct exactly? That 60% of my "important" code base is tested? How can I

As far as I am concerned, I prefer to keep the "real" code coverage value, even if we can't be cheerful about it. In addition, thanks to Sonar, we can easily navigate in our code base and know, for any module / package / class, its own code coverage. But of course, the global code coverage will still be low.

What is your opinion on that subject? How do you do on your projects?

Thanks.

(1) These layers are generally related to the UI / Java beans, etc.

(2) I know that's not true. In fact, it only means that 40% of my code base

答:
I tend to agree with you, and include all relevant code in code coverage metrics (and Sonar in general). Even if you don't plan to test some parts of the code (for the foreseeable future that is), the metrics should reflect the actual status. This forces you to have a compelling reason not to write tests for a significant part of the codebase. Eventually (once other, more important parts of the code are already covered) you may reconsider, or choose a different way to eliminate this dissonance - e.g. by refactoring the code in question to make it testable, or to migrate all logic from it into a different, testable part of the codebase, or even to eliminate the whole layer altogether (if a layer is not worth testing, does it have a good enough reason to exist?)

In my current projects, we also include all the code in metrics, with one exception: generated code, producing heaps of static analysis warnings. As this code typically consists of humongous POD classes without any logic, there is nothing to test there anyway.


问:
How do programming languages benefit from being based on English?
I think the world now programs in English-based programming languages not only because of historical/economic circumstances, but because the English morphology in particular has some properties that suit algorithmic thinking best. But anyway it would be interesting to hear your opinions on this, especially if you are multilingual yourself.

I've seen some mentioning of German-based languages (see Plankalkul for example, in fact the first ever programming language we know very little about, thanks to WW2), also a Russian-based flavor of Algol which existed back in the 80's at least on paper, not sure if it ever existed in binary or not. Both looked a bit sluggish because there were more shortened words and weird abbreviations than full words like in the EN-based languages. So if you know of any other national language-based PL's, even completely archaic and irrelevant today, purely theoretical or whatever, would be interesting to take a look at them.

And back to the main question: so what, if any, makes the Shakespeare's language so good for programming?

(There is actually a list of Non-English-based programming languages on Wikipedia (of course, where else?), but it would be interesting to hear opinions of native speakers of those languages on how a given "national" programming languages really feels like.)

答:
Disclaimer: My native language is German.

I don't think there is any reason English as a language to take keywords from would be better than any other natural language. I do think it's the one all-important language in IT, but not because of linguistic properties, but because most tech people speak it to some degree, it's the native tounge of quite a few important people in the field, most tech-related terms are already English, etc.

But since we talk about programming languages, not about documentation/API/names/etc, I have to object: Programming languages are not based on English - or on any other natural language, for that matter. Programming languages are formal languages. They do use, to varying degree, a handful of words from (usually) English. Some even try to mimic its grammar -- but utterly fail to read like English regardless.
To add insult to injury, they only associate one single (in rare cases a handful of) meaning(s) with each word they borrow. Often, this meaning is very jargon-y, specialized, or based on a questionable analogy. Therefore, knowing the myriad natural-language meanings of a word borrowed by programming language doesn't really help understanding the programming concept behind the keyword. Examples off the top of my head: array, type, goto, class, void. (Fun fact that sprung to mind as I re-read the question: All of these, except goto, have German translations which are at most one character longer: Feld, Typ, Klasse, Leere. They all sound weird to me, but that's probably a matter of habit.)


答:
I generally exclude auto-generated code, such as the WCF clients that Visual Studio generates. There are usually a lot of lines of code there and we're never going to test them. This makes it very demoralising to increase testing on a large chunk of code elsewhere and only increase code coverage by 0.1%.

I will also exclude data-layer interactions, as long as the team can say with certainty that this layer is as thin as it possibly can be. While you can argue that, if the layer is thin, it won't have a massive effect, it does leave a lot of components in the coverage report with 0% against them, so we don't necessarily notice the ones that we need to really worry about. The UI layer could be argued in a similar way, depending on the framework being used.

But, as a counter-point, I will also exclude the unit tests themselves. They should always have ~100% coverage and they amount to a large percentage of the code-base, skewing figures dangerously upwards.

Title: Should we exclude code for the code coverage analysis?

Body:
I'm working on several applications, mainly legacy ones.
Currently, their code coverage is quite low: generally between 10 and 50%.

Since several weeks, we have recurrent discussions with the Bangalore teams (main part of the development is made offshore in India) regarding the exclusions of packages or classes for Cobertura (our code coverage tool, even if we are currently migrating to JaCoCo).

Their point of view is the following: as they will not write any unit tests on some layers of the application (1), these layers should be simply excluded from the code coverage measure. In others words, they want to limit the code coverage measure to the code that is tested or should be tested.

Also, when they work on unit test for a complex class, the benefits - purely in term of code coverage - will be unnoticed due in a large application. Reducing the scope of the code coverage will make this kind of effort more visible...

The interest of this approach is that we will have a code coverage measure that indicates the current status of the part of the application we consider as testable.

However, my point of view is that we are somehow faking the figures. This solution is an easy way to reach higher level of code coverage without any effort.
Another point that bothers me is the following: if we show a coverage increase from one week to another, how can we tell if this good news is due to the good work of the developers, or simply due to new exclusions?

In addition, we will not be able to know exactly what is considered in the code coverage measure. For example, if I have a 10,000 lines of code application with 40% of code coverage, I can deduct that 40% of my code base is tested (2). But what happen if we set exclusions? If the code coverage is now 60%, what can I deduct exactly? That 60% of my "important" code base is tested? How can I

As far as I am concerned, I prefer to keep the "real" code coverage value, even if we can't be cheerful about it. In addition, thanks to Sonar, we can easily navigate in our code base and know, for any module / package / class, its own code coverage. But of course, the global code coverage will still be low.

What is your opinion on that subject? How do you do on your projects?

Thanks.

(1) These layers are generally related to the UI / Java beans, etc.

(2) I know that's not true. In fact, it only means that 40% of my code base


答:
Now I am not much acquainted with the code coverage tools that you are using nor am I familiar with the Java beans, but from what you say they are related to the UI.

With my limited knowledge I have this to say:

Do not let numbers by any kind of testing tools hinder with your tests.

If the classes are complex and not unit testable, it is always a good idea to re-factor them into more compact and testable classes. It will require a lot of effort and dedication but it will pay in the long run.

Testing UI components can be tough, but you could still test the function that is being performed by those components.

If you are doing a web based project then you can use QUnit to unit test all of the client side code.

All in all you should keep in mind that code coverage is just a number, and high code coverage does not indicate good tests. Focus on making the core libraries more robust and testable rather than aiming for a higher percentage.


答: Some exclusions make sense (boiler plate code that has no real impact or potential of impact on your project functioning correctly). Even still collecting code coverage as a metric is pointless because it doesn't tell you anything useful anyway. 100% code coverage isn't a real goal, and low coverage numbers also may not be bad depending on the project, it could be possible that 20-30% code coverage covers everything that is worth testing. code coverage only tells you X% of your code that is potentially worth covering actually is by some type of test of unknown quality.</p>


答:
Good question. In general I tend to exclude code from code-coverage for some reasons, e.g. it is:

generated

legacy (not updated anymore)

here it comes: certain layers, I don't intend to test

Why the last point? I think it's good practice to focus on things I care about, while suppress distractions. If you don't intend to test the UI-Layer, why take it into consideration - it would only draw attention away from the important part of your software - the business logic.

BUT:

You should have a good reason, why excluding a certain layer from unit-testing at all (there may be questions - from your boss, your teammates, the press ;-)

If you want them to test these layers, you should include them in the statistics to show the whole team, every day that it is important and needs to be done.

Finally: don't take numbers too serious. 30% coverage may proof a software rock solid, when it is the essential part of it.


问:
How important is positive feedback in code reviews?
Is it important to point out the good parts of the code during a code review and the reasons why it is good? Positive feedback might be just as useful for the developer being reviewed and for the others that participate in the review.

We are doing reviews using an online tool, so developers can open reviews for their committed code and others can review their code within a given time period (e.g. 1 week). Others can comment on the code or other reviewer's comments.

Should there be a balance between positive and negative feedback?

答:
If I saw something in a code review that I really liked and was above and beyond "good-enough" code, I'd give positive feedback.

In general, I think that if someone writes a piece code that actually makes you say "Wow, this is really nice!" then yes, positive feedback is important - it makes it known to the author that what they did was enjoyed by others, and they should try to do that again. It has to be more than just following guidelines and standard practices though. Giving out praise because someone indented nicely or added boilerplate comments could set the bar rather low.


答:
Improve Quality and Morale Using Peer Code Reviews

http://www.slideshare.net/SmartBear_Software/improve-quality-and-morale-using-peer-code-reviews

Things Everyone Should Do: Code Review

http://scientopia.org/blogs/goodmath/2011/07/06/things-everyone-should-do-code-review/

Both of these articles state that one of the purposes of code review is to share knowledge about good development techniques, not just find errors.

So I'd say it's very important.  Who wants to go to a meeting and only be criticized?

Title: How important is positive feedback in code reviews?

Body:
Is it important to point out the good parts of the code during a code review and the reasons why it is good? Positive feedback might be just as useful for the developer being reviewed and for the others that participate in the review.

We are doing reviews using an online tool, so developers can open reviews for their committed code and others can review their code within a given time period (e.g. 1 week). Others can comment on the code or other reviewer's comments.

Should there be a balance between positive and negative feedback?


答:
When the code is for a competition or submitted for a job interview (in other words, code that's written and cannot be rewritten), then positive comments are a must. In fact, you should ensure that there is positive feedback (where possible!) as well as negative. That way, the coder knows where his strengths and weaknesses lie, and can compensate.

However, you seem to be talking in a workplace environment, where the code can be rewritten. In which case, you're trying to get bugs the hell out of your system. So, in that situation, only negative bugs are of any worth.

If you feel uncomfortable about that, have a weekly code review meeting, where everyone can discuss both good code and bad code.

EDIT: Though I will say that, if something impresses you enough, there's nothing stopping you from expressing your praise in person. The tracker, however, seems to be only for production code review.


问:
Check parameters annotated with @Nonnull for null?
We've begun using FindBugs and annotating our parameters with @Nonnull appropriately, and it works great to point out bugs early in the cycle. So far we have continued checking these arguments for null using Guava's checkNotNull, but I would prefer to check for null only at the edges--places where the value can come in without having been checked for null, e.g., a SOAP request.

```<code>// service layer accessible from outside
public Person createPerson(@CheckForNull String name) {
    return new Person(Preconditions.checkNotNull(name));
}

...

// internal constructor accessed only by the service layer
public Person(@Nonnull String name) {
    this.name = Preconditions.checkNotNull(name);  // remove this check?
}
</code>```

I understand that @Nonnull does not block null values itself.

However, given that FindBugs will point out anywhere a value is transferred from an unmarked field to one marked @Nonnull, can't we depend on it to catch these cases (which it does) without having to check these values for null everywhere they get passed around in the system? Am I naive to want to trust the tool and avoid these verbose checks?

Bottom line: While it seems safe to remove the second null check below, is it bad practice?

This question is perhaps too similar to Should one check for null if he does not expect null, but I'm asking specifically in relation to the @Nonnull annotation.

答:
Well, consider why you don't write

```<code>this.name = Preconditions.checkNotNull(name);  // Might be necessary
that.name = Preconditions.checkNotNull(this.name);  // Who knows?
</code>```

Programming isn't black magic. Variables don't suddenly become Null. If you know a variable isn't Null, and you know it's not changed, then do not check it.

If you do check it, some programmer in the future (possibly you) will spend a lot of time finding out why that check is there. The check must be there for a reason, after all, so what are you overlooking?

Body:
Well, consider why you don't write

this.name = Preconditions.checkNotNull(name);  // Might be necessary
that.name = Preconditions.checkNotNull(this.name);  // Who knows?

Programming isn't black magic. Variables don't suddenly become Null. If you know a variable isn't Null, and you know it's not changed, then do not check it.

If you do check it, some programmer in the future (possibly you) will spend a lot of time finding out why that check is there. The check must be there for a reason, after all, so what are you overlooking?


答:
Here are some benefits to a hypothetical programming language would have if it just assumed the English - Latin alphabet.

It's a small character set (unlike say Kanji)

Doesn't usually use diacritical marks (unlike French, Spanish, German, etc.)

Every Upper case has a lower case (unlike the German Eszett)

It's collation is straight forward

All of these things are problems that still haven't properly been solved on all devices. For example Song titles with diacritical marks don't show up correctly on a number music players


答:
The only way that I can think of where providing positive feedback about code could backfire on you is if you're not careful to avoid the "backhand compliment." Most people are familiar with this... it's signified by phrases like, "Great job, but..."

If everyone comes to the meeting with the attitude that this is not a personal review of the programmer, but an effort to improve coding practice for the quality of the entire system, then all feedback is "good" feedback. Feedback that highlights ways to improve coding practice becomes just as important as feedback highlighting a useful new method for handling a problem.

At the very least, if one doesn't go to that length, it should be stressed that striving to do a "good feedback, bad feedback, good feedback, bad feedback" cycle within the review process is only going to come across with the same backhand compliment feeling. Don't try to force good feedback, try to reinforce good effort, and shore up holes in knowledge.

Phrases that I've learned the most from, over the years:

"That's an interesting approach. What happens if we have to accommodate [some other use case]?"

"Nice try! Did you know we already have a method for doing that? Maybe we should do some benchmarking to see which approach is more efficient."


答:
It's more important if you're doing side-by-side or team reviews. In a written review, no news is good news. The goal is to get code into production. When it's your code, you should feel good about yourself.

Code review should be used as a source of information to help with mentoring and managing of the team. There are plenty of opportunities to give positive feedback without cluttering up the code review database. Examples can be pulled out to share with others.

There is a lot more to reviewing the developer other than their code. Hijacking code review time can be counter-productive to getting an app out the door. Set time that is specific to helping the developer outside of code reviews, but that doesn't mean you should exclude code review feedback.