问:
What is a Ph.D. good for in the software industry?
I'm a self-taught programmer and have just started a computer science degree to supplement my knowledge and fill in the gaps.

However, I'm already debating the direction of my education. I want a 4 year bachelor's degree for sure, but after that, I'm not sure: Is it worth it to get an M.Sc? What about a Ph.D.? What opportunities do these degrees open up?

Currently my goal is to be a software developer, but there are a number of fascinating fields in the software industry and I'm certainly interested in investigating many of them. It is in this respect that I think a higher degree may be worth it -- even if it wouldn't necessarily help a career of software development.

So will it be worth it? Will grad school open doors?

答:
Can anyone name a CEO of a large company that has a PhD in computer science? Steve Jobs? dropped out of college, 'cos he famously hated the boring bits. Bill Gates? also dropped out as he felt was surrounded by people not as smart as he (based on GPA).

I've worked for companies that have amazing programmers that work on incredible systems, some of which people use every day (e.g. Windows) and others that help industries get along together (e.g. XML and SOAP). Many of these guys were self-taught and studied subjects other than Computer Science, for example Physics or Eletronic Engineering. The reason for programming in their lives was as a tool for getting their work done, rather than studying programming to learn how to do programming.

I've also worked with government and large corporations that have amazing Cambridge graduates that have had not just one, but two PhD's. These were incredibly intellectual guys who created sophisticated and elegant solutions to very specific problems in fields such as communications and signal processing. They weren't rich, nor did they have high-level jobs in their departments. It felt like they were hired as a 'boffin' and left alone to think up these solutions.

In my industry experience, there is no correlation between programming ability and the level of formal education in the computer science field. In my early days as a software engineer, I saw people promoted past me whose programming was 'not as good as mine' (IMO, of course) - but they had the social engineering skills to work out what were the right things to say to the right people and when. They didn't BS their way up - they could do the job, it's just that other skills (talking to clients, delivering on deadlines, etc) were important too, so they didn't spend 100% of their time coding like I did.

I learned an important lesson - if you have the fire within you to succeed, you'll find the solution, programming or otherwise, to the business problem in hand in order to make your company/department more successful and therefore more profitable.

Of all the programmers I've hired, I didn't care for their education track record. If they passed the programming tests and my lead engineers were happy with their abilities, the education did not matter. One of the best guys we hired was straight out of school - i.e. no degree at all.

In summary, if you're passionate about the technology and the art/science of programming itself, by all means pursue an absorbing and fascinating academic path. If you're looking to go places and be successful beyond just programming, widen your focus to include other skills such as business and psychology/sociology. Decide what you really want in 10, 20, 30 years from now and then work backwards to determine which course of action will get you to those goals.

To answer your question: a PhD is good for something really niche. It probably won't pay well, but it might be interesting.


问:
Why is extending the DOM/built-in object prototypes a bad idea?
I'm looking for a definitive answer to why extending built-in prototypes is so heavily chastised in the JS developer community. I've been using the Prototype JS framework for a while, and to me doing [1,2,3].each(doStuff) seems much more elegant than $.each([1,2,3], doStuff). I know that it creates "namespace pollution," but I stil don't understand why it's considered to be a bad thing. Also is there any real performance degradation associated with extending built-in prototypes? Thanks!

答:
Another reason is code readability/maintainability. If another developer (especially a newbie) is reading my code and sees [0, 1, 2].foo(...), they may not know what the foo method is or where to find documentation/source for it. Is foo is an extension to the language added by prototype.js, or by another library in use, or by some other portion of my code in another file, or is it a native JavaScript method that they didn't know about? They need to hunt for it and may not find it right away (or if there are conflicts they may not find the right one).

With the jQuery approach, if you see $.foo(...), the namespace of the foo method makes it obvious where to find its definition/documentation if you don't know what it does.

OwnerDisplayName: lxe

ContentLicense: CC BY-SA 3.0


问:
Automatic programming: write code that writes code
After reading the book The Pragmatic Programmer, one of the arguments I found most interesting was "write code that writes code".

I tried searching over the net for some more explanations or articles about it, and while I found some good articles on the subject, I still haven't found any specific code implementation or good examples.

I feel it's still not a so common argument, something that lacks documentation or it's not embraced by so many people, and I would like to know more about it.

What do you think about the subject? Is it something that will really increase your productivity? What are some good resources on the subject, among books, blogs, slideshows, etc?

Some code examples would be greatly appreciated to allow me to better understand its implementation.

Here's the wiki page on the subject with various relevant programming techniques, like Meta Programming, Generative Programming and Code Generation.

答:
I am just working on such a tool. In our particular case we generate the VB.NET code based for the Data Layer on the signatures of the functions in the database.

Starting to work on and with code generation is difficult at first since you have no idea how the code should be generated, but once you have an established set of rules, and the code that has to be generated can always be generated based on those rules, working with that code is not that difficult. OF course, depending on the complexity of the code generation and on the number of rules, the task can become more difficult. But in essence, auto-code generation is used for repetitive coding tasks and not for advanced code that varies much.

Testing the output is twofold. First you have to make sure that the code compiles, and that's easy. Then you have to make sure that the output does what you meant it to do based on the parameters it was generated on.. and the difficulty of that varies on the complexity of the code you generate.

My sincere recommendation is that if you feel like you write code in a repetitive way, and you can afford the time.. Try to think if what you are doing can't be done by generated code. And if so (if it's repetitive code than is almost always the case) think how many times will you have to extend, slightly modify that code and also how many times do you have to write that exact kind of code. If the answer to any of these is "many" then you should seriously consider making a generator for that code.

Hope that helps,

IPP


问:
License on papers published at universities?
I've done some searching around on how to interpret morse code inputted by a human. I haven't found any existing libraries or applications that do this, but I found some academic papers on how it can be done.

Before embarking on the journey of trying to interpret the academic language and advanced topics I have to know if it is okay for me to use these papers? What kind of license do they have? One I'm thinking of specifically is "A Morse-code recognition system with LMS and matching algorithms for persons with disabilities." but also others floating around. The paper mentioned appears to cost money to read, but then what? Can it have been patented? What rules apply here?

答:
If the patent had been applied for before the paper was written, it would probably say in the paper.  But it might have been patented AFTER the paper was written, so you'd best look up the authors at the USPTO website.

I am not a lawyer, but I don't think there is any license at all on algorithms that are published in academic papers.  There would be a license on software that was produced by an academic institution, but that's a different thing.

However, what Academia just about always cares about more than licensing is getting proper credit for their discoveries.  Thus you should credit that paper's authors and their institution in your app's About Box (if it has one), in the online help if it's a command-line program, or on your app's website if it's a web app.  Also credit them in your documentation.

Finally email the authors to tell them that you are using their algorithm.  The chances are pretty good that they didn't expect to make money from it, but the fact that their invention is being put to good use in industry will help them get grants, advanced in rank (say from associate professor to full professor) or maybe even get tenure.

I have seen an academic source code license that more or less says you can do what you want with the code provided the original authors get visible credit for their work.  To do otherwise would be just like using their paper's results in your own paper without providing a citation, which is a form of plagiarism.


问:
Should we use python 2.6 or 2.7 or 3.x?
The version of python which I am using is 2.6, and there is a 2.7 and 3.x. Usually I use python for some trivial program/snippet. I realize there are some major difference between 2.x and 3.x. I would really like to know, if I am going to make a bigger project with python, which version of python should I use?

Should I upgrade to 2.7, or go to 3.x or stay with 2.6?

The decision should be based on these terms:

Number of user in the internet as a community. More users mean more open-source package and help from them.

Functionality.

Support from official development team.

Compatibility for existing module/package.

Thanks!

答:
My opinion is we need to start getting people over to Python 3 and if there are libraries that are not compatible with Python 3, we need to start making that not the case.

Python 3 is the future of the language, and the more code we write using it, the better.

Title: Should we use python 2.6 or 2.7 or 3.x?


答:
For each project check if all libraries required for a project already got 3.x python support then use python 3.x because it's future and that's last official stable version.

Else use whatever you need to use for library compatibility.

Title: Should we use python 2.6 or 2.7 or 3.x?

Body:
The version of python which I am using is 2.6, and there is a 2.7 and 3.x. Usually I use python for some trivial program/snippet. I realize there are some major difference between 2.x and 3.x. I would really like to know, if I am going to make a bigger project with python, which version of python should I use?

Should I upgrade to 2.7, or go to 3.x or stay with 2.6?

The decision should be based on these terms:

Number of user in the internet as a community. More users mean more open-source package and help from them.

Functionality.

Support from official development team.

Compatibility for existing module/package.

Thanks!


答: Basically, that's dependent on the institution where the work was done and the issuers of the grants that funded it.  There's no overall policy for that sort of thing.  Contacting the author(s) would probably be your best option at this point.</p>

Title: License on papers published at universities?

Body:
I've done some searching around on how to interpret morse code inputted by a human. I haven't found any existing libraries or applications that do this, but I found some academic papers on how it can be done.

Before embarking on the journey of trying to interpret the academic language and advanced topics I have to know if it is okay for me to use these papers? What kind of license do they have? One I'm thinking of specifically is "A Morse-code recognition system with LMS and matching algorithms for persons with disabilities." but also others floating around. The paper mentioned appears to cost money to read, but then what? Can it have been patented? What rules apply here?


问:
Is Razor or XSLT better for my project?
I'm in the early stages in the design of a system that will essentially be split into two parts. One part is a service and the other is an interface with the service providing data through something like OData or XML. The application will be based on the MVC architectural pattern. For the views, we are considering using either XSLT or Razor under ASP.NET.

XSLT or Razor would help to provide a separation of concerns where the original XML or response represents your model, the XSLT or 'Razor view' represents your view. I'll leave the controller out for this example. The initial design proposal recommends XSLT, however I suggested the use of Razor instead as a more friendly view engine.

These are the reasons I suggested for Razor (C#):

Easier to work with and build more complicated pages.

Can easily produce non-*ML output, eg csv, txt, fdf

Less verbose templates

The view model is strongly typed, where XSLT would need to rely on
convention, eg boolean or date values

Markup is more approachable, eg nbsp, newline normalization, attibute
value normalization, whitespace rules

Built in HTML helper can generate JS validation code based on DTO attributes

Built in HTML helper can generate links to actions

And the arguments for XSLT over razor were:

XSLT is a standard and will still exist many years into the future.

It is hard to accidentally move logic into the view

Easer for non programmers (which I don't agree with).

It's been successful in some of our past projects.

Data values are HTML-encoded by default

Always well formed

So I'm looking for aguments on either side, recommendations or any experience making a similar choice?

答:
Is there a 1:1 relation between HTML pages and XML output? Consider following cases:

Strong correlation: each web page has an HTML and a corresponding XML form.

Example: you're hosting a website with movies reviews. You have a home page with latest reviews, one page per review and a page with guests comments and ratings. There is no registration whatsoever. You want to make it easy to use your website programmatically without the ugly HTML parsing. In this case, you can have a 1:1 relation: all the human can do, the bot can do too: with same requests, they will obtain the same content.

http://example.com/Movie/View/12345/The%20Adjustment%20Bureau is used by humans.

http://example.com/Movie/View/12345/The%20Adjustment%20Bureau?xml is used by bots to access the same information.

Weak or no correlation: there is just a bunch of web services on one side, and a bunch of web pages on the other.

Example: you're a creator of another Facebook. There is a website, and there is an API. The only common point is that the same database is used, but bots cannot access what people can, and the information is presented differently.

http://example.com/MyFriends/ shows the top ten of friends I have in my account. By clicking "More", an AJAX request is made, showing other friends.

http://api.example.com/friends?user=MainMa&key=1DE051C6F&xml shows the corresponding XML with all friends I have.

You can see that:

The API is hosted separately, on a distinct server,

The relation between pages and API is hard to see.

The website needs to use sessions to track logons. The API needs just a generated key to be sent on every request.

The number of requests is not the same. In one case, you have to query the page, then do an AJAX request to obtain the rest of your friends. In other case, you obtain the whole list at once.

The returned information is not the same. As a human, you identify your friends by their name. A bot using the API will identify them by their unique identifier which you may never see on the website.

I recommend choosing XSLT only if you are near a 1:1 relation. In this case, it will simplify the approach: the application will emit XML every time, but sometimes transform it with XSLT for the browsers.

If you don't have this relation, I don't see any benefit of XSLT over Razor. It provides a separation of concerns which Razor provides too. It allows you to modify HTML without the need to recompile the website, which Razor allows too.

As for the benefits you listed:

XSLT is a standard and will still exist many years into the future

Are you planning to make an application which will live for a very long time? Razor have chances to be used in four years, or at least be supported. The lifespan of most applications is less than four years, so...

Easer for non programmers (something which i could contend with).

Wait, what?! Even programmers find that XSLT sucks, is difficult to understand and to use. And when I talk to non-programmers about XML (not even close to XSLT), they cry and run away.

It's been successful in some of our past projects.

If your team never used Razor before, then consider the time required to learn it.

If your team used it, but those projects failed, consider analyzing why is it failed and was it because of Razor, and what could you do to avoid such failures in future projects.

Title: Is Razor or XSLT better for my project?


问:
Are Java certifications important for an architect role?
I want to know how much Java Certifications (SCJP, SCWCD and others) are important for an architect position. If a person posses a good experience in Java development and want to pursue his career on architect level, do you guys think he need to have certification on his CV. If he has never worked on lead developer roles?

If you conducting my interview for an architect position. And I have worked as a Java web developer in different teams having 5 years of exp. Never lead any. And I am having certification badges on my CV.

How can a developer make his career path towards being an architect in a team?

答:
Early in my career I studied for and acheived my SCJP, and I would do it again just because the goal of the certification was motivation for me to study and learn the intricate details of Java.  The certification itself did nothing for my career however.

They tend not to matter much at all in the US, however in places like India where there are a lot of truly qualified applicants and higher competition for top jobs like Software Architect's then they can be used to weed out certain candidates.

I think certifications are ultimately worth it even if they are only slightly beneficial but certainly they are many orders of importance lower than true talent and skill.

Your question concerns me though that I don't think you may be ready for a SA role.  A good software architect IMHO must have a diverse background in a multitude of different technologies.  He/She must have at least a high level understanding of any framework or language, and the ability to critically evaluate legacy systems for strengths and weaknesses in design.  Given a number of constrains a good software architect must also be able to determine a number of different potential solutions and weigh the pros and cons of each one.

When a high level manager asks you why you choose Java over Ruby what do you say?  What about the benefits of PHP versus C#?  Can you define an Anemic Data Model?  What are the benefits of Java EE approach over the the Spring Framework AOP approach or vice-versa?

These are the kinds of questions an architect should be able to answer and if you have to do research for these then you may not be up to the task.


问:
Language Choice for Algorithm Competitions
Hi everyone
I have just started taking part in online coding competitions.I would like to know which language would be better as regards efficiency and ease of debugging. I tend to avoid c++ and generally go with java.
1. Would some other language be suitable? How about c sharp or python or some other (No issues with learning a new one.)
2. Is proficiency in C++ necessary to do efficient programming?
3. And out of java & c# which is better for algorithm competitions?

答:
I participated in IOI a couple of times, and coded in C. At the time, I did not know of OO, or even how to allocate memory on the heap (I allocated all memory I needed on the stack). All focus was on the algorithm.

However, nowadays, I'd stick to Java, because of the large library of algorithms and data structures available. But, of course, take into consideration that at IOI, you are not allowed to bring any prepared code, so a huge library of algorithms and structures is a great advantage.
Online competitions is probably another matter...

OwnerDisplayName: filokalk


问:
What are the disadvantages of using/writting a .Net Custom Membership Provider?
Recently, I posted the following question on SO: https://stackoverflow.com/questions/7197337/using-asp-net-membership-provider-with-an-existing-user-database

As you may notice, I ended up answering my own question stating that it looked like writting/implementing a "Custom Membership Provider" was the way to go.

Literally, a few minutes later, I stumble across this question: https://stackoverflow.com/questions/7222306/simple-login-attempt-counter-using-mvc-3-and-ajax/7222407#7222407

I try to answer and get a comment back that .Net Membership provider is "terrible on many levels". I'll admit, this is the first time I'm using Membership provider but it sure looked slick to me.

I haven't seen anything that backs up the "terrible" claim so before I implement something "terrible", I was hoping to get some feedback from the community.

答:
It doesn't do what you want. At first glance you may find it takes care of all your needs and some, but a new requirement comes up. Now you 'really' have to learn how this thing works. The benefit of having all of this prebuilt diminishes because you were in that false sense of security.

@Travis mentioned using an existing data model, but the choice of database can be a restriction as well: Oracle?

I don't know if it works with 3rd party verification systems like Facebook or Google.


问:
How do you prevent the piracy of your software?
Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>

答:
If you don't add any protection or annoyance (i.e a nag screen), almost no one will pay for you work.

With a basic protection, the average user, really motivated to buy your software, will buy it, but avoid to make too complex its life: the customer is paying you, so be kind.

A good way to protect software is online activation. Of course keep in mind that every copy protection system may be overridden, so don't spend too much time in developing complex protection schemes: people that absolutely don't want or can't afford buying it will either crack it or skip it.

ContentLicense: CC BY-SA 2.5


答:
I would suggest there's a third and better way: put two different thin front ends on top of a single service/application layer which has no UI as such.

So, rather than

```<code>UI -> converts to and from xml -> Service -> talks to -> Application Layer -> Model
</code>```

use

```<code>UI -> talks to -> Application Layer -> manipulates -> Model
Service ^
</code>```

and ensure that the UI and Service contain ONLY code that is unique to that interface. (apologies for the ASCII diagrams, best I can do right now)

The reason I would be concerned about either of the designs you are discussing is that it ties development of the user interface to development of the service, which is rarely how you want to work. If the business wants to add a piece of functionality to the user interface, you don't want to be forced to write that service before you can do it. You want to write the user interface part and then, assuming it is required in the service, reuse the code there.

Worse, if the business wants to display data very differently to the end-user from how it is presented to a mechanical user via the service (which seems highly likely), you're going to have to start putting complex code into XSLT, or build a second service layer (or worse, fat controllers) on top of your service to represent presentation to the user.

Think about validation in this case. You are potentially drawing three levels of trust. Your model will require validation to make sure you don't store invalid data; then your service may require some more validation, to ensure that external consumers don't try to do something they're not allowed to do; and your UI will need some validation rules, at best so that it can avoid a postback.

And this is before we even touch the sticky situation of something which should not be allowed through the API but should be allowed through the UI, which requires the API.

I have heard an argument that running your UI through your service is dogfooding and thus good for the quality of the service, but I strongly suggest there are better ways to do that while keeping a solid (and SOLID) separation of concerns between the service, the UI and the business model.

All this said, if you must go the way of wrapping your service with a UI, I would strongly recommend Razor over XSLT.

XSLT is a standard, yes. But XSLT 2.0 still has limited support, so you're stuck with an outdated standard if you want to make that argument.

XSLT is not easy to read. By anyone that isn't an XSLT expert. Who do you think is easier to find, when you need to hire new staff? Someone claiming to be an XSLT expert or an ASP.NET for MVC expert?

And yes, I have seen XSLT used successfully, but only before MVC for ASP.NET was an option.

Title: Is Razor or XSLT better for my project?

Body:
I'm in the early stages in the design of a system that will essentially be split into two parts. One part is a service and the other is an interface with the service providing data through something like OData or XML. The application will be based on the MVC architectural pattern. For the views, we are considering using either XSLT or Razor under ASP.NET.

XSLT or Razor would help to provide a separation of concerns where the original XML or response represents your model, the XSLT or 'Razor view' represents your view. I'll leave the controller out for this example. The initial design proposal recommends XSLT, however I suggested the use of Razor instead as a more friendly view engine.

These are the reasons I suggested for Razor (C#):

Easier to work with and build more complicated pages.

Can easily produce non-*ML output, eg csv, txt, fdf

Less verbose templates

The view model is strongly typed, where XSLT would need to rely on
convention, eg boolean or date values

Markup is more approachable, eg nbsp, newline normalization, attibute
value normalization, whitespace rules

Built in HTML helper can generate JS validation code based on DTO attributes

Built in HTML helper can generate links to actions

And the arguments for XSLT over razor were:

XSLT is a standard and will still exist many years into the future.

It is hard to accidentally move logic into the view

Easer for non programmers (which I don't agree with).

It's been successful in some of our past projects.

Data values are HTML-encoded by default

Always well formed

So I'm looking for aguments on either side, recommendations or any experience making a similar choice?

Body:
I would suggest there's a third and better way: put two different thin front ends on top of a single service/application layer which has no UI as such.

So, rather than

UI -> converts to and from xml -> Service -> talks to -> Application Layer -> Model

use

UI -> talks to -> Application Layer -> manipulates -> Model
Service ^

and ensure that the UI and Service contain ONLY code that is unique to that interface. (apologies for the ASCII diagrams, best I can do right now)

The reason I would be concerned about either of the designs you are discussing is that it ties development of the user interface to development of the service, which is rarely how you want to work. If the business wants to add a piece of functionality to the user interface, you don't want to be forced to write that service before you can do it. You want to write the user interface part and then, assuming it is required in the service, reuse the code there.

Worse, if the business wants to display data very differently to the end-user from how it is presented to a mechanical user via the service (which seems highly likely), you're going to have to start putting complex code into XSLT, or build a second service layer (or worse, fat controllers) on top of your service to represent presentation to the user.

Think about validation in this case. You are potentially drawing three levels of trust. Your model will require validation to make sure you don't store invalid data; then your service may require some more validation, to ensure that external consumers don't try to do something they're not allowed to do; and your UI will need some validation rules, at best so that it can avoid a postback.

And this is before we even touch the sticky situation of something which should not be allowed through the API but should be allowed through the UI, which requires the API.

I have heard an argument that running your UI through your service is dogfooding and thus good for the quality of the service, but I strongly suggest there are better ways to do that while keeping a solid (and SOLID) separation of concerns between the service, the UI and the business model.

All this said, if you must go the way of wrapping your service with a UI, I would strongly recommend Razor over XSLT.

XSLT is a standard, yes. But XSLT 2.0 still has limited support, so you're stuck with an outdated standard if you want to make that argument.

XSLT is not easy to read. By anyone that isn't an XSLT expert. Who do you think is easier to find, when you need to hire new staff? Someone claiming to be an XSLT expert or an ASP.NET for MVC expert?

And yes, I have seen XSLT used successfully, but only before MVC for ASP.NET was an option.


问:
How to get better at testing your own code
I am a relatively new software developer, and one of the things I think I should improve is my ability to test my own code. Whenever I develop a new functionality, I find it really difficult to follow all the possible paths so I can find bugs. I tend to follow the path where everything works. I know this is a well known issue that programmers have, but we don't have testers at my current employer and my colleagues seem to be pretty good at this.

At my organization, we do neither test-driven development nor unit testing. It would help me a lot but it's not likely that this will change.

What do you guys think I could do in order to overcome this? What approach do you use when testing your own code?

答:
The job of a coder is to build things.

The job of a tester is to break things.

The most difficult is to break things you just built. You will succeed only by going over this psychological barrier.


答:
You could look into the possible usage of Truth Tables to help you define all of the potential paths in your code. It's impossible to account for all possibilities in complex functions, but once you have your handling established for all known paths, you can establish a handling for the else case.

Most of this particular ability is learned by experience though. After you've used a certain framework for a significant amount of time, you begin to see the patterns and earmarks of behavior that will let you look at a piece of code and see where a small change could cause a major error. The only way I can think of to increase your aptitude in this is practice.

Title: How to get better at testing your own code

Body:
I am a relatively new software developer, and one of the things I think I should improve is my ability to test my own code. Whenever I develop a new functionality, I find it really difficult to follow all the possible paths so I can find bugs. I tend to follow the path where everything works. I know this is a well known issue that programmers have, but we don't have testers at my current employer and my colleagues seem to be pretty good at this.

At my organization, we do neither test-driven development nor unit testing. It would help me a lot but it's not likely that this will change.

What do you guys think I could do in order to overcome this? What approach do you use when testing your own code?


答:
If like you said you don't need Unit testing I don't see any better approach than trying to break your own code manually.

Try to push your code to the limits. For example try to pass variables to a function exceeding the boundary limits. Do you have a function which is supposed to filter user input? Try to input different combinations of characters.

Consider the user's point of view. Try to be one of the users who will use your application or library of functions.


问:
Ruby on Rails downsides and caveats
This is not an opening gambit for RoR bashing - honest!

I'm learning Ruby and the Rails framework. Prima facie it appears to be pretty cool, and a wonderful experience compared to PHP. (In fact, it's reminding me of happier days with C# and .NET.)

However, going into this, I have no experience with this framework or language, and I'm curious - what are the current downsides or things you'd wish you'd known when you were beginning?

(Maybe this should be made a community wiki?)

答:
Speed definitely is an issue. Ruby's extreme flexibility comes with a significant performance hit.

Scaling horizontally is a non-obvious task, except for technologies specifically designed for that task, which usually trade off simplicity to scale well.

If you can handle 100 times as many requests per machine with technology A than with technology B, using technology A is worth consideration if you have reason to believe that you can serve your data from a single server for a time frame that allows you to add parallelization afterward.

In 2009 stackoverflow was still served from one web server. Of course this is no longer an option. But I suppose it was good they started with a technology, that could scale up to a lot of users on a single instance, before they had to worry about scaling out.

Compared to that, RoR is really slow. The time to handle simple requests is significant and
therefore it's a problem to handle many clients (this is all to be seen in relation to faster alternatives).

For the sake of vague orientation, here are some numbers, comparing various other languages suitable for web development to Ruby:

Go

Clojure

JavaScript V8 (node.js)

JRuby (an alternative not to be forgotten - depending on your problem area JRuby may be a better or a worse choice to get some speed out of a rails app)

Scala

Java

C#

Note that this doesn't mean, that if you use framework X for Java that it will be exactly 200 times faster than RoR. But the speed difference measured in these benchmarks has an important impact on the overall performance of your app.

Title: Ruby on Rails downsides and caveats


答:
Are certifications good in career path for architect?

Yes. In my opinion the main outcome of being certified is some overview. You know the technology (be aware it doesn't mean you know how to use the technology - that needs practice). For architect it can be quite useful to have solid overview of the technology used in his area of specialization but in Java world certifications don't have to be enough - you should also know about some main application servers and frameworks.

I passed many MS certification and just because of preparation for these certification I become familiar with parts of API I have never needed to use before (and sometimes I didn't know about them at all). Later I was able to propose these parts of API as a ready to use solution for some problems. So that is the reason why I continue taking certifications. The certification itself means nothing at interview until you prove that you know the related stuff.

Will certifications help me to get a job as architect?

No. Certification itself means nothing. You must have other skills to become an "architect". Programming itself is not enough to become architect - you must be able to make a decisions, to take a responsibility, to design a component or whole application and to prepare work for other (sometimes even lead them). You must have good communication skills.

At least that was what I expect from architect. But what / who is an architect? For me it is just over used buzzword. More then half of architects I have ever met were just in the right time (or long enough) on the right place to be promoted. Being architect doesn't mean that you are good or better then others and even if you are you are still on the same career level like these who are not. Once I meet somebody how calls himself architect I'm always very suspicious.

Title: Are Java certifications important for an architect role?

Body:
I want to know how much Java Certifications (SCJP, SCWCD and others) are important for an architect position. If a person posses a good experience in Java development and want to pursue his career on architect level, do you guys think he need to have certification on his CV. If he has never worked on lead developer roles?

If you conducting my interview for an architect position. And I have worked as a Java web developer in different teams having 5 years of exp. Never lead any. And I am having certification badges on my CV.

How can a developer make his career path towards being an architect in a team?


问:
What do you think of opening brace comments in source code?
I have developed a habit of writing comments in my code by putting the comments on the same line as the opening brace, after the brace. I've found that this saves vertical space. It also leaves a hint why something was done, but I'm wondering if it's readable for others.

Example:

```<code>void DoSomeInterestingImageManipulation(char *pImage)
{//This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {//Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}
</code>```

Do you consider it easier to read or harder to read?

答:
Personally, I don't find your comment style readable. I prefer my comments that explain a block of code to be above the block of code. In languages that use curly braces, this is typically above the curly brace.

Also, I noticed from your comments that you are explaining a lot of "what", although this might just be in the sample. This typically goes out of date faster than the code since people will change the code but not the comments. Your comment about doing something because it saves space is a good comment, but the other ones, not so useful. Not having the comments where they don't explain rationale would save space and improve readability.


答: I actually like to keep that extra space empty, but perhaps it's just a matter of getting used to.</p>

Title: What do you think of opening brace comments in source code?

Body:
I have developed a habit of writing comments in my code by putting the comments on the same line as the opening brace, after the brace. I've found that this saves vertical space. It also leaves a hint why something was done, but I'm wondering if it's readable for others.

Example:

```<code>void DoSomeInterestingImageManipulation(char *pImage)
{//This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {//Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}
</code>```

Do you consider it easier to read or harder to read?


答:
Franciso, I'm going to make some assumptions here, based on what you've said:

"We don't do neither TDD nor unit testing. It would help me a lot but it's not likely that this will change."

From this, I suspect your team does not place a lot of value on testing or management will not budget time for the team to try and tidy up existing code and keep technical debt to a minimum.

Firstly, you need to convince your team/management the value of testing. Be diplomatic. If management is keeping your team moving forward, you need to show them some facts, such as the defect rate for every release. Time spent fixing defects could be better spent on other things, such as improving the application and making it more adaptive to future requirements.

If the team and management in general are apathetic about fixing the code and you feel unhappy about it, you may need to look for another place to work, unless you can convince them as I have said. I've encountered this problem to different degrees in all places I've worked. It could be anything from lack of a proper domain model, to poor communication in the team.

Caring about your code and the quality of the product you develop is a good attribute and one you always want encourage in other people.


答:
When I look at testing my code, I usually go through a series of thought processes:

How do I break this "thingy" down into a testable size chunks?  How can I isolate just what I want to test?  What stubs/mocks should I create?

For each chunk: How do I test this chunk to make sure that it responds correctly to a reasonable set of correct inputs?

For each chunk: How do I test that the chunk responds correctly to incorrect inputs (NULL pointers, invalid values)?

How do I test for boundaries (e.g. where values go from signed to unsigned, 8 bit to 16 bit, etc.)?

How well do my tests cover the code?  Are there any conditions I missed?  [This is a great place for code-coverage tools.]  If there is code that was missed and can never be executed, does it really need to be there? [That's a whole other question!]

The easiest way I have found to do this is to develop my tests along with my code.  As soon as I have written even a fragment of code, I like to write a test for it.  Trying to do all of the testing after having coded several thousand lines of code with non-trivial cyclomatic code complexity is a nightmare.  Adding one or two more tests after adding a few lines of code is really easy.

BTW, just because the company you work at and/or your colleagues don't do Unit Testing or TDD, doesn't mean you can't try them, unless they are specifically prohibited.  Perhaps using them to create robust code will be a good example for others.


答:
I think it's readable but weird. Whenever I see something next to a brace, I expect it to be part of the body. Now a // or a /* gives the comment away, but it doesn't feel natural.

Another big issue is ineffective debugging. Consider this:

```<code>// code

for () { /* comment
    end comment */
loop
} */

//code
</code>```

If you decide that you want to comment out the loop to test the effect, what you'll end up doing is this:

```<code>/* for () { /* comment
        end comment */
    loop
    } */
</code>```

and the loop remains. Now this is kind of a strange example, but the issue is there.

In addition, you haven't established a concrete reason for the advantages of this style. I don't think "saving a line" counts.

Body:
I think it's readable but weird. Whenever I see something next to a brace, I expect it to be part of the body. Now a // or a /* gives the comment away, but it doesn't feel natural.

Another big issue is ineffective debugging. Consider this:

// code

for () { /* comment
    end comment */
loop
} */

//code

If you decide that you want to comment out the loop to test the effect, what you'll end up doing is this:

/* for () { /* comment
        end comment */
    loop
    } */

and the loop remains. Now this is kind of a strange example, but the issue is there.

In addition, you haven't established a concrete reason for the advantages of this style. I don't think "saving a line" counts.


答:
If you code in C, Objective-C or C++ you can use the CLang Static Analyzer to critique your source without actually running it.

There are some memory debugging tools available: ValGrind, Guard Malloc on Mac OS X, Electric Fence on *NIX.

Some development environments provide the option to use a debugging memory allocator, that does stuff like fill newly allocated pages and newly freed pages with garbage, detect the freeing of unallocated pointers, and write some data before and after each heap block, with the debugger being called if the known pattern of that data ever changes.

Some guy on Slashdot said he got a lot of value out of single-stepping ever new line of source in a debugger.  "That's it" he said.  I don't always follow his advice, but when I have it has been very helpful to me.  Even if you don't have a test case that stimulates an uncommon code path, you can twiddle a variable in your debugger to take such paths, say by allocating some memory, then using the debugger to set your new pointer to NULL instead of the memory address, then stepping through the allocation failure handler.

Use assertions - the assert() macro in C, C++ and Objective-C.  If your language doesn't provide an assert function, write one yourself.

Use asserts liberally, then leave them in your code.  I call assert() "The test that keeps on testing".  I use them most commonly to check preconditions at the entry point of most of my functions.  That's one part of "Programming by Contract", which is built into the Eiffel programming language.  The other part is postconditions, that is, using assert() at function return points, but I find that I don't get as much mileage out of that as preconditions.

You can also use assert to check class invariants.  While no class is strictly required to have any invariant at all, most sensibly designed classes do have them.  A class invariant is some condition that is always true other than inside of member functions that might temporarily place your object into an inconsistent state.  Such functions always must restore the consistency before they return.

Thus every member function could check the invariant upon entry and exit, and the class could define a function called CheckInvariant that any other code could call at any time.

Use a code coverage tool to check which lines of your source are actually getting tested, then design tests that stimulate the un-tested lines.  For example you could check low memory handlers by running your app inside a VM that is configured with little physical memory, and either no swap file or a very small one.

(For some reason I was never privy to, while the BeOS could run without a swap file, it was highly unstable that way.  Dominic Giampaolo, who wrote the BFS filesystem, urged me never to run the BeOS without swap.  I don't see why that should matter, but it must have been some kind of implementation artifact.)

You should also test your code's response to I/O errors.  Try storing all your files on a network share, then disconnect your network cable while your app has a high workload.   Similarly disconnect the cable - or turn off your wireless - if you are communicating over a network.

One thing that I find particularly infuriating are websites that don't have robust Javascript code.  Facebook's pages load dozens of little Javascript files, but if any one of them fails to download, the whole page breaks.  There just has to be some way either to provide some fault tolerance, say by retrying a download, or to provide some kind of reasonable fallback when some of your scripts didn't download.

Try killing your app with the debugger or with "kill -9" on *NIX while it is right in the middle of writing a big, important file.  If your app is well-architected, the entire file will get written or will not be written at all, or maybe if it is only partially written, what does get written will not be corrupted, with what data that is saved being completely usable by the app upon re-reading the file.

databases always have fault-tolerant disk I/O, but hardly any other kind of app does.  While journaled filesystems prevent filesystem corruption in the event of power failure or crashes, they don't do anything at all to prevent the corruption or loss of end-user data.  That is the responsibility of the user applications, but hardly any other than databases implement fault-tolerance.


答:
Don't like to mix comments and code. Even if the code is a single {.

For example, some IDEs helps you by greying out lines that are commented. When you mix code and comment, you can loose this code-coloring.

Another point: I prefer to use one comment-symbol per line. In Java, for example, I prefer to use lots of //, one each line, instead of /* and */.

This way, when debuging, I can use the /* */ to comment the code that'll be left out without having to see where I'm finishing explanation-comments


答:
It feels weird. There's no problem with it. You could also do:

```<code>void foobar() {
    // comment explaining function
    ...
}
</code>```

And you get the same number of lines just by putting the opening brace on the same line as the function name.

Body:
It feels weird. There's no problem with it. You could also do:

void foobar() {
    // comment explaining function
    ...
}

And you get the same number of lines just by putting the opening brace on the same line as the function name.


问:
How do I sell my software on the Internet?
I'd like to sell my software on the 'net but am not sure how to do the whole Merchant setup.  I have access to Commerce Server 2009, and I want to seem professional so a plain old PayPal account is out.

What do I need to know/do to sell a few things using ASP.NET, accept credit cards, and what not?

答:
You can use a simple checkout service like 2checkout.com, paypal, or Google Checkout.

Or you can use a service which has an affiliate network like regnow.  This will get your product onto hundreds and hundreds of sites, but it is extremely rare to ever have a sale on any of those sites.  In my experience 99.999% of sales came directly from my own company website.


问:
What to do when the programming activity becomes a problem?
I once saw a program (can't remember which) where it talked about people "experiencing flow" when they are doing something they are passionate about. When "in flow", they tend to lose track of time and surrounding, concentrating only on their activity at hand.

This happens a lot for me when I program; most particularly when I face a problem. I refuse to give up until it's solved. This usually leads to hours just rushing by and I forget to eat lunch, dinner gets pushed into far into the evening, and when I finally look at the clock, it's way into the wee-hours of the night and I will only get a few hours of sleep before having to rise early in the morning. (This is not to say that I'm in flow only when facing a problem - but I find it particularly hard to stop programming and step back when there's something I can't solve immediately.)

I love programming, but I hate it when it disrupts my normal routines (most importantly eating and sleeping patterns). And sitting still for so many hours, staring a screen, is not healthy.

Please, any ideas on how I can get my rampant programming activity under control?

答:
Set yourself goals for the night. I get the impression from the answers that you basically sit down, start working, get into a flow and just keep going.

It's as much a time management problem as it is a self control problem - write down the things you're trying to achieve (nothing mental, don't bother with software, stick these tasks on post it notes, etc). Scribble an estimate against them - i.e. "Write feature X, should take an hour". Maybe even add a 'difficulty' score so you can get a feel for the potential problems you'll run into and how badly you'll fall into your flow and lose time.

Before you start working that evening work out how many hours you can spend and pick tasks that fit into that time slot - this is especially important (i.e. "I have two hours spare, i'm going to grab two 1 hour easy tasks, or a single 2 hour difficult task").

This is, in essence what I do now. I had a similar problem to you - in the end I realised that losing this time was a result of simply not anticipating problems or knowing the effort required for the task. As soon as I started thinking about this at the start and breaking my project down into really small little taks, it became much more manageable.

I will add a caveat to this though; Flow is a Good Thing (tm), and estimating is guessing - sometimes it just happens. What you're looking for a balance and managing your tasks better would give you this.


答:
In addition to the advice given in the other answers, I would suggest using static analysis tools (Wikipedia has a list of a number of static analysis tools for various languages) to find potential defects before testing begins as well as monitoring some metrics that relate to the testability of code, such as cyclomatic complexity, the Halstead complexity measures, and cohesion and coupling (you can measure these with fan-in and fan-out).

Finding hard to test code and making it easier to test will, well, make it easier for you to write test cases. Also, catching defects early will add value to your entire quality assurance practices (which include testing). From here, getting familiar with unit testing tools and mocking tools will make it easier for you to implement your testing.


答:
Personally, I would write the same code as this:

```<code>///Converts the image to formatABC to save x% space
void DoSomeInterestingImageManipulation(char *pImage) {
    //Handle need for internal decompression
    if(pImage && pImage[0] == 0xFF) {
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}
</code>```

If you have to comment what something does, then write it before that something. Some people prefer to just read your code and will only be distracted by your comments. Some might want to read your comments and not have to search them within you code.

Also, keep comments as sparse, short and clear as possible. If you have the feeling that you have to save some of the lines occupied by the comments, than consider making shorter comments or removing them entirely and choosing self-explanatory identifiers instead.

Body:
Personally, I would write the same code as this:

///Converts the image to formatABC to save x% space
void DoSomeInterestingImageManipulation(char *pImage) {
    //Handle need for internal decompression
    if(pImage && pImage[0] == 0xFF) {
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}

If you have to comment what something does, then write it before that something. Some people prefer to just read your code and will only be distracted by your comments. Some might want to read your comments and not have to search them within you code.

Also, keep comments as sparse, short and clear as possible. If you have the feeling that you have to save some of the lines occupied by the comments, than consider making shorter comments or removing them entirely and choosing self-explanatory identifiers instead.


答:
I would not recommend that style as it makes it difficult to scan for braces.

```<code>void DoSomeInterestingImageManipulation(char *pImage)
{//This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {//Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}
</code>```

Look at the end braces and tell me where the block begins.

Now do the same for this one:

```<code>void DoSomeInterestingImageManipulation(char *pImage)
{
    //This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {
        //Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}
</code>```

Can you tell me where the start more easily?

Body:
I would not recommend that style as it makes it difficult to scan for braces.

void DoSomeInterestingImageManipulation(char *pImage)
{//This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {//Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}

Look at the end braces and tell me where the block begins.

Now do the same for this one:

void DoSomeInterestingImageManipulation(char *pImage)
{
    //This will convert the image to formatABC which allows x% space savings for storage
    if(pImage && pImage[0] == 0xFF)
    {
        //Process the extra case where image internal format needs decompression
        ++pImage;
        //...
        //...
        //...
    }

    //Proceed normally
    *pResult = Foo(pImage);
}

Can you tell me where the start more easily?


问:
Ideas on writing a meaningful resume which is not a compilation of buzz words?
I'm am about to commence redesigning my resume all over. What I'm stuck with is where should I  draw the line between writing everything down and writing too little.

I don't want my resume to be a pack of buzzwords nor do I want to seem to not know any of the things I do know.

Keep these thoughts in mind and wanting to write a meaningful resume, how do I go about it. Someone reading my resume should be able to tell if I'm a hacker culture person or someone who went to computer school just for the heck of it.

Edit: In view of answer majorly focusing on buzzwords I would like to point out I'm also looking for things that make my resume more meaningful - I want the reader to be able to tell the difference between a hacker person and just another guy who went to computer school.

答:
Having had the experience of reading many resumes to find the candidates we wanted to interview, and then finding myself on the other side trying to get my resume read, here are a few pointers:

You have 20 seconds to catch your audience!

Resumes are first skimmed.

After ~20 seconds, the reader will either put your resume aside or continue reading.

Catch the reader's attention in that time and convince them to read further.

Keep things short, concise and easy to skim.

Buzz Words work, but they do become overused.  (How many people are "creative"?)

Use action words and an active voice

Don't lie in your resume, but be aggressive

"I was part of a team that architected the XYZZY" vs. "XYZZY system architect."

With the plethora of digital resume scanning tools, you may want to consider adding a list of buzz words / technologies at the end of your resume.  I was getting no hits on my resume until I added another page just listing the technologies I had used, even if I had only done them in passing.  As other replies have said, you also need to be prepared to defend what you wrote.

Last, but not least, consider writing a "Marketing Plan" for yourself.  Your resume says where you have been.  A Marketing Plan says where you are heading.


答:
I like the style, and would actually go one step further and put a comment on the closing brace to indicate what it is closing.

The only major change I would make is to make sure the opening brace is a little more obvious by putting space after it.

```<code>while (!fruitList.isEmpty())     // while there is fruit
{                                // ... do something with it
    Fruit fruit = fruitList.takeFirst();

    switch (fruit)
    {
    case apple:
        MakeAppleSauce();
        break;

    case banana:
        MakeBananaBread();
        break;

    case grape:
        MakeWine();
        break;

    default:
        // Don't do anything (for now)
    }   // switch (fruit)
}       // while (!fruitList.isEmpty())
</code>```

Body:
I like the style, and would actually go one step further and put a comment on the closing brace to indicate what it is closing.

The only major change I would make is to make sure the opening brace is a little more obvious by putting space after it.

while (!fruitList.isEmpty())     // while there is fruit
{                                // ... do something with it
    Fruit fruit = fruitList.takeFirst();

    switch (fruit)
    {
    case apple:
        MakeAppleSauce();
        break;

    case banana:
        MakeBananaBread();
        break;

    case grape:
        MakeWine();
        break;

    default:
        // Don't do anything (for now)
    }   // switch (fruit)
}       // while (!fruitList.isEmpty())


答:
but we don't have testers at my current employer and my colleagues seem to be pretty good at this

Your colleagues must be truly exceptional to not follow TDD or unit test and never generate bugs so on some level I doubt that they are not performing any unit testing themselves.

I am guessing that your colleagues are doing more testing than is being let on but because this fact isn't known by management then the organization suffers as a result because management gets the impression that true testing is not being performed and bug numbers are low thus testing is unimportant and time will not be scheduled for it.

Talk to your colleagues and try to figure out what kind of unit testing they are doing and emulate that.  At a later time you can prototype better ways to unit test and TDD attributes and slowly introduce these concepts to the team for easier adoption.


问:
How to commit in-progress refactoring?
So, I have this big project, which is in the process of being refactored by me. I am changing a lot of stuff, so there is no chance to get it to compile some time soon. I am living in a special git branch which I named cleanup (which is going to get merged into master eventually, of course).

The problem is, that I/we have the policy to never commit non-compiling code (ideally it should also work, but it must compile and link, at the very least). So, until I am finished with this huge task, I am unable to commit anything (for review or for bookkeeping).

This is not the way I like to work (I believe most people commit at least once a day or so).

What do you think? Is there a solution I am overlooking?

Can I later tell git to aggregate commits or something? I could live with non-compiling commit as long as they stay in the cleanup branch.

Edit

To the subject of pushing/committing: I am aware that it is a huge difference, but later, there will be broken revisions, when I merge my stuff into master. So if you browse through the history (or git bisect ...) then the "local" revisions will be world accessible. So only committing locally and not pushing is not the best solution, because it will cause you trouble later on (when the subject is closed and forgotten for some time).

In short: Local commits will be pushed eventually. The global history should not show non-compiling commits.

答:
You are using Git, thus committing does not necessarily imply pushing your changes....

IMHO, and working with Git, it is perfectly good to commit your work, even if it does not compile... because, after all, once you commit your changes, no one will have the code available (until you push it). Of course, before pushing it, you must ensure it works well and compile, so that others can fetch and merge your changes without any problems.

Also, you are working on a different branch than the master one. So, if you want (and I recommend this), you won't push your branch ever. Once you have finished the refactoring, just checkout master branch, merge your changes and push master branch.

Edit

In that case you can use git cherry-pick or play around with git rebase

Title: How to commit in-progress refactoring?


问:
How do I improve my coding skills?
Here's a bit information about me, before starting with the question.

I am a Computer Science Undergraduate, Java being my primary coding language.

The basic problem in my University are the teaching standards. No one is concerned about teaching coding knowledge to students, rather than just theoretical knowledge.

The effect being, most of my fellow college mates don't understand programming at all.

Even I haven't been able to come out of the traditional programming environment, which limits my coding to an extent.

What are the possible ways by which I can develop and expand my programming/coding skills.

Also, can you suggest the sources for the same?

Edited:
Sources suggesting development of coding skills.

答:
My suggestions

Find a pet project and write it in a different language(lyke python/c#) to the one you know. This will teach you more than you can imagine. Look at other projects that are similar and try to get feature parity with them. You can go slow with this and have modest goals, steadily increasing your difficulty level with new features. This also becomes your show piece whn you go for a job interview.

Find uses in your project for relevant technologies like web services, javascript, ajax, geocoding and basically anything that is making headway in the software world.

Play with other operating systems like Linux/freebsd. The more exposure you get to different kinds of systems the more you will understand the thinking behing them, and why they did things in the way they did.

When your done with parts of your code go back to it and try to improve it constantly. Find ineffiencies, add more comments when needed, try to perfect it.

Dig around at c2.com. There are a lot of good coding practices. Learn these and try to apply them in your own project.

Read books like the pragmatic programmer and code complete, they will give you the knowledge of battle hardened programming.

This may sound unrelated, but find another technical hobby if you don't have one already like racing RC cars, playing a musical instrument or learning a foreign language. The more pieces of your brain are in use the better, and you need to unwind from time to time because programming can get too much.

Title: How do I improve my coding skills?


问:
What is the limit to the number of a class methods?
In different design books that I read, sometimes big emphasis is put on the number of methods that a class must have (considering an OO language, as java or C# for instance). Often the examples reported in those books are very neat and simple, but rarely they cover a "serious" or complex case.

However the range seems to be between 5 and 8.

In a project I developed a class "Note", with its attribuse as properties: Title, Desctiption, CreateDate, etc.
 Then some basic methods like: getRelations (if the note is assigned to different documents), getExpiryDate, ect.

However proceeding in the development of the application, more functionalities were required, and, therefore, more methods.

I know that the less methods a class has, the more loosly coupled it is. That is indeed a good advantage in terms of modularity and reusability, plus easier to edit.

By the way if in our context there is no need (or even sense) to create sub-classes and all the needed functions are related to that class, how many methods can we further attach?

I agree that having more than 15 methods, then maybe a little re-design might be required.
But even in that case, if deleting some of the methods or inheritance is not an option, which would be the proper way?

答:
The answer is really simple: Put everything in a class that belongs to its responsibilities, but be careful when assigning responsibilities.

Sometimes a big class is a composite of smaller classes with different responsibilities.

In general, I try to divide the responsibilities into smaller classes when the class becomes unwieldy in its usage or in maintenance. I seldomly have classes that are longer than 500 lines. My biggest classes have approximatelly 1.5k locs.

You simply cannot state a general rule like "a class should have between n and m methods".


答: Have as many methods as you need. I would try to keep down the number of public methods to that 5-8 rule if possible. Honestly, most people have the opposite problem where they have crazy super-methods that need to be broken out more, not less. It really does not matter how many private helper methods you have. In fact, if you stayed below 8 methods in Java you could hit the limit with a class that only had a constructor, a toString, and the getter/setter for 3 properties...which is not exactly a robust class. The bottom line is, do not worry about how many methods your class is. Worry about making sure your class does not take on unrelated concerns, and that you have a reasonable public interface that has easy to understand methods.

Title: What is the limit to the number of a class methods?

Body:
In different design books that I read, sometimes big emphasis is put on the number of methods that a class must have (considering an OO language, as java or C# for instance). Often the examples reported in those books are very neat and simple, but rarely they cover a "serious" or complex case.

However the range seems to be between 5 and 8.

In a project I developed a class "Note", with its attribuse as properties: Title, Desctiption, CreateDate, etc.
 Then some basic methods like: getRelations (if the note is assigned to different documents), getExpiryDate, ect.

However proceeding in the development of the application, more functionalities were required, and, therefore, more methods.

I know that the less methods a class has, the more loosly coupled it is. That is indeed a good advantage in terms of modularity and reusability, plus easier to edit.

By the way if in our context there is no need (or even sense) to create sub-classes and all the needed functions are related to that class, how many methods can we further attach?

I agree that having more than 15 methods, then maybe a little re-design might be required.
But even in that case, if deleting some of the methods or inheritance is not an option, which would be the proper way?


答:
There is no reason (in OO design) for having only so many methods. It is also not true that a class with less methods is better decoupled.

Look at the java.lang.String class, for example. Lots of methods, because there are so many things one can do with a string. Nevertheless not coupled strongly.

I wonder why a magic number like 15 could separate good and bad design. No, it's not that easy.


答:
Personally, I have never seen much point in "saving vertical space" for its own sake. We have plenty of vertical space. There are applications out there that use milions of lines of vertical space.

If some method gets too big vertically, it means it should be split. Putting more and more stuff in same lines is not a solution, it's just hiding the problem. The readability of the style you suggested is poor in my opinion.

Instead of:

```<code>if(pImage && pImage[0] == 0xFF)
{//Process the extra case where image internal format needs decompression
    ++pImage;
    //...
    //...
    //...
}
</code>```

Just:

```<code>if(pImage && pImage[0] == 0xFF)
{
    processDecompressableImage(pImage); // separate method. self-documenting.
}
</code>```

Body:
Personally, I have never seen much point in "saving vertical space" for its own sake. We have plenty of vertical space. There are applications out there that use milions of lines of vertical space.

If some method gets too big vertically, it means it should be split. Putting more and more stuff in same lines is not a solution, it's just hiding the problem. The readability of the style you suggested is poor in my opinion.

Instead of:

if(pImage && pImage[0] == 0xFF)
{//Process the extra case where image internal format needs decompression
    ++pImage;
    //...
    //...
    //...
}

Just:

if(pImage && pImage[0] == 0xFF)
{
    processDecompressableImage(pImage); // separate method. self-documenting.
}


答:
I've never seen such an unreadable piece of code.

All those comments between code lines will only get in the way. You should write self-documented code and perhaps considering a comment before the function.

Then, if you really have the need to have comments between code lines, at least write them before an important (or not so easy to understand) piece of code, in an empty line and with the same padding as the code below.

Edit

To clarify, even with syntax highlighting the comments look out of place to the code itself, because of missing paddings.

For a better readability, paddings and empty lines are great at separating different portions of code. Together with syntax highlighting, you obtain a greater code readability.


答:
Ruby on Rails has a significant learning curve. First you have to learn the oddities of the language, then learn the framework, then learn the Rails Way of doing things, then learn about the many commonly used Gems.

However, when you have learned those things, it does come incredibly naturally. In fact other frameworks start to feel like a burden.

Rails is very TDD/BDD-oriented, so if you are not then that's two more things you'll have to learn before you become a competent Rails programmer. You don't have a compiler and IDEs to back you up, so test coverage is very much your fallback.

Many TDD advocates, myself included, would consider this one of the strengths of RoR, as well as its curse. Once you start to write TDD, you find that the security offered by test coverage is better than the security offered by a compiler. Then having to write code JUST to please a compiler becomes burdening.

TDD doesn't feel like an additional task in RoR, it feels like the only way to work.

Rails has one serious performance problem: each request is queued up behind the currently active one, as opposed to threading them as most frameworks do or allowing blocking events to free other requests as the like of Node.js and Twister do. This means you have to code to make response times fast, but that's quite easy to do in most cases.

Rails is also very much designed to handle content systems very well, which in fairness is a lot of the internet. Doing something a little more complicated, such as a web game or an ecommerce system, means learning new gems. You quickly learn that all the gems are out there, but the more obscure the thing you want to do, the harder it will be to find good documentation.

Title: Ruby on Rails downsides and caveats

Body:
This is not an opening gambit for RoR bashing - honest!

I'm learning Ruby and the Rails framework. Prima facie it appears to be pretty cool, and a wonderful experience compared to PHP. (In fact, it's reminding me of happier days with C# and .NET.)

However, going into this, I have no experience with this framework or language, and I'm curious - what are the current downsides or things you'd wish you'd known when you were beginning?

(Maybe this should be made a community wiki?)


答: Check out the manual page for git rebase, particularly the git rebase -i variant. It allows you to re-order, delete or squash together any number of commits in your history, which sounds like what you are looking for. I use it all the time in exactly the situation you describe: making many small commits which are not suitable for public consumption, then squashing them together into a single "refactoring" commit before pushing to the shared repository.

Title: How to commit in-progress refactoring?

Body:
So, I have this big project, which is in the process of being refactored by me. I am changing a lot of stuff, so there is no chance to get it to compile some time soon. I am living in a special git branch which I named cleanup (which is going to get merged into master eventually, of course).

The problem is, that I/we have the policy to never commit non-compiling code (ideally it should also work, but it must compile and link, at the very least). So, until I am finished with this huge task, I am unable to commit anything (for review or for bookkeeping).

This is not the way I like to work (I believe most people commit at least once a day or so).

What do you think? Is there a solution I am overlooking?

Can I later tell git to aggregate commits or something? I could live with non-compiling commit as long as they stay in the cleanup branch.

Edit

To the subject of pushing/committing: I am aware that it is a huge difference, but later, there will be broken revisions, when I merge my stuff into master. So if you browse through the history (or git bisect ...) then the "local" revisions will be world accessible. So only committing locally and not pushing is not the best solution, because it will cause you trouble later on (when the subject is closed and forgotten for some time).

In short: Local commits will be pushed eventually. The global history should not show non-compiling commits.


答:
In PMD, the default behavior of the TooManyMethods rule is to identify and flag classes with 10 or more methods as potential errors. This is just an arbitrary number, though. It's easily changed in a configuration. Regardless of what this number is, it's just a flag for a developer to look at a class and see if there is an issue, not that there is a problem with it.

Something that is a little more concrete might be the 7 plus/minus 2 rule. This states that the human mind can hold and comprehend between 5 and 9 "objects" in memory. When reading a particular class, the objects would most likely be the methods and fields that make up that class. However, classes frequently have more than 9 fields and methods, even if you don't count accessors, mutators and any standard operations (for example, toString(), hashCode(), and equals() in Java).

The most relevant measures would be of fan-in and fan-out and discussions of coupling and cohesion. The single responsibility principle and separation of concerns should be applied - a class should do or represent one thing and one thing alone. These are far better than trying to assign numbers to maximum/minimum number of methods when assessing a design or implementation.


答:
Include briefly the projects that you have worked on and the role you played in them too. This will help demonstrate your experience.

And as Kevin also states, include the things you introduced into the team/environment. This shows that you've got initiative and can not only code but also contribute to the evolution of  a team.

Title: Ideas on writing a meaningful resume which is not a compilation of buzz words?

Body:
I'm am about to commence redesigning my resume all over. What I'm stuck with is where should I  draw the line between writing everything down and writing too little.

I don't want my resume to be a pack of buzzwords nor do I want to seem to not know any of the things I do know.

Keep these thoughts in mind and wanting to write a meaningful resume, how do I go about it. Someone reading my resume should be able to tell if I'm a hacker culture person or someone who went to computer school just for the heck of it.

Edit: In view of answer majorly focusing on buzzwords I would like to point out I'm also looking for things that make my resume more meaningful - I want the reader to be able to tell the difference between a hacker person and just another guy who went to computer school.


答:
Depending on how you look at it, the speed with which Rails changes may or may not be a caveat for you. Things change somewhat radically from year to year as more is grokked out of what sucks and needs solutions.

If you're in active development, you'll have your finger on the pulse of this however.

Title: Ruby on Rails downsides and caveats


答:
Your justifications make no sense to me. I'm not sure why you'd want to save vertical space unless you plan to print it out all the time (and why would you do that) because the net result is less legible code on the screen. I don't see that as productive. Secondly, how do you plan to avoid leaving a hint of how/why something was done without a comment of some description? It's not the location of the comment that gives that information, it's the content. It's possible to construct comments in a more legible manner than this and there are  a number of examples posted already.

I don't know why you developed this habit - maybe it is something like a signature for you. Additionally, being used to it, you may find it easier to read now. However, I don't really find it particularly legible as code goes.

The short answer to your question is it's harder to read.


答:
What about:

```<code>void DoSomeInterestingImageManipulation(char *pImage)
{
    convertToFormatAbc(pImage); // allows x% space savings.
    *pResult = Foo(pImage);
}

void convertToFormatAbc(char *pImage)
{
    if (internalFormatNeedsDecompression(pImage))
    {
        decompress(pImage);
    }
}

boolean internalFormatNeedsDecompression(char *pImage)
{
    return pImage && pImage[0] = 0xFF;
}
</code>```

The point that I want to illustrate is that you should aim to have self-documenting code. That will require very few comments, if at all. If you need comment, always go for readability, not screen space savings.

In my opinion, comments above or at the beginning of a block of code simply means that this should be a method/class of its own.

Body:
What about:

void DoSomeInterestingImageManipulation(char *pImage)
{
    convertToFormatAbc(pImage); // allows x% space savings.
    *pResult = Foo(pImage);
}

void convertToFormatAbc(char *pImage)
{
    if (internalFormatNeedsDecompression(pImage))
    {
        decompress(pImage);
    }
}

boolean internalFormatNeedsDecompression(char *pImage)
{
    return pImage && pImage[0] = 0xFF;
}

The point that I want to illustrate is that you should aim to have self-documenting code. That will require very few comments, if at all. If you need comment, always go for readability, not screen space savings.

In my opinion, comments above or at the beginning of a block of code simply means that this should be a method/class of its own.


答:
The git merge --squash command allows you to create a single commit on top of the current branch whose effect is the same as merging another branch.  The command updates the working tree and stages the changes in the index, so all you have to do next is commit:

```<code>git checkout master
git merge --squash cleanup
git commit -m "Merge cleanup branch"
</code>```

The git rebase -i command can also squash commits but requires more work.

Title: How to commit in-progress refactoring?

Body:
The git merge --squash command allows you to create a single commit on top of the current branch whose effect is the same as merging another branch.  The command updates the working tree and stages the changes in the index, so all you have to do next is commit:

git checkout master
git merge --squash cleanup
git commit -m "Merge cleanup branch"

The git rebase -i command can also squash commits but requires more work.


答:
This is from experience learning, continuing to learn, and writing a relatively simple application in Rails.

1) Learning Curve

Rails is deceptively simple.  The tutorials, videos, and books all demonstrate how quick you can get a working (if ugly) application, but these really just scratch the surface.  They tend to heavily rely on code generation and "scaffolding" which admittedly is a good tool when learning but quickly outlives its usefulness.

Make no mistake, Rails is hard to master.  Once you get past the very basics (more on this later) you will run headlong into a wall if you need to do more than the extremely simplistic "demo app" functionality that you see touted.  You can get by with a basic knowledge of Ruby while learning, but you quickly need to pick up Ruby or you'll be left high and dry (and not the good kind of DRY) if you need to go outside the Rails constraints.

Rails is, as I like to call it in a loving way, paint by numbers programming.  If you stick 100% to the conventions (i.e. stay within the lines and use the colors you're told to use) you can make decent applications quickly and easily.  If and when you have to deviate though, Rails can go from your best friend to your worst enemy.

2) When All You Have Is a Hammer...

Rails does simplistic CRUD applications very well.  The problem comes when your app has to do more than just read/write from a database.  Now, for the record the last Rails version I used was 2.3.4 so things may have changed since then, but I ran into major issues when business requirements changed so the application had to have a small workflow system built into it, and integrate with a legacy PHP application.  The Rails convention of "one form, one model" works fine for trivial apps and data entry applications, but not so much when you need to do processing logic, or have workflows, or anything that isn't the typical "User enters data into a few text fields, hits Submit" type of thing.  It can be done, but it's by no means "easy", or rather it wasn't when I last used Rails.

Also, Rails does not like to play well with other applications that aren't using it's preferred methods of data access; if you have to interface with an application that doesn't have a "Web 2.0" style API, you have to work around Rails instead of with it; again I speak from experience here as this is what happened to me.

3) It's New

Finally, Rails is still the "new kid on the block" in many areas.  This doesn't matter for personal use or "I think it's cool and want to learn it" type of scenarios, but speaking as someone who would prefer to use Rails at my day job, if you aren't in a location where Rails is widespread, it can be very difficult to find fulltime work as a Rails developer.  It's still largely the domain of "hip, new startups" and not a major player in most metropolitan areas.  Your mileage may vary in this regard, but I know my area (Tampa) Rails is essentially nonexistent.

4) Fire and Motion

Rails is ever-changing.  This is both a good and a bad thing; it's good because the community evolves and embraces new concepts.  It's bad because the community evolves and embraces new concepts.  It can be very overwhelming for a Rails newbie because typically when you run into an issue, and look around, you'll see either people recommending such-and-such gem to fix it, or saying that way is bad anyways and you shouldn't use it, here's a better way... and you end up having a laundry list of additional tools to learn along with Rails to keep up with the Rails cognoscenti.  Things like Git, BDD/RSpec, Cucumber, Haml/Sass, and a cornucopia of other things all float around and get pushed as the "right way to do things" in Rails-land, and speaking from experience you may end up being swamped trying to learn a dozen or more technologies in addition to Rails, because using the standard Rails toolkit feels "wrong".

This is now compounded even more by Rails 3.1 making Sass and CoffeeScript of all things the default, so a total Rails newbie not only has to learn Ruby and Rails but Sass (arguably simple if you know CSS) and CoffeeScript (not crazy difficult but certainly different enough from raw JavaScript) at a bare minimum to get started, plus it can be assumed Git.  Even without factoring in RSpec and friends, and the dozen or more gems that you'll typically end up with, that's 4 different things you have to learn before you can seriously begin to write Rails applications.  Compare this to a language like C#, or Java, or even PHP where your HTML/CSS/JavaScript/SQL knowledge isn't going to change and you just have to learn the language itself and perhaps the framework nuances.

Title: Ruby on Rails downsides and caveats


问:
Is it better to have separate Create and Edit actions or combine Create and Edit into one?
We are using ASP.NET MVC 2 with a Controller/View Presentation Layer and Model consisting of A Business Logic Layer, Data Access Layer [Stored Procedures and classes/methods to talk to the stored procedures].

In the business layer and above for most purposes Edit seems to be capable of representing both the creation of an object and the editing of an object. This coincides well with our Repository Design Pattern that defines a "Save" method. We can simply check in the stored procedure if the ID is 0 and then create a new object if it is 0 otherwise we can just update the existing object, since the category id should match one.

The primary point of discussion is if it makes the most sense to split Edit that includes Creation into it's separate parts of Create and Edit beyond the DAL layer.

An obvious example can be shown as routes:

Create - http://someurl/somearea/edit/0

Edit - http://someurl/somearea/edit/254

vs.

Create - http://someurl/somearea/create

Edit - http://someurl/somearea/edit/254

Are there any established standards or best practices in regard to this?

I know this is a small detail, but I think it's logistically an important one.

答:
I usually prefer to create one Save method in the DAL, but actually implement the Create/Edit/Delete separately.

For example, my Save method would check the Object State, and call the Create/Edit/Delete method depending on what is needed

```<code>switch(obj.State)
{
    case ObjectState.New:
        CreateObject(obj);
        break;
    case ObjectState.Modified:
        UpdateObject(obj);
        break;
    case ObjectState.Deleted:
        DeleteObject(obj);
        break;
}
</code>```

This allows me to just call one generic method for saving any object, but still keeps the implementation of each (Create, Edit, Delete) separated.

Body:
I usually prefer to create one Save method in the DAL, but actually implement the Create/Edit/Delete separately.

For example, my Save method would check the Object State, and call the Create/Edit/Delete method depending on what is needed

switch(obj.State)
{
    case ObjectState.New:
        CreateObject(obj);
        break;
    case ObjectState.Modified:
        UpdateObject(obj);
        break;
    case ObjectState.Deleted:
        DeleteObject(obj);
        break;
}

This allows me to just call one generic method for saving any object, but still keeps the implementation of each (Create, Edit, Delete) separated.


答:
Documentation.

While Rails Guides are great learning resource, Rails (and Ruby, generally) library reference is not easy to navigate. Say, you want to learn more about belongs_to method. Although it is used on ActiveRecord::Base subclasses (one's models), it's not documented in ActiveRecord::Base docs, but in a mixin that the class imports. Essentially, you can not see a comprehensive list of all methods that you can use on an object in one place (except when you fire up irb and check the object itself).

With a highly dynamic language as Ruby, it is not straightforward to tell where a method you are using comes from. It can be a problem, especially for learning programmers trying to get a grasp on a new technology stack.

Title: Ruby on Rails downsides and caveats


问:
What are the non-technical reasons that make Object-Relational Mapping tools (ORMs) so difficult to write?
I know the technical pitfalls of writing an ORM are pretty well-known nowadays, but what are some non-technical factors (e.g., Scope) that make it difficult to writing a good ORM?

I have already read the technical reasons for why ORMs are so difficult to write from this Stackoverflow post: https://stackoverflow.com/questions/404083/is-orm-still-the-vietnam-of-computer-science

答: I think the Object relational impedance mismatch is the big problem. OO is not relational. For example, where does relational theory describe inheritance. Also smaller (but big issues) like if the programming language doesn't support nullable types. How do you map that to a nullable column in the database?</p>


答:
Write your tests before you write your code.

Any time you fix a bug that wasn't caught by a test, write a test to catch that bug.

You should be able to get coverage on what you write even if your organization doesn't have full coverage. Like so many things in programming, the experience of doing it again and again one of the best ways to be efficient at it.


答:
I think lists of nouns (buzzwords or not) are ineffective. I would NOT write this section:

Web Technologies: Faceted Search, Zend, PHP, jQuery, HTML5, CSS

Weave those nouns into stories to satisfy both human readers and OCR scanners. Compare:

Web Experience

Created a faceted search system using the Zend framework (PHP) for a local library

Implemented an HTML5 and CSS compliant UI based on wireframes from designers

Improved responsiveness and lowered load time via jQuery Ajax calls

Both sections are packed with "buzzwords", so they pass any automated scans, but the second tells the human reader a story of why and how you use the technologies in question. To me, that's meaningful - and technical readers will start to appreciate what you know about the buzzwords in play.

Another class of buzzwords: "creative", "cooperative", "results-oriented"... I wouldn't include any of these. Those add no value to a resume with accomplishments like the Web Experience section above. Obviously you're creative, cooperative, and results-oriented from stories like those!


问:
Is it efficient to attach a comment on every function?
I moved to this company recently, and my first reaction of the development process leaves me with doubts.

Here is where I really doubt the efficiency:  Every single function must have Javadoc style comment, and the code is tested by White-box Test automatically.
Even when I write simple & short function, the function must have a Javadoc style comment.

For example:

```<code>void request_ait(void)
{
      hoa_request_ait();
}
</code>```

If I write code without a Javadoc style comment, even for this simple function, the QA tool register it as a defect.  So I write a simple comment template.

For example:

```<code>/**
  * @author peter
  * @version 1.0
  * @since   2011-08-28
  */
    void request_ait(void)
    {
          hoa_request_ait();
    }
</code>```

I know that comments on API functions or important functions are really useful. But forcing every function to have a Javadoc style comment is inefficient...

I want to listen your opinion.

Am I wrong?

答:
The problem with these kinds of policies is that they cause developers to use macros in their code editors to add comment templates to all new methods. These comment templates never contain useful information, which defeats the purpose of the policy.

It makes sense to put Javadoc-style comments on public methods, because they will be used by other developers, teams, customers, etc. who aren't familiar with the internals of the codebase. However, putting them on private methods that are only used within a class is overkill, especially if those methods are short and well-named, and the class itself is well-designed.

OwnerDisplayName: sunglim


问:
How do you manage workflow tasks for a distributed team?
I work for a small software company which is responsible for delivering roughly a thousand custom software packages for roughly 100 customers.

We are struggling at tracking the release process. The entire thing is pretty repeatable but, because of the different distribution processes, there are about 2 dozen steps from the time we sign a contract to the point a product goes out the door.

To make matters more complicated, we have a few different 'types' of employees that are involved. We have a sales person who gets all requirements and deal terms. We have developers who do any modifications required by the customer. There is another type of employee which does the work of running the final build, testing and distributing the product.

I'm looking for ideas on how people manage these sorts of processes as we look to fix some issues which have been plaguing us for a while. Primarily, we are seeing a lot of issues sequencing the events AND communicating the information associated with each product to the build/distribution team.

Currently we use SVN(SCM), Jenkins/Hudson(Build) and Redmine(Feature/Bug Tracker).

Are there software solutions or is this just an internal process we have to document and understand? I'd really like to find a way to keep everyone aware of what the status of a particular app is and notify people that they are expected to do something.

答:
If it means anything to you at all then please note that you are not alone in this problem.  The last couple companies and the one I am at now struggle with this very problem.

Your company likely has software that they would like to be as "out-of-box" as possible but in reality each one of your clients have unique needs which DEMAND custom software.  Lets face it, the salesperson pitches out-of-box and the developers deliver custom software.

The way that we handle it is DOCUMENTATION and formulating a special team of high level software developers to be the "Build" team.  This team's responsibilities besides maintaining in house builds and environments for the different client solutions is to be the ones responsible for working with the clients to give them releases and assist in special deployment instructions (Again documentation...).

Further if you do not have an internal Wiki or Sharepoint document management system, GET ONE.  This would be an exceptionally helpful and public repository for maintaining such documentation.


问:
What are the most common algorithms in the field of computational geometry?
So far I've touched on various aspects of computational geometry including constructive planar geometry (locus intersections), algorithms for planar graph topologies, 3D DDA, and most recently a 2D convex hull implementation using Graham's Scan and k-means clustering represented as Voronoi diagrams.

It's a fascinating field. I'm interested to know more. I would like to know which algorithms are most common in this field, and what they do.

答:
I'm unable to create a list of most used in the field, I know only the ones I used :) But a good place to look for is in the O'Rourke book Computational Geometry in C. It was the book my University adviser asked to go through as a way to get acquainted in the field.

The same author, O'Rourke, has a computational geometry handbook if I recall correctly.