答:
For those really horrible problems my strategy usually goes as follows.

Experiment and google. Keep trying to solve the problem. Most of the time this solves the problem in an hour or less.

So that hasn't worked. Take a break. Have a coffee, talk about something unrelated to a colleague. Push the problem out of your mind. When you look at the problem 5 or 10 minutes later you are looking at it from a slightly different perspective. Most of the time this works.

In this case it hasn't. So spend another 10 - 30 minutes looking at it. Then call in a colleague. But before you do, make some notes; you want to demonstrate the problem, reproduce it, then list of the things you have tried, and most importantly prove that you have tried them. So do a dry run first. Set some book marks in the code, close any superfluous open documents etc. This way you may either solve the problem yourself, or when you do demonstrate the problem you won't be wasting their time.

Ask your colleague to make you prove all your assumptions. is that setter actually being invoke? Is that method really returning what you claim it is? You think that object isn't null - show them it isn't null.

Most of the time, either demonstrating the problem will make you realise that you haven't  tried all the possibilities or your colleague will see your mistake.

If that doesn't work its time to get serious. Document exactly what you are trying to do, what you have tried, and why it didn't work. Email this to all your colleagues. Post it on SO. At this point the document should be a perfect SO question.

While you wait for responses, google google google. Try every permutation of the question you have. Open up a bunch of tabs. You probably aren't going to get an answer by this point, but you're looking for ideas, possibilities, different ways of approaching the problem.

Do something else, if you've spent 5 hours on a problem its time to leave it for another day. Maybe you will get a useful response. Maybe when you attack the problem the next day it will be obvious.

If none of that works, its time to look for a different solution. Maybe you can use a different method, a different technology. Maybe you should consider abandoning the feature for now. Are you billing the client by the hour? Are you working for a company on an internal app? You need to escalate this to the owner and tell them "look, I've spent x hours on this and made no progress, is the cost benefit worth it?". You don't want to go to your boss and tell them you spent 16 hours on a problem only for them to turn around and say, it nots that important, skip it for this release. you need to find that out earlier.

And if that doesn't work? Well your only options are to keep hammering away at the problem or seek out industry expertise. Ask technology experts on twitter. Email your technology provider.


问:
How do you tackle really bizarre errors that keep you puzzled for more than 10 hours?
You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle?</p>

答:
Sleep over it

Otherwise, call someone nearby and ask him to take a quick look over the code.

Often errors which would take you a long time to find (since its your code) are found very easily by others

ContentLicense: CC BY-SA 3.0


问:
Determine Better Coding Practice
As a new programmer, it has always been hard to create applications, because I am still at the learning stage.

I understand that to achieve a particular affect or function in an application, there will be numerous ways to achieve the same result.

However, should I just purely create a function to it's working state, which means that as long as it works, just as the way I want it to, then it should be fine.

Can any fellow programmers of a higher level kindly let me know the right way of doing things?

答:
I would approach improvements from several directions:

Use some tools/plugins that give you instant feedback during programming, so that you can make your code better readable, usable, robust, performant, correct. For instance in Java, you could use checkstyle, PMD, Findbugs

Write tests: that alone improves your development process, and gives you a safety net when you are experimenting and trying to improve your code, e.g. by refactoring.

Use metrics to check your result and get further hints. For instance in Java, thee is jdepend, metrics, JavaNCSS, EclEmma.

Get new ideas and information by

reading books

code review

pair programming

talking with other developers, e.g. on brown bag meetings / lunch breaks

listen to podcasts

read stackexchange posts.

Title: Determine Better Coding Practice


问:
Creating a Performance Model for a Legacy product
I've been given the task for creating a performance model for a legacy product. The product is about 10 years old and has never had any performance requirements or performance models before. Generally whats happened in the past is a customer will complain that a particular feature is slow or they are not getting the throughput that they want/need and the developers will investigate and see if any more performance can be squeezed out the code for the feature.

Since the product doesn't have any hard measurements and metrics for past versions I fell all I can do is create baselines for the current version and go from there. Other developers sometimes notice that memory usage is really high and ask why. Also, I am new to the product so I don't know all the feature points (which there are hundreds to thousands) and the performance cost of running each.

The program is an ASP.NET/.NET 2.0 webapp on IIS 6. I've started looking into performance counters and the CLR Profiler to start getting measurements. I've also read the following docs:

Measuring ASP.NET Performance

Improving ASP.NET Performance

So my question is: How can I create a performance model for a legacy product that I am new too and hasn't had a performance model/requirement in the past?

答:
I'm not entirely sure what your application/system is, and what it's purpose/userbase is, but I'll let you know how I would approach the task.

I would first seek to break the system down into sub-systems, or components, that are relatively self-contained with only a handful, at most, interfaces to the other components. If you can build and run these individually you will be able to better monitor their performance, and associated resource cost. If you find a particularly resource-intensive process or thread it also allows you to manage the 'drill-down' to find the root cause. The scale of these steps is totally dependent on your architecture.

If it's possible for you to isolate and monitor feature chains, all the better. I'm not sure how much effort you have been assigned by management to perform this task, and unfortunately that will always be the primary driver (depending on your upwards influence) of what you can achieve. But I have found a break down into smaller units to be a fantastic approach to most aspects of software engineering - including performance modelling!


问:
Looking for good books about the theory behind search engines
I am working on a project that requires that I understand different techniques used by search engines for the web.

I have a strong scientific and development background, so I am not afraid of highly technical information.

I am looking for all forms of technical information including information on web crawlers, other techniques for acquiring data, methods of data storage and how to query it, etc., etc.

I am completely new to the subject and I'm looking for useful resource and books on the subject.  Any suggestions are appreciated.

答: This area of study is known as Information Retrieval. This Wikipedia article contains a good summary and lots of useful links.</p>


答:
First, Google actively participates in the "science" of technology and often shares their knowledge by releasing papers from their R&D department.  You can find those papers from the reference link below.  I haven't searched for specific papers on search retrieval algorithms but there should be more than enough information available on the subject from a very technical perspective, as well as papers on storing massive sets of data and effectively querying it.

Publications by Googlers

Other than Google's resources, I highly recommend that you look into Semantic Web research.  Semantic web isn't a method of searching data and even though the concept at first seems a little vague, the clear implications of a semantic web "engine" would be to parse the information within the WWW and link relevant information with one another.

In short, semantic web is the science of what many forward-thinkers hope and are working for the internet to truly become where the information that is provided is well parsed, interpreted and correctly linked together.  I haven't looked into it much myself, so some of my information may be a bit incorrect.  However, their are plenty of resources available that discuss semantic web and many are hoping/waiting/working on a break through within the field with the hopes of making the "next big thing" for the internet.

A good starting point for learning about semantic web is, of course, Wikipedia.

These references may not be books but it is a lot of information.  Reading and sifting through all of the technical information should keep you busy for a while.

Title: Looking for good books about the theory behind search engines

Body:
I am working on a project that requires that I understand different techniques used by search engines for the web.

I have a strong scientific and development background, so I am not afraid of highly technical information.

I am looking for all forms of technical information including information on web crawlers, other techniques for acquiring data, methods of data storage and how to query it, etc., etc.

I am completely new to the subject and I'm looking for useful resource and books on the subject.  Any suggestions are appreciated.


问:
Do some languages make it easier to build graphically-intensive GUIs?
I made an algorithm that has a good potential use for a commercial application. I'm thinking of making a GUI, and since it's computationally expensive, I'm thinking of putting it "on the cloud" to offer the numerical part as a service. What I'm thinking is making a GUI, and then the users submit the work to the server. This GUI could be made open software (in fact, very probably will be). The GUI has a lot of graphics. Imagine something like making picks on surfaces plots, taking a look at those picks with different tools, and using numerical mathematics on those picks.

Are there languages that make this work easier? What, specifically, about them aide in creating GUIs like this?

答:
There are not GUI-Easiest languages: but take a look at C# with Windows Forms and Delphi: Both are RAD tools: C# uses C# as a language (Wich is very simillar to Java), and Delphi uses Pascal.

There are not specific languages for GUIs, but there are great RAD tools.


问:
Is there a reason for initial overconfidence of scientists and engineers working on artificial intelligence in the 1960s?
I just started an AI & Data Mining class, and the book. AI Application Programming, starts off with an overview of the history of AI. The first chapter deals with the history of AI from the 1940s to present. One particular statement stuck out at me:

[In the 60s] AI engineers overpromised and underdelivered...

What was the reason for the overconfidence? Was it because of mathematical prediction models showing that a breakthrough was around the corner, or due to the ever-increasing hardware capability to take advantage of?

答:
I can think of a couple of reasons.

AI experienced such rapid success with some of the toy problems tackled in the late 50s and early 60s, that they overestimated what they had accomplished. ELIZA and SHRDLU stunned folks despite being relatively simple programs. Unfortunately, a large part of what made those programs stunning was really just novelty. Nobody is very impressed by a conversation with ELIZA today, but at the time folks thought it was near miraculous.

Also, as problems are "solved" or at least become tractable, folks no long think of them as AI. Code optimization used to be an AI problem. Statistical learning budded out of AI into its very own speciality, and took speech recognition with it. As data mining becomes mainstream it will loose its association with AI. Over time AI forgets its successes and gets stuck holding on to the intractable and insoluble problems, and it ends up looking like a flop.


问:
Should we rewrite it from scratch
At work, we have a software written in PL/SQL - Oracle Forms 10g, which runs the software as a Java Applet.

My Company bought the software and we have to develop the software, but we feel that  Oracle Forms 10g Technology with Java applet is out of date. It's a technology from the past decade and we must move the software to a different platform (ie. Web or some other platform).

Is this a good or bad idea? And why?

答:
Unless you give technical reasons why you're not satisfied with the current solution, and unless you evaluate the financial side of the rewrite, all you will get here be opinions based on nothing but personal preferences. Which is, needless to say, something no business decision should be based on in general.

Edit: To elaborate a bit on the already said, generally the process of decision of a rewrite goes like this (in this order):

1. What's wrong with the current solution? Is there a list of real problems with it? Performance? Client asking for features different to implement, if at all possible?
Or are you just unsatisfied / bored with the current technology (this is an often case with technical staff who want to work with the new technologies).

2. What does the current solution "depend" on? Proprietary technologies? Are there alternatives to those in language B (in which you wish to rewrite it). Is it possible to do a rather direct rewrite of codebase or will a large part of it need to be differently structured (architecture wise).

3. Is the current staff familiar with language B? If not, is there enough available staff in the area where your company resides? Commercial support for language B - does it exists? (Do not rely on communities of volunteers for long term projects; they go from one technology to another as their interests change. For a let's say two decade application lifespan you need solid grounds in terms of commercial support.)

4. How many clients depend on the current solution? Your costs of their transfer (you'll have to provide technical support) to new solution? Costs of giving support for how many years to those that have not upgraded?

5. Financial analysis of the whole thing (this is best done by someone from the managerial level; take it as a fact that if there is one thing they value and know how to estimate it is costs.)

I deliberately avoided specifics here since you didn't gave many in your question. Also there is probably more which I forgot to mention ... but it's 2am in my part of the world and I'm starting to get ... zzz <-- sleepy

Title: Should we rewrite it from scratch


答: Honestly, you need a far better justification than "We feel it's out of date" to justify spending the amount of money it will cost. What are the problems with the current incarnation?</p>

Title: Should we rewrite it from scratch

Body:
At work, we have a software written in PL/SQL - Oracle Forms 10g, which runs the software as a Java Applet.

My Company bought the software and we have to develop the software, but we feel that  Oracle Forms 10g Technology with Java applet is out of date. It's a technology from the past decade and we must move the software to a different platform (ie. Web or some other platform).

Is this a good or bad idea? And why?


答:
The short answer to this question, imho, is no. You should seek out existing solutions, be it open source or commercial. I've sat in meetings with developers and heard them utter statements such as "I think technology X is utter garbage, I could write a better product than that!". The truth is, they probably can, but are they in the business to be rolling out their own frameworks? Writing stuff from scratch should be a last resort, unless it's some esoteric domain where existing software solutions are scarce.

It's a technology from the past decade and we must move the software to a different platform (ie. Web or some other platform).

Looking at this, it sounds as though your company has recognized there is heavy baggage associated with the product it is using and that there is a desire to move to something else. It also seems as though you are indecisive about what platform to move to, so you need to take a step back and think about your customers, what their use case scenarios are and then consider what platform/medium would be the best approach to deliver a revised form of what you have currently.

Title: Should we rewrite it from scratch


答:
Quite simply, they massively underestimated the scale of the problem at hand, especially where combinatinatorial explosion is concerned. Many AI solutions work fine for "toy" samples, but fail hard when they scale up to human-level problems.

Arguably, they were also simply inexperienced. AI as a field had (relatively) only just been invented in terms of practical applications, so nobody had significant experience applying theory to anything.

Title: Is there a reason for initial overconfidence of scientists and engineers working on artificial intelligence in the 1960s?

Body:
I just started an AI & Data Mining class, and the book. AI Application Programming, starts off with an overview of the history of AI. The first chapter deals with the history of AI from the 1940s to present. One particular statement stuck out at me:

[In the 60s] AI engineers overpromised and underdelivered...

What was the reason for the overconfidence? Was it because of mathematical prediction models showing that a breakthrough was around the corner, or due to the ever-increasing hardware capability to take advantage of?


问:
How to most effectively debug code?
Bugs creeping into code can be minimized, but not entirely eliminated as it is written - programmers are, although many would disagree, only humans.

When we do detect an error in our code, what can we do to weed it out? How should we approach it to make most effective use of our valuable time and enable us to spend less time trying to find it and more time coding? Also, what should we avoid when debugging?

Note here that we're not talking about preventing bugs; we're talking about what to do when bugs do appear. This is a wide field, I know, and may be highly dependent on language, platform and tools. If so, keep to encompassing answers such as mindsets and general methods.

答:
There is an excellent book I read on this subject called Why Programs Fail, which outlines various strategies for finding bugs ranging from applying the scientific method to isolate and resolve a bug, to delta debugging. The other interesting part of this book is that it does away with term 'bug'. Zeller's approach is:

(1) A programmer creates a defect in the code.
(2) The defect causes an infection
(3) The infection propagates
(4) The infection causes a failure.

If you want to improve your debugging skills, I highly recommend this book.

In my own personal experience, I've found plenty of bugs in our application, but management simply presses us onwards to get new features out. I've frequently heard "We found this bug ourselves and the client hasn't noticed it yet, so just leave it until they do". I think being reactive opposed to proactive in fixing bugs is a very bad idea as when the time comes to actually put a fix in, you've got other issues that need resolved and more features management want out the door ASAP, so you get caught in a vicious cycle that can lead to a great deal of stress and burn out and ultimately, a defect ridden system.

Communication is also another factor when bugs are found. Sending an email out or documenting it on the bug tracker is all fine and well, but in my own experience, other developers find a similar bug and rather than reuse the solution you put to fix the code (as they've forgotten all about it), they add their own versions, so you've got 5 different solutions in your code and it looks more bloated and confusing as a result. So, when you do fix a bug, make sure a few people review the fix and give you feedback in case they have fixed something similar and found a good strategy to dealing with it.

limist mentioned the book, The Pragmatic Programmer which has some interesting material on fixing bugs. Using the example I gave in the previous paragraph, I'd look at this: Software Entrophy, where the analogy of a broken widow is used. If two many broken windows appear, your team may become apathetic towards ever fixing it unless you take a proactive stance.

ContentLicense: CC BY-SA 2.5

Title: How to most effectively debug code?


答:
Generally speaking, it's best to avoid making such decisions based on feelings.  Just because the technology is old does not mean that it should be replaced.  Old technology tends to be proven technology.  The question usually boils down to the costs involved.

You need to determine what issues you are having with the existing solution and how much that is costing the business.  You need to determine how much it will cost to rewrite it.  Compare the two and use that to help you make the decision.  (Note that not all of the cost is necessarily in terms of money or can be easily quantified.  So, this isn't exactly an easy comparison to make.)

Rewriting software tends to take longer and cost more than actually anticipated.  Also there is no guarantee that it will actually be better than the existing solution.  Don't take my word on this, Joel Spolsky blogged about why rewriting software from scratch is a mistake a long time ago.

So, if possible, an incremental approach should be taken.  Rather than scraping the whole thing and starting over, make changes slowly and migrate the solution to newer tech piece by piece.

Title: Should we rewrite it from scratch


问:
How is Delphi XE2 going to work across platforms?
So I've been reading a little about Delphi XE2 and I probably will go to the world tour thing in Chicago coming up later this month and ask this question if no one can answer it here.

What I wonder is how is my Delphi code going to be executed on a Mac? Is something else going to have to run (i.e. virtual machine) in order for the program to run?

答:
You can now download the trial version of Delphi XE2 and try it for yourself.

Firemonkey (FMX) is the new business-focused 2d and 3d cross platform framework, for Windows, mac and iOS devices (iPad, iPod Touch, iPhone).

It is indeed based on technology acquired from ksdev and almdev companies based out of Russia, and the developers from those companies now work for Embarcadero, and were part of the team that built Firemonkey, and the new VCL themes support in XE2.

There is a lot to Firemonkey, but XE2 Firemonkey is a "first release" of a brand new platform.  Look out for a lot of amazing stuff coming from Embarcadero in the next few releases, as Firemonkey grows and matures.  My opinion of working with it is that it is "ahead of its time".   It's a great way to build great looking applications.

However, it's not as mature and capable as the VCL, especially on Win32, you will miss a lot of stuff. Reporting systems. Etc.  There will be a third party component ecosystem, as time goes on, but for now, there are no big third party component libraries that run in FMX yet. For example, there is no equivalent to the Developer Express or TMS component sets, there are no Rave or FastReports.  The first third party on board out of the box, is the Venerable TeeChart, which is now both for VCL and Firemonkey. (I'm very glad to see that. It would have been sad if a "business framework" shipped without the ability to make pie-charts.)


答:
When we do detect an error in our code, what can we do to weed it out? How should we approach it to make most effective use of our valuable time and enable us to spend less time trying to find it and more time coding? Also, what should we avoid when debugging?

Assuming that you are in a production environment, here is what you need to do:

Describe the "error" correctly, and identify the events that cause it to happen.

Determine if the "error" is a code error or specification error. For example, entering a 1 letter name may be considered an error to some systems but acceptable behavior for other systems. Sometimes a user would report an error that he/she thinks is a problem but the user's expectation for the behavior of the system was not part of the requirements.

If you have proved that there in an error and the error is due to the code, then you can determine which code pieces need to be fixed to prevent the error. Also examine the effect of the behavior on current data and future system operations (impact analysis on code and data).

At this point you would probably have an estimate of how much resources are going to be consumed to fix the bug. You can either fix it right away or schedule a fix within an upcoming release of the software. This depends also on the whether the end user is willing to pay for the fix. You should also evaluate different available options to fix the error. There may be more than one way. You need to select the approach that best suits the situation.

Analyze the reasons that caused this bug to appear (requirements, coding, testing, etc.). Enforce processes that would prevent the condition from happening again.

Document the episode adequately.

Release the fix (or the new version)

Title: How to most effectively debug code?

Body:
Bugs creeping into code can be minimized, but not entirely eliminated as it is written - programmers are, although many would disagree, only humans.

When we do detect an error in our code, what can we do to weed it out? How should we approach it to make most effective use of our valuable time and enable us to spend less time trying to find it and more time coding? Also, what should we avoid when debugging?

Note here that we're not talking about preventing bugs; we're talking about what to do when bugs do appear. This is a wide field, I know, and may be highly dependent on language, platform and tools. If so, keep to encompassing answers such as mindsets and general methods.


答:
While I agree with all the fellow programmers, I also need to introduce less tangible but nonetheless important aspects to this situation. Software development is relatively young discipline and it changes fast, really fast. What's the average age of your dev team? 45? Imagine hiring college grads to work on your stack, do you foresee any difficulty? Is your current stack conducive to rapid development and short iteration cycles? Do you have unit and integration tests? Is it even possible to have them with Oracle Forms? Is your dev team excited (not in hubris and/or wild west sense though) to come to work and augment the system? At this time you know your system and underlying requirements much better than you did at the inception stage. Would you still go with your current stack? Are there significantly better tools and products available now to achieve what you need in a more economic and pragmatic way?

This is just a food for thought. If you do embark on a re-write then do yourself a favour: try to make it as iterative as possible and resist the "big bang" approach. I speak from experience.

Title: Should we rewrite it from scratch


答:
Here's how I do it:

use the same method every time to find the problem. This will improve your reaction time to the errors.

Best way is probably reading the code. This is because all the information is available in the code. You just need efficient ways to find correct position and ability to understand all the details.

debugging is very slow way, and only necessary if your programmers do not yet understand how computer executes asm instructions/cannot understand call stacks and basic stuff

Try to develop proof techniques like using function prototypes to reason about behaviour of the program. This will help finding the correct position faster

Title: How to most effectively debug code?


问:
What is the object-oriented thought process?
I've been studying OOP in conjunction with Zend's MVC implementation for the past few months. I'm pretty new to programming, generally, but I feel strongly that I should learn things the 'right' way, which for me means to make sure I understand why things are done the way they are. I.e., I have found that in learning how to do something (anything, say music), the best way to learn how to do something is to know why it's done that way in the first place.

Anyway, I have been struggling very hard with understanding how to develop my own business models (i.e., the M of MVC), and I have decided it's not because I don't understand OOP in general, because I've studied it for several months and I don't think the concepts are very difficult to grasp. I find the examples I've studied very intuitive, actually. The problem for me, I think, lies in the process of translating my own problems into object oriented solutions. The examples in books (that I've read so far) are too obvious, so the process of translating the problem into objects isn't very difficult. What I think I might be missing is a high-level abstracted process. Some kind of list of steps or questions that every object-oriented solution must answer on the highest level.

If you had to describe such a process in no more than five steps, what would they be and why? What is the most effective process in translating any problem into an object-oriented solution?

答:
Here's steps I use in c++ code:

decide class name

decide constructor parameters and data members.

decide member function names and prototypes

make it independent of other classes

The design is done, and everything else is just the implementation.

The reason for (1) is that it defines the scope of what functionality belongs to the class.
The reason for (2) is that it defines how the class communicates with the outside world.
The reason for (3) is that it defines how to choose which functionality of the class is needed in each situation. The reason for (4) is that it allows class to be used in many different situations. The reason for (5) is that it defines the border between design and implementation.


答:
Explain the problem to someone else.

By explaining the problem to someone else, you have to clarify it:  this often lets you see the solution.

(One of the UK professional computer magazines once proposed selling life size cardboard cut-outs of a senior programmer specifically for this purpose.)

I find sleeping on a problem (sometimes for a couple of days) can also help.

Title: How do you tackle really bizarre errors that keep you puzzled for more than 10 hours?

Body: You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle?</p>


答:
In my opinion, taking TDD approach is natural and efficient:

Write down specific requirements (Given, When, Then)

Translate each requirement (most important one first) into a unit test.

Write least amount of code in order to pass the test written in #2.

After passing the test, refactor your code according to SOLIDD design principles.

After #4, make sure your code still pass all tests written.

Repeat 2-5.

With this process, you can gradually produce testable code with sound design. You might think at first that writing test is unnecessary but that activity actually helps you build sound architecture.

Title: What is the object-oriented thought process?

Body:
I've been studying OOP in conjunction with Zend's MVC implementation for the past few months. I'm pretty new to programming, generally, but I feel strongly that I should learn things the 'right' way, which for me means to make sure I understand why things are done the way they are. I.e., I have found that in learning how to do something (anything, say music), the best way to learn how to do something is to know why it's done that way in the first place.

Anyway, I have been struggling very hard with understanding how to develop my own business models (i.e., the M of MVC), and I have decided it's not because I don't understand OOP in general, because I've studied it for several months and I don't think the concepts are very difficult to grasp. I find the examples I've studied very intuitive, actually. The problem for me, I think, lies in the process of translating my own problems into object oriented solutions. The examples in books (that I've read so far) are too obvious, so the process of translating the problem into objects isn't very difficult. What I think I might be missing is a high-level abstracted process. Some kind of list of steps or questions that every object-oriented solution must answer on the highest level.

If you had to describe such a process in no more than five steps, what would they be and why? What is the most effective process in translating any problem into an object-oriented solution?


问:
What writing rules are different for humans and code?
It seems that some rules of writing code are in direct contradiction with the rules of human writing.  For example in code it's advisable to define each piece of information in only one place and in writing for humans it's normal to repeat important points (though usually phrased differently).

What rules of writing good code contradict the rules of good writing?

答:
```<code>Indentation rules (most coding standards impose) really contradict
    rules of good writing,
    the way people perceive information,
    and the grammar rules.
Making things (that group naturally, but not syntactically) inside
parenthesis also contradicts how texts are usually typed.
If (you try to type text that way)
    you'll face misunderstanding even (if programmers read you)
otherwise
    your text will be easy to read,
    and your writing will be productive
!
</code>```


问:
What traits do the best managers you've worked for have in common?
I have been listening to Scott Hanselman and Rob Conery's podcast, This Developer's Life.

In the latest episode, they discuss personality traits:

1.0.4 - Being Mean.

What makes people mean in our
  industry? What about aggressive?
  Confident? What's the difference?
  Would you rather have a drill sergeant
  for a boss, or a zen master? We talk
  to Cyra Richardson and Giles Bowkett.

It got me thinking, what traits did the best managers you've worked for have in common?

EDIT: Just to clarify, as there have been a few close votes, I'm interested in whether there are traits common to managers of developers that are not necessarily those traits that a manager of some other profession requires.

As for whether this is programming related or not, well I don't want to ask this question on a site that isn't about programming because, frankly, I'm not as interested in what people who make cans of soup for a living want from their managers as I am interested in what developers want from their managers.

答:
Recognition that I am hired and paid to make decisions.

I am not a $7/hour food service employee.  I am here to make decisions.  If I'm told every detail of what to do, I might as well be a typist.


问:
What happens at [platform] user groups?
I'm a .NET developer, but I've never been to a .NET user group meeting or anything like that.

I might have the opportunity soon to start attending one, but I'm wondering. What happens at user groups? I'm not looking necessarily for info specifically about .NET ones, but they are preferred.

What do you get out of it excluding the opportunity for networking?

答:
I attend my local .NET User Group every month.  Here are some things that go on besides networking:

Giveaways: Win books, licenses of ReSharper or CodeRush, etc.

Presentations: Speakers from all over the country (and world) give talks on development best practices, new technologies, etc.

Eat food:  Pizza...of course! (Sponsored by a local business)

Title: What happens at [platform] user groups?


答: Good code doesn't require interpretation whereas good writing often can.  Shakespeare comes to mind as an example here.  The vagueness of some writing doesn't exist in code often is another way to see this.</p>

Title: What writing rules are different for humans and code?

Body:
It seems that some rules of writing code are in direct contradiction with the rules of human writing.  For example in code it's advisable to define each piece of information in only one place and in writing for humans it's normal to repeat important points (though usually phrased differently).

What rules of writing good code contradict the rules of good writing?


答:
Finding a suitable model isn't always straight forward. It is one of these things which require more experience than plain knowledge. However, the following simple recipe might help you to get over an initial mental block.

It was originially described in this paper by Abbott and is frequently referred to as "Abbott's textual analysis".

Write a plain text specification.

Identify classes: Nouns are good candidates.

Find the attributes: Adjectives/adverbs are good candidates.

Find the operations: Verbs are good candidates.

Find the associations between classes.

Refine.

Example:

Nouns, verbs and adjectives are marked.

The library contains books and journals. It may have
  several copies of a given book. Some of the books
  are for short-term loans only. All other books can be
  borrowed by any library member for three weeks.
  Members of the library can normally borrow up to six
  items at a time, but members of the staff may borrow
  up to 12 items at one time. Only members of the staff
  may borrow journals.

A first analysis iteration would yield:

Classes:

Library

Book, Journal

Copy

Loan

Library Member

Item

Staff Member

From here on, you can think about which class needs which attributes and methods to implement the behaviour and then refine that model increasingly.


问:
Have you ever found a bug you can't solve? What do you do in that case?
We're developing a hosted CMS, something like WordPress.com. When we were creating the Image Gallery module, we examined many jQuery libraries like easySlider, jCarousel, and Nivo Slider. But each of them had some kind'of weird bug across browsers. We almost put 2 days into finding where the bug was from. But we couldn't find the problem source. The most important reason could be that our system is now is complex.

Here are the problems:

easySlider sliding were not transitional and was abrupt.

jCarousel were sliding images half to their width in IE.

Nivo Slider didn't hide the last-shown image, thus was not suitable for and image gallery with heterogeneous images.

We just concluded that we need to find a library which can work without bug, and we searched and found one.

But my question is, is it normal for large projects that the source of a bug cannot be found and instead, it's located with trial-and-error and you simply flee from the bug? Do you have such an experience?

答:
We just concluded that we need to find a library which can work without bug, and we searched and found one.

Or, better, you can contact the respective authors of those libraries and submit them the bug you've found.

You may also be surprised if those authors answer that the bug does not exist. For example, I used jCarousel  in the past and never had any width problem in IE. Your case may be some very strange edge case or a bug introduced in the latest version, but it also may be the fact that you're using the library wrong.

Now, if you contact the author and he spends lots of time correcting a bug while you have deadlines approaching, or his answer is unhelpful, there is nothing wrong to abandon a library and choosing another one. You can also disable a buggy feature in the current release of your website, and search for a solution by your own later, optionally contributing to the library if it is open source.


问:
C++ to friend or not to friend
I have an object oriented programming with c++ course this semester at college and we were learning about friend functions.

I instinctively dislike them for their ability to bypass the security that Encapsulation and Data hiding provide, I read a few articles on the internet and some people thought that it was a good idea with some legitimate uses.

What would an OOPs expert say about friend fucntions in C++? Should I just skim over it or should I learn more about it?

答: If you're passionate about what you do, you would be learning everything about C++. Learn what they're used for, how to use them, and then - and only then - decide not to use them. At the very least, you'll be prepared when reading someone else's code that uses this facet of C++.</p>

Title: C++ to friend or not to friend


答:
By definition every bug can be fixed, perhaps by writing your own operating system in assembler language. That's one of the beauties of programming.

On a more realistic note, the problem is to find a fix to the bug that has a reasonable cost. Rewriting a chunk of Linux is much cheaper than writing your own OS. Finding a library that works is cheaper than rewriting a broken library.

Drupal has a trick whereby the HTML is given to html.tpl.php to be written to the browser. By editing that file I have "fixed" bugs by replacing the actual HTML with my own. Examples include translating from English into Chinese, adding a language switcher in a disallowed corner of the screen, and picking a random imaage to display. It's low level, but it's possible.

It's always possible to "fix" a bug by replacding the code that generates the problem. The smaller the chunk you replace, the less it costs.

Title: Have you ever found a bug you can't solve? What do you do in that case?

Body:
We're developing a hosted CMS, something like WordPress.com. When we were creating the Image Gallery module, we examined many jQuery libraries like easySlider, jCarousel, and Nivo Slider. But each of them had some kind'of weird bug across browsers. We almost put 2 days into finding where the bug was from. But we couldn't find the problem source. The most important reason could be that our system is now is complex.

Here are the problems:

easySlider sliding were not transitional and was abrupt.

jCarousel were sliding images half to their width in IE.

Nivo Slider didn't hide the last-shown image, thus was not suitable for and image gallery with heterogeneous images.

We just concluded that we need to find a library which can work without bug, and we searched and found one.

But my question is, is it normal for large projects that the source of a bug cannot be found and instead, it's located with trial-and-error and you simply flee from the bug? Do you have such an experience?


答: You can also add this to your resume: show potential employers that you are involved in the programming community outside work.</p>

Title: What happens at [platform] user groups?

Body:
I'm a .NET developer, but I've never been to a .NET user group meeting or anything like that.

I might have the opportunity soon to start attending one, but I'm wondering. What happens at user groups? I'm not looking necessarily for info specifically about .NET ones, but they are preferred.

What do you get out of it excluding the opportunity for networking?


答:
HTML

Several years ago I switched from conventional GUI to HTML-based browser based GUI. It is convenient, workstation-independent, widely available, does the job. For more power add PHP and/or Javascript and you've got a bundle that can't be matched by any conventional library. No need to "deploy" anything; it's all on the server.

Title: Do some languages make it easier to build graphically-intensive GUIs?

Body:
I made an algorithm that has a good potential use for a commercial application. I'm thinking of making a GUI, and since it's computationally expensive, I'm thinking of putting it "on the cloud" to offer the numerical part as a service. What I'm thinking is making a GUI, and then the users submit the work to the server. This GUI could be made open software (in fact, very probably will be). The GUI has a lot of graphics. Imagine something like making picks on surfaces plots, taking a look at those picks with different tools, and using numerical mathematics on those picks.

Are there languages that make this work easier? What, specifically, about them aide in creating GUIs like this?


问:
Should I make public my implementation of a published algorithm?
My company has problem A, lets say, face recognition. We find a nice algorithm like this one. We implement it and go home happy. Problem is, once home I cant sleep because I wonder if we should make the implementation public. After all the algorithm was public. Someone did intensive research and did half ( or more ) the work for us. I feel like we should help back and make our efforts public too. But then our commercial product would not be very commercial, just image our banner:

Hey customer please buy our grunt master 6000 software, its only $1,000.00 ! Oh by and by the way, you can download the main algorithms here for free !

Is there some sort of licence of derivative work from these academic research papers ? Is it my duty to make my implementations public ? Or is it up to me ? Can I make money from the algorithm ?

答:
In the vast majority of occasions, publishing code can even be positive towards your company. The people who are willing to buy your software will do so anyway, because they are simply not programmers and do not care about algorithms, but results.

If you are worried about competitors, then you may need to rethink about publishing. However, since you say that this is just a simple implementation, i don't really see a clear benefit for possible competitors, unless you thought of something really innovative.

Generally, you don't need to publicize your own work if you don't want to, but if you are thinking of doing it, mostly judge based on competition and not your clients.

OwnerDisplayName: alanboy

OwnerDisplayName: SpyrosP


答:
It is not an "all or nothing" proposition. Perhaps it would be easier to convince management if you release the code under a license which does not allow for commercial use. This does not prevent you from using your own code any way you like. A public implementation for acadmic use only is pesky for many users, but might be an easier sale still with management.

There is certainly no obligation to publish just because you used someone's research paper to guide your implementation. I like how you feel that you should contribute back, though. If the code is not part of your company's key IPR, there are also actual benefits from making it open source, though (provided you can reach users who are able and willing to help improve the code).

Your valuation of the research paper's share of the product's cost is way inflated, by the way. The typical bean counter will calculate no more than approximately 30% of the commercial product's value from the actual code (so that's 15% tops from the research effort, if your 50% estimate is correct; but I speculate it is also much too high); the rest is the productization, packaging, support, marketing, sales, administrative overhead, margin, etc.

"Margin" means "profit" and is quite okay, legally and morally. If you attempt to make an unreasonable profit, you risk creating a niche for a hungrier competitor who charges less. So at least according to the theory of supply and demand.

Title: Should I make public my implementation of a published algorithm?

Body:
My company has problem A, lets say, face recognition. We find a nice algorithm like this one. We implement it and go home happy. Problem is, once home I cant sleep because I wonder if we should make the implementation public. After all the algorithm was public. Someone did intensive research and did half ( or more ) the work for us. I feel like we should help back and make our efforts public too. But then our commercial product would not be very commercial, just image our banner:

Hey customer please buy our grunt master 6000 software, its only $1,000.00 ! Oh by and by the way, you can download the main algorithms here for free !

Is there some sort of licence of derivative work from these academic research papers ? Is it my duty to make my implementations public ? Or is it up to me ? Can I make money from the algorithm ?

OwnerDisplayName: tripleee


答: Following advices from @Andy Waite I read the wikipedia page on information retrieval, and followed the references. There is a lot of online information, and I find this introduction to information retrieval, which is an online book from 2008, so probably up-to date, and which seems to be quite a good intro to the topic.</p>


答:
C++ friend functions are closely related to the following functionality:

free functions

static functions

friend functions

This means that they do not have this-pointer and thus are outside of the class/object. On the other hand, they often take parameters that make them again belong to the class. Here's some example which clarifies the link:

```<code>class B;
class A {
public:
    friend void f(A &a, B &b);
private:
    int m_a;
};
class B {
public:
   friend void f(A &a, B &b);
private:
   int m_b;
};
void f(A &a, B &b) { /* uses both A's and B's private data */ }
</code>```

The only difference between static functions and friend functions is that a friend function can use several classes.

Using friend mechanism in c++ requires programmers that have about 10-15 years experience with the c++ way of programming, and thus initially you should avoid it. It's advanced feature.

Title: C++ to friend or not to friend

Body:
I have an object oriented programming with c++ course this semester at college and we were learning about friend functions.

I instinctively dislike them for their ability to bypass the security that Encapsulation and Data hiding provide, I read a few articles on the internet and some people thought that it was a good idea with some legitimate uses.

What would an OOPs expert say about friend fucntions in C++? Should I just skim over it or should I learn more about it?

Body:
C++ friend functions are closely related to the following functionality:

free functions

static functions

friend functions

This means that they do not have this-pointer and thus are outside of the class/object. On the other hand, they often take parameters that make them again belong to the class. Here's some example which clarifies the link:

class B;
class A {
public:
    friend void f(A &a, B &b);
private:
    int m_a;
};
class B {
public:
   friend void f(A &a, B &b);
private:
   int m_b;
};
void f(A &a, B &b) { /* uses both A's and B's private data */ }

The only difference between static functions and friend functions is that a friend function can use several classes.

Using friend mechanism in c++ requires programmers that have about 10-15 years experience with the c++ way of programming, and thus initially you should avoid it. It's advanced feature.


答:
capitalizationIsUsuallyAtTheBeginning

underlines_are_usually_under_the_words_not_the_spaces

subject.verb(noun,noun)


答:
I had a similar problem, an apparent memory corruption in Objective-C, which I struggled with for many hours. But then me and my colleagues just took a walk for lunch, and I explained the problem (and one particular bit having to do with deserialization of an object in its init method), and basically explained the whole problem to myself.

(techy details: basically, I initialized and returned an object onto something else than self, so there were two allocs, but just one object returned. Memory shifted and went crazy, crashes, and the debugger didn't really know what to do with it either).


答:
Alanboy, I am afraid you are mixing two totally distinct things.

One thing is to implement a known algorithm for your company, while hiding the fact it was researched by another entity (that does not seem to be the case). This may be in some contexts be ethically reprehensible.

Other totally distinct thing is to make the code you created public just because it was based on research done by another entity. I don't see any valid reason why should you publish your code. Were we programmers publishing all the code we've wrote that used algorithms read from books or the internet, and virtually every single line of our code would have to be made public! 7/9 of windows would have to be open source!

I'll now turn the question around. Would you, as a face recognition researcher that publishes his results to the public, expect that any person alive that implements the algorithm to have to turn it public? I don't think so.

It is important to discern what is at stake here. Are you in any way effectively ripping off the author of the algorithm? It does not seem so.

I therefore see no good reason for publishing your code implementation. What you could, and should do, is to reference the name (and possibility, the author) of the algorithm in your application or its documentation.


问:
How do you encourage your organization to move from Java to Scala?
Has anybody's organization started the migration from Java to Scala? If yes, how do you do that? What can I do to encourage my colleagues to do the same?</p>

答:
I'm wondering why choose one or the other? Why decide to throw Java out the door and go Scala all the way?

There is no such thing as the perfect tool for the job. There's no reason to throw expertise in one language out the door completely and replace it with another.

I wouldn't want to work (anymore) at a company that focusses on one language or environment, tbh. It's better to know many things and pick the right tool for the job.

Next to that, it's hard if not impossible to get your organization to switch over to Scala completely. Instead, I'd try to get some projects (or even parts of projects) done in Scala, instead of going for the all-or-nothing approach. You could, for example, opt to test your Java code with Specs2, which has a pretty nice syntax compared to plain old JUnit - and it's not complex, confusing and hard Scala code and paradigms either, just syntactic sugar around defining behavior of your application.


答:
Friend functions are no different to member functions in terms of encapsulation. They can, however, offer other advantages- such as being more generic, especially where templates are concerned. In addition, some operators can only be specified as free functions, so if you want them to have member access, you must friend.

It's better to friend a single function than be forced to make something you don't want to be public. That means the whole world can use it- instead of just one function.

Title: C++ to friend or not to friend


问:
Is it okay to use a short EULA?
I need to add an EULA to my (commercial) software but I cannot afford a lawyer. Also I had a look at various EULA examples on the internet but they are all for specific software or countries, and are probably copied from other commercial software.

So I'm thinking about using a short custom EULA which would just mention the essential. Something like:

You may redistribute the trial version of this software

If you buy a license, you may not redistribute it or sell it

You may not sue me for any financial or material loss arising from the use of this software

This software is copyright XXX, all rights reserved.

Would that kind of EULA protect me in most cases? Also do you know of any company that use short EULA?

答:
I need to add an EULA to my (commercial) software but I cannot afford
  a lawyer.

Well, this site isn't a lawyer either. You need to hire one. If you can't afford it, then your project is fundamentally mismanaged and it's not something that can be fixed here. There's a reason that most companies offer EULAs that are six trillion pages long, and it's usually because they got sued a few times before making it that way.

You cannot go anywhere except a lawyer for legal advice.

Title: Is it okay to use a short EULA?


问:
Should I use one database per application or share a single database amongst multiple applications
I have multiple applications some that use data from the same sources.
Is it best practice (or what are the pros/cons) to:

leave the data in databases shared by multiple applications

saves space as only one database is needed

complicates indexing as different applications have different querying needs

import data daily into per-app databases

uses more space as duplicated data exists in per-app databases

easier indexing as each app can focus on its individual needs

I may have left out other advantages/disadvantages, please list if any, also how is this done at your workplace?

答:
Space is cheap these days, so I'd advise to use one database per application.

Sharing one database for amongst multiple applications has some serious disadvantages:

The more applications use the same database, the more likely it is
that you hit performance bottlenecks and that you can't easily scale the
load as desired. SQL Databases don't really scale. You can buy bigger machines but they do not scale well in clusters!

Maintenance and development costs can increase: Development is harder if an application
needs to use database
structures which aren't suited for the task at hand but have to be
used as they are already present. It's also likely that adjustments of one application will have side effects on other applications ("why is there such an unecessary trigger??!"/"We don't need that data anymore!"). It's already hard with one database for a single application, when the developers don't/can't know all the use-cases.

Administration becomes harder: Which object belongs to which application? Chaos rising. Where do I have to look for my data? Which user is allowed to interact with which objects? What can I grant whom?

Upgrading: You'll need a version that is the lowest common denominator for all applications using it. That means that certain applications won't be able to use powerful features. You'll have to stick with older versions. It also increases development costs a bit.

Concurrency: Can you really be sure that there're no chronological dependencies between processes? What if one application modifies data that is outdated or should've been altered by another application first? What about different applications working on the same tables concurrently?

Compared to that, data imports/ETL-processes are almost always pretty straightforward and simple. Load the data as often as you need to, space is cheap. You can account for scalability for each application independently, adjust and tweak the structures as you need them and there won't be concurrency issues. Side effects can be traced much easier, too.

Edit:
I'd like to point out, though, that as @Saeed mentioned, if you can encapsulate data manipulations in a service which is commonly available, then it's easier to share one database with multiple applications. As long as you don't need raw access that is a very good approach.


答:
I had a similar situation once. My problem was to build 3 applications, one for inventory management, one for procurement management, and one for managing users, i.e. employees. My recommendation is not to break databases physically per application, or join them physically per application. Rather, IMHO logical separation works better.

For example, all 3 applications needed to work with employee information. Both inventory and procurement systems were using the same information of goods and inventory items.

I created a shared database, in which I stored the information of users and goods. Then I built a service layer on top of it and I used those services in other applications. To show a list of all employees who are now in the company for example, I only needed to call a method from the service like GetOnWorkEmployees().

I also created a common UI for interacting with users and goods which was a separate web application in its own.

So, adding to what @Falcon has pointed to, I think that you can benefit from centralizing the common functionality among applications in one database.

Title: Should I use one database per application or share a single database amongst multiple applications

Body:
I have multiple applications some that use data from the same sources.
Is it best practice (or what are the pros/cons) to:

leave the data in databases shared by multiple applications

saves space as only one database is needed

complicates indexing as different applications have different querying needs

import data daily into per-app databases

uses more space as duplicated data exists in per-app databases

easier indexing as each app can focus on its individual needs

I may have left out other advantages/disadvantages, please list if any, also how is this done at your workplace?


答:
This is an elaboration of the second point in Ryan Hayes' answer as I have attended a few local .Net group events:

Preview of upcoming stuff:  There can be cases where an evangelist comes to show off some functionality that is coming soon.

Demonstration of tools or practices:  I remember attending a talk where connecting Biztalk and Sharepoint was illustrated.  Using jQuery in ASP.Net MVC would be another talk I attended for a specific example.

The giveaways and food are good too. :)

Title: What happens at [platform] user groups?


答:
It may or may not be worth the trade off in your situation, but maintaining data integrity is easier with a single database. In MS SQL Server at least, you cannot foreign key from one database into a different database. You can simulate foreign key behavior with triggers, but it's not particularly elegant.

In addition, creating local copies of the data can be dangerous when writes come into play. If AppA and AppB both have a copy of some shared data and AppA updates it, AppB will still have the old data. Or, you will have to setup triggers to keep the data in sync.


答:
The whole purpose of scientific publication is to disseminate new ideas so that others can benefit from them, either by using the ideas for practical purposes or as a basis for further research.  Certainly the researchers would be happy to know if you are using their ideas, and if you make improvements on the algorithm it would be appreciated if you published them (perhaps in collaboration with the original researchers), but there is absolutely no obligation to publish your code.  It would also be nice to mention the algorithm publically, perhaps in your documentation or even a workshop presentation.

However, in the modern world the ideals of scientific progress are not always appreciated, and there is the unfortunate possibility that the research institute has patented the algorithm.  The legal implications of that are the responsibility of your company managers and lawyers.


答:
Let's take a look at what you plan to write:

You may redistribute the trial version of this software

If you buy a license, you may not redistribute it or sell it

This is the basic information about the license under which you're distributing the software. It should be somewhere the users can easily find it, but doesn't have to be an annoying click-through dialog.

You may not sue me for any financial or material loss arising from the use of this software

This has no legal standing whatsoever. Whether or not someone is allowed to sue you is not something you can choose. The only thing you can do is to clarify that you don't claim the software is good for anything and people are using it at their own risk, but it probably won't make a difference either way in most jurisdictions.

This software is copyright XXX, all rights reserved.

This is unnecessary. You don't have to explicitly claim copyright over something (though it might help to prevent people from accidentally violating it.

Title: Is it okay to use a short EULA?

Body:
I need to add an EULA to my (commercial) software but I cannot afford a lawyer. Also I had a look at various EULA examples on the internet but they are all for specific software or countries, and are probably copied from other commercial software.

So I'm thinking about using a short custom EULA which would just mention the essential. Something like:

You may redistribute the trial version of this software

If you buy a license, you may not redistribute it or sell it

You may not sue me for any financial or material loss arising from the use of this software

This software is copyright XXX, all rights reserved.

Would that kind of EULA protect me in most cases? Also do you know of any company that use short EULA?


答:
I understand the desire for a simple, no foolin' around statement of what you intend, but there's no point in having a EULA at all if it's not going to do the job that it's supposed to do, which is to protect your rights and to define what the user is and isn't allowed to do. Legal language is like computer code -- it should unambiguously define your intent for every situation that might come up. Can you imagine a non-programmer writing a useful application in 4 lines?

So lets look at your "EULA":

Line 1: Who is "you"? What is "this software", and what is the "trial version"? What does it mean to "redistribute"?

Line 2: I understand that if I buy a license I may not redistribute that license, but what does that have to do with the software? Also, I can still redistribute if somebody else bought my license, right? Under what circumstances can someone transfer their license to someone else?

Line 3: My state has a law that specifically disallows provisions that unilaterally limit my right to sue. Stick that in your pipe and smoke it.

Line 4: That's a copyright statement. I don't think you want it as part of your EULA. If I can get the EULA tossed does the copyright go with it?

I'm not a lawyer -- expect anyone who has had a year of law school to be able to shoot a lot more holes in your agreement than this.

I'd suggest that you talk to a real lawyer, get a real EULA, and perhaps supplement that with a simple statement (written by your lawyer) in plain English that summarizes the EULA.

You feel that you can't afford a lawyer, but at the same time you describe your software as "commercial." You must feel that your software has value since you expect people to be willing to pay for it, so it would seem smart to protect your future revenue stream and your investment in the product by getting some proper legal advice. Don't just wing it with a half-baked list of terms that may or may not carry the legal meaning you intend.

Title: Is it okay to use a short EULA?


答:
I would say you did the right thing, just possibly took too long to get there. For things like third-party open-source libraries I prefer to do a quick "spike" on the ones that seem most promising. The "spike" is a quick feasibility test, with small isolated bits of code, to quickly determine if the library will be suitable to the problem.  If it's not then you can quickly move to the alternative. </p>

<p>Of course if none of them are suitable you will be faced with writing your own implementation or, for the one that is the closest match, you can either fix the issue or work with the author as MainMa suggests.  In the case of fixing it you would employ standard debugging techniques, but the spike method can help with that in that you have less of your own code getting in the way and can isolate better the third-party code that is problematic. </p>

Body:
I would say you did the right thing, just possibly took too long to get there. For things like third-party open-source libraries I prefer to do a quick "spike" on the ones that seem most promising. The "spike" is a quick feasibility test, with small isolated bits of code, to quickly determine if the library will be suitable to the problem.  If it's not then you can quickly move to the alternative.

Of course if none of them are suitable you will be faced with writing your own implementation or, for the one that is the closest match, you can either fix the issue or work with the author as MainMa suggests.  In the case of fixing it you would employ standard debugging techniques, but the spike method can help with that in that you have less of your own code getting in the way and can isolate better the third-party code that is problematic.


问:
Common to use linear programming?
I have read about linear programming and its content and I wonder if this way of programming is common to use in the market? I often hear about object oriented programming but not linear programming.

I would like to hear a discussion about it.

答: Linear programming is not a style of computer programming. It is a subclass of mathematical programming, which in turn is a subclass of mathematical optimization. A mathematical program is an optimization problem where the function to be optimized is subject to constraints. In linear programming, the function to be optimized is a linear function of the inputs, as are all of the constraint functions.</p>

Title: Common to use linear programming?


问:
How have you got chances to learn multiple languages?
I read A programmer should concentrate on at least how many languages?, and I found out that I don't know languages in number 2, 3 of first answer. I want to learn more languages to increase my knowledge and programming skill. However, usually in companies they use fixed framework and languages and changes seldom. So I'm not sure if I can get a chance to learn those languages and I think it would be same to other programmers.

However, I've seen many developers who knows multiple languages in here. How do you get chances to learn many languages?

Update

I think, there are many people who feel uncomfortable because it seems I don't want study in my spare time at all. Actually, that's not true.:) I'm an enthusiast programmer and that's why I posted this kind of question here. I study in my spare time but I just thought it would be not enough to be skillful in languages. Anyway, thanks for all answers!

答: You just have to make the time to do it. Check out the book "Seven Languages in Seven Weeks" from the Prags. It will give you an intro to seven very interesting languages and from there you can go all sorts of places. </p>


答: The best way to learn a new language when you have a problem to solve. Rather than just using what you are comfortable with, spend some time to look at what tools (languages, frameworks, libraries) might be useful in helping you solve the problem. If you have the time to learn the new tool, go for it. You might not be able to do this at work, when you have schedule pressures and technology limitations driven by outside factors, but there's no reason why you can't take this approach to personal projects.</p>

Title: How have you got chances to learn multiple languages?

Body:
I read A programmer should concentrate on at least how many languages?, and I found out that I don't know languages in number 2, 3 of first answer. I want to learn more languages to increase my knowledge and programming skill. However, usually in companies they use fixed framework and languages and changes seldom. So I'm not sure if I can get a chance to learn those languages and I think it would be same to other programmers.

However, I've seen many developers who knows multiple languages in here. How do you get chances to learn many languages?

Update

I think, there are many people who feel uncomfortable because it seems I don't want study in my spare time at all. Actually, that's not true.:) I'm an enthusiast programmer and that's why I posted this kind of question here. I study in my spare time but I just thought it would be not enough to be skillful in languages. Anyway, thanks for all answers!


答:
I find the best way to learn a language is by using it immediately to make something useful or that you need.

For example I found myself in the need to automate many operations I had to do manually every time. Repetitive tasks, files and folders creation, etc... so I simply chose a scripting language to make some useful tool. I went for Perl, and started to learn the syntax and the functions I needed to make my script, thanks to online tutorials and books.

In a couple of days I had my tool up and running, then in my spare time I kept learning new things about the language and adding more functionalities to it.

Another great option that comes to mind is: if you don't find a language you like, or you think doesn't fit your needs completely, you can still create your own language.

I'm doing it now with Perl, I chose a syntax that would help me best solving my specific problems (since you are writing your own language, you may want to choose the right syntax for the job, the one which best describes and solve your specific domain issues).

The result? Development is now much quicker and the code itself is much more descriptive because it's a domain specific language. I asked a question related to this topic some weeks ago with many useful links.

You can use any scripting language to create a new one, even with PHP.


问:
Do some languages make it easier to build graphically-intensive GUIs?
I made an algorithm that has a good potential use for a commercial application. I'm thinking of making a GUI, and since it's computationally expensive, I'm thinking of putting it "on the cloud" to offer the numerical part as a service. What I'm thinking is making a GUI, and then the users submit the work to the server. This GUI could be made open software (in fact, very probably will be). The GUI has a lot of graphics. Imagine something like making picks on surfaces plots, taking a look at those picks with different tools, and using numerical mathematics on those picks.

Are there languages that make this work easier? What, specifically, about them aide in creating GUIs like this?

答: Partially. The syntax of some languages may seem to make more sense when creating a GUI, and the implementation of a language may allow a GUI library to better handle interaction with the low-level operating system.</p>


答:
Just start using it. Obviously, building a production system from scratch in a language you have never had any exposure to is a bad idea, but here's a few suggestions:

Learn in your own time. Pick a project you find interesting, where you are confident you can finish it on your own. It's best to do some introductory reading on your new language to judge if it is suitable - each language has strengths and weaknesses, and it's best to start with a problem that the language was designed to excel at.

Start doing maintenance tasks on an existing project. This way, you can pick up a large part of the language without even reading documentation: a lot can be inferred from example code, and for the parts where you do need to read documentation, it will be much clearer because you've seen the code already. It's also easier to look up "what does this code do" than "how can I write code that does X".

Use your new language for small tools and helpers you need: shell scripts, throwaway code for specific tasks, quick calculations (e.g., the interactive interpreters of many dynamic languages - python, lisp, haskell, etc. - make for excellent calculators). Not all languages are suitable for this though.


答:
Pick something relatively small that you've done in one language, and develop a drop-in replacement in another language.  Do this just to challenge yourself.  In order to complete it, you'll learn a great deal about the other language.

Just within the past week, I decided to learn and re-write a web-service back-end in NodeJS (previously a JSP service.)  It only took about a day to get the bare-bones service working, and a few days later I had expanded its infrastructure, error handling, logging, and added live monitoring.  It is now superior to the original.  Whether management accepts it or not is immaterial, as I've learned something and am very happy with it.


答:
Any bug can be 'found' in the sense that you'll end up in one of the following situations:

You can pinpoint the exact file and line in your code where things go wrong. If you're here, good, you have practically solved the bug.

You conclude that the requirements that aren't met are in fact not well-defined: they may be too vague, contradictory, or ambiguous. The solution then is to go back to the customer and get the requirements straight before throwing random changes at your code.

You can pinpoint a section of your code where things go wrong, but that section is so complicated that analyzing its behavior and comparing it to the intended behavior would take very long. This is an alarm bell, and you should  rewrite that code immediately.

You can pinpoint the bug to be somewhere outside your own code: a library; a browser's implementation of javascript, CSS, HTML, or whatever you're using; another host's implementation of a network protocol; etc. If you can, replace the faulty code with an alternative that works. If you can't (e.g. with a javascript bug), find a workaround, but integrate it into your code in a way that makes switching back to compliant behavior easy and straightforward. Ideally, you want to be able to detect a non-compliant environment and adjust automatically.

So, while you can't always find the bug in the sense of the first bullet point, you should always be able to end up in one of these four situations, and they all have solutions (although some can be rather painful).


答:
Here's some problems that could happen in these situations:

Since you used someone elses work for it, you don't know how much effort there is to create it again

If your product becomes very popular, and everyone in the world absolutely needs it, it's based on work amount estimates that are not known

once your competitors try to do the same, it fails => they cannot help you with handling the amount of customers

then you'll have big problem because serving the whole world from your small company is pretty much impossible

You'll receive large amounts of money as a substitute to limit the amount of damage your actions have caused -- and then you need to work very hard or the world is going to suffer

but then you need to figure out how to create improvements to the core work, and it's going to fail if the work amount you rely on is too large

Of course the competition sometimes also makes this same mistake, and gets better product out in very short time; and the people who could actually handle the amount of customers is losing their position.

Making the algorithm public just invites other people to do the same mistake.

On the other hand, some stuff is absolutely impossible to do at all without large amount of previous effort. Some stuff that could be so much more useful than what stuff already exists.

Being very successful is not very nice thing. That's why the work amount usually restricts the scope of how widely the products can be distributed. You should aim to take over the world obviously, but try to rely on as little external work as possible.


答:
"What would an OOPs expert say ..." It mostly depends on how expert he is in C++, that -by its own specification - is not (and doesn't want to be) a language for purist.

OOP Zealots don't use C++ (they prefer Smalltalk, and like Java).

Functional programming zelots don't use C++ (they prefer LISP, and its successors)

The most of OOP experts dislike friend function simply because they want the OOP part of C++ to behave like Smalltalk. But C++ is not Smalltalk, and they cannot even understand that friend don't break encapsulation, for the very simple reason that a function cannot be friend of your class without your class wants it.

And from the "functionality" stand point, between a.fn(b) and fn(a,b) there is no difference (where fn is a friend): the involved parties are the same. Simply, one syntax may be more suitable than another: if fn is commutative regarding a and b, fn(a,b) is probably more suitable then a.fn(b) (where a looks having a "special role" that, in fact, it doesn't.)

Title: C++ to friend or not to friend


问:
Determine Better Coding Practice
As a new programmer, it has always been hard to create applications, because I am still at the learning stage.

I understand that to achieve a particular affect or function in an application, there will be numerous ways to achieve the same result.

However, should I just purely create a function to it's working state, which means that as long as it works, just as the way I want it to, then it should be fine.

Can any fellow programmers of a higher level kindly let me know the right way of doing things?

答:
I am personally fan of the High Integrity C++ standard.

The rules are extremely objective, there is no naming convention for example.

3 Class

3.1 General

High Integrity CPP Rule 3.1.1 Organise 'class' definitions by access level, in the following order: public, protected, private. (QACPP 2108, 2109, 2191, 2192, 2195)

Justification Order by decreasing scope of audience. Client program designers need to know public members; designers of potential subclasses need to know about protected members; and only implementors of the class need to know about private members and friends.

```<code>class C // correct access order
{
public: // ...
protected: // ...
private: // ...
};
</code>```

Reference Industrial Strength C++ A.12, A.13;

Title: Determine Better Coding Practice

Body:
I am personally fan of the High Integrity C++ standard.

The rules are extremely objective, there is no naming convention for example.

3 Class

3.1 General

High Integrity CPP Rule 3.1.1 Organise 'class' definitions by access level, in the following order: public, protected, private. (QACPP 2108, 2109, 2191, 2192, 2195)

Justification Order by decreasing scope of audience. Client program designers need to know public members; designers of potential subclasses need to know about protected members; and only implementors of the class need to know about private members and friends.

class C // correct access order
{
public: // ...
protected: // ...
private: // ...
};

Reference Industrial Strength C++ A.12, A.13;


问:
Storing passwords for usage in scripts
There are few situations that require users to provide their password while automating things during development process. Site deployment is only one of the common situations. Creating dmg files under OS X requires password as well. Most of the command line utilities used in scripts has an ability to receive a password via stdin.

Providing password each time the script is run kinda defeats the purpose of "automatic". Storing it plain text in the script defeats the purpose of "password". What is the most optimal approach to providing passwords to scripts that requires them?

答:
Without knowing more specifics about this particular situation, it seems as though you are unable to "have your cake and eat it too".  If there is no other option (my disclaimer here is that I'm unfamiliar with OS X), then you need to choose between automation and security.

Who has access to these dmg files?  If administrators or trusted users are the only ones, then you are probably fine with storing this passwords in plain text, as long as these are dedicated passwords and don't extend beyond the necessity of the script completion.

Is this a truly unattended script?  If it is not, and it's a minor inconvenience to input a password, then you may be better off just sucking it up and entering in the password as the only step for these script files.

Again, somebody with OS X experience might give more applicable suggestions, but a general rule of thumb for security is deciding which is more important (security vs. adminsitration) for the given situation/environment.

Title: Storing passwords for usage in scripts


答: Put it in a separate configuration file only accessible to you, and let your scripts read in said configuration file at execution time.</p>

Title: Storing passwords for usage in scripts

Body:
There are few situations that require users to provide their password while automating things during development process. Site deployment is only one of the common situations. Creating dmg files under OS X requires password as well. Most of the command line utilities used in scripts has an ability to receive a password via stdin.

Providing password each time the script is run kinda defeats the purpose of "automatic". Storing it plain text in the script defeats the purpose of "password". What is the most optimal approach to providing passwords to scripts that requires them?


问:
What should you leave behind for your successors?
Assume that you're a sole developer leaving a job. What kind of information/material, outside of the code itself, should you create and leave behind for your replacement?

An obvious answer is "whatever you would want at a new job" for sure, but it's been a while since I started a new job, and I forget what the most important things that I needed were back then.

I'm thinking:

accounts/passwords

location of equipment, backups, software CDs

What else?

答:
Documentation of the programs you have written e.g. their purpose, location of source files for future development, passwords, etc..

This can either be within the code as a comment or outside in plain sight.


答:
These sorts of questions always baffle me.  I've used 7 languages professionally, have written code in around 5 more languages in hobby and academic settings, and can read code in maybe a dozen more languages.   Not once have I learned a language just for the sake of it.  There's always some concrete and immediate goal in mind.  For example, this weekend I learned enough Android libraries to start working on an app for my family.  If we had iPhones I would have learned Objective-C.

My feeling is that knowing multiple languages is a symptom of being a skilled, or at least enthusiastic,  programmer, not a cause of it. If you can't think of a compelling reason to learn a new language, I don't know how much it would benefit you.


答:
It is not always convenient to make all the functions related to a C++ class members of that class.  For example, imagine an implementation of vector algebra with scalar multiplication.  We want to write:

```<code> double a;
 Vector v, w;
 w = v * a;
</code>```

We can do this with a member function:

```<code>public class Vector {
 ...
 Vector operator*(double a);
}
</code>```

But we would also like to write:

```<code>w = a * v
</code>```

This requires a free function:

```<code> Vector operator*(double a, Vector v)
</code>```

The friend keyword was added to C++ to support this usage.  The free function is part of the Vector class implementation, and should be declared in the same header and implemented in the same source file.

Similarly we may use friend to simplify the implementation of tightly coupled classes, like a collection and an iterator.  Again, I would declare both classes in the same header, and implement them in the same source file.

Title: C++ to friend or not to friend

Body:
It is not always convenient to make all the functions related to a C++ class members of that class.  For example, imagine an implementation of vector algebra with scalar multiplication.  We want to write:

 double a;
 Vector v, w;
 w = v * a;

We can do this with a member function:

public class Vector {
 ...
 Vector operator*(double a);
}

But we would also like to write:

w = a * v

This requires a free function:

 Vector operator*(double a, Vector v)

The friend keyword was added to C++ to support this usage.  The free function is part of the Vector class implementation, and should be declared in the same header and implemented in the same source file.

Similarly we may use friend to simplify the implementation of tightly coupled classes, like a collection and an iterator.  Again, I would declare both classes in the same header, and implement them in the same source file.


问:
How do you change how intellij auto formats code?
IntelliJ does some odd formatting with Javascript code and I am trying to figure out how to get it to stop formatting this way.  Whenever I chain jQuery functions together, it over indents the auto created code such as this:

```<code>$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
        /* this is where the cursor and closing braces end up */
        })
</code>```

I want it to look like this:

```<code>$('#something').focus(function() {
    /* Do some stuff */
}).blur(function() {
    /* cursor and closing braces indented normally */
});
</code>```

How do I change this?

答:
All the settings you need to control code formatting in intellij are in File>Other Settings>Template Settings.

If Javascript is not listed (i.e you've not installed a Javascript plugin), you can define the code formatting under the General tab and then the Other tab. There will be options for controlling indentation and spacing.


问:
Does project architecture have a strong relation to used libraries?
Programmers, when it comes to talk about popular patterns in enterprise applications, preach that you should code against interfaces to remove strong relations between components; doing this will aid in changing concrete types while minimizing changes in other areas of the application. The underlying assumption is that interfaces are all about abstractions. When it comes to real life it is almost impossible. Lets use an example:

Lets say you currently use an ORM framework in your application, which you abstracted by applying the repository pattern. Now, can you really change ORM framework seamlessly?

```<code>public interface IRepository<T>
{
    T GetById(int id);
    void Add(T entity);
    void Remove(T entity);
    void Update(T entity);
    IQueryable<T> Query(Expression<Func<T, bool>> filter);
}
</code>```

Theoretically, this implementation can be applied to the rest of the application, but many questions remain about the actual application of this pattern:

How does this pattern shield me from the internal process of libraries?

How does the abstraction deal with the variation in exceptions thrown by each library?

If I have selected an ORM which provides a caching mechanism internally and I later decide to switch to an alternative ORM with no such support, how does the pattern handle this?

So, from this, I believe that the project architecture is strongly influenced on the libraries that are used. Is there anything wrong with this? Am I assuming too much from this pattern?

答:
What you describe is just another case of Joel's "Law of leaky abstractions". Read his great blog entry about this topic:

```<code> http://www.joelonsoftware.com/articles/LeakyAbstractions.html
</code>```

On the other hand,  when you want different repository implementations to be interchangeable, just conferring to some interface is not enough, that's correct. At least, they have to follow the Liskov substitution principle. This principle says that your different subclasses of IRepository must behave all alike, for example, consistent use of exceptions for error handling,

Well, the ORM example is of course a tough case, since ORM's are often complex components where even things like performance requirements or memory overhead can make the difference between a component feasible for your project or not. The dependency inversion principle (that's the pattern you described) applies much easier to smaller components. And it applies much better to components you have under your own control - don't expect third-party components to be interchangeable easily if they are not especially designed for that purpose.

IMHO the real value of an interface IRepository is not the interchangeability of one ORM against another. The real value is that you can create a mock implementation for your repository allowing lightweight unit tests.

Body:
What you describe is just another case of Joel's "Law of leaky abstractions". Read his great blog entry about this topic:

 http://www.joelonsoftware.com/articles/LeakyAbstractions.html

On the other hand,  when you want different repository implementations to be interchangeable, just conferring to some interface is not enough, that's correct. At least, they have to follow the Liskov substitution principle. This principle says that your different subclasses of IRepository must behave all alike, for example, consistent use of exceptions for error handling,

Well, the ORM example is of course a tough case, since ORM's are often complex components where even things like performance requirements or memory overhead can make the difference between a component feasible for your project or not. The dependency inversion principle (that's the pattern you described) applies much easier to smaller components. And it applies much better to components you have under your own control - don't expect third-party components to be interchangeable easily if they are not especially designed for that purpose.

IMHO the real value of an interface IRepository is not the interchangeability of one ORM against another. The real value is that you can create a mock implementation for your repository allowing lightweight unit tests.


答:
Accounts & Passwords

Server information

Good code

Documentation

Database diagrams & explanations are amazing

List of oddities in the code

Procedures

Explanation of manual processes, or occasional, non-obvious, work

List of programs they used or found helpful

Contact information ;)

Title: What should you leave behind for your successors?

Body:
Assume that you're a sole developer leaving a job. What kind of information/material, outside of the code itself, should you create and leave behind for your replacement?

An obvious answer is "whatever you would want at a new job" for sure, but it's been a while since I started a new job, and I forget what the most important things that I needed were back then.

I'm thinking:

accounts/passwords

location of equipment, backups, software CDs

What else?


问:
Do I need to understand pointers to use C++?
Well, I love C++, I have been using it for a while: I like all the libraries (Allegro, SDL, QT, Ogre, etc.), but I have a problem: I don't understand pointers.

Do I really need them ? I just program for fun: but I want to study it some day.
Thanks.

答: Yes, definitely. They are a fundamental concept of programming, no matter if you program in a language that supports direct pointer management or not, but even more so if you do.</p>


答:
Pointers are an integral part of C++ and though you can avoid them and use references instead, you will find a lot (A LOT) of code that relies on the efficiency and power of pointers. You cannot write a QT GUI app without using pointers.

I suggest you get a good book on pointers and master them. Even experts sometimes get confused with pointers, but eventually, the power and the flexibility that comes with pointers is just too lucrative.
Try this and this

PS: DO NOT make a transition to Java, just because you don't get pointers. You will, and you WILL understand them, if you're passionate enough.

Title: Do I need to understand pointers to use C++?

Body:
Well, I love C++, I have been using it for a while: I like all the libraries (Allegro, SDL, QT, Ogre, etc.), but I have a problem: I don't understand pointers.

Do I really need them ? I just program for fun: but I want to study it some day.
Thanks.


答:
AnyOne,

The interface you have shown is an example of a typical abstraction that sits between a client and a CRUD System. As with all patterns, there is a point where you need to recognize the product is being over engineered. Compensating a lack of domain knowledge by building in systematic flexibility is one of the many evils of software development. Your a programmer, not a prophet.

You mentioned caching. The interface you have shown makes no assumption that caching is used, so the interface is shielding the client code from this difference if you choose to switch. Performance wise, you may notice a difference, but the code won't care.

With regards to exceptions, you can build your own hierarchy that wraps specific exceptions. I believe the Spring framework takes this approach with JDBC templates as the JDBC API has only one exception - SQLException, which doesn't shield client code from JDBC driver specific issues, so Spring gives you an exception hierarchy that wraps most of the driver specific errors that can happen during runtime.

So, your choice of libraries may influence the performance and runtime behavior of your system, but general purpose interfaces should not care about specific features of an underlying implementation as that would result in what Spolsky referred to as a leaking abstraction.

Title: Does project architecture have a strong relation to used libraries?

Body:
Programmers, when it comes to talk about popular patterns in enterprise applications, preach that you should code against interfaces to remove strong relations between components; doing this will aid in changing concrete types while minimizing changes in other areas of the application. The underlying assumption is that interfaces are all about abstractions. When it comes to real life it is almost impossible. Lets use an example:

Lets say you currently use an ORM framework in your application, which you abstracted by applying the repository pattern. Now, can you really change ORM framework seamlessly?

```<code>public interface IRepository<T>
{
    T GetById(int id);
    void Add(T entity);
    void Remove(T entity);
    void Update(T entity);
    IQueryable<T> Query(Expression<Func<T, bool>> filter);
}
</code>```

Theoretically, this implementation can be applied to the rest of the application, but many questions remain about the actual application of this pattern:

How does this pattern shield me from the internal process of libraries?

How does the abstraction deal with the variation in exceptions thrown by each library?

If I have selected an ORM which provides a caching mechanism internally and I later decide to switch to an alternative ORM with no such support, how does the pattern handle this?

So, from this, I believe that the project architecture is strongly influenced on the libraries that are used. Is there anything wrong with this? Am I assuming too much from this pattern?