问:
Are null references really a bad thing?
I've heard it said that the inclusion of null references in programming languages is the "billion dollar mistake".  But why?  Sure, they can cause NullReferenceExceptions, but so what?  Any element of the language can be a source of errors if used improperly.

And what's the alternative?  I suppose instead of saying this:

Customer c = Customer.GetByLastName("Goodman"); // returns null if not found
if (c != null)
{
    Console.WriteLine(c.FirstName + " " + c.LastName + " is awesome!");
}
else { Console.WriteLine("There was no customer named Goodman.  How lame!"); }
```

<p>You could say this:</p>

<pre class="lang-cs prettyprint-override"><code>if (Customer.ExistsWithLastName("Goodman"))
{
    Customer c = Customer.GetByLastName("Goodman") // throws error if not found
    Console.WriteLine(c.FirstName + " " + c.LastName + " is awesome!");
}
else { Console.WriteLine("There was no customer named Goodman.  How lame!"); }
</code>```

But how is that better?  Either way, if you forget to check that the customer exists, you get an exception.

I suppose that a CustomerNotFoundException is a bit easier to debug than a NullReferenceException by virtue of being more descriptive.  Is that all there is to it?

答:
The problem with nulls is that languages that allow them pretty much force you into programming defensively against it. It takes a lot of effort (far more than trying to use defensive if-blocks) to make sure that

the objects you expect them not to
be null are indeed never null, and

that your defensive mechanisms
indeed deal with all potential NPEs
effectively.

So, indeed, nulls end up being a costly thing to have.

Title: Are null references really a bad thing?


问:
Are tree structures inherently bad for mark-and-sweep garbage collector performance?
I'm implementing a bounding volume hierarchy in F#. Since it would be for a game, I want the garbage collector to be as quick and infrequent as possible.

It seems though that I may have to pull some whacky tricks, probably pre-allocating everything. That means that I can't have many things immutable, and that I have to know up front how large my tree will be -- a major annoyance.

I'll probably end up biting the bullet and doing just that (or maybe just go back to C++), but for the record, are trees inherently bad for GC performance? They would seem to be, considering the mark stage would have to traverse a lot of nodes.

答:
They are. However, the CLR GC is way too smart for this. Once the tree nodes survive a collection, the generational aspect will kick in and prevent it from needlessly marking the tree over and over again. You'd need a big-ass tree to mark a noticable slowdown.

Edit: Remember, trees are very common structures. The CLR GC designers will have considered and profiled this situation extensively over the past decade.

ContentLicense: CC BY-SA 3.0


答:
I understand that you are concerned about this issue not because you suffer from the premature optimization syndrome, but because you are worried that this potential performance issue might need to be taken into consideration in order to make the right choices of technologies in the very beginning of the project.

If that is your concern, there is no answer "oh, yes, that's really going to kill the GC" or "no, don't worry, everything will be fine" that you should really depend on.

Just implement a test scenario, and see for yourself how it performs.

(My guess is that there will be no problem whatsoever. Even in conditions 10x worse than your projected usage.)

Title: Are tree structures inherently bad for mark-and-sweep garbage collector performance?

Body:
I'm implementing a bounding volume hierarchy in F#. Since it would be for a game, I want the garbage collector to be as quick and infrequent as possible.

It seems though that I may have to pull some whacky tricks, probably pre-allocating everything. That means that I can't have many things immutable, and that I have to know up front how large my tree will be -- a major annoyance.

I'll probably end up biting the bullet and doing just that (or maybe just go back to C++), but for the record, are trees inherently bad for GC performance? They would seem to be, considering the mark stage would have to traverse a lot of nodes.


问:
Is OOP hard because it is not natural?
One can often hear that OOP naturally corresponds to the way people think about the world. But I would strongly disagree with this statement: We (or at least I) conceptualize the world in terms of relationships between things we encounter, but the focus of OOP is designing individual classes and their hierarchies.

Note that, in everyday life, relationships and actions exist mostly between objects that would have been instances of unrelated classes in OOP. Examples of such relationships are: "my screen is on top of the table"; "I (a human being) am sitting on a chair"; "a car is on the road"; "I am typing on the keyboard"; "the coffee machine boils water", "the text is shown in the terminal window."

We think in terms of bivalent (sometimes trivalent, as, for example in, "I gave you flowers") verbs where the verb is the action (relation) that operates on two objects to produce some result/action. The focus is on action, and the two (or three) [grammatical] objects have equal importance.

Contrast that with OOP where you first have to find one object (noun) and tell it to perform some action on another object. The way of thinking is shifted from actions/verbs operating on nouns to nouns operating on nouns -- it is as if everything is being said in passive or reflexive voice, e.g., "the text is being shown by the terminal window". Or maybe "the text draws itself on the terminal window".

Not only is the focus shifted to nouns, but one of the nouns (let's call it grammatical subject) is given higher "importance" than the other (grammatical object). Thus one must decide whether one will say terminalWindow.show(someText) or someText.show(terminalWindow). But why burden people with such trivial decisions with no operational consequences when one really means show(terminalWindow, someText)? [Consequences are operationally insignificant -- in both cases the text is shown on the terminal window -- but can be very serious in the design of class hierarchies and a "wrong" choice can lead to convoluted and hard to maintain code.]

I would therefore argue that the mainstream way of doing OOP (class-based, single-dispatch) is hard because it IS UNNATURAL and does not correspond to how humans think about the world. Generic methods from CLOS are closer to my way of thinking, but, alas, this is not widespread approach.

Given these problems, how/why did it happen that the currently mainstream way of doing OOP became so popular? And what, if anything, can be done to dethrone it?

答:
Take a look at DCI (data, context and interaction) invented by the inventor of the MVC pattern.

The goal of DCI is (quoted from Wikipedia):

Give system behavior first-class status, above objects (nouns).

To cleanly separate code for rapidly changing system behavior (what the system does) from code for slowly changing domain knowledge (what the system is), instead of combining both in one class interface.

To support an object style of thinking that is close to peoples' mental models, rather than the class style of thinking.

Here's a good article by the authors and here's is a small example implementation (.NET) if you want to see some code. It's much simpler than it might sound, and feels very natural.

ContentLicense: CC BY-SA 2.5

Title: Is OOP hard because it is not natural?


问:
What is a good time/task tracking software to use when consulting?
I am looking for time tracking software to use as an individual consulting on multiple projects at once.  The projects I work on are billable to different clients.  Some clients are billed on an hourly basis while others are billed on a project basis.  I also track personal projects that may never produce income.  I need to be able to track the time down to the individual task level.  I am looking for software that is easy to use, cost effective, easy to invoice out of and has data mining reports.</p>

答: If you are emacs user, there is org-mode a great tool which apart from all cool features(Org-mode is for keeping notes, maintaining TODO lists, doing project planning) also support Clocking tasks, have a look into this article.</p>


问:
Should one use pseudocode before actual coding?
Pseudocode helps us understand tasks in a language-agnostic manner. Is it best practice or suggested approach to have pseudocode creation as part of the development lifecycle? For instance:

Identify and split the coding tasks

Write pseudocode

Get it approved [by PL or TL]

Start Coding based on Pseudocode

Is this a suggested approach? Is it practiced in the industry?

答:
In my opinion, pseudo-code has only two valid purposes:

(1) For programming students who need to learn the concepts of modularity and algorithms, but aren't yet fluent in a programming language.

(2) To communicate how something will work to a non-technical person, or just for the sake of expediency in a white-board type meeting.


问:
How to deploy a heterogeneous server application to customers?
We have a bigger application server which customers would like to have deployed locally.

It consists of an MySQL server database, a REDIS database, multiple Web servers for sub parts, a NGINX reverse proxy so that these web servers are reachable from Port 80 and a homegrown C++ server.

All sub parts (DB, Webservers, ...) have to be configured to be accessible by each other.

At the moment (for in house use) deployment and configuration is done by hand; but in order to roll it out to customers, we would like to have a Out-of-the-Box-Solution which gets assembled by some build script.

What would you suggest?

Maintaining a VM which just gets configured and then deployed?

Maintaining some installation script or package

Something else?

Usually we would prefer 2. as it seems the more natural way and let the customer decide whether he wants to use a real server or a VM. Also sounds automatic creation of VMs rather time-expensive.

The Problems we face are the usually not-to-be-embedded-components like MySQL and NGINX. NGINX configuration is stored in /etc/nginx/. I don't think that .DEB-packages are allowed to overwrite foreign NGINX configuration nor is it a good practice. The same with MySQL.

It is also possible to embed MySQL/NGINX/Redis but this is not a trivial task.

答:
For all supported platforms create packages which pull in the right dependencies and run scripts for configuration.  I.e. debs for Ubuntu/Debian, rpm's for Redhat/Centos.

This will also buy you easy upgrading if you need that.


问:
Comment before or after the relevant code
Assuming a comment won't fit (or can't go) on the line it applies to, should one write the comment before the code or after?

Well, wherever future readers will best understand the comment's scope. In other words, wherever most programmers/scripters put such comments.

So where do most programmers/scripters put a comment: before or after its code?

If your answer applies only to specific languages, please indicate which.

And if you can cite an accepted spec or guide that supports your answer, so much the better.

答:
So where do most programmers/scripters put a comment: before or after its code?

In many years of programming using a variety of languages, I don't recall seeing any code in any language where a comment is placed on a new line after the code to which it refers. In the US, at least, the de facto standard is commenting either before the code or on the same line following the code. Writing your comments after the related code invites a drug test, a psychiatric evalutation, and/or a date with a pair of pliers and a blow torch.

The only exception I can think of is a comment marking the end of a previously commented section, like this:

```<code>// BEGIN CRITICAL SECTION
lock(&myMutex);

doSomeThreadUnsafeStuff();

unlock(&myMutex);
// END CRITICAL SECTION
</code>```

Jef Raskin wrote a well-considered essay on comments that's worth a read. He doesn't say whether he puts his comments before or after the code, but he does say that he never puts them inline, and I'd bet a lot of money that he doesn't put them after either.

Body:
So where do most programmers/scripters put a comment: before or after its code?

In many years of programming using a variety of languages, I don't recall seeing any code in any language where a comment is placed on a new line after the code to which it refers. In the US, at least, the de facto standard is commenting either before the code or on the same line following the code. Writing your comments after the related code invites a drug test, a psychiatric evalutation, and/or a date with a pair of pliers and a blow torch.

The only exception I can think of is a comment marking the end of a previously commented section, like this:

// BEGIN CRITICAL SECTION
lock(&myMutex);

doSomeThreadUnsafeStuff();

unlock(&myMutex);
// END CRITICAL SECTION

Jef Raskin wrote a well-considered essay on comments that's worth a read. He doesn't say whether he puts his comments before or after the code, but he does say that he never puts them inline, and I'd bet a lot of money that he doesn't put them after either.


问:
How to make code writing more accurate?
I am trying to practice writing code for a long period of time before compiling and write unit test (if possible) for what I wrote (the language is C++). Of course, I got the IDE support (Emacs or Eclipse for on the fly error detection and code completion) with minimal or no error. I practice this ability because the pattern "trial and error" in which a bit of code is written and then build/run to check the correctness is not productive as I feel.

However, isn't what I am doing counter the purpose of testing? Maybe, the point of my practice is not to assure 100% logic correctness, but rather, 100% or close to 100% syntax correctness, in order to vastly improve productivity. I will try to practice with the small piece of code first, and then improve gradually as time passes.

What's your opinion on code writing and productivity in general? Do you practice like I do or do you have much better method? (Aside from being in the "flow", or extremely concentration). I concern this matter because I heard that some people are an actual human compiler, and it seems like they can directly translate the logic to code as their natural language.

Edit: I was a bit wrong when I mentioned not to improve logical correctness. Yes, logical correctness counts as well. What I want is to practice programming to the point where I can keep writing code for a long period of time with minimal mistakes (such as I can write 1000 lines of code,a and only a few trivial errors occur).In case of C++ or any language, using external libraries require you to understand many dependencies of the libraries to use it correctly in your code. For example, if you use Spring framework in Java, you have to make sure the xml, the server etc... are set up correctly. I consider this is also a form of syntax, and one way to achieve "syntax correctness" is to practice it frequently to the point when you can minimize the most mistakes written by hands. This is similar to when we first start learning programming, sometimes/often we miss the semicolon. Then we learn the mistake and improve it.

答: A good testing has nothing to do with correct syntax. The compiler does this for you. A good testing is one, which covers a high percentage of your code and a wide range of special cases, not one that happens often. Use unit tests wherever possible. These allow you to repeat the tests, after you have made changes to your code. This ensures that the changes and additions are not breaking the existing logic.</p>

Title: How to make code writing more accurate?


答:
Fixing syntax errors represents only a tiny fraction of the total amount of time that we programmers spend while doing our job. I mean, it is so tiny that it gets lost in the noise. The compiler points them out to you, you fix them, and you both move on.

Even typing is not the bottleneck, so a slow typer is generally not at any great disadvantage over a fast typer.

Fixing logical errors gets somewhat closer to representing a significant portion of our work effort, but still, that is not the biggest time waster.

Design refactoring (When we realize that the way we were trying to do something is not going to work, and we have to rewrite the whole thing from the beginning) is probably the single thing that we waste most of our time doing.

So, what do we learn from that? Our job is mostly about managing the complexity of the problems we are trying to solve.  And that's a whiteboard and marker problem.  A nice development environment and tools help, but precisely what we do with them does not really count that much, because the greatest bottleneck by far is the design.

Title: How to make code writing more accurate?

Body:
I am trying to practice writing code for a long period of time before compiling and write unit test (if possible) for what I wrote (the language is C++). Of course, I got the IDE support (Emacs or Eclipse for on the fly error detection and code completion) with minimal or no error. I practice this ability because the pattern "trial and error" in which a bit of code is written and then build/run to check the correctness is not productive as I feel.

However, isn't what I am doing counter the purpose of testing? Maybe, the point of my practice is not to assure 100% logic correctness, but rather, 100% or close to 100% syntax correctness, in order to vastly improve productivity. I will try to practice with the small piece of code first, and then improve gradually as time passes.

What's your opinion on code writing and productivity in general? Do you practice like I do or do you have much better method? (Aside from being in the "flow", or extremely concentration). I concern this matter because I heard that some people are an actual human compiler, and it seems like they can directly translate the logic to code as their natural language.

Edit: I was a bit wrong when I mentioned not to improve logical correctness. Yes, logical correctness counts as well. What I want is to practice programming to the point where I can keep writing code for a long period of time with minimal mistakes (such as I can write 1000 lines of code,a and only a few trivial errors occur).In case of C++ or any language, using external libraries require you to understand many dependencies of the libraries to use it correctly in your code. For example, if you use Spring framework in Java, you have to make sure the xml, the server etc... are set up correctly. I consider this is also a form of syntax, and one way to achieve "syntax correctness" is to practice it frequently to the point when you can minimize the most mistakes written by hands. This is similar to when we first start learning programming, sometimes/often we miss the semicolon. Then we learn the mistake and improve it.


问:
As a young developer, should I be worried about having to use "out-of-style" tech at work?
I'm a recent college graduate (last May!). While I was still in school, I wanted to make sure that I had a job before I graduated, and very early (probably too early) in my job search I settled on one in a region I'd been hoping to move to after undergrad.

However, I've been second guessing this decision for months now, for several reasons. One is that I'm not very challenged at work, and I feel like I haven't improved much at programming since starting here. I can always make time to work on open source (and have in the past) outside of my job, though, so I do have a venue to get around this disappointment. More importantly, I'm worried by the fact that my job is basically to work on a creaky old Perl web application (using Mason and a weird in-house ORM).

Am I shooting myself in the foot here by working with a technology that's no longer popular, and won't really help me out getting a job in the future? I rarely see Perl jobs, and when I do, it's usually doing something I'm not interested in (front-end web development stuff).

Systems programming, visualisation, network programming, or at least backend web development stuff are the sort of topics that I'd actually enjoy working in -- it doesn't seem like my current work experience is helping me towards positions doing any of these things.

答:
What you call "out-of-style" tech is what the majority of this industry is about. The reason is simple: there is more development done to maintain existing systems than there is developing new ones. And even when developing new ones, oftentimes they will be developed using technologies that are older, but proven and that fit into a larger architectural landscape. This is just the reality of software development. Few developers are in a position that they are always able to work on the "bleeding edge" of technology.

In my opinion, there is less glory in working with [insert super-cool new technology here] than in delivering on time, on budget and according to expectations. That is something you can only learn through experience and that is completely technology-independent. I'd say you are on a good course right now. Keep learning the trade and art of software development on the job and keep up with the technology curve as best you can outside of work. That's how most of us do it.


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答: My primary language is English, but I frequently misspell in British English. Does that count? :D</p>


答:
Step 1: Try to draw the problem on whiteboard or paper (boxes, arrows, information-flows)

Step 2: Isolate logic and express it in pseudo-code (if input > 10 then do this, else do that)

Step 3: Write a unit-tests based on result of step 2

Step 4: Write code that passes the unit-tests in step 3

It's not always as straight-forward and I'm certainly no saint when it comes to following the tenets of TDD, but that is how I want it to look.

Title: How to make code writing more accurate?


答:
The "whacky tricks" you mention are not so whacky. Given the content, and the date of the article, it appears to be based on another blog article written by Shawn Hargreaves - who was well known for his work on XNA (until very recently, as he moved to the windows phone team).

One of the main reasons why GC performance is a big deal is because devices that run the compact framework (phones, xbox) don't have the same kind of generational garbage collection as the PC/Server versions of the GC do. They do a full collection every time (see here).

To directly answer your "for the record" though: No, they're not inherently bad. You do have to take your deployment platform into account, no matter what you're making though. Consider that even games written in C++ or without a garbage collection have to consider when they create and delete resources, or framerates will suffer. That's why we have loading screens and why resource streaming technologies are so interesting and difficult to implement.

ContentLicense: CC BY-SA 4.0


问:
Are there any languages that allow the static context of a method call to be available at runtime?
Is it possible for a method to know the type of the method it is called under? So for example in the following object orientated psuedo code:

```<code>Instance io = new InstanceSubclass();
io.doStuff();
</code>```

Is there a language that allows doStuff() to know that it was called as an Instance?

The question arose out of the fact the Java does not provide any kind of support for interface name clashes, for example if you create a class that implements interfaces A and B that both have a method signature such as void doWork() would it be possible for the body of doWork() to do something similar to the following :

```<code>public void doWork() {
    Class<?> context = getMethodCallContext();
    if(context == InterfaceA.class) {
        doAsInterfaceA();
    }
    else if(context == InterfaceB.class) {
        doAsInterfaceB();
    }
    else {
        // Shenanigans and error handling
    }
}
</code>```

I am not planning to write any code that takes advantage of this feature as to do so reeks of an anti-pattern waiting to happen, I only want to know if it CAN be done, if so which languages permit it?

答:
You can get exactly this effect in Java by overloading a method:

```<code>  public void doStuff(InterfaceA object) {
    // stuff for InterfaceA
  }

  public void doStuff(InterfaceB object) {
    // stuff for InterfaceB
  }
</code>```

And call it as follows:

```<code>  if (object instanceof InterfaceA) {
    doStuff((InterfaceA)object)
  }
  else if (object instanceof InterfaceB) {
    doStuff((InterfaceB)object);
  }
</code>```

This is also pretty performant: all the calls will be statically determined by the compiler so you really only have the instanceof / casting overhead (which is pretty minimal).

Body:
You can get exactly this effect in Java by overloading a method:

  public void doStuff(InterfaceA object) {
    // stuff for InterfaceA
  }

  public void doStuff(InterfaceB object) {
    // stuff for InterfaceB
  }

And call it as follows:

  if (object instanceof InterfaceA) {
    doStuff((InterfaceA)object)
  }
  else if (object instanceof InterfaceB) {
    doStuff((InterfaceB)object);
  }

This is also pretty performant: all the calls will be statically determined by the compiler so you really only have the instanceof / casting overhead (which is pretty minimal).


答:
Dissenting with everyone else, this job could very well be hurting you.  I regularly interview candidates who are trying to get away from their first job after college.  They usually were stuck using a language that tends to be used for maintenance plus a ton of in-house "frameworks".  In other words, they have learned how to use some toolkit they will never have access to ever again, wasted time as far as employability goes.

On top of that, most maintenace shops I've been exposed to do not teach you the skills you need to be part of a real development effort.  When I'm interviewing someone coming out of their first job, I want to know they understand:

Some common software development lifecycle

Source Control

How to test code (TDD, unit tests, selenium, anything like these)

OOD principles (For example: In college you hopefully got exposed to design patterns, now show me you have actually used/seen them)

Basic understanding of enterprise architecture (For example, what is a 3 tier system, and have you ever worked with one)

How to work with a team

Most of these skills I picked up on my first job by being exposed to smart people, and working with them every day.  If you don't think you are learning anything (about software or business), then start looking for another job.

Edit: As a side note, I remember the job hunt out of college.  I was at a career fair, and started talking to some company that worked with law firms.  I started asking them about their development practices, and it came out that they doing everything in VBA.  I thanked them for their time, and got out of there.

Title: As a young developer, should I be worried about having to use "out-of-style" tech at work?

Body:
I'm a recent college graduate (last May!). While I was still in school, I wanted to make sure that I had a job before I graduated, and very early (probably too early) in my job search I settled on one in a region I'd been hoping to move to after undergrad.

However, I've been second guessing this decision for months now, for several reasons. One is that I'm not very challenged at work, and I feel like I haven't improved much at programming since starting here. I can always make time to work on open source (and have in the past) outside of my job, though, so I do have a venue to get around this disappointment. More importantly, I'm worried by the fact that my job is basically to work on a creaky old Perl web application (using Mason and a weird in-house ORM).

Am I shooting myself in the foot here by working with a technology that's no longer popular, and won't really help me out getting a job in the future? I rarely see Perl jobs, and when I do, it's usually doing something I'm not interested in (front-end web development stuff).

Systems programming, visualisation, network programming, or at least backend web development stuff are the sort of topics that I'd actually enjoy working in -- it doesn't seem like my current work experience is helping me towards positions doing any of these things.


问:
How do existential types differ from interfaces?
Given the existential type

```<code>T = ∃X.{op₁:X, op₂:X→boolean}
</code>```

and this generic Java interface:

```<code>interface T<X> {
    X op₁();
    boolean op₂(X something);
}
</code>```

What are the fundamental differences between the existential type and the Java interface?

Obviously there are syntactical differences, and Java's object-orientation (which also includes details such as hidden this parameters etc.). I'm not so much interested in these as in conceptual and semantic differences — though if someone would like to shed light on some finer points (such as the notational difference between T vs. T<X>), that would be appreciated too.

答:
The only difference is that the Java interface actually means something to the Java compiler.

The existential type is the formal definition of a type, non-specific to any language. Computer scientists use this sort of definition to prove things about the type and about languages implementing it.  The Java interface is one of Java's implementations of the formally defined type.


问:
Recommend a text that explains the physical implementation of C (stack, heap, etc)
One of the most popular questions on stackoverflow.com is this one:

https://stackoverflow.com/questions/4025768/what-do-people-find-difficult-about-c-pointers

Many of the answers seem to gravitate toward the fact that students often don't get a good understanding of what is physically going on when code executes... the very most basic part of this seems to be stack/heap.

I've read through K&R twice and finally have a good understanding of the language, but I don't think that is enough.  Nearly every tough question here has the work "stack" or "heap" in the answer, and while I have a limited understanding of what those mean just from context and wikipedia searches, I prefer the comprehensive approach of a textbook.  So, please recommend a textbook which explains things like stack, heap, memory allocation, etc from a physical standpoint, as it relates to C programming.

I tried asking this question on stackoverflow and apparently it was not the right place to ask it.  So I hope this site is a better location.  If not, please consider migrating it to the proper stackexchange site.  Thanks.

答: The first two chapters of The Art of Exploitation do a pretty good job into describing C programming from a low level point of view: disassembling C code, CPU registers, debugging, pointers and memory, static variables, memory segmentation (including the stack and the heap), and more. Note that the book is using GNU/Linux tools (objdump, gcc, gdb, etc.).


答:
Although there's nothing wrong with practicing to write correct code, I would strongly advise you from attempting and practicing to write code without testing or compiling for long lengths of time. Instead, I would suggest complete opposite to that, compile and test your code as often as you can.

You can significantly minimize debugging time if you write one small segment of code and when you compile/run something doesn't work and needs to be fixed.  If you wrote 5 classes and 30 functions and then run everything, you'll have a hell of a time finding all the logic errors even after you get past 80 compilation errors.

Also, depending on which IDE you are using, you might be able to write faster code if what was written previously is compilable. For example VS2010 IDE will continuously compile your code in the background to rebuild its IntelliSense database, so if you made a syntax error, you might lose function/variable name lookup.

As far as training yourself to make less mistakes, I think it'll come eventually regardless of how frequently (or infrequently) you build/execute your code. As long as you are paying attention to what kind of things you miss and actively trying to reduce the error rate, you should be fine.  The other thing I would also practice is maintaining a consistent coding style. Don't simply let IDE format everything for you but make sure every time you insert a space or new line that you mean it. I think being careful with every keystroke and paying attention to what you are typing, not only produces cleaner, more readable code but also helps you not make the simple syntax mistakes as often.

Title: How to make code writing more accurate?


答:
Schwern,

I used to think exactly the same as you in many ways. I came out of University with strong skills in Java and Python. My first job involved working with Delphi. I was immediately worried about this, but as I had no employment and was fresh out of university, I decided to bite the bullet and take the job as I would have experience working as a programmer regardless of the language.

My second job involved working in a large bank doing Smalltalk development most of the time, with a bit of Perl and Java. My friends laughed at me as I couldn't get a job as a core Java developer and told me I was damaging my resume. I'm now looking forward to starting a new job in a few weeks that has all the technologies I want to work with and has a better salary to it.

Obviously, I can't say your experience will be the same as my own, but there are a few lessons you can take away from it to mull over. Firstly, programming is secondary to what you do. If you have good domain modeling skills and can learn business processes quickly, that will pay off more dividends in the long run as opposed to avoiding learning how the business works and spending more time majoring in minor issues, which I've seen in most places I've worked.

The second thing you need to remember is that your on another person's clock. If you want to have your own say on what to do and have full control over everything, then start your own business. I've watched far too many people join a company and moan about legacy tech, I did it myself when I first graduated. Typically these people are viewed as toxic to the workplace and don't last very long.  The key thing to remember is that the technology is there to support the business, not the other way round. The best you can do
in these situations is create opportunities from them, otherwise, it's time to pack up and leave and seek alternative employment, but your going to find every company you work for has legacy issues of some kind.

Above and beyond what I've brought up, I will say that you don't want to appear to be 'institutionalized'. What I mean by this is that you are stuck to using particular languages and technologies and can't get beyond that. You want to cultivate some flexibility in your career, that includes domain modeling skills.  Since your starting off in your career, I will point you at some good material I wish I had available to me when I started:

The Passionate Programmer

The Pragmatic Programmer

Domain-driven Design

The Career Programmer


问:
How common are "bandage" fixes?
Imagine the following scenario:

You've detected that your (or someone else's) program has a bug - a function produces the wrong result when given a particular input. You examine the code and can't find anything wrong: it just seem to bog out when given this input.

You can now do one of two things: you either examine the code further until you've found the actual cause; or you slap on a bandage by adding an if statement checking if the input is this particular input - if it is, return the expected value.

To me, applying the bandage would be completely unacceptable. If the code is behaving unexpectingly on this input, what other input that you've missed will it react strangely to? It just doesn't seem like a fix at all - you're just shoveling the problem under the rug.

As I wouldn't even consider doing this, I'm surprised at how often the professors and books keep reminding us about how applying "bandage" fixes is not a good idea. So this makes me wonder: just how common are these kinds of "fixes"?

答:
As much as we as programmers don't like to admit it, beautifully coded software isn't always going to translate to more value to the company or the customers. This is doubly true in a disaster situation, for example the software is double charging people's credit cards. Sometimes, like a bandage, you just need to stop the bleeding by whatever means necessary and promise to get back after the patient has been stabilized and actually fix the core problem.

The trick is, that once the urgency is gone, it is really hard to convince anyone to prioritize replacing the bandage with a true fix. Especially considering that there is always another urgent issue waiting in line behind the first one. You just have to be vigilant about staying with the issue beyond the quick-fix.

Title: How common are "bandage" fixes?


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

答:
First of all, I would boldly claim that you can never keep the administrator account from verbatim copying files on their machine.

However, regarding copying you could simply set the permissions on your executable files to 111 and make them belong to root, such that everybody may execute the file but not read it (thus not copy it). However, root will still be able to change that.

Since you cannot prevent the binary from being copied, and you are willing to manually install it on target systems. Compile them explicitly for that system and include a hash of the system configuration (e.g. hostname, hardware, ...). Check during runtime that you are running on a system that matches this configuration.

Still this will only make it harder to steal your software, not prevent it, because you can always take the binary, examine it and remove the part that checks for the correct machine.

All in all, doing this is usually a bad idea (IMHO) because it will cause problems to your customers (the last thing you want). If you really want to sell commercial software to people, bind them by law, not by hacks, to obey your terms and conditions.


答: Ultimately you can't - it's just a question of how much time/money you want to spend compared to how much time/money the other guy wants to spend copying it.</p>

Title: How do you prevent the piracy of your software?

Body: Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>


问:
C++ for C# Developers
I know C# pretty well (self-taught, sadly) and need to do some C++ programming for a Windows application.  I have been able to find a ton of information for C++ developers learning C# but haven't been able to find much on learning C++ when you already know C#.  Has anyone come across a good rundown of the basics?

MSDN has a comparison but it is not very in-depth.

I can piece together several sources but figured something was out there - I just can't find it.  Thanks for your help.

答: Unfortunately, there's not much about C++ that's basic, so I wouldn't get your hopes up. In addition, there's little you'll know about C# that's even remotely transferrable to C++, so I wouldn't expect any specific material to exist covering that angle. You'll need to learn from scratch.</p>

Title: C++ for C# Developers


答:
There's no easy fix for this, C++ isn't particularly difficult, but its not easy for beginners.

I would recommend reading up on the basics of C programming (to get a grounding of the low level stuff you'll find), then learn the STL, followed by articles from the likes of Scott Meyers. Here's one to get you started, as it shows how you should be writing modern C++, compared to C-with-classes.

Title: C++ for C# Developers

Body:
I know C# pretty well (self-taught, sadly) and need to do some C++ programming for a Windows application.  I have been able to find a ton of information for C++ developers learning C# but haven't been able to find much on learning C++ when you already know C#.  Has anyone come across a good rundown of the basics?

MSDN has a comparison but it is not very in-depth.

I can piece together several sources but figured something was out there - I just can't find it.  Thanks for your help.


问:
Lisp As A Langauge For A Beginner?
Should I learn Lisp as my first programming language? I have no prior experience but have heard great things about it from programming friends.</p>

答:
Lisps are great and I'd encourage anyone to try.

Depending on your mindset and aptitudes, it could be a good first programming language.

However be aware that many of the advanced features in Lisps require years of programming experience to master / appreciate. It's a bit unfair to expect a beginner to get their head around the subtleties of macro-based metaprogramming for example.

One quick and easy way to experiment with a modern Lisp online is Try Clojure. If you manage to get through the tutorial successfully and enjoy it then Lisp could be for you.....

Title: Lisp As A Langauge For A Beginner?


答:
In my eyes it is not so important what language you learn first, if you make sure you learn one functional, one object oriented, and maybe a procedural and a logical language. You say that you have friends who are good at lisp. So if i were you i would (beside the fact that there are really cool language features) learn lisp. While learning these languages (look at other/similiar languages) closely look at the concepts and not too close on the concrete syntax. This will give you the ability to learn the next language much faster.

+1 For giving me the idea of learning and reading little about lisp :) !

Title: Lisp As A Langauge For A Beginner?

Body: Should I learn Lisp as my first programming language? I have no prior experience but have heard great things about it from programming friends.</p>


答:
I don't see why not, if you don't have any exposure to traditionally imperative languages such as Java, C#, or C++ :) When you hear people saying that Lisp, ML or whatever is "too difficult", this usually means they learned C++ or similar first. What they really mean is "this language is unlike what I have already learned, therefore it's too weird".

But if you approach it from a clean slate, I think it's going to be ok.

Title: Lisp As A Langauge For A Beginner?


问:
Is it worth learning C++ in depth JUST for a career in low latency trading?
I am interested in ultra high frequency trading and Java is the language I know best.

I was always under the impression I would have to perfect my C++ skills in order to work within the ultra high frequency domain (no pun intended) because a lot of job specs seemed to ask for this.

Elsewhere on the internet i have seen people comment that Java is actually preferred because you can find Java developers much easier. However, I thought this a bad argument because in terms of ultra high frequency, you need to grab an order as soon as possible and designing your system based upon the ease of finding programmers isn't going to achieve what you need in terms of latency.

So, would you say I would be best off concentrating on Java, or is it unavoidable to specialise in C++ in order to get into this career?

答:
There are low-latency systems built in Java (for example the Disruptor), but C++ is still a commonly used language in this space. I'd personally learn both and how to communicate between the two (e.g. JNI or similar).

Looking at existing job ads in this area is probably a good idea as well.


答: You make it sound as if there are no jobs outside of the high-frequency trading industry in C++. That's just not true- C++ is an excellent language to learn and master for plenty of other reasons.</p>

Title: Is it worth learning C++ in depth JUST for a career in low latency trading?

Body:
I am interested in ultra high frequency trading and Java is the language I know best.

I was always under the impression I would have to perfect my C++ skills in order to work within the ultra high frequency domain (no pun intended) because a lot of job specs seemed to ask for this.

Elsewhere on the internet i have seen people comment that Java is actually preferred because you can find Java developers much easier. However, I thought this a bad argument because in terms of ultra high frequency, you need to grab an order as soon as possible and designing your system based upon the ease of finding programmers isn't going to achieve what you need in terms of latency.

So, would you say I would be best off concentrating on Java, or is it unavoidable to specialise in C++ in order to get into this career?


问:
Is it possible to prune the stacktrace returned for a custom exception in PHP
I am working on a project in PHP that does a lot of input validation and can throw different custom exception classes in various layers of the application. To make the project code easier to read, I've displaced all the validation code into static methods of a validation class, which performs the check and throws the appropriate exception if necessary. My problem is, the exception stacktrace displays the entire call stack down into the validation class, but I feel like the extra information is not helpful and will only serve to confuse someone trying to debug the location of the real problem. Should I simply rely on informative exception messages or is it possible to trim the trace log in some way.</p>

答:
A possible workaround would be a project wide custom exception handler, via set_exception_handler(), where you could get the trace array from Exception::getTrace() and show whatever you want to show.

But I don't really see what the problem is, a stack trace is supposed to show you the full path from where you are to where the exception was thrown. I don't really think there's anything confusing about that.

Although it doesn't really answer your question, take a look at xdebug, at the very least it prettifies traces.


问:
Unit testing methods with indeterminate output
I have a class that is meant to generate a random password of a length that's also random, but limited to be between a defined min and max length.

I'm constructing unit tests, and ran into an interesting little snag with this class.  The whole idea behind a unit test is that it should be repeatable.  If you run the test a hundred times, it should give the same results a hundred times.  If you're depending on some resource that may or may not be there or may or may not be in the initial state you expect then you're meant to mock the resource in question to ensure that your test really is always repeatable.

But what about in cases where the SUT is supposed to generate indeterminate output?

If I fix the min and max length to the same value then I can easily check that the generated password is of the expected length.  But if I specify a range of acceptable lengths (say 15 - 20 chars), then you now have the problem that you could run the test a hundred times and get 100 passes but on the 101st run you might get a 9 character string back.

In the case of the password class, which is fairly simple at its core, it shouldn't prove a huge problem.  But it got me thinking about the general case.  What is the strategy that's usually accepted as the best one to take when dealing with SUTs that are generating indeterminate output by design?

答:
Many unit testing difficulties become trivial when you refactor your code to sever dependencies. A database, a file system, the user, or in your case, a source of randomness.

Another way of looking at is that unit tests are supposed to answer the question "does this code do what I intend it to do?". In your case, you don't know what you intend the code to do because it's non-deterministic.

With this mind, separate your logic in to small, easily understood, easily-tested-in-isolation parts. Specifically, you create a distinct method (or class!) that takes a source of randomness as its input, and produces the password as an output. That code is clearly deterministic.

In your unit test, you feed it the same not-quite-random input every time. For very small random streams, just hard-code the values in your test. Otherwise, provide a constant seed to the RNG in your test.

At a higher level of testing (call it "acceptance" or "integration" or whatever), you'll let the code run with a true random source.

OwnerDisplayName: GordonM


答:
I have to disagree with the accepted answer, for two reasons:

Overfitting

Impracticability

(Notice that it may be a good answer in many circumstances, but not in all, and maybe not in most.)

So what do I mean by that? Well, by overfitting I mean a typical problem of statistical testing: overfitting happens when you test a stochastic algorithm against an overly constrained set of data. If you then go back and refine your algorithm, you will implicitly make it fit the training data very well (you accidentally fit your algorithm to the test data), but all the other data maybe not at all (because you never test against it).

(Incidentally, this is always a problem that lurks with unit testing. This is why good tests are complete, or at least representative for a given unit, and this is hard in general.)

If you make your tests deterministic by making the random number generator pluggable, you always test against the same very small and (usually) non-representative data set. This skews your data and may lead to bias in your function.

The second point, impracticability, arises when you haven’t got any control over the stochastic variable. This doesn’t usually happen with random number generators (unless you need a “real” source of random) but it can happen when stochastics sneak into your problem by other ways. For instance, when testing concurrent code: race conditions are always stochastic, you cannot (easily) make them deterministic.

The only way to raise confidence in those cases is to test a lot. Lather, rinse, repeat. This raises confidence, up to a certain level (at which point the trade-off for additional test runs becomes negligible).

Title: Unit testing methods with indeterminate output

Body:
I have a class that is meant to generate a random password of a length that's also random, but limited to be between a defined min and max length.

I'm constructing unit tests, and ran into an interesting little snag with this class.  The whole idea behind a unit test is that it should be repeatable.  If you run the test a hundred times, it should give the same results a hundred times.  If you're depending on some resource that may or may not be there or may or may not be in the initial state you expect then you're meant to mock the resource in question to ensure that your test really is always repeatable.

But what about in cases where the SUT is supposed to generate indeterminate output?

If I fix the min and max length to the same value then I can easily check that the generated password is of the expected length.  But if I specify a range of acceptable lengths (say 15 - 20 chars), then you now have the problem that you could run the test a hundred times and get 100 passes but on the 101st run you might get a 9 character string back.

In the case of the password class, which is fairly simple at its core, it shouldn't prove a huge problem.  But it got me thinking about the general case.  What is the strategy that's usually accepted as the best one to take when dealing with SUTs that are generating indeterminate output by design?


答:
Even if you could, I don't think you should mess with the stack trace. It messes with the programmer's mental model of how exceptions work. When I look at the top line of an exception trace, I expect to see a throw.

Any time you do something that's not "expected", it takes me (ie someone using your library) time to figure out what's actually going on. By keeping surprises to an absolute minimum, you make using your library easier and more intuitive.

Plus, I'd be really, really surprised if you were using set_exception_handler from an input validation library!

Title: Is it possible to prune the stacktrace returned for a custom exception in PHP

Body: I am working on a project in PHP that does a lot of input validation and can throw different custom exception classes in various layers of the application. To make the project code easier to read, I've displaced all the validation code into static methods of a validation class, which performs the check and throws the appropriate exception if necessary. My problem is, the exception stacktrace displays the entire call stack down into the validation class, but I feel like the extra information is not helpful and will only serve to confuse someone trying to debug the location of the real problem. Should I simply rely on informative exception messages or is it possible to trim the trace log in some way.</p>


问:
Should I use switch statements or long if...else chains?
Often when I hear about the switch statement, its put off as a way to replace long if...else chains. But it seems that when I use the switch statement I'm writing more code that I would be just writing if...else. You also have other issues like keeping all variables for all calls in the same scope.

Here's some code that represents the flow I normally write (thanks to diam)

```<code>String comment;   // The generated insult.
int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

if (which == 0) {
    comment = "You look so much better than usual.";
} else if (which == 1) {
    comment = "Your work is up to its usual standards.";
} else if (which == 2) {
    comment = "You're quite competent for so little experience.";
} else {
    comment = "Oops -- something is wrong with this code.";
}
</code>```

Then they want me to replace that with this:

```<code>String comment;   // The generated insult.
int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

switch (which) {
    case 0:
             comment = "You look so much better than usual.";
    break;
    case 1:
             comment = "Your work is up to its usual standards.";
    break;
    case 2:
             comment = "You're quite competent for so little experience.";
    break;
    default:
             comment = "Oops -- something is wrong with this code.";
}
</code>```

Seems like a lot more code in a much more awkward syntax. But is there really an advantage to using the switch statement?

答: One of the things that makes the C/C# style switch particularly annoying is the insistence on the case value being literals.  One nice thing about VB/VB.NET is that select/case allows each case to be any boolean expression.  That is convenient.  Insofar as a series of mutually exclusive boolean expressions is often helpful, a series of if/else ifs is more flexible, not to mention being more efficient to type and read.


问:
What is the value for a web developer to be familiar with the source code of a web browser?
Are there any specific reasons for a developer that deals with web applications (let's say writing html and js) to download a browser's source code (like Chromium) and learn how the engine works (renderer, javascript vm, network processing, etc.)?</p>

答:
It is more important to understand HTTP, client server, web standards and specifications (HTML 4, XHTML, HTML 5, CSS 2.0, CSS 3.0, Javascript) and the differences between the different browsers and browser versions.

Understanding the inner workings of a single browser engine can be useful in the same way that understanding how an engine works will help a driver get the most out of his car, but some of the knowledge will not transferable to other browsers.


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

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

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

答:
That drives me crazy too, but I'd say mention the redundancy to them in a constructive way and then drop it even if they don't concur.

Alternatively you could try this approach:

You: Can you start using the following code convention for evaluating Booleans?

```<code>if (someBool==true)&&(true==true) {}
</code>```

Them: Why would we do that? The second half of that statement is redundant, it would always evaluate to true.

You: By George, you are right. Silly me. Let's just go with a version without all the redundancy then. How about?

```<code>if (someBool) {}
</code>```

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

Body:
That drives me crazy too, but I'd say mention the redundancy to them in a constructive way and then drop it even if they don't concur.

Alternatively you could try this approach:

You: Can you start using the following code convention for evaluating Booleans?

if (someBool==true)&&(true==true) {}

Them: Why would we do that? The second half of that statement is redundant, it would always evaluate to true.

You: By George, you are right. Silly me. Let's just go with a version without all the redundancy then. How about?

if (someBool) {}


答:
To preface my answer I will say I have worked in the finance industry so I will start with a little history lesson before going into why you should learn C++.

Before Java's release C++ was the language used primarily for banking applications, especially when dealing with low latency situations such as HFT. When Java became stable enough with delivering the "write one, run anywhere" slogan that the banks started to adopt it as the new default language for smaller application and, when it's performance improved, they began using it for larger ones.

With this in mind you should also know that banks are in habit of both writing all there own stuff by default (with some exceptions) and not re-writing it if it just works in making them money; you do see a lot of legacy applications that require ancient versions of the JVM or a certain amount of magic to get working but are adding business value. Older versions of the JVM had sucky performance compared to C++ at the time and indeed current generation VMs so writing a low latency, real time system was probably not seen as being particularly viable from a performance point of view.

In other words the odds are you will likely be maintaining an existing platform that was probably written when C++ was the language of choice. At the end of the day it will either be Java or C++, you might stumble across some C or even assembly (unlikely). Additionally even if the application is Java it could call out over JNI to C++ to do the heavy lifting so I would learn C++ to the point I can do something useful in it.

In terms of mastering C++ over Java or vice versa: learn both to the point you can pass an interview, there are going to be platforms out there that have Java, mastery will come with use.


问:
Are detailed style requirements inappropriate from Marketing?
I'm working on the UI-side of a project which is under intense scrutiny by our Marketing group.  Most of the time, we're reviewing functionality requirements.

Once in a while, however, they will get very in-depth regarding colors, styles, etc.  For example, I've been tasked by Marketing to make one particular button a very specific color and a very specific size,

In other projects I've worked on, however, these types of requirements have been quietly ignored or rejected when they came from Marketing.  Managers and tech leads have insisted Marketing shouldn't be specifying details like colors, styles, control layouts, etc., but I've never really been told why.

Is it inappropriate for Marketing to list detailed style requirements for a UI, including colors, shades, layout, sizes, etc.?  If so, why?  Is this just a case of conflicting philosophies regarding Marketing responsibilities?

(I should probably mention that we're not working with a unified style guide for company-wide applications.  In the past, other projects I've worked on have "winged it" when assembling their UIs.)

Edit: I removed an editorial comment I made which probably implied this post was a complaint couched in a question. I'm not really concerned with what I should do, but rather I would like better understanding as to what Marketing's responsibility is regarding these types of requirements.  I've had very little exposure to Marketing (I've been more distanced from them in previous projects) and I don't understand their role as it pertains to UI styling.

答:
Is it inappropriate for Marketing to list detailed style requirements for a UI, including colors, shades, layout, sizes, etc.?

Yes.  It's inappropriate.

They're idiots and don't understand the consequences of their actions.  Want consistency?  Don't listen to marketing.

No.  It's not inappropriate.

They're describing to you precisely what the customer wants to pay for.  Want to sell product?  Listen to marketing.

Is this just a case of conflicting philosophies regarding Marketing responsibilities?

Yes.

You should, perhaps, find the "Product Owner" who has the final say in this.  That's the usual approach.

If there is no product owner, you have an organizational problem.


答:
Java is a certainly well used in high frequency trading. There are libraries like Javolution for example for very low latency coding (achieved for example by special data structures that avoid heap allocation), or the Disruptor which underpins the LMAX trading platform.

C/C++ still gives you more direct control over the machine, which can give you the edge in some extremely latency sensitive situations. And for these reasons it's still probably the "traditional" choice for ultra high frequency applications.

But overall, most of the code in trading platforms isn't so latency sensitive that you really need C/C++. Think about all the analytics tools for example - latency simply isn't an issue and the productivity you get from being on the JVM will clearly outweigh any minor performance advantages of C/C++. In addition, I'd say that Java (along with other JVM languages like Scala and Clojure) is much better suited to handle the highly concurrent, distributed, big data problems that are likely to be a major driver for future developments.

I would give you the following advice:

Apply for jobs anyway, don't wait to master C/C++ first. If you're a good enough Java coder you should be able to get jobs in the right kind of companies and transition to C/C++ later if there is a need.

Start learning C/C++ anyway. It will make you a better coder overall to have a low level systems language under your belt (even if Java is bringing in the money most of the time). Some basic C/C++ knowledge might help you in interviews as well - you can position yourself as a Java expert but with an interest/aptitude for C++.


答:
I prefer

```<code>if (bVal)
</code>```

or

```<code>if (!bVal)
</code>```

too, but I'm afraid that bringing it up would piss people off, so my advice is to forget it. Sorry!

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

Body:
There is a colleague of mine who constantly writes:

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

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

Body:
I prefer

if (bVal)

or

if (!bVal)

too, but I'm afraid that bringing it up would piss people off, so my advice is to forget it. Sorry!


答:
What each unit within a company does can easily change from company to company.

For example, many companies have detailed requirements around how their brand is portrayed.  If we are making software that incorporates our company's brand then we must use colors from a specific set, the logo must be positioned like so, etc.

Have you asked why they make these requests?  That might go a long way to understanding if it makes sense or not.

Title: Are detailed style requirements inappropriate from Marketing?

Body:
I'm working on the UI-side of a project which is under intense scrutiny by our Marketing group.  Most of the time, we're reviewing functionality requirements.

Once in a while, however, they will get very in-depth regarding colors, styles, etc.  For example, I've been tasked by Marketing to make one particular button a very specific color and a very specific size,

In other projects I've worked on, however, these types of requirements have been quietly ignored or rejected when they came from Marketing.  Managers and tech leads have insisted Marketing shouldn't be specifying details like colors, styles, control layouts, etc., but I've never really been told why.

Is it inappropriate for Marketing to list detailed style requirements for a UI, including colors, shades, layout, sizes, etc.?  If so, why?  Is this just a case of conflicting philosophies regarding Marketing responsibilities?

(I should probably mention that we're not working with a unified style guide for company-wide applications.  In the past, other projects I've worked on have "winged it" when assembling their UIs.)

Edit: I removed an editorial comment I made which probably implied this post was a complaint couched in a question. I'm not really concerned with what I should do, but rather I would like better understanding as to what Marketing's responsibility is regarding these types of requirements.  I've had very little exposure to Marketing (I've been more distanced from them in previous projects) and I don't understand their role as it pertains to UI styling.


答:
It can be appropriate yes, but it is probably not the best idea for a number of reasons.

Marketing people usually put a lot of research into their customers wants and needs and they also do a lot of research on competitors products.  Many times they want to either distinguish themselves from competition or they want to emulate them.  Their responsibility is to generally help create and promote a product, on the work that the software team usually produces.  They generally should have some influence in the look and feel.

The problem with them having full control however is that they may not be as qualified as a designer.  They could be making some very poor UI design judgments that will impact negatively on the usability or the look and feel.


问:
How do you manage extensibility in your multi-tenant systems?
I've got a few big web based multi-tenant products now, and very soon I can see that there will be a lot of customizations that are tenant specific.

An extra field here or there, maybe an extra page or some extra logic in the middle of a workflow - that sort of thing.

Some of these customizations can be rolled into the core product, and that's great. Some of them are highly specific and would get in everyone else's way.

I have a few ideas in mind for managing this, but none of them seem to scale well. The obvious solution is to introduce a ton of client-level settings, allowing various 'features' to be enabled on per-client basis. The downside with that, of course, is massive complexity and clutter. You could introduce a truly huge number of settings, and over time various types of logic (presentation, business) could get way out of hand. Then there's the problem of client-specific fields, which begs for something cleaner than just adding a bunch of nullable fields to the existing tables.

So what are people doing to manage this? Force.com seems to be the master of extensibility; obviously they've created a platform from the ground up that is super extensible. You can add on to almost anything with their web-based UI. FogBugz did something similiar where they created a robust plugin model that, come to think of it, might have actually been inspired by Force. I know they spent a lot of time and money on it and if I'm not mistaken the intention was to actually use it internally for future product development.

Sounds like the kind of thing I could be tempted to build but probably shouldn't. :)

Is a massive investment in pluggable architecture the only way to go? How are you managing these problems, and what kind of results are you seeing?

EDIT: It does look as though FogBugz handled the problem by building a fairly robust platform and then using that to put together their screens. To extend it you create a DLL containing classes that implement interfaces like ISearchScreenGridColumn, and that becomes a module. I'm sure it was tremendously expensive to build considering that they have a large of devs and they worked on it for months, plus their surface area is perhaps 5% of the size of my application.

Right now I am seriously wondering if Force.com is the right way to handle this. And I am a hard core ASP.Net guy, so this is a strange position to find myself in.

答:
Having lots of versioning logic and layers of code to manage isn't adding value to your web app / site. It also requires more brain power to understand what is going on and distracts you from the core of what you are doing.

I advise differently. I advise to keep things simple over complex.

Maintain a single code base that is the same for everyone. Every feature you add is a feature for all. Only restrict the number of items or storage or some quantifiable thing, not features. The reason being is quantifying things such as storage, number of data entries, etc is so simple to program against and it can be applied to just a small handful of things that really does restrict the user from going buck wild on your app. It only needs to be programmed upon the adding of items instead of doing some feature logic. What if features are tied into other features? It becomes very complicated to code for this.

To qualify my answer, I have built an ecommerce framework that I have for many clients and have learned the hard way of trying to maintain all their idiosyncrasies. I ended up breaking the chain and created a single administration website that is multi-tennant for ecommerce. I then have websites that pull in data from web service calls. This allows different teams in different technologies to implement specific features for ecommerce sites while I keep getting paid each month on the same infrastructure and I don't care what they are doing. I just limit the usage by numbers, not features. Its way easier. The client is able to choose their own vendor to build their website and I'm not involved anymore in those decisions.

I also have a subscription service for content management SAAS. This works by usage tiers as well and the clients can add their own plugins if they want while I have my team add more features for all.

This is just my experience from banging my head into the wall after so long, then stumbling upon something simpler.

If something is always going to be specific for each client, don't make a framework for it. Break it down to its simplest parts so the framework portion works for all and then cut the rest out so you can extend it for the individual.

OwnerDisplayName: Brian MacKay


答:
Understanding the inner workings of a single browser engine is a gigantic task That can only mislead a normal web dev. Chromium is not really a standard and webkit engines (and chromium is one of those) have the ugly tendency of rendering stuff in slightly different ways across platforms. (it's a problem with webkit that gets more dramatic over mobile phones, but it's there)

Anyway, to keep up with analogies: it's like having to plow a field with a tractor in autumn and spend time bothering about the inner workings of the combined harvester that will eventually clean it up the next summer.

It's... going off trail in an obsessive compulsive way.

It can be useful if you actually want to develop a native plugin for Chrome OS, (whose future is pretty uncertain, but well, it exists, at least) but what you really want to know for the immediately foreseeable future in web dev is HTML4, CSS3, SVG, and the audio/video/canvas/location/storage quasi-standardization commonly known as HTML5.

...and a javascript toolkit: jquery or amplesdk, they're libraries that build over the standards and try to level browser discrepancies.

And please: do everyone a favour and get someone to teach you SQL, it's still there, and with many clever tricks it can facebook-scale.

All of those technologies reside in a different layer above the browser implementation. And then further, on the server side of things. Yes, web devs do server side computations. Actually, is what pays most, in real life.

In a single browser source code, then, there's a lot of political and marketing strategies going on. The browser war is still raging on, with differrent competitors, but then.

Little details make the difference, and a single vendor's choices hardly reflect the "this should be done this way" consensus. (and chromium, being so much Google-influenced, will reflect some not-really-canon Google views on what the internet should look like)

Title: What is the value for a web developer to be familiar with the source code of a web browser?

Body: Are there any specific reasons for a developer that deals with web applications (let's say writing html and js) to download a browser's source code (like Chromium) and learn how the engine works (renderer, javascript vm, network processing, etc.)?</p>


答: Complete waste of time. What is important to have at hand is the standards, and perhaps some documents explaining browser peculiarities. But not the source code of the browser! It would be like hoping to get better at drawing pictures by studying the source code of Photoshop.</p>


问:
Developing using a non-official kit on the Android?
I have been doing some research on developing on the Android platform and found that the only way to develop an app using C++ is using the NDK. I also came to know that the NDK has limited support to C/C++, with C++ having even lesser support than C.
Here's the problem. I need to develop using C++ as I'm not very familiar with Java. In fact, not familiar at all. I'm still 18, so I don't have much experience with many programming languages. After doing some more research I have found a non-official NDK, called the NDK-CrystaX that implements more support for C/C++ than the official NDK. Before I start using I have to know if it would be legal to use this custom NDK in an Android app and still be able to sell it on the Android Marketplace. Is it? Or is it not?
Another solution would be if the newer releases of the NDK had full support for C/C++. But I'm not sure of that either, so I'm seeking your generosity again and asking you to share your knowledge on this too.</p>

答: Your problem is that you don't know Java, but I promise you if you're proficient with C++ , its only a matter of a few months, you can master Java too.You say you're only 18 and you don't have experience with many languages, YES this is the time, dive into Java, you'll never regret.</p>


答: Generally will omit the '== true', but it's hardly worth even a minute discussing it unless you have it included in your team's coding standards.</p>

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


答:
The only dependable and relatively problem-free way I know of is to have the software "call home" and ask "Here is my serial number, am I a legal copy?" Of course the program needs to have an internet connection in order to do that, which might be thought of as a bit of a problem, but it gets remedied by including a "check for updates" option and doing the checking during that time.

Actually, even that is not exactly dependable without additional measures to prevent people from running version 1 build 1 for eternity, or people reverse-engineering your app and disabling the protection, but this is a good start in the right direction.


答:
Waste of time, waste of disk space.

I'm +10 years experience of Windows C++ dev but building the executable of Firefox is to difficult and time consuming, so I've tried couple of times and gave up. Chrome has somewhat easier build environment but their implementation is more complicated, I think.

Below is the behind the scene document of modern web browsers. I want to say, if you fully understand this document, you can hope matching the concept to the source code in time scale of weeks (without sufficient C++ dev knowledge, it could be months).

How Browsers Work


答:
Not really. I have been developing for the web since about 1994 and I have never had the need to dig into the source of a browser. Honestly I would not know where to start, they are huge applications written in C++, which I have not done since college. </p>

<p>If you want to do it, that is great! And I am sure that you can learn a lot, but I'm not sure it will be about web development. If you want to learn about that go study Javascript or the like. Read "Javascript the Good Parts" or learn about about how to use Monads in Javascript. </p>

Body:
Not really. I have been developing for the web since about 1994 and I have never had the need to dig into the source of a browser. Honestly I would not know where to start, they are huge applications written in C++, which I have not done since college.

If you want to do it, that is great! And I am sure that you can learn a lot, but I'm not sure it will be about web development. If you want to learn about that go study Javascript or the like. Read "Javascript the Good Parts" or learn about about how to use Monads in Javascript.


答:
This thread (link now dead, view archived) on C++ for Java developers is very similar and should be useful, especially Mark Byer's post:

Read these books:

Effective C++

Sutter's books - Exceptional C++ style for example

Modern C++ Design

Probably the most important thing to keep in mind is to understand the difference in memory management techniques between C#/Java and C++.

One of my profs came from a Java background and taught an introductory C++ course thinking it would be cake. Nothing he explained made any sense to anyone. He had had memory leaks everywhere. His pointer arithmetic was terrible. He never got to the OOP part of the syllabus (thank god). Virtually nothing he demonstrated would have compiled. He didn't understand that char[] needed a sentinel \0. Don't end up like him.

Title: C++ for C# Developers


答: Just learn Java and program your app in that, in the end it will make your life a lot easier than having to go through what are you are talking about doing.</p>

Title: Developing using a non-official kit on the Android?

Body:
I have been doing some research on developing on the Android platform and found that the only way to develop an app using C++ is using the NDK. I also came to know that the NDK has limited support to C/C++, with C++ having even lesser support than C.
Here's the problem. I need to develop using C++ as I'm not very familiar with Java. In fact, not familiar at all. I'm still 18, so I don't have much experience with many programming languages. After doing some more research I have found a non-official NDK, called the NDK-CrystaX that implements more support for C/C++ than the official NDK. Before I start using I have to know if it would be legal to use this custom NDK in an Android app and still be able to sell it on the Android Marketplace. Is it? Or is it not?
Another solution would be if the newer releases of the NDK had full support for C/C++. But I'm not sure of that either, so I'm seeking your generosity again and asking you to share your knowledge on this too.</p>


答:
It's only redundant code, not life or death.  However....

If it's happening a lot, it could be a problem with how someBool is being named. A good name can go a long way towards eliminating the need for the ==true

```<code>if(IsSomeCondition)
</code>```

or

```<code>if(hasCondition)
</code>```

or

```<code>if(somethingExists)
</code>```

for example.

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

Body:
It's only redundant code, not life or death.  However....

If it's happening a lot, it could be a problem with how someBool is being named. A good name can go a long way towards eliminating the need for the ==true

if(IsSomeCondition)

or

if(hasCondition)

or

if(somethingExists)

for example.


问:
version control workflow for environment with shared code
I work at a company that is looking into "upgrading" our version control system. We have about 200 websites that operate in their own directories. However, all of these websites use the same shared code. We basically use the 200 directories for the display code (html/css) and then the shared code for the processing and database queries. Its a little more detailed but I'll leave it at that for now. We also have a backend system that primarily uses shared code only.

We currently have multiple programmers and multiple coders/designers that all need access to the code on a regular basis. Unfortunately our shared code isn't exactly modular, so it is hard to split something off into a "project" when something needs done since so many files are hit. I am basically looking for suggestions on the best workflow available for a version control system. As far as we can tell from research, git seems to be the way to go. But being the version control newbies that we are, we still have concerns on general workflow. Can anyone give me any advice on this topic?

Edit:
I'm trying to be a little more detailed, hopefully I answer some questions from the comments. Pretty much anyone is allowed to change any code at any time. If a change is made to shared code then it is immediately applied to the central code base. We don't really have a versioning scheme. We used to in the past but it was never enforced when new developers were brought on board. The shared code is clearly separated from the rest of the code. There are a few files in our system that get edited a lot. We are constantly "stepping on each other's toes" with these files. These files are very important to our system. I'll be the first one to say this is not an ideal work situation. We are well aware these files need to go. We are in the planning process of modularizing them but we would still need to consider them when choosing a versioning system. I guess another good thing to mention is the fact that we have a large number of files. This isn't ideal either but its happened primarily from not having a sound version control system put in place. Many developers over the years would just save a back up of a file if making a significant change. This is another reason we want to move away from the current scheme. Thanks for your responses already.

答:
@jbc1785: I'm going to take a stab at this based on the following assumptions about your code and your team -

You currently do not have any code in a version control system and you are new to version control

Every developer can access and change any file in the code base

You have multiple developers working on multiple projects in parallel

The code is not very modular and there are some key files in your code base that need to be touched almost every time you make any change.

In your situation, I would recommend that you start off with a centralized version control system like Subversion (SVN) instead of a distributed one like Git. I have worked in places without version control systems and (as you have correctly identified) it is vital to put in place a version control tool that simple and provides a simple workflow that teaches good version control habits. Since you have a system where you have a high chance of multiple developers making changes to the same file at the same time, you should leverage a centralized tool like subversion better to reduce the amount of errors and confusion that can occur with merge conflicts.

Subversion provides a "lock" functionality that allows users to lock files that they are editing - I recommend you use this in the initial stages so that your team gets used to the concepts of checking out and editing files. The lock status will reduce the initial confusion by making clear that a file is being currently worked on by someone and that conflicts will occur if the file is changed by someone else.

As the team gets used to the concepts of version control you can disable the "lock" functionality and introduce the concept of merging files, "merge conflicts" and their resolution. Usually once a team gets comfortable with the concept of locked files, the necessary caution and communication needed for working on files in parallel gets developed.

Once the team gets used to working with Subversion, a DVCS like Git is the logical next step. It's very easy (there are multiple tools) to move from Subversion over to Git. In fact you can run Subversion and Git in parallel and migrate over. Git scores over Subversion in terms of performance, ability to scale and the fact that since it's distributed there are no single points of failure. I think the only problem with Git is that it's command syntax is a bit cryptic and it takes a bit of getting used to.

Update: Since the comments for this post are getting numerous and hidden, I thought I'd add them to the post itself in an effort to make it more easily seen.

According to @Tamás Szelei and @JanHudec, DVCS is the way to go since locking is a bad feature of centralized version control systems that should be avoided. The contention is that Subversion dont have a good merge feature and therefore uses locking as a way to get around that deficiency.

While I accept that merging in Subversion is not as great as it is in a DVCS like Git, I disagree that using locks and the workflow encouraged by Subversion is necessarily an evil thing that should be avoided at all costs. I think Subversion has its place and in certain situations (like in case of binary files - mentioned in the other answer to this question) might even be better suited than a DVCS.

This is a matter of opinion and I still believe that given the situation mentioned in the question (listed in the beginning of this answer) using Subversion is a good way to instill version control practices and workflows in a team that have never used version control before.


答:
The software product that I work on has extra fields for user extensibility.  Each data item for these fields can be keyed to an existing row in the main tables in the application.  For example if your software contains customers and each customer a list of orders, then the customizable data table will have a column for foreign keys to the customer table and the order table, only one of which will be non-null.  Either that or a number of tables each one having the custom fields for one table.

This is a simple and performant way to store extra data for the user.  Additional information would need to be stored about the names and types of these fields.

That covers the custom fields for a customer.  For custom behaviour, a web services API would allow for extensions.

Title: How do you manage extensibility in your multi-tenant systems?

Body:
I've got a few big web based multi-tenant products now, and very soon I can see that there will be a lot of customizations that are tenant specific.

An extra field here or there, maybe an extra page or some extra logic in the middle of a workflow - that sort of thing.

Some of these customizations can be rolled into the core product, and that's great. Some of them are highly specific and would get in everyone else's way.

I have a few ideas in mind for managing this, but none of them seem to scale well. The obvious solution is to introduce a ton of client-level settings, allowing various 'features' to be enabled on per-client basis. The downside with that, of course, is massive complexity and clutter. You could introduce a truly huge number of settings, and over time various types of logic (presentation, business) could get way out of hand. Then there's the problem of client-specific fields, which begs for something cleaner than just adding a bunch of nullable fields to the existing tables.

So what are people doing to manage this? Force.com seems to be the master of extensibility; obviously they've created a platform from the ground up that is super extensible. You can add on to almost anything with their web-based UI. FogBugz did something similiar where they created a robust plugin model that, come to think of it, might have actually been inspired by Force. I know they spent a lot of time and money on it and if I'm not mistaken the intention was to actually use it internally for future product development.

Sounds like the kind of thing I could be tempted to build but probably shouldn't. :)

Is a massive investment in pluggable architecture the only way to go? How are you managing these problems, and what kind of results are you seeing?

EDIT: It does look as though FogBugz handled the problem by building a fairly robust platform and then using that to put together their screens. To extend it you create a DLL containing classes that implement interfaces like ISearchScreenGridColumn, and that becomes a module. I'm sure it was tremendously expensive to build considering that they have a large of devs and they worked on it for months, plus their surface area is perhaps 5% of the size of my application.

Right now I am seriously wondering if Force.com is the right way to handle this. And I am a hard core ASP.Net guy, so this is a strange position to find myself in.


问:
Android, OpenGL and extending GLSurfaceView?
This question is part-technical, part-meta, part-subjective and very specific:

I'm an indie game dev working on android, and for the past 6 months I've struggled and finally succeeded in making my own 3D game app for android. So I thought I'd hop on SO and help out others struggling with android and openGL-ES

However, the vast majority of questions relate to extending GLSurfaceView. I made my whole app without extending GLSurfaceView (and it runs fine). I can't see any reason at all to extend GLSurfaceView for the majority of questions I come across.

Worse, the android documentation implies that you ought to, but gives no detailed explaination of why or what the pros/cons are vs not extending and doing everything through implementing your own GLSurfaceView.Renderer as I did

Still, the sheer volume of questions where the problem is purely to do with extending GLSurfaceView is making me wonder whether actually there is some really good reason for doing it that way vs the way I've been doing it (and suggesting in my answers to others to do).

So, is there something I'm missing? Should I stop answering questions in the meantime?

Android openGL documentation

答:
Well...GLSurfaceView is, as I am sure you've noticed, just a wrapper for common good. It encapsulates all the functionality one would need to render with opengl, having the option to incorporate it nicely with the android View hierarchy.

You did not provide your alternative so it is impossible to compare, but I hope you spawned another thread for rendering as GLSurfaceView does, or your user input might lag.

So again: GLSurfaceView provides a new thread for rendering, so you dont have to worry about user input lag


答:
I generally don't like either approach. Long switch or if statements just beg to be refactored to an object oriented abstraction (however your example I would classify as short, not long).

I would personally wrap that kind of code into a separate helper method.

```<code>private string GetInsult()
{
    int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

    switch (which) {
        case 0: return "You look so much better than usual.";
        case 1: return "Your work is up to its usual standards.";
        case 2: return "You're quite competent for so little experience.";
        default: return "Oops -- something is wrong with this code.";
    }
}

public void Foo()
{
    string comment = GetInsult();
    Print(comment);
}
</code>```

Placing the switch in a separate method allows you to place return statements directly inside the switch statement (at least in c#), eliminating the need for break statements either, making the code much easier to read.

And this is imho much nicer than the if/else if/else if approach.

Title: Should I use switch statements or long if...else chains?

Body:
Often when I hear about the switch statement, its put off as a way to replace long if...else chains. But it seems that when I use the switch statement I'm writing more code that I would be just writing if...else. You also have other issues like keeping all variables for all calls in the same scope.

Here's some code that represents the flow I normally write (thanks to diam)

```<code>String comment;   // The generated insult.
int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

if (which == 0) {
    comment = "You look so much better than usual.";
} else if (which == 1) {
    comment = "Your work is up to its usual standards.";
} else if (which == 2) {
    comment = "You're quite competent for so little experience.";
} else {
    comment = "Oops -- something is wrong with this code.";
}
</code>```

Then they want me to replace that with this:

```<code>String comment;   // The generated insult.
int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

switch (which) {
    case 0:
             comment = "You look so much better than usual.";
    break;
    case 1:
             comment = "Your work is up to its usual standards.";
    break;
    case 2:
             comment = "You're quite competent for so little experience.";
    break;
    default:
             comment = "Oops -- something is wrong with this code.";
}
</code>```

Seems like a lot more code in a much more awkward syntax. But is there really an advantage to using the switch statement?

Body:
I generally don't like either approach. Long switch or if statements just beg to be refactored to an object oriented abstraction (however your example I would classify as short, not long).

I would personally wrap that kind of code into a separate helper method.

private string GetInsult()
{
    int which = (int)(Math.random() * 3);  //  Result is 0, 1, or 2.

    switch (which) {
        case 0: return "You look so much better than usual.";
        case 1: return "Your work is up to its usual standards.";
        case 2: return "You're quite competent for so little experience.";
        default: return "Oops -- something is wrong with this code.";
    }
}

public void Foo()
{
    string comment = GetInsult();
    Print(comment);
}

Placing the switch in a separate method allows you to place return statements directly inside the switch statement (at least in c#), eliminating the need for break statements either, making the code much easier to read.

And this is imho much nicer than the if/else if/else if approach.


答: Believe me, Pick a good book on C++ (there are much more, just do a search) and start learning...</p>

Title: C++ for C# Developers


答:
I'd say consistency is king in a codebase. So you should use the style, that is mostly used in your organization. Try to make your preferred style part of official company coding guidelines. If it's already in the guidelines, just follow it.

(That being said, it would also really annoy me - but probably not enough to make a big deal out of it).

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


答: I think it is good that you dont find too many C# to C++ tutorials. They may probably muddle up your brain. Its a lot like trying to learn riding a motorcycle first and then switching to a bicycle (not an entirely appropriate anology but you get the idea). It is better for you to take a fresh book on C++. Since you are already familiar with the OOP concepts you can either skip the lengthy introductions to OOP concepts( they are meant for people migrating from C to C++). Or go diretly for a reference book meant for begginer-to-intermediate or intermediate levels. </p>

Title: C++ for C# Developers


问:
How can I inspire engineers to positively conduct telephone interviews
Our (mid-size) company (with 150 employees) has witnessed considerable growth since last year, and as a result we have been conducting lots of interviews to hire more and more engineers to bring new projects in motion.

To begin with, following is our interview process

Screening resume by HR

Telephone technical interview (conducted by senior engg)

Final technical + HR interview (conducted by team-lead/PM)

After some analysis we found that telephone interviews are not really becoming effective, due to which we are not able to find good number of engineers in final interview. My analysis revealed that engineers don't consider interviewing as important/serious activity, since it's internal and non-billable. Also I see that engineers don't find it really prestigious to carry a label of "interviewer" (at-least telephone interviewer). We do have  set of good experienced engineers in company who can take any interview very effectively, but since number of telephonic interviews is large, this pool is not sufficient. Hence we try to use other engineers as well.

What can be done to inspire engineers to conduct telephone interviews seriously and positively (not treating this as mundane job)?

[Update-2011/12/28]

Thanks for sharing your valuable opinions. It really helped me to look at problem from variety of different angles. Alongside I was discussing issues with few colleagues as well and I personally feel that there is no single silver bullet for such issue. I will need to think recruitment process as a whole unit and plan to improve different areas/stages in it.

答:
Keep it simple. Do not inspire them, respect them. Pay them up front. Acknowledge their contribution in shaping your organization. Tomorrow, your company is going to be what they hire today.

Btw, would you mind dropping 'Best Practices' from the tags? -- no offense meant.

OwnerDisplayName: FutureProof