问:
Should a string constant be defined if it's only going to be used once?
We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application.

This is done by implementing classes which map strings (passed to us from Jaxen) into elements of our data model. We estimate we'll need around 100 classes with over 1000 string comparisons in total.

I think that the best way to do this is simple if/else statements with the strings written directly into the code — rather than defining each strings as a constant. For example:

```<code>public Object getNode(String name) {
    if ("name".equals(name)) {
        return contact.getFullName();
    } else if ("title".equals(name)) {
        return contact.getTitle();
    } else if ("first_name".equals(name)) {
        return contact.getFirstName();
    } else if ("last_name".equals(name)) {
        return contact.getLastName();
    ...
</code>```

However I was always taught that we should not embed string values directly into code, but create string constants instead. That would look something like this:

```<code>private static final String NAME = "name";
private static final String TITLE = "title";
private static final String FIRST_NAME = "first_name";
private static final String LAST_NAME = "last_name";

public Object getNode(String name) {
    if (NAME.equals(name)) {
        return contact.getFullName();
    } else if (TITLE.equals(name)) {
        return contact.getTitle();
    } else if (FIRST_NAME.equals(name)) {
        return contact.getFirstName();
    } else if (LAST_NAME.equals(name)) {
        return contact.getLastName();
    ...
</code>```

In this case I think it's a bad idea. The constant will only ever be used once, in the getNode() method. Using the strings directly is just as easy to read and understand as using constants, and saves us writing at least a thousand lines of code.

So is there any reason to define string constants for a single use? Or is it acceptable to use strings directly?

PS. Before anyone suggests using enums instead, we prototyped that but the enum conversion is 15 times slower than simple string comparison so it's not being considered.

Conclusion:
The answers below expanded the scope of this question beyond just string constants, so I have two conclusions:

It's probably OK to use the strings directly rather than string constants in this scenario, but

There are ways to avoid using strings at all, which might be better.

So I'm going to try the wrapper technique which avoids strings completely. Unfortunately we can't use the string switch statement because we're not on Java 7 yet. Ultimately, though, I think the best answer for us is to try each technique and evaluate its performance. The reality is that if one technique is clearly faster then we'll probably choose it regardless of its beauty or adherence to convention.

答: I would still use constants defined at the top of your classes. It makes your code more maintainable since it's easier to see what can be changed at a later time (if necessary). For instance, "first_name" could become "firstName" at some later time.


问:
Why isn't Java more widely used for game development?
I'm not a game developer or anything, but I know that Java is not very widely used for game development. Java should be fast enough for most games, so where's the catch? I can think of some reasons:

Lack of game developers with expertice in Java

Lack of good game development frameworks

Programmers don't want to accept Java as a games programming language. Most only accept C++ as that?

No support for game consoles (though the PC market still exists)

It could of course be something else. Could someone who knows the business better than me explain why Java isn't getting momentum when it comes to game development?

答:
The question is on par to asking something in the lines of:

What is better to power your car, a boat engine or jet engine.

It comes down to scalability, bug avoidance, speed, memory signature, modularity and a whole host of things. The question should not be be about what is better as an industry standard, the question should be "what is better for me" as in what you know or how well you know it. If it does the job then it does the job, if you can actually sell the idea then it works and who knows you might even bend a few spoons.

ContentLicense: CC BY-SA 2.5

ContentLicense: CC BY-SA 3.0


问:
Recommendations for teaching junior programmers good coding style
I am a big fan of good coding style, producing clean, clear code that runs well and is easy to use and integrate into larger systems. I believe that we programmers are essentially craftspeople who should take pride in our work, every line. I am not fond of code that is inconsistently formatted, cluttered with commented out experimental code, and rife with unhelpful or misleading function and variable names. But I sometimes find it hard to argue with code like this that basically works.

If you think that coding style matters, I am looking for recommendations for ways of teaching good, professional coding style to the junior programmers under me. I want them to take pride in their work, but my concern is that they appear to become satisfied when their code just barely works, and seem to have no interest in producing what professionals like me would consider professional code. On the other hand, if you think coding style is not particularly valuable, I welcome your comments and am open to reconsidering my standards and tolerances.

I know the usual arguments in favor of good code: comprehensibility, ease of maintenance, etc., but I would also like to hear some rebuttals to arguments like "it works, what more do you want?"

In our industry we can use the compiler to hide a multitude of sins. Clean code and messy code can both lead to identically functioning programs, so does cleanliness matter, and if so, why?

[While there are several existing questions on coding style, I didn't find any that related to teaching methods and ways to instill good coding style in junior programmers.]

答:
I first learned programming by being handed a well written program and lead through it line by line.  (I learned a lot in those couple of hours that I didn't get in my entire degree program.)  Try the same with them, walking them through one of your best modules pointing out how and why it is constructed and styled that way.  You can do this in a group session.

If you can, play benevolent dictator.  Depending on your revision control system you may be able to use it to help you.  However, you could end up being the bottleneck in the development process.

Deploy an automated style checker to verify as many styling rules as you can.  (Many checkstyle rules should be portable between Java and C++.)  This will get you part way there, but will not substitute for code reviews.  Getting your developers to peer review code may help reduce the load.

If you are implement an automated style checker, you may also want to implement a static code analysis tool.  This should help eliminate some of the bugs than may be missed in code reviews.  It will also enable you to concentrate on stylistic issues rather looking for the errors the static code analysis tool covers.  There may still be common cases that need to be checked for.

Develop a checklist for developers to use before checking in the code.  This can contain other things you want to occur before check-in.  There is growing evidence that checklists can help reduce errors.  Encourage developers to build their own check list of mistakes they commonly make, so that they can avoid repeating them.


问:
I target short projects, but fail miserably on projects that requires persistence
I know this is kind of time-management question. I do well in short assignments, but fail miserably, when it comes to projects that require hours and hours of work to be done day after day.

I cannot code more than 10 minutes, unless there is a deadline. I kinda wander and come back and code. It takes me ridiculously large amount of time even for simple project. I kinda lack persistence. I have my thesis coming up in December. The more time I spend, the better my publication will be.

I was wondering, may be I could get some help on how to code persistently?

I just get out of my chair and start doing other things, when I see a bug or when I have a module that requires thinking and it takes me long time to come back sit and put my thought back to the code.

Any advice on how to improve my persistent coding skills?

答:
How is your project planning? In the past, I've had significant personal projects fall apart because I would get lost in the complexity of a project as its implementation details began to unwind beyond my initial expectations. As things would get messier, I would get frustrated and then sloppy as a result, eventually resulting in a horrible mess of code that would subconsciously encourage me to procrastinate (for fear of untangling the mess) until a fresh new idea piqued my interest.

Better planning really helps. Some prefer formal specifications like UML diagrams while others prefer to create an informal model of their application. Either way, with a project specification it becomes easy to remain productive when you hit roadblocks as you're able to quickly transition to an easier or  exciting part of the project (while being assured that it is necessary work). When it comes time to return to your old problem, you know exactly which portion of the project you should return to and if your roadblock eventually leads you to rebuild a section of your application, your specification will guide you through a more efficient refactoring process.


答: If you're going to maintain this (make any sort of nontrivial changes ever), I might actually consider using either some sort of annotation-driven code generation (perhaps via CGLib) or even just a script that writes all the code for you.  Imagine the number of typos and errors that could creep in with the approach you're considering...</p>

Title: Should a string constant be defined if it's only going to be used once?

Body:
We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application.

This is done by implementing classes which map strings (passed to us from Jaxen) into elements of our data model. We estimate we'll need around 100 classes with over 1000 string comparisons in total.

I think that the best way to do this is simple if/else statements with the strings written directly into the code — rather than defining each strings as a constant. For example:

```<code>public Object getNode(String name) {
    if ("name".equals(name)) {
        return contact.getFullName();
    } else if ("title".equals(name)) {
        return contact.getTitle();
    } else if ("first_name".equals(name)) {
        return contact.getFirstName();
    } else if ("last_name".equals(name)) {
        return contact.getLastName();
    ...
</code>```

However I was always taught that we should not embed string values directly into code, but create string constants instead. That would look something like this:

```<code>private static final String NAME = "name";
private static final String TITLE = "title";
private static final String FIRST_NAME = "first_name";
private static final String LAST_NAME = "last_name";

public Object getNode(String name) {
    if (NAME.equals(name)) {
        return contact.getFullName();
    } else if (TITLE.equals(name)) {
        return contact.getTitle();
    } else if (FIRST_NAME.equals(name)) {
        return contact.getFirstName();
    } else if (LAST_NAME.equals(name)) {
        return contact.getLastName();
    ...
</code>```

In this case I think it's a bad idea. The constant will only ever be used once, in the getNode() method. Using the strings directly is just as easy to read and understand as using constants, and saves us writing at least a thousand lines of code.

So is there any reason to define string constants for a single use? Or is it acceptable to use strings directly?

PS. Before anyone suggests using enums instead, we prototyped that but the enum conversion is 15 times slower than simple string comparison so it's not being considered.

Conclusion:
The answers below expanded the scope of this question beyond just string constants, so I have two conclusions:

It's probably OK to use the strings directly rather than string constants in this scenario, but

There are ways to avoid using strings at all, which might be better.

So I'm going to try the wrapper technique which avoids strings completely. Unfortunately we can't use the string switch statement because we're not on Java 7 yet. Ultimately, though, I think the best answer for us is to try each technique and evaluate its performance. The reality is that if one technique is clearly faster then we'll probably choose it regardless of its beauty or adherence to convention.


问:
Biggest mistake you've ever made
Similar to the question I read on Server Fault, what is the biggest mistake you've ever made in an IT related position. Some examples from friends:

I needed to do some work on a production site so I decided to copy over the live database to the beta site. Pretty standard, but when I went to the beta site it was still pulling out-of-date info. OOPS! I had copied the beta database over to the live site! Thank god for backups.

And for me, I created a form for an event that was to be held during a specific time range. Participants would fill out the form for a chance to win, and we would send the event organizers a CSV from the database. I went into the database, and found ONLY 1 ENTRY, MINE. Upon investigating, it appears as though I forgot an auto increment key, and because of the server setup there was no way to recover the lost data.

I am aware this question is similar to ones on Stack Overflow but the ones I found seemed to receive generic answers instead of actual stories :)

What is the biggest coding error/mistake ever…

答: My biggest mistake was to think that programming is easy money...</p>

Title: Biggest mistake you've ever made


问:
Has whitespace in identifiers ever been idiomatic?
C# style suggests using CamelCase in identifiers to delimit words. Lisp tradition suggests using-dashes-instead.

Has there ever existed a programming language where using spaces in identifiers was not only allowed, but a commonly used idiom when employing multi-word identifiers?

It's possible to have identifiers with spaces in some Scheme implementations, but it's not a widely seen practice. Here's an example:

```<code>Petite Chez Scheme Version 8.4
Copyright (c) 1985-2011 Cadence Research Systems

> (define |hey there| 100)
> (define |x y z| 200)
> (list |hey there| |x y z|)
(100 200)
</code>```

答:
Well Whitespace is all about... whitespace:

Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren't there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.

Unfortunately Markdown doesn't support its syntax and I can't show you some code, but Wikipedia has a human friendly code sample.


答:
Edit: This answer was shown to be not correct, see the comments.

If I understand your question correctly, a compiler can't allow space(s) in identifier name because it could cause duplicate names (unless a delimiter is used). For example:

int my=0;
bool my count=false;
int count=0;
if (my Count)...

the term 'my count' is confusing it could either refer to the variable called 'my count' or maybe the developer forgot to write a relation operator such as > between my and count.

COBOL allowed division names and section names to be separated by space but those are not identifiers and variables as in your question.

Title: Has whitespace in identifiers ever been idiomatic?

Body:
C# style suggests using CamelCase in identifiers to delimit words. Lisp tradition suggests using-dashes-instead.

Has there ever existed a programming language where using spaces in identifiers was not only allowed, but a commonly used idiom when employing multi-word identifiers?

It's possible to have identifiers with spaces in some Scheme implementations, but it's not a widely seen practice. Here's an example:

```<code>Petite Chez Scheme Version 8.4
Copyright (c) 1985-2011 Cadence Research Systems

> (define |hey there| 100)
> (define |x y z| 200)
> (list |hey there| |x y z|)
(100 200)
</code>```


答:
Does SQL count?</p>

```<code>create table "Registered Members" (
    "Full Name" varchar(100),
    "Mailing Address" varchar(100),
    etc...
);
</code>```

Body:
Does SQL count?

create table "Registered Members" (
    "Full Name" varchar(100),
    "Mailing Address" varchar(100),
    etc...
);


答: Your school surely has a counseling center -- take advantage of it. Whether it's time management, procrastination, or something else, it's still a real problem for you, and the folks at the counseling center will help you deal with it. They're there to help you, and you're certainly not the first student they've seen with a problem like this. Don't put it off (no joke), stop in  as soon as you can and arrange to talk to someone.</p>

Title: I target short projects, but fail miserably on projects that requires persistence

Body:
I know this is kind of time-management question. I do well in short assignments, but fail miserably, when it comes to projects that require hours and hours of work to be done day after day.

I cannot code more than 10 minutes, unless there is a deadline. I kinda wander and come back and code. It takes me ridiculously large amount of time even for simple project. I kinda lack persistence. I have my thesis coming up in December. The more time I spend, the better my publication will be.

I was wondering, may be I could get some help on how to code persistently?

I just get out of my chair and start doing other things, when I see a bug or when I have a module that requires thinking and it takes me long time to come back sit and put my thought back to the code.

Any advice on how to improve my persistent coding skills?


答:
FORTRAN compilers ignored spaces so:

```<code>   result = value * factor
   r e s u l t = val ue * fac tor
   result=value*factor
</code>```

were identical as far as the compiler was concerned.

Some SQL dialects allow embedded spaces in column names but they need to be surrounded by backquotes or some other delimiter before they can be used.

Body:
FORTRAN compilers ignored spaces so:

   result = value * factor
   r e s u l t = val ue * fac tor
   result=value*factor

were identical as far as the compiler was concerned.

Some SQL dialects allow embedded spaces in column names but they need to be surrounded by backquotes or some other delimiter before they can be used.

ContentLicense: CC BY-SA 4.0


问:
Freelancing - Share the source code?

Possible Duplicate:

Hand over source code to customer

I have developed a couple of form based windows application in vb.net for a client and they all work well and he paid me through a freelance site. I have handed over the executable and the setup to the client and all was well. Now the client wants the source code for the application. Is there a general practice on sharing the source code with the client?

Please note - the client never mentioned he needs the source code and he is now asking for it after a week after the app was completed and he made the payment.

I don't mind sharing the source code, but I am not sure if I should. This probably means the client would not hire me again and the bigger question is the source code really his property?

This question may have been asked a few times, but I cannot still draw a conclusion on what is right.

update

To answer some of the questions:

The source code was not mentioned at all. There was no exclusive contract signed except for the usual agreement of the freelance site.

I am not sure if software development comes under work for hire and is it valid for users outside of the US?

The reason for not sharing the source code was this was a very small project and I got paid for a mere few hours. So if I have an option then definitely I would want to keep the source code to myself as that gives a possibility of the client coming back. The application works flawlessly and the code is solid. Also, the task that the client wanted to achieve was very challenging and I would not like other programmers (competitors) to know how I achieved it.

So unless I get the confirmation that the source code is purely the property of the client, I would not be willing to share it.

答:
This probably means the client would not hire me again...

Why? Do you think they won't hire you because of the poor quality of the code, or do you think that once they've got the code they don't need you anymore?

If the code is lousy, consider this a lesson learned and do a better job next time. On the other hand, if the code is solid, why wouldn't they want to work with you again? They may want to add features to whatever you did, and who better to do that than the guy who wrote the code in the first place? Or they may have other projects in the works, and the happier they are with your work the more likely they'll be to want to keep working with you.

BTW, I agree with the other two posts. I'm no lawyer, but it sounds like this was a straight work for hire arrangement, and that usually means that the code is theirs.

Title: Freelancing - Share the source code?


答:
You might consider this to be the case in Cucumber/Gherkin, where function names are effectively sentences with the arguments embedded inside them.

As an extension, I would expect this to be more common in tiny DSLs, where the language is supposed to be friendly to non developers. For example, many rules engines provide an abilty to define rules with an english-like description, where spaces can be used in identifiers.


问:
How should the cppcms template hierarchy be used
I understand that the hierarchy, in cppcms for templates, goes skin (topmost, representing a namespace), then view (representing a class) and finally template (representing a function).

I want to know when I should use a skin and when I should use a view; would each page be a skin or would it be a skin per application, etc.

Could you explain when each should be used and could you give some examples?

答:
Read these tutorials carefuly:

http://cppcms.com/wikipp/en/page/cppcms_1x_templates_gen

http://cppcms.com/wikipp/en/page/cppcms_1x_tut_templates_inheritance

They cover the topic.

I want to know when I should use a skin and when I should use a view; would each page be a skin or would it be a skin per application, etc.

Almost always you would use views... Skins are for "skinning" purposes or for totally
separate units like for example "general pages" and "administrator interface" that
share almost nothing - and it is yet non-mandatory.


答:
I don't know if you consider MediaWiki wikitext a language, but names with spaces are definitely idiomatic:

```<code>==Example==
This example lacks text.
{{Expand section}}
</code>```

Where "expand section" is the name of a template (http://en.wikipedia.org/wiki/Template:Expand_section)

I guess it meets the criteria - a language where identifiers routinely contain spaces. It's never (I think?) ambiguous because identifiers are always surrounded by lots of punctuation to separate them from raw wiki text.

Body:
I don't know if you consider MediaWiki wikitext a language, but names with spaces are definitely idiomatic:

==Example==
This example lacks text.
{{Expand section}}

Where "expand section" is the name of a template (http://en.wikipedia.org/wiki/Template:Expand_section)

I guess it meets the criteria - a language where identifiers routinely contain spaces. It's never (I think?) ambiguous because identifiers are always surrounded by lots of punctuation to separate them from raw wiki text.


问:
Floyd's algorithm
Is it possible(expected) for an individual to figure out(having never seen it before) the algorithm if asked at an interview? What other problems have equally interesting solutions?

Edit: Due to the confusion of the actual algorithm I am referring to, it is the
Floyd's cycle-finding algorithm, aka, tortoise and hare algorithm.

答:
As this is an interview question, you always have to ask yourself the most important question first:

What can a potential employer expect from a typical candidate and how can I do better?

Obviously, almost no one (and certainly not a prototypical candidate) will be able to perform work that took brilliant scientists years within the time constraints of an interview. So that is not what they expect from you.

What else could the employer expect?

You may already know the algorithm. This is simple and boring. You can just tell so and most likely the topic will be switched, because there is not much more to be learnt about yourself (from the point of view of the employer).

You may not know the algorithm. This is actually the typical candidate's state to be in, and if that is expected, what should the result be? Consider the company's perspective here and you will find that it is most likely not a good thing if a candidate is unable to state the obvious: I do not know this algorithm. If you start giving vague sentences and talk around the real issue here, then you will give a bad impression. So the primary purpose of asking such a question is not to expect you to be able to answer it, but to test your reaction when encountering things you do not know.

You may not know the algorithm, but... to come back to the original question above: how can you do better? You may know similar algorithms, so do explain the similarities you recognize (for example, Floyd's Tortoise+Hare algorithm uses a similar approach as the Polard-Rho-Algorithm). You may have impressive code-reading/understanding skills, etc.. Of course, this part is the hardest, but then again, it's only available if you actually are better than the average candidate, which by definition makes it kind of easier.

Title: Floyd's algorithm


答: Smalltalk features keyword methods such as a:b:c: which involve whitespace when invoked. E.g.: a: 100 b: 200 c: 300. This is a standard idiom in the language.


答: If your naming is consistent (aka "some_whatever" is always mapped to getSomeWhatever()) you could use reflection to determine and execute the get method.


答:
If at all possible use Java 7 which allows you to use Strings in switch statements.

From http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

```<code>public class StringSwitchDemo {

    public static int getMonthNumber(String month) {

        int monthNumber = 0;

        if (month == null) {
            return monthNumber;
        }

        switch (month.toLowerCase()) {
            case "january":
                monthNumber = 1;
                break;
            case "february":
                monthNumber = 2;
                break;
            case "march":
                monthNumber = 3;
                break;
            case "april":
                monthNumber = 4;
                break;
            case "may":
                monthNumber = 5;
                break;
            case "june":
                monthNumber = 6;
                break;
            case "july":
                monthNumber = 7;
                break;
            case "august":
                monthNumber = 8;
                break;
            case "september":
                monthNumber = 9;
                break;
            case "october":
                monthNumber = 10;
                break;
            case "november":
                monthNumber = 11;
                break;
            case "december":
                monthNumber = 12;
                break;
            default:
                monthNumber = 0;
                break;
        }

        return monthNumber;
    }

    public static void main(String[] args) {

        String month = "August";

        int returnedMonthNumber =
            StringSwitchDemo.getMonthNumber(month);

        if (returnedMonthNumber == 0) {
            System.out.println("Invalid month");
        } else {
            System.out.println(returnedMonthNumber);
        }
    }
}
</code>```

I have not measured, but I believe that the switch statements compile to a jump table instead of a long list of comparisons.  This should be even faster.

Regarding your actual question:  If you only use it once you do not need to make it into a constant.  Consider however that a constant can be documented and shows up in Javadoc.  This may be important for non-trivial string values.

Body:
If at all possible use Java 7 which allows you to use Strings in switch statements.

From http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

public class StringSwitchDemo {

    public static int getMonthNumber(String month) {

        int monthNumber = 0;

        if (month == null) {
            return monthNumber;
        }

        switch (month.toLowerCase()) {
            case "january":
                monthNumber = 1;
                break;
            case "february":
                monthNumber = 2;
                break;
            case "march":
                monthNumber = 3;
                break;
            case "april":
                monthNumber = 4;
                break;
            case "may":
                monthNumber = 5;
                break;
            case "june":
                monthNumber = 6;
                break;
            case "july":
                monthNumber = 7;
                break;
            case "august":
                monthNumber = 8;
                break;
            case "september":
                monthNumber = 9;
                break;
            case "october":
                monthNumber = 10;
                break;
            case "november":
                monthNumber = 11;
                break;
            case "december":
                monthNumber = 12;
                break;
            default:
                monthNumber = 0;
                break;
        }

        return monthNumber;
    }

    public static void main(String[] args) {

        String month = "August";

        int returnedMonthNumber =
            StringSwitchDemo.getMonthNumber(month);

        if (returnedMonthNumber == 0) {
            System.out.println("Invalid month");
        } else {
            System.out.println(returnedMonthNumber);
        }
    }
}

I have not measured, but I believe that the switch statements compile to a jump table instead of a long list of comparisons.  This should be even faster.

Regarding your actual question:  If you only use it once you do not need to make it into a constant.  Consider however that a constant can be documented and shows up in Javadoc.  This may be important for non-trivial string values.


问:
How to log configuration or code behaviour changes in non-disruptive way
We've probably all been in the situation where you'd like to alert your team members to some change ("I changed X, so now it's running every hour instead of every day"). But the change is non-urgent, and email can be disruptive - or get tuned out.

Anyone have any techniques where the team can have a running log of changes that everyone should be aware of, that they can peruse at their leisure - or at least, when they suspect something is up?

答:
If your team find email disruptive or tune it out, something is wrong (they've set their notifications to be too in-your-face, or they're getting too many private emails, or they haven't set up filters/triggers properly). Email is, in my opinion, the perfect tool for this. Set it up right and it will serve its purpose.

You could do something silly and complicated, like use a wiki page, set up an RSS feed specifically for this, or give the team a freakin' twitter account, but when you stop and think about it, email can already do what you want.


答:
In Algol 68 you could have space in identifiers (I don't remember if they were significant or not). But keywords were marked by stropping. Using names with space in them was idiomatic (at least around me).

VHDL allows escaped identifiers with significant spaces in them: \foo bar\. This allows also to use keywords as identifier \and\, any character \n<42>\ and case sensitivity in identifiers (\Foo\ and \foo\ are different while Foo and foo are equivalent, and different from either \Foo\ and \foo\!). Verilog also has espaced identifiers with most of these characteristics (normal identifiers are case sensitive and escaping them unnecessarily doesn't make another identifier), but doesn't allow spaces in them.  The need from escaped identifiers in VHDL and Verilog come from the fact they are often produced automatically from other sources (such as schematic) where identifiers customarily don't have the same restriction as in programming language; AFAIK, they aren't idiomatically used in other circumstances.


问:
Are code reviews necessary for junior developers?
I've worked at two companies, who each had a different methodology when it came to code reviews:

In the first company, a code review was conducted by the team leaders and was required after the completion of every module.

However, in the second company, team leaders weren't required to conduct any code reviews, and just checked for functionality and design issues.

So I am confused. Is the code review process really needed? If it is, why? And if it isn't, why not?

答:
I work in a place where code review is now a requirement but was not as little as 3 years ago. It has made a huge improvement in in our code and in the ability of others to maintain the code later. Even senior, very experienced developers make mistakes which can easily and quietly be fixed in code review before QA finds them or worse before the customer finds them. Further at least one person other than the orginal developer is familar with the code.

Often when an organization tries something new to it, as we did with code review, there is much resistance to change. I have seen almost none of that (we were estatic to get a formal QA department too.) with code review. It pretty much takes only one or two reviews to see the value.

I have found new techniques I had not considered both in doing a code review of someone else's work or in having my code reviewed. We have found competence problems with new hires relatively quickly by having code reviews and more importantly by how they responded to the code review.  We have learned what things that seem perfectly clear right now in the thick of programming that section that will not be clear in maintenance. This is invaluable. It may be that the only thing needed is a comment as to why something was done. We have found some fundamental misunderstandings about our database design that needed to be corrected for a report to actually have the correct information.

Often what I have seen in a code review is that, by the very act of explaining something to someone else, the developer will have a lightbulb turn on in his head and realize that there is a bug the reviewer didn't see.

And boy can code review identify those cowboy programmers who won't follow any standard or use mandated tools and whose code will be nigh onto unmaintainable by anyone else. And it can force them to get with the program or get out too.

The people most resistant to code review are often the people the organization most needs to get rid of because they know in their hearts their code can't pass a code review.


问:
Is there a semi-scientific term for this filtering behavior?
I'm looking for the term that applies to a certain kind of filtering behavior. It's often used in webshop-like interfaces, where large amounts of data are filtered based on a selection of filter criteria. The most distinguishing feature is that it's impossible to pick a filter criterium that leads to no results, as the filters that would do so are hidden with real-time updates.

To see an example look at this boot finder section on the blue-tomato.com webshop.

Is there a term for this kind of filtering?

答: Your description reminds me of Faceted search. This is a way users can interact and refine a possibly huge set of search results in an intuitive way. You might have seen it on library websites. Your point about "impossible to pick a filter criterium that leads to no results" is fulfilled because the facets are facets of the properties of the search items. Thus there is always at least one item fulfilling the search criterion.</p>


答:
The query model is called BMO (best matches only) and avoids empty result sets by returning the best matches instead of the perfect matches. This can be achieved by defining a strict partial order over the data you have.

This implies that in case you have zero "hard" matches, all data is returned because the best possible result is the one that is the lowest in your strict partial order. So in practical applications you will combine soft constraints with hard ones to assure that at least some relevant results will be returned.

You can find an introductory paper here.

Title: Is there a semi-scientific term for this filtering behavior?

Body:
I'm looking for the term that applies to a certain kind of filtering behavior. It's often used in webshop-like interfaces, where large amounts of data are filtered based on a selection of filter criteria. The most distinguishing feature is that it's impossible to pick a filter criterium that leads to no results, as the filters that would do so are hidden with real-time updates.

To see an example look at this boot finder section on the blue-tomato.com webshop.

Is there a term for this kind of filtering?


问:
Subrepositories (submodules) as a dependency tracking solution - yes or no?
What do you think about SCM-based (subrepositories in mercurial, submodules in git) dependencies management?

Is it definitely a good way of managing dependencies? Or definitely bad way?

Should I prefer some build system (ant/phing/rake) over subrepositories?

Some particular example for you to have a context:

I have several web applications that share across reusable components, say jquery plugins.

答:
If you have the option, then go with a dedicated tool instead of using the SCM for this. I've written about this on SO, but the argument boils down to coupling, in particular overly tight coupling. Flexible software development is all about avoiding tight coupling unless it's really needed and both Mercurial subrepositories and Git submodules introduce a very tight coupling.

In addition, subrepos/submodules introduce extra complexity in the daily workflow. If people are already familiar with the SCM, then this might be acceptable. But I've seen many organizations where they tries to introduce Mercurial and subrepos at the same time — I consider that a mistake since it just makes everything seem extra complicated.

The Mercurial wiki has a set of recommendations for how subrepos should be used. These include the use of a thin shell repository. This avoids coupling the components together. You can work in either subrepo as needed and push/pull to update them. Once in a while someone (maybe a build engineer, maybe a continuous integration server) will test new configurations of the components. If they pass tests, then a new commit is made in the shell repository so that people have a new base to use for their work.


答:
Try this.  The initial reflection is certainly expensive, but if you're going to use it many many times, which I think you will, this is most certainly a better solution what what you're proposing.  I don't like using reflection, but I find myself using it when I don't like the alternative to reflection.  I do think that this will save your team a lot of headache, but you must pass the name of the method (in lowercase).

In other words, rather than pass "name", you would pass "fullname" because the name of the get method is "getFullName()".

```<code>Map<String, Method> methodMapping = null;

public Object getNode(String name) {
    Map<String, Method> methods = getMethodMapping(contact.getClass());
    return methods.get(name).invoke(contact);
}

public Map<String, Method> getMethodMapping(Class<?> contact) {
    if(methodMapping == null) {
        Map<String, Method> mapping = new HashMap<String, Method>();
        Method[] methods = contact.getDeclaredMethods();
        for(Method method : methods) {
            if(method.getParameterTypes().length() == 0) {
                if(method.getName().startsWith("get")) {
                    mapping.put(method.getName().substring(3).toLower(), method);
                } else if (method.getName().startsWith("is"))) {
                    mapping.put(method.getName().substring(2).toLower(), method);
                }
            }
        }
        methodMapping = mapping;
    }
    return methodMapping;
}
</code>```

If you need to access data contained within members of contact, you might consider building a wrapper class for contact which has all methods to access any information required.  This would also be useful for guaranteeing that the names of the access fields will always remain the same (I.e. if wrapper class has getFullName() and you call with fullname, it will always work even if contact's getFullName() has been renamed -- it would cause compilation error before it would let you do that).

```<code>public class ContactWrapper {
    private Contact contact;

    public ContactWrapper(Contact contact) {
        this.contact = contact;
    }

    public String getFullName() {
        return contact.getFullName();
    }
    ...
}
</code>```

This solution has saved me several times, namely when I wanted to have a single data representation to use in jsf datatables and when that data needed to be exported into a report using jasper (which doesn't handle complicated object accessors well in my experience).

Body:
Try this.  The initial reflection is certainly expensive, but if you're going to use it many many times, which I think you will, this is most certainly a better solution what what you're proposing.  I don't like using reflection, but I find myself using it when I don't like the alternative to reflection.  I do think that this will save your team a lot of headache, but you must pass the name of the method (in lowercase).

In other words, rather than pass "name", you would pass "fullname" because the name of the get method is "getFullName()".

Map<String, Method> methodMapping = null;

public Object getNode(String name) {
    Map<String, Method> methods = getMethodMapping(contact.getClass());
    return methods.get(name).invoke(contact);
}

public Map<String, Method> getMethodMapping(Class<?> contact) {
    if(methodMapping == null) {
        Map<String, Method> mapping = new HashMap<String, Method>();
        Method[] methods = contact.getDeclaredMethods();
        for(Method method : methods) {
            if(method.getParameterTypes().length() == 0) {
                if(method.getName().startsWith("get")) {
                    mapping.put(method.getName().substring(3).toLower(), method);
                } else if (method.getName().startsWith("is"))) {
                    mapping.put(method.getName().substring(2).toLower(), method);
                }
            }
        }
        methodMapping = mapping;
    }
    return methodMapping;
}

If you need to access data contained within members of contact, you might consider building a wrapper class for contact which has all methods to access any information required.  This would also be useful for guaranteeing that the names of the access fields will always remain the same (I.e. if wrapper class has getFullName() and you call with fullname, it will always work even if contact's getFullName() has been renamed -- it would cause compilation error before it would let you do that).

public class ContactWrapper {
    private Contact contact;

    public ContactWrapper(Contact contact) {
        this.contact = contact;
    }

    public String getFullName() {
        return contact.getFullName();
    }
    ...
}

This solution has saved me several times, namely when I wanted to have a single data representation to use in jsf datatables and when that data needed to be exported into a report using jasper (which doesn't handle complicated object accessors well in my experience).


答:
what about adding a textfile "compatibility_issues.txt" where configuration or code behaviour changes are added together with version/datetime info and add this file to the sourcecode-repository. This way the issues don-t get lost and you can find out the source-code fragments that are related to the changes through sourcecode-repository history.

however i would also keep emailing these issues.

Do you have a naming convention for these emails. If i as a developper am not intrerested in this "compatibility-change-spam" i can setup an email-filter for this.

Title: How to log configuration or code behaviour changes in non-disruptive way

Body:
We've probably all been in the situation where you'd like to alert your team members to some change ("I changed X, so now it's running every hour instead of every day"). But the change is non-urgent, and email can be disruptive - or get tuned out.

Anyone have any techniques where the team can have a running log of changes that everyone should be aware of, that they can peruse at their leisure - or at least, when they suspect something is up?


问:
Finding right bug tracker web application
I'm looking for a bug tracking system (similiar as http://www.mantisbt.org) with these following requirements:

Requirement specifications are:

Upload picture and different files without any limitaton of the file's space.

If user belong to a specific group or businesss group, the GUI:s logotype should be changed into group's logotype after the user has entered user name and password. All user use the same database with different GUI.

Right information of unassigned, modified and resolved bug case will be displayed based on what group or business group that the user is assigned to.

All information will display after the user has logged in.

Enable to create 1 or more super user (administrator) and regular user.

Right user with right group or business group will retrieve right information.

Non functional requirement:

The bugging tracker take place in a webbapplication.

All information must use web browser to view all information.

答:
You did not mention whether you are looking for an open source or proprietary solution. Check out Issue Tracking Anywhere if you like. All features are supported except the changing logo on a per-user group basis one. It's free for the first 15 users.

Disclaimer: I am with the company which produces the product.


问:
Advantages and disadvantages of building a single page web application
I'm nearing the end of a prototyping/proof of concept phase for a side project I'm working on, and trying to decide on some larger scale application design decisions.  The app is a project management system tailored more towards the agile development process.  One of the decisions I need to make is whether or not to go with a traditional multi-page application or a single page application.

Currently my prototype is a traditional multi-page setup, however I have been looking at backbone.js to clean up and apply some structure to my Javascript (jQuery) code.  It seems like while backbone.js can be used in multi-page applications, it shines more with single page applications.  I am trying to come up with a list of advantages and disadvantages of using a single page application design approach.  So far I have:

Advantages

All data has to be available via some sort of API - this is a big advantage for my use case as I want to have an API to my application anyway. Right now about 60-70% of my calls to get/update data are done through a REST API.  Doing a single page application will allow me to better test my REST API since the application itself will use it.  It also means that as the application grows, the API itself will grow since that is what the application uses; no need to maintain the API as an add-on to the application.

More responsive application - since all data loaded after the initial page is kept to a minimum and transmitted in a compact format (like JSON), data requests should generally be faster, and the server will do slightly less processing.

Disadvantages

Duplication of code - for example, model code.  I am going to have to create models both on the server side (PHP in this case) and the client side in Javascript.

Business logic in Javascript - I can't give any concrete examples on why this would be bad but it just doesn't feel right to me having business logic in Javascript that anyone can read.

Javascript memory leaks - since the page never reloads, Javascript memory leaks can happen, and I would not even know where to begin to debug them.

There are also other things that are kind of double edged swords.  For example, with single page applications, the data processed for each request can be a lot less since the application will be asking for the minimum data it needs for the particular request, however it also means that there could be a lot more small request to the server.  I'm not sure if that is a good or bad thing.

What are some of the advantages and disadvantages of single page web applications that I should keep in mind when deciding which way I should go for my project?

答:
The choice doesn't have to be the one or the other. JWt is for example a web toolkit that implements the perfect illusion of a multi-page web-page, yet it is a single page. Additionally, it will recognise google bots and browsers that don't have javascript (try it), and switch to the traditional multi-page model when it detects them.

In short:

no need to write an API (but you still can, if you want to)

responsive application: every user click needs at most one server round-trip (plus fetching images)

no duplication of code

no business logic client-side

minimal complexity client-side

search bots can index it


答: I think that how verbose 2nd party inspection is depends on your lifecycle, whether you're more agile, or more waterfall in your processes.  I think it's reasonable to do high level designs/inspections, as well as more detail level design inspections.  I think it's also good to involve several members of a team to inspect.</p>

Title: Are code reviews necessary for junior developers?

Body:
I've worked at two companies, who each had a different methodology when it came to code reviews:

In the first company, a code review was conducted by the team leaders and was required after the completion of every module.

However, in the second company, team leaders weren't required to conduct any code reviews, and just checked for functionality and design issues.

So I am confused. Is the code review process really needed? If it is, why? And if it isn't, why not?


答:
I assume you have changed something because you had a defect to correct or a feature implemented. Therefoer the correct way for people to know about these changes is your change tracking system.

If email is your change tracking system and people are not reading emails, it will make little difference if you send one or don't........


问:
Is BSD-License compatible with Apple AppStores?
I would like to know if it is possible to make an application to be sold on Apple AppStores that is linked (during compilation) to a BSD-licensed library.</p>

答:
In theory it should be fine.

The BSD license is a Permissive free software license which means it doesn't insist on anything using it being shared in the same way.

The BSD license only says that redistribution and use in source and binary forms are permitted (subject to certain constraints) but doesn't mandate how that should be other than that the copyright notices should remain intact if it is.


答:
OS X contains many components that are BSD-licensed.

This implies that all Mac applications are directly or indirectly linked to BSD-licensed libraries.

Moreover, OS X itself is available on Mac App Store.

So I assume that BSD license is compatible with Mac App Store.

Title: Is BSD-License compatible with Apple AppStores?

Body: I would like to know if it is possible to make an application to be sold on Apple AppStores that is linked (during compilation) to a BSD-licensed library.</p>


答:
http://en.wikipedia.org/wiki/BSD_licenses

You have several versions of the BSD license. It's one of the simplest licenses, so you should simply read it.

Here is the "longest one":

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

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

Redistributions in binary form must reproduce the above copyright    notice, this list of conditions and the following disclaimer in the

documentation and/or other materials provided with the distribution.

All advertising materials mentioning features or use of this software    must display the following acknowledgement:    This
product includes software developed by the .

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

So, yes, you can redistribute it on app stores. Just include the copyright in your distribution.


问:
REST vs RESTful vs "normal" web service - the same or not?
I've read a couple of definitions and discussion on REST and/or RESTful applications, but I still do not understand the real meaning of it.

I usually work with the apps which either fetch data via GET or send data via POST to some web service (usually a PHP script) which then either get data from the database or do writing into the database.

Now, is this a RESTful app? If not, what would be a RESTful app? What is difference between RESTful concept and the concept I worked so far with? Please explain via an example.

Also, someone is talking about the REST and someone about RESTful apps. I found that the REST term refers to the theoretical concept, while RESTful is used when we talk about the specific app. Is this right or there are real differences between REST and RESTful apps?

答:
Before going further, this related question may help you

The difference between REST and RESTful is simply semantics. REST is an architectural style applied to a client-server relationship. RESTful is simply a way of telling your clients that you use REST.

Many web applications claim to be RESTful, but actually are only partially conformant to the REST Constraints (as Martijn Verburg has also referenced in his answer). I'll just list them here but I strongly urge you to read the article:

Client–server

Cacheable

Layered system

Code on demand (optional)

Since you mention that you work on the client side it might be helpful to see what a REST architecture will give and expect from you as a connecting client. Although REST is not HTTP it is by far the most popular protocol that supports what REST is so I'll frame my example around that.

Your client will be expected to:

use HTTP verbs (e.g. GET, POST, PUT, DELETE, OPTIONS, PATCH) to perform relevant operations

offer Accept headers and understand Content-Type headers (e.g. you receive some XML you've never seen before but you can use a referenced XSD to create a client-side domain model to present to your user)

follow offered links in a Content-Type you understand (e.g. get your user or your application to infer that <link rel="pay" href="http://example.org/orders(1)/payment"> in HTML expresses a state transition to create a payment resource through a POST with a body containing some XML that represents the payment details like credit card number, amount and so on)

react correctly to the wide range of HTTP status codes

If it does the above then it can be thought of as being a REST client, you may want to call it a "RESTful app" but that would rather imply that you're using REST on the client side which is incorrect so best to avoid the term.


问:
Does the MIT open source license require work derivatives to be made public (under MIT license)?
I am looking for an open source license for a library I want to publish. Ideally, one should be allowed to use this library in free or commercial applications without paying me a fee, but if any derivative work from the library is created (any improvement of the library for example), it should be made available to everyone under that same license.

In other words, I want to put the following ethics: "You benefit from this piece of work for free, and if you improve it, I can benefit from your improvement for free too". It's a type copyleft license I am looking for.

The MIT license looks like a possible solution, but it is unclear to me whether derivative works of the code covered by this license MUST be made available PUBLICLY to everyone. Can anyone clarify/confirm this? If there is another more appropriate open source license covering my needs, I am interested too. Thanks.

答:
Short Answer

A combination of the Eclipse Public License and the LGPL ensures exactly what you wish: Modifications of your code have to be made available, but using the code in a larger product does not force the larger product being relicensed. The combination is necessary to allow the code to be used in both GPL and non-GPL projects.

This is a way projects such as JGraphT have done.
They relicensed their project under EPL and LGPL.
The motivation and procedure is described in their wiki.

Long Answer

I think, the Mozilla Public License (MPL) or the Eclipse Public License (EPL) is the license you are looking for, because "if any derivative work from the library is created (any improvement of the library for example), it [IS] made available to everyone under that same license."

The MPL and the EPL license is between of GPL and MIT.

MIT allows the user to do everything with it, including modification, selling and not giving back the modified code to the community.

GPL forces the user to give away all the code to the community, even if your library is only 1% of the whole product.

LGPL forces the user to give away the modification of the LGPL-part of the code.

MPL and EPL are similar to LGPL: It also forces the user to make the modified source available. "Modified source" includes only the part of the MPL-/EPL-covered code. That means, the user may build a new product out of your library. If he does modification of the MPL-/EPL-part, he has to publish it. The new things by him do not need to be published.

I feel the MPL/EPL more fitting, as LGPL explicitly talks about "libraries" and MPL just talks about "Covered Software" (which is a broader scope).

However, choosing EPL causes trouble with combing the software with GPL software: The EPL is not compatible with GPL. This is not the case if you just use the MPL.

If you want to ensure that your code may be used in both GPL and non-GPL projects, dual license the code under LGPL and EPL as described in the short answer.

Examples

JGraphT

logback

<s>qooxdoo</s>. They are planning "to simplify and modernize the qooxdoo licensing terms" and thus they switch from the dual licensing to MIT.


问:
How to be a successful programmer without a CS degree

Disclaimers (Please read before jumping to answer):

I've seen a number of questions similar to the one I would like to ask, so here are some similar questions.

IMHO They are neither completely what I'm asking, nor are they as thorough as I hope to be (I don't mean to brush off the answers to the below questions, nor am I discrediting the askers, I just want to be a little more thorough):

Can a CS degree benefit an older programmer?

https://softwareengineering.stackexchange.com/questions/80024/importance-of-certifications-for-java-programmer-without-bs-degree

https://softwareengineering.stackexchange.com/questions/81591/in-the-absense-of-a-cs-degree-how-can-i-fill-in-the-gaps-so-to-speak

Importance of CS degree when applying for development jobs?

Let me be clear, I'm not asking the following:

How to teach myself programming from scratch (without a degree in CS)

How to market myself as a good software developer (without a degree in CS)

How to get a great high paying job as a software developer (without a degree in CS)

A little context:

Now that I have disclaimers out of the way, let me flesh out my question, starting with a brief history of my experience as a software developer.

First off, I have been incredibly lucky. I've been given several job opportunities (a couple heavy backend PHP/MySQL projects, and several WP7 apps in XAML/C#) through which I really learned everything I know about software development. Nearly all of the software development jobs I've had were ones that I was not rightfully qualified to have (and I made that clear to my employers before they hired me). I don't want to give myself credit where it's not due, but I would say that perfect humility dispenses with modesty.

In nearly every single development job I've had, I have exceeded the expectations of my employer, and proved to be a valuable asset. There are of course exceptions1. But my point is I'm fairly intelligent and was able to teach myself what I needed to know in order to be successful at my job. With each job I had, I was stretched more and more.

I attend the University of Washington's Seattle campus, and am currently in my fourth year with two years left, working on a Math degree. During the various jobs I've had (see my résumé if you want that list) I've also been attending school as a full time student.

As I think most developers would agree, studying the typical general ed undergraduate courses, including introductory programming courses ABSOLUTELY PALES in comparison with writing real code, building real2 products, working with awesome people, and positively affecting the lives of users3.

So... as things go... I spent far more of my time and energy working instead of focusing on my studies. At times I performed very horribly, but for the most part I was able to stay afloat with my grades.

However the computer science program at UW is very, very, very, very competitive.

So, it was no surprise to me when I got rejected by the program. Twice. Ironically enough, the same half-hour window in which I received the always polite, albeit disheartening rejection notice via email, I got a phone call from Amazon offering me a summer internship4 as an SDE.

As I look around at other 'gents my age (21), who share the same goals as myself in software development, I find myself feeling pretty good about where I'm at, what I'm learning, who I am, and what I can do. There are of course much, much, much more brilliant 21 year olds out there than myself, I don't mean to say I stand out in a crowd, merely that I feel like I'm not abysmally behind the progress of my average peer.

I feel confident about my ability to be successful in the world of software. More importantly I feel confident in my ability and desire to continue to grow, learn, and be embarrassingly humbled when I really need it.

Math Degree

I find myself pursuing a Math degree with the sole purpose of having a degree. There are those that say I should drop out and start working now (as I've had opportunity to do), and there are those that say I should really finish my degree. I've made up my mind to go ahead with my degree for entirely different reasons than either camp tends to bring up, so please don't encourage me one way or another on that matter. Consider the issue "closed" :)

*DEEP BREATH* ...sorry this is longer than I anticipated.

This in essence, is my question:

How do I objectively determine what areas of study, general knowledge, and other skills I would have gained through a CS degree that I may or may not be lacking in now?

How do I sort these skills in order of most importance?

What is the best way (over the next two years) to supplement my education to attain those attributes in such a way to match or even surpass the level of a CS undergrad from a top university?

Here are the steps that I am taking already:

Ask the development community (this post)

Pursue mentorships with seasoned developers who share a similar career path with me

Define short and long term "learning" goals and subsequent syllabi outlining topics of study

Continue to write code and work on projects that I'm passionate about

If you've gotten this far, you deserve a cookie :) I appreciate you bearing with me.

So... development community, seasoned developers, fellow students who are in the same boat as me, what advice would you have?

Also... please do keep in mind my disclaimers at the top of this post about what I'm NOT asking for.

Update:

I realize that I did not provide very concrete parameters for what I deem a successful "answer" to my question(s). I think the question is very vague, and could warrant a number of "correct" answers.

After a reasonable amount of time I will select the answer that fits the following attributes:

Explains the why behind their answer

Can speak from some level of experience (be it hiring/interacting with or being someone who has/is in my shoes)

Is concise but thorough, gives broad principles preferably coupled with specific examples

Lastly, considering the length that matching the above would seem to require, please make it a good well communicated answer that's pleasant to read. Others who may be interested in this in the future I would hope would be entertained as well as educated by the response.

So there are some parameters for "correct". They're very high I think, but I've designed them as kind of an outline for what I envision the "best" answer would be. Obviously given enough time I'll select the closest matching response as the "answer".

```
(1) - I worked on a prior version of this website, and while we did not have an explicit
      conversation about it, I felt that I was not able to do very well at all (this can be
      evidenced by the fact that they have since changed their website entirely)
(2) - Firstly, yes, it's a real product (even though I'm writing this post in Chrome...), and
      it kicks ass. Secondly, I was a high school intern developer in test, wrote proof of
      concept code for some of the new features for IE8... so it was a while ago.
(3) - At the time of this posting I am the developer who wrote this app, I am no longer
      responsible for it's code base
(4) - My internship will start in June of 2012, and I'll be working in the Web Store
      team.
```

答:
There are more than a few stories of people becoming millionaires before they graduate from college, maybe the one I hear most is Bill Gates. The people with niche abilities tend to do better without a degree than the cookie stamped CS graduate.

Find something that very few people are into, usually something that is boring, tedious, or difficult to learn, and learn it well, become obsessed with it. Some areas that I have heard about are Unix back end stuff (not Linux, although Linux is not far behind in demand), Flash (I don't know enough about flash to remember exactly what it was, but I know a guy who moved up fast knowing it and he said there is STILL a market for this, mostly because people say it is dying and will not learn it). You might need to take a few classes to get going, but if you know your stuff and have an impressive portfolio there are business out there that are going to need you!


答:
This in essence, is my question:
  How do I objectively determine what areas of study, general knowledge, and other skills I would have gained through a CS degree that I may or may not be lacking in now?

Answer 1

If you learn something new from your study. Then you can objectively say that you gained this through a CS degree.

A1. The Why

A CS degree conceptually is about learning. If one returns from a CS degree with no net difference, then its core aim is not fulfilled. Exams and coursework are the "official" measure of what has been learned. However, individual comprehension (have I learnt anything new?) should be a better objective measure.

A1. The Experience

I have both been in academia, and now work professionally. I chose a Master Degree in Computer Science because I wanted to expand my understanding and I have a passion for learning.

My world has expanded as a result of getting a Masters in computing. My world has also expanded from working professionally.

How do I sort these skills in order of most importance?

Answer 2

Importance is relative on who's asking the question and for what situation. If its for personal growth, then its all important. If its for industry, then things like algorithms and good OOP/standard software practices are important.

A2. The Why

The "scope" of importance is highly dependent on the "context". Without a context, the merits of the skills are difficult to sort.

A2. The Experience

I have found that the skills obtained from "university" vs "in the field" are different. The "skills" in university are more "theory", from industry its more "practice". For this reason, this difference means that the skills are indeed ranked differently in terms of importance.

What is the best way (over the next two years) to supplement my education to attain those attributes in such a way to match or even surpass the level of a CS undergrad from a top university?

Answer 3

Push your self beyond breaking point, and when you break keep breaking yourself again.

What do I mean?

If you get to a point where you don't understand, then you have broken yourself. Keep learning until you understand. Then push further until you find something else you don't understand (ad infinitum).

A3. The Why

If you only learn and stay within your boundary, you will only be "ok". You don't want to be just "ok". You want to be the "best" you can be. You can't reach your real potential, if you don't CONSTANTLY push beyond your boundary.

A3. The Experience

I'm always going to be a life long student, I'm not going to enumerate my current skill set, if you are curious you can just see my profile.

The one thing, I will say is that. I'm never fulfilled with my current knowledge. I want to fly higher, see further, and go deeper.

Title: How to be a successful programmer without a CS degree

Body:
Disclaimers (Please read before jumping to answer):

I've seen a number of questions similar to the one I would like to ask, so here are some similar questions.

IMHO They are neither completely what I'm asking, nor are they as thorough as I hope to be (I don't mean to brush off the answers to the below questions, nor am I discrediting the askers, I just want to be a little more thorough):

Can a CS degree benefit an older programmer?

https://softwareengineering.stackexchange.com/questions/80024/importance-of-certifications-for-java-programmer-without-bs-degree

https://softwareengineering.stackexchange.com/questions/81591/in-the-absense-of-a-cs-degree-how-can-i-fill-in-the-gaps-so-to-speak

Importance of CS degree when applying for development jobs?

Let me be clear, I'm not asking the following:

How to teach myself programming from scratch (without a degree in CS)

How to market myself as a good software developer (without a degree in CS)

How to get a great high paying job as a software developer (without a degree in CS)

A little context:

Now that I have disclaimers out of the way, let me flesh out my question, starting with a brief history of my experience as a software developer.

First off, I have been incredibly lucky. I've been given several job opportunities (a couple heavy backend PHP/MySQL projects, and several WP7 apps in XAML/C#) through which I really learned everything I know about software development. Nearly all of the software development jobs I've had were ones that I was not rightfully qualified to have (and I made that clear to my employers before they hired me). I don't want to give myself credit where it's not due, but I would say that perfect humility dispenses with modesty.

In nearly every single development job I've had, I have exceeded the expectations of my employer, and proved to be a valuable asset. There are of course exceptions1. But my point is I'm fairly intelligent and was able to teach myself what I needed to know in order to be successful at my job. With each job I had, I was stretched more and more.

I attend the University of Washington's Seattle campus, and am currently in my fourth year with two years left, working on a Math degree. During the various jobs I've had (see my résumé if you want that list) I've also been attending school as a full time student.

As I think most developers would agree, studying the typical general ed undergraduate courses, including introductory programming courses ABSOLUTELY PALES in comparison with writing real code, building real2 products, working with awesome people, and positively affecting the lives of users3.

So... as things go... I spent far more of my time and energy working instead of focusing on my studies. At times I performed very horribly, but for the most part I was able to stay afloat with my grades.

However the computer science program at UW is very, very, very, very competitive.

So, it was no surprise to me when I got rejected by the program. Twice. Ironically enough, the same half-hour window in which I received the always polite, albeit disheartening rejection notice via email, I got a phone call from Amazon offering me a summer internship4 as an SDE.

As I look around at other 'gents my age (21), who share the same goals as myself in software development, I find myself feeling pretty good about where I'm at, what I'm learning, who I am, and what I can do. There are of course much, much, much more brilliant 21 year olds out there than myself, I don't mean to say I stand out in a crowd, merely that I feel like I'm not abysmally behind the progress of my average peer.

I feel confident about my ability to be successful in the world of software. More importantly I feel confident in my ability and desire to continue to grow, learn, and be embarrassingly humbled when I really need it.

Math Degree

I find myself pursuing a Math degree with the sole purpose of having a degree. There are those that say I should drop out and start working now (as I've had opportunity to do), and there are those that say I should really finish my degree. I've made up my mind to go ahead with my degree for entirely different reasons than either camp tends to bring up, so please don't encourage me one way or another on that matter. Consider the issue "closed" :)

*DEEP BREATH* ...sorry this is longer than I anticipated.

This in essence, is my question:

How do I objectively determine what areas of study, general knowledge, and other skills I would have gained through a CS degree that I may or may not be lacking in now?

How do I sort these skills in order of most importance?

What is the best way (over the next two years) to supplement my education to attain those attributes in such a way to match or even surpass the level of a CS undergrad from a top university?

Here are the steps that I am taking already:

Ask the development community (this post)

Pursue mentorships with seasoned developers who share a similar career path with me

Define short and long term "learning" goals and subsequent syllabi outlining topics of study

Continue to write code and work on projects that I'm passionate about

If you've gotten this far, you deserve a cookie :) I appreciate you bearing with me.

So... development community, seasoned developers, fellow students who are in the same boat as me, what advice would you have?

Also... please do keep in mind my disclaimers at the top of this post about what I'm NOT asking for.

Update:

I realize that I did not provide very concrete parameters for what I deem a successful "answer" to my question(s). I think the question is very vague, and could warrant a number of "correct" answers.

After a reasonable amount of time I will select the answer that fits the following attributes:

Explains the why behind their answer

Can speak from some level of experience (be it hiring/interacting with or being someone who has/is in my shoes)

Is concise but thorough, gives broad principles preferably coupled with specific examples

Lastly, considering the length that matching the above would seem to require, please make it a good well communicated answer that's pleasant to read. Others who may be interested in this in the future I would hope would be entertained as well as educated by the response.

So there are some parameters for "correct". They're very high I think, but I've designed them as kind of an outline for what I envision the "best" answer would be. Obviously given enough time I'll select the closest matching response as the "answer".

```
(1) - I worked on a prior version of this website, and while we did not have an explicit
      conversation about it, I felt that I was not able to do very well at all (this can be
      evidenced by the fact that they have since changed their website entirely)
(2) - Firstly, yes, it's a real product (even though I'm writing this post in Chrome...), and
      it kicks ass. Secondly, I was a high school intern developer in test, wrote proof of
      concept code for some of the new features for IE8... so it was a while ago.
(3) - At the time of this posting I am the developer who wrote this app, I am no longer
      responsible for it's code base
(4) - My internship will start in June of 2012, and I'll be working in the Web Store
      team.
```


问:
Is there a need for a factory class for creating viewmodels?
A colleague of mine suggested using a factory class for creating viewmodel objects in our ASP.NET MVC solutions. The idea being that it can help with the design, and maintainability, of the way viewmodels are built in our apps.

I wanted to find out if anyone else has experience of this. I've done some research and found very little on this practise.

Currently we create viewmodel objects at the controller level eg

```<code>public ActionResult Index()
{
    return this.View(this.BuildIndexViewModel());
}
</code>```

So this.BuildIndexViewModel() is responsible for creating the viewmodel class (obviously :). But we're looking into the possability of:

```<code>public ActionResult Index()
{
    return this.View(ViewModelFactory.CreateIndexViewModel());
}
</code>```

This is an interesting idea, but I'm not 100% convinced. I was interested in other people's opinions on this.

答:
In this case I would say the best guidance to follow would be the GRASP principles. In particular look at the four criteria of assigning object creation:

In general, a class B should be responsible for creating instances of class A if one, or preferably more, of the following apply

Instances of B contains or compositely aggregates instances of A

Instances of B record instances of A

Instances of B closely use instances of A

Instances of B have the initializing information for instances of A and pass it on creation.

Your controller class (B) matches the items #3 & #4 of that list (and #2 if the viewmodel is POSTed back) , so it's already a very sensible place for the viewmodel (A) construction behaviour to live. As I see it there would only be two reasons which would compel me to extract that construction behaviour into a specialist class.

DRY - If two or more controllers need to share the viewmodel construction behaviour, encapsulating it in a distinct component would facilitate code re-use and avoid duplication.

If the construction behaviour has dependencies on other system components such as repositories, validators etc, and you don't want to introduce this coupling to the controller itself (in GRASP terms, a pure fabrication).

Looking back at those 4 object creation criteria in GRASP, I would only extract the behaviour to a separate factory if it won me an extra tick on that list. Otherwise there wouldn't be any value in doing so.

Hope that helps!


答:
I think a very good practice is to setup a post commit hook to email the diff of changes. Set a fixed subject prefix and noreply@yourcompany.com sender address to make them easy to filter out, so it's non-intrusive.

We've been doing this at all my past workplaces, and it's always popular. Many developers read the diffs regularly and recommend improvements to each other. It's a good way to keep everybody involved well-informed about the changes happening in the project. Some developers might not be too happy at first, I've heard complaints of "some strange spam", referring to the diff emails, but even the skeptics tend to warm to the idea after a while. I strongly recommend it.


问:
Should data structures be integrated into the language (as in Python) or be provided in the standard library (as in Java)?
In Python, and most likely many other programming languages, common data structures can be found as an integrated part of the core language with their own dedicated syntax. If we put LISP's integrated list syntax aside, I can't think of any other languages that I know which provides some kind of data structure above the array as an integrated part of their syntax, though all of them (but C, I guess) seem to provide them in the standard library.

From a language design perspective, what are your opinions on having a specific syntax for data structures in the core language? Is it a good idea, and does the purpose of the language (etc.) change how good this could be of a choice?

Edit: I'm sorry for (apparently) causing some confusion about which data structures I mean. I talk about the basic and commonly used ones, but still not the most basic ones. This excludes trees (too complex, uncommon), stacks (too seldom used), arrays (too simple) but includes e.g. sets, lists and hashmaps.

答:
I think it is a bad idea to have too many privileged data types that get special syntax. This complicates the language syntax needlessly, making code harder to read, making it harder for beginners to learn and making it harder to develop tools for the language.

It's OK to make an exception for a small number of very common data structure types. I'd probably allow at a maximum:

Fixed-length arrays

Sets

Hashmaps

Sequences / lists

Records / structs / classes

Anything more sophisticated than that should probably be left to libraries to handle, using the language's normal syntax for custom data types.

In particular, things like Red/Black trees, Priority Queues etc. have quite a lot of possible implementation options, so it isn't wise to bake a particular implementation into the core language. It's better to let people choose the most appropriate implementation for their situation. Examples of implementation choices that I might not want a language designer to restrict my choice on:

Mutable or immutable?

Allows nulls or not?

Synchronised or not?

Backed by persistent storage or not?


答: Enforce (ideally automatically) the creation of checkin comments in your source control system.  That way people can easily see a summary of the changes that have been made recently.</p>


答:
How do I objectively determine what areas of study, general knowledge,
  and other skills I would have gained through a CS degree that I may or
  may not be lacking in now?

Browse the curriculum of the CS department at UW, borrow and browse through the required reading, look at previous exams and lab exercises (homework assignments).  If you have no idea about how you would approach the problem, you have a hole in your knowledge.

How do I sort these skills in order of most importance?

Think about what kind of programming you would like to do in the future. If you're happy building websites and CRUD applications, it seems you already have all the knowledge you need.

CS education enters the picture if you are interested understanding in how [distributed] databases, web servers, compilers and interpreters, operating systems, network protocols etc. work under the hood, and are interested in building such systems yourself.

What is the best way (over the next two years) to supplement my
  education to attain those attributes in such a way to match or even
  surpass the level of a CS undergrad from a top university?

I do not know.  For me, the greatest benefit of the university was to 1) broaden my horizons (I have forgotten 90% of the details I learned at uni, but I remember concepts and ideas), and 2) keep my intrinsic motivation for learning the stuff from waning: It's easier to keep motivation up when you're working towards a goal -- exam, another exam, etc. until you graduate. (Also, structuring self-education is not an easy task.)

[Added: choose a university whose CS program you would like to follow, choose courses in topics you're interested in and go through the curriculum yourself: homework assignments, exams, etc. Most courses publish lecture slides and assignments/exams from earlier years.]

A word of advice though: DO NOT give up your math degree. Any bright person can teach themselves to program, but math will give you competitive edge if you should ever wish to work on applications other than CRUD/frontend, for example fluid and mechanical simulations, computer graphics, image processing, recognition and machine learning applications, (even finance!) etc.

UPDATE 2 -- experience [long]: I obtained master's degree at EE faculty: the first two years were common curriculum (physics, electrical engineering, analog&digital electronics, and a lot of math -- linear algebra; discrete math; real, vector and complex applied analysis.) This was very valuable, esp. the EE and electronics part -- it allowed me to work on mixed HW-SW projects, and cooperating with HW designers was very exciting. I didn't contribute anything to HW design, but I was able to follow the HW designer "debugging" his schematic diagram and ask sensible questions [we were unsure whether the bug was in SW or HW -- turned out it was in HW :-)].

Then the lines branched and I choose the CS line. Some of the "details" contributed to ingraining the concepts (e.g., "running" Dijkstra's algorithm by hand). Also I learned details about how CPUs work (bus signals, interpreting bus diagrams, execution, etc.) on the example of, already then, obsolete Motorola 68000, but the concepts learned through details aren't very different for modern CPUs either.

Other details, esp. SW implementations (e.g., implementing Dijkstra), were for me [since I've gotten quite good at coding in highschool] a pointless exercise in debugging and contributed ZERO to understanding of concepts.

And then I enrolled into PhD programme, where I had to take obligatory courses. I was disappointed by the choice of courses, since many of them seemed more to be oriented towards industry's demands (e.g., using Python for scientific data analysis -- thank you, I can program and I'm very much capable of teaching myself that -- which again involved a lot of pointless coding) than towards teaching fundamental concepts (fortunately, I dug out courses on discrete optimization, static analysis of programs and formal analysis with Promela).

So, some details were useful for ingraining concepts, and some were outright unnecessary burden (another example: programming serial port communication between two computers.  I was already then used to reading and interpreting HW specs and programming HW through registers, so it was just.. boring.  Maybe I'm naive in assuming that average to-become CS engineers don't need to be educated about how to read HW docs).

In conclusion: expose yourself to many different concepts (high-level ideas) and go into detail for those that you want to prioritize and become extremely good at. [You CANNOT be extremely good at everything!]


答:
I use Mercurial and use subrepositories for all my dependencies (GLEW, GLM, Boost, Assimp, Bullet) but am not convinced it's always a good thing. Sometimes I think it makes more sense to just link against a prebuilt library.

For me, it's nice to be able to build and step through all the external code I'm using for debugging's sake, plus I can make my own branches to make custom changes and still pull updates for my subrepositories.

I keep all my subrepositories in a Dependencies directory just below the project root, although Mercurial's docs recommend a master repository with your own project and any dependencies as subrepositories.

Title: Subrepositories (submodules) as a dependency tracking solution - yes or no?

Body:
What do you think about SCM-based (subrepositories in mercurial, submodules in git) dependencies management?

Is it definitely a good way of managing dependencies? Or definitely bad way?

Should I prefer some build system (ant/phing/rake) over subrepositories?

Some particular example for you to have a context:

I have several web applications that share across reusable components, say jquery plugins.


答:
Why do you think that a CS degree is so important to be a Successful programmer?

What you need in order to be a successful programmer is:

Passion about programming

A neverending thirst for knowledge about new technologies

Get into the industry someway

Usually the CS degree will get you inside the industry, but if you dont have the passion and the thirst for knowledge, you will suffer, and you will never be a good programmer.

Looks like you already got into the industry, and it certainly feels like you have both the passion and the thirst for knowledge.

What you got to do know is to keep on researching and learning and gaining experience, and the industry will know how to appreciate you without the degree.

An Example From someone I work with

one of the Software Developers working in my team has a law degree... after a few years she understood she doesnt like law at all, and that she wants to be a programmer. she couldn't get a job as a programmer(no experience, no degree), so she did a 6 month computer course, then she got a job, and she's a great developer ever since.


答:
I interview and participate in recruiting a lot of junior people fresh out of college. I have yet to hire anyone based on the subject-matter skills they picked up from whichever program they took. The reason for this is simple: no CS program (or any other program) I've encountered teaches any concrete skills connected with programming or software development that is on a professional, commercial level. Being able to crank out models and solutions to complex differential equations and writing optimized special-purpose sorting-algorithms may have academic and/or scientific value, but it has no bearing on general software development.

What DO I look for then? Well, I expect a college graduate to have perfected the art of learning. That is, after all, what a good college should be teaching it's students. How to analyze and break down general problems into logical, discrete components that are predictably solvable. A methodical approach to find, evaluate, organize and apply knowledge and information towards a solution.

Also, I look for people who understand that a group of people, working together and communicating, are worth much more than the sum of it's individuals. That requires maturity and humility and the ability to both give and ask for help.

So, to loop back to the scope of your question: while a CS degree might improve your chances of getting that first interview out of college, I find it has little to no bearing on your success or proficiency as a developer. I've always followed the philosophy "hire for attitude, train for skill" and it's payed off well.

My advice: continue with your math degree if that is something that interests you. Any scientific education will server you well, so pick the one that you like most as that's the one you're most likely to excel in. Then focus on learning the important things: how to learn, how to analyze and approach problem-solution in a structured way, how to interact and cooperate with other people, how to take leadership and responsibility for both your own and your teammates' delivery. The rest is just technology and coding, the tools of the trade. Those, you can and will learn on your own. Pick up and study some general purpose knowledge, like popular design patterns and architectural paradigms. Start writing programs to practice. Pick some language and technology base that is fairly up to date, but don't make the mistake of thinking it's the final one you'll learn. Tools and languages change all the time so software development is a constant process of learning anyway.


问:
File system layout for multiple build targets
I am seeking some ideas for how to build and install software with some parameters. These including target OS, target platform CPU details, debugging variant, etc.
Some parts of the install are shared, such as documentation and many platform independent files, others are not, such as 64 and 32 bit libraries when these are separated and not together in a multi-arch library.

On big networked platforms one often has multiple computers sharing some large server space, so there is actually cause to have even Windows and Unix binaries on the same disk.

My product has already fixed an install philosophy of $INSTALL_ROOT/genericname/version/ so that multiple versions can coexist.

The question is: how to manage the layout of all the other stuff?

答:
At one time, I worked for an SAN manufacturer in the build group. We had to support about 40 different operating systems.

The distributions were organized by major OS families at the root level of the distribution media (CD and DVD), such as HPUX, Z/OS and Windows, with versions branching off those. So for example, the Windows branch would have Server and Workstation off that folder, and each would have a set of x86, x64, ia64 and Alpha folders, each with their own installs.


问:
A software design pattern to model runtime-dependent behavior
In a interview I was asked,

Suppose we are going to create a software that runs on both desktop machines and smartphones. Name a software design pattern that could be used to enable the application to create different classes for display at runtime depending on the platform.

I know there are simple solutions to implement this feature in the actual code. For example, in Java I can check the display size and create the suitable class (MobileDisplay or DesktopDisplay class) for that display.

But I don't how this is related to the software design; in my opinion, creating suitable class based on runtime platform is an implementation concern rather than a software design issue.

答:
I think the interviewer was expecting the Abstract Factory pattern.
http://www.vincehuston.org/dp/abstract_factory.html
And I also think that you are missing the point of software design. Ultimately software is about implementation, but a little thought and design patterns make the implementation easy to follow.</p>


问:
Difference between a pseudo code and algorithm?
Technically, Is there a difference between these two words or can we use them interchangeably? Both of them more or less describe the logical sequence of steps that follow in solving a problem. ain't it? SO why do we actually use two such words if they are meant to talk of the same?

Or, In case if they aren't synonymous words, What is it that differentiates them? In what contexts are we supposed to use the word pseudo code vs the word algorithm?

答: An algorithm is a systematic logical approach used to solve problems in a computer while Pseudocode is the statement in plain English which may be translated later into a programming language (program).</p>


答:
Patterns work well together. I can't claim to know exactly what your interviewer was looking for, but I would have suggested a combination of patterns:

MVC, MVVM, MVP are all patterns that try decouple the UI from the model/data, permitting multiple visual representations for the same model/data. I would have picked the one I was most familiar with.

From there, Factory Method and/or dependency injection (whichever flavour you want constructor/property etc.) can be used at runtime to choose/instantiate the relevant view. Consider that DI is a pattern, and that DI frameworks exist mostly to make it easier and more consistent/readable.

Title: A software design pattern to model runtime-dependent behavior

Body:
In a interview I was asked,

Suppose we are going to create a software that runs on both desktop machines and smartphones. Name a software design pattern that could be used to enable the application to create different classes for display at runtime depending on the platform.

I know there are simple solutions to implement this feature in the actual code. For example, in Java I can check the display size and create the suitable class (MobileDisplay or DesktopDisplay class) for that display.

But I don't how this is related to the software design; in my opinion, creating suitable class based on runtime platform is an implementation concern rather than a software design issue.


问:
Has whitespace in identifiers ever been idiomatic?
C# style suggests using CamelCase in identifiers to delimit words. Lisp tradition suggests using-dashes-instead.

Has there ever existed a programming language where using spaces in identifiers was not only allowed, but a commonly used idiom when employing multi-word identifiers?

It's possible to have identifiers with spaces in some Scheme implementations, but it's not a widely seen practice. Here's an example:

```<code>Petite Chez Scheme Version 8.4
Copyright (c) 1985-2011 Cadence Research Systems

> (define |hey there| 100)
> (define |x y z| 200)
> (list |hey there| |x y z|)
(100 200)
</code>```

答:
FWIW, Tcl allows spaces (and just about every other character) in identifiers, though it's not common to take advantage of this feature. The main reason it's not used very often is just that you have to use proper quoting. For example, the following sets a variable named "my name" to "bob", then prints it

```<code>set "my name" "bob"
puts "hello, ${my name}"
</code>```

OTOH, it's very useful when building variables dynamically since, when creating such variables, one doesn't have to worry about illegal characters

Body:
FWIW, Tcl allows spaces (and just about every other character) in identifiers, though it's not common to take advantage of this feature. The main reason it's not used very often is just that you have to use proper quoting. For example, the following sets a variable named "my name" to "bob", then prints it

set "my name" "bob"
puts "hello, ${my name}"

OTOH, it's very useful when building variables dynamically since, when creating such variables, one doesn't have to worry about illegal characters