问:
How to store an object state/data for later processing?
What do you think would be the most effective solution to maintain an object status through a life cycle? The goal to be able to be continue from any state any time. During the life cycle likely to have human interactions over a variety of interface.

For example, an order which needs to be approved by a few people. Or a data supply process that can requires many people to approve or edit?

In my mind some solutions:

When called a function serializes the object and saves it in a database.

All steps of the process would be saved to somewhere (database, csv, xml, etc.), so it can always be recreated based on this.

Possibly a mixture of the two methods?

Any good methods for the problem?

答:
It sounds for me that you are mixing two problems into one here. In order to implement an object that can “continue” from any state, you probably need to implement a state machine.

As for serializing the object in case you need fault tolerance or some kind of persistence, you can use a lot of things — a database like SQL, No-SQL, Berkeley DB, or maybe a simple binary file, shared memory, or something like that. Which one to use depends on what exactly you need or what you already have.

In terms of what design patterns you may use, check these out:

Design Patterns for Data Persistence

State Pattern


问:
What is the best way to load balance javascript applications?
I write a lot of javascript applications and in many different circumstances the browser will become unresponsive or give a "slow script" error. Even when following best practices, initializing large data sets, complex animation, or when too many event handlers fire at once, I have to include extra setTimeouts or requestAnimationFrames around script blocks to load balance them. Seems like there should be some standard way of managing the browser load for large javascript applications.

Any ideas? It seems like there must be JS application designers thinking about this, but I can find nothing on the web or on stack.

edit

I appreciate all the response. My question is not "How can I write efficient Javascript?" which seems to be the question the current responses are answering. My question is: How can I balance the load of multiple sequential threads of javascripts running in the same browser?

I am well aware of all the information posted in the responses so far and appreciate the posters, but I am looking for a framework or a design pattern that balances script execution in a browser. This question is common in many other languages and for devops, I am simply asking the same question for javascript.

答:
So there are some long-winded answers here that are actually likely all correct. However, for your particular site, I'd consider it pretty likely that there are 1 to 5 functions that steal 99% of the CPU time, and could be 80%-optimized with some work.

Most browsers have code-profiling tools that will allow you to watch the code as you do something slow, and then tell you what the browser spent the most time doing. Whatever's at the top of the list afterwards is what you should focus on first.

The stuff about web workers, for instance, is really neat. But, in a basic webpage only using Javascript for a better user experience (as opposed to doing some sort of actual work) I'd be surprised if that's needed.

ContentLicense: CC BY-SA 3.0


问:
Efficient way to shuffle objects
I'm writing a program for some quiz software. I have a question class containing the ArrayLists for the question, answer, options, marks and negative marks. Something like this:

```<code>class question
{
    private ArrayList<Integer> index_list;
    private ArrayList<String> question_list;
    private ArrayList<String> answer_list;
    private ArrayList<String> opt1_list;
    private ArrayList<String> opt2_list;
}
</code>```

I want to shuffle all questions, but for questions to be shuffled, all the objects need to be shuffled. I would have approached this problem in this way:

First of all, I would not have used this design and used String not ArrayList<String> type as instance variables, and would then have used the Collections.shuffle method to shuffle objects. But my team insists on this design.

Now, the question class is containing increasing ArrayLists as the entry to the questions are made. How to shuffle the questions now?

答:
My original naive and wrong answer:

Just create (at least) n random numbers and interchange item n
  with item i in a for loop for each list you have.

In pseudo code:

```<code>for (in i = 0; i < question_list.length(); i++) {
  int random = randomNumber(0, questions_list.length()-1);
  question_list.switchItems(i, random);
  answer_list.switchItems(i, random);
  opt1_list.switchItems(i, random);
  opt2_list.switchItems(i, random);

}
</code>```

Update:

Thanks for the_lotus for pointing out the coding horror article. I feel much smarter now :-)
Anyway Jeff Atwood also shows how to do it right, using the Fisher-Yates algorithm:

```<code>for (int i = question_list.Length - 1; i > 0; i--){
  int n = rand.Next(i + 1); //assuming rand.Next(x) returns values between 0 and x-1
  question_list.switchItems(i, n);
  answer_list.switchItems(i, n);
  opt1_list.switchItems(i, n);
  opt2_list.switchItems(i, n);
}
</code>```

The main difference here is that each element is swapped only once.

And while the other answers correctly explain that your object model is flawed, you might not be in the positioin to change it. So the Fisher-Yates algorithm would solve your problem without changing your data model.

Title: Efficient way to shuffle objects

Body:
My original naive and wrong answer:

Just create (at least) n random numbers and interchange item n
  with item i in a for loop for each list you have.

In pseudo code:

for (in i = 0; i < question_list.length(); i++) {
  int random = randomNumber(0, questions_list.length()-1);
  question_list.switchItems(i, random);
  answer_list.switchItems(i, random);
  opt1_list.switchItems(i, random);
  opt2_list.switchItems(i, random);

}

Update:

Thanks for the_lotus for pointing out the coding horror article. I feel much smarter now :-)
Anyway Jeff Atwood also shows how to do it right, using the Fisher-Yates algorithm:

for (int i = question_list.Length - 1; i > 0; i--){
  int n = rand.Next(i + 1); //assuming rand.Next(x) returns values between 0 and x-1
  question_list.switchItems(i, n);
  answer_list.switchItems(i, n);
  opt1_list.switchItems(i, n);
  opt2_list.switchItems(i, n);
}

The main difference here is that each element is swapped only once.

And while the other answers correctly explain that your object model is flawed, you might not be in the positioin to change it. So the Fisher-Yates algorithm would solve your problem without changing your data model.


问:
When would I require a Macro instead of a function?
I am new to Clojure, I am new to Macros and I have no prior background in Lisp.
I went on to create my own switch case like form and ended up with this:

```<code>(defmacro switch-case [v cases default] (if (cases v) (cases v) default ))
</code>```

and then tried making a function and ended up with this:

```<code>(defn fn-switch-case [v cases default] (if (cases v) (cases v) default ))
</code>```

Both

```<code>(switch-case 5 {6 "six" 7 "seven"} "not there")
</code>```

and

```<code>(fn-switch-case 5 {6 "six" 7 "seven"} "not there")
</code>```

Work fine.

What could be the scenario where I would need a macro and a function wont work ?
Is there a drawback in my function or macro implementations ?

答:
I'm not exactly sure what you want your switch-case function to do. What should be the value of:

```<code>(def x 5)
(switch-case x {5 :here}
             :not-there)
</code>```

It might be useful if you viewed the source of the related core functions/macros by using the repl

```<code>(clojure.repl/source case)
</code>```

But in general a reason why you might want a macro as opposed to a function is that using the core case macro

```<code>(case 6
  5 (print "hello")
  "not there")
</code>```

will not print hello.
However, if case were defined as a function, it print "hello" to the screen and the whole expression would evaluate to "not there". This is because functions evaluate their arguments before every calling the function.

Body:
I'm not exactly sure what you want your switch-case function to do. What should be the value of:

(def x 5)
(switch-case x {5 :here}
             :not-there)

It might be useful if you viewed the source of the related core functions/macros by using the repl

(clojure.repl/source case)

But in general a reason why you might want a macro as opposed to a function is that using the core case macro

(case 6
  5 (print "hello")
  "not there")

will not print hello.
However, if case were defined as a function, it print "hello" to the screen and the whole expression would evaluate to "not there". This is because functions evaluate their arguments before every calling the function.


问:
How much inconsistency arises from Javascript's high flexibility?
I'll admit it, I haven't yet mastered the language, but my experience with it tells me that Javascript is a highly flexible language, allowing prototypal inheritance, dynamic typing, functions as first class citizens and so many more cool stuff. I think such features bring some inconsistencies, but that's nothing new, most people would agree with me. I wanted to discuss specific examples that have been annoying me, like "for in" loops:

```<code>for(var role in rolesToAdd){
                if(rolesToAdd.hasOwnProperty(role)){
                    // for body
                }
}
</code>```

Why should I need to do this? Doesn't this break the concept of classes and inheritance? I might not want to loop through the whole prototype, but what if I still need some of the attributes/methods from an object's direct parent, for example?

Also, I would be most grateful if someone could explain me why the interpreter doesn't allow synonymous global/local variables to share the same scope, when there is certainly a way it could distinguish one from the other. Like in:

```<code>var foo = function() {
        var wth = bar();
        var bar = wth;
        // body...
}();

function bar(){
    return 'bar mitzvah';
}
</code>```

You can see that, even though our local bar has been declared after the call to our global bar, bar's value in foo's scope will always reflect the local bar, which will hold 'undefined'. Isn't that a strange behavior? I would love if senior Js programmers enlightened me on this and showed me what is gained from these seemingly strange features and if the disadvantages I mentioned here are valid.

答:
It's assumed you want all the iterable properties of an object,  you only need to use hasOwnProperty if you think there are methods or properties in the object or its prototype that should have been marked as non enumerated but weren't. You seem to be fighting against the language where it is assumed your going to want all the properties of the object your iterating including all of the ones it inherited.  You need to remember that

JavaScript Does not have classes

this is important, you can simulate classes using libraries and classes may be added in ES6 but currently it has prototype based inheritance which which burn you if you try to pretend it's exactly the same as a class based one.

Your second issue relates to functional scoping,

```<code>var foo = function() {
    var wth = bar();
    var bar = wth;
    // body...
}();

function bar(){
    return 'bar mitzvah';
}
</code>```

is really.

```<code>var foo;

function bar(){
    return 'bar mitzvah';
}
foo = (function() {
    var wth;
    var bar = wth;
    wth = bar();
    // body...
})();//you want parentheses here I'm pretty sure.
</code>```

The issue is that new variables are hoisted to the top of the local (functional) scope meaning that even though you haven't redefined bar yet, as far as the language is concerned you have.

I honestly don't know the advantage that were in mind when it was created, if you really want to know you should ask Brendan Eich (no seriously he has been known to answer those questions on twitter), it is a feature though that I'm not sure many people who use JavaScript necessarily like as much as deal with.

Body:
It's assumed you want all the iterable properties of an object,  you only need to use hasOwnProperty if you think there are methods or properties in the object or its prototype that should have been marked as non enumerated but weren't. You seem to be fighting against the language where it is assumed your going to want all the properties of the object your iterating including all of the ones it inherited.  You need to remember that

JavaScript Does not have classes

this is important, you can simulate classes using libraries and classes may be added in ES6 but currently it has prototype based inheritance which which burn you if you try to pretend it's exactly the same as a class based one.

Your second issue relates to functional scoping,

var foo = function() {
    var wth = bar();
    var bar = wth;
    // body...
}();

function bar(){
    return 'bar mitzvah';
}

is really.

var foo;

function bar(){
    return 'bar mitzvah';
}
foo = (function() {
    var wth;
    var bar = wth;
    wth = bar();
    // body...
})();//you want parentheses here I'm pretty sure.

The issue is that new variables are hoisted to the top of the local (functional) scope meaning that even though you haven't redefined bar yet, as far as the language is concerned you have.

I honestly don't know the advantage that were in mind when it was created, if you really want to know you should ask Brendan Eich (no seriously he has been known to answer those questions on twitter), it is a feature though that I'm not sure many people who use JavaScript necessarily like as much as deal with.


问:
Difference between functional and technical specification
I'm writing a specification for a project, and am struggling with separating functional specification from technical specification (see http://www.joelonsoftware.com/articles/fog0000000035.html).

For example, I'm trying to specify the behaviour when a user requests a list of Foo objects they have visibility on. In the functional specification, should I describe what precisely is returned (i.e. the structure of a Foo object) or just that the system returns a list of them and then put the details of the Foo object in the technical specification?

The design is for an API in case that makes any difference. I can't find many examples of how such an API specification is written.

答:
Technical specifications is a broad term.  It describes any characteristic of an engineered system that must conform to a specific metric, within some degree of error.

Functional specifications describe the expected behavior of a software system.  Program specifications describe what the software is supposed to achieve.  This differs from a functional specification in that, while a program specification describes what the system does, the functional specification will describe the manner in which it does it.

I suggest you work for awhile with use cases.  At the user level, use cases are the way you describe the behavior of the system, whereas at the code level, the way you describe system behavior is with unit tests.  Both techniques can be used to derive functional specifications.  As you flesh out the behavior of the system with use cases, it should become clearer what the API should look like.

You begin by creating an informal list of use cases.  This document summarizes the process, as does this one.  Once you have use cases, you can begin to build functional requirements from them.

Example

When the reserved vehicle is not available due to late returns, the customer is informed of the situation and told about the other vehicle types that are available. The customer is offered an incentive to accept another vehicle type. If the customer is not satisfied, the reservation is cancelled without penalty charges. The customer either accepts another vehicle type or cancels the reservation.

Several functional requirements can be derived from this use case:

The system shall indicate when a vehicle is not available, and the reason.

The system shall provide a list of other available vehicles.

The system shall provide a list of possible incentives.

The system shall provide a way to choose a different vehicle.

The system shall provide a way to cancel the reservation.

And so on.  From such a list of functional requirements, the elements that need to be present in the API should become readily apparent.


问:
Using public final rather than private getters
I see most immutable POJOs written like this:

```<code>public class MyObject {
    private final String foo;
    private final int bar;

    public MyObject(String foo, int bar) {
        this.foo = foo;
        this.bar = bar;
    }

    public String getFoo() {
        return foo;
    }

    public int getBar() {
        return bar;
    }
}
</code>```

Yet I tend to write them like this:

```<code>public class MyObject {
    public final String foo;
    public final int bar;

    public MyObject(String foo, int bar) {
        this.foo = foo;
        this.bar = bar;
    }
}
</code>```

Note the references are final, so the Object is still immutable.  It lets me write less code and allows shorter (by 5 chars: the get and ()) access.

The only disadvantage I can see is if you want to change the implementation of getFoo() down the road to do something crazy, you can't.  But realistically, this never happens because the Object is immutable; you can verify during instantiation, create immutable defensive copies during instantiation (see Guava's ImmutableList for example), and get the foo or bar objects ready for the get call.

Are there any disadvantages I'm missing?

EDIT

I suppose another disadvantage I'm missing is serialization libraries using reflection over methods starting with get or is, but that's a pretty terrible practice...

答:
In layman's words:

You violate encapsulation in order to save a few lines of code. That
defeats the purpose of OOD.

Client code will be hard coupled to the names of your class members. Coupling is bad. The whole purpose of OOD
is preventing coupling.

You are also very sure your class will never need to be mutable. Things change. Change is the only thing that is constant.


问:
Java language constructs to enforce design decisions
What constructs in OOP languages (specifically Java) allow you to enforce design decisions and intent?

I think some examples would be the 'final' keyword, access modifiers, template methods, perhaps interfaces - but clearly I am having trouble coming up with an exhaustive list.

Some constructs, like inheritance, feel like they fit this criterion but I find it difficult to explain exactly why.

[edit] Turns out I took down a few more notes: Enum types, constructors, constants, and generic types. Although as in all things explaining why will be more important than just listing examples.

答:
First of all, I think that your question hits a topic which is of great importance these days, namely thinking about and documenting design decisions/intent.

In Java, the main mechanisms to really express intent besides just using the available keywords are assertions and annotations, because you can state for example pre/post-conditions, invariants or even the specification about parts of your programs which can be on a higher level of abstraction than code can be. The benefit comes to light if you have to read or maintain a piece of code written by someone else and you simply can't figure out its functionality.

In addition to that, each keyword has of course some semantics and because of this it also inherently expresses some intention when using it. As a matter of fact, you could state that using any pre-defined keyword in any language could be seen as a design decision, even the usage of a language is already a design decision.

The important point is that you simply can not express all your intentions through code and comments without loosing the "big picture", i.e. the code is definitely not the only truth. Therefore we have a "construct" called architecture which has the purpose of making visible and documenting those design decisions and intentions we are making up while thinking about a system. Sure, they can be enforced in code to make the code better readable and navigable but the code should not be the main place where the intentions are stated.


问:
Is there any way to get faster at solving bugs? I've just had a warning from my boss
I've just been told by my boss that I will receive a negative performance review on Monday. He wants to talk to me about why I am so slow and why my bug fix rate is so low.

I love programming and solving problems but I actually do find my job really really hard.

I've actually been a programmer for about 10 years. But this is my first multithreading embedded linux job - I've been here 2 years and it's obvious to everyone that I'm still struggling. And I think I've become so demoralised and feel so marginalised that I've lost a lot of the fire that I had at the start of the job.

Has anyone ever been in a similar situation and how do you go about increasing your bug fix rate?

Update:
I had the review. I have been put on a 3 month 'employee development program' (of the type mentioned by Dunk ). Not sure whether I can turn this around. But even if I do have to move on, I've learned a lot from this experience.

Another Update

It's now about 6 weeks since the first review.
My advice to anyone facing the same situation is to be humble enough to take criticism and learn from your mistakes. And to not be afraid to look dumb. Ask loads and loads of questions. Let people know you're trying to learn and keep asking until you understand.
But be prepared for it not to work out. I'm constructing a portfolio of code ... as well as giving it my best shot.

Yet another update

I am hesitant to put this on here, since I'm concerned that I will not be able to refer future employers to my stackoverflow profile... But anyway, it might be of interest for someone reading this question, but I actually lost my job a few weeks ago. I'm in the midst of brushing up on all the skills I need to - I've taken a lot from the advice given here.

答:
I recently read the book Working Effectively with Legacy Code and it's given me a significant boost of confidence when tackling an issue in any codebase.

If the code you're working with is anything less than perfect, I think this book would be of help. I've found that a lot of the time in order to fix a bug, I need to first refactor the surrounding code in order to even understand it, and then once I understand the code, and hopefully make the code testable, tracking down and fixing the problem is less of an ordeal. (Sometimes I even rewrite the code just to understand it, but then revert my changes to reduce the risk of introducing new bugs. Then I insert my bug fix. That technique is based on a trick from the book.)

I think my suggestion only addresses part of your issue, and somewhat indirectly, but the book is worth reading no matter what, since working with legacy code is an inevitability for any developer.


问:
What simple techniques do you use to improve performance?
I'm talking about the way we write simple routines in order to improve performance without making your code harder to read... for instance, this is the typical for we learned:

```<code>for(int i = 0; i < collection.length(); i++ ){
   // stuff here
}
</code>```

But, I usually do this when a foreach is not applicable:

```<code>for(int i = 0, j = collection.length(); i < j; i++ ){
   // stuff here
}
</code>```

I think this is a better approach since it will call the length method once only... my girlfriend says it's cryptic though. Is there any other simple trick you use on your own developments?

答:
I've got a little different take on it. Just simply following advice you get here isn't going to make much difference, because there are some mistakes you need to make, which you then need to fix, which you then need to learn from.

The mistake you need to make is to design your data structure in the way everyone does. That is, with redundant data and many layers of abstraction, with properties and notifications that propagate throughout the structure trying to keep it consistent.

Then you need to do performance tuning (profiling) and have it show you how, in many ways, what is costing you oodles of cycles is the many layers of abstraction, with properties and notifications that propagate throughout the structure trying to keep it consistent.

You may be able to fix these problems somewhat without major changes to the code.

Then if you are lucky you can learn that less data structure is better, and that it is better to be able to tolerate temporary inconsistency than to try to keep many things tightly in agreement with waves of messages.

How you write loops has really nothing to do with it.

ContentLicense: CC BY-SA 2.5


问:
Source code of jar.exe - is it available
This may seem an odd question, but I want to create an executable which runs under Windows written in C++.  The program needs to be able to update a jar file even if Java is not installed on the target machine.  I have seen the src.zip in the Java JDK folder and the jar folder but this is Java code.  I assume jar.exe is written in C or C++?  Is it possible to see the jar.exe source code?  If so where would I find that?</p>

答:
Actually, jar.exe is just a thin wrapper around a Java implementation found in the package sun.tools.jar.

But a JAR file is simply a ZIP archive with a metadata directory. You can use any ZIP implemetation such as libzip to manipulate JAR files.


问:
How can I maintain a SQL schema upgrade that goes out to our users on a regular basis?
I work on a project that uses a SQL database as a back end, and a desktop app as a front end. We do releases on a regular basis, and as part of a release, our client needs to update their SQL server.

Our business requires that we are upgradable from version 1.x to 1.y, and the way we've been doing it so far is by following a simple pattern for dozens/hundreds of tables:

IF NOT EXISTS (XXX) CREATE TABLE/VIEW YYY ...

ALTER TABLE (XXX) ADD COLUMN (WWW) ...

CREATE INDEX (ZZZ) on table XXX (if needed)

So on...

The problem I see with this is that the steps laid out above are all laid out in a one-for-one relationship with the table that's being created. This is fine for simpler databases that have no constraints, but becomes a pain when foreign keys/triggers/anything complex becomes involved.

I was wondering if there was a pattern out there that could help me clean this up and make modifications to my script easier. I was thinking something along the lines of following these steps for every table in the database:

perform cleanup from any "old" version

create/update all tables/columns (without constraints)

create/update all views based on tables

create/update all foreign keys / constraints

create/update all indexes

create/update all triggers

...

I use a tool to merge all of the SQL files in my repository into one, but the rhyme/reason to which file gets merged at what point is becoming unclear - often I just give up and hack something in that says "include file X directly before/after file Y". It's becoming unmaintainable (I can still fix problems, but I want to be able to hand off this responsibility).

It's this last annoyance that I want to be able to avoid. I want to be able to create a new table by just dropping a script with the content "CREATE TABLE X..." in a "Tables" directory and call it done.

Are there any patterns out there that can help me? I'm really looking for some sort of ammunition that I can use when I propose this to my colleagues by saying "see - there IS a solution to this cluster* and THIS is how other companies address it."

答:
This is not originally my idea, but here's a manual way to do it:

Create a "UpdateScripts" directory.

Create a field in the database which tracks the ID# of the last-run script.

Every time any change is made to the database structure, save it as a script in that directory, with a sequential number (such as 00001) in front.

Every time the customer launches, run every script in order between the stored ID and the last script in the directory.

Update the last script field.

There are a number of alternatives, most more automated than this, discussed here.


问:
How can I extract words from a sentence and determine what part of speech each is?
I want to write something that takes a sentence and identifies each word it contains and defines what part of speech each word is.

For example

Hello World, I am a sentence

would return this

```<code>verb noun, pronoun verb adjective noun
</code>```

Ideally, I'd like to eventually take it one step further and take a sentence and programmatically have it understand what it is trying to interpret and maybe do something about it.

So my question is, has someone heard of something like this?

答:
A cheap way of doing this would be to set up a database of the dictionary (I'm almost positive that someone has done this).

Need two fields in the table: word and usage

Turn the phrase into an array of strings, (each word being a string) and independently:

```<code>select 'usage' from Dictionary WHERE 'word' = $word;
</code>```

It's a heavy solution, but one that I've used in the past.

Body:
A cheap way of doing this would be to set up a database of the dictionary (I'm almost positive that someone has done this).

Need two fields in the table: word and usage

Turn the phrase into an array of strings, (each word being a string) and independently:

select 'usage' from Dictionary WHERE 'word' = $word;

It's a heavy solution, but one that I've used in the past.


问:
Should I allow my client to self host?
I'm just starting out as a web designer. I'm trying to build up a portfolio for my own website.

I'm concerned about designing a site and handing it over to the client. Once I do this I could lose access to the site. They can change the login information and they may not need to me manage it. If the client changes anything on the site that compromises my design work, it will reflect my business. My business' name will be on the homepage of the website.

Is this a valid concern?

答:
I always host for clients:

You built the website, you are responsible for its security.

You cannot trust cheaphostx to be secure or have the libraries required for your site to run.

Perfect example, I had a client who wanted to self host. But the site I built them required php with cURL. The host they chose didn't have cURL a piece of the site didn't function and I got blamed for it.

So I always host.

Title: Should I allow my client to self host?


问:
Is Objective C a reasonable way to learn C?
I want to learn C but I tend to learn best when I have a project to work on. I've never done iPhone development, so I'm hoping to kill two birds with one stone. Will learning objective c also teach me to program c reasonably well, or are they too dissimilar?

EDIT: I'm mostly wondering if objective-c/iphone-development would teach me all the little gotcha's that are inherent to c. I come from a .Net background so I haven't done much in terms of memory management or working with pointers.

答:
they are two seperate languages,

Learning the Obj C Language may actually hurt your understanding of C in the long run, since C is very low level and Procedural, where Obj C is not.

to learn C...you need to learn C.

the closest thing i can think of to learning a language like C that isnt C. would be PHP.


问:
How can degree of order in a list be measured?
The following questions gave me food for thought:

Efficient way to shuffle objects

I'd like to write an "ultimate shuffle" algorithm to sort my mp3 collection

When you sort a list - you always have a base-line(numbers, alphabet, ...) which tell you how to order the list.

Question: When you shuffle a set - how would you measure "degree of order"?

For example: 9 8 7 6 5 4 3 2 1 is ordered, even if completely differently than 1 2 3 4 5 6 7 8 9.  And 9 8 7 6 1 2 3 4 5 also has some order (if you look at it in chunks: 9 8 7 6 and 1 2 3 4 5). Another example could be 9 2 3 4 5 6 7 8 1.
How can you determine if one listing is less or more ordered than another.

Note: since there has been some confusion about the goal of this question - I would like to specify, that I'm not looking for a method to measure randomness. 1234 is just a random set of 4 digits as 4213, but it seems to me that 1234 is more ordered than 4213. The comment about "Kolmogorov complexity" by user61852, or the answer by Mathew Foscarini which mentions measuring the deviation between neighboring numbers in a sequence, are the types of answers I am looking for. I'm not sure if the measure entropy approach in the comment by MichaelT helps identify order in a list - if the comments could be elaborated into answers that would be great.

答:
The structure of an order set of numbers is measured by the deviation between the numbers.

Given a sequence of 1 2 3 4 5 6 7 8 each number deviates by 1 from it's neighbor. A consistent deviation applies the sequence has structure.

If two sequences share the same deviations between numbers, then they are of the same level of complexity or lack of complexity. 1 2 3 4 5 and 8 9 10 11 12 both deviate by 1 yet share no numbers.

Deviation doesn't apply what type of structure. It just defines a value for the structure. Example; 1 2 1 2 1 2 and 1 2 3 4 5 6 both have a deviation of 1.

A non-sequential and non-repeating deviation does not imply a random sequence. It just implies constant variation in the structure of the sequence.

Keep in mind that randomness and non-repeating are different. Random numbers do repeat, and they do run in sequence. The randomness of a sequence can only be a calculated by sampling other sequences from the same population of data. If you just have one sequence, then it's not possible to say if the whole sequence is random.

If we have a sequence of numbers that is 3 digits long, then randomly speaking every possible 3 digit number is possible. Roll a set of 3 dice enough times and the number 666 will up as many times as the number 123.

If you have a sequence of numbers. You could divide that sequence up into smaller pieces, and then calculate the odds of that small sequence appearing. If you find a sequence repeating more often then it should, then those pieces are not appearing randomly.

For example;

227322282364622617
broken into 2 digit numbers would be

22 73 22 28 23 64 62 26 17

The odds of a 2 digit number appear or 1 in 100, but the number 22 appears twice. If our sequence was long enough. We could tell if 22 is appearing more often than once for every 100 pairs.


答:
When evaluating a shuffling algorithm to determine if it truly generates a "random" sequence you can't just look at once sequence.  1 2 3 4 5 is a perfectly valid result of shuffling 5 numbers.  What's important when evaluating a shuffling algorithm is that every single possible ordering is equally likely.  As such, every single possible ordering is a "valid" result of shuffling the list.

So, how do you determine if your shuffling algorithm is "fair" or if it's "biased"?

First you'll need to generate a lot of random sequences.  It should be at least an order of magnitude, if not several, larger than the size of the list.

Next, determine what percentage of the time each item appears in each position of the list.  You should find that each item appears in each position about 1/n% of the time (where n is the size of the list).  If certain items are more likely to appear in certain positions, then your shuffling algorithm is not "fair".

Title: How can degree of order in a list be measured?

Body:
The following questions gave me food for thought:

Efficient way to shuffle objects

I'd like to write an "ultimate shuffle" algorithm to sort my mp3 collection

When you sort a list - you always have a base-line(numbers, alphabet, ...) which tell you how to order the list.

Question: When you shuffle a set - how would you measure "degree of order"?

For example: 9 8 7 6 5 4 3 2 1 is ordered, even if completely differently than 1 2 3 4 5 6 7 8 9.  And 9 8 7 6 1 2 3 4 5 also has some order (if you look at it in chunks: 9 8 7 6 and 1 2 3 4 5). Another example could be 9 2 3 4 5 6 7 8 1.
How can you determine if one listing is less or more ordered than another.

Note: since there has been some confusion about the goal of this question - I would like to specify, that I'm not looking for a method to measure randomness. 1234 is just a random set of 4 digits as 4213, but it seems to me that 1234 is more ordered than 4213. The comment about "Kolmogorov complexity" by user61852, or the answer by Mathew Foscarini which mentions measuring the deviation between neighboring numbers in a sequence, are the types of answers I am looking for. I'm not sure if the measure entropy approach in the comment by MichaelT helps identify order in a list - if the comments could be elaborated into answers that would be great.


问:
What does it mean for an architectural style to be document-centric?
I heard it said that REST is "document-centric". Unclear what this meant, I began poking around and found the term document-oriented being used of databases, particularly NoSQL databases, and in contrast to a barebones key-value store. Thus it seems that documented-orientation of databases has to do with their internal representations being JSON or XML; I saw on the Wikipedia page that many document-oriented databases claim to support a RESTful API, but not having experience with any NoSQL databases and also being new to REST, I'm unsure what that means (the database itself is directly accessible through a service?); and anyway, as far as I know, REST does not constrain the underlying data model of an application, but only its service contract.

So what does it mean to say that REST is document-centric/oriented? Does it mean that REST constrains a service to use JSON or XML in its contract? Does it mean that REST is more friendly towards NoSQL databases than conventional relational databases?

答: Document-centric means that it doesn't require static schema. This is usually done by saving data in platform-agnostic format using many data-serializing methods like JSON and XML. This allows easy development and versioning, but makes it harder to validate each object.</p>


问:
Asp.Net MVC Windows authentication - vulnerabilities of http vs https?
I am developing an ASP.Net MVC 3 intranet site that will use Integrated Windows Authentication exclusively. What are the vulnerabilities of the challenge/response authentication traffic being sent in plain text? Will someone sniffing the network traffic be able to hijack an authenticated session?</p>

答: NTLM is probably one of the better options you've got in terms of authenticating in the clear, but you still have plenty of vulnerability if you aren't encrypting the transport layer, even in a somewhat trusted environment. Basically, if the data matters spend the extra $25 and get yourself a legit certificate.</p>


问:
Should MVVM ViewModel inject an HTML template for default view?
I'm working on web application design that includes Knockout.js and have an overall MVVM question: Does it make sense for the ViewModel to automatically inject a default HTML template (pulled from separate file)?

More detail: suppose I have a site like this...

```<code>header...
    widget 1
    widget 2
    widget 3
footer
</code>```

...and widgets 1/2/3 are going to be Knockout.js ViewModels determined at runtime from an overall list of available widgets, each with associated HTML template file. I understand that in MVVM you want the view (HTML template in this case) to be separate from the ViewModel (Javascript file in this case) so that people can edit it separately and possibly provide multiple templates for different "skins". However, it seems like it would also make sense for the ViewModel to point to a default html template that gets automatically used unless the controlling code provides a different one.

Am I looking at this correctly?

As an example, see this answer on StackOverflow where he recommends injecting the HTML and then the ViewModel. Seems like a one-liner would make more sense in that case, with the possibility of overriding a default template value.

答:
I think in this context (of favouring flexibility via an interface comprised of widgets) using a ViewModel-assigned layout is fair game.  i.e. the default interface/layout is just as well served as a template along with everything else.  It just makes it harder to understand and you'd probably have another step or two in your workflow and debugging - though these could be engineered out with supporting apps or scripts.

Pros: flexibility, maintainability*

Cons: less intuitive*, slight delay in rendering

* if/unless you understand it!


问:
What traits do the best testers you've worked with have in common?
Tester and blogger Lanette Creamer recently posted this question on Twitter:

If you are a professional software developer who works with testers, think of the best testers you know. What traits do they have in common?

I thought it would make an excellent question for here.

My thoughts are:

They want to remove ambiguity from requirements even if it means asking awkward questions.

They create new features by seeing the way software "should" work, rather than just how it's documented.

They demonstrate honesty and integrity and encourage but not demand it from those around them. In other words, they model behavior.

What are the traits of the best testers you've worked with?

答:
Two things that haven't been mentioned yet:

Asks questions

Pays attention to details


问:
Is there a compliance test for C++ compilers?
Is there, somewhere, a freely usable/accessible script, source file, or whatever, that is able to measure the compliance of a given C++ compiler?

For example, the Acid3 test for browsers: http://acid3.acidtests.org/

The results I dream of would be a global percentage note (or multiple notes, one for each standard, e.g. , c++98, c++11, c++14, etc.), and then detailed tests with "success" or "failure" for each of them.

Background: I had a discussion at work about boost and some challenged compilers. My interlocutor spoke about boost being an academic project, because it won't work in major C++ compilers, and me answering that mentally challenged compilers should not count. Being able to measure with code the actual conformance of a compiler would help both in evaluating the compiler, and discovering the "corner cases" that should be avoided in cross-platform code compiled with them.

Edit: 2013-06-22

Not an answer, but apparently, the C++ committee is working on the subject:

SG10, Feature Test: Clark Nelson (Intel). Investigation into whether and how to standardize a way for portable code to check whether a particular C++ product implements a feature yet, as we continue to extend the standard.

Source: http://isocpp.org/std/the-committee

答:
The closest thing I'm aware of is in the context of a specific standard version. Similarly, there are blog posts that contain like content. However, I'm not aware of a de facto or de jure body, test, or test suite that rules on such matters. Even isocpp.org doesn't appear to have conformance resources currently. The closest you can get is probably each vendor's specific conformance charts which is inconsistent at best.

e.g. Clang, GCC, MSVC, Intel

There are really only a few competitive compilers (at least in the x86/x64 space - I assume it's also the case for less popular platforms), but I agree that it would be very nice to have a reference, especially now that the standard is picking up speed.


答:
I am unaware of any standards testing, though the following URL is the official standards website comitee http://www.open-std.org/jtc1/sc22/wg21/.

Also, many things that are found in Boost make their way into the C++ standard.  According to Dr. Kenneth Sundberg of Utah State University.

I also can't verify the accredibility of it yet, I am still trying to figure out if it is credible, but the Google Group at https://groups.google.com/forum/?fromgroups#!forum/comp.std.c++ claims that no official test exist.

Title: Is there a compliance test for C++ compilers?

Body:
Is there, somewhere, a freely usable/accessible script, source file, or whatever, that is able to measure the compliance of a given C++ compiler?

For example, the Acid3 test for browsers: http://acid3.acidtests.org/

The results I dream of would be a global percentage note (or multiple notes, one for each standard, e.g. , c++98, c++11, c++14, etc.), and then detailed tests with "success" or "failure" for each of them.

Background: I had a discussion at work about boost and some challenged compilers. My interlocutor spoke about boost being an academic project, because it won't work in major C++ compilers, and me answering that mentally challenged compilers should not count. Being able to measure with code the actual conformance of a compiler would help both in evaluating the compiler, and discovering the "corner cases" that should be avoided in cross-platform code compiled with them.

Edit: 2013-06-22

Not an answer, but apparently, the C++ committee is working on the subject:

SG10, Feature Test: Clark Nelson (Intel). Investigation into whether and how to standardize a way for portable code to check whether a particular C++ product implements a feature yet, as we continue to extend the standard.

Source: http://isocpp.org/std/the-committee


问:
In which cases build artifacts will be different in different environments
We are working on automation of deployment using Jenkins. We have different environments - DEV, UAT, PROD. In SVN, we are tagging each release and placing same binaries in DEV, UAT, PROD. The artifacts already contains config files w.r.t each environment but I am  not understanding why we are storing binaries in environment folder again. Are there any scenarios where deployment might be different for different environments.</p>

答:
There are a number of scenarios where your deployment could be different per environment:

Which machines are being deployed to (obviously).

Config files (you mentioned this).

Number of machines (or VMs) per environment.

Load balancer.

Network configurations.

Authentication.

There could be lots of others, but it's hard to say without more info on your specific project.

As for storing binaries, it is fairly common to store build artifacts somewhere, but I'd recommend using an actual artifact repository rather than a "source code repository" like SVN. You'd have build jobs that create the artifacts (release or in-progress) and put into the repository. Then you'd have other jobs that deploy the artifacts to servers. You can combine them, but that gets to be a lot on one job and you start losing granularity.

(Aside: I've got some experience using Maven, Nexus, and Jenkins for C# webservices... but that's some real craziness for most .NET developers. But once you've got Maven working for you in .NET-land -- instead of against you -- then you gain some neat benefits.)


问:
What is the best way to load balance javascript applications?
I write a lot of javascript applications and in many different circumstances the browser will become unresponsive or give a "slow script" error. Even when following best practices, initializing large data sets, complex animation, or when too many event handlers fire at once, I have to include extra setTimeouts or requestAnimationFrames around script blocks to load balance them. Seems like there should be some standard way of managing the browser load for large javascript applications.

Any ideas? It seems like there must be JS application designers thinking about this, but I can find nothing on the web or on stack.

edit

I appreciate all the response. My question is not "How can I write efficient Javascript?" which seems to be the question the current responses are answering. My question is: How can I balance the load of multiple sequential threads of javascripts running in the same browser?

I am well aware of all the information posted in the responses so far and appreciate the posters, but I am looking for a framework or a design pattern that balances script execution in a browser. This question is common in many other languages and for devops, I am simply asking the same question for javascript.

答:
To address the "load balancing" aspect of your question, I'd say that it is impossible for browser-based JavaScript.

"Load balancing" implies that you have more than one machine to work against. I.e. if deploying a RESTful service, you'd have many machines running the same service and spread out the traffic amongst them. This idea really doesn't apply to JavaScript running in browsers (node.js is a different story) because you've only got one client machine. There isn't a way to spread the load out to other machines.

"Threading" is probably a better analogy (as others have mentioned). In general, threading isn't really available in JavaScript, but you can use HTML5 Web Workers to achieve a similar result... but then you're restricted to supported browsers.


问:
Task Planning on an Agile Team
At the beginning of each sprint our team will pull in a handful of user stories and then, one by one, write slightly more detailed tasks for them as well as assign specific hours to each task.

Having individual tasks helps us establish our sprint burn-down by having a specific total number of hours up front, as well as make it more feasible to keep track of who's working on what and what all has been completed.

However, I recently read that some mature Agile teams have eliminated the use of writing tasks altogether and head right into their sprints armed only with their user stories as the modularized sources of work for the sprint.

I'm having a hard time seeing how eliminating task planning could still provide an Agile team with small enough units of work so as to keep the sprint organized and transparent. Has anyone here tried or use this approach and if so how do you keep track of exactly who is working on what?

答:
It all depends on how the team wants to manage its time and consume stories, and how well that works for the Scrum Master and other management staff that care about metrics.

Task breakdown is a good way for a team to verify the original estimated complexity of the story (usually estimated way back in a "milestone planning meeting" given only a high-level view of the requested features), and to plan out the division of labor based on the various "critical paths" through the stories in the sprint backlog. By breaking the stories into tasks, you can see your progress from day to day on a burndown chart, without having to log actual hours spent and estimated hours remaining on each story; when the task is done, those estimated hours come off the top, and the results are the same as if developers were constantly inputting estimated remaining time (and who wants to be doing that all day?).

It's useful to the point of necessity in two common situations:

Your team's "hours per point" metric is greater than a developer-day. If one developer would regularly report that they're working on the same story for two or more standups, then to get an idea of progress from day to day through the sprint, it's virtually a requisite to describe that progress in terms of smaller pieces of the larger story (just like most everything in Agile is described), i.e. tasks. Otherwise, if a developer was assigned a story that will take him the entire iteration to complete, then his story's points value just sits there in the burn-down until the last day, when he either makes or breaks the sprint.

Two or more developers will be working on the story. If two developers have to divvy up the work, then it's critical that they break the work down into chunks that they can share between them, to avoid both of them doing the same work or neither of them doing something important.

Now, if the nature of the stories that your team regularly brings into a sprint is such that one developer could complete at least one a day, then that baseline for a "one-pointer" means that a points-based burndown makes more sense, and task breakdown is less of a concern. Your stories are already "bite-sized", either by doing a story breakdown of larger work or simply because you're in "maintenance mode" and only small incremental changes are being requested, such that even if you only report completed stories, your burndown will pretty accurately reflect remaining work.

Title: Task Planning on an Agile Team


问:
How does a CLI-oriented programmer's workflow differ from a GUI-oriented one?
I've heard a lot about the advantages of doing less programming work in GUI apps and using more command-line tools (especially with regard to getting things done more efficiently).  However, since I don't understand how my workflow would be different if I depended more on command-line tools, I can't readily evaluate whether there's enough of a payoff for me personally to invest time and effort learning a new toolset and changing my workflow.

Right now:

I code some side projects in languages like C/C++/D/C#/Java/Python using Visual Studio, Eclipse, etc., and run them by setting up the build settings, and pressing F5 to build/run.

I'm developing a web program at work, so that involves using Django to set up a server, connect to a database, etc... almost all within the SciTE text editor.

For launching regular programs, I use Launchy... still no terminal. :)

For copying files and whatnot, I use a regular find/move in the graphical file manager (Windows Explorer, Nautilus).

Debugging: I use either Visual Studio or Debugging tools for Windows (if I'm on Windows). I haven't done much debugging on Linux, but for the things I've done, I've used Eclipse (also for Java on Windows).

At work: To connect to the build system and set up a project, I just use tools that have been integrated into Eclipse for my use -- no need for a terminal or anything (although I'm certainly welcome to use a terminal if I indeed want to)

What is it like to do these things in CLI?  Which parts become more/less efficient?  Which aspects of my workflow would need to be changed to get the greatest advantage from a shift to working mostly in CLI?  In other words... If you magically transformed me into a command-line guru, how would my new coding workflow be different from my current, GUI-centered, way of doing things?

答:
"converted into a CLI guru overnight?"  Aye, there's the rub. Well-designed GUIs tend to be more discoverable than CLIs, and more forgiving to the newbie.

My workflow, recently enhanced by a tiling window manager (dwm), consists of a lot of typing.  My laptop is now actually usable without plugging in a mouse (The trackpad is adequate for what's left of pointing).  I keep a lot of apps open and switch with alt-tab.  I don't waste time moving and resizing windows.

Most of the time, I use a browser, vim, and a bunch of terminals. SSH gives me a lot of flexibility as to where I work (physically). Remote desktops may offer a better experience when we all have 10Gigabit pipe to the net, but I won't hold my breath.

I haven't learned vim well enough to take advantage of its complex features, but I am leaning in that direction -- I want to have vim jump to the right line # after a failed make. (Technically vim is a Visual Interface, even though it runs in a terminal, but I drive it with a keyboard, not a mouse.)

The real problem is poorly designed interfaces.  Well-designed interfaces are hard to create, so they don't happen very often in either camp.  But since more non-ux-wizards are designing GUIs today than CLIs, ....

(My other big pet peeve is bloat. When it takes a 19MB program to help me accomplish the same task as a 200kB program, something is wrong. XTree Gold for DOS enhanced my productivity more than any modern file manager. Windows 2.11 used only tiled windows. Turbo C was an awesome IDE. Why does my Nook seem to run slower than a Mac classic?  Why does the kernel alone now take up more disk space than the entire system used to take?)


问:
How to handle deleting record with associated records?
This is not a technical question but rather about the right logic on handling delete with foreign key constraint. In my exercise app, I cascaded the record with OneToMany relationship with other records. In other words when I delete the record, Hibernate will automatically delete the associated records.

My problem is, my teacher told me that cascading is not right. He said that the user must delete first the associated records and he didn't tell me the details and he is kinda angry when he told us. (I don't know what's his problem but I don't really mind. I just want to learn).

Please give me some advice because I cannot make up my mind. So far these are my thoughts:

1) After clicking delete, the system will tell the user that there are associated records and it will be deleted along if he continues. He will be then ask if he will continue.

2) After clicking delete, the system will tell the user that there are associated records and he can be redirected to a page or there is a pop-up that will show all the associated records and he can manually delete.

3) Don't allow the user to delete.

答:
The answer depends entirely on the system requirements.

Some systems do a "cascading delete," which deletes the related records before the primary record is deleted.  Others set a flag on all deleted records, and only removes them from the database permanently when a certain amount of time has expired; this allows for undeletes to take place, if desired.

In all cases, it can be useful to notify the user when related records are about to deleted, or display the records to the user so that they can approve deletion.  Security systems can prevent a user from deleting the records, if they don't have the right to do so.  But ultimately it depends on what the requirements are.


答:
The term load balancing is confusing here and I think that has led to some answers that you don't feel are helpful.

First off, all of the advice given in the other answers is sound.  Please listen to the other experts here.

Now on to your load balancing.  Load balancing means to create multiple workers and distribute work to them transparently.  Traditionally, it means having multiple servers serve client requests.  But I see how it applies to your JavaScript performance issue here.

It sounds like you are trying to see if you can break your code up into multiple processes or threads so that they can run in parallel.  Two problems with that:

Parallelizing something doesn't speed it up as dramatically as you might think and adds complexity / risk and sometimes even performance penalties as you add synchronization points around your critical sections.

JavaScript is single-threaded.  Even if you want to take the risk of creating multiple threads, you cannot.

That said, there is a possible solution.  There is a new technology called web workers designed for message passing and handling.  That can probably give you what you need.  However, I don't believe (could be mistaken here) that it is supported by all browsers.

http://www.html5rocks.com/en/tutorials/workers/basics/

Mozilla's developer site has good information about thread safety issues.  Read that over before you pursue this course.

https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers

Title: What is the best way to load balance javascript applications?

Body:
I write a lot of javascript applications and in many different circumstances the browser will become unresponsive or give a "slow script" error. Even when following best practices, initializing large data sets, complex animation, or when too many event handlers fire at once, I have to include extra setTimeouts or requestAnimationFrames around script blocks to load balance them. Seems like there should be some standard way of managing the browser load for large javascript applications.

Any ideas? It seems like there must be JS application designers thinking about this, but I can find nothing on the web or on stack.

edit

I appreciate all the response. My question is not "How can I write efficient Javascript?" which seems to be the question the current responses are answering. My question is: How can I balance the load of multiple sequential threads of javascripts running in the same browser?

I am well aware of all the information posted in the responses so far and appreciate the posters, but I am looking for a framework or a design pattern that balances script execution in a browser. This question is common in many other languages and for devops, I am simply asking the same question for javascript.


问:
Balance Tree with depth n has how many nodes maximum?
I couldn't find the answer anywhere, but let's say we have a B-Tree with min = 1 and max = 2: What is the formula to calculate the maximum number of nodes in this B-Tree if the depth is say 100? This question was given on an in-class test to which most everyone had no idea what the answer was. I was completely stumped and am wondering if anyone knows what it is. Thanks a lot!</p>

答:
A binary tree of level 0 has 1 node.

A binary tree of level 1 has 3 nodes. (1 + 2)

A binary tree of level 2 has 7 nodes. (1 + 2 + 4)

This can be written as 2n + 2n-1 + ... + 20.  In a more formal notation this can be represented as

This also has another property that is obvious when written in binary

```
0 -> 1                  -> 1
1 -> 3  (1 + 2)         -> 11
2 -> 7  (1 + 2 + 4)     -> 111
3 -> 15 (1 + 2 + 4 + 8) -> 1111
```

The nuber of nodes of a binary tree depth n is 2n+1 - 1.

See also A000225 from the Online Encyclopedia of Integer Sequences.

Body:
A binary tree of level 0 has 1 node.

A binary tree of level 1 has 3 nodes. (1 + 2)

A binary tree of level 2 has 7 nodes. (1 + 2 + 4)

This can be written as 2n + 2n-1 + ... + 20.  In a more formal notation this can be represented as

This also has another property that is obvious when written in binary

0 -> 1                  -> 1
1 -> 3  (1 + 2)         -> 11
2 -> 7  (1 + 2 + 4)     -> 111
3 -> 15 (1 + 2 + 4 + 8) -> 1111

The nuber of nodes of a binary tree depth n is 2n+1 - 1.

See also A000225 from the Online Encyclopedia of Integer Sequences.


问:
modify source of copyrighted software
There is a a program that I want to use that is released in two (fully copyrighted) ways:

Stable binary form

Beta release, mostly-stable binary form that is easy to derive the source (uses jars) (this version is free)

Question:

Can I legally download the beta version, make the necessary changes to work properly on my machine, recompile and then use the software?

If yes to question 1, can I then explain to people I work with how to do the same thing so that they too can use the product?

In no way would I be giving them the modified software, but rather distributing instructions how to modify it.  The original download would still come from the copyright owner.

I believe I have done my due diligence searching these and google's forums, but as always, if you find a duplicate question, please let me know (and point to where it is found).  It seems odd to me that this hasn't been covered yet.

答:
Are you "copying" the part of the program or all of it? Is your program/app when compiled have any resemblance on the original? Is it a GUI or just plain library code? I think you can easily get around when you're just using part of it, and if your app does not resemble or function the same way as with the original.

Licenses varies so you better try to consider that when re-using code, even big Companies get sued for this kind of matter.

My suggestion is, if there's a app or source code that functions the same way with that you are trying to re-use using Apache License then better go with that.

Otherwise, a "hacky" approach is to just copy parts of it, ideas and patterns from the code. If it's not patented then I don't think they can sue you for looking at their code, and creating your own code out of that code you saw.

Title: modify source of copyrighted software


问:
Dependent Object Serialization
What's the recommended way to serialize dependent objects, especially when objects are being freshly constructed (to avoid malicious byte streams, or whatever)?  For example....

After creating a (genericized, but setup through Spring for my company) fiscal calendar based on JodaTime, I'm creating the next version based on JSR310 (using the back-port for development) in preparation for Java 8.

Currently, I'm working through serialization; how am I supposed to serialize dependent objects?  Most of the existing stuff has a 'single' chronology, but I don't get to rely on that (for instance, the fiscal year can start on any day during the ISO year, which means a new FiscalChronology).  Something like this:

```<code>public class FiscalDate implements Serializable {
    private final long epochDays;
    private final FiscalChronology chronology;

    // Many of the other 'date' instances also have a reference to their 'era':
    private final transient FiscalEra era;
}

public class FiscalChronology implements Serializable {
    // These two control year/month patterns.
    private final YearPattern yearPattern;
    private final MonthPattern monthPattern;
    // This should be derived during deserialization, for safety reasons.
    private transient final FiscalEra[] eras;

    private Object readResolve() {
        return FiscalChronology.create(yearPattern, monthPattern);
    }
}
</code>```

What do I do for the 'derived' era?

```<code>public class FiscalEra implements Serializable {
    // So that eras can be singletons, per JSR310 documentation/recommendations.
    private static final ConcurrentHashMap<FiscalChronology, FiscalEra[]>;

    private final int eraValue;
    private final FiscalChronology chronology;

    public static FiscalEra of(FiscalChronology chronology, int era) {
        return putIfAbsent(chronology, makeEras(chronology))[era];
    }
}
</code>```

Should I just remove serialization?  Only serialize eraValue (and rely on the serialization graph including the Chronology on its own)?

EDIT:

Related to this, what am I supposed to do for the output of toString() - should it just be the name of the era (which I'm linking to the ISO eras), and expect people to include chronology information if it's important, or always include information about the chronology?

答:
Maybe you can use XStream:

From their website it supports:

Full object graph support. Duplicate references encountered in the

  object-model will be maintained. Supports circular references.

Title: Dependent Object Serialization


问:
What's the right way to work with a graphic designer?
Recently, we worked with a graphic designer (arranged by the client) to provide the skin for a Django+Bootstrap application we had built. The designer provided a series of static images of the new layout, along with a document describing some technical attributes (font sizes, colours, a few dimensions etc).

It turned out to be incredibly time consuming to implement this. Although the whole site was basically a front page, an index page, and half a dozen detail pages, I spent at least 5 days just implementing the CSS and HTML changes. So I'll go out on a limb and call this The Wrong Way.

My basic approach was:

Compare the static image and current rendering, and notice a difference.

Guess what change would be need in the CSS/HTML

Make that change

Go to step 1.

Some of the particular issues were me not understanding that the design included a change from 8 columns to 12, some images provided in the wrong format (.png's can render differently on different browser/platform combinations), hassles trying to undo Bootstrap's styling, the usual CSS wrestling to achieve pixel perfect rendering etc. And occasionally I had to reorganise the HTML templates to get a certain behaviour.

What's the right way?

答:
I am facing a similar problem. i have the idea that tools like Greasemonkey or Tampermonkey can be used for that purpose. Just last week, i asked for comments about this idea: How to outsource the UI of a dynamic Web application?, but didn't get satisfactory responses.

With these tools you can inject CSS, HTML and Javascript to a page. In my idea, you give the URL of the working site to the designer and expect Greasemonkey scripts in return.  Theoretically you should be able to integrate those very quickly to the existing site. This way, it will be the designer's job to write the HTML and CSS and make the site actually work. This requires much more programming skills on the designer side though.

I know that this idea requires much elaboration. But I haven't tried that yet and don't know if anyone else is doing this. There may be some problems with the implementation.


问:
Static or non-static?
For example I have these two classes:

First

```<code>public class Example
{
    public Example()
    {
    }

    public int ReturnSomething
    {
      return 1;
    }
}
</code>```

Second

```<code>public class Example
    {
        public Example()
        {
        }

        public static int ReturnSomething
        {
          return 1;
        }
    }
</code>```

I want to use the ReturnSomething method, which of the two classes allocated less/more memory? When I use

```<code>int x = Example.ReturnSomething;
</code>```

or when I use

```<code>Example object = new Example();
int x = object.ReturnSomething();
</code>```

答:
If you don't use the object inside a method (i.e. you don't have this.), then make it static. In .NET Framework, for example, in order to be Code analysis compliant, you have to use static in this case (see rule CA1822: Mark members as static).

Also consider OOP in order for your code to be readable. Is the method inherent to the instance of the object? Is it more appropriate for class only, but not the instance? Is the method appropriate here in the first place?

Note: you're expected to write code for humans, not computers. Unless you work on embedded hardware, write your code with the consideration of readability, not memory consumption. If you're instead in a case where every byte of memory counts, profile the application to determine which of multiple ways of solving the problem matches the non-functional requirements related to memory consumption.

Title: Static or non-static?


问:
When would I require a Macro instead of a function?
I am new to Clojure, I am new to Macros and I have no prior background in Lisp.
I went on to create my own switch case like form and ended up with this:

```<code>(defmacro switch-case [v cases default] (if (cases v) (cases v) default ))
</code>```

and then tried making a function and ended up with this:

```<code>(defn fn-switch-case [v cases default] (if (cases v) (cases v) default ))
</code>```

Both

```<code>(switch-case 5 {6 "six" 7 "seven"} "not there")
</code>```

and

```<code>(fn-switch-case 5 {6 "six" 7 "seven"} "not there")
</code>```

Work fine.

What could be the scenario where I would need a macro and a function wont work ?
Is there a drawback in my function or macro implementations ?

答:
One benefit of macros is that they don't follow the same evaluation rules as functions, since they're just performing transformations on the code.

An example of a construct you couldn't create just by using functions is Clojure's threading macro.

It lets you insert an expression as the first argument in a sequence of forms:

```<code>(-> 5
  (+ 3)
  (* 4))
</code>```

is equivalent to

```<code>(* (+ 5 3) 4)
</code>```

You wouldn't be able to create this kind of construct using only functions, since before the -> expression was evaluated, the inner (+ 3) and (* 4) would be, meaning -> would receive

```<code>(-> 5
    3
    4)
</code>```

and it needs to see the actual functions being used in order to work.

In your example, consider if the result for some case were to have side-effects or call some other function. A function version would not be able to prevent that code from being run in a situation where that result is not picked, whereas a macro could prevent that code from being evaluated unless it is the option taken.

Body:
One benefit of macros is that they don't follow the same evaluation rules as functions, since they're just performing transformations on the code.

An example of a construct you couldn't create just by using functions is Clojure's threading macro.

It lets you insert an expression as the first argument in a sequence of forms:

(-> 5
  (+ 3)
  (* 4))

is equivalent to

(* (+ 5 3) 4)

You wouldn't be able to create this kind of construct using only functions, since before the -> expression was evaluated, the inner (+ 3) and (* 4) would be, meaning -> would receive

(-> 5
    3
    4)

and it needs to see the actual functions being used in order to work.

In your example, consider if the result for some case were to have side-effects or call some other function. A function version would not be able to prevent that code from being run in a situation where that result is not picked, whereas a macro could prevent that code from being evaluated unless it is the option taken.


答:
MainMa provided a great answer to your unspoken question ("Which option should I choose"), but, for completeness, I thought I'd answer your explicit question:

I want to use the ReturnSomething method, which of the two classes allocated less/more memory?

Your second option allocates a tiny bit more memory. 12 bytes, to be precise, if you are running an x86 application with .NET 4. However, your object will be garbage collected as needed (unless you actively do something to prevent that), so this becomes irrelevant in the long run (even on very memory-constrained devices).

Unless you have a very good reason for it, this tiny amount should not influence your decision. There are very good reasons to choose the static option, but this is not one of them.

Title: Static or non-static?

Body:
For example I have these two classes:

First

```<code>public class Example
{
    public Example()
    {
    }

    public int ReturnSomething
    {
      return 1;
    }
}
</code>```

Second

```<code>public class Example
    {
        public Example()
        {
        }

        public static int ReturnSomething
        {
          return 1;
        }
    }
</code>```

I want to use the ReturnSomething method, which of the two classes allocated less/more memory? When I use

```<code>int x = Example.ReturnSomething;
</code>```

or when I use

```<code>Example object = new Example();
int x = object.ReturnSomething();
</code>```


答:
I'm not sure there is a "right way", but a reasonably effective way of cooperating with a designer is to first build an unstyled system that uses templates and allows for the easy interchange of all templates. Then, once you have a functional-but-unstyled (or minimally styled) interface, you hand the results over to the designer for styling.

A decent example of this sort of design pattern would be jQueryUI (http://jqueryui.com/)

Title: What's the right way to work with a graphic designer?

Body:
Recently, we worked with a graphic designer (arranged by the client) to provide the skin for a Django+Bootstrap application we had built. The designer provided a series of static images of the new layout, along with a document describing some technical attributes (font sizes, colours, a few dimensions etc).

It turned out to be incredibly time consuming to implement this. Although the whole site was basically a front page, an index page, and half a dozen detail pages, I spent at least 5 days just implementing the CSS and HTML changes. So I'll go out on a limb and call this The Wrong Way.

My basic approach was:

Compare the static image and current rendering, and notice a difference.

Guess what change would be need in the CSS/HTML

Make that change

Go to step 1.

Some of the particular issues were me not understanding that the design included a change from 8 columns to 12, some images provided in the wrong format (.png's can render differently on different browser/platform combinations), hassles trying to undo Bootstrap's styling, the usual CSS wrestling to achieve pixel perfect rendering etc. And occasionally I had to reorganise the HTML templates to get a certain behaviour.

What's the right way?


问:
Is it allowed to make multiple instances of a singleton class?
I am confused when I read this (regarding singleton design pattern):

How do we ensure that a class has only one instance and that the instance is easily
  accessible? A global variable makes an object accessible, but it doesn't keep you from
  instantiating multiple objects.

So what is the use of singleton pattern if we can create multiple instances?

SOURCE:

Design Patterns - Elements Of Reusable Object Oriented Software (1995) - Gamma, Helm, Johnson, Vl

答:
In case of a singelton class. I can create multipe object by using Malloc.
For example:-

Singeltone* ptr = (Singeltone*) malloc(sizeof(Singeltone));


问:
Effective way to gain practical knowledge
I am currently nearing the end of my first year of my CS degree and have been disappointed with the lack of coding I have been asked to do (one unit).

I am basically looking for an effective way to gain practical knowledge but am unsure where to look for experience from a near beginner's perspective.

答: The one great thing about today's world is access to tonnes of resources over the internet and the fact that you can always get an expert to help you remotely using legitimate tailor made solutions that fit your budget and needs. So whether you're simply seeking help programming or a personal tutor to help you on your course work projects, all you need to know is the right place to go!!  </p>


答:
You approach the problem from the wrong direction - you ask for a general answer where there is none. The answer depends on a lot of details of the use case. Ask yourself:

what kind of data is managed by your exercise app?

does the user need the information about the associated records to make a decision about the deletion? Or can the system safely delete the associated records, and the additional information is of no value for the user?

what is the expected behaviour in case your user deletes the record accidentally? Can the data easily be restored?

shall any user have the right to delete those records and the associated records as well? Or can this cause further problems?

(... add more points like this by yourself)

Anyhow, it is good practice to ask such kind of questions before starting to code the deletion logic - if you did not ask before any of those questions, though your teacher gave you a chance to ask, he may rightfully question your solution.

Title: How to handle deleting record with associated records?

Body:
This is not a technical question but rather about the right logic on handling delete with foreign key constraint. In my exercise app, I cascaded the record with OneToMany relationship with other records. In other words when I delete the record, Hibernate will automatically delete the associated records.

My problem is, my teacher told me that cascading is not right. He said that the user must delete first the associated records and he didn't tell me the details and he is kinda angry when he told us. (I don't know what's his problem but I don't really mind. I just want to learn).

Please give me some advice because I cannot make up my mind. So far these are my thoughts:

1) After clicking delete, the system will tell the user that there are associated records and it will be deleted along if he continues. He will be then ask if he will continue.

2) After clicking delete, the system will tell the user that there are associated records and he can be redirected to a page or there is a pop-up that will show all the associated records and he can manually delete.

3) Don't allow the user to delete.


问:
RESTful API design. What should I return if there are no rows?
I'm currently coding an API for a social network with the Slim Framework. My question is: What are the best practices when there are no rows to return in the json structure?

Lets say that this call /v1/get/movies returns 2 rows from the table movie names:

```<code>[
    {"name": "Ghostbusters"},
    {"name": "Indiana Jones"}
]
</code>```

But, then I call /v1/get/books and there are no rows in that table. Should I just return an empty structure?

```<code>[
]
</code>```

...or would it be better a message and an error code?

```<code>[
    "errors": {
        "message": "no matches found",
        "code": 134
    }
]
</code>```

Which is a better practice? (the API will be used in iOS and Android apps) Thanks!

答:
The first thing to consider, since you are building a RESTful API, is to return an appropriate response code. And the more appropriate response code to communicate that the request went through normally, but the requested resource is not available at the moment is the venerable 404.

If you design your API in such a way that it always returns a sensible response code, you might not even need to return a body when the resource was not found. That said, returning a body, especially a humanly readable one, can't hurt.

There's no "best practice" here, both your examples are arbitrary, just pick one and be consistent. Developers hate surprises, if /v1/get/movies returns {} when there are no movies then we'd expect /v1/get/actors to also return {} when there are no actors.


答: I've seen both cases in production environments. Which one you choose depends on who will be using the API. If they want to know why the list is empty or to be sure that the list is really empty and no errors occurred while retrieving it, then you should attach an "errors" object. If they don't care, go with returning an empty list. I'd go with second approach since it covers more needs than the first.</p>

Title: RESTful API design. What should I return if there are no rows?

Body:
I'm currently coding an API for a social network with the Slim Framework. My question is: What are the best practices when there are no rows to return in the json structure?

Lets say that this call /v1/get/movies returns 2 rows from the table movie names:

```<code>[
    {"name": "Ghostbusters"},
    {"name": "Indiana Jones"}
]
</code>```

But, then I call /v1/get/books and there are no rows in that table. Should I just return an empty structure?

```<code>[
]
</code>```

...or would it be better a message and an error code?

```<code>[
    "errors": {
        "message": "no matches found",
        "code": 134
    }
]
</code>```

Which is a better practice? (the API will be used in iOS and Android apps) Thanks!


答:
Usually I would return number of records in result as metadata. I am not sure if that is normal REST practice, but it is not much extra data, and it is very precise.
Usually there is pagination for lots of services, it is impractical to return huge resultset at once. Personally I am annoyed when there is pagination for small result sets..
If it is empty, return number_of_records : 0 and books as empty list/array books : [].

```<code>{
    meta: {
        number_of_records : 2,
        records_per_page : 10,
        page : 0
    },
    books : [
        {id:1},
        {id:27}
    ]
}
</code>```

EDIT (few years later):
Answer from Martin Wickman is much better, here is "short" of explanation why.

When dealing with pagination always keep in mind possibility of contents or ordering changing. Like, first request comes, 24 results, you return first 10. After that, "new book" is inserted and now you have 25 results, but with original request it would come ordered in 10th place. When first user requests 2nd page, he would not get "new book". There are ways to handle such problems, like providing "request id" which should be sent with following API calls, then returning next page from "old" result set, which should be stored somehow and tied to "request id". Alternative is to add field like "result list changed since first request".

Generally, if you can, try to put extra effort and avoid pagination. Pagination is additional state which can be mutated and tracking such changes is error prone, even more so because both server and client need to handle it.

If you have too much data to process at once, consider returning "id list" with all results and details for some chunk of that list, and provide multi_get/get_by_id_list API calls for resource.

Body:
Usually I would return number of records in result as metadata. I am not sure if that is normal REST practice, but it is not much extra data, and it is very precise.
Usually there is pagination for lots of services, it is impractical to return huge resultset at once. Personally I am annoyed when there is pagination for small result sets..
If it is empty, return number_of_records : 0 and books as empty list/array books : [].

{
    meta: {
        number_of_records : 2,
        records_per_page : 10,
        page : 0
    },
    books : [
        {id:1},
        {id:27}
    ]
}

EDIT (few years later):
Answer from Martin Wickman is much better, here is "short" of explanation why.

When dealing with pagination always keep in mind possibility of contents or ordering changing. Like, first request comes, 24 results, you return first 10. After that, "new book" is inserted and now you have 25 results, but with original request it would come ordered in 10th place. When first user requests 2nd page, he would not get "new book". There are ways to handle such problems, like providing "request id" which should be sent with following API calls, then returning next page from "old" result set, which should be stored somehow and tied to "request id". Alternative is to add field like "result list changed since first request".

Generally, if you can, try to put extra effort and avoid pagination. Pagination is additional state which can be mutated and tracking such changes is error prone, even more so because both server and client need to handle it.

If you have too much data to process at once, consider returning "id list" with all results and details for some chunk of that list, and provide multi_get/get_by_id_list API calls for resource.


问:
Training old timey fortran programmers to better code design. hints?
I need to quickly train Fortran 90 developers into object oriented design, good coding, and general coding practices to make code maintenance easier and accessible to everybody. Their current style is the usual:

long routines that do too much

modules are aggregated in "family mode" (routines that have something to do with different kind of objects who share a common use are all in one module, instead of having different modules for different type)

huge globals module with hundreds of variables

general un-greppability of identifiers

This is just out of my head. I did a course to one of them explaining OO and modularization in terms of a Pen (with methods such as uncap(), and members like inkLevel) and I was very successful in diverting his point of view. I also gave him the exercise to code in OO style a very simple textual adventure, where the player can move around rooms. I also introduced the concept of patterns and antipatterns.

I would like to know any hints and suggestions on how to perform this task at best.

Thanks

答:
experienced procedural programmers - if they're good at it - have internalized models of code construction that tend towards object-orientation, but they don't realize it. The same way good database designers tend to create tables in third normal form, even if they've never heard of database normalization.

chances are the big ugly balls of mud you're seeing are ancient artifacts, laden with decades of technical debt and emergency changes.

when teaching OOP to procedural programmers (caveat: many years ago) I found that starting with what they know and what they think is good and building up from there into objects and classes makes it "click" much faster than lecturing on abstract concepts and coding talking animals.

example: a good function uses all of its parameters, and only its parameters. a good data structure contains only elements that are logically related to the 'key'. a good module typically centers on one data structure (or an aggregate) and contains the functions that produce, use, and consume the data structure.

remember that the habits these programmers have developed have served them well (as far as they know!) for a very long time; don't tell them that they need to 'forget all that and start over', that just breeds resentment. Tell them that everything they already know is still correct, it's just reorganized. Then show them how to reorganize it, then show them the benefits of the reorganization.

a useful exercise might be to have them code something simple but useful 'the old way', then walk through the refactoring that would make it work 'the new way'. The Socratic method (asking questions instead of showing them directly) is entirely appropriate for this kind of exercise.

good luck!


答:
If this is JSON, you should really consider returning an Array of objects. This has many advantages including that when you have no records it is an empty array.

So when you have records, you would be returning:

```<code>    [
        {"name": "Ghostbusters"},
        {"name": "Indiana Jones"}
    ]
</code>```

And when you have no records, you would be returning:

```<code>    [

    ]
</code>```

Body:
If this is JSON, you should really consider returning an Array of objects. This has many advantages including that when you have no records it is an empty array.

So when you have records, you would be returning:

    [
        {"name": "Ghostbusters"},
        {"name": "Indiana Jones"}
    ]

And when you have no records, you would be returning:

    [

    ]


答:
First, I have to admit that I never have worked with web front ends so far.

But I think it might be good practice for you and the designer to write prose of how the final design should look like. That way you can be more sure it is consistent, because it would smell if you were describing different tables for every page. Prose can make your implementation easier, because you are actually writing code, which is closer to your implementation than images.

Also try to make the designer focus on components, not whole pages. If you get the components of a page right, then composing them to the whole page is a much easier step.


问:
Is it worthwhile to create a knowledge map for software?
Basically, the objective is to create a visual representation of the software specification document. This visual representation would capture various scenarios involved in the software.

Benefits:

Picture speaks louder than words

Catch scenarios so that they need to be handled by the developer

Becomes a knowledge map for others

Can be used as a reference

Can be used for knowledge transfer as well.

Ideas:

If possible, we can dynamically modify the visual representation to add scenarios when
site issues are found and they were not identified initially.

I do not know how to do this. But I would like to invest time to find out how to do this.
But is it worth the effort?

答:
Well, I'm going to talk a little about my experience with AndroidRipper, perhaps it can help you.

When I was designing the general architecture for my thesis project, I had the idea while sitting on a bench. I only had paper and pen, so I sketched up a Class/Package Diagram (I'm not very strict about UML) the captured the barebones of the idea. Here's the very first draft BTW:

https://coderbits.com/posts/IZWhAg

The constraints of the medium helped me to focus on the pure functionality rather than how to implement it, so that in the end all the classes listed in that high level diagram ended up being abstract ones or interfaces.

The diagram could also be read data-flow schematic since (at the third or fourth attempt...) I drew the components so that you can follow how they interact with each other, in ordinary situations, going clock-wise. Each component is then moduled in its own class diagram (but these were made much later, on my PC) where extra ordinary situations and submodules are described in detail.

In my case, the software was supposed to be used by the software engineering department, therefore using UML made complete sense. If you map needs to be used by non-techies, then maybe a generic diagram is better suited.


答:
In my company, there are a few people specialized in this job.

They are designers. And they know HTML. They can be a bridge between the designers and the front-end engineers; which they usually are. This way, we just have to integrate their HTML.

This is a hard job. There's a reason sites like "PSD to HTML in 24h" work well. The solution in our company is to have people specialized in doing this. For us, working with the HTML is a breeze.

There's no silver bullet.


答:
Your example is broken. You shouldn't have json objects with duplicate keys. What you are looking for is an array with movie objects, like this:

```<code> [
    {"name": "movie1"},
    {"name": "movie2"}
 ]
</code>```

This approach also answers your question. You should return an empty array when the query does not match:

```<code>[]
</code>```

On the other hand, if you try to get a specific movie resource with GET api/movie/34 and that movie does not exist, then return 404 with a suitable (json encoded) error message in the body

Body:
Your example is broken. You shouldn't have json objects with duplicate keys. What you are looking for is an array with movie objects, like this:

 [
    {"name": "movie1"},
    {"name": "movie2"}
 ]

This approach also answers your question. You should return an empty array when the query does not match:

[]

On the other hand, if you try to get a specific movie resource with GET api/movie/34 and that movie does not exist, then return 404 with a suitable (json encoded) error message in the body


问:
What is the definition of "Big Data"?
Is there one?

All the definitions I can find describe the size, complexity / variety or velocity of the data.

Wikipedia's definition is the only one I've found with an actual number

Big data sizes are a constantly moving target, as of 2012 ranging from a few dozen terabytes to many petabytes of data in a single data set.

However, this seemingly contradicts the MIKE2.0 definition, referenced in the next paragraph, which indicates that "big" data can be small and that 100,000 sensors on an aircraft creating only 3GB of data could be considered big.

IBM despite saying that:

Big data is more simply than a matter of size.

have emphasised size in their definition.

O'Reilly has stressed "volume, velocity and variety" as well. Though explained well, and in more depth, the definition seems to be a re-hash of the others - or vice-versa of course.

I think that a Computer Weekly article title sums up a number of articles fairly well "What is big data and how can it be used to gain competitive advantage".

But ZDNet wins with the following from 2012:

“Big Data” is a catch phrase that has been bubbling up from the high
  performance computing niche of the IT market... If one sits through
  the presentations from ten suppliers of technology, fifteen or so
  different definitions are likely to come forward. Each definition, of
  course, tends to support the need for that supplier’s products and
  services. Imagine that.

Basically "big data" is "big" in some way shape or form.

What is "big"? Is it quantifiable at the current time?

If "big" is unquantifiable is there a definition that does not rely solely on generalities?

答:
Using Doug Laney's answer as a starting point, we reverse-engineered a list of Big Data definitions, now over 30 and going strong. Our list of definitions for "Big Data" is located here.

We welcome corrections, entries, graphics, etc.

Title: What is the definition of "Big Data"?


问:
What core skills does a new Computer Science Graduate need to be employable?
A computer science degree (like any undergraduate degree) does not prepare you to be productive immediately. And my sense is that employers are less and less willing to provide that initial training. (Or at least if you DO have those core skills*, you have a broader selection of "first jobs" to choose from).

What skills should a senior focus on to make him/her self more employable?
And how might you get those skills?

*EDIT: I'm not talking about experience/mastery of technology. I'm talking about core skills like Source Control (not mastery of a particular SC, but just being able to use one an understanding the concepts) and Unit Testing (having written Unit Tests using at least some famework), etc.

答:
When I interviewed people I always looked at which skills they learned outside of their studies and whether their hobbies/after-hour activities included things like programming or web design. I am not even interested in what specific programming they did, but rather that they show initiative to learn things outside of normal studies/work. Another good thing to show is involvement in the open source community for instance taking part in Open Source Sprints.

Look at skills that will be useful in any kind of environment - like being able to use: Bug trackers(bugzilla), version control(Subversion). Something people lack as well is the ability to write code that handles expected errors and stopping program for just ending with an unhandled exception, practise this.

Also depending on which business you want to go into there are some additional subjects that could be good to take, for instance Management and Finance subjects are soem good choices.


问:
What makes it hard to monetize browser extensions?
With the monetization of mobile apps being so popular, I'm surprised that extension developers are still mostly relying on donations as their primary form of compensation for their software.

While this is, of course, not a problem, I find myself wondering why browser extensions and plugins are generally exempt from monetization unlike plugins designed for software like Visual Studio and Photoshop are very often available only with purchase.

What makes broswer extensions different, and has anyone had any success charging for a browser extension?

Relevant: http://www.quora.com/Monetization/How-do-browser-extensions-monetize

答:
Another point, a lot of popular extensions are there to view content. And while the plugins to view this content are gratis, the programs to create this content are often not.

If you want to sell a lot of the content-creating software, you have to make sure that all the customers of your customers can view this content. That's why they don't charge for viewers.

ContentLicense: CC BY-SA 4.0