答:
my solution will give you stronger skew for bigger dominance differences:

it is using the fact that raising a value between 0 and 1 to a positive power will skew the result within the same range.

set the fine-tuning, as you see fit.

```<code>import random
a_trait = 5
a_dominance = 2
b_trait = 10
b_dominance = 7

target = random.random()
skew = abs(a_dominance - b_dominance) + 1
fine_tuning_multiplier = 0.3
skewed_target = target ** (skew * fine_tuning_multiplier)

trait_delta = abs(a_trait - b_trait)
target_trait = trait_delta * (1 - skewed_target)

if a_dominance > b_dominance:
  val = b_trait - target_trait
else:
  val = a_trait + target_trait

print "val:", int(round(val))
</code>```

note that in this solution the traits must be sorted. (i.e. a_trait < b_trait)

40 consecutive runs resulted in:

8 8 9 8 9 10 6 7 7 10 8 8 9 9 10 9 9 7 10 6 10 7 10 9 10 10 7 8 8 7 10 5 6 6 9 9 10 10 6 6

Title: python random with a skew

Body:
my solution will give you stronger skew for bigger dominance differences:

it is using the fact that raising a value between 0 and 1 to a positive power will skew the result within the same range.

set the fine-tuning, as you see fit.

import random
a_trait = 5
a_dominance = 2
b_trait = 10
b_dominance = 7

target = random.random()
skew = abs(a_dominance - b_dominance) + 1
fine_tuning_multiplier = 0.3
skewed_target = target ** (skew * fine_tuning_multiplier)

trait_delta = abs(a_trait - b_trait)
target_trait = trait_delta * (1 - skewed_target)

if a_dominance > b_dominance:
  val = b_trait - target_trait
else:
  val = a_trait + target_trait

print "val:", int(round(val))

note that in this solution the traits must be sorted. (i.e. a_trait < b_trait)

40 consecutive runs resulted in:

8 8 9 8 9 10 6 7 7 10 8 8 9 9 10 9 9 7 10 6 10 7 10 9 10 10 7 8 8 7 10 5 6 6 9 9 10 10 6 6


问:
Fixed window size app development for Mac OS X
I am developing a rather eye-candy application which is to be released on Mac App Store.

Due to its graphics intensive use, it would save a great deal of time on UI end if the app could be released with a fixed size main frame-dialog.

I did try doing a search regarding App Store policies on the matter but could not find anything.

Is the distribution of fixed-size frame [productivity] apps are allowed within the App Store if they conform with other design guidelines?

答:
An app will not be rejected only because it has a fixed window size.

Although such a design choice could result in an inferior useabity. And that could be a reason for refusal.

ContentLicense: CC BY-SA 3.0


问:
Why Have People Started Deeming it Necessary to Separate JS hooks from CSS hooks in HTML?
Edit: Point of clarificatioon, IDs and classes as separate hooks is just one form of the applied idea in question which is to never use the same hooks for CSS as you do in JS. I've also seen people want things like js-combo_box and css-combo_box as classes on the same element.

This is one I've started running into more and more in recent years. People wanting to only use IDs for JS and classes for CSS. Or they don't want JS to touch classes and IDs at all and rely on things like HTML5 data-attributes hooks (which is and will probably remain the slowest way to actually find an element even in modern browsers).

In 5+ years of occasionally heavy-duty/insane-environment client-side web development including one very large totally messed up e-commerce retail operation where HTML nobody was even working with would mutate because we had 200 offshore devs of varying levels code illiteracy (completely on the low end, not kidding) jumping up and down on the back end codebase with no source control, I've never run into an issue where JS and CSS targeting shared attributes in the HTML caused any kind of maintainability or ease of modification problem for me. I guess I'm wondering what is informing this perceived need and whether I'm missing something that comes up for a lot of people?

Isn't HTML via selectors and the DOM API effectively the point of abstraction that ties everything together? Why would JS and CSS concerns sharing the same attributes there ever cause a problem?

答:
Using classes for JS makes perfect sense.

Classes, like their name suggests classify DOM elements.

For example, if I had a list of items

```<code><div class='item'>Item1</div>
<div class='item'>Item2</div>
<div class='item'>Item3</div>
<div class='item'>Item4</div>
</code>```

It would make perfect sense to select them with the following selector .item instead of assigning an ID to each of them.

More-over, in many commonly used JavaScript libraries and code bases class selectors are used for selecting elements. I've seen it used in production code many times and it seems like acceptable practice.

The only beef people have with class selectors over ID selectors is that ID selectors are faster (perf here). Most of the time I have found that doesn't really matter.

Body:
Using classes for JS makes perfect sense.

Classes, like their name suggests classify DOM elements.

For example, if I had a list of items

<div class='item'>Item1</div>
<div class='item'>Item2</div>
<div class='item'>Item3</div>
<div class='item'>Item4</div>

It would make perfect sense to select them with the following selector .item instead of assigning an ID to each of them.

More-over, in many commonly used JavaScript libraries and code bases class selectors are used for selecting elements. I've seen it used in production code many times and it seems like acceptable practice.

The only beef people have with class selectors over ID selectors is that ID selectors are faster (perf here). Most of the time I have found that doesn't really matter.


答:
Maybe you notice that because, as you said it yourself, you have to work with inexperienced programmers.

In practice, the distinction you observe doesn't exist. Frameworks, by the way, discourage such distinction.

For example, jQuery encourages pretty well to use selectors in a general way, which means that you use IDs to target a single element and classes to target multiple elements.

In the same way, a not totally retarded developer would quickly notice (learn) that classes are bad candidates for unique elements on a page: of course, you can replace all IDs by classes in both HTML and correspond CSS, but it would make things slightly... let's say unreadable, if nobody cares about performance.

As for the inexperienced programmers, they may tend to do strange things. It took me a few weeks to explain to one fellow colleague that:

```<code><div id="entry">Some text here</div>
<div id="entry">Some other text</div>
</code>```

is wrong, because IDs are unique. Take one beginner who have just read an article explaining how to use classes in CSS and another article about data- attributes in jQuery, and you easily understand why this beginner starts to use classes for CSS and data- for jQuery selectors.

Title: Why Have People Started Deeming it Necessary to Separate JS hooks from CSS hooks in HTML?

Body:
Edit: Point of clarificatioon, IDs and classes as separate hooks is just one form of the applied idea in question which is to never use the same hooks for CSS as you do in JS. I've also seen people want things like js-combo_box and css-combo_box as classes on the same element.

This is one I've started running into more and more in recent years. People wanting to only use IDs for JS and classes for CSS. Or they don't want JS to touch classes and IDs at all and rely on things like HTML5 data-attributes hooks (which is and will probably remain the slowest way to actually find an element even in modern browsers).

In 5+ years of occasionally heavy-duty/insane-environment client-side web development including one very large totally messed up e-commerce retail operation where HTML nobody was even working with would mutate because we had 200 offshore devs of varying levels code illiteracy (completely on the low end, not kidding) jumping up and down on the back end codebase with no source control, I've never run into an issue where JS and CSS targeting shared attributes in the HTML caused any kind of maintainability or ease of modification problem for me. I guess I'm wondering what is informing this perceived need and whether I'm missing something that comes up for a lot of people?

Isn't HTML via selectors and the DOM API effectively the point of abstraction that ties everything together? Why would JS and CSS concerns sharing the same attributes there ever cause a problem?

Body:
Maybe you notice that because, as you said it yourself, you have to work with inexperienced programmers.

In practice, the distinction you observe doesn't exist. Frameworks, by the way, discourage such distinction.

For example, jQuery encourages pretty well to use selectors in a general way, which means that you use IDs to target a single element and classes to target multiple elements.

In the same way, a not totally retarded developer would quickly notice (learn) that classes are bad candidates for unique elements on a page: of course, you can replace all IDs by classes in both HTML and correspond CSS, but it would make things slightly... let's say unreadable, if nobody cares about performance.

As for the inexperienced programmers, they may tend to do strange things. It took me a few weeks to explain to one fellow colleague that:

<div id="entry">Some text here</div>
<div id="entry">Some other text</div>

is wrong, because IDs are unique. Take one beginner who have just read an article explaining how to use classes in CSS and another article about data- attributes in jQuery, and you easily understand why this beginner starts to use classes for CSS and data- for jQuery selectors.


答:
Okay, a complete flip-flop of what I was going to write, based on two specific parts of the question:

we had 200 offshore devs of varying levels code illiteracy (completely on the low end, not kidding)

and

Why would sharing attributes there ever cause a problem?

I have run across something similar to this in the project I'm on at work right now.  What I was dealing with is what happens when the unskilled programmers tie functionality entirely to classes, without thinking about consequences or maintainability.  (That is, they were reusing classes just because they're there and happen to be on all the right elements)

What you're looking at is a simple, sledgehammer-like way to enforce separation of concerns on the unskilled programmers.

If functionality is strictly tied to IDs, and design to Classes, then they can change both without having to worry about the other.  This is especially helpful from a design standpoint - as long as they include all the requisite IDs for the Javascript functionality, they're fine.

That said, I strongly disagree with this approach (see other answers for why).  It's extremely limiting to even the halfway-decent programmers and almost always requires extra bookkeeping javascript to keep track of #foo_1, #foo_2... when .foo would have sufficed.

EDIT @jmoreno has pointed out that I missed the clarification paragraph at the top, so now parts of my original answer seems much more appropriate.  Personal anecdote time!

See, at work, we have a library written in Django+JS+CSS, shared among a large chunk of our products.  It was written in a very specific way, meant to be highly configurable, and included into various projects by way of a Django templatetag with arguments used for configuration of the JS.

Unfortunately, because the JS and CSS was tied together by sharing classes, it meant that certain features that looked like entirely separate options could only work if both were specified, or both were left out.  And they were mutually exclusive with a third.  Any other combination caused the JS to error out, because it would make assumptions about which classes existed in the generated HTML.

We needed options 2 and 3, but not 1.  This was unfortunate, to say the least:  For example, Option 1 was including CSS-styled classes for Option 2's JS (which it was only using because, as described above, the classes were already there so why not?).  So if you used Option 2 without Option 1, there would be so much breakage styling-wise that it became unusable.

I have been beating that JS into submission on and off for nearly three months at this point, just making all 3 options independent of each other and ironing out the bugs.

This extra work shouldn't have been necessary, and wouldn't have been if the whole thing was well-written initially.  Forcibly separating which classes the JS and CSS act upon would have helped to prevent Option 1 and Option 2 from getting tied together back when it was first being written.

That said, it's generally not possible to be 100% on this rule.  One of those is a simple .loading class that gets added/removed as necessary.


问:
Should I read a chapter about Memory management if now a days we mostly use ARC?
I'm reading a book on Objective C, and I was wondering about 2 things:

Should I take the time currently to read a whole chapter on memory management?

If you are doing a really good job on manual management, can you get to better performance than using ARC?

答: Yes, you should read it.  Automatic memory management of any kind is not magical; like any abstraction, it's not perfect and foolproof.  When you're confronted with it's limitations or something difficult to understand, it pays to know what is going on behind the scenes.  Moreover there are many third-party libraries that don't use ARC so you may not have the option of only using ARC.</p>


问:
LGPL 2.1 vs LGPL 3.0 Advantages and Disadvantages
From what I've read, LGPL 3.0 allows you to use the license together with other licenses, more permissive about that(Not even sure about that).
From https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility it says that it is not compatible with GPLv2, while LGPL 2.1 is compatible with it. That's a bit contrary to the thing I've read...

So, do you know what the real advantages and disadvantages of LGPL 3.0 over LGPL 2.1 are?

One disadvantage would be that it is not compatible with GPLv2.

答:
I think you have to start with the intent of the LGPL 2.1 and the LGPL 3.  The LGPL 2.1 was designed to be a license written largely in plain English that would give programmers guidance on what they could do with the software.  It is generally clearer than the GPL 2 because of the linking safe harbor.  One major uncertainty regarding the GPL is whether a copyright holder even has an interest in controlling what programs can link to a copyrighted library.  The LGPL dispenses with this uncertainty by providing a safe harbor regarding linking.

The major shortcoming of this approach though is that it tends to be dependent on US legal concepts and the like, and jurisdictional definitions.  What may be a derivative work in one jurisdiction might not in another and this makes a significant difference when software is bundled and distributed, and permission is given for aggregation but not derivation.  The LGPL has less trouble here than the GPL but it is a significant uncertainty particularly in the GPL which is a companion license.

To resolve some of these issues and also provide better controls over exact rights, the GPL v3 series of licenses were drafted (the LGPL 3 is part of that).  These seek to do away with jurisdictional definitions of derivation and aggregation and rewrite the language so that it provides guidance for lawyers rather than programmers.  The licenses are far more complex, far utilizing structures more accessible to lawyers than programmers, and not necessarily any less vague.[1]  However they do succeed to some extent in getting around jurisdictional definitions.

So the first tradeoff is whether you want to be writing your license as one that the audience is a programmer vs the audience is a lawyer and the second is how concerned you are about international definitions in different jurisdictions.

The final one though is that the GPL v3 series of licenses have forced compatibility with the AGPL v3, meaning that code can be taken from GPL programs and have the added restrictions of the AGPL added on in such a way that this cannot be contributed back under the same license.  This is an issue with LGPL -> GPL copying as well on either license so it is probably a relatively minor concern.

Myself, I prefer the GPL v2 and LGPL 2.1 licenses because they are simpler and so I figure that there is less opportunity for a major misunderstanding to take place (minor misunderstandings may be more commonplace however), but this is my own personal preference, and yours may vary.

[1]  For example, if you read both the 2-clause BSD license and the GPL v3 (and by extension the LGPL b3) narrowly, these licenses are incompatible because the BSD licenses do not explicitly mention sublicensing unlike the MIT licenses and therefore at least some lawyers like Larry Rosen do not believe such of a license is granted.  Therefore you can't just take BSD code and relicense it as GPL v3 without actually adding copyright-worthy changes.  Yet everyone agrees the BSD and GPL v3 licenses are compatible.  This poses significant problems in interpreting the licenses and line drawing however.


答:
To answer question one:

Regarding question two, you most definitely can do better than ARC. Automated resource management in any language is always a heuristic approach that can never interpret the intentions of the programmer 100%. When you opt to control this process, you will almost always have fewer alloc/free calls for a given run of your program.  This means more efficiency, (usually) less memory fragmentation, and sadly, the unfortunate task of having to worry about memory leaks.

Memory management (and pointers/aliasing) tend to be taught to people with the stigma of difficulty. This is an awful mistake. These concepts are actually quite simple and fundamental to how the machine you're operating works. Face them head on and early, and you'll be a force to reckon with.

That said, unless you have a specific reason to use MRC, ARC will save you debugging time and let you write safer code faster.

Title: Should I read a chapter about Memory management if now a days we mostly use ARC?

Body:
I'm reading a book on Objective C, and I was wondering about 2 things:

Should I take the time currently to read a whole chapter on memory management?

If you are doing a really good job on manual management, can you get to better performance than using ARC?


问:
UML diagrams for small projects
All of a sudden the need for proper formal documentation has become a thing in our organization. A lot of work I do are enhancements and addition to an existing system. Generally a quick fix or a new method, etc.

I am just not sure what kind of diagrams I should/could use for small projects. For instance I am adding a new functionality to an existing system that verifies format of a field and they want proper "Component design description with diagrams" for a simple regex that verifies format of one field. In the past we only did pseudocode and that was enough for such projects as the system is somewhat legacy with very little original documentation.

答: It sounds like your existing code isn't really documented, so as you fix the code, you should be documenting all of the final product, not just your stuff. If you change code that was already documented, you should be updating the documentation to make sure it's still accurate.</p>

Title: UML diagrams for small projects


问:
Can a programmer renounce ownership of source code?
I came across this license:

```<code>/**
 * The author disclaims copyright to this source code. In place of
 * a legal notice, here is a blessing:
 *
 * May you do good and not evil.
 * May you find forgiveness for yourself and forgive others.
 * May you share freely, never taking more than you give.
 */
</code>```

Can a programmer really renounce the ownership of their source code?

答:
Disclaiming copyright is the same as placing it in the public domain, and means there is no copyright, so there are no restrictions whatsoever.  Technically, disclaiming copyright isn't a license, since a license states the terms under which you may make copies legally.  </p>

<p>They are not the same, but there would be little practical difference in some jurisdictions.  </p>

Body:
Disclaiming copyright is the same as placing it in the public domain, and means there is no copyright, so there are no restrictions whatsoever.  Technically, disclaiming copyright isn't a license, since a license states the terms under which you may make copies legally.

They are not the same, but there would be little practical difference in some jurisdictions.


问:
What non-theoretical, practical programming language has no reserved keywords?
I have been searching for a practical programming language that has no reserved keywords but I haven't had any luck finding one.

I am working on a programming language for my own edification and entertainment and I haven't needed to include any keywords yet, that is what led me to my search and the question:

I don't see convenience to the compiler writer as being important to the end user of the language. Computers are powerful enough now days to be able to infer meanings from context. No more than a writer needs to label nouns, verbs and such when writing a novel, why should a programmer have to label functions and variables with function x() {} or set x = 1 or var x = 1 etc; when I can infer from the context of the statements that it is a function declaration or an invocation or that a label is an assignment to a value or a reference to that labels value?

Here is a concrete example of what my current parser is doing, no need for reserved keywords to support common things that would normally have a bunch of noise like func or function or dec or what not.

Function Declaration

```<code>sum3(a,b,c) -> a + b + c.
</code>```

Function Invocation

```<code>x = sum3(1,2,3).
</code>```

Anonymous Function Named x

```<code>x = (a,b,c) -> a + b + c.
y = x(1,2,3).
</code>```

I would like to know why are keywords that important to a successful programming language?

答:
As far as I know, Smalltalk is the language that has least keywords (if I am not counting languages like Brainfuck). Smalltalk keywords are  true, false, nil, self, super and thisContext.

I have designed a langage, inspired with smalltalk, that had no keywords. But after some time of using it I ended up adding a few keywords, mostly for syntactic sugar.

So, my opinion is that language without keywords is possible, but it is not very practical and that is the reason why all popular languages have keywords.


答:
MUMPS is highly successful, being widely used in insurance and healthcare and and has no reserved words. I'd say they help in terms of writing clearer code but they aren't strictly necessary. APL is another example. APL sees use for one-off scripts in the Nuclear Industry amongst others. J, a member of the APL family also lacks keywords.

Keywords help compiler writers implement parsing more easily. APL is famously right associative. They also help reinforce conventions and improve readability. APL is not known for being hugely readable to most.

Title: What non-theoretical, practical programming language has no reserved keywords?

Body:
I have been searching for a practical programming language that has no reserved keywords but I haven't had any luck finding one.

I am working on a programming language for my own edification and entertainment and I haven't needed to include any keywords yet, that is what led me to my search and the question:

I don't see convenience to the compiler writer as being important to the end user of the language. Computers are powerful enough now days to be able to infer meanings from context. No more than a writer needs to label nouns, verbs and such when writing a novel, why should a programmer have to label functions and variables with function x() {} or set x = 1 or var x = 1 etc; when I can infer from the context of the statements that it is a function declaration or an invocation or that a label is an assignment to a value or a reference to that labels value?

Here is a concrete example of what my current parser is doing, no need for reserved keywords to support common things that would normally have a bunch of noise like func or function or dec or what not.

Function Declaration

```<code>sum3(a,b,c) -> a + b + c.
</code>```

Function Invocation

```<code>x = sum3(1,2,3).
</code>```

Anonymous Function Named x

```<code>x = (a,b,c) -> a + b + c.
y = x(1,2,3).
</code>```

I would like to know why are keywords that important to a successful programming language?


答:
There are some rare examples.

APL uses only symbols -- but a lot of them! You need a special keyboard to use the language.

See this wikipedia article

CORAL 66 -- had keywords but only recognised them if they were quoted with single quotes.

PL/1 also had keywords -- but you could also use them as variable or procedure names.

All in all though your question is a bit like asking "why do spoken languages have words?".


问:
What "sublicense" actually means?
First, it is clear that the right to sublicense doesn't give you the right to relicense.

Let's say that we have a library licensed under the MIT license(1 file), someone adds some features to the library but puts them under GPL(in the same 1 file). Or, if someone wants to sublicense, do they have to separate the code?

If someone wants to use the library, how are the licenses handled?

Let's say that the developers use only the MIT licensed code, without directly using some features under the GPL license, that are inside the same file.

Do they have to GPL their application because of the GPL licensed code?

Do they have to remove the GPL code in order to be free of the GPL restrictions or they can just use the library under the MIT permissions/restrictions as long as they don't use the GPL code?

答:
IANAL but I have discussed this and many similar issues with lawyers enough to have a good idea of what I am talking about here.  This is not legal advice.  The best background reading is Larry Rosen's book in the context of open source software.

Rights, Licenses, Copyright and Sublicenses

Under copyright law a copyright holder is granted certain exclusive rights over his or her work.  Most or all of these (depending on jurisdiction) can be exclusively or nonexclusively licensed to a third party.  If sublicensing is allowed, a licensee can pass on some or all of the rights in the license to a third party by contracting directly with them.

Currently in the United States, exclusive licensees are assumed by statute to have a right to sublicense (though I presume this could be further clarified in the exclusive license).  This makes sense because exclusive licensees are presumed to have control.  Nonexclusive licensees are not assumed to be granted such a monopoly by the licensor.

For example, suppose I write a novel.  Suppose I offer an exclusive license to the work in its current form as a book, and I offer someone else a non-exclusive license to make a sequel which is a derivative work.  The exclusive licensee can issue non-exclusive licenses to other authors to use excerpts from the book by sublicensing.  The non-exclusive licensee cannot authorize yet another unauthorized sequel of my novel, nor can the exclusive licensee sublicense a right they have not been granted (movie rights for example).

BSD vs MIT licenses and Sublicensing:  A Possibly Big Difference

This section is mostly based on Rosen's book (above).  If you need legal advice, please hire a lawyer, and don't get it off Stack Exchange.

The MIT license explicitly allows sublicensing while the BSD license does not.  Following the above discussion this means that the MIT license allows something that the BSD license probably does not in most jurisdictions, namely sublicensing.  Both licenses address, however, only the code and software provided and neither one limits what a work as a whole can be licensed under.  This leads to a significant question of how to interpret the GPL v3 to be compatible with the BSD licenses btw.

Under the MIT license you can do basically two seemingly similar things:

1)  You can incorporate the work in your own works and distribute these under a more restrictive license.

2)  You can take the original MIT-licensed work, add additional restrictions on it, and distribute the work under a more restrictive license but where you have not modified the code at all.  The GPL v3 claims to require this to be compatible, if one sees the GPL as governing all terms of the license.[1]

Under the BSD family of licenses, however, you can only add restrictions to your own code and to the derivative works you create.  You cannot add them to the original code by passing on only some of the rights granted to you.  So I can't take the BSD-licensed PostgreSQL, rename it to PostSQL, and license it under the GPL, but I can take MIT-licensed Kerberos and rename it as HadesHound and license it under the GPL (in both cases assuming that no code has changed).  This means that the vehicle for rights is different (always direct in the case of the BSD license, either direct or indirect in the case of the MIT license).

Conclusions

Sublicense is a legal term.  If you want to read about what it actually means, my recommendation is to start talking with lawyers, the Software Freedom Law Center, and others, and consult legal dictionaries.  The basic idea though is that if this is granted, a licensee can become a licensor of some of the rights of the grant they received regardless of any other claim they may have to copyright control over what they distribute.

You are asking about a specific legal document and a term used in it.  I hope this helps explain exactly what that term means and what impact it provides.

Many of your questions are likely to be long and complicated,[2] and depend on jurisdiction, but a basic rule regarding the MIT License is that if your channel claims it is licensed now under the GPL, it is licensed under the GPL.  This may or may not be a safe assumption under the BSD license however.  Moreover this is true regardless of whether the original version was modified or not if the MIT license was used.  Under the BSD license, the scope of modifications are indeed determinative regarding which license governs.

[1] One solution is to see the GPL in a different way, and to allow "reasonable legal notices" (additional restrictions under section 7) to include notices of additional license rights.  In this case one would have additional permissions which were removable, governed under section 7 as additional permissions, but also allow, as an additional restriction (under section 7(b)), a notice saying that certain rights are not removable.  This is one of the things I dislike about the GPL v3, namely that it makes one think like a lawyer regarding how to address license compatibility.

[2] For example there is an open question whether distributing software which links to a third party library requires copyright permission at all.  If this is the case that it does, then PostgreSQL compiled on MinGW requires Microsoft's permission and they can revoke that at any time, but if it doesn't then I can write proprietary programs that link against GNU Readline and the FSF can't claim this is copyright infringement.  This open question makes most of your questions regarding whether a developer can link to a library under a license other than the GPL impossible to answer with any certainty.

ContentLicense: CC BY-SA 4.0

Title: What "sublicense" actually means?


答: As the other answers say you should read it to get an understanding of what it does and there are still a lot of non-ARC code out there in various projects you might want to use but I would like to point out that even though it is possible to beat ARC in performance you probably won't do it and the effort to do manual memory management could be spent elsewhere.</p>


问:
Starting consulting while employed - conflict of interest
First of all I am not after legal advice. This is a bit TL;DR but I have a summary at the bottom, I'm explaining it all so people can offer insightful advise.

Situation

I need to explain my present situation to explain why I've decided to go the route that I have. I have recently been asked to find another job, due to the local economy struggling. I haven't been sacked but the cause is due to my present employer no longer being able to afford to employ me full time.

I looked for jobs for a while but there is very little around, particularly for the level that I'm at, and I don't want just another job that I'm not going to find challenging or enjoy.

My current position sees me work as an architect and software manager. The vast majority of work is internal, but I do a little external consulting for my employer.

My decision

I've decided to go out on my own as a consultant / contractor. I already have quite a fair bit of work lined up. But while I establish my business I need to make money to support my family. The eventual outcome is to monetize some products, but product development takes time.

The issue

My current employer has offered me part-time employment with them. They are primarily a retail operation although since my employment have moved extensively into web work (mainly CMS-based sites) and to a lesser extent, programming, which is where I come in. This is undertaken both on a consulting basis as well as several internal projects. There is also a very large IT support business. The software development is largely ancillary although there is a large focus on (basic) web development. Software development will largely stop when I leave, if not completely

Conflict of Interest

If I take up the part time role I need to have a contract written about conflict of interest. I will see a lawyer for legal advise however I need to know what to allow myself.

TL;DR

Working as a consultant as well as for a company doing software part time, I can think of the following areas to define in the contract to allow myself to operate:

When I work for them, I am employed by them and will not publicise or disclose my own business details

I will not, outside of work, pursue their clients offering services

They will not own any right to anything I produce whilst I am not employed by them

If an existing client approaches me from their own research then it is fair game

If they have a client leaving then I am entitled to work for them, and to either approach them or have them approach me

Can you think of any other areas to approach my lawyers with that I have missed?

I want to allow my business to grow and flourish and to protect myself.

Case in point - one client of theirs has told me they want me to do their work, and it was unsolicited.

答:
What about contracting for your present employer? Would they be willing to strike you off their employee roster and pay you as a contractor instead? Then they are just like your other clients and you (and they) have the same contractual obligations with all of them.

I'm not sure if that's really getting at the reasons you posted here, but that's my 0.02.


答:
You can do better, but you might also end up doing a lot worse (introducing leaks and crashes).

I'd say you should read about it, but use ARC as default anyway. When you have to, override ARC for certain files and manage your alloc's/releases by yourself.

I recommend Ray's article about memory management. It describes a few practices which helps a lot. Obj-C is more about "conventions" and consistency than language rules, so learning those conventions is a must if you're doing manual memory management.


问:
Is there a language that transpiles to C, with better syntax?
CoffeeScript is a language that transpiles to JavaScript, with a clean syntax, inspired by Ruby. Is there a similar language that transpiles to C, allowing for more readable code without compromising on performance? If nothing like that exists, is there a good reason for not creating it?</p>

答:
Rock is an ooc compiler that generates C99 source.
The ooc-lang is a programming language with objects, first-class functions, and pink unicorns. The ooc is a dynamic-language and walks so far away.
It generates fatter and slower c codes. u need modified more to suite your requirement. But it is a good start point. </p>


答:
One well known language without keywords is Lisp. The closest thing it has to keywords are so called special forms - their number may vary between dialects - that get special treatment from the interpreter. Apart from that they are indistinguishable from regular functions in terms if how they are used, with the exception that they can't be redefined (at least in Lisps i'm familiar with).

This results in a simple (but paren-heavy) syntax, and is one of the things that enabled Lisp to have such a powerful macro system. On the other hand, Lisp is often said to be hard to read. APL and MUMPS, even more so, I've seen both described as halfway to Brainf*ck. Keywords do help in this department and make reading code easier for us humans too.

So I wouldn't say keywords are required for a successful language, but they sure help a language to become successful.


答:
First, I don't think that separation is absolute.  id's for example are unique to a document and so it makes sense to use them for both CSS and JS.  For classes though, there are good reasons for these to be separate.

The basic issue is that CSS and JS implement what you might think of as cross concerns. CSS implements layout, display, and typography, while JS implements behavior.  Or at least this is how they are most often (and I think, best) used.  You can think of these as orthogonal concerns or dimensions, and so individual DOM objects may need to be placed, not in a line of functionality, but rather in a two-dimensional area where the dimensions are display and functionality.

Again if you want to look up a single element, CSS and JS may both do this by ID, but if you want to look up a group you probably don't want to tie display and behavior together too tightly.

This is a general issue and I don't think it depends on how experienced your developers are or what tools you are using.  As long as the concerns are different you may want to be able to classify elements according to multiple types of concerns and this is one way this happens.


问:
NoSQL Document Database as a Message Queue
I am considering using a NoSQL Document database as a messaging queue.

Here is why:

I want a client to post a message (some serialized object) to the server and not have to wait for a synchronous response.

I want to be able to pull messages off of the "queue" based on some criteria, which may be more sophisticated than just a priority level (I am working on a hosted web app, so I want to give all of my customers a fair amount of "computing time", and not let one customer hog all of the processing).

I want the queue to be durable - if the server goes down I want any remaining messages to be handled when it comes back up.

So, I am considering using MongoDB or RavenDB as a message queue.  The client can post the message object to a web service which writes it to the database.  Then - the service doing the work can pull the various message types based on any criteria that may arise.  I can create indexes around the scenarios to make it faster.

So - I am looking for someone to shoot a hole in this.  Has anybody successfully done this?  Has anybody tried this and failed in some way?

答:
I agree with MrFox. You need to consider that if you have several threads updating the same data in the queue, your database must support true ACID transaction or you will risk the same item in the queue to be processed more than once, besides getting duplicates of the same item in the queue.

If the total data that you post to the queue is not in big data size (>PB) of data I would advice on selecting another type of database, at least a database that supports true consistency.

The process queue will be better suited for an OLTP type of database since you are basically doing more inserts/updates rather than anything else.


问:
Java vs PHP Memory / CPU Consumption
I work in a PHP based company. There is a project where we want to create a backend service. Senior members here are going for PHP, even though it is slower than Java. Their only point of contention, that Java is heavier than PHP in both memory and cpu load standpoint.

Jvm is more like a container environment, if u bring in more baggage it will consume that much, but service we are talking here will be of medium complexity. So chances are that it won't be much demanding (or will it?)

I understand this question leans heavily towards vagueness, however my point of ponder is, that is it always the same case? That java is more hardware demanding? I would just like to know opinions of all you experienced folks about how the actual scenario looks like.

答:
Many enterprise Java shops tend to add a lot of abstractions and frameworks (such as ORMs, EJBs, spring, third-part libs, containers etc) to their systems. Sometimes these abstractions are meaningful, but often they end up adding bloat (memory, cpu) and complexity.

PHP, otoh, can be used pretty much "as-is", warts and all. But with Java you certainly need to juggle a lot more parts.

So you need to factor in those other things as well before making a decision.

Title: Java vs PHP Memory / CPU Consumption


答:
TCL has no key words, and indeed only 12 syntax rules. while its not as popular as it once was, it has its niche with expect and embedded in ECAD and routers so it certainly counts as a practical to my mind.

I also think it may show why lots of languages don't go this route. Yes its perfectly possible to write a TCL parser (arguably easier than many other languages) however you can't write a very useful BNF grammar for the language and many people seem to have trouble learning the language. I suspect this is at least partly because of lack of keywords.


答:
For instance I am adding a new functionality to an existing system that verifies format of a field and they want proper...

you can try Use-case diagram

Its hard to define what is a small-project, sometime you may design a small-component but it can turn out that the component will
be used in other 100 projects but here my small attempt
For small projects diagrams like user-case, class, activity ,sequence & state diagram can do the job.

If you are using intellij for development then ctrl+alt+shift+u on package and it will auto-generate class diagram for you

Title: UML diagrams for small projects

Body:
All of a sudden the need for proper formal documentation has become a thing in our organization. A lot of work I do are enhancements and addition to an existing system. Generally a quick fix or a new method, etc.

I am just not sure what kind of diagrams I should/could use for small projects. For instance I am adding a new functionality to an existing system that verifies format of a field and they want proper "Component design description with diagrams" for a simple regex that verifies format of one field. In the past we only did pseudocode and that was enough for such projects as the system is somewhat legacy with very little original documentation.


问:
Why aren't young programmers interested in mainframes?
A key issue with mainframes is that the cohort of supporting programmers is dwindling. While normally this wouldn't be a problem in that a falling supply of programmers would be offset by an increasing amount of salary those causing a rising supply of programmers via the law of supply and demand, I'm not sure this is really happening for mainframes.

While they still form critical infrastructure for many businesses, the simple fact is there isn't an adequate number of young programmers coming up along to keep the support population populated.

Why is this? What makes mainframes unattractive to young programmers?

答:
I am 28 and I have been a professional developer for 10 years. I spent 3 years working on a mainframe.

The environment was esoteric, stale, stagnant, confusing (JCL and ISPF anyone?). With that said I did have an enormous amount of respect for the system, how it all worked, the scale of it. The system had something like 150M SLOC, supported a midrange farm of UNIX servers via SOA and literally ran a major part of the country.

With that said, why are young programmers not interested? Here's my take, as a "young" programmer (I started on this system at the age of 23). Bare in mind this is my perspective from the system I was working on, and the research I did:

There is little new mainframe development. A lot of it is legacy.

There are huge barriers to entry

The work done is for financials, big business and government. None of this is bleeding edge.

The development tools are old and largely antiquated. Debugging is nothing like VS.

Mainframes will always have a place in the economy. They just don't drive early businesses due to their enormous cost and and support requirements.


答: OCaml can compile to bytecode, to native code, can be interpreted directly, or can compile to C.</p>

Title: Is there a language that transpiles to C, with better syntax?

Body: CoffeeScript is a language that transpiles to JavaScript, with a clean syntax, inspired by Ruby. Is there a similar language that transpiles to C, allowing for more readable code without compromising on performance? If nothing like that exists, is there a good reason for not creating it?</p>


问:
Why does Java require a servlet container for simple RPC service?
I have a big database controller which is written in Java. The controller reads information from the database, and interprets it into data structures which are then displayed in a CLI.

Java was chosen because writing code in it is fast and easy. Now I want to create an  RPC server on top of the controller (XML-RPC or JSON-RPC for future AJAX calls), but it looks like I need a servlet container for my RPC service. I am confused because last year when I needed this kind of capability for another project in python, it took me less than 5 minutes to create the same functionality using the SimpleXMLRPCServer

The same ease of creation applies also to C# as far as I recall.

But in Java the story is different; now I need a servlet and therefore a servlet container (i.e Tomcat, Jetty) which means I need to install and maintain web servers. From what I can tell, JSON-RPC requires Spring framework in order to work.

I have already spent around two hours in learning the design and sort-of how Tomcat works without writing even one line of code.

I searched the web and found out that I have standalone options: I can use this library, but it doesn't seem maintained and it is also somewhat complex (I'm looking for something with decorators / annotations).

The other option I found is to use the so called "embedded" jetty and then trying to set it and configure it by code which also seems a tedious task.

Why isn't there a standalone mechanism for such a popular interface? Am I missing out something here?

答:
You want to create a server and you're surprised you have to install and maintain server software?

The "concept or vision" that you're running up against is the idea that if you're running a server, you really should use something solid and mature that can be monitored with standard tools, instead of just running some code and starting to roll your own admin tools as soon as you want to do anything more with it.

Besides, it's not as if setting up Tomcat (let alone Jetty) were all that complex. You don't have to understand all its capabilities to use it for a simple project like this.


答:
The enterprise features of Java (as in those in JEE) are not implemented by Oracle/Sun and are instead contained within the Java Enterprise Edition specification.

As a result there are numerous implementations of application servers - Tomcat, Jetty, WebSphere, etc, all of which implement different parts of the JEE specification.

Because you are using enterprise Java features, you need an application server - hence your present situation.

Jetty is a very lightweight server and you might have some luck there if you're having trouble with Tomcat.

I understand where you're coming from, doing this sort of thing in .NET is trivially easy, Java needs a little bit more work to get there but the result in the end is the same.

Title: Why does Java require a servlet container for simple RPC service?

Body:
I have a big database controller which is written in Java. The controller reads information from the database, and interprets it into data structures which are then displayed in a CLI.

Java was chosen because writing code in it is fast and easy. Now I want to create an  RPC server on top of the controller (XML-RPC or JSON-RPC for future AJAX calls), but it looks like I need a servlet container for my RPC service. I am confused because last year when I needed this kind of capability for another project in python, it took me less than 5 minutes to create the same functionality using the SimpleXMLRPCServer

The same ease of creation applies also to C# as far as I recall.

But in Java the story is different; now I need a servlet and therefore a servlet container (i.e Tomcat, Jetty) which means I need to install and maintain web servers. From what I can tell, JSON-RPC requires Spring framework in order to work.

I have already spent around two hours in learning the design and sort-of how Tomcat works without writing even one line of code.

I searched the web and found out that I have standalone options: I can use this library, but it doesn't seem maintained and it is also somewhat complex (I'm looking for something with decorators / annotations).

The other option I found is to use the so called "embedded" jetty and then trying to set it and configure it by code which also seems a tedious task.

Why isn't there a standalone mechanism for such a popular interface? Am I missing out something here?


答:
Bjarne Stroustrop's original C++ compiler, "cfront", compiled C++ to C, which it would then optionally run the C compiler against to produce object code.  C++ is about as "non-theoretical" as you can get :-)

The Unix "yacc" and GNU "Bison" compiler-compilers translate their input languages to C.  Many, many sophisticated systems have been written with them.


答:
Incorrect assumptions

Your assumption that you need servlets and a server is mis-guided and incorrect. there are plenty of embeddable HTTP servers in Java, some are single classes, they aren't full featured servers, but an HTTP server is just a TCP/IP Socket based protocol. The Servlet API is just a nice abstraction away from the details.

You don't want to do RPC, you want to do REST

You will need a minimal Servlet container to use something that will accelerate your development like RESTEasy.


答:
Don't give up anything you don't have to.  You're starting off wrong.  Your employer has cut you back, and may very well do it again (that's the way these things go).  You're doing something for them that they don't want to be doing ("Software development will largely stop when I leave, if not completely").  Neither of these justify you conceding points, especially at the start of negotiations.

"When I work for them, I am employed by them and will not publicise or disclose my own business details" This is generally-good ethics, and depending on where you live and work, may be required under law (e.g., in the USA, the "duty of loyalty").

"I will not, outside of work, pursue their clients offering services" Don't offer this to them, and don't be quick to agree if they suggest it.  If your employer will effectively be exiting "your" business when you leave, they shouldn't see you as a competitor.

"They will not own any right to anything I produce whilst I am not employed by them" I assume you mean "... produce on my own time whilst ..." (because sometimes this just isn't the case).

In addition to what you've listed yourself, you should clarify your rights to what's in your head.  In some jurisdictions, lawyers had successfully advanced the "doctrine of eventual disclosure" as an effectively-perpetual extension of non-disclosure and non-compete agreements that you may have already signed.  Your new contract should, at a minimum, explicitly supersede and replace any previous NDA/NCA in its entirety, and clearly specify how long you will not solicit your employer's existing customers.

More than that, since your employer seems to be terminating a line of business, you should consider positioning yourself to them (and thus to their clients) as the safety net for their clients.  You're not your employer's competitor, you're a white knight rescuing their customers from abandonment and allowing your employer to gracefully exit a business they don't want without destroying relationships with their clients.

Title: Starting consulting while employed - conflict of interest

Body:
First of all I am not after legal advice. This is a bit TL;DR but I have a summary at the bottom, I'm explaining it all so people can offer insightful advise.

Situation

I need to explain my present situation to explain why I've decided to go the route that I have. I have recently been asked to find another job, due to the local economy struggling. I haven't been sacked but the cause is due to my present employer no longer being able to afford to employ me full time.

I looked for jobs for a while but there is very little around, particularly for the level that I'm at, and I don't want just another job that I'm not going to find challenging or enjoy.

My current position sees me work as an architect and software manager. The vast majority of work is internal, but I do a little external consulting for my employer.

My decision

I've decided to go out on my own as a consultant / contractor. I already have quite a fair bit of work lined up. But while I establish my business I need to make money to support my family. The eventual outcome is to monetize some products, but product development takes time.

The issue

My current employer has offered me part-time employment with them. They are primarily a retail operation although since my employment have moved extensively into web work (mainly CMS-based sites) and to a lesser extent, programming, which is where I come in. This is undertaken both on a consulting basis as well as several internal projects. There is also a very large IT support business. The software development is largely ancillary although there is a large focus on (basic) web development. Software development will largely stop when I leave, if not completely

Conflict of Interest

If I take up the part time role I need to have a contract written about conflict of interest. I will see a lawyer for legal advise however I need to know what to allow myself.

TL;DR

Working as a consultant as well as for a company doing software part time, I can think of the following areas to define in the contract to allow myself to operate:

When I work for them, I am employed by them and will not publicise or disclose my own business details

I will not, outside of work, pursue their clients offering services

They will not own any right to anything I produce whilst I am not employed by them

If an existing client approaches me from their own research then it is fair game

If they have a client leaving then I am entitled to work for them, and to either approach them or have them approach me

Can you think of any other areas to approach my lawyers with that I have missed?

I want to allow my business to grow and flourish and to protect myself.

Case in point - one client of theirs has told me they want me to do their work, and it was unsolicited.


答:
Your main problem seems to be that UML diagrams document systems, not projects. It is indeed completely nonsensical to demand separate UML documentation for a project that consists of adding a small amount of functionality to an existing large system.

Talk to your management about how this discrepancy can be resolved. If all they want is some sort of "formal documentation", propose a standardized form to handle such "small change" projects (with entries such as "system to be changed", "summary of change", "affected assets", etc.). If they insist on UML purely for buzzword compatibility, a use case document (not diagram) is quite similar to that and may satisfy the demand.

Alternatively or additionally, you may want to consider creating some high-level UML documentation for those legacy projects and integrate future changes in that.

Title: UML diagrams for small projects


问:
With agile, what do when a user story doesn't get completed in an iteration?
Do you just move the story to a new iteration, or delay the next iteration?

It gets a bit tricky when you use something like Jira when you have to copy or move around stories between iterations as it effects calculations of velocity/points etc.

Is there a best-practice?

答:
The dilemma: Where do story points for unfinished stories go? The sprint where they are finished? Partial credit in each sprint for the portion finished in each sprint? Here is how I answered the dilemma in a blog post:

Those points go nowhere. No credit. But the team DOES have to complete the work.

Full blog on this topic here:
http://agileangle.blogspot.com/2011/07/story-points-who-gets-credit.html

OwnerDisplayName: codecompleting


答:
Computers are powerful enough now days to be able to infer meanings
  from context.

Does this mean you want a grammar that is not context free? Good luck.

It's not a question about being powerful or not. There are eternal, unchanging rules about languages - mathematical ones. This, and the fact that a programming language should be syntactically easy will make CFGs rule for some decades to come.

Btw., in Haskell like syntax, you just write something like

```<code>f x y = (x+1)*(y-1)
</code>```

to define a function. But observe that the "keyword" in this case is the '='. If you miss it, terrible things will happen in the parser.

But this is a point where I agree with you, I find this much more intuitive than all the def, dcl, fun, fn, function or what-not keywords that introduce functions in other languages.

Yet, this grammar can be written in plain old LALR(1), no meaning is "inferred from the context" here.

Body:
Computers are powerful enough now days to be able to infer meanings
  from context.

Does this mean you want a grammar that is not context free? Good luck.

It's not a question about being powerful or not. There are eternal, unchanging rules about languages - mathematical ones. This, and the fact that a programming language should be syntactically easy will make CFGs rule for some decades to come.

Btw., in Haskell like syntax, you just write something like

f x y = (x+1)*(y-1)

to define a function. But observe that the "keyword" in this case is the '='. If you miss it, terrible things will happen in the parser.

But this is a point where I agree with you, I find this much more intuitive than all the def, dcl, fun, fn, function or what-not keywords that introduce functions in other languages.

Yet, this grammar can be written in plain old LALR(1), no meaning is "inferred from the context" here.


答:
I think you're on the right track with your considerations.  Everything you have described is transparent and ethical.

I would consider the following:

Have a defined intellectual property agreement in place with your current employer.  What you're suggesting is a reasonable interpretation and aligns with most legal practice.  Having an IP agreement documented though will help prevent future misunderstandings and headaches.

Identify what is required in order to document when and where work is performed.  An obvious example is that you won't use your employer's resources in order to perform your consulting work for your clients.  You'll likely need your own computing equipment and software for your consulting work, but you may also need to generate a log book indicating what hours were worked and for which projects.  ie.

8AM - 12PM "revised DB diagrams for client ABC"

1PM - 5PM "refactored data access layer for employer"

Likewise, have a defined agreement regarding existing clients, any cool-off periods, and / or similar anti-poaching considerations.  You'll want something concrete to indicate when a former client of theirs can employee you.

Setup terms regarding the scope of your part-time work and expectations.  "Other duties as assigned" can become a very onerous job requirements when you're working to build up your own clientele base.  It's very easy for them to turn around and say "No, no, we expected you to go out and drum up business for us."

You'll also want to negotiate the hours and times you are working as a part-time employee.  Having defined windows of employment with them makes it easier to delineate when your work is theirs and when your work is yours.

Have a conversation with your boss and your boss' boss.  They likely regret having to cut you back to part time and should be understanding that you need to build up a consulting base.  Having open and honest conversations with them will make it easier for them to understand what your second job is and how that may impact your work for them.  This is a case where honesty and openness will be your best policies.

Consider how you want to work with your client base if and when your employer is able to move you back to full-time employment.  You'll want to think this through as it's likely your future clients that know of your employer will be asking about this.

Discuss with your attorney how you will transition from part-time to contracting with your former employer.  At some point, your consulting business will be self-sustaining but your former employer may still need your services for the various internal projects that you mentioned.


问:
How to deal with necessary workarounds in software?
Even with detailed specifications for exchanging data between computer programs, chances are that data generated by older versions of programs do not conform 100% to the specification, or that they use old obscure features which few people know how to implement them. As a result, companies have to keep a library of "odd specimens" for testing their software.

In good software design, these quirks can be confined into a small layer of libraries called "Abstraction Layer". However, most abstraction layers cut off too many functionalities (in order to prevent the higher level software from touching the unstable parts of the lower level software).

Sometimes it is not possible to completely hide away the unstable parts. What are the strategies for coping with such necessary workarounds?

((Please pardon my poor language skills.)

答:
Good documentation.

Code comments go a long way towards telling the next developer why the hack was placed there, and why it needs to stay.

Hopefully the reason is sound. At some point, if enough technical debt is incurred, a refactoring should be considered.

ContentLicense: CC BY-SA 2.5


问:
Is there a constant for "end of time"?
For some systems, the time value 9999-12-31 is used as the "end of time" as the end of the time that the computer can calculate. But what if it changes? Wouldn't it be better to define this time as a builtin variable?

In C and other programming languages there usually is a variable such as MAX_INT or similar to get the largest value an integer could have. Why is there not a similar function for MAX_TIME i.e. set the variable to the "end of time" which for many systems usually is 9999-12-31. To avoid the problem of hardcoding to a wrong year (9999) could these systems introduce a variable for the "end of time"?

**Real example **

End of validity date: 31/12/9999. (official documents are listed like this)
The blogger wants to write a page that is always on top, the welcome page. So it's given a date as far in the future as possible:

3000? Yes, the welcome page which you're facing is posted at 1 January
  3000. So this page will be kept on the top of the blog forever =) It's actually posted at 31 august 2007.

答:
Cocoa/Objective-C has factory methods [NSDate distantPast] and [NSDate distantFuture] that represent exactly the kind of thing you're referring to.

The values returned by the current implementation are constants representing circa 0 AD and 4000 AD, although these aren't guaranteed or documented.

Title: Is there a constant for "end of time"?


问:
Re-writing a large web application - alternatives to LAMP
We have a very large, 10 year old LAMP (Linux, Apache, MySQL, PHP) web application that is out of control and poorly written due to a large number of patches and possible hundreds of programmers.

If we were to do a re-write, what are alternatives to the LAMP stack?  One of the reasons behind LAMP was that it's easy to develop and cheap.  Now the company can afford to spend more time/effort/money on a new system.  I thought about Java or C++ with Oracle?  Is there a common 'Enterprise' stack companies use?

Many thanks.

答:
Ask yourself why you want to move from LAMP; is it because of deficiencies in the stack, or deficiencies in the practices and design around the original application?  Bad code can be written in any environment, from assembler to the most astronautical architectures.

Currently, my company runs a highly scalable set of web services on Linux, nginx, MySQL, and Python; the biggest hurdle has been the problem of poorly written legacy code, not the scalability of any of the aspects of this stack. You could do the same thing in Java, or .NET; it really doesn't matter, as long as you have the expertise in that stack to make it effective.


答:
I don't see any path from this that isn't full of failure - one of the biggest draws of the LAMP stack is that PHP has a lot of libraries, and if the code is already in PHP you're certain that PHP supports anything you need to do.

You can write bad, unmaintainable code in any language, but your choices for "Enterprise" web are basically Python, Ruby, C#, Java, or PHP. The only benefit of moving away from PHP might be moving to a statically typed language - that's one argument I could agree with, but for anything else I don't think there's a strong reason from moving away from PHP as a language.

Title: Re-writing a large web application - alternatives to LAMP

Body:
We have a very large, 10 year old LAMP (Linux, Apache, MySQL, PHP) web application that is out of control and poorly written due to a large number of patches and possible hundreds of programmers.

If we were to do a re-write, what are alternatives to the LAMP stack?  One of the reasons behind LAMP was that it's easy to develop and cheap.  Now the company can afford to spend more time/effort/money on a new system.  I thought about Java or C++ with Oracle?  Is there a common 'Enterprise' stack companies use?

Many thanks.


问:
How to implement two different web services running the same business logic?
We are developing a ReSTful HTTP API with Servicestack(.NET).

Some of the API clients, which have a subset of the actions, demand a service which could be easily added with all the entities, like with the "Add Service Reference" with Visual Studio.

We are thinking about creating a simple asmx web service, but our thoughts on how to do it divide to two:

The asmx WS will call the ServiceStack service with an HTTP client.

The asmx WS will reference the same BL that the main service references and will call it directly.

Which is the preffered way?

Is there any other way you would recommend?

答:
Consider writing adapters for input into your application logic.  The application should not have to really know about the clients that access the business logic.  Instead you write code that adapts the client's (in this case your web services) calls into your application into what it needs.  This is a basic principle in Allistair Cockburn's Ports and Adapters Pattern ("Ports and Adapters" or "Hexagonal" Pattern)

The idea behind this principle is to limit the entanglement between the business logic and the interaction with external entities.

The classic Design Patterns book has a description of the generic "Adapters" pattern. Ports-and-adapters uses this pattern.


问:
Why is "working with files" is an important subject when learning Objective C?
I'm reading a book on Objective C, and I was wondering how important the subject Working with files for learning to develop iOS in particular?

On you tube the tutorials are very short, maybe 10 min of video that teaches you how to do stuff with files and URL's. But in the book its a very long chapter with lot's of detail. The basics of working with files and URL's if very clear and simple, so I was wondering when I be really need this and this information become handy, and if I need to dig that deep in this topic right now?

The main question is, if I know the basics, can I move on and come back when I need it? or it's a really crucial to dig in right now?

答:
Specific to iOS, "working with files" isn't that important for a lot of applications.  "Working with streams" however, is. Files are a good introduction to working with streams.  So learn to work with files, but pay close attention to the higher-level abstraction of streams.

That said, I learn best when I have a specific project in hand and I'm focused on learning only the thing I need to complete the next step.  If that works for you, skip over it for now and circle back when you need it. But like I said in an answer to your other question, where possible read everything you can.


答: The main reason is that it's easier for both humans and computers to parse. Disambiguating a complex language without keywords would require many symbols as syntax, and it would be massively and unnecessarily confusing. It's much easier to read function than $!{}. And context does not resolve all ambiguities.


问:
Convert letters to numbers
I have the following problem.

Given A=1, B=2 , ... , Z =26

I need an algorithm that given a letter combination, like the column order in excel, returns me the number/

AA=27
AB=28

ABC?

Thanks a lot

This is my algorithm so far, I dont like the switch inside the for.  Any help is appreciate it, I will write it later in c#

```<code>Given A=1, B=2, Z=26. AB=27, ABC?
Variable = ABC
Positions =  Variable.Length -1
Int  result= 0
FOR (i=0; i<= Positions; i++)
{
     Letter=Variable[i];
    Switch(Letter)
    Case A:
        LetterValue=1
     result=+ result+26*(LetterValue)^i
}
</code>```

答:
Think of a sequence of letters as a base-26 number: each letter represents a digit; each position N's value is 26^N (N is zero-based). This is similar to converting decimal numbers to integer values, except you have letters as your digits, and 26 instead of ten as your base.

Now the algorithm is clear: start from the left, and convert letters to numbers. If you see more digits to the right, multiply the result you've got so far by 26, and use that as your initial number for your next iteration. Here is a simple implementation in C#:

```<code>private static int FromBase26(string s) {
    int res = 0;
    foreach (var c in s) {
        int d = c - 'A' + 1;
        res = 26 * res + d;
    }
    return res;
}
</code>```

Title: Convert letters to numbers

Body:
Think of a sequence of letters as a base-26 number: each letter represents a digit; each position N's value is 26^N (N is zero-based). This is similar to converting decimal numbers to integer values, except you have letters as your digits, and 26 instead of ten as your base.

Now the algorithm is clear: start from the left, and convert letters to numbers. If you see more digits to the right, multiply the result you've got so far by 26, and use that as your initial number for your next iteration. Here is a simple implementation in C#:

private static int FromBase26(string s) {
    int res = 0;
    foreach (var c in s) {
        int d = c - 'A' + 1;
        res = 26 * res + d;
    }
    return res;
}


问:
Ruby manager for Windows: Is Ruby's PIK alive or dying?
At first, please forgive probably offtopic and/or notconstructive question, but I truly have no idea where to ask it. At first I targetted StackOverflow there's at least some PIK-related traffic visible, but Programmers seem more relevant (although there seems to be not a three words here about PIK..).

Some time ago I was looking for a quick way to predictably and repeatibly setup Ruby environments and I've found PIK to be relatively easy and usable. Note that I'm not a full time Ruby developer, I use it more as a "quick hacking console" and "lightweight Bash replacement" on Windows.

For the last one or maybe even three years I was happily using PIK for isolating Ruby's ENVS from the normal windows shell environment. I've also came up with some extensions, both to windows's shell and PIK itself, and from time to time I feel the urge to publish them. They include simple things from running a script by doubleclick alike to .vbs or .bat, to more interesting ones like drag&dropping files onto a .rb script, to some fairly esotheric like emulated support for shebangs like #!/bin/ruby-187 #!/bin/ruby-193 so you can easily switch Ruby runtimes in the scripts lying on your desktop.

Some background covered, let me then ask the awful question: is it worth publishing?. No, obviously almost everything usable is worth that. My point is more about the feeling that I maybe I could spent that time better, there's no point in polishing dead tools, and as I search the web, I see very little movement in the subject :)

Are such extensions actually needed, or maybe they do exist and I simply reinvented a wheel? Do you, Ruby users, feel "lack" of them in your "everyday use" of Windows?

Is the PIK alive, getting popular or dying? is it known/used throughout the windows/ruby community, or should I adapt my addons to other managers?

答:
I took kinda life support maintenance of Pik when Gordon (the original author) left the OSS community.

While I would like to say Pik is still alive, no new feature has been added to it over the past few years, simply because most of what it was required for it to do was doing properly.

I use Pik every day to switch versions and I couldn't live without it.

However, new versions of Ruby and new platforms for Ruby itself being added are making Pik become out-of-date, yet still useful.

Pik itself is written in Ruby, not a simple project, yet is still Ruby.

Certain tricks and extra tools are used to generate installers and executables of it, but it contains specs to confirm the proper behaviors.

You can find Pik source code here

Feel free to raise questions and send patches that make Pik and how to develop it more easy.

Contributors are always welcome.


问:
Implementing Context-based Undo/Redo Functionality
I'm currently implementing an undo/redo mechanism using the Command Pattern. Everything works so far. My problem now is to implement the undo/redo functionality in a way that it is bound to a given context.

Assume the following situation:

You have win1 and win2. In win1 you execute action1; then you switch to win2 and you execute action2 and action3. You "undo-stack" would look as follows

action3

action2

action1

Now what happens if win1 gets closed/removed and you start performing undos. At action1 the program would probably crash as the context is has been executed against previously (i.e. win1) doesn't exist any more. As such, when win1 gets closed, all the corresponding actions should be removed from the "undo-stack".

My question is on whether there exist already implementations/best practices for implementing such scenario properly? Or do you have any ideas?

答:
What happens if win1 gets closed/removed? To answer this question, ask you another one: is the action reversible?

1. Case where the closing/removal action is reversible:

The closing/removal event is recorded in the undo stack, and when the user is performing undos, it un-does the closing/removal.

For example, when a user removes, through your application, a file win1, the app should not remove the file, but only mark it as a candidate for removal; then, a potential undo will un-mark the file.

2. Case of irreversible actions:

If you're talking about irreversible actions, given that the reversibility is not depending of your application, then deal with it, for example by disabling the corresponding undo elements.

For example, you're writing a tool which manages server farms, and at a given moment, the server win1 is materially unplugged from the network. In this case, your application can't replug the server, since it requires human intervention.

The application should then adapt its behavior in a more intuitive way: cancel or undos anterior to the irreversible one, skip the irreversible action, or something radically different and innovative. It's up to your interaction designer to come with the most intuitive way.

This is not much different from a case such as when your application tries to access a database, but the database is offline: you can't do anything about it, and the way you behave depends on the precise context.

Example:

Let's take an example from your comment: the removal of an Excel sheet. The successive actions are:

Change the cell A1 in sheet 1,

Change the cell A1 in sheet 2,

Remove the sheet 1.

Two possible behaviors would be:

The reversibility of sheet removal. Strangely, Excel team have chosen to not make it reversible. While this is probably motivated by some technical aspects I ignore, this behavior is totally wrong UX-wise. As a user, when by mistake I destroy a sheet, I expect to be able to get it back by pressing Ctrl+Z.

Not being able to do that makes it risky to use Excel, since I can never know what could be reverted, and what could result in a loss of work. That's not nice at all.

The impossibility to remove the sheet with the loss of "Change the cell A1 in sheet 1" step in the undo stack after the removal. Technically, it's not so difficult. Imagine the following structure:

```<code>class undoEntry
{
    string text; // Text which is displayed to the user in the undo history.
    sheet? correspondingSheet; // The sheet where the action happened, or null.
    undoAction action; // The action to undo.
}
</code>```

With correspondingSheet property, you can then walk though the undo stack when a sheet is removed, and delete the entries you shouldn't display any longer.

Body:
What happens if win1 gets closed/removed? To answer this question, ask you another one: is the action reversible?

1. Case where the closing/removal action is reversible:

The closing/removal event is recorded in the undo stack, and when the user is performing undos, it un-does the closing/removal.

For example, when a user removes, through your application, a file win1, the app should not remove the file, but only mark it as a candidate for removal; then, a potential undo will un-mark the file.

2. Case of irreversible actions:

If you're talking about irreversible actions, given that the reversibility is not depending of your application, then deal with it, for example by disabling the corresponding undo elements.

For example, you're writing a tool which manages server farms, and at a given moment, the server win1 is materially unplugged from the network. In this case, your application can't replug the server, since it requires human intervention.

The application should then adapt its behavior in a more intuitive way: cancel or undos anterior to the irreversible one, skip the irreversible action, or something radically different and innovative. It's up to your interaction designer to come with the most intuitive way.

This is not much different from a case such as when your application tries to access a database, but the database is offline: you can't do anything about it, and the way you behave depends on the precise context.

Example:

Let's take an example from your comment: the removal of an Excel sheet. The successive actions are:

Change the cell A1 in sheet 1,

Change the cell A1 in sheet 2,

Remove the sheet 1.

Two possible behaviors would be:

The reversibility of sheet removal. Strangely, Excel team have chosen to not make it reversible. While this is probably motivated by some technical aspects I ignore, this behavior is totally wrong UX-wise. As a user, when by mistake I destroy a sheet, I expect to be able to get it back by pressing Ctrl+Z.

Not being able to do that makes it risky to use Excel, since I can never know what could be reverted, and what could result in a loss of work. That's not nice at all.

The impossibility to remove the sheet with the loss of "Change the cell A1 in sheet 1" step in the undo stack after the removal. Technically, it's not so difficult. Imagine the following structure:

class undoEntry
{
    string text; // Text which is displayed to the user in the undo history.
    sheet? correspondingSheet; // The sheet where the action happened, or null.
    undoAction action; // The action to undo.
}

With correspondingSheet property, you can then walk though the undo stack when a sheet is removed, and delete the entries you shouldn't display any longer.


答:
Context is important from a programming/technical standpoint, as well as, usability. Your Excel comment is a good example. Several documents and then worksheets could be in the same instance of Excel and your undo would go across them (assuming you made recent actions on different ones), but this wouldn't happen in another instance of Excel or from Excel to Word.

Users may be able to provide the context where they see the line drawn with this functionality. Microsoft could have built this functionality in the context of all open Office applications. I wouldn't like it as a user eventhough it is technically possible.

Title: Implementing Context-based Undo/Redo Functionality

Body:
I'm currently implementing an undo/redo mechanism using the Command Pattern. Everything works so far. My problem now is to implement the undo/redo functionality in a way that it is bound to a given context.

Assume the following situation:

You have win1 and win2. In win1 you execute action1; then you switch to win2 and you execute action2 and action3. You "undo-stack" would look as follows

action3

action2

action1

Now what happens if win1 gets closed/removed and you start performing undos. At action1 the program would probably crash as the context is has been executed against previously (i.e. win1) doesn't exist any more. As such, when win1 gets closed, all the corresponding actions should be removed from the "undo-stack".

My question is on whether there exist already implementations/best practices for implementing such scenario properly? Or do you have any ideas?


问:
How did JavaScript become popular?
In ancient history, Brendan Eich had a language design, and in today's world, JavaScript is a popular language implemented and used in many different places.

What caused the language to become popular? Was it the C-like syntax familiar to previous programmers? Did Netscape have enough control of the market to force it to be used? Or is there some deeper reason that JavaScript is popular and other languages are not?

Particularly, if you had to make a language as popular as JavaScript, what initial conditions would you need to recreate its growth in popularity?

答:
I'm going to add an update to this because I think JS's emergence on the client-side web has been misunderstood on a few key points over the years.

It wasn't Ajax

I'm not saying Ajax wasn't important to the evolution of understanding of JS as a language but the fight for client-side browser dominance was over long before the term Ajax was coined.

It wasn't because it was the only game in town

There were Java Applets, Flash, and VBScript. I've heard there were even other scripting options in the '90s (but required plug-ins IIRC). Java is hugely popular yet applets were a dismal failure. They were ugly and often security-swiss-cheese but more importantly I don't think Java was a good fit for reasons I'll go into later. Flash was very popular and had a strong foothold for a number of years but even when Flash finally had SEO options, they weren't typically used, making exclusively Flash sites very hard to discover. Even now, most of us regularly update Flash so we can see movies but that's the real Achilles heel. Proprietary technology in browsers is annoying. And of course VB, which would only ever work with IE, so no.

Right Place at the Right Time is Relevant But Not the Whole Answer

Yes, without the web wave to ride we may never have seen JavaScript or a language in popular usage like it as soon as we did. Or maybe we would have...

It Ended Up Being the Perfect Tool for the Problem Domain

I'd say around 2000ish we had the following problems:

IE and Netscape had only just agreed to start playing nice by attending to the same DOM API and CSS standards and we've had to deal with a crap-ton of legacy JS cross-browser issues ever since which are only just starting to become manageable without the aid of JS DOM normalization tools like jQuery post IE8

There was a whole new generation of web developers/designers who weren't all necessarily heavyweights as programmers looking to improve their game post-.com-bubble-burst when they stopped handing you a decent salary for showing up at the door with nothing more than basic HTML-literacy and some photoshop skills.

There was this new CSS kid in town that offered intriguing possibilities for what would ultimately be called DHTML, (more appropriately) DOM Scripting, (now inappropriately) HTML5 (zomghtml5!).

So we needed a language that was both deep, offering the ability to actually structure and architect a more advanced app with portable/re-usable components on the client-side but also accessible to people who didn't know a lot and just needed things to appear/reappear when you clicked a button.

Furthermore, MS being the ungainly/incompetent and/or dominance-through-anti-competitive-practice-scheming beast that they sometimes are, failed to really touch their non-compliant DOM API implementation for a good solid decade, although they did manage to add the occasional thing like the original XHR object and querySelectors in IE8.

The important thing to note is that by around 2005 we had managed to so completely bury the complexity involved in handling cross-browser issues that it wasn't really a serious issue anymore on the JavaScript front. The failure to support CSS2 properly for as long as they did caused considerably more pain. For an idea of the sheer volume and depth of issues, I recommend checking out quirksmode.org. I do not think that this is a feat that could have been achieved as smoothly and in as many libraries in Java, certainly not in VB and definitely not with any plug-in strategy whose goal is to sidestep the entire issue by becoming an entirely new kind of nuisance.

Other Language Features That Make a Lot of Sense for UI:

First Class Functions: In my experience, nothing lends itself better to async processing and event-driven paradigms than a language that makes its functions first-class. Both concerns are regularly addressed in UI work.

Dynamic Types: Casting and type-checking is a very rare need in JavaScript which helped keep code concise and lean. UI concerns can get complex and messy very quickly. Keeping code tight and being absolutely clear about flow of data is critical to understanding and modifying/maintaining it.

It's Not Protectionist: For many years somebody's been preaching that you need to protect yourself from your own mistakes and the dumb things the other guy might do with your code by making code constructs highly rigid and inflexible and impossible to meddle with the original intent it was authored with and a lot of people have been listening. I won't say they're always wrong (might think it) but I will say it's the wrong approach to web UI and I do believe that it's something of a phenomenon that we've been cranking out, maintaining, and modifying client-side GUIs at a much faster pace and with greater ease than such work was typically accomplished in more restrictive languages in the past. Being able to change things on the fly quickly and easily makes it much easier to have dynamic/fluid architecture schemes that don't require monumental amounts of indirection and abstraction overhead which ultimately makes it easier to see what the Hell is going on in your code and pre-empt or handle exceptions much more cleanly. It is easier to maintain simply through sheer virtue of making it possible to be more direct in everything you do and with much less code than it would take given the other philosophy.

How did JS become popular? It has proven itself to be an excellent tool for the job time and time again. It is not the language we are "stuck with" It's the language that may have inspired a great deal of evolution in popular languages in general. And for that, you can thank Brendan Eich and any contemporaries who helped put the idea into his head, for liking Scheme as a design-inspiration fit for the problem at hand more than he liked Java.

Title: How did JavaScript become popular?


问:
How to create p2p enviroment in single laptop?
I'm developing a peer-to-peer dataspace application.

For that I want to create a peer-to-peer environment locally (on a single machine, a laptop). Is there a any method or tool to do that?

答:
Just connect it to a network, then it's on the same network as itself!

No joke, its that easy.. It can access itself variety of ways (over the network)
(As long as you can run 2 instances of your app on the same Computer)

By internal IP (and port)

By Computer Name (and port)

By IP: 127.0.0.1 (and port)

By external IP (and port) (if
you router is configured to forward forward incoming traffic to your computer )

Use a Service like Noip.com (Also Requires Router configuration)


问:
Looking to build a 2 java applications. should it be web-based application or standalone application?
The first application (web-based) will be located at site1 and once the information is processed, it will be sent to the second application(web-based) located at site2. Application2 needs to be able to do the same thing as application1. Because of this, there has to be a way to share the database to keep data in sync. I wanted to go web-based for these two applications, but the issue arises, what if the internet is down? If application1 goes down due to a blackout or lost of internet, application2 should still be able to do what it needs to. I was thinking the database/server will be on Amazon EC2.

Even if I go with a standalone application for site1 and site2, it still needs some sort of internet connection to talk to a shared database/server right, possiblity through tcp connection? Because of this, I dont see why it shouldn't just be a web-based applicatin then. This the disagreement I'm having with my team.

I want to know the pros and cons of making these two application either being a stand-alone or web-based.

答:
Before going web or standalone, figure out your business domain.

How often app talks to server(synchronizing user-workspace, fetch data, updating data, etc.)

How frequently user will be accessing the app (1 or 100 times a day).

How much time user will spend on the app (5 mins or 2 hrs).

pros and cons of making these two application...

There can be a huge list, but here are just few points for standalone:

pros:

work-offline(big plus).

No need to conside issues like cross-browser compatability.

No need to get into one more JEE Layer(KISS principle)

Simpler security model(e.g. no need to bother about xss attack, etc.).

cons:

accessbility(have to install on seperate machines e.g. home, office).

availability(not avilable on other devices, like tablets, smartphones).

upgrading


答:
Congratulations, you've embarked on the single riskiest type of project that is possible.

Complete rewrite, second system, unresolved people problems, lack of technical direction, up front willingness to make it big - any of those are red flags that would cause sane people to run screaming the other way.  The only bonus is that it would be hard to pick a worse language than the one you have now.

First we need to set a baseline expectation with some rough figures.  On average an "enterprise software development project" upon delivery takes 200% of estimated time, 200% of estimated budget, and delivers 50% of initially promised features.  Those aren't the failures - those are the successes.  Failure is extremely common, and looks the same as success until the organization pulls the plug because there isn't a working deliverable.  That is average.  Given the list of red flags that leapt out at me, your baseline expectation should be that you're at severe risk of starting below average.

I wish I was exaggerating.  Unfortunately I am not.

You're going to need to start counter-acting that with some positives.

First of all the platform. There are a ton of acceptable platforms that will do just fine for you.  If you want to move away from PHP (I'm biased - I would), then I strongly recommend that you embark on pilot programs in different environments to see what works for you.  Then go with whatever had the best reception among important stakeholders (including developers!).  What you choose will not be more important than whether stakeholders are happy with the choice.

Secondly the feature set.  You're building a second system.  Your top priority needs to be avoiding second system syndrome.  Everyone knows what they do not like in the current system.  Everyone has their, "I wish" and "what if" lists.  Individually those look great, and they are informed by experience with the first system.  But when you pile them all into the second system, it will fail.  Therefore someone must be in place to say no to feature requests, and must be ruthless.  (Read The Mythical Man-Month for a classic book inspired by an architect of a second system trying to figure out what went wrong.)  As a general rule of thumb, on a first system the inexperience shows and a third system generally goes well, but a second system is the most likely to fail.

Thirdly software estimation.  Run, do not walk, to pick up Software Estimation: Demystifying The Black Art by Steve McConnell and improve your organization's ability to produce accurate estimates.  Very few organizations are any good at it, and improving on this is a top priority before trying to embark on any large project.

Fourth, shy away from the "enterprise" label.  In general enterprise software means software that is sold to executives who are disconnected from the actual work.  Therefore it possesses excellent marketing and only occasionally technical merit.  Oracle would love to get your business.  They would definitely make you pay top dollar.  But unless you have something specific that you'd gain from them, they don't really have much to offer technically that PostgreSQL doesn't have.  And, speaking personally, the largest database that I've seen was a MySQL database at Google.  If Google can make it scale to their needs, it can scale to yours.  (OK, so Google was able to back it with what was effectively a RAM disk built on top of a redundant array of inexpensive computers.  And Google doesn't use MySQL for most of their data storage needs.)

Good luck.  Hopefully I scared you.  You should be scared.  This is definitely a high risk project.  But it is not impossible - just very, very risky.  A failure to accept, understand, and actively mitigate those risks is a guarantee of failure.