答:
Go back to basics. Writing code is only one of several important programming skills; if he can't solve problems, teaching him language syntax won't help.

Give the guy a simple problem and have him write down, in English, the steps needed to solve that problem. Make it something really simple, like FizzBuzz or the sieve of Eratosthenes.

When he has come up with a solution, sit down and run through it by hand together with him. If it's correct, great. If not, try to help him identify and solve any problems. Don't do it for him -- just provide some guidance. If his sieve "program" emits an 8, you might point out that 8 isn't prime and ask how that happened. The idea here is to get him thinking like a programmer. He might have known how to do this once, so hopefully it's just a matter of getting him back on track.

When the "program" is correct, ask him to translate it from English to whatever language you're using, again on paper. He may need more help from you at this point since it sounds like he really doesn't speak the language. Have him keep a list of every new language construct, what it's for, and how it's used.

When the translation is done and looks correct to you, have him type it into a computer, compile, and run. It probably won't run the first time; that's fine, the idea here is to get used to working with a compiler and learn to interpret errors. Again, your help will probably be required.

When the program runs, verify that it produces the correct output. If so, go back to step one with a new problem. Repeat as necessary until he's comfortable with the process and can solve simple problems, then slowly increase the complexity of the problems.

At some point, one of his programs will produce incorrect results, or will fail to work at all. Show him how to use a debugger and other tools to identify and fix the problem.

Don't expect miracles. Nobody learns to program in a week. Keep at it, a little at a time, and hopefully you'll soon be able to give him some simple real-world tasks on your project. Along the way, he'll have learned at least some basic skills, and you'll have gotten some experience in helping the people you manage become more effective.

Title: How to teach basic principles to programmers

Body:
In order to get experience as a team lead, I was recently given the task of supervising a programmer.

What I found out is that he is having a problem in writing a simple if condition. He has issues with string. And he doesn't know how to pass a variable in the addClass function of jQuery with an if condition.

And he doesn't know when to use a for loop. Or even what a for loop is used for.

How to make him understand these basic concepts quickly?

I told him to Google for how to use if condition for addClass variable. But he didn't find it, then I told him to do it quickly in the early morning, when discussing he was giving reasons that it is what that, then I told him I show you how to do that,
then he told me, you should have done it before.

What should I reply to him? He is telling me that you should tell me everything or Should I do it and show him every time? It may take lot of time, and every time I have to do a task. I want him to be independent.


问:
Bluetooth or Bump API for membership card functionality?
I am looking to implement membership card functionality inside a mobile application for a local coffee shop. The idea is to make payments at the point of sale, and deduct the amount from the client's prepaid account.

I was looking into NFC functionality, but only a few devices support them (and most are not available in Montreal yet).

The other idea is to use the Bump API, which would work great for iOS and Android.

The last resort would be to use Bluetooth somehow.

Any thoughts on any of these approaches, or for those who have tried this, any pros and cons for these ideas.

答:
Have you considered using a plain old bar-code?  It's immune to 'sniffing', people understand how it works (at least much more than NFC or Bump), and it works on pretty much every device.  It would also make it very easy to code the app (and also make it not even require a phone, you could just use a key-chain or wallet card).  My local supermarkets both just use bar-code based membership cards, and each have an app with the ability to store those cards on the phone.

The benefit for bar-code based membership cards would be also the ability to scan/store the bar-codes in the app of the user's choosing, as there are some "membership card storage" apps already on the market, and you wouldn't have to duplicate functionality for users of said applications, they could store the cards and display the bar-code as they choose.  Until NFC becomes ubiquitous (if ever), I'd just go with a bar-code.

ContentLicense: CC BY-SA 3.0


问:
How to determine the effectiveness of a code review process?
We've introduced a code review process within our organisation and it seems to be working well. However, I would like to be able to measure the effectiveness of the process over time, i.e. are we not finding bugs because the code is clean or are people just not picking up on bugs?

Currently, we don't have an effective fully-automated test process. We primarily employ manual testing, so we can't rely on defects found at this stage to ensure that the code review process is working.

Has anyone come across this issue before or has any thoughts on what works well in measuring code reviews?

答:
While largely it is true that code review would pick up problems which are rather latent that testing may or may not catch. However, in my opinion you may have a really stable (practically bug free) code but still written in such a way that it is extremely non-readable or not quite maintainable. So it may be that code review may NOT find bugs if there are no real issues actually in the code.

Having said that, i would really ask, why would one want to do code review? The simple reason why it is important is that the code should be improved to be made more readable, maintainable and evolvable. Many people should be able to read cleaner code and make sense out of it. In that sense, simplest objective of the code review process is to produce clean code. So the measure of effectiveness is how much cleaner the code is now.

As you wanted to have a measurable effectiveness - here is what i would suggest:

Metric related to amount of rework -
Number of time the rework is applied in a same given module/object/work item is a measure of how poor that code is in terms of maintainability. When effective code-review is applied, how often are we able to reduce the re-work request on the same module?

Metric related to amount of change that every change request incurs.
When every time a change request occurs - a poorly factored code will always have larger number of modules get affected. A measure would probably indicate that after a code review - a was that any reduction of such spread of change for a similar change request in the past?

Metric related to average speed with which a change request can be responded.
When the code is cleaner - faster and better it is to respond to required changes. After the code was cleaned in the review process, die we find any speed up in responding the similar size request.

I am not putting exact units of measures - you can probably craft more accurate measure about this from this approach. There can be more extension formalism in the above approaches on this.

Basically, my point is that instead of looking at the number of bugs the code-review process identifies; we should measure the effectiveness in terms of whether code-review has been able to bring code to be more cleaner, leaner and easy-to-maintain state; hence, we can gauge that effectiveness if we see that similar change requests in future becomes more efficient to be responded.


问:
How far is the trail from Java to C / C++?
I want to find out how easy or hard the transition to C / C++ is for a mid-experienced Java programmer.

I've already read the questions about "C++ for Java Programmers" and "Is it necessary for Java programmers to learn some C/System programming?".

Everything sounds very interesting, but I want to specifically add the aspect I have experience in Python programming as well. I'm aware that you are able to run python on the JVM with jython, but I think it will provide better experience to get exposed to new concepts and to explore Python's origins. My target environment is mainly Linux.

Could you estimate (perhaps even tell from your own experience) how hard it would be and especially give a hint as to whether it would be better to go with C or C++ in order to interact with Python?

答:
C is a very small language, so any experienced programmer willing to put enough effort and time should be able to become proficient in it in 3 months in my opinion (this includes creating some medium to large projects using the language, or at least studying some created by experienced C programmers).

C++ is a whole different story, though, given its size and complexity of features. I am not that experienced with the language, but I would guess you would need at least one year working with it to say you have a decent grasp of the language, and 3+ years to say you have mastered it.

Considering you are coming from Java I would also not recommend to skip C and jump directly into C++, as you might lose some interesting insights C provides.

As for interacting with Python, I believe C would be easier.


答:
Since C++ can use C interfaces perfectly well, and C++ offers many very useful additional features (to the point where C's original features are almost completely useless in comparison)  there's absolutely no reason to use C instead unless you're trying to compile for a target where no C++ compiler exists.

Now, it's going to be a hard transition. Java and C++ share some syntax, and that's about it. You'll have to become intimately familiar with the god-awful, like the compilation model, and the glorious, like templates.

However, more fundamentally, C++ uses static, strong value typing, whereas Java uses relatively weak reference typing, and there's virtually no such thing as good Java code which is also good C++ code. In addition, C++ programmers are expected to be familiar with a much wider range of techniques, including expression templates, functional interfaces, etc. This makes for a pretty hard trip.

Title: How far is the trail from Java to C / C++?

Body:
I want to find out how easy or hard the transition to C / C++ is for a mid-experienced Java programmer.

I've already read the questions about "C++ for Java Programmers" and "Is it necessary for Java programmers to learn some C/System programming?".

Everything sounds very interesting, but I want to specifically add the aspect I have experience in Python programming as well. I'm aware that you are able to run python on the JVM with jython, but I think it will provide better experience to get exposed to new concepts and to explore Python's origins. My target environment is mainly Linux.

Could you estimate (perhaps even tell from your own experience) how hard it would be and especially give a hint as to whether it would be better to go with C or C++ in order to interact with Python?


问:
Is it a really required skill to program without API documentation?
I barely passed my Java programming exam today. I had to answer some general questions about threading which I did well and to write a little threaded program which was worse. I had to connect my laptop to the projector screen and write the program right away. My first attempt was to use anonymous classes but I forgot the exact syntax. Maybe because of some excitement or maybe because last two weeks I was coding mostly in php. Then I asked is it allowed to use the API documentation. The answer was "NO". So I decided to go another way around and I implemented Runnable. The program was doing what was requested at the end. Of course the examiners noticed my first fail and that affected my score greatly. I was amazed that it was not allowed to use the API documentation.

So, my question is: Is it really important to be able to code flawlessly without API documentation? Should I develop this skill? Is it really important in the real world and in the work environment? While on programming courses I focused on learning patterns, developing skills to write good design applications, skills to use API and find the necessary information fast. I was not trying to learn how to program without API documentation. Is it must-have during job interviews (coding without API documentation)?

答:
In Real Life™, I would rate this skill as a "nice to have", but not at all required. In a university setting it is different, however.

An ability to code without documentation can be used as an indirect indication of student's familiarity with the subject. In a sense, seeing how you solve a problem without looking at the documentation tells the professor that you have practiced using the API before -- by doing your homework and other assignments, or perhaps even by programming for fun on your own. A smart person with a cursory understanding of the API in question should be able to figure out almost any Java API on her own by looking at the documentation. This is not a coincidence: programmers are expected to learn on the job, and the API documentation for popular programming systems, including Java, is structured to help them learn quickly. To helps programmers complete their tasks without requiring prior familiarity with the API, the documentation often supplies short, self-contained examples, which illustrate the concept in a brief and concise way. This covers a wide range of tasks, including most problems that you may see at an examination.

Unfortunately, this works directly against your professor's goal of measuring your knowledge of the subject, as opposed to measuring how smart you are. Hence, in a university settings it is not unreasonable to ask you to code without looking at the documentation.

ContentLicense: CC BY-SA 4.0


问:
What would be the best way to spend a day learning Guice?
I have just joined a company where the major projects, including the one i have landed on, use Guice. I have never used Guice. I am familiar with dependency injection, in the shape of CDI (a bit) and the obscure but decent Nucleus (part of ATG).

We just completed a successful iteration, so tomorrow (friday the 13th!) is a day that developers have to spend on things they think are valuable.  I have some meetings during the day, but i will have about four or five hours to do this. I have a machine to myself, with Eclipse installed and configured to my liking.

I would like to spend my day learning about Guice.

How should i spend my time?

(I'm not entirely sure this is an appropriate question for Programmers, but there's only one way to find out)

答:
My experience with guice is that a great way to learn it is just to pick a few different scenarios for something your company already has, think of a use-case for each one, and work on implementing them using guice principles.

So when I went to learn it I took an already existing REST server that I had been working on for my company.  I decided not to greenfield it, since I find the only real way to learn a new toolkit is to use it on a real-worldish project, and we already had a unit test suite set up for that service, so I would know if I caused a regression. I set a series of goals for where I wanted to take the project with guice, the first three were roughly:

Use guice to replace all of the various singletons, DAOs, etc. Essentially objects that are poster-children for dependency injection and where DI makes them easier to test. This meant I had to figure out how to get guice integrated with junit very early, and also provided an opportunity to abstract out some modules I wanted injected during test and some other modules I wanted injected when in production.

Get as much of the application to show up using the Grapher as possible.  This also had the advantage of getting most of it integrated via providers, modules, etc.

Abstract out the logging we were doing in the entry-and-exit methods using AOP.

So at the end of this I had a great graph of how our classes were interacting, all of the unit tests were passing, and I had simplified and improved our logging facilities for the REST interface.

I had substantially longer than a day (and I also had a longer list, including getting the JPA persistence piece integrated), but those seem like reasonable areas to start with if you have a suitable project lying around (or can make one quickly, e.g., by creating a quick REST service to do something that might be useful or fun).

I do highly recommend starting with something that either has tests or that you can write some basic tests for quickly, since that will let you tweak things or completely replace components and ensure that everything is still working.

Hope that helps.


问:
How to teach basic principles to programmers
In order to get experience as a team lead, I was recently given the task of supervising a programmer.

What I found out is that he is having a problem in writing a simple if condition. He has issues with string. And he doesn't know how to pass a variable in the addClass function of jQuery with an if condition.

And he doesn't know when to use a for loop. Or even what a for loop is used for.

How to make him understand these basic concepts quickly?

I told him to Google for how to use if condition for addClass variable. But he didn't find it, then I told him to do it quickly in the early morning, when discussing he was giving reasons that it is what that, then I told him I show you how to do that,
then he told me, you should have done it before.

What should I reply to him? He is telling me that you should tell me everything or Should I do it and show him every time? It may take lot of time, and every time I have to do a task. I want him to be independent.

答:
There are 2 problems that I see here. They are very separate, but both equally important.

As @Matthieu has suggested it appears that you have a bad employee, the type that are not only non-productive (zero impact), but are a negative impact on progress and the team (morale, fusion / gelling, friendliness). You need to understand why this employee was hired. If it is a HR error, or a competent liar during the interview, then you can most likely resolve it by recommending to your management (or their boss) the termination of this employee's employment as a programmer. Perhaps they are a competent IT system administrator and perplexed why they are being asked to do programming. -- I've had job interviews through recruitment agencies that were about as messed up (on purpose by the agency) in the past, so it may not be the employee's fault.

But there may be office politics, such as a relationship to senior staff / executives that you may need to know about before making noise. This you need to do quietly before saying anything to anyone other than your manager / supervisor. In that case you could need to develop a containment strategy which is primarily isolation (problem containment) and damage control.

Then, the second issue, if you end up keeping this employee then you need to give them their own environment where they can safely learn and progress, mistakes and all, in a healthy positive environment that can hopefully groom a potential programmer. This means they do need "real" projects eventually. An employee who clearly knows they are being isolated becomes even more disenfranchised and demotivated. You need to create a miniature "career development" strategy for this employee. What would it take to get them to become a useful employee in the future? Typically starting with education and/or training. Combined with developing a sense of basic skills in the work place (often called work ethic).

You don't mention age explicitly, but I'm going to assume that hopefully this employee is young as well as new, and thus most likely inexperienced, and can be encouraged to learn how to get along in the workplace. HR might be able to suggest "career development" training options that might be an opportunity for them to learn how they should act in the workplace. Larger employers may have some in-house options even. Human Resources can often help here.

I believe you are on the right track that something is amiss, and that you need to gather future information before taking action.

Another action I would also take, is sit down with the employee and ask them about themselves, so you know more about their background and experience. Family connections will tend to be mentioned if that is the basis of employment.

Best of luck.


答:
No.  I would be dead without the ability to look up from the API documentation.  The only time I don't have it is when I'm trying to debug something where I can't get access to the documentation.  Then I "reverse engineer" the api and cut-n-paste pieces as needed.

It's important to have a good idea of what the API is about and which part is best to use, but knowing the method names, variable names... not really necessary.

Title: Is it a really required skill to program without API documentation?

Body:
I barely passed my Java programming exam today. I had to answer some general questions about threading which I did well and to write a little threaded program which was worse. I had to connect my laptop to the projector screen and write the program right away. My first attempt was to use anonymous classes but I forgot the exact syntax. Maybe because of some excitement or maybe because last two weeks I was coding mostly in php. Then I asked is it allowed to use the API documentation. The answer was "NO". So I decided to go another way around and I implemented Runnable. The program was doing what was requested at the end. Of course the examiners noticed my first fail and that affected my score greatly. I was amazed that it was not allowed to use the API documentation.

So, my question is: Is it really important to be able to code flawlessly without API documentation? Should I develop this skill? Is it really important in the real world and in the work environment? While on programming courses I focused on learning patterns, developing skills to write good design applications, skills to use API and find the necessary information fast. I was not trying to learn how to program without API documentation. Is it must-have during job interviews (coding without API documentation)?


问:
Make a big deal out of == true?
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

答:
remind me of "boolean madness code", its like these

```<code>if(someBool == true)
   otherBool = false;
else
   otherBool = true
</code>```

Instead of:

```<code> otherBool = !someBool
</code>```

ContentLicense: CC BY-SA 2.5

Title: Make a big deal out of == true?

Body:
remind me of "boolean madness code", its like these

if(someBool == true)
   otherBool = false;
else
   otherBool = true

Instead of:

 otherBool = !someBool


答:
Is it a really required skill to program without API documentation?

I wouldn't say that it is required but it is

very desirable skill

imNSho.

I spent recent few months coding in close collaboration with the guy who knows API noticeably better than me. He is just so much more productive - simply because he can skip API docs checks that distract me.

Here, I am talking about fluency. About being not just capable of something but fluent.

Do you know what it is to be fluent? It's when for someone looking at you it appears as if you code as you type...

...As if the right code simply flows from your fingers to the screen. As if you don't check the API docs, tutorials and manuals. Actually, you do check them all, but that's invisible because it's all in your head. You've got all the knowledge you need right there in your brain - charged, loaded and ready to use.

...That's fluent knowledge. It's when it takes you a minute to do what takes newbie an hour. It's worth the effort, really. It smells like victory.

If you master fluency in some API and if you properly memorize how does it feel like, this memory will further guide you through in how to become most productive working with any other API.


答:
In work I've never had a situation where I had no access to documentation. On the other hand, having the reading comprehension and general understanding to be able to interpret poorly-written documentation comes in useful all the time.

You should eventually get to know the patterns and structure of your APIs, but knowing exactly where everything is is not particularly useful.

At SFU Computing Science, closed-book exams constitute between 70% and 100% of our grades. The theory is that exams test your understanding of the course material and your adaptability. In reality, all it really tests is your nerves, your sleep quality/duration, your wit, and your rote memorization techniques -- none of which is necessary either academically or for a typical job in the software industry.


答:
To all but your last question:
Encyclopaedic knowledge of any API documentation is not important. You will obviously program faster if you know every detail of every method of every class, but that's not a reasonable expectation.

To your last question:
You may be expected to know the specifics of some classes without the API documentation. If you know before walking in to the interview that you will be tested, or if the job is very focused (i.e.: you will be doing threading all day), then you could reasonably expect to need to know the related classes in detail.

Addendum:
You should clarify well before any exam with your professor/instructor exactly what materials will be provided and what materials you may bring yourself. Assume that anything they have not explicitly agreed to is not allowed. I've had courses where I could only bring the basics for writing, where I could bring any books I wished, and where I could bring exactly one double-sided sheet with anything I wanted on it. Exams are usually structured around what materials are allowed.


问:
What is this development methodology called?
I recall a methodology that emphasized making functions short and numerous.  It said that if a section of code can be separated at all, it should be, even if the resultant functions are only used once.  Some argue that it's DRY taken too far, and that this kind of obsessive refactoring is counterproductive.

Does anyone know what it could be called?  I don't think it actually had refactoring in the name.

答:
Martin Fowler's Refactoring book identifies long methods as a code smell, with the Extract Method refactor being a solution.

I think it could also be considered a derivative of the Single Responsibility Principle. Applying it at the method level can make unit-testing much easier, since you don't have to worry about testing multiple results from a single tested method.

It could also be called Short Methods; the link has a good discussion of this methodology. The point is that we can only keep in our minds around 5-9 things at one time, so shorter methods allow us to abstract away some bit of logic whose implementation is unimportant at the point where it's used.


问:
Defining Rank names for employees
I want to create a list of ranks for the employees in my company. We are an open source integrator that works usually with existing solutions and also building custom solutions.

We don't want to name our employees as normal senior consultant, trainee and we would like give them ranks as forums do to the users.

Does anyone have any suggestion for this?

答:
Scalar is a entry level

Composite is regular developer

Function is senior

Macro or Template  is the architect

Title: Defining Rank names for employees


答:
API docs != language syntax.

I can understand when someone doesn't know the exact names of various Java classes and their methods. I don't know them and I code in Java every day. I'd be lost without either the docs or the almighty IDE auto-completion - especially when it comes to Java standard API which is well known for its verbosity in variable/class/method names.

However, as you said yourself, it isn't anything which is usually found in docs that you could't remember. It is the syntax for inner classes - this is a feature of language itself not something to be memorized from the docs.

As much as I think that students should (in many cases) be allowed to use the docs for standard APIs, I do think that anyone who wants to pass a programming exam should know the language syntax. And I don't mean some freaky edge cases that only language designers know about, just the standard ones - like the one in your example.


答:
Find a small program which has a Factory and rewrite the program so Guice can inject a provider you can use instead of the factory.

Note that the object in which the provider or instance is to be injected may not be created with a new but must be retrieved from Guice.  This may require you to rework the inner logic a bit.

Title: What would be the best way to spend a day learning Guice?

Body:
I have just joined a company where the major projects, including the one i have landed on, use Guice. I have never used Guice. I am familiar with dependency injection, in the shape of CDI (a bit) and the obscure but decent Nucleus (part of ATG).

We just completed a successful iteration, so tomorrow (friday the 13th!) is a day that developers have to spend on things they think are valuable.  I have some meetings during the day, but i will have about four or five hours to do this. I have a machine to myself, with Eclipse installed and configured to my liking.

I would like to spend my day learning about Guice.

How should i spend my time?

(I'm not entirely sure this is an appropriate question for Programmers, but there's only one way to find out)


答:
First, I agree with @Matthieu in that he shouldn't be on your team in the first place. He's not a productive member of the team, and from your account, doesn't seem to have much interest in becoming one. He doesn't seem to have any interest in doing his job and expects you to do it for him.

Also, my direct response to him saying "you should have done it before," would be along the lines of "no, it's your responsibility. I gave you that task, it's your job to complete it to the best of your ability."

That said, if you're stuck teaching him (or you find yourself in a learning environment), here are some things I did as a tutor to help people learn about the basics of programming.

Never just give them the answer. Giving them the answer, even with explaining it to them afterward does nothing to help them learn it. Remember the saying "I hear and I forget, I see and I remember, I do and I understand." Instead, show them how to come to the answer the first time, them help them figure it out for themselves. Not only do you keep them from just taking your answer blindly, you show them how to find their own answers ("give a man a fish...").

Relate the concepts to real actions. Doing this makes loops and conditionals stupidly easy. Walk them through something as if they, themselves were doing it, and what actions they would take under those circumstances. FizzBuzz is a good example - you're doing a repetitive behavior (counting), and checking each item for a given conditional (multiple of 3 and/or 5).

Let them fail, then show them what they did wrong. Some people learn best when they've screwed something up, as long as they know why they screwed up. Let them try to solve the problem, then walk through it with them and show them how it can be fixed/improved.


答:
Sounds like an extreme version of Modularization

this kind of obsessive refactoring is counterproductive.

That's called "Modularize, not atomize" ;-)

Title: What is this development methodology called?

Body:
I recall a methodology that emphasized making functions short and numerous.  It said that if a section of code can be separated at all, it should be, even if the resultant functions are only used once.  Some argue that it's DRY taken too far, and that this kind of obsessive refactoring is counterproductive.

Does anyone know what it could be called?  I don't think it actually had refactoring in the name.


答:
Give him simple tasks and the tools to do what he needs to do and let him sink or swim....

If this guy is not putting in the work to at least learn then what good is he to you? It's OK to not know everything but if he expects you to walk him through everything it's just not going to work.

I think what makes us programmers is our constant desire to learn and get better. If this guy cannot or refuses to work with you then all he will do is slow you and your team down.

What this guy needs is a reality check and you my friend should give it to him asap.


答:
There was a guy once who had a little bug in his code, so he took it to StackOverflow and asked for help. StackOverflow: Java (generating numbers with no repeats ). I looked at his code and I pointed out to him that his HashSet was perpetually being filled with values but it was never cleared. So, he asked me: "how do you clear it?" I have to admit that I am not particularly proud of the answer I gave.

You absolutely need to know the basic stuff that you use every day. You need to know them all, and you need to know them well. But only the basic stuff.

For everything else, the  important thing is to know that there is something out there that does what you want. Precisely which class you need to use, precisely which method you need to call, and precisely what parameters you need to pass to it, is something that you do not need to keep precious neurons of your brain occupied with. That's what documentation is for, and that's why IDEs with autocomplete were invented. And if push comes to shove, there is always StackOverflow and the greater interwebz out there.

Asking programmers to know by heart APIs is akin to asking lawyers to know by heart the legal code and all precedents. It is pointless. An exercise in futility.


问:
Is it bad practice to create new objects without storing them?
I've seen objects created in Java code without storing a reference to the object.  For example, in an eclipse plugin I've seen a SWT Shell created like so:

```<code>new Shell();
</code>```

This new Shell object is not stored in a variable, but will remain referenced until the window is disposed which [I believe?] happens by default when the window is closed.

Is it bad practice to create objects like this without storing a reference to them? Or was the library poorly designed? What if I don't have need of a reference, but only want the "side effects" of the object? Should I store a reference anyways?

UPDATE:

Admitedly, my above example is poor.  While I have seen UI elements created like this, creating a SWT Shell like this would probably be pointless because you need to call the open method on the Shell instance.  There are better examples provided by aix such as the following from the Java concurrency tutorial:

```<code>(new HelloThread()).start();
</code>```

This practice is seen in many contexts, so the questions remains. Is it good practice?

答:
There's an element of personal preference to this, but I think that not storing the reference is not necessarily a bad practice.

Consider the following hypothetical example:

```<code>new SingleFileProcessor().process(file);
</code>```

If a new processor object needs to be created for every file, and is not needed after the process() call, there's no point in storing a reference to it.

Here is another example, taken from the Java concurrency tutorial:

```<code>(new HelloThread()).start();
</code>```

I've seen lots of other examples when the reference is not stored, and that read perfectly fine to my eye, such as:

```<code>String str = new StringBuilder().append(x).append(y).append(z).toString();
</code>```

(The StringBuilder object is not kept.)

There are similar patterns involving common.lang's HashCodeBuilder et al.

Body:
There's an element of personal preference to this, but I think that not storing the reference is not necessarily a bad practice.

Consider the following hypothetical example:

new SingleFileProcessor().process(file);

If a new processor object needs to be created for every file, and is not needed after the process() call, there's no point in storing a reference to it.

Here is another example, taken from the Java concurrency tutorial:

(new HelloThread()).start();

I've seen lots of other examples when the reference is not stored, and that read perfectly fine to my eye, such as:

String str = new StringBuilder().append(x).append(y).append(z).toString();

(The StringBuilder object is not kept.)

There are similar patterns involving common.lang's HashCodeBuilder et al.

OwnerDisplayName: aix


答:
This could be bad if you're using SWT, because there you have to clean up after yourself (calling the dispose() method).
But for other classes (non SWT) it's ok.

Here's an article about Managing Operating System Resources

Title: Is it bad practice to create new objects without storing them?

Body:
I've seen objects created in Java code without storing a reference to the object.  For example, in an eclipse plugin I've seen a SWT Shell created like so:

```<code>new Shell();
</code>```

This new Shell object is not stored in a variable, but will remain referenced until the window is disposed which [I believe?] happens by default when the window is closed.

Is it bad practice to create objects like this without storing a reference to them? Or was the library poorly designed? What if I don't have need of a reference, but only want the "side effects" of the object? Should I store a reference anyways?

UPDATE:

Admitedly, my above example is poor.  While I have seen UI elements created like this, creating a SWT Shell like this would probably be pointless because you need to call the open method on the Shell instance.  There are better examples provided by aix such as the following from the Java concurrency tutorial:

```<code>(new HelloThread()).start();
</code>```

This practice is seen in many contexts, so the questions remains. Is it good practice?

OwnerDisplayName: Alexandra N


答:
In general, it's good practice to release references as quickly as they can reasonably be released. I see no difference between:

```<code>HelloThread thread = new HelloThread();
thread.start();
// where thread is never used for the rest of the method
</code>```

and

```<code>(new HelloThread()).start();
</code>```

As far as the code is concerned, you're just avoiding the use of a variable name, which could be a positive thing. The JIT compiler is generally smart enough to recognize it can garbage collect the thread after its last use, so there's probably no difference from a performance standpoint.

The only real issue to avoid is the Code in the Constructor Anti-Pattern, but it doesn't sound like that's what you're asking about.

Body:
In general, it's good practice to release references as quickly as they can reasonably be released. I see no difference between:

HelloThread thread = new HelloThread();
thread.start();
// where thread is never used for the rest of the method

and

(new HelloThread()).start();

As far as the code is concerned, you're just avoiding the use of a variable name, which could be a positive thing. The JIT compiler is generally smart enough to recognize it can garbage collect the thread after its last use, so there's probably no difference from a performance standpoint.

The only real issue to avoid is the Code in the Constructor Anti-Pattern, but it doesn't sound like that's what you're asking about.

OwnerDisplayName: StriplingWarrior


答:
what should I reply to him?

"Look, this is very basic stuff. It's not my job to teach you the basics - it's my job to assign you work and check that it's being done right. If you don't know this sort of stuff, and can't figure it out, then you're not a programmer. I'll ask about getting you sent on a training course, but if you can't do this stuff then you can't do the job."


问:
How to keep a big and complex software product maintainable over the years?
I have been working as a software developer for many years now. It has been my experience that projects get more complex and unmaintainable as more developers get involved in the development of the product.

It seems that software at a certain stage of development has the tendency to get "hackier" and "hackier" especially when none of the team members that defined the architecture work at the company any more.

I find it frustrating that a developer who has to change something has a hard time getting the big picture of the architecture. Therefore, there is a tendency to fix problems or make changes in a way that works against the original architecture. The result is code that gets more and more complex and even harder to understand.

Is there any helpful advice on how to keep source code really maintainable over the years?

答: Read and then re-read Code Complete by Steve McConnell. It's like a bible of good software writing, from initial project design down to a single line of code and everything in between. What I like most about it is that it is backed up by decades of solid data; it's not just the next best coding style.


问:
Is the GoF book still the one to read?

Possible Duplicate:

  Is there a canonical book on design patterns?

I'd like to read a design patterns book. GoF for sure is the one to read. But after 15 years is it still valid, I mean isn't there an updated one?

Something like "Charles Darwin On the origin of species" is a very important book, and some main concepts are still valid, anyway today (2010) one would read another book to study the subject.

In this question the main suggestions are the Head First and GoF books. But Head first is not a replacement for GoF.

So any suggestion or should I stick with GoF?

答: I recommend reading the Head First book first, as it does a better job of explaining why design patterns are needed. After that, you can use the GoF book for examples and as a reference.</p>

Title: Is the GoF book still the one to read?


问:
How can I gauge a candidate's ability to learn in an interview?
We are hiring for a small development department within a medium sized company for which software is not the main line of business.  As such, we are attempting to recruit what we have labeled a Senior Programmer.  The goal is to find someone that can design, implement and maintain entire new and existing systems from the database through to the front-end.

Regardless of a candidates claim to experience (read: massively spun CVs), or the results of the technical test, what I really care about is their ability to learn and the speed at which they will pick up technologies or concepts they are not familiar with to fill any gaps they might have in their knowledge.

How can I go about getting an idea as to a candidates ability to (or speed of) learning?

答:
Explain to them a semi-complex business concept and then ask them to model it. This will give you information both about their problem-solving skills and their ability to learn.

Also, ask them about recent technologies they've learned, how they've gone about learning them, how they've made sure that what they're learning is best practice (for want of a better phrase), and how they've applied what they've learned.

Those kind of open-ended questions should be followed by discussions, they don't have right and wrong answers, but they should give you a lot of information by the time the conversation is over.


答:
A detailed conversation would be the best approach. I'd recommend telling them something about the work you want them to do, like a new app, and have them describe how they would implement it. You could also give an overview of a current app you have and ask them how they might have gone about implementing it.

Another way is to ask them about particular projects they've worked on previously and how they did them. Look for ways that app might relate to the work you want them to do. For example, if you want them to implement a web service, ask them about how they implemented that web service mentioned on their resume. Ask why they picked pattern A over pattern B. Get them talking. They should love to tell you about their projects and be able to explain them in depth.

Unless they're particularly skillful liars, you should find out where they're at.

Title: How can I gauge a candidate's ability to learn in an interview?

Body:
We are hiring for a small development department within a medium sized company for which software is not the main line of business.  As such, we are attempting to recruit what we have labeled a Senior Programmer.  The goal is to find someone that can design, implement and maintain entire new and existing systems from the database through to the front-end.

Regardless of a candidates claim to experience (read: massively spun CVs), or the results of the technical test, what I really care about is their ability to learn and the speed at which they will pick up technologies or concepts they are not familiar with to fill any gaps they might have in their knowledge.

How can I go about getting an idea as to a candidates ability to (or speed of) learning?


问:
Change Management Standard
Is there any Change Management Standard which is widely accepted in software and other industries? I worked at several companies with absolutely different target domains (investment banking and telecommunications). Companies had very similar Global Change Management (GCM) organization and processes. More specifically:

There was GCM department responsible for all IT-related changes, such as company wide firewall changes, databases allocation/support, version control system support, etc.

There was such notion as change freezes. It was not possible to get my changes implemented if change implementation date was the same as change freeze date.

There was GCM meeting (conference call) when everybody discussed necessity and importance of their changes. It was hosted by GCM department representative every week at the same time (Tuesday, 17:00 GMT, for example).

Changes should have been approved by Change approvers. There were different kind of request which have their own list of mandatory approver groups. Groups had several members working at different time zones. At least one such member must have approved the GCM in order to have whole group approved the change. It was required that approves for all mandatory approver groups had been collected before scheduled implementation time came. Otherwise there was 100% guarantee that it will not be implemented.

Bureaucracy of GCM processes was remarkable. It was pure bureaucratic hell. Tools were awful, people slow and stubborn. It was nearly impossible to implement even minor changes. Sometimes I failed to get one last approve before implementation time or suddenly it turned out that implementation time is scheduled on the time of change freeze.

I would like to have a look at it, so that I would have general understanding of GCM processes and how they work at different companies. I would like to know whether it is so damn awful everywhere, or it was just poor GCM processes implementation at one specific company.

答:
Check out ITIL. It is a collection of practices and guidelines for managing an IT infrastructure. You can set up processes to manage facilities, power, equipment, operating system software, frameworks, databases, and applications.

Ideally, the "barriers" to change are meant to protect existing assets, and should be strong enough so that changes that will add little value at great risk are blocked, while changes that add value with little risk can pass can overcome them.

Title: Change Management Standard


答: If you don't need a reference to the created object, then don't hold onto the reference. It's as simple as that.


问:
DRY way to write Javadoc on overload methods
I want to write Javadoc in DRY way. But the oracle document about Javadoc says write same thing again in overload method comment. Can't I avoid repetition?</p>

答:
The point of documentation is to illuminate future users of an item.  This is partly for the convenience of the author, so that he or she does not have to be contacted whenever someone cannot figure out how the thing works. Mostly, however, it is for the benefit of the people who need to use or support the thing.

As such, the point should be clarity, as opposed to convenience for the author.  You cannot expect folks to hunt up and down through your API documentation because you were essentially too lazy to repeat yourself.  Suck it up--Javadoc will be repetitive.

That said, there's no reason, if you're clever, you can't write a program that would stick comments into your code based on markers or some other criteria.  It may be more trouble than it's worth. Or not.


问:
Managers X Motivation
As a programmer what do you think that is the thing that your manager does that mostly decreases your motivation?

My manager insists in blocking web content (this week was msdn content and Microsoft domain sites) This is so stupid, make me think I am not a reliable professional or that I am stealing his internet. And not, it is not a small business. It is a huge enterprise where such dinossaurs should not exist anymore.

答:
It would be understandable to block pr0n or time-sapping sites (Facebook, MySpace, etc), but not professional resources such as these.

I strongly recommend that you book a 1-to-1 meeting with your manager and explain your case for requiring access to MSDN, Microsoft, *.se.com, etc and see what their response is. If, in a 1-to-1 meeting (i.e. private meeting room), they come out with 'I banned them to increase your productivity', you can:

Ask how they are measuring productivity - by bug count, LOC written, or the number of times they spot MSDN open on your monitor?

Point out that blocking these resources reduces productivity because you don't have reference materials, etc.

Also point out that a move such as this has damaged yours/teams morale considerably and that the decision should be reversed.

Whatever you do, don't quit or go job-hunting without trying to work things out first. Describing your company/manager as a 'dinosaur' tells us that you may have some prejudices to address first and/or some gentle education of your management of modern software development techniques.

Title: Managers X Motivation


问:
How is Python used in the real world?
I'm looking to get a job as a Python programmer. I know the basics of the language and have created a few games with it using pygame. I've also started to experiment with Django.

However, looking at the job market, it doesn't seem very many Python jobs are web-related. On the desktop side of things, it doesn't seem like very many companies use the popular GUI libraries like pyQt or wxPython.

How are companies actually using Python? What areas should one focus on to land a job as a Python programmer?

答:
The thing about interpreted languages is companies that don't want to give their source code away don't use it in delivered software, so almost all the jobs you will see are web related.  You might have better luck searching for specific frameworks like Django.  If there's an open source project written in python you like, you might apply to a company that sponsors it.

It usually won't make it into the job description, but it's almost an underground among programmers who use languages like C++ to use python when they have a choice, for one-off utilities, in-house applications, or things like automated test scripts that aren't shipped with their official product.

Some high-end software like Maya uses python for scripting, so that might be another route to pursue.

Title: How is Python used in the real world?


答:
Tecplot, a popular visualization package uses python for internal scripting. Rhinoceros3d, a NURBS modelling solution uses it also.

Don't know how many other applications there are, or whether this answers your question at all ... but I've gotten the feeling that python is finding its niche as a embedeed scripting language.

Title: How is Python used in the real world?

Body:
I'm looking to get a job as a Python programmer. I know the basics of the language and have created a few games with it using pygame. I've also started to experiment with Django.

However, looking at the job market, it doesn't seem very many Python jobs are web-related. On the desktop side of things, it doesn't seem like very many companies use the popular GUI libraries like pyQt or wxPython.

How are companies actually using Python? What areas should one focus on to land a job as a Python programmer?


答:
I can only tell you what was done to me once:

I was given a project in a language with libraries I have not done before and I had to complete it within a week.  This will tell you exactly how quickly and how well the person can learn.


问:
What can we learn from inactive assembly languages?
There are still groups of programmers who support old microprocessors, e.g., Z80, 6510, 68000, etc. What can we learn from old assembly languages at a time when functional programming is becoming fashionable?

EDIT

I imagine that there would be more to learn for embedded systems. However, assembler styles apply to a more limited extent for web programming where caching is used and the size of routines does not really matter. The guideline for best practice for embedded and web styles differs massively (server and client styles being different). For example, the optimising a sprite multiplexer to run in say, under 30 bytes, is different to types of optimising we would make for code we intend to run on a web server. The types of optimisation are very different. The sprite multiplexer is written with memory usage as the main priority but regarding our web server routine, we want maximum performance which has little to do with efficient use of memory unless we are talking about shared resources.

答:
If you have an interest in computer history, how did we get to where we are now.  if you examine a lot of assembly today, much of the time most people are looking at compiler generated code, not hand written assembly.  The 6502 is a prime example if a processor to learn.  For one thing there are many roms from the classic standup arcade games like Asteroids.  You can learn the instruction set by writing a disassembler.  Writing a disassembler for a variable length instruction set is a educational programming challenge in and of itself, well worth the effort, or at least like a maze solving program, worth at least getting to the point where you figure out what you have to do to solve it.  Because these were hand coded assembler, they didnt have to, and didnt follow programming conventions like a compiler would.  Some of these roms either intentionally or on purpose have some traps in them that trip up a disassembler.  Back to the disassembler learning experience.  Then you can examine the programming style, how it might be similar to general programming in any language and the kinds of tricks and habits used by the programmer for that instruction set.  The 6502 holds an important position in computing history, despite the sales pitch leading many to think that Apple had anything to do with anything (they were an also ran behind commodore and tandy/radio shack in the personal computer movement) the 6502 was the common factor in the move from time share computers to ones you could afford to own.  As well as the video game world both atari vcs (a.k.a atari 2600) and stand up arcades.  Later the z80, and a number of others took over and carried us to where we are now.  the 6502 in particular has an addressing mode, which the msp430 can also take advantage of in its own way.  YOu may think of the 6502 being starved for registers, but consider the actual registers just temporary registers and the page zero memory being 256 registers.

I also highly recommend going backwards to the 8088/86 to get the history of where the current x86 family was born, compare it to the z80, 8080, and others that sprang from a common source/concept and evolved on their own. x86, even the modern one can be considered a dead instruction set it is so painful and archaic, it just wont die.  Why bother translating to some other instruction set inside, why not do what DEC did with the Alpha running windows and dynamically recompile converting the program to another instruction set, allowing legacy programs to run, the reason why microsoft and intel are still in business, but moving away from a poor intermediate interface between the source code and the execution unit(s).

Perhaps the most important lesson is that processors are as similar as they are different, load, store, the basic set of alu operations, xor, add, etc.  At the same time even with C, the programming languages never really clinched the features of the hardware, you still have to dive down into assembly to hand tune for performance.  core language libraries like memcpy for C are hand tuned asm per platform because the language just doesnt cut it.

You will also find out that many of the processors you claim to be obsolete are still available for sale, sure a small vendor or two with a small market share, but some markets or companies rely on the 8051 for example (have you used a network card lately, sent any TCP/IP packets to anyone?  how did you get this web page, there were a number of 8051 driven macs and phys that your packet flowed through, even reading the datasheets and programming those parts you dont realize they are 8051 based unless you have had the history or asked the right question to the vendor when programming those parts).  zilog still lives (z80) (and rabbit semiconductor is a modified z80), forms of the the 6502 are still for sale, the hc11, etc, etc.


问:
How do you name your private variables in C#?
What is the best practice, most commonly accepted naming conventions for private variables in C#?

private int myInteger;

private int MyInteger;

private int mMyInteger;

private int _myInteger;

private int _MyInteger;

Mysterious other option

Which do you use and why?  (My company is fairly new to C# and I would like to pick the most "industry accepted" method to try and get into our coding standard.)

答:
Juval Lowy's IDesign C# Coding Standard is quite popular.  This standard recommends prefixing private member variables with "m_" (Option 6).  That's what we do in our team.

```<code>private int m_myInteger;
</code>```

Option 4 (_myInteger) is an acceptable variation of this standard.

I didn't like the MSDN recommendation (myInteger), because it makes it difficult to tell a private member from a local variable.  Their recommendation, of course, solves this problem by qualifying private members with this, which seems redundant to me.

Body:
Juval Lowy's IDesign C# Coding Standard is quite popular.  This standard recommends prefixing private member variables with "m_" (Option 6).  That's what we do in our team.

private int m_myInteger;

Option 4 (_myInteger) is an acceptable variation of this standard.

I didn't like the MSDN recommendation (myInteger), because it makes it difficult to tell a private member from a local variable.  Their recommendation, of course, solves this problem by qualifying private members with this, which seems redundant to me.


答:
First of all, you're going to annoy people who learned C or C++ before Java.  I'll leave that as an exercise for the reader to decide if that's a pro or a con.

While there are certainly situations in which objects are designed to be very short-lived, most of the time if something is complex enough to create an object for, it's complex enough to have good reasons to keep a reference, so not keeping it should at the very least be a warning to double check if you have missed something.

For example, in a tutorial no one cares about keeping a thread reference, but in real life, if something takes long enough that you want to spawn a thread, it usually takes long enough that you want to be able to cancel the thread.  Or if shorter-lived, you usually are spawning a bunch of threads you will want to join before continuing.  Or you want to make sure your thread creation actually succeeded.  Or you want to make sure the thread finishes cleanly before exiting.  You get the picture.


答:
I've used python at my current and my previous job for creating automated testing frameworks, for writing automated tests, and for writing desktop applications used by our testers. In my previous job they also used python for a lot of other internal tools, build scripts, system monitoring and logging tools and so on.

Python and other dynamic languages may not always be used to create the product, but they often power the tools that build the product. Don't just look for companies that sell products based on python, look for companies that have smart internal systems groups that aren't required to use compiled languages. I've built a very long career almost entirely with dynamic languages like python, perl, ruby and Tcl and have loved every minute of it.

Title: How is Python used in the real world?


问:
Learning to Program in Assembly - Useful Resources
Following on from a previous thread, it has got me interested in learning a little about Assembly programming.  Not so much for wanting to program useful apps in, just to get a feel for low level programming to better understand what is happening.

Can anybody recommend any books or online resources for beginners?

Thanks.

答: I have an instruction set, assembler, and simulator, with some lessons that were created just for this purpose.  I dont yet have feedback on how good or bad I did but its out there, give it 15 minutes or a half an hour see if it teaches you anything.  http://github.com/dwelch67/lsasim  After that I have some mainstream instruction set simulators you can try as well, simple, no frills, should run anywhere you have a C compiler, etc.</p>


问:
Should I include `assembly` as programming language in the CV?
In the answer for one question someone wrote that assembly is not a language, it's a process. I tend to agree, since the assembly "language" is dependent on the architecture it will run on, which may differ quite a bit from one CPU to another.

So if you've written assembly for one architecture, does that mean you can include it in the CV under merely assembly along with the other programming languages? Or do you explicitly say that you've written assembly for that particular architecture?

EDIT: Changed 'dabbled' to 'written'. English isn't my native language and I misunderstood the term, thinking it meant that you've used it a lot instead of just a bit.

答:
Assembly is a language, there is at least one for every instruction set.

Yes, absolutely put it on there even if you write web applications in a high level scripty language.

Maybe where I work is the exception not the rule (the networking business, and chip/processor business) but  a fair amount of our programmers know and write assembly, and even if you were looking for a linux porting or device driver job we would see the assembly experience, ask you questions about it and make decisions based on your answers.

Like anything else on your CV that doesnt relate to the job you are applying for they will just skip over it.  this is not a "less is more" kind of thing.  If you really know something put it down, languages, processors, protocols, apis, etc.  If you leave things out and expect the interviewer to read your mind or be forced to guess at what questions to ask to try to draw this stuff out, it is to your disadvantage.  I would rather have a multi page CV/resume to look at when interviewing a candidate than someone who tried to cram what they could on one page and left out the "meat".  Often a resume like that doesnt make it through the pre-screening process.  HR often scans the resumes for key words, enough key words and you rise to the top of the pile, not enough or none and you get discarded without even a phone interview.  Instead of less is more, more is more.  At the same time if you dont really know the language, or took a class in it in college and it was so long ago you really dont remember any details, leave it off, getting to the interview with answers like that encourages your resume/CV to make its way quickly to the shredder.

Yes list it as a programming language, that is what it is and specify the processor (family).

C, C++, Java, assembly language (x86, ARM, MIPS), Python, Perl...

Some folks will list the assembler not the language  TASM, NASM, MASM.


问:
Were the first assemblers written in machine code?
I am reading the book The Elements of Computing Systems: Building a Modern Computer from First Principles, which contains projects encompassing the build of a computer from boolean gates all the way to high level applications (in that order).  The current project I'm working on is writing an assembler using a high level language of my choice, to translate from Hack assembly code to Hack machine code (Hack is the name of the hardware platform built in the previous chapters).  Although the hardware has all been built in a simulator, I have tried to pretend that I am really constructing each level using only the tools available to me at that point in the real process.

That said, it got me thinking.  Using a high level language to write my assembler is certainly convenient, but for the very first assembler ever written (i.e. in history), wouldn't it need to be written in machine code, since that's all that existed at the time?

And a correlated question... how about today?  If a brand new CPU architecture comes out, with a brand new instruction set, and a brand new assembly syntax, how would the assembler be constructed?  I'm assuming you could still use an existing high level language to generate binaries for the assembler program, since if you know the syntax of both the assembly and machine languages for your new platform, then the task of writing the assembler is really just a text analysis task and is not inherently related to that platform (i.e. needing to be written in that platform's machine language)... which is the very reason I am able to "cheat" while writing my Hack assembler in 2012, and use some preexisting high level language to help me out.

答:
There is no difference then or now.  You want to invent a new programming language, you choose one of the languages available to you today to make the first compiler.  over some period of time, if it is a goal of the project, you create a compiler in that language and it can then self-host.

If all you had was pencil and paper and some switches or punch cards as your user interface to the first or next new instruction set, you used one or all of the items available to you.  You could very well have written an assembly language, on paper, and then used an assembler, you, to convert it into machine code, maybe in octal, then at some point that went into the interface to the machine.

When a brand new instruction set is invented today, no different, depending on the company/individuals, practices, etc.  it is quite likely that the hardware engineer probably programming in verilog or vhdl, writes the first few test programs by hand in machine code (probably in hex or binary).  depending on the software teams progress they may very quickly or not for a very long time coming switch to assembly language and then a compiler.

The first computing machines were not general purpose machines that you could use to create assemblers and compilers from.  You programmed them by moving some wires between the output of the prior alu to the input of the next.  Eventually you had a general purpose processor such that you could write an assembler in assembly, hand assemble it, feed it in as machine code, then use that to parse ebcdic, ascii, etc. and then self-host. store the binary to some media that you could later read/load not having to keep flipping switches to hand feed machine code.

Think of punch cards and paper tape.  Instead of flipping switches you could most definitely make a completely mechanical machine, a labor saving device, that created the media the computer would read.  Instead of having to enter the machine code bits with switches like an altair you could instead feed paper tape or punch cards (using something mechanical, not processor driven, that fed the memory or processor, OR using a small machine code written boot loader).  This was not a bad idea because you could make something, driven by the computer that could also mechanically produce the paper tapes or punch cards, and then feed those back in.  Two sources of punch cards, the non-computer based mechanical labor saving device, and the computer driven machine.  both produce the "binaries" for the computer.


答: Python is used in GIS programming. It is used as a scripting language for ArcGIS, and for Quantum GIS. </p>

Title: How is Python used in the real world?


问:
Choosing a functional programming language
I have read a lot of threads about functional programming languages lately (almost in the past year, in fact). I would really like to pick one and learn it thoroughly.

Last [course] semester, I have been introduced to Scheme. I loved it. Loved the extreme simplicity of syntax, the homoiconicity principle, the macros (hygienic and non-hygienic), the n-arity of procedures, etc.

The problem with Scheme is it's an academic language. I don't think it is really used in production environments. I don't believe either that it is particularly good to have on our resume. So, I have been looking around for alternatives. There are many of them and they somehow all seem to have a similar level of popularity.

Some thoughts about some other functional languages I have considered yet:

Clojure: It sounds great because it can access the Java world, it is oriented towards scalability and concurrency, but isn't the Java world on an edge right now? I already know Java pretty well, but would it be wise to add even more energy on depending on the JVM?

Haskell: Looks like a very appreciated language, but from what I have read, it's also more of an academic language.

Lisp: It's been around since forever. It seems to have most of what I like from Scheme. It has a big community. For what I [think I] know, it is probably the most widely used functional programming language in industry(?).

F#: Didn't really consider it. I'm not a big fan of MS stuff. I don't have the money to pay for their softwares (I could have them free from university alliances, but I'm more inclined to go with community-driven solutions). Though... I guess it would be the best career-oriented choice.

Tonight, I'm leaning towards Lisp. One week ago, it was Haskell. Before that it was Clojure. In the past year, I was doing some Scheme for fun, not pushing it for the reason you know. Now I would like to get serious (about learning one, about doing real projects with it, about maybe eventually professionally working with it). My problem is I would need to learn them all in depth before being able to choose one.

答:
I evaluated all the major functional languages a year or two back, from the perspective of wanting a practical, general purpose functional programming language.

I ended up picking Clojure, which has subsequently proved to be an excellent choice.

Broadly speaking the key reasons were:

Library ecosystem - for a language to be useful, you need access to good libraries. Being on the JVM means that you have easy access to the largest open source library and tool ecosystem, so going for a JVM language was a no-brainer from a pragmatic perspective. Scala also scored highly here.

Macro-metaprogramming - This aspect of Lisp always appealed to me, especially since I anticipated doing quite a bit of code generation. I've very much appreciated the arguments made in Paul Graham's short essay "Beating The Averages". The various Lisps all scored strongly here.

Performance was "good enough" - Clojure is always compiled and gets the benefits of the JVM JIT optimiser and excellent GC. As always, there is some overhead in using a functional language but with Clojure it was clear that you can each close to Java speed with a bit of effort (Clojure supports Java primitives and optional static typing for those situations where you need it). My estimate is that Clojure is ballpark 2-5x slower than what you could achieve with optimised Java or C++ code, which is consistent with what you see in the flawed benchmarks, and over time I expect that gap to narrow further. Also, it's easy enough to just write particularly performance-sensitive code in pure Java and call it from Clojure.

Concurrency - Clojure has a fairly unique and powerful approach to concurrency, particularly for highly multi-core concurrency. It's a bit hard to explain, but this video is excellent to give a taste of the principles. I think Clojure currently has the best answer to the tricky question "how should you manage shared, concurrent and mutable state in a functional programming language?".

Language design - Clojure is IMO a very well thought-out language design. Examples are having vector [] and map {} literals in addition to the regular Lisp parentheses, use of immutable persistent data structures, supporting laziness throughout the language via the sequence abstraction, and providing the programmer with a variety of orthogonal features to solve different problems. See the art of abstraction and simple made easy.

Community - always subjective, but I liked what I saw in the Clojure community. The attitude was very helpful, constructive and pragmatic. There is a strong "get things done" emphasis, possibly reflecting the fact that a lot of Clojure people (including Rich Hickey himself) come from a background of building complex enterprise systems. The fact that the Clojure community has strong links into the Java community as well was important in convincing me that Clojure wouldn't run the risk of getting stuck in a "niche".

If I had to name a couple of minor downsides of Clojure, these would be:

Dynamic typing - often this is an advantage in terms of productivity, but on average I think I'd trade this for stronger type checking and inference. Mostly this gets mitigated by having a good automated test suite, but if you like your types statically validated by the compiler then Haskell or Scala may be more your cup of tea.

Cutting edge - Clojure is developing very fast and there's a lot of innovation going on - the downside of this is that there is a lot of experimentation, some libraries and tools are still immature, and there are occasional breaking changes between Clojure major versions that you need to keep an eye on.

Overall though, I don't think you can go wrong with Clojure if you want an excellent and pragmatic modern functional language!


问:
Find all points within a certain distance of each other?
Let's say, we have... 50k points randomly allocated in 3D space, according to some volumetric function, so that in some parts of the space, points are closer together, but in other parts, they are further away. Every point has a random color (represented by an integer, for example)

I would like to find all points that:

Are within a certain (general) distance of each other, and

are of different color.

What is the fastest way to compute this?

Further, non-mandatory details:

My end goal, is to remove all points with the same color, until there are no more collisions. I would like to remove as few colors as possible, however, this is not mandatory I could simply remove all colors that are involved in any collisions AT ALL, though, it could result in a lower quality result.

The distance does not need to be exact. For instance, if an exact "collision radius" represents a perfect sphere, then I would be fine with the collision radius being the shape of, say, a cube. I am also fine with a trigger-happy solution. That is, I am fine if points get "detected" even if they are not too close. I just don't want this to happen very often, and I cannot accept points that are to close not being detected.

Also, I'm sure there is a family of algorithms devoted to this, but I can't for the life of me come up with any names... Knowing the name of an algorithm of this type would be immensely helpful.

答:
I can think of one optimization straight off.

If you traverse the space, starting at the bottom left hand corner, left to right then bottom to top you need only examine those points to the right and above.

There is a possibility (whatever algorithm you use!) that you will get different results if you start from a different point.


答:
It appears that the family of algorithms you are looking for are those used for cluster analysis.

Most algorithms of this family are not exact ones, as cluster analysis is traditionally performed on huge datasets, for which getting exact results is infeasible.

The main problem you will get with a clustering approach though, is that these algorithms will usually not care about a small number of outliners.

For your problem, I think a solution could look something like this:

Cluster your point cloud to get clusters of points which are close together. Fine-tune this step to your specific requirements to get useful clusters.

Use a different algorithm to examine the points inside each cluster and filter them based on your requirements. This algorithm can be one that a) delivers exact results and b) is possibly not very efficient, as it has to deal with a much smaller number of points.

Title: Find all points within a certain distance of each other?

Body:
Let's say, we have... 50k points randomly allocated in 3D space, according to some volumetric function, so that in some parts of the space, points are closer together, but in other parts, they are further away. Every point has a random color (represented by an integer, for example)

I would like to find all points that:

Are within a certain (general) distance of each other, and

are of different color.

What is the fastest way to compute this?

Further, non-mandatory details:

My end goal, is to remove all points with the same color, until there are no more collisions. I would like to remove as few colors as possible, however, this is not mandatory I could simply remove all colors that are involved in any collisions AT ALL, though, it could result in a lower quality result.

The distance does not need to be exact. For instance, if an exact "collision radius" represents a perfect sphere, then I would be fine with the collision radius being the shape of, say, a cube. I am also fine with a trigger-happy solution. That is, I am fine if points get "detected" even if they are not too close. I just don't want this to happen very often, and I cannot accept points that are to close not being detected.

Also, I'm sure there is a family of algorithms devoted to this, but I can't for the life of me come up with any names... Knowing the name of an algorithm of this type would be immensely helpful.


答:
The easiest approach would be a nested loop, checking the distance for each point-pair. This is off course the least efficient method, which you are not looking for probably.

A not uncommon approach in particle dynamics, is to divide your domain into boxes. You loop once over all particles to get some particle-id to box connectivity. Doing so, you can reduce the inner loop considerably, if you chose your box-size small.

I however wonder what you are trying to do here. Since you're first generating random points, and after this you delete them again, including some color, that is a bit weird. If you generate the points smarter, so with a different color by definition, and do some search during the point location generation. This will save you a lot of check afterwards.


答:
I don't know much about 3D algorithms but a little while ago I came across an Octree.  Based on some reading I did, it is widely used in 3D applications because it essentially gives you a way to binary sort all your data points (or surfaces) in 3 different dimensions.

If you know the center in 3D space and your 50k points are all sorted using this data structure, seems it should be very easy to find all containing cubes that have only the points which would be within some radius.


问:
LUA vs Shell scripting vs C for cgi-scripting on embedded devices
I am going to try CGI scripting for implementing a web based Graphical User Interface on an embedded device. What advantages does LUA scripting have over shell scripting or C for implementing dynamic HTML files? Which one do you think is easy-to-use from developer's perspective.

My GUI will comprise of some form based HTML pages. Some times, I would like a C program to run corresponding to an action performed on the GUI and then display result of the program to the user on GUI. Will shell scripting suffice in such a scenario or will I 'have to' use LUA? I have some experience with shell scripting actually.

答:
You can code CGI in any languages, and actually there are CGI applications coded in C or C++, in Lua, in Ocaml, in Perl or Ruby, even in Bash.

My feeling is that for an embedded system, C is the best choice (because the binary program would be small, and there is no need to add an interpreter).

But the language choice is up to you.

Of course, you should be aware of the limitations of CGI. the CGI program should run quickly, and you should make it store explicitly (in file or database) any persistent data to be shared from one HTTP request to the next.


问:
Should companies consider remote employees or stick to local employees?
Elite developers can be 10x more productive than an average developer.

Clearly it's easier to find an elite developer around the whole world than in a company's backyard.

If a company is not located in a programming hot spot, should they consider hiring people who work from home?

答:
Companies that don't know what they're doing should not have remote employees. The most incompetent manager will only feel like you are working hard if they can actually see you sitting at your computer doing a lot of typing. Also, sitting in useless meetings is one of the best indicators of strong communication and time managment.

When you have people who know what they are doing and are managed by those who know what they're doing, it really doesn't matter when, where, or how they work. They get what's needed done when it needs to be done.

I'm at a company that pays someone to do a direct deposit for payroll AND print out a faux paper check (actual pre-printed check paper), puts it in an envelope and sticks it in our mailboxes. I guess internal email is not secure enough and what would we do with all those checks?. I believe this edict came from the Department of Redundancy Department. If anyone were to work remotely, there would be the extra cost of postage which is a good reason not to let people work remotely - too expensive.


问:
One-use variables - has any language ever had them?
A principle that I follow is that, when an identifier is established, it should be a signal to the reader that the value referred to is indeed an abstraction which will be used more than once. That is, the identifier is defined or assigned once, and the value is read more than once.

However, a common idiom exists whereby, in order to increase readability, parts of a complex expression are factored out into variables. These variables will only be used once, violating the principle.

Thus, a special separate class of identifier should be used to indicate a one-use variable.

This principle applies to any identifier. So you might have one-use functions, one-use methods, one-use variables, etc.

Has there ever been a programming language which supported one-use variables?

答:
Haskell has a where construct that fits your description, as well as let…in.

The Lisp/Scheme family have let, letrec and let*.

ML also sports let…in.

OwnerDisplayName: dharmatech

OwnerDisplayName: Marcelo Cantos


答:
Technically any such factored out variable is going to be used twice: first to store the result of some sub-expression, and then as a reference to that result as part of the larger expression.

As you've experienced most languages also support one-use variables in the sense that it's perfectly possible to use that idiom.  Is there some specific different handling of them that you'd like?

SHould they be removed from the namespace after use?  Or do you just want a way to indicate "don't get attached to this variable"?  The former should, hopefully, be taken care by generally limited scopes: single-use anything should be restricted to well-contained areas that they won't cause any cluttering problems in.  The latter possibility should be handled by variable naming conventions or comments.

Is there something else that you'd like to have happen?

Title: One-use variables - has any language ever had them?

Body:
A principle that I follow is that, when an identifier is established, it should be a signal to the reader that the value referred to is indeed an abstraction which will be used more than once. That is, the identifier is defined or assigned once, and the value is read more than once.

However, a common idiom exists whereby, in order to increase readability, parts of a complex expression are factored out into variables. These variables will only be used once, violating the principle.

Thus, a special separate class of identifier should be used to indicate a one-use variable.

This principle applies to any identifier. So you might have one-use functions, one-use methods, one-use variables, etc.

Has there ever been a programming language which supported one-use variables?

OwnerDisplayName: blahdiblah


答:
In c/c++ it's one of the main uses for the trinery operator

const int color = in_the_matrix() ? red : blue;

Especially useful for things like threading/OMP where you need to show that a variable can't be modified by another thread.

OwnerDisplayName: Martin Beckett


答:
You can use auto storage class variables in C this way.  Just start a new block with {, declare and initialize some auto variables, do your calculation, then close the block with }, and all the auto variables in the block go away.  An example from some code of mine:

```<code>{
    int term = tar->array[i];
    int offset = isnegation(term) ? 41 : 0;
    int var = variable(term);
    int bx = ((var + offset) / bits_per_sigblock) % CLAUSE_SIGNATURE_SIZE;
    int shift = ((var + offset) % bits_per_sigblock) - 1;
    sp[bx] |= (signature_type)1 << shift;
}
</code>```

This could have been rolled into one line of code, but it would have been unreadable, even to me!

Body:
You can use auto storage class variables in C this way.  Just start a new block with {, declare and initialize some auto variables, do your calculation, then close the block with }, and all the auto variables in the block go away.  An example from some code of mine:

{
    int term = tar->array[i];
    int offset = isnegation(term) ? 41 : 0;
    int var = variable(term);
    int bx = ((var + offset) / bits_per_sigblock) % CLAUSE_SIGNATURE_SIZE;
    int shift = ((var + offset) % bits_per_sigblock) - 1;
    sp[bx] |= (signature_type)1 << shift;
}

This could have been rolled into one line of code, but it would have been unreadable, even to me!

OwnerDisplayName: Kyle Jones


答:
In type theory, single-use variables are modeled with (a derivative of) linear logic. In linear logic, a proposition can only be used once; linear logic is sometimes seen as a logic of resources. In linear logic, if you want to use A twice, you need to have A⊗A (both A and A) available; if you want to use A as many times as you like, you need to have !A (“of course A”).

Linear logic has not made it into many mainstream programming languages. It is the foundation of uniqueness typing in the clean programming language which is used to model side effects. In Clean, an expression of type Int denotes a pure computation that produces an integer value, i.e. a computation that can be made at any time, or multiple times, without changing the behavior of the program. An expression of type u:Int denotes a computation that produces an integer and that must be performed exactly once, for example because it performs a side effect.

OwnerDisplayName: Gilles


答:
My buddy Joe Groff sent an answer via email:

Those are called "uniqueness types". The Clean programming language is
a pure functional language that builds its side-effect management
system around them. IIRC Mercury and Oz also support uniqueness types,
and there's a GHC extension that allows uniqueness annotation in
Haskell. C++11 has them too in the form of rvalue references.


答:
You should probably take a look at ATS and Mercury. Both have support for linear types, although in different paradigms.

In particular I would to add, that ATS uses linear types for tracking resource usage, and this has both performance and correctness implications, e.g. allowing explicit memory reclamation and supporting efficient mutable arrays.

Also, terms of linear types are not necessarily "used once", but I will not go that far (PDF).

OwnerDisplayName: Artyom Shalkhakov


答:
Here is what I would do:

Divide the space into a regular lattice of cubes. The the length of the side of each cube should be half the minimum distance between points.

For the first point, see which cube it is in. Add a flag to the cube that contains the point to indicate that that cube contains a point of that color.

For the next point, see which cube is in. If none of the adjacent cubes are flagged with a point of that color, flag the cube with the color of the point like in (2). Otherwise throw the point away.

If you still have unprocessed points, go to 3.

Advantages

The advantages of this approach are:

It is fast

It is easy to understand and to implement

Limitations

This algorithm has several limitations:

Use of Cubes

The algorithm will throw away too many points because it uses cubes instead of spheres. The question suggests that this is OK.

It it is a problem, however, this limitation can be overcome.

One way is to add the coordinates of the point to the flags. Then, when you test points in step (3) and you find that there is already a point in an adjacent cube, check the distance to that point before you decide whether to throw the point away.

Of course, this will slow things down / add complexity / increase the memory requirements of the algorithm.

Order of Testing Points

The number of points you end up with will depend on the order in which you test the points. To prove this, imagine the situation where you have just 3 red points, and that the cubes they fall into happen to be in a row:

```
+-----+-----+-----+
|     |   . |     |
|.    |     |     |
|     |     |   . |
+-----+-----+-----+
```

In this case, you could either throw away the point in the centre cube or the two points in the adjacent cubes.

To improve on the original algorithm, then, you could use the cubes as a basis to count the points of a given color that are tooo close to each other, then throw away the points that have the most points too close. I have not explored this in much depth: I'd need to work through a set of scenarios on paper to figure out the best way to do this.

Memory Use

Another potential problem is that the algorithm could use up quite a lot of memory.

A sensible first step would be to limit the number of cubes created to the minimum by calculate the bounding cuboid for all the points and then only using enough cubes to contain the bounding cuboid.

Another improvement would be to divide the problem into larger cubic regions that contain sub-sets of the full set of points, and processing each of these regions separately. Naturally, special care will need to be taken at the boundaries of thes regions.

Body:
Here is what I would do:

Divide the space into a regular lattice of cubes. The the length of the side of each cube should be half the minimum distance between points.

For the first point, see which cube it is in. Add a flag to the cube that contains the point to indicate that that cube contains a point of that color.

For the next point, see which cube is in. If none of the adjacent cubes are flagged with a point of that color, flag the cube with the color of the point like in (2). Otherwise throw the point away.

If you still have unprocessed points, go to 3.

Advantages

The advantages of this approach are:

It is fast

It is easy to understand and to implement

Limitations

This algorithm has several limitations:

Use of Cubes

The algorithm will throw away too many points because it uses cubes instead of spheres. The question suggests that this is OK.

It it is a problem, however, this limitation can be overcome.

One way is to add the coordinates of the point to the flags. Then, when you test points in step (3) and you find that there is already a point in an adjacent cube, check the distance to that point before you decide whether to throw the point away.

Of course, this will slow things down / add complexity / increase the memory requirements of the algorithm.

Order of Testing Points

The number of points you end up with will depend on the order in which you test the points. To prove this, imagine the situation where you have just 3 red points, and that the cubes they fall into happen to be in a row:

+-----+-----+-----+
|     |   . |     |
|.    |     |     |
|     |     |   . |
+-----+-----+-----+

In this case, you could either throw away the point in the centre cube or the two points in the adjacent cubes.

To improve on the original algorithm, then, you could use the cubes as a basis to count the points of a given color that are tooo close to each other, then throw away the points that have the most points too close. I have not explored this in much depth: I'd need to work through a set of scenarios on paper to figure out the best way to do this.

Memory Use

Another potential problem is that the algorithm could use up quite a lot of memory.

A sensible first step would be to limit the number of cubes created to the minimum by calculate the bounding cuboid for all the points and then only using enough cubes to contain the bounding cuboid.

Another improvement would be to divide the problem into larger cubic regions that contain sub-sets of the full set of points, and processing each of these regions separately. Naturally, special care will need to be taken at the boundaries of thes regions.


答:
go for the Head First. it explains how you write code the usual way, what the problem would be with a modification not done the right way, the design principle to apply, the refactor and then points the result to what pattern you just used.

i found the design principles most useful. would not have bothered with the patterns if the principles weren't explained

Title: Is the GoF book still the one to read?

Body:
Possible Duplicate:

  Is there a canonical book on design patterns?

I'd like to read a design patterns book. GoF for sure is the one to read. But after 15 years is it still valid, I mean isn't there an updated one?

Something like "Charles Darwin On the origin of species" is a very important book, and some main concepts are still valid, anyway today (2010) one would read another book to study the subject.

In this question the main suggestions are the Head First and GoF books. But Head first is not a replacement for GoF.

So any suggestion or should I stick with GoF?