问:
One-line functions that are called only once
Consider a parameterless (edit: not necessarily) function that performs a single line of code, and is called only once in the program (though it is not impossible that it'll be needed again in the future).

It could perform a query, check some values, do something involving regex... anything obscure or "hacky".

The rationale behind this would be to avoid hardly-readable evaluations:

if (getCondition()) {
    // do stuff
}
```

where getCondition() is the one-line function.

My question is simply: is this a good practice? It seems alright to me but I don't know about the long term...

答: Moving that one line into a well named method makes your code easier to read. Many others have already mentioned that ("self-documenting code"). The other advantage of moving it into a method is that it makes it easier to unit test. When it's isolated into it's own method, and unit tested, you can be sure that if/when a bug is found, it won't be in this method.</p>


问:
What is the best way to design a web site to be highly scalable?
For websites that need to be highly scalable, such as social networks like facebook, what's the best way to design the website?

Should I have a web service which the site queries to get data that it needs?

or

Should the site query databases directly? (can be done using built in language constructs to fill tables automatically etc).

I would think the web service is the better design since it gives centralized data access and things like caching and the like become much easier to control, but what do others think?

答:
Any additional step in connecting to the database, is just an overhead. For example, between UI -> Business Facade -> Business -> Data Access -> Database and UI -> Database, the second approach is faster. However, the more steps you remove, the less maintainable your system becomes and the more duplication appears. Imagine writing the necessary code to retrieve the list of friends in profile, home page, fiends management page, etc.

So, you should make a balance here between higher performance (which of course directly affects higher scalability) and better maintainability.

But, don't get limited to database connection topic when you think about creating highly-scalable web sites. Consider these items too:

Choosing the right platform (PHP is faster because of its scripting nature, but ASP.NET needs to compile the requested file on the fly to process it and serve something. Also node.js is claimed to be more scalable, because of its callback-based architecture)

Using RESTful architecture instead of web service model (SOA)

Using JSON for data transfer instead of XML (which results in less bytes to be transfered)

Following Yahoo's performance guidelines

Network and hardware topics like load balancing, or tier architecture

ContentLicense: CC BY-SA 3.0


问:
How can I find the root of confusing problems?
Several times after posting over at Stack Overflow, I have found that the problem I have is somewhat specific, and may have issues rooted elsewhere in my code. These are very difficult to solve with a question, and I often end up getting poor or irrelevant answers.

When a problem is just too localized or to complex for Stack Overflow to be any use, what should I be doing to break down the problem so it can be solved? How can I approach peers or user groups about problems like these?

答:
I believe you are not investing enough time in debugging and moving around the code you build and quickly jumping into a conclusion that its not working due to MethodA. As an SO user is unaware of what the other things are the only way is to infer from the details/code you have provided which could be wrong and at times misleading.

First you need to be sure as to what is causing the problem even in case you realise it latter update your question with the relevant facts. Jon skeet has mentioned few guidelines on how to go about for a question

Hope this helps and you get better results from SO, avoid the urge to immediately ask it and take some time on your own.(this is how all those SO veterans have learned)


问:
SLF4J vs LOG4J Which one to prefer?
I have seen this question but does not answer me.

It have a brand new project. I have almost always used Log4J but now I am seeing SLF4J making some waves. What is it that Log4J could not do and we needed SLF4J? Is it really an upgrade. Should I use it in a project which will also have an API for other to extend upon?

答:
slf4j is an API designed to give generic access to many logging frameworks and then with a lot of glue code allowing existing code to be used easily.    Which one you use, is then decided at deployment time, not when you write your code.

Best practice today is to use slf4j to for your own log statements, and then choose the appropriate backend for it.  Here log4j.

The primary reason for migrating is that you get {} in your message strings allowing you to skip the ifDebug() { log("...") } construct.

Title: SLF4J vs LOG4J Which one to prefer?


答:
The problem I have is somewhat specific, and may have issues rooted elsewhere in my code. It seems to me you are unable to understand the problem in first place. This situation mainly arise when we expect an error to occur because of one reason and if that reason is not the source for error, we jump to the conclusion that it's bit overwhelming problem and cannot be explained in words.

To avoid such things, i would suggest you to keep your mind open to all the errors that can happen within a code and try them one by one. Identifying the problem is a major concern which can only be done on your end. You should give some time to understand debugging and tracing fundamentals because if they are learnt you won't have any problem which is unreachable or out of words.

And once you have the problem in hands, I am sure SO is sufficient enough to solve ANY problem in coding. Cheers :-)

Title: How can I find the root of confusing problems?

Body:
Several times after posting over at Stack Overflow, I have found that the problem I have is somewhat specific, and may have issues rooted elsewhere in my code. These are very difficult to solve with a question, and I often end up getting poor or irrelevant answers.

When a problem is just too localized or to complex for Stack Overflow to be any use, what should I be doing to break down the problem so it can be solved? How can I approach peers or user groups about problems like these?


答:
Develop a simple website and let it reach some traffic level. Along the lines you will learn how to make scalable websites.

Until you face the problem, you can't think of solution.

Trust me once you have the site rolling and facing requirement of scaling, you will definitely know how to do that. :-)

Title: What is the best way to design a web site to be highly scalable?

Body:
For websites that need to be highly scalable, such as social networks like facebook, what's the best way to design the website?

Should I have a web service which the site queries to get data that it needs?

or

Should the site query databases directly? (can be done using built in language constructs to fill tables automatically etc).

I would think the web service is the better design since it gives centralized data access and things like caching and the like become much easier to control, but what do others think?


答: Develop your site using a technology platform which has completely integrated support for the cloud.</p>


问:
Can GPL-licensed software be resold?
My research group is developing some software for research purposes. The project leader wants the software to be open source and likes the GPL, but wants to ensure that they software cannot be sold.

Are we reading the GPL correctly? The software can be freely modified, (re)distributed, and sold? If so, I see why it would be difficult to effectively sell the software; however, the GPL isn't quite strict enough for our needs.

Any suggestions?

答:
Make your software proprietary and publish the source code online with a click wrap license which prohibits from compiling the source and selling it.

That should do.

Title: Can GPL-licensed software be resold?


问:
is it realistic to make use of HTML5 local storage to store CSS, and JavaScript
The idea is to make use of HTML5 local storage to store frequently accessed CSS and JavaScript.

For example (pseudo-code):

```
var load_from_cdn = true;
if (detect local storage)
{
  if (cache of css, js found)
  {
     load the local storage cache
     load_from_cdn = false;
  }
}
if (load_from_cdn)
{
   document.write('<script>...');
}
```

Is this possible or realistic?

I do aware browser cache, there will be still some header access checking,

I assuming no HTTP access is better (in my thinking)

PS : It seems that local storage only support key-value pair, can someone prove it ?

(best with some examples)

答:
It is absolutely OK to use local storage to store JS and CSS. However, local storage has 5M per domain limitation. You might have to reconsider this strategy.

For desktop web, you can leverage default browser cache to do the trick. Just set the JS & CSS HTTP response to be cacheable. It is simple and easy.

For mobile web, latency is high. So, reducing HTTP requests is critical. So, having JS & CSS in external URL's is optimal. It would be much better to have JS & CSS inline. This reduce HTTP requests, but bloated the HTML content. Then What? Just as you said, use local storage!

When one browser visits the site for the first time, JS & CSS are put inline. The JS also has two more jobs:
1) Store JS & CSS into local storage;
2) Set cookie to flag that JS & CSS are in local storage.

When the browser access the site for the second time, server got the cookie and know that the browser already have related JS & CSS. So the render HTML has inline JS to read JS & CSS from local storage and insert into DOM tree.

This is basic idea how bing.com mobile version is created. You may need to put JS&CSS version control into consideration when implement it in production.

Thanks


答:
As said SLF4j is only a logging API/interface, it does not directly replace log4j which is a complete logging framework (with configurable appenders, filters, …) but replaces Commons Logging as a framework-agnostic API for logging.

SLF4j can be configured to use log4j as a logging backend so they can work together. However a quite closely related project is logback (http://logback.qos.ch/). Logback is a replacement for Log4j: it is a logging framework (as Log4j) but it uses natively the SLF4j API.

SLF4j has some useful companion JAR files which can be used to make other logging API delegate to the SLF4j API : jcl-over-slf4j (replacement API compatible with commons logging), jul-to-slf4j (for java.util.logging), log4j-over-slf4j (API compatible with log4j). Using those you can have a lot of logging API talk forward to SLF4j (useful for third-party JARs) so that you have a single logging framework handling all logs.

The SLF4j API supports the "MDC" feature of log4j/logback (which is not availablog in the Commons Logging API) so you can use this feature in your project without depending on a specific framework. You probably can replace log4j calls with SLF4j calls in your code (unless your using other features such as NDC) but you will probably still want to ship log4j or slf4j as a backend for the SLF4j API.

Title: SLF4J vs LOG4J Which one to prefer?

Body:
I have seen this question but does not answer me.

It have a brand new project. I have almost always used Log4J but now I am seeing SLF4J making some waves. What is it that Log4J could not do and we needed SLF4J? Is it really an upgrade. Should I use it in a project which will also have an API for other to extend upon?


问:
Has JPA replaced CMP?
No question too stupid right :)

Came across this on wikipedia

The Java Persistence API replaces the persistence solution of EJB 2.0
  CMP (Container Managed Persistence).

My understanding was the CMP is still there i.e Pooling,Transactions etc can be done via CMP where as JPA is ORM for me. I did not think there are even same thing . I thought may be CMP VS JTA might make sense but obviously not.

I know how off track I am but thats why I am here may some can help me get things in perspective.

答:
CMP is still there in that an app using CMP and entity beans will still work on a Java EE 6 server, but they are considered deprecated. So the statement you cited is true: CMP is being replaced by JPA.

My understanding was the CMP is still there i.e Pooling,Transactions etc can be done via CMP

Neither connection pools nor transactions have anything to do with CMP. In fact, there is a completely separate expression for the latter: Container Managed Transactions (vs. Bean Managed Transactions).

CMP never was anything but a kind of overengineered and underperforming ORM.

Title: Has JPA replaced CMP?


问:
Why do some websites allow editing a post/blog-entry for a limited amount of time only?
There are numerous websites that allow users/visitors to post content (such as comments to blog posts or news). The published post can be edited by the poster, but only for some amount of time (typically in the order of minutes). After that, the "Edit" button no longer appears and the post can't be edited.

My question is: what's the rationale for this behaviour? If it is technically possible to let the users editing their posts, why not offering this feature indefinitely?

答:
Quick example could be facebook where someone posts "Who loves kittens?" loads of people like and comment on it over time.

They then change it to "Who wants to murder kittens?"


答:
We discussed this behavior once among our developers and came to the conclusion that the only valid reason for this could be, to conserve the consistency of the posts.

Consider the Stack Exchange sites for example. Sometimes I come across a comment saying:

What did you mean by x

However, when I read the question 10 times, I don't see x anymore. This means the break of referential integrity. In other words, sometimes you refer to something, which can be deleted or completely changed later. This is not good IMHO.

Title: Why do some websites allow editing a post/blog-entry for a limited amount of time only?

Body:
There are numerous websites that allow users/visitors to post content (such as comments to blog posts or news). The published post can be edited by the poster, but only for some amount of time (typically in the order of minutes). After that, the "Edit" button no longer appears and the post can't be edited.

My question is: what's the rationale for this behaviour? If it is technically possible to let the users editing their posts, why not offering this feature indefinitely?


答:
Not sure the question belongs here, but I might as well try answering it.

The reason for this is basically, that you don't want posts/comments to change once they have been responded to. For example on stackexchange, there is no such limitation on answers, therefore you do have quite a number of comments, that seem to make no sense, simply because the answer was edited ever since.

Now on SE this is not such a big deal, because for one, you can see the edit history to understand an obviously outdated comment, but more importantly, because SE is not a place for discussion. In a discussion, being able to change what you said can basically destroy the whole discussion. It invites moving the goalpost and many other manipulations, even after the discussion actually would have been concluded.


答:
Simple answer:  It's difficult to hold a conversation in a forum when comments are not sorted chronologically.  When people are able to edit their comments after there have been replies, this often leads to people modifying their posts to reply to the responses posted later.  This can quickly make the discussion thread impossible for new readers to follow.  (Indeed, it's difficult even to determine what comments are new, when changes can happen anywhere in the thread!)

Limiting edits promotes serial comments, where each new post chronologically follows the previous, so that others can follow the thread of the discussion simply by reading from start to end.

The usual reason for allowing a short period where someone can perform edits is to let them fix typos or broken markup that they only notice immediately after posting.


答:
Comprehension

the fastest route is comprehension. that's a skill you will need, and it develops with experience.

rather than "help! i don't understand my program/problem", work through it.

programming is really quite simple. most things just resolve to true or false. the number of large problems which cannot be simplfied to those that can be further simplified is very low (in programming).

write your program to detect its mistakes (and immediately correct the issues). ideally, this would be done as you go. simplify your program - not in functionality, but in its interactions; reduce or localize the complexity of your classes, functions, etc..

i write programs as though i am more or less an idiot - my programs are throughly defensive and simplified. this helps detect issues and serves as documentation. the end result has very few bugs because the problems are localized to the callsite, and more importantly they are detected very early on.

so now it's code review time for you: start with the problematic areas and add a bunch of sanity checks (e.g. assertions), then write unit tests - fixing as you go. then you learn what goes wrong and why it goes wrong, and you will understand the problems you face and how to approach them easily (programmer errors have a way of repeating themselves).

leaving you with a quote: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan


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

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

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

答:
You not gonna believe me, but flash and (in a little bit java applets earlier) made a huge contribution in growth of popularity of javascript and the to evolution of the language itself.

When flash came up to the scene, it was the first evidence that web applications is something worth to think about.

In some sense competition with plugins, constant attempts to show - look what we can do without plugins made javascript a language with a wider spectrum of applications, and, therefore, made it popular.

ContentLicense: CC BY-SA 2.5

Title: How did JavaScript become popular?


问:
Schemes to resolve deadlocks
I am interested in research that detects and recover from deadlocks. In other words the system is able to recover from deadlock faults. I'm interested in shared memory multicore processors. Uptill now I have only seen research for distributed systems. Can anyone guide me on this.</p>

答:
I'm not sure what do you mean by recover, because since you're in a deadlock - you're obviously in a state where two threads depend on each other to complete their current tasks. So the recovery would be for one of them (or both...) not to complete the task.

In many cases, especially in embedded event-driven systems the detection is done through hardware watchdog that reboots the system. This can be considered as a recovery mechanism.

You can of course be less rigorous and instead of rebooting the system, shut down one of the offending threads (or all of them) and restart them, making sure that the deadlock situation can be avoided in the future (purging the bad input for example).

Or you can just unlock the blocking call and let the threads run with (potentially) corrupt data. Again, depends on your system and the reasons for deadlock.

Bottom line - watchdog (hardware, or software) is the solution, but if you're using the software version - you need to make sure that it itself is never locked out (i.e.: run on a dedicated CPU for example).

Ah, and the best of all is of course not to get into a deadlock situation entirely. You can verify your code using model checking or simulations, but it is of course easier said then done, even if you verified the model, you might still have bugs in the actual code implementation....

OwnerDisplayName: MetallicPriest

Title: Schemes to resolve deadlocks

OwnerDisplayName: littleadv


答:
I'd take a look into Real-Time Systems and Programming Languages by Burns and Wellings. It discusses ways to prevent deadlocks in real time and does a good job with citing papers.

I don't have to book with me at work, but glancing at the ToC you have:

```
     4.7   Multiprocessor and distributed systems
     5.10  Shared memory multiprocessors
    11.14  Multiprocessor scheduling
```

Title: Schemes to resolve deadlocks

Body: I am interested in research that detects and recover from deadlocks. In other words the system is able to recover from deadlock faults. I'm interested in shared memory multicore processors. Uptill now I have only seen research for distributed systems. Can anyone guide me on this.</p>

Body:
I'd take a look into Real-Time Systems and Programming Languages by Burns and Wellings. It discusses ways to prevent deadlocks in real time and does a good job with citing papers.

I don't have to book with me at work, but glancing at the ToC you have:

     4.7   Multiprocessor and distributed systems
     5.10  Shared memory multiprocessors
    11.14  Multiprocessor scheduling


答:
One example of deadlock avoidance is the use of reader-writer locks. The basic pattern is that if you have one lock (the reader) and try to acquire the other (writer) but can't, then you have to abandon and retry your entire operation.

This could in principle be used as a deadlock recovery mechanism - in a classic lock inversion situation, where two threads each hold a lock that the other one wants, then one or both could back out to the point where they acquired the first lock and retry (not both at the same time, or they'll just lock-invert again!). But this is limited as a means of fault tolerance, since it requires co-operation from the threads. In a bad case, each thread might have put some data structure into an inconsistent state that it doesn't know how to back out of, only how to complete. So the fault is un-recoverable. In many cases it's harder to avoid that than it is just to avoid lock inversion.

Those distributed systems you've seen research for, might have the advantage that if a set of nodes gets into an unfortunate deadlocked state, they can all just be shot dead and their contributions ignored. To do that in the bad case I describe above, you'd need some form of transactional memory, which is difficult (and actively researched). But of course you can always write your multi-core code as if it were distributed code (share nothing between threads), then use the techniques for distributed code.

Detecting a locking inversion for mutexes is trivial in principle, since you can draw a directed graph of each thread's dependencies on other threads (A depends on B if B holds a lock that A is waiting on) and check for cycles. Detecting deadlock on semaphores or condition variables is impossible unless you can do enough static analysis to determine which thread is "supposed" to post each semaphore that another thread is waiting on, or supposed to make true a condition that another thread needs to be true before continuing.

Title: Schemes to resolve deadlocks

OwnerDisplayName: Steve Jessop


问:
What makes a piece of software an Engine?
The descriptor 'Engine' gets thrown around a lot: graphics engine, RegEx engine, AI engine, etc. but what actually makes a piece of software an Engine? Design, Input/Output, Purpose, Size?</p>

答:
An engine is basically software that can be extended to create something.

For example, in gaming, you'll hear a lot about 'something' game engine. This means a particular software was modified and extended to create a totally unique game.


问:
Can we replace XML with JSON entirely?
I'm sure lots of developers are familiar with XML and JSON, and they've used both of them. Thus no point in explaining what they are, and what is their purpose, even in brief.

If we try to map their concepts, we can say (correct me if I'm wrong):

XML tags are equivalent to JSON {}

XML attributes are equivalent to JSON properties

XML tag collection is equivalent to JSON []

The only thing I can think of, which doesn't exist in JSON, is XML Namespaces.

The question is, considering this mapping, and considering that JSON is highly lighter in this mapping, can we see a world in future (or at least theoretically think of a world) without XML, but with JSON doing everything XML does? Can we use JSON everywhere XML is used?

PS: Please note that I've seen this question. It's something entirely different from what I'm asking here. Thus please don't mention duplicate.

答: JSON is fairly new and legacy systems wont support it. Upgrading legacy systems is expesive and introduces bugs. JSON wont replace XML any time in the near future.</p>

Title: Can we replace XML with JSON entirely?


问:
Resolving merge conflicts due to refactoring
I got involved in a discussion recently on how to handle refactoring in general (which is an interesting topic in itself). Eventually the following question was brought up:

How does one handle merge conflicts that occured due to that someone did a refactoring of a part of the code, while someone else was working on a feature for the same piece of code?

Basically, I have no idea how to deal with this in an efficient manner. Are there any best practices that one should follow regarding this? Is there any difference on how one should handle this for a system with tons of legacy code?

答:
Have a separate common branch for developing a certain feature, merge/pull/push often - that's it.

And communicate. Speak with other developers about code even when launching. Even when coding )))


答:
Good question. The best strategy I can think of is:

Prevention

A combination of continuous integration and making small refactorings often (instead of occasional large refactorings) will go a long way to minimizing the cost and frequency of such conflicts.

Title: Resolving merge conflicts due to refactoring

Body:
I got involved in a discussion recently on how to handle refactoring in general (which is an interesting topic in itself). Eventually the following question was brought up:

How does one handle merge conflicts that occured due to that someone did a refactoring of a part of the code, while someone else was working on a feature for the same piece of code?

Basically, I have no idea how to deal with this in an efficient manner. Are there any best practices that one should follow regarding this? Is there any difference on how one should handle this for a system with tons of legacy code?


答:
I think to answer your question, first we have to see why conflicts happen, and what is the true meaning and process of merging?

Conflicts occur only when two or more developers are working on the same file at the same time and then they both try to check in. The first developer won't get any conflict, of course. But the second (third, fourth, and so on) would get conflicts. Why, because (s)he has some code which is partially or entirely different from existing code on the server.

This in nature means that the second developer has something in mind different than first developer. This difference can vary from styling, like using new UserManager().GetUserName() instead of UserManager userManager = new UserManager(); userManager.GetUserName(); up to the level you mentioned, which means that both developers had different ideas of how to refactor the code to improve it.

Merging, on the other hand, doesn't mean that developers can check-in their code without considering conflicts. They should and must address those conflicts. If conflicts are not important, then they may check-in and override previous code. But when they see something entirely different, they should call the previous developer, and talk to him, so that they can both get coordinated together to check-in the best solution.

For example, if you ask two developers to improve online-payment library, and their work overlap, this means that at least on some places, there are 2 different solutions. So, one of those solutions should be talked about and be accepted, thus checked-in, as the better solution.

I don't agree on preventing these circumstances, as we should tend to be more real than theoretical. Sometimes a guy is really good at CSS, while another is really good at ASP.NET Markup. But their work may conflict when they should both work on login page to make it work. I mean, if we think real (not ideal), we can see that many times this phenomenon (conflict) happens.

Another point I just wanted to mention, is to use tools to help you in your check-in process. These tools usually visualize the difference of server code and developer code, and helps a lot in determining which part should be checked-in.


答: There's a lot of functionality using XSLT that may not be possible with JSON. So, if they're not functionally equivalent they couldn't replace each other.</p>

Title: Can we replace XML with JSON entirely?

Body:
I'm sure lots of developers are familiar with XML and JSON, and they've used both of them. Thus no point in explaining what they are, and what is their purpose, even in brief.

If we try to map their concepts, we can say (correct me if I'm wrong):

XML tags are equivalent to JSON {}

XML attributes are equivalent to JSON properties

XML tag collection is equivalent to JSON []

The only thing I can think of, which doesn't exist in JSON, is XML Namespaces.

The question is, considering this mapping, and considering that JSON is highly lighter in this mapping, can we see a world in future (or at least theoretically think of a world) without XML, but with JSON doing everything XML does? Can we use JSON everywhere XML is used?

PS: Please note that I've seen this question. It's something entirely different from what I'm asking here. Thus please don't mention duplicate.


问:
Source code and project documentation requirements for legal agreement

Question

What kind of documentation and other artifacts would you expect to get in case of taking over existing Java webapp (probably it uses JBoss Seam framework) made in-house?

I would expect to get:

Source code in form ready to open in specified IDE.

All external elements (i.e. DB schema as SQL scripts, installation scripts).

Configuration files (both for devel, testing and production environments).

All external libraries needed by project.

All external tools used in project or at least their description (i.e. make program, version control software).

Detailed info about:

How to compile project (IDE, libraries, their versions, compilers, OS),

How to setup development environment (database version, OS, DB schema),

How to install and run application -- server specification (OS, database, versions, minimal hardware, configuration both app and DB),

Probably it would be also nice to have:

Archive of the whole version control system (to make possible checking changes from the past).

UML diagrams or other form of big picture of application design.

DB schema.

What I miss?

Some background details

Friend works as a lawyer for a company which needs legal agreements with people who develop applications for them. Just in case something goes wrong.

In general -- the company wants to have source code deposited somewhere. But source code is not enough to maintain or even compile and run webapp, so they also needsome documentation which helps maintain the app.

I've never taken someone else's project in a similar case (no access to previous developers), and I am not Java developer, so I expect there are a lot of things to miss.

More details added after a few answers

The bosses of company (named it A, small corporation), which ordered and uses the app and company (named it B, a few people) which writes the app, are friends.

Development is in-house. No formal spec, no written specification. All features are discussed over mail or on meetings.

Everything, including hosting the app, is managed by B.

Friend (who is also one of heavy users of the app -- let's say she is product owner) doesn't trust developers from B at all.

Friend also doesn't believe in B competencies (believe me -- she should not).

So to protect A business friend wants written legal agreement with B in case B would go away with A data and app...

As MSalters wrote -- don't laugh -- it happens :(.

A already made B to make and provides backups.

答:
Source code in form ready to open in specified IDE

above, though nice to have, feels rather slippery - leaving too much room to fuss over IDE version, plugins, configuration. "oh by the way this will work only if you install and enable Habracadabra plugin v 6.6.6. And, hey, just in case if you don't know, this version of Habracadabra works only with Netclipse 3.4.5"

When taking over I'd prefer to insist on having source code ready to build from command line

Also, in case if "they" use issue tracker for the project, I would do my best to squeeze all the data about these issues somehow (all issues in tracker, no matter fixed or not) - either by completely taking over that issue tracker with or by getting a read-only access to it or at least by getting a "snapshot" of it by whatever means.

Information stored in an issue tracker might be a great help for maintainer

update Can't tell if this qualifies as an artifact but given details provided later, I'd consider some sort of service-level agreement to somehow "bind" their developers to answering questions about the application.

"For first 3 (4,5) months mean time to answer within 8 hours, assuming 100 or less questions a week. For next 3-6 months mean time to answer within 24 hours, assuming 10 or less questions a week..."


答:
The main difference, I think, is in the fact that XML is designed to be self-explaining with its dtd's and everything.

With JSON, you have to assume alot about the data you are receiving.

Title: Can we replace XML with JSON entirely?


问:
For what common problems is functional programming not a good fit?
Functional programming is a declarative paradigm. One of the strenghts with FP is that side-effects are avoided. It's said that for some problems FP isn't a good fit.

For what common problems isn't functional programming a good fit?

答: Data-driven business applications. User interface and simple data operations don't need FP.</p>


答:
JSON and XML are both ways of formatting data. Both are capable of doing it perfectly well, so can JSON do everything XML does? Yes.

But.....
A more relevant question might not be what XML/JSON can do, but rather, what can you do with XML/JSON.

There are several things you can do with XML that I don't think you can with JSON, such as translate with XLST, search with XPath and validate with schemas. All very, very useful.

Title: Can we replace XML with JSON entirely?


答: Make sure that the merge is as simple as possible. Refactoring is usually a rather mechanical process which changes many existing lines: Move variable declarations, whitespace changes, formatting, sequence of operations. Feature creation is usually a much more creative venture, often resulting in new code plus a few minor tweaks to the existing code. Now if the developer doing the refactoring records the steps (for example as regular expressions), it can be much easier to apply these to the code with the extra functionality rather than the other way round. Based on this, I'd say that as a general rule you should apply the most complex change first, followed by progressively simpler changes.


答:
A literal translation to JSON is often less succinct and less clear. Consider:

```<code><foo>
   <x:bar x:prop1="g">
      <quuz />
   </bar>
</foo>
</code>```

The most effective JSON representation I have seen of this:

```<code>{"localName":"foo",
 "children": // you need to have a special array to hold all children
 [
    {"localName": "bar",
     "namespace": "x"
        // once again, to ensure that there are no collisions,
        // attributes should be brought out into their own JSON structure
        "attributes":[
            {"localName":"prop1",
             "namespace":"x",
             "value":"g"}
        ],
         "children":[
             {"name":"quux"}
         ]
     }
 ]}
</code>```

Now, imagine that for an entire XML file. I am not saying that JSON does not have its place, but XML should not be ruled out.

Title: Can we replace XML with JSON entirely?

Body:
A literal translation to JSON is often less succinct and less clear. Consider:

<foo>
   <x:bar x:prop1="g">
      <quuz />
   </bar>
</foo>

The most effective JSON representation I have seen of this:

{"localName":"foo",
 "children": // you need to have a special array to hold all children
 [
    {"localName": "bar",
     "namespace": "x"
        // once again, to ensure that there are no collisions,
        // attributes should be brought out into their own JSON structure
        "attributes":[
            {"localName":"prop1",
             "namespace":"x",
             "value":"g"}
        ],
         "children":[
             {"name":"quux"}
         ]
     }
 ]}

Now, imagine that for an entire XML file. I am not saying that JSON does not have its place, but XML should not be ruled out.


答:
I'd say that cwallenpoole makes an excellent point. While most XML can be translated to JSON, whether doing so is better for it is a separate point.

JSON lends itself to data structures at least as well as XML and probably better, but XML reads much more naturally than JSON when marking up textual documents, where tags are used within a larger flow of text rather than simply as a way to delimit a hierarchy of fields.

While HTML 5 may have its own parser, that still leaves applications like DocBook.

Title: Can we replace XML with JSON entirely?


问:
Observer pattern over HTTP and TCP/IP (Server-Client)
I have a server and many clients (around 50 clients) who connect to that server based on a web application, which is of course based on HTTP protocol, which in turn uses TCP/IP (correct me if I'm wrong, cause I'm not really good at networking).

The problem is that, I should develop an alert mechanism, in which, when somebody submits a form with dangerous values, the manager (who is also connected via the same web application) should receive an alert pop-up on his screen, almost real-time (instantly).

However, since the HTTP protocol is stateless, I' a little puzzled here. I don't know how I can implement this.

One of the solutions could be to use JavaScript alongside setInterval() function to pull data each second from server. But this seems a little dirty to me and unprofessional.

Do you guys have any idea of implementing another solution?

答:
This is a good use case for WebSockets were created for. If you don't need compatibility with older browsers you might want to use this instead of polling (and possibly fall back to polling).

Another solution is to use server-sent events.

I'm not sure how stable the spec/implementations are these days (it was not very stable not so long ago). It seems the latest spec is implemented in Firefox 6 and Chromium 14.

ContentLicense: CC BY-SA 4.0


答:
The following points might help too:

(JUnit) Tests

JavaDoc (automatically generated from the source code, might give a good clue about the quality)

But in general, a knowledge transfer between one of the developers and the new maintainers might be "a good thing" (tm).

Seeing as the webapp was ordered by the company, the company has decent docs/specs about what they wanted to have?

Title: Source code and project documentation requirements for legal agreement

Body:
Question

What kind of documentation and other artifacts would you expect to get in case of taking over existing Java webapp (probably it uses JBoss Seam framework) made in-house?

I would expect to get:

Source code in form ready to open in specified IDE.

All external elements (i.e. DB schema as SQL scripts, installation scripts).

Configuration files (both for devel, testing and production environments).

All external libraries needed by project.

All external tools used in project or at least their description (i.e. make program, version control software).

Detailed info about:

How to compile project (IDE, libraries, their versions, compilers, OS),

How to setup development environment (database version, OS, DB schema),

How to install and run application -- server specification (OS, database, versions, minimal hardware, configuration both app and DB),

Probably it would be also nice to have:

Archive of the whole version control system (to make possible checking changes from the past).

UML diagrams or other form of big picture of application design.

DB schema.

What I miss?

Some background details

Friend works as a lawyer for a company which needs legal agreements with people who develop applications for them. Just in case something goes wrong.

In general -- the company wants to have source code deposited somewhere. But source code is not enough to maintain or even compile and run webapp, so they also needsome documentation which helps maintain the app.

I've never taken someone else's project in a similar case (no access to previous developers), and I am not Java developer, so I expect there are a lot of things to miss.

More details added after a few answers

The bosses of company (named it A, small corporation), which ordered and uses the app and company (named it B, a few people) which writes the app, are friends.

Development is in-house. No formal spec, no written specification. All features are discussed over mail or on meetings.

Everything, including hosting the app, is managed by B.

Friend (who is also one of heavy users of the app -- let's say she is product owner) doesn't trust developers from B at all.

Friend also doesn't believe in B competencies (believe me -- she should not).

So to protect A business friend wants written legal agreement with B in case B would go away with A data and app...

As MSalters wrote -- don't laugh -- it happens :(.

A already made B to make and provides backups.


答: "docs/specs" (mentioned by Turbo) is indeed a very good point. You might want to add in the original requirements as well, and the current issue tracker database. When those are managed by email (don't laugh, it happens) you'd want those emails instead, and you'd charge the client for entering them into a proper issue tracker.</p>


答:
What does he mean, "cannot be resold"?

There are two interpretations, an economical one and a legal one.

Under the legal interpretation, if your software is under the GPL license, other people are explicitly allowed to resell your software.

Under the economical interpretation, if you offer a free-as-in-beer GPL version on your website, other people cannot resell your software because they'd not be able to undercut you.

In either case, third parties can charge for warranties, maintenance, support, and quite a few other things anyway.

Title: Can GPL-licensed software be resold?

Body:
My research group is developing some software for research purposes. The project leader wants the software to be open source and likes the GPL, but wants to ensure that they software cannot be sold.

Are we reading the GPL correctly? The software can be freely modified, (re)distributed, and sold? If so, I see why it would be difficult to effectively sell the software; however, the GPL isn't quite strict enough for our needs.

Any suggestions?


答:
If there's no active management of tasks, you have conflicts.

If, however, you have a daily stand up meeting or a manager, you cannot possibly have this problem.

Either talk (via a daily stand up) or talk to a manager.

This is trivially prevented by talking.


问:
Are programmers who read programming-related books still rare?
Both in Code Complete by Steve McConnell and The Pragmatic Programmer by Andrew Hunt & David Thomas, they allege that most programmers don't read programming-related books as a habit, or at least not often enough. Does this still hold? Are programmers who do read such books still rare?

I must admit that only quite recently did I start reading (and now I can't stop; it's burning a whole in my wallet!). Before I was actually against it and argued that it's better to write programs than to waste time reading about it. Now I realize that the best outcome, for me at least, is to do both.

EDIT: I actually meant any kind of books that on way or another was related to programming; be it either on a particular language, technology, pattern, paradigm - anything as long as it may benefit you as a programmer. I was just referring to Code Complete and The Pragmatic Programmer because that's where I read that programmers don't usually read such books. It would have looked stranged if the title just read "Are programmers who read books still rare?"

答:
Whilst interviewing developers I've noticed that the ones who perform better at the technical tasks (both verbal and practical) and (far more importantly) understand the reasons why they're doing what they're doing are all developers who read at least the occasional book. I don't think that that's entirely a coincidence.

Although you can certainly use Google for quick answers and blogs can be excellent for indepth coverage of specific things, books I think give you a more co-ordinated view of the topics they cover. Also, by providing the information in a different context they help knowledge stick in people's heads better. Even if it's something you already know I think it's valuable to have something which validates that knowledge.

Finally, if someone is reading books about the subject they're working in then it almost certainly means that they're genuinely interested in what they're doing and not just plodding through things - for knowledge based or creative jobs this is very important if you're after the best staff.


问:
how to start with ASP.NET MVC 3 razor
I going to start a new project in my company in which are involved the use of MVC 3, now this is the first time that we are using this framework, and i have a couple of questions,

It's recommended to start with MVC3 and not from the MVC2?

Any Tutorials in specific that you can recommend?

This framework have full integration with jQuery?

答:
No question about doing Razor -- it really makes development much, much better.

I think the real question at this point is "Should I start on MVC4 or just use MVC3?" Their dev cycle is pretty tight, in many cases you are better off aiming at the version of the framework under development lest you end up needing to upgrade immediately after publishing.

Title: how to start with ASP.NET MVC 3 razor


问:
Computer Science and other advance topics taught in javascript
I'm an 'okay' Javascript developer working on browser javascript and node.js. However because I'm self taught, starting from copying and pasting jquery, there are a lot of holes in my programming/CS education.

I don't really have the time to devote myself to fully learning all the CS concepts that might be taught in a real college program, and learning C or Scala or whatnot, I'm just too addicted to hacking and making things that work. On some level studying CS seems to be 'premature scaling' in Hacker News parlance.

But every so often I get struck by the thought that maybe there is something that I should really really learn to take my skills and productivity to the next level.

Is there a book, a list of concepts or things that I can study and learn in my 'down time' that would see reasonable returns on my productivity and ability in 1 - 2 months?

Thanks!

And yes, the only language I know and use is Javascript, though I have tinkered with Python (High School), Ruby (RoR), PHP (Drupal), and Assembly (Making Diablo 2 Mods) in the past.

Please note that a book like O'Reilly's JavaScript Web Applications is too easy for me and not really what I'm talking about.

答:
Yeah you can read books on algorithms or how to write more "effective and clean" code but I think it will be much easier (and cheaper) for you just to fork respectable github projects and look at the code. Then just follow up with Wikipedia or Stackoverflow on what you don't understand.

Since you are a Javascript programmer it might be good idea to understand how the Javascript parser and runtime (V8) works or how nodejs works. Those technologies use many of things @Philip mentions. Nodejs and V8 are also written in C/C++ which is always good to know a little of.

Unless you have incredible discipline I find studying something for the sake of knowing not as effective as picking a project or problem and learning on the way.

I think you will learn more (not just programming) by picking something challenging to tackle and then do research on how to solve that problem.


答: Another big reason is spam -- one forum I was a moderator of had a rash of fake "fluff" posts that seemed pointless yet innocuous. Until something came along and edited the forum posts for more nefarious purposes. Pretty brilliant plan to be honest -- most forums pay lots of attention to stopping the bots from posting but editing was wide open with a little CURL action.</p>


答: I have to manage more than a few outsourced development projects. One trick to make sure you get a buildable, runnable project is to make sure that you own and host the source control server and build/qa environments. By definition you'll have a buildable, runnable copy of the project with full history.</p>


答:
The thing that gives XML its power and a lot of its complexity is mixed content. Stuff like this:

```<code><p>A <b>fine</b> mess we're in!</p>
</code>```

Don't even try to do that in JSON, or manipulate it in conventional programming languages. They weren't designed for the job.

This kind of question usually comes from people who forget that that the M in XML stands for markup. It's a way of taking plain text and adding markup to create structured text. It's quite handy for old-fashioned data too, but that's not what it was designed for or where its main strengths lie. There are plenty of ways of handling simple data, and JSON is one of them.

Title: Can we replace XML with JSON entirely?

Body:
The thing that gives XML its power and a lot of its complexity is mixed content. Stuff like this:

<p>A <b>fine</b> mess we're in!</p>

Don't even try to do that in JSON, or manipulate it in conventional programming languages. They weren't designed for the job.

This kind of question usually comes from people who forget that that the M in XML stands for markup. It's a way of taking plain text and adding markup to create structured text. It's quite handy for old-fashioned data too, but that's not what it was designed for or where its main strengths lie. There are plenty of ways of handling simple data, and JSON is one of them.


答: The fact is, we're going to have to live with both for a long time, and being a JSON bigot is "considered harmful."  </p>

Title: Can we replace XML with JSON entirely?


问:
Best book, articles and literature on unit testing
In my battle to introduce unit testing in my workgroup, I find a lot of people that have little to none knowledge of the concept. Can you suggest:

best articles or tutorials for quickly introducing people on the topic

best comprehensive book(s) for learning unit testing in depth

academic works and studies that prove the effectiveness of unit testing

答:
I found Test Driven Development By Kent Beck to be a
good introduction.</p>


问:
What should take precedence: YAGNI or Good Design?
At which point should YAGNI take precedence against good coding practices and vice versa?  I'm working on a project at work and want to slowly introduce good code standards to my co-workers (currently there are none and everything is just kind of hacked together without rhyme or reason), but after creating a series of classes (we don't do TDD, or sadly any kind of unit testing at all) I took a step back and thought it's violating YAGNI because I pretty much know with certainty that we don't require the need to extend some of these classes.

Here's a concrete example of what I mean: I have a data access layer wrapping a set of stored procedures, which uses a rudimentary Repository-style pattern with basic CRUD functions.  Since there are a handful of methods that all my repository classes need, I created a generic interface for my repositories, called IRepository.  However, I then created a "marker" interface (i.e. interface that doesn't add any new functionality) for each type of repository (e.g. ICustomerRepository) and the concrete class implements that.  I've done the same thing with a Factory implementation to build the business objects from DataReaders/DataSets returned by the Stored Procedure; the signature of my repository class tends to look something like this:

```<code>public class CustomerRepository : ICustomerRepository
{
    ICustomerFactory factory = null;

    public CustomerRepository() : this(new CustomerFactory() { }

    public CustomerRepository(ICustomerFactory factory) {
        this.factory = factory;
    }

    public Customer Find(int customerID)
    {
        // data access stuff here
        return factory.Build(ds.Tables[0].Rows[0]);
    }
}
</code>```

My concern here is that I'm violating YAGNI because I know with 99% certainty that there is never going to be a reason to give anything other than a concrete CustomerFactory to this repository; since we don't have unit tests I don't need a MockCustomerFactory or similar things, and having so many interfaces might confuse my co-workers.  On the other hand, using a concrete implementation of the factory seems like a design smell.

Is there a good way to come to a compromise between proper software design and not overarchitecting the solution?  I'm questioning if I need to have all of the "single implemenation interfaces" or if I could sacrifice a bit of good design and just have, for example, the base interface and then the single concrete, and not worry about programming to the interface if the implementation is that will ever be used.

答: Allowing your code to be extended with unit tests is never going to be covered under YAGNI, because you will need it. However, I'm not convinced that your design changes to a single-implementation interface are actually increasing the testability of the code because CustomerFactory already inherits from an interface and can be swapped out for a MockCustomerFactory at any time anyway.


答:
Is there a good way to come to a compromise between proper software design and not overarchitecting the solution?

YAGNI.

I could sacrifice a bit of good design

False assumption.

and the base interface and then the single concrete,

That's not a "sacrifice".  That is good design.

Title: What should take precedence: YAGNI or Good Design?

Body:
At which point should YAGNI take precedence against good coding practices and vice versa?  I'm working on a project at work and want to slowly introduce good code standards to my co-workers (currently there are none and everything is just kind of hacked together without rhyme or reason), but after creating a series of classes (we don't do TDD, or sadly any kind of unit testing at all) I took a step back and thought it's violating YAGNI because I pretty much know with certainty that we don't require the need to extend some of these classes.

Here's a concrete example of what I mean: I have a data access layer wrapping a set of stored procedures, which uses a rudimentary Repository-style pattern with basic CRUD functions.  Since there are a handful of methods that all my repository classes need, I created a generic interface for my repositories, called IRepository.  However, I then created a "marker" interface (i.e. interface that doesn't add any new functionality) for each type of repository (e.g. ICustomerRepository) and the concrete class implements that.  I've done the same thing with a Factory implementation to build the business objects from DataReaders/DataSets returned by the Stored Procedure; the signature of my repository class tends to look something like this:

```<code>public class CustomerRepository : ICustomerRepository
{
    ICustomerFactory factory = null;

    public CustomerRepository() : this(new CustomerFactory() { }

    public CustomerRepository(ICustomerFactory factory) {
        this.factory = factory;
    }

    public Customer Find(int customerID)
    {
        // data access stuff here
        return factory.Build(ds.Tables[0].Rows[0]);
    }
}
</code>```

My concern here is that I'm violating YAGNI because I know with 99% certainty that there is never going to be a reason to give anything other than a concrete CustomerFactory to this repository; since we don't have unit tests I don't need a MockCustomerFactory or similar things, and having so many interfaces might confuse my co-workers.  On the other hand, using a concrete implementation of the factory seems like a design smell.

Is there a good way to come to a compromise between proper software design and not overarchitecting the solution?  I'm questioning if I need to have all of the "single implemenation interfaces" or if I could sacrifice a bit of good design and just have, for example, the base interface and then the single concrete, and not worry about programming to the interface if the implementation is that will ever be used.


答:
At my job the term seems to mean "A single code file in the format XEngine.cs with multiple classes inside that code file, all of which contain nothing but static methods".  I throw up a little inside every time I look at it; might as well be a VB6 module.

I personally wouldn't use the term, it's ambiguous and meaningless (unless, I suppose, you're writing software that simulates an automobile or perhaps a racing game) in most cases; it's like the old "Manager" classes of yore - the name tells you nothing other than "This does a lot of stuff" and usually that means it's a gross violation of SOLID.

Title: What makes a piece of software an Engine?

Body: The descriptor 'Engine' gets thrown around a lot: graphics engine, RegEx engine, AI engine, etc. but what actually makes a piece of software an Engine? Design, Input/Output, Purpose, Size?</p>


答:
In most cases, avoiding code that you aren't going to need leads to better design. The most maintainable and future-proof design is the one that uses the smallest amount of well-named, simple code that satisfies the requirements.

The most simple designs are the most easy to evolve. Nothing kills maintainability like useless, overengineered abstraction layers.


问:
How significant are Spring and Hibernate in software development?
I am a software professional with about 1.6 years of experience in Java. Due to personal reasons, I had to quit my job, and now after 5 to 6 months, I am about start my career again. I am planning to attempt to take the SCJP exam, but some of my seniors suggested that I should learn Spring and Hibernate. I am totally new to Spring and Hibernate, but I am good in core Java concepts, servlets, and JSPs to some extent.

Which option would help me securing a job fast? Do software companies not use Java and JDBC alone, without advanced concepts like EJBs, Struts, Spring, Hibernate, servlets, JSPs, etc? Is it enough for an individual to possess skills in Java alone by attempting to obtain the SCJP certification, or do you need advanced Java skills to secure a job?

答:
At this point, you should probably learn Spring and Hibernate. If you were just graduating, SCJP could have more value, but your 1.6 years Java experience gives you credibility as a Java programmer.

Yes, most Java shops use frameworks like Spring and Hibernate, EJB, Struts 2, or a combination of these, based on my experience.

The problem with learning Spring/Hibernate on your own is that many employers don't give much consideration to experience that is not work experience.

How to learn Spring/Hibernate is another large question. The short version is: build something, understand and use Dependency Injection, use Spring DAO's along with Hibernate for your DB access. If you can get that much working, add Spring MVC for the front end.

If you like books, the "In Action" books are good. (Spring in Action, Hibernate in Action)

If you accomplish that much, you should be able to decide for yourself what to do next.


答:
You don't have much experience so not much should be expected of you other than a willingness to work hard and a strong desire to learn and pick up new concepts quickly.

For 1.5 years experience I would expect some exposure to JSP, Struts or Spring, Hibernate or any other ORM tool, and servlets.  Can the applicant explain Spring to me?  Struts?  What are the benefits of these tools?  Can they explain what an ORM mapper is and the benefits.  Can they demonstrate any experience in any of this?

The SCJP is a VERY basic certification and all it tells me is a basic level of Java programming competency.  I would skip basic Java knowledge questions if I notice it on a resume but I would still ask typical OO knowledge questions and it certainly wouldn't influence my decision in any way.

You don't need to be an expert or have developed a large distributed system using these technologies to be considered at your experience level.

Title: How significant are Spring and Hibernate in software development?

Body:
I am a software professional with about 1.6 years of experience in Java. Due to personal reasons, I had to quit my job, and now after 5 to 6 months, I am about start my career again. I am planning to attempt to take the SCJP exam, but some of my seniors suggested that I should learn Spring and Hibernate. I am totally new to Spring and Hibernate, but I am good in core Java concepts, servlets, and JSPs to some extent.

Which option would help me securing a job fast? Do software companies not use Java and JDBC alone, without advanced concepts like EJBs, Struts, Spring, Hibernate, servlets, JSPs, etc? Is it enough for an individual to possess skills in Java alone by attempting to obtain the SCJP certification, or do you need advanced Java skills to secure a job?


答:
Instead of either of those, I prefer WTSTWCDTUAWCROT?

(What's the simplest thing we can do that's useful and we can release on Thursday?)

Simpler acronyms are on my list of things to do, but they're not a priority.


问:
Can GPL-licensed software be resold?
My research group is developing some software for research purposes. The project leader wants the software to be open source and likes the GPL, but wants to ensure that they software cannot be sold.

Are we reading the GPL correctly? The software can be freely modified, (re)distributed, and sold? If so, I see why it would be difficult to effectively sell the software; however, the GPL isn't quite strict enough for our needs.

Any suggestions?

答:
Using a license that prohibits commercial usage (which, by the way is VERY hard to define) than GPL will make your software incompatible with all existing libraries and programs that use that license. It also means that it will not be included in software like R or in linux distributions like debian.

I know different programs which used some kind of noncommercial license and which was not maintained for this reasons: you can not link the software to most other libraries or utilities.

If you use the GPL, and someone will sell products using or based on your code, they are obliged to give access to the full source code. That means including all their modifications and all other code for their program. I think that's a fair deal: improvements and new possibilities become available.

Since you are the copyright holder, you can also decide to have both a GPL version and a commercial license: in reality people selling software will want a license which does not force them to publish their whole program under the GPL. They will happily buy a license to get rid of that restriction. This is a scheme which among many others is used by oracle for berkeley db:

Thus, the license depends on how a particular application that uses
  Berkeley DB is distributed to the public. Software that is not
  distributed can use the Sleepycat License, as can free and open source
  software. Proprietary software can use Berkeley DB only under a
  commercial license agreement between Oracle and the application's
  publisher.

A last thing: it is very hard to define 'commercial usage'. Is a PhD student working on a project using your software commercial usage? His wage is paid by the project...

One last thing to convince your team leader:

Releasing code under the GPL leaves only the same opportunities for
  (legal) commercial gain as does publishing a journal article
  describing some method or process that can be exploited commercially.

From this similar question on Stackoverflow. And in fact it is not true: if you publish an article, the publisher will usually claim the copyright and the revenues of the article, so you are better of using GPL than publishing it in a journal.

Title: Can GPL-licensed software be resold?


问:
How do you know if you've split your domain correctly
In DDD i struggle to understand whether or not my domain is split correctly into aggregate roots and then those aggregate roots are grouped correctly into bounded contexts. is there a way - like a set of rules/guidance i can use to decide whether or not i am placing things in the right AR/BC</p>

答:
I think Udi Dahan gives a fantastic answer on DDD and creation of aggregate roots:
http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/

As stated by @Malvolio you need to figure out what problem you are trying to solve then decided on how the situation maps back to the real world. Once you have this then the aggregate root will become clear and obvious.


问:
What are the best FizzBuzz questions for interviewing a candidate for a Software Developer role?
I'm looking for some advice on interviewing technical candidates. I touched on this briefly in a question I previously asked: template questions in a technical interview and was informed that FizzBuzz questions are designed to weed out candidates you definitely don't want coming near your code.  Moving on from that, I'd like to know what FizzBuzz questions work best? In my own experience, the common one I've seen is "Can you write a method to determine if a number is prime or not?". Personally, I find this a little too easy (writing the most efficient one is another story). Are there better FizzBuzz questions that can be used? What ones would you put to a candidate?</p>

答:
I would look through this list of 100 questions and tailor it as needed for the specific job requirements of the position. I would suggest trying to hit every area once, especially if you are looking for a well-rounded engineer, but focus on the areas most relevant to the job.

A few examples of the questions it sounds like you are most interested in. Instead of asking "how", explicitly ask them to write a method or routine, either in pseudocode (my preferred method) or the language that they would be using if they were hired.

How do you find out if a number is a power of 2? And how do you know if it is an odd number?

How do you find the middle item in a linked list?

How would you write a function to reverse a string? And can you do that without a temporary string?

In an array with integers between 1 and 1,000,000 one value is in the array twice. Write a method to determine which one.


答:
Personally, I wouldn't put any of them to a candidate. I'd sit him down in front of a laptop in a non-threatening setting and have him hack on a project with you to show critical thinking skills and ability to pick up new tools/technologies quickly.

Seriously, they're not children. Logic puzzles rarely do what you hope they do. Asking someone to write an algorithm on the spot is a hard thing to do. At least for me, I like to go mull a problem over coffee and sketch a bit before I sit down and start working on it. A traditional interview setting does not beget easy-flowing thought.

Hell, take him out for a beer and talk to the guy. The most important thing is to get to know someone when they aren't twitchy and nervous, see what kind of person they are, and evaluate their abilities in a non-threatening way.

If my current employer did this, I probably wouldn't have gotten the job. Right now I develop complex and good-working systems requiring abilities well beyond that asked in an interview, as a bonus I get along really well with everyone in the office. Why? Non-traditional interview policies. All of our candidates come in (after a telephone screen) to hack for a day. Better yet, pay them for a day.

Title: What are the best FizzBuzz questions for interviewing a candidate for a Software Developer role?

Body: I'm looking for some advice on interviewing technical candidates. I touched on this briefly in a question I previously asked: template questions in a technical interview and was informed that FizzBuzz questions are designed to weed out candidates you definitely don't want coming near your code.  Moving on from that, I'd like to know what FizzBuzz questions work best? In my own experience, the common one I've seen is "Can you write a method to determine if a number is prime or not?". Personally, I find this a little too easy (writing the most efficient one is another story). Are there better FizzBuzz questions that can be used? What ones would you put to a candidate?</p>


答:
You could ask questions that are related to programming paradigms, for instance, a problem that could be solved easily using functional programming. Let's say, design an algorithm to compute a postfix expression. That way you could also see if the candidate knows how to use stacks.

I recommend you reading:

How Would You Move Mount Fuji?

Cracking the Coding Interview, Fourth Edition: 150 Programming Interview Questions and Solutions

Algorithms For Interviews


答: The Art of Unit Testing by Roy Osherove. Great practical examples on using unit and integration tests, employing mocking frameworks, etc.</p>

Title: Best book, articles and literature on unit testing

Body:
In my battle to introduce unit testing in my workgroup, I find a lot of people that have little to none knowledge of the concept. Can you suggest:

best articles or tutorials for quickly introducing people on the topic

best comprehensive book(s) for learning unit testing in depth

academic works and studies that prove the effectiveness of unit testing


问:
Which Java framework meets these requirements?
Which Java framework meets these requirements?
What set of frameworks would be best suited to meet these requirements?

The requirements are:

oriented for web

support for transactions

support for creating RESTful web services

support for security, levels of security

integration with some kind of ORM framework like Hibernate

ability to change front-end without need of making changes to back-end. Firstly, I want to develop a flex based front-end but if I've ever wanted to change it to HTML5 then I don't want to make changes to my back-end

ready for cloud

free to use for commercial purposes

To my mind comes Spring but are there any other alternatives meeting these requirements?
What about if it is not necessary java? Do you know framework, set of frameworks combined together in other language which meet these requirements best?

答: Spring is pretty much the standard for that type of thing.  It's a pretty big framework though.  I use JSF for things that really don't require Spring (but probably is too lightweight for where you're going?).


答:
In your example, I would say that YAGNI should prevail. It won't cost you that much if you need to add interfaces later. By the way, is it really good design to have one interface by class if it serves no goal at all ?

One more thought, maybe sometimes what you need is not Good Design but Sufficient Design. Here are is very interesting sequence of posts on the topic :

Sufficient Design

Sufficient Design Means Damned Good Design

When Sufficient Design means Poor Design


答:
In addition to the answers above, what ever you do, please don't just go and learn the framework!!

Hibernate is the most popular implementation of the Java Persistence Architecture (JPA) standard.  However, it is not the only one and so understanding JPA before tackling Hibernate is recommended.  With Hibernate, learn how it works under the hood so that you don't make mistakes like trying to call delete() on 1 million objects on a limited resource server.

Spring is a vast framework with many tentacles, but at its heart is the concept of Dependency Injection (DI).  You want to make sure that you understand that concept first, so you can apply it to Spring, Guice, Pico Container or any of the other Inversion of Control (IoC) containers out there.

Frameworks go in and out of fashion, the underlying principles last much longer :-)


答: See Matt Raible's presentations on his evaluation of various JVM web frameworks.  It's a very good idea to follow his methodical approach.  Spring MVC and Grails were the leading contenders last time I did an evaluation with your criteria, but you should definitely make your own analysis.</p>

Body:
Which Java framework meets these requirements?
What set of frameworks would be best suited to meet these requirements?

The requirements are:

oriented for web

support for transactions

support for creating RESTful web services

support for security, levels of security

integration with some kind of ORM framework like Hibernate

ability to change front-end without need of making changes to back-end. Firstly, I want to develop a flex based front-end but if I've ever wanted to change it to HTML5 then I don't want to make changes to my back-end

ready for cloud

free to use for commercial purposes

To my mind comes Spring but are there any other alternatives meeting these requirements?
What about if it is not necessary java? Do you know framework, set of frameworks combined together in other language which meet these requirements best?


答:
Some people argue, that interface names should not be starting with I. Specifically one reason is, that you're actually leaking the dependency on whether the given type is a class or an interface.

What prohibits you from CustomerFactory being a class at first and later changing it into an interface, that will either be implemented by DefaultCustormerFactory or UberMegaHappyCustomerPowerFactory3000? The only thing you should be having to change is the place, where the implementation gets instantiates. And if you have a more less good design, then this is a handful of places at most.

Refactoring is a part of development. Better have little code, that is easy to refactor, than have an interface and a class declared for every single class, forcing you to change every method name in at least two places at the same time.

The real point in using interfaces is achieving modularity, which is possibly the most important pillar of good design. Note however, that a module is not only defined by its decoupling from the outside world (even though that is how we perceive it from the outside perspective), but equally by its inner working.

What I mean to point out is, that decoupling things, that inherently belong together doesn't make much sense. In a way it is like having a cupboard with an individual shelf per cup.

The importance lies in devising a big, complex problem into smaller, simpler subproblems. And you must stop at the point, where they become simple enough without further subdivisions, or else they will in fact become more complicated. This could be seen as a corollary of YAGNI. And it definitely means good design.

The goal is not to somehow solve a local problem with a single repository and a single factory. The goal is, that this decision has no effect on the rest of your application. That's what modularity is about.

You want your coworkers to look at your module, see a facade with a handful of self-explanatory calls and feel confident, that they can use them, without having to worry about all the potentially sophisticated inner plumbings.


答:
They aren't in conflict, your goals are wrong.

What are you attempting to accomplish?

You want to write quality software, and to do that you want to keep your code base small and not have issues.

Now we reach a conflict, how do we cover off all cases if we don't write cases we aren't going to use?

Here's what your problem looks like.

(anyone interested, this is called evaporating clouds)

So, what's driving this?

You don't know what you're not going to need

You don't want to waste time and bloat your code

Which one of these can we solve? Well, it looks like not wanting to waste time and bloat code is a great goal, and makes sense. What about that first one? Can we find out what we're going to need to code?

I'm working on a project at work and want to slowly introduce good code standards to my co-workers (currently there are none and everything is just kind of hacked together without rhyme or reason) [...] I took a step back and thought it's violating YAGNI because I pretty much know with certainty that we don't require the need to extend some of these classes.

Let's re-phrase all of that

No code standards

No project planning going on

Cowboys everywhere doing their own damn thing (and you're trying to play sheriff in the wild wild west), yee haw.

Is there a good way to come to a compromise between proper software design and not overarchitecting the solution?

You don't need a compromise, you need someone to manage the team who is competent and has vision of the whole project. You need someone who can plan what you ARE going to need, instead of each of you throwing in things you ARE NOT going to need because you're so uncertain of the future because... why? I'll tell you why, it's because nobody has a damn plan among all of you. You're trying to bring in code standards to fix an entirely separate issue. Your PRIMARY problem you need to solve is a clear roadmap and project. Once you have that, you can say "code standards help us reach this goal more effectively as a team," which is the absolute truth but outside the scope of this question.

Get a project/team manager who can do these things. If you have one, you need to ask them for a map and explain the YAGNI problem that not having a map is presenting. If they're grossly incompetent, write the plan yourself and say "here's my report for you on things we need, please review it and let us know your decision."


问:
Is there any formal research in FizzBuzz Question Effectiveness?
After seeing this question today on variation of the FizzBuzz interview question, as well as seeing other questions related to it around, I have to ask: is there any formal research on how effective this is as an interview technique? There are plenty of folks who say that it filters out some crazy-sounding percentage of candidates (95%+ in some cases) but how good is it for finding good programmers/developers?

There has been some research that shows that soft skills might be better indicators than hard skills for choosing a good candidate for a job role. As well, there might be some intermediate reasons for so many candidates failing this test (nervousness, thinking "it's a trick", etc).

Based on the comments so far, it looks like the idea behind FizzBuzz questions is to determine whether or not the person has good (enough) coding skills to be further considered. I'm not totally convinced FizzBuzz actually does this. Also, remember that FizzBuzz filters a very large percentage of candidates very early in the hiring process, which could mean that significant numbers of good candidates are being removed early on because they can't solve silly problems fast enough.

Also, I'll point out that looking at FizzBuzz effectiveness is something that can completely be done in a quantitative manner. This is unlike looking at "fit" or "passion" which are highly variable and highly unscientific (but still quite important for new hiring decisions).

答:
The purpose of fizzbuzz isn't to find good programmers, it's to find a certain class of bad programmers, which is people who can't implement a simple algorithm.  Your question is sort of like asking how many Nascar champions are identified during their driver license exams.  There's a lot of middle ground between someone you definitely don't want to hire and someone you definitely do.

There are other classes of "bad" programmers that require different methods of identification, like those who aren't proficient in a given language or have behavioral issues.  However, "fizzbuzz-bad" programmers are almost universally undesired, which is why the test is so frequently recommended. Whether a programmer who is overly territorial or one who needs to transfer skills to a new language is "good" or "bad" depends much more on the individual employer's needs and preferences.


答:
YAGNI and SOLID (or any other design methodology) are not mutually exclusive. However, they are near-polar opposites. You do not have to adhere 100% to either, but there will be some give-and-take; the more you look at a highly-abstracted pattern used by one class in one place, and say YAGNI and simplify it, the less SOLID the design becomes. The reverse can be true as well; many times in development, a design is implemented SOLIDly "on faith"; you don't see how you will need it, but you just have a hunch. This could be true (and is more and more likely to be true the more experience you gain), but it could also put you in as much technical debt as a slap-dash "do it light" approach; instead of a DIL "spaghetti code" codebase, you may end up with "baklava code", having so many layers that simply adding a method or a new data field becomes a days-long process of wading through service proxys and loosely-coupled dependencies with only one implementation. Or you could end up with "spaghetti-Os code", which comes in such small, loosely-structured pieces that moving up, down, left or right in the architecture takes you through 50 methods with 3 lines each.

I've said it in other answers, but here it is: On the first pass, make it work. On the second pass, make it elegant. On the third pass, make it SOLID.

Breaking that down:

When you first write a line of code, it simply has to work. At this point, for all you know, it's a one-off. So, you don't get any style points for building an "ivory-tower" architecture to add 2 and 2. Do what you gotta do, and assume you'll never see it again.

The next time your cursor goes in that line of code, you have now disproved your hypothesis from when you first wrote it. You are revisiting that code, likely either to extend it or to use it elsewhere, so it's not a one-off. Now, some basic principles like DRY (don't repeat yourself) and other simple rules for code design should be implemented; extract methods and/or form loops for repeated code, extract variables for common literals or expressions, maybe add some comments, but overall your code should self-document. Now, your code is well-organized, if still maybe tightly-coupled, and anyone else looking at it can easily learn what you're doing by reading the code, instead of tracing it line-by-line.

The third time your cursor enters that code, it's probably kind of a big deal; you're either extending it yet again or it's become useful in at least three different other places in the codebase. At this point, it's a key, if not core, element of your system, and should be architected as such. At this point, you usually also have the knowledge of how it's been used so far, which will allow you to make good design decisions regarding how to architect the design to streamline those usages and any new ones. Now the SOLID rules should enter the equation; extract classes containing code with specific purposes, define common interfaces for any classes that have similar purposes or functionality, set up loosely-coupled dependencies between classes, and design the dependencies such that you can easily add, remove, or swap them.

From this point on, should you need to further extend, reimplement or re-use this code, it's all nicely packaged up and abstracted in the "black box" format we all know and love; plug it in wherever else you need it, or add a new variation on the theme as a new implementation of the interface without having to change the usage of said interface.


问:
What's the difference between CRM, CMS and ERP
I know that CRM stands for Customer Relationship Management, CMS stands for Content Management System and ERP stands for Enterprise Resource Planner. I would like to know what each of things does best and which scenarios they are used in. So basic understanding of the three with differences among them and the environments in which they are used.

Edit:  I read up on the Wiki a bit more and now I understand according to the ERP wiki that a CRM is a part of the ERP. My question to be more specific is:

 Why have a CRM separately if it's already a part of the ERP? Abstraction?

To log and store the information of a call-center that calls a hundred odd people to get info, which is more better to achieve the following tasks, a CRM or an ERP? :

Store all the information about all the people that we have been called

Store information about which person called and how many hours a person has worked?

Find out which employee has been more productive?

My friend strongly believes a CRM will get the job done. So thought I'd ask you guys which would be better and why does it make it better.

答:
In short, and from the viewpoint of a user of these systems:

A user of a CMS manages the content and structure of a website.
A user of a CRM manages a company's contacts.
A user of an ERP application manages invoices, product prices and inventory.

A CMS is something completely different than a CRM/ERP application.

There is often overlap between a CRM and an ERP, but a CRM is more focused towards sales people and an ERP system is more often used by administration.

I think wikipedia will tell you all you want to know.


答:
Typically,

A CRM is used to manage contact information (Salesforce).

A CMS is used to manage information for display to the general public (such as a web based CMS like Drupal).

An ERP system can typically refer to a system that is used to manage all aspects of operating a business, possibly including but not limited to: Purchasing, Sales, Accounting, Production, Payroll, Contacts/Customers/Vendors, etc. (DEACOM, SAP ERP, Oracle ERP, Microsoft Dynamics, ProsessPro).

Title: What's the difference between CRM, CMS and ERP

Body:
I know that CRM stands for Customer Relationship Management, CMS stands for Content Management System and ERP stands for Enterprise Resource Planner. I would like to know what each of things does best and which scenarios they are used in. So basic understanding of the three with differences among them and the environments in which they are used.

Edit:  I read up on the Wiki a bit more and now I understand according to the ERP wiki that a CRM is a part of the ERP. My question to be more specific is:

 Why have a CRM separately if it's already a part of the ERP? Abstraction?

To log and store the information of a call-center that calls a hundred odd people to get info, which is more better to achieve the following tasks, a CRM or an ERP? :

Store all the information about all the people that we have been called

Store information about which person called and how many hours a person has worked?

Find out which employee has been more productive?

My friend strongly believes a CRM will get the job done. So thought I'd ask you guys which would be better and why does it make it better.


问:
Can we replace XML with JSON entirely?
I'm sure lots of developers are familiar with XML and JSON, and they've used both of them. Thus no point in explaining what they are, and what is their purpose, even in brief.

If we try to map their concepts, we can say (correct me if I'm wrong):

XML tags are equivalent to JSON {}

XML attributes are equivalent to JSON properties

XML tag collection is equivalent to JSON []

The only thing I can think of, which doesn't exist in JSON, is XML Namespaces.

The question is, considering this mapping, and considering that JSON is highly lighter in this mapping, can we see a world in future (or at least theoretically think of a world) without XML, but with JSON doing everything XML does? Can we use JSON everywhere XML is used?

PS: Please note that I've seen this question. It's something entirely different from what I'm asking here. Thus please don't mention duplicate.

答:
It depends on the domain. In terms of web services? Absolutely. It's utterly shameful that vendors are still pushing SOAP on their customers. REST + JSON all the way.

Now, when you're talking about complex, structured data with style information like Docbook or other implementation? That's a proper domain for XML.

Title: Can we replace XML with JSON entirely?


答:
YAGNI and good design are not conflicting. YAGNI is about (not) supporting future needs. Good design is about making transparent what your software does right now and how it does this.

Will introducing a factory make your existing code simpler? If not, don't add it. If it does, for example when you are adding tests (which you should do!), add it.

YAGNI is about not adding complexity to support future functions.

Good Design is about removing complexity while still supporting all current functions.


问:
What is the term that describe objects representing both logic and data?
The reason I am asking this question is I want to know how to properly call an architecture where classes have either data or logic but not both. I know this goes against object orientation and encapsulation. I want to use the proper terms for discussing this architecture.

EDIT: By reading the answers I have received, I can see my question wasn't clear. I also feel the edit that was made didn't push the question in the direction I was going for.

I will restate the question in other terms.

Suppose you are working in C#, Java or some other OO language.

You have 2 designs:

DESIGN A:

```<code>class Car
{
     // data
     int numberOfWheels;
     Engine carEngine;

     // methods
     public void StartCar();
}
</code>```

DESIGN B:

```<code>class Car
{
     // this class contains only data (be it entity, DTO, whatever)
     int numberOfWheels;
     Engine carEngine;
}

class CarStarter
{
     public void StartCar(Car aCar);
}
</code>```

In DESIGN B, some classes are used as data structures/DTO/entities (they contain only data and should not contain methods). Other classes contains logic and work with the data classes.

Now suppose you have a design/architecture where DESIGN B, should be applied throughout rather than design A.

I was looking either for a term that described DESIGN B, or the OOP term/notion that consist of DESIGN A. Preferably both.

For the OOP term I guess encapsulation could be it. From Wikipedia Encapsulation

A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.

I still don't know how to call DESIGN B though.

答:
What is the term, in relation to OO programming, to describe objects that represent both logic and data.

Object

The question could be turned upside down, what would be the term to describe objects that contain only logic

Procedure if it has side-effects, Function if it is referentially transparent.

or only data.

Data

The reason I am asking this question is I want to discuss an architecture where objects only either have data or only have logic and I want to use the proper terms to do so.

This is called functional programming if the logic is referentially transparent and the data is immutable, and procedural programming otherwise.


答:
Data-only objects are commonly known as Data Transfer Objects.

Data-free objects are probably best called Stateless Objects, as there is no state within them to be maintained.

Title: What is the term that describe objects representing both logic and data?

Body:
The reason I am asking this question is I want to know how to properly call an architecture where classes have either data or logic but not both. I know this goes against object orientation and encapsulation. I want to use the proper terms for discussing this architecture.

EDIT: By reading the answers I have received, I can see my question wasn't clear. I also feel the edit that was made didn't push the question in the direction I was going for.

I will restate the question in other terms.

Suppose you are working in C#, Java or some other OO language.

You have 2 designs:

DESIGN A:

```<code>class Car
{
     // data
     int numberOfWheels;
     Engine carEngine;

     // methods
     public void StartCar();
}
</code>```

DESIGN B:

```<code>class Car
{
     // this class contains only data (be it entity, DTO, whatever)
     int numberOfWheels;
     Engine carEngine;
}

class CarStarter
{
     public void StartCar(Car aCar);
}
</code>```

In DESIGN B, some classes are used as data structures/DTO/entities (they contain only data and should not contain methods). Other classes contains logic and work with the data classes.

Now suppose you have a design/architecture where DESIGN B, should be applied throughout rather than design A.

I was looking either for a term that described DESIGN B, or the OOP term/notion that consist of DESIGN A. Preferably both.

For the OOP term I guess encapsulation could be it. From Wikipedia Encapsulation

A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.

I still don't know how to call DESIGN B though.


问:
How to decide which classes are necessary for the system
I know design principles and design patterns in theory. But it's embarrassing to realize that it's not clear when applying it in practice.

For example, let's think about simple tic tac toe console game. How would you decide what class is for certain responsibility and how do you determine that responsibility/class is necessary for the system even before applying design patterns or principles? I understand it should be based on requirements and domain knowledge, but there are lots ways to satisfy the requirements. If I take agile (TDD) approach, there are still many ways to achieve the key requirement by making it testable.

I wish there are many materials (books or web sites) on this but most of them are on theory but rarely on practices. I would appreciate if anybody can refer to such materials with which I can practice the class designs.

答:
If I take agile (TDD) approach, there are still many ways to achieve the key
  requirement by making it testable.

Yes, however, when you make the wrong decisions, there are some pretty blatant signals.

You will find very quickly that you have classes where there is nothing to test. When you find those, rethink your design, you probably don't need that class.

On the other hand, you'll also find code where you feel you are swimming in treacle while trying to write the tests. Again, rethink your design, it probably needs an abstraction layer you don't have yet.

In other cases, you'll find tests that fail intermittently. Again, this requires a rethink. Tests should always pass or always fail against the same piece of code; if they're dependant on situation then you need to abstract something out.

There are other lessons to learn but, as has been pointed out, you'll learn them more by trial and error than by reading.

However, if you really want an example to read through, there is a particularly good one in Robert C Martin's Agile Software Development, Principles, Patterns, and Practices, where two developers pair up to code a bowling score card TDD-style. They manage to fall into many of the traps of "obvious" design and show you how to adjust your design accordingly.


答:
Read this: http://en.wikipedia.org/wiki/Class-responsibility-collaboration_card.

And this:  http://alistair.cockburn.us/Using+CRC+cards

And this:  http://c2.com/doc/oopsla89/paper.html

It helps understand how to arrive at a sensible allocation of responsibility for a class definition.

Title: How to decide which classes are necessary for the system

Body:
I know design principles and design patterns in theory. But it's embarrassing to realize that it's not clear when applying it in practice.

For example, let's think about simple tic tac toe console game. How would you decide what class is for certain responsibility and how do you determine that responsibility/class is necessary for the system even before applying design patterns or principles? I understand it should be based on requirements and domain knowledge, but there are lots ways to satisfy the requirements. If I take agile (TDD) approach, there are still many ways to achieve the key requirement by making it testable.

I wish there are many materials (books or web sites) on this but most of them are on theory but rarely on practices. I would appreciate if anybody can refer to such materials with which I can practice the class designs.


答:
The books are written on the theory because in practice it only works for that practice example. I'd suggest just making a lot of small projects. Or analyzing the architecture of large projects.

If you feel crippled by indecision about the multiple ways in which you could solve a problem, simply pick one. Start at the beginning, work through the middle, and stop when you reach the end. Chances are you'll scrap your original decision and go with something else, but that's ok. Plan a little, work a little. Too much or too little of either will be detrimental to the whole.

Tic tac toe: First you need a board. You need a lot of other things, but you're having problems starting out, so the board is a good a place to start as any. A board has a 2D array of fields that can have three states. It needs to test for win conditions. It needs to tests for ties. These are things that COULD be done by some other object, but we're starting with the board. That could change in the future, but it's good for now.


答: Classes contain both logic in form of Members(Functions) and data in form of Fields(variables). The object representing the class at run-time is called Instance