问:
If you learned formal methods for software, how useful have you found it?
If you have been trained in the use of formal methods (FM) for programming:

How useful have you found it?

What did your FM training involve (e.g. a course, a book)?

What FM tools do you use?

What advantages in speed/quality has it given you compared to not using FM?

What kind of software do you create with FM?

And if you don't directly use FM now, was it at least worth learning??

I'm curious to hear as many experiences/opinions on FM as can be found in this community; I'm starting to read up on it and want to know more.

Background

Programming and software development/engineering are some of the newest human skills/professions on Earth, so not surprisingly, the field is immature — that shows in our field's main output, as code that is typically late and error-prone.  Industry immaturity is also shown by the wide margin (at least 10:1) in productivity between average and top coders.  Such dismal facts are well covered in the literature, and introduced by books like Steve McConnell's Code Complete.

The use of formal methods (FM) has been proposed by major figures in software/CS (e.g. the late E. Dijkstra) to address (one of) the root causes of errors: the lack of mathematical rigour in programming.  Dijkstra, for instance, advocated for students developing a program and its proof together.

FM seems to be much more prevalent in CS curricula in Europe compared to the US.  But in the past few years, new "lightweight" FM approaches and tools like Alloy have attracted some attention.  Still, FM is far from common usage in industry, and I'm hoping for some feedback here on why.

Update

As of now (10/14/2010), of the 6 answers below, no one has clearly argued for the usage of FM in "real world" work.  I'm really curious if someone can and will; or perhaps FM really does illustrate the divide between academia (FM is the future!) and industry (FM is mostly useless).

答: State diagrams and Petri nets are useful for modelling and analyzing protocols and realtime systems. First they help design a solution. Second they help find test cases for exciting software in very specific situations.</p>


问:
How does one get a group of programmers together for a project?
I recently pitched a project I've been working on to a small company that I know, coincidentally, has a need for something similar. They seemed excited by what I have, and what I said I could do, but worried that, as a lone (actually, they said 'rogue') programmer I could up and leave them with a non-functional program. They suggested that I get a few people together, write up a solid proposal, and meet with them again. They've promised office space and a good budget because this is an application that would greatly increase productivity for them.

The problem is I'm still quite new to the field, I have no professional experience, and while I know I could complete this project, I don't know how to find other people to bring in on it.

Does anyone have any experience in situations like this? Any ideas on where I could look?

Also, the company and I are both located in Manhattan, if that helps determine where to look for people.

答:
Since you are in Manhattan, wait for the storm to die down then try Craigslist. But don't forget that the strangers that you bring into the program may be worse than a single "rogue" programmer.

Your better bet would be to demonstrate that you are using established programming techniques in an established programming language. Demonstrate that your code is well commented and conforms to standard programming conventions. Then in the event that you get hit by a bus anyone with knowledge of the language will be able to step in.

ContentLicense: CC BY-SA 3.0


问:
When developing a piece of software, when do you start thinking/designing the concurrent sections?
Following along with the principle of not optimizing too early, I'm wondering at what point in the design / development of a piece of software do you start thinking about the concurrency opportunities?

I can well imagine that one strategy would be to write a single threaded application, and through profiling identify sections that are candidates to run in parallel.  Another strategy I've seen a little of is to consider the software by groups of tasks and to make the independent tasks parallel.

Part of the reason for asking is that of course, if you wait until the end and only refactor the software to operate concurrently, you may structure things in the worst possible way and have a major task on your hand.

What experiences have helped to determine when you consider parallelization in your design?

答:
Java programmers should embrace the Callable interface for work units.  If your whole application consists of a loop of creating Callables, shipping all the units of to an Executor, handle any post generation tasks, you have something that can be very easily be shaped into serial processing, "three work queues" and "do all at once" simply by picking the right executor.

We are slowly adapting this pattern as it is very common that the serial approach gets too slow at one point and then we need to do it anyway.


问:
practical way to learn C?
I want to dig into C and normally when I want to learn a new language I think of a simple/attainable project goal that has some practical purpose (make use of an api, automate a task, etc...)

I'm having a harder time coming up with one for C mainly because everything I read points to the fact that C's primary use currently is in embedded systems and more complex software projects like operating systems.

Does this point me to the fact that I don't need to learn it or that I just need to be a bit more convoluted in my learning strategy?

References to practical learning resources? (tutorial/how to that produces an end result that has some purpose/benifit)

答:
I would just recommend picking up a copy of Kernighan and Ritchie's The C Programming Language (2nd Edition). It has a number of exercises at the end of each chapter that you can do, along with providing a very good introduction to the C language. It won't make you a master of the language, but you should have a good enough grasp at the end of the book and exercises in order to perhaps find an open source project written in C that you could read the source to and perhaps contribute to.

If you want to see actual real-world projects with C code in them. It is getting harder - many projects use a "higher level" language, but C is still alive and kicking. If you want to learn C, don't be afraid to reinvent the wheel to achieve learning. It's not a good idea to reinvent solutions on the clock, but it's perfectly fine to do so as an academic exercise.

Title: practical way to learn C?


问:
Is performance engineering a different specialization from general software development?
A major objective of software development is to focus on delivery of features implemented in good quality code.

Knowledgeable developers are supposed to write software with good performance to the extent of their understanding (that is, in the software module they are working on). For example, they should be able to use appropriate algorithms and data structures when implementing various parts of the system. In other words, the first implementation which they wrote to satisfy a unit test would have the good performance characteristic that the final product is supposed to have.

However, when the system is large and complex, consisting of many components written by different people/teams and include multiple vendors, is it more productive for a company to separate the roles of performance engineering from software developers, so that software developers can focus on features and correctness that meet specification, and the performance engineer can focus on measuring and improving performance without affecting feature and correctness?

Put simply, are there two different hats, requiring two different mind-sets?

Motivation:

From the answers I got from another question An alternative to requiring red in TDD: reverting code change?, it dawns on me that during the main software development time, meeting functional requirements is a must-have while software performance is a nice-to-have.

Tests on functional requirements have deterministic outcomes, usually Pass/Fail, or Accept/Reject.

Performance characteristics don't have a fixed Accept/Reject target, but do have a metric which can drive the performance-optimizing effort.

Future changes in functional requirements may make it necessary to sacrifice/adjust certain performance objectives.

Personally, I do agree that there should be a quick feedback cycle between feature implementation and software performance monitoring.

In this question I'm arguing whether these two are separate specializations - although some people might be specialized in both.

Possible outcomes

When feature implementation and optimization are done by different developers:

They will go into conflicts and nothing gets done. (contributed by @quant_dev)

The resulting software has better performance.

The resulting software has poor performance.

Related:

https://softwareengineering.stackexchange.com/q/59292/620

(Will ask in a separate question soon.) Is it possible that software performance issues can arise from large software systems that cannot be forecast even by the very knowledgeable software developers? Will a dedicated performance engineer be able to solve it?

答:
Here's an example of one of my experiences in performance tuning.

Here's another.

If I were back in academia, and I could tell today's programmers how to deal with this issue, I would make sure they are competent in the random-pausing technique.

As it is, they come out of school thinking a) performance is all about big-O, and b) profilers are how you find performance problems. This is because that's all their teachers know, and their teachers have never done much performance tuning on real (large) software, as in the links above.
They still think measuring = finding, and they still think they're looking for "methods where time is spent", as if the meaning of that is even understood.
Here's a list of the myths.

So, to answer your question, a) quality testing should make sure stress-tests are included, to detect performance problems, and b) the programmers should be the ones to find and fix the performance problems, just like any other bug.

When programmers get enough experience, they learn to avoid design approaches that lead to performance problems, such as over-complicated data structure design, unnormalized data, and things they've been taught as part of OOP, such as over-reliance on notification, too much "new"-ing, and information-hiding leading to program-counter-swallowing black holes.

With experience, they learn how to use their OOP skills judiciously and sparingly, so as not to cause many performance problems.
They also learn how to find and remove the remaining ones they do cause.

Performance problems are just like bugs. Experienced programmers make less of them, but if they're not making any they're not working.
In any case it's their job to find and fix them,
but in my experience, sadly, few of them actually know how, and we all experience the result.


答:
If you are looking for help for a short-term project, you may ask for help on specialized websites (I won't link them cause I'm not sure it's allowed). You can find people working near you or worldwide with a remote job. I would start there. Googling for "freelancers" will give you already many.

You can also search for help in some programmers or programming-related forums, creating a new post (if a specified section for this topic exists) explaining your needs and the kind of project you need to make.

Title: How does one get a group of programmers together for a project?

Body:
I recently pitched a project I've been working on to a small company that I know, coincidentally, has a need for something similar. They seemed excited by what I have, and what I said I could do, but worried that, as a lone (actually, they said 'rogue') programmer I could up and leave them with a non-functional program. They suggested that I get a few people together, write up a solid proposal, and meet with them again. They've promised office space and a good budget because this is an application that would greatly increase productivity for them.

The problem is I'm still quite new to the field, I have no professional experience, and while I know I could complete this project, I don't know how to find other people to bring in on it.

Does anyone have any experience in situations like this? Any ideas on where I could look?

Also, the company and I are both located in Manhattan, if that helps determine where to look for people.


答:
I agree with most people here that today languages are determined by the task at hand . There was a time when you had limited choice in this regard .
 Today C is mainly used in Embedded/System programming domain where there is a need for code optimization . You need to write precise codes to get the maximum because if ever you start to use that abstraction , then the underlying stuff has to very robust . I would say you try to get around some open source GNU projects like Linux itself or something that needs C developers . Try your hand in those projects instead of writing something out of scratch in C . This is probably the better way to write codes and learn a language .</p>

Title: practical way to learn C?

Body:
I want to dig into C and normally when I want to learn a new language I think of a simple/attainable project goal that has some practical purpose (make use of an api, automate a task, etc...)

I'm having a harder time coming up with one for C mainly because everything I read points to the fact that C's primary use currently is in embedded systems and more complex software projects like operating systems.

Does this point me to the fact that I don't need to learn it or that I just need to be a bit more convoluted in my learning strategy?

References to practical learning resources? (tutorial/how to that produces an end result that has some purpose/benifit)


答:
You're going to have to really understand memory allocation.  You sound like you've used other languages before, but the chances are that those other languages hid the gory details of memory management from you.  In C, the memory management is always explicit.  There are some advantages to this, but it means that you have to be careful to get it right or all Hell will break loose.

Use whatever memory debugging facilities are available for the platform you use.  For Linux there is Electric Fence, on Mac OS X there is Guard Malloc.  Also there is Valgrind which supports a number of operating systems.

If you fail to free memory that should be freed, you'll have a memory leak.  Keep doing that and you'll run out of memory.  Even with backing store (what most people call virtual memory), you can cause the system to page excessively or even run out of swap space.

If you free memory that has already been freed, you'll corrupt the heap and crash, but probably not right away.  You'll also corrupt the heap if you overrun a buffer.  The memory debugging tools will help with all of these.

Unit testing also helps.

Title: practical way to learn C?


问:
Why does the Perl community have such a bad reputation?
I'm still fairly new to programming. I spend most of my time in Ruby, and I'm discovering a certain fondness for playing with regular expressions. That being said, I'm considering taking a look at Perl, just as a hobby. However, I've heard a lot about the Perl community, and none of it good. I've heard the community described as extremely elitist and resistant to inexperienced programmers.

Is this true? If it is, why is that the case?

答:
Nowadays I can't say that it's true.
However I believe such description of Perl community has it's background in past and anyway you can find elitist in any community around any language.

There's large community around web frameworks like Mojolicious, Catalyst or Dancer and they are very friendly to newbies (not only for framework itself, but for Perl language too).

Also as of I saw, help communities are very friendly to inexperienced programmers.

Just and example I can provide #perl-help channel at irc.perl.org server where you often can get help from extremely experienced Perl programer who often advise you to use right library from CPAN for your case or just help with syntax and regexp.
Also #mojo and #dancer channels on the same server are good example of framework communities.


问:
Is it common to print out code on paper?
I like to keep my lines of code under 80 characters because:

I don't have to do any horizontal scrolling;

I know the line is probably too complicated if it exceeds this limit; and

it prints out nicely on paper.

Concerning the latter, I've met only a few who actually print out code to look at (I'm one of them). So how common is it to print out code?

答:
These days, never. I have the support of multiple monitors if I need to reference some particularly difficult code. Modern hard drives aren't going to blink at me storing code that's even several thousand lines long. Printing code IMHO is wasteful and generally useless but that's just me.

That said when I was first learning up to develop/program I thought nothing of printing 20 pages of code, so I suppose there might be a time and a place for it but I just find these days there isn't much use for it.

ContentLicense: CC BY-SA 2.5


问:
Should I try to do practice problems in assembly?
I was looking at Project Euler Problem 48:

The series, 11 + 22 + 33 + ... + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.

In Python I can do this with a single line :

```<code>sum((x**x for x in xrange(1,1001))
</code>```

But the assembly equivalent of this would be 100 lines and a real challenge.

Should I be doing some of these puzzles in assembly to gain some insight into low-level programming and understand how the computer actually works?

答:
The way I've been working on understanding assembler is by writing programs in higher-level languages, then replacing parts with (at least hopefully) functionally equivalent tracts of assembled code. This means I get to use HLLs for what they're good for-organising and solving high-level problems-and I use asm for banging the metal.

(When I talk about the host program being written in a HLL, I mean C or ObjC when I'm trying to learn x86_64 asm, and BASIC when I'm working on Z80, 6502 and 6809 asm).


问:
Supplying code to people helping you debug?
I was wondering if it is wise or advisable to send over a large amount of source code of one's application for debugging and error solving purposes, I'm working on an iOS app that I hope to release to the App Store and am seeking help on Stack Overflow and I'm tempted to send over a large amount of the code so someone (they requested it) can help me. Would you recommend sending over a significant portion of your app to someone for debugging purposes?</p>

答:
Remember that code published on Stack Exchange sites will become CC-wiki licensed, so you may not want to license your code thus by publishing it in that context.

More generally, you want to demonstrate enough code that the problem or bug you're trying to solve is reproducible. But regardless of intellectual property considerations, giving the other party more code than is necessary makes it harder for them to determine where the problem lies-remember that you're having trouble finding the bug, and you know your code better than they do. The "minimal buggy project" helps your reader see what you're trying to do, and indeed you may even gain a better understanding of the problem by identifying the relevant extracts of code.


问:
Reestimation (ideal hours + elapsed time)
At the beginning of every iteration our whiteboard is covered with "not started" stories estimated in IDEAL HOURS. On a daily basis we update these estimates to keep track of each task's progress. I think we are doing it wrong. The original estimates are in ideal hours and our daily "re-assessment" in ELAPSED TIME. This seems inconsistent, right?! How would you measure your progress towards the end of the sprint?</p>

答:
Reestimating tasks during sprint is non-sense. It will just spoil burndown chart and it will not change commitment you already did.

Anyway in my opinion whole point of "estimating" tasks is waste. What you will get by estimating these tasks?

Will the estimate will make your product better?

Will the estimate increase the quality of the product?

Will you make your product faster if you spend time on doing estimates?

Will your product be better if you do more estimation?

I don't think so => task estimation doesn't bring any value.

Now what will happen if you don't do estimates?

Does it mean that you will not be able to track the work progress?

Does it mean that you will not estimate?

Does it mean that you will not be able to do commitment?

No because tasks are created from user stories which are already estimated. Commitment is done on user stories so it doesn't matter what is estimate of tasks. Only important thing to track during sprint is amount of completed user stories which can in case of burndown chart still be represented in amount of delivered "story points" or any other unit used to estimate user stories. Tasks should be small and it doesn't matter if small mean day or 3 hours. Developers should be skilled enough to create such tasks without need for estimation. It means that task estimation doesn't remove any value.

If we go to lean principles any process which doesn't bring any added value and can be removed without loosing any value is a waste and should be eliminated.

But perhaps you get some value from task estimation - every team can implement Scrum little bit differently. If you doubt you can use great feature of agile. You can simply try it in one sprint and if it doesn't prove itself useful you can return to task estimation.


问:
How do you deal with errors in enumeration / list processing (lowish-level API)
Ive struggled with variants of this problem many times, experimenting with different solutions, happy with none.

Abstract: Enumerating a list of items, an error for one item does not affect the others. Potential callers have varying requirements on how to treat these errors, goal of the API is to simplyfy use and reduce complexity.

A more general case in which this problem occurs would be processing a list of independent items, and partial success is acceptable / desired, i.e. it's not run as a transaction.

Example scenario:

I am dealing with a low level C-Style enumeration API like this:

```<code> // gets called for each "stuff" item
 typedef bool (*tEnumStuffCallback)(stuff * item, void * callbackArg);

 // calls "callback" for each "stuff" item.
 // caller enumeration context in callbackArgs
 void EnumStuff(tEnumStuffCallback callback, void * callbackArg)
 {
     stuff * item = 0;
     for(;;)
     {
         int err = stuff_get_next_item(&item);
         if (err == no_more_stuff)
           return;

         // === TODO: handle "real" errors ===

         // pass item  to callback, stop enumeration if requested
         if (!callback(item, callbackArg))
           return;
     }
 }
</code>```

For backward compatibility and "caller expectations", I want/need to preserve the pure C style without exceptions. A higher-level wrapper, built on top, might look like this:

```<code> EnumStuffs(std::vector< boost::shared_ptr<stuff> > & items);
</code>```

The caller may need one of the following strategies when enumeration errors occur:

Stop enumeration  on first error, e.g. because caller will ignore the entire list and enumeration is costly. A C++ client might want to throw an exception from the callback (allowed).

Ignore the items - e.g. when enumerating connected devices, and looking for a specific one to be available, and device not found errors are handled separately

Ignore, but log diagnostics in a caller-specific way (i.e. caller needs to know abotu errors)

Caller needs detailed list of errors for further analysis, e.g. items may be "retried" on certain types of errors

Note that this is the callers choice, I can't force a decision.

Note / Context Example idealized, in practice, I have multiple enumerators involving different types; sometimes I have to provide the enumerator, sometimes the enumerator function comes from the OS. Error information can be more complex than a single int.  The underlying API involves dozens of rather confusing types already, I want to avoid introducing the same amount of additional/wrapper types. Bridging different development styles is actually part of
my job description, opportunities for educating either end is tricky (I have to pick my battles).

My ideas / solutions

provide a separate callback for the errors. Enables all scenarios, but bloats the interface.

Replace the enumerator function with a stateful object. Increases number of types, does not provide backward "style" compatibility.

pass the errors to the enumerator. that's sometimes a bit better than the previous solution, but usually requires an "enumeration context" structure instead of separate arguments. Goes against the plan to avoid additional types for each enumerator

introduce an "error type", caller can either request a "list of errors" as a result, or get the "stop/throw at first error" behavior by default. I've used that before, but in the end the detailed information is typically used only to build some diagnostics, and isn't "liked" as it makes it "complicated to deal with errors".

Questions

What are your thoughts? Do you have ideas for, or have you used other approaches? Under what circumstances would you use / not use above approaches?

答:
Short Version:

You say it's the caller's choice how to handle errors, so implement your first idea. It's simple and one more argument can't be considered interface bloat, in fact, in your case it's even desired as it tightens your contract between caller and callee! It's quite easy to use and the caller manages all the errors.

Long Version:

provide a separate callback for the errors. Enables all scenarios, but
  bloats the interface.

I can see no interface bloat when you just pass a second function pointer for error handling if it's the callers responsibility to handle them. Three arguments ain't that much. You'd have to pass a third argument anyway when you'd try to apply a strategy pattern. Do you want one callback for each error? Why not have one callback for all errors? The callback could take the current error as an argument and react to it. It should have a way to stop the enumeration or ignore the item, too, which can be done by a custom return type (best is probably a simple enum: continue_processing/ignore_item/abort_processing). Usually I'd advise using a strategy pattern here, but if you can't control the callers, that is, you can't make them write strategies or you want to keep the interface in pure C-Style, then use the simple function pointer callback (basically a "hole in the middle"-pattern)! TBH, imho it's even desired to have the error-handler in the methods signature, as it communicates the contract much clearer.

Replace the enumerator function with a stateful object. Increases
  number of types, does not provide backward "style" compatibility.

Homogeneity is sacred. Always strive to have one clear way of dealing with stuff, that'll make the API more intuitive to understand, so less learning of particular exceptions is necessary. Only do so if it isn't possible to provide a "standard" interface. I don't think you should encapsulate each enumeration in a stateful object just because you have a "hole in the middle" (I'll talk about that later as well). That could violate DRY principles. If you can have a base class on the other hand and just have objects that deal with the custom error handling, that'd be an acceptable design. But I wouldn't sacrifice homogeneity if there're other solutions that work equally well.

pass the errors to the enumerator. that's sometimes a bit better than
  the previous solution, but usually requires an "enumeration context"
  structure instead of separate arguments. Goes against the plan to
  avoid additional types for each enumerator

That's basically idea 1 just with a list of errors and handlers (the context). Imho it's just the complicated version of idea 1. Keep it simple.

introduce an "error type", caller can either request a "list of
  errors" as a result, or get the "stop/throw at first error" behavior
  by default. I've used that before, but in the end the detailed
  information is typically used only to build some diagnostics, and
  isn't "liked" as it makes it "complicated to deal with errors".

So you get a list of errors before you enumerate to which you can then subscribe with a callback? Again, sounds like a complicated version of idea 1. Again: Keep it simple.

What you are encountering is called "hole in the middle". The functional programmer's have long solved these kind of problems by passing functions (which are first class citizens in such languages). A function pointer (as in idea 1) can achieve the desired behaviour almost as easy. The interface/signature is just one function pointer more and as the responsibility of error handling belongs to the caller, it's even desired to have this in the interface/signature.


答:
Whenever I have a such scenario when I have to share my code for debugging purposes on Stack Overflow. I do a lot of edits. I remove the package of my organization from Java files. I rename API names. And a lot of stuff. So that I can comply to the policy of my company to not supply code online. But with edits, it will be safe to get help from people.

People can help quickly with short code snippets. I always share my sense and approach that I am using and ask people. And I always get very useful pointers.

Title: Supplying code to people helping you debug?

Body: I was wondering if it is wise or advisable to send over a large amount of source code of one's application for debugging and error solving purposes, I'm working on an iOS app that I hope to release to the App Store and am seeking help on Stack Overflow and I'm tempted to send over a large amount of the code so someone (they requested it) can help me. Would you recommend sending over a significant portion of your app to someone for debugging purposes?</p>


问:
When you write wrappers for APIs how do you handle usage errors?
When you write wrappers for APIs how do you handle usage errors?

Do you assume that the user uses it right and write the wrapper such that it makes the call to the server and let the server return the error?

Or do you check for the missing parameters and return an error? If yes, how do you convey the error? a string or an error code?

答: You should never trust your caller, who is calling your API. You need to implement tight checks on the inputs. And always validate the request object before sending it to further processing. You can use the approach of giving a response object to the caller. Having a field of response code and response description. And you can standardized these response codes for your application.</p>


答:
Licensing and copyright issues notwithstanding, you usually get the best responses for really short code snippets - 5 lines is ideal, 50 lines is doable, 500 lines is asking too much. If you post a short snippet, you demonstrate that you have made an effort narrowing the problem down, that you are willing to do your homework (translate the short proof-of-concept solution into something that works in your product), and that you consider the time of those that are helping you as valuable as your own.

Honestly, I can't think of a problem that would require you to send large quantities of code; such problems should always fall in one of the following categories:

"Please do my work for me, because I am lazy": Your problem can be solved or narrowed down using standard debugging techniques, but rather than try them yourself and seek help with the results, you prefer someone else doing the work for you.

"I don't understand this code, it's too complicated": One could argue that if your code is so complicated that you cannot understand it, it is bad code and needs to be refactored or even rewritten. It is also possible that you do not fully understand the problem you are trying to solve, in which case your coding attempt is doomed from the beginning; and the solution is obvious (though not comfortable): re-analyze the problem, refactor, redesign, rewrite, until the structure is clear. You should now be able to extract a short snippet that shows the problem.

Someone Else's Mess. Most of us have been in a situation where you inherit a 10-something-year-old pile of spaghetti, with cross-dependencies all over the place, full of mysterious methods with no apparent purpose, misleading identifier names, useless comments, liberal use of obscure language features and edge cases, stuff that's needlessly complicated, redundant, or outright wrong - in short, your average nightmare. The sad news is: You're in this mess alone, nobody likes dealing with it. Man up and ask questions about suitable strategies (in fact, p.se is full of excellent questions and answers on this topic), but don't expect anyone to do your work for you (see a pattern yet?)

Large-scale design problems. These problems play at the macroscopic scale, but if you can word them well, you don't need to post any code at all, or maybe just some stubs illustrating your design.


问:
How can I configure my programming environment to enable rapid switching between projects?
It often happens that I develop multiple different projects at once, so I need a solution to switch from one environment to another.

I have created batch files to do the job but as this thing grows, I'll soon need something better.

Some things I do are:

Map drives

Launch applications

Load test databases

Set environment variables

etc.

Any suggestions on that?

Edited:
I want to unify the development process in some way. We use VS, Eclipse, Notepad++ or what ever the developer needs.
The goal is to be able to load a project in any windows machine without having compiling or other issues.

Example:

The solution might need to reference files, sdk folders, test data paths or other stuff.
To solve this: I have mapped the code to a drive. The project doesn't need to know whether the dev is using c:\dev or c:\programming folders (user choice). They only need to map their coding folder to a drive (lets say W:) every file of the solution is under W:

Another problem is the SDKs. An sdk can be in c:\programfiles\Microsoft sdks\etc.. or in c:\programfiles x86\Microsoft sdks\etc..
Those Sdks should also need mapping to a standard folder that the solution knows.

Another thing is that we want services running (apache lets say) if we develop a website. We don't want this to run all the time.

The solution so far is to distribute batch files that the developer edits once in order to match their paths to the solutions and they run the batch before they start their new task.

I am thinking on developing a app that will set the environment as desired. Preconfigured sets that are distributed. The developer executes them in order to set the enviromnent as desired.

I hope to be clear now on the problem. Any suggestions on doing that in a better way?

答: Sounds like you should have a look at virtual machines and simply have one per project.  Then you can separate your projects completely, and you can have several projects open at one time.


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

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

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

答:
SCJP is a very basic cert.  You should certainly get this, then do SCJD.
(Note that these things have new names now.)  SCWCD is also basic.  Do something more impressive.

http://en.wikipedia.org/wiki/Sun_Certified_Professional

In terms of your on the job responsibilities, you probably ought to be doing project leadership work before seeking an architecture position.


答: Whenever I interview people I usually ignore their certifications.  In my experience certifications are not a good barometer for usable knowledge.  My questions during the interview will usually let me know if the person knows the information needed AND can apply it to real world problems.</p>

Title: Are Java certifications important for an architect role?

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

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

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


问:
How can one manage thousands of IF...THEN...ELSE rules?
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in any landscape. They are affected by things like the sun, wind, food source, sudden events etc.

How can such an application be managed? I imagine that after a few hundred IF-statements, it would be as good as unpredictable how the program would react and debugging what lead to a certain reaction would mean that one would have to traverse the whole IF-statement tree every time.

I have read a bit about rules engines, but I do not see how they would get around this complexity.

答:
This is more of a community wiki answer, aggregating the various modelling tools suggested by other answers, I've just added additional links to resources.

I don't think there's any need to restate that you should be using a different approach to thousands of hard-coded if/else statements.

DSL Programming (Domain Specific Language)

Markov Model/Markov Decision process

Rete net / Rete algorithm

Expert System

Matlab, (Wikipedia)

R


问:
What's the relationship between Java EE and Glassfish?
I'm confused. Does Glassfish come as part of the Java EE platform? Can you get Glassfish but not Java EE?</p>

答:
Glassfish is the reference implementation by Oracle for Java EE specifications. So, Java EE - a set of specifications for enterprise applications - is independent of Glassfish - a reference implementation for Java EE specifications.

Glassfish does not come as a part of Java EE as there are other Java EE implementations such as IBM's WebSphere. However, it is not possible to get Glassfish without Java EE as it is the reference implementation of Java EE specifications.


答:
If it's financially sound for you to finish the project in your spare time without getting paid, then do that.  Then come back to the company and pitch the finished project with a pilot trial run. No guarantees they'll buy it, but it will lay to rest their fears of an unfinished/useless program.

FYI. Contacts are gold and you don't share that all willy nilly. You may get cut out of the deal.


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

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

For example:

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

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

For example:

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

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

I want to listen your opinion.

Am I wrong?

答:
You have probably been reading agile books.  The agile style seems to be small functions that do one thing and are well named.  In fact within a function if you have to write a comment, many of the agile books advise taking that code, wrapping it in a function with an understandable name which can serve as that comment and calling that.  One of the reasons is that they are big into DRY (don't repeat yourself) and comments often have a habit of becoming outdated and repeating stuff that should be clear from the code.  The only guaranteed documentation is the code.

But in most real code bases, I often see functions that do multiple things or are poorly named.  E.g. request_ait, hoa_request_ait...  I have no clue what those functions do.  The abbreviations hoa and ait might mean something to your business, but what if someone new comes in?  I would say a comment could clear up what is being done (most new people are just thrown into the fire without much formal business training).  Many times the acronyms in programs do not tie to common business acronyms.  E.g. instead of FindSpellingErrorInList someone decided to do FSE_List or something.  Good luck to someone who does not know that FSE is how you find a spelling error in a list unless there is a comment.

Another thing is the language itself.  For example Java can document error conditions by throwing well named exception (throws ArgumentOutOfRangeException, throws NoMoreAITSlotsFreeException, etc.).  But even then some functions throw runtime exceptions which do not need to be declared and are not obvious.  Something like that can benefit from a comment.  If you move on to C where errors are often passed by setting errno or returning some type of return value out of the normal range...comments become VERY useful.  But if you are going to comment there needs to be stuff in place to keep them up to date, and out of date comments need to be treated as a bug and with the same seriousness as keeping the codebase updated.

Also when using a library in something like Java/Perl often it is much easier just to go through the javadoc/POD [perl documentation format] to read the function names/variable names and a brief description of what they do rather than to go through the code interpreting what is done...  I know in both Java and .NET that I do not go through the library source code when I want to use them, I go through the Java Docs/MSDN and that makes me much more productive...  Reading the code it is harder to jump file to file from function to function when reading the code.  In JavaDocs/MSDN it is really easy to click on the hyper links to jump through the documentation from one function to another.

Additionally comments are the only way to communicate why something is so.  The code only communicates what is happening and how it is done (although some declarative languages do not even communicate the how).  For the why it requires some other document.  E.g. do you need to fire some hardware operations on a device before doing a certain hardware operation?  If you do not comment, another developer may look and say hmmm why is this guy/girl doing operation x and then y when they should only be doing y.  If you do not document that y does not work unless you do x first with a comment the developer has no way of knowing.

So basically it's a trade off (like most things in software)......  For a function comment the most important things that spring to mind:

Are your functions well named with names that clearly reveal what they do?  If not, this would seem to indicate comments YAY

Do your functions mostly do one thing?  If not this would seem to indicate comments....

Are there a lot of implicit error conditions, weird out of range return values, numeric error codes (e.g. C errno)?  If you answered yes, this would seem to indicate comments

Do your functions have many side effects, especially to global structures?  If so then comments are your friend.....

Is everyone interested in readable code or does the quality of the code base vary based on who works on something?  If it varies then comments might be your friend, you don't want to see RLAB

And there are many more things besides those 3.  For example, named modules, named classes, named structs, etc. all create a context.  If you have a customer class and an attribute called name, then you know that is a customer name.  If you just have a variable in the middle of nowhere called name, how do you know if it is a CustomerName, SupplierName, PetName?

To summarize, the most important concern is clearly communicating your intend in the code.  If the code does not do that, and you cannot refactor and enforce keeping the code like that then comments are necessary.

That being said, you just moved to this company so you probably will have to conform with the Javadocs whether they are right or wrong.

OwnerDisplayName: sunglim


答: I don't think efficiency is the issue because you're using a template anyway. Don't waste time deciding which functions should have a comment. Too many teams can get caught up in this debate during code review. It's a battle that's not worth fighting.</p>

Title: Is it efficient to attach a comment on every function?

Body:
I moved to this company recently, and my first reaction of the development process leaves me with doubts.

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

For example:

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

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

For example:

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

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

I want to listen your opinion.

Am I wrong?


答:
In terms of looking for people to join you…

• User groups

Look for meetings of user groups focused on the technologies you’ve chosen for the project. Attend those meetings regularly. You can get a sense of people by observing and chatting with them. Personality, interest, and reliability are at least as important as specific skills.

Besides technical user groups, there are also support/discussion groups for small business owners and people launching startups. They may know of individuals who are good at helping on a project.

• Word of Mouth

Let people know you are looking for a partner/co-worker in this project. Start asking around the technical folks you know (or will meet through user groups, etc.). Talk to people in your client’s industry. Lastly talk to the folks you know who "know people", who have a wide circle of acquaintances and contacts. I'm amazed at how some people alway seem to “know somebody who knows somebody who does such-and-such”. Baristas, café servers, people that work in Human Resources departments, etc.

• Ask Who To Ask

A successful salesperson taught me that when they get a "No" answer, they directly ask who else they could meet who might say "Yes". In this context, that means when talking to people who know a lot of people, if they can't think of any potential candidates, ask them who else might know of potential candidates. They might not have an apple to give you, but can point you to an apple tree.

This might seem tedious and inefficient. But actually you may be amazed how productive these approaches are. People like to help in this manner.


问:
Fostering a time period where everyone can try any ideas to make software run faster?
Sometimes software performance tricks are found from a methodological and thorough search. Sometimes it requires divergent thinking and courage to try crazy ideas. Sometimes an idea is just the beginning that needs to be followed with a lot of hard work.

How to foster a time period where everyone can try different ideas to improve the performance of the software we're working on? Everyone on the team has at least several months of experience with the software and are very good at it.

Do you agree that divergent thinking will help find ways to improve software performance? Why? Why not?

What techniques will enable us to quickly try out an optimization idea? Is fast coding speed necessary for getting good results from the try-out?

Finally, how much "time" should be allocated to ensure good results without creating the possibility of slacking off?

Is experimentation necessary to prove that "a faster way to do something" exists? (Added 2011-06-07)

Related:

What are your strategies to improve the level of your team in a clever way?

When do code hacks become bad?

(For bounty purpose only-2011/06/07 the team size is 2-4 developers, no dedicated QA. All code, unit test and performance test done by developers. Because of the nature of the project, profiler result is useful in showing proportional execution time even if it does not reveal a single bottleneck.)

答:
In general (**) you don't get better performance by experimentation.

You get it by

Knowing how to make a simple, efficient design to start with. If you get this part wrong, experimentation will not make much difference. For example, know how to tell when using a code generator is a winning design approach.

Knowing how to tune software by locating the activities that are a) expensive on a percentage basis, and b) replaceable with something better. Everybody knows you should "use a profiler", but that's not enough.

Check this answer to your other question.

** Exceptions might be tight hardware-dependent code, like graphics rendering, processor pipeline or CUDA behavior, or experimenting with network or DB protocols, where you just need to get familiar with the best way to use it.

ADDED: There is something that many programmers of large systems find surprising.
It is that in large perfectly well-constructed programs, there can be large, invisible performance problems, and profilers can't find them because they are not localized to routines.
They are part of the general structure of the program, even though the program may be done in the very best style.

Just to give a concrete example, here is a program with source code (in C++) that does a job.
It is distilled from a real C program I worked on.

It does what it was intended to do, but what fraction of its time is not really necessary?
How much could it be speeded up?

Well, in the first version of the program, something perfectly reasonable-looking and nonlocal (invisible to a profiler) was taking 33.3% of the time. When it was replaced, that time was saved, and that was the second version of the program.

In the second version of the program, something else (invisible to any profiler) that could be removed was taking 16.7% of the time. Removing it led to version 3.

In version 3, 13% was removed. Out of what was left, 66% was removed.
Out of what was left after that, 61% was removed!

Then finally, out of what was left after that, 98% was removed!

So what's the big picture? Out of every 1000 cycles spent by the original program, how many were removed?
998 !

Every program is different, but every large program, in my experience, has a series of time-taking issues that profilers won't find, that manual sampling will, and that, if the programmers are truly going for maximum performance, can be removed for large speedups.


答:
I'd add that it might be the case that if you truly have thousands of IF...THEN rules you might be overspecifying.  For what it's worth, neural network modeling talks I've attended often start with stating how with "a simple set of rules" they can generate fairly complex and reasonably reality-matching behavior (of, in those cases, real neurons in action).  So, are you sure you need thousands of conditions?  I mean, besides 4-5 aspects of weather, location of food sources, sudden events, herding, and terrain, are you really going to have many more variables?  Sure, if you tried to do all possible permutations of combining those conditions, then you could easily have many thousands of rules, but that is not the right approach.  Maybe a fuzzy logic style approach in which the various factors introduce a bias on each cow's location that combine to an overall decision would allow you to do this in far fewer rules.

I also agree with everyone else that the rule set should be separate from the general flow of code, so that you can easily tweak it without changing the program.  You could even come up with competing rule sets and see how they do against real cow movement data.  Sounds fun.

Title: How can one manage thousands of IF...THEN...ELSE rules?

Body:
I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in any landscape. They are affected by things like the sun, wind, food source, sudden events etc.

How can such an application be managed? I imagine that after a few hundred IF-statements, it would be as good as unpredictable how the program would react and debugging what lead to a certain reaction would mean that one would have to traverse the whole IF-statement tree every time.

I have read a bit about rules engines, but I do not see how they would get around this complexity.


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

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

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

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

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

答:
So I'm not sure "terrible" is the best word here. However, it has limitations, and as soon as your needs do not fit how the membership provider was designed you end up with a lot of glue code. If you can use the membership provider out of the box, I would say go for it. As soon as you start writing a custom one I question using the membership stuff anyways.

In my experience the membership provider buys you...

Sign up already built in for MVC app

Account editing

Forgot Password is easy to hook up

Validate user method

I'm sure there's something else I'm missing but I think those are the big ones. Now when you need custom password management, two factor authentication, to work with an existing data model, or a whole host of other things you start to lose out. The code that's already written for you with the membership provide should take on the order of a few days to duplicate if you know what you're doing.


答:
They probably will help as it indicates some technical ability and perseverance.

But actually it should not; Architecture is not programming.

I will presume we are talking about a "Solution Architect" role here. The solution architect's role is quite complex and involves many things.

Understanding and conforming to the organization's Enterprise Architecture

Ditto the technical architecture

Ditto the security architecture

Understanding the project sponsors aims and goals. Verifying the the requirements are relevant to these goals

Choosing a platform, development language, framework and libraries etc. from among those recommended by the technical architects.

Perhaps (and you need a really good reason to do this!) persuading the technical architects to accept a platform, language or framework outside their recommended set.

Negotiating the interfaces to other applications.

Providing the documentation required by the security architects.

Defining the hardware requirements based on the non functional requirements, expected load etc.

Requesting the required hardware, network connections and software etc from the infrastructure team

Providing the documentation required by the infrastructure team

Providing the architectural documentation required by the operations team

A tiny part of the role deals with programming and development environments, in practice, most of your time will be spent filling in boiler plate documents, or, attending endless meetings where your sole contribution is to veto idiotic suggestions and ensure that there is some residual sanity in the resulting agreements.


答:
Tackling the if web problem you can create a rule engine where each specific rule is coded independently.  A further refinement for this would be to create a domain specific language (DSL) to create the rules, however a DSL alone only displaces the problem from one code base (main) to another (DSL).  Without structure the DSL will not fare any better than native language (Java, C# etc), so we'll come back to it after we find an improved structural approach.

The fundamental issue is that you are having a modelization problem.  Whenever you encounter combinatorial situations like this it is a clear sign that your model abstraction that describes the situation is too coarse.  You are most likely combining elements that should belong to different models in a single entity.

If you keep breaking down your model you will eventually completely dissolve this combinatorial effect.  However when taking this path it is easy to get lost in your design creating an even bigger mess, perfectionism here is not necessarily your friend.

Finite state machines and rule engines are just an example of how this problem can be broken down and made more manageable.  The main idea here is that a good way to rid of a combinatorial problem such as this is often to create a design and repeat it ad-nauseam in nested levels of abstraction until your system performs satisfactorily.  Akin to how fractals are used to create intricate patterns.  The rules remain the same no matter if you look at your system with a microscope or from a high birds eye view.

Example of applying this to your domain.

You are trying to model how cows are moving through a terrain.  Though your question lacks details I would guess that your large amount of ifs include decision fragment such as if cow.isStanding then cow.canRun = true but you get bogged down as you add details of terrain for example.  So for every action you want to take you have to check every aspects you can think of and repeat these verifications for the next possible action.

First we need our repeatable design, which in this case will be a FSM to model the changing states of the simulation.  So the first thing I would do is implement a reference FSM, defining a state interface, a transition interface, and perhaps a transition context that can contains shared information to be made available to the other two.  A basic FSM implementation will switch from one transition to another regardless of the context, this is where a rule engine comes in. The rule engine cleanly encapsulates the conditions that must be met if the transition is to take place.  A rule engine here can be as simple as a list of rules each having an evaluate function returning a boolean.  To check if a transition should take we place, iterate the list of rules and if any of them evaluate to false, the transition does not take place.  The transition itself will contain the behavioural code to modify the current state of the FSM (and other possible tasks).

Now, if I start to implement the simulation as a single large FSM at the GOD level I end up with a LOT of possible states, transitions etc.  The if-else mess looks like it's fixed but it's actually just spread around: each IF is now a rule that performs a test against a specific information of the context (which at this point pretty much contain everything) and each IF body is somewhere in the transition code.

Enter the fractals breakdown: the first step would be to create a FSM for each cow where the states are the cow's own internal states (standing, running, walking, grazing etc) and transitions between them would be affected by the environment.  It's possible that the graph is not complete, for example grazing is only accessible from the standing state, any other transition is dissalowed because simply absent from the model.  Here you effectively separate the data in two different models, the cow and the terrain.  Each with it's own properties set.  This breakdown will allow you to simplify your overall engine design.  Now instead of having a single rule engine that decides all you have multiple, simpler rule engines (one for each transitions) that decide on very specific details.  Many games company are using finite state machines such as this to decide on such aspects.

Because I am re-using the same code for the FSM this is basically a configuration of the FSM.  Remember when we mentioned DSL's earlier?  This is where the DSL can do a lot of good if you have a lot of rules & transitions to write.

Going deeper

Now GOD no longer has to deal with all the complexity on managing the cow's internal states, but we can push it further.  There is still a lot of complexity involved in managing the terrain for example.  This is where you decide where the breakdown is enough.  If for example in your GOD you end up managing terrain dynamics (long grass, mud, dry mud, short grass etc) we can repeat the same pattern.  There is nothing preventing you from embedding such logic in the terrain itself by extracting all the terrain states (long grass, short grass, muddy, dry, etc) into a new terrain FSM with transitions between the states and perhaps simple rules.  For example to get to the muddy state the rule engine should check the context to find liquids, otherwise it is not possible.  Now GOD got simpler still.

You can complete the system of FSM by making them autonomous and give them each a thread.  This last step is not necessary but it allows you to change the system's interaction dynamically by adjusting how you delegate your decision making (launching a specialized FSM or just return a pre-determined state).

Remember how we mentioned that transitions could also do "other possible tasks"? Let's explore that by adding the possibility for different models (FSM) to communicate with each-other.  You can define a set of events and allow each FSM to register listener to these events.  Thus, if, for example a cow enters a terrain hex the hex can register listeners for transition changes.  Here it gets a bit tricky because each FSM is implemented at very high level without any knowledge of the specific domain it harbours.  However you can achieve this by having the cow publish a list of events and the cell can register if it sees events to which it can react.  A good hierarchy of event family here is a good investment.  Thus if the cow starts grazing the patch of terrain can record the grazing time and after some time can transition from long grass to short grass thus signalling the cow there is nothing left to eat here.

You can push deeper still by modeling the nutrient levels and growth cycle of grass, with... you guessed it... a grass FSM embedded in the terrain patch's own model.

If you push the idea far enough GOD has very little to do as all the aspects are pretty much self managed, freeing up time to spend on more godly things.

Recap

As stated above the FSM here is not the solution, just a means to illustrate that the solution to such a problem is not found in code per say but how you model your problem.  There are most likely other solutions that are possible and most likely much better than my FSM proposition. However the "fractals" approach remains a good way to manage this difficulty.  If done correctly you can dynamically allocate deeper levels where it matters while giving simpler models where it matters less.  You can queue changes and apply them when resources become more available.  In an action sequence it may not be all that important to calculate the nutrient transfer from cow to grass patch.  You can however record these transitions and apply the changes at a later time or just approximate with an educated guess by simply replacing the rule engines or perhaps replacing the FSM implementation altogether with a simpler naive version for the elements that are not in the direct field of interest (that cow at the other end of the field) to allow more detailed interactions to get the focus and a larger share of resources.  All this without ever revisiting the system as a whole; since each part is well isolated it becomes easier to create a drop-in replacement limiting or extending the depth of your model.  By using a standard design you can build on that and maximize investments made in ad-hoc tools such as a DSL to define rules or a standard vocabulary for events, again starting at very high level and adding refinements as needed.

I would provide a code example but this is all I can afford to do right now.


问:
Guidance choosing tools for developing cross-platform mobile app
I have no mobile application development experience, I don't even own a rich mobile device (I can send text messages with my cellphone :) I have strong web, .NET, and Java experience but am open to develop with any language / platform. I need to target at least iPhone, Android, and Blackberry devices. I am seeking some guidance on the right set of tools for developing an application targeting these devices given my requirement. An easy deployment model would be a big plus. I have some notion of the difference between native apps and mobile apps on devices, and the later seems like it may be a good choice in terms of cross-platform support and easy deployment, but I do need access to some device information.

I currently have a fairly simple Java Swing application which is backed by JSON web services. The application is launched automatically when a user logs into their computer via a login script (it's deployed on corporate-like network). The user is presented with some html formatted information, and they click a button to answer a question. That's about it!

Core Requirements

Must be able to get user identification information from the mobile device and send it to the server; the Swing client sends the Windows account and domain name.

Would very much like to retrieve the local date and time of the mobile device and send it to the server

Must be able to have the GUI workflow described previously: present content to user, user "clicks" a button to respond.

Must be able to communicate with the JSON web service; if needed, could use some other data encoding, but just need to be able to communicate over HTTP (unless things are very different in the mobile world and I don't know what I'm talking about!)

Nice to Have Requirements

Render HTML fragments for the content (if not possible, could strip it down to plain text)

Be able to "click" on a link to send an email someway for help / feedback

"Click" link to a web site with information on how well the user is responding to their questions; could also build this into the app if it is a mobile app.

Be able to build some kind of user options "dialog"

Render small pictures along with the content; currently the pictures are just http resources.

Thanks in advance!

答:
Check out ZooLib.  It can build BlackBerry and iOS Apps from a single set of C++ sources.  I don't think it yet supports Android, but it could be made to do so without a whole lot of work.

Until recently Android Apps had to be written in Java, but I understand that recent Android releases support Apps that are entirely native code.


答:
The irony of certifications in the Java space is that it is actually the lowest level ones which I think are the most useful.

I have the old Sun Certified Java Programmer for example (the lowest one you can have). While it doesn't really teach you anything that any decent programmer couldn't learn by doing Java tutorials for a few weeks, it does act as a simple filter. To pass it, you simply have to know basic core Java - in this sense, it's probably a somewhat useful filter for junior roles where you're looking for a straight up Java programmer. If they have it, it means they know basic Java.

I've never done any higher certifications than this - but to be honest, from experience I've found that most architects get there by becoming seniors and team leaders and getting promoted in the company simply by being good at what they do. I can't really imagine any of the Java companies I've worked at hiring someone for an architect role off the street. It's essentially in-house senior developers and team leaders who eventually got an architecture role.

At any rate, I think what's important is showing an aptitude for high level system architecture and design by taking ownership of large tasks which exercise these skills. It will probably, in some way, involve being a lower level team lead first. Proven team leading and "architecture-like" high level system design experience goes a much longer way than any certification at this level.

Note: I'm not an architect myself (or even a team lead), but this is what I've observed for over 10 years in various companies. The people who end up architects are people who know how to take ownership of large tasks, lead teams, and get things done. And I don't know any who even had any Java certifications at all.


答:
Java EE is an API, GlassFish is an implementation of that API.

Much in the same way that List is an interface, and that ArrayList implements that interface.  (This is also why you cannot get ArrayList without getting List, and why you cannot get GlassFish without getting Java EE).

Title: What's the relationship between Java EE and Glassfish?

Body: I'm confused. Does Glassfish come as part of the Java EE platform? Can you get Glassfish but not Java EE?</p>


问:
How large non-OO code bases are managed?
I always see abstraction is a very useful feature the OO provides for managing the code-base. But how are large non-OO code bases are managed? Or do those just become a "Big Ball of Mud" eventually?

Update:

It seemed everyone is thinking 'abstraction' is just modularization or data-hiding. But IMHO, it also means the use of 'Abstract Classes' or 'Interfaces' which is a must for dependency-injection and thus testing. How non-OO code bases manage this? And also, other than abstraction, the encapsulation also helps a lot to manage large code bases as it define and restrict the relation between data and functions.

With C, it is very much possible to write pseudo-OO code. I don't know much about other non-OO languages. So, is it THE way to manage large C code bases?

答:
One way of managing code is to decompose it into the following types of code, along the lines of the MVC (model-view-controller) architecture.

Input handlers - This code deals with input devices such as mouse, keyboard, network port, or higher-level abstractions such as system events.

Output handlers - This code deals with using data to manipulate external devices such as monitors, lights, network ports, etc.

Models - This code deals with declaring the structure of your persistent data, rules for validating persistent data, and saving persistent data to disk (or other persistent data device).

Views - This code deals with formatting data to meet the requirements of various viewing methods such as web browsers (HTML/CSS), GUI, command line, communication protocol data formats (e.g. JSON, XML, ASN.1, etc).

Algorithms - This code repeatably transforms an input data set to an output data set as fast as possible.

Controllers - This code takes inputs via the input handlers, parses the inputs using algorithms, and then transforms the data with other algorithms by optionally combining inputs with persistent data or just transforming the inputs, and then optionally saving the transformed data in persistent via the model software, and optionally transforming the data via the view software to render onto an output device.

This method of code organization works well for software written in any OO or non-OO language because common design patterns are often common to each of the areas. Also, these kinds of code boundaries are often the most loosely coupled, except algorithms because they link together the data formats from the inputs to the model and then to the outputs.

System evolutions often take the form of having your software handle more kinds of inputs, or more kinds of outputs, but the models and views are the same and the controllers behave very similarly. Or a system may over time need to support more and more different kinds of outputs even though the inputs, models, algorithms are the same, and the controllers and views are similar. Or a system may be augmented to add new models and algorithms for the same set of inputs, similar outputs, and similar views.

One way OO programming makes code organization hard is because some classes are deeply tied to the persistent data structures, and some are not. If the persistent data structures are intimately related with things such as cascading 1:N relationships or m:n relationships, it is very hard to decide class boundaries  until you have coded a significant and meaningful part of your system before you know you got it right. Any class tied to the persistent data structures will be hard to evolve when the schema of the persistent data changes. Classes which handle algorithms, formatting, and parsing are less likely to be vulnerable to changes in the schema of the persistent data structures. Using an MVC kind of code organization better isolates the messiest code changes to the model code.


答:
Abstraction, abstract classes, dependency injection, encapsulation, interfaces and so on, are not the only way of controlling large code bases; this is just and object-oriented way.

The main secret is to avoid to think OOP when coding non-OOP.

Modularity is the key in non-OO languages. In C this is achieved just as David Thornley just mentioned in a comment:

The interface goes in the .h file, publicly available functions in the
  .c file, and private variables and functions get the static access
  modifier attached.

Title: How large non-OO code bases are managed?

Body:
I always see abstraction is a very useful feature the OO provides for managing the code-base. But how are large non-OO code bases are managed? Or do those just become a "Big Ball of Mud" eventually?

Update:

It seemed everyone is thinking 'abstraction' is just modularization or data-hiding. But IMHO, it also means the use of 'Abstract Classes' or 'Interfaces' which is a must for dependency-injection and thus testing. How non-OO code bases manage this? And also, other than abstraction, the encapsulation also helps a lot to manage large code bases as it define and restrict the relation between data and functions.

With C, it is very much possible to write pseudo-OO code. I don't know much about other non-OO languages. So, is it THE way to manage large C code bases?


问:
If you learned formal methods for software, how useful have you found it?
If you have been trained in the use of formal methods (FM) for programming:

How useful have you found it?

What did your FM training involve (e.g. a course, a book)?

What FM tools do you use?

What advantages in speed/quality has it given you compared to not using FM?

What kind of software do you create with FM?

And if you don't directly use FM now, was it at least worth learning??

I'm curious to hear as many experiences/opinions on FM as can be found in this community; I'm starting to read up on it and want to know more.

Background

Programming and software development/engineering are some of the newest human skills/professions on Earth, so not surprisingly, the field is immature — that shows in our field's main output, as code that is typically late and error-prone.  Industry immaturity is also shown by the wide margin (at least 10:1) in productivity between average and top coders.  Such dismal facts are well covered in the literature, and introduced by books like Steve McConnell's Code Complete.

The use of formal methods (FM) has been proposed by major figures in software/CS (e.g. the late E. Dijkstra) to address (one of) the root causes of errors: the lack of mathematical rigour in programming.  Dijkstra, for instance, advocated for students developing a program and its proof together.

FM seems to be much more prevalent in CS curricula in Europe compared to the US.  But in the past few years, new "lightweight" FM approaches and tools like Alloy have attracted some attention.  Still, FM is far from common usage in industry, and I'm hoping for some feedback here on why.

Update

As of now (10/14/2010), of the 6 answers below, no one has clearly argued for the usage of FM in "real world" work.  I'm really curious if someone can and will; or perhaps FM really does illustrate the divide between academia (FM is the future!) and industry (FM is mostly useless).

答:
I used to work in a department at ICL, before they were bought up by Fujitsu. They had some large government-type contracts that required proof that the software worked as advertised, so they built a machine that would take the formal specification written in Z and validate the code as it ran, with a big green or red light for pass/fail.

It was an amazing thing, but, as the esteemed @FishToaster points out, it was useless for anything non-trivial.


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

答:
Here's the basic issue: What happens if you have two tools that extend prototypes in incompatible ways, or which extend commonly-called methods in ways such that they yield different results (this is a particular issue for for...in in JavaScript), thus causing code that relies on their normal behavior to break?

Basically, it's the same issues that you have when you mis-use global variables. By itself, perhaps nothing bad happens. But, it opens you up for trouble when two ostensibly-separate pieces of code suddenly step on each other (and it's a pain to debug when that happens).

Certainly prototype.js is pretty well-known and most tools work around what it does. Similarly, I'm sure there are cases where extending base prototypes is the right thing to do. But, it's something to approach with caution.

OwnerDisplayName: lxe

OwnerDisplayName: Luke


答: Not sure if this is really still an issue anymore, but my experience with earlier versions of Internet Explorer is that sometimes it wasn't even possible to extend certain build-in types.</p>

Title: Why is extending the DOM/built-in object prototypes a bad idea?

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

OwnerDisplayName: Jan-Peter Vos


答:
There are two separate issues here. The first is the general extending of built-in prototypes, and the other is specifically extending DOM prototypes. The arguments against extending built-in prototypes:

Potential clashes: two pieces of code from different sources both defining the same property on the same prototype

Side-effects: extending Array.prototype or Object.prototype can have knock-on effects, such as adding the extension methods being enumerated in a for...in loop

As for extending DOM prototypes, the potential clash argument above still applies. Additionally, DOM nodes are host objects and as such are not subject to any of the normal rules of native JavaScript objects. They can essentially do what they like and are under no obligation to provide sensible prototype objects or even allow extra ("expando") properties. IE in particular exercises this right, providing no prototypes for DOM objects before IE 9 and having various weirdnesses about properties on various DOM objects (although you're generally OK assigning properties to elements, provided nothing's set document.expando to false.)

OwnerDisplayName: Tim Down


答: If you are asking about management of a large code-base, you are asking for how to keep your code base well structured on a relatively coarse level (libraries / modules / building of subsystems / using namespaces / having the right docs at the right places etc.). OO principles, especially 'abstract classes' or 'interfaces', are principles for keeping your code clean internally, on a very detailed level. Thus, the techniques for keeping a large code base manageable don't differ for OO or non OO-code.</p>


答:
Does Glassfish come as part of the Java EE platform?

No, Glassfish is an application server that fully implements all of the Java EE API and, thus, makes it fully Java EE compliant Application Server. This means that if you write a Java EE application, Glassfish will run it for you with ease (you will have to do minimal configuration, if not, none).

Can you get Glassfish but not Java EE?

Java EE is an API framework consistings of Java EE API's (JDBC, RMI, JPA, EJB, JMS, etc.). You can get Oracle Glassfish Server (that isn't JEE compliant). There are other JEE compliant Application Server on the market, such as JBoss Application Server, IBM Wesphere Application Server, etc.,


答:
I fully agree with you. A policy that every method must be commented is absolutely horrible, because it only leads to useless, massively duplicated and invariably often outdated or wrong comments that effectively decrease mantainability.

Unfortunately, it is extremely unlikely that as a new hire you can do anything to change this policy. Your best bet may be to discuss it with your colleagues. If they feel like you, you may have a chance to campaign together for the policy to be changed.


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

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

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

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

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

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

答:
Take a look to CL (Common Lips) Macros. In my opinion that is exactly what you want. Lips is perfect in metaprogramming.

Also I suggest Nemerle if you want to have .NET powers with perfect Metaprogramming support (including macros)

But if you want a true code-generation engine take a look on Apache thrift


问:
best practice when unit testing for embedded development
I am looking for some best practice strategies for unit testing code written for embedded system. By embedded system, I mean code such as device drivers, ISR handlers etc., stuff that are pretty close to the metal.

Most of the unit tests are not possible without testing it on the hardware with the aid of a ICE. Sometimes, the embedded unit also needs to be hooked up to other stimulus such as a mechanical switches, stepper motors and light bulbs. This usually occurs in a manual fashion, automation would be great but hard and expensive to achieve.

Update

I came across a C testing framework that seems to be quite successful in testing embedded projects. It uses the ideas of mocking hardware. Check out Unity, CMock, and possibly Ceedling.

Update 06Jul2016

Came across cmocka - seems to be more actively worked on.

答:
This is a very difficult problem.

I have actually designed a unit testing harness for an embedded system, which would allow simulating hardware events/interrupts, and control the timing of the execution (to ensure we cover all the possible interleavings due to the concurrency), and it took a team of programmers more than 2 years to actually implement it and put it to work. That project is a proprietary development, but a similar (simpler in design) project is available here.

So yes, automation would be great. Yes, it is very hard and expensive to achieve. Yes, sometimes you have to do that. Rarely though, in my experience in most cases its faster and cheaper to use the stepper motors and light bulbs and make it all work manually.


答:
In embedded developing you often do boundary scans to verify the whole application (including hardware) works. Also see JTAG for in system debugging.

Testing pure software routines without link to the hardware can be done by a standard C Unit Test framework like Check. But beware of memory limitations (especially stackspace etc. on small devices). Know your contracts! You can also try to abstract the software routines from the hardware to gain a bigger test-coverage but this is usually costly in terms of performance on embedded devices like small PICs or AVRs. However, you can mock hardware ports to achieve a bigger coverage (and of course you can test that mock, too).

You can also try to use emulators for the chip or circuit simluators, but these kind of tools are expensive (especially in combination) and complicated.

Title: best practice when unit testing for embedded development

Body:
I am looking for some best practice strategies for unit testing code written for embedded system. By embedded system, I mean code such as device drivers, ISR handlers etc., stuff that are pretty close to the metal.

Most of the unit tests are not possible without testing it on the hardware with the aid of a ICE. Sometimes, the embedded unit also needs to be hooked up to other stimulus such as a mechanical switches, stepper motors and light bulbs. This usually occurs in a manual fashion, automation would be great but hard and expensive to achieve.

Update

I came across a C testing framework that seems to be quite successful in testing embedded projects. It uses the ideas of mocking hardware. Check out Unity, CMock, and possibly Ceedling.

Update 06Jul2016

Came across cmocka - seems to be more actively worked on.


答:
I suggest you to read this article which I think explains pretty well why extending objects is a bad idea, with regard to Prototype also.

In summary:

Lack of specification

Exposure of "prototype objects" is not part of any specification.
[...] In order for implementation to conform to DOM Level 2 fully,
there's no need to expose those global Node, Element, HTMLElement,
etc. objects.

Host objects have no rules

DOM objects are host objects [...] Host objects may implement these
internal methods with any implementation-dependent behaviour, or it
may be that a host object implements only some internal methods and
not others.

[...] Internal methods behavior is implementation-dependent. [...] By
definition, you are working with something that's allowed to behave in
unpredictable and completely erratic way.

Chance of collisions

Given huge amount of environments in use today, it becomes impossible
to tell if certain property is not already part of some DOM. [...]

Every named form control shadows properties inherited through
prototype chain. The chance of collisions and unexpected errors on
form elements is even higher.

Employing some kind of prefixing strategy can alleviate the problem.
But will probably also bring extra noise.

Performance overhead

[...] browsers that don’t support element extensions—like IE 6, 7,
Safari 2.x, etc.—require manual object extension. The problem is that
manual extension is slow, inconvenient and doesn’t scale.

[...] once you start extending elements, library API most likely needs
to return extended elements everywhere. As a result, querying methods
like $$ could end up extending every single element in a query.

IE DOM is a mess

As shown in previous section, manual DOM extension is a mess. But
manual DOM extension in IE is even worse [...]

Bonus: browser bugs


答:
I would abstract away from the hardware dependencies at the earliest possible step, and build the system on software emulation/test harnesses, enabling all sorts of test frameworks. Often my developement PC was used to test as much as 95% or more of the complete system. The cost of the extra overhead (another layer of abstraction) was easily won back by the cleaner code generated as a result of that abstraction.

The testing of the truely baremetal parts of an embedded system is usually a seperate application (Unit test?) that hammers the firmware well beyond what the applications can even hope to achieve. Automation can be done - at a cost, but is not typical.

Unless, that is, you have the budget to build a unit test hardware harness including full ICE. This is absolutly fine as generally the functional tests are small.


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

答:
Give them more than just the software somehow. Free downloadable content for paid users and free upgrades and patches, training videos, cheap upgrades or free upgrades to the latest versions. You can also donate a bit of your profits to a charity, so the users have a feeling of giving something back when they buy your software.

If there are online features only make them accessible to paying users. Copy protection is a waste of time. Nowadays it's all about content and service, and not just giving someone a static exe and expecting to make free money after your costs are covered.


问:
Wrapping my mind around prefix notation?
I'm reading about LISP.

I understand how prefix notation works at a certain level, but I was wondering if there are any tricks to making it intuitive.

答:
When (eventually) "Everything is a function call" (or a special form, or a macro-expansion, both having the surface syntax of "function call") clicked, it felt pretty natural.

So, for (= 1 2) I read that as 'call the numeric equals comparison on 1 and 2'.


问:
Identify Service Oriented Architecture
How can I tell if a system is built upon a service oriented architecture when reading its source code?</p>

答:
SOA is an architecture style, and so, the intend is more important than the code. Who says, the code you think is SOA-Style does not get refactored the next iteration? Generally, i would expect, it's easier just to ask the architect.

That said, ideally (i.e., when intend and source match), the following apply:

The Source Code of the whole Project is split into very independend units that can be deployed 'standalone', i.e, without the rest beeing deployed. These are the services.

Such a service would have an Interface to the external world, as a means of communication with other services. For Examle, a Date Service could answer under the url http://example.com/current_date something like {"year": 2011, "month": 8, "day": 29}.

Except for it's interface, a service is a 'black box' to the other services. All communication is done over these interfaces. In particular, there is no shared database.

When designed as SOA from the start, one would expect the same technology to be used for most of the interfaces. 'SOAP' and 'RPC over HTTP/JSON' would be examples for such technologies.

(EDIT: cleaned the answer a little)

Title: Identify Service Oriented Architecture


答:
Embedded CPU simulators can generally be programmed to also simulate hardware.  All the virtualization technologies other than Xen do that.  But you need to write code that pretends to have some registers at some physical address or, on x86, an address on the I/O bus, and then you need to respond to reads and writes to these addresses as if your software was a physical chip whose control and status registers were being accessed.

If you want to do this, I would suggest modifying QEMU.  But it would not be easy.  This sort of thing is generally only done when you are designing a custom chip with a microcontroller and some other cores for your I/O.

The development system sold by ARM Holdings provides for this and is likely easier to work with than hacking on QEMU, but is very expensive.

There are several Open Source ARM emulators that run a single subroutine, which itself can call other subroutines, that you can use for debugging tuning the performance of subroutines that don't depend on hardware access.  I used one of these to great success to optimize an AES encryptor for ARM7TDMI.

You could write a simple unit test harness in C or C++, link the class or subroutine under test to it, then run it in the simulator.

I've been pondering a similar problem for years, how to unit test Linux or Mac OS X kernel code.  It should be possible, but I've never actually tried.  One possibly is to build a full kernel rather than testing your code in isolation, with the unit test framework linked directly into your kernel.  You would then fire off the unit tests from some kind of external interface.

Maybe it would be more productive to use a code coverage tool, then test your firmware as a complete package through its external interface.  The coverage tool would find code paths that were not yet tested, so you could then add additional external tests in an attempt to get more coverage.