答:
So there's my second question "What's the best way to design REST service code to support prior versions."

A very carefully designed, and orthogonal API will probably never need to be changed in backward incompatible ways, so really the best way is not to have future versions.

Of course, you probably won't really get that the first try; So:

Version your API, just as you are planning (and it's the API that is versioned, not individual methods within), and make lots of noise about it.  Make sure that your partners know that the API can change, and that their applications should check to see if they are using the latest version; and advise users to upgrade when a newer one is available.  Supporting two old versions is tough, supporting five is untenable.

Resist the urge to update the API version with every "release".  The new features can usually be rolled into the current version without breaking existing clients; they're new features.  The last thing you want is for clients to ignore the version number, since it's mostly backwards compatible anyway.  Only update the API version when you absolutely cannot move forward without breaking the existing API.

When the time comes to create a new version, the very first client should be the backwards-compatible implementation of the previous version.  The "maintenance API" should itself be implemented on the current API.  This way you aren't on the hook for mantaining several full implementations; only the current version, and several "shells" for the old versions.  Running a regression test for the now deprecated API against the backwards comaptible client is a good way to test out both the new API and the compatibility layer.

Title: What is a recommended pattern for REST endpoints planning for foresighted changes

Body:
Trying to design an API for external applications with foresight for change isn't easy, but a little thought up front can make life easier later on. I'm trying to establish a scheme that will support future changes while remaining backward compatible by leaving prior version handlers in place.

The primary concern on this article is to what pattern should be followed for all defined endpoints for a given product/company.

Base Scheme

Given a base URL template of https://rest.product.com/ I have devised that all services reside under /api along with /auth and other non-rest based endpoints such as /doc. Therefore I can establish the base endpoints as follows:

```<code>https://rest.product.com/api/...
https://rest.product.com/auth/login
https://rest.product.com/auth/logout
https://rest.product.com/doc/...
</code>```

Service Endpoints

Now for the endpoints themselves. Concern about POST,GET,DELETE is not the primary objective of this article and is the concern on those actions themselves.

Endpoints can be broken down into namespaces and actions. Each action must also present itself in a way to support fundamental changes in return type or required parameters.

Taking a hypothetical chat service where registered users can send messages we may have the following endpoints:

```<code>https://rest.product.com/api/messages/list/{user}
https://rest.product.com/api/messages/send
</code>```

Now to add version support for future API changes which may be breaking. We could either add the version signature after /api/ or after /messages/. Given the send endpoint we could then have the following for v1.

```<code>https://rest.product.com/api/v1/messages/send
https://rest.product.com/api/messages/v1/send
</code>```

So my first question is, what is a recommended place for the version identifier?

Managing Controller Code

So now we have established we need to support prior versions we need to thus somehow handle code for each of the new versions which may deprecate over time. Assuming we are writing endpoints in Java we could manage this through packages.

```<code>package com.product.messages.v1;
public interface MessageController {
    void send();
    Message[] list();
}
</code>```

This has the advantage that all code has been separated through namespaces where any breaking change would mean that a new copy of the service endpoints. The detriment of this is that all code needs to be copied and bug fixes wished to be applied to new and prior versions needs to be applied/tested for each copy.

Another approach is to create handlers for each endpoint.

```<code>package com.product.messages;
public class MessageServiceImpl {
    public void send(String version) {
        getMessageSender(version).send();
    }
    // Assume we have a List of senders in order of newest to oldest.
    private MessageSender getMessageSender(String version) {
        for (MessageSender s : senders) {
            if (s.supportsVersion(version)) {
                return s;
            }
        }
    }
}
</code>```

This now isolates versioning to each endpoint itself and makes bug fixes back port compatible by in most cases only needing to be applied once, but it does mean that we need to do a fair bit more work to each individual endpoint to support this.

So there's my second question "What's the best way to design REST service code to support prior versions."


问:
How is software scalability measured?
I was asked to make some small technical presentation about specific application scalability. The application is developed using Java, Spring MVC, Hibernate. I have access to the application source code.

How can I measure software scalability (using sources) and what metrics do I need to look after when measuring software scalability?

答:
Scalability is not really a quantifiable property for real applications.

In practical terms, scalability is about being able to support workloads that are increasing in various dimensions.

To start with the application will support the increasing workloads with existing hardware resources.  But there are various points where you hit limits; e.g. the amount of memory, the number of cores, contention on data structures, database throughput, and so on.  Each time you hit one of these limits, you have to take a different approach to supporting increasing workloads.  Scalability is about how long you can keep increasing the workload before you hit an insurmountable limit, or you need to undertake a major redesign.

ContentLicense: CC BY-SA 3.0

Title: How is software scalability measured?

ContentLicense: CC BY-SA 2.5


问:
What are effective ways to introduce the concept of code kata into the workplace?
In your experiences, what are some effective ways to introduce code kata practice into an organization or company?

To be clear, I'm not concerned with the usefulness of code kata. I'm interested in methods to introduce this concept to a development team.

答:
How you introduce code katas into your workplace depends very much on what you want to get out of them.

In my case I wanted to encourage the use of Test Driven Development so I ran a Cyber-Dojo. With this sort of exercise, the emphasis is not on the code itself, but on the process of writing the code.

We spent an afternoon, in pairs, repeating the same kata, but under different conditions. We started with all groups doing one exercise at the same time. This provided a baseline.

We then discussed some of the basic principles of TDD, had everyone change partners and repeat the same kata. We repeated the same kata to de-emphasise the generation of code and instead concentrate people on the process of naming test cases and the Red/Green cycle.

Then we repeated the kata again, but roughly every 10 minutes one person in each group would move to another group, simulating the rather fluid team environments we often find ourselves in these days.

In the final iteration, we had both partners change every 10 minutes or so into different groups.  This helped to demonstrate that with TDD, even the handover from one team to a completely different one needn't necessarily be too painful, since the project should only every be one Red/Green cycle from working.

The interesting thing was, there were few people who had done any TDD before the session, but what TDD knowledge there was rapidly spread until by the final iteration through the kata, most people were thinking in a TDD way or could at least appreciate why it might be beneficial.

People generally said that the afternoon was both fun and informative and we are now looking at other ways to use Cyber-Dojo at my workplace.

Cyber-Dojo, written by Jon Jagger is works incredibly well for this sort of exercise. It is a web based integrated environment for doing deliberate practice of TDD and learning about team dynamics. It has lots of kata's selected specifically to help people concentrate on the process of TDD and not the problem. It also supports a range of languages, from Python and Ruby to Java and C++.

The best thing is, after doing a kata you can then go back and look at the red/green progression (or maybe not *8') of each of the groups participating. It's traffic lights are a great way to visualise how the TDD process works.

If you want your own CyberDojo server, the whole project can be found at github and there is even a Turnkey Linux appliance virtual machine linked from there, which means that assuming you already have VMware player or VirtualBox installed, you can be up and running within a few minutes of downloading the appliance!


问:
What are the main bottlenecks to know about Java portability?
Java is known to be portable; "compile once, run anywhere".  I know this is often true because I have many times deployed jar or war without any cross-platform troubles.  Still, I am left wondering if this is always true.

For example, Swing applications look different between different OS platforms. Also, JDK-1.7 is still a preview release for Mac OS X.

So, what are the common problems that prove that Java applications are not entirely cross platform?

答:
Swing is platform-dependent to a certain extent.  In addition to the widget themes being different, as you noted, we've had Swing-based applications where the layout is different from platform to platform.  There was also another group I worked in that had some widgets not even show up on certain platforms.

I'm not sure how big a problem this is though, because I'm not sure how much Swing is used anymore.  Eclipse's SWT seems to be a lot more platform-independent, so it seems that Java + GUI doesn't necessarily imply non-portability.

Also, any Java code that uses the operating system or makes assumptions about the underlying platform will naturally be less portable, for reasons including (but not limited to):

case (in)sensitivity of the filesystem

newline characters

threads/processes

(Many of these can be easily handled by Java APIs -- System.getProperty("line.separator");).

As a counterpart to the saying you mentioned, some of the more experienced programmers in my group say that Java is "write once, test everywhere".


问:
Is JavaScript interpreted by design?
I am cautious of asking this question because it might appear overly fastidious. I just opened up JavaScript: The Definitive Guide, and it states of the first page of chapter 1

"JavaScript is a high-level, dynamic, untyped interpreted programming
  language”

So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

There are no static compilers for JavaScript apparently -
https://stackoverflow.com/questions/1118138/is-there-a-native-machine-code-compiler-for-javascript so maybe it's just a reflection of this.

答:
The V8 JavaScript VM used in Chrome doesn't include an interpreter. Instead it consists of two compilers and compiles the code on the fly. One of the compilers runs quickly but generates inefficient code, the other is an optimizing compiler.

I can understand why some people would consider this "cheating", since V8 takes source code as input every time the code runs and the user has to have V8 installed. But consider a compiler which emits an executable which includes a complete interpreter and bytecode. Then you would have a stand-alone program. It just wouldn't be very efficient.

Title: Is JavaScript interpreted by design?


问:
Is Flash really superior to Java applets?
I'm still a student, without much real life experience in programming. I've never written anything bigger than ~5k lines of code. I've written code in both Flash and Java, and I just can't understand why people are writing web applications like video players (YouTube etc.) in Flash, and not as Java applets. So I want to ask you, programmers with hands on experience, for some wise words on the subject.

I see no real benefit of Flash over applets, while on the other hand, at least to me, it seems buggy as hell. I understand it is faster to make something in Flash, and I can see why it would be a good thing for fast prototyping, but in general, is it worth it? Every time a YouTube goes berserk, i curse the developers for writing it in Flash. And if you are using Linux with Opera, this happens all the time.

So, basically, why are people using flash, and not applets?

答:
simple answer is.. flash is for designers. and java is for programmers
it doesn't get any easier than this..
not one better than the other.. they're just different tools for different jobs..
so to assume flash or java being superior to one another.. is just a bias.. they're just different tools both get the job done in different contexts..
as for the downvote.. i don't see your point.. it is relevant to say such things.. and not let bias get in the way..

you left a downvote ?
how about telling us all why in a constructive manner? :)


问:
Senior Engineers: Go Back to Coding?
This is a question regarding engineers with 20+ years experience, but it is a question for everybody, as it has to do with career development.

I'm in a surprisingly long job hunt, and the problem seems to be that employers will not accept me as a coder.  Yes, I have done lots of things, had my own company, sold it too early, etc.  But the world always needs productive workers, and my skills are current and sharp.  The market I am in has fewer openings for senior people, and I don't mind taking a step or two back if I can find a place to contribute. What are your thoughts about career management that prepares the 40, 50 year-old for a sudden career disruption?

答: I would be careful how much non-programming content you put on your resume and try to limit it as much as you can to being relevant to software development.</p>

Title: Senior Engineers: Go Back to Coding?


答: I like a football analogy here.  You're like a seasoned lineman in the NFL.  You're really good at your job, but you cost a lot.  The team believes that they can get enough productivity out of someone younger for less money and the performance will be good enough.  You're basically priced high for the market with a lot of experience.  The jobs become a little harder to find, but there is someone who will pay you.</p>

Title: Senior Engineers: Go Back to Coding?

Body:
This is a question regarding engineers with 20+ years experience, but it is a question for everybody, as it has to do with career development.

I'm in a surprisingly long job hunt, and the problem seems to be that employers will not accept me as a coder.  Yes, I have done lots of things, had my own company, sold it too early, etc.  But the world always needs productive workers, and my skills are current and sharp.  The market I am in has fewer openings for senior people, and I don't mind taking a step or two back if I can find a place to contribute. What are your thoughts about career management that prepares the 40, 50 year-old for a sudden career disruption?


问:
Drawbacks of code kata
Code kata is a concept that proposes to hone programmer's skill by doing small problems many times trying to improve the code at each iteration.  The name comes from an analogy to martial art kata where forms (aka kata) are practices done over and over leading to improvements.  </p>

<p>From the reaction I got to my last question on the topic, I wish to know what are the draw backs of this approach? </p>

答:
I agree that the metaphor "kata" may not be the best.  A kata in karate is performed for the purpose of practicing a specific, discrete movement until it can be performed flawlessly, crisply, and automatically.  This does not translate well to an activity where critical thinking and creativity are required.  (It would translate better to, say, typing).

That said, the failing of the name is not a failing of the activity.  What possible drawback could there be to practicing something at which someone wants to get better?  I suppose one could say that the time spent doing it is a drawback, from an opportunity cost perspective, but really, it's an investment.  So, the time spent practicing the craft of software development is to software developers as the money spent on equities or bonds is to a long term saver/investor.  It's not a 'drawback' -- it's table stakes.

Title: Drawbacks of code kata


问:
How to measure external quality of software
For my thesis, I am doing research into the characteristics of Behavior Driven Development (BDD). One of the BDD claims is that by specifying the requirements in a ubiquitous language together with the customer, the software will score better on the external quality. Another claim of BDD is that it produces clean code with a high code coverage.

In my experiment, I will perform a software project both in BDD and traditional style, so that in the end I have two end products. The second claim of BDD is easy verifiable, by checking the code against some quality metrics, like Lines of Code, Cyclomatic Complexity and Code Coverage. However, I cannot think of a good measurement for the first claim. Is there anybody out here who has done this already? Or maybe can propose an alternative experiment that can validate this claim?

答: I wanted to tell you that all the common metrics like McCabe Complexity don't give helpful results when normalized for lines-of-code.  I couldn't find the paper demonstrating that, so take it as a rumor.  I did find a doctoral thesis roughly the same topic, but using TDD. Perhaps what that guy writes about code quality can help.</p>


问:
Syntax tree dump format
When writing a compiler, it is useful to include the ability to dump the abstract syntax tree in a human readable format, for debugging purposes. This output might also be useful for other tools like IDEs and code analyzers, so I might as well provide it as a documented feature.

Given that, what format would be the most useful? It doesn't make much difference to me as long as I can eyeball it, so I might as well provide e.g. whatever other tools would find easiest to read.

答:
There are lots of viewers for the DOT file format. It is fairly simple to output ( plain text ) and produces ( depending on the viewer ) adequate to very nicely formatted output.

I believe DOT is what ANTLRWorks uses for its AST visualization.

I don't know what "tools" you are referring to reading the output, but something hierarchical like Xml Orientend Gcc AST ANalyzer or some equivalent JSON output would probably work as a generic input format to some visualization tool you might create.

Title: Syntax tree dump format


答:
You get better by trying things that are difficult and just out of reach of your abilities; challenging yourself.  Doing the same "code kata" over and over, like a martial arts form, doesn't do that.  I think it stagnates your abilities instead of helping to push your skills forward.

It has its use as a method of practice the first time, but it is limited.  I tell people to use project Euler instead.  More problems and more challenging.

Title: Drawbacks of code kata

Body:
Code kata is a concept that proposes to hone programmer's skill by doing small problems many times trying to improve the code at each iteration.  The name comes from an analogy to martial art kata where forms (aka kata) are practices done over and over leading to improvements.  </p>

<p>From the reaction I got to my last question on the topic, I wish to know what are the draw backs of this approach? </p>


问:
Is it a bad practice to use inline styling with generated code?
If I'm using a technology like Grails. It's really easy to wind up with inline styling.

Are there any downsides to auto-generating code with inline styling? Is this considered bad practice? Why?

答:
Yes, inline styling is considered very poor practice.
You have no centralized location for your styles, which is why (ideally) you want to link to an external style sheet.
With an external style sheet, you make a few simple edits and your changes are reflected site-wide.
With inline styles, you have to go hunting for those styles and make your edits.</p>

OwnerDisplayName: OrganizedFellow


问:
Pronunciation in programming?
How do you correctly or erroneously pronounce programming terms?  Any that you find need strict correction or history into the early CS culture?

Programming

char = "tchar" not care?

! = bang not exclamation?

# = pound not hash? Exception #! = shebang

* = splat not star?

regex = "rej ex" not "regg ex"?

sql = "s q l" not "sequel" (already answered, just i.e.)

Unixen

| = pipe not vertical bar?

bin = bin as in pin , not as in binary?

lib = lib as in library , not as in liberate?

etc = "ett see" , not "e t c" (as in /etc and not "&c")

Annoyance

/ = slash not backslash

LaTeX = "laytek" not "lay teks"

答:
To summarize my own (North American) experience:

char may be pronounced both ways: like "char" in "charcoal", or close to "care"; never like "car"

! is an "exclamation point"

# is a "pound sign" (probably an Americanism)

* is an "asterisk" (never in 15 years heard anyone call it "splat")

RegEx with a hard "g" because it's regular, not rejular.

SQL: heard both "ess-queue-ell" and "sequel"; but (Microsoft's) SQL Server is much more often pronounced "sequel server".

bin is like a recycle bin; not "bine"

LaTeX's ancestor is TeX.  The "tech" pronunciation goes all the way back to TeX's creator Donald Knuth.  Actually the X was supposed to sound more like the German "ch" in Bach.  "La-tech" is the only way LaTeX is pronounced in the US research community; if you pronounce it like a sort of rubber, you give away that you don't belong to it.

Title: Pronunciation in programming?


答:
Kata means the exact opposite of what you should be striving for.

an exercise consisting of a sequence of the specific movements of a martial art, used in training and designed to show skill in technique

The term Kata ( Origin:
1950–55;  < Japanese:  shape, pattern ) as used in martial arts, and your question are about rote memorization of muscle memory like touch typing .

In the original Karate Kid, waxing the cars, sanding the floors, painting the fence these were all Katas that were taught, completely out of context and in this case without explanation just to provide muscle memory. It wasn't until a sensei came in and gave these hollow activities context that they meant anything.

I think the same thing applies here, without a mentor to put things in context re-doing problem solving wrong in multiple languages is no better than a single one. Without the mentor to tell you where to improve they are a waste of time.

It is the exact opposite of creatively solving problems by learning new variations of idioms and semantics of a language or platform.

If you want to be able to type System.out.println() as effortlessly as possible, then practicing that would be a Kata.

If you want to improve a solution to a problem in a different implementation, to reduce time and/or space requirements or apply more idiomatic principles, that isn not something that Kata will help you with.

There is already an accepted industry term for re-implementing the same thing over and over after it already works striving for small incremental improvements and questionable benefits of perfection, it is called Gold Plating!

The terms they should have used are Refactoring when applied to the same language/runtime/platform. And Porting when moving a working program to a different language/runtime/platform. Kata was probably erronously chosen because it sounds hipster, cool and mystical without completely understanding the semantics.

Solving different difficult problems with little planning, experience or guidance is what most developers, especially junior developers have to do every day.

Only academics get to do the same exercise over and over just for the sake of honing a specific solution. The skill in having a successful career as a developer is in adaptation, not repetition.

Who says that there aren't smart people that don't need to study after work, and can learn everything the need to know and sometimes more in their 8 hours at work?

Title: Drawbacks of code kata


答:
So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

EcmaScript language geeks often use the term "ES interpreter" to refer to an implementation of EcmaScript, but the spec does not use that term.  The language overview in particular describes the language in interpreter-agnostic terms:

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.

So EcmaScript assumes a "host environment" which is defined as a provider of object definitions including all those that allow I/O or any other links to the outside world, but does not require an interpreter.

The semantics of statements and expressions in the language are defined in terms of completion specification which are trivially implemented in an interpreter, but the specification does not require that.

8.9 The Completion Specification Type

The Completion type is used to explain the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control. Values of the Completion type are triples of the form (type, value, target), where type is one of normal, break, continue, return, or throw, value is any ECMAScript language value or empty, and target is any ECMAScript identifier or empty.

The term “abrupt completion” refers to any completion with a type other than normal.

The non-local transfers of control can be converted to arrays of instructions with jumps allowing for native or byte-code compilation.

"EcmaScript Engine" might be a better way to express the same idea.

There are no static compilers for JavaScript apparently

This is not true.  The V8 "interpreter" compiles to native code internally, Rhino optionally compiles to Java bytecode internally, and various Mozilla interpreters ({Trace,Spider,Jager}Monkey) use a JIT compiler.

V8:

V8 increases performance by compiling JavaScript to native machine code before executing it, versus executing bytecode or interpreting it.

Rhino:

```<code>public final void setOptimizationLevel(int optimizationLevel)
</code>```

Set the current optimization level.
  The optimization level is expected to be an integer between -1 and 9. Any negative values will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An optimization level of -1 indicates that interpretive mode will always be used. Levels 0 through 9 indicate that class files may be generated. Higher optimization levels trade off compile time performance for runtime performance. The optimizer level can't be set greater than -1 if the optimizer package doesn't exist at run time.

TraceMonkey:

TraceMonkey adds native‐code compilation to Mozilla’s JavaScript® engine (known as “SpiderMonkey”). It is based on a technique developed at UC Irvine called “trace trees”, and building on code and ideas shared with the Tamarin Tracing project. The net result is a massive speed increase both in the browser chrome and Web‐page content.

Title: Is JavaScript interpreted by design?

Body:
I am cautious of asking this question because it might appear overly fastidious. I just opened up JavaScript: The Definitive Guide, and it states of the first page of chapter 1

"JavaScript is a high-level, dynamic, untyped interpreted programming
  language”

So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

There are no static compilers for JavaScript apparently -
https://stackoverflow.com/questions/1118138/is-there-a-native-machine-code-compiler-for-javascript so maybe it's just a reflection of this.

Body:
So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

EcmaScript language geeks often use the term "ES interpreter" to refer to an implementation of EcmaScript, but the spec does not use that term.  The language overview in particular describes the language in interpreter-agnostic terms:

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.

So EcmaScript assumes a "host environment" which is defined as a provider of object definitions including all those that allow I/O or any other links to the outside world, but does not require an interpreter.

The semantics of statements and expressions in the language are defined in terms of completion specification which are trivially implemented in an interpreter, but the specification does not require that.

8.9 The Completion Specification Type

The Completion type is used to explain the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control. Values of the Completion type are triples of the form (type, value, target), where type is one of normal, break, continue, return, or throw, value is any ECMAScript language value or empty, and target is any ECMAScript identifier or empty.

The term “abrupt completion” refers to any completion with a type other than normal.

The non-local transfers of control can be converted to arrays of instructions with jumps allowing for native or byte-code compilation.

"EcmaScript Engine" might be a better way to express the same idea.

There are no static compilers for JavaScript apparently

This is not true.  The V8 "interpreter" compiles to native code internally, Rhino optionally compiles to Java bytecode internally, and various Mozilla interpreters ({Trace,Spider,Jager}Monkey) use a JIT compiler.

V8:

V8 increases performance by compiling JavaScript to native machine code before executing it, versus executing bytecode or interpreting it.

Rhino:

public final void setOptimizationLevel(int optimizationLevel)

Set the current optimization level.
  The optimization level is expected to be an integer between -1 and 9. Any negative values will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An optimization level of -1 indicates that interpretive mode will always be used. Levels 0 through 9 indicate that class files may be generated. Higher optimization levels trade off compile time performance for runtime performance. The optimizer level can't be set greater than -1 if the optimizer package doesn't exist at run time.

TraceMonkey:

TraceMonkey adds native‐code compilation to Mozilla’s JavaScript® engine (known as “SpiderMonkey”). It is based on a technique developed at UC Irvine called “trace trees”, and building on code and ideas shared with the Tamarin Tracing project. The net result is a massive speed increase both in the browser chrome and Web‐page content.


答:
Downsides, to my eye:

You may impair the integrity of visual design. If you reuse styles from a carefully crafted CSS, your design has better chances to look consistent.

Changing the visual design becomes harder because styling information is scattered in code.

Your page gets bigger. This may play a role if you e.g. style each item in a long list.

There a are times when you can't escape inlining style info: it's sending HTML-formatted emails.

Title: Is it a bad practice to use inline styling with generated code?

Body:
If I'm using a technology like Grails. It's really easy to wind up with inline styling.

Are there any downsides to auto-generating code with inline styling? Is this considered bad practice? Why?


答:
In a word, consulting.

If you've got domain specific knowledge and can walk in, solve difficult problems or implement the exact solution they need, you can charge them an arm and a leg for the amount of time you spend on it. They'd take months to tackle it cold anyway.

But getting hired as a consultant is usually a matter of who knows you, which is why all the consultants are either a) people who have been in the industry for decades, b) people who are working for the consulting agency that has been servicing the industry for decades, or c) someone's son-in-law.

Downsides are that there could be a lot more travel, sometimes there's resentment from the locals, and you're always in that initial first-impression schmoozing phase. Consultants can be like nomadic gypsies looking for the next sweet spot. This could be in terms of industry, technical skill-set, or physical location. Life on the road can be tough. (And I know a guy who flies from Iowa to Florida every other weekend, it's one hell of a commute).  You get to see a lot of code shops, and I've heard that they're not always happy to have other people coming in to do their job. Other times you are their savior coming down with divine solutions and banishing the beasts that plague them. Rarely do you settle down in one company long enough to be comfortable, and even if you've been there for years, you can still be "just" the contractor.

Title: Senior Engineers: Go Back to Coding?


答:
There are two main reasons why this auto-generated inline styling is bad:

Inline CSS styling overwrites by default the rules defined in a stylesheet. This means that you'll have a hard time to style the content according to your requirements through the stylesheet itself, and it would require to constantly switch from stylesheet to the tool which let you customize the auto-generated code.

Auto-generated code is [mostly] always stupid. And by stupid, I mean... totally, horribly stupid. If you have three buttons on a web page and you change the text color of those buttons, instead of writing one line of code, the auto-gen tool will write three lines. More buttons → more lines → more nightmare and performance issues.

Moreover, auto-generated code is mostly limited to what it is capable of doing. In CSS, I know how to create a shadow or a gradient which will work in Chrome, Firefox and other normal browsers. I also know it will not work in Internet Explhorror. If you use auto-generated code, in most cases (today there are a few exceptions), either it will not even let you create a shadow or a gradient, or it will do it, but will not tell you that it works only in some browsers¹.

Finally, consider a following scenario. You've created a website which uses auto-generated code to change the color of the buttons to gray. There are around 30 pages with an average of 5 buttons per page. Two days before the release, you're asked to switch the color from gray to teal:

If you've used a stylesheet from the beginning, you would spend ten seconds finding the line which specifies the color, and changing it.

If you use auto-gen code, you have to go and change all those colors for all 150 buttons, by hand. Or you can try to develop a reliable solution which will walk through all your source files and change the color. Can you do it in ten seconds?

¹ Of course, this is not an issue if you're knowledgeable about CSS and you know exactly what you're doing.


答:
I believe without some form of Kata you'll never be a great coder.  Kata is practice, that's literally what it means.  Take this as an example: An athlete says "I'll just show up and run the 100 meter dash, screw practice".  Does that sound like a winning strategy?  Is it ever done this way?

I suggest people Read Uncle Bob's "The Clean Coder", he goes in depth on this (and other) topics of professionalism in the field of programming.

Oh and arguments put forth that you can't do Kata and raise a family are simply excuses.  Speaking from experience: kids go to sleep at some point...

Title: Drawbacks of code kata


问:
How long can I store the subscribe personal information?
In my subscription form I want to use a double opt-in method:

First, the visitor subscribes

Then a confirmation email is dispatched. If he replies...

Then I add him to the system.

In the case where the user does not reply, how long can I store their email address? Are there any legal requirements with regard to that?

I am from U.S. and I am  also interested in the policy in European countries.

答: There's no official policy or so as far as I know. It entirely depends on how long the developer wants to store it in the database.</p>


问:
How to Mentor a Junior Developer
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).

答:
Whenever I am asked a question that I know can be resolved by a quick Google search, I will find documentation or a relative article and relay that to the person asking the question.

Knowing where to look things up is an important skill, and it is sometimes more difficult than you'd think for a new developer.  They may not even know what they are looking for, and this is where you need to help them.

Once in their hand, articles and documentation will force them to read about the solution instead of clawing at other developers for a quick answer.

This will accomplish the following:

Taking some of the burden off of seasoned developers.

Forcing the new developer to learn.

Happiness for all.

Sometimes you just have to give them some tough love, especially if they don't seem as if they want to learn.  Don't give them the answer, but make sure you point them in the right direction.

Title: How to Mentor a Junior Developer


答:
However for easier conversion, you can send the subscriber a reminder as follows:

a) 15 days - thanking them for subscribing to your services, and letting them know that there is only one more step to go to activate their account

b) 45 days - Letting them know that they are missing out on the goodies on your site or news letter

c) 75 days - letting them know a while ago they signed up and you would like them to complete activation

After 90 days delete their information, because they are not going to come back anyway. I remember Google and Microsoft would only hold data for 3 months before deleting it, but I am not yet sure anymore what the number is.

Title: How long can I store the subscribe personal information?

Body:
In my subscription form I want to use a double opt-in method:

First, the visitor subscribes

Then a confirmation email is dispatched. If he replies...

Then I add him to the system.

In the case where the user does not reply, how long can I store their email address? Are there any legal requirements with regard to that?

I am from U.S. and I am  also interested in the policy in European countries.


答:
Programming is an art--like painting or music.  When someone becomes a musician or artist for money you can tell, there is no inspiration, the performance is not really worth your time.  If you are into the art, nothing can stop you from practicing and constantly refining it--every day refining a single technique, noticing the nuances that most people will never see.

There is always room for people happy being bar musicians and house painters, but they are a completely different class of talent.  I suppose that most house painters would laugh at the idea of practicing, but I bet a painter that did research and practiced techniques--essentially recognizing their job as an art would do a noticeably better job, even on something as mundane as painting your house.

Some people will recognize the value of practice some wont. That alone should be of value if you are in the position to evaluate and you are looking for people who can make art (lean, simple, understandable code) and not just a solution.

ps.  I'm not calling myself awesomely artistic or anything--I don't do Kata on abstract problems but I recognize the value and I do try to refactor my production code quite a bit.

Title: Drawbacks of code kata


问:
Need advice for approach for a web-based app that loads excel worksheet but exposes only the charts
I'm looking for suggestions on the Visual Studio approach to take for a web application that is in the conceptual stage.

My environment has a lot of tools:

Windows Server 2008 R2 Standard 64bit

Visual Studio 2010 Professional Edition

Sharepoint 2010 Server Enterprise Edition

SQL Server 2008 R2

Office 2010 Professional

I know I will need this app to retrieve data from a database (or a web service - not sure exactly at this point). The data needs to be placed in an Excel workbook dynamically. The app will need to have a nice user interface (standard web controls - perhaps with some Javascript effects). The Excel ribbon and worksheet grid will need to be hidden. Some web control(s) will cause the Excel chart(s) to be rendered.

I am thinking this sounds like Visual Studio Tools for Office (VSTO) so as to leverage .Net and hide Excel.

Can you offer suggestions regarding:
One ASP.Net Web App Project
One Class Library Project for Excel
or perhaps which one of the several different Excel 2010 project types (addin, template, document)

Would Excel Services for Sharepoint be useful (or required) ?

I am feeling a little overwhelmed with so many choices at this early stage of conceptualizing the app. Can you suggest some ideas for this sort of thing? Also, I am a bit more experienced with C# but I've read VB.Net is better for work with the Excel object model.

What are general advises with regard to tool choice and overall approach tradeoffs?

答:
If you need to only show charts to the user, you can generate those on the fly and display them as a part of the web page. Look into ASP.Net chart controls. There are some other commercial chart components. If the information is relatively static, you can pre-build charts and refresh them as needed. You can accomplish everything from one ASP.Net web project. You can also create a class library to generate charts if you plan to use charts somewhere else.

If my answer does not help, please clarify your scenario. Do you need to use all the tools? Do you have to make charts available in SharePoint? Do your users have to have the Excel documents as backup source to validate data (you can still do that from ASP.Net app though)? If you could elaborate more on your end product, that would help.


答:
To me, the main drawback of the technique as I see it is its sub-optimal use of your time.

The learning value of this exercise is also questionable: when you do something over an over to get better at it, expert feedback is essential. Without high-quality feedback you will learn something too, but there is a chance of learning a wrong thing very well.

Don't get me wrong, practicing remains the only way of becoming good at programming, and kata is most definitely a form of practice. But so is solving coding competition problems, writing your own "fun projects", learning new programming languages, and so on. Ultimately, you need to choose the technique with which you are most comfortable, and make sure that you have clear guidance along the way.

Title: Drawbacks of code kata


答:
I'd suggest taking a look at s-expressions.

The tooling side is a bit weak, but there seems to be a tool to convert s-expressions to DOT files.

Title: Syntax tree dump format

Body:
When writing a compiler, it is useful to include the ability to dump the abstract syntax tree in a human readable format, for debugging purposes. This output might also be useful for other tools like IDEs and code analyzers, so I might as well provide it as a documented feature.

Given that, what format would be the most useful? It doesn't make much difference to me as long as I can eyeball it, so I might as well provide e.g. whatever other tools would find easiest to read.


答:
I use the following:

char: "char", as in "charbroiled". It rhymes nicely with "star", so "char *" comes off as "char star".

!: Intriguing; I'm not sure I've ever pronounced this aloud. I'd probably say "exclamation point", to be honest, just to be clear.

#: "Hash", although sometimes in my head I also say "number".

*: "Star"

Regex: "REG-ex". It's interesting, since "regular" has a hard g, but I suppose the soft g flows better.

SQL: Maybe I differ from most people, but I say "sequel", except in the case of PostgreSQL. I've heard you can tell on what RDBMS programmers cut their teeth, as those who learned on SQL Server tend to say "sequel" and everyone else tends to say "ess cyoo ell". Not sure if that's true, but it's true in my case. :)

|: "Pipe". Duh. :)

bin: "bin" rhymes with "pin"

lib: "lib" as in "liberate"

etc: "ets-see", as in "slash ets-see". :)

/: "Slash". It annoys me when people call it a backslash, too -- so much that I wrote a blog post about it many moons ago.

LaTeX: I say "LUH-tech".

I'll throw another one in the mix:

Mac OS X: It's "Mac OS Ten", not "Mac OS Ex" :)

Title: Pronunciation in programming?

Body:
How do you correctly or erroneously pronounce programming terms?  Any that you find need strict correction or history into the early CS culture?

Programming

char = "tchar" not care?

! = bang not exclamation?

# = pound not hash? Exception #! = shebang

* = splat not star?

regex = "rej ex" not "regg ex"?

sql = "s q l" not "sequel" (already answered, just i.e.)

Unixen

| = pipe not vertical bar?

bin = bin as in pin , not as in binary?

lib = lib as in library , not as in liberate?

etc = "ett see" , not "e t c" (as in /etc and not "&c")

Annoyance

/ = slash not backslash

LaTeX = "laytek" not "lay teks"


问:
Pros/cons between emphasizing client-side or server-side processing
Why would I want to write a web app with lots of processing server-side?

To me, writing the program client-side is a huge advantage because it takes away as much server load as possible because it only has to send data to the client with minimal processing.

I see very little on writing web-apps besides writing it server-side and treating client-side as only a view. Why would I ever want to do this? The only advantage I see is that I can write in whatever language I want (http://www.paulgraham.com/avg.html).

答:
First and foremost is Security. Push all your logic out to the client and it is fair game for hackers and exploits.

Anything with any perceived value won't last 5 minutes, especially monetary value, and will be gamed or hacked or exploited and break your system pretty badly. Even if it has little to no monetary value, there is a class of people that will hack it just to break your system because they are bored.


问:
Should images be stored in a git repository?
For a distributed team that uses Git and GitHub as version control, should images also be stored in the git repository?

The images in question are small/medium-sized web-friendly images. For the most part, the images won't be changed. The folder containing them will only grow in size as images are added. A concern is that the image folder may grow to a large size over time by combination of large images or a lot of images.

Is this considered a best practice? What other alternatives are there to sharing binary files needed in projects that a distributed team can easily access?

答: The whole "don't store binaries in source control" is set forth for a specific reason: If you have source code that compiles, don't store the actual compilation, but just the source code.  Images and visual assets do not have a "source," so they should be tracked in version control.

ContentLicense: CC BY-SA 4.0


答:
There are two major issues.

The first is easy--you usually don't know what sort of resources are available on the client side.  If it requires 1.5GB to process something, can you really push that onto an unknown client browser (IE, Safari, Opera, Firefox, etc.) on an unknown client platform?  Will the client appreciate his system dogging when you overwhelm it?

The second is more architectural--what layers do you want to expose to the outside world?  Most would agree that it's incredibly risky to expose your data layer.  How about your service layer?  Do you really want to deliver that logic out there?  If you do, are you also exposing the entry points to your data layer?  If you keep the service layer server side, then what's left?  The UI, right?  See reason 1 about for considerations on how much of that lives on the server and how much on the client.

Title: Pros/cons between emphasizing client-side or server-side processing

Body:
Why would I want to write a web app with lots of processing server-side?

To me, writing the program client-side is a huge advantage because it takes away as much server load as possible because it only has to send data to the client with minimal processing.

I see very little on writing web-apps besides writing it server-side and treating client-side as only a view. Why would I ever want to do this? The only advantage I see is that I can write in whatever language I want (http://www.paulgraham.com/avg.html).


问:
Agile software development: How do you react *financially* to changing user requirements?
There's one thing I've always wondered when reading about all this "agile development" stuff here on SE and other sites:

In "traditional" software engineering, you

collect the user's requirements,

write a specification based on these requirements,

give it to the customer and bill him for the work done so far,

do a (rough) technical design, so that you can estimate the cost of implementation,

give the user a price quote for the implementation,

wait for the customer to sign the specification and accept the offer,

design, implement, test,

bill.

If, during the process, the requirements change, you send an offer (with a price) for the desired changes (or do it for free if the change is small, you like the customer and the customer doesn't do it too often).

So, how does this work (financially) in an agile project, where frequent requirement changes are a part of the process?

Do you write an offer for every design change? (Wouldn't this be quite a mess?)

Or do you negotiate a fixed price and hope that the customer does not change the requirements too often? (Could be risky, I know customers who would use this opportunity to request new features for years before accepting that the project is completed.)

Or do you just bill the customer for the total time required? (Could be risky for the customer, who does not know the cost in advance.)

答:
In an ideal Agile world, you agree a price up front and a number of hours, but not scope. The customer decides what the minimum useful product is, rather than the product they really want, and that should estimate well short of the number of hours agreed.

Then you deliver to them iteratively and they change their minds all they want, but you never go over the number of hours agreed. In theory, and often in practice, they end up with the product they really need rather than the product they really want.

And if they want to continue to pay you for extra hours after the original agreed value, that's fine too. If you do a good enough job of making progress visible, through story cards, Greenhopper or whatever, you can make it very obvious to the customer which features they are losing (or at least deprioritising) each time they add something new, which largely puts a stop to frivolous changes.

There are two risks worthy of note here. First is that the customer may be scared off, if he hasn't understood Agility up-front. It does seem like he's taking all the risk. Only experience shows that he isn't really.

The second is that they must be engaged, throughout the whole process, or everyone will lose. Many customers fail to understand how engaged they must be until it's too late.

But if you, as a company, explain it well enough, everyone's a winner.


答:
This is not really related to Agile programming or whatever model you use. Working as a freelancer, I use a mix of Waterfall and V-model, but still have the same problem: what if the customer wants to change something during detailed design? What if he make changes during implementation?

The approach you have to use depends on the customer and your relations.

If a contact is a must-have for everything you do for this customer, because you know that he tries not to pay when he can, or he will try to sue you whenever possible, then yes, you have to write an offer for every tiny change in the requirements. It's not a mess: if you're well organized, it may not be too difficult to accommodate a new requirement during the development. But for sure, it's a loss of time and money, and it's rather strange to have to sign an offer for a change which will take you two hours to implement.

For other customers, the approach which work well is the following:

When signing the first offer, specify the estimated cost and the maximum cost. Estimated cost doesn't mean anything legally: it's just an estimate. The maximum cost has legal value: if you say that the product will cost $3,000 to your customer, and it finally costs you $3,157.24, the customer will still have to pay $3,000. In practice, in most cases, the real cost will be less than the given maximum, and closer to your estimate.

When the customer asks to change a requirement, estimate the cost it has and compare it to the actual cost and state. If you nearly finished the product and the real cost is $2,108.36 and the cost of the change is estimated to $150, just do it. If, on the other hand, there is the risk of reaching the maximum, then tell your customer that you have to reevaluate the overall cost together.

Title: Agile software development: How do you react *financially* to changing user requirements?

Body:
There's one thing I've always wondered when reading about all this "agile development" stuff here on SE and other sites:

In "traditional" software engineering, you

collect the user's requirements,

write a specification based on these requirements,

give it to the customer and bill him for the work done so far,

do a (rough) technical design, so that you can estimate the cost of implementation,

give the user a price quote for the implementation,

wait for the customer to sign the specification and accept the offer,

design, implement, test,

bill.

If, during the process, the requirements change, you send an offer (with a price) for the desired changes (or do it for free if the change is small, you like the customer and the customer doesn't do it too often).

So, how does this work (financially) in an agile project, where frequent requirement changes are a part of the process?

Do you write an offer for every design change? (Wouldn't this be quite a mess?)

Or do you negotiate a fixed price and hope that the customer does not change the requirements too often? (Could be risky, I know customers who would use this opportunity to request new features for years before accepting that the project is completed.)

Or do you just bill the customer for the total time required? (Could be risky for the customer, who does not know the cost in advance.)


答:
Other people's experience will probably vary, but one way I've seen it done is largely the same as your "traditional" with a couple of things to note:

Build in some overhead for changes (for example, 10%)

Assess and separately bill for large changes or aggregate and bill changes beyond the built-in cost (a good, albeit not programming, example is design work, where often the initial cost includes, say 3 revisions, and subsequent revisions or maybe total redos are extra)

Often, too, agile projects start out as a "core" item, and spiral out from there in a modular way on an as-needed basis (I've seen this happen quite a bit on the projects I've involved with). So, you start with a core product, let's say it's a mapping application. The first implementation is just a map that centers on your current location (what the customer initially ordered).

The customer then decides they want to have pin drops of certain attractions around you. Okay, that's a pretty big piece (relatively speaking), so you bill it as a new "module" or purchase order. Changes to things like the color or design of those pins are built into the cost of that order. Directions and overlays are another purchase order, since they weren't requested until after the other purchase order was underway, and so on and so forth.


答:
Agile and 'Write an offer' seems like an antithesis :) - the latter is not productive software engineering :D

Okay, now that we have the joke out of the way - back to the real thing.

"How does it work in Agile?" - the contract complicates things but I hope to make it clear. Agile is founded on the prinicple of 'trust' and 'co-working' which means that the customer is allowed to change whatever, whenever and understands that it may cost a bit more or if non-intrusive, maybe for no extra cost.

What does this mean? It means that the contract spells out that we (the client) fix an initial estimate of cost and the +/- variance % that we can handle e.g. $100K bid but I'm willing to go up to $120K (this MAY not be part of the contract, but in the mind of the customer).

Now, when a design change comes in you go agile with the estimating and planning to - you get your team together and ask them the 'story point' estimate w.r.t. complexity of factoring the changes. Owing to some velocity estimate, you could multiply them and give a schedule estimate. It should be relatively easy to drive out the cost per story point if you know the team and their relative salaries (please don't average across EVERYONE's salary, you'll succumb to the flaw of averages).

Do you need to go back to the customer with the financials? NO. Not necessarily. You'll have the customer prioritize these and insert them at the correct place in the backlog. Now that you know the size of the backlog (you should if you don't already) and based on the financials (cost per story point) you know which low priority requirements may not be doable with the given budget. SHOW them the reprioritized backlog with the estimate of doable features as per $$ contract. Then let THEM decide if they are willing to pay more to get more if/when you/they get there. If they want it for free...you take a stand and TELL them it'll cost more.

This should help without you constantly going back with financials if you can have this graph up somewhere for the customer to see.

Hope this helps!


答:
I'm going to buck the trend here and suggest that you not try to encourage junior developers to learn how to find the answers themselves. This looks like a game of "I have it but I'm not going to give it to you."

Instead, pair up with them in finding the answer. You're going to google it anyway, so do it while sitting with them. They'll pick up that this is the way to find answers.

If you work closely with them, they'll pick up how to use the IDE properly; How to normalize a database; how to DRY out your code... whatever you know that is worth knowing.

The keys are: one - to make yourself available to them so they can see how you work. And two - to say out loud why you are doing what you are doing. "This code repeats itself, so I'm going to refactor it," not "use extract method on those three lines."

Title: How to Mentor a Junior Developer

Body:
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).


答:
Some people attempted to give solutions to use Agility in fixed price projects in the past. I personally think it's generally not possible.

Scrum in particular is suited for product software companies, and is less used in service companies.

You can use some agility in your projects, such as iterations, daily stand-ups, burndorn, etc, but I can assure you that if you offer a certain amount of things for a certain price and deliver less than what was in the contract, you'll have a problem.

Please don't serve Agility à toutes les sauces. We must use the appropriate solution to a given problem.


答: A big part is keeping your processing close to your data.  If you've got hundreds of GB of data you're obviously not going to ship that to a client.  With data access speeds increasing this is becoming less of an issue, but if you've got a Big Data site you still want to do as much filtering and narrowing on the server as you can before shipping it out.</p>


问:
Is Assembly still relevant?
Are there major differences between assembly language and higher level languages when it comes to coding and/or managing projects? Obviously it takes more statements in assembly language to carry out a particular operation than in most other languages, but are there differences that affect how a project needs to (or should) be run based on targeting assembly language (specifically x86/x64 assembly language)?

To the extent that there are differences between assembly language and other languages, it seems reasonable to guess that at least some of these are advantages for the other languages. Can anybody point out specific disadvantages of assembly language, and ways to mitigate those disadvantages?

One specific example would be staff availability. Has anybody had trouble finding experienced assembly language programmers, and if so, what steps can be taken to mitigate this problem?

答:
in my opinion assembly as a development platform may not be relevant for everyday use. the main reason for this opinion may be because the amount of computational power that is removed from a given process Versus the amount of development time needed to optimise the same given process usually is not worth the time and energy
(there is a specific term for this.. it sounds like man/hour or something..please edit if you know what i speak of..)
there are the obvious exceptions mentioned above but as far as mainstream programming goes assembly is not used often.

this being said..assembly is still relevant today when learning programming in the context of software engineering studies,it teaches what a low level programming language looks like feels like and behaves. i'll go on and give the example of what we use in class these days. we use the pep/8 assembly that is developed by Stanley Warford (Pepperdine University USA) and its open source software given here.
mainly used because it virtualizes the cpu and shows the memory contents while stepping through the code while it's running (quite useful for learning,debugging).

So depending on your usage assembly may or may not be relevant in my opinion.

Title: Is Assembly still relevant?


答:
Primarily it will be a duplication of effort.  Most likely any data from the client will have be checked and processed at the server level again.

The server cannot assume that your rich/robust client sent the data, so with anything data being sent, the server must validate it and process.  So it makes sense to put it there.

However, I beleive some logic can be done at the client level for a better UI experience.

You are correct, why send data to the server if is not complete or incorrect.  It's easy to check for required fields or for properly formatted phones or email addresses.  I never liked submitting a form and then waiting 5 seconds to tell me I forgot to enter a field.  That kind of processing, sure, do it on the client and make sure it is correct and using client side logic for a fast response to the user.  As you have pointed out, a bonus side effect would be that your server would have to deal with less bad data requests.  BUT, the server still has to validate also, so you are duping logic.  But, your users will be happier.

There is a fine line here.  Simple validation logic OK, core business logic not OK.


问:
Servicing background tasks on a large site
We're dealing with an interesting problem on StackOverflow.

We've got a whole bunch of little "needs to be done soon-ish" tasks.  An example is updating "Related Questions" lists.  What we've done in the past is to piggy-back those tasks onto some users' page loads.

This was never ideal, but it wasn't really noticeable.  Now that SO has passed the 1,000,000 question mark, those unlucky users are starting to feel it.

The natural solution is to actually push these tasks into the background.  There are two broad ways of doing this I'm considering.

1. In IIS as a custom Thread-Pool/Work-Queue

Basically, we spin up a few (non-ThreadPool, so as to not interfere with IIS) threads and have them services some collections we're shoving Funcs into.

The big pro here is simplicity.  We don't have to worry about marshaling anything, nor do we have to make sure some external service is up and responding.

We also get access to all of our common code.

The con is, well, that we shouldn't use background threads.  The objections I know of are all centered around starving IIS (if you use ThreadPool) and the threads dieing randomly (due to AppPool recycling).

We've got existing infrastructure to make the random thread death a non-issue (its possible to detect a task has been abandoned, basically), and limiting the number of threads (and using non-ThreadPool threads) isn't difficult either.

Am I missing any other objections to in IIS process thread-pooling/work-queues?

Moved to StackOverflow, as it wasn't really addressed here.

2. As a Service

Either some third-party solution, or a custom one.

Basically, we'd marshal a task across the process boundary to some service and just forget about it.  Presumably we're linking some code in, or restricted to raw SQL + a connection string.

The pro is that its the "right way" to do this.

The cons are that we're either very restricted in what we can do, or we're going to have to work out some system for keeping this service in sync with our code base.  We'll also need to hook all of our monitoring and error logging up somehow, which we get for free with the "In IIS" option.

Are there any other benefits or problems with the service approach?

In a nutshell, are there unforseen and insurmountable problems that make approach #1 unworkable and if so are there any good third-party services we should look into for approach #2?

答:
Cron + Web App

This is a battle-tested design that scales horizontally along with your web farm and ensures that you're using the web technology stack you already know.

Here's how it works:

Create a controller/action in your web application to handle scheduled background tasks. By convention, I usually call mine http://mydomain.com/system/cron.

For security, this action should be locked down to only authenticated IP addresses on the local network.

On a seperate machine, install Wget and setup a Scheduled Task to have wget fetch the resource from step 1. You can make the task run as frequently as you want (I usually opt for 30 seconds). Don't forget to pass the appropriate cookie argument to Wget so that it authenticates to your web app.

For redundancy, you can also install a second scheduled wget on a second machine.

Hooray! Now you have a route that will be called every 30 seconds. And if the request takes 5 minutes to process, nobody will care, because it's not part of a user's page request.

The cron action ends up looking very simple: he has a list of methods to execute on a certain frequency. When a request comes in, he sees if there is a method that needs to be executed and calls the appropriate method. This means that you can control the schedule in your database, where you probably already have lots of other important configuration data for your site.

More importantly (for you), this means that your jobs don't have to be called on a fixed schedule. You can write any logic you want for determining when to execute a method.

Pros and Cons

Pros

You're already very good at writing ASP.NET MVC code, so this lets you write your background tasks in the same platform that you write the rest of your solution in.

The tasks run in the same context as your web app, so you can share the cache and make use of helper methods that already exist.

If you have wget fetch a load-balanced URI, then your background tasks are now load-balanced as well.

Simultaneous deployment - you don't have to worry about syncing your web app with your background task logic, because they're all in the same deployment.

Cons

Over the years, a few people have told me this design is "highly coupled", but when pressed they haven't been able to articulate why that is a bad thing.

Note: If there are any questions or concerns, please add a comment. I'm happy to elaborate.


答:
My first answer is the same as Philip's: consulting. I've done that, enjoyed the challenges, and find I still prefer traditional employment.

My second answer is a strategy I've found useful to keep my hand in development, even after 33 years. Let's call this "internal consulting". I interact with customers, sales, marketing, technical teams and C-level management, speak each group's language and learn what's important to each group. I often find myself in a position to suggest ideas that have potential value to the company and also bridge the goals of each  group. These ideas usually require development of a proof of concept prototype. Project time varies from an afternoon to ~12 months. I am never in critical path development, and no longer lead a development team, but I get to do early concept development. This post-Senior Engineer sort of thing may not be for everyone. However, it works for me and provides value to my employer.

In terms of concrete advice to become an "internal consultant":

Listen. Listen some more. Repeat. Learn what's important to people.

Do not be attached to concepts, opinions & ideas you may have.

Be willing to tackle the "impossible" tasks.

Practice learning anything quickly.

Embrace failure as an integral and necessary part of any process.

Be willing to look foolish by asking questions.

See #1.

Title: Senior Engineers: Go Back to Coding?


问:
Exporting huge data into XLS in a web application
I am developing a web application in Java/J2EE, in which I have export functionality.
I have used Jasper for the same. The issue is when trying to export a huge set of data it is consuming a lot of time.

Is there any design approach for export functionality so that I can improve the performance?

I had tried JExcel API earlier and then moved to DynamicJasper API.

答:
You might try exporting to .csv, which Excel will happily read.  Thats how we do all our 'excel' exports in our web app.  Its very easy to output, and you dont need a library for it (though there probably is one for Java).  Plus its human readable.

7 minutes for 25,000 rows sounds extraordinarily slow.  I'm talking would have to go out of your way to make it that slow slow.  You might do some metrics to see how the time differs between different sized datasets.  If you see it getting progressively slower, it may be an indication the exporter is doing something like loading the excel data, adding a row, saving to file... loading the excel file, adding another row, saving to file, etc.


问:
Is security a real argument for centralized version control?
I'm trying to understand if security is a real concern, or if distribution actually does a better job with security. See, the access to the main source repository could be layered and inherently managed by a network of trust, and could still have centralized user management integrating users from an LDAP/Active Directory, while the centralized version control system just relies on the later. With distribution, access could even be given to less users per repository in different countries and maintained easier.

I can see why it is easy to think that having tight & centralized access management to a code repository translates to security, however, that doesn't mean that code cannot be accessed or redistributed other ways. But, is there a real argument/use case/scenario for security where the centralized model is just better than the distributed one?.

Some context: I'm trying to make the case (with a whitepaper) to my company to switch to a DVCS (I already have other problems identified that are successfully addressed by most DVCSs) and security is one of the arguments I'm expecting to have to justify. My company is open minded though; they currently use perforce and are distributed geographically.

答:
There are two aspects to security:  reading and writing.  If you have read permissions on centralized source control, you have enough permissions to convert it to a DVCS repo no one else knows about.  Therefore, security from unauthorized distribution is a wash either way.

While in theory CVCS has robust and fine-grained permission controls on what can get written into the repository, the reality is these permissions become ever looser as people need to get their job done.  Once granted "temporarily," permission is rarely ever taken away.

The distributed nature of DVCS means people have the power to do whatever they need in their local repo, making it easier for others to strictly control what goes into the official repo.  PQ can control a repo that nothing goes into unless it passes their tests, while developers have free reign over their own domain.  For example, this structure allows Linus Torvalds to personally approve every single change that goes into the Linux kernel, although a lot of those changes he approves by virtue of his trust of his lieutenants.

In other words, DVCS security is like guarding individual jail cells, where CVCS security is like guarding an exercise yard.  The smaller the number of people who have access, the easier it is to control.


答:
On the contrary, a DCVS can be far more secure, and here is why:

Whereas a given developer having source code in any form on their workstation can do anything they want to do (steal it, share it, post it to facebook), you have to address that issue outside of version control.  So it's the same playing field once a working copy is checked out.

When it comes to checking out a working copy, I would imagine the security is comparable.  We use SSH for all access to git, so it is about as secure as it gits (pun intended).

Here is where they are different:

If you use the proper workflow, then nobody but your most trusted engineers have push access to your primary repository.  Regular developers work...work...work, and then submit a pull request to the trusted engineer, who will pull, review, and push to the main repository.

Think how open source projects, like Linux, manage their workflow in a no-trust environment.  If the same concepts are applied to your DCVS workflow, you actually have far better security with regards to bugs, security holes, or malicious code being added to your product.

Title: Is security a real argument for centralized version control?

Body:
I'm trying to understand if security is a real concern, or if distribution actually does a better job with security. See, the access to the main source repository could be layered and inherently managed by a network of trust, and could still have centralized user management integrating users from an LDAP/Active Directory, while the centralized version control system just relies on the later. With distribution, access could even be given to less users per repository in different countries and maintained easier.

I can see why it is easy to think that having tight & centralized access management to a code repository translates to security, however, that doesn't mean that code cannot be accessed or redistributed other ways. But, is there a real argument/use case/scenario for security where the centralized model is just better than the distributed one?.

Some context: I'm trying to make the case (with a whitepaper) to my company to switch to a DVCS (I already have other problems identified that are successfully addressed by most DVCSs) and security is one of the arguments I'm expecting to have to justify. My company is open minded though; they currently use perforce and are distributed geographically.


问:
Does giving a developer a slower development machine result in faster/more efficient code?
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards

答:
I'm going to buck the trend here too.

Anecdote: I worked for a Dutch software development firm that upgraded 286 computers to 486-es (yes, I'm that old).  Within weeks the performance of all of our in-house libraries dropped by 50% and bugs increased...  A little research showed that people no longer thought through the code itself during the debugging process, but resorted to 'quick' successive code -> compile -> test -> fix (code) etc. cycles.

Related: when I started a subsidiary for that same company in the USA, I ended up hiring Russian programmers because they were used to PCs with fewer features/less power and were much more efficient coders.

I realize these were different times, and resources were much more scarce than they are today, but it never ceases to amaze me how, with all the progress that's been made on the hardware front, the net result seems to be that every step forward is negated  by sloppier programming requiring higher minimum specs...

Hence... I feel programmers should be forced to test their applications on machines that do not exceed the 'Average Joe' computing power and hardware specs.

OwnerDisplayName: John SMythe


问:
What's the best/most efficent way to create a semi-intelligent AI for a tic tac toe game?
basically I am attempting to make a a efficient/smallish C game of Tic-Tac-Toe. I have implemented everything other then the AI for the computer so far. my squares are basically structs in an array with an assigned value based on the square. For example

```<code>s[1].value = 1;
</code>```

therefore it's a x, and then a value of 3 would be a o. My question is whats the best way to create a semi-decent game playing AI for my tic-tac-toe game? I don't really want to use minimax, since It's not what I need. So how do I avoid a a lot of if statments and make it more efficient.

Here is the rest of my code:

```<code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

struct state{ // defined
    int state; // 0 is tie, 1 is user loss, 2 is user win, 3 is ongoing game
    int moves;
};

struct square{ // one square of the board
    int value; // 1 is x, 3 is o
    char sign; // no space used
};

struct square s[9]; //set up the struct
struct state gamestate = {0,0}; //nothing

void setUpGame(){ // setup the game
    int i = 0;
    for(i = 0; i < 9; i++){
        s[i].value = 0;
        s[i].sign = ' ';
    }
    gamestate.moves=0;
    printf("\nHi user! You're \"x\"! I'm \"o\"! Good Luck :)\n");
}

void displayBoard(){// displays the game board
    printf("\n %c | %c | %c\n", s[6].sign, s[7].sign, s[8].sign);
    printf("-----------\n");
    printf(" %c | %c | %c\n", s[3].sign, s[4].sign, s[5].sign);
    printf("-----------\n");
    printf(" %c | %c | %c\n\n", s[0].sign, s[1].sign, s[2].sign);
}

void getHumanMove(){ // get move from human
    int i;
    while(1){
        printf(">>:");
        char line[255]; // input the move to play
        fgets(line, sizeof(line), stdin);
            while(sscanf(line, "%d", &i) != 1) { //1 match of defined specifier on input line
            printf("Sorry, that's not a valid move!\n");
            fgets(line, sizeof(line), stdin);
        }
        if(s[i-1].value != 0){printf("Sorry, That moves already been taken!\n\n");continue;}
        break;
    }
    s[i-1].value = 1;
    s[i-1].sign = 'x';
    gamestate.moves++;
}

int sum(int x, int y, int z){return(x*y*z);}

void getCompMove(){ // get the move from the computer

}

void checkWinner(){ // check the winner
    int i;
    for(i = 6; i < 9; i++){ // check cols
        if((sum(s[i].value,s[i-3].value,s[i-6].value)) == 8){printf("The Winner is o!\n");gamestate.state=1;}
        if((sum(s[i].value,s[i-3].value,s[i-6].value)) == 1){printf("The Winner is x!\n");gamestate.state=2;}
    }
    for(i = 0; i < 7; i+=3){ // check rows
        if((sum(s[i].value,s[i+1].value,s[i+2].value)) == 8){printf("The Winner is o!\n");gamestate.state=1;}
        if((sum(s[i].value,s[i+1].value,s[i+2].value)) == 1){printf("The Winner is x!\n");gamestate.state=2;}
    }
    if((sum(s[0].value,s[4].value,s[8].value)) == 8){printf("The Winner is o!\n");gamestate.state=1;}
    if((sum(s[0].value,s[4].value,s[8].value)) == 1){printf("The Winner is x!\n");gamestate.state=2;}
    if((sum(s[2].value,s[4].value,s[6].value)) == 8){printf("The Winner is o!\n");gamestate.state=1;}
    if((sum(s[2].value,s[4].value,s[6].value)) == 1){printf("The Winner is x!\n");gamestate.state=2;}
}

void playGame(){ // start playing the game
    gamestate.state = 3; //set-up the gamestate
    srand(time(NULL));
    int temp = (rand()%2) + 1;
    if(temp == 2){ // if two comp goes first
        temp = (rand()%2) + 1;
        if(temp == 2){
            s[4].value = 2; s[4].sign = 'o';
            gamestate.moves++;
        }else{
            s[2].value = 2; s[2].sign = 'o';
            gamestate.moves++;
        }
    }
    displayBoard();
    while(gamestate.state == 3){
        if(gamestate.moves<10);
            getHumanMove();
        if(gamestate.moves<10);
            getCompMove();
        checkWinner();
        if(gamestate.state == 3 && gamestate.moves==9){
            printf("The game is a tie :p\n");
            break;
        }
        displayBoard();
    }
}

int main(int argc, const char *argv[]){
    printf("Welcome to Tic Tac Toe\nby The Elite Noob\nEnter 1-9 To play a move, standard numpad\n1 is bottom-left, 9 is top-right\n");
    while(1){ // while game is being played
        printf("\nPress 1 to play a new game, or any other number to exit;\n>>:");
        char line[255]; // input whether or not to play the game
        fgets(line, sizeof(line), stdin);
        int choice; // user's choice about playing or not
        while(sscanf(line, "%d", &choice) != 1) { //1 match of defined specifier on input line
            printf("Sorry, that's not a valid option!\n");
            fgets(line, sizeof(line), stdin);
        }
        if(choice == 1){
            setUpGame(); // set's up the game
            playGame(); // Play a Game
        }else {break;} // exit the application
    }
    printf("\nThank's For playing!\nHave a good Day!\n");
    return 0;
}
</code>```

答:
So you want the human to have a chance to win?

Then play the move that blocks a winning line, or if there isn't one, play a move at random. Perhaps weight the centre for 3 and the corners for 2, with the edges at 1, but if what you want is an opponent you can beat, you don't want to be to clever.

Obviously, the AI should play a winning move if there is one.


问:
What's a nice explanation for pointers?
In your own studies (on your own, or for a class) did you have an "ah ha" moment when you finally, really understood pointers? Do you have an explanation you use for beginner programmers that seems particularly effective?

For example, when beginners first encounter pointers in C, they might just add &s and *s until it compiles (as I myself once did). Maybe it was a picture, or a really well motivated example, that made pointers "click" for you or your student. What was it, and what did you try before that didn't seem to work? Were any topics prerequisites (e.g. structs, or arrays)?

In other words, what was necessary to understand the meaning of &s and *, when you could use them with confidence? Learning the syntax and terminology or the use cases isn't enough, at some point the idea needs to be internalized.

Update: I really like the answers so far; please keep them coming. There are a lot of great perspectives here, but I think many are good explanations/slogans for ourselves after we've internalized the concept. I'm looking for the detailed contexts and circumstances when it dawned on you.

For example:

I only somewhat understood pointers
  syntactically in C. I heard two of my
  friends explaining pointers to another
  friend, who asked why a struct was
  passed with a pointer. The first
  friend talked about how it needed to
  be referenced and modified, but it was
  just a short comment from the other
  friend where it hit me: "It's also
  more efficient." Passing 4 bytes
  instead of 16 bytes was the final
  conceptual shift I needed.

答:
This document really helped me get it straight in my head: http://www.udel.edu/CIS/105/pconrad/03F/2003.fall.doc

I linked to the UD version because I like the extra explanation P. Conrad added, but the original Stanford version is just as good. All of these Stanford intro CS docs have a permanent home on my iPad. I like to read over them every now and then - keeps me grounded :-)

Title: What's a nice explanation for pointers?


问:
What can slow a developer down?
What things tend to slow a developer down?

Please try to refrain from posting answers that:

are slow now but useful in the feature. (TDD, Refactoring, ...)

list a distraction.

答:
Apart of the things mentioned by others, the long way between deciding to compile&run your code and getting a positive/negative result. Ideally, this RTT would be just a second, but I've seen an example of hours. BTW, unit testing tries to deal with this problem.

Another related this is a general latency of your working environment. Imagine you'd need to work over remote desktop connection to the computer on the other side of the world, over a creepy connection. I've been there. I've hated this.

Title: What can slow a developer down?


问:
Standard way to generate HTML prototypes?
I used to get PSD files and generate HTML prototypes from them which are supposed to be exact replica of these PSDs. The process I follow is simplest one generate plain HTML pages for each PSD.

But I have seen some of the prototypes being generated from server-side includes (like PHP pages). Benefit of using server side includes is that you don't have to repeat header, footers and side panels for each page. But in this case, anyone who want to run pages needs to setup the server and then execute these pages on server.

I want to know, what are some recommended practices to generate prototypes? Or what are the steps followed generally in case of big projects?

答:
First of all there is no standard way to generate HTML prototypes, it depends on the complexity of the problem, the target audience and what the target audience expects from the HTML prototype.

Look and Feel with 2-3 pages - the HTML from PSDs may be sufficient or even from MS Word, Viso or Powerpoint

5-10 pages - HTML prototypes can be generated from wire framing tools like Axure (http://www.axure.com/)

More complex proof of concept prototypes - server side programming tools may be used. There are some application generation tools which you give a data model and they generate code for a navigable UI.

The call on which tool to use depends on what your customers/clients expect


问:
Is it reasonable to run processes with CI tools?
At my company, we have a quagmire of disparate cron jobs (on multiple systems) and manually kicked off processes which keep our business functioning that is a result of years of expedient development and subsequent neglect.

Someday, we will need to come up with a more centralized solution for obvious reasons.

One thought that we have been kicking around is to use our Continuous Integration software (Jenkins) to run these processes, which seems logical.

My question is: Are other companies doing this? Is this a generally accepted practice? Doesn't this conflict with the definition of a CI tool implicit in its name? Are there any other options?

Note:
https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Jenkins claims that it focuses on "Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs". I'm not sure if this is exactly what I am talking about.

答:
Theoretically it makes sense for you to have a single location for controlling all the disparate jobs, however based on industry experience that is like the "Holy Grail" you will need cron jobs here, bash scripts there and cli scripts over here.

There is also a mantra "If it ain't broke, don't fix it", so while they are plodding along, initially focus on documenting what scripts you have running, what they do and what systems they touch so that you "know" how your business is being run.

Then as a long term strategy setup a centralized system for running the jobs, pick your solution wisely because you are going to have to live with it. Then for each change request, enhancement, upgrade, bug fix or new solution you add within your business architecture ensure that its scheduled and automated tasks are added to your "enterprise control solution".

That way you gradually migrate from a batch of scripts to a more enterprise friendly environment.


答:
First of all you need to understand the architecture of web applications, most if not all are 3-tier:

a) Client/Presentation - HTML and Javascript, may contain ActiveX/Flash/Java Applets/Silverlight. I will go out on a limb and add native mobile applications which communicate with a backend server. Basically the role of this layer is to provide an interface for the user of the system to interact with it.

b) Business Logic - PHP/RoR/Java where the data from the client is collected, processed and store and where client requests for data are processed and sent back to the client

c) Backend Data Store - provides persistent storage for the system information

So where do you do the validation, in all layers. Why?

a) Client side - ensure the user enters correct data, required fields etc

b) Business logic - filter, sanitize and validate client data. Run more complex business rules to ensure that the data is well formed for storage. Some of the validation done at the front end is repeated here, due to the fact that there may be different clients, take for example browsers the Javascript can be disabled. It may also accept data from different sources via APIs for example, so it all needs to be validated.

c) Backend Data Store - constraints ensure that the data is well formed for storage and later retrieval.

So where do you focus your validation efforts, use each layer to perform the validation that suits it best, and leave more complex rules for the layer that can handle it