问:
Custom graph comparison?
I'm trying to compare two graphs using hash value ( i.e, at the time of comparison, try to avoid traversing the graph )
Is there a way to make a function such that the hash values compared can also lead to determining at which height the graphs differ?
The comparisons between two graphs are to be made by comparing children at a certain level.
One way to compare the graphs is have a final hash value for the root node and compare them, but that wouldn't directly reflect at which level the graphs differ, since their immediate children might be the same ( or any other case ).</p>

答:
A cobbled together solution:

You could probably cobble something together where each level of the graph affected a different portion of the hash value. What you'd essentially be doing here is creating a separate hash value for each level and appending them in sequence.

e.g. For a 32-bit hash and graphs with 8 levels, each level could hash to 4 bits: 1st level => bits 1-4; 2nd level => bits 5-8; etc.

If the number of levels in your graphs isn't fixed/known, then you'll have to wrap this around. This wouldn't tell you exactly which level was different, but it would narrow down your options.

e.g. For a 32-bit hash and graphs with an unknown number of levels, each level could still hash to 4 bits: bits 1-4 would be affected by the 1st, 9th, 17th, ... layers; bits 5-8 would be affected by the 2nd, 10th, 18th, ... layers; and so on.

Why it's probably a bad idea:

The hash function I've described is a rubbish hashing function. I expect it would produce a lot of clashes, and poor distribution.

Using hash values to detect differences is only quicker if there is a difference. hash(A) != hash(B) tells you that A and B are different, but hash(A) == hash(B) does not tell you that they are the same. In the second case, you'll have to do a full comparison to be sure.

Some other possible approaches:

Take another approach. If the comparisons are too slow, run a profiler and see if there are other ways you can speed up the comparison: try using a different data structure for storing your graphs, etc.

Try a compromise:

Create a separate hash value for each level as well as one for the entire graph. Comparing hash values for each level is still going to be loads quicker than comparing every single node.

Instead of using a hash value to speed up your comparisons, create two objects with metadata about the graphs (e.g. # of levels, # of nodes on each level, etc.) and compare those.

Title: Custom graph comparison?


问:
Why is it good to split a program into multiple classes?
I'm still a student in high school (entering 10th grade), and I have yet to take an actual computer course in school. Everything I've done so far is through books. Those books have taught me concepts such as inheritance, but how does splitting a program into multiple classes help? The books never told me.

I'm asking this mainly because of a recent project. It's an arcade video game, sort of like a Flash game as some people have said (although I have no idea what a Flash game is). The thing is, it's only one class. It works perfectly fine (a little occasional lag however) with just one class. So, I'm just asking how splitting it into multiple classes would help it.

This project was in Java and I am the only person working on it, for the record.

答:
One of the benefits is re-usability. A program is basically a bunch instructions grouped together. You'd find that some of those instructions are suitable for other programs as well.

Let's say you make a jumping game. Later on when you decide to make a cannon game, you find  that the physics calculation you used in the jumping game comes handy here.

So instead of writing it again, or worse copy and pasting it into the new program, you make it into a class. So next time you make another game where the game mechanics requires physics, you could just reuse it. Of course this is oversimplified but I hope it makes sense.

ContentLicense: CC BY-SA 3.0


问:
What's your strongest opinion against functional programming?
Functional programming is one of the oldest programming paradigms. However it isn't used much in the industry compared to more popular paradigms. But it have largely been emphasized in academia.

What's your strongest opinion against functional programming?

答: With all due respect, I think your question is ill posed.  Functional programming is a tool, or rather a set of tools that are useful for solving certain kinds of problems.  Having an opinion about it only makes sense in the context of a specific problem or application.  Having an opinion against it in general, is like having an opinion against pliers or wrenches.</p>

ContentLicense: CC BY-SA 2.5


问:
Convention for writing Python without newlines or whitespace?
Is there a convention for writing Python when deprived of newlines and whitespace? For example, stackexchange comments, Twitter, text messages...</p>

答:
Short answer: No, there is no such convention.

Typical solution would be to use a pastebin service and link to you snippet there.

There are several services for that. You might want check this link: http://www.1stwebdesigner.com/freebies/paste-share-code-snippets/


问:
How to get motivation and time to learn outside of work?
I work 40 hours as a programmer, and by the time I get home, the last thing I want to do is code some more. However, I feel like I am not getting better, and I do love software engineering. So how do you guys find the time/motivation to improve your craft outside of work?</p>

答:
Working after coming home actually never worked out for me. What worked out (well, most of the times, not always) was working on hobby projects BEFORE going to work.

So, get up 1-2 hours earlier, grab some coffee, read a book or write some code.

(The  problem is that this requires a fair amount of discipline... still, I found it easier than coding late in the evening.)


问:
Who owns the code, who owns the algorithm, who owns the idea?
This question got me thinking what products of the programming effort belong to the employer, and what don't.

The two extremes are (0) the code - it apparently belongs to the employer and (1) the learned personal and technical skills. But what is in between? Who owns the pseudocode/algorithm? Who owns the general idea of the algorithm? Who owns the know-how that such an algorithm may serve some useful purpose (e.g. on this site questions are values, as well as answers)?

Also: Who owns an idea on the web?

答:
The only answer that's actually likely to be 100% correct is that it depends on your contract and local laws, talk to an IP lawyer to be sure.

My personal experience in the field leads me to believe the following:

Many contracts have clauses that say any actual work you do (i.e. code, documentation) belongs to your employer, sometimes during work hours, sometimes ALL the work you do for the duration of the contract.

Algorithmic ideas may be patented by the company or someone else, in which ownership is always clear.

If the "general idea" of an algorithm is actually covered by a patent (and it usually will be if it's written by decent patent lawyers), then it belongs to the patent-owner.

The know-how for a useful purpose of an algorithm isn't really own-able, unless it significantly deviates from the purpose of the algorithm as described in any existing patent, in which case you could conceivably get a patent for the new use, or get a license for the patented algorithm and develop a business model around it.


问:
How do you convince the client their application's backend needs a rewrite?
I have been supporting a LOB winforms application for a client the last 3 years. The application is built with a simple monolithic architecture and uses .NET 2.0.

The application is a core part of their operations and its longevity is paramount. It needs to evolve with their evolving business processes, as well as implement improved functionality etc....this brings me to believe that this application needs an overhaul of sorts on the back-end.

The problem is changing a back-end is "invisible"...i.e. the user never actually sees it. It's a quality of the system that is changing (stability, maintainability, reliability, longevity), not some functional requirement that will be easily seen...i.e. the ROI is not obvious.

There is a lot of new functionality to be added to the front-end as well (user experience). I am considering a strategy of changing the back-end over time...i.e. when making a change or adding a feature to the front-end, change those components in the back-end that are affected, eventually you get to everything.

How do I convince the client that we need to rebuild the back-end?

答: By showing them how they will either save money or make more money by doing this rewrite, and since you say it's critical to their operation - that they will not be inconvenienced in any way while the rewrite is going on.</p>


答:
If you discuss it the way the question is asked, you can't. What the client will hear is "bla bla bla, I want to play with a shiny new toy, bla bla bla, its going to cost you a heap of money, bla bla bla"

What you need to do it put in in context of whats important to them. "The backend is coming to the end of it's working life. If you want to continue to provide core services to your end users cost effectively, and have the ability to support the new features they will be expecting and take advantage of the faster and cheaper developmenent cycles provided by modern tools, you need to plan a migration path to a more modern platform that will scale well. I am more than happy to put together a proposal"

If you need to talk technology at this stage, you will (and should) loose. Plenty of mission critical systems were written 20 or 40 years ago, and despite the retoric, it's more cost effective to pay Cobol programmers than it is to rebuild it using [Insert latest buzz word/silver bullet here]

Read Things You Should Never Do, Part I

Title: How do you convince the client their application's backend needs a rewrite?

Body:
I have been supporting a LOB winforms application for a client the last 3 years. The application is built with a simple monolithic architecture and uses .NET 2.0.

The application is a core part of their operations and its longevity is paramount. It needs to evolve with their evolving business processes, as well as implement improved functionality etc....this brings me to believe that this application needs an overhaul of sorts on the back-end.

The problem is changing a back-end is "invisible"...i.e. the user never actually sees it. It's a quality of the system that is changing (stability, maintainability, reliability, longevity), not some functional requirement that will be easily seen...i.e. the ROI is not obvious.

There is a lot of new functionality to be added to the front-end as well (user experience). I am considering a strategy of changing the back-end over time...i.e. when making a change or adding a feature to the front-end, change those components in the back-end that are affected, eventually you get to everything.

How do I convince the client that we need to rebuild the back-end?


答:
when making a change or adding a feature to the front-end, change those components in the back-end that are affected, eventually you get to everything.

How do I convince the client that we need to rebuild the back-end?

These two statements seem at odds to me. A rewrite is very different then evolving an application such that it is different a year from now. A complete rewrite is almost a guaranteed failure.

You don't tell them you will be rewriting the back-end. You do exactly what you said before, fix the rotting code as you come to it. Eventually the back-end may evolve into something else but a complete rewrite means 1) Their "new" back-end won't be working for a long time 2) Their existing back-end won't be fixed for a long time. It's a lose-lose situation to do a complete rewrite.


答:
Well, what seems logical is that the code itself containing the business logic of the application / software should not be kept without permission of the company.

On the other hand if we talk about the Algorithm or Idea that may differ from above because an Algorithm is what you follow or develop to solve a particular problem that usually is not directly associated with the business logic of the application itself, like you had an issue with multiple files uploading and you created a function in you code and implement that also one may have some algo for user auth process or you have designed a custom function which gets name of the table and excluded fields from it and selects everything else from the table, this is your own creation I think you can use that.

Above all, that literally depends on the contract, what it says, though its mentioned in most contracts that you are not going to reuse the code but, I think its regarding the entire project, its main theme or idea. What a developer can reuse is a piece of code or logic he has developed to solve a particular issue.

If we are stuck to very strict rule regarding this then how can anyone justify reuse of even a facebook authentication process in multiple applications ? as we develop apps for different clients {who are actual owner of apps} and we use the same auth process for every app {mostly} then in this case before us our employer should answer for the reuse of the code

Title: Who owns the code, who owns the algorithm, who owns the idea?

Body:
This question got me thinking what products of the programming effort belong to the employer, and what don't.

The two extremes are (0) the code - it apparently belongs to the employer and (1) the learned personal and technical skills. But what is in between? Who owns the pseudocode/algorithm? Who owns the general idea of the algorithm? Who owns the know-how that such an algorithm may serve some useful purpose (e.g. on this site questions are values, as well as answers)?

Also: Who owns an idea on the web?


问:
Version control implementation advice on legacy websites?
Assuming no experience with version control systems, just local to live web development. I've been dropped in on a few legacy website projects, and want an easier and more robust way to be able to quickly push and revert changes en masse. I'm currently the only developer on these projects, but more may be added in the future and I think it would be beneficial to set up a system that others can use.</p>

答:
You've received many good suggestions in this post. Just add some comments and hope the info help you find a better version control tool.

Considering you are new to version control, I recommend a tool with good UI (more intuitive for beginners)

Provides the feature "web deployment".

Good IDE integration.

I also list some version control tools here for your consideration.

Open Source:

Git

SVN

Commercial:

SourceAnywhere

TFS (Express)


答:
Just to throw in a different perspective:

Although lots of people say, only coding teaches you coding, there are (fairly often) times I come home after coding for 8 hours and the last thing I would do is sitting (again) in front of my PC and code my own stuff.

Would it be better for my coding skills to do so? Maybe. Would it be better for myself? Don't know, everybody is different. Many different things may be more important than programming - children, girlfriend, family, hobbies, whatever.

I prefer the more theoretical stuff after work - read a book about some interesting stuff, learn some theoretical CS, whatever. Just not sit (again) in front of my pc.

Never done anything with databases? Read something about it. Computing complexity of algorithms? Dig into it. Functional programming? Crazy stuff to do. There are tons of stuff that may be done with only a sheet of paper and a book while relaxing on a beach.

Every now and then, I think for myself: Wow, building your own Video game would be fun. Then I pull out this big pile of paper and write all that awesome stuff together that comes to my mind. Then I go out for research, look for stuff I may use to accomplish my goals, build large theoretical buildings, throw them away, build new ones and so on. Will the idea ever go into code? Don't know. Maybe in 30 years when I'm retired :-)

One thing is important:

Be curious about new things. Even if you just read about all that crazy stuff, think to yourself: Where would this be really cool to be used? Which problems in everyday programming may it solve? Maybe one of this thoughts will escape and bring you to your home pc to hack it into code. But don't force yourself into it.

Title: How to get motivation and time to learn outside of work?

Body: I work 40 hours as a programmer, and by the time I get home, the last thing I want to do is code some more. However, I feel like I am not getting better, and I do love software engineering. So how do you guys find the time/motivation to improve your craft outside of work?</p>


答:
Get time and motivation?

Time: this is our precious resources. Work on its management

Motivation: point attention on fun and personal out-of-work passion. leave money away from your mind, they bring you to people that does not care about the real essence of the job.


问:
A programmer should concentrate on at least how many languages?
For me I am C# and Java person. I find these 2 languages are quite similar so its easier for me to crossover each other. I'm not sure if its good idea to pick up other different languages. Any thoughts?</p>

答:
This could become another specialist vs generalist debate in a sense.  Some people may spend a long time knowing one language to great depths which works fine for them.  Other people may like to know a little about a bunch of different languages which works fine for them.  Most people are between these two extremes.

If you want suggestions of languages to explore here are a few ideas:

Functional programming - Haskell or Lisp would be examples here and the paradigm shift can be a bit of a head turner to some extent.

Database specific - PL/SQL or T-SQL come to mind as something that may be useful if you want to do more back-end work with systems that require a database for some of its functionality.

UI web languages - ActionScript or Javascript would be examples here of languages used in Rich Internet Applications, though AIR can make some desktop applications use web calls in some cases like Twhirl using the Twitter API.

These are just ideas and depending on where you want to be these may be useful or useless to you.  Good luck with whatever choices you make.


问:
Am I getting Scheme wrong?
Inspired by the numerous posts about the importance of learning Lisp/Scheme I started to learn Scheme two days back, I am using the book "The little Schemer" and have completed half of it.

But I still haven't learned anything new, the book teaches about recursion which I already understand and uses lambda (which I can think of a way to define a function in C). I still haven't got the concept of functional programming (please point to some example of functional compared to normal programming methods in C/C++ so I can get it).

Am I learning in the wrong way? or is "The little Schemer" for a newbie in programming and I should look for some other books?

答:
The best way to get the taste of functional programming is to write programs.

For example, write a simple XML parser in C++ and scheme. (and do not use mutable variables in scheme).

Or solve some euler-project problems in scheme/haskell/ocaml/whatever.

Title: Am I getting Scheme wrong?


问:
Are there any good use-cases for variable variables?
Today I encountered this little PHP gem called variable variables.

```<code>$literal = "Hello";
$vv = "literal";
echo $$vv; // => prints "Hello"
</code>```

Are there actually any real use-cases for this language feature?

答:
Honestly?  In nearly 10 years of PHP experience I've never encountered a problem to which the only solution (or indeed the best solution from a choice) was to use a variable variable.  The closest I've got is being able to access constants on an instance of a class such as $classInstance::CLASS_CONSTANT (which has been available since PHP 5.3) and even then I don't normally have much use for it.

I suspect it's one of the many warts that exist in PHP that seemed like a good idea at the time.

So in answer to your question, if there are use cases where it's the best or only approach to a particular problem, I've not seen them.


问:
What is the best way to approach visualization projects?
I work on several areas related to information visualization, linked data, computer vision and other stuff, so mainly front-end. I am not really happy with the fact that visualizations take lots of iterations and lots of time from first prototype to production ready code. So here is the question: what can I do to improve that?

Sometimes we do a prototype in few hours, add something, do another prototype, rewrite it to use jQuery instead of Prototype because it's a better fit and so on and so forth, but almost all visualizations go trough 15-20 iterations (sometimes taking up to few months of development time - the code will also go from the 300 lines of the initial prototype to 2000 or 3000 lines due to evolving requirements and iterations). Since I am working at multiple projects, from my point of view the fact that sometimes it can take months is not a problem, just that I am not really happy, as I could do 40 visualizations per year instead of 15 for example, if I would only be able to improve this process by reducing the number of iterations or by any other means.

答:
Information is beautiful is a good site to keep reading.  It has some truly amazing visualisation of data.

What is vital is to understand what the end users wants and how to display it in an informative way.  Using such tools as R, you can mock up some graphs easily and fast to make sure that your users know what they are getting. Having a portfolio of visualisation does help as well as this can serve as a basis for your new project -- in the same way as the above link can.

Finally, start (really) simple and add complexity later on.  This does mean you will have to refactor large chunk of your code.

From comment: How do you know at which iteration to stop, provided that your code does not have serious bugs?

The mercenary approach: when the money the client gave you runs out.

The academic approach: when you can write a paper about it.

The pragmatic approach: when all your other projects have trumped this one.

The perfectionist approach: My children's children's children will still be working on this.

For myself, it is when the visualisation tells me things I did not know or expect about my data.  Once that is done, I either understand the data (thus write a paper) or the data is incomplete in some sense (new hypothesis time).


答:
"The Little Schemer" is an exercise book, aimed at giving you a grounding in the Scheme dialect of LISP.

It is most emphatically NOT a textbook on LISP or Scheme programming, much less a text on functional programming.  For that, you want, as SK-Logic said, Structure and Interpretation of Computer Programs.

Title: Am I getting Scheme wrong?

Body:
Inspired by the numerous posts about the importance of learning Lisp/Scheme I started to learn Scheme two days back, I am using the book "The little Schemer" and have completed half of it.

But I still haven't learned anything new, the book teaches about recursion which I already understand and uses lambda (which I can think of a way to define a function in C). I still haven't got the concept of functional programming (please point to some example of functional compared to normal programming methods in C/C++ so I can get it).

Am I learning in the wrong way? or is "The little Schemer" for a newbie in programming and I should look for some other books?


问:
How to manage and improve a web application with 50 customers?
We've developed a Web Application using ASP.NET and Sql Server. We've started selling it and of course are still continue improving and developing it.

How do we go about updating each client's version of the site? We have, maybe, 50 customers. So 50 different folders and 50 different db's sounds like a bad idea. Is there any known method for solving this kind of scenario?

Some more detaials: we are developing a CRM, for 50 companies. They will have 10 users maybe. It makes 500 users and their customers and products.

答:
The way you described that you have one application and its been used for several different clients and as you mentioned you have 50 folders and 50 databases it means you have the entire application on your server or one server probably.

If I get the descriptions correct then I would suggest you look into the Whitelable Solution for this application. check this link

You would have all the code in one place and one database {or you may use different if applicable}

hope this helps


答:
Generally it is not possible to update each client version.

One solution is to provide updates as additional modules or plugins. So there is no need to modify the core.

It works in the case of php application called wordpress.

Wordpress cms is used to develop blog websites.

In wordpress you can add or remove plugins,which provides additional features.

Title: How to manage and improve a web application with 50 customers?

Body:
We've developed a Web Application using ASP.NET and Sql Server. We've started selling it and of course are still continue improving and developing it.

How do we go about updating each client's version of the site? We have, maybe, 50 customers. So 50 different folders and 50 different db's sounds like a bad idea. Is there any known method for solving this kind of scenario?

Some more detaials: we are developing a CRM, for 50 companies. They will have 10 users maybe. It makes 500 users and their customers and products.


问:
Computer Graphics: Principles and Practice in C ( in Python? )
I am attending a Computer graphics course after the summer. I have read lots of good things about the book "Computer Graphics: Principles and Practice in C" for people who are willing to put in some work. My school does not focus on C/C++ until next year, so I have decided to learn Python this summer and get good at Python this following year. </p>

<p>How language dependent is this book? Can I work through it in Python? </p>

答:
Python is a great language, but Computer Graphics are heavy and need performance. Because of this, commonly people use C or C++ in games. At most, C# and Java. XNA, for example, is a framework for C# that allows the user to make 3D games, but internally it has a lot of code written in C++.

Python is reserved for scripts, but the core engines are commonly made in C or C++. Panda 3D, for example, allows you to make games in Python. But internally, it uses C++.

But you CAN make basic Computer Graphics with Python, if it's for learning purposes. There is a Python binding to OpenGL. If the book uses OpenGL for making the graphics, you can use Python without a lot of effort.

But I think it's worth to learn C or C++ and learn how computer graphics works, given everything I explained.


问:
How compilers know about other classes and their properties?
I'm writing my first programming language that is object orientated and so far so good with create a single 'class'.  But, let's say I want to have to classes, say ClassA and ClassB. Provided these two have nothing to do with each other then all is good. However, say ClassA creates a ClassB--this poses 2 related questions:

-How would the compiler know when compiling ClassA that ClassB even exists, and, if it does, how does it know it's properties?

My thoughts thus far had been: instead of compiling each class at a time (i.e scan, parse and generate code) each "file (not really file, per se, but a "class") do I need to scan + parse each first, then generate code for all?

答:
Practically speaking, with Java, the IDE's look at a whole program at once; when ClassB is referenced, the IDE compiler will look at it.  Everything, including the libraries, is one complete whole.  Once the program is ready, you can change classpaths, swap in and out individual .class files, and switch library versions.  You could also compile individual .java files without using the IDE (or somehow avoiding it's checks).  The result does not need to be consistent at all, and if it's not you will get run-time exceptions.  (One of the many things an IDE is trying to do for you is turn run-time errors into compile-time, or rather, edit-time, errors.)

C#'s about the same, and I don't think C and C++ are really that different, in that what the Java and C# IDE's are doing is just creating C/C++-style headers for you behind the scenes.


答:
If each customer has a separate copy that you regularly ship updates to, your application must be able to handle upgrades gracefully.

Database versioning

You must store the schema version in the database. Each time you change the schema, you have to include logic in an admin module so customers can upgrade the database (semi-automatically). Each version upgrade should be defined as an action, and upgrading across several versions means running the actions one after the other.

Application versioning

When you install new versions of the software, you have to provide a migration procedure. Sometimes this means that all customer changes must go into a special folder that is copied back into your software after upgrade. At other times it means you must make an installer that "patches" the installed copy.


问:
Etiquette when asking questions in an IRC channel
Many larger OSS projects maintain IRC channels to discuss their usage or development. When I get stuck on using a project, having tried and failed to find information on the web, one of the ways I try to figure out what to do is to go into the IRC channel and ask.

But my questions are invariably completely ignored by the people in the channel. If there was silence when I entered, there will still be silence. If there is an ongoing conversation, it carries on unperturbed. I leave the channel open for a few hours, hoping that maybe someone will eventually engage me, but nothing happens.

So I worry that I'm being rude in some way I don't understand, or breaking some unspoken rule and being ignored for it. I try to make my questions polite, to the point, and grammatical, and try to indicate that I've tried the obvious solutions and why they didn't work. I understand that I'm obviously a complete stranger to the people on the channel, but I'm not sure how to fix this. Should I just lurk in the channel, saying nothing, for a week? That seems absurd too.

A typical message I send might be "Hello all - I've been trying to get Foo to work, but I keep on getting a BarException. I tried resetting the Quux, but this doesn't seem to do anything. Does anyone have a suggestion on what I could try?"

答:
Rule #1: Don't ask to ask

Rule #2: Behave as you would do in a real life conversation

Rule #3: Be patient. If there is no activity, it usually means that no one has read what you wrote yet. If no one responds, they don't know or didn't notice. You can re-try after a while, or ask if anyone has any clue with regards to your question x minutes ago.

Also, sometimes IRC is not the best way to get help. You could ask if there is a more active forum, like a mailing list, that you can try.


答:
If possible, break your question down to be as simple as possible.  While learning to program I spent a lot of time asking questions in IRC.  Sometimes my code just wouldn't work, and I didn't know why, so I'd put my 200 line program into a paste bin and ask why I was getting an error on line 78. Nobody would answer.

I found that in order to get answers I had isolate the problematic code.  If I couldn't get my example to fit in 20 lines or less, it was hard to get a good answer.  This often required a significant amount of work, but in the process I often solved my own problem before I had to ask in the IRC.

(This advice also applied to good SO questions.)

Title: Etiquette when asking questions in an IRC channel

Body:
Many larger OSS projects maintain IRC channels to discuss their usage or development. When I get stuck on using a project, having tried and failed to find information on the web, one of the ways I try to figure out what to do is to go into the IRC channel and ask.

But my questions are invariably completely ignored by the people in the channel. If there was silence when I entered, there will still be silence. If there is an ongoing conversation, it carries on unperturbed. I leave the channel open for a few hours, hoping that maybe someone will eventually engage me, but nothing happens.

So I worry that I'm being rude in some way I don't understand, or breaking some unspoken rule and being ignored for it. I try to make my questions polite, to the point, and grammatical, and try to indicate that I've tried the obvious solutions and why they didn't work. I understand that I'm obviously a complete stranger to the people on the channel, but I'm not sure how to fix this. Should I just lurk in the channel, saying nothing, for a week? That seems absurd too.

A typical message I send might be "Hello all - I've been trying to get Foo to work, but I keep on getting a BarException. I tried resetting the Quux, but this doesn't seem to do anything. Does anyone have a suggestion on what I could try?"


问:
What is the standard for naming variables and why?
I'm going through some training on objective-c.  The trainer suggests setting single character parameter names.  The .NET developer in me is crying.  Is this truly the convention?  Why?

For example,

```<code>@interface Square : NSObject
{
  int size;
}

-(void)setSize: (int)s;
</code>```

I've seen developers using underscores int _size to declar variables (I think people call the variable declared in @interface ivar for some unknown reason).  Personally, I prefer to use descriptive names. E.G.

```<code>@interface Square : NSObject
{
  int Size;
}

-(void)setSize: (int)size;
</code>```

C, like C# is case sensitive.  So why don't we use the same convention as .NET?

答:
If I have understood correctly you are talking about Hungarian Notation.

In this case you can refer to this answer for an explanation.

You can also refer to this answer for the second part of your question.


问:
what is the difference between Soak testing and Stress testing?
Can anybody explain the difference about soak and stress testing? I googled about them and found that both are about to test the software beyond its limits. Is it right for both testing strategies?</p>

答:
The tests can be similar or the same the main difference is the goal.

In stress testing the objective is to find at what point the system will brake.  The goal is to push it until it doesn't work anymore, in order to establish the maximum capacity of the system.

In soak testing the goal is totally different.  The goal is to determine if something is not going to work as early as possible.  This test is trying to expose a bad design.


答:
Check the timezone of the main developers, if they're not awake when you IRC them, you'll hardly get any reply.

Some may appear online, but just left a bot or left the client open to check for some messages when they wake up/come back. If you don't log back on, when they're available, they will have no way of coming back to you, though.

Anyway, for usage directions, mailing lists or issue trackers work better.

IRC is more useful for developers working on the project: so they can sync and discuss each others' efforts in real time without accidentally starting a flamewar.

(Mistakes and misunderstandings on debatable topics — like "what to do next?" — are faster to spot and correct in realtime)


答:
There are many standards for variable naming, it depends on the programming language used, and on the core developers involved in the project.

In case of objective-c, I think this page should answer your question:
https://developer.apple.com/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html

As per using single-letter parameter names as a general rule, it is clearly a horrible idea, don't listen to it.

Title: What is the standard for naming variables and why?

Body:
I'm going through some training on objective-c.  The trainer suggests setting single character parameter names.  The .NET developer in me is crying.  Is this truly the convention?  Why?

For example,

```<code>@interface Square : NSObject
{
  int size;
}

-(void)setSize: (int)s;
</code>```

I've seen developers using underscores int _size to declar variables (I think people call the variable declared in @interface ivar for some unknown reason).  Personally, I prefer to use descriptive names. E.G.

```<code>@interface Square : NSObject
{
  int Size;
}

-(void)setSize: (int)size;
</code>```

C, like C# is case sensitive.  So why don't we use the same convention as .NET?


问:
Do companies care about university grades when hiring programmers?
Most of my fellow students that I've talked to claim that aiming for good grades is useless as the companies don't care about them when hiring programmers. To them, it's enough to have simply attended courses which may be important, and that's that.

Is this true? Are university grades useless when leaving campus, or do employers ask to see them for an interview?

答:
I've never had anyone ask to even see proof that I have a degree, let alone actually look at my academic transcript and results (4 jobs so far, almost a decade in the industry).

You'll generally find that, for most programming jobs, it's what you can do that counts. In my experience, getting through technical questioning/tests in the interview and hiring process  and showing first hand that you know your stuff takes you 90% of the way there. This is one thing I really like about programming. Unlike some other white collar fields, the Who You Know and Book Learnin' Grades factors are relatively low and it's reasonably pragmatic-meritocratic (far from 100% of course, but relatively speaking).

All that said, many big companies who have very formal hiring processes for graduates/juniors probably WILL check your grades. So it's good to have the best grades possible to keep as many options open as possible. But I wouldn't lose much sleep over not being top of the class.


问:
Entity and pattern validation vs DB constraint
When it comes to performance:
What is the better way to validate the user input?

If you think about a phone number and you only want numbers in the database, but it could begin with a 0, so you will use varchar:

Is it better to check it via the entity model like this:

```<code> @Size(min = 10, max = 12)
 @Digits(fraction = 0, integer = 12)
 @Column(name = "phone_number")
 private String phoneNumber;
</code>```

Or is it better to use on the database side a CHECK (and no checking in the entity model) for the same feature?

答:
Performance is irrelevant for validating user input.

If it's taking too long to validate your form, your form has too many fields on it.  They would have to number in the thousands (in most programming languages) before performance ever became a limiting factor.

Where you validate depends on what your goals are.  If your database will connect to different systems, it might make sense to do validation right in the database system.  But the validation model can be richer elsewhere, as the example in your question illustrates.

Also, if you validate on the client side, you will still have to validate again on the server side (never trust client data).


问:
Reformatting and version control
Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide from day 1, and major improvements may arrive any day. Maybe you find that

```<code>SELECT id, name, address
FROM persons JOIN addresses ON persons.id = addresses.person_id;
</code>```

could be better written as / is better written than

```<code>SELECT persons.id,
       persons.name,
       addresses.address
  FROM persons
  JOIN addresses ON persons.id = addresses.person_id;
</code>```

while working on adding more columns to the query. Maybe this is the most complex of all four queries in your code, or a trivial query among thousands. No matter how difficult the transition, you decide it's worth it. But how do you track code changes across major formatting changes? You could just give up and say "this is the point where we start again", or you could reformat all queries in the entire repository history.

If you're using a distributed version control system like Git you can revert to the first commit ever, and reformat your way from there to the current state. But it's a lot of work, and everyone else would have to pause work (or be prepared for the mother of all merges) while it's going on. Is there a better way to change history which gives the best of all results:

Same style in all commits

Minimal merge work

?

To clarify, this is not about best practices when starting the project, but rather what should be done when a large refactoring has been deemed a Good Thing™ but you still want a traceable history? Never rewriting history is great if it's the only way to ensure that your versions always work the same, but what about the developer benefits of a clean rewrite? Especially if you have ways (tests, syntax definitions or an identical binary after compilation) to ensure that the rewritten version works exactly the same way as the original?

答:
There are viable two approaches that I've seen for this.

1. Reformat code on commit-hook

While it's initially hair-raising to alter code after they've submitted it, if your reformatting procedure (e.g. astyle) doesn't hurt the code, then its a safe operation. Over time the whole team will appreciate that all code eventually looks the same. Clearly, having comprehensive unit/automated tests will ensure that nothing broke.

2. One-time reformatting of all the code

This is more dangerous in my experience, and makes tracking issues across the big-bang difficult, but it's possible. Running all tests afterwards is essential. For coding style, the majority of differences revolve around use of whitespace - indentation or newlines. A decent merge tool should be able to be told to ignore all whitespace differences, so this will help with merges.

Title: Reformatting and version control


答: Your entity model rules can be both applied on the server side and rendered as JavaScript code to be applied on the client side, vastly improving user experience.  There's no contest.</p>

Title: Entity and pattern validation vs DB constraint

Body:
When it comes to performance:
What is the better way to validate the user input?

If you think about a phone number and you only want numbers in the database, but it could begin with a 0, so you will use varchar:

Is it better to check it via the entity model like this:

```<code> @Size(min = 10, max = 12)
 @Digits(fraction = 0, integer = 12)
 @Column(name = "phone_number")
 private String phoneNumber;
</code>```

Or is it better to use on the database side a CHECK (and no checking in the entity model) for the same feature?


问:
Staying alert and awake while coding
What methods do you use to stay awake and alert while working?

Personally I drink coffee non stop throughout the day.  But I've also heard of this thing called exercise that should help too.  Does anyone else have tips and tricks to stay more awake and alert while working?  Redbull? Maybe a magic pill that won't require me to sleep?

答: Last year at the Over the Air conference and hack day in London - a gathering of mobile developers - they had a Qi Gong guy come in and do half an hour of stretching and exercise, after a lot of people had been up all night programming. Half an hour of exercise out in the fresh air was a really good wake-up, even if we did all feel a bit silly with all the stuff about balls of qi energy and the like.</p>

Title: Staying alert and awake while coding


问:
What are the drawbacks of Python?
Python seems all the rage these days, and not undeservingly - for it is truly a language with which one almost enjoys being given a new problem to solve. But, as a wise man once said (calling him a wise man only because I've no idea as to who actually said it; not sure whether he was that wise at all), to really know a language one does not only know its syntax, design, etc., advantages but also its drawbacks. No language is perfect, some are just better than others.

So, what would be in your opinion, objective drawbacks of Python.

Note: I'm not asking for a language comparison here (i.e. C# is better than Python because ... yadda yadda yadda) - more of an objective (to some level) opinion which language features are badly designed, whether, what are maybe some you're missing in it and so on. If must use another language as a comparison, but only to illustrate a point which would be hard to elaborate on otherwise (i.e. for ease of understanding)

答: Arguably, the lack of static typing, which can introduce certain classes of runtime errors, is not worth the added flexibility that duck typing provides.

Title: What are the drawbacks of Python?


问:
Variable names for Contact Information bits
I am in the middle of refactoring code and would like to get some ideas on variable naming so that my new names clearly represent the data they hold.

I have a class called ContactMethod which makes sense to me; each instance is a different way to contact someone. My problem comes when naming the properties of ContactMethod. For example, one instance might be a Fax number of 555-555-5555 while another could be an Email address of bob@email.com; I've got a property called contactMethodType to hold the values "fax" or "email", but I don't know what to call the "555-555-5555" or "bob@email.com" part. Has anyone here created a good generic name for this piece of contact information?

(PS - the old convention was to call it a "Phone" with fields "phoneType" holding the "fax"/"email" value and "phoneId" holding the number/address. Yuck.)

答:
To my mind, if you can't think of a meaningful name for an abstraction, it means that the abstraction is probably not going to help you.   Out of curiousity why does calling it ContactMethod help you or make more sense than a separate Phone and Email class?

Abstractions are supposed to provide you with common behaviour for entities which are similar.   I don't know anything about the particular problem which you're trying to solve, but off the top of my head I can't really see much in common between a phone number and an e-mail address.    For example, your validation will probably follow totally different rules, and the way in which you use an e-mail address to contact someone (sending them an e-mail) is different to the way you'd contact them with their phone number.

(Also, the fact that you are storing a separate ContactType suggests your code may be packed full of if(type == phone) else if(type == email) etc anyway).

IMO it is ok (and sometimes better/desirable) to create separate data/entities for things which are logically different.  Sometimes you can try too hard to find a common one-size-fits all solution which ultimately doesn't make your life any easier


答:
If you are using a database shared by many applications and all applications share the same rules, then validation in the database layer makes sense. This is also true if your database is populated from feeds such as batch feeds. Otherwise, it is common to include validations that does not require database data in the client or at the business layer or on both. Database constraints are always used for Referential Integrity, PK enforcements and 'not null' enforcement. Considering the need for speed during data entry, waiting for the database to respond with an error is hard to justify as per @chaos reply.

It is best if you can centralize your validation processing. As for using Check constraint note that:

Check constraint don't allow for custom error messages

They apply only to data in 1 table

They don't apply to views


答:
You typically end up repeating some validation:

You validate on the client just for performance (instant feedback)

You validate on the server because you don't trust the client and validation is technically business logic and doesn't belong in the data layer

You validate in the database (data layer) iff something other than your application writes to the database that doesn't do perfect validation itself

Unfortunately this means repeating yourself, but that's life when it comes to programming today.  Technically if you were using Node.js you should be able to share the validation code between the client and the server.


问:
How to get motivation and time to learn outside of work?
I work 40 hours as a programmer, and by the time I get home, the last thing I want to do is code some more. However, I feel like I am not getting better, and I do love software engineering. So how do you guys find the time/motivation to improve your craft outside of work?</p>

答:
How to get motivation?
  Find a local business that needs a piece of software developed and work on it. Make sure you get paid for it, even if a small amount because you will feel more committed when you are paid, and that will make you persistent working your way through hard problems, otherwise it will be easy to give up when the going gets tough.

How to get time?
  You need to be very careful here. If you end up taking time from your family, friends or from sleep, you will burn out soon and will loose all motivation. What worked for me is 2 hours a day (from 10pm to 12pm) 4 times a week. You are the only one that can determine how much time and what ours will work best for you.


问:
How do we set a link to a Paid version of app if we don't have the app in App Store ?
If we don't have the free and the paid apps on the Apple app store yet, how would we program in the free version to link to the paid version because the link is not there yet?

Do we have to have a webpage as a placeholder to do the forward, for this first, initial case?   Is this the only solution and what if we don't have a website?

答: Forwarding to a temporary URL is your best bet.  If you don't already have a URL, then I would suggest masking it with your own domain, like myapppaid.mydomain.com.  You don't need a website to do it, but you would need a domain name registered, which on average is about $10 US.  Just set up the subdomain and have the app point to that address, and then when the other app version is in the store, just redirect that url to the iTunes address or whatever it is you need to point to.  URL shortening services may be able to do this for you if you can't get a domain, but the major ones (Bitly and TinyURL) don't allow you to change the underlying link for security purposes.</p>


问:
When would I use pseudocode instead of flowchart?
I'm a student working with various techniques of programming, and I've come across pseudocode and flowchart. I know that these are both used in order to think through the problem before actually programming, but I have a few questions with this.

When would I use pseudocode to plan out and when would I use flowcharts? Or is it better to do both before actually programming. Particularly for a small arcade sort of game in JAVA since that is my next project.

I've noticed that pseudocode is very similar to the actual code rather than flowcharts. Would this make pseudocoding better because you essentially copy/paste the pseudocode into your program (of course, you have to change it to fit the language. I understand that part).

Is it practical to use both of these while programming? Particularly the same game mentioned earlier.
Thanks.

答:
Flowcharts and pseudocode often have the same level of expressiveness, but differ in linearization. Pseudocode is linear (i.e. a sequence of lines with instructions), a flowchart is not. Therefore, flowcharts are a higher abstraction level, used before writing pseudocode or for documentation.

Flowcharts have, in my opinion, two strong advantages over pseudocode: Firstly, they are graphical. Many non-technical people have a strong fear of structured text, but not of graphical descriptions, so flowcharts will sit much nicer with them. Secondly, flowcharts are much better at expressing meta-considerations such as showing the main line of execution as opposed to branches.

Your questions in detail:

For a really complicated problem, you would use flowcharts first, then pseudocode. Both are optional when you feel secure enough.

Yes, pseudocode has the advantage of being mergeable with real code. Steve McConnell, for example, strongly recommends writing methods in pseudocode first and then leaving the pseudocode in the code as comments.

I always felt that the need to draw a flowchart during design shows insufficient partition of your problem. Non-trivial flowcharts indicate convoluted logic, which should be avoided at great costs.


答:
Generally i don't write Flowcharts while i am working on Personal projects (as projects are not much big) and most of the inputs, outputs and processes are clear.
but as you will start working on complex big projects with different input sources flat files, databases, manual interfaces etc flowcharts are handy.

I would recommend you writing Pseudo code and UML digrams as these tools will help you to come up with better classes, methods etc. Sometimes while writing pseudo code you will find different and more efficient ways to solve a program.

Title: When would I use pseudocode instead of flowchart?

Body:
I'm a student working with various techniques of programming, and I've come across pseudocode and flowchart. I know that these are both used in order to think through the problem before actually programming, but I have a few questions with this.

When would I use pseudocode to plan out and when would I use flowcharts? Or is it better to do both before actually programming. Particularly for a small arcade sort of game in JAVA since that is my next project.

I've noticed that pseudocode is very similar to the actual code rather than flowcharts. Would this make pseudocoding better because you essentially copy/paste the pseudocode into your program (of course, you have to change it to fit the language. I understand that part).

Is it practical to use both of these while programming? Particularly the same game mentioned earlier.
Thanks.


答: Python's scoping is badly broken, which makes object-oriented programming in Python very awkward.</p>

Title: What are the drawbacks of Python?

Body:
Python seems all the rage these days, and not undeservingly - for it is truly a language with which one almost enjoys being given a new problem to solve. But, as a wise man once said (calling him a wise man only because I've no idea as to who actually said it; not sure whether he was that wise at all), to really know a language one does not only know its syntax, design, etc., advantages but also its drawbacks. No language is perfect, some are just better than others.

So, what would be in your opinion, objective drawbacks of Python.

Note: I'm not asking for a language comparison here (i.e. C# is better than Python because ... yadda yadda yadda) - more of an objective (to some level) opinion which language features are badly designed, whether, what are maybe some you're missing in it and so on. If must use another language as a comparison, but only to illustrate a point which would be hard to elaborate on otherwise (i.e. for ease of understanding)


答:
Pseudo code is for quickly representing an idea to those that understand at least the basics of code. Flowcharts are fr drawing pretty pictures for everyone else to understand the same thing.

Flow charts are often used for documentation purposes because many different people use that documentation and flowcharts are easier to follow than pseudo code for non programmers. In a project you are working on for yourself sticking with pseudo code is fine as its far more useful and much easier to create since a text editor is all that you need.


答:
Flowcharts are a high level of abstraction they let you plan how things should proceed, For example

if x dies y wins

They don't need to depend on how you are designing the program in terms of classes and methods, pseudo code on the other hand provide a lower level of abstraction (though it really depends)

if(isdead(s)) y.win()

thus pseudo code can now be translated into actual program based on the language you are using.

For a game I would recommend using a flowchart first, then design the classes and methods, write pseudo code and finally convert that into a program


答:
On Pseudo Code

To be honest, I don't use pseudocode much.  Typically it's faster to just write the code, so that when I'm done with my code, it's actual code.  There are some cases when pseudo code may be helpful, but you're generally working on something very complex and just trying to break down the structure of a method or something.  In those cases, I use comments in my IDE to lay out the structure until I get things right.  Then, I go in and write the actual code in the comments.   This helps me do a few things:

I can see areas I have and haven't implemented by reading the comments and seeing obvious gaps in them.

When I fill in the real code, I have comments explaining in English what I'm doing.  (They'll probably need it if it's so complicated that I need to write pseudo code first).

On Flowcharts

Code typically changes so much that flowcharts aren't helpful except for larger, more system-wide architecture design or documentation.  In those cases I'll just whiteboard a diagram to get the gist of things or to show to someone else on the team.  Unless you really need a flowchart to help you understand, then you don't really need them to "do" software right.  Nowadays, there are lots of plugins for IDEs that will generate flowcharts from the code itself, as well as class diagrams and others (and vice versa`).  The only real time you'd need to do a seriously accurate flowchart is if you can't keep the whole architecture and how things work in your head at once and need to talk through something visual to catch kinks.


答:
When I first started out and wanted to improve my skill set beyond that of my work life (at the time I was more SQL than anything else) I decided to find a project that would not only teach me something but also be rewarding.

I found a local charity that needed some database work done, not just the data warehousing but a GUI to interface with it. This gave me a reason to work at home later in the day and felt very rewarding knowing that I was stopping a charity from shelling out a lot of cash to some faceless software house.

That mixed with a lighter working environment (my trance playlist and some big speakers) helped a lot. On days that I felt I was being overly distracted I would take my laptop to the local Starbucks and work there (no TV to distract me!), I even found that after a while the staff would come and refresh my coffee for me so I didn't have to leave my laptop!


答:
I would consider the nature of the code you are writing. If it is:

Highly iterative/recursive

Branches in complicated ways

Implemented in several systems, which you want to represent

In the first two cases, pseudocode becomes progressively harder to read than a big picture diagram. On the other hand, code that is mostly linear makes incredibly boring diagrams that actually make the process harder to understand because of how much it blows it up.

For the third case, flowcharts are better at representing processes that cross system boundaries and represent the entire process.


问:
How to show or direct a business analyst to do data modelling?
Our business analysts pushed hard to collect data through a spreadsheet.  I am the programmer responsible for importing that data.  Usually when they push hard for something like this, I never know how well it will work out until a few weeks later when I have time assigned to work on the task of programming the import of the data.  I have tried to do as much as possible along the way, named ranges, data validations, etc.  But I usually don't have time to take a detailed look at all the data and compare to the destination in the database to determine how well it matches up.

A lot of times there will be maybe a little table of items that somehow I have to relate to something else in the database, but there are not natural or business keys present that would allow me to do so.   Make the best of this, trying to write something that can compare strings and make a best guess at it and then go through the effort of creating interfaces for a user to match the imported data to the destination.

I feel like if the business analyst was actually creating a data model, they would be forced to think about these relationships, and have an appreciation for the need of natural or business keys to be part of the spreadsheet for the purposes of smoothly importing the data.  The closest they come to business analysis is a big flat list of fields, and that would be fine if it were like any other data dictionary and include data types+relationships, but it isn't.  They are just a bunch of names.  No indication of what type of data they might hold, and it is up to me to guess.  When I have pushed for more detail, they say that it is just busy work.

How can I explain the importance of data modelling?  How can I tell them what it is and how to do it?  It feels impossible, because they don't have an appreciation for its importance.  They do however, usually have an interest in helping out in whatever way they can, it's just this in particular has never gotten a motivated response.

答: Provide your business analyst with a data template that both of you can live with.  It's not necessarily his job to do database and system interface design; it is yours.</p>


答:
I use Python somewhat regularly, and overall I consider it to be a very good language.  Nonetheless, no language is perfect.  Here are the drawbacks in order of importance to me personally:

It's slow.  I mean really, really slow.  A lot of times this doesn't matter, but it definitely means you'll need another language for those performance-critical bits.

Nested functions kind of suck in that you can't modify variables in the outer scope.  Edit:  I still use Python 2 due to library support, and this design flaw irritates the heck out of me, but apparently it's fixed in Python 3 due to the nonlocal statement.  Can't wait for the libs I use to be ported so this flaw can be sent to the ash heap of history for good.

It's missing a few features that can be useful to library/generic code and IMHO are simplicity taken to unhealthy extremes.  The most important ones I can think of are user-defined value types (I'm guessing these can be created with metaclass magic, but I've never tried), and ref function parameter.

It's far from the metal.  Need to write threading primitives or kernel code or something?  Good luck.

While I don't mind the lack of ability to catch semantic errors upfront as a tradeoff for the dynamism that Python offers, I wish there were a way to catch syntactic errors and silly things like mistyping variable names without having to actually run the code.

The documentation isn't as good as languages like PHP and Java that have strong corporate backings.

Title: What are the drawbacks of Python?


答:
Don't rewrite VCS history: it;s against VCS principles.

Don't try to automate fixing the formatting: it is treating the symptoms, not the real problem (= developers not following coding standards).

Define the coding standard and formatting best practices in a common document and get all developers to agree.

You mention Git, which is great, because it's distributed. With a DVCS it's very easy to enforce best practices through the gatekeeper workflow. Gatekeepers reject merge proposals (= pull requests in Git) that don't conform to the common guidelines. And I do mean reject, in bold letters, otherwise the coder in violation will not bother to follow the rules and continue to repeat the same mistakes.

This technique works well for me. Coders want their work to be merged, so after a few mistakes in the beginning they start following the rules.

As per fixing the existing code base... I recommend doing that gradually, perhaps module by module, or as it makes sense for your project. Test carefully at each step. It may sound stupid, but mistakes do happen even with trivial changes like just the formatting, so be prepared for some minor bumps on the road.

Title: Reformatting and version control

Body:
Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide from day 1, and major improvements may arrive any day. Maybe you find that

```<code>SELECT id, name, address
FROM persons JOIN addresses ON persons.id = addresses.person_id;
</code>```

could be better written as / is better written than

```<code>SELECT persons.id,
       persons.name,
       addresses.address
  FROM persons
  JOIN addresses ON persons.id = addresses.person_id;
</code>```

while working on adding more columns to the query. Maybe this is the most complex of all four queries in your code, or a trivial query among thousands. No matter how difficult the transition, you decide it's worth it. But how do you track code changes across major formatting changes? You could just give up and say "this is the point where we start again", or you could reformat all queries in the entire repository history.

If you're using a distributed version control system like Git you can revert to the first commit ever, and reformat your way from there to the current state. But it's a lot of work, and everyone else would have to pause work (or be prepared for the mother of all merges) while it's going on. Is there a better way to change history which gives the best of all results:

Same style in all commits

Minimal merge work

?

To clarify, this is not about best practices when starting the project, but rather what should be done when a large refactoring has been deemed a Good Thing™ but you still want a traceable history? Never rewriting history is great if it's the only way to ensure that your versions always work the same, but what about the developer benefits of a clean rewrite? Especially if you have ways (tests, syntax definitions or an identical binary after compilation) to ensure that the rewritten version works exactly the same way as the original?


答:
You should use whatever you feel comfortable with.  That said, my impression is that flowcharts are not heavily used to sketch out program control these days; for one thing, they are typically unstructured, compared to pseudocode.  It is more common to use class-dependency diagrams like UML, to describe your architecture at a much higher level.  Also, if your application has a state machine, drawing a (flowchart-like) state machine diagram is essential.

I think you are correct here.  One way to work is to write out your pseudocode as comments in your source file to start with, and insert the actual implementation lines among them.

Again, use whatever you feel comfortable with.  If you're not sure, try them both out; I expect your practice will quickly converge on whatever is most useful to you.  I personally don't find flowcharts useful unless I'm trying to untangle a particularly complicated execution order.


问:
Do higher resolution laptop displays matter for programmers?
I'm buying a new laptop that I'll be using mainly for programming.  A couple of options that really intrigue me are the Asus Zenbook UX31A and the new Retina Macbook Pro.  It's obvious that the high-resolution displays on these laptops is useful for entertainment, photo-editing, and other things.  My question is this:  Do these displays provide any benefit for programmers?  Do these displays make code any easier to read?  Are they any easier on the eyes after a whole day of staring at the screen?</p>

答: The benefit to a higher resolution is the ability to fit more on a screen. This may or may not be useful to you as a programmer. Having more lines of code can help you grasp some things better, other times its just more clutter. As for eye strain that depends on what color schemes, brightness, contrast, lighting, test size, refresh rates... Text size is really the only thing that resolution affects and even that is adjustable outside of resolution.</p>


问:
How to determine if a class meets the single responsibility principle?
The Single Responsibility Principle is based on the high cohesion principle. The difference between the two is that a highly cohesive classes features a set of responsibilities that are strongly related, while classes adhering to SRP have just one responsibility. </p>

<p>But how do we determine whether a particular class features a set of responsibilities and is thus just highly cohesive, or whether it has only one responsibility and thus adheres to SRP? In other words, isn't it more or less subjective, since some may consider a class very granular (and as such will believe the class adheres to SRP), while others may consider it not granular enough? </p>

答:
Bob Martin (Uncle Bob), who originated the SOLID principles of which SRP is the first, says about this (I am paraphrasing, can't recall the actual words):

A class should only have one reason to change

If it has more than one reason, it does not adhere to SRP.


答:
The higher resolution isn't likely to be particularly useful to you on a notebook.  The reason high-res displays look better on tablets is because you tend to hold them a lot closer to your face than a notebook.  By the inverse-square law, if you hold something flat twice as close, you see twice as much detail in both the X and Y dimensions.

So having a notebook without an ultra-high resolution display, and keeping it at a normal distance from your eyes, will give you the same experience as an ultra-high resolution tablet display held much closer.  Any claims to the contrary (see: MacBook with Retina display) are just marketing hype, and as Kyle pointed out, tend to actually look worse unless they're designed specifically with the ultra-high resolution display in mind.

Title: Do higher resolution laptop displays matter for programmers?

Body: I'm buying a new laptop that I'll be using mainly for programming.  A couple of options that really intrigue me are the Asus Zenbook UX31A and the new Retina Macbook Pro.  It's obvious that the high-resolution displays on these laptops is useful for entertainment, photo-editing, and other things.  My question is this:  Do these displays provide any benefit for programmers?  Do these displays make code any easier to read?  Are they any easier on the eyes after a whole day of staring at the screen?</p>


答:
Resolution does matter for development even on a laptop. Try to run Eclipse with the Package explorer open and a source file with the MacBook Pro 13". It is not fun. IDE's are not meant to run on low resolution displays. If you are used to vi and tabing around I imagine a low resolution display will work just fine.

The next important thing is to make sure all the text is very clear. Nothing worse than a high resolution on a small screen where you cannot read the source code.

Use SetResX to change the Retina Display to effective 2880x1800, it's not worth killing your eyes over. But the default 1440x900 or even the resolution above that gives nice results.

Also based on what I read about the Asus notebook the MBP beats it hands down in every way. So you are really talking about money here. If you are willing to spend the $2400-$3000 ish get the MBP. If you have to stick with something less than $2k your option is only Asus. If you want the most performant machine the MBP Retina Display has fantastic hardware in it.


问:
What is a best practice tier structure of a Java EE 6/7 application?
I was attempting to find a best practice for modeling the tiers in a Java EE application yesterday and couldn't come up with anything current.  In the past, say java 1.4, it was four tiers:

Presentation Tier

Web Tier

Business Logic Tier

DAL (Data Access Layer ) which I always considered a tier and not a layer.

After working with Web Services and SOA I thought to add in a services tier, but that may fall under 3. the business logic tier.

I did searches for quite a while and reading articles.  It seems like Domain Driven Design is becoming more popular, but I couldn't find a diagram on it's tier structure.

Anyone have ideas or diagrams on what the proper tier structure is for newer Java EE applications or is it really the same, but more items are ranked under the four I've mentioned?

Aftermath:

Really, I should have reworded my question as my real intent was to ask where to put the business logic in a Java EE application?  In thinking along those terms, I somehow concluded that the tier structure had changed, when it had not.  However, with the advent of POJO programming and lightweight frameworks that I was using in my day to day work, I lost sight of all this.

The tier structure of Java EE apps still holds to the same, but now instead of heavy weight EJB2 type business logic in the middle tier I was using POJO's with services to implement business logic.

答:
I believe the answer to your question will vary depending on the type of an application you are developing. Since I am more familiar with Web Based desktop (vs mobile) applications I will try to answer for this type.

The most prevalent architecture of JEE web apps these days is based on MVC (Model View Controller) design patter. This pattern breaks out your app into View layer designated to be consumed by the Client Tier, Model and Controller layers reside in your server side app tier. Additionally most app frameworks rely on application Services layer (not WebServices) for your application specific logic (business logic, etc). Besides these layers application may consume or produce a WebService (either SOAP based or REST(RESTlike) ). And finally most web apps read and write to a Database (or other persistent storage).

I would consider breaking up your architecture diagram into three main tiers: Client-Server-Data (where data tier could have both a database and a set of webservices to read/write data)
I know this isn't traditional SOA architecture break out - but that is how most apps that I have seen actually work.

Hope this helps.
Dmitry.


问:
Technology/Techniques to prevent offensive images on a website
I am planing to build a website which one of its main features is the usage of pictures. I was wondering what existing techniques are used to prevent offensive pictures (i.e pornography) to get loaded by users. i.e What does Facebook or Pinterest use?

As well I would like to know what your recommendations would be to control offensive pictures to get uploaded to the site (OpenSource tools maybe..) Taking into consideration this is a personal project and will be developed with a very small budget.

Thank you

答: Don't forget that once you have broadcast that you filter out "offensive" pictures, you open yourself up to lawsuits if you miss one. You could add a flag button to each page and be prepared to delete the offending photo after reviewing it.</p>


答:
Why yes it is very subjective, and it is the subject of many heated, red-faced debates programmers get into.

There's not really any one answer, and the answer may change as your software becomes more complex.  What was once a single well-defined task may eventually become multiple poorly-defined tasks.  That's always the rub too.  How do you choose the proper way to divide a program up into tasks?

About the only advice I can give is this:  use your (and your coworkers') best judgement.  And remember that mistakes can (usually) be corrected if you catch them soon enough.

Title: How to determine if a class meets the single responsibility principle?

Body:
The Single Responsibility Principle is based on the high cohesion principle. The difference between the two is that a highly cohesive classes features a set of responsibilities that are strongly related, while classes adhering to SRP have just one responsibility. </p>

<p>But how do we determine whether a particular class features a set of responsibilities and is thus just highly cohesive, or whether it has only one responsibility and thus adheres to SRP? In other words, isn't it more or less subjective, since some may consider a class very granular (and as such will believe the class adheres to SRP), while others may consider it not granular enough? </p>


问:
Is it necessary to memorize code?
I am a new developer, who just got hired at a big company.  I don't know how but I guess they are desperate.  However, I am well-versed with HTML5/CSS3 though things change and new things are released and I keep up with as much as I can.  But this job required me to hand-code Javascript, know Jquery and Ajax.  I have been exposed to this a bit but I am not sure if I can hand-code Javascript.

My question is, is it necessary to memorize all there is about Javascript or are there a few key things that I should know how to hand-code because looking at javascript code it seems there are lots of lines code!

Please point me in the right direction.

答:
What do you mean "required to hand code"? Are they going to not allow you to run Eclipse or any myriad of tools that groks these languages? Or are they just trying to judge your basic understanding of them? I work with a number of languages daily (C++, Java, JavaScript, Php), so I often forget the exact syntax for what I want to do. Say I want to get the part of a string after the first space in Java. I use indexof(" ") to find the position, then substring() to get the rest of the string. I don't recall if it's indexOf, but it's asinine to not use Eclipse and save a few minutes of wading through the docs.

doug

Title: Is it necessary to memorize code?


答:
I've been working on my current project for several years and have surprised myself as to how much of the database I've memorized. Obviously, this information is readily available to lookup, but when you get so familiar with something, you can't help but remember it. My boss asked me an ad hoc question, and I pounded out a query as he shockingly peered over my shoulder. It's nice to be recognized; enjoy it while you can.

Normally, this isn't true for me at all. I use lots of tools to keep track of things and to search for code samples. I'm guessing if I work on something else, some of this will go away.

If your job requires you to work on various projects using different tools, you're not going to become completely fluent in many of them. The capacity to grasp concepts and learn new things will be more important in the long-run because much will change. At some point you shouldn't have to search for the syntax of if/then/else in your language of choice 5 times a day.

Title: Is it necessary to memorize code?

Body:
I am a new developer, who just got hired at a big company.  I don't know how but I guess they are desperate.  However, I am well-versed with HTML5/CSS3 though things change and new things are released and I keep up with as much as I can.  But this job required me to hand-code Javascript, know Jquery and Ajax.  I have been exposed to this a bit but I am not sure if I can hand-code Javascript.

My question is, is it necessary to memorize all there is about Javascript or are there a few key things that I should know how to hand-code because looking at javascript code it seems there are lots of lines code!

Please point me in the right direction.


问:
My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

答:
Maybe you should look at it as "Who is in the best position to fix the bug?" A part of me also feels, you broke it, you fix it. There should be some accountability.

I don't agree with keeping some sort of score. Some people create more bugs because they work on more complex parts of the code. If lines of code isn't a useful metric, I doubt bugs per lines of code is any better. Code will never get checked in.

At some point a manager should know who is doing their job and who isn't, as well as, who does it better because the rest of the team does.


答:
The main argument I would use against it is to ask what problem he's trying to solve. There are almost certainly better ways of solving the same problem.

For one thing, is there really only ever one person to blame? If there is, you're doing something else wrong. A good process takes a piece of work through an analyst, a programmer, a reviewer and a tester before it gets to production. If you're not doing all of these stages, maybe that's the solution to the problem your boss is trying to solve. If you are then which one is to blame? It might be none of them, it could be legacy code that's to blame.

It's no good having people back-biting and pointing fingers, trying to avoid a black mark which won't go away once it's set. It solves nothing. Very few people are maliciously negligent. You need to do a proper retrospective, see what went wrong and what you can do to make sure it doesn't go wrong again.

From that you will clearly see if one person is regularly at fault and that may be a different problem to deal with.

The trick to stopping a manager set on creating accountability is to offer accountability yourself, but in a way that actually makes sense to you.

Title: My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?

Body:
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

ContentLicense: CC BY-SA 4.0


问:
How do I get up-to-date on web development technologies?
I'm a regular user here, but linking my screen name to my real identity is dirt simple, and the question I'm about to ask would lead to a very unpleasant conversation with my current employer were they to see it.  So, my apologies for this sock-puppet account; I promise Socky and I won't be voting on each other's stuff, and Socky won't be doing much of anything other than voting on answers to his own questions.

I may have an opportunity to work with somebody I've worked with in the past.  Short, extremely understated summary:  It went well.  This time he's looking to bring me on as a partner to a fledgling web venture.  My job title isn't defined, but I'd basically be "the guy" in terms of the tech side of the company.  One of the first things I'd be doing is fleshing out the current and future requirements of the site and determining the best way to meet them -- overhaul the existing site?  Scrap the existing site entirely and replace it with something like Drupal?  I'd also be tasked with making sure that the site is not only a pleasant user experience, but that it looks and feels like a modern, professional website.

One problem:  I'm not qualified.

At least, not yet.

I wasn't really qualified for the last time we worked together, but I taught myself what I needed to know and ... like I said.  It Went Well.  However, I was a lower-level code wrangler that time around, and a lot of key decisions had already been made.  I had more room for error and time to learn as I was going.

This outing, not so much.  It's been a long damn time since I was completely up-to-date on web programming; my current gig has a healthy dash of web stuff, but the web interface isn't the main business and it's built on old technology.  (Technology it honestly doesn't use particularly well.)  I just don't spend a lot of time playing with new tech when I'm not at work; I generally spend that time on hobbies and passions I don't get paid to do.

But I want this to happen.  And I want to do it right.  So my question is:  what resources would you recommend I use to both get myself up-to-date and stay up-to-date on professional-caliber web programming?

I know I need to beef-up my jQuery-fu; I've been exposed to it a little, and holy crap does it make hard jobs easy.  I also know I need to acquaint myself with Drupal and other content management systems so that I can accurately gauge whether using one as the foundation for the site would be a good idea or a waste of time.  But I'm certain there are other technologies out there that would help me do that job that I don't yet know anything about.  What are some good resources for helping me figure out what I don't know?

Websites, magazines, podcasts, whatever.  I need to figure out how to get back into the game properly.

This is scary as hell, but it also feels like it could be a huge step forward in my career.  (Assuming it's not a step into a pool filled with laser sharks.)  My thanks in advance for any assistance anybody can offer in curing my ignorance.

答:
Don't lie about who you are and what you can do but consider that if your business partner knows the first thing about you and technology, then he has an idea of how much web development you have done.

The thing about our industry is that it changes very frequently and lots of things are new. This why, every other questions about 'what language should I learn next' invariably ends up being answered as 'whichever is different enough from what you know now' - so that you gain knowledge and not just mechanical skills.

So, what do you do? Here's what I do:

Independent research: look up the docs, wrap your head around it

Refer to authorities: look at my P.SE/SO history, I've been asking questions about WCF Silverlight and EF recently. I didn't have much experience with them but I've researched them, formed opinions and think I have some answers. Now I'm cross referencing what I think I know against what my peers/superiors know.

Practice: Use the technology to implement something you already know how to make using the technologies you already know. You're not trying to create anything, you're trying to figure out the intricacies of a technology: don't compound it with domain knowledge problems.

I want to drill this point home: If your business partner wanted a 10 year vet, he could go find one. He wanted you, and you are a technology specialist not a [language] user. Leverage that knowledge to attain the skills you need to complete the job. If you can't then be honest with your partner and yourself and turn it down.

btw: you can.


答:
OO says that classes are a grouping of data a functionality.  This definition leaves plenty of room for subjective interpretation.

We do know that classes should be clearly and easily defined.  But, in order to define such a class, we have to have a clear notion of how a class fits into the overall design.  Without waterfall type requirements which, paradoxically, are considered an anti-pattern...this is difficult to achieve.

We can implement a class design with an architecture that works in most cases, like MVC.  In MVC applications we only assume to have data, a user interface and a requirement for the two to communicate.

With a basic architecture, it's easier to identify cases where single responsibility rules are being broken.  E.G. Passing an instance of a User Control to a Modal.


答:
Tell them this is only an amateurish name for the Root Cause field used by professionals (when issue tracker does not have dedicated field, one can use comments for that).

Search the web for something like software bug root cause analysis, there are plenty of resources to justify this reasoning 1, 2, 3, 4, ....

...a root cause for a defect is not always a single developer (which is the main point of this field)...

That's exactly why "root cause" is professional while "person to blame" is amateurish. Personal accountability is great, but there are cases when it simply lays "outside" of the dev team.

Tell your boss when there is a single developer to blame, root cause field will definitely cover that ("coding mistake made by Bob in commit 1234, missed by Jim in review 567"). The point of using the term root cause is to cover cases like that, along with cases that go out of the scope of the dev team.

For example, if the bug has been caused by faulty hardware (with the person to blame being someone outside of the team who purchased and tested it), the root cause field allows for covering that, while "single developer to blame" would simply break the issue tracking flow.

The same applies to other bugs caused by someone outside of the dev team - tester errors, requirements change, and management decisions. Say, if management decides to skip investing in disaster recovery hardware, "blaming a single developer" for an electricity outage in the datacenter would just not make sense.


答:
If you're up for a little civil disobedience, get the team to agree to put a list of all the developers in that field for each bug. If that won't fit, write "I'm Spartacus!" instead. The point, of course, is that you're all responsible for all the bugs, and you're not happy about having to point out the individual who created any one bug.

Another option: play along. Don't do anything in particular -- just do good work and fill in the field as accurately as you can for a few months. Then explain to the boss that assigning blame for each bug makes everyone on the team unhappy and uncomfortable. Tell him that you all feel that there's little correlation between bugs created and anything else (skill, effort, sanity). (It'll help if you can run some numbers that show that there really isn't a correlation.)

Gandhian Civil Disobedience: Put your name on every field(unless other developers step up and put their name for their bugs), and accept blame for every bug whether it's yours or not. Nothing will render that field or the idea of blaming someone more useless than this. If your boss asks why is your name on every field, then you can explain "because I don't think development is a blame game, if you really need people to blame and crucify, then crucify me for everything and let my team work peacefully."


答:
Simple answer.

The "Blame" field will be used for nothing more than scapegoating and fingerpointing, morale will plummet, team trust will be destroyed and everyone will be trying to find ways to prove that something is not their fault instead of fixing it.  People will also be more inclined to keep quiet about bugs instead of reporting them, because they don't want a colleague to get into trouble.  It's completely counter productive.

What's more important, victimising somebody for making an honest mistake, or getting the problem fixed as quickly as possible?

Your boss seems to think bugs are a sign of laziness or sloppiness.  They're not.  They're a fact of life.  How many patches does Microsoft push out in a year?


答:
Tell your boss that developing in a team needs social skills. He might even nod.

But the problem is, that this is something developers are extremely bad with. Adding tools that suggest blaming is more important than proper problem analysis is counter-productive.

Instead you need incentives to improve social skills, and the communication infrastructure you have should support that. For example, coin it positively: Name a person who is responsible for a ticket, who takes care of it.

Also start with code reviews so you can learn from each other. That spares the blames later on.