问:
Is is possible to develop an application for both metro and classic style?
Is it possible to develop one application that can be be run in both: metro and classic style in Windows 8? I mean, application with the same core and two separate UIs, adjusted to currently used mode.</p>

答: It appears that you will need to modify .Net for Classic Windows to make Metro Apps. So it's not JVM style drag, drop and run; even with different GUIs. The differences are more fundamental.</p>


问:
Why are cyclic imports considered so evil?
Seriously, what's the big deal about having a few cycles in one's import graph?  I see it as a lesser evil than having super fine grained imports that make keeping track of where to look for what code an absolute nightmare.</p>

答:
Depending on your environment, cyclic dependencies across modules can make static linking impossible.  Module A cannot be linked until Module B is linked; but Module B depends on Module A and cannot be linked until Module A is linked.  This is why some environments - such as .NET and Delphi - don't allow this sort of thing at all.

Other environments/compilers/linkers may be more forgiving, but that does not make it better design.  While it seems to be generally accepted that cyclic dependencies within data structures are sometimes necessary (entity models, doubly-linked lists, certain kinds of trees... you get the picture), it is almost always a serious design flaw to have a cyclic module dependency.

Why?  Try to picture the initialization phase of an application, while modules are still being loaded.  Most modules count on the fact that all of their dependencies have been fully-loaded before running any initialization code.  Cyclic dependencies invalidate this assumption, because it's physically impossible (at least in this universe) for both modules to be loaded before each other.  Similarly, in the teardown phase, finalization code that makes perfectly reasonable assumptions may crash because a dependent module has already been unloaded by the runtime.

The worst part is that on most operating systems, when you have cyclic module dependencies, the load order is deterministic but impossible to predict.  So an assumption about initialization order that turns out to be correct today may suddenly break tomorrow due a totally innocent change in a totally different part of the application.  Tracking down these bugs can be an excruciatingly painful process.

Cyclic imports within a single package/module/assembly are really another story entirely.  An "import" can mean so many different things depending on the context.  In many cases they are "Considered Harmful" simply because early compilers couldn't handle them, so you had to do your own cycle detection with a bunch of #ifdef directives (or similar) and obviously, after a certain number of these, you start to lose your mind.  But in modern-day object-oriented programming it's often considered good practice to have one file per class, which means that a cyclic import is merely a sign of a cyclic class dependency, which as I mentioned above, isn't necessarily such a bad thing unless it's unnecessary.

If it's unnecessary, then it's a Bad Thing simply on account of the fact that any unnecessary complexity is a Bad Thing, and cyclic dependencies add complexity.

ContentLicense: CC BY-SA 2.5


答:
If you merely mean "possible", then the answer is yes.

If you want to know what you'll run into, you should ask a more precise question. :)

ContentLicense: CC BY-SA 3.0

Title: Is is possible to develop an application for both metro and classic style?

Body: Is it possible to develop one application that can be be run in both: metro and classic style in Windows 8? I mean, application with the same core and two separate UIs, adjusted to currently used mode.</p>


问:
Diagram that could explain a state machine's code?
We have a lot of concepts in making diagrams like UML and flowcharting or just making up whatever boxes-and-arrows combination works at the time, but I'm looking at doing a visual diagram on something that's actually really complex.

State machines like those that parse HTML or regular expressions tend to be very long and complicated bits of code.

For example, this is the stateLoop for FireFox 9 beta. It's actually generated by another file, but this is the code that runs.

How can I diagram something with the complexity of this in a way that explains flow of the code without taking it to a level where I draw every single line-of-code into it's own box on a flowchart?

I don't want to draw "Invoke loop, then return" but I don't want to explain every last detail.

What kind of graph is suitable to do this? Is there already something out there similar to this? Just an example of how to do this without going overboard in complexity or too-high-level is really what I want.

If you don't feel like looking at the code, basically it's 70 different state flags that could occur, inside an infinite loop that exists to a label based on some conditions, each flag has it's own infinite loop that exists to a label somewhere, and each of those loops has checks for different types of chars, which then runs off into various other methods.

答:
For something that long, you're best bet is to create a dynamic state diagram. (Yay for computers!)  I have never seen one, but it's easy enough to imagine a debugger-like view of the diagram where you have "watch" variables to track the current state while you make choices of which state to examine.  It would end up allowing you to see all of one state on-screen and understand things by watching what happens when things change.

It could be a bit of work, and someone may have created it before.  I just hope the idea helps.


问:
Difference between REST and CRUD
I learned REST and it feels a lot like CRUD (from what I have read about CRUD).

I know they are different, and I wonder if thinking they are similar means I don't understand them.

Is it that REST is a "superset" of CRUD?  Does it do everything CRUD does and more?

答:
CRUD specifies a minimal set of basic storage verbs for data reading and writing: create, read, update and delete. Then, you can build other operations by aggregating these. These are usually considered database operations, but what is considered a database is arbitrary (e.g., could be a relational DBMS, but could also be YAML files).

REST is an "architectural style" that usually includes CRUD operations and other, higher level operations, all to be performed on some concept of "resources" (arbitrary, but these are entities in your application). REST has a bunch of constraints that make it interesting (and particularly well-paired with HTTP).

A REST interface can, but doesn't have to, expose all CRUD operations on a particular resource. What is available in a REST interface is arbitrary and may change due to system permissions, UI considerations, and how hot it was on the day the interface was designed and created. Hotter days lead to more minimalist interfaces, usually, though the opposite can be true.

ContentLicense: CC BY-SA 4.0

Title: Difference between REST and CRUD


答:
First of all, both are simply common initials; they're nothing to be afraid of.

Now, CRUD is a simple term that was abbreviated because it's a common feature in many applications, and it's easier to say CRUD. It describes the 4 basic operations you can perform on data (or a resource). Create, Read, Update, Delete.

REST however, is a named practice (just like AJAX), not a technology in itself.
It encourages use of capabilities that have long been inherent in the HTTP protocol, but seldom used.

When you have a URL (Uniform Resource Locator) and you point your browser to it by the address line, you're sending an HTTP request. Each HTTP request contains information that the server can use to know which HTTP response to send back to the client that issued the request.

Each request contains a URL, so the server knows which resource you want to access, but it can also contain a method. A method describes what to do with that resource.

But this "method" concept wasn't used very often.

Usually, people would just link to pages via the GET method, and issue any type of updates (deletions, insertions, updates) via the POST method.

And because of that you couldn't treat one resource (URL) as a true resource in itself. You had to have separate URLs for deletion, insertion or update of the same resource. For example:

```<code>http://...com/posts/create- POST request  -> Goes to posts.create() method in the server
http://...com/posts/1/show- GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1/delete - POST request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1/edit- POST request  -> Goes to posts.edit(1) method in the server
</code>```

With REST, you create forms that are smarter because they use other HTTP methods aside of POST, and program your server to be able to distinguish between methods, not only URLS. So for example:

```<code>http://...com/posts - POST request  -> Goes to posts.create() method in the server
http://...com/posts/1 - GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1 - DELETE request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1 - PUT request  -> Goes to posts.edit(1) method in the server
</code>```

Remember, a single URL describes a single resource. A single post is a single resource.
With REST you treat resources the way they were meant to be treated. You're telling the server which resource you want to handle, and how to handle it.

There are many other features to "RESTful architecture", which you can read about in Wikipedia, other articles or books, if you're interested. There isn't a whole lot more to CRUD itself, on the other hand.

Title: Difference between REST and CRUD

Body:
I learned REST and it feels a lot like CRUD (from what I have read about CRUD).

I know they are different, and I wonder if thinking they are similar means I don't understand them.

Is it that REST is a "superset" of CRUD?  Does it do everything CRUD does and more?

Body:
First of all, both are simply common initials; they're nothing to be afraid of.

Now, CRUD is a simple term that was abbreviated because it's a common feature in many applications, and it's easier to say CRUD. It describes the 4 basic operations you can perform on data (or a resource). Create, Read, Update, Delete.

REST however, is a named practice (just like AJAX), not a technology in itself.
It encourages use of capabilities that have long been inherent in the HTTP protocol, but seldom used.

When you have a URL (Uniform Resource Locator) and you point your browser to it by the address line, you're sending an HTTP request. Each HTTP request contains information that the server can use to know which HTTP response to send back to the client that issued the request.

Each request contains a URL, so the server knows which resource you want to access, but it can also contain a method. A method describes what to do with that resource.

But this "method" concept wasn't used very often.

Usually, people would just link to pages via the GET method, and issue any type of updates (deletions, insertions, updates) via the POST method.

And because of that you couldn't treat one resource (URL) as a true resource in itself. You had to have separate URLs for deletion, insertion or update of the same resource. For example:

http://...com/posts/create- POST request  -> Goes to posts.create() method in the server
http://...com/posts/1/show- GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1/delete - POST request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1/edit- POST request  -> Goes to posts.edit(1) method in the server

With REST, you create forms that are smarter because they use other HTTP methods aside of POST, and program your server to be able to distinguish between methods, not only URLS. So for example:

http://...com/posts - POST request  -> Goes to posts.create() method in the server
http://...com/posts/1 - GET request  -> Goes to posts.show(1) method in the server
http://...com/posts/1 - DELETE request  -> Goes to posts.delete(1) method in the server
http://...com/posts/1 - PUT request  -> Goes to posts.edit(1) method in the server

Remember, a single URL describes a single resource. A single post is a single resource.
With REST you treat resources the way they were meant to be treated. You're telling the server which resource you want to handle, and how to handle it.

There are many other features to "RESTful architecture", which you can read about in Wikipedia, other articles or books, if you're interested. There isn't a whole lot more to CRUD itself, on the other hand.


问:
How one could use a live editor
I was thinking about a live editing environment where code / a source file is synchronized so that changes made by one user would be carried across to all others editing the file.
Something like Google Wave, but for code.

Could this kind of an environment be better for the code, as changes are shared instantly?
(with revision-control, of course)

Has anyone tried (or has had a need for) using a shared environment for code?
I'd love to hear from someone who has used such an editor.

答: You are talking about a collaborative real-time editor, which is an old idea. There are numerous products that support it to varying degrees. Check out SubEthaEdit for a recent example. This screenshot provides an overview of how it could be used in practice.</p>

Title: How one could use a live editor


答:
How can I diagram something with the complexity of this in a way that explains flow of the code without taking it to a level where I draw every single line-of-code into it's own box on a flowchart?

I would suggest that you define the purpose of the diagram and the scope of detail you want to provide. You either want a precise diagram or an overview diagram.

Diagrams reflecting precise information usually end up messy.  To overcome diagram complexity, you would generally do this:

Break the state flow into separate logical pieces with clear start and end. Use state machine chart to show each logical set. Sort the sets by either start or end state. This will show the flow of state (but not the code). The State Machine diagram suggested by other contributors to this post is the only way to precisely represent state change visually.

Alternatively, use Pseudo code with rules table. Rules table reduce the complexity of the text significantly (I wish programming languages could implement then in their editors).
This combination will show program flow and rules for arriving to a given state but won't give an obvious visual state transition flow.

If you are providing an overview diagram, you may choose to show the major states on a State Machine diagram.

Edit:
Another way to represent this kind of information,is by using a table/matrix. Show each state in a separate column and each state in a separate row of the matrix. The intersection represents the conditions under which the transition occurs. Empty cells indicate that there is no state transition between the intersecting states. To show transition direction define 2 colors. One for transition from row value to column value and another to represent transition from column value to row value. The matrix option proposed here can be used with all above mentioned suggestions. if you add a number to cells where transitions occur, you could then show a flow of transitions (not shown in the example).

Title: Diagram that could explain a state machine's code?

Body:
We have a lot of concepts in making diagrams like UML and flowcharting or just making up whatever boxes-and-arrows combination works at the time, but I'm looking at doing a visual diagram on something that's actually really complex.

State machines like those that parse HTML or regular expressions tend to be very long and complicated bits of code.

For example, this is the stateLoop for FireFox 9 beta. It's actually generated by another file, but this is the code that runs.

How can I diagram something with the complexity of this in a way that explains flow of the code without taking it to a level where I draw every single line-of-code into it's own box on a flowchart?

I don't want to draw "Invoke loop, then return" but I don't want to explain every last detail.

What kind of graph is suitable to do this? Is there already something out there similar to this? Just an example of how to do this without going overboard in complexity or too-high-level is really what I want.

If you don't feel like looking at the code, basically it's 70 different state flags that could occur, inside an infinite loop that exists to a label based on some conditions, each flag has it's own infinite loop that exists to a label somewhere, and each of those loops has checks for different types of chars, which then runs off into various other methods.


答:
You probably will want either a full traditional state diagram or a summary pseudo-state diagram.

The full diagram would have a state circle for each of the (in your example) 72 states, and each of the transitions (including self loops).  Such a diagram is good for documentation and study for modifications.  It is easier to deal with than the C code as it suppresses the irrelevant verbiage.

A summary diagram would be better for an introduction to the state machine code.  It would require you to figure out some "super states" that represent groups of real states.  This is often not too hard. In your example, it looks like the states with the "NS_HTML5TOKENIZER_COMMENT" name prefix can be grouped together, for instance.  So in your diagram you would have one "comment parsing" super state to represent these 6 six real states.  Then you make a fairly normal state diagram using these super states, showing the major transitions (or all, if you want accuracy) between the super states.  This reduces the complexity of the diagram and show the major functions going on in the machine.


问:
How should we deal with multiple transaction-report requests?
We are developing a system for the retail market and of its features will enable clients (actually consumer clubs) to go through all transactions made by end-clients.

One of the ways to get this information will be via an API.

The idea is that there will be requests for reports with a start date and an end date, and a response will have all the transactions between those dates.

We worry that some reports will be very large, and that some clients will repeatedly request for reports, in this case the DB and CPU will be very overloaded.

The same server that is going to service those requests will also take care of the actual retail transactions (received by proprietary devices) and of the Web application.

We are not sure about how to limit the report requests from the API so that it won't affect the system too much.

So, how should we deal with this scenario? any thoughts?

EDIT:

just to make it clear:
When I mentioned proprietary devices I meant "On-Location" devices which are used during sales with end-clients, this means that these requests shouldn't get delayed, and this is the main concern.

One more question : Some people here suggested the use of prioritized threads, i.e. - giving lower priority to the threads retrieving the reports, is this a good idea?

答:
If you make a business rule such that 1 customer may ask for at most 3 reports a day and the total duration of dates in between is not greater than 30, then you could design a table that the system checks before a report request is processed.

A better approach to study the reporting requirement a bit further and consider an Data Mart approach. Move the data to the data mart sever and let the users run the reports as much as they want from the data mart server. Of course this will require more work but it is the better approach from an architecture perspective and it will help your customers with other reporting needs too in the future.


答:
I love this code!

We have had twenty years of object-orientation now, but some people still don't get it. Hey Geeks: There is a difference between spaghetti carbonara and  spaghetti code.

As this is generated code, why don't you visualize it from a higher level of abstraction? We don't know how "generated by another file" works, but it seems that the mechanism is easier to understand from the other files perspective otherwise code generation wouldn't make any sense. Provided that the transformation is correct, the information is the same.


问:
Unit tests, write them before or after the framework?
This is my first question here, so i'll make it short and to the point.

When Writing unit tests, should you write them before or after you have made the underlying framework for them? This came up in a discussion between my CEO and President, and I wanted your opinion on this.

Personally, I have always wrote the code first, then wrote the unit tests, but what about you?

答: Write the unit tests first - they'll help you define your interfaces - starting from what functionality they expose down to the method signatures.</p>


答:
Limit the API access to the most recent: day, week, month, whatever volume you can handle. Anything older could be provided in prebuilt compressed files from an ftp archive site. The limitation of course is changing the format of the archived files.

Do they just need the data to pull into their own analysis and reporting systems or are you providing the code for querying the data?

Title: How should we deal with multiple transaction-report requests?

Body:
We are developing a system for the retail market and of its features will enable clients (actually consumer clubs) to go through all transactions made by end-clients.

One of the ways to get this information will be via an API.

The idea is that there will be requests for reports with a start date and an end date, and a response will have all the transactions between those dates.

We worry that some reports will be very large, and that some clients will repeatedly request for reports, in this case the DB and CPU will be very overloaded.

The same server that is going to service those requests will also take care of the actual retail transactions (received by proprietary devices) and of the Web application.

We are not sure about how to limit the report requests from the API so that it won't affect the system too much.

So, how should we deal with this scenario? any thoughts?

EDIT:

just to make it clear:
When I mentioned proprietary devices I meant "On-Location" devices which are used during sales with end-clients, this means that these requests shouldn't get delayed, and this is the main concern.

One more question : Some people here suggested the use of prioritized threads, i.e. - giving lower priority to the threads retrieving the reports, is this a good idea?


问:
Graduate expectations versus reality
When choosing what we want to study, and do with our careers and lives, we all have some expectations of what it is going to be like. Now that I've been in the industry for almost a decade, I've been reflecting a bit on what I thought (back when I was studying Computer Science) programming working life was going to be like, and how it's actually turning out to be.

My two biggest shocks (or should I say, broken expectations) by far are the sheer amount of maintenance work involved in software, and the overall lack of professionalism:

Maintenance: At uni, we were all told that the majority of software work is maintenance of existing systems. So I knew to expect this in the abstract. But I never imagined exactly how overwhelming this would turn out to be. Perhaps it's something I mentally glazed over, and hoped I'd be building cool new stuff from scratch a lot more. But it really is the case that most jobs are overwhelmingly maintenance, bug fixing, and support oriented.

Lack of professionalism: At uni, I always had the impression that commercial software work is very process-oriented and stringently engineered. I had images of ISO processes, reams of technical documentation, every feature and bug being strictly documented, and a generally professional environment. It came as a huge shock to realise that most software companies operate no differently to a team of students working on a large semester-long project. And I've worked in both the small agile hack shop, and the medium sized corporate enterprise. While I wouldn't say that it's always been outright "unprofessional", it definitely feels like the software industry (on the whole) is far from the strong engineering discipline that I expected it to be.

Has anyone else had similar experiences to this? What are the ways in which your expectations of what our profession would be like were different to the reality?

答:
A lot of software just doesn't make it to the point where it gets used/purchased enough. When one makes it, it tends to stick around and is only "messed" with in maintenance.

User expectations are increasing every day for features, but in many areas, they are lower in areas of engineering. Let's assume banking transaction software is as solid and professionally engineered as a modern automobile. The handling of volume is a modern marvel, but what abouut the reliability of each transaction? Not so much. Your post about your puppy's first crap on the rug was dropped, so what. It's more like the little plastic bags at the grocery store. They make billions of them, they rip and tear and get thrown away. Most people don't care enough to demand a better bag.

I think quality software gets made, eventually. Some of that hits the market sooner than most comemercial products. Who gets to drive a car in Beta?

Title: Graduate expectations versus reality


答:
During. You're not going to get an entire framework done in one iteration. Your framework and unit tests should co-evolve simultaneously.

On a more micro scale, tests first, code second.

Title: Unit tests, write them before or after the framework?

Body:
This is my first question here, so i'll make it short and to the point.

When Writing unit tests, should you write them before or after you have made the underlying framework for them? This came up in a discussion between my CEO and President, and I wanted your opinion on this.

Personally, I have always wrote the code first, then wrote the unit tests, but what about you?


问:
How do I deal with analysis paralysis?
Very frequently, I am stuck when choosing the best design decision. Even for small details, such as function definitions, control flow, and variable names, I spend unusually long periods perusing the benefits and trade-offs of my choices.

I feel like I am losing a lot of efficiency by spending my hours on insignificant details like these. Even though, I know in the back of my mind that I can change these things if my current design doesn't work out, I have trouble deciding firmly on one choice.

What should I do to combat this problem?

答:
Often, the best solution is to try explaining your decision to a colleague. However, since you don't want to do this very often, the next best thing is to think on paper - either with a paper/pen, or an empty notepad window.

Start by writing absolutely anything - just to get into the rhythm of writing. In a notepad window you may just type "I am thinking on paper" and then just carry on with a stream of consciousness. After a few seconds you'll be in the rhythm of writing, so press enter a few times, and start explaining your dilemma.

State the problem, then state the possible solutions, what's good about each one, etc.

Though it doesn't always work, the process of getting thoughts out of your head (RAM) and onto external media (the notepad document) gives you more freedom to make new connections, and view the decision from different perspectives.

Title: How do I deal with analysis paralysis?


问:
What are the most over-saturated iPhone App category/markets?
I'm considering learning iPhone development and Objective C but don't want to avoid developing something for the most saturated markets and app categories.

What categories should I avoid?  Are there too many dating applications, or should I just stick to coming up with a creative game or two?

答:
If you want to know what's on the App Store, look at the App Store.

I don't think you are going to produce good work if you start by asking yourself, "What should I not do?"

Come up with a few ideas for apps, then search the App Store for them. If you find a dozen apps already there, you can avoid that category. (Unless you think you can do something much better than what's already there.) Then you can make your plans based on the search results.


答:
I suffer from the same problem. For small problems, the way I try to deal with it is to go with the first design I think of that isn't stupid. There's no point trying to find an optimal design; it's difficult if not impossible to reason about all of the nuances of any design you may think of without writing it up. As you code, you'll find that you can make small improvements. Done right, I find it's fairly easy to converge on a reasonably good solution this way.

For bigger problems, I think there is merit in thinking through your options first, but timebox it. Big problems have big solution spaces, you can't evaluate every possibility, neither should you try to.

TLDR; Pick a reasonable solution, improve it as you go.

This is also relevant:

The ceramics teacher announced on opening day that he was dividing the
  class into two groups. All those on the left side of the studio, he
  said, would be graded solely on the quantity of work they produced,
  all those on the right solely on its quality. His procedure was
  simple: on the final day of class he would bring in his bathroom
  scales and weigh the work of the "quantity" group: fifty pound of pots
  rated an "A", forty pounds a "B", and so on. Those being graded on
  "quality", however, needed to produce only one pot - albeit a perfect
  one - to get an "A".

Well, came grading time and a curious fact emerged: the works of
  highest quality were all produced by the group being graded for
  quantity. It seems that while the "quantity" group was busily churning
  out piles of work - and learning from their mistakes - the "quality"
  group had sat theorizing about perfection, and in the end had little
  more to show for their efforts than grandiose theories and a pile of
  dead clay.

from http://www.codinghorror.com/blog/2008/08/quantity-always-trumps-quality.html .

Title: How do I deal with analysis paralysis?

Body:
Very frequently, I am stuck when choosing the best design decision. Even for small details, such as function definitions, control flow, and variable names, I spend unusually long periods perusing the benefits and trade-offs of my choices.

I feel like I am losing a lot of efficiency by spending my hours on insignificant details like these. Even though, I know in the back of my mind that I can change these things if my current design doesn't work out, I have trouble deciding firmly on one choice.

What should I do to combat this problem?


问:
Why aren't postfix and primary expressions symmetrical?
Every primary expression is a postfix expression but a postfix expression is not primary expression.

But in mathematics, equality seems to be symmetrical. That is:

If A is B, then B is A

Why isn't this the case for postfix and primary expressions?

答:
What you have here is not a problem with programming or logic, but an English comprehension problem.

The verb “be” has many different meanings in English. Human languages very often omit logical connectives like quantifiers. Sometimes, “be” expresses an equivalence:

A mare is an adult female horse.

Stated semi-formally, this sentence means that the word “mare” means the same thing as “adult female horse”.

Sometimes, “be” expresses that a concept is an instance or example of another concept.

A horse is an animal.

States semi-formally, this sentence means that any entity that has the property of being a horse also has the property of being an animal.

Which meaning is intended is normally clear from context. In everyday situations, humans automatically infer the right context almost all the time; this is why languages tend to omit precise logical connectives unless they are really necessary. Mathematical texts that deal with somewhat abstract notions often need to make logical connectives very clear, and hence use more precise language, often backed with mathematical notations.

The statement “a primary expression is a postfix expression” is of the second kind. Every expression that belongs to the category of primary expressions also belongs to the category of postfix expressions. This statement does not imply that every postfix expression is a primary expression.

In a comment, you suggest the statement “primary expression may be a postfix expression”. This statement, in everyday english, is wrong. It implies that some primary expressions are postfix expressions, and some are not. This is not the case: every primary expression is a postfix expression. On the other hand, it is true that a postfix expression may be a primary expression: there are postfix expressions that are also primary expressions, and postfix expressions that are not.


问:
Would you put your Stack Overflow profile link on your CV / Resume?
If applying for a new job, would you put your Stack Overflow profile link on your resume?

This would show the employer you're an active member of the development community and also provide an insight into your knowledge + how well you convey your ideas.

However it would feel a bit gimmicky to me?

答:
Yes.

Your SO profile gives potential employers a look at you actually coding, as well as your ability to solve problems and seek help.  If you have any amount of reputation there, I'd say put it on.  Either a URL alongside your contact info, or a bullet under "Misc"/"Other" with your rep.


问:
Showing real time data using WCF call (silverlight)
Currently I have a WCF method which brings back all the data from the db and binds it to a grid, but I would like to call this method regularly to get the updated data back each time, to show the user real time data, what is the best way to go about this?

Thanks in advance.

答:
I would create a backgroundworker thread and put it into an endless loop. You could send the request to the service asynchronously if a specified period of time has elapsed (2 seconds maybe?) and you are not still waiting on results from the previous request. When the completion event fires, update your UI.

Having said that, if there is a lot of data involved, I would find out if there was a way in which you could only retrieve the differences between the last data that you received and the current data (i.e. adds, updates, deletes) and only make those changes to the grid data rather than rebinding every time.


问:
Analyzing a programming language
In SICP, the authors state (Section 1.1) that there are three basic "mechanisms" of programming languages:

primitive expressions, which represent the simplest entities the language is concerned with

means of combination, by which compound elements are built from simpler ones

means of abstraction, by which compound elements can be named and manipulated as units

How can I analyze a mainstream programming language (Java, for example) in terms of these elements or mechanisms?

答:
The distinction between primitive expressions, means of combination and means of abstraction is a useful one when modelling programming languages. Note that this is not an intrinsic property of the language: you can't point at any language definition and say “this feature is unambiguously a primitive expression, that feature is unambiguously a means of combination”. The distinction is a property of the model, and complex models can resist classification.

A textbook example of these three concepts is the lambda calculus, which has exactly one of each:

Variables x, y, … are the only primitive expressions.

Function application M N is the one means of combination.

Lambda abstraction λx.M is the one means of abstraction.

When you get to languages with more features, the modeling can become more ambiguous. Generally speaking, a primitive expression is one that you can't or won't break down into primitive components. But it's like the atom: it's primitive until science marches on. For example, there is a variant of the lambda-calculus in which variables use numbers rather than names (de Bruijn indices), which is particularly convenient when modeling lambda-terms for computer proofs; and in computer proofs, integers are broken down into constituent parts. So in these models, variables aren't primitive expressions after all.

In (a typical model of) Java, primitive expressions are primarily constants and variables. Means of combinations include the numerous operators; more precisely, “additive expression” is a means of combination with two slots (the left-hand side and the right-hand side), or with three slots (the two sides plus the operator) if you include both A + B and A - B under that name (in which case the operators + and - would be primitive constructs in their own right). Other means of combination include sequences of instruction I ; J, loop constructs while (…) {…}, and so on. Then you have constructs like variable declarations, function definitions, class definitions and so on which are both means of combinations (they combine parameter names and types, bodies, initializers, …) and means of abstraction (because they define names for reuse). It is in fact quite common that means of abstraction are also means of combination: they combine a name with its definition.

Title: Analyzing a programming language


问:
Design For Asynchronous User Interface
I have been working on a integration that has posed an interesting user interface conundrum that I would like suggestions for.

The user interface is displayed within a third party product. The state of the interface is supplied by calls to a service I have written. There can be small delays between the actual state changing the the user interface changing due to the polling for state by the third party.

When a user interacts with the user interface, requests are sent back to my application. This then affects the state and the next state poll request will update the user interface.

The problem is that the delay between pressing a button and seeing the user interface update is perhaps 1 or 2 seconds and in usability testing I can see that people are clicking again before the user interface updates, thinking that they haven't properly clicked the first time.

Given the constraints (we can only update the user interface via the polling mechanism - if we updated it when they clicked, the polling might return and overwrite the change causing unpredictable / undesirable results)... what can we do to make the user experience better.

My current idea is to show a message for a couple of seconds so people know their click was accepted, the message would not be affected by the state polling, so wouldn't be prematurely removed / overwritten etc. I'm sure there are other ideas out there and I'm also confident someone has a better idea that I have!

答:
Immediately show some feedback: change the visual state of the button, display an animated throbber.

If the app logic allows, disable the button once it has been pressed, enable it back when the answer arrives.

Once the answer has arrived, show the real feedback: update the controls, remove the throbber.

Title: Design For Asynchronous User Interface


问:
What is an effective way to convert a shared memory-mapped system to another data access model?
I have a code base that is designed around shared memory.  Each process that needs to access the memory maps it into its own address space.  The data structures in the shared memory are directly accessed, that is, there is no API.  For example:

Assume the following:

```<code>typedef struct {
  int x;
  int y;
  struct {
    int a;
    int b;
  } z;
} myStruct;

myStruct s;
</code>```

Then a process might access this structure as:

```<code>myStruct *s = mapGlobalMem();
</code>```

And use it as:

```<code>int tmpX = s->x;
</code>```

The majority of the information in the global structure is configuration information that is set once and read many times.  I would like to store this information in a database and develop an API to access the database.  The problem is, these references are sprinkled throughout the code.  I need a way to parse the code and identify global structure references that will need to be refactored.

I've looked into using ANTLR to create a parser that will identify references to a small set of structures and enter them into a custom symbol table.  I could then use this symbol table to identify which source files need to be refactored.  It looks like a promising approach.

What other approaches are there?  Of course, I'm looking for a programmatic approach.  There are far too many source files to examine each one visually.

This is all ordinary ANSI C.  Nothing else.

答:
I am assuming this is a part of a big project because you mentioned 'too many source files'. I am unclear about the final objective. You can put the configuration in a database and modify mapGlobalMem() to populate & return a memory location that contains the configuration. That way you're not breaking your contract with the current code but you've moved your configuration 'outside' the process. I am assuming you dont want to make a call to the database each time someones trying to access the configuration information.

Now, if you're worried about freshness and hence you need to refactor this out into an API, I would suggest looking for all occurances of mapGlobalMem() and myStruct. This should give you a ball park estimate.

Ultimately, if you're trying to automate this change, I'd assume you'd spend more time automating it than a simple sed / find-replace.


答:
Check parapura's answer in this Question.

This approach is called long polling, its simple and should provide you the data you want whenever its available from the server side.

Check this Blog for more detailed sample class.

Title: Showing real time data using WCF call (silverlight)

Body:
Currently I have a WCF method which brings back all the data from the db and binds it to a grid, but I would like to call this method regularly to get the updated data back each time, to show the user real time data, what is the best way to go about this?

Thanks in advance.


答:
It Depends

When I was looking for a job a month ago, I didn't put a link to SO on my resume, but I did mention that I participate on SO and added a link to my blog that contains the SO "flair" on the About page. At that point I had about 3000 rep.

I wouldn't try to leverage rep, but I would leverage intelligent participation. If you act like a moron on SO and draw attention to it, that's obviously a bad move. But if you say "hey, I participate on this dedicated Q&A site" and you have been giving good answers and asking smart questions, it can work in your favour as it shows passion for your work and fellow developers.

Title: Would you put your Stack Overflow profile link on your CV / Resume?

Body:
If applying for a new job, would you put your Stack Overflow profile link on your resume?

This would show the employer you're an active member of the development community and also provide an insight into your knowledge + how well you convey your ideas.

However it would feel a bit gimmicky to me?


问:
Need to figure out Timesheet via Email
So we are thinking that we might want to make timesheet submission easier by having our timesheet system send out a person's timesheet via email to the employee. The employee then should fill out the timesheet and send it back via email for it to be processed. Anybody know of some write up on how other's have done this? I've googled but without luck.

Thanks for any thoughts/input.

答:
You could have a look at ADOBEs interactive PDF forms:-
Create Fillable PDF forms which would seem to be the Rolls Royce solution.

You could achieve the much the same thing with Microsoft EXCEL, some VBA scripts and some mail server cludges. You would need to mess around with password protecting worksheets and making sure the scripts could not be edited to achieve some sort of reliability.

Title: Need to figure out Timesheet via Email


问:
Who is responsible for the development of Java?
When I google about Java, the companies most mentioned are Sun, Oracle and IBM. I know that Oracle bought Sun, and the Java official website is Oracle domain, so I can assume that Oracle is the official Java developer. But after a little research, IBM also provides many tutorials and documents about Java. Why is this? Is IBM also involved in some development of Java?</p>

答:
Oracle does own the "Java" trademark, but anyone can implement a JVM.  From Java Virtual Machine:

Oracle, the owner of Java, produces a JVM, but JVMs using the "Java" trademark may be developed by other companies as long as they adhere to the JVM specification published by Oracle and to related contractual obligations.

IBM publishes a lot of documentation about Java because they've implemented a JVM called IBM J9, as well as the WebSphere application server.


问:
What are the differences between aspect-oriented, subject-oriented, and role-oriented programming?
I know there are many papers describing these three paradigms but I'm looking for a schematic explanation.

There are a few very good descriptions of aspect-oriented programming on here so I'm asking this question in the hope to get the kind of high-quality answer people at Stack Overflow are used to delivering.

答:
One can answer this by writing a book on this. However, here is a basic comparison

1. Subject oriented Programming

Subject-Oriented Programming is radical departure from the Object oriented as follows. In OO, objects are defined in terms of intrinsic (i.e. based on a model that independently describes it). and based on this its attributes (properties) and methods (behavior) are derived. The application makes only the use of these properties and behavior. Contrary to this, in subject oriented programming, no object exists (and modeled) in such an isolation. In the process, but behaviors of the objects is been provided by the various other "subjects” of the objects which are beyond the scope and control of the author of the original object. Think of it as a way of extending various "independently definable behaviors" on the object. I think this would be way beyond defining templates of inheritance compared to what is being discussed here.

The undisputed origin of terms (and concept) comes from the paper "Subject Oriented Programming: A Critique of Pure Objects, William Harrison and Harold Ossher". Here is another good paper. Though personally i believe this is a theoretical framework. I don't know if there are any languages/implementation

See this, this and this for more info.

2. Aspect Oriented Programming

Aspect oriented programming has originated from the concept of "Separation of oncerns". Basically it extends the either procedural or object oriented programming for concerns which are cross-cutting. Over simplifying one can say that software has functional requirements and non-functional ones. These cross cutting requirements includes examples like logging, exception handling, thread synchronization, memory management, optimization and so on. These cross cutting ASPECTS should be expressed and implemented separately and independently to any other functional parts.

A comprehensive work in this area is from IBM; basically each such concerns or aspects can be independent from each other forming multidimensional "concern space". , (read this).

Some of the good practical implementations of Aspect Oriented are AspectJ and AspectC++ and many more. See this.

3. Role Oriented Programing

As we evolve towards agents, many a times it is necessary to define "roles" and objectives where as exact activities that agent ends-up performing depends on the environment it is in. This is analogous to human conceptual understanding.

The primary objective is to decouple objective of task from it's co-operation capability by defining explicit construct called cooperation processes.
A role is modeled as a set of the capabilities and an expected behavior. however, these approaches also allow modeling of the execution environment and how agent/object can perceive the environment as well. See this.

There are various frameworks proposed in the research for role based modeling and implementations. A few of them are ROPE, BRAIN, ALAADIN and more.

OwnerDisplayName: Peter Fountain


问:
audio and video data in RTP
Suppose a user wants to transmit both audio and video to another user, whose formats are AMR for audio and H.264 for video. Does the user have to transmit audio and video packets always separately? Meaning that it is not possible to mix audio and video within the same RTP packed, is that correct?

If this is true I guess the RTP protocol will need to know the SSRC of both audio and video to be able to check the sync of the two streams.

答:
In order to ensure proper playback, the audio and video data MUST always be multiplexed together along with the timing information. This is done by various container formats like mp4 or 3gpp or mov.

In the file formats the audio and video data are partitioned in the form of chunks and their time of playout is marked. This allows players to understand when to display video to screen and put the audio samples to speaker - irrespective of how they arrive. Usually there is sufficient buffer to ensure that sufficient time still exists after all network delays to reach the data to rendering even if audio and video has a different amount of delay while transmission.

If you use container formats such as ones mentioned above, RTP doesn't need to know whether particular packet is Audio or Video.

One more thing - SSRC doesn't really provide any crucial timing information by itself. It is only a label. For example, if i a DVR is receiving data from 16 cameras (and 16 microphones for audio), it needs reference for each such source. This is only an address or identifier not a source of timing information. So if logically, audio and video comes from same source, it can have same tag.

Title: audio and video data in RTP


答:
Sun was the creator of the Java programming language, until it was bought by Oracle 2 years ago. Now, as Bill said, Oracle owns the java trademark.

On the other hand, Oracle and IBM announced in October 2010 that we will collaborate in the OpenJDK Community to develop the leading open-source Java SE implementation, and make the OpenJDK Community the primary location for open-source Java SE development.

So, regarding the development of the Java language itself, Oracle, IBM and any individual developer can contribute with the next version of java (JDK 7).

If you have any more questions about Java Language don't hesitate to check the Open JDK FAQ or ask here.

Title: Who is responsible for the development of Java?

Body: When I google about Java, the companies most mentioned are Sun, Oracle and IBM. I know that Oracle bought Sun, and the Java official website is Oracle domain, so I can assume that Oracle is the official Java developer. But after a little research, IBM also provides many tutorials and documents about Java. Why is this? Is IBM also involved in some development of Java?</p>


问:
Difference between REST and CRUD
I learned REST and it feels a lot like CRUD (from what I have read about CRUD).

I know they are different, and I wonder if thinking they are similar means I don't understand them.

Is it that REST is a "superset" of CRUD?  Does it do everything CRUD does and more?

答:
Surprisingly, I don't see in the other answers what I consider the real difference between REST and CRUD: what each one manages.

CRUD means the basic operations to be done in a data repository.  You directly handle records or data objects; apart from these operations, the records are passive entities.  Typically it's just database tables and records.

REST, on the other hand, operates on resource representations, each one identified by an URL.  These are typically not data objects, but complex object abstractions.

For example, a resource can be a user's comment. That means not only a record in a 'comment' table, but also its relationships with the 'user' resource, the post that comment is attached to, maybe another comment that it responds to.

Operating on the comment isn't a primitive database operation, it can have significant side effects, like firing an alert to the original poster, or recalculating some game-like 'points', or updating some 'followers stream'.

Also, a resource representation includes hypertext (check the HATEOAS principle), allowing the designer to express relationships between resources, or guiding the REST client in an operation's workflow.

In short, CRUD is a set primitive operations (mostly for databases and static data storages), while REST is a very high-level API style (mostly for web services and other 'live' systems).

The first one manipulates basic data, the other interacts with a complex system.

Title: Difference between REST and CRUD


问:
Finding a definition for this anti-pattern
Working on a large and multi-tiered software project, I just found a recurring anti-pattern to be occurring in the code. I coulnd't find its definition in Wikipedia or other sources after a quick search, so I would like to ask you if there is a known anti-pattern for our current situation. I'll explain it both in the general way and by providing you an example.

In general, this anti-pattern could be called like the Italian expression "scaricabarile" (lit. passing the buck, avoiding your responsibility and giving it to someone else under you).

If there are several people on a [sub]project, and they are organized in a chain of responsibility, someone on the upper levels could decide to deliberately avoid resolving a design problem and leave it resolution to the person next to him, who could repeat this and ultimately "leave the last developer in a mess of development complexity". The anti-pattern appears when it's discovered that if the person on top of the chain resolved the problem on his own, much less work and rework would have been done by people under him.

Real world situation (in general): you are developing a middle-tier service which handles calls from front-end and has to perform several calls to different back-end services (a DB, a web service, a file storage, outsourced services...) which are not very well documented. When you get an input field you immediately can't handle on your own, instead of asking further information you simply put it in your front-middle-end interface and require the front-end guy to supply you with this parameter that will be passed unprocessed to the back-end. The front-end guy may have to perform several calls to services to get a single value that could be else obtained by the middle-tier with few calls/instructions.

In my case (assuming that in the middle-back-tier interface all values are considered to be string, and please don't comment on that becuase there are reasons), I discovered that the back-end services require fields such as order, flagDescription which can be thought to be respectively an enumeration of ascending, descending, and a boolean.
One of the problems is to encode the enumeration. What does the service accept as values? ASC/DESC? A/D? 0/1? Only BE developers know.

In fact, we ultimately discovered that the original ME developer was too lazy to ask for detailed information about the possible values of these fields. He instead put them in the front-middle-end interface as two strings, leaving the FE guys angrily questioning "where do we pick values these fields?".

I'll describe another case with a fictional example: suppose an outsourced back-end service define an operation as doSomethingOnAPerson(string socialSecurityNumber, string phoneNumber, Date birthdate), your Persons DB table identifies people by a unique ID and contains all of these information. At a certain time, FE knows only person ID and a bunch of information insufficient to make a complete call. However, the middle tier exposes the same signature as the back-end instead of a simpler doSomethingOnAPerson(long personID) which can be implemented as a DB call followed by a service call. Since ME is already deployed, this forces the FE guys to request a rework for a new service to retrieve the missing information to call the middle end services, or in other cases request that the service is re-developed to change the signature and perform the missed operation. In general words, the original developer didn't take the time to resolve the [very simple/simplified] problem of obtaining the required information from the smallest information of data available, but decided to pass the buck to the FE

In a few words, a better design and much more attention could have prevented both situations. In fact, the first also led to troubles when switching from a mocked environment to integration testing.

I would like to explain the team that we did wrong by passing the buck between ourselves rather than solving problems.

Do you find a popular definition for what I have descripted so far? Can you help me find articles about this, if it has been documented yet?

答:
I'm not sure that there is a specific anti-pattern term for the general miscommunication that is occurring within your development group; however, there may be applicable anti-pattern terms for the problems in your codebase:

This is not necessarily a widely accepted term, but for your first example, the name I give this anti-pattern (applicable when using type-safe languages) is "Everything as a String".  It is poor practice and in a type-safe language should be avoided at all costs - the basis being that you have types; use them!

The second example you give is more subjective - from the standpoint of the backend engineer from an API design perspective, it may make more sense to provide an interface that accepts input that does not rely on the internal recordkeeping details (i.e., personID) for usage.  I'm not sure this example qualifies as an anti-pattern; avoiding this should be considered good practice and the opposite may actually be considered an anti-pattern.

OwnerDisplayName: djechelon

OwnerDisplayName: Billy Rappleye


问:
Headaches using distributed version control for traditional teams?
Though I use and like DVCS for my personal projects, and can totally see how it makes managing contributions to your project from others easier (e.g. your typical Github scenario), it seems like for a "traditional" team there could be some problems over the centralized approach employed by solutions like TFS, Perforce, etc. (By "traditional" I mean a team of developers in an office working on one project that no one person "owns", with potentially everyone touching the same code.)

A couple of these problems I've foreseen on my own, but please chime in with other considerations.

In a traditional system, when you try to check your change in to the server, if someone else has previously checked in a conflicting change then you are forced to merge before you can check yours in. In the DVCS model, each developer checks in their changes locally and at some point pushes to some other repo. That repo then has a branch of that file that 2 people changed. It seems that now someone must be put in charge of dealing with that situation. A designated person on the team might not have sufficient knowledge of the entire codebase to be able to handle merging all conflicts. So now an extra step has been added where someone has to approach one of those developers, tell him to pull and do the merge and then push again (or you have to build an infrastructure that automates that task).

Furthermore, since DVCS tends to make working locally so convenient, it is probable that developers could accumulate a few changes in their local repos before pushing, making such conflicts more common and more complicated.

Obviously if everyone on the team only works on different areas of the code, this isn't an issue. But I'm curious about the case where everyone is working on the same code. It seems like the centralized model forces conflicts to be dealt with quickly and frequently, minimizing the need to do large, painful merges or have anyone "police" the main repo.

So for those of you who do use a DVCS with your team in your office, how do you handle such cases? Do you find your daily (or more likely, weekly) workflow affected negatively? Are there any other considerations I should be aware of before recommending a DVCS at my workplace?

答:
The premise of your question seems to be around "Merges are hard and must be avoided". DVCS systems remove this barrier, in fact they do more, the embrace the idea of merging - you should not be scared of merges and merge conflicts as a result, as unlike centralized tools, the DVCS tools support it by design.

As the excellent answer by Jamie F states - Work flow of Commit-Pull-Merge-Push done regularly (daily) means that if you are walking on some elses work, you see it early - as long as it's visible, it can be managed.

The problems you describe are as more about how you choose to use the tools.

We switched from SVN to GIT 6 months ago, after using SVN and GIT locally for a couple of years. No one will go back, and painful merge conflicts are a thing of the past. The "Commit small and often" mantra is the key.


问:
Is there a way to prevent others to steal your open source project and use it to make a profit?
This might seems like a silly question to ask, but I can't really figure out the answer. The title pretty much says it all.

Let's say you have an open source music player, along comes someone, copies it, adds features, modifies the interface, etc and sells it. Nobody would find out. So how does it work?

Related: I'm working in some projects myself to make me more employable, so employers can take a look at my code but with some of them I don't feel like uploading them to an online repository, ie sourceforge, and make them visible for the general public.

答:
Your License.

When you create and distribute your code, you can choose the terms to distribute it with. You may choose to allow anyone to do anything with it, or you may choose to only allows those who pay to use it.

If you choose a restrictive license, and someone violates the terms, you may then take legal action. Of course laws are not the same everywhere and international issues may be harder to deal with.

If you are only writing code to show employers, consider sending them a link and credentials to an area where they can view it but the public cannot.


答:
"Let's say you have an open source music player, along comes someone, copies it, adds features, modifies the interface, etc and sells it."

Most open source licenses permit this. If you don't want other people to copy or modify the code then you need a different sort of license. Remember publishing the source does NOT make it open source.

Title: Is there a way to prevent others to steal your open source project and use it to make a profit?

Body:
This might seems like a silly question to ask, but I can't really figure out the answer. The title pretty much says it all.

Let's say you have an open source music player, along comes someone, copies it, adds features, modifies the interface, etc and sells it. Nobody would find out. So how does it work?

Related: I'm working in some projects myself to make me more employable, so employers can take a look at my code but with some of them I don't feel like uploading them to an online repository, ie sourceforge, and make them visible for the general public.


问:
How large is ok for a Class?
I’m a long time developer (I’m 49) but rather new to object oriented development. I’ve been reading about OO since Bertrand Meyer’s Eiffel, but have done really little OO programming.

The point is every book on OO design starts with an example of a boat, car or whatever common object we use very often, and they start adding attributes and methods, and explaining how they model the state of the object and what can be done with it.

So they usually go something like "the better the model the better it represents the object in the application and the better it all comes out".

So far so good, but, on the other hand, I’ve found several authors that give recipes such as “a class should fit in just a single page” (I would add “on what monitor size?" now that we try not to print code!).

Take for example a PurchaseOrder class, that has a finite state machine controlling its behavior and a collection of PurchaseOrderItem, one of the arguments here at work is that we should use a PurchaseOrder simple class, with some methods (little more than a data class), and have a PurchaseOrderFSM “expert class” that handles the finite state machine for the PurchaseOrder.

I would say that falls in the “Feature Envy” or “Inappropriate Intimacy” classification of Jeff Atwood's Code Smells post on Coding Horror. I’d just call it common sense. If I can issue, approve or cancel my real purchase order, then the PurchaseOrder class should have issuePO, approvePO and cancelPO methods.

Doesn’t that goes with the “maximize cohesion” and “minimize coupling” age old principles that I understand as cornerstones of OO?

Besides, doesn’t that helps toward the maintainability of the class?

答:
Let's get at it backward:

Doesn’t that goes with the “maximize cohesion” and “minimize coupling” age old principles that I understand as cornerstones of OO?

Actually, it's a cornerstone of programming, of which OO is but one paradigm.

I'll let Antoine de Saint-Exupéry answer your question (cause I am lazy ;) ):

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.

The simpler the class, the more confident you'll be it's right, the easier it'll be to fully test it.

Title: How large is ok for a Class?


答:
Oracle "owns" the Java trademark, and, ultimately has the right to decide what can be called Java.

However Sun set up the "Java Community Process" which has been continued by Oracle. This is effectively the governing body for "Java" the language, and, the definitions for the various editions: "ME", "SE" and "JE". Leadership is somewhat restricted to major stakeholders read -- Oracle, IBM and HP plus "heavy" users of Java. However any interested party can join and submit proposals for the development of the language and libraries.

So Oracle are currently playing the good guy and for the most part carrying on where Sun left off. However they still "own the ball" and can at any point say " I am going home with the ball unless I win".

Crucially they have not open sourced the Java Test Suite. Any JVM must be run through the test suite and certified before it can be called "Java". This causes lots of problems for "ideologically pure" open source projects such as  "gnu","debian" and "canonical".


问:
Introducing Programming To a Mathematician
I currently am a programmer, I'm almost 16 years of age and have pretty much narrowed my careers down to something involving a Computer Science degree or Electrical Engineering degree (I know they are quite different but this question is about my friend) but my friend isn't so sure.

He is very interested in maths and is very good at it and I think he would enjoy programming but he isn't willing to try it (edit he is willing to try but has never done before). Can anyone give me an suggestions for a language or tool that he could dabble in programming (at a reasonably basic level I assume) to solve maths problems or involve some kind of maths.

As I say he enjoys maths a lot but I think he would enjoy programming, the problem is I don't want him to be put off by the stuff that isn't relevant at introductory levels such as memory allocation et al. I know that is very important but the point is that I want him to learn a bit of programming with maths then hopefully if he is interested enough he can start learning programming as programming.

Edit:
Its not that he's completely uninterested - more that he hasn't actively explored the area before, maybe because he isn't informed about it. I wouldn't want to force him to do something he doesn't want to, I see this as more of a little push so that he can learn about programming. If he doesn't like it - fair enough, I can't control that and don't want to but if he turns out to enjoy it - this push will have been the right thing.

答:
To me, programming starts from wanting to "do something", a "what if?" question:

"I would like to make my own web site", so learn about HTML, etc.

"I hate that I have to click X or that I see Y on this web site every time I visit. Isn't there a way to automate that?" So you learn about bookmarklets or writing browser extensions.

"I want to catalog all my music and none of the tools I have seen do it in the way I want", so you learn about databases.

"I want to track expenses for my Math Club", so you learn about spreadsheets, programming macros, or perhaps even databases.

In order for the drive to really be there, the underlying problem has gotta come from him. I would try to find a problem he wants to solve and then choose a tool/language/system that allows him to automate/program the solution.


答:
Timesheet submission via email makes no sense. Why go through the rigamarole of getting the form, filling it out, emailing, and processing it when there is no reason to do so?

Just set up an online form that the person fills out. It's much simpler and less error prone. If necessary create a log-in system for security.

If you don't want to hassle with developing your own system use a web based one. I don't have any first-hand experience, but I am sure there are very good, simple and cheap solutions. It would make a great question here, Stack Overflow or perhaps another Stack Exchange site.

Title: Need to figure out Timesheet via Email

Body:
So we are thinking that we might want to make timesheet submission easier by having our timesheet system send out a person's timesheet via email to the employee. The employee then should fill out the timesheet and send it back via email for it to be processed. Anybody know of some write up on how other's have done this? I've googled but without luck.

Thanks for any thoughts/input.


问:
How one could use a live editor
I was thinking about a live editing environment where code / a source file is synchronized so that changes made by one user would be carried across to all others editing the file.
Something like Google Wave, but for code.

Could this kind of an environment be better for the code, as changes are shared instantly?
(with revision-control, of course)

Has anyone tried (or has had a need for) using a shared environment for code?
I'd love to hear from someone who has used such an editor.

答:
It's a good idea, but the only time that it would be useful is for remote pair programming, as mentioned by Falcon.

Version contol systems and automated testing eliminates the need to see what changes other people make. A shared repository makes sure that all the code fits together and unit/functional testing helps prevent introducing errors. Therefore one person doesn't need to see the code that someone else wrote.

Title: How one could use a live editor


问:
Is JSF really ready to deliver high performance web applications?
I have heard a lot of good about JSF but as far as I know people also had lots of serious complains with this technology in the past, not aware of how much the situation has improved. We are considering JSF as a probable technology for a social network project. But we are not aware of the performance scores of JSF neither we could really come across any existing high performance website that had been using JSF. People complain about its performance scalability issues.

We are still not very sure if we are doing the right thing by choosing jsf, and thus would like to hear from you all about this and take your inputs into consideration.

Is it possible to configure JSF to satisfy the high performance needs of social networking service ? Also till what extent is it possible to survive with the current problems in JSF. What exactly are its problems ?

I am not  worried about the development complexities with JSF what others usually complain about because as per my personal experience I believe that's not at all true, but I am more concerned about what performance and scalability issues. And please don't just abuse it on its old issues linked to previous versions. I just care about the present state whatever had been its past.

答: There is a problem with Facelets in general which IMHO is a pretty inconvenient thing to use. It is four times more wordy than indeed necessary and need too much manual work once you make one step off something primitive. HybridJava would be a good replacement for Facelets as presentation engine within JSF - it does the same job (and even much more, in particular - it makes all the "bindings" and ids for you) with much fewer keystrokes.  </p>


问:
Are Get-Set methods a violation of Encapsulation?

Possible Duplicate:

  When are Getters and Setters Justified

In an Object oriented framework, one believes there must be strict encapsulation. Hence, internal variables are not to be exposed to outside applications.

But in many codebases, we see tons of get/set methods which essentially open a formal window to modify internal variables that were originally intended to be strictly prohibited. Isn't it a clear violation of encapsulation? How broadly such a practice is seen and what to do about it?

EDIT:

I have seen some discussions where there are two opinions in extreme: on one hand people believe that because get/set interface is used to modify any parameter, it does qualifies not be violating encapsulation. On the other hand, there are people who believe it is does violate.

Here is my point. Take a case of UDP server, with methods - get_URL(), set_URL(). The URL (to listen to) property is quite a parameter that application needs to be supplied and modified. However, in the same case, if the property like get_byte_buffer_length() and set_byte_buffer_length(), clearly points to values which are quite internal. Won't it imply that it does violate the encapsulation? In fact, even get_byte_buffer_length() which otherwise doesn't modify the object, still misses the point of encapsulation, because, certainly there is an App which knows i have an internal buffer! Tomorrow, if the internal buffer is replaced by something like a packet_list the method goes dysfunctional.

Is there a universal yes/no towards get set method? Is there any strong guideline that tell programmers (specially the junior ones) as to when does it violate encapsulation and when does it not?

答:
No.

Getters and setters don't violate encapsulation, they provide it. If you're using accessor methods, you are by definition not accessing an object's variables directly. You are instead using an interface that the object provides to manipulate some properties, and you don't care whether those properties are stored in ivars, stored in a dictionary, calculated from other values, etc. The implementor of the class in question remains free to change the way the class works without breaking existing client code so long as he or she maintains the interface.

Some say that if your interface consists of little more than a set of accessors for your instance variables, your class isn't doing enough to justify its existence, or you're not doing enough to hide the way the class works from external code. All that may be true, depending on the class, but it doesn't change the fact that access to the internal state (the ivars) is restricted to the class' own methods and therefore encapsulated.

There's obviously some disagreement in the comments below about what the term encapsulation means. I offer the following definition from the paper Encapsulation and Inheritance in Object-Oriented Programming Languages (pdf):

A module is encapsulated if clients are restricted by the definition
  of the programming language to access the module only via its defined
  external interface. Encapsulation thus assures designers that
  compatible changes can be made safely, which facilitates program
  evolution and maintenance. These benefits are especially important for
  large systems and long-lived data.

It's hard to argue that accessors don't qualify as "defined external interface" to a class. If you also take steps to prevent external direct access to a class' internal state (that is, make your ivars 'private'), then by the definition above you will have achieved encapsulation.

From a pragmatic viewpoint, though, things aren't exactly that simple. The very next paragraph in the paper goes on to say:

To maximize the advantages of encapsulation, one should minimize the
  exposure of implementation details in external interfaces. A
  programming language supports encapsulation to the degree that it
  allows minimal external interfaces to be defined and enforced.

Like any technique, encapsulation can be used well or not so well, and I think this is at the heart of most differences in opinion about what does or doesn't "break" encapsulation. If hiding the internal representation of data behind an external interface is good, then revealing only what is necessary for the class to do its job is better. A class which has a one-to-one correspondence between property accessors and ivars can properly be said to encapsulate its state, but it may not be using that encapsulation to best effect. I'd agree that if your code contains many classes in this situation, it's a good bet that the system is not as well designed as it could be.

How can you judge whether you're using encapsulation effectively? Continuing from the paper:

This support can be characterized by the kinds of changes that can
  safely be made to the implementation of a module. For example, one
  characteristic of an object-oriented language is whether it permits a
  designer to define a class such that its instance variables can be
  renamed without affecting clients.

I like this test because it provides a simple guideline that corresponds directly to the reason we value encapsulation in the first place. It also makes clear the idea that the benefit gained from encapsulation is a continuous value, not a binary one. We shouldn't lose sight of the fact that the paper describes encapsulation as a language feature, but I think it's safe to apply the test to specific code to help us decide how well that code uses the encapsulation provided by the language.

Example 1: Applying the "What kind of changes can safely be made?" test to the example in the OP's question, it seems likely that the code probably doesn't make good use of encapsulation. It may be technically true that the get_byte_buffer_length() and set_byte_buffer_length() methods encapsulate some internal state, but if the "byte buffer" is an implementation detail rather than an important external property of the UDP server, the buffer shouldn't be exposed at all. The very fact that it is exposed limits the ways in which the UDP server can be modified.

Example 2: It's often said that inheritance breaks encapsulation because subclasses typically (depending on the language) have direct access to the parent class' internal state. Despite this, programmers can take advantage of encapsulation by using accessors (sometimes private accessors) to access state from a parent class instead of using the ivar itself.

When in doubt, a programmer should ask him or herself: Will my code break if the parent class changes? and Will subclasses of this class break if I change X?


答:
In my opinion, as long as you allow the property to change from within your class code and using your class code, you are not violating encapsulation.

If you want to prevent change, there are ways to prevent change either at design time (using access modifiers, readonly specification) or at run-time (using business rules).

One of the advantages of using set/get pair is to provide a point in your code to control what happens after/before reading/setting a data value.

we see tons of get/set methods which essentially open a formal window to modify internal variables that were originally intended to be strictly prohibited.

Regarding internal variables (I assume you are taking about fields as in C#), those are always recommended to be declared private whether the property is public, read-only, or otherwise.

This link may add further help:
Using a SetProperty method to prevent accidental changes to a property

Edit-1

After reading your edit to the original question

Based on your example, the problem is not with get/set per-se. I think that the implementation of properties that depend on external source of data leads to the dependency problem you are describing.
To have a more 'pure' property definition, you should send a message to the object owning this data and let the method return the desired value, then use Set/Get to continue processing.

Encapsulation definition (as in Encpc.Def-About.Com does not imply that the data of a class must all be created in the class or by the class alone. It is OK (and in fact desirable) for classes to communicate or collaborate. This way, you limit the complexity of a class and encourage sharing of code that already exists.

Edit-2

This in response to the first comment for the message.
Reading Martin Fowler in this article Getters Eradicator says:

"I have a lot of sympathy with this motivation, but I fear that just telling people to avoid getters is a rather blunt tool. There are too many times when objects do need to collaborate by exchanging data, which leads to genuine needs for getters."

the article is very related to the subject and may answer your question.

Title: Are Get-Set methods a violation of Encapsulation?

Body:
Possible Duplicate:

  When are Getters and Setters Justified

In an Object oriented framework, one believes there must be strict encapsulation. Hence, internal variables are not to be exposed to outside applications.

But in many codebases, we see tons of get/set methods which essentially open a formal window to modify internal variables that were originally intended to be strictly prohibited. Isn't it a clear violation of encapsulation? How broadly such a practice is seen and what to do about it?

EDIT:

I have seen some discussions where there are two opinions in extreme: on one hand people believe that because get/set interface is used to modify any parameter, it does qualifies not be violating encapsulation. On the other hand, there are people who believe it is does violate.

Here is my point. Take a case of UDP server, with methods - get_URL(), set_URL(). The URL (to listen to) property is quite a parameter that application needs to be supplied and modified. However, in the same case, if the property like get_byte_buffer_length() and set_byte_buffer_length(), clearly points to values which are quite internal. Won't it imply that it does violate the encapsulation? In fact, even get_byte_buffer_length() which otherwise doesn't modify the object, still misses the point of encapsulation, because, certainly there is an App which knows i have an internal buffer! Tomorrow, if the internal buffer is replaced by something like a packet_list the method goes dysfunctional.

Is there a universal yes/no towards get set method? Is there any strong guideline that tell programmers (specially the junior ones) as to when does it violate encapsulation and when does it not?


问:
Should we write detailed architecture design or just an outline when designing a program?
When I'm doing design for a task, I keep fighting this nagging feeling that aside from being a general outline it's going to be more or less ignored in the end. I'll give you an example:

I was writing a frontend for a device that has read/write operations. It made perfect sense in the class diagram to give it a read and a write function. Yet when it came down to actually writing them I realized they were literally the same function with just one line of code changed (read vs write function call), so to avoid code duplication I ended up implementing a do_io function with a parameter that distinguishes between operations. Goodbye original design.

This is not a terribly disruptive change, but it happens often and can happen in more critical parts of the program as well, so I can't help but wondering if there's a point to design more detail than a general outline, at least when it comes to the program's architecture (obviously when you are specifying an API you have to spell everything out).

This might be just the result of my inexperience in doing design, but on the other hand we have agile methodologies which sort of say "we give up on planning far ahead, everything is going to change in a few days anyway", which is often how I feel.

So, how exactly should I "use" design?

答:
It is a fact of life in most real-life projects that things change:

(as you noted) the environment / platform / APIs the program is going to use may be different than originally assumed

the requirements may change at any point

the market / surrounding world may change, obsoleting some requirements (or the whole project)

...

This is why Agile methods oppose Big Design Up Front, because it just gives a false sense of security, involves a lot of useless effort, and makes adapting to the inevitable changes more difficult.

However, Agile does not equal to "give up on planning far ahead". Agile methods do involve the necessary amount of careful and thoughtful planning, just no more. They are very disciplined, and different from "cowboy coding". Doing the right amount of design is a continuous attempt to find the right balance between over- and underdesigning. But IMHO it is better to err a little on the side of too much, than to do too little.

The initial design should not try to cover everything, but should give you a secure feeling that you know how to move on with the implementation, you have answers to the fundamental questions about the architecture, and you have a mental model of how the known use cases are going to work in real life. In the Agile view, the real test of a design is implementation, so it is OK to start writing code even during the design phase, just to get a feeling of how the envisioned design would look like, or to quickly prototype / validate some assumption. Note though that most of these early work are to be thrown away once the answer to the given question is determined. It is almost always a Bad Thing to start building a real production app from an early prototype.

And it is also OK to go back and modify the design if you make a new important realization during implementation. This is an important feedback on two levels:

your concrete design needs to be adapted to the changing world, and

your design process needs to be adapted to cover such possibilities in the future (i.e. next time think through the use case of reading from and writing to the device better in advance).


答:
If it made perfect sense to provide read and write operations, why remove them?

From the user point of view it still makes perfect sense. The implementation details should not interfere with a provided interface.

What you can do is to create an internal do_io that gets called by read and write.

In the end the design process follows these steps:

define the interface

draw a rough design

refine without changing the agreed interface

Title: Should we write detailed architecture design or just an outline when designing a program?

Body:
When I'm doing design for a task, I keep fighting this nagging feeling that aside from being a general outline it's going to be more or less ignored in the end. I'll give you an example:

I was writing a frontend for a device that has read/write operations. It made perfect sense in the class diagram to give it a read and a write function. Yet when it came down to actually writing them I realized they were literally the same function with just one line of code changed (read vs write function call), so to avoid code duplication I ended up implementing a do_io function with a parameter that distinguishes between operations. Goodbye original design.

This is not a terribly disruptive change, but it happens often and can happen in more critical parts of the program as well, so I can't help but wondering if there's a point to design more detail than a general outline, at least when it comes to the program's architecture (obviously when you are specifying an API you have to spell everything out).

This might be just the result of my inexperience in doing design, but on the other hand we have agile methodologies which sort of say "we give up on planning far ahead, everything is going to change in a few days anyway", which is often how I feel.

So, how exactly should I "use" design?


答:
Architecture design of a program evolves over time. I don't think at the beginning you have every piece of information you will need to have a correct design.

So, if you stick to the design you thought at the beginning you will probably limit yourself.

Unless you are creating a public api I think its OK to make changes to the design along the way.

Also one of the best things to do is invest in a tool that can extract the design from the code ( like NDepend for C# )


问:
Would you put your Stack Overflow profile link on your CV / Resume?
If applying for a new job, would you put your Stack Overflow profile link on your resume?

This would show the employer you're an active member of the development community and also provide an insight into your knowledge + how well you convey your ideas.

However it would feel a bit gimmicky to me?

答:
No

I would not put any websites on my Resume. I will make reference to projects or applications I have done and other information that is readily applicable to the person reviewing the resume. My resume is a one page summary of me, I don't have room for the half dozen SO family accounts, LinkedIn, my blog, Facebook, Twitter, Tumblr, Digg, Reddit, (you get the picutre).

Putting "I have XXX reputation on stackoverflow.com" is just like saying "I have 8.3k posts on myfavoriteforum.com." It's not professional. Deliberately pointing people elsewhere for information is also, in my view, wrong. What do you want to gain from adding a link to your LinkedIn profile? Work history? That should be on your resume. People you know? Connections? I guess it would be some indicator of how well you are known in the community, but honestly that information should be found elsewhere.

If they care, they can visit my website where I have an Imprint page linking to various online profiles. I get more referrals in regards to my blog then I do from my stackoverflow reputation ranking. I'm on page one of superuser.com but have never had someone drop me an email because of it. Reputation is great however it is not applicable to your job.

If I notice I'm writing an extraordinarily good answer to something I will turn it into a blog post. Sometimes I'll even turn it into a full blown application. This gets far more recognition and attention then crawling through your answers. My second highest rated answer on stackoverflow is a XKCD comic. My highest rated answer on programmers is an explanation of a brace. These are not answers I'm especially proud of or feel like I should show off.


答:
using Zoho you could send data to the database directly using email if you are using Zoho Creator database - See: Sending Data by Email

It is possible to have an excel sheet based on template exchanged via eamil.

The problem is usually what happens when there is an error in the exchanged data? The error may be skipped during filling the form, and since there is no immidiate interaction, problems could happen.

I suggest you use an on-line application instead of email.

Title: Need to figure out Timesheet via Email


答:
You seem to have stumbled across a common conundrum in Software Development. It is not possible to plan an entire system before you start to build it, because there are too many things you don't yet know.

This is the reason why Agile methodologies use iterative development, because it allows regular feedback to change the direction of the software, rather than letting things get further and further from what is actually needed. Each change will affect the design.

So having said all of this, I actually would have written two methods for the specific scenario you describe above, but I would have encapsulated the shared logic in a third private method that can be used by the two methods. This way, the public methods are responsible for just one thing and are easy to name, read_file and write_file say exactly what they do, whereas do_file is ambiguous.

Books such as Clean Code, Robert C Martin and Emergent Design, Scott L Bain will give you more detailed insights into this subject.


问:
Diagram that could explain a state machine's code?
We have a lot of concepts in making diagrams like UML and flowcharting or just making up whatever boxes-and-arrows combination works at the time, but I'm looking at doing a visual diagram on something that's actually really complex.

State machines like those that parse HTML or regular expressions tend to be very long and complicated bits of code.

For example, this is the stateLoop for FireFox 9 beta. It's actually generated by another file, but this is the code that runs.

How can I diagram something with the complexity of this in a way that explains flow of the code without taking it to a level where I draw every single line-of-code into it's own box on a flowchart?

I don't want to draw "Invoke loop, then return" but I don't want to explain every last detail.

What kind of graph is suitable to do this? Is there already something out there similar to this? Just an example of how to do this without going overboard in complexity or too-high-level is really what I want.

If you don't feel like looking at the code, basically it's 70 different state flags that could occur, inside an infinite loop that exists to a label based on some conditions, each flag has it's own infinite loop that exists to a label somewhere, and each of those loops has checks for different types of chars, which then runs off into various other methods.

答:
Many options exist to graphically represent state machines, among them:

state diagrams and its popular successor statechart, which is integrated to UML.

Petri net, if you want to control combinatorial explosion.

Some tools are able to generate code from them.


答:
This might be just the result of my inexperience in doing design, but
  on the other hand we have agile methodologies which sort of say "we
  give up on planning far ahead, everything is going to change in a few
  days anyway", which is often how I feel.

It is not possible to plan every single detail in advance. It is perfectly acceptable to make changes here and there.

However, it is important to plan ahead. Doing agile doesn't mean no design and no planning at all, but it means that you are expecting changes.

So, how exactly should I "use" design?

You should use your design as it is. Since it is not written in the stone, it is easy to change it.


答:
Agile claims to answer this problem, with some success, However Fred Brooks had the answer 40 years ago, when he wrote "Write one to throw away, because you will anyway".
Those who do not study history are doomed to repeat it.

So what do do is treat the design as a plan, which is made for the sole purpose of changing it. Designs that cannot be changed are doomed. You must be prepared to throw away bad ones.

If the design is one of a public API, interface or such like, much care needs to be take as the cost of change is high, however, the inability to change will doom it to failure.

Do not for one second think you are good enough, and know enough to get it right first, second or even third time.


答:
If you live in a country that recognized software licences, then you can sue them.

If not, only thing you can do is add them on your black list*.

* Scroll to the end of the page.


问:
How to drastically improve code coverage?
I'm tasked with getting a legacy application under unit test. First some background about the application: It's a 600k LOC Java RCP code base with these major problems

massive code duplication

no encapsulation, most private data is accessible from outside, some of the business data also made singletons so it's not just changeable from outside but also from everywhere.

no abstractions (e.g. no business model, business data is stored in Object[] and double[][]), so no OO.

There is a good regression test suite and an efficient QA team is testing and finding bugs. I know the techniques how to get it under test from classic books, e.g. Michael Feathers, but that's too slow. As there is a working regression test system I'm not afraid to aggressively refactor the system to allow unit tests to be written.

How should I start to attack the problem to get some coverage quickly, so I'm able to show progress to management (and in fact to start earning from safety net of JUnit tests)? I do not want to employ tools to generate regression test suites, e.g. AgitarOne, because these tests do not test if something is correct.

答:
I have a lot of experience working on legacy systems (not Java though), much larger than this. I hate to be the bearer of bad news, your problem is the size of you problem. I suspect you have underestimated it.

Adding regression tests to legacy code is a slow, expensive process. Many requirements are not well documented - a bug fix here, a patch there, and before you know it, the software defines it's own behavior. Not having tests means that the implementation is all there is to go by, no tests to "challenge" the implicit requirements implemented in the code.

If you try to get coverage quickly, it is likely you will rush the job, half bake it, and fail. The tests will give partial coverage of the obvious stuff, and poor to no coverage of the real issues. You will convince the very managers you are trying to sell to that Unit Testing is not worth it, that it's just another silver bullet that does not work.

IMHO, The best approach is to target you testing. Use metrics, gut feeling and defect log reports to identify the 1% or 10% of code that produces the most problems. Hit these modules hard, and ignore the rest. Don't try to do too much, less is more.

A realistic goal is "Since we implemented UT, defect insertion in modules under test has dropped to x% of those not under UT"  (ideally x is a number <100).