问:
What does it mean that "language A is written in language B"?
I often hear the term that language A is written in language B. For example, PHP has been written C, C# is written in C++.

Can someone please explain what does that mean and if it is even correct? Does that have anything to do with the compiler of interpreter used by the language?

In addition what are the factors on which the choice of the implementing language is built upon?

答:
You are basically right. If it is said that Ruby is written in C, this means that the language interpreter and parts of the core library are written in C.

So the Ruby interpreter is a C program that takes a text file as input, processes it and then calls functions that are either in another text file (if written in Ruby) or that are compiled C code, as much of the basic functionality that needs to directly access system resources like memory, the file system and more. And some functions that require very high performance.

So you have different parts of a language that can or have to be written in other languages. Nothing would keep you from writing the interpreter in C and the libraries in C++ (though maybe making a few things more difficult). You could even have multiple steps and use a language that is very good at text processing to generate some intermediate data which then is processed by some C code.

Factors for the decision may be just the same as for other complex applications. Performance is one. The ability to write code that can access system resources directly another. So in most cases it has to be a compiled language (though in theory you could write a Ruby interpreter in Python). Availability on different systems is important if you want your language to run on Linux, Win, OS X and others.


问:
Duplication of code (backend and javascript - knockout)
We have a new developer on our team. He seems to be a smart guy (he just came in so I cannot really judge). He started with implementing some small enhancements on the project (MVC3 web application using Javascript with jQuery and Knockout).

Let's say we have two values:

```<code>A - quite complex calculation
C - constant
B = A + C
</code>```

On the screen there is value B and user can change it (normal texbox). When B changes, A changes as well because C is constant. So there is linear dependency between A and B.

Now, all the calculations are done in the back-end, but we need to recalculate A as user changes B (in Javascript, I would use knockout). I thought about storing old A and B and when B changes by 10 then we know that new A will be old A + 10. He says this is dirty, because it's duplication of code (we make use of the fact that they are dependent and according to him that should be only in one place in our app). I understand it's not ideal, but making AJAX request after every key press seems a bit too much.

It's a really small thing and I would not post if we haven't had long discussion about it.

How do you deal with such problems? Also I can imagine that using knockout implies lots of calculations on the client side, which very often leads to duplication of the same calculations from the back-end. Does anyone have links to some articles/thoughts on this topic?

答:
In a slightly more complex situation, I decided to use AJAX to make sure the calculation is only done in one place, i.e. on the server. Coding the same calculation twice (on the server in C#, on the browser in JavaScript) is code duplication and might negatively affect maintainance; making use of a property of the calulation like you proposed seems even more dangerous because once someone decides that from now on, the formula has to be

```<code> B = A * 1.05 + C
</code>```

your code will create subtle errors and probably cause a lot of headaches.

ContentLicense: CC BY-SA 3.0

Body:
In a slightly more complex situation, I decided to use AJAX to make sure the calculation is only done in one place, i.e. on the server. Coding the same calculation twice (on the server in C#, on the browser in JavaScript) is code duplication and might negatively affect maintainance; making use of a property of the calulation like you proposed seems even more dangerous because once someone decides that from now on, the formula has to be

 B = A * 1.05 + C

your code will create subtle errors and probably cause a lot of headaches.


答:
Most programming languages fall in two categories: interpreted, and compiled languages.

A compiled language is translated by a compiler into machine code, the language the CPU directly executes step by step. An interpreted language, on the other hand, uses an intermediary, an interpreter, to run the language code. The interpreter is itself another program, usually itself compiled to machine code.

PHP is an interpreted language. You need a separate program to run PHP code, the computer does not run the program directly. That separate program, the PHP interpreter, is itself written in C.

C# is a compiled language, but it is not compiled to machine code. Instead, it is compiled to a specialist language, byte code, to be run on a virtual machine. Java is another example of such a setup. You could see it as a hybrid between compilation and interpretation, where the virtual machine is an interpreter. The virtual machine for C# (the CLI, or Common Language Infrastructure) is written in C++.

Other examples are:

Python: The Python interpreter compiles Python code to Python bytecode, then interprets the bytecode. The interpreter itself is written in C. New implementations have since been added, including one that compiles python to run on the same CLI used for C#, called IronPython, and one that runs on the Java virtual machine, Jython. To complete the circle, there is a Python version written in (a subset of) Python, PyPy.

Ruby: Ruby started out as a pure interpreted language, but the most recent version switched to using bytecode. For Ruby, too, there is a project that compiles to the CLI, named IronRuby, and one for the Java VM, JRuby.

Title: What does it mean that "language A is written in language B"?

Body:
I often hear the term that language A is written in language B. For example, PHP has been written C, C# is written in C++.

Can someone please explain what does that mean and if it is even correct? Does that have anything to do with the compiler of interpreter used by the language?

In addition what are the factors on which the choice of the implementing language is built upon?

ContentLicense: CC BY-SA 4.0


答:
It simply means that most of the core of language A is written in language B. What "core of language A" might differ from language to language, but in general terms you guess right, it means it's compiler or interpreter. The deciding factor on picking a language to write another language in is, as with almost every project, what languages the developers are more familiar with.

That said, "language A is written in language B" is an oversimplification for most modern languages. If we take Python as an example, while the reference implementation, CPython, was indeed written in C there are implementations written in other languages, like Jython (written in Java), IronPython (written in C#), PyPy (writen in Python), CLPython (written in Common Lisp), Stackless Python (written in C and Python) and Unladen Swallow (written in C++).

A programming language is a definition, and as the Python example shows, there aren't really any restrictions on what languages its compiler, interpreter and libraries can be written in. And of course it's also possible for a language to be written in itself, through a process called bootstrapping.


答:
From the perspective of using a programming language, a programming language is just a program. It might be a compiler, or it might be an interpreter, or it might be some sort of virtual machine. All of those things are just computer programs, and thus can be written in any language.

So, if you wanted to create your own version of PHP, you might start out with whatever language you are most fluent in. You would then write a program that can read PHP-formatted code and do whatever the PHP spec says your program should do. You are thus creating the PHP language in language X.


答:
A very similar phrasing with completely different meaning is "writing language A in language B", e.g. "writing C in Java".

This describes code that is syntactically correct in one language, but uses structures, idioms and conventions from another language. In the "writing C in Java" example, signs of this would be declaring all local variables on top of each method, using integer constants instead of enums, using identifiers_with_underscores, etc.

Typically this happens when someone has worked with one language for a long time (especially when they have worked only with that language) and is very new to the current language (or not interested in writing clean code).


问:
How to keep the trunk stable when tests take a long time?
We have three sets of test suites:

A "small" suite, taking only a couple of hours to run

A "medium" suite that takes multiple hours, usually ran every night (nightly)

A "large" suite that takes a week+ to run

We also have a bunch of shorter test suites, but I'm not focusing on them here.

The current methodology is to run the small suite before each commit to the trunk. Then, the medium suite runs every night, and if in the morning it turned out it failed, we try to isolate which of yesterday's commits was to blame, rollback that commit and retry the tests. A similar process, only at a weekly instead of nightly frequency, is done for the large suite.

Unfortunately, the medium suite does fail pretty frequently. That means that the trunk is often unstable, which is extremely annoying when you want to make modifications and test them. It's annoying because when I check out from the trunk, I cannot know for certain it's stable, and if a test fails I cannot know for certain if it's my fault or not.

My question is, is there some known methodology for handling these kinds of situations in a way which will leave the trunk always in top shape? e.g. "commit into a special precommit branch which will then periodically update the trunk every time the nightly passes".

And does it matter if it's a centralized source control system like SVN or a distributed one like git?

By the way I am a junior developer with a limited ability to change things, I'm just trying to understand if there's a way to handle this pain I am experiencing.

答:
The failing medium tests: Is it true that most of the time the same tests fail?

If there is a failure are there always the same related tests that fail?

If true: May be you can selectively pick some medium tests that often fail (one test for every class of error) and execute them within the small set.

Are most of the tests integration-tests that use a real database? If so is it possible to replace them with a unittest that has a mocked-database?


问:
How to name an subclass that add a minor, detailed thing?
What is the most concise (yet descriptive) way of naming a subclass that only add a specific minor thing to the parent? I encountered this case a lot in WPF, where sometime I have to add a small functionality to an out-of-the-box control for specific cases.

Example: TreeView doesn't change the SelectedItem on right-click, but I have to make one that does in my application.

Some possible names are

TreeViewThatChangesSelectedItemOnRightClick (way too wordy and
maybe difficult to read because there is so many words concantenated
together)

TreeView_SelectedItemChangesOnRightClick (slightly
more readable, but still too wordy and the underscore also breaks the normal
convention for class names)

TreeViewThatChangesSIOnRC (non-obvious
acronym),

ExtendedTreeView (more concise, but doesn't describe what
it is doing. Besides, I already found a class called this in the
library, that I don't want to use/modify in my application).

LouisTreeView, MyTreeView, etc. (doesn't describe what it is doing).

It seems that I can't find a name which sounds right. What do you do in situation like this?

答:
If your application is supposed to use both the original, non-right-sensitive version and your own improved version, then the name absolutely has to express  what the derived class does. Otherwise everyone navigating the code base will go nuts understanding what the difference is and where it applies or not. Something like RightSensitiveTreeView is probably your best bet, even though it is already clumsy and will become much more clumsy if you ever need to express more than one extended behaviour.

But if you use the extended version exclusively, there is little harm in using a euphonious, even proud name like LouisTreeView - it will stay accurate even if you add more enhancements later, since those presumably will also be used everywhere. The only thing you should not do is reuse the original name exactly and disambiguate by putting it into a different package path. That is just asking for confusion.

(Disclaimer: proverbially, there are only two really hard things in computer science - cache invalidation and naming things. This is my opinion, but people will probably come forward with very different views.)


问:
C++ is easy once you know PHP
I was at work last week and one of our "lead developers" (who said he has programmed C++ before, but I don't believe him) was talking about C++ and how our team of developers who only know PHP would not have a hard time at all learning C++.

My first reaction was pure shock and then I laughed at his comment. He gave me a bad look and i asked if he was serious. Me personally I program a lot of C and C++ for mostly school projects and coding competitions. I don't think it's at all like PHP. I asked him why they were the same and he could not give me an answer (he doesn't know C++ at all I was thinking). Then I said "OK, yeah they both use curly braces and have conditional statements. But C++ you have to worry about memory management and all the easy to use built in functions in PHP, for example the array functions, are non-existent in C++. You actually have to know the algorithms behind them.". There are some great C++ libraries (STL, Boost) that will make your life easier but C++ is like PHP, come on!

If you already know one language it will make it a little easier to learn another because you will already be good at boolean login (if this then that) or looping but there is just so much more to C++ than PHP. Like you have to compile the language and actually have to define what type of variable you are using and returning from functions.

What do you think?

EDIT: Actually what he said was "C++ is not much different than PHP"

答:
There is programming as a skill independent of any language, and then there is knowledge of a specific language's constructs, libraries, and conventions.  You can be great at the former and suck at the latter (for a specific language) or vice versa.

Without knowing anything about your team, we can't say whether they'd be good at C++.  And there are various ways to write C++ too, as some people get themselves stuck 20 years ago without the stdlib, boost, other libraries, or even without compiler features everyone else takes for granted.

However, there are a lot of problems with C++, and as someone that both loves and hates it, yet still has it for the highest count on SO, I'll be the first to admit it really sucks at times.  Then again, the more you know about a language, the more you find out how it sucks.  If there's any tool where you consider yourself an expert, yet you can't name at least 10 ways it's broken, inadequate, or you just hate it... :)

ContentLicense: CC BY-SA 2.5

Title: C++ is easy once you know PHP

OwnerDisplayName: Roger Pate


答:
If it's just generic functionality that will probably be wanted anytime you use such a control, such as changing items on right-click, I usually just add Ex to the end of my class to signify it's an extended version of the class. For example, TreeViewEx or TabControlEx

The actual word being used doesn't really matter, but I do try and keep it consistent throughout all my customized classes, and generic so I can add other functionality later if needed without having to rename the class (Ex, Extended, Custom, etc).

Of course, if the control does something specialized that is unlikely to be wanted in other cases when using that control, then I'll add a more descriptive suffix to the control name instead.

I also add the word at the end of the control name (TreeViewCustom instead of CustomTreeView) so it pops up in auto-complete when you try and use the standard control.

Title: How to name an subclass that add a minor, detailed thing?

Body:
What is the most concise (yet descriptive) way of naming a subclass that only add a specific minor thing to the parent? I encountered this case a lot in WPF, where sometime I have to add a small functionality to an out-of-the-box control for specific cases.

Example: TreeView doesn't change the SelectedItem on right-click, but I have to make one that does in my application.

Some possible names are

TreeViewThatChangesSelectedItemOnRightClick (way too wordy and
maybe difficult to read because there is so many words concantenated
together)

TreeView_SelectedItemChangesOnRightClick (slightly
more readable, but still too wordy and the underscore also breaks the normal
convention for class names)

TreeViewThatChangesSIOnRC (non-obvious
acronym),

ExtendedTreeView (more concise, but doesn't describe what
it is doing. Besides, I already found a class called this in the
library, that I don't want to use/modify in my application).

LouisTreeView, MyTreeView, etc. (doesn't describe what it is doing).

It seems that I can't find a name which sounds right. What do you do in situation like this?


问:
Should adapters or wrappers be unit tested?
Suppose that I have a class that implements some logic:

```<code>public MyLogicImpl implements MyLogic {
    public void myLogicMethod() {
        //my logic here
    }
}
</code>```

and somewhere else a test class:

```<code>public MyLogicImplTest {
    @Test
    public void testMyLogicMethod() {
        /test my logic
    }
}
</code>```

I also have:

```<code>@WebService
public MyWebServices class {
    @Inject
    private MyLogic myLogic;

    @WebMethod
    public void myLogicWebMethod() {
        myLogic.myLogicMethod();
    }
}
</code>```

Should there be a test unit for myLogicWebMethod or should the testing for it be handled in integration testing.

答:
```<code> > Should adapters or wrappers be unit tested
</code>```

yes the main responsibility of the wrapper should be unit tested through the wrapper

no not the complete functionality should be unit tested through the wrapper

Here is an example that illustrates what i mean:

if you have a

class MyComplicatedBusinessCalculation and

class MyPermissionManager and

webservice MyComplicatedBusinessCalculationWebservice that combines calculation and permissions

you should have full unittests for calculation and full unittests for permissions.

For the webservice you should only have to test that for every webservice method the corresponding calculation is called and that permissioncheck is applied.

There is no need to test through webservice the combinations of permissions are correct since you already have tested these with the permission-unittests.

There is no need to test through webservice the different edgecases for  businesscalculations  since you already have tested these with the calculation-unittests.

I would not recomment to test the underlying classes through the webservice.

Example:

If MyPermissionManager changes only the MyPermissionManager-Unittests must be updated but not the webservice-tests

Body:
 > Should adapters or wrappers be unit tested

yes the main responsibility of the wrapper should be unit tested through the wrapper

no not the complete functionality should be unit tested through the wrapper

Here is an example that illustrates what i mean:

if you have a

class MyComplicatedBusinessCalculation and

class MyPermissionManager and

webservice MyComplicatedBusinessCalculationWebservice that combines calculation and permissions

you should have full unittests for calculation and full unittests for permissions.

For the webservice you should only have to test that for every webservice method the corresponding calculation is called and that permissioncheck is applied.

There is no need to test through webservice the combinations of permissions are correct since you already have tested these with the permission-unittests.

There is no need to test through webservice the different edgecases for  businesscalculations  since you already have tested these with the calculation-unittests.

I would not recomment to test the underlying classes through the webservice.

Example:

If MyPermissionManager changes only the MyPermissionManager-Unittests must be updated but not the webservice-tests


问:
Is Google Closure a true compiler?
This question is inspired by the debate in the comments on this Stack Overflow question. The Google Closure Compiler documentation states the following (emphasis added):

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript.

However, Wikipedia gives the following definition of a "compiler":

A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language... A language rewriter is usually a program that translates the form of expressions without a change of language.

Based on that, I would say that Google Closure is not a compiler. But the fact that Google explicitly state that it is in fact a "true compiler" makes me wonder if there's more to it. Is Google Closure really a JavaScript compiler?

答:
It's semantics in my opinion. In the traditional sense, it is not a compiler. However, in the same Wikipedia link, it says

A compiler is likely to perform many or all of the following
  operations: lexical analysis, preprocessing, parsing, semantic
  analysis (Syntax-directed translation), code generation, and code
  optimization.

Closure performs some or all of those operations.

A little farther down in the Wikipedia article

However, in practice there is rarely anything about a language that
  requires it to be exclusively compiled or exclusively interpreted,
  although it is possible to design languages that rely on
  re-interpretation at run time.

That being said, my guess is that it was easier to call it the "Closure Compiler" rather than the "Closure Optimizer" because really it is just optimizing JavaScript for browsers, not necessary translating it into another language or bytecode.

Closure Compiler as a noun is a non-sequitur.

Title: Is Google Closure a true compiler?


答:
Based on that, I would say that Google Closure is not a compiler.

Well yes ... but that assumes that Wikipedia is authoritative on this point.

And as a counter to the Wikipedia definition, consider some dictionary definitions (from http://www.thefreedictionary.com/compiler):

2) (Computer Science) - A program that translates another program written in a high-level language into machine language so that it can be executed.

2) (Electronics & Computer Science / Computer Science) a computer program by which a high-level programming language, such as COBOL or FORTRAN, is converted into machine language that can be acted upon by a computer.

A computer program associated with certain programming languages that converts the instructions written in those languages into machine code that can later be executed directly by a computer.

Granted these definitions are all a bit old-fashioned, but it does illustrate that there is no "one true meaning" ... and indeed that meanings of terms like "compiler" change over time.  (And, IMO that is just fine, because we don't really need a precise definition for this case.)

Debating whether the Closure compiler is a "true compiler" or not is (IMO) not a fruitful activity.  It would be more useful to understand what the Google folks mean by "true compiler" ... in that context.

Title: Is Google Closure a true compiler?

Body:
This question is inspired by the debate in the comments on this Stack Overflow question. The Google Closure Compiler documentation states the following (emphasis added):

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript.

However, Wikipedia gives the following definition of a "compiler":

A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language... A language rewriter is usually a program that translates the form of expressions without a change of language.

Based on that, I would say that Google Closure is not a compiler. But the fact that Google explicitly state that it is in fact a "true compiler" makes me wonder if there's more to it. Is Google Closure really a JavaScript compiler?


答:
The Closure Compiler is a minifier, an optimiser and a validator all-in-one. That kind of puts it in its own category, because you're correct that a compiler should at least take something that won't run in its current form and turn it into something that will (take TypeScript for an ECMAScript-based example).

But do you blame Google for stretching the terminology? What else were they going to call it? Google Minifier? No, it's more than that, and there are hundreds of those out there. Google Optimiser? It's way more than that. Google Validator? No, it's way more than that too.

So the choice is

Call it Google Closure Foogle and introduce a whole new otherwise-meaningless word into the lexicon.

Call it Google Closure Minoptivalidator, which is clearer in intent but harder to remember.

Call it Google Closure Compiler, which is pretty close to the truth.

It does everything you would expect a compiler to do, with only a semantic difference. And, in the end, all words are defined by their usage, to some extent. So if Google can convince people to call this a compiler, the definition of compiler changes slightly. Certainly not in any way that will cause a problem.

Or, to come back to the earlier example, can you find anything significant about TypeScript that allows it to be called a "true compiler", while Google Closure Compiler should be restricted to "almost a compiler"?

Title: Is Google Closure a true compiler?


答: Sounds like you called out a bluffer (I refer to the fact that he couldn't back up his statement) :). This is no bad thing as long as it's done politely, respectfully and with technical merit.</p>

Title: C++ is easy once you know PHP

Body:
I was at work last week and one of our "lead developers" (who said he has programmed C++ before, but I don't believe him) was talking about C++ and how our team of developers who only know PHP would not have a hard time at all learning C++.

My first reaction was pure shock and then I laughed at his comment. He gave me a bad look and i asked if he was serious. Me personally I program a lot of C and C++ for mostly school projects and coding competitions. I don't think it's at all like PHP. I asked him why they were the same and he could not give me an answer (he doesn't know C++ at all I was thinking). Then I said "OK, yeah they both use curly braces and have conditional statements. But C++ you have to worry about memory management and all the easy to use built in functions in PHP, for example the array functions, are non-existent in C++. You actually have to know the algorithms behind them.". There are some great C++ libraries (STL, Boost) that will make your life easier but C++ is like PHP, come on!

If you already know one language it will make it a little easier to learn another because you will already be good at boolean login (if this then that) or looping but there is just so much more to C++ than PHP. Like you have to compile the language and actually have to define what type of variable you are using and returning from functions.

What do you think?

EDIT: Actually what he said was "C++ is not much different than PHP"


问:
Extracting color profile information from JPEG files
I'm trying to look up info about reading JPEG's color profile info and to my surprise there's very little open specific how-to information on that regard, but rather lots of general explanation on what it is.

Does anyone know how to find and read the color profile information from JPEG?

答:
Independent JPEG ground - http://www.ijg.org/  is the authority (reference) code for JPEG decoding and JPEG encoding encapsuled as libjpeg; which is also the most portable and default library for JPEG in most platforms.

You should try to dig into libjpeg for this.

Specifically, there is an ambiguity in the native representation of JPEG's color space. As IJG's documentation describes:

The JPEG standard itself is "color blind" and doesn't specify any
  particular color space.  It is customary to convert color data to a
  luminance/chrominance color space before compressing, since this
  permits greater compression.  The existing de-facto JPEG file format
  standards specify YCbCr or grayscale data (JFIF), or grayscale, RGB,
  YCbCr, CMYK, or YCCK (Adobe).  For special applications such as
  multispectral images, other color spaces can be used, but it must be
  understood that such files will be unportable.

Different applications actually have a different ways to represent this which is actually a problem. See this: http://photo.net/digital-darkroom-forum/00TVcQ

However, it doesn't mean that things are absolutely broken. The information related to color space is usually in the file format, namely JFIF or EXIF.

JFIF

For JFIF (Reference 1:  OR Reference 2) - there is a notion of default color space.

From the spec:

Standard color space The color space to be used is YCbCr as defined by CCIR 601 (256 levels). The RGB components calculated by linear
  conversion from YCbCr shall not be gamma corrected (gamma = 1.0). If
  only one component is used, that component shall be Y.

The conversion of YCbCr to RGB and vice-versa is also given in the same document. You can also checkout the libjpeg library (IJG) for actual code on this.

EXIF:

In EXIF,

The color space information tag (ColorSpace) is always recorded as the
  color space specifier. Normally sRGB (=1) is used to define the color
  space based on the PC monitor conditions and environment. If a color
  space other than sRGB is used, Uncalibrated (=FFFF.H) is set.

EXIF, allows to specify your custom color table and gamma levels through alternative set of tags including: TransferFunction, white point, PrimaryChromaticities, ReferenceBlackWhite and YCbCrCoefficients.

See. Appendix E, "Color Space Guidelines,"
Reference: http://www.exif.org/Exif2-1.PDF

See also,

JPEG Files -wikipedia

JFIF, JPEG File Interchange Format, Version 1.02

Embedding ICC profiles in image file formats


问:
Inventory Consignment Flow
Not sure whether this is the right place to ask this question, but here goes..

Currently I have requirement to add support for consignment transaction in our inventory module. I have a very limited understanding of what consignment means in inventory, i.e.

Customer get stocks/products from Seller without actually buying them, the product just resides in the Customer's inventory and it's still owned by the Seller. Only when the Customer actually buy the stocks then only will the ownership of the stock is transferred.

The issue is i can't imagine how the data will be presented to both the Customer and the Seller. What i know is that i would need to deduct the stock from the Seller's inventory when the Customer raise a request to get the stock through consignment, but what about the 'ownership' of the stocks/products? Does that mean i would need to create another column in my table to state that for each inventory it is owned by who?

Anywhere i can get information on how i should work out an inventory module like this?

Thanks.

答:
Fist, I must implore you not to build this system from scratch.  It is a much more complex project than it seems.  Please consider using an open source eCommerce platform, order management system, and product catalog.  Check out the Apache Open for Business Project.  There are many others - most want you to pay them consulting fees.

Many order management software packages often model this using the concepts of supply and demand.  You have some high level entities, such as Product (for example, FancyBrand Men's V-neck undershirts), Item (for example, FancyBrand Men's undershirt in size Medium and color white), Supplier (the company who sells the item to the retailer), Vendor (the company who actually makes the item, who is not necessarily the same as the Supplier).  A Retailer could buy Product Foo, which is produced by Vendor Fooz, from Supplier Bar today and then from Supplier Baz tomorrow.  Or Foo could by supplied by both Bar and Baz at the same time (hint: don't use 1 column for the Supplier-Product relationship).

When Supplier Bar sends/allocates N more Foo Items to the Retailer, Retailer should increase its Supply of Item Foo by N.  You can also attach a "type" to the Supply that you add.

When a Customer begins the process of purchasing M Foo Items, you typically increase the demand against Foo by M.  After the transaction is complete (credit card has been validated, fraud check has completed, etc.) Retailer decrements both Supply and Demand by M.

I would also avoid thinking about the Supplier's inventory level for Foo.  The Retailer knows nothing about the Supplier's inventory.  The Retailer only knows how many Foo items are in the Retailer's inventory, and of those, how many came from Supplier Bar or Supplier Baz.  Even if the Retailer hasn't paid the Supplier for the item, and even if the Supplier never sends the items to the Retailer (maybe because the Supplier ships directly to the customer after the Retailer handles the transaction), if the Retailer can sell those items to its customers, then those items are part of the Retailer's Supply.

There are 2 ways a Supplier might want to be paid: on each transaction, or periodically.  If the Supplier wants to be paid every X days for whatever items the Retailer has sold.  So you need to be able to answer the question: "How many Foo items from Supplier Baz did I sell in the last X days?"  If the Supplier wants to be paid on each transaction, you still need to know which Foo Item in each transaction was sent/allocated from Supplier Baz.

Again - don't build this all by yourself!

But if you insist, I've seen consignment modeled 2 different ways and both worked fine.  One way is to model all the consigned inventory as a separate distribution center.  For example, if you have 45 physical stores and 5 warehouses, you'd have 50 distribution centers.  You can treat all consigned goods as being held in a separate distribution center.  This works particularly well if your suppliers don't actually send you the product, and the product is in fact shipped to the consumer from the supplier.

The other way I've seen this done is to use a type attribute on your Supply.  Some example types could be "good condition", "slightly damaged", "safety", or in your case, "purchased" vs. "consigned."  Therefore you could have rows like the following in your Supply entity:

```<code>id  sku         quantity  type
--  ----------  --------  ---------
1   foo-item1   10        consigned
2   foo-item2   5         purchased
3   fooz-item1  20        consigned
</code>```

Note that the sku must uniquely identify an item and if you have multiple suppliers for that item, then you need to be able to navigate from the sku back to the supplier.

And you can also find a reasonable open source data model for invoices and oders.

Title: Inventory Consignment Flow

Body:
Fist, I must implore you not to build this system from scratch.  It is a much more complex project than it seems.  Please consider using an open source eCommerce platform, order management system, and product catalog.  Check out the Apache Open for Business Project.  There are many others - most want you to pay them consulting fees.

Many order management software packages often model this using the concepts of supply and demand.  You have some high level entities, such as Product (for example, FancyBrand Men's V-neck undershirts), Item (for example, FancyBrand Men's undershirt in size Medium and color white), Supplier (the company who sells the item to the retailer), Vendor (the company who actually makes the item, who is not necessarily the same as the Supplier).  A Retailer could buy Product Foo, which is produced by Vendor Fooz, from Supplier Bar today and then from Supplier Baz tomorrow.  Or Foo could by supplied by both Bar and Baz at the same time (hint: don't use 1 column for the Supplier-Product relationship).

When Supplier Bar sends/allocates N more Foo Items to the Retailer, Retailer should increase its Supply of Item Foo by N.  You can also attach a "type" to the Supply that you add.

When a Customer begins the process of purchasing M Foo Items, you typically increase the demand against Foo by M.  After the transaction is complete (credit card has been validated, fraud check has completed, etc.) Retailer decrements both Supply and Demand by M.

I would also avoid thinking about the Supplier's inventory level for Foo.  The Retailer knows nothing about the Supplier's inventory.  The Retailer only knows how many Foo items are in the Retailer's inventory, and of those, how many came from Supplier Bar or Supplier Baz.  Even if the Retailer hasn't paid the Supplier for the item, and even if the Supplier never sends the items to the Retailer (maybe because the Supplier ships directly to the customer after the Retailer handles the transaction), if the Retailer can sell those items to its customers, then those items are part of the Retailer's Supply.

There are 2 ways a Supplier might want to be paid: on each transaction, or periodically.  If the Supplier wants to be paid every X days for whatever items the Retailer has sold.  So you need to be able to answer the question: "How many Foo items from Supplier Baz did I sell in the last X days?"  If the Supplier wants to be paid on each transaction, you still need to know which Foo Item in each transaction was sent/allocated from Supplier Baz.

Again - don't build this all by yourself!

But if you insist, I've seen consignment modeled 2 different ways and both worked fine.  One way is to model all the consigned inventory as a separate distribution center.  For example, if you have 45 physical stores and 5 warehouses, you'd have 50 distribution centers.  You can treat all consigned goods as being held in a separate distribution center.  This works particularly well if your suppliers don't actually send you the product, and the product is in fact shipped to the consumer from the supplier.

The other way I've seen this done is to use a type attribute on your Supply.  Some example types could be "good condition", "slightly damaged", "safety", or in your case, "purchased" vs. "consigned."  Therefore you could have rows like the following in your Supply entity:

id  sku         quantity  type
--  ----------  --------  ---------
1   foo-item1   10        consigned
2   foo-item2   5         purchased
3   fooz-item1  20        consigned

Note that the sku must uniquely identify an item and if you have multiple suppliers for that item, then you need to be able to navigate from the sku back to the supplier.

And you can also find a reasonable open source data model for invoices and oders.


答:
For a single class like your TreeView subclass that just adds a small amount of functionality, it's probably not necessary to try too hard to make a good name.  Personally I would make do with CustomTreeView or similar.  Then the actual "Custom" bit can be described in some docs or comments above the class definition.

However suppose you have several of these classes, each extending TreeView in some small way.  Then a generic name like the above wouldn't cut it.  You could attempt to name each customisation descriptively but then you things could go south - "RightSensitiveTreeView" for example is a bit lengthy for a class name.

If you want to add bits of functionality to a class, consider this approach:  Create one subclass in your application (or personal/company library) and call it CustomTreeView or whatever.  Make it work identically to TreeView by default.  Add properties/methods that enable/disable the extended functionality - say, a selectOnRightClick property would do nicely for your extension.  Then you can add as many customisations as you like to your one subclass, and all code that uses your subclass automatically has access to those customisations, with minimal change to code.


问:
Progressbar patterns (Eclipse)
I've struggled quite a bit with Eclipse and progress-monitors to try to have good progressbars which report useful progress information to the user. Inevitably the code gets cluttered with lots of things like

```<code>if (monitor.isCancelled())
    return;

...

lengthyMethodCall(monitor.newChild(10));
</code>```

and all over the place I need to pass a IProgressMonitor as an argument to my methods. This is bad, for several reasons:

The code gets cluttered with lots of code which is not relevant to what the function actually does.

I need to manually guesstimate which parts of the code takes time, and which parts do not.

It interacts badly with automated tests; where much of the information which goes into a progressbar instead should be logged for later inspection.

Is there a way out of this? Are there tools which can help me out with one or more of these problems? Should I be looking at Aspect-Oriented Programming tools, or are there other alternatives?

答:
The code gets cluttered with lots of code which is not relevant to what the function actually does.

Sounds like Java run time exceptions. :-)  I guess one way out of the IProgressMonitor mess is to wrap up all of your "batch" processing into Jobs (org.eclipse.core.runtime.jobs).

I need to manually guesstimate which parts of the code takes time, and which parts do not.

Not really.  You can wrap any code in a Job.  If it executes quickly, you won't even see the progress monitor popup.  If it takes time to process, then it should be a Job anyway.

It interacts badly with automated tests; where much of the information which goes into a progressbar instead should be logged for later inspection.

ratchet freak already answered this in his comment.  You can write your own implementation of IProgressMonitor that logs the information you wish.

Title: Progressbar patterns (Eclipse)


答:
The only way to fix the root cause of the instability is to decouple the code so changes are more isolated, as other answers have suggested.

However, as an individual developer, if you want a more stable build for you personally to work on, that's relatively easy to solve.  Instead of working off of the tip, you only pull the last build that passed the overnight test suite into your working tree.  If you can create feature branches for each change, then branch off of the last stable build.

Yes, your tree will be a few days behind, but most of the time that doesn't matter.  Do your work against the stable build, so you know your changes are the ones that broke any tests, then before you check in, update to the latest and do your normal integration.  Then after you check in, back up to the last stable build again.

You still have to do the messy integration work, but what I like about this method is it isolates the integration work to a time more convenient for me, and gives me a stable code base for development when it isn't convenient.  I have a much better idea when it's my changes that likely broke the build versus someone else's.

Title: How to keep the trunk stable when tests take a long time?

Body:
We have three sets of test suites:

A "small" suite, taking only a couple of hours to run

A "medium" suite that takes multiple hours, usually ran every night (nightly)

A "large" suite that takes a week+ to run

We also have a bunch of shorter test suites, but I'm not focusing on them here.

The current methodology is to run the small suite before each commit to the trunk. Then, the medium suite runs every night, and if in the morning it turned out it failed, we try to isolate which of yesterday's commits was to blame, rollback that commit and retry the tests. A similar process, only at a weekly instead of nightly frequency, is done for the large suite.

Unfortunately, the medium suite does fail pretty frequently. That means that the trunk is often unstable, which is extremely annoying when you want to make modifications and test them. It's annoying because when I check out from the trunk, I cannot know for certain it's stable, and if a test fails I cannot know for certain if it's my fault or not.

My question is, is there some known methodology for handling these kinds of situations in a way which will leave the trunk always in top shape? e.g. "commit into a special precommit branch which will then periodically update the trunk every time the nightly passes".

And does it matter if it's a centralized source control system like SVN or a distributed one like git?

By the way I am a junior developer with a limited ability to change things, I'm just trying to understand if there's a way to handle this pain I am experiencing.


答:
I think your "lead developer" should consider another line of work. Seriously, though, this usenet post I saw a year ago about C++ says it all:

I don't know about you, but there's something really scary to me about a
language where copying state from one object to another is this
complicated.  By now, I suspect at least a dozen or two programmers have
contributed something new to this discussion. If it takes this many
programmers to write a simple assignment operator, think how complicated
writing code that actually does something meaningful must be!

Title: C++ is easy once you know PHP


答:
The key thing you are taking for granted in your question is that all commits must pass tests.  While this is a nice rule to follow and it seems to make some sense, sometimes it's not practical.  Your case is an example (although MadKeithV does make a point), and I can imagine keeping a VCS branch so pristine could be difficult if there isn't sufficient cooperation among devlopers.

In reality what you want is to somehow know which commits pass or fail.  A "pre-commit branch" as you suggested would work, but that might require extra effort from developers when they make commits, which might be hard to sell.

A similar approach that could be easier is to leave the trunk for people to break as they please, and have a branch for commits that aren't broken.  An automated script could go through commits as they are made to the trunk, run the tests on them and add them to the branch if they pass.

Or you could be absurdly simplistic and have a script that lists the passing commits in a text file (which may or may not itself be version controlled).

Or have a batch system that accepts requests for branches/revisions to test (from anywhere in the tree), and tests them and commits them to the trunk (or another branch) if they pass.


答:
You need to make your tests run faster, there is no other way to square this circle.

Consider the problem: you want to be sure that when you check out, you have working code. Sure, you can delay commits and do branching until before the release, but that will only delay the onset of the problem until integration. As in, will you have to run the week-long suite after every merge? Methodology is not the solution, the solution is purely technical.

Here is what I suggest:

1) Make the tests as atmomic as possible, and maximize environment reuse.

2) Get a test-suite farm to run them. If rather than 8 big modules you end up with 50, you can spin up a bunch of an Amazon EC2 spot instances and run the whole suite in parallel. I'm sure this will cost some money, but it will save huge amounts of developer time.


问:
Why aren't more desktop apps written with Qt?
As far as I know and have understood in my experience with Qt, it's a very good and easy to learn library. It has a very well designed API and is cross-platform, and these are just two of the many features that make it attractive. I'm interested to know why more programmers don't use Qt. Is there a deficiency which speaks against it? Which feature makes other libraries better than Qt? Is the issue related to licensing?</p>

答:
As people say, each tool fits to each problem and situation...

But if you're C++ programmer, Qt is your framework.
No rival.

We develop a complex medical imaging commercial application,
and Qt holds on.

I don't say that the 'cons' that people say about it are false,
but I have the feeling that they don't have tried Qt for a long time
(its continously improving on each new version...)
And,
mostly all of the issues they comment are not a problem if you take care.

UI platform inconsistency:
 only if you use the UI widgets 'as they are', with no customization or custom art.

Qt preprocessor overload:
 Only if you abuse of signal-slot mechanism, or QObject inheritance,
when there is no really need.

By the way, We still write applications in C#.NET, and been doing it for a long time. So I think I have enouch perspective.

As I said, each tool for each situation,

but Qt is with no doubt a consistent and useful framework.


问:
How to discriminate from two nodes with identical frequencies in a Huffman's tree?
Still on my quest to compress/decompress files with a Java implementation of Huffman's coding (http://en.wikipedia.org/wiki/Huffman_coding) for a school assignment.

From the Wikipedia page, I quote:

Create a leaf node for each symbol and add it to the priority queue.

While there is more than one node in the queue:

Remove the two nodes of highest priority (lowest probability) from the queue

Create a new internal node with these two nodes as children and with probability equal to the sum of the two nodes' probabilities.

Add the new node to the queue.

The remaining node is the root node and the tree is complete.

Now, emphasis:

Remove the two nodes of highest priority (lowest probability) from the queue

Create a new internal node with these two nodes as children and with probability equal to the sum of the two nodes' probabilities.

So I have to take two nodes with the lowest frequency. What if there are multiple nodes with the same low frequency? How do I discriminate which one to use?

The reason I ask this is because Wikipedia has this image:

And I wanted to see if my Huffman's tree was the same. I created a file with the following content:

```<code>aaaaeeee       nnttmmiihhssfffouxprl
</code>```

And this was the result:

Doesn't look so bad. But there clearly are some differences when multiple nodes have the same frequency.

My questions are the following:

What is Wikipedia's image doing to discriminate the nodes with the same frequency?

Is my tree wrong? (Is Wikipedia's image method the one and only answer?)

I guess there is one specific and strict way to do this, because for our school assignment, files that have been compressed by my program should be able to be decompressed by other classmate's programs - so there must be a "standard" or "unique" way to do it. But I'm a bit lost with that.

My code is rather straightforward. It literally just follows Wikipedia's listed steps. The way my code extracts the two nodes with the lowest frequency from the queue is to iterate all nodes and if the current node has a lower frequency than any of the two "smallest" known nodes so far, then it replaces the highest one. Just like that.

答:
For huffman coding, if two nodes have the same frequency then for purposes of compression they are identical, so you can choose one or the other and you will get equal compression.

Try it - set your program up so it can be configured to choose either.  Then run some test data through it and see if the resulting compressed data changes in size.


答: "Language A is written in language B" means that the only implementation of language A (or the only one that is widely used) is the one that is actually a project developed in language B, and the only complete, up-to-date specification of A is the B source code which implements it such that if the documentation and the B program disagree, the B program is usually deemed correct.</p>


问:
Validating User Stories: How much change is too much?
While the core of requirements development and acceptance criteria would ideally take place during the planning meeting in order to create a better estimate, Scrum encourages continuous interaction with the product owner throughout the sprint to validate and refine user stories.

What kind of criteria is used to judge if there is too much change being imposed on a user story mid-sprint?

When is it appropriate to change the requirements of the user story?

When is it appropriate to cancel the user story / sprint in order to re-evaluate and re-estimate a user story in question?

答:
I am in favor of locking down stories fairly quickly in their life cycle. Requirements should be set after less than a day's worth of discussion in most cases. After that point, it's up to the product owner to decide if those requirements are actually something they want.  If they aren't, cancel the story. If they are something they want or partly what they want, complete that story, and create a new story for the following changes.

When in doubt, fight for creating a new story.  Constantly changing the requirements just keeps moving the goal posts for the developers.  That isn't fair to them, and it's bad for morale.


答:
Another question we might ask ourselves is: what constitutes a good user story?

Scrum Breakfast: Getting to Good User Stories suggests that a good user story answers the three questions of Who? What? and Why? and that it can submitted to a team in any order; that it will be easy to estimate, is small, and testable.

User stories that are too vague need more design time and usually end up wasting valuable sprint time. One of the attributes of a professional programmer is the ability to be honest with management. Many times this means that we need to be brave enough make sure difficult discussions happen when a story is not quite ready for implementation, because once it is ready, we'll be able to accurately estimate when it can be done. We'll then be comfortable making a firm commitment as to when we will deliver.

Attempting to estimate for a story that has too many unknowns will ultimately hurt your relationship with your managers, because, how can you deliver what they want when they can't even fully define it yet. Stories like this usually need more design time. Allowing for design time during a sprint can help, but that's only a first step. Design is not delivery. Until you have a story you can deliver, we must stay at the drawing board.

Title: Validating User Stories: How much change is too much?

Body:
While the core of requirements development and acceptance criteria would ideally take place during the planning meeting in order to create a better estimate, Scrum encourages continuous interaction with the product owner throughout the sprint to validate and refine user stories.

What kind of criteria is used to judge if there is too much change being imposed on a user story mid-sprint?

When is it appropriate to change the requirements of the user story?

When is it appropriate to cancel the user story / sprint in order to re-evaluate and re-estimate a user story in question?


答:
I think it depends upon your environment and how the product owner(s) react to missed deadlines.  Because ultimately, changing the requirements increases the chances of missed deadlines.

Our job as programmers is to build what the business needs.  So it's always appropriate to change the requirements of the user story based upon the business' needs.  It's also appropriate to document the change(s) so that a postmortem review can identify those changes as a contributing factor.

The criteria to judge the change impact is the same criteria you use to estimate the user story in the first place.  The developer working on that user story should understand the change and be able size the impact.  If the new sizing increases the scope beyond the remainder of the sprint, then the modified user story should be broken down into smaller components.  It's the same process that's used to size and manage user stories before they hit the product backlog.

So let's go back to the environment.  If the product owner can't handle missed deadlines, then it's better to cancel the work from them sprint and re-schedule.  That becomes part of the change management conversation.  If the product owner is okay with some slippage, then the developer works as much into that sprint as feasible, and either creates a new story for the next sprint with the remaining work or lets the existing story bleed over.  The new | bleed-over decision is one for the team based upon what works best for managing estimates.

But our job is to build what the business needs.  Change is good.  It keeps us employed.  And it gets the business what they need.


答:
Technology is an inherently iterative process. We start with simple tools and then use those tools to make better ones. The first assembly languages were pretty much 1:1 translations of the standardized instruction bytecodes for the chip; the 8086 architecture and its assembler became dominant over other architectures like Z80, RISC, etc, and so we began to develop languages that could be digested into 8086 assembly, like FORTRAN, COBOL, Pascal and C. The program that interprets the source code of these languages has to be written in something more primitive, otherwise you end up in a chicken-and-egg argument; if the source code for the first C compiler was written in C, then what compiled that C source code, and wouldn't that, by definition, be the first C compiler?

Basically, "C# is written in C++" should be taken to mean that the first and/or most popular compiler and runtime/core libraries that obey the specification of the C# language (those being Microsoft's .NET Framework, and the command-line compiler program CSC.exe) are written in C++.


答:
From the agile manifesto: "Customer collaboration over contract negotiation"

If you consider a story as a contract you committed to at the beginning of the sprint, you can't change much without renegotiating your commitment. But I think that's the wrong approach.

It's fast and cheap to ask for a reestimate of the new story content at any time. Did the estimate (remaining work) change? Then you're good to  go. Otherwise, sprint planning might need adjustment - and as long as anyone is clear about it, it shouldn't be an issue.


问:
What should I do to be language-agnostic?
By now I work with asp.net and C#. I have done a decent work in Java as well. I am planning my career in such a way I should be language-agnostic someday. What are the things that I need to learn?

First would OOP paradigms as its speaks about the Class design. Are there any others?

答:
It's not just the languages, Java itself has so many different modes that you could spend years just learning them all.  You could learn:

J2EE features like Messaging and Persistence and the various servers

jsp and Apache-oriented toolkits

ant, maven and other build systems (Languages themselves).

The whole Groovy/Grails world

all the apache commons APIs

testing systems (Mocking, JUnit)

GUI builders like Swing, GWT...

And a hundred things I'm missing--JUST within java.

If you spend years covering the breadth (learning every language) you'll have trouble gaining the depth to work effectively in any one of them.

I'm not saying that learning a new language is EVER a problem, you shouold be actively doing so!  I try to pick my next job based on what I can learn (what I haven't done yet), but I don't often pick a random language and learn it any more--Last time I tried that was with Scala and I left somewhat humbled...


答:
If strongly desired, common code can be isolated across multiple languages and environments.

Imagine maintaining the same application written in both Java and C. They have several command line arguments in common; however, a few parameters differ. You could write the help for both applications independently (once in Java, once in C), ignoring the DRY principle. You could write a help file once in XML and use stylesheets to generate a Java Help class and a C help function. For example:

```<code><?xml version="1.0"?>
<help>
  <param name="server" abbr="s" lang="both" arg="string">Application server name.param>
  <param name="garbage" abbr="g" lang="java" arg="nil">Attempt garbage collection.</param>
</help>
</code>```

This allows generating help for both applications and -- with not much more work -- inject the parameters into the command line parsing code.

In your particular case, you have server code and client code that performs a calculation. If you really wanted to isolate the calculation, you could describe the calculation in a language-neutral format and then generate the corresponding code for the server and the client.

Constants are a similar issue: how do you maintain a list of constants within a client-server application, while applying the DRY principle? Use a database table to store the name and value of the constants and then generate the common code (Java interfaces, PHP globals, JavaScript variables, and such).

See also: https://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-and-escape-newlines

Title: Duplication of code (backend and javascript - knockout)

Body:
We have a new developer on our team. He seems to be a smart guy (he just came in so I cannot really judge). He started with implementing some small enhancements on the project (MVC3 web application using Javascript with jQuery and Knockout).

Let's say we have two values:

```<code>A - quite complex calculation
C - constant
B = A + C
</code>```

On the screen there is value B and user can change it (normal texbox). When B changes, A changes as well because C is constant. So there is linear dependency between A and B.

Now, all the calculations are done in the back-end, but we need to recalculate A as user changes B (in Javascript, I would use knockout). I thought about storing old A and B and when B changes by 10 then we know that new A will be old A + 10. He says this is dirty, because it's duplication of code (we make use of the fact that they are dependent and according to him that should be only in one place in our app). I understand it's not ideal, but making AJAX request after every key press seems a bit too much.

It's a really small thing and I would not post if we haven't had long discussion about it.

How do you deal with such problems? Also I can imagine that using knockout implies lots of calculations on the client side, which very often leads to duplication of the same calculations from the back-end. Does anyone have links to some articles/thoughts on this topic?

Body:
If strongly desired, common code can be isolated across multiple languages and environments.

Imagine maintaining the same application written in both Java and C. They have several command line arguments in common; however, a few parameters differ. You could write the help for both applications independently (once in Java, once in C), ignoring the DRY principle. You could write a help file once in XML and use stylesheets to generate a Java Help class and a C help function. For example:

<?xml version="1.0"?>
<help>
  <param name="server" abbr="s" lang="both" arg="string">Application server name.param>
  <param name="garbage" abbr="g" lang="java" arg="nil">Attempt garbage collection.</param>
</help>

This allows generating help for both applications and -- with not much more work -- inject the parameters into the command line parsing code.

In your particular case, you have server code and client code that performs a calculation. If you really wanted to isolate the calculation, you could describe the calculation in a language-neutral format and then generate the corresponding code for the server and the client.

Constants are a similar issue: how do you maintain a list of constants within a client-server application, while applying the DRY principle? Use a database table to store the name and value of the constants and then generate the common code (Java interfaces, PHP globals, JavaScript variables, and such).

See also: https://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-and-escape-newlines


问:
Database development/admin - What exactly should I be trying to learn?
I've been a bit weary about approaching learning databases. I've dabbled into them before, and "DATA" in itself appeals to me a lot. Maintaining/searching/moving, everything about it in the abstract sense I love. (This isn't a career question, this is a learning question.)

But as RDBMS's begin to be easier to maintain, and with tools that "anyone" can use to manage data I feared for the database admin jobs. (Yet I see jobs for SQL everywhere!). I know "No-SQL" was a big deal but it kinda has its niche.

But that leaves me here... unsure of really "what" to study. What tools should I have in my tool belt?

I'm sure RDBMS's will be around in both use and maintaining legacy code. But what else? Obviously data will always be around, but is this a secure field or a dying one? And what should I be concentrating on?

答:
People always worry about "is my favorite technology dead," but don't consider the advantages of learning it anyway.

Learning SQL will serve you well; it will teach you set theory, which will help you tremendously in your programming career even if SQL databases disappear tomorrow, which they won't.

NoSql is not a replacement; it is an alternative.  See also:

http://www.it-career-coach.net/2009/07/11/what-is-the-demand-for-sql-skills/


问:
How to access / query Team Foundation Server 2012 with Odata?
I've tried to find a solution for this for hours now, and I'm getting the same results in the end, asking me to install a lot of Azure and other stuff, plus running some example project .sln that I can't open with my 2012 version of Visual Studio.

So, I'm pretty much stuck, and have some pretty straight forward questions regarding this:

Does TFS 2012 include the Odata service in any way, so that I don't have to install it?

If not, how can I install a NATIVE 2012 version of the Odata service for TFS 2012?

Is it possible that I'm aiming for the wrong target here? I'm looking for a solution to the following:

I have a TFS 2012 Server that I need to be able to create Work Items on programatically, based on data from our Help Desk system. Then I need to query these Work Items for changed status since its creation, and update the Help Desk Database.

Am I better off using the "regular" TFS API? I was kinda thinking that the Odata way was more "future proof", but I'm not sure...

答:
Here are some ways I have been able to accomplish similar tasks in TFS 2010 (Disclaimer: I haven't been able to try them in 2012 yet, and I'm not having luck finding 2012 documentation for this, so be careful and try them out in a test environment first):

Write a TFS plugin (see http://blog.hinshelwood.com/team-foundation-server-2010-event-handling-with-subscribers/) - this involves dropping in some DLLs that are ran in-process with TFS.  If you go this route make sure you handle all exceptions gracefully, and that your plugin doesn't take a long time to execute.  Installing your own TFS plugin also takes down TFS for about 10 seconds while TFS loads your DLL(s).

Write a plugin that triggers a job extension (see http://blogs.microsoft.co.il/blogs/assafstone/archive/2011/07/29/how-to-write-a-robust-tfs-server-plugin-with-job-extensions.aspx) - I have used this a few times to do some longer running tasks, as well as to do a consistency check over all work items.  This also allows you to access the server-side TFS API (which is poorly documented, to the point that most people just use the Client API anyway.  But if you can figure out how to use it, more power to you)

Subscribe to TFS SOAP event for work items being changed (see http://www.ewaldhofman.nl/post/2010/08/02/How-to-use-WCF-to-subscribe-to-the-TFS-2010-Event-Service-rolling-up-hours.aspx) - this does not require any TFS downtime when you make changes, and doesn't take away from available processing power on your TFS server.

As for the OData, I have also been struggling for the last couple of days to get that built, and have had a similar difficulty with the Azure tools.  The only reason I am trying to get OData to work is for accessing TFS from mobile devices, since the TFS client API DLLs aren't portable.  Brian Keller (as of Oct 2011) says the following about the OData service (see Link):

"Currently we have no plans to support true work item editing / creation"

"I would like to continue to iterate on this and add value over time. I should make it clear, however, that this is not an official release from the TFS engineering team. The TFS engineering team has reviewed the service and approved of the approach we are taking, but there is no official support for this service"

I share your frustration about future-proofing.  As of yet I have not seen any solution that won't need adjustment in the next iteration.  The closest I have come is using the TFS Client API, since I have only noticed subtle differences between 2010 and 2012.


答:
I've focussed myself on MS SQL Server a few years ago (read: 2006). You've already pointed out the tooling is a lot easier these days, so it's rather easy to learn to maintain a (small) database.

When you are serious about creating databases, there's still a ton of stuff to learn. You can look into replication, mirroring, fall-back scenario's, point-in-place restores, sharding, performance, indices, BI, Analysis, Big Data, etc.

I've also done a SQL Server training of 5 days, which helped me understand the enterprisy features of the product. That's because most of us haven't got multiple servers in place with the requirement of mirroring, performance, etc. In such a training you can exercise these things and maybe specialize in it.

For MS SQL Server, you can try out the certification path. The trainings are quite good and you'll cover a lot of the product.
I assume Oracle also has some training set up for their product.

When you're familiar with one of these commercial products, you can always decide to look into one of the smaller products (PostgreSQL, MySQL, SQLLite or any other). They probably work about the same, just with less features.

In our country there's also something called a 'SQL Saturday'. Which means you'll meet up with other SQL people (on a saturday) and have sessions about the product. It's quite fun and you can also learn a lot.

Title: Database development/admin - What exactly should I be trying to learn?

Body:
I've been a bit weary about approaching learning databases. I've dabbled into them before, and "DATA" in itself appeals to me a lot. Maintaining/searching/moving, everything about it in the abstract sense I love. (This isn't a career question, this is a learning question.)

But as RDBMS's begin to be easier to maintain, and with tools that "anyone" can use to manage data I feared for the database admin jobs. (Yet I see jobs for SQL everywhere!). I know "No-SQL" was a big deal but it kinda has its niche.

But that leaves me here... unsure of really "what" to study. What tools should I have in my tool belt?

I'm sure RDBMS's will be around in both use and maintaining legacy code. But what else? Obviously data will always be around, but is this a secure field or a dying one? And what should I be concentrating on?


答:
If your assignment doesn't specify how to discriminate between identical frequencies, then the compression format is underspecified, and you generally can't expect independent implementations to interoperate.

This could either be an oversight on the part of the teacher -- or he/she could be trying to make a memorable point of all this.

I would first try asking for clarification, but absent further input, I would choose a method that is easy to implement and to document, then write up a standard that clearly documents your choice (such that your classmates could readily use it to make sure their implementation was compatible with yours), and turn it in with your assignment.

Title: How to discriminate from two nodes with identical frequencies in a Huffman's tree?

Body:
Still on my quest to compress/decompress files with a Java implementation of Huffman's coding (http://en.wikipedia.org/wiki/Huffman_coding) for a school assignment.

From the Wikipedia page, I quote:

Create a leaf node for each symbol and add it to the priority queue.

While there is more than one node in the queue:

Remove the two nodes of highest priority (lowest probability) from the queue

Create a new internal node with these two nodes as children and with probability equal to the sum of the two nodes' probabilities.

Add the new node to the queue.

The remaining node is the root node and the tree is complete.

Now, emphasis:

Remove the two nodes of highest priority (lowest probability) from the queue

Create a new internal node with these two nodes as children and with probability equal to the sum of the two nodes' probabilities.

So I have to take two nodes with the lowest frequency. What if there are multiple nodes with the same low frequency? How do I discriminate which one to use?

The reason I ask this is because Wikipedia has this image:

And I wanted to see if my Huffman's tree was the same. I created a file with the following content:

```<code>aaaaeeee       nnttmmiihhssfffouxprl
</code>```

And this was the result:

Doesn't look so bad. But there clearly are some differences when multiple nodes have the same frequency.

My questions are the following:

What is Wikipedia's image doing to discriminate the nodes with the same frequency?

Is my tree wrong? (Is Wikipedia's image method the one and only answer?)

I guess there is one specific and strict way to do this, because for our school assignment, files that have been compressed by my program should be able to be decompressed by other classmate's programs - so there must be a "standard" or "unique" way to do it. But I'm a bit lost with that.

My code is rather straightforward. It literally just follows Wikipedia's listed steps. The way my code extracts the two nodes with the lowest frequency from the queue is to iterate all nodes and if the current node has a lower frequency than any of the two "smallest" known nodes so far, then it replaces the highest one. Just like that.


问:
A little code to allow word substitution depending on user
I'm creating a demo web app in html in order for people to physically see and comment on the app prior to committing to a proper build.

Whilst the proper app will be database driven, my demo is just standard html with some JavaScript effects.

What I do want to demonstrate is that different user group will see different words. For example, imagine I have an html sentence that says:

This will cost £100 to begin.

What I need to some way of identifying that if the user has deemed themselves to be from the US, the sentence says:

This will cost $100 to begin.

This requirement is peppered throughout the pages but I'm happy to add each one manually. So I envisage some code along the lines of 'first, remove the [boot US] trunk' where the UK version is 'first remove the boot' but the code is saying that the visitor needs the US version. It then looks up boot (in an Access database perhaps) and sees that the table says for boot for US, display 'trunk'.

I'm not a programmer but I can normally cobble together scripts so I'm hoping someone may have a relatively easy solution in JavaScript, CSS or ASP.

To recap: I have a number of words or short sentences that need to appear differently and I'm happy to manually insert each one if necessary (but would be even better if the words were automatically changed).
And I need a device which allows me to tell the pages to choose the US version, or for example, the New Zealand version.

答:
If all you want is a quick and dirty demo to show what functionality will be in the app without actually making a full blown app. Make every section of localized text its own container and have one container for each localization. Then just use JavaScript and CSS to hide/display the containers that match the desired location, your HTML page would look like this.</p>

```<code><p class='UK' >This will cost £100 to begin.</p>
<p class='US' >This will cost $100 to begin.</p>
<p class='CAN' >This will cost $150 to begin.</p>
</code>```

Body:
If all you want is a quick and dirty demo to show what functionality will be in the app without actually making a full blown app. Make every section of localized text its own container and have one container for each localization. Then just use JavaScript and CSS to hide/display the containers that match the desired location, your HTML page would look like this.

<p class='UK' >This will cost £100 to begin.</p>
<p class='US' >This will cost $100 to begin.</p>
<p class='CAN' >This will cost $150 to begin.</p>


问:
Cookie Settings Storage Method
I've got an web app that needs to store some non-sensitive preferences for the user. Right now I'm storing their language preference and what mode they want a window opened in by default in two cookies:

"lang" can be "en" or "de"

"mode" can be "design" or "view"

I might add a few more in the future. I'm not sure how many, but probably never more than a dozen.

Language is parsed on every request, whereas the mode cookie is only used occasionally. I saw a recommendation that made sense I shouldn't try to do what I was originally planning to do and strongly type a user settings class deserialized on each request because of the overhead involved.

I see three options here and I'm not sure which is the best overall.

Keep things as they are, add a new cookie for each new setting

Combine the cookies into a single settings cookie and add future values to it

Change the mode cookie to settings (leaving language alone), add new user settings values to the settings cookie

All would work obviously. I'm leaning toward option three, but I'm not sure if there's a best practice for this?

答:
Good question.

I don't know of any standard in dealing with cookies. I know what works for me. It might vary from platform to platform. Keep in mind that data stored in cookies is visible to anyone.

I always encrypt cookies, even if the data is not important. The encryption ensures the integrity of the cookie. A malicious person can not tell how I am using the cookie. If the cookie is tampered with, it will fail decryption. I typically serialize, with JSON, a class into the cookie. This keeps the data structured and enables an easy way to read and write data to and from the cookie. Depending on browsers and servers there are limitations. It's important to keep cookie data to a minimum. The smaller the better.

Title: Cookie Settings Storage Method


答:
Reading your question and some of the answers one can have the impression that you equal "language agnosticism" with "knowing every paradigm on earth".

I'm not sure whether knowing every paradigm that exists or knowing an assorted range of languages, spanning several paradigms and types of languages makes you "language agnostic".

It's like saying that having practiced all religions makes yourself religiously agnostic.

I think a language agnostic person regarding programming languages should be someone that doesn't know how to program in any language at all or doesn't care what language he/she is asked to programm with.

That said, some people say a true programmer can program in any language given access to that language's documentation.

If that is what you mean by "language agnostic" then almost any experienced programmer can program in any language he/she gets forced to work with, given access to the language documentation.

Maybe you want to be "language polytheist".

I myself am competent in several language paradigms but I'd prefer OOP when it aplies. So I guess I'm not agnostic.

You will hardly find anyone who doesn't prefer a certain paradigm or language given the liberty to choose.

Title: What should I do to be language-agnostic?

Body:
By now I work with asp.net and C#. I have done a decent work in Java as well. I am planning my career in such a way I should be language-agnostic someday. What are the things that I need to learn?

First would OOP paradigms as its speaks about the Class design. Are there any others?


问:
What's the benefit of the Nothing constructor in Haskell?
I'm new to Haskell and I'm not really sold on the Nothing constructor. It sounds like just another silent fail that's going to create headaches down the line. It seems much more useful to throw an error so I'll have a clue what's happening.

Why am I wrong here?

答:
Why am I wrong here?

Because a lack of value is not always indicative of an error.


答:
I think the reason why it can be called "a real compiler" is because it builds a complete AST (abstract semantic tree) out of your programs, and uses it to generate a new text.

The fact that both the original and resultant texts are valid JavaScript is mere coincidence.

This is important because there are many tools that only do text manipulations of the code (minifiers, prettifiers, etc) but doesn't do any AST  handling, much less code re-generation.  Even if those tools are more and more powerful, they're not the same kind of software, and the limitations are different.

Title: Is Google Closure a true compiler?


问:
Is passing the Model around in this way considered bad practice?
If I have a view called, for example, ViewDetails that displays user information in labels and has a Model called ViewDetailsModel and if I want to allow the user to click a button to edit some of these details, is it considered bad practice is I pass the entire Model in the markup to a controller method which then assigns the values for another model, using the values stored in the Model that was passed in as a parameter to that action method? If so, should there instead be a service method that gets the data required for the edit view?

For example:

In the ViewDetails view, the user clicks the edit button which calls an action method in the controller (and passes in the Model object).

The action method then uses the data in the Model object to populate another model which will be used for the EditDetails view that will be returned.

答:
How else would you do it?  If EditDetails needs to change depending on values in ViewDetails, obviously this is the correct way to do it.

As long as you're using view-models separate from your domain models, it should be clean.

It sounds like you're just working on something complex; that's probably what is making your code a bit "ugly", not the way you've designed it.


答:
In addition to Telastyn's answer:

Maybe never "silently fails". In contrast to null, which might be what the OP's is comparing it to, a Haskell function which can return Nothing must explicitly do so in its type.

For comparison: a method returning String in Java might return a String or null, and you cannot tell just by looking at its type:

```<code>public String myFunc(int x) { /* do something, might return null! */ }
</code>```

In Haskell a function which returns a String has a type similar to this:

```<code>myFunc :: Int -> String
</code>```

You know it cannot return Nothing, because if it did, its type would be:

```<code>myFunc :: Int -> Maybe String
</code>```

This means Nothing can never sneak up on you and "cause headaches down the line"!

Title: What's the benefit of the Nothing constructor in Haskell?

Body:
I'm new to Haskell and I'm not really sold on the Nothing constructor. It sounds like just another silent fail that's going to create headaches down the line. It seems much more useful to throw an error so I'll have a clue what's happening.

Why am I wrong here?

Body:
In addition to Telastyn's answer:

Maybe never "silently fails". In contrast to null, which might be what the OP's is comparing it to, a Haskell function which can return Nothing must explicitly do so in its type.

For comparison: a method returning String in Java might return a String or null, and you cannot tell just by looking at its type:

public String myFunc(int x) { /* do something, might return null! */ }

In Haskell a function which returns a String has a type similar to this:

myFunc :: Int -> String

You know it cannot return Nothing, because if it did, its type would be:

myFunc :: Int -> Maybe String

This means Nothing can never sneak up on you and "cause headaches down the line"!


问:
Is there an excuse for short variable names?
This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't documentation as to what most of them do, so I have to spend extra time tracking down what they represent.

For example, I was reading over some code that updates the definition of an optical surface. The variables set at the start were as follows:

```<code>double dR, dCV, dK, dDin, dDout, dRin, dRout
dR = Convert.ToDouble(_tblAsphere.Rows[0].ItemArray.GetValue(1));
dCV = convert.ToDouble(_tblAsphere.Rows[1].ItemArray.GetValue(1));
... and so on
</code>```

Maybe it's just me, but it told me essentially nothing about what they represented, which made understanding the code further down difficult. All I knew was that it was a variable parsed out specific row from a specific table, somewhere. After some searching, I found out what they meant:

```<code>dR = radius
dCV = curvature
dK = conic constant
dDin = inner aperture
dDout = outer aperture
dRin = inner radius
dRout = outer radius
</code>```

I renamed them to essentially what I have up there. It lengthens some lines, but I feel like that's a fair trade off. This kind of naming scheme is used throughout a lot of the code however. I'm not sure if it's an artifact from developers who learned by working with older systems, or if there's a deeper reason behind it. Is there a good reason to name variables this way, or am I justified in updating them to more descriptive names as I come across them?

答: The only case where illegibly short variable names are acceptable in modern software engineering is when they exist in a script and the throughput of that script (over a network generally) is important. Even then, keep the script with long names in source control, and minify the script in production.


答:
Variables with short lifetimes should be named shortly. As an example, you don't write for(int arrayCounter = 0; arrayCounter < 10; arrayCounter++) { .... Instead, you use for(int i ....

In general rule of thumb it could be said that the shorter the variable scope the shorter the name should be. Loop counters are often only single letters, say i, j and k. Local variables are something like base or from and to. Global variables are then somewhat more elaborate, for example EntityTablePointer.

Perhaps a rule like this isn't being followed with the codebase you work with. It's a good reason for doing some refactoring though!

Title: Is there an excuse for short variable names?

Body:
This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't documentation as to what most of them do, so I have to spend extra time tracking down what they represent.

For example, I was reading over some code that updates the definition of an optical surface. The variables set at the start were as follows:

```<code>double dR, dCV, dK, dDin, dDout, dRin, dRout
dR = Convert.ToDouble(_tblAsphere.Rows[0].ItemArray.GetValue(1));
dCV = convert.ToDouble(_tblAsphere.Rows[1].ItemArray.GetValue(1));
... and so on
</code>```

Maybe it's just me, but it told me essentially nothing about what they represented, which made understanding the code further down difficult. All I knew was that it was a variable parsed out specific row from a specific table, somewhere. After some searching, I found out what they meant:

```<code>dR = radius
dCV = curvature
dK = conic constant
dDin = inner aperture
dDout = outer aperture
dRin = inner radius
dRout = outer radius
</code>```

I renamed them to essentially what I have up there. It lengthens some lines, but I feel like that's a fair trade off. This kind of naming scheme is used throughout a lot of the code however. I'm not sure if it's an artifact from developers who learned by working with older systems, or if there's a deeper reason behind it. Is there a good reason to name variables this way, or am I justified in updating them to more descriptive names as I come across them?


答:
It appears that these variable names are based on the abbreviations you'd expect to find in a physics textbook working various optics problems.  This is one of the situations where short variable names are often preferable to longer variable names.  If you have physicists (or people that are accustomed to working the equations out by hand) that are accustomed to using common abbreviations like Rin, Rout, etc. the code will be much clearer with those abbreviations than it would be with longer variable names.  It also makes it much easier to compare formulas from papers and textbooks with code to make sure that the code is actually doing the computations properly.

Anyone that is familiar with optics will immediately recognize something like Rin as the inner radius (in a physics paper, the in would be rendered as a subscript), Rout as the outer radius, etc.  Although they would almost certainly be able to mentally translate something like innerRadius to the more familiar nomenclature, doing so would make the code less clear to that person.  It would make it more difficult to spot cases where a familiar formula had been coded incorrectly and it would make it more difficult to translate equations in code to and from the equations they would find in a paper or a textbook.

If you are the only person that ever looks at this code, you never need to translate between the code and a standard optics equation, and it is unlikely that a physicist is ever going to need to look at the code in the future perhaps it does make sense to refactor because the benefit of the abbreviations no longer outweighs the cost.  If this was new development, however, it would almost certainly make sense to use the same abbreviations in the code that you would find in the literature.


答:
Variable names should be as descriptive as possible to help the readability of the program. You experienced it yourself: you had a lot of trouble identifying what the program did because of the poor naming.

There is no good reason not to use descriptive name. It will help you, and everyone else that works/will work on the project. Well actually there is a single valid use for short names: loop counters.


答: The typical approach is to only store a unique session id with the cookie.  No need to store anything other than that on the client side.  On the server side you'd associate data with that key.  Typically that means a session information table that has at least two columns: the session id and session data.  Session data often is comprised of some serialized data structure (in php, an array, for example).  On the page load, after reading the session id from the request, load and unserialize the session data from the database (or storage system of your choice).  When the request ends, save it back to the database.

Title: Cookie Settings Storage Method

Body:
I've got an web app that needs to store some non-sensitive preferences for the user. Right now I'm storing their language preference and what mode they want a window opened in by default in two cookies:

"lang" can be "en" or "de"

"mode" can be "design" or "view"

I might add a few more in the future. I'm not sure how many, but probably never more than a dozen.

Language is parsed on every request, whereas the mode cookie is only used occasionally. I saw a recommendation that made sense I shouldn't try to do what I was originally planning to do and strongly type a user settings class deserialized on each request because of the overhead involved.

I see three options here and I'm not sure which is the best overall.

Keep things as they are, add a new cookie for each new setting

Combine the cookies into a single settings cookie and add future values to it

Change the mode cookie to settings (leaving language alone), add new user settings values to the settings cookie

All would work obviously. I'm leaning toward option three, but I'm not sure if there's a best practice for this?


问:
How do I pitch ASP.NET over PHP to a potential client?
I work at a Microsoft shop doing mainly web development.

We had a client who asked us to review (improve) the data model for his web app, but said that he wants to develop his app in PHP (he knows "a guy" who can do it).

When I asked him why he wants to go with PHP, he gave me the standard set of arguments from the 90's:

Microsoft is evil, and PHP is free

Writing an ASP.NET app is more expensive (software-wise)

Why would Facebook use PHP if it was a bad idea? [classic]

He had a few more comments about the costs associated with going .NET.

The truth is that "Microsoft is expensive" does not hold water any longer, with their "Express" suite, you can develop an ASP.NET app without paying anything for software.

When it comes to hosting, you can save a few bucks with PHP over .NET, but that's a small fraction of the projected development costs (we quoted 10-15k).

Going back to my question, what arguments would I give to a client in favor of ASP.NET over PHP? [please provide sources for quantitative claims]

答:
I just witnessed a company pay nearly $200,000 for a not-yet-ready-for-primetime PHP ecommerce website (I lost the contract a year ago to these clowns). It's been over 10 months of development time. The site looks wonderful, but is lacking so many ecommerce "basics", it's a joke.
I admit, I'm a lousy marketer - but here's the pitch the PHP company used:
It's "free" and "open source"!
Facebook uses it!
Linux & MySQL is "free"!
It's faster than ASP.Net!
It's faster to develop!

The truth is, the original website (written in ASP.NET) had twice the features and was completed by a single developer in 3 months at a cost of $25K (including the cost for a FULL, single CPU license of SQL Server 2008 R2 & Visual Studio Pro).
The $200K site had a team of developers, and STILL is not finished after 10 months, is half the speed (with cacheing) of the old site.

If you want to sell them ASP.Net, say "L.A.M.P. may be free, but your development time will cost more... MUCH MORE!"  Facebook runs PHP, true, but they started out of an apartment where money was low and time was free.  Facebook uses Oracle and MANY compiled programs these days (so that point is moot).

If you need reusability and simple code maintenance, scripted languages can quickly turn into a nightmare (including ASP here as well).

If you need performance, go with a compiled language - no scripted language will ever compete with compiled code and never will as the interpreter will always add overhead. Caching does help tremendously, but ASP.Net has caching too.

Sure, Linux is free, but Linux experts are very expensive when something goes wrong. Win server costs $$$ up front, but experts are cheap to find (and nearly ubiquitous) when something goes wrong.  Connectivity to win-networks is dumb simple and rock solid, so integrating into other business systems is a breeze (accounting packages, shippers, etc) with the best user account management I've seen (though, MS did borrow a lot from Novell).

The GUI overhead that Linux people say is a big resource waster is nearly a non-issue with today's hardware. If you have an issue with it, there's the non-GUI versions of Windows Server ("Core" version) available w/powerShell.


问:
C++ is easy once you know PHP
I was at work last week and one of our "lead developers" (who said he has programmed C++ before, but I don't believe him) was talking about C++ and how our team of developers who only know PHP would not have a hard time at all learning C++.

My first reaction was pure shock and then I laughed at his comment. He gave me a bad look and i asked if he was serious. Me personally I program a lot of C and C++ for mostly school projects and coding competitions. I don't think it's at all like PHP. I asked him why they were the same and he could not give me an answer (he doesn't know C++ at all I was thinking). Then I said "OK, yeah they both use curly braces and have conditional statements. But C++ you have to worry about memory management and all the easy to use built in functions in PHP, for example the array functions, are non-existent in C++. You actually have to know the algorithms behind them.". There are some great C++ libraries (STL, Boost) that will make your life easier but C++ is like PHP, come on!

If you already know one language it will make it a little easier to learn another because you will already be good at boolean login (if this then that) or looping but there is just so much more to C++ than PHP. Like you have to compile the language and actually have to define what type of variable you are using and returning from functions.

What do you think?

EDIT: Actually what he said was "C++ is not much different than PHP"

答:
Sounds like one "team lead" guy (also a PHP dev like yours) who told me that C++ "sucks, take templates for example". Much as I try not to, lines like those always flip the infamous bozo bit with me.

Your friend has a HUGE problem here, namely he is so overconfident that he does not know how much he does not know.

Saying that learning C++ is easy once you know PHP is like saying that once you can drive a Segway, it would be quite easy to learn operating an Airbus A-380, because, 'you know, they both have some wheels to stand on and are controlled by advanced embedded circuit boards.

Title: C++ is easy once you know PHP