问:
The purpose of using a constants pool for immutable constants
I come across the following code with a lot of frequency:

```<code>if (myArray.length == Constants.ZERO_INT)
</code>```

or

```<code>if (myString != null && !myString.equals(Constants.EMPTY_STRING))
</code>```

Neither of these makes much sense to me. Isn't the point of having a constant pool for ease of code appearance and to allow for modularity? In both of the above cases, it just looks like needless noise that accomplishes neither objective.

My question: what is the purpose of using a constants pool for variables like this which will never change? Or is this just cargo cult programming? If so, then why does it seem to be prevalent in the industry? (I've noticed it with at least two different employers I've worked with).

答:
There are two options that one has for dealing with specific, frequently occurring immutable objects.  You can either instantiate them each time, or you can use a constant that is probably stuck in a final static in some class.

BigInteger for example has ZERO, ONE, and TEN.

However, this is an attempt to avoid instantation of new objects.  Say you're adding the sum of some BigIntegers.  You've got the choice of:

```<code>BigInteger sum = BigInteger.ZERO;
for(int i = 0; i < array.length; i++) {
  sum = sum.add(BigInteger.valueOf(array[i]));
}
</code>```

vs

```<code>BigInteger sum = BigInteger.valueOf(0);
for(int i = 0; i < array.length; i++) {
  sum = sum.add(BigInteger.valueOf(array[i]));
}
</code>```

vs

```<code>BigInteger sum = null;
for(int i = 0; i < array.length; i++) {
  if(sum == null) { sum = BigInteger.valueOf(array[i]); }
  else { sum = sum.add(BigInteger.valueOf(array[i])); }
}
</code>```

The first code is simpler to understand and less error prone.

The second creates another object when its not needed - do this several times and you've got several BigInteger.valueOf(0) objects that need to get collected at some point.

The third is error prone - if the array is empty, sum comes out with a null.

However this should be remembered that this is trying to avoid instatiation of objects.  Using it for things such as comparisons doesn't help.

```<code>if (myArray.length == Constants.ZERO_INT)
</code>```

This is some dangerous code.  Sure, ZERO_INT is an Integer and it will get unboxed back to a 0.  But if the myArray ever becomes something that returns an Integer?  It may break depending on how ZERO_INT was defined (Integer ZERO_INT = 0 is less likely to, Integer ZERO_INT = new Integer(0) is more likely to).  And things you get back from ORMs and the like are rarely boxed.

At a former employer, I had BigDecimal KM_IN_MI = BigDecimal.valueOf("1.60934"); defined because it was a value that kept getting used and removed code that would create it a few dozen times otherwise.  That's a good constant - and its not one that would get auto boxed for you.  Its also one that needs to stay consistent through multiple calculations.

Defining Integer.valueOf(0) fails at this test because it is one that would get auto boxed for you, is more likely to be buggy (the == works sometimes), and is already a constant 0.

The empty string is... kind of useless, other than its name.  "" is easier to type and probably more convenient.  That said, some tools will yell at you for having a string constant used multiple times as string constants - set up your static analysis to put "" into its exception list.

This is because Java does String interning.  <s>They take strings out of college and put them to work.</s>  At compile time, all the string literals are put into a specific pool of strings that are pre-defined.  This can save memory and speed things up - and make things referentially equal ("foo" == "foo" is true, while "foo" == new String("foo") is false, but "foo" == (new String("foo")).intern() is true -- got all that?).

Defining some strings as constants means that you are not violating DRY.  But for "", this is probably overkill, unnecessary and, frankly, a pain.

For final static primitives (byte, short, int, float, double, char, long, boolean), these are translated to literals at compile time (String also has this behavior though it is complicated with the interning pool). They do have uses, as can seen in the code for java.util.Calendar. However, extreme caution must be taken with this.

If your code looks like:

```<code>class A {
   final static int FOO = 1;
}

class B {
    private int field;
    public B { field = A.FOO; }
}
</code>```

when it gets compiled, class B effectively becomes:

```<code>class B {
    private int field;
    public B { field = 1; }
}
</code>```

There is no reference to A.FOO in the code.  This is mentioned in Understanding Class Members:

If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant. If the value of the constant in the outside world changes (for example, if it is legislated that pi actually should be 3.975), you will need to recompile any classes that use this constant to get the current value.

As these numbers get compiled into any class that uses them (rather than referencing the constant), it means if the value changes for some reason everything that uses it must be recompiled. Failing to do that means that you think you are using a given value from the new .jar but you are still using the old one.

There are a couple of ways to make sure you don't have this problem of mismatched constants.

The easiest (and hardest to enforce) is to say "once something is a public final static int answer = 42 it never changes."  If you need a new answer, you make a new constant.  If you need to change this value some day, too bad.

One is to make sure that the values don't get out of the package as a public final static and instead make it package level. This means that it isn't likely to be used in another .jar and changing it means recompiling the current .jar.

Another approach is to make the constant accessed via a getter. The getter doesn't get inlined at compile time, but can get inlined at JIT time. This means that you don't have to worry about if the constant in the other class changes because you are accessing it via a getter at runtime rather than compile time inlining.

As this is a bit complex and has been the source of at least one bug that I've fought (and oh, what an epic fight it was - it works on my machine, doesn't work in the dev environment, works on test, but not on production (but differently than how it didn't work in dev); because different versions of a .jar were present on each one and the final static int was different) -- one should be wary of these values if they have at all a chance to change with future versions.  There is also some more esoteric breaking of case statements where two of them could have the same value.  There are some idioms to avoid this mentioned at the end of section 13.4.9 of the JLS though it has the caveat of "We note, but do not recommend..."

I should point out that final static {primitive} is not a pool at all in the language of patterns. It is a way of invoking a compiler optimization for DRY at the cost of closer coupling between the classes and the possibility of errors if that coupling doesn't mean all the classes are recompiled at the same time when the 'constant' changes.

Constant pools of objects are there for performance issues.  Look at the IntegerCache in the Integer class (its a Flyweight Pattern).  Or the proper use of String interning.

But that speed performance gain is unlikely of any use if the code that is written is harder to understand and more likely to have a bug introduced in it.

When dealing with non-mathematical constants and primitive types, make sure that these values are constant to avoid some rather hard to track down bugs (see this explanation of one such 'bug').

Write what is understandable.  Unless demonstrated otherwise, programmer time is more valuable than cpu time.

Body:
There are two options that one has for dealing with specific, frequently occurring immutable objects.  You can either instantiate them each time, or you can use a constant that is probably stuck in a final static in some class.

BigInteger for example has ZERO, ONE, and TEN.

However, this is an attempt to avoid instantation of new objects.  Say you're adding the sum of some BigIntegers.  You've got the choice of:

BigInteger sum = BigInteger.ZERO;
for(int i = 0; i < array.length; i++) {
  sum = sum.add(BigInteger.valueOf(array[i]));
}

vs

BigInteger sum = BigInteger.valueOf(0);
for(int i = 0; i < array.length; i++) {
  sum = sum.add(BigInteger.valueOf(array[i]));
}

vs

BigInteger sum = null;
for(int i = 0; i < array.length; i++) {
  if(sum == null) { sum = BigInteger.valueOf(array[i]); }
  else { sum = sum.add(BigInteger.valueOf(array[i])); }
}

The first code is simpler to understand and less error prone.

The second creates another object when its not needed - do this several times and you've got several BigInteger.valueOf(0) objects that need to get collected at some point.

The third is error prone - if the array is empty, sum comes out with a null.

However this should be remembered that this is trying to avoid instatiation of objects.  Using it for things such as comparisons doesn't help.

if (myArray.length == Constants.ZERO_INT)

This is some dangerous code.  Sure, ZERO_INT is an Integer and it will get unboxed back to a 0.  But if the myArray ever becomes something that returns an Integer?  It may break depending on how ZERO_INT was defined (Integer ZERO_INT = 0 is less likely to, Integer ZERO_INT = new Integer(0) is more likely to).  And things you get back from ORMs and the like are rarely boxed.

At a former employer, I had BigDecimal KM_IN_MI = BigDecimal.valueOf("1.60934"); defined because it was a value that kept getting used and removed code that would create it a few dozen times otherwise.  That's a good constant - and its not one that would get auto boxed for you.  Its also one that needs to stay consistent through multiple calculations.

Defining Integer.valueOf(0) fails at this test because it is one that would get auto boxed for you, is more likely to be buggy (the == works sometimes), and is already a constant 0.

The empty string is... kind of useless, other than its name.  "" is easier to type and probably more convenient.  That said, some tools will yell at you for having a string constant used multiple times as string constants - set up your static analysis to put "" into its exception list.

This is because Java does String interning.  <s>They take strings out of college and put them to work.</s>  At compile time, all the string literals are put into a specific pool of strings that are pre-defined.  This can save memory and speed things up - and make things referentially equal ("foo" == "foo" is true, while "foo" == new String("foo") is false, but "foo" == (new String("foo")).intern() is true -- got all that?).

Defining some strings as constants means that you are not violating DRY.  But for "", this is probably overkill, unnecessary and, frankly, a pain.

For final static primitives (byte, short, int, float, double, char, long, boolean), these are translated to literals at compile time (String also has this behavior though it is complicated with the interning pool). They do have uses, as can seen in the code for java.util.Calendar. However, extreme caution must be taken with this.

If your code looks like:

class A {
   final static int FOO = 1;
}

class B {
    private int field;
    public B { field = A.FOO; }
}

when it gets compiled, class B effectively becomes:

class B {
    private int field;
    public B { field = 1; }
}

There is no reference to A.FOO in the code.  This is mentioned in Understanding Class Members:

If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant. If the value of the constant in the outside world changes (for example, if it is legislated that pi actually should be 3.975), you will need to recompile any classes that use this constant to get the current value.

As these numbers get compiled into any class that uses them (rather than referencing the constant), it means if the value changes for some reason everything that uses it must be recompiled. Failing to do that means that you think you are using a given value from the new .jar but you are still using the old one.

There are a couple of ways to make sure you don't have this problem of mismatched constants.

The easiest (and hardest to enforce) is to say "once something is a public final static int answer = 42 it never changes."  If you need a new answer, you make a new constant.  If you need to change this value some day, too bad.

One is to make sure that the values don't get out of the package as a public final static and instead make it package level. This means that it isn't likely to be used in another .jar and changing it means recompiling the current .jar.

Another approach is to make the constant accessed via a getter. The getter doesn't get inlined at compile time, but can get inlined at JIT time. This means that you don't have to worry about if the constant in the other class changes because you are accessing it via a getter at runtime rather than compile time inlining.

As this is a bit complex and has been the source of at least one bug that I've fought (and oh, what an epic fight it was - it works on my machine, doesn't work in the dev environment, works on test, but not on production (but differently than how it didn't work in dev); because different versions of a .jar were present on each one and the final static int was different) -- one should be wary of these values if they have at all a chance to change with future versions.  There is also some more esoteric breaking of case statements where two of them could have the same value.  There are some idioms to avoid this mentioned at the end of section 13.4.9 of the JLS though it has the caveat of "We note, but do not recommend..."

I should point out that final static {primitive} is not a pool at all in the language of patterns. It is a way of invoking a compiler optimization for DRY at the cost of closer coupling between the classes and the possibility of errors if that coupling doesn't mean all the classes are recompiled at the same time when the 'constant' changes.

Constant pools of objects are there for performance issues.  Look at the IntegerCache in the Integer class (its a Flyweight Pattern).  Or the proper use of String interning.

But that speed performance gain is unlikely of any use if the code that is written is harder to understand and more likely to have a bug introduced in it.

When dealing with non-mathematical constants and primitive types, make sure that these values are constant to avoid some rather hard to track down bugs (see this explanation of one such 'bug').

Write what is understandable.  Unless demonstrated otherwise, programmer time is more valuable than cpu time.


问:
Efficient algorithm for Virtual Machine(VM) Consolidation in Cloud
PROBLEM:

We have N physical machines(PMs) each with ram Ri, cpu Ci and a set of currently scheduled VMs each with ram  requirement ri and ci respectively

Moving(Migrating) any VM from one PM to other has a cost associated which depends on its ram ri. A PM with no VMs is shut down to save power.

Our target is to minimize the weighted sum of (N,migration cost) by migrating some VMs i.e. minimize the number of working PMs as well as not to degrade the service level due to excessive migrations.

My Approach:

Brute Force approach is choosing the minimum loaded PM and try to fit its VMs to other PMs by First Fit Decreasing algorithm or we can select the victim PMs and target PMs based on their loading level and shut down victims if possible by moving their VMs to targets.

I tried this Greedy approach on the Data of Baadal(IIT-D cloud) but It isn't giving promising results.

I have also tried to study the Ant colony optimization for dynamic VM consolidating but was unable to understand very much. I used the links.

http://dumas.ccsd.cnrs.fr/docs/00/72/52/15/PDF/Esnault.pdf
http://hal.archives-ouvertes.fr/docs/00/72/38/56/PDF/RR-8032.pdf

Would anyone please clarify the solution or suggest any new approach/resources for better
performance.

I am basically searching for the algorithms not the physical optimizations and I also know that many commercial organizations have provided these solution but I just wanted to know more the underlying algorithms.

Thanks in advance.

答:
I wouldn't try to optimize the load across the PM's, since that will probably result in constant moving of VM's. The result of a single move will likely change the balance, requiring yet another move.

Instead, i would try to determine the acceptable load factor per PM (over-allocation), and only take actions when:

a. the action will not disturb operations

b. the result will improve the situation (a significantly better location is available on another PM)

And there are other factors in play as well. Do you know which machines have 'affinity' to other machines? A pair of a web-server and a related database-server will probably perform better when placed nearer to each other..

In other words: i would aim for stability (minimal number of moves, and smallest moves) instead of maximum resource optimization.

I would guess that you can optimize placement by using certain standard sizes of VM's, that are easily divideable for your hardware (like LEGO blocks are different sizes, but you can always find a piece that 'fits'), That would minimize the unusable 'rest' hardware for a PM that is to small to place a VM in.

But I would guess the mayor suppliers of virtualization software already have this worked out much better than you or i can in 5 minutes.

ContentLicense: CC BY-SA 3.0


问:
How important is XML for a developer?
Is it must that every developer should know XML? How important is XML for a developer? Any suggestion...</p>

答: It's a format for data exchange thats wildly popular these days. It helps if you know it, certainly, since programs usually need to exchange data among each other.</p>

ContentLicense: CC BY-SA 2.5

Title: How important is XML for a developer?


问:
High-level strategy for distinguishing a regular string from invalid JSON (ie. JSON-like string detection)
Disclaimer On Absence of Code:

I have no code to post because I haven't started writing; was looking for more theoretical guidance as I doubt I'll have trouble coding it but am pretty befuddled on what approach(es) would yield best results. I'm not seeking any code, either, though; just direction.

Dilemma

I'm toying with adding a "magic method"-style feature to a UI I'm building for a client, and it would require intelligently detecting whether or not a string was meant to be JSON as against a simple string.

I had considered these general ideas:

Look for a sort of arbitrarily-determined acceptable ratio of the frequency of JSON-like syntax (ie. regex to find strings separated by colons; look for colons between curly-braces, etc.) to the number of quote-encapsulated strings + nulls, bools and ints/floats. But the smaller the data set, the more fickle this would get

look for key identifiers like opening and closing curly braces... not sure if there even are more easy identifiers, and this doesn't appeal anyway because it's so prescriptive about the kinds of mistakes it could find

try incrementally parsing chunks, as those between curly braces, and seeing what proportion of these fractional statements turn out to be valid JSON; this seems like it would suffer less than (1) from smaller datasets, but would probably be much more processing-intensive, and very susceptible to a missing or inverted brace

Just curious if the computational folks or algorithm pros out there had any approaches in mind that my semantics-oriented brain might have missed.

PS: It occurs to me that natural language processing, about which I am totally ignorant, might be a cool approach; but, if NLP is a good strategy here, it sort of doesn't matter because I have zero experience with it and don't have time to learn & then implement/ this feature isn't worth it to the client.

答:
The real answer ("tell between invalid JSON and a string")

For a lot of obvious reasons we're not going to come up with a definite answer - we can at best hope to determine an index that will tell us whether a string might have been JSON.

The best approach I can think of is to use something like the Levenshtein algorithm, with this twist: we have no "B string", but rather we start parsing the candidate string and modify it as soon as we hit an invalid character.

To do this, we can use a JSON streaming parser (state-based). Let's say we parse

```<code>{ "key": value" }
</code>```

then the parser will find the 'v' and choke. At that point we can try deleting the character, or adding one of several possible valid characters for that state and recurse.

Any branch can be abandoned as soon as the distance to valid JSON for that branch exceeds a minimum, if one has been found so far, or according to some heuristics (e.g. no more than four consecutive ['s, and so on), or as soon as it exceeds a maximum allowed distance (say, 5). This last condition is probably essential to avoid snowballing.

A drawback of this approach is that some solutions would require backtracking:

```<code>{ "key": "value }
</code>```

would be accepted up to the end, then a missing " would be added, and finally a missing }, getting a valid JSON:

```<code>{ "key": "value }"}
</code>```

with a distance of 2 (two additions). Perhaps some fast heuristic for backtracking can be found (e.g. when in "wait-for-end-quote", backtrack until the first non-"special" character, and ignore whitespaces).

An important element to assess the viability of a solution would be how is this invalid JSON generated, i.e., is it a truncated JSON? Are some characters damaged? has it some sort of basic structure which is always the same?

User-generated JSON

As per comment, this JSON may be the result of an attempt of hand-building JSON. This on one hand is bad since human beings are very close to a random source when we're talking about errors :-). On the other hand it may be good since the JSON is probably "almost good JSON" with possibly only a few errors: commas left out or added in,

```<code>{ "first_name": "John", "last_name": "Doe", "email": "jdoe@email.com", }
</code>```

Indeed, we might find it useful to at least preprocess the string to remove some common errors:

",\s*} --> "}                       # Extra comma due to copy-paste
   (")\s*[:;.]\s("[^"]"\s:)     # Forgot or mistyped a comma between 1 and 2

and since (hopefully) square and curly braces won't appear inside keys or values, we can try and balance them, and/or use them as guidance: e.g. if the curly braces are balanced, assume they're okay and do not add or remove any of them. This has to be weighted against users' error capacity - if they are liable to totally misplace a closing curly brace, then we can't rely on balancing.

(Of course, we can't do anything against a malicious user intentionally feeding malformed JSON designed to either trick the system, or even cause a denial of service through some expression requiring exponential time computation).

At that point we could instead, as you suggested, consider the frequency of JSON control characters, or try recognizing JSON subsequences. This has to be compared against whatever else might come in in that field.

The bad answer ("tell between valid JSON and a string")

In the general case you cannot distinguish with 100% accuracy between strings and JSONs because, while not all JSONs are valid strings, all valid strings are valid JSONs. The encoding of a bare string is that string.

So upon receiving "Hello, world", any function would return that this is both a valid string and a valid JSON. Which should it choose?

Otherwise, distinguishing is pretty straightforward. Plug the JSON engine of your choice and try decoding the string as JSON. If you can, that is a JSON string. If you can't, it's a text string:

```<code>-- pseudo code
with ( JSON.decode(myString) ) {
    if (.isNull()) {
        -- Error. Not valid JSON, so it must be a String.
        return "String"
    }
    -- It is a valid JSON, but a String is that, too.
    if (.type().equals("String")) {
        -- Could return either, too, depending.
        return "Ambiguous"
    }
}
return "JSON"
</code>```

This is surely not as efficient as a function that just checks the grammar constraints (you can find the schemas on the home page), but it's a lot more maintainable. You can probably get a FSM by boiling dry the code of a streaming parser and removing all data emission, just returning "true" or "false" (a processing error meaning it's not valid JSON).

OwnerDisplayName: Jonline

Body:
The real answer ("tell between invalid JSON and a string")

For a lot of obvious reasons we're not going to come up with a definite answer - we can at best hope to determine an index that will tell us whether a string might have been JSON.

The best approach I can think of is to use something like the Levenshtein algorithm, with this twist: we have no "B string", but rather we start parsing the candidate string and modify it as soon as we hit an invalid character.

To do this, we can use a JSON streaming parser (state-based). Let's say we parse

{ "key": value" }

then the parser will find the 'v' and choke. At that point we can try deleting the character, or adding one of several possible valid characters for that state and recurse.

Any branch can be abandoned as soon as the distance to valid JSON for that branch exceeds a minimum, if one has been found so far, or according to some heuristics (e.g. no more than four consecutive ['s, and so on), or as soon as it exceeds a maximum allowed distance (say, 5). This last condition is probably essential to avoid snowballing.

A drawback of this approach is that some solutions would require backtracking:

{ "key": "value }

would be accepted up to the end, then a missing " would be added, and finally a missing }, getting a valid JSON:

{ "key": "value }"}

with a distance of 2 (two additions). Perhaps some fast heuristic for backtracking can be found (e.g. when in "wait-for-end-quote", backtrack until the first non-"special" character, and ignore whitespaces).

An important element to assess the viability of a solution would be how is this invalid JSON generated, i.e., is it a truncated JSON? Are some characters damaged? has it some sort of basic structure which is always the same?

User-generated JSON

As per comment, this JSON may be the result of an attempt of hand-building JSON. This on one hand is bad since human beings are very close to a random source when we're talking about errors :-). On the other hand it may be good since the JSON is probably "almost good JSON" with possibly only a few errors: commas left out or added in,

{ "first_name": "John", "last_name": "Doe", "email": "jdoe@email.com", }

Indeed, we might find it useful to at least preprocess the string to remove some common errors:

",\s*} --> "}                       # Extra comma due to copy-paste
   (")\s*[:;.]\s("[^"]"\s:)     # Forgot or mistyped a comma between 1 and 2

and since (hopefully) square and curly braces won't appear inside keys or values, we can try and balance them, and/or use them as guidance: e.g. if the curly braces are balanced, assume they're okay and do not add or remove any of them. This has to be weighted against users' error capacity - if they are liable to totally misplace a closing curly brace, then we can't rely on balancing.

(Of course, we can't do anything against a malicious user intentionally feeding malformed JSON designed to either trick the system, or even cause a denial of service through some expression requiring exponential time computation).

At that point we could instead, as you suggested, consider the frequency of JSON control characters, or try recognizing JSON subsequences. This has to be compared against whatever else might come in in that field.

The bad answer ("tell between valid JSON and a string")

In the general case you cannot distinguish with 100% accuracy between strings and JSONs because, while not all JSONs are valid strings, all valid strings are valid JSONs. The encoding of a bare string is that string.

So upon receiving "Hello, world", any function would return that this is both a valid string and a valid JSON. Which should it choose?

Otherwise, distinguishing is pretty straightforward. Plug the JSON engine of your choice and try decoding the string as JSON. If you can, that is a JSON string. If you can't, it's a text string:

-- pseudo code
with ( JSON.decode(myString) ) {
    if (.isNull()) {
        -- Error. Not valid JSON, so it must be a String.
        return "String"
    }
    -- It is a valid JSON, but a String is that, too.
    if (.type().equals("String")) {
        -- Could return either, too, depending.
        return "Ambiguous"
    }
}
return "JSON"

This is surely not as efficient as a function that just checks the grammar constraints (you can find the schemas on the home page), but it's a lot more maintainable. You can probably get a FSM by boiling dry the code of a streaming parser and removing all data emission, just returning "true" or "false" (a processing error meaning it's not valid JSON).


问:
Should I create separate work and personal GitHub accounts?
I'm fairly new to programming, and I've been working on many personal projects, which I'm concerned can come across as silly and unprofessional. The kind of projects I have are a Reddit Image Downloader and a tool for GMs to use in roleplaying games.

I want to start building up a GitHub account for projects in my chosen field of data analytics, but I'm not sure how to organize projects on my GitHub account. Should I create a "professional" GitHub, mainly containing different analytical scripts and have a separate "personal" account for fun little projects of mine? Or am I just overthinking this, and should I just maintain one account?

答:
I recommend you keep them together.

showing suitable personal projects is often a big plus as it shows your passion and initiative

simpler to manage what goes where over time.

only 1 set of ssh keys to manage

no need to log in/out from one to another.

allows you to have 1 github to 1 main personal email, also simpler.

I think one answer to what you want (and what I do) is to have a paid account (I think its $7 a month for 5 privates) that allows more private repositories.  So keep the work/play ones that you want to be public as public and keep other ones as private.


问:
Pure Front end JavaScript with Web API versus MVC views with ajax
This was more a discussion for what peoples thoughts are these days on how to split a web application.

I am used to creating an MVC application with all its views and controllers. I would normally create a full view and pass this back to the browser on a full page request, unless there were specific areas that I did not want to populate straight away and would then use DOM page load events to call the server to load other areas using AJAX.

Also, when it came to partial page refreshing, I would call an MVC action method which would return the HTML fragment which I could then use to populate parts of the page. This would be for areas that I did not want to slow down initial page load, or areas that fitted better with AJAX calls. One example would be for table paging. If you want to move on to the next page, I would prefer it if an AJAX call got that info rather than using a full page refresh. But the AJAX call would still return an HTML fragment.

My question is. Are my thoughts on this archaic because I come from a .net background rather than a pure front end background?

An intelligent front end developer that I work with, prefers to do more or less nothing in the MVC views, and would rather do everything on the front end. Right down to web API calls populating the page. So that rather than calling an MVC action method, which returns HTML, he would prefer to return a standard object and use javascript to create all the elements of the page.

The front end developer way means that any benefits that I normally get with MVC model validation, including client side validation, would be gone. It also means that any benefits that I get with creating the views, with strongly typed html templates etc would be gone.

I believe this would mean I would need to write the same validation for front end and back end validation. The javascript would also need to have lots of methods for creating all the different parts of the DOM. For example, when adding a new row to a table, I would normally use the MVC partial view for creating the row, and then return this as part of the AJAX call, which then gets injected into the table. By using a pure front end way, the javascript would would take in an object (for, say, a product) for the row from the api call, and then create a row from that object. Creating each individual part of the table row.

The website in question will have lots of different areas, from administration, forms, product searching etc. A website that I don't think requires to be architected in a single page application way.

What are everyone's thoughts on this?

I am interested to hear from front end devs and back end devs.

答:
In my last application I combined REST api and JavaScript front-end.

What I did was :

I created a REST API for CRUD operations.

I created a Javascript application that loads pre-defined HTML
templates and populates with data returned from the REST API.

Basically the JS front-end communicates with REST API for CRUD operations and populates the HTML's with the returned data or created data, or removes the deleted data or updates changed data.

Thus we have pure HTML, we have the processing done on the client, we have less bandwidth usage by not having to load all the HTML and can give an experience truly Web 2.0 to the users.

I do not do business validations on the front end for safety and code duplication, since anyone can change the data before sending them to the server and we have to validate the data on the server again. Therefore, this would be easily hacked. All validations are done on the back-end. Validations on client-side are made only for types of input.

Pros:

Facility to make changes in HTML due to the fact it is not generated
by JS;

Lower consumption of bandwidth by using ajax and JSON;

Lower consumption of server processing, since HTML is populated on
the client side;

Improved user experience by using JS to change the screen, allowing
use of effects and increasing the rendering speed.

Better use of the HTTP protocol, by using REST.

Cons:

2 applications to be maintained;

Depends on the client processing, which can be bad due to poor hardware.

Hope this helps.

Regards,


问:
Simplicity-efficiency tradeoff
The CTO called to inform me of a new project and in the process told me that my code is weird.

He explained that my colleagues find it difficult to understand due to the overly complex, often new concepts and technologies used, which they are not familiar with. He asked me to maintain a simple code base and to think of the others that will inherit my changes.

I've put considerable time into mastering LINQ and thread-safe coding. However, others don't seem to care nor are impressed by anything other than their paycheck.

Do I have to keep it simple (stupid), just because others are not familiar with best practices and efficient coding? Or should I continue to do what I find best and write code my way?

答:
It seems to me that you were given legitimate feedback from your manager.  Not taking anything from it would be a lost opportunity for you.  Whether or not your way is right or not your colleagues are struggling.  If they're struggling the company will struggle and you will struggle providing tons of support when they're trying to debug, extend or otherwise maintain your code.

Definitely do everything you can to mentor them to be better developers, but also take the opportunity to review your coding practices.   Ask yourself:

Am I over-engineering this?

Am I optimizing too early or too much (why design to support a million users if you know the user base will always be much smaller)?

Am I trying to appear "clever" with my solution?  Don't let ego drive you to unnecessary complexity or obscurity

I catch myself being guilty of all these things from time to time and find asking myself these questions helps keep my code simple.  Just remember simple and efficient are not mutually exclusive.

Title: Simplicity-efficiency tradeoff


问:
How would you introduce an agile methodology like scrum?
If you've found agile and walk into a workplace that doesn't particularly follow any methodology and they are resistant to change (as most people usually are), how would you introduce an agile methodology like scrum?

NOTE:

Well, I've phrased it as a hypothetical question, but it isn't.

I'm not very confident about Agile myself

答:
Truth is that it is hard to be a leader and to get things started, if you don't have the power to do so (you said you were not the supervsior or boss).  First you need to have the belief that Agile, Scrum, or whatever may not be the best for you.  Maybe cowboy loner coding is best for you.

Second, you have to have a mission, small at first, but a mission.  The first mission will be for yourself - follow your agile plan so you understand it, just for a small project.

Third, you have to have a mission, small at first, but a mission.  This second mission will involve you and another team member.  After that mission is complete have an honest conversation about the methodology and seeing if it works for you.  If you do guess what?  You need another mission and another person.  Talk about it again.  Eventually you'll have enough to talk to the boss.  But if you have the developers on board, you don't need the boss because everyone will be doing it.

In this latter case, the one where you are successful, I would document from the beginning to the last scenario all that you have done and the results.  I would present that to the boss and at least have a good write up for it and maybe a better raise when the time comes.

Don't forget to document this procedure or you won't get your credit - and you deserve it if it honestly helps you and your organization.

edit:  this presumes you have the freedom from on high to do this.  if you don't you'll need to ask for permission unless you are very sure, in which case you'll have to ask for forgiveness.  Creativity needs freedom.  Be sure you have it or be very careful.


问:
Benefits of porting C library to C++
Say we take any C library such as libpng or libvorbis and convert it so that it compiles as C++ (only the minimum changes to make it compile as C++ code).

Can the compiler do extra optimizations when its C++ code? Is there any sort of benefit to be gained by porting the code to C++? What are the downsides that might cancel out these benefits?

答:
Is there any sort of benefit to be gained by porting the code to C++?

I think the key phrase here is "porting". What do you mean by that? If you truly port the code to C++, make use of C++' features like templates etc., there is a chance this might speed up the code. (For example, C++' std::sort() is known to be faster than C's qsort() because a C++ compiler can inline the calls to the comparison function.) OTOH, the algorithms used are likely to be tailored to C-style programming, so it might well be that the only way to get a measurable speed gain would be to start from scratch and implement and polish for years to make the library shine in C++. However, a C++ compiler can do more compile-time checks for code written in C++ style, so you would gain there.

But if you only make the C code compile with a C++ compiler, the task is questionable. Given C code, a C++ compiler cannot make (m)any assumptions a C compiler cannot make to base its optimizations on. And C-style code is prone to shutting up the compiler (hard casts, no templates, etc.), so you are unlikely to gain any improved type safety at compile time.

What are the downsides that might cancel out these benefits?

Either way, you need to change the code. That will introduce bugs and incompatibilities. That alone is a big downside that will never be outweighed by the meager chances for improvements listed above.

Title: Benefits of porting C library to C++


答:
I think you should keep the accounts separate.

In almost all cases, work you create as a matter of your employment with a company is owned by the company. It is not your property. When you leave the company, the company keeps all that work and you no longer have any rights to it.

If you keep your personal and work accounts separate, it makes this much easier.  When you leave, you just hand over the work account and they take ownership. You would not need to separate your projects from the company projects, and would not need to try to delete the projects from your account. Employment with any given company is fleeting, and the more you entangle your personal stuff with company stuff makes it harder when you separate.

This is my rule of thumb, and certainly individual organizations will have their own opinion on this. I could see some companies deciding that they have no problem with you keeping a copy of this stuff once you leave the company as long as they have a copy too. On the other hand, the company I work at keeps very tight control over things and they would likely fire me if I put company work product on github.

Title: Should I create separate work and personal GitHub accounts?

Body:
I'm fairly new to programming, and I've been working on many personal projects, which I'm concerned can come across as silly and unprofessional. The kind of projects I have are a Reddit Image Downloader and a tool for GMs to use in roleplaying games.

I want to start building up a GitHub account for projects in my chosen field of data analytics, but I'm not sure how to organize projects on my GitHub account. Should I create a "professional" GitHub, mainly containing different analytical scripts and have a separate "personal" account for fun little projects of mine? Or am I just overthinking this, and should I just maintain one account?


问:
Differences between TypeScript and Dart
Microsoft recently unveiled Typescript, a new JavaScript-like programming language.
Some time ago, I heard about Dart, a new programming language created by Google to solve problems related to Javascript like performance, scalability, etc..

The purpose of both new languages seem the same to me.. What do you think?

Are the purposes of the languages the same?

What are the real differences about them?

答:
Had to chime into this discussion with my own finding lately.

1st: TypeScript

MS has taken a nice approach in the fact that you can easily jump in and out of TS and JS.  We mainly use AngularJS for our development and have found while not much documentation exist for converting Angular to TypeScript.  It has been a nice addition to incorporate TypeScript into our Dev workflow.

2nd: Dart

Dart is a bit of an ironic step for Google.  Maybe they don't remember activeX and all of the nightmares around trying to get an application working in anything but the dreaded IE 5 or IE 6 of the day.  It has taken MS many years to recover from those days.

Dart as a language "conceptually" seems to try to combine some nice OOP features.  Annotations etc are a nice thought for Javascript.

The problem, it is hard to imagine enough bandwidth to create a new editor, new language, new vm's across browsers, plugins for other IDE's, compiler to convert to javascript (without being multiple meg in size), convert or create new dart libraries to replace the thousands of current js libraries, have someone decide polymers or directives, convert the dartlang site to use dart, this is what I can think of off the top of my head.

The concept of trying to use Dart in anything but a trivial app at this time is scary.

On top of all of this ES6 is not far away.  ES6 brings many features that Dart is trying to fix that exist in ES5.  What will the value proposition be once ES6 hits the streets?  At least at this time the only change you have to make in TypeScript once ES6 comes out is to maybe choose a different compile to target.

Just to clear up any though that I am a pro MS person.  MS makes some decent products and has made great strides to fix past mistakes with the OSS community.  I still vary rarely use anything other than TypeScript from MS.

Title: Differences between TypeScript and Dart


问:
design practice for business layer when supporting API versioning
Is there any design pattern or practice recommended for business layer when dealing with multiple API version.

For example, I have something like this.

http://site.com/blogs/v1/?count=10

   which calls business object method GetAllBlogs(int count) to get information

http://site.com/blogs/v2/?blog_count=20

which calls business object method GetAllBlogs_v2(int blogCounts)

Since parameter name is changed, I created another business method for version 2.  This is just one example but it could have other breaking changes for which it requires me to create another method to support both version.  Is there any design pattern or best practice for business/data access layer I should follow when supporting API Versioning?

答:
Since the change you made is at the API layer, it should not affect the way the business layer gets blog posts.  Just change the validation of the parameters sent to the business layer.  To illustrate:</p>

```<code>//I don't care about this API thing
class BlogService{
   public getBlogs(int count) {
      //...
   }
}

namespace API.V1

class Blogs{
   //...
   public getBlogs(MyParamterClass p) {
     if (p.hasParameter("count") {
         blogs = blogService.getBlogs(p.getParameter("count"));
     } else {
        //Invalid request handling
     }
   }
}

namespace API.V2

class Blogs extends API.V1.Blogs {
   //...
   public getBlogs(MyParamterClass p) {
     if (p.hasParameter("blog_count") {
       blogs = blogService.getBlogs(p.getParameter("blog_count"));
     } else {
      //Invalid request handling
     }
   }
}
</code>```

Body:
Since the change you made is at the API layer, it should not affect the way the business layer gets blog posts.  Just change the validation of the parameters sent to the business layer.  To illustrate:

//I don't care about this API thing
class BlogService{
   public getBlogs(int count) {
      //...
   }
}

namespace API.V1

class Blogs{
   //...
   public getBlogs(MyParamterClass p) {
     if (p.hasParameter("count") {
         blogs = blogService.getBlogs(p.getParameter("count"));
     } else {
        //Invalid request handling
     }
   }
}

namespace API.V2

class Blogs extends API.V1.Blogs {
   //...
   public getBlogs(MyParamterClass p) {
     if (p.hasParameter("blog_count") {
       blogs = blogService.getBlogs(p.getParameter("blog_count"));
     } else {
      //Invalid request handling
     }
   }
}


问:
Confused about implementing Single Responsibility Principle
Please bear with me if the question looks not well structured.

To put you in the context of my issue:

I am building an application that invoices vehicles stay duration in a parking. In addition to the stay service there are some other services. Each service has its own calculation logic.

Here is an illustration (please correct me if the design is wrong):

```<code>public abstract class Service
{
   public int Id { get; set; }
   public bool IsActivated { get; set; }
   public string Name { get; set }
   public decimal Price { get; set; }
}

public class VehicleService : Service
{
   //MTM : many to many
   public virtual ICollection<MTMVehicleService> Vehicles { get; set; }
}

public class StayService : VehicleService
{

}

public class Vehicle
{
   public int Id { get; set; }
   public string ChassisNumber { get; set; }
   public DateTime? EntryDate { get; set; }
   public DateTime? DeliveryDate { get; set; }
   //...
   public virtual ICollection<MTMVehicleService> Services{ get; set; }
}
</code>```

Now, I am focusing on the stay service as an example:
 I would like to know at invoicing time which class(es) would be responsible for generating the invoice item for the service and for each vehicle? This should calculate the duration cost knowing that the duration could be invoiced partially so the rule is as follows: not yet invoiced stay days * stay price per day.

At this moment I have InvoiceItemsGenerator do everything but I am aware that there is a better design.

答:
I would like to know at invoicing time which class(es) would be
  responsible for generating the invoice item for the service and for
  each vehicle?

It seems pretty obvious that would be the responsibility of your InvoiceItemsGenerator class.

Your problem is with your implementation of InvoiceItemsGenerator, which you say contains bundled within it all the business logic for the various sorts of business and their corresponding invoices, etc.

Maybe try weeding through that business logic and breaking it out into discreet classes that represent the different sorts of logic and apply it -perhaps a class hierarchy with a factory method- it can be used by the InvoiceItemsGeneratorand with further refactoring, perhaps by other classes as well.

Grossly oversimplified and not compilable:

```<code>class BaseServiceInvoiceProcessor
{
  Invoice generateInvoice(){...}
};

class VehicleServiceInvoiceProcessor:BaseServiceInvoiceProcessor{...}
class StayServiceInvoiceProcessor:BaseServiceInvoiceProcessor{...}

BaseServiceInvoiceProcessor getInvoiceProcessor(enumServiceTypes serviceType){...}

InvoiceItemsGenerator
  {
    ...
   Invoice GetInvoiceByServiceType(enumServiceTypes serviceType)
    {
       BaseServiceInvoiceProcessor iProc= getInvoiceProcessor(serviceType);
       return iProc.generateInvoice()
    }

   };
</code>```

etc.

Body:
I would like to know at invoicing time which class(es) would be
  responsible for generating the invoice item for the service and for
  each vehicle?

It seems pretty obvious that would be the responsibility of your InvoiceItemsGenerator class.

Your problem is with your implementation of InvoiceItemsGenerator, which you say contains bundled within it all the business logic for the various sorts of business and their corresponding invoices, etc.

Maybe try weeding through that business logic and breaking it out into discreet classes that represent the different sorts of logic and apply it -perhaps a class hierarchy with a factory method- it can be used by the InvoiceItemsGeneratorand with further refactoring, perhaps by other classes as well.

Grossly oversimplified and not compilable:

class BaseServiceInvoiceProcessor
{
  Invoice generateInvoice(){...}
};

class VehicleServiceInvoiceProcessor:BaseServiceInvoiceProcessor{...}
class StayServiceInvoiceProcessor:BaseServiceInvoiceProcessor{...}

BaseServiceInvoiceProcessor getInvoiceProcessor(enumServiceTypes serviceType){...}

InvoiceItemsGenerator
  {
    ...
   Invoice GetInvoiceByServiceType(enumServiceTypes serviceType)
    {
       BaseServiceInvoiceProcessor iProc= getInvoiceProcessor(serviceType);
       return iProc.generateInvoice()
    }

   };

etc.


答:
I say you can eat the cake in have it too! Introducing GitHub Organizations.

Use your GitHub account for your personal projects, and create an organization for your professional projects. The organization's homepage will show the professional projects you want to introduce, and it'll have a link to your personal account that shows all the things you have done in GitHub.

Benefits:

You'll have the clean separation you wanted while keeping a relation between your personal and professional GitHub activity.

You'll be able to control everything from a single account. No need to relogin just to open a repository in the professional account - all you have to do is to select the organization when you open a new repository.

No need to manage two different SSH keys on the same computer!

You can add other GitHub users to your organization, and even transfer the organization's ownership to them if you even need to. Each user will have their own account, so you don't need to share a professional account's password with other people. As a bonus, different accounts can have different permissions based on their actual role in the team - something you couldn't do with a shared GitHub account for professional projects.

Basically, this approach gives you the benefits of both approaches. The only downside is if you have some personal projects that you don't anyone to ever relate them with your professional public face. However, these criteria usually involves illegal stuff you wouldn't want to put on GitHub in the first place, so it shouldn't be a problem.


问:
How does an optimizing compiler react to a program with nested loops?
Say you have a bunch of nested loops.

```<code>public void testMethod() {
    for(int i = 0; i<1203; i++){
                //some computation
        for(int k=2; k<123; k++){
                        //some computation
            for(int j=2; j<12312; j++){
                                //some computation
                for(int l=2; l<123123; l++){
                                        //some computation
                    for(int p=2; p<12312; p++){
                            //some computation
                    }
                }
            }
        }
    }

}
</code>```

When the above code reaches the stage where the compiler will try to optimize it (I believe it's when the intermediate language needs to converted to machine code?), what will the compiler try to do? Is there any significant optimization that will take place?

I understand that the optimizer will break up the loops by means of loop fission. But this is only per loop isn't it? What I mean with my question is will it take any action exclusively based on seeing the nested loops? Or will it just optimize the loops one by one?

If the Java VM complicates the explanation then please just assume that it's C or C++ code.

答:
An optimising compiler generally works on the basis that the innermost loop is the only one worth the effort. The strategies for optimising loops include unrolling, vectorisation, hoisting (calculations out of the loop), and so on. It may also change the code if it can determine that the loop will terminate early, or not at all. None of these are specific to nested loops.

The only optimisations I know of that are specific to nested loops are these.

Loop exchange/inversion. for(x...){for(y...){...}} can be inverted into for(y...){for(x...){...}} if the compiler can determine that it is (a) equivalent (b) faster or (c) can be made faster.

Vectorisation applied to the inner loop may be extended to vectorise multiple loops, depending on the instruction set available.

If the inner loop can be unrolled or vectorised or deleted then the next loop becomes the inner loop, and is subject to the same optimisations.

If an expression can be hoisted out of an inner loop, it can perhaps be hoisted further.

It's not easy to know which compilers currently implement which if any of these. I know that Fortran compilers were very early implementers of aggressive vectorisation on machines like Cyber and Cray, but I'm not in touch with that now. You would now look at compilers targeting GPUs.


问:
First ATMs programming language
First ATMs performed tasks like a cash dispenser, they were offline machines which worked with punch cards impregnated with Carbon and a 6-digit PIN code.

Maximum withdrawal with a card was 10 pounds and each one was a one-time use card - ATM swallowed cards!

The first ATM was installed in London in the year 1967, as I looked at time line of programming languages, there were many programming languages made before that decade.
I don't know about the hardware either, but in which programming language it was written? (also which hardwares were used?)

*I didn't find a detailed biography of John Shepherd-Barron (ATM inventor at 70s)

Update

I found this picture, which is taken from a newspaper back to the year 1972 in Iran.

Translated PS :

Shows Mr. Rad-lon (if spelled correctly), The manager of Barros (if spelled
  correctly) International Educational Institute in United Kingdom at the right, and
  Mr. Jim Sutherland - Expert of Computer Kiosks.

In the rest of the text I found on this paper, these kind of ATMs which were called "Automated Computer Kiosk" were advertised with this moto:

Mr. Rad-lon (if spelled correctly) puts his card to one specific location of Automated Computer Kiosk and after 10 seconds he withdraws his cash.

Two more questions are:

1- How those ATMs were so fast? (withdrawal in 10 seconds in that year)

2- I didn't find any text on Internet which state about "Automated Computer Kiosk", Is it valid or were they been called Computer in that time?

答:
Answers, as I remember them.

They were fast because they were connected to leased lines and a dedicated server at the bank. Bank software was written in medium and low level compiled languages (Cobol, PL/I, Assembler) with non-relational databases (IMS, IDMS, etc). Response times of 1-2 sec were routinely achieved.

ATM is relatively new. The first modern ATM was an IBM 2984 and came into use at Lloyd Bank, Brentwood High Street, Essex, England in December 1972. I used these machines in London in 1973, and they were called Cashpoint or 'hole in the wall'.

The electronics in these machines was custom built, based on a VDU display terminal and a customer multi-chip processor. Microprocessors were not available until somewhat later.

No, they did not use punched cards or relays. A little perspective, please!

Title: First ATMs programming language


问:
What is the evidence that an API has exceeded its orthogonality in the context of types?
Wikipedia defines software orthogonality as:

orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language. The term is most-frequently used regarding assembly instruction sets, as orthogonal instruction set.

Jason Coffin has defined software orthogonality as

Highly cohesive components that are loosely coupled to each other produce an orthogonal system.

C.Ross has defined software orthogonality as:

the property that means "Changing A does not change B". An example of an orthogonal system would be a radio, where changing the station does not change the volume and vice-versa.

Now there is a hypothesis published in the the ACM Queue by Tim Bray - that some have called the Bánffy Bray Type System Criteria - which he summarises as:

Static typings attractiveness is a direct function (and dynamic typings an inverse function) of API surface size.

Dynamic typings attractiveness is a direct function (and static typings an inverse function) of unit testing workability.

Now Stuart Halloway has reformulated Banfy Bray as:

the more your APIs exceed orthogonality, the better you will like static typing

My question is: What is the evidence that an API has exceeded its orthogonality in the context of types?

Clarification
Tim Bray introduces the idea of orthogonality and APIs. Where you have one API and it is mainly dealing with Strings (ie a web server serving requests and responses), then a uni-typed language (python, ruby) is 'aligned' to that API - because the the type system of these languages isn't sophisticated, but it doesn't matter since you're dealing with Strings anyway.

He then moves on to Android programming, which has a whole bunch of sensor APIs, which are all 'different' to the web server API that he was working on previously. Because you're not just dealing with Strings, but with different types, the API is non-orthogonal.

Tim's point is that there is a empirical relationship between your 'liking' of types and the API you're programming against. (ie a subjective point is actually objective depending on your context).

答:
What is the evidence that an API has exceeded its orthogonality in the context of types?

Literally speaking, any API that allows you to do some task in more than one way is not entirely orthogonal.

Given that there is no formal measure of orthogonality apart from the binary one above, the only meaning for "exceeded its orthogonality" is "not entirely orthogonal".

Thus the "evidence" you are asking for is some task (any task) that can be done more than one way.

Which is not useful ...

The "source" you are asking us to interpret for is a tweet.  I don't think it is a worthwhile activity to read great depth of meaning into it.  In this case, I doubt that deep meaning is intended.  Certainly not the kind of meaning you are trying to read into it.


问:
What is the preferred Internet media type of a RESTful POST request?
Is there a preferred/recommended Internet Media Type for RESTful POST requests?

For example, if I want to add a new user, should I send the data as a URL encoded string like:

```<code>name=Foo&otherData=Bar
</code>```

or does REST recommend I send the data as whatever format the response is going to be sent as (e.g. JSON/XML)?

```<code><user>
  <name>Foo</name>
  <other-data>Bar</other-data>
</user>
</code>```

答:
Is there a preferred/recommended Internet Media Type for RESTful POST requests?

No there isn't. Use the media type that is most convenient for the clients that need to access the API.

With that said, you should always strive to use well-standardized formats, like XML or JSON or application/x-www-form-urlencoded to reduce the amount of work needed in the client. Additionally, if the API is meant for use outside your organization, you'd want to accept requests in multiple media types to let the clients choose the one that's most convenient for them; require the client to send Content-Type header in their requests so the server know how to decode the request body.

or does REST recommend I send the data as whatever format the response is going to be sent as (e.g. JSON/XML)?

There isn't any requirement for request body to have the same content type as the response, nor any need to. A REST client should send a Content-Type header to specify the request's media type and Accept header to negotiate the response media type.


问:
What happened to VM based deployments?
Watched some MountainWest RubyConf 2014 talks and noticed an interesting theme. Many dynamic programming environments back in the old days used to be self-contained VM images, e.g. SmallTalk, GemStone/S.

One could checkpoint, modify, and ship these images wholesale and have it up and running with very little effort. Fast forward to now and I'm still using Make files to configure and install binaries. What happened?

答:
Yes, there used to be quite a few of these. I'm referring to a single package that contains code written for a VM, the VM itself and a set of data files, often using a proprietary database format. If you write and save code it too gets saved inside the environment.

The advantage it that it's a single object to ship, and it just runs with no installation since it has no dependencies (except that target OS). I recall various flavours of Smalltalk, Logo, Mumps/MIIS, Pick/Information/Ultimate.

They share much of the same history with 4GLs and together they constitute something of a programmer's [walled garden] (http://en.wikipedia.org/wiki/Closed_platform). I think what happened, surprisingly, was the Internet.

Developers had long wanted a better database, better IDE, better libraries, etc. Before the Internet they were stuck, but suddenly they could find all sorts of better tools and the package vendors couldn't move fast enough to either bring them inside the walled garden or compete directly. These packages gave you everything you needed as long as you didn't need much, but the Internet gave you infinite choice, at a price.

Personally I think that the walled garden has a lot going for it, especially for programmers with limited skills. However, you can't make money out of them any longer and the smart people creating tools don't see the point, so I don't think we'll see a comeback.

Title: What happened to VM based deployments?


问:
Rewriting code under BSD license
I am currently studding OpengGL with OpenGL Supebible 5th edition. I've found interested for me some C++ code that is distributed with the book (see also on google code). That code is under New BSD License. I am writing my software on C# with SharpGL wrapper and I'd like to know following things:

Can I rewrite that C++ to C#? edid: I'am interesting in using such things like GLBatch, GLShaderManager and some other thing from GLTools. Problem is that library is on C++, but I use C#.

How do I have to mark my source code if I put it somewhere like to my github account?

What disclaimer should be?

Original disclaimer looks like:

```<code>/* GLShaderManager.h

Copyright (c) 2009, Richard S. Wright Jr.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

Neither the name of Richard S. Wright Jr. nor the names of other contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
</code>```

Edit:
Should my copyright looks like after rewriting something like that?

```<code>Copyright (c) 2014, My Name

Copyright (c) 2009, Richard S. Wright Jr.
All rights reserved.

Redistribution...................
</code>```

答:
With most open source licences you can do what you like with the code as long as it's for your own personal use. However if you plan on distributing the code (or any significant part of it) to others then you can only do that in the way that the licence allows.

BSD is pretty easy to comply with. What you are proposing should be just fine. If in doubt, contact the author and ask.

As I tell people repeatedly, if you make no money out of it and harm no-one then just do your best, acknowledge the work of others and don't worry too much. If you make money out of your product or services and/or if you may cause damage to someone, you must take competent legal advice. That won't protect you, but it will warn you about the risks and possibly help to mitigate them.

If you write new code which is based on close study of code written by someone else but is not a copy or adaptation of it, you may be able to argue that you don't need a licence. That's only something to consider if at some future time you want to use the code in ways that might breach the BSD licence.

Title: Rewriting code under BSD license


问:
Is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified?
This question is about good design practice in programming.

Let see this example, we have 2 interrelated tables:

```
Table1
textID - text
1      - love..
2      - men...
...

Table2
rID - textID
1   - 1
2   - 2
...
```

Note:

In Table1:

textID is auto_increment primary key

In Table2:

rID is auto_increment primary key & textID is foreign key

The relationship is that 1 rID will have 1 and only 1 textID but 1 textID can have a few rID.

So, when table1 got modification then table2 should be updated accordingly.

Ok, here is a fictitious example. You build a very complicated system. When you modify 1 record in table1, you need to keep track of the related record in table2. To keep track, you can do like this:

Option 1: When you modify a record in table1, you will try to modify a related record in table 2. This could be quite hard in term of programming expecially for a very very complicated system.

Option 2: instead of modifying a related record in table2, you decided to delete old record in table 2 & insert new one. This is easier for you to program.

For example, suppose you are using option2, then when you modify record 1,2,3,....,100 in table1, the table2 will look like this:

```
Table2
rID   - textID
101   - 1
102   - 2
...
200   - 100
```

This means the Max of auto_increment IDs in table1 is still the same (100) but the Max of auto_increment IDs in table2 already reached 200.

what if the user modify many times? if they do then the table2 may run out of records? we can use BigInt but that make the app run slower?

Note: If you spend time to program to modify records in table2 when table1 got modified then it will be very hard & thus it will be error prone. But if you just clear the old record & insert new records  into table2 then it is much easy to program & thus your program is simpler & less error prone.

So, is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified?

答:
The unneccesary complexity you are facing originates from the fact that your design is not normalized.

If two entities have a one-to-one relationship, you have to reconsider whether they should be a single entity.

Unless Table2 represents a role specialization of Table1, which it doesn't seem to be since Table2 has no other columns, there's no need of them being separate tables.

In a normalized design, that complicated update strategies never arise. Normalization eliminate update inconsistencies.


答:
Everyone follows a methodology. Their's probably doesn't have a standard name and may be inconsistent.

If everyone is productive and likes the way things are, change is difficult (as it should be in this case).

Think about the problems 'agile' has solved for you. Present these privately to the leader if they address issues he/she has identified. Getting someone to accept they have a problem is usually the hardest part, so pick on the low-hanging fruit.

Eventually, they like the pieces of a methodology and find that using all aspects of it is usually what it takes to make the whole thing work. It also can save a lot of trial and error.

Title: How would you introduce an agile methodology like scrum?

Body:
If you've found agile and walk into a workplace that doesn't particularly follow any methodology and they are resistant to change (as most people usually are), how would you introduce an agile methodology like scrum?

NOTE:

Well, I've phrased it as a hypothetical question, but it isn't.

I'm not very confident about Agile myself


问:
Is it RESTful to resume terminated POST operation on a GET request?
I have a RESTful API, one of the resource has a state that is determined collectively by multiple servers, not all of them belong to us. One of the operation on this resource will have to modify the state of multiple servers. The client sends a POST request to do this operation to our API server and our API server sends requests to the other servers to fulfil the request.

Due to the nature of the whole operations, not all of the operation can be done in a single transaction. The APIs for the participating servers mostly do not support 2-phase commit, but most do have some idempotence guarantee, although not all of them are RPCish rather than RESTful. If any error happens during this operation, the resource is left on an intermediate state, but the server should be able to repeat the operations from the point it has left off to fix the resource's state.

Would it be a bad idea or would it conflict with REST principles if the server transparently resumes unfinished operations the next time the client reloads the state of the request (with a GET) rather than requiring the client to discover the resource is in an intermediate state and send another request to fix the situation before continuing anything else.

One one hand, GET is supposed to be a safe operation, but on the other hand, letting GET resolve the situation simplifies the client as it doesn't have to deal with this situation.

Note that the users also interacts with the other participating servers directly (i.e. not just through our client) so they may see some of the effects of the operations if a resource is left in an intermediate state.

答: The GET should be indepotent.  If you're using it to change state, then you're abusing the REST call and your api would be considered poorly designed.  You shouldn't use GET and some side effect to proceed.</p>


问:
How to refactor my design, if it seems to require multiple inheritance?
Recently I made a question about Java classes implementing methods from two sources (kinda like multiple inheritance). However, it was pointed out that this sort of need may be a sign of a design flaw. Hence, it is probably better to address my current design rather than trying to simulate multiple inheritance.

Before tackling the actual problem, some background info about a particular mechanic in this framework:

It is a simple game development framework. Several components allocate some memory (like pixel data), and it is necessary to get rid of it as soon as you don't need it. Sprites are an example of this.

Anyway, I decided to implement something ala Manual-Reference-Counting from Objective-C. Certain classes, like Sprites, contain an internal counter, which is increased when you call retain(), and decreased on release().

Thus the Resource abstract class was created. Any subclass of this will obtain the retain() and release() implementations for free. When its count hits 0 (nobody is using this class), it will call the destroy() method. The subclass needs only to implement destroy().

This is because I don't want to rely on the Garbage Collector to get rid of unused pixel data.

Game objects are all subclasses of the Node class - which is the main construction block, as it provides info such as position, size, rotation, etc.

See, two classes are used often in my game. Sprites and Labels.

Ah... but wait. Sprites contain pixel data, remember? And as such, they need to extend Resource.

But this, of course, can't be done. Sprites ARE nodes, hence they must subclass Node. But heck, they are resources too.

Why not making Resource an interface?

Because I'd have to re-implement retain() and release(). I am avoiding this in virtue of not writing the same code over and over (remember that there are multiple classes that need this memory-management system).

Why not composition?

Because I'd still have to implement methods in Sprite (and similar classes) that essentially call the methods of Resource. I'd still be writing the same code over and over!

What is your advice in this situation, then?

答:
You wrote

Sprites contain pixel data

which is a clear sign of a "has a" relationship, not an "is a". So bite the bullet and make Sprite -> Resource a composition.

Why not composition? Because I'd still have to implement methods in Sprite (and similar classes) that essentially call the methods of Resource

yes, you will - but only trivial delegation methods. You won't have to repeat any functional code. That's actually acceptable. and the standard way composition/delegation works. Here you find a detailed example how to replace inheritance by delegation. This approach is so common, there is even an Eclipse refactoring exactly for this purpose,


问:
What license is the GPL License licensed under?
The actual GPL License (that is, the text that contains the words "The licenses for most software and other practical works are designed...") is a document; I would assume therefore that it is under some sort of copyright?

What license is this license licensed under?

That is, if I were to include the body of the GPL License in my own projects (and perhaps create a derivative work) what limitations am I under?

答:
The standard copyright terms for GNU web pages [and all text contained therein] is the Creative
Commons Attribution-NoDerivs 3.0 United States License. It used to be
(and for a few pages still is): Verbatim copying and distribution of
this entire article are permitted worldwide, without royalty, in any
medium, provided this notice is preserved.

Notice the use of the word "verbatim."  The license states that

You are free to:

Share — copy and redistribute the material in any medium or format for any purpose, even commercially. The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:

Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

No Derivatives — If you remix, transform, or build upon the material, you may not distribute the modified material.

Kinda makes sense, really.  If you want people to use your license freely, but don't want them to alter it, this is the license you would use.

http://www.gnu.org/licenses/licenses.html


答:
Let me preface this by saying IANAL.

It might be possible to think of your particular situation of adding mark ups to license text as providing a translation (although from text to Markdown, rather than to another human language), which is regarded as such:

Are there translations of the GPL into other languages?
  :

It would be useful to have translations of the GPL into languages other than English. People have even written translations and sent
  them to us. But we have not dared to approve them as officially valid.
  That carries a risk so great we do not dare accept it.

A legal document is in some ways like a program. Translating it is like translating a program from one language and operating system to
  another. Only a lawyer skilled in both languages can do it—and even
  then, there is a risk of introducing a bug.

If we were to approve, officially, a translation of the GPL, we would be giving everyone permission to do whatever the translation
  says they can do. If it is a completely accurate translation, that is
  fine. But if there is an error in the translation, the results could
  be a disaster which we could not fix.

If a program has a bug, we can release a new version, and eventually the old version will more or less disappear. But once we
  have given everyone permission to act according to a particular
  translation, we have no way of taking back that permission if we find,
  later on, that it had a bug.

Helpful people sometimes offer to do the work of translation for us. If the problem were a matter of finding someone to do the work,
  this would solve it. But the actual problem is the risk of error, and
  offering to do the work does not avoid the risk. We could not possibly
  authorize a translation written by a non-lawyer.

Therefore, for the time being, we are not approving translations of the GPL as globally valid and binding. Instead, we are doing two
  things:

Referring people to unofficial translations. This means that we permit people to write translations of the GPL, but we don't
  approve them as legally valid and binding.

An unapproved translation has no legal force, and it should say so explicitly. It should be marked as follows:

This translation of the GPL is informal, and not officially approved by the Free Software Foundation as valid. To be
    completely sure of what is permitted, refer to the original GPL (in
    English).

But the unapproved translation can serve as a hint for how to understand the English GPL. For many users, that is sufficient.

However, businesses using GNU software in commercial activity, and people doing public ftp distribution, should need to check the
  real English GPL to make sure of what it permits.

Publishing translations valid for a single country only.

We are considering the idea of publishing translations which are officially valid only for one country. This way, if there is a
  mistake, it will be limited to that country, and the damage will not
  be too great.

It will still take considerable expertise and effort from a sympathetic and capable lawyer to make a translation, so we cannot
  promise any such translations soon.

Title: What license is the GPL License licensed under?

Body:
The actual GPL License (that is, the text that contains the words "The licenses for most software and other practical works are designed...") is a document; I would assume therefore that it is under some sort of copyright?

What license is this license licensed under?

That is, if I were to include the body of the GPL License in my own projects (and perhaps create a derivative work) what limitations am I under?


答: No, its not necessary.    While it might be convenient for browsing through the data manually, it doesn't impact the program at all since you already have the textid in the second column.  Don't worry about what the auto_increment key value is in the tables.  Just look at it as a guaranteed unique value that can be use to identify the row.

Title: Is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified?

Body:
This question is about good design practice in programming.

Let see this example, we have 2 interrelated tables:

```
Table1
textID - text
1      - love..
2      - men...
...

Table2
rID - textID
1   - 1
2   - 2
...
```

Note:

In Table1:

textID is auto_increment primary key

In Table2:

rID is auto_increment primary key & textID is foreign key

The relationship is that 1 rID will have 1 and only 1 textID but 1 textID can have a few rID.

So, when table1 got modification then table2 should be updated accordingly.

Ok, here is a fictitious example. You build a very complicated system. When you modify 1 record in table1, you need to keep track of the related record in table2. To keep track, you can do like this:

Option 1: When you modify a record in table1, you will try to modify a related record in table 2. This could be quite hard in term of programming expecially for a very very complicated system.

Option 2: instead of modifying a related record in table2, you decided to delete old record in table 2 & insert new one. This is easier for you to program.

For example, suppose you are using option2, then when you modify record 1,2,3,....,100 in table1, the table2 will look like this:

```
Table2
rID   - textID
101   - 1
102   - 2
...
200   - 100
```

This means the Max of auto_increment IDs in table1 is still the same (100) but the Max of auto_increment IDs in table2 already reached 200.

what if the user modify many times? if they do then the table2 may run out of records? we can use BigInt but that make the app run slower?

Note: If you spend time to program to modify records in table2 when table1 got modified then it will be very hard & thus it will be error prone. But if you just clear the old record & insert new records  into table2 then it is much easy to program & thus your program is simpler & less error prone.

So, is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified?


问:
How to design console application with good seperation of UI from Logic

Is it considered an overkill for console application to be design like MVC , MVP or N tier architecture?  If not which is more common and if you can link me to simple example of it.

I want to implement a tic tac toe game in console application.

I have a solution which hold two projects: TicTacToeBusinessLogic (Class library project) and
TicTacToeConsoleApplication (Console application project) to represent the view logic.
In the TicTacToeConsoleApplication I've Program.cs class which holds the main entry point (public static void Main).

Now I face a problem.

I want the game to handle its own game flow so I can:
Create new GameManager class (from BL) but this causing the view to directly know the BL part.

So I'm a little confused how to write it in an acceptable way.
Should I use delegates? Please show me a simple example.

答:
I would at the very least go with something where you have one layer that listens to keyboard etc. events and translates those into calls into the game logic layer and gets updated (Observer) as those calls change the state of the game.

Take it a few steps further and guess what, you are back in MVC or MVP or MVVM territory.

Whether or not to go with any of these patterns has nothing to do with the type of UI, and everything to do with separation of concerns, loose coupling and maintainability.


答:
Your Sprite object is effectively trying to take 2 responsibilities: manage memory cleanup and do the job with mentioned pixel data. The S letter in SOLID principles advices to leave each class a single responsibility. Bread doesn't slice itself: there is some external force that takes the bread, the tool(s) and does its job. I would think of those, who are going to call these retain() and release() methods. Are the callers actually want to "slice the bread", i.e. "do the referencecounting of the arbitrary object"?

So I would recommend neither composite, nor inherit the Resource in Sprite, but rename it to some sort of ResourceReferenceCounter and use Sprite and ResourceReferenceCounter independently. Which is how effectively java garbage collector works with your objects from your application's point of view.

Title: How to refactor my design, if it seems to require multiple inheritance?

Body:
Recently I made a question about Java classes implementing methods from two sources (kinda like multiple inheritance). However, it was pointed out that this sort of need may be a sign of a design flaw. Hence, it is probably better to address my current design rather than trying to simulate multiple inheritance.

Before tackling the actual problem, some background info about a particular mechanic in this framework:

It is a simple game development framework. Several components allocate some memory (like pixel data), and it is necessary to get rid of it as soon as you don't need it. Sprites are an example of this.

Anyway, I decided to implement something ala Manual-Reference-Counting from Objective-C. Certain classes, like Sprites, contain an internal counter, which is increased when you call retain(), and decreased on release().

Thus the Resource abstract class was created. Any subclass of this will obtain the retain() and release() implementations for free. When its count hits 0 (nobody is using this class), it will call the destroy() method. The subclass needs only to implement destroy().

This is because I don't want to rely on the Garbage Collector to get rid of unused pixel data.

Game objects are all subclasses of the Node class - which is the main construction block, as it provides info such as position, size, rotation, etc.

See, two classes are used often in my game. Sprites and Labels.

Ah... but wait. Sprites contain pixel data, remember? And as such, they need to extend Resource.

But this, of course, can't be done. Sprites ARE nodes, hence they must subclass Node. But heck, they are resources too.

Why not making Resource an interface?

Because I'd have to re-implement retain() and release(). I am avoiding this in virtue of not writing the same code over and over (remember that there are multiple classes that need this memory-management system).

Why not composition?

Because I'd still have to implement methods in Sprite (and similar classes) that essentially call the methods of Resource. I'd still be writing the same code over and over!

What is your advice in this situation, then?


答:
The terms under which the text of the various versions of the GPL may be distributed are quite clearly given in the opening lines of the licences:

GNU General Public License, Version 3:

Copyright © 2007 Free Software Foundation, Inc. http://fsf.org/

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

GNU General Public License, Version 2:

Copyright (C) 1989, 1991 Free Software Foundation, Inc.

  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

Everyone is permitted to copy and distribute verbatim copies

  of this license document, but changing it is not allowed.

GNU General Public License, Version 1:

Copyright (C) 1989 Free Software Foundation, Inc.

  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

  Everyone is permitted to copy and distribute verbatim copies

  of this license document, but changing it is not allowed.


问:
Do I need to contact a lawyer to report a GPL violation in software distributed on Apple's App Store?
Some company is selling software through Apple's App Store which uses portions of code that I released publicly under the GPL. The company is violating the licensing terms in two ways, by (1) not preserving my copyright statement, and not releasing their code under the GPL license and (2) by distributing my GPL-licensed code through Apple's App Store. (The Free Software Foundation has made clear that the terms of the GPL and those of the App Store are incompatible.) I want to report this to Apple, and ask that they take appropriate action. I have tried mailing them to ask for more information about the reporting process, and have received the automated reply quoted below.

The last point in the list of things one needs to provide, the “a statement by you, made under penalty of perjury,” sounds as if they mean some kind of specific legal document. I'm not sure. Does this mean I need to contact a lawyer just to file the report? I'd like to avoid going through that hassle if at all possible.

(Besides an answer to this specific question, I'd welcome comments and experience reports from anyone who has already had to deal with a GPL violation on Apple's App Store.)

Thank you for contacting Apple's Copyright Agent.  If you believe that your work has been copied in a way that constitutes infringement on Apple’s Web site, please provide the following information:

an electronic or physical signature of the person authorized to act on behalf of the owner of the copyright interest;

a description of the copyrighted work that you claim has been infringed;

a description of where the material that you claim is infringing is located on the site; your address, telephone number, and email address;

a statement by you that you have a good faith belief that the disputed use is not authorized by the copyright owner, its agent, or the law;

a statement by you, made under penalty of perjury, that the above information in your Notice is accurate and that you are the copyright owner or authorized to act on the copyright owner’s behalf.

For further information, please review Apple's Legal Information & Notices/Claims of Copyright Infringement at: http://www.apple.com/legal/trademark/claimsofcopyright.html

To expedite the processing of your claim regarding any alleged intellectual property issues related to iTunes (music/music videos, podcasts, TV, Movies), please send a copy of your notice to iTunesStoreNotices@apple.com   For claims concerning a software application, please send a copy of  your notice to AppStoreNotices@apple.com.

Due to the high volume of e-mails we receive, this may be the only reply you receive from copyrightagent@apple.com.  Please be assured, however, that Apple's Copyright Agent and/or the iTunes Legal Team will promptly investigate and take appropriate action concerning your report.

答:
There is a standard process for handling copyright violations in a situations like this, and that is sending a DMCA notice to Apple, just as they described it. What happens after you send a correct DMCA notice is that Apple will remove the app from their store and inform the app developers. The app developers have the choice to give in, or to send Apple a counter notice saying that they are not infringing on your copyright. If that happens, Apple will put the app back on the store, and then you have the choice of suing the app developers - at that point you definitely need a lawyer. (Apple may look at the situation and decide that they don't want the app if they believe there is copyright infringement, but they don't have to).

What you are worried about is the "under penalty of perjury" bit. You say that you have the copyright on some software X, and you believe that software Y on the store infringes your copyright. You must absolutely make sure that you do indeed have the copyright on software X. So you wrote it and didn't sell the copyright, and it wasn't a work for hire that a company owns that paid you. Or you bought the copyright from the copyright holder. That must be true, and if it isn't, then you commit perjury. But that is something I assume you would know. If you are not sure whether you own the copyright, you'd need a lawyer. Obviously when you license under the GPL or any other license, you still own the copyright. If you transferred the copyright to the FSF, for example, then you are not the copyright holder and sending a DMCA notice claiming you are would be perjury.

On the other hand, when you say that software Y infringes your copyright, you might be wrong. They might not use your code at all, or they might have a valid license. That's Ok, nothing can happen to you because you made a mistake here, as long as you have you have a good faith belief that there is copyright infringement. So all in all, as long as you are 100% sure that you are the copyright holder, you don't need a lawyer at this point. And if you are not the copyright holder, a lawyer can't help you.

Now all that said, you should think very hard whether the app store is indeed incompatible with the GPL license. I personally don't think so at all. The Free Software Foundation is frankly not an unbiased source. Nor am I. (Apple will still remove the software, since it's none of their business. It's between you and that app developer. And not providing the source code is definitely wrong, app store or not). If all you disagree with is the principle of distribution through the app store, you really need to think about what you want to achieve. Do you want to give people the freedom to use your software by denying them to use your software?


问:
If you had to go back and re-learn your skill set, how would you do it?
My younger brother is looking to start programming. He's 14, and technically-inclined, but no real experience programming. He's looking to me for guidance, and I don't feel as if my experience is enough, so I figured I'd ask here.

He's more interested in web programming, but also has an interest in desktop/mobile/server applications.

What would be a good learning path for him to take? I'm going to buy him a bunch of books for Christmas to get him started; the question is, what should he learn, and in which order?

The way I see it, he needs to learn theory and code. I'd like to start him off with Python or Ruby or PHP. If he wants to get in to web, he's also going to need to learn HTML, CSS, Javascript, etc.

Out of those three domains (Languages, Theory, Markup/Etc.), what is the best order do you think to learn in? Also, am I missing anything?

Thanks!

答:
I would go to school, if college age.
I would take it high school, if high school age.

I'd have a mission and adjust the curriculum accordingly at 14.

many people will down me for this but Visual Basic .NET seems to be easier for some, just saying folks.  It appears to be that way for many not in the initiate.


答:
web / desktop / mobile / server programming? Seems like to me, he is interested in everything. The problem is however, he's gotta start with something.

Many will disagree, as of course there is no "right" answer to this, but I'd buy him a book on Python (Learning Python is thick and thorough enough to keep him busy for a long time), and it is definitely a language which will give him a good ratio of stuff I learned vs. eye candy (i.e. what can be achieved with it). It is also a good starting point for many of the above.

After that, see what he favours the most of the above mentioned, and direct him further with advice in that direction.

Title: If you had to go back and re-learn your skill set, how would you do it?

Body:
My younger brother is looking to start programming. He's 14, and technically-inclined, but no real experience programming. He's looking to me for guidance, and I don't feel as if my experience is enough, so I figured I'd ask here.

He's more interested in web programming, but also has an interest in desktop/mobile/server applications.

What would be a good learning path for him to take? I'm going to buy him a bunch of books for Christmas to get him started; the question is, what should he learn, and in which order?

The way I see it, he needs to learn theory and code. I'd like to start him off with Python or Ruby or PHP. If he wants to get in to web, he's also going to need to learn HTML, CSS, Javascript, etc.

Out of those three domains (Languages, Theory, Markup/Etc.), what is the best order do you think to learn in? Also, am I missing anything?

Thanks!