问:
How to make a license apply to a whole library?
I'm creating a standard library for a programming language, and I'd like to license each and every single class or function in there under the MIT license, so they're completely FOSS.

All of the files reside in a single directory. Would it be enough to put a LICENSE.txt file in the same directory, containing the MIT license? Do I need to say that the following license applies to all features of the library, or is the library itself considered to be a program?

答:
The general practice is to place the license text in a clearly identifiable location, like you suggest, and to include comments near the top of each source file that tell the reader to look there.  And don't forget to make the license obvious to someone who doesn't download the source code, just a binary.

As to what comprises a "program", you get to ignore that.  In a binary distribution, there's no question - you download one .dll/.so/whatever file and a license file.  In a source distribution, the license or a reference to it is present in every file.


问:
What constitutes a programming language and how does one copyright a programming language?
I've decided to create a programming language of my own, mostly just for fun. However, I got interested in the legal aspect of it all.

You can, for example, licence specific programs under specific terms. However, how do you go about licensing a language? Also, by that I don't just mean the implementation of the language (compiler & VM), but the standard itself. Is there something else to a programming language I'm missing?

What I would like to achieve by such licensing:

Make it completely FOSS (can a language even be FOSS, or is that the implementation that can be FOSS?)

Establish myself as the author (can you legally be an author of a language? Or, again, just the implementation?)

Make it so that anyone implementing my language would be required to attribute me (MIT-style. Please note that I do not have any hopes for anyone actually ever doing that though, I'm just learning.)

I think that the solution would be to separately license the VM and the compiler for my language, as "the official implementation", and then license the design document as the language itself.

What exactly am I missing here?

答:
There have been different answers to this question over time:

In 2012, a similar question was answered "you cannot" in the Oracle v.s. Google case over the use of the Java API in Android, and a similar answer was given in the case of WPL's implementation of the SAS programming language in their own product. The rationale for this answer was that interopability between different implementations of a language requires copying of the syntax of a programming language, and thus doing so should be allowed under "fair use" rules.

In 2014, however, the US court of appeals decided that the just legal answer was indeed "yes, you can", on the grounds that to provide interopability (or not), and under what rules is at the sole discretion of the original copyright holder. In this most recent interpretation, if someone does not want you to be compatible with their programming language, API or other interface specification, they have every right to stop you.

In a nutshell, as of 2014 it is probably fair to assume: yes, a programming language (its syntax, structure and sequence of language constructs) can be copyrighted

Note that copyright law is subject to local interpretaton and that rules in your country may differ. If in doubt consult a lawyer...

(removed the rest of the argument, see history)

Disclaimer: IANAL

ContentLicense: CC BY-SA 3.0


问:
tips, guidelines, points to remember for rendering professional code?
I'm talking about giving clients professional looking code. The whole nine yards, everything you hardcore professional highly experienced programmers here probably do when coding freelance or for the company you work in.

I'm fresh out of college and I'm going into freelance. I just want to be sure that my first few projects leave a good after-taste of professionalism imprinted on the clients' minds.

When I Googled what I'm asking here, I was given pages that showed various websites and tools that let you make flashy websites and templates etc. The $N package and such stuff.

I can't recall the word experts use for it. Standard, framework [I know that's not it]. English isn't my first language so I'm sorry I don't really don't know the exact phrase for it.

That abstract way of writing code so that you don't come across as a sloppy programmer.

That above mentioned way for programming websites and desktop software [in python/C/C++/Java].

EDIT: I can work on the accruing vast knowledge and know-how and logic building etc. what I'm asking for is the programming standard/guidelines you guys follow so that the client on seeing code feels that its a professional solution. Like comment blocks, a particular indentation style something like that. Is there any book on it or specific list of points for enterprise type coding by them? Especially here as in my case, for building websites [php for now..], and desktop software [c/c++/java/python]

答:
Rather then form a belief about what it means to "be professional" I would recognize your clients particular beliefs and tailor yourself around them. The best way to find out what they want is to ask them. This is good advice in any relationship.

Readability and effective code often come hand in hand and both are part of having a better solution. I believe you might get better results learning what you can do to improve posting some of your solutions on code review and having people give specific advice.


答:
what i'm asking for is the programming standard/guidelines you guys follow so that the client on seeing code feels that its a professional solution

From client and project perspective - asking questions, clarifying client needs, following pre-existing application standards(if you are supporting and enhancing an existing application), documenting your code, and improving all these steps as needed.

For professional development - this sounds to me as a need to keep learning, using, practicing and mastering your SOLID Principles. The way to go for building ROCK SOLID applications.

NOTE: However, it really make difference on what type of applications are you working on. My advice is for enterprise level, high performing, scaleable application development.

We all heart about the coding standards like KISS and YAGNI . They are easy to remember and follow, as far as we are trying to improve yourselves. Thus, it is a constantly revolving process to follow.

References:

Best Coding Practices - wiki

Development best practices: coding standards and the “20 lines” rule

Front-end Code Standards & Best Practices

Java Best Practices, Code Conventions and Style Guide

Coding Standards & Best Practices - Omaxy source

Title: tips, guidelines, points to remember for rendering professional code?

Body:
I'm talking about giving clients professional looking code. The whole nine yards, everything you hardcore professional highly experienced programmers here probably do when coding freelance or for the company you work in.

I'm fresh out of college and I'm going into freelance. I just want to be sure that my first few projects leave a good after-taste of professionalism imprinted on the clients' minds.

When I Googled what I'm asking here, I was given pages that showed various websites and tools that let you make flashy websites and templates etc. The $N package and such stuff.

I can't recall the word experts use for it. Standard, framework [I know that's not it]. English isn't my first language so I'm sorry I don't really don't know the exact phrase for it.

That abstract way of writing code so that you don't come across as a sloppy programmer.

That above mentioned way for programming websites and desktop software [in python/C/C++/Java].

EDIT: I can work on the accruing vast knowledge and know-how and logic building etc. what I'm asking for is the programming standard/guidelines you guys follow so that the client on seeing code feels that its a professional solution. Like comment blocks, a particular indentation style something like that. Is there any book on it or specific list of points for enterprise type coding by them? Especially here as in my case, for building websites [php for now..], and desktop software [c/c++/java/python]


问:
Could a programming language work as well without statements?
As programming in JavaScript, I've noticed everything that can be done with statements and blocks can be done with expressions alone. Can a programming language work fine with only expressions? And, if yes, why are statements used at all?</p>

答: ATL and Xtend are statement-less well working programming languages. Many functional languages are also statement-less. So, yes a programming language can work fine without statements. I think statements are in many languages a relict from imperative programming. They are still used because they are widely known and for some cases they make code more readable.</p>


答:
The most basic technique gives the most bang for the buck. Single purpose modules. It might seem a little too obvious and basic but single purpose modules gives you good code. It's half the battle.

The modules could come in the form of functions, classes, separate projects compiled to DLL, a source-code level macro, etc.

Separate things out till they are single purpose, then they can be reused.


答:
Yes.

Functional languages (and single assignment languages) everything is an expression. Examples are Haskal (and SISAL). Where both if statements and for loops return values.

There are other classes of languages: The easy one that springs to mind is declarative languages (I am sure there are many others that don't depend on statements). These languages don't even need expressions (in the same sense as you would normally think). You declare what is true and you can get multiple results backs. The easy one here is prolog.

Title: Could a programming language work as well without statements?

Body: As programming in JavaScript, I've noticed everything that can be done with statements and blocks can be done with expressions alone. Can a programming language work fine with only expressions? And, if yes, why are statements used at all?</p>


问:
Is a functional spec a part of the System requirement spec?
I wonder, sources like wikipedia or templates I found shows that Functional spec is a part of System requirement documents. I always thought that SRD is just overall decsription of the system, with all functional and non functional requirements. Yet I thought that Functional spec is more detailed and it is a separate document, while SRD is high level customer-created description (how is this one called then?)
Could anyone help to make this clear for me?

答:
Disambiguation

System Requirements (used in systems engineering)

Software Requirements (used in software engineering)

Main Answer

System requirements outline the requirements for the whole system. A system is a set of hardware and software to support a specific business need.

Software requirements are only concerned with software. They are much more detailed than system requirements, so that the software can be actually built from these.

The Software Requirements Specification (SRS) is a standard: IEEE 830-1998. Functional requirements are a part of this standard.

Functional specification is a separate document which is no longer used today (at least in Software Engineering). It was a standard at times when waterfall was used as the best-known technique, and before the IEEE Software Requirements Specification became a standard. The SRS has replaced it because functional requirements are now defined as a part of a larger document (software requirements).

At the dark times of software crisis, I believe that functional specification was the best they knew (without all these amenities the full SRS gives us). They thought software requirements specification is only a specification of required functions. Today we know there is more to it. (see the SRS)

History and Current Use of the SRS

The SRS is from 1998 and it wasn't meant for OOP. I've used it in my company, but only as a basis for customization. Instead of describing functional requirements using natural language, like the old functional specification document, I've used UML (use case diagrams). This is something that wasn't considered by 1998 yet, so that engineers still described the needs quite inefficiently.

Conclusion

Functional specification is a part of the software specification document.  The document is useful, but I wouldn't recommend adopting it as-is because it was defined in 1998; instead, I suggest considering UML where appropriate to replace natural language specification.

References

http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=720574

http://en.wikipedia.org/wiki/Software_requirements_specification

http://en.wikipedia.org/wiki/Use_case

http://en.wikipedia.org/wiki/Functional_specification


问:
Documenting a REST interface with a flowchart
Does anybody have suggestions on creating a flowchart representation of a REST-style web
interface? In the interest of supplying thorough documentation to co-developers, I've been toying around in dia modeling the interface for modifying and generating a product resource:

This particular system begins to act differently with user authentication/resource counts, so before I make modifications, I'm looking for some clarification:

Complexity: how would you simplify the overall structure to make this easier to read?

Display Symbol: is this appropriate for representing a page?

Manual Operation Symbol: is this appropriate for representing a user action like a button click?

Any other suggestions would be greatly appreciated.

My apologies for the re-post. The main stackexchange site suggested this question was better presented on programmers.

答:
My two pennies on the subject, as I am working with this at the moment:

focus on resources and their relations

and not on the action, and thus the HTTP method

when you follow a link, no matter if you did a GET or POST, your next possible states are dictated primarily by the current resource, and much less by the request's HTTP method

With that in mind:

remove some obvious links (i.e. to self, to root)

remove the relations' label if it just states "this [car] has a [owner]", where the source resource is car and the target resource is owner. It doesn't add anything

an interactive graph can be of great help with a complex state diagram (example)


问:
Pattern for loading and handling resources
Many times there is the need to load external resources into the program, may they be graphics, audio samples or text strings.

Is there a patten for handling the loading and the handling of such resources?

For example: should I have a class that loads all the data and then call it everytime I need the data? As in:

```<code>GraphicsHandler.instance().loadAllData()
...//and then later:
draw(x,y, GraphicsHandler.instance().getData(WATER_IMAGE))
//or maybe
draw(x,y, GraphicsHandler.instance().WATER_IMAGE)
</code>```

Or should I assign each resource to the class where it belongs?
As in (for example, in a game):

```<code>Graphics g = GraphicsLoader.load(CHAR01);
Character c = new Character(..., g);
...
c.draw();
</code>```

Generally speaking which of these two is the more robust solution?

```<code>GraphicsHandler.instance().getData(WATER_IMAGE)
//or
GraphicsHandler.instance().WATER_IMAGE //a constant reference
</code>```

答:
It depends on the purpose of your application.

In some games, there is a need for a highly responsive user interface and loading resources while playing could have a negative impact. Secondly, many games run with 100% CPU usage, esp. 3D shooters, so that any data which can be preloaded also becomes preloaded. This lowers the overall system requirements. As can be seen, there are performance reasons for preloading of resources. Finally, resources are often compressed inside one large archive to save disk space. It takes some time to decompress all files for the current level. That is the last reason for preloading.

Is the program a game? Does it need some of these performance-optimization techniques? Otherwise, the closest design pattern for this would be Facade:
http://en.wikipedia.org/wiki/Facade_pattern

```<code>Gfx ghost = (Gfx)ResourceLoader.load("/gfx/sprites/ghost");
Sound taunt = (Sound)ResourceLoader.load("/audio/boost/you_play_like_a_girl.voc");
Music levelMusic = (Music)ResourceLoader.load("/audio/music/level1.mp3");
</code>```

With the solution above, there can be a resource cache and you want to log most frequently loaded resources. After that, you can preload those resources implicitly after your program starts because you know they will be needed. You should not however preload everything. For every level, different resources are needed.

Body:
It depends on the purpose of your application.

In some games, there is a need for a highly responsive user interface and loading resources while playing could have a negative impact. Secondly, many games run with 100% CPU usage, esp. 3D shooters, so that any data which can be preloaded also becomes preloaded. This lowers the overall system requirements. As can be seen, there are performance reasons for preloading of resources. Finally, resources are often compressed inside one large archive to save disk space. It takes some time to decompress all files for the current level. That is the last reason for preloading.

Is the program a game? Does it need some of these performance-optimization techniques? Otherwise, the closest design pattern for this would be Facade:
http://en.wikipedia.org/wiki/Facade_pattern

Gfx ghost = (Gfx)ResourceLoader.load("/gfx/sprites/ghost");
Sound taunt = (Sound)ResourceLoader.load("/audio/boost/you_play_like_a_girl.voc");
Music levelMusic = (Music)ResourceLoader.load("/audio/music/level1.mp3");

With the solution above, there can be a resource cache and you want to log most frequently loaded resources. After that, you can preload those resources implicitly after your program starts because you know they will be needed. You should not however preload everything. For every level, different resources are needed.


问:
Do I need to make the source code available to a modified AGPL application if the application is only exclusively available over my private LAN?
I have a network game licensed under the AGPL that I modified to suit my needs.  Theoretically, I want to charge people to play this game over a local area network that is set up in a private establishment of which I own all the local network infrastructure including the server and the game stations. would I still be required to make the source code available to these people?</p>

答:
I'm not a lawyer (and I'm not giving you legal advice, please consult a lawyer).

However, it's my current understanding that GPL-style licenses don't care so much about costs and monetary exchange, or public vs private, or ownership of the distribution medium, but more distribution of source and binaries.

The spirit of the GPL is that if you take code from a GPL source, you must make your derivative works and modifications public you must make available the source of derivative works and original (or modified) GPL source to those that use your binaries.

The AGPL was created to address a perceived shortcoming in the letter of the GPL where hosting some code on an external server that a client connected to was used to shield the source from being released. Ergo, the spirit of this license is that network distribution falls under the GPL constraints.

I personally believe the answer to your question is clear cut based on this information, but again, I'm not a lawyer and there are myriad intricacies that I may not be privy to.

Edited based on comments that responded to my original answer.


问:
What's a nice explanation for pointers?
In your own studies (on your own, or for a class) did you have an "ah ha" moment when you finally, really understood pointers? Do you have an explanation you use for beginner programmers that seems particularly effective?

For example, when beginners first encounter pointers in C, they might just add &s and *s until it compiles (as I myself once did). Maybe it was a picture, or a really well motivated example, that made pointers "click" for you or your student. What was it, and what did you try before that didn't seem to work? Were any topics prerequisites (e.g. structs, or arrays)?

In other words, what was necessary to understand the meaning of &s and *, when you could use them with confidence? Learning the syntax and terminology or the use cases isn't enough, at some point the idea needs to be internalized.

Update: I really like the answers so far; please keep them coming. There are a lot of great perspectives here, but I think many are good explanations/slogans for ourselves after we've internalized the concept. I'm looking for the detailed contexts and circumstances when it dawned on you.

For example:

I only somewhat understood pointers
  syntactically in C. I heard two of my
  friends explaining pointers to another
  friend, who asked why a struct was
  passed with a pointer. The first
  friend talked about how it needed to
  be referenced and modified, but it was
  just a short comment from the other
  friend where it hit me: "It's also
  more efficient." Passing 4 bytes
  instead of 16 bytes was the final
  conceptual shift I needed.

答: A pointer is a variable whose value is the memory address of another variable.</p>

ContentLicense: CC BY-SA 2.5

Title: What's a nice explanation for pointers?


答:
I don't know that either option is going to be particularly robust.  In both cases, you're relying on some kind of singleton or static-state-heavy implementation to manage what amount to global variables.  How exactly you access the global variables (whether directly or hidden behind some kind of weakly typed "getData()" call) isn't going to matter a lot to maintainability in the face of a global variable scheme in general.  Your application is going to be highly cross-coupled and interdependent either way.

I would say a decent option with an eye on future flexibility would be to take your getData() concept and put it in an interface.  Then inject an instance of that interface into classes that need access to the data (and try to limit that number as much as possible).  This way you can mock out or swap the thing that provides that data.  The way you have it now, this is impossible -- every client of that singleton depends on the entire application state being spun up in order for it to be used, making testing and decoupling difficult, if not impossible.  And that state of affairs is the opposite of robust.

Title: Pattern for loading and handling resources

Body:
Many times there is the need to load external resources into the program, may they be graphics, audio samples or text strings.

Is there a patten for handling the loading and the handling of such resources?

For example: should I have a class that loads all the data and then call it everytime I need the data? As in:

```<code>GraphicsHandler.instance().loadAllData()
...//and then later:
draw(x,y, GraphicsHandler.instance().getData(WATER_IMAGE))
//or maybe
draw(x,y, GraphicsHandler.instance().WATER_IMAGE)
</code>```

Or should I assign each resource to the class where it belongs?
As in (for example, in a game):

```<code>Graphics g = GraphicsLoader.load(CHAR01);
Character c = new Character(..., g);
...
c.draw();
</code>```

Generally speaking which of these two is the more robust solution?

```<code>GraphicsHandler.instance().getData(WATER_IMAGE)
//or
GraphicsHandler.instance().WATER_IMAGE //a constant reference
</code>```


答:
It's hard to say for certain.

Based upon the AGPL text, it could be argued that you're propagating the code.  As such, you would be obligated to then provide the source.

OTOH, it appears that they explicitly exempt what you're describing in part of their definition for conveyance: Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.  In which case, you would not need to provide the source.

(Update, hat tip to K.Steff!) Section 13 muddies the waters even further.  Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source.  On the one hand, this section appears to be directly related to what you suggest.  But on the other hand, you're not providing remote access, you're providing local access to the to the application.  It's a fine line, but court cases have been settled over less.

I would recommend dropping the FSF an email and just ask them.  It's the only way you can get a definitive answer.  Obviously they have a bias towards saying "yes" in distributing the source, but I think they'll be fair in how they assess your question.  It sounds like you're halfway ready to provide the source anyway.  Getting a "ruling" from FSF in this case is about as good of a scenario as you can get.

Title: Do I need to make the source code available to a modified AGPL application if the application is only exclusively available over my private LAN?

Body: I have a network game licensed under the AGPL that I modified to suit my needs.  Theoretically, I want to charge people to play this game over a local area network that is set up in a private establishment of which I own all the local network infrastructure including the server and the game stations. would I still be required to make the source code available to these people?</p>


问:
brackets in php templates
I have a script, and now it's the perfect time to have an option to change theme templates.

I was looking forward to store these files in php files, or html files. with CSS file. I looked over some codes and I found that they use brackets to refer to the variable.

Here's an example of a template block:

```<code><div class='block_div'>
<center>{title}</center>
{content}
</div>
</code>```

I know that I can use PHP vars usering <?=$var;?>. However, I think the one above is better, and I looked over the web to find anything about it but I couldn't.

My Question is how I can use these brackets in my php or html code. to let the user changing the template only not the code!

答:
I don't think this question belongs to this site but to stackoverflow. Anyway, I'd tell you to take a look at any of the several templating libraries out there, for both PHP and JavaScript, such as:

For PHP: twig, smarty, etc.

For JavaScript: mustache.js, handlebars.js

Title: brackets in php templates


答:
Consistency is king. Pick a naming/capitalization standard and stick with it. If you're confident, come up with your own, but it'll be much easier if you grab an already existing standard

Comment your functions by explaining what they are trying to do. Not what each line of code does but more like "this function take in 2 numbers, multiplies them and returns the result"

Group relevant functions together into well named classes - not as easy as it sounds

Get your error logging happening at the start of the project and log DEBUG, INFO, WARN and ERROR logs

Get your error handling framework happening at the start of the project so it's consistent

Don't plaster your name all over your code or put in stupid comments in your code (like "// warning, this is a hack because Y sux"). Don't use obscenities or racial language etc. Sounds too obvious? You'd be surprised.

Don't go overboard in your design!! Just because you want it to be professional doesn't mean it has to have 6 layers and a million classes. Keep it simple!

Don't re-invent the wheel. Very common for young grads. Use libraries that have already done the work for you!

If you're doing web stuff, separate out your CSS and Javascript to separate files. Keep your Javascript simple.

Write Unit Tests - keep it simple though.

If you're talking to a database, create a database project that abstracts away the DB stuff from your front-end.

Use a source code revision management tool. Which one? Any of them, just use one.

Keep code file sizes smallish. Opinions vary but I reckon anything over 1000 lines should be broken up into smaller files.

Don't hardcode filesystem paths, server names or "magic numbers". Use relative paths, put server names into a config file and use constants.

Use relative URLs.

Catch as many errors at compile-time if possible. Makes cleaning up your code easier.

Don't be afraid to refactor stuff.

Don't "optimise" your code if it doesn't need to be optimised. Premature optimisation will make your code a mess. Don't do anything stupid like reading 10 gig of data into ram too.

Only cache stuff if you need to. Keep it simple.

A few other non programmy things you're going to have to learn:

How to estimate and project plan. People will ask you for an estimate, be prepared.

Document the customers requirements. This will make things easier for you and them.

Get someone (preferably experienced) to review your code after you've written a week or two's worth. It will only take them a few minutes to glance over it all to point out what will be obvious to them but not you.

Learn about design patterns but don't overzealously use them for the sake of it.

Backup your stuff.

Keep track of bugs, issues and feature requests somehow (they are all different things). Just a text file is fine, but either way do it. Someone will eventually ask you for it.

Keep up to date with frameworks/libraries so that you're not doing things a really old way that can be done quicker and easier with a new library. If it seems way to hard then there's probably (hopefully) a much easier way of doing things.

If there's any complicated logic going on, document it somehow with a flowchart or just write it out in english. Don't expect that someone will spend 2 days trying to reverse engineer your code.

I'd also suggest that as you're just out of college you won't get things right the first time, nor the second time (none of us do). My advice would be to try to join a team of experienced developers, learn for them, and then a few years later consider freelancing. But hey if you want to get stuck into it good luck :)


问:
Can AfferoGPLv3 code be used in GPLv3 code?
Can software with AGPLv3 license be used with GPLv3 project?

Can the resulting project be GPLv3, or must it have the special requirements of AGPLv3?

I am not very smart from clause 13 of GLPv3 that mentions AGPLv3.

Notwithstanding any other provision of this License, you have
  permission to link or combine any covered work with a work licensed
  under version 3 of the GNU Affero General Public License into a single
  combined work, and to convey the resulting work. The terms of this
  License will continue to apply to the part which is the covered work,
  but the special requirements of the GNU Affero General Public License,
  section 13, concerning interaction through a network will apply to the
  combination as such.

Must the resulting, combined work be AGPLv3 or not?

答: The resulting combined work would need to be AGPL. Here is a handy chart that explains many popular licensees. Arrows indicate that two licenses may be combined, and that the combined work can effectively be treated as having the license at the end of the arrow, possibly with some additional restrictions taken from the license at the start of the arrow.


问:
How do people read big technical books?
I see that most of the good programmers have the habit of reading big books for learning about technology.

What does it really take to read technical books, apart from the real interest on the technology?

How can I improve my ability to read these books?

答:
I've read about 300 books so far in my life (some with as many as 700 pages,) and I'd have to say that you have to (1) eliminate distractions, (2) find someone who is also interested in the topic so that you can tell them about what you recently learned from reading, and (3) ask yourself this question: In 3 days, do I want to have accomplished something and learned a lot, or do I want to have learned nothing, having sat in front of the TV or played video games?

Few people in America actually read non-fiction books.  I've met probably 100 people in the past six months, and although almost every single one of those people knows that I am a semi-avid reader of non-fiction books, not one person ever spoke about reading a non-fiction book, nor did I ever see one of them read a non-fiction book.  Being willing and able to read non-fiction books instantly raises my respect for someone, even if I hate the books that they like.  So few people are willing to do anything other than drink, brag, etc. that it is really quite remarkable when someone sits down and reads a book.

Title: How do people read big technical books?


问:
What is the reason behind the if syntax of CoffeeScript?
In most other languages the condition comes before the statement to be executed when the condition is met. However, in CoffeeScript (and maybe some other languages) the syntax is:

```<code>number = -42 if opposite
</code>```

Is there any online documentation of what the logic behind this design decision for this syntax was?

答:
Is it not just the fact that  (-42 if opposite) is valid expression?

Lua has something similar, so does Javascript.

Lua: a = a or b

JS: a = a || b

These are important use cases. Initialize a unless it is already initialized.

Also, in Lua you can say:

```<code>a = b and c or d
</code>```

this sets a to b unless b is nil or false in which case it sets a to d.

Body:
Is it not just the fact that  (-42 if opposite) is valid expression?

Lua has something similar, so does Javascript.

Lua: a = a or b

JS: a = a || b

These are important use cases. Initialize a unless it is already initialized.

Also, in Lua you can say:

a = b and c or d

this sets a to b unless b is nil or false in which case it sets a to d.


问:
Chambers In A Castle Algorithm
Problem Statement -

Given a NxM grid of 1s & 0s (1s mark walls, while 0s indicate empty chambers), the task is to identify the number of chambers & the size of the largest. And just to whet my curiosity, to find in which chamber, a cell belongs.

It seems like an ad hoc problem, since the regular algorithms just don't fit in. I just can't get the logic for writing an algorithm for the problem. If you get it, pseudo-code would be of great help!

Note - I have tried the regular grid search algorithms, but they don't suffice the problem requirements.

Source - INOI Q Paper 2003

答:
There is really an off-the-shelf algorithm for this: flood fill

The idea is simply to start a search (DFS or BFS) from any empty space and mark it. If you want to be able to tell the chamber for each cell, you could mark it with a chamber number and a size number, whereas the latter increments during the search. Once the search terminates due to completely filling one chamber, you know its size by the largest size-number written during the search.

You then search for any non-marked and non-wall cells and start a fresh flood fill from there with the next chamber number and size number 1 again.

Your regular grid search algorithm is basically the starting point in order to find free cells for the flood fill algorithm. Once the cells are marked, you simply continue with the same grid search to search a non-marked cell as usual.

The flood fill algorithm takes its name from its early origins in pixel-based paint tools, where it has been the basis for the bucket-fill-tools, which fill an area with the current background color. The wikipedia page linked above contains a nice animated gif to visualize the process. The only adaptations for this problem are that you need to set a size number instead of a color and watch for walls, other than that you can take the pseudocode implementation given on the linked page. But you might as well roll your own, as it is a straightforward search.

It doesn't really matter either if you do a depth-first-search or a breadth-first-search. If you implement DFS (non-tail) recursively and have a huge matrix you might end up in trouble with stack sizes. In that case, the space investment of the BFS might be preferable. Pseudo-code for both variants is given on the wikipedia page.

Note: the wikipedia page already has a nice example on the problem of when there is a 'gap' between chambers. In this problem description, it is not explained properly what a 'connection' is. In other words, from the description you do not know if you should flood 4-way or 8-way, where the latter allows for connections being made through diagonally placed walls, that share a corner, but not an edge. Common sense would dictate a 4-way flood though, as people usually don't consider mathematically point-sized doorways in their castles.

Title: Chambers In A Castle Algorithm


问:
Concept behind SHA-1 Checksum
What's the basis behind SHA-1 or SHA-2 or other Checksum algorithms?
I read about it here http://en.wikipedia.org/wiki/SHA-1#Data_Integrity

But I am still wondering about an answer in a layman's language.

Can I understand it as a very, very compressed code that can be translated back into original data?

Let's say, I have a letter written in notepad. Then the whole of my 1 A4 page size data can be converted into something like this "9b90417b6a186b6f314f0b679f439c89a3b0cdf5". So whenever I want my original data back, I can convert this back into original data?

I am very sure that I am wrong here, because it is weird how data that itself contains combination of letters and numbers can be represented by smaller set of letters and numbers. Illogical!

Then, what's the basic?

答:
SHA1/2 and many others are Hash Functions or Cryptographic Hash. The key point of hash functions is that they compute "fingerprint" from arbitrary big data and it should not be possible to:

Find a data, that has specific hash

Find 2 different data, that has same hash

Modify data, so that it will have same hash

Hashes are commonly used for data integrity checks eg. sender sends data and hash of it, receiver gets data, computes hash from them. If hashes are equal, then data were received correctly. Hashes are also used for Digital signatures, where they allow us to use awfully slow asymmetric cryptography to create non-falsible "fingerprint" of data.

Title: Concept behind SHA-1 Checksum


问:
Does UX matter for enterprise software?
I've come to notice that a lot of software that companies use for managing things like time, expenses, setting up phone systems, etc is very non-intuitive from a user experience point of view.  I know personally I waste a lot of time just trying to figure out how to navigate these systems, especially if I don't have a co-worker close by who I can bug to help me out.  The help files are usually just as bad as the user interface itself.  Are companies that complacent or are there just not any comparable enterprise products out there which do the job for these sorts of tasks?  It seems that on the consumer side there is plenty of market opportunity for creating better user experiences, but how about for enterprise software?  Obviously a certain level of slickness is not going to matter to a company, but when a better UX design translates to time saved, it's hard to argue against that.

Edit: I'm not referring to in-house applications, but rather off the shelf systems from large software companies.

答:
It matters a lot. Good UX increases productivity.

If UX is good, the company can focus on "how to do their stuff" instead of "how to use your software to do their stuff", and it takes less time to teach new workers.

And, good UX will drastically decrease the number of support tickets, so you can spend more time on resolving serious issues rather than "how to use" issues.

Title: Does UX matter for enterprise software?


问:
Should I use a parser generator or should I roll my own custom lexer and parser code?
What specific advantages and disadvantages of each way to working on a programming language grammar?

Why/When should I roll my own? Why/When should I use a generator?

答:
It depends on what your goal is.

Are you trying to learn how parsers/compilers work?  Then write your own from scratch.  That's the only way you'd really learn to appreciate all the ins and outs of what they are doing.  I've been writing one the past couple months, and it's been an interesting and valuable experience, especially the "ah, so that's why language X does this..." moments.

Do you need to put something together quickly for an application on a deadline?  Then perhaps use a parser tool.

Do you need something that you'll want to expand upon over the next 10, 20, maybe even 30 years?  Write your own, and take your time.  It'll be well worth it.

ContentLicense: CC BY-SA 4.0


答:
A hash is a one-way function to digest an arbitrary amount of data into a result. The function shall have the property that for a particular input, it generates the same output.

You could consider addition or multiplication a very horrible hashing function. Given a sum or product, you cannot uniquely determine the numbers that were added or multiplied to produce that result, but you can always given a set of numbers re-add or re-multiply them to test that your set is either probably right, or definitely wrong.

A good hash function scrambles the structure of the source data such that the resulting hash bears very little resemblance to the original data, and has properties that small changes in the input causes large changes in the result.

Title: Concept behind SHA-1 Checksum

Body:
What's the basis behind SHA-1 or SHA-2 or other Checksum algorithms?
I read about it here http://en.wikipedia.org/wiki/SHA-1#Data_Integrity

But I am still wondering about an answer in a layman's language.

Can I understand it as a very, very compressed code that can be translated back into original data?

Let's say, I have a letter written in notepad. Then the whole of my 1 A4 page size data can be converted into something like this "9b90417b6a186b6f314f0b679f439c89a3b0cdf5". So whenever I want my original data back, I can convert this back into original data?

I am very sure that I am wrong here, because it is weird how data that itself contains combination of letters and numbers can be represented by smaller set of letters and numbers. Illogical!

Then, what's the basic?


答:
Of course it matters, but companies simply learned to live with it. Instead of creating pressure through demand on developer companies to create applications with good UX, they accepted that most, if not all, business software has bad UX.

It is hard to tell if managers and businessmen see any kind of reason for good UX or are they simply ignorant of it.

Title: Does UX matter for enterprise software?

Body:
I've come to notice that a lot of software that companies use for managing things like time, expenses, setting up phone systems, etc is very non-intuitive from a user experience point of view.  I know personally I waste a lot of time just trying to figure out how to navigate these systems, especially if I don't have a co-worker close by who I can bug to help me out.  The help files are usually just as bad as the user interface itself.  Are companies that complacent or are there just not any comparable enterprise products out there which do the job for these sorts of tasks?  It seems that on the consumer side there is plenty of market opportunity for creating better user experiences, but how about for enterprise software?  Obviously a certain level of slickness is not going to matter to a company, but when a better UX design translates to time saved, it's hard to argue against that.

Edit: I'm not referring to in-house applications, but rather off the shelf systems from large software companies.


问:
What are the downsides of leaving automation tags in production code?
I've been setting up debug tags for automated testing of a GWT-based web application. This involves turning on custom debug id tags/attributes for elements in the source of the app. It's a non-trivial task, particularly for larger, more complex web applications. Recently there's been some discussion of whether enabling such debug ids is a good idea to do across the board.

Currently the debug ids are only turned on in development and testing servers, not in production. There have been points raised that enabling debug ids does cause performance to take a hit, and that debug ids in production may lead to security issues.

What are benefits of doing this? Are there any significant risks for turning on debug tags in production code?

答:
```<code>> What are the downsides of leaving automation tags in production code?
</code>```

I agree with @Sachin Shekhar R that performance and space penalty is marginal.

The only problem i can think of is that bots can use your website much easier, if there are tags on your important input and output fields. if this can become a problem or not depends on your use-case.

At least the login and the customer registeration form should be protected agaist bots.

Body:
> What are the downsides of leaving automation tags in production code?

I agree with @Sachin Shekhar R that performance and space penalty is marginal.

The only problem i can think of is that bots can use your website much easier, if there are tags on your important input and output fields. if this can become a problem or not depends on your use-case.

At least the login and the customer registeration form should be protected agaist bots.


答:
This is what I would tell someone without a computer science or programming background.

A hash is like the hand written signature of a person. But the signatures are unreadable. So unreadable that you cannot tell the name of the person just by looking at the signature. But you still can compare two signatures and decide if the same person signed two different documents.

In this analogy the data is the person, the computed hash is the signature and computing the hash is like asking the person to sign something. If you have computed the hash, you can compare it to another hash. But you have no way to know the data (from which the hash was computed) just by looking at the hash.

Title: Concept behind SHA-1 Checksum


答:
Maybe it depends who pays for the software.

Enterprise software might be bought by the IT director. They probably just look for a list of features. They'll have a hard time persuading their CEO and board to pay more money for usability.

Consumer software is bought by the consumer, or paid for by advertising. Either way, usability is very important. Otherwise the software business will die.

Title: Does UX matter for enterprise software?


答: Frank correctly points out one off-the-shelf approach. There is at least one other: disjoint set forests. This may have some benefits, as you can implement a simple data structure and then process the grid in linear order without needing to search for a new starting point.</p>

Title: Chambers In A Castle Algorithm

Body:
Problem Statement -

Given a NxM grid of 1s & 0s (1s mark walls, while 0s indicate empty chambers), the task is to identify the number of chambers & the size of the largest. And just to whet my curiosity, to find in which chamber, a cell belongs.

It seems like an ad hoc problem, since the regular algorithms just don't fit in. I just can't get the logic for writing an algorithm for the problem. If you get it, pseudo-code would be of great help!

Note - I have tried the regular grid search algorithms, but they don't suffice the problem requirements.

Source - INOI Q Paper 2003


问:
What mistakes do your users make, and how can you update your application to handle them?
In fact this question is about cautions to be taken to enhance quality user experience and reduce avoidable support calls.</p>

答: I don't think users are stupid. They don't want to use your or any program at all. All they want is to get their things done. Help them and prevent harm from happening to them along the way.</p>


问:
Time allocated to code reviews
If you are doing code reviews

How much time do you spend on code reviews, compared to implementation?

How much of the changes undergo code review?

you think it's to much / should be more?

Are there any studies about effectiveness?

[edit] thank you all for the answers, it's hard to pick a "winner" for such a question, there is lots of valuable info in the other replies, too.

答: In regards to studies, Smart Bear software will send you a small book, Best Kept Secrets of Peer Code Review, for free.  It has a number of articles in it about various aspects of code review, including studies on how much time they should take and how effective they are.</p>

Title: Time allocated to code reviews


问:
What's the problem with Scala's XML literals?
In this post, Martin (the language's head honcho) writes:

[XML literals] Seemed a great idea at the
  time, now it sticks out like a sore thumb. I believe with the new
  string interpolation scheme we will be able to put all of XML
  processing in the libraries, which should be a big win.

Being interested in language design myself, I'm wondering: Why does he write that it was a mistake to incorporate XML literals into the language? What is the controversy regarding this feature?

答:
I believe Martin explains the reasoning very well in his post:

I have always tried to make Scala a very powerful but at the
  same beautifully simple language, by trying to find unifications of
  formerly disparate concepts.

The problem many languages face when they become more and more popular is that features are wanted by the community and added on top of the language. A worst-case example of this (at least in my book) is C++, where you have pretty much everything, yet not at all in a beautiful unified manner (see for example this question arising from that).

The difficulty, when a language grows due to demands/needs from the community is to add the new features in a way that is consistent with the language's core. And in this respect, the XML literals support of Scala is a sore thumb, because this is a unique thing. It's not really part of a beautiful unified core, but has been added as a once-off solution, whereas the string interpolation is a core concept powerful enough to replace the once-off feature.


答:
Are you familiar with the concept of a normal checksum? e.g. adding up the ascii values of all the letters in a string?

Take your name:

```<code>V    I    S    H    W    A    S

86 + 73 + 83 + 72 + 87 + 65 + 83  =  549
</code>```

The problem with using something so simple to verify the correctness of a transmission is that many simply errors will leave the checksum unchanged.

e.g. if two letters get swapped around, so VISHWAS becomes VIHSWAS, the checksum will be the same.

Or if one letter is wrong and another is wrong in the opposite direction: VISGWBS

With a good hashing function like SHA-1, a small error in the transmission will result in a completely different hash. And it is incredibly unlikely that any two errors will combine to give the same hash result.

Title: Concept behind SHA-1 Checksum

Body:
Are you familiar with the concept of a normal checksum? e.g. adding up the ascii values of all the letters in a string?

Take your name:

V    I    S    H    W    A    S

86 + 73 + 83 + 72 + 87 + 65 + 83  =  549

The problem with using something so simple to verify the correctness of a transmission is that many simply errors will leave the checksum unchanged.

e.g. if two letters get swapped around, so VISHWAS becomes VIHSWAS, the checksum will be the same.

Or if one letter is wrong and another is wrong in the opposite direction: VISGWBS

With a good hashing function like SHA-1, a small error in the transmission will result in a completely different hash. And it is incredibly unlikely that any two errors will combine to give the same hash result.


问:
How to make a license apply to a whole library?
I'm creating a standard library for a programming language, and I'd like to license each and every single class or function in there under the MIT license, so they're completely FOSS.

All of the files reside in a single directory. Would it be enough to put a LICENSE.txt file in the same directory, containing the MIT license? Do I need to say that the following license applies to all features of the library, or is the library itself considered to be a program?

答:
Well, at one level the answer depends on the law of the legal jurisdiction you release your software in. So you might want to check that.

But more generally, adding a full copy of the text of the licence in the root directory of your distribution and then placing a one line comment in each source file is likely to convey your intentions very clearly.


问:
When to switch to mobile programming?
We're a team of developers working on some PC applications. But we have also witnessed a trend in the market towards writing more and more mobile sites and mobile applications.

Is it time for developers to shift to mobile programming?

答:
If it is right for your applications, then the answer may well be yes.

This might give you a new distribution channel, or may give you an edge over your competitors.

But I don't think this is a "yes or no" question.

Analyse whether this will help your application, do market research, don't just do it for the sake of doing it.

Title: When to switch to mobile programming?


答:
I had similar experiences with you. I believe the following dynamics/factors are in place with enterprise software and UI.

As stated in another answer the person that will sign the purchase of the software is different than the person that will use it and different that the person that will maintain it. So purchase is made based on "features" or some other factors.

A timeless classic read about this is Joel Spolsky's "Five Words", "internal" section: "Here usability is a lower priority, because a limited number of people need to use the software, and they don't have any choice in the
matter, and they will just have to deal with it."
There is no choice. Users cannot opt for an alternative. Additionally many times such software is developed internally, from an internal department acting as a self imposed artificial monopoly (another nice article about is this: http://37signals.com/svn/posts/2785-the-end-of-the-it-department)

Also to be honest many times it does not matter, so no financial sense to make it UI better. Examples: (1) I just use such software 10 minutes each week, not as often as my email client (an hour per day or so), which means that it does not matter that much. (2) The worst (from UX perspective) software I have used was for logging time spend, which took place once per month for five to ten minutes each month. It did not annoy me that much.

ROI of learning curve. It might be annoying to learn to use software with the UI you describe and also time consuming, but this effort will be an one-off for all the time of my employment. Usually such software stays for five or more years, so time invested (a day/two) is nothing in the long run.

Because of common long life span (have encountered a 10 year installation), it could have been state of the art when it was introduced, but looking odd to modern eyes.

Title: Does UX matter for enterprise software?


答:
Absolutely it does - only the trouble with "Enterprise" software is that it is sold entirely on feature sets, to managers who don't have to use it (or even look at it), by smarmy salesmen who know all the tricks of getting such software sold.

This is one reason why a lot of companies moved to open-source software - apart from the other reasons like cost, OSS tends to have a better UX than the enterprise stuff, which means people like to use it.

I hope this is a lesson to all the commercial software companies out there, that a good UI is a serious advantage to the product, but they'll still make shi**y UIs because it costs and provides no 'feature' benefits.

Title: Does UX matter for enterprise software?


答:
The cost of such software, both initially and set up costs tends to be very high, once implemented it's unlikely that a business will start to use it and then stop based on the UX. This won't be so true of consumer level software where the cost of switching will be less prohibitive.

This means people have to stick with stuff that would otherwise be dropped quickly from a UX perspective. Given time you will work out how the software works, good or bad and so when much further down the line when re-evaluating the product that is less of an issue than had you never used it.

That will mean that when it comes time to renew a business will be less inclined IMO to switch to something else, which in turn means the company developing the software won't need to update the UX as much as a consumer product would.

Title: Does UX matter for enterprise software?


问:
Joomla Secondary Users

Background

I have a joomla based application. My customers sign up and they register as a user on the site. My customers (primary customers) then have their own space on the site that they can then setup their own customers (secondary customer).

Question/Problem

The problem I am having is that I need to tag each secondary customer to a primary customer. I thought about just creating a new component and having a separate table that includes all the secondary customers. The problem is that I then lose out on all the authentication, session handling and login/logout that the core joomla _users component offers. I then thought about just having all the users in the core _users table and add the primary customer associated with each secondary customer to a field in a profile plugin. This would work for the most part, but this means that primary customers cannot create a secondary customer with a user name that already exists in the _users table. I didn't think this would be an issue, but several of my primary customers (currently only test users) have been confused by the site telling them a username is not available, since they can only see the names of their own secondary customers.

Any ideas on some architectural changes I could make to solve this?

答:
The login views and modules are really com_user (and mod_login via com_user) which just calls user.login (in com_user) which then calls the $app instance ('site' or 'admin') and asks it to do the login $app->login(). This in turn creates a JAuthentication object passing it the user credentials.

The JAuthentication class actually loads any active authentication plugins to perform the actual validation of the users credentials.

If the response from that authentication step is successful, then all your session data and user state gets established.

So, as you can have as many active authentication plugins as you want you could create your own version of the plugins/authentication/joomla plugin and point it at your version of the user table.

Title: Joomla Secondary Users


问:
Good practice about Javascript referencing
I am fighting about a web application script optimization. I have an ASP.NET web app that reference jQuery in the master page, and in every child page can reference other library or JavaScript extension.

I would like to optimize the application with YUI for .NET.

The question is, I should put all the libraries reference in the master page or to compress all the JavaScript code in a single file, or I should create a file for every page that contains only the code useful to the page?

Is there any guidance to follow?

答: If you put all your JavaScript into one file and use it everywhere, the browser can cache the file ond only needs to download it once.</p>


答:
The practice that I generally see followed is to put all js code in a single file, using a minimizer like Microsoft AJAX minifier or YUI compressor, and reference the file on the master page. That way you have a small file for the production version, while you can keep the code in separate files to ease development and debugging. You reference ASP.NET - Chirpy is a good VS plugin to help you manage js/css mashing and minimizing.

As for having separate files with page-specific functionality and referencing them on a per-page basis, you have to weigh the benefits of having a lighter 'main' script and the users having to download additional scripts when required versus the additional work it will take to maintain this more elaborate setup.

If you have a really 'heavy' js script required only for some seldom used functionality that only a fraction of your users will access (something like a rich text editor comes to my mind), you might see benefits in only including it where it's absolutely needed. Use your best judgement here to decide how granular you want to make your scripts.

I remember reading somewhere how it's a good practice to keep the script for your main page as light as possible, as this is the one that the users' impressions hinge on, and use a 'regular' script on other pages. I would have to look up the reference for that though.

Title: Good practice about Javascript referencing

Body:
I am fighting about a web application script optimization. I have an ASP.NET web app that reference jQuery in the master page, and in every child page can reference other library or JavaScript extension.

I would like to optimize the application with YUI for .NET.

The question is, I should put all the libraries reference in the master page or to compress all the JavaScript code in a single file, or I should create a file for every page that contains only the code useful to the page?

Is there any guidance to follow?


问:
Just how bad is it not to Dispose() SqlConnections?
Personally, I break out in hives if I don't put ADO objects that implement IDisposable in using statements.  But at my current contract, I've found that their homegrown enterprise framework "data access provider" code does not 1) implement IDisposable and 2) call Dispose() on anything it uses, at any point, ever.  Users have been complaining a great deal about performance issues in the Winforms applications that heavily use this framework for data access, and though there are a LOT of other problems in the code that could be hitting performance, this one just screams at me and is more low-hanging-fruit than the others.

So, beyond saying something like "Dispose is there for a reason, use it," what can I tell these people to convince them that this is really, really bad?

答:
If you do not call the Dispose method on a SQL Connection, when you done using it, that connection does NOT get returned back to the connection pool.

If you are having performance issues, my guess is that the maximum connections are opened on your database.  A DBA could easily confirm this.

Microsoft's Best Practice calls for you to place your connection code inside of a Using statement, ensuring the connection is disposed of and that the connection is returned back to the pool.


问:
Is there some software to manage a XP Project?
I was wondering if there's some software to manage a XP project. I'm starting a school project and I want to follow this methodology, but, we don't have a place to work. Each one works at home (in pairs), therefore I can't follow XP ambient patterns.

So, anyone knows of any software to manage this?

答:
Whilst I don't know if this strictly speaking is designed for XP Programming, I would say you should have a look at https://www.trello.com/

This will easily let you share 'cards' with your fellow collaborators, add tasks to them etc...

From their help guide:

To give you an example, our board consists of five lists ordered left to right: Ideas, Design, Development, Implemented, and Deployed. For us, a card is usually a bug or a feature. A feature card that has finished being designed will be moved from the Design list to the Development list, and so on down the line. When we push bad code, we move cards from Deployed to Development. We sort cards vertically in a list to designate priority, the top being the highest priority. The cards with bad code are usually at the top. One look at the board will tell you where a feature or bug is in the development cycle.

https://trello.com/about


答: If you develop for mobile you have to focus on the users needs because the display space is limited. This increases quality.</p>

Title: When to switch to mobile programming?

Body:
We're a team of developers working on some PC applications. But we have also witnessed a trend in the market towards writing more and more mobile sites and mobile applications.

Is it time for developers to shift to mobile programming?


问:
Architecting persistence (and other internal systems). Interfaces, composition, pure inheritance or centralization?
Suppose that you need to implement persistence, I think that you're generally limited to four options (correct me if I'm wrong, please)

Each persistant class:

Should implement an interface (IPersistent)

Contains a 'persist-me' object that is a specialized object (or class) that's made only to be used with the class that contains it.

Inherit from Persistent (a base class)

Or you can create a gigantic class (or package) called Database and make your persistence logic there.

What are the advantages and problems that can come from each of one? In a small (5kloc) and algorithmically (or  organisationally) simple app what is probably the best option?

答:
The code is very readable - you know exactly what you persist.

This reminds me of the Memento-Pattern. It is good to revert changes.

It is like 1. but for inheritence - the baseclass defines the interface. Can cause problems if you have or do not have multiple inheritence.

Databases can not save every object but only some with constraints. You care about what the object consists of.

Gemstone/S and MagLev enables to store any object. In contrast to 1-4 it uses transactions. At the end of a transaction all modified objects are persisted.

Examples

In Python and marshalling-aproaches: persistence often uses 1. to convert an object to something persistable and 3 to not implement this algorithm too often. A Marshaller like in 4. enables object-identity in persistence and recursion. (persisting an object twice creates a reference).

The Webframework Rails in Ruby use 4. and 3. to store the model of the Model-View-Controller Program. You work on copies of the original object. You have like typed object attributes.

How to start

You can begin with 1. and a toString() method.

Once you need the same algorithm again, you can use 3..

If you need to persist recursive structures or ensure object-identity introduce a Marshaller that handles that. (It is also responsable for objects whose persistence behaviour you cannot touch.)

If you have many simple objects and do not worry about identity but just about some data: use a database 4..

2. seems to be unralated and can be built in every solution.

5. if your language supports it. Use what was given.


答:
Didn't see this mentioned, but you have to think of this also...

you want people to use it. If the UX isn't good or has too high of a learning curve, not intuitive, clunky etc the end user won't want to use it and if you are designing software they are your customer. If they are happy with it chances are you'll never hear any praise about it but if they are unhappy you better expect to hear about it.

Title: Does UX matter for enterprise software?


答: I'd say the best thing you can do is point them to Microsoft's Patterns and Practices regarding Dispose() here.  Let them see the full consequences of not utilizing this tool that's right in front of them.

Title: Just how bad is it not to Dispose() SqlConnections?

Body:
Personally, I break out in hives if I don't put ADO objects that implement IDisposable in using statements.  But at my current contract, I've found that their homegrown enterprise framework "data access provider" code does not 1) implement IDisposable and 2) call Dispose() on anything it uses, at any point, ever.  Users have been complaining a great deal about performance issues in the Winforms applications that heavily use this framework for data access, and though there are a LOT of other problems in the code that could be hitting performance, this one just screams at me and is more low-hanging-fruit than the others.

So, beyond saying something like "Dispose is there for a reason, use it," what can I tell these people to convince them that this is really, really bad?


问:
How can I get my progress reviewed as a solo junior developer
I am currently working for a 2 person company, as the solo primary developer. My boss gets the clients, mocks up some png design templates and hands them over to me.

This system has been working fine and i'm really enjoying it.

The types of projects I work on are for small - medium sized businesses and they usually want a CMS system. Developed from scratch i'll build a customised backend for the client to add/edit/remove categories, tags, products etc and then output them to the front end according to the design template handed to me. As time has gone on, the projects have increased in complexity, with shopping cart / ordering features and other common e-commerce type features.

Again, this system has been working fine and i'm really enjoying it.

My issue is my personal development as a programmer. I spend a lot of my spare time reading programming blogs, checking through stackexchange, reading suggested programming books (currently on 'The Pragmatic Programmer', really good so far), doing brain exercises (lumosity.com and khanacademy math problems), doing lots of physical exercise and other personal development type activities.

I can't help but feel though, that I'm missing out on feedback, critique. My boss is great and never holds back on praise in regards to my work, but he unfortunately is either to busy to check my code, or to be honest, I don't think it's one of his specialties and so can't provide feedback.

I want to know what i'm doing wrong and what i'm doing right. Should I be putting that much logic in the controller, am I modulating my code enough etc.

So what I have done is developed a little 'Family Budgeting' app and tried to do it as cleanly and effectively as I currently know how.

What i'm wanting to know is, is there somewhere I can submit this app, and have some seasoned developers provide feedback. It's not just a subsection of my code like 'codereview.stackexchange' appears to require, it's my entire workflow that I want critiqued.

I know this is a lot to ask, and I expect the main advice given will be to look for a job within a team, which is certainly something I will look into later down the track, but for now I want to persist with my current employment situation, but just don't want to develop too many bad habits.

Let me know if I can provide any further information to help clarify, or if this isn't the right place for this type of question I apologise in advance. Didn't want to use reddit as I felt this community fosters more well thought out responses.

答:
Le me share my opinion, some words of wisdom and some questions for you to reflect upon.

Being an experienced programmer I have found over the years that best code is the one that is simple (look at KISS concept)and easier to be modified by another programmer.

Also, leaving adequate space for the code not to be congested (breathing space) and evenly structured. Use a well known naming convention for your variables, giving them understandable names (that another programmer can understand) and writing comments that are to the point, not too much and not too little.

If you follow the above you are already on a good road.

Moreover, since developers are something like architects I will give you a very important saying that you should reflect upon;

“Perfection is achieved, not when there is nothing left to add, but when there is nothing left to take away” – Antoine de Saint-Exupery.

and

"Striving for excellence motivates you; striving for perfection is demoralizing" - Harriet Beryl Braiker.

However,

"Many events, roughly 80% of the effects come from 20% of the causes" - Pareto principle

With the above I want you to understand that there is a fine balance between effort and effect, cost and quality.

And the questions to reflect upon;

What do I like to be doing in five years ahead from now?

Will the effort improving my coding skills benefit my professional career in the long run?


问:
How to get audio spectrum analysis?
I need to find or create a tool that analyzes the audio spectrum of a sound file (like a .wav or .mp3). I need to output the "volume" or power of x number of frequency bands and output the data as text. This will be used to produce a visualization, a graphic equalizer like you'd see on a stereo.

I am currently looking at python to do it. My question is are there some tools out there that would do this (signal processing), like math works or others? I don't have any experience with them so any advice would be appreciated.

答:
Similar to Robert Harvey's comment, you'll want to look for a Fast Fourier Transform with python.

There is an SO question that discusses the output from one of the algorithms and how to interpret it.

Here's the numpy module which came up second in my search.  So it looks like you shouldn't need to do much coding at all.

This link will point you to some other implementations.

And here's a wordpress blog that provides some background on the FFT as well as using the numpy module.

And as jk points out: "you may need a Window Function as well to smooth out spectral leakage."

Title: How to get audio spectrum analysis?


问:
Integrating feature request functionality directly into the business software you write?
What are relative merits of something like a button on a piece of custom bizware that says, "press me to ask for a feature" or "click here if something didn't work right".

The problem I'm trying to remedy is the general lack of formality surrounding feature requests.  Most specifically, the rate at which I receive walk-ups from end-users.  Taken one at a time, it can be beneficial, but sometimes it can hinder productivity on the larger scale.

Has anyone done something like this and has it been a general success or alternately somewhat a waste of time.  My instincts are not giving me a hint here.

答: There are several web sites which you can use for feedback like http://uservoice.com. Just create an account in any of them and include a link in your application.</p>


问:
Switch interface implementation using configuration
We want to allow the same core service to be either fully implemented or, as other option, to be a proxy toward a client legacy system (via a WSDL for example).

In that way, we have both implementation (proxy & full) and we switch which one to use in the configuration of the app.

So in a nutshell, Some desired features:

Two different implementation (proxy, full) instead of one implementation with a switch inside

Switch implementation using configuration: dependency injection? reflection?

Nice-to-have: the packaged delivered to the client doesn’t have to change depending on the choice between proxy or full

Nice-to-have: Client can develop their custom implementation of the Core Interface and configure the applciation to use that one

With this background, the question is: What alternatives we have to choose one implementation or other of an interface just changing configuration?

Thanks

答: Both dependency injection and abstract factory are perfect for this. You have two implementation of one interface IService where one is implemetation itself and another is proxy. Depends on actual configuration you could either inject or construct one or another. Implementation using abstract factory is much easier: all logic to determine what to build is inside factory. To achieve this with dependency injection you could start with Composition Root, afterward define configuration for instance creation (full or proxy). This is much harder by flexible way to achieve required behaviour.


答:
It depends on how you want to do it.

Proxy pattern would enable you to switch implementation internally without exposing the details to anything else in your application. Hence you could at any time switch implementation without letting anything else in the code be aware of the switch.

Factory pattern: Let the factory decide which implementation to create (by using a config file or factory arguments). Unlike proxy you can't switch implementation once a class have received a created objected.

Title: Switch interface implementation using configuration

Body:
We want to allow the same core service to be either fully implemented or, as other option, to be a proxy toward a client legacy system (via a WSDL for example).

In that way, we have both implementation (proxy & full) and we switch which one to use in the configuration of the app.

So in a nutshell, Some desired features:

Two different implementation (proxy, full) instead of one implementation with a switch inside

Switch implementation using configuration: dependency injection? reflection?

Nice-to-have: the packaged delivered to the client doesn’t have to change depending on the choice between proxy or full

Nice-to-have: Client can develop their custom implementation of the Core Interface and configure the applciation to use that one

With this background, the question is: What alternatives we have to choose one implementation or other of an interface just changing configuration?

Thanks


答:
In any serious application I would say that it is pretty bad. Not only will leaving these objects float around kill performance, it is also simply unprofessional. The good news is that Microsoft implements Finalize in the object hierarchy.

```<code>~Object()
{
    this.Dispose(false);
}

public void Dispose()
{
    this.Dispose(true);
    GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
    // ...
}
</code>```

Take System.Data.SqlClient.SqlConnection for example:

```
System.ComponentModel.Component <strong><-- Implements the Finalize dispose pattern.</strong>
    |
System.Data.Common.DbConnection
    |
System.Data.SqlClient.SqlConnection
```

The objects will eventually be disposed but the non-deterministic nature reaks havoc on performance.

Body:
In any serious application I would say that it is pretty bad. Not only will leaving these objects float around kill performance, it is also simply unprofessional. The good news is that Microsoft implements Finalize in the object hierarchy.

~Object()
{
    this.Dispose(false);
}

public void Dispose()
{
    this.Dispose(true);
    GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
    // ...
}

Take System.Data.SqlClient.SqlConnection for example:

System.ComponentModel.Component <-- Implements the Finalize dispose pattern.
    |
System.Data.Common.DbConnection
    |
System.Data.SqlClient.SqlConnection

The objects will eventually be disposed but the non-deterministic nature reaks havoc on performance.


答:
An IoC container which loads its configuration from an xml-config-file can do this.

If you are using java you can use spring-ioc for this.

The java config file for the Full service might contain this

```<code><bean id="catalogService" class="com.mycompany.myproduct.MyFullCatalogService" scope="singleton" />
</code>```

If you want to use the proxy version

```<code><bean id="catalogService" class="com.mycompany.myproduct.MyProxyCatalogService" scope="singleton" />
</code>```

Your main application just asks the container for id="catalogService" to get the current service.

Body:
An IoC container which loads its configuration from an xml-config-file can do this.

If you are using java you can use spring-ioc for this.

The java config file for the Full service might contain this

<bean id="catalogService" class="com.mycompany.myproduct.MyFullCatalogService" scope="singleton" />

If you want to use the proxy version

<bean id="catalogService" class="com.mycompany.myproduct.MyProxyCatalogService" scope="singleton" />

Your main application just asks the container for id="catalogService" to get the current service.


问:
Does UX matter for enterprise software?
I've come to notice that a lot of software that companies use for managing things like time, expenses, setting up phone systems, etc is very non-intuitive from a user experience point of view.  I know personally I waste a lot of time just trying to figure out how to navigate these systems, especially if I don't have a co-worker close by who I can bug to help me out.  The help files are usually just as bad as the user interface itself.  Are companies that complacent or are there just not any comparable enterprise products out there which do the job for these sorts of tasks?  It seems that on the consumer side there is plenty of market opportunity for creating better user experiences, but how about for enterprise software?  Obviously a certain level of slickness is not going to matter to a company, but when a better UX design translates to time saved, it's hard to argue against that.

Edit: I'm not referring to in-house applications, but rather off the shelf systems from large software companies.

答:
In the absence of good UX, software that is merely useful will catch on, because people need to get their work done.

Useful and usable software will trump useful but hard-to-use software--if users get a choice (and if the difference is big enough to get over the 'familiarity' hump). But with Enterprise applications, you usually have a captive audience, and the users are NOT the ones making a purchase decision.

So, yes, UX matters, and its importance can be hidden behind conflated factors like price, familiarity, and inertia.

Title: Does UX matter for enterprise software?


答: Unfortunately, the definition of "good" in many cases turns out to be "what looks slick in a demo".  I used to work on enterprise systems, and most of the UX design docs ran along the lines of "make this work like Facebook/Twitter/Angry Birds".  We had some incredibly popular features in the last system I worked on that were absolutely horrible -- expensive to generate in terms of system resources, and very simplistic in terms of capabilities.  However, they showed data as diagrams that you could click on, and the diagrams moved and rearranged themselves on the screen as you worked with them.  Time for an experienced user to reconcile an invoice tripled (at least), but it looked so cool in demos that we won lots of sales based on it.</p>

Title: Does UX matter for enterprise software?


答:
I write enterprise software and UX matters to me and my team an awful lot, but in my experience UX has not been as important a factor as it should on the sales side.

Typically the people signing the cheque to pay for the software are not the people using it, so what they're interested in is not ease of use but that their high-level actions are defensible.

If you're the executive whose job is on the line if the software 'fails' then you don't really care about UX, you care about being able to say that you bought it from a well known name. You care about a feature list, the contract and your job; everything else is a distant second.

The decision maker on which product a company is going to buy will get sent all sorts of free stuff (I've seen things like a Ferrari for a week). They may also be answerable to shareholders (or even voters) who generally want big IT deals to go to companies they've heard of (which is why enterprise companies like IBM and SAP advertise heavily).

Meanwhile the developers don't use the software either. They're part of a huge team and they're working off a list of features to complete, but often they don't really understand how anyone would use that software in the real world. Most enterprise software is Themware. Note that those developers may well be excellent, they're just isolated from the users.

All that said it does appear to be getting better. Companies are dog-fooding more and are beginning to understand how important UX is in the long term success of big IT projects.

I've pushed UX in terms of how much it saves in staff training and the real cost savings of reduced support (fewer calls for help). There's a constant balance between adding the new functionality that might win new business and making our existing functionality as easy and obvious to use as we can. A healthy balance for us (I think) but it's easy to see how that could get out of whack.

Title: Does UX matter for enterprise software?


问:
Should developers be responsible for tests other than unit tests, if so which ones are the most common?
I am currently working on a rather large project, and I have used JUnit and EasyMock to fairly extensively unit test functionality. I am now interested in what other types of testing I should worry about. As a developer is it my responsibility to worry about things like functional, or regression testing? Is there a good way to integrate these in a useable way in tools such as Maven/Ant/Gradle?  Are these better suited for a Tester or BA? Are there other useful types of testing that I am missing?</p>

答:
It is your responsibility to strive to deliver defect-free code. You should write, help write, or ensure tests get written or performed in order to give you confidence in the code you are delivering.

Note: I'm not saying you are required to deliver defect-free code. Rather, you should attempt to write the best code you can for the requirements you were given. Part of being able to do that means the code should be tested.

Whether that means you are personally responsible for functional and regression tests is mostly a function of how your company is organized. All of the highest skilled programmers I know don't ask themselves "is it my responsibility to write tests of type X?". Instead, they ask themselves "what must I do to make sure my code is properly tested?". The answer might be to write unit tests, or to add tests to the regression, or it might mean to talk to a QA professional and help them understand what tests need to be written. In all cases, however, it means that they care enough about the code they are writing to make sure it is properly tested.

Bottom line: you should be responsible for delivering high quality code. If that means you need to write some functional or regression tests, do it.


问:
How to implement Scrum in a company with three similar web-based products
I am somewhat familiar with the concepts and benefits of Scrum. With that in mind, I am trying to improve the failing Scrum product management structure of a company I'm now working for that has three separate B2C products, catering to the same demographic and accessible on the same website. Each product has a product owner and a unique development team (5 - 9 people in each) behind it.

Given that the target audiences are similar (not sure if it should matter) and the 3 web products are similar in nature, what are the potential benefits/risks associated with merging the teams and having just one product owner/scrum master/dev team? Some questions that come to mind are: does it make sense to have 3 product owners and three distinct backlogs if your website has three distinct products? Also, if you only have one product owner, what is the best metric off which to choose who that will be?

答:
Merging the teams would be a bad idea. You would have way too many devs for an effective Scrum team and have to split up again anyway, you would also have to balance concerns between the three websites so one site never monopolizes time.

You need to look at each individual team and determine why that team is failing and fix it. Consolidating the teams is just consolidating failure and will bring even more problems. It could be the only thing you actually need is a subset of people to be part of an overall Scrum team that manages the 3 teams so you truly have a Scrum of Scrums.


答:
As a developer I consider myself to be responsible for unit testing all my code and guarantee to the best of my possibilities that it has no defect. That's why we have so much tools at our disposal such as mocking. The goal of creating mocking objects in your tests is exactly to try and isolate your code from the "outside" world and guarantee that it's working fine and if there's anything failing, "it's not your fault".

That being said, despite the fact that it's not your fault and that your code is working as it should, that doesn't mean you can't help in the rest of the tests. I believe it's also your responsibility to help and integrate your work on the work made by others. IT Development teams should work every time as a well oiled machine, working together with other departments (like QA) as a bigger team to provide reliable software.

But that's the work of a team, not only yours.

Title: Should developers be responsible for tests other than unit tests, if so which ones are the most common?

Body: I am currently working on a rather large project, and I have used JUnit and EasyMock to fairly extensively unit test functionality. I am now interested in what other types of testing I should worry about. As a developer is it my responsibility to worry about things like functional, or regression testing? Is there a good way to integrate these in a useable way in tools such as Maven/Ant/Gradle?  Are these better suited for a Tester or BA? Are there other useful types of testing that I am missing?</p>


答:
This might help you:

Q1 are written by the developers.

Q2 are automated by the developers and written in collaboration with the business and/or testers.


问:
Solutions for "Maintenance Mode"
Given a web application running across 10+ servers, what techniques have you put in place for doing things like altering the state of your website so that you can implement certain features.

For instance, you might want to:

Restrict Logins/Disable Certain Features

Turn Site to "Read Only"

Turn Site to Single "Maintenance Mode" page.

Doing any of the above is pretty trivial. You can throw a particular "flag" in an .ini file, or add a row/value to a site_options table in your database and just read that value and do the appropriate thing.

But these solutions have their problems.

Disadvantages/Problems

For instance, if you use a file for your application, and you want to switch off a certain feature temporarily, then you need to update this file on all servers.  So then you might want to look at running something like ZooKeeper, but you are probably overcomplicating things.

So then, you might decide that you want to store these "feature" flags in a database. But then you are obviously adding unncessary queries to each page request. So you think to yourself, that you will throw memcached in to the mix and just cache the query. Then you just retrieve all of your "Features" from memcached and add a 2ms~ latency to your application on every page. So to get around this, you decide to use a two tier-cache system, whereby you use an inmemory cache on each machine, (like Apc/Redis etc). This would work, but then it gets complicated, because you would have to set the key/hash life to perhaps 60 seconds, so that when you purge/invalidate the memcached object storing your "Features" result, your on machine cache is prompt enough to get the the new states.

What suggestions might you have? Keeping in mind that optimization/efficiency is the priority here.

答:
There can be many answers here for the way you state the question, all correct that could potentially produce the same result.

Configuration management as stated in another answer.

Switch board pattern. You can have a database table for configuration with "server name", "configuration" and "value" fields. Before each operation a check could ensure that the operation is permitted. Results can be cached locally for performance.

Continuous Deployment: switching off things fast from source control/CI system.

Generally it would be easier to suggest the optimal solution if the rationale for doing so was known.

Title: Solutions for "Maintenance Mode"


答:
Are there other useful types of testing that I am missing?

There is acceptance testing for which I'd recommend BDD-style frameworks which use Gherkin language: JBehave (Java), Cucumber (Ruby), Behat (PHP), etc. This type of testing has some advantages over unit tests:

Tests are easily readable by non-developers, so you can show them to customers

Tests clearly describe business processes without going into implementation details (I don't mean implementation is not important - it sure is - but it's better when you separate business requirements from the code itself)

Tests do things which users will do using your application

They are easier to write (IMHO, may depend on the language and framework): no mocking, less technical details


答: I believe it is our (a developer also) responsibility to encompass all possible test scenarios before it is released for QA. The purpose of QA is to validate the software. Plus, hammering your own code for errors will always make you look good come QA time.


答:
I prefer the leverage of RequireJS. Takes a little bit of getting used to, but I believe your use case lands in the RequireJS wheelhouse.

I prefer this approach because it sort of combines your two decisions into one... RequireJS will load only the javascript you require (a file for every page, if you like), and it will load them in one HTTP request.

In short, it condenses all of your modular javascript code into one file for low overhead.


问:
When to update jQuery?
When you recommend updating jQuery/jQuery UI? Or in other words: what are the best practices for updating jQuery/jQuery UI?

I’m working on a long project that will take at least one more year. In that time span, I’m sure that jQuery/jQuery UI will be updated many times.

Do you recommend update my jQuery/jQuery UI files every time an update is released? Or is better to stick with a particular version until the end of the project?

I’m afraid of “breaking” code changes, and every time an update is released, I have to test everything. That takes too much time. But on the other hand, if I didn’t update, I’m afraid of bugs that later will bite me in the rear.

The project is an ASP.MVC and I use jQuery a lot.

Any thoughts?

答:
In my experience, new versions of jQuery are generally more rigorous in their code cleanliness requirements regarding the calling code (your code).

There are numerous items that have been made deprecated ( http://api.jquery.com/category/deprecated/). There is no deprecated-since tag on the page, unfortunately. Older deprecations are more likely to break something.

Most notably (to me), the :checkbox selector and the toggle() function have been  deprecated. Some time ago, this change has  affected my own (oldest) jquery code. I did not this realize for a while.

On the other hand, newer jQuery releases usually come with substantial performance improvements. Check the changelogs, or maybe one of John Resig's presentations to see where the performance improvements were realized. If you would get any benefit from them... that's up to you to decide.

OwnerDisplayName: epaulk

Title: When to update jQuery?


问:
How to create a manager class without global variables nor singletons?
I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc...

At first, I wanted to make a global variable that simply contains an instance of my manager class. I found this question: https://stackoverflow.com/questions/4646577/global-variables-in-java. However, the users there seem to recommend to never use global variables.

Fine then, I once heard about Singletons, so I though I could use that instead. I mean, creating just one instance of my manager class sounds good. However, I found this other question: When is Singleton appropriate?, which basically tells me that Singletons are, in most scenarios, some kind of anti-pattern.

Now I am a bit lost - what other approach can I take to create my manager class, whose only requirement is to be accessible from anywhere?

答:
whose only requirement is to be accessible from anywhere?

Did you actually read those two questions?

Having anything accessible from anywhere is design pitfall #1. It tightly couples your manager to your code, preventing that from being as flexible as it needs to be, making the code hard to test, hard to debug, hard to make concurrent...

No. If you must have a manager (I don't personally believe strongly in the link, but it's worth noting) then the app should make one and pass it into whatever needs a factory/manager for your textures/etc.


答:
Who better than a developer to know what test cases are the most relevant.
The developer should be responsible for doing all the  unit testing, where possible the developer should help to write and execute the testing scripts. Since this seldom possible in large projects time should be given for the developer to review all test cases. In addition the developer should have knowledge and use the wide variety of automated test tools available.

In my development career I find that projects end up with better outcomes were there is a tight integration between the development teams and the test teams.

at least one member from each team should sit in on the others planning and implementation meetings also.


答:
I suggest you look into using a dependency injection framework to achieve inversion of control.

Your "Manager" would not be a traditional Singleton, but you would only create one through the framework configuration. The "Manager" would also not be global, but every component that would need to use it would have it assigned.

Title: How to create a manager class without global variables nor singletons?

Body:
I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc...

At first, I wanted to make a global variable that simply contains an instance of my manager class. I found this question: https://stackoverflow.com/questions/4646577/global-variables-in-java. However, the users there seem to recommend to never use global variables.

Fine then, I once heard about Singletons, so I though I could use that instead. I mean, creating just one instance of my manager class sounds good. However, I found this other question: When is Singleton appropriate?, which basically tells me that Singletons are, in most scenarios, some kind of anti-pattern.

Now I am a bit lost - what other approach can I take to create my manager class, whose only requirement is to be accessible from anywhere?