问:
Where (if there is) is the IEEE glossary newer than 1990?
I have been looking for some formal definitons but could not find any IEEE newer than 610, which is from 1990. Could you help me please?</p>

答: Yes, there is a better "IEEE glossary" than IEEE 610-1990. It's ISO/IEC/IEEE 24765:2010 Systems and software engineering -- Vocabulary. It can be accessed through the IEEE Computer Society for free.</p>


问:
shadow simulation from buildings
Is it possible to calculate shadow areas of buildings or simulate shadows of buildings in a city, using the heights of these buildings and the sun angle and azimuth?

The basic light tracing concept using trigonometry is known. However, how would one come up with simulated shadow of group of buildings in one place?

答:
Yes, of course this is possible.  It is called ray tracing.

Being old and grey means I can remember when ray tracing was exclusively the province of large supercomputers.  It is now routinely assigned as an undergraduate computer graphics class programming assignment, and the results can be STUNNING.

Take a look at this, for some examples of what the kids are doing these days.

OwnerDisplayName: Yudine

ContentLicense: CC BY-SA 3.0

Title: shadow simulation from buildings

ContentLicense: CC BY-SA 2.5


问:
Why must the burden of proof rest with the caller and not the method of the class that is being called?
Michael Perry states in his Pluralsight course on Provable Code (transcript subscription only) that:

[T]he burden of proof rests with the caller

In a code contract, why must the burden of proof rest with the caller and not the method of the class that is being called? Is this a preferred convention or does it have a more solid basis? At the moment it just like a dogma to me as the class being called could make its own safety checks, which would reduce calling code duplication.

答:
As far as I recall, "Don't blame me, I was only following orders" was rejected as a defence at Nuremburg.

So I would reject out of hand the defence that "Don't blame my code, it was the garbage it was given". That does not make for safe, secure or reliable software.

As such, while it is the responsibility of the Caller to provide correct data to the Method, it should also be incumbent on the Method to validate its inputs and handle safely any error conditions.

Just remember, most exploits are there because software doesn't validate its inputs....


问:
Is this how dynamic language copes with dynamic requirement?
The question is in the title. I want to have my thinking verified by experienced people. You can add more or disregard my opinion, but give me a reason.

Here is an example requirement: Suppose you are required to implement a fighting game. Initially, the game only includes fighters, who can attack each other. Each fighter can punch, kick or block incoming attacks. Fighters can have various fighting styles: Karate, Judo, Kung Fu... That's it for the simple universe of the game. In an OO like Java, it can be implemented similar to this way:

```<code>abstract class Fighter {
    int hp, attack;

    void punch(Fighter otherFighter);
    void kick(Fighter otherFighter);
    void block(Figther otherFighter);
};

class KarateFighter extends Fighter { //...implementation...};
class JudoFighter extends Fighter { //...implementation... };
class KungFuFighter extends Fighter { //...implementation ... };
</code>```

This is fine if the game stays like this forever. But, somehow the game designers decide to change the theme of the game: instead of a simple fighting game, the game evolves to become a RPG, in which characters can not only fight but perform other activities, i.e. the character can be a priest, an accountant, a scientist etc... At this point, to make it more generic, we have to change the structure of our original design: Fighter is not used to refer to a person anymore; it refers to a profession. The specialized classes of Fighter (KaraterFighter, JudoFighter, KungFuFighter) . Now we have to create a generic class named Person. However, to adapt this change, I have to change the method signatures of the original operations:

```<code>class Person {
    int hp, attack;
    List<Profession> skillSet;
};

abstract class Profession {};

class Fighter extends Profession {
    void punch(Person otherFighter);
    void kick(Person otherFighter);
    void block(Person otherFighter);
};

class KarateFighter extends Fighter { //...implementation...};
class JudoFighter extends Fighter { //...implementation... };
class KungFuFighter extends Fighter { //...implementation ... };

class Accountant extends Profession {
     void calculateTax(Person p) { //...implementation...};
     void calculateTax(Company c) { //...implementation...};
};
//... more professions...
</code>```

Here are the problems:

To adapt to the method changes, I have to fix the places where the changed methods are called (refactoring).

Every time a new requirement is introduced, the current structural design has to be broken to adapt the changes. This leads to the first problem.

Rigid structure makes it hard for code reuse. A function can only accept the predefined types, but it cannot accept future unknown types. A written function is bound to its current universe and has no way to accommodate to the new types, without modifications or rewrite from scratch. I see Java has a lot of deprecated methods.

OO is an extreme case because it has inheritance to add up the complexity, but in general for statically typed language, types are very strict.

In contrast, a dynamic language can handle the above case as follow:

```<code>;;fighter1 punch fighter2
(defun perform-punch (fighter1 fighter2) ...implementation... )

;;fighter1 kick fighter2
(defun perform-kick (fighter1 fighter2) ...implementation... )

;;fighter1 blocks attacks from fighter2
(defun perform-block (fighter1 fighter2) ...implementation... )
</code>```

fighter1 and fighter2 can be anything as long as it has the required data for calculation; or methods (duck typing). You don't have to change from the type Fighter to Person. In the case of Lisp, because Lisp only has a single data structure: list, it's even easier to adapt to changes. However, other dynamic languages can have similar behaviors as well.

I work primarily with static languages (mainly C and Java, but working with Java was a long time ago). I started learning Lisp and some other dynamic languages this year. I can see how it helps improving my productivity.

答:
I am not entirely sure what your question is, because it the question includes a number of vague terms: "dynamic language", "this" and "dynamic requirement".

"Dynamic language" can refer to any programming language that does something that other languages may do at compile time. This can include aspects of data values (null or not null), aspects of the type system (e.g. creating new types at runtime), aspects of method and function dispatch and many other aspects.
Your question seems to be primarily concerned with dynamic method dispatch (although you talk about static typing later on).
My attitude to this would be that different languages provide one with different tools of how to deal with requirements and also with changing requirements. In that sense, the answer to your question is probably "yes". Where languages like Java or Scala provide interfaces and traits to make it easier to adapt the design of your programs to changing requirements, a language like Clojure provides dynamic dispatch, Groovy provides metaprogramming and still other languages provide no or very little tools at all.
I think which of these tools are better suited for the task depends on the details of the task, the details of your definition of "better" (development time and effort, availability of programmer, performance of code, likelihood of certain classes of bugs during runtime etc.) and on personal preference and cannot be answered in general.


问:
What's the most absurd myth about programming issues?
To put it another way... What is the most commonly held and frustrating misunderstanding about programming, you have encountered?

Which widespread and longstanding myths/misconceptions do you find hard for programmers to dispel/correct.

Please, explain why this is a myth.

答: All programmers are good at math. :-)</p>

Body: All programmers are good at math. :-)


问:
Google App Engine, what are the advantages and limitations?
First, does anyone know a specific advantage of Google App Engine for Python Apps?
Is there some advantage over Heruko or Appfog?
And about the database API?

Now, what about the limitations?
Are there any factors that make you think twice about using GAE?

答:
Pros

Access to google infrastructure

Less likely that google( has the company) is going close shop then Heroku or Appspot

Cons

App Engine uses the Big Table database, so you are kinda limited to what database you use Edit
They now have a cloud sql service which for limited time they are having a free trial but will be a paid feature

Google has a history of closing produts down that isn't align with there main revenue generator.  Heroku and Appspot, this is there product so if they close it down then they are out of business

Not sure about  Appspot but Heroku seems to implement newer technologies faster and has a bigger selection of backend databases to chose from

Also if you need to change infrastructure I believe that Heruku is much easier to move from then Google App


问:
IEEE SRS documents: lightweight version when working with outside contractors?
Typically we follow an Agile development process that tends not to put an emphasis on writing requirements and technical documents that nobody will read.  We tend to focus our limited manpower to development and testing activities with collaborative design and whiteboarding as a key focus.

There is a mostly standalone web component that will take quite a few weeks to develop, but this work can be mostly parallel with other project work going on.  To try and catch up time I was given a budget for hiring a developer on oDesk to complete this work.

While my team isn't accustomed to working off of a firm SRS document, I realize that with outsourced development that it is a good idea to be as firm and specific as possible so I realize that I need to provide a detailed Requirements and Technical Specification document for this work to be done correctly.

When I do write a Requirements document I typically utilize the standard IEEE SRS document template but I think this is too verbose and probably overkill for what I need to communicate to a developer.  Is there another requirements document that is more lightweight and also accepted by a major standards organization like the IEEE?

Further, as what will be developed as a software module that will interact with other software modules, my requirements really need to delve into technical specifications for things to work correctly.  In this scenario does it make sense to merge technical and requirements specifications into a single document, and if not, what is a viable alternative?

答:
Summary

If it is Agile, there is a couple of issues to consider. Firstly, SRS is a no-go in Agile, and secondly, the IEEE won't back it up by any standards as they don't apply here.

User Stories, not SRS

The best option would be to reconsider the methodology to something like RUP, or to practice Agile properly and benefit from its native solutions to problems, i.e. in agile, requirements are specified as User Stories.

Agile Methodologies

Consider Scrum, for example. All stories are first piled up in Product Backlog. Then, the Product Owner (you) select stories that should be implemented in the next sprint by putting them into Sprint Backlog. Finally, the iteration starts and you can watch the Burndown chart to see how stories are being implemented.

Another recommended Agile methodology is TDD or BDD where it is refined. The developer first writes tests based upon user stories and then codes the actual internals of the software to pass the tests.

Similarly, there is Extreme Programming, Crystal, DSDM and other agile methodologies to consider.

Software Process

When practicing Agile, or any other methodology, it is imperative that the particular methodology is chosen well and followed with a certain rigor. Otherwise, "we are using Agile" becomes "we are using a process which is not formally recognized and we are actually not even sure of the outcome, we don't know what we are doing, but let's already start hacking stuff"


问:
What data structure could a word processor use to map the user's caret position/text selection to its internal representation of the document?
Word processors (e.g. Microsoft Word) display documents to the user as styled text. The user can select a part of this text and apply styles to it, and edit the text.

The word processor must (I guess) have an internal representation of the document that indicates which bits of the text displayed to the user should be styled differently. But the user doesn't interact with this internal representation. They interact with the text, by using the caret and selecting portions of it.

What data structure might the word processor use to efficiently map the text with which the user interacts to its internal model of the document?

答:
I would like to preface this post by saying that I haven't actually worked on any text editors yet. There may be some standard practice that I am unaware of...that being said, a tree doesn't seem to make much sense here; what would you have for siblings? If you tried to use a tree, I think you would end up with a linked list, which does work well here.

What is it that you want from your data structure? I assume you will need to move the cursor around quickly, making copy / pasting fast, etc. With a linked list, you have have constant time insertions, so moving the cursor is as simple as removing a special cursor node __c and inserting it one place forward.

```<code>(T) -> (h) -> (__c) -> (i) -> (s)
(T) -> (h) -> (i) -> (__c) -> (s)
</code>```

It also works well because the majority of a users navigation will be "linear"; they probably move the cursor one space forwards or backwards at a time. The usual downside to linked lists is indexing, but this behavior lends itself well to an iterator.

You will always have cases where the user uses the mouse to click and move the cursor to a much earlier position, and you might want to change the node structure to contain more than just one letter or you will end up iterating through thousands of nodes to move the cursor, but this is the general idea. Maybe you want to make each node a "paragraph" node that points to another linked list of characters? You might want to make the primary node a "formatting" node; the choice is yours.

Body:
I would like to preface this post by saying that I haven't actually worked on any text editors yet. There may be some standard practice that I am unaware of...that being said, a tree doesn't seem to make much sense here; what would you have for siblings? If you tried to use a tree, I think you would end up with a linked list, which does work well here.

What is it that you want from your data structure? I assume you will need to move the cursor around quickly, making copy / pasting fast, etc. With a linked list, you have have constant time insertions, so moving the cursor is as simple as removing a special cursor node __c and inserting it one place forward.

(T) -> (h) -> (__c) -> (i) -> (s)
(T) -> (h) -> (i) -> (__c) -> (s)

It also works well because the majority of a users navigation will be "linear"; they probably move the cursor one space forwards or backwards at a time. The usual downside to linked lists is indexing, but this behavior lends itself well to an iterator.

You will always have cases where the user uses the mouse to click and move the cursor to a much earlier position, and you might want to change the node structure to contain more than just one letter or you will end up iterating through thousands of nodes to move the cursor, but this is the general idea. Maybe you want to make each node a "paragraph" node that points to another linked list of characters? You might want to make the primary node a "formatting" node; the choice is yours.


问:
Why shouldn't I use the repository pattern with Entity Framework?
During a job interview, I was asked to explain why the repository pattern isn't a good pattern to work with ORMs like Entity Framework. Why is this the case?</p>

答:
Here's one take from Ayende Rahien: Architecting in the pit of doom: The evils of the repository abstraction layer

I'm not sure yet whether I agree with his conclusion. It's a catch-22 - on the one hand, if I wrap my EF Context in type-specific repositories with query-specific data retrieval methods, I am actually able to unit test my code (sort of), which is almost impossible with Entity Framework alone. On the other hand, I lose the ability to do rich querying and semantic maintenance of relationships (but even when I have full access to those features I always feel like I'm walking on egg shells around EF or any other other ORM I might choose, since I never know what methods its IQueryable implementation might or might not support, whether it will interpret my adding to a navigation property collection as a creation or merely an association, whether it is going to lazy or eager load or not load at all by default, etc., so maybe this is for the better. Zero-impedance object-relational "mapping" is something of mythological creature - maybe that is why the latest release of Entity Framework was codenamed "Magic Unicorn").

However, retrieving your entities through query-specific data retrieval methods means that your unit tests are now essentially white-box tests and you have no choice in this matter, since you must know in advance exactly which repository method the unit under test is going to call in order to mock it. And you're still not actually testing the queries themselves, unless you also write integration tests.

These are complex problems that need a complex solution. You can't fix it by just pretending that all your entities are separate types with no relationships between them and atomize them each into their own repository. Well you can, but it sucks.

Update: I have had some success using the Effort provider for Entity Framework. Effort is an in-memory provider (open source) that allows you to use EF in tests exactly the way you would use it against a real database. I am consider switching all the tests in this project I'm working to use this provider, since it seems to make things so much easier. It is the only solution I've found so far that addresses all of the issues that I was ranting about earlier. Only thing is there is a slight delay when starting my tests as it's creating the in-memory database (it uses another package called NMemory to do this), but I don't see this as a real problem. There's a Code Project article that talks about using Effort (versus SQL CE) for testing.

OwnerDisplayName: StringBuilder

ContentLicense: CC BY-SA 4.0


答:
Think of it this way. Suppose you have a web app where one field is the SSN of the user. You grab whatever the user types, remove any non-integer values, and call getName(int), which returns their name. Does it make more sense to have getName() throw an illegal arg exception when the user enters an illegal value, or should your web app first validate the entered value?

You always validate as close to the data as possible.

Title: Why must the burden of proof rest with the caller and not the method of the class that is being called?

Body:
Michael Perry states in his Pluralsight course on Provable Code (transcript subscription only) that:

[T]he burden of proof rests with the caller

In a code contract, why must the burden of proof rest with the caller and not the method of the class that is being called? Is this a preferred convention or does it have a more solid basis? At the moment it just like a dogma to me as the class being called could make its own safety checks, which would reduce calling code duplication.


问:
Would it be better to have extra checks, or would it be a waste of time?
In your opinion, do you think it is a waste of time to make checks that you know there is no possible way of it being there/not being there, or would you just put it there just in case there is a bug or something?  For example, below checks to see if a button is visible, then music is playing, but there is no way for that button to be shown without the music playing:</p>

```<code>if (buttonVisible)
    if ([music playing] == true) //is always true if the button is visible
        [music stopPlaying];
</code>```

答:
I'd liken these seemingly superfluous checks to activating your directional when turning on a vacant street.

On that vacant street, you've done your due diligence, scanned your surroundings, and checked your rear view mirror. There's nobody around, so why should you activate your directional?

Here's why: Because next time you drive down a similarly vacant street, you might miss a car in your blind spot.

The act of activating your car's directional communicates intent. Also, it's just a good habit to get into.

Similarly, I recommend that you include such checks in your code wherever you think they are applicable. These checks will communicate intent to future programmers who will read your code. And in light of the fact that your code will be modified in the future, you can't predict the context of future method calls.

EDIT: Per @Chuck Conway's comment, it is probably best to convert most of these if checks to either assert statements or if (not 'X') then throw statements. An encapsulating if statement might cloak a very unexpected bug!

Also, I agree with his point about simplicity. There's a fine line between adding some additional checks and adding junk that will confuse future programmers. So be judicious.


问:
"A good programmer can be as 10X times more productive than a mediocre one"
I had read an interview with a great programmer (it is not in English) and in it he said that "a great programmer can be as 10 times as good as a mediocre one" giving reason for why good programmers are very well paid and why programming companies give many facilities for their employees. The idea was that there is a very large demand for good programmers, because of the above reason and that's why companies pay very much to bring them.

Do you agree with this statement? Do you know any objective facts that could support it?

Edit: The question has nothing to do with experience; if you talk about one great programmer with 1 year experience then s/he should be 10 times more productive than a mediocre programmer with 1 year experience. I agree that from certain experience years onwards, things start to dissipate but that's not the purpose of the question.

答:
My answer is "yes, but be careful how you use that metric".

A programmer who is, shall we say, functioning optimally, is one who creates for functionality and causes fewer errors that need fixing than his lower performing bretheren.  I would not find it all hard to believe that these folks can perform at 10X the producitivity of others, particularly when you consider that a single good or bad choice made in an hour can readily have 10 hours of impact, and programmers make many such choices most days.

But...

You have be careful in you measure this.  I really don't trust most measurements on productivity since I've seen endless cases where just about every known metric fails to consider something I consider vital for team productivity.  So I generally hate such hard numbers for "productivity".  Here's some examples:

Lines of code (LOC) - a generally hated metric, since a thoughtless programmer can generate many horrible, verbose, inefficient, hard to debug lines of code while a good programmer creates a few, elegant, easy to fix, rarely broken lines of code in more time, but which are overall a better choice.

Bugs generated and/or time to fix - everyone will generate some bugs, and often the most expensive bugs are generated by a series of bad decisions for which the generator of the issue is merely the last in the domino effect.  Also, your great debuggers are not always your great designers - you need both.

By almost any metric, there are great developers who are such a pain to have on a team, that 1 "super productive" developer will drive away 10 basically good developers and I rarely see someone who can do everything well, so we'll need more than 1 person on the project.

There's no way to easily account for those wonderful people who see the problems coming before they serious and head them off, particularly when the problem is a gap in a process - faulty CM, inefficient build, a gap in testing, a security flaw - these often look like a big waste of time until you realize that they save you from disaster - there's no way to measure that.

Also, there are folks I consider necessary on a team of a certain size that I would call "cohesion builders" - rarely the absolute top of productivity, they are usually still in the upper 20% and they do the invaluable job of helping ramp up new people, connecting the dots and making sure that the right questions get asked and the right people get kept in the loop, they write (unasked!) the key piece of documentation that everyone refers to because it is not only the right document, but it's put together just the right way.  If you want 10 people to work at peak efficiency you absolutely need one of these folks and you won't get it if you put 10 super developers in a room.

Many measurement systems have tried to take these factors into account, but I have yet to see that there's one that takes all of these issues into account, so I'm never overly impressed with factors like "a good developer is 10X more productive than a mediocre one" because I have to wonder if the metric really accounts for all the work that needs to go into a successful ongoing product or a successful, thriving team.

So my big caveat is - what are you going to do with this metric?  I'll use something like this to be aware that the right tools and talent can cause a big difference in how work gets done but if you try to optimize to a team where each individual produces 10X the "typical" output, you are bound for a case of frustration.  Better is to find a way to get your team to do 2-3X what they were doing before by working together better.


问:
Why aren't there Dimension and Point interfaces?
I mean something along the lines of:

```<code>public interface Dimensioned {
    int getWidth();
    int getHeight();
}
</code>```

and

```<code>public interface Positioned {
    int getX();
    int getY();
}
</code>```

There are a lot of standard java classes that have exactly those methods-- notably Component and all of its subclasses as well as Dimension and Point. Image could implement Dimensioned.

Despite the widespread use of these methods, there's no uniform way of referring to them. Is this a conscious decision on the part of the language designers? In writing this question, I've noticed that it is rather difficult to come up with good descriptive names for the interfaces. Even so, it feels like it would be useful to have them. I can't seem to find much information on the topic.

答: Interfaces aren't just some means to group classes together that happen to have common function names, they must have some value to the code that calls the functions.  You would need a compelling use case for having something like a Vector<Dimensioned> and calling getWidth() on all of its elements, whether they're components or something else.  It's easy to come up with use cases for a Vector<Component> or a Vector<Image>, but not a mixed bag of both.  Feeling "like it would be useful" isn't a compelling reason.


问:
Why isn't DSM for unstructured memory done today?
Edit: Comments suggested, that DSM just faded out by being not used recently. What were the reasons for this, what are DSMs drawbacks? Literature lists many positive aspects like
easy to port programms to, no marshalling and therefore faster and so on but also negative aspects like only usable in homogenous environments due to endianess and word size issues. So why is all data synchronizing done by databases and not DSM anymore? Has there been a historic comparison or study at the time when both ways existed concurrently?

Old text:

Ages ago, Djikstra invented IPC through mutexes which then somehow led to shared memory (SHM) in multics (which afaik had the necessary mmap first). Then computer networks came up and DSM (distributed SHM) was invented for IPC between computers. So DSM is basically a not prestructured memory region (like a SHM) that magically get's synchronized between computers without the applications programmer taking action. Implementations include Treadmarks (inofficially dead now) and CRL.

But then someone thought this is not the right way to do it and invented Linda & tuplespaces. Current implementations include JavaSpaces and GigaSpaces. Here, you have to structure your data into tuples. Other ways to achieve similar effects may be the use of a relational database or a key-value-store like RIAK. Although someone might argue, I don't consider them as DSM since there is no coherent memory region where you can put data structures in as you like but have to structure your data which can be hard if it is continuous and administration like locking can not be done for hard coded parts (=tuples, ...).

Why is there no DSM implementation today or am I just unable to find one?

答:
DSM (Distributed Shared Memory) is a topic from Computer Architecture rather than software development; however, I have the answer:

Summary

DSM has never stopped being used. There is an evidence with enough additional information to prove the use of DSM today and an active research in that area.

Numbers

Only for year 2012, there are 173 new unique papers at IEEE Explore describing various applications of DSM.

Additional Resources

Many other recent papers can be found in the ACM Digital Library.

Sample Papers and DSM Implementations

Software distributed shared memory and its various implementations can be found here, i.e. this paper describes a particular SW DSM implementation.

Another example of a DSM paper.


问:
C++ name mangling and linker symbol resolution
The name mangling schemes of C++ compilers vary, but they are documented publicly.  Why aren't linkers made to decode a mangled symbol from an object file and attempt to find a mangled version via any of the mangling conventions across the other object files/static libraries?  If linkers could do this, wouldn't it help alleviate the problem with C++ libraries that they have to be re-compiled by each compiler to have symbols that can be resolved?

List of mangling documentations I found:

MSVC++ mangling conventions

GCC un-mangler

MSVC++ un-mangling function documentation

LLVM mangle class

答:
Name mangling is a very small part of the problem.

Object layout is only defined in the C++ standard for a very restricted set of classes (essentially only standard layout types - and then only as much as the C standard does, alignment and padding are still to be considered). For anything that has virtuals, any form of non-trivial inheritance, mixed public and private members, etc. the standard doesn't say how they should be layed out in memory.

Two compilers can (and this is not purely hypothetical, this does happen in practice) return different values for sizeof(std::string) for instance. There is nothing in the standard that says: an std::string is represented like this in memory. So interoperability at the object file level doesn't exist.

Binary compatibility between C++ compilers is a much larger problem than just name mangling. You'd need to standardize much more than what is currently specified.


答: The name mangling scheme is only a tiny part of the ABI. Calling conventions, structure padding, vtable contents, sizes and internal layout of non-POD classes, etc. also vary among compilers. Getting past the differences in name mangling doesn't help with that, it just means silencing a link-time diagnostic for a condition (ABI mismatch) that's bound to lead to silent run-time errors (object slicing, bogus parameters, overwriting unrelated data, disagreeing which pieces of an object are to be used for what purpose, and many more).</p>

Title: C++ name mangling and linker symbol resolution

Body:
The name mangling schemes of C++ compilers vary, but they are documented publicly.  Why aren't linkers made to decode a mangled symbol from an object file and attempt to find a mangled version via any of the mangling conventions across the other object files/static libraries?  If linkers could do this, wouldn't it help alleviate the problem with C++ libraries that they have to be re-compiled by each compiler to have symbols that can be resolved?

List of mangling documentations I found:

MSVC++ mangling conventions

GCC un-mangler

MSVC++ un-mangling function documentation

LLVM mangle class


问:
Will Java still be relevant in 5 years?
Will Java have the same importance it had in the past, or it will be less relevant than nowadays?</p>

答:
TIOBE rates language uses... http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Based off their stats Java leads the way and will probably do so for a long time to come - #1 since 2005.  I have used Java over my career and everywhere I have ever worked had Java applications/developers - even in places that considered themselves Microsoft Dev Shops.  Java is just such an easy language to pick up when you have to develop solutions on a Mac or Linux Server.

Also, good ole C/C++ are still holding strong at #2 and #3 - while C# - the language everyone thinks it is the most popular (MS marketing at its best) - isn't even close!  I use C# now, but it will take years to equal the amount of code I've written in Java and Delphi.

So don't be afraid to learn or use Java - there is always jobs posted for them. So, yes Java will will be very relevant for a long time to come.

Title: Will Java still be relevant in 5 years?


问:
How did Python become popular as a scripting language?
I looked at it in my field of work, which is film and pretty much every software we use comes with python as a scripting language: http://en.wikipedia.org/wiki/List_of_Python_software That made me assume it's the most popular.

How did Python become popular as a scripting language? Especially as an embedded language into standalone applications.

What's the reason for this? There are others like Lua, Ruby, etc. but yet it looks like Python came on top.

If it's because of a particular thing or just a matter of getting out there at the right time?

答: There's no way to say for certain, but in my experience most people I know who like python like it become of it's rich "batteries included" nature. It comes with an incredible number of modules that do many useful things, which means developers spend less time reinventing wheels and more time making interesting applications.</p>


问:
Custom error handling
I'm trying to figure out the best way to handle custom errors in my application.

Option 1:

```<code>if(expr) {
} else {
    $_SESSION['error'] = "Some message describing the error";
}
</code>```

Option 2:

```<code>if(expr) {
} else {
    $_SESSION['error'] = 2;
}
</code>```

In option 1, the same error might be recycled in multiple situations. If I ever decide to change the message then I'll have to dig through my code and find every occurrence.

In option 2, I give a numerical value which could reference a master list of errors. This seems to solve the problem associated with option 1 but makes the code harder to read.

What should I do?

答:
Perhaps the simplest solution might be to define a set of constant variables that reference the error message. This should give you the best of both worlds, since you can easily change the error message by editing the constant, and the constant can be named to give you an idea of what the error is when you are reading the code.

Assuming this is PHP, I'd use code like the following in a file you include everywhere:

```<code>define("ERR_FOO", "Error foo occurred.");
define("ERR_BAR", "Error bar occurred.");
</code>```

Then in your code:

```<code>if(expr) {
} else {
    $_SESSION['error'] = ERR_BAR;
}
</code>```

EDIT: I tend to agree with the point that error messages intended solely for human consumption should be written into the code as string literals at the point where they are used. Although it can probably be inferred from context, the question didn't specify whether the errors would be only read by humans once stored in $_SESSION['error'] or if some later code would need to check $_SESSION['error'] and take action based on its value. It would be difficult to accomplish this latter use case with hard-coded strings alone.

Title: Custom error handling

Body:
Perhaps the simplest solution might be to define a set of constant variables that reference the error message. This should give you the best of both worlds, since you can easily change the error message by editing the constant, and the constant can be named to give you an idea of what the error is when you are reading the code.

Assuming this is PHP, I'd use code like the following in a file you include everywhere:

define("ERR_FOO", "Error foo occurred.");
define("ERR_BAR", "Error bar occurred.");

Then in your code:

if(expr) {
} else {
    $_SESSION['error'] = ERR_BAR;
}

EDIT: I tend to agree with the point that error messages intended solely for human consumption should be written into the code as string literals at the point where they are used. Although it can probably be inferred from context, the question didn't specify whether the errors would be only read by humans once stored in $_SESSION['error'] or if some later code would need to check $_SESSION['error'] and take action based on its value. It would be difficult to accomplish this latter use case with hard-coded strings alone.


答:
Pros

a pre-configured architecture that makes app development easier (once you know the concept)

automatic scalability

multi-site replication as the default

RDBMS or NoSQL databases available

Managed VMs (with your own configuration)

Cons

vendor dependency - relatively hard to port applications to other platforms

only three languages supported out of the box (Java, Python, Go, PHP)

Title: Google App Engine, what are the advantages and limitations?

Body:
First, does anyone know a specific advantage of Google App Engine for Python Apps?
Is there some advantage over Heruko or Appfog?
And about the database API?

Now, what about the limitations?
Are there any factors that make you think twice about using GAE?


问:
Why aren't user-defined operators more common?
One feature I miss in from functional languages is the idea that operators are just functions, so adding a custom operator is often as simple as adding a function. Many procedural languages allow operator overloads, so in some sense operators are still functions (this is very true in D where the operator is passed as a string in a template parameter).

It seems that where operator overloading is allowed, it is often trivial to add additional, custom operators. I found this blog post, which argues that custom operators don't work nicely with infix notation because of precedence rules, but the author gives several solutions to this problem.

I looked around and couldn't find any procedural languages that support custom operators in the language. There are hacks (such as macros in C++), but that's hardly the same as language support.

Since this feature is pretty trivial to implement, why isn't it more common?

I understand that it can lead to some ugly code, but that hasn't stopped language designers in the past from adding useful features that can be easily abused (macros, ternary operator, unsafe pointers).

Actual use cases:

Implement missing operators (e.g. Lua doesn't have bitwise operators)

Mimic D's ~ (array concatenation)

DSLs

Use | as Unix pipe-style syntax sugar (using coroutines/generators)

I'm also interested in languages that do allow custom operators, but I'm more interested in why it has been excluded. I thought about forking a scripting language to add user-defined operators, but stopped myself when I realized that I haven't seen it anywhere, so there's probably a good reason why language designers smarter than me haven't allowed it.

答:
Operator overloads are a bad idea for the same reason that method overloads are a bad idea: the same symbol on the screen would have different meanings depending upon what is around it.  This makes it more difficult for casual reading.

Since readability is a critical aspect of maintainability, you should always avoid overloading (except in some very special cases).  It is far better for each symbol (whether operator or alphanumeric identifier) to have a unique meaning that stands on its own.

To illustrate: when reading unfamiliar code, if you encounter a new alphanum identifier that you don't know, at least you have the advantage that you know you don't know it.  You can then go look it up.  If, however, you see a common identifier or operator that you know the meaning of, you are far less likely to notice that it actually has been overloaded to have a completely different meaning.  To know what operators have been overloaded (in a code base that made widespread use of overloading), you would need a working knowledge of the complete code, even if you only want to read a small part of it.  This would make it hard to bring new developers up to speed on that code, and impossible to bring people in for a small job.  This may be good for programmer job security, but if you are responsible for the success of the code base, you should avoid this practice at all costs.

Because operators are small in size, overloading operators would allow more dense code, but making code dense is not a real benefit.   A line with twice the logic takes twice as long to read.  The compiler does not care.  The only issue is human readability.  Since making code compact does not enhance readability, there is no real benefit to compactness.  Go ahead and take the space, and give unique operations a unique identifier, and your code will be more successful in the long run.


问:
What should I be responsible for as the first developer in a large scale web project?
I am the first developer in a large scale web project, in the real estate sector.
I am not an expert in any field, I know the basic of all, programming, databases, something about design and a little bit about SEO, and website optimization / caching. And I have some knowledge about other technologies and stuff that could be required in the project.

So I am a developer, my boss does some drawing on a paper to present me his ideas and then I start programming and I show him the result. Until now there was no problem, but now the web application is large enough, and it lacks a little bit of database optimization and intuitive user interface. Beside the website, the project also has an offline newspaper, and a desktop application that is a reduced version of the online one, both this things are not managed by me, but by other people or developers that are external to the company.

We do not use a collaboration tool for sharing knowledge between the people working on this project, just emails, and we do not use a development methodology, as for the team, we are:

the developer(me),

a designer,

a secretary, and

the boss.

I have the possibility to ask the boss hire the people I want so I can increase the team and have the right person dealing with the right part of the project.

This is the story, the real question is, what should be my attitude towards the project and the company? Should I stay a developer and participate in taking decisions and organizing tasks from time to time to help the boss? Or should I get more serious about this and try to learn project management and implement everything I consider it's required to ensure the quality of the work and final results?

I am the one who best knows what has been developed until now, should I try to organize all the work and the team? Or should I ask my boss to hire some expert to do that?

答:
With your level of knowledge about the project as a whole I would keep your current role, but get some specialized assistance. You could find someone to optimize the database and another to improve the UI. Most of their expertise can be utilized right away and then hire as needed. Maybe you need to make a significant change to the database or it starts to slow down again. You may want a different look to the user interfaces and you can bring that person back.

Ask you boss for the tools to help with coordinating the efforts with outside developers. You want to be involved with the selection and implementation of this application as much as possible.


答:
I have spent a lot of time considering this issue.  I believe that the MOST IMPORTANT issue in writing error messages is to communicate accurately to the user.  The purpose of an error message to help the user to eliminate the problem that existed.  Such a problem may be a misunderstanding between the user and the program (i.e. the user thought that a file name could have a slash in the name, but that simply is not possible) or it may be an environmental problem (i.e. the disk ran out of space).

In my experience, most software has lousy error reporting.  Either cryptic numbers, or overused generic error messages with no specifics.  You need to do whatever it takes communicate as accurately and completely as possible.  Anything that stands in the way of this will reduce the quality of your error messages.  The question to ask yourself is: how will I successfully make all error messages as good as possible.

I have found, then, that putting the complete error message directly in the code is the best for making sure that the message is clear, accurate, and complete.  I work on some large codes based (> 1 million lines of code) and I have NOT had a problem finding those error messages by searching, because I make the error message as complete as possible.

If I have the same error being reported many times, I make a method/subroutine, and put the test and exception throw in there, instead of copying the same code in many places.

I don't have anything against defining a set of constants, and then using them to look up the error message, but

I have found that most programmers will make much poorer messages in this case.

The extra overhead of allocating a new constant, and putting that text into another resource file, and then arranging a call for it, is enough overhead that programmers will often simply reuse an existing message even when it is not a perfect fit.

Programmers think they will come back later and provide a better one, but they never do.

When you are removed from the context of the code that is testing for the problem, it is hard to write an accurate error message.

Spreading this information across two or three different files makes the code more complicated and difficult to maintain.

Once you define a constant it is difficult to remove even if you remove the original code

If the condition changes, it is hard to know whether you can just change the message, or whether a new message should be created.

If your goal is to clearly, accurately, and completely communicate to the user, then such use of constants and look-up files gets in the way of that communications, with no real compensating benefit.

In actuality, I separate errors into two categories: errors that can be due to user input, and errors that are due to programmers.  The ones for users need to be localizable, and those need to reference into resource files.  For these, I use constants that are NOT numerical, but instead are fair approximations of the error message.  Then the resource bundle uses that to look up a localized version of the message.  However, for the programmer errors, I embed them directly in the code, and you only get English.  I find that most (maybe 60% to 75%) are programmer oriented errors.

Title: Custom error handling

Body:
I'm trying to figure out the best way to handle custom errors in my application.

Option 1:

```<code>if(expr) {
} else {
    $_SESSION['error'] = "Some message describing the error";
}
</code>```

Option 2:

```<code>if(expr) {
} else {
    $_SESSION['error'] = 2;
}
</code>```

In option 1, the same error might be recycled in multiple situations. If I ever decide to change the message then I'll have to dig through my code and find every occurrence.

In option 2, I give a numerical value which could reference a master list of errors. This seems to solve the problem associated with option 1 but makes the code harder to read.

What should I do?


问:
Am I allowed to create closed-source software with open-source code?
I was using a popular music package (Ableton Live) when I opened the legal section of the helpfile and saw that the program contained code licenses that appeared to be both free as in freedom and free as in beer. I cannot find an online copy, alas, but if necessary I can list the licensed packages.

As far as I can see there are 3 possibilities here:

A fairly large company is violating code licensing - highly unlikely, if that were so why would they include the license text?

It's actually legit for some reason to charge money for and close source of a package that contains opensource code - this is news to me, definitely.

I am misunderstanding something - highly probable.

答:
It depends on which license.

There are some free software licenses that are specifically designed to prevent people from doing stuff like that, such as the GNU GPL.  They're known as "viral" licenses, because their licensing terms spread to any code you use them with, which keeps you from using a GPL library in a non-GPL (or compatible) program.

Other licenses are more concerned with freely sharing code than with pushing a particular ideology.  Somewhere in the middle of the spectrum, you have the MPL (Mozilla Public License,) which is non-viral and can be used in proprietary projects, but the license terms require that the MPL code itself remain covered by the MPL, and that any modifications (such as improvements, bugfixes, ports, etc) that you make to the MPL code must be published freely.  The idea here is "you get this code freely, so if you improve it, you should contribute your improvements back to the community as payment."

And at the far end of the spectrum are the completely open licenses, such as the BSD, MIT and Zlib licenses.  They essentially say "this code is free for anyone to use however they want." (With a few restrictions, of course, but there's really not much to them.)  People using these licenses are making free use of their code the highest priority.

So not all free software licenses are created equal.  Take a look at the licenses that are being used here, and what their terms are, and you'll get a better idea of whether or not the developer is complying with them by using them in a proprietary project.

Also, there's a fourth possibility:  The "fairly large company" could have licensed the product under different terms.  A software license is designed to limit users of the software, not the creator of the software, and it's not unheard of for someone to release an open-source library under GPL-style terms, and then also sell commercial licenses for it to people who want to use it in a proprietary project, without their codebase being "infected" by a viral license.


问:
How object oriented is PHP?
I had a chance to have an interesting conversation with my co-workers. Most of them are flash action script or Java developers.

We talked about how well php handles OOP. I said that PHP can handle almost every OOP stuff as of PHP 5.2 or 5.3. Am I wrong? I'm not trying to get yes/no answer, but I would like to hear more opinions from developers.

答:
PHP Categorized

PHP is only a glue language just like BASH or Perl. It is good at that, but not good at anything else, leave apart some serious work. The language is not designed. It is merely evolved by hacking up various code together in a haphazard manner (code-and-fix).

Compiled Languages

In contrast to PHP, Java is a compiled language which has been properly engineered. There are JSRs defining the language, many enterprise-grade frameworks and concepts such as EJB, JMS, ESB, Spring, Struts, Hibernate, and other.

Enterprise Software

In terms of enterprise systems, Java EE is a solution which fits the purpose (Enterprise Edition) whereas PHP is used in companies that are trying to reduce costs by hiring a cheap labor with lesser qualifications.

There has been a considerable effort to drag PHP into the Enterprise segment using various frameworks. Most notably, Zend Framework 2. The fundamental problem here is not object-orientation of PHP, but it is the lack of design, missing strong typing, non-standard solutions to standard problems (kind of hacks for everything), and a complete lack of any prescribed architecture.

Software Design (Architecture Discussed)

With PHP, the burden of architecting software is still fully up to the developers who have been doing a very poor job i.e. often not having any architecture at all, just randomly code and fix. Security and transactions are missing and need to be shoehorned by developers. In Java, one solution is annotated EJB. Also consider the fact that, in PHP, nothing happens if you omit catching exceptions or make various errors. That is until the run-time. With Java, you will get warning and errors directly at design time. That is called robustness, but with PHP you can only keep on dreaming.

Multithreading

PHP does not support multithreading. The code is always a single thread. This hinders its performance for non-trivial problems under heavier load. With Java EE, multithreading is fully supported, for example via the Runnable interface.

Support and Standards

Also consider the deployment, Web Services, and other standards. Whereas in Java, there are big companies like Oracle, IBM, RedHat, Apache, and many others, PHP has only Zend.

Conclusion

To conclude, PHP is a very bad object-oriented language. Strictly speaking, it is not even object-oriented, but hybrid which is bad from versions >5 because OOP is mixed up with procedural programming. I would only recommend PHP as a glue like BASH, but for serious work I'd use Java EE.

Related Thoughts

The main deal with the latest Zend Framework 2 is that it is trying to be like Java EE, but completely fails to deliver at least a remotely comparable set of available packages, features, tools, automation, error-checking, architecture, design, and everything.

It is, in my experience, more expensive to use PHP for complex projects than with Java.

There are also some rumors such as that PHP stands for Pretty Horrible Programming. I can confirm these.

Title: How object oriented is PHP?


答:
Well we have to think of what makes a language more OO and what reasons are there that made it like that.

JavaScript is an implementation of ECMAScript which meant to run in browser environement as an Interpreted language. The fact that it is thought to be interpreted language had very big effect on its syntactical/behavioral design.

For example, it does not follow OOP. But apart from that there are many facts like, OO prgrammer may find some of its behavior like function hoisting very confusing.

Again there are many things came with OO languages like C++, Java, C# to make them compiler efficient like strong typing. However, since JS runs in interpreted environment it does not follow strong typing instead it is loosely typed language.

Apart from above behavioral differences there are many syntactical differences like JS have Object Literal notation that may very well confuse C# programmers. However C# do also have Object literal like syntax, even though it is compiled language and such syntax is rarely used as it is not traditionally OO code style.

Now there is one more point that dictates whether the language is good OO: is it evolved from C++. As Java, C# are evolved from C++ and follow similar behavior and syntax, a big community does perceive such behavior and syntax as the only OO thing, and think that any language that does not inhibit such similarities are simply not OO.

However let us not forget that OO is very abstract concept it is not tied to any syntax style and even not to any specific beahavioral property.

And PHP is very well OO. Simply not looking and feeling like Java, C++, C# does not make it poor OO language. Well I learnt C++ then Java and then C#.

So, until now my head was very well OO. Then I learnt JS from a very good book "Wrox Pro", and it just overblown me. I just enjoyed the behavior and syntactical distinctness of JS. Then I realize that Object literal like syntax was in their in C#. And now while learning PHP I am feeling as if it brings many things from both worlds.

All we really have to do is to learn syntax and behavior subtleties a language have while implementing OO. Once we master them we may start think that this is better OO implementation.

Title: How object oriented is PHP?

Body:
I had a chance to have an interesting conversation with my co-workers. Most of them are flash action script or Java developers.

We talked about how well php handles OOP. I said that PHP can handle almost every OOP stuff as of PHP 5.2 or 5.3. Am I wrong? I'm not trying to get yes/no answer, but I would like to hear more opinions from developers.


答:
Disclaimer: I am not a lawyer. From working with lawyers in the past, software developers tend to guess the intent of legal documents and work of that whereas lawyers (1) read what is written and (2) use the legal rather than common definitions of words. Be careful.

As Mason said, it depends on the license used by the open source software. There are many common license types. Most allow others to use their code as long as they indemnify the author and include attribution (such as the license contents in a help file or About dialog). The more restrictive licenses may demand any further changes are also open source (such as GPL).

Many companies use open source components as part of closed source software. As long as the closed source software complies with the license terms, just like it would with commercial components, it is usable.

If you are looking to use these components yourself, there are other things to consider, too. For example, in the statement "Am I allowed to create closed-source software with open-source code?", it depends on what is meant by "with". Is the package  using compiled libraries? Is it using the source code directly? Is it modifying the source code or including it in yours? Any form of code modification or intermingling is much trickier from a legal or licensing perspective.

Also, is the code being distributed to customers (such as run on their servers, PCs or mobiles) or is it being used in a server in the cloud? Distributing software may be restricted or limited. Other laws apart from the software license may apply, too, such as US export restrictions (although I think I am getting beyond the question now).

Body:
I was using a popular music package (Ableton Live) when I opened the legal section of the helpfile and saw that the program contained code licenses that appeared to be both free as in freedom and free as in beer. I cannot find an online copy, alas, but if necessary I can list the licensed packages.

As far as I can see there are 3 possibilities here:

A fairly large company is violating code licensing - highly unlikely, if that were so why would they include the license text?

It's actually legit for some reason to charge money for and close source of a package that contains opensource code - this is news to me, definitely.

I am misunderstanding something - highly probable.


答:
In your opinion, do you think it is a waste of time to make checks that you know
  there is no possible way of it being there/not being there, or would you just put
  it there just in case there is a bug or something?

There are three possibilities, it's implossible

```<code>int i = 0;
if (i==1 && i==2) {
 // useless test
}
</code>```

It's possible but requires a change in the code somewhere.

```<code>int i = 0;
if (i>0) {
// line above should prevent this from happening.
// extreme case, if this branch is executing someone did something wrong
}
</code>```

And finally it could simply be an invalid state, something which you don't think can happen given good data.

The first case is a total waste of time, no change to the code or the user input can result in that test succeeding.  The second case is MOSTLY useless, but a variation on it can be useful.  Basically, the second case as presented requires a change in the code to for that branch to be take, but a more complex example could be useful in validating an assumption that is baked into the following algorithim, but is not inherently enforced.

For instance, if instead of an int, it was creating a uninitialzed User, then a check that the name was empty could theoretically be valid -- the User could be changed so that a default name is supplied, and if a write once property was changed so that the default name could be changed, it could mess things up.

But really, there are better ways of testing for such things (unit test for instance, although that's not really what they are for).

Finally, there's the last case -- and whether you test for that depends upon what you can do about it that is useful.  And just how unlikely you think it is -- if it is realistically never going to happen, then testing for it is a waste of time.  If on the other hand, it shouldn't happen but can, then by all means catch it if you can do something useful.

Title: Would it be better to have extra checks, or would it be a waste of time?

Body:
In your opinion, do you think it is a waste of time to make checks that you know there is no possible way of it being there/not being there, or would you just put it there just in case there is a bug or something?  For example, below checks to see if a button is visible, then music is playing, but there is no way for that button to be shown without the music playing:</p>

```<code>if (buttonVisible)
    if ([music playing] == true) //is always true if the button is visible
        [music stopPlaying];
</code>```

Body:
In your opinion, do you think it is a waste of time to make checks that you know
  there is no possible way of it being there/not being there, or would you just put
  it there just in case there is a bug or something?

There are three possibilities, it's implossible

int i = 0;
if (i==1 && i==2) {
 // useless test
}

It's possible but requires a change in the code somewhere.

int i = 0;
if (i>0) {
// line above should prevent this from happening.
// extreme case, if this branch is executing someone did something wrong
}

And finally it could simply be an invalid state, something which you don't think can happen given good data.

The first case is a total waste of time, no change to the code or the user input can result in that test succeeding.  The second case is MOSTLY useless, but a variation on it can be useful.  Basically, the second case as presented requires a change in the code to for that branch to be take, but a more complex example could be useful in validating an assumption that is baked into the following algorithim, but is not inherently enforced.

For instance, if instead of an int, it was creating a uninitialzed User, then a check that the name was empty could theoretically be valid -- the User could be changed so that a default name is supplied, and if a write once property was changed so that the default name could be changed, it could mess things up.

But really, there are better ways of testing for such things (unit test for instance, although that's not really what they are for).

Finally, there's the last case -- and whether you test for that depends upon what you can do about it that is useful.  And just how unlikely you think it is -- if it is realistically never going to happen, then testing for it is a waste of time.  If on the other hand, it shouldn't happen but can, then by all means catch it if you can do something useful.


问:
Difference between language virtual machine and emulating vm?
I'm having a hard time understanding the difference between an emulation virtual machine and a language vm. I started with the research and implementation of an emulation virtual machine. Primarily emulating quite old 16-bit architectures.

I want to get the basics down for a language virtual machine. Are both systems similar? Do they both use register-based architectures and stack-based?

I'm under the impression a language VM is basically a run time environment. Depending on the complexity of the VM, it may have a garbage collector, JIT compiler, etc... Would that assumption be correct?

EDIT: I'm also talking about bytecode VMs, but native machine code works too.

答:
The line can be very fuzzy, but the distinction lies in their intended purpose rather than their implementation.

Language VMs typically operate at a higher level of abstraction. They may execute bytecode or execute the AST directly. JIT compilation may occur in either case, but I don't know of any processors that implement GC (except possibly lisp machines?).

Your assumption is correct, a language VM implements the runtime environment in a language implementation.


问:
How to program thread allocation on multicore processors?
I would like to experiment with threads on a multi-core processor, e.g. to create a program that uses two different threads that are executed by two different processor cores.

However, it is not clear to me at which level the threads get allocated to the different cores. I can imagine the following scenarios (depending on operating system and programming language implementation):

Thread allocation is managed by the operating system. Threads are created using OS system calls and, if the process happens to run on a multi-core processor, the OS automatically tries to allocate / schedule different threads on different cores.

Thread allocation is managed by the programming language implementation. Allocating threads to different core requires special system calls, but the programming language standard thread libraries automatically handle this when I use the standard thread implementation for that language.

Thread allocation must be programmed explicitly. In my program I have to write explicit code to detect how many cores are available and to allocate different threads to different core using, e.g.,  library functions.

To make the question more specific, imagine I have written my multi-threaded application in Java or C++ on Windows or Linux. Will my application magically see and use multiple cores when run on a multi-core processor (because everything is managed either by the operating system or by the standard thread library), or do I have to modify my code to be aware of the multiple cores?

答:
Will my application magically see and use multiple cores when run on a
  multi-core processor (because everything is managed either by the
  operating system or by the standard thread library), or do I have to
  modify my code to be aware of the multiple cores?

Simple answer: Yes, it will usually be managed by the operating system or threading library.

The threading subsystem in the operating system will assign threads to processors on a priority basis (your option 1). In other words, when a thread has finished executing for its time allocation or blocks, the scheduler looks for the next highest priority thread and assigns that to the CPU. The details vary from operating system to operating system.

That said, options 2 (managed by programming language) and 3 (explicitly) exist. For example, the Tasks library and async/await in recent versions of .Net give the developer a much easier way to write parallelizable (i.e. that can run concurrently with itself) code. Functional programming languages are innately parallelizable and some runtimes will run different parts of the program in parallel if possible.

As for option 3 (explicitly), Windows allows you to set the thread affinity (specifying which processors a thread can run on). However, this is usually unnecessary in all but the fastest, response-time critical systems. Effective thread to processor allocation is highly hardware dependent and is very sensitive to other applications running concurrently.

If you want to experiment, create a long running, CPU intensive task like generating a list of prime numbers or creating a Mandelbrot set. Now create two threads in your favorite library and run both threads on a multi-processor machine (in other words, just about anything released in the last few years). Both tasks should complete in roughly the same time because they are run in parallel.


问:
Type systems: nominal vs. structural, explicit vs. implicit
I'm a bit confused about the difference between nominal and structural type systems. Can someone please explain how they differ?

From what I understand:

Nominal: Type compatibility is based on type name.

Structural: Type compatibility is based on the type structure, e.g. in C if 2 variables are struct types with different names but the same structure, then their types are compatible.

Now about explicit and implicit: why is it different from static and dynamic typing? In static typing, types will be explicit while in dynamic typing, types are implicit. Am I right?

答:
In a dynamically typed system, values have types at runtime but variables and functions do not. In a statically typed system, variables and functions have types known and checked at compile-time. E.g. in Python x can be anything; at runtime, if it is 1 it's a number and if it is "foo", it's a string. You would only know which type x was at runtime, and it could be different each time you ran the program. In a language like Java, you would write int x if x was to be a number, and you would know at compile time that x always has to be an int.

"Explicit" and "implicit" types both refer to static type systems. The defining characteristic of a static system is that the types are known at compile time, but not necessarily that they have to be written out. In Java, types are explicit--you have to write them out. So in Java, a method might look something like:

```<code>public int foo(String bar, Object baz) { ... }
</code>```

The types are both known at compile time (static) and written out (explicit). However, there are also languages that do not force you to write the type out. They can infer the type of a function from its body and how it is used. An example would be OCaml, where you can write something like:

```<code>let foo x = x + 1
</code>```

Since you used +, OCaml can figure out that x has to be an int all on its own. So the type of foo (foo : int -> int) is known at compile time, just like the Java example. It is entirely static. However, since the compiler can figure out what the types have to be on its own, you do not have to write them out yourself: they're implicit.

In short: whether a type system is explicit or implicit is a property of static systems. It is a completely different question from whether a type system is dynamic or static.

Often, you have type systems that are at times explicit and at times implicit.

For example, I believe C# lets you infer types using the var keyword. So instead of writing int x = 10, you can write var x = 10 and the compiler figures out that x has to be an int. C++ does something similar with auto. These systems are usually explicit but have some inference.

On the flipside, there are systems that are usually implicit but sometimes force you to write out a type signature. Haskell is a great example. Most of the time, Haskell can infer the types for you. However, sometimes you can write code that is ambiguous like show . read, where Haskell cannot figure out the types on its own. In this case, you would be forced to explicitly specify the type of either show or read. Additionally, some more advanced features of the type system (like rank-n polymorphism) make inference undecidable--that is, it is not guaranteed to halt. This means that code using this feature often needs explicit type signatures.

Body:
In a dynamically typed system, values have types at runtime but variables and functions do not. In a statically typed system, variables and functions have types known and checked at compile-time. E.g. in Python x can be anything; at runtime, if it is 1 it's a number and if it is "foo", it's a string. You would only know which type x was at runtime, and it could be different each time you ran the program. In a language like Java, you would write int x if x was to be a number, and you would know at compile time that x always has to be an int.

"Explicit" and "implicit" types both refer to static type systems. The defining characteristic of a static system is that the types are known at compile time, but not necessarily that they have to be written out. In Java, types are explicit--you have to write them out. So in Java, a method might look something like:

public int foo(String bar, Object baz) { ... }

The types are both known at compile time (static) and written out (explicit). However, there are also languages that do not force you to write the type out. They can infer the type of a function from its body and how it is used. An example would be OCaml, where you can write something like:

let foo x = x + 1

Since you used +, OCaml can figure out that x has to be an int all on its own. So the type of foo (foo : int -> int) is known at compile time, just like the Java example. It is entirely static. However, since the compiler can figure out what the types have to be on its own, you do not have to write them out yourself: they're implicit.

In short: whether a type system is explicit or implicit is a property of static systems. It is a completely different question from whether a type system is dynamic or static.

Often, you have type systems that are at times explicit and at times implicit.

For example, I believe C# lets you infer types using the var keyword. So instead of writing int x = 10, you can write var x = 10 and the compiler figures out that x has to be an int. C++ does something similar with auto. These systems are usually explicit but have some inference.

On the flipside, there are systems that are usually implicit but sometimes force you to write out a type signature. Haskell is a great example. Most of the time, Haskell can infer the types for you. However, sometimes you can write code that is ambiguous like show . read, where Haskell cannot figure out the types on its own. In this case, you would be forced to explicitly specify the type of either show or read. Additionally, some more advanced features of the type system (like rank-n polymorphism) make inference undecidable--that is, it is not guaranteed to halt. This means that code using this feature often needs explicit type signatures.


答:
static vs dynamic describes when types are checked (more or less at compile time or at execution time)

nominal vs structural describes when two types are considered the same.

(And there are variations, the best known is the variant of structural typing which considers only what is used instead of the whole type known as duck typing).

The four combinations (static nominal, static structural, dynamic nominal, dynamic structural) are possible, and languages quite often aren't purely in one class but have aspects which are in others.

For instance, the type systems of C++ is static, mostly nominal but structural when you consider templates (and you can consider part of the problems around concepts in C++ as a conflict between those wanting to from duck typing to a full form of structural typing and those wanting to go to nominal typing). And the use of classes and inheritance allows to use a dynamic and nominal typing in some cases.

Language which a dynamic type systems often are using structural typing, but CLOS as nominal aspects.

Title: Type systems: nominal vs. structural, explicit vs. implicit

Body:
I'm a bit confused about the difference between nominal and structural type systems. Can someone please explain how they differ?

From what I understand:

Nominal: Type compatibility is based on type name.

Structural: Type compatibility is based on the type structure, e.g. in C if 2 variables are struct types with different names but the same structure, then their types are compatible.

Now about explicit and implicit: why is it different from static and dynamic typing? In static typing, types will be explicit while in dynamic typing, types are implicit. Am I right?


问:
Outsourcing Quality Assurance and Testing
I was recently approached by a software firm that specializes in Quality Assurance and Testing.

Up until this point, the developers at our (small) company have been responsible for their own QA for the most part and we've had mixed results. We're at the point where we are ready to hire a full time QA guy, but I was curious as to whether or not other's have used teams like this in the past and what the results were? I'm a bit skeptical but trying to be open-minded.

tl;dr What was your experience with an outsourced QA/testing team? Pros and cons?

答:
QA / Testing has an image problem.  I've done my fair bit of freelance software testing and it has always been valuable to the clients.  I've mostly worked with startups, small software houses and digital agencies.

The need for outside testing help often arises when these companies either have lots of work on or are not quite ready to commit to a full time resource.  Having the ability to call upon a freelance tester at short notice can be extremely valuable.

The problem that many companies face is lack of really good testing and testers.  Getting a good tester on board can really help a project launch confidently.  Getting a bad one will just slow things down.  I run a community of software testers so have come across my fair share of great and bad testers.

Asking a tester a few basic questions should easily filter out the incompetent.

Tell them about your needs and see if they ask questions or recommend a solution straight away.  The good testers will ask the right questions.

Ask them about projects they have recently been involved in. What was their biggest challenge?

Ask for recommendations/references.

Ask them what their best skill is, or what their focus on testing is.  Testing is increasingly becoming specialised, it's hard to become an expert in specific fields.

The best testers will also drill down super quick into important (not superficial) problem areas.

Hope that helps.


问:
Licence all code?
Should every piece of code put online have a licence with it, or should it explicitly mentioned that it is in the public domain?

I'm writing a simple python script that will take a project euler problem number and save a file with the question text as comment. As I was creating the directory and initializing git I added a licence file, which got me thinking is it even necessary to put a licence for something so simple.

So, should every project no matter how trivial have it's licence explicitly mentioned or is it just overkill to put a licence with such small scripts? What is the recommended practice here?

答: I would recommend including a license. It may seem to be unnecessary overhead and not every piece of code is a patent-ridden court case in the making but many people and organizations, large companies in particular, are very careful about other source that they use. Even if is just a quick cut and paste of the BSD or MIT licenses (two short, very open licenses), it just clarifies the author's intentions.</p>

Title: Licence all code?


问:
Is online freelance work viable by American standards?
I've always been curious about trying out online freelance sites... it would be nice to work from home, feel independent, get to choose what I want to work on, get to work on different technologies, lose the PHB, etc.

However I never really gave them a chance because I'm used to American rates and assumed that I would be competing with people from India, Russia, China, etc. that would severely undercut me, and it wouldn't be viable for me.

Am I correct in this assumption or should I give it a shot?  What kind of hourly rate would I be able to expect on short-term programming work?

答:
You are absolutely correct. Most people who look for contractors on freelance sites seem to look for a top-notch quality at a low-most rate.

It's ridiculous. And yes you will be competing with individuals from a lot of countries who seem to have absurdly huge skills portfolios, sometimes it seems they include everything in range from FORTRAN to HTML5.

Re: pay rates - from ($5-$25)/hr.

If you would like to try it out, go and try out just don't quit your day job yet.


问:
How to extract operators from the grammar productions for conflict resolution in LALR parser?
Is there some standardized or widely accepted algorithm for picking up operators in shift/reduce conflicts in LALR parser? The question is naive, my problem is not with implementing my solution, but implementing the solution is already widely used.

For shift the operator is the next input token, for reduce, it depends -- I consider all already read symbols (for given production) declared as operators:

if there is one -- it is the operator

if there are more than one -- I report grammar error

if there is none I use the input token as operator

So for example:

```<code>E ::= E + E
E ::= E * E
E ::= num
</code>```

in case of

```<code>E + E | * num
</code>```

Considering first production I read +, and since it is the only one operator read I pick this one for reduce operator. * is the first token in input so it servers as shift operator.

But is my algorithm correct (i.e. the same as normally used for LALR parsers)? I am especially worried for the point when I have more than 1 operator in the read tokens.

Update

What I NOT am asking here

I don't ask how to resolve shift/reduce conflict once you have the operators. I don't ask how to set the precedence for operators.

What I am asking here

I ask how to extract operators from the "stream" of tokens. Let's say user set some precedence rules for +, - and *. The stack is: - E + E and input is E. Or the stack is E and input is *.

What is the operator for reduce in first case? And in the second? Why?

The stack is really entire right hand side of production.

答: Well, let me grab the first parser I can find that tries to resolve this type of issue automatically and see what it does.  According to http://www.haskell.org/happy/doc/html/sec-conflict-tips.html their default is to choose the shift over a reduce if there is a shift-reduce conflict, and to choose the first rule in the grammar file if there is a reduce-reduce conflict.  (They consider reduce-reduce conflicts to be more serious problems.)</p>


问:
Why is using classic for loops as iterators in stl considered bad?
I've read a couple of articles (example) that consider the classic

for (int ...... size() .... i++) loop bad practice when iterating through for example vectors in stl.  Instead the recommended why is to use vector iterators, i.e. begin, end, etc.

Why is that?

答:
If you know you're operating on a std::vector, and that's never going to change, there's nothing fundamentally wrong with that form of for loop - it's well understood, easy to read, and the compiler will usually do a good job of eliminating the potential cost of calling size() on every loop.

But using a for loop with iterators is more generic. It doesn't require that your container have a size() operator at all, and doesn't require that the container have index-based accessors at all (let alone efficient ones). So your code will be more generic if you go that route.

Other things to consider these days:

The range-base for loop: compact syntax, very few requirements on the container type.

Algorithms like for_each/find/fill/... combined with lambdas if the body of the loop lends itself to it for more functional-style C++.


答:
Structural: Type compatibility is based on the type structure, e.g. in C if 2 variables are struct types with different names but the same structure, then their types are compatible.

This is usually not the case. Structural typing means that B is a subtype of A if it can satisfy A's interface. This usually means having members with the same name; not just the same structure in memory.

This differs from nominative typing that requires super-types to be specified on declaration.


答:
I wouldn't say it's a bad practice, I would say that using an iterator as the better practice.

Why?  Because it's more explicit.  With a normal loop you aren't necessarily using each element, you could be doing a related, but not directly connected operation.  For instance a group chartering program might book X number of tickets because it has a group of size X, where the ticket assignment happens in a later stage.

Using the iterator says that you are going over the collection and doing something with each element.  It conveys the intent of the program better.

Title: Why is using classic for loops as iterators in stl considered bad?

Body:
I've read a couple of articles (example) that consider the classic

for (int ...... size() .... i++) loop bad practice when iterating through for example vectors in stl.  Instead the recommended why is to use vector iterators, i.e. begin, end, etc.

Why is that?


答:
It depends upon the implementation of the collection.  Some collections do not have a fast and ready way to determine the number of elements they contain.  For these collections, calling size() may require a complete iteration through the collection just to tell you how many there are.  Such collections may not have an easy mechanism for random access either.

For example, a collection of "lines in a text file" would require parsing the entire text file just to find the number of lines in it.  If you are just writing a loop to find one line in the file, you actually don't care how many lines the file has, it is needed only to construct a loop in this way.

Such a collection can still be optimized to work well without random access ability.  The hypothetical "lines in a text file" can easily give you each line, in order, quickly and efficiently.  The Iterator object holds the current position, and knows how to get the next value, but nobody had to make an index of all the starting positions of all the lines in the file.

In summary, the iterator approach allows you to iterate such collections without having to know ahead of time how many elements there are, and without needing a fast random access method.


问:
Are there published guidelines, standards, or references that propose more than 80 chars per line?
Despite increases in screen size and resolution, many sources still suggest that code be limited to 80 characters per line. I realize than there are many different opinions on this subject, but I wonder whether there are any standards bodies or influential firms that use other limits (120 characters is a common alternative). For example, are any standards bodies considering "enlarging" the suggested limit? Are there large scale software projects (e.g. at NASA or ESA) that use larger limits?

Note: This is not yet another question about what individuals do, or
  about related opinions, though I'd welcome such information as
  comments. This is a specific question about whether there is any indication that standard practice or recommendations (in the form of
  specific examples) is likely to change soon.

答:
The Android style guide says

Limit Line Length

Each line of text in your code should be at most 100 characters long.

There has been lots of discussion about this rule and the decision remains that 100 characters is the maximum.

Exception: if a comment line contains an example command or a literal URL longer than 100 characters, that line may be longer than 100 characters for ease of cut and paste.

Exception: import lines can go over the limit because humans rarely see them. This also simplifies tool writing.

Chromium also uses these style guidelines, and I believe Guava uses something similar.  All of these are derived at some point from Google's internal style guide which allows 100 columns.  For example, the eclipse rule set from code.google.com/p/google-styleguide includes:

```<code><setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/>
</code>```

Body:
The Android style guide says

Limit Line Length

Each line of text in your code should be at most 100 characters long.

There has been lots of discussion about this rule and the decision remains that 100 characters is the maximum.

Exception: if a comment line contains an example command or a literal URL longer than 100 characters, that line may be longer than 100 characters for ease of cut and paste.

Exception: import lines can go over the limit because humans rarely see them. This also simplifies tool writing.

Chromium also uses these style guidelines, and I believe Guava uses something similar.  All of these are derived at some point from Google's internal style guide which allows 100 columns.  For example, the eclipse rule set from code.google.com/p/google-styleguide includes:

<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/>


答:
Well it really depends on you.  Now that you're in a position to hire people underneath you, you can take one of two central roles:

You can play the role of the project
manager.  You create the time
estimates and organize the
specifications for each thing your
boss wants you to do.  It
essentially distants you a little
from the technical aspect of the
job, and there's a lot of room for
growth (perhaps not in the immediate
future but down the road).  It also
means you're the one who gets fired
when your hirelings don't do the
work on time, so you have to provide
good estimates and reasonable
deadlines.

Or you can play the role of the
technical advisor.  Whenever any
questions of a technical nature arise, you're the man to consult.  It also means you must be able to make educated decisions regarding the direction of technologies used.  As for organization, you leave it to your superiors.  You're only responsible for the time estimates that you claim.  The role of your hirelings is to assist you complete the work that needs to be done and explaining how to do it if they don't know how (which is a subtle difference from handing over the work and letting them make more independent decisions).

Hope that helps.  Do whatever sounds more appealing to you for a job.  Though I would encourage you not to follow the path to the dark side and stay true to your humble beginnings as a programmer.

Title: What should I be responsible for as the first developer in a large scale web project?

Body:
I am the first developer in a large scale web project, in the real estate sector.
I am not an expert in any field, I know the basic of all, programming, databases, something about design and a little bit about SEO, and website optimization / caching. And I have some knowledge about other technologies and stuff that could be required in the project.

So I am a developer, my boss does some drawing on a paper to present me his ideas and then I start programming and I show him the result. Until now there was no problem, but now the web application is large enough, and it lacks a little bit of database optimization and intuitive user interface. Beside the website, the project also has an offline newspaper, and a desktop application that is a reduced version of the online one, both this things are not managed by me, but by other people or developers that are external to the company.

We do not use a collaboration tool for sharing knowledge between the people working on this project, just emails, and we do not use a development methodology, as for the team, we are:

the developer(me),

a designer,

a secretary, and

the boss.

I have the possibility to ask the boss hire the people I want so I can increase the team and have the right person dealing with the right part of the project.

This is the story, the real question is, what should be my attitude towards the project and the company? Should I stay a developer and participate in taking decisions and organizing tasks from time to time to help the boss? Or should I get more serious about this and try to learn project management and implement everything I consider it's required to ensure the quality of the work and final results?

I am the one who best knows what has been developed until now, should I try to organize all the work and the team? Or should I ask my boss to hire some expert to do that?


问:
C++ name mangling and linker symbol resolution
The name mangling schemes of C++ compilers vary, but they are documented publicly.  Why aren't linkers made to decode a mangled symbol from an object file and attempt to find a mangled version via any of the mangling conventions across the other object files/static libraries?  If linkers could do this, wouldn't it help alleviate the problem with C++ libraries that they have to be re-compiled by each compiler to have symbols that can be resolved?

List of mangling documentations I found:

MSVC++ mangling conventions

GCC un-mangler

MSVC++ un-mangling function documentation

LLVM mangle class

答:
I think name mangling mismatch is good as having an uniform name mangling or auto detection name mangler/mangler could create havoc by linking objects of different kind which would otherwise be incomparable in regards to calling convention, structure padding and alignment, and others as mentioned in the previous two questions.

Unfortunately, these are all run-time mismatch and a linker could seldom handle  these scenarios. Thus thankfully, because of name mangling mismatch, linkers can refrain from linking objects of different ABI.


问:
When are RPC-ish approaches more appropriate than REST?
After watching this talk on REST, Reuse and Serendipity by Steve Vinoski, I wonder if there are business cases in greenfield projects for (XML-)RPC-ish setups, that REST could not solve in a better way.

A few RPC-Problems he mentions:

Focus on language (fit the distributed system to the language, not the other way around)

"Make it look local" (and cope with failure and latency as exceptions rather than the rule)

intended to be language-independent, but still has "function calls"  across languages as main ingredient

IDL boilerplate

Illusion of type safety

and a few more ...

Just to dramatize it a bit, some Google Instant results for RPC vs REST:

答:
There are some major advantages of REST when products are scaled up accross a datacenter and you are doing high availability and load balancing.

However, think about a smaller scale project. Needing a webservice that will have a few  hundred requests an hour? WCF deals with all the transport issues. Has a convenient interface for sending objects accross the network, and allows the network connection to be configured, encrypted and certified with zero programming using just the application.config file.


问:
Increase the size of a memory mapped file
I am maintaning a memory mapped file to store my tree like datastructure.

When I'm updating the datastructure ,I got this problem.
The file is limited on it's size and can't be too long or too small.

I have a methods like

```<code> void mapfile_insert_record(RECORD* /* record*/);

 void mapfile_modify_record(RECORD* /* record*/);
</code>```

Both operations could lead to exceed the space which is free on memory file.

How do I overcome this?
What strategy I should use.

calculate whether it requires to exceed the file as a pre-condition on both
methods.

Dynamically exceed it , for a example manage a timer and constantly polling file
for it's free avaliable size and then automatically extend it.

Any ideas or patterns to overcome this problem?

答:
Polling is not a good idea. It would only makes sense if the file is modified by other processes but even then it is better to extend only before insert/modify. Besides, concurrent access is dangerous, as you have to worry about synchronization.

Assuming that your file is never shrunk, you can cache the size of the file, so you only have to check the file size if your current request is outside of the last seen file size.

By the way, you describe version 2) as "Dynamically exceed it...". For me, version 1) also dynamically extends the file. The only difference is that 1) extends only on-demand, whereas 2) extends eagerly.

Unless there are some additional constraints that we do not know I would recommend to keep it simple and stick with version 1).