问:
What are functional-programming ways of implementing Conway's Game of Life
I recently implemented for fun Conway's Game of Life in Javascript (actually coffeescript but same thing). Since javascript can be used as a functional language I was trying to stay to that end  of the spectrum. I was not happy with my results. I am a fairly good OO programmer and my solution smacked of same-old-same-old. So long question short: what is the (pseudocode) functional style of doing it?

Here is Pseudocode for my attempt:

```<code>class Node
  update: (board) ->
    get number_of_alive_neighbors from board
    get this_is_alive from board
    if this_is_alive and number_of_alive_neighbors < 2 then die
    if this_is_alive and number_of_alive_neighbors > 3 then die
    if not this_is_alive and number_of_alive_neighbors == 3 then alive

class NodeLocations
  at: (x, y) -> return node value at x,y
  of: (node) -> return x,y of node

class Board
  getNeighbors: (node) ->
   use node_locations to check 8 neighbors
   around node and return count

nodes = for 1..100 new Node
state = new NodeState(nodes)
locations = new NodeLocations(nodes)
board = new Board(locations, state)

executeRound:
  state = clone state
  accumulated_changes = for n in nodes n.update(board)
  apply accumulated_changes to state
  board = new Board(locations, state)
</code>```

答:
If you're writing a functional programming version of Life you owe it to yourself to learn about Gosper's Algorithm. It uses ideas from functional programming to achieve trillions of generations per second on boards trillions of squares on a side. That sounds impossible I know, but it is thoroughly possible; I have a nice little implementation in C# that easily handles square boards 2^64 squares on a side.

The trick is to take advantage of the massive self-similarlity of Life boards across both time and space. By memoizing the future state of large sections of the board you can rapidly advance huge sections at once.

I've been meaning to blog a beginners introduction to Gosper's Algorithm for many years now, but I have never had the time. If I end up doing so, I'll post a link here.

Note that you want to look up Gosper's Algorithm for Life computations, not the Gosper's Algorithm for computing hypergeometric sums.


问:
Rights and use of developed software
I have been working on a piece of software for a company, that they wish to resell.

There was an mail-based agreement upon a flat hourly rate for my work, and eager me chose to accept a rather low fee.

Due to the stress and tempo of the task, a direct contract was never formed or signed.

The software was developed locally on my machine, and I was pretty much alone with it, except by excellent help from StackOverflow when I got stuck.

Now, the software is nearing completion, I suddenly hear that they have hired a new developer to make the same piece of software as me, and that I was expected to resign within long.

Confused I ask around, and realize that the CEO of the company had informed the rest of the company that I was terminally ill and had cancer, and was expected to leave the company soon.

Since I'm perfectly healthy, this confused me even more, until I realized what was going on. When I confronted my boss with this, I was no longer seen as a member of the company, and I left the same day, never to return.

Later, I raised the question about my missing pay, since I had been working for quite a bit, and not received any payment for my software. I saw that they had already sold a fair copy of my software, and since it's not exactly sold cheap, the company should have plenty of gold to pay me.

The company refused, and said that they owned the software, and everything it contained.

That was a lot of drama, but my question is this:

Who has the rights to the software ?

The source code had my personal watermarks and copyrights inprinted, but they have since simply deleted it. The company claim that they have all the rights, because they have a website made about the product, where they write that they have "All rights reserved" in the bottom.

My instinct tells me that if a company buys a service like this, and then refuses to pay their developer, then they should not be allowed to keep, and much less resell the product.

I have not signed any agreements about giving the company the use of this product, I have made it in my own time and without help from the rest of the company.

This all takes place in Denmark, Europe, but I would guess that the rules about this is somewhat universal.

Im not the strongest person to legal-talk, so I might be wrong.

答:
It is quite likely that you have a contract with this company. It may be verbal, but as there are emails agreeing terms, they are likely to be part of the contract.

Now the important bit is this, in the UK, just because someone has paid you to do the work does not mean that they own the copyright of the code. Most employment contracts for developers have a specific clause in the contract to grant copyright to the company.  Without it, the developer owns the code.  This may well be the case in Denmark too.

If you have a record of your development, e.g a source control repository then it's straightforward to prove you wrote the code.

The companies that are using the software product you wrote are also in breach of your copyright. With your solicitor, it may be worth approaching them for your royalties for the use of the code.

You also have separate non programming issues related to the company conduct that should also be addressed.

ContentLicense: CC BY-SA 3.0

Title: Rights and use of developed software


问:
Where can I find inspiration for a good user interface?
I've got a mental block as far as desigining the main screen interface for a desktop application that I'm currently upgrading. When I first developed this program the screen resolution was 640 X 480. Today there are multiple screen resolutions out there.

Where can I find ideas for a good main screen layout for a desktop application?

答:
I would recommend you check out a couple different books, which, oddly enough, aren't focused on desktop application GUI design. Regardless, these texts will help you start thinking in terms of how to get the information your users need in a form that their brains will comprehend. Anyway, the first book is The Non-Designer's Design Book by Robin Williams. This book will teach you about composition in not-so-graphic-design-oriented terms. This book will get you started thinking about how the human mind perceives design elements.

Second, check out Don't Make Me Think by Steve Krug. It deals with navigation and data representation on web pages, but many of the recommendations (i.e. bread crumb navigation) often make just as much sense in desktop apps as they do on web pages.

As another poster indicated, good design patterns do not exist in per-medium isolation. Some things do not translate so well between analog and digital (i.e. multiple column text in actual an actual newspaper vs. an app for the newspaper) because certain restrictions are different depending on the medium, but many principles of good design hold true no matter what medium you're talking about.


问:
How to build completely modular web applications
In the coming months we're going to begin a project where we take a system we've built for a client (v1) and rebuild it from scratch.  Our goal with v2 is to make it modular, so that this specific client will have their own set of modules they use, then another client may use a different set of modules altogether.  The trick here is that Company A might have a series of checkout and user modules that change how that system works.  Company B might stick with the standard checkout procedure but customize how products are browsed.

What are some good approaches to application architecture when you're building an application from scratch that you want to have a Core that's shared among all clients while still maintaining the flexability for anything to be modified specifically for a client?

I've seen CodeIgniter's hooks and don't think that's a good solution as we could end up with 250 hooks and it's still not flexible enough.  What are some other solutions?  Ideally we won't need to draw a line in the sand.

答:
To achieve highly organized and decoupled modularity, you can follow the Hierarchical MVC  architectural pattern, sometimes known as Presentation–abstraction–control (although they aren't strictly the same pattern). Kohana, Alloy, Fluency and FuelPHP support HMVC natively* and Kohana's HMVC approach is discussed in Scaling Web Applications with HMVC and Optimising HMVC Web Applications for Performance, by Sam de Freyssinet.

Unfortunately CodeIgniter doesn't support HMVC natively. I've built my own libraries to provide some sort of HMVC support on CodeIgniter, taking some inspiration from wiredesignz's codeigniter-modular-extensions-hmvc. There's a very nice introduction to HMVC article at nettus+, that discusses CodeIgniter and wiredesignz's extension. The following image and quote are from that tutorial:

Each triad functions independently from one another. A triad can request access to another triad via their controllers. Both of these points allow the application to be distributed over multiple locations, if needed. In addition, the layering of MVC triads allows for a more in depth and robust application development. This leads to several advantages which brings us to our next point.

Finally, you are on the right track with hooks, even if you adopt an HMVC architecture, there is going to be some problems you'll still need to solve with hooks, depending on your implementation and the level of automation that you are looking for. A good use of hooks would be a pre_controller hook that would make sure all dependencies for installed modules are present, for example.

* There may be others I don't know of.


问:
Where do other programming languages fit in Windows 8 development model?
Today, Windows applications can be developed in numerous languages and frameworks. But in the upcoming Windows 8, with the introduction of WinRT, the development model is going change at a large scale. So, where do other programming languages fit in this model?</p>

答:
WinRT is only part of Windows 8. If you have an application that runs on Windows 7, it will run on Windows 8 (desktop mode) regardless of the tool and language you use. This is true for all the Windows 8 installations that currently exist. It may not be true for ARM installations, if your tool can't target that instruction set. I have heard speculation that some SKUs of Windows 8 might be Metro only, meaning your desktop mode app wouldn't run on those. But for what we have in our hands today, all languages and all tools can still play.

If you want to adopt Metro, because you like the design paradigm, then you might want to switch to one of the four languages you can write Metro apps in. But don't confuse that with all of Windows 8.


问:
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?

答:
I would have to say unit tests first then coding. Even with the best will in the world, tight deadlines and other priorities will simply mean they will get pushed back or not done at all. Leaving a bigger headache for those who'll have to maintain the codebase.

Besides writing the unit test should help you formulate what your trying to achive.

ContentLicense: CC BY-SA 2.5


答:
I can't recommend Edward Tufte's book The Visual Display of Quantitative Information highly enough.  Really makes you think about what you're presenting and why.  All his books are good, but I find myself referring to this one the most.

A good "UI Design Pattern" book I've found is Designing Interfaces.  It has sections on designing layouts, navigation, displaying complex information and designing input forms.  There's a similar book out on designing social interfaces (called, appropriately enough, Designing Social Interfaces), but I haven't read it so I don't know enough to recommend it.

Title: Where can I find inspiration for a good user interface?

Body:
I've got a mental block as far as desigining the main screen interface for a desktop application that I'm currently upgrading. When I first developed this program the screen resolution was 640 X 480. Today there are multiple screen resolutions out there.

Where can I find ideas for a good main screen layout for a desktop application?


问:
Purely technical reasons for PHP as a first choice?
I know this may come off as a flame-y / troll-y, but I hope you will take my word for it that it's not my intention.  I am just trying to understand the PHP phenomenon.

After looking at the many technical issues with the language design of PHP, I am hard pressed to find any redeeming technical advantages where PHP surpasses all other languages.  Before coming to the conclusion that there would simply be no reason to choose PHP as a development language on purely technical grounds, I would like to ask, if all non-technical factors were equal (such as what language the developers already know, what languages the hosting provider offers, language of existing code, cost, license, corporate fiat, etc.), would there be any type of new software system that would indicate making PHP a first choice for development?  If so, what technical advantage does PHP have over all other languages that would cause you to choose it?

EDIT: I am not interested in comparing PHP "out of the box" with other languages "out of the box".  If PHP has a certain feature "out of the box" that another language has only after installing some readily available add-on, that is not considered an advantage for PHP for the purposes of this question.

答:
My answer:
there is no technical feature where PHP is better than other languages.

There is some trend, some call it "language oriented programming", that in the future people should be able to write programs like adding new stuff to wikipedia. Just using very simple mechanisms.

To some extend PHP is good at it. It's more about how many people have access to contribute than the technical features.

With dynamic objectoriented programming there are a lot of features that PHP doesn't provide yet. (example needed)

Concerning the "OOP scripting" and using the "language as a template language" can be done with many programming languages (I think even perl6, and possibly even ruby offer this).

I think it is important to further look at the trend that more people can contribute programs. Even with domain specific languages (DSLs), small sub languages that provide the ability for non-programmers to add functionality.

Further, it is important to follow the trend of using functional programming for web programming. This is the opposite: highly complex languages and frameworks that are only suited for expert programmers. With complex stuff like Monads, category theory, lazy evaluation.

There are two very good examples:

  1. Haskell and the snap frame work

  2. Scala and the lift framework

(and further maybe also Clojure and http://webnoir.org/).


问:
best and most used algorithm for finding the primality of given positive number
When I was in college and as a programming language learner I wrote program for finding out prime numbers but then I never mind the program performance in terms of speed. Now after long time just started solving the problems from projecteuler.net.

Now I wonder is there any best and most used algorithm for finding the primality of a given positive number which produces the result fast?

Thanks

答:
The fastest way is going to be a lookup table:

This page indexes many of the lists of primes stored at this site. The main list we keep is the list of the 5000 largest known primes and selected smaller primes. We also have list of the first primes, but it is not practical to keep too long of such list...


问:
How to instrument existing ASP.NET application?
We have several highly complex ASP.NET web applications that are used internally by hundreds of users.  We are trying to figure out which areas of the applications to invest in to improve functionality, but we aren't sure which screens/features are more heavily used.  So, ideally, I'd like to find a way to add a layer of instrumentation to the applications that gathers metrics on which buttons are being clicked, which text boxes are being used, etc.

Are there any products / open source apps out there that will do this sort of instrumentation for ASP.NET?  Obviously I could do it myself manually by going into the code and injecting logging statements everywhere but this would be a significant amount of work that will be hard to accomplish.

答: To me, the easiest way to do this is to just setup a Google Analytics account and then monitor it from there. It won't cost you a dime and all you'll have to do is add the javascript to each page. You would then be able to see which pages are frequented most often and you could even do in-page analysis which would show where your users are clicking.</p>


问:
Idea of an algorithm to detect a website's navigation structure?
Currently I am in the process of developing an importer of any existing, arbitrary (static) HTML website into the upcoming release of our CMS.

While the downloading the files is solved successfully, I'm pulling my hair off when it comes to detect a site structure (pages and subpages) purely from the HTML files, without the user specifying additional hints.

Basically I want to get a tree like:

```<code>+ Root page 1
     + Child page 1
     + Child page 2
         + Child child page1
     + Child page 3
+ Root page 2
     + Child page 4
+ Root page 3
+ ...
</code>```

I.e. I want to be able to detect the menu structure from the links inside the pages. This has not to be 100% accurate, but at least I want to achieve more than just a flat list.

I thought of looking at multiple pages to see similar areas and identify these as menu areas and parse the links there, but after all I'm not that satisfied with this idea.

My question:

Can you imagine any algorithm when it comes to detecting such a structure?

Update 1:

What I'm looking for is not a web spider, but an algorithm do create a logical tree of the relationship of the pages to be able to create pages and subpages inside my CMS when importing them.

Update 2:

As of Robert's suggestion I'll solve this by starting at the root page, and then simply parse links as you go and treat every link inside a page simply as a child page. Probably I'll recurse not in a depth-first manner but rather in a breadth-first manner to get a more balanced navigation structure.

答:
You need a recursive data structure.  Something like this:</p>

```<code>public class TreeNode<T>
{
    public T node { get; set; }
    public List<TreeNode<T>> descendants { get; set; }
}
</code>```

Body:
You need a recursive data structure.  Something like this:

public class TreeNode<T>
{
    public T node { get; set; }
    public List<TreeNode<T>> descendants { get; set; }
}


问:
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?

答:
I will have to hire someone in the next few months, and seeing that the person participates in the software community is a huge +1 on that end. Seeing that they have intelligent ways to solve problems, work with others respectfully, and have the courage to admit there's something they don't know-- but know how to ask for help... that's really attractive. Am I great in all the areas I mentioned? Not as well as I'd like to be, but it's part of growing. If you can show that you're always growing by linking to SO, go for it.

Don't put "I have over 9000 rep on SO." but explain what you have. I'm not a fan of paper resumes, I'd like to see a web presence with online portfolio (which isn't always easy to do, I understand), but if you have to stick it on paper, put it under "Professional Communities," where you have a table of communities you are inolved with, for example,

```<code> Community        | description                           | involvement
 Stack Exchange   | A community of software professionals | I have participated in over 400 discussions on highly-technical issues, ranging from <your best two options here>.
 EFF              | Down with the man                     | I'm stalking politicians against NN in my blog
 FSF              | Free as in beer                       | I edit the man pages for YetAnotherY. The Y stands for YetAnotherY.
</code>```

Body:
I will have to hire someone in the next few months, and seeing that the person participates in the software community is a huge +1 on that end. Seeing that they have intelligent ways to solve problems, work with others respectfully, and have the courage to admit there's something they don't know-- but know how to ask for help... that's really attractive. Am I great in all the areas I mentioned? Not as well as I'd like to be, but it's part of growing. If you can show that you're always growing by linking to SO, go for it.

Don't put "I have over 9000 rep on SO." but explain what you have. I'm not a fan of paper resumes, I'd like to see a web presence with online portfolio (which isn't always easy to do, I understand), but if you have to stick it on paper, put it under "Professional Communities," where you have a table of communities you are inolved with, for example,

 Community        | description                           | involvement
 Stack Exchange   | A community of software professionals | I have participated in over 400 discussions on highly-technical issues, ranging from <your best two options here>.
 EFF              | Down with the man                     | I'm stalking politicians against NN in my blog
 FSF              | Free as in beer                       | I edit the man pages for YetAnotherY. The Y stands for YetAnotherY.


问:
Does waterfall require code complete before QA steps in?
The process used at a certain company consists of:

Create a layout according to some designs made in a web page design tool.  (CSS, html)

Requirements come in with "functional requirements".  These consist of 100's of lines of business directions. E.G.  Create a Table on page X.  Column1 has numeric data.  Column1 is the client code.  Column2 is a string...etc.

Write code to meet all functional requirements.

When all code is checked in, send to QA (which is the BA that wrote the requirements) for inspection, bug finds and change requests.

Punt back to developer with a list of X bugs and Y change requests.

While bug finds or change requests > 0 go to step 4.

The agile development environments I have worked in allow, if not demand, early QA inspection and early user acceptance.  So, pieces of the program can be refined and redefined before the entire application is in place.

Not only that, but the process leaves little room for error or people changing their minds.  Instead, those "change requests" come in at the last stage when they do the most damage.  And being that a bug-fix's cost increases over time, this is a costly way to write code.

I am no waterfall expert.  As described, is this waterfall being mishandled in some way?  How does waterfall address my concerns?

答:
This seems pretty true to the traditional Waterfall methodology and you already mentioned a significant drawback of Waterfall in that the relative cost of a bug or missed requirement exponentially increases over the course of the project:

The way to minimize this in Waterfall development is to provide regular status updates with BA/QA throughout the course of the project so if they see something going astray then they can call it out earlier before it has a chance of being a bug or missed requirement later in the SDLC.


答:
Perhaps giving a simple yes/no is the desired answer for this question, but I just can't do it.

The thing about Waterfall is that it looks great on paper but almost never manages to match with the reality of human behavior.

You allude to having some familiarity with Agile, and you point out issues occuring from people changing their minds, so I assume you have some familiarity with this problem. Software development is not similar enough to bridge-building to proceed in a nice, orderly fashion from Step 1 to Step 2 to Step 3. We learn more as we go, customers' ideas grow and mature, priorities change.

So given that, I'll say theoretically yes, according to the rigid and often impractical process outlined by Waterfall, code is complete before going to test. In reality, though, this often just doesn't work and leads to much gnashing of teeth.

Title: Does waterfall require code complete before QA steps in?

Body:
The process used at a certain company consists of:

Create a layout according to some designs made in a web page design tool.  (CSS, html)

Requirements come in with "functional requirements".  These consist of 100's of lines of business directions. E.G.  Create a Table on page X.  Column1 has numeric data.  Column1 is the client code.  Column2 is a string...etc.

Write code to meet all functional requirements.

When all code is checked in, send to QA (which is the BA that wrote the requirements) for inspection, bug finds and change requests.

Punt back to developer with a list of X bugs and Y change requests.

While bug finds or change requests > 0 go to step 4.

The agile development environments I have worked in allow, if not demand, early QA inspection and early user acceptance.  So, pieces of the program can be refined and redefined before the entire application is in place.

Not only that, but the process leaves little room for error or people changing their minds.  Instead, those "change requests" come in at the last stage when they do the most damage.  And being that a bug-fix's cost increases over time, this is a costly way to write code.

I am no waterfall expert.  As described, is this waterfall being mishandled in some way?  How does waterfall address my concerns?


答:
Two things come to mind:

Web log analysis with a tool like AWStats. This isn't going to give you the granularity that you are asking for, but is still very useful.

Work backwards from your most expensive and frequent database queries.

Title: How to instrument existing ASP.NET application?

Body:
We have several highly complex ASP.NET web applications that are used internally by hundreds of users.  We are trying to figure out which areas of the applications to invest in to improve functionality, but we aren't sure which screens/features are more heavily used.  So, ideally, I'd like to find a way to add a layer of instrumentation to the applications that gathers metrics on which buttons are being clicked, which text boxes are being used, etc.

Are there any products / open source apps out there that will do this sort of instrumentation for ASP.NET?  Obviously I could do it myself manually by going into the code and injecting logging statements everywhere but this would be a significant amount of work that will be hard to accomplish.


问:
How is precedence determined in C pointers?
I've come across two pointer declarations that I'm having trouble understanding. My understanding of precedence rules goes something like this:

Operator             Precedence             Associativity
(), [ ]                  1                  Left to Right
*, identifier            2                  Right to Left
Data type                3
```

<p>But even given this, I can't seem to figure out how to evaluate the following examples correctly:</p>

<h3>First example</h3>

```float * (* (*ptr)(int))(double **,char c)
```

<p>My evaluation:</p>

<ol>
<li><code>*(ptr)</code></li>
<li><code>(int)</code></li>
<li><code>*(*ptr)(int)</code></li>
<li><code>*(*(*ptr)(int))</code></li>
</ol>

<p>Then,</p>

<ol>
<li><code>double **</code></li>
<li><code>char c</code></li>
</ol>

<h3>Second example</h3>

```unsigned **( * (*ptr) [5] ) (char const *,int *)
```

*(ptr)

[5]

*(*ptr)[5]

*(*(*ptr)[5])

**(*(*ptr)[5])

How should I read them?

答:
You could try the 'The Clockwise Spiral' Method to understand these insane declarations:

http://c-faq.com/decl/spiral.anderson.html

I blogged about it here too:

http://www.kalekold.net/index.php?post=4


答:
It's a function pointer.   The person who wrote it could have made better use of typedefs to have made it clearer.

It is in effect a pointer to function with these parameters.
    float* myfunc(double**, char)

Title: How is precedence determined in C pointers?

Body:
I've come across two pointer declarations that I'm having trouble understanding. My understanding of precedence rules goes something like this:

Operator             Precedence             Associativity
(), [ ]                  1                  Left to Right
*, identifier            2                  Right to Left
Data type                3
```

<p>But even given this, I can't seem to figure out how to evaluate the following examples correctly:</p>

<h3>First example</h3>

```float * (* (*ptr)(int))(double **,char c)
```

<p>My evaluation:</p>

<ol>
<li><code>*(ptr)</code></li>
<li><code>(int)</code></li>
<li><code>*(*ptr)(int)</code></li>
<li><code>*(*(*ptr)(int))</code></li>
</ol>

<p>Then,</p>

<ol>
<li><code>double **</code></li>
<li><code>char c</code></li>
</ol>

<h3>Second example</h3>

```unsigned **( * (*ptr) [5] ) (char const *,int *)
```

*(ptr)

[5]

*(*ptr)[5]

*(*(*ptr)[5])

**(*(*ptr)[5])

How should I read them?


答:
My guess for the first one: ptr is a pointer to a function that takes as parameter an int, and returns a pointer to a function that takes as parameters a pointer to pointer to double and a char, and returns a pointer to float.

Interpretation:

(*ptr)(int)

says that ptr is a pointer to a function taking an int as an argument. To discover what that function returns we need to expand our view:

(* (*ptr)(int))

this means the function returns a pointer to another function. The parameters of that other function are:

(double **,char c)

and it returns

float *

And for the second one: ptr is a pointer to an array of five pointers to functions that take as parameters a constant pointer to char and a pointer to int, returning a pointer to a pointer of unsigned int.

Interpretation:

( * (*ptr) [5] )

declares ptr as a pointer to array of five pointers to a function taking

(char const *,int *)

as arguments and returning

unsigned **


答:
The use of the Waterfall methodology, as it is described on the Wikipedia article, on any project of significant scale, is a risky endeavour. In the commonly taught waterfall methodology, testing happens at the very end. There is no discussion (that I am aware of, anyway) of verification or validation happening prior to the "testing" phase. However, the commonly taught Waterfall method is an example of how not to build software systems, and comes from a paper by Winston Royce, where it is described as:

I believe in this concept, but the implementation described above is risky and invites failure. The problem is illustrated in Figure 4. The testing phase which occurs at the end of the development cycle is the first event for which timing, storage, input/output transfers, etc., are experienced as distinguished from analyzed. These phenomena are not precisely analyzable. They are not the solutions to the standard partial differential equations of mathematical physics for instance. Yet if these phenomena fail to satisfy the various external constraints, then invariably a major redesign is required. A simple octal patch or redo of some isolated code will not fix these kinds of difficulties. The required design changes are likely to be so disruptive that the software requirements upon which the design is based and which provides the rationale for everything are violated. Either the requirements must be modified, or a substantial change in the design is required. In effect the development process has returned to the origin and one can expect up to a lO0-percent overrun in schedule and/or costs.

Figure 10 in the paper I linked to is Royce's proposed model of software development, which explicitly includes requirements, design, and implementation reviews. I would suspect that a quality assurance team would be involved in these reviews, to some extent. And in addition to involving quality assurance, the customer is even involved (as appropriate) in the development process at all phases, which is contrary to the Waterfall model traditionally taught.

Now, plan-driven methodologies (like Royce's proposed methodology) are not wrong or bad, when used in the appropriate instances. For example, in a project with volatile requirements, they aren't the best option, and it sounds like this is your case. So yes, when you don't know for sure what you need to build or change is likely, using a plan-driven methodology is costly for the reasons maple_shaft wrote in his answer.


问:
How should a developer reject impossible requirements?
Here's the problem I'm facing:

Quote From Project Manager:

Hey Spark, I'm assigning you the task of developing a framework that could be used for many different iOS applications. Here are the requirements:

It should be able to detect the thickness of the thumb or fingers being used to manipulate the UI.

With this information, all elements of the UI should be arranged & sized automatically.

For a larger thumb, elements should be arranged nearer the center of the screen.

For a smaller thumb, elements should be arranged nearer the corners of the screen.

For a larger thumb, all fonts should be smaller. (We're assuming an adult in this case.)

For a smaller thumb, all fonts should be larger. (We're assuming a younger person in this case.)

Summary:

This framework is required for creating user-friendly user interfaces programmatically. The framework should be developed in such a way that we can use for as many projects as needed, so it must also be very developer-friendly.

I am the developer given this task, so my questions are as follows:

How can I explain that these requirements are a little ridiculous?

How can I explain that it would be better to concentrate on developing actual projects?

How can I explain that even if this were possible, I wouldn't recommended developing such a thing?

How do I say NO to this project politely, gently, and respectfully?

How can I explain that even for a developer with 3 years of experience, this might not be possible?

答:
I'd consider trying to solve the root issue in another way before saying it can't be done.

For instance, if the user often tries to click a small button and misses, you could watch the area around the button and use that to re-calibrate all other clicks.

Presenting a creative solution like this is probably what they are after more than asking you to magically figure out the width of a finger (which you can inform them is not in the API).

It may still be difficult--placing an area around buttons to detect misses--so estimate more hours.


答:
I'm not a PHP guy, but on the java-script  side if you are going to have lots of modules that you would like to keep as independent as possible there are several systems for this, such as RequireJS, that have java-script modules that declare dependencies on other modules, and the framework makes sure they are loaded when needed.

The various frameworks out there vary in how dependencies are declared, how much dependency handling is done as a build step on the server, on page load, or dynamically upon request, and in how much you have to change the way you write your java-script.

These frameworks don't apply as much (or perhaps at all) if your server side framework is handling this or generating your java-script for you, but you could possibly want your java-script to be independent of your server side framework.

If you don't have too much java-script but you want some modularity, you can always stick to anonymous self calling functions that handle dependencies by ordering the script tags with dependencies first, and referencing each other by registering themselves with a single object in the global namespace.  That at least makes them nearly modular and doesn't cost you much to implement.

Title: How to build completely modular web applications

Body:
In the coming months we're going to begin a project where we take a system we've built for a client (v1) and rebuild it from scratch.  Our goal with v2 is to make it modular, so that this specific client will have their own set of modules they use, then another client may use a different set of modules altogether.  The trick here is that Company A might have a series of checkout and user modules that change how that system works.  Company B might stick with the standard checkout procedure but customize how products are browsed.

What are some good approaches to application architecture when you're building an application from scratch that you want to have a Core that's shared among all clients while still maintaining the flexability for anything to be modified specifically for a client?

I've seen CodeIgniter's hooks and don't think that's a good solution as we could end up with 250 hooks and it's still not flexible enough.  What are some other solutions?  Ideally we won't need to draw a line in the sand.


问:
Managing software projects - advice needed
I work for a large government department as part of an IT team that manages and develops websites as well as stand alone web applications.

We’re running in to problems somewhere in the SDLC that don’t rear their ugly head until time and budget are starting to run out.

We try to be “Agile” (software specifications are not as thorough as possible, clients have direct access to the developers any time they want) and we are also in a reasonably peculiar position in that we are not allowed to make profit from the services we provide. We only service the divisions within our government department, and can only charge for the time and effort we actually put in to a project. So if we deliver a project that we have over-quoted on, we will only invoice for the actual time spent.

Our software specifications are not as thorough as they could be, but they always include at a minimum:

Wireframe mockups for every form view

A data dictionary of all field inputs

Descriptions of any business rules that affect the system

Descriptions of the outputs

I’m new to software management, but I’ve overseen enough software projects now to know that as soon as users start observing demos of the system, they start making a huge amount of requests like “Can we add a few more fields to this report.. can we redesign the look of this interface.. can we send an email at this part of the workflow.. can we take this button off this view.. can we make this function redirect to a different screen.. can we change some text on this screen… can we create a special account where someone can log in and get access to X… this report takes too long to run can it be optimised.. can we remove this step in the workflow… there’s got to be a better image we can put here…” etc etc etc.

Some changes are tiny and can be implemented reasonably quickly.. but there could be up to 50-100 or so of such requests during the course of the SDLC. Other change requests are what clients claim they “just assumed would be part of the system” even if not explicitly spelled out in the spec.

We are having a lot of difficulty managing this process. With no experienced software project managers in our team, we need to come up with a better way to both internally identify whether work being requested is “out of spec”,  and be able to communicate this to a client in such a manner that they can understand why what they are asking for is “extra” work.

We need a way to track this work and be transparent with it.

In the spirit of Agile development where we are not spec'ing software systems in to the ground and back again before development begins, and bearing in mind that clients have access to any developer any time they want it, I am looking for some tips and pointers from experienced software project managers on how to handle this sort of "scope creep" problem, in tracking it, being transparent with it, and communicating it to clients such that they understand it.

Happy to clarify anything as needed.

I really appreciate anyone who takes the time to offer some advice.

Thanks.

答:
All the answers here have been good, just to throw in my 2 cents.

Personally I wouldn't give the customer direct access to the developers. The customer, most of the time, won't know how to get the best out of the developer and the impact that their requests will have. Someone said to me once "you can either be a shit funnel or a shit umbrella", you might not see it but you're kind of shit funnelling - the developers are the most important people in a project, not the customer, in my opinion.

Echoed here already, the customer needs to understand that development is a service based industry, they're buying hands on keyboards, not a web app.

I'd try and give an estimate, take the customers budget. Lay your projects out: kick off week, sprint week, review week, sprint week, review week etc. The more time (reviews) you can get the better - ideally I don't want developers to work more than two days a week on a project.

I aim to get the product 'launch-able' at the end of every sprint week, in the review weeks we can then work with the customer to decide what goes into the following week. If the team that are working on the project can only kick out 20 units of work in a week then there needs to be 20 units of work - if you want to add work you need to take away other work.

If the customer requests new features, book in another sprint - I normally say "if you think you're going to want it book it in now, because we might be booked with another project by the end".

I find this is easier to budget, easier to schedule and teaches the customer the impact of adding features.

Hope that's of some help.


答:
I'm going to play Devil's Advocate here a bit and say that I think it's actually technically feasible to measure the size of a person's thumb. The iPhone is a multitouch device. For calibration, you could instruct the user to place their thumbs or two fingers on the screen side-by-side, and measure the distance between these touches.

Of course this would require testing and experimentation to see how feasible my intuition is. Perhaps the thumbs would have to be dragged across the screen to get a better reading.

That said, there are serious usability and implementation issues.

What if the device is shared? When does the calibration happen?

How can you dynamically determine the position of the UI elements arbitrarily across all applications built with the framework? Obviously each app will have a different UI and different layout.

A simple survey of current iOS apps shows that the well designed ones use all the horizontal space available, and already space elements such that important buttons are as large as possible and placed near the edges. The full width of the device is used for lists and layout, obviously.

Even if it were possible, what is the cost/benefit analysis? How much would be gained from such a system compared to standard UI controls? Wouldn't it be easier to have a simple toggle control for font size like many apps already use?

Title: How should a developer reject impossible requirements?

Body:
Here's the problem I'm facing:

Quote From Project Manager:

Hey Spark, I'm assigning you the task of developing a framework that could be used for many different iOS applications. Here are the requirements:

It should be able to detect the thickness of the thumb or fingers being used to manipulate the UI.

With this information, all elements of the UI should be arranged & sized automatically.

For a larger thumb, elements should be arranged nearer the center of the screen.

For a smaller thumb, elements should be arranged nearer the corners of the screen.

For a larger thumb, all fonts should be smaller. (We're assuming an adult in this case.)

For a smaller thumb, all fonts should be larger. (We're assuming a younger person in this case.)

Summary:

This framework is required for creating user-friendly user interfaces programmatically. The framework should be developed in such a way that we can use for as many projects as needed, so it must also be very developer-friendly.

I am the developer given this task, so my questions are as follows:

How can I explain that these requirements are a little ridiculous?

How can I explain that it would be better to concentrate on developing actual projects?

How can I explain that even if this were possible, I wouldn't recommended developing such a thing?

How do I say NO to this project politely, gently, and respectfully?

How can I explain that even for a developer with 3 years of experience, this might not be possible?


问:
What common programming problems are best solved by using prototypes and closures?
As much as I understand both concepts, I can't see how can I take advantage of JavaScript's closures and prototypes aside from using them for creating instantiable and/or encapsulated class-like blocks (which seems more of a workaround than an asset to me)

Other JS features such as functions-as-values or logical evaluation of non-booleans are much easier to fall in love with...

What common programming problems are best solved by using propotypal inheritance and closures?

答:
Closures don't solve any programming problems that can't be solved without them.  However, this can be said for any language feature not needed for Turing completeness, so it doesn't mean much.

Think about how you have to rewrite any code that uses a closure, to not use a closure.  You would probably give the function with the closure extra properties so it could hold it's state between calls.  Which would just be copying the variables that are already in scope into properties of the same name on the function, so it would be the kind of mindless typing exercise that makes you want to yell at the screen "why can't the stupid compiler (interpreter, whatever) figure this out?"  That's what closures are, the stupid compiler is smart enough to figure it out.


答:
I think the first step is to determine a style/theme. For example Windows 8 Metro vs. NT style.

Some suggestions for resources and inspiration (I mention WPF/Web but you don't have to be using it of course):

A - If you want to start with prototyping, control styles here are cool Web Control Styles and Controls

B - Component Factory does give windows forms a good face lift - They even offer one free product at: Component Factory

C  - 3rd party GUI control makers have good looking demos

D - Try to search for the word "books" in this site:User Experience - You will get plenty of posts.

E- This WPF application: WPF Health Care Application

F - This WPF application: Billy Holis - WPF
and the finished version on: WPF - StaffLynx

G - Metro style tools are out there if you like. Check this: Metro Style

Most importantly, as you may already know, balance effort with value.

Edit

DevXpress has released a new release supporting Metro Style, just seen the video toady DevXpress-2


答:
Disclaimer - I don't know whether your request is possible, and if it is possible then you need to determine how long it would take and provide that feedback to your manager. But I'm writing this answer with the assumption that it is not feasible, at least using the standard framework - and I'm extending my answer to the more general case when you really can't or shouldn't do something.

Just say NO.

There are many 'never say no' answers in this thread, which I believe is a soft and submissive attitude. Think about it this way - I'm the technical expert in this team, and my other team members are trying to do something that I think is unfeasible, over-complicated, potentially not possible. It's my responsibility to say no.

Of course I can & should say no gently; I can "strongly recommend against this" while offering to "investigate whether it's possible" before saying no. But I'm ultimately going to say no because that's my job.

There are so many analogies to this

My Accountant, I want you to put my Thanksgiving dinner down as a tax deduction

Mr Chef, I would like my chicken left on the counter overnight and served raw, please.

My Lawyer, I want to sue my children for not tidying their bedrooms

Mr Mechanic, please install a turbocharger on my electric car

You can ask all of these people to perform tasks that they'll know are silly, wasteful, dangerous or wrong. And you would expect all of them to advise against these actions and ultimately refuse (at least I'd hope so). If any of these professionals replied 'Hmm okay I guess we can do that' - without giving me a straight up "This Is A Bad Idea" - then quite frankly I wouldn't want to hire them anyway.

Your colleagues will value and respect your honesty, and you will save everyone a lot of time and money if you provide useful feedback rather than going along with something you know won't work.


答:
I always follow the rule of minimizing clicks and keystrokes.
I'm not very good at making a sexy-looking UI, with lots of colors and plump-looking buttons, but users tell me my UIs are a breeze to use.
Here's one.

One of the things I discovered is that users love instant response.
It's like Hollywood.
People love pixels (preferably colored pixels).
They really love pixels that move.

In an attempt to make UIs like that, and to simplify the coding effort, ages ago I came up with a scheme that I still use to this day - Differential Execution.
(I can't say I've had much luck publicizing it, but there it is. It has been published, FWIW.)

So that's just my two cents.


问:
int* i; or int *i; or int * i;
What is your favorite method to declare a pointer?

```<code>int* i;
</code>```

or

```<code>int *i;
</code>```

or

```<code>int * i;
</code>```

or

```<code>int*i;
</code>```

Please explain why.

see also: http://www.stroustrup.com/bs_faq2.html#whitespace

答:
There are no pointer types in C! So, "int*" means nothing. The asterisk is always bound to the element written right of it, it belongs to the element right to it. "*i" is an int. And because of *i is an int, it follows that i is a pointer to int. That's the logic behind it and that is why "int *i" is the only possible solution. Everything else is an illusion (which is automatically corrected by the compiler in most cases).
In C++ and C# that's something different. But for C there is only one bible: "Dennis M. Ritchie: The C Programming Language". Dennis (R.I.P.!) wrote it: "int *i". There is no need to question this. </p>

Title: int* i; or int *i; or int * i;


答:
When it comes to requirements I usually do it like this: I try to estimate how long it would take to realize a specific requirement.

In case of requirements that might be impossible, ask for some days or whatever time it takes to find out whether it is possible. In your case the question is: "Is it possible to determine how thick the user's finger is?"

In fact this question is even a bit more complex: "Is it possible to determine how thick the user's finger after the first touch in less than 200 milliseconds to allow for a immediate interaction?" (replace first by 2nd or ...; and 200 ms by 300 ms or whatever...)

Maybe even answering this question takes one month. Maybe even if this is more or less feasible, it takes a super complex algorithm that only works good in 80% of the cases.

You see where I'm going?

People often make wrong assumptions about possibilities because they have low expertise and experience regarding the field in question. Therefore you cannot argument with intuition, but you need facts.

If the other stakeholders realize that this feature would take 2 man-years and requires the iPhone 10 to arrive before 2014, there will quickly downscale their requirements.


问:
What are functional-programming ways of implementing Conway's Game of Life
I recently implemented for fun Conway's Game of Life in Javascript (actually coffeescript but same thing). Since javascript can be used as a functional language I was trying to stay to that end  of the spectrum. I was not happy with my results. I am a fairly good OO programmer and my solution smacked of same-old-same-old. So long question short: what is the (pseudocode) functional style of doing it?

Here is Pseudocode for my attempt:

```<code>class Node
  update: (board) ->
    get number_of_alive_neighbors from board
    get this_is_alive from board
    if this_is_alive and number_of_alive_neighbors < 2 then die
    if this_is_alive and number_of_alive_neighbors > 3 then die
    if not this_is_alive and number_of_alive_neighbors == 3 then alive

class NodeLocations
  at: (x, y) -> return node value at x,y
  of: (node) -> return x,y of node

class Board
  getNeighbors: (node) ->
   use node_locations to check 8 neighbors
   around node and return count

nodes = for 1..100 new Node
state = new NodeState(nodes)
locations = new NodeLocations(nodes)
board = new Board(locations, state)

executeRound:
  state = clone state
  accumulated_changes = for n in nodes n.update(board)
  apply accumulated_changes to state
  board = new Board(locations, state)
</code>```

答:
You might want to look at the implementations on RosettaCode for inspiration.

For example there are functional Haskell and OCaml versions which create a new board each turn by applying a function to the previous one, while the graphical OCaml version uses two arrays and updates them alternately for speed.

Some of the implementations decompose the board update function into functions for counting the neighbourhood, applying the life rule and iterating over the board. Those seem like useful components to base a functional design on. Try modifying only the board, keeping everything else as pure functions.


答:
Nice coincidence, we covered this exact problem in our Haskell lecture today.  First time I've seen it but here is a link to the source code we were given:

http://pastebin.com/K3DCyKj3

Title: What are functional-programming ways of implementing Conway's Game of Life

Body:
I recently implemented for fun Conway's Game of Life in Javascript (actually coffeescript but same thing). Since javascript can be used as a functional language I was trying to stay to that end  of the spectrum. I was not happy with my results. I am a fairly good OO programmer and my solution smacked of same-old-same-old. So long question short: what is the (pseudocode) functional style of doing it?

Here is Pseudocode for my attempt:

```<code>class Node
  update: (board) ->
    get number_of_alive_neighbors from board
    get this_is_alive from board
    if this_is_alive and number_of_alive_neighbors < 2 then die
    if this_is_alive and number_of_alive_neighbors > 3 then die
    if not this_is_alive and number_of_alive_neighbors == 3 then alive

class NodeLocations
  at: (x, y) -> return node value at x,y
  of: (node) -> return x,y of node

class Board
  getNeighbors: (node) ->
   use node_locations to check 8 neighbors
   around node and return count

nodes = for 1..100 new Node
state = new NodeState(nodes)
locations = new NodeLocations(nodes)
board = new Board(locations, state)

executeRound:
  state = clone state
  accumulated_changes = for n in nodes n.update(board)
  apply accumulated_changes to state
  board = new Board(locations, state)
</code>```


问:
How to "back track"?
I find that I start projects and, due to my lack of experience, find that old database structures and huge blocks of code are inefficient and memory-costly. However, by the time I realize a re-design of the entire project is needed, the project has grown to such a size that it is simply too late to go back and modify the project in its current state and requires a completely new project file and the whole shebang.

How should I prevent ruts such as this one, where it is too late to go back and modify the current project to fit specifications modified far down the road from the creation of the project?

(Apologies in advance for confusing grammar, it's been a long day here... as you can probably tell.)

答:
There are a number of things that will help, but there's no silver bullet that makes reworking your project simple. In no particular order:

Use version control. You should be able to go back to any revision of your project at any time. If you determine that you made a big design mistake two weeks ago and wish you could take it back, version control lets you go back.

Avoid dependencies. If fixing your project is harder than starting over from scratch, it's very likely that the various parts of your program are far too interdependent. There are many patterns and strategies for making your code more modular and reducing dependencies between modules. Spend some time learning about good object oriented design (assuming you're working in the OO style). Isolating different functionality in separate modules means that problems should be better confined to specific modules, and improving your project means reworking a module or two instead of rewriting the whole project.

Fix your code anyway. Fixing your code might seem like more work than starting over, but you'll probably learn a lot more by fixing your mistakes. It's hard to really understand problems until you have to fix them. Starting over may just lead to making the same old mistakes and needing to start over yet again sometime in the future.

Review early, review often. If you don't notice problems until they're so broken that you have to abandon the project, you're not looking at your code hard enough, early enough, or often enough.

Get help. You say that your lack of experience leads to bad decisions. Find some smart, experienced friends or colleagues who can help you make design decisions in the first place and review both your design and your code along the way. Explaining your work to other people can help even if your helpers aren't really all that smart or experienced. Other viewpoints are often helpful, and the act of explaining itself helps you see your work through someone else's eyes.

Title: How to "back track"?


答:
One way of diverting the unreasonable request is by helping the client understand the nature of the problem they're trying to solve. Through a planning interview technique colloquially known as "popping the why stack", you continue asking "why" recursively (in a polite, intelligent way of course):

One important tool for both getting communications going and "cutting to the chase" of specific issues is what Barrett calls popping the "why" stack. This is simply to keep asking the question "why is it done that way?" about project requirements. He gave an archetypal example of what the technique can unearth: "I once worked with a client where there was a requirement that data was printed out at a particular stage in the process, so I asked why" he said. "The answer was that the department receiving the data needed to key it in. It had never occurred to them that the data could be transferred to their application automatically."

The goal is to arrive at the core business value of the feature:

Protect revenue

Increase revenue

Manage cost

Increase brand value

Make the product remarkable

Provide more value to your customers

(Items from Cucumber wiki)

If the feature doesn't fit one of these categories, it may help the client to see that there are either more important things to focus on, or through this thought process you may be able to advise them on how to address the problem they're trying to solve in a more meaningful way. Often the real problem lies at a higher level of abstraction than the problem they've requested you to fix.

To use your example of scanning thumb sizes:

Client: We want to detect the thickness of the thumb or fingers being used to manipulate the UI.

Dev: Why do you want to do that?

Client: Because when I try to tap these small buttons I often hit the wrong thing, and our software is used by a lot of construction workers with big hands like me. If they could calibrate the UI for their finger size, it would make it easier to use.

Dev: Ease of use would certainly be valuable to the customer, but why would they want to calibrate the UI? If the people using this are known to have big hands, why not adjust the design for that use case?

Client: I never thought of it that way, I suppose a cleaner design would work just as well for people with small hands too!


问:
Why is Conway's "Game of Life" used for code retreats?
Code Retreat is an all-day training event that focuses on the fundamentals of software development. There's a "global" code retreat day coming up, and I'm looking forward to it. That said, I've been to one before and have to say there was a huge amount of chaos... which is fine.

One thing that I still don't get is why the "Game of Life" is a good problem for TDD, and what good and bad TDD for it feels like.

Realize this is a pretty open ended question, so feel free to comment.

答:
Conway's Game of Life would be a good fit because it's a fairly simple coding set that has profoundly powerful results. As for using it to drive Test-Driven Development, I'd wager its because the tests would fairly tricky to write because the results you are looking for are not obvious from the code you are writing. Writing code that gets you a glider is quite the trick if you've not done it before or not done it in a long time. Thus its suited to stretching the art of the discipline, particularly when executed in pair programming as TDD usually is.

As far as teaching you useful things; it's an exercise in a kind of lateral thinking. You have to conceptualize how your code will function, run it, see it fail, gather data, refactor, and continue iterating. All of these things are crucial to TDD. Linking it up to the real world, it's akin to a client handing you a vague requirements document that just says "I want X". So you give them X but getting to X might be a tricky. Conway's Game of Life is good at teaching that. It's also fairly easy to code and typically doesn't take tons of code to do so. (APL being one of the more extreme examples of implementation.) So it's quite suited for the short sessions a retreat would have rather than a week or two week iteration as you might typically find in a production environment.


问:
CQRS without using others patterns
I would like to explain CQRS to my team of developers. I just can't figure out how to explain it in the simplest way so they can implement the pattern rapidly without any others frameworks. I've read a lot of resources including video and articles but I don't find how to implement CQRS without using others patterns like a service Bus, event sourcing pattern, domain driven design. I know the purpose of these pattern but for the first step, I don't want them to think CQRS and these patterns must be tied together.

My first idea is to say that CQRS is about separating the read part and the write part. The read part is composed only of the UI project, and DAL project. Then the write part is composed of a typical multilayer architecture: UI/BLL/DAL. Then, does CQRS say we must also have two datastore ? What about the notion of commands which reveal the user's intention, is it also something part of CQRS or DDD ?

Basically, how to implement CQRS without using others patterns. I concede it's also not that clear in my mind because I've used to work with NCQRS/DDD/Event Sourcing/ServiceBus in my personal project.

答:
There are several ways of going about this. You know your team best. It's best to ask yourself at what level of abstraction you need to speak for them to comprehend.

Cqrs is really about seperating read logic from write logic. This is best explained by comparing it to todays layered architecture as promoted by database vendors (video section over on http://dddcqrs.com does a good job at that), mostly because people can relate to it and see how the changes you propose fit into that architecture. You could just stop at the argument that for the purpose of reading data there's no need to jump through all the hoops (of the write logic). No need to go any further (no seperate stores, ddd concepts, messaging, service bus, etc.). That said, there's much more value to be gained, both from a technical and functional perspective, if you pursue further. But again, 1 step at a time. Remember, people in general are not very fond of change (even if it's a good change). There's lots of value in the offspring of cqrs, but it requires careful judgement and assesment if it fits your team (and their maturity). Sometimes it's better to grow together than dragging people into something. Also, don't forget that management is not to be ignored either.

OwnerDisplayName: John Smith

Title: CQRS without using others patterns

OwnerDisplayName: Yves Reynhout


答:
It all depends on what aspect of your process you want to practice / train for.

A single day is not enough to cover all aspects of software engineering regardless of the approach / project management paradigm you choose.  So to make it effective you probably should concentrate on a small subset of the whole.

If you focus on the technical aspects of TDD for example then you may want to let go the large grey areas around requirements and relations with the customer and cut right to the coding of a solution.

In this regards the Game of Life is a good candidate because it is simple, well understood and does not have many grey areas in it's requirement that will be open for debate.  Thus you can start writing your test right away and code against them.

If on the other hand the goal was to see how we can use TDD to hone in on the requirements then I might have chosen the game of life but I would not have told the devs that this is what I want.  Instead I would have circled around providing hints and ideas without actually mentioning it by name.  That said the game of life may prove a tad bit too simple for this kind of exercise as attendees would most likely see through the ploy pretty quickly.

Examples are not always easy to find for such synthetic exercise. it has to be simple as to be done in a day yet not too simple to make it through the day.  It has to be fun yet not meaningless ...  But to me it has to be a bit original, I cant recall how many times I was asked to get the students to create a videoclub management system for homework....  iiirch.

Title: Why is Conway's "Game of Life" used for code retreats?

Body:
Code Retreat is an all-day training event that focuses on the fundamentals of software development. There's a "global" code retreat day coming up, and I'm looking forward to it. That said, I've been to one before and have to say there was a huge amount of chaos... which is fine.

One thing that I still don't get is why the "Game of Life" is a good problem for TDD, and what good and bad TDD for it feels like.

Realize this is a pretty open ended question, so feel free to comment.


问:
Best free UML authoring tool
What free UML authoring tools do you use and why is it better than others?</p>

答:
I use Umlet. What I like with this software is that it's a drawing tool only. It doesn't force you to create and maintain a model, and it doesn't try to generate/parse code. Unlike a lot of UML tool I tried, I've always been able to draw the diagram I had in mind (the drawing primitives are quite complete, and they are extensible by code).
It works well with my other tools : the text based format is ok for working with my VCS, and the png/svg can be generated using a command line (I use it to automate the build of my doc).</p>

Title: Best free UML authoring tool


问:
Unit testing - getting started
I am just getting started with unit testing but I am not sure if I really understand the point of it all. I read tutorials and books on it all, but I just have two quick questions:

I thought the purpose of unit testing is to test code we actually wrote. However, to me it seems that in order to just be able to run the test, we have to alter the original code, at which point we are not really testing the code we wrote but rather the code we wrote for testing.

Most of our codes rely on external sources. Upon refactoring our code however, even it would break the original code, our tests still would run just fine, since the external sources are just muck-ups inside our test cases. Doesn't it defeat the purpose of unit testing?

Sorry if I sound dumb here, but I thought someone could enlighten me a bit.

Thanks in advance.

答:
My 0.02$... this is a bit subjective, so take with a grain of salt, but hopefully it'll get you thinking and/or spark some dialog:

The primary purpose of unit testing to me is to ensure that the code
that you wrote fulfills the contracts and edge cases your code is
intended to fulfill.  With unit tests in place, you can better
ensure that when you (or someone else in the future) refactors your
code, any external consumers of your code should remain unaffected
if you have proper state coverage. (at least to the degree that you
intend for them to be unaffected).

In the majority of cases you should be able to write code that can
both be shipped to production and is easily unit-testable. A good
place to start may be to look into Dependency Injection patterns and
frameworks. (Or other philosophies for your language / platform of
choice).

It is correct that external implementations could affect your code.
However ensuring that your code works correctly as part of a larger
system is a function of integration testing. (Which could also be
automated with varying degrees of effort).

Ideally your code should only rely upon the API contracts of any 3rd
party components which would mean that so long as your mocks fulfill
the correct API your unit tests still provide value.

That said I'll readily admit that there have been times where I did
forgo unit testing in favor of integration testing alone, but that
has been only cases where my code had to interact so profusely with
3rd party components with poorly documented APIs. (i.e. the
exception rather than the rule).

OwnerDisplayName: higgenkreuz

Title: Unit testing - getting started


答:
Try writing your tests first. That way, you will have a solid base
for the behaviour of your code and your test becomes a contract for
the required behaviour of your code. Thus, changing the code to pass
the test becomes "changing the code to fulfill the contract proposed
by the test" instead of "changing the code to pass the test".

Well, be careful about the difference between stubs and mocks. Being
unaffected by any changes in the code is characteristic behaviour of
stubs, but not mocks. Lets start with the definition of the mock:

A Mock object replaces a real object under test conditions, and allows
  verifying the calls (interactions) against itself as part of a system
  or unit test.

-The Art of Unit Testing

Basically, your mocks should check for the required behaviour of your interactions. Thus, if your interaction with the database fails after a refactoring, your test using the mock should also fail. This of course has limitations, but with careful planning your mocks will do much more than just "sitting there" and it won't "defeat the purpose of unit testing".

Title: Unit testing - getting started

Body:
I am just getting started with unit testing but I am not sure if I really understand the point of it all. I read tutorials and books on it all, but I just have two quick questions:

I thought the purpose of unit testing is to test code we actually wrote. However, to me it seems that in order to just be able to run the test, we have to alter the original code, at which point we are not really testing the code we wrote but rather the code we wrote for testing.

Most of our codes rely on external sources. Upon refactoring our code however, even it would break the original code, our tests still would run just fine, since the external sources are just muck-ups inside our test cases. Doesn't it defeat the purpose of unit testing?

Sorry if I sound dumb here, but I thought someone could enlighten me a bit.

Thanks in advance.

OwnerDisplayName: ruhsuzbaykus


答:
When I was looking around, I put a link to my careers.so page, which has a link to my SO and SU accounts, in the block with my contact information.  I felt this was an unobtrusive way to provide more information, if someone desired it.

As someone who has done lots of developer hiring recently, I would be happy to see references to someone online profiles.  It wouldn't turn a no into an interview, but it might tip the scales if I'm unsure whether to bring someone in, assuming I like what I see online.  It gives a much deeper insight into how someone might fit into out team that a resume ever would.

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?


答:
Using cdecl.org:

char * const (* (* const bar)[5])(int )

declare bar as const pointer to array 5 of pointer to function (int) returning const pointer to char

unsigned **( * (*ptr) [5] ) ( char const *,int *)

declare ptr as pointer to array 5 of pointer to function (pointer to const char, pointer to int) returning pointer to pointer to unsigned


答:
Asking a good question isn't dumb in any way.

I'll address your questions.

The purpose of unit-testing is not to test the code you already wrote. It has no notion of time. Only in TDD you're supposed to test-first, but that doesn't strictly apply to any kind of unit-testing.
The point is to be able to automatically and efficiently test your program in the class-level. You do what you need to do in order to get there, even if it means changing the code. And let me tell you a secret - it often means that.

When you write a test you have 2 primary options to help ensure your test is correct:

Vary the inputs for each test

Write a test-case that ensures that your program works properly, and then write a corresponding test-case that ensures your program doesn't work the way it shouldn't

Here's an example:

```<code>TEST(MyTest, TwoPlusTwoIsFour) {
    ASSERT_EQ(4, 2+2);
}

TEST(MyTest, TwoPlusThreeIsntFour) {
    ASSERT_NE(4, 2+3);
}
</code>```

On top of that, if you're unit-testing the logic inside your code (not the 3rd party libraries), then it's perfectly fine that you don't worry about the other code breaking, while in that context. You're essentially testing the way your logic wraps and uses the 3rd party utilities, which is a classic testing scenario.

Once you're done testing at the class level, you can go on to testing the integration between your classes (the mediators, from what I understand) and the 3rd party libraries. These tests are called integration tests, and do not use mocks, but rather the concrete implementations of all classes. They're a bit slower, but still very important!

Title: Unit testing - getting started

Body:
Asking a good question isn't dumb in any way.

I'll address your questions.

The purpose of unit-testing is not to test the code you already wrote. It has no notion of time. Only in TDD you're supposed to test-first, but that doesn't strictly apply to any kind of unit-testing.
The point is to be able to automatically and efficiently test your program in the class-level. You do what you need to do in order to get there, even if it means changing the code. And let me tell you a secret - it often means that.

When you write a test you have 2 primary options to help ensure your test is correct:

Vary the inputs for each test

Write a test-case that ensures that your program works properly, and then write a corresponding test-case that ensures your program doesn't work the way it shouldn't

Here's an example:

TEST(MyTest, TwoPlusTwoIsFour) {
    ASSERT_EQ(4, 2+2);
}

TEST(MyTest, TwoPlusThreeIsntFour) {
    ASSERT_NE(4, 2+3);
}

On top of that, if you're unit-testing the logic inside your code (not the 3rd party libraries), then it's perfectly fine that you don't worry about the other code breaking, while in that context. You're essentially testing the way your logic wraps and uses the 3rd party utilities, which is a classic testing scenario.

Once you're done testing at the class level, you can go on to testing the integration between your classes (the mediators, from what I understand) and the 3rd party libraries. These tests are called integration tests, and do not use mocks, but rather the concrete implementations of all classes. They're a bit slower, but still very important!


问:
How to layout class definition when inheriting from multiple interfaces
Given two interface definitions ...

```<code>IOmniWorkItem = interface ['{3CE2762F-B7A3-4490-BF22-2109C042EAD1}']
  function  GetData: TOmniValue;
  function  GetResult: TOmniValue;
  function  GetUniqueID: int64;
  procedure SetResult(const value: TOmniValue);
//
  procedure Cancel;
  function  DetachException: Exception;
  function  FatalException: Exception;
  function  IsCanceled: boolean;
  function  IsExceptional: boolean;
  property Data: TOmniValue read GetData;
  property Result: TOmniValue read GetResult write SetResult;
  property UniqueID: int64 read GetUniqueID;
end;

IOmniWorkItemEx = interface ['{3B48D012-CF1C-4B47-A4A0-3072A9067A3E}']
  function  GetOnWorkItemDone: TOmniWorkItemDoneDelegate;
  function  GetOnWorkItemDone_Asy: TOmniWorkItemDoneDelegate;
  procedure SetOnWorkItemDone(const Value: TOmniWorkItemDoneDelegate);
  procedure SetOnWorkItemDone_Asy(const Value: TOmniWorkItemDoneDelegate);
//
  property OnWorkItemDone: TOmniWorkItemDoneDelegate read GetOnWorkItemDone write SetOnWorkItemDone;
  property OnWorkItemDone_Asy: TOmniWorkItemDoneDelegate read GetOnWorkItemDone_Asy write SetOnWorkItemDone_Asy;
end;
</code>```

... what are your ideas of laying out class declaration that inherits from both of them?

My current idea (but I don't know if I'm happy with it):

```<code>TOmniWorkItem = class(TInterfacedObject, IOmniWorkItem, IOmniWorkItemEx)
strict private
  FData              : TOmniValue;
  FOnWorkItemDone    : TOmniWorkItemDoneDelegate;
  FOnWorkItemDone_Asy: TOmniWorkItemDoneDelegate;
  FResult            : TOmniValue;
  FUniqueID          : int64;
strict protected
  procedure FreeException;
protected //IOmniWorkItem
  function  GetData: TOmniValue;
  function  GetResult: TOmniValue;
  function  GetUniqueID: int64;
  procedure SetResult(const value: TOmniValue);
protected //IOmniWorkItemEx
  function  GetOnWorkItemDone: TOmniWorkItemDoneDelegate;
  function  GetOnWorkItemDone_Asy: TOmniWorkItemDoneDelegate;
  procedure SetOnWorkItemDone(const Value: TOmniWorkItemDoneDelegate);
  procedure SetOnWorkItemDone_Asy(const Value: TOmniWorkItemDoneDelegate);
public
  constructor Create(const data: TOmniValue; uniqueID: int64);
  destructor Destroy; override;
public //IOmniWorkItem
  procedure Cancel;
  function  DetachException: Exception;
  function  FatalException: Exception;
  function  IsCanceled: boolean;
  function  IsExceptional: boolean;
  property Data: TOmniValue read GetData;
  property Result: TOmniValue read GetResult write SetResult;
  property UniqueID: int64 read GetUniqueID;
public  //IOmniWorkItemEx
  property OnWorkItemDone: TOmniWorkItemDoneDelegate read GetOnWorkItemDone write SetOnWorkItemDone;
  property OnWorkItemDone_Asy: TOmniWorkItemDoneDelegate read GetOnWorkItemDone_Asy write SetOnWorkItemDone_Asy;
end;
</code>```

As noted in answers, composition is a good approach for this example but I'm not sure it applies in all cases. Sometimes I'm using multiple inheritance just to split read and write access to some property into public (typically read-only) and private (typically write-only) part. Does composition still apply here? I'm not really sure as I would have to move the property in question out from the main class and I'm not sure that's the correct way to do it.

Example:

```<code>// public part of the interface interface
IOmniWorkItemConfig = interface
  function  OnExecute(const aTask: TOmniBackgroundWorkerDelegate): IOmniWorkItemConfig;
  function  OnRequestDone(const aTask: TOmniWorkItemDoneDelegate): IOmniWorkItemConfig;
  function  OnRequestDone_Asy(const aTask: TOmniWorkItemDoneDelegate): IOmniWorkItemConfig;
end;

// private part of the interface
IOmniWorkItemConfigEx = interface ['{42CEC5CB-404F-4868-AE81-6A13AD7E3C6B}']
  function  GetOnExecute: TOmniBackgroundWorkerDelegate;
  function  GetOnRequestDone: TOmniWorkItemDoneDelegate;
  function  GetOnRequestDone_Asy: TOmniWorkItemDoneDelegate;
end;

// implementing class
TOmniWorkItemConfig = class(TInterfacedObject, IOmniWorkItemConfig, IOmniWorkItemConfigEx)
strict private
  FOnExecute        : TOmniBackgroundWorkerDelegate;
  FOnRequestDone    : TOmniWorkItemDoneDelegate;
  FOnRequestDone_Asy: TOmniWorkItemDoneDelegate;
public
  constructor Create(defaults: IOmniWorkItemConfig = nil);
public //IOmniWorkItemConfig
  function  OnExecute(const aTask: TOmniBackgroundWorkerDelegate): IOmniWorkItemConfig;
  function  OnRequestDone(const aTask: TOmniWorkItemDoneDelegate): IOmniWorkItemConfig;
  function  OnRequestDone_Asy(const aTask: TOmniWorkItemDoneDelegate): IOmniWorkItemConfig;
public //IOmniWorkItemConfigEx
  function  GetOnExecute: TOmniBackgroundWorkerDelegate;
  function  GetOnRequestDone: TOmniWorkItemDoneDelegate;
  function  GetOnRequestDone_Asy: TOmniWorkItemDoneDelegate;
end;
</code>```

答:
Did you consider using composition here? My Delphi is horrible, but this should get you an idea:

```<code>TOmniWorkItemEx = class(IOmniWorkItemEx)
    //implement it
end;

TOmniWorkItem = class(TInterfacedObject, IOmniWorkItem)
//implement the whole interface
//and now compose:
strict private
  FHandlers          : TOmniWorkItemEx;
protected
  function GetHandlers: IOmniWorkItemEx;
public
  property Handlers:IOmniWorkItemEx read GetHandlers;
end;
</code>```

This splits the code nicely. Technically, IOmniWorkItemEx (and TOmniWorkItemEx) would best be parametrized with the function type and would have more generic method names (and a more generic name in the first place), and would thus be reusable.

Update:

Well, according to SOLID, interfaces should be as small as possible and classes should only have one responsibility (having a class implement too many interfaces is often an indicator that it violates the SRP).

For code division and code reuse, there's two approaches:

inheritance and partial implementation

composition and decomposition

Composition can be tedious, especially since most languages don't support syntactic delegation, but other than that, it almost certainly leads to better results.

In your last example, you have some code duplication and lack of normalization as well. Here's how I'd do it:

```<code>IWorkerItem<Owner, Worker> = interface
    function GetWith(const aTask: Worker):Owner
    function GetWorker: Worker
end;

class TOmniConfigWorkerItem<Worker> = class(IWorkerItem<TOmniWorkItemConfig, Worker>)
    //... implement
end;
</code>```

And use it like this:

```<code>private strict
   FOnExecute        : TOmniConfigWorkerItem<TOmniBackgroundWorkerDelegate>;
   FOnRequestDone    : TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
   FOnRequestDone_Asy: TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
protected
   function GetOnExecute        : TOmniConfigWorkerItem<TOmniBackgroundWorkerDelegate>;
   function GetOnRequestDone    : TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
   function GetOnRequestDone_Asy: TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
public
   property OnExecute : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnExecute;
   property OnRequestDone : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnRequestDone;
   property OnRequestDone_Asy : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnRequestDone_Asy;
</code>```

This probably doesn't look like much of an improvement. In languages where declaring a read-only property is a matter of one line, it becomes really apparent. But even in this case, you swapped two partial abstractions against a very simple, atomic one.

Also the code might not compile. Some languages demand the type of an accessor to be equal to that of its property, so you might need to change that. I just thought it'd be better to use the abstraction for the public interface and the concretisation for the internal implementation.

Body:
Did you consider using composition here? My Delphi is horrible, but this should get you an idea:

TOmniWorkItemEx = class(IOmniWorkItemEx)
    //implement it
end;

TOmniWorkItem = class(TInterfacedObject, IOmniWorkItem)
//implement the whole interface
//and now compose:
strict private
  FHandlers          : TOmniWorkItemEx;
protected
  function GetHandlers: IOmniWorkItemEx;
public
  property Handlers:IOmniWorkItemEx read GetHandlers;
end;

This splits the code nicely. Technically, IOmniWorkItemEx (and TOmniWorkItemEx) would best be parametrized with the function type and would have more generic method names (and a more generic name in the first place), and would thus be reusable.

Update:

Well, according to SOLID, interfaces should be as small as possible and classes should only have one responsibility (having a class implement too many interfaces is often an indicator that it violates the SRP).

For code division and code reuse, there's two approaches:

inheritance and partial implementation

composition and decomposition

Composition can be tedious, especially since most languages don't support syntactic delegation, but other than that, it almost certainly leads to better results.

In your last example, you have some code duplication and lack of normalization as well. Here's how I'd do it:

IWorkerItem<Owner, Worker> = interface
    function GetWith(const aTask: Worker):Owner
    function GetWorker: Worker
end;

class TOmniConfigWorkerItem<Worker> = class(IWorkerItem<TOmniWorkItemConfig, Worker>)
    //... implement
end;

And use it like this:

private strict
   FOnExecute        : TOmniConfigWorkerItem<TOmniBackgroundWorkerDelegate>;
   FOnRequestDone    : TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
   FOnRequestDone_Asy: TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
protected
   function GetOnExecute        : TOmniConfigWorkerItem<TOmniBackgroundWorkerDelegate>;
   function GetOnRequestDone    : TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
   function GetOnRequestDone_Asy: TOmniConfigWorkerItem<TOmniWorkItemDoneDelegate>;
public
   property OnExecute : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnExecute;
   property OnRequestDone : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnRequestDone;
   property OnRequestDone_Asy : IWorkerItem<TOmniWorkItemConfig, TOmniBackgroundWorkerDelegate> read GetOnRequestDone_Asy;

This probably doesn't look like much of an improvement. In languages where declaring a read-only property is a matter of one line, it becomes really apparent. But even in this case, you swapped two partial abstractions against a very simple, atomic one.

Also the code might not compile. Some languages demand the type of an accessor to be equal to that of its property, so you might need to change that. I just thought it'd be better to use the abstraction for the public interface and the concretisation for the internal implementation.


问:
Why is a linked list implementation considered linear?
Typically, computer memory is always linear. So is the term non linear used for a data structure in a logical sense? If so, to logically achieve non linearity in a linear computer memory, we use pointers. Is that right?

In that case, if pointers are virtual implementations for achieving non linearity, why would a data structure like linked list be considered linear, if in reality the nodes are never physically adjacent?

答:
I think what they mean by "linear" is most probably the linked list's performance characteristics. To access the n-th element of a linked list, you need to walk through each element before it one by one. Thus, the time required to do this is a linear function of n (the upper limit of which is the list size). As opposed to e.g. an array, which is random access, i.e. accessing any array element by index requires practically the same, constant time.

OTOH inserting a new element in a known location in the middle of a linked list requires constant time, while doing the same in an array requires shifting the remainder of the array in memory, which is linear to number of subsequent elements (bounded by the size of the array). So linked lists do have performance benefits.


答:
One possible reason - because where the nodes appear in memory isn't really relevant. It's more important is how you view the list conceptually.

In more concrete terms, consider how you'd normally represent a linear list as a diagram. Since arrangement in memory is unimportant - it's purely an implementation detail - you don't represent that in the diagram. You typically order the items according to the list order, so they form a line, with each item in order being one step further along the line.

Another idea is that it's purely "linear" in contrast to circular linked lists.

Péter raises a good point, too - probably better than mine. But we're both just inventing rationalisations I suspect. Some names don't have deep meaning, but were just what someone thought up without putting much thought into it, and then the name stuck.

Title: Why is a linked list implementation considered linear?

Body:
Typically, computer memory is always linear. So is the term non linear used for a data structure in a logical sense? If so, to logically achieve non linearity in a linear computer memory, we use pointers. Is that right?

In that case, if pointers are virtual implementations for achieving non linearity, why would a data structure like linked list be considered linear, if in reality the nodes are never physically adjacent?


问:
A programming language that does not allow IO. Haskell is not a pure language
Are there any 100% pure languages (as I describe in the Stack Overflow post) out there already and if so, could they feasibly be used to actually do stuff? i.e. do they have an implementation? I'm not looking for raw maths on paper/Pure lambda calculus. However Pure lambda calculus with a compiler or a runtime system attached is something I'd be interested in hearing about.</p>

答:
A "pure" language that couldn't do IO couldn't do much. ...after all, even printing a result on the screen is IO. So if you can't see the result of a program, wouldn't it be rather pointless?

You couldn't read files, couldn't listen to sockets, couldn't interact with users, couldn't ask for input... etc. What good would that be?

That said, Haskell is the closest to "pure" (whatever that means) functional programming I know of. Their whole IO system is even made using Monads, which kind of a mix between IO and functional.

I also know of "Clean" which is an academic functional language and sees IO as a transform of a World object if I remember right ...however, this starts to be very exotic.


答:
Indeed, as Simon Peyton Jones once stated, Haskell is the finest imperative language out there.

Seriously, purity is not a religious issue. The problem is not that impure functions and mutable data exist. The problems in conventional languages is that often you can't tell impure frm pure and mutable from immutable: not by looking at it, not by compiling it, only by running it.

This is the great advantage that Clean, Haskell (and followers like Frege) have. Conversely, languages like F#, Scala or Clojure that embrace the imperative world and just add the possibility to build something functional alongside suffer from the same problems as the imperative languages, although they may seem very practical indeed.

Title: A programming language that does not allow IO. Haskell is not a pure language

Body: Are there any 100% pure languages (as I describe in the Stack Overflow post) out there already and if so, could they feasibly be used to actually do stuff? i.e. do they have an implementation? I'm not looking for raw maths on paper/Pure lambda calculus. However Pure lambda calculus with a compiler or a runtime system attached is something I'd be interested in hearing about.</p>


问:
UML Diagrams of Multi-Threaded Applications
For single-threaded applications I like to use class diagrams to get an overview of the architecture of that application. This type of diagram, however, hasn’t been very helpful when trying to understand heavily multi-threaded/concurrent applications, for instance because different instances of a class "live" on different threads (meaning accessing an instance is save only from the one thread it lives on). Consequently, associations between classes don’t necessarily mean that I can call methods on those objects, but instead I have to make that call on the target object's thread.

Most literature I have dug up on the topic such as Designing Concurrent, Distributed, and Real-Time Applications with UML by Hassan Gomaa  had some nice ideas, such as drawing thread boundaries into object diagrams, but overall seemed a bit too academic and wordy to be really useful.

I don’t want to use these diagrams as a high-level view of the problem domain, but rather as a detailed description of my classes/objects, their interactions and the limitations due to thread-boundaries I mentioned above.

I would therefore like to know:

What types of diagrams have you found to be most helpful in understanding multi-threaded applications?

Are there any extensions to classic UML that take into account the peculiarities of multi-threaded applications, e.g. through annotations illustrating that

some objects might live in a certain thread while others have no thread-affinity;

some fields of an object may be read from any thread, but written to only from one;

some methods are synchronous and return a result while others are asynchronous that get requests queued up and return results for instance via a callback on a different thread.

答:
For multi-threaded applications using the same class, the trick could be to drag and drop the same class into each model representing a thread. You would be able to have the same class with different views and navigate in the model and code by clicking on the class, the diagram or the code.
I know that the model merge is not a well known concept but it works really well within Eclipse with Omondo.

I mean that when I model a large application which is composed by more than one project. I create a model for each project and then merge them inside a larger project. All modeling is done using class diagrams, which is the model I got when reversing the full project from java code to UML. I mean that in my example I use existing code and reverse it into a single UML model and then merge all this reverse code which has created UML models into a single large model. You can also create multiple models rather than reverse existing code. It works both ways—at creation without code or at reverse engineering stage with existing code.

I don't know if it makes sense but you could maybe create one large model, regrouping sub models for each thread like what I do with multi-projects modeling?
Hope this help.


答:
I would regard Haskell as 100% pure. And it can certainly get stuff done.

While there are some good debates about what "100% pure" actually means, it is certainly not true that a pure functional language cannot do IO. See also the comp.lang.functional FAQ.

All you have to do to allow IO in a pure language is pass a parameter that represents the state of the world to the program, and return the state of the world as an output. This program has no side effects, is referentially transparent and counts as 100% pure. This is pretty much what Haskell's IO Monad does under the hood.

A special mention perhaps for Clojure, which is definitely a practical language with the entire JVM ecosystem and toolchain to your fingertips. It is clearly not 100% pure (since you can get side effects via the STM managed references, various IO functions or Java interop). However the core language if you avoid these special cases is purely functional. So if you stick to the pure subset of Clojure, you actually have a pretty decent pure functional language for most purposes.