答:
Giving the Answer

I was going to say that if the candidate isn't interested enough to ask, I wouldn't waste my breath, but @Yannis_Rizos answer is much better.

Interviews are pretty fast paced.  I know I often look things up for days after an interview.

People Who Can't Code FizzBuzz Classic

I imagine a big sticking point is being aware of the % operator.  You would hope that someone could think to compare (myInt / 3) == (myDouble / 3.0) but maybe with the stress of an interview...  Still, FizzBuzz Classic forces a brute-force approach, putting it in the category of the easiest algorithm problems to solve.  As a hint, have you tried asking people to just code "Fizz" for half-credit and maybe add "Buzz" later as an enhancement?

I think the ultimate answer to your question is that it's just really hard to find good candidates.

Interview Questions in General

I've often found it easier and more productive to ask candidates to describe the last programming project that they were excited about.  I've had 100% success with this question, meaning that people who spoke animatedly about a programming project and could answer technical questions about it were great hires and those who couldn't, weren't.  This has the nice side effects of putting the candidate at ease, and encouraging open-ended discussion.  With this question, the candidate will, in effect, tell you what they are most suited for.

Maybe at a think tank algorithm questions are necessary as well, but I've abandoned them in favor of the "favorite project" question.

Sum (Son) of FizzBuzz

Your interview question is not equivalent to FizzBuzz:

If we list all the natural numbers below 10 that are multiples of 3 or
  5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Write a
  function that finds the sum of all the multiples of 3 or 5 below 1000.

Where FizzBuzz Classic forces you to go through n iterations (to print out every number or Fizz/Buzz), your problem can be done in n/5 + n/3 + n/15 iterations, or even no iterations - a direct fixed-point calculation is possible.  The following program compares these three methods:

```<code>public static void main(String[] args) {
  long n = Long.valueOf(args[0]).longValue();
  long sum = 0;
  long ms = System.currentTimeMillis();
  // Brute force method  Performance: cn
  for (long i = 1; i <= n; i++) {
    if ((i % 3) == 0) { sum += i;
    } else if ((i % 5) == 0) { sum += i; }
  }
  System.out.print("Brute force sum:    " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Second solution: iterate through only numbers we are
  // interested in.  Performance: c * (n/3 + n/5 + n/15)
  // We counted multiples of 15 twice, so subtract one of them
  sum = countSum(n, 3) + countSum(n, 5) - countSum(n, 15);
  System.out.print("Only multiples sum: " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Third solution: Use high school algebra.  Performance: c
  sum = sumSeries(n, 3) + sumSeries(n, 5) - sumSeries(n, 15);
  System.out.print("Sum of series:      " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
}

// Iteravely sum all multiples of skip
private static long countSum(long n, long skip) {
  long skipTotal = skip;
  long grandTotal = 0;
  while (skipTotal <= n) {
    grandTotal += skipTotal; skipTotal += skip;
  }
  return grandTotal;
}

// Thanks to @Caleb for pointing this out!  High school algebra
// tells us that the sum of a series is: (n * (a1 + an)) / 2
// where a1 is the first term and an is the nth term.  E.g. The
// sum of a series of 3 is: (n/3 * (3 + n - (n % 3))) / 2
// Since we are thinking about performance here, we'll shift
// right one instead of dividing by 2 for style points.  ;-D
private static long sumSeries(long n, long skip) {
  return (n/skip * (skip + n - (n % skip))) >> 1;
}
</code>```

Output (sum of FizzBuzz < 1000):

```<code>$JDK_HOME/bin/java FizzBuzzNot 999
Brute force sum:    233168 time: 0
Only multiples sum: 233168 time: 0
Sum of series:      233168 time: 0
</code>```

With a larger n for performance comparison:

```<code>$JDK_HOME/bin/java FizzBuzzNot 1000000000
Brute force sum:    233333334166666668 time: 4744
Only multiples sum: 233333334166666668 time: 818
Sum of series:      233333334166666668 time: 0
</code>```

Note to those who down-voted this as off-topic

The point of presenting a solution to this question is to show that while the brute force solution to Sum of FizzBuzz is similar to FizzBuzz Classic, better solutions to the Sum problem are available, making it a fundamentally different problem.  Sum of FizzBuzz is extremely tricky if you don't remember the proper formula for the sum of a series, or don't realize that it applies when stepping by 3 or 5.

If you re-derive the formula for the sum of a series by splitting the series in half, reversing one half, and pairing them up, you get (n + 1)(n / 2) which can take you down a really messy path as far as integer division and truncated remainders are concerned.  The (n(a1 + an)) / 2 version of this formula is absolutely critical for a simple answer for all values of n.

Body:
Giving the Answer

I was going to say that if the candidate isn't interested enough to ask, I wouldn't waste my breath, but @Yannis_Rizos answer is much better.

Interviews are pretty fast paced.  I know I often look things up for days after an interview.

People Who Can't Code FizzBuzz Classic

I imagine a big sticking point is being aware of the % operator.  You would hope that someone could think to compare (myInt / 3) == (myDouble / 3.0) but maybe with the stress of an interview...  Still, FizzBuzz Classic forces a brute-force approach, putting it in the category of the easiest algorithm problems to solve.  As a hint, have you tried asking people to just code "Fizz" for half-credit and maybe add "Buzz" later as an enhancement?

I think the ultimate answer to your question is that it's just really hard to find good candidates.

Interview Questions in General

I've often found it easier and more productive to ask candidates to describe the last programming project that they were excited about.  I've had 100% success with this question, meaning that people who spoke animatedly about a programming project and could answer technical questions about it were great hires and those who couldn't, weren't.  This has the nice side effects of putting the candidate at ease, and encouraging open-ended discussion.  With this question, the candidate will, in effect, tell you what they are most suited for.

Maybe at a think tank algorithm questions are necessary as well, but I've abandoned them in favor of the "favorite project" question.

Sum (Son) of FizzBuzz

Your interview question is not equivalent to FizzBuzz:

If we list all the natural numbers below 10 that are multiples of 3 or
  5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Write a
  function that finds the sum of all the multiples of 3 or 5 below 1000.

Where FizzBuzz Classic forces you to go through n iterations (to print out every number or Fizz/Buzz), your problem can be done in n/5 + n/3 + n/15 iterations, or even no iterations - a direct fixed-point calculation is possible.  The following program compares these three methods:

public static void main(String[] args) {
  long n = Long.valueOf(args[0]).longValue();
  long sum = 0;
  long ms = System.currentTimeMillis();
  // Brute force method  Performance: cn
  for (long i = 1; i <= n; i++) {
    if ((i % 3) == 0) { sum += i;
    } else if ((i % 5) == 0) { sum += i; }
  }
  System.out.print("Brute force sum:    " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Second solution: iterate through only numbers we are
  // interested in.  Performance: c * (n/3 + n/5 + n/15)
  // We counted multiples of 15 twice, so subtract one of them
  sum = countSum(n, 3) + countSum(n, 5) - countSum(n, 15);
  System.out.print("Only multiples sum: " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Third solution: Use high school algebra.  Performance: c
  sum = sumSeries(n, 3) + sumSeries(n, 5) - sumSeries(n, 15);
  System.out.print("Sum of series:      " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
}

// Iteravely sum all multiples of skip
private static long countSum(long n, long skip) {
  long skipTotal = skip;
  long grandTotal = 0;
  while (skipTotal <= n) {
    grandTotal += skipTotal; skipTotal += skip;
  }
  return grandTotal;
}

// Thanks to @Caleb for pointing this out!  High school algebra
// tells us that the sum of a series is: (n * (a1 + an)) / 2
// where a1 is the first term and an is the nth term.  E.g. The
// sum of a series of 3 is: (n/3 * (3 + n - (n % 3))) / 2
// Since we are thinking about performance here, we'll shift
// right one instead of dividing by 2 for style points.  ;-D
private static long sumSeries(long n, long skip) {
  return (n/skip * (skip + n - (n % skip))) >> 1;
}

Output (sum of FizzBuzz < 1000):

$JDK_HOME/bin/java FizzBuzzNot 999
Brute force sum:    233168 time: 0
Only multiples sum: 233168 time: 0
Sum of series:      233168 time: 0

With a larger n for performance comparison:

$JDK_HOME/bin/java FizzBuzzNot 1000000000
Brute force sum:    233333334166666668 time: 4744
Only multiples sum: 233333334166666668 time: 818
Sum of series:      233333334166666668 time: 0

Note to those who down-voted this as off-topic

The point of presenting a solution to this question is to show that while the brute force solution to Sum of FizzBuzz is similar to FizzBuzz Classic, better solutions to the Sum problem are available, making it a fundamentally different problem.  Sum of FizzBuzz is extremely tricky if you don't remember the proper formula for the sum of a series, or don't realize that it applies when stepping by 3 or 5.

If you re-derive the formula for the sum of a series by splitting the series in half, reversing one half, and pairing them up, you get (n + 1)(n / 2) which can take you down a really messy path as far as integer division and truncated remainders are concerned.  The (n(a1 + an)) / 2 version of this formula is absolutely critical for a simple answer for all values of n.


问:
Is there an antipattern to describe this method of coding?
I have a codebase where the programmer tended to wrap things up in areas that don't make sense.  For example, given an Error log we have you can log via

```<code>ErrorLog.Log(ex, "friendly message");
</code>```

He added various other means to accomplish the exact same task.  E.G.

```<code>SomeClass.Log(ex, "friendly message");
</code>```

Which simply turns around and calls the first method.  This adds levels of complexity with no added benefit.  Is there an anti-pattern to describe this?

答:
Not that this makes it acceptable but this could just be an unfinished refactoring.  Maybe the SomeClass.log() had it's own logic an was implemented first.  And later they realized that they should be using ErrorLog.Log().  So rather than change 100 places where SomeClass.Log() is called, they just delegated to the ErrorLog.Log().  Personally I would change all the references to ErrorLog.Log() or at least comment SomeClass.log() to say why it delegates the way it does.

Just something to consider.

ContentLicense: CC BY-SA 3.0


问:
Am I sending large amounts of data sensibly?
I am about to design a video conversion service, that is scalable on the conversion side.

The architecture is as follows:

Webpage for video upload

When done, a message gets sent out to one of several resizing servers

The server locates the video, saves it on disk, and converts it to several formats and resolutions

The resizing server uploads the output to a content server, and messages back that the conversion is done.

Messaging is something I have covered, but right now I am transferring via FTP, and wonder if there is a better way? is there something faster, or more reliable? All the servers will be sitting in the same gigabit switch or neighboring switch, so fast transfer is expected.

EDIT:

The question goes on the server <-> server side of things. The servers are co-located in same LAN, so the security of the interconnection there is not expected to be the main issue.

答:
I would use autonomous servers. Each server hosts the uploading frontend, the encoder and the download service. This way you don't have to transfer files around. To scale, simply add more servers- it sounds like you don't have any obstacles doing that.

Research if you can stream the process; start encoding the file while it is still uploading, download the result while it is still being encoded. This won't reduce the cost of any of the operations, but the end user will perceive a significant benefit.

Offer alternatives to HTTP upload if your files are large. If the upload stops for whatever reason, the user must restart the upload from scratch.

OwnerDisplayName: Sofus Albertsen


问:
What are the caveats of the event system built on Messenger rather than on classic .NET events?
MVVM Light and PRISM offer messenger to implement event system.

the approximate interface looks like the following one:

```<code>interface Messanger
{
    void Subscribe<TMessageParam>(Action<TMessageParam> action);
    void Unsubscribe<TMessageParam>(Action<TMessageParam> action);
    void Unsubscribe<TMessageParam>(objec actionOwner);
    void Notify<TMessageParam>(TMessageParam param);
}
</code>```

Now this model seems beneficial comparing to classic .net events. It works well with Dependency Injection. Actions are stored as weak references so memory leaks are avioded and unsubscribe is not a must.
The only annoyance is the need to declare new TMessageParam for each specific message.
But everything comes at a cost. And what I'm really worried about is that I see no shortcomings of this approach.

Has anoyne the experience of some troubles with this design pattern?

Update

We tried it and the most unpleasant thing with messages is their implicitness from the point of view of interface. Messages contrary to Events are not exposed explicitly in the interface so additional documentation must be provided.

As Laurent said below very loose coupling comes at a cost of vagueness.

答:
One of the native .NET event's attributes is that it's immutable, which makes their access locklessly thread-safe. I'm guessing the same can't be said of this implementation you're referring to, though it may handle the locks under the covers for you so at least you don't have to. Alternatively it may have it's own form of immutable access (is the interface implemented on a value type?) but doing something of that nature is quite tricky in C# which is why events have always had language level support.

Other than that, there may be performance differences between the two but I can't say for certain one way or the other, and further there is the fact of the syntax which is not available in your mentioned approach.


问:
Should I give the answer to a failed interview coding exercise?
We had a senior level interview candidate fail a nuance of the FizzBuzz question12.

I mean, really, utterly, completely, failed the question - not even close.

I even coached him through to thinking about using a loop and that 3 and 5 were really worth considering as special cases.

He blew it.

Just for QA purposes, I gave the same exact question to three teammates; gave them 5 minutes; and then came back to collect their pseudo-code.  All of them nailed it and hadn't seen the question before.  Two asked what the trick was...

On a different logic exercise, the candidate showed some understanding of some of the features available within the language he chose to use (C#).  So it's not as if he had never written a line of code.  But his logic still stunk.

My question is whether or not I should have given him the answer to the logic questions.

He knew he blew them, and acknowledged it later in the interview.

On the other hand, he never asked for the answer or what I was expecting to see.

I know coding exercises can be used to set candidates up for failure (again, see second link from above).  And I really tried to help him home in on answering the core of the question.  But this was a senior level candidate and Fizz-Buzz is, frankly, ridiculously easy even after accounting for interview jitters.

I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience.  But again, he didn't ask.

What's the right way to handle that situation?

1Okay, that's not the link to the actual FizzBuzz question, but it is a good P.SE discussion around FizzBuzz and links to the various aspects of it.

2 To help clarify, this is the nuance of Fizz-Buzz I asked and it's from Project Euler's first problem.  Substitute printing Fizz | Buzz for summing the numbers and you have the same fundamental question.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.  Write a function that finds the sum of all the multiples of 3 or 5 below 1000.

3 This question attracted more attention than I had expected, and I appreciate all of the replies.  Some of the later answers have really gotten to the core of my question, so I'll allow the community to review and up-vote before assigning "the" answer.

4 I selected "the" answer based upon community votes at that point in time.  And I think Yannis' answer is appropriate for interviews with newer devs.  I think the collective response focusing on the lack of asking for the answer is spot-on as well.

答:
Your "problem" is that you're an empathetic human, so it's hard to watch someone struggle with a problem that you know the answer to (this is also a problem if you run usability studies). From a duties-as-an-interviewer perspective, you are not in any way obliged to teach the interviewee how to program or problem-solve, or the solution to a problem that you ask.

When you coach an interviewee, it's not so that they can get the right answer. It's so that you can see if they really can't solve the problem or if they just got hung up on one or two mistakes or misunderstandings.

So if you want to give an interviewee the solution after the fact, you're doing it purely for yourself. In general, I'd rather use that time to allow the interviewee attempt another problem. But a "senior" programmer who can't answer FizzBuzz is probably off the list. If you decide to give solutions make sure you don't fool yourself into thinking the interview went better than it did (if you find yourself thinking, "he could not solve the problem, but when I explained it he understood it well", then you're on a dangerous path).

And yes, I have been an interviewee who was in over his head and couldn't even make the first attempt at solving an interview problem. That simply meant that I needed to learn a lot more in order to pursue a job in that field.


问:
Is there a real difference between dynamic analysis and testing?
Often testing is regarded as a dynamic analysis of a software. Yet while writing my thesis, the reviewer noted to me that dynamic analysis is about analyzing the program behind the scenes - e.g. profiling and that it is not the same as testing because its "analysis" which looks inside and observes.

I know that "static analysis" is not testing, should we then separate this "dynamic analysis" also from testing? Some books do refer to dynamic analysis in this sense. I would maybe say that testing is a one mean of dynamic analysis?

As for testing definitions:

IEEE 829 broadens the idea to “analyzing,” thus including “static
  testing.” And ISTQB takes the full step and includes both “dynamic and
  static.” Testing is both dynamic and static.

So maybe it is just a matter of semantics? If testing is considered to be an analysis, then its both static and dynamic analysis is a testing approach.

答:
Perhaps a good analogy is that (manual) testing is to dynamic analysis what code reviews are to static analysis. Both manual testing and dynamic analysis rely on the behaviour of code as it is executed to find problems.

But testing is not a means for dynamic analysis. For starters, dynamic analysis is automated. It also helps you observe behaviours that are not easily seen otherwise, such as memory usage and profiling. Testing, on the other hand, helps you assess qualities like usability and presentation, things you cannot ask a dynamic analysis tool to help you with.


问:
Creating my own PHP framework
Disclaimer: I don't want to start any flame war so there will not be no name of any framework mentioned.

I've been using quite many from the existing PHP frameworks and my experience in each case was similar: everything is nice a the beginning but in the moment you require something non standard you get into lot of problems to fix otherwise simple issues. In case of frameworks following the MVC design pattern there are some issues with the implementation of each layer for example there is a lot of codding used for model and data access with using ORM and presentation is not much more than pure phtml. Some frameworks use their own wrappers for existing PHP functionality and in some cases severely limiting original functionality. Depending on framework you can have additional problems like lack of documentation, slow or non existent development cycle and last but not least speed.

While ago I made my own framework which while doing it's job and being used for few different applications after couple of years more of experience with PHP doesn't seem to be perfect piece of codding. I could write my own framework and use additional experience I've gathered during these years to make it better on the other hand I'm aware that there is quite many better programmers working on creating/upgrading existing frameworks.

So does it make at all nay sense to write my own PHP framework if there is so many possibilities to choose from?

答:
I don't think it make sense to create your own framework completely from scratch with the wealth of libraries that exist out there.  I have actually created (or glued) my own framework together with using Silex as a base, added some functionality to be able to use yaml for configuration, be able to use class as the controllers easily, ability to create the standard REST APIs with like 6 lines of controller code, and then add in a completely custom DAL/Active Record system (because I don't like any of the existing ones out there).  I also use Monolog for logging.

I think writing certain components of your framework can be warranted but not the entire thing, make use for those good open source general purpose libraries (a lot of the Symfony2 components can be used by themselves and Silex is just a collections of the core ones).

Title: Creating my own PHP framework


问:
What are some good End-User Programming solutions you have seen?
End-User Programming is where regular end users, i.e. non-programmers, are able to customize a program, or create a new one, with minimal training or instruction.

App Inventor for Android is one recent example, but perhaps the most popular example of end-user programming is the spreadsheet.

What examples of end-user programming have you seen used, or believe to be useful? What's the philosophy of the system? What challenges remain?

答:
VBA
when used with Excel or Access

It deserves its own answer, and is probably the most widely used example of a end-user programming environment on the planet.

ContentLicense: CC BY-SA 2.5


问:
When counting function points, is my website menu an External Input?
I'm doing a function point count for a large website. Does the main website menu count as an External Input?

I'm doing a function point count as described in this article.

If so, since you only click on one menu item at a time, I assume the number of DETs == 1?

答:
Yes a menu is an external input from the user that gives control information.
I also agree that this is DETs == 1 since it gives you one low complexity data item: the destination of the navigation.</p>


问:
Does command/query separation apply to a method that creates an object and returns its ID?
Let's pretend we have a service that calls a business process. This process will call on the data layer to create an object of type A in the database.

Afterwards we need to call again on another class of the data layer to create an instance of type B in the database. We need to pass some information about A for a foreign key.

In the first method we create an object (modify state) and return it's ID (query) in a single method.

In the second method we have two methods, one (createA) for the save and the other (getId) for the query.

```<code>    public void FirstMethod(Info info)
    {
        var id = firstRepository.createA(info);
        secondRepository.createB(id);
    }

    public void SecondMethod(Info info)
    {
        firstRepository.createA(info);
        var key = firstRepository.getID(info);
        secondRepository.createB(key);
    }
</code>```

From my understanding the second method follows command query separation more fully. But I find it wasteful and counter-intuitive to query the database to get the object we have just created.

How do you reconcile CQS with such a scenario?

Does only the second method follow CQS and if so is it preferable to use it in this case?

答:
CQS is a guideline rather than an absolute rule.  See the wiki article for examples of activities that are impossible under strict CQS.

However, in this case, if you did want to maintain CQS, you could either create the ID on the client side (such as a GUID), or the client could request an ID from the system before creating any objects, which feels cleaner to me than creating the object then querying for it (but is harder than just using an identity column).

Personally I'd just return the ID and call it one of those situations where CQS isn't a good fit.

Another good article with examples: Martin Fowler


问:
Lazy Processing of Streams
I have the following problem scenario:

I have a text file and I have to read it and split it into lines.

Some lines might need to be dropped (according to criteria that are not fixed).

The lines that are not dropped must be parsed into some predefined records.

Records that are not valid must be dropped.

Duplicate records may exist and, in such a case, they are consecutive. If duplicate / multiple records exist, only one item should be kept.

The remaining records should be grouped according to the value contained in one field; all records belonging to the same group appear one after another (e.g. AAAABBBBCCDEEEFF and so on).

The records of each group should be numbered (1, 2, 3, 4, ...). For each group the numbering starts from 1.

The records must then be saved somewhere / consumed in the same order as they were produced.

I have to implement this in Java or C++.

My first idea was to define functions / methods like:

One method to get all the lines from the file.

One method to filter out the unwanted lines.

One method to parse the filtered lines into valid records.

One method to remove duplicate records.

One method to group records and number them.

The problem is that the data I am going to read can be too big and might not fit into main memory: so I cannot just construct all these lists and apply my functions one after the other.

On the other hand, I think I do not need to fit all the data in main memory at once because once a record has been consumed all its underlying data (basically the lines of text between the previous record and the current record, and the record itself) can be disposed of.

With the little knowledge I have of Haskell I have immediately thought about some kind of lazy evaluation, in which instead of applying functions to lists that have been completely computed, I have different streams of data that are built on top of each other and, at each moment, only the needed portion of each stream is materialized in main memory.

But I have to implement this in Java or C++. So my question is which design pattern or other technique can allow me to implement this lazy processing of streams in one of these languages.

答:
Even though this question has an accepted answer already, I have recently found another interesting solution, which I would like to share here.
I would be interested to learn about other techniques for implementing streams in Java.

The first ideas for my solution came from a course on Scala in which I was able to experiment with Scala's library streams (scala.collection.immutable.Stream). The course explained that a stream in Scala is very similar to a list (sequence of cons cells) in which the tail() function / method is computed lazily: the tail sequence is computed on demand when tail() is called for the first time, and cached for further accesses.

Of course, the tail is computed lazily as well, i.e. only the first cons cell of the tail is generated when tail() is called: subsequent elements of the tail stream are generated when tail() is called on this stream, and so on.

The second part of the solution came from this question and some of its answers: the only extension I needed was to implement cons cells with lazy tails.

Based on this solution, it was easy to define the usual functions (methods) take and drop, and the higher-order functions map, filter, dropWhile, takeWhile which also work lazily on streams. With these tools the original problem of manipulating streams of strings is much easier to solve.

My Solution

I first implemented lists as indicated in the programmers question and then implemented a similar data type Stream<T>.
A cons cell consists of an object of class Cons<T> containing

A value of type T (the head), and

A closure (function object) with one apply method returning the tail stream.

Here are the key definitions:

```<code>// An interface to store functions (closures) that are
// used to produce a stream's tail on demand.
public interface IStreamFunction<A>
{
  public Stream<A> apply();
}

// Wrapper object that invokes a stream function
// and then stores the result for future invocations of tail().
public class Memoizer<Stream<A>>
{
  private final IStreamFunction<A> _f;

  private Stream<A> _v;

  public Memoizer(IStreamFunction<A> f)
  {
    _f = f;

    _v = null;
  }

  public Stream<A> value()
  {
    if (_v == null)
    {
      _v = _f.apply();
    }

    return _v;
  }
}

// Stream class with two subclasses implementing the empty stream
// and a cons cell, respectively.
public abstract class Stream<A>
{
  // Private constructor cannot be called by any subclasses except inner classes.
  private Stream()
  {
  }

  public abstract A head();

  public abstract Stream<A> tail();

  public abstract boolean isEmpty();

  // Empty stream.
  public static final class Nil<A> extends Stream<A>
  {
    public Nil()
    {
    }

    public A head()
    {
      throw new NoSuchElementException("Nil.head");
    }

    public Stream<A> tail()
    {
      throw new NoSuchElementException("Nil.tail");
    }

    public boolean isEmpty()
    {
      return true;
    }
  }

  // Cons cell.
  public static final class Cons<A> extends Stream<A>
  {
    private final A _h;
    private final Memoizer<Stream<A>> _m;

    public Cons(A h, IStreamFunction<A> f)
    {
      _h = h;
      _m = new Memoizer<Stream<A>>(f);
    }

    public A head()
    {
      return _h;
    }

    public Stream<A> tail()
    {
      return _m.value();
    }

    public boolean isEmpty()
    {
      return false;
    }
  }
}
</code>```

Title: Lazy Processing of Streams

Body:
Even though this question has an accepted answer already, I have recently found another interesting solution, which I would like to share here.
I would be interested to learn about other techniques for implementing streams in Java.

The first ideas for my solution came from a course on Scala in which I was able to experiment with Scala's library streams (scala.collection.immutable.Stream). The course explained that a stream in Scala is very similar to a list (sequence of cons cells) in which the tail() function / method is computed lazily: the tail sequence is computed on demand when tail() is called for the first time, and cached for further accesses.

Of course, the tail is computed lazily as well, i.e. only the first cons cell of the tail is generated when tail() is called: subsequent elements of the tail stream are generated when tail() is called on this stream, and so on.

The second part of the solution came from this question and some of its answers: the only extension I needed was to implement cons cells with lazy tails.

Based on this solution, it was easy to define the usual functions (methods) take and drop, and the higher-order functions map, filter, dropWhile, takeWhile which also work lazily on streams. With these tools the original problem of manipulating streams of strings is much easier to solve.

My Solution

I first implemented lists as indicated in the programmers question and then implemented a similar data type Stream<T>.
A cons cell consists of an object of class Cons<T> containing

A value of type T (the head), and

A closure (function object) with one apply method returning the tail stream.

Here are the key definitions:

// An interface to store functions (closures) that are
// used to produce a stream's tail on demand.
public interface IStreamFunction<A>
{
  public Stream<A> apply();
}

// Wrapper object that invokes a stream function
// and then stores the result for future invocations of tail().
public class Memoizer<Stream<A>>
{
  private final IStreamFunction<A> _f;

  private Stream<A> _v;

  public Memoizer(IStreamFunction<A> f)
  {
    _f = f;

    _v = null;
  }

  public Stream<A> value()
  {
    if (_v == null)
    {
      _v = _f.apply();
    }

    return _v;
  }
}

// Stream class with two subclasses implementing the empty stream
// and a cons cell, respectively.
public abstract class Stream<A>
{
  // Private constructor cannot be called by any subclasses except inner classes.
  private Stream()
  {
  }

  public abstract A head();

  public abstract Stream<A> tail();

  public abstract boolean isEmpty();

  // Empty stream.
  public static final class Nil<A> extends Stream<A>
  {
    public Nil()
    {
    }

    public A head()
    {
      throw new NoSuchElementException("Nil.head");
    }

    public Stream<A> tail()
    {
      throw new NoSuchElementException("Nil.tail");
    }

    public boolean isEmpty()
    {
      return true;
    }
  }

  // Cons cell.
  public static final class Cons<A> extends Stream<A>
  {
    private final A _h;
    private final Memoizer<Stream<A>> _m;

    public Cons(A h, IStreamFunction<A> f)
    {
      _h = h;
      _m = new Memoizer<Stream<A>>(f);
    }

    public A head()
    {
      return _h;
    }

    public Stream<A> tail()
    {
      return _m.value();
    }

    public boolean isEmpty()
    {
      return false;
    }
  }
}


答: I could imagine it to be cultural difference. Maybe there is a good reason for having duplicate functionality in this particular code base. I could image ease of writing to be such a reason. The Python programmer in me would still say it is bad, since "There should be one-- and preferably only one --obvious way to do it.", but some Perl guys might be accustomed to the fact that "There's more than one way to do it".</p>

Title: Is there an antipattern to describe this method of coding?

Body:
I have a codebase where the programmer tended to wrap things up in areas that don't make sense.  For example, given an Error log we have you can log via

```<code>ErrorLog.Log(ex, "friendly message");
</code>```

He added various other means to accomplish the exact same task.  E.G.

```<code>SomeClass.Log(ex, "friendly message");
</code>```

Which simply turns around and calls the first method.  This adds levels of complexity with no added benefit.  Is there an anti-pattern to describe this?


问:
Build one to throw away vs Second-system effect
On one hand there is an advice that says "Build one to throw away". Only after finishing a software system and seeing the end product we realize what went wrong in the design phase and understand how we should have really done it.

On the other hand there is the "second-system effect" which says that the second system of the same kind that is designed is usually worse than the first one; there are many features that did not fit in the first project and were pushed into the second version usually leading to overly complex and overly engineered.

Isn't here some contradiction between these principles? What is the correct view over the problems and where is the border between these two?

I believe that these "good practices" are were firstly promoted in the seminal book The Mythical Man-Month by Fred Brooks.

I know that some of these issues are solved by Agile methodologies, but deep down, the problem is still the principles still stand; for example we would not make important design changes 3 sprints before going live.

答:
Build one to throw away comes from "not knowing what you don't know" at the start, so you learn as you go what you should have done at the start.

Second System Effect comes from "now knowing what you did not know, however not knowing what you still don't know" i.e. Second system effect comes from trying to build a bigger, shinier, more complex system than the first one, without the knowledge needed at the start - sounds  a lot like what happens with the first system.

Therefore second system effect is not contradiction. Building a second system to the same functionality as the first is (to my knowledge) never done. The second system always has to be "better", therefore more complex, therefore substantially similar problems to the first system are expected - that should be thrown away.

So build one to throw away, throw it way and build it again with no scope enlargement, and you won't have a second system problem. (This tends to be done more often on planets with purple skies, pink seas, and flying pigs.)


答:
I even coached him through to thinking about using a loop and that 3
  and 5 were really worth considering as special cases.

It'd be interesting to know what you think the "correct" answer to your FizzBuzz-ish question is. From where I sit, a good one (in C) written to the letter of your question is:

```<code>int f(void) {
    // sum the multiples of 3 and of 5 and subtract multiples of 15 so we don't count them twice
    return ((1000/3)/2)*(999+3) + ((1000/5)/2)*(995+5) - ((1000/15)/2)*(990+15);
}
</code>```

A better one might be:

Why the heck would you write a program to do that when you can calculate it directly?

The point is that there's more than one way to skin a cat, and the fact that the candidate in question didn't immediately start writing for loops and mod operators doesn't mean that he's stupid. If you want to know what the candidate knows, discuss the problem -- find out what he's thinking. If he's stuck or confused, find out where and why. He might lead you to an approach that you never considered.

My question is whether or not I should have given him the answer to the logic questions.

As the interviewer, it's not your place to teach the candidate a lesson. If they really don't know how to write code, there's absolutely no need to embarrass them by dwelling on how much they don't know. If they're interested enough to ask, then by all means feel free to share. Otherwise, finish up the interview, thank them for their time, and move on to the next candidate.

Title: Should I give the answer to a failed interview coding exercise?

Body:
We had a senior level interview candidate fail a nuance of the FizzBuzz question12.

I mean, really, utterly, completely, failed the question - not even close.

I even coached him through to thinking about using a loop and that 3 and 5 were really worth considering as special cases.

He blew it.

Just for QA purposes, I gave the same exact question to three teammates; gave them 5 minutes; and then came back to collect their pseudo-code.  All of them nailed it and hadn't seen the question before.  Two asked what the trick was...

On a different logic exercise, the candidate showed some understanding of some of the features available within the language he chose to use (C#).  So it's not as if he had never written a line of code.  But his logic still stunk.

My question is whether or not I should have given him the answer to the logic questions.

He knew he blew them, and acknowledged it later in the interview.

On the other hand, he never asked for the answer or what I was expecting to see.

I know coding exercises can be used to set candidates up for failure (again, see second link from above).  And I really tried to help him home in on answering the core of the question.  But this was a senior level candidate and Fizz-Buzz is, frankly, ridiculously easy even after accounting for interview jitters.

I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience.  But again, he didn't ask.

What's the right way to handle that situation?

1Okay, that's not the link to the actual FizzBuzz question, but it is a good P.SE discussion around FizzBuzz and links to the various aspects of it.

2 To help clarify, this is the nuance of Fizz-Buzz I asked and it's from Project Euler's first problem.  Substitute printing Fizz | Buzz for summing the numbers and you have the same fundamental question.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.  Write a function that finds the sum of all the multiples of 3 or 5 below 1000.

3 This question attracted more attention than I had expected, and I appreciate all of the replies.  Some of the later answers have really gotten to the core of my question, so I'll allow the community to review and up-vote before assigning "the" answer.

4 I selected "the" answer based upon community votes at that point in time.  And I think Yannis' answer is appropriate for interviews with newer devs.  I think the collective response focusing on the lack of asking for the answer is spot-on as well.

Body:
I even coached him through to thinking about using a loop and that 3
  and 5 were really worth considering as special cases.

It'd be interesting to know what you think the "correct" answer to your FizzBuzz-ish question is. From where I sit, a good one (in C) written to the letter of your question is:

int f(void) {
    // sum the multiples of 3 and of 5 and subtract multiples of 15 so we don't count them twice
    return ((1000/3)/2)*(999+3) + ((1000/5)/2)*(995+5) - ((1000/15)/2)*(990+15);
}

A better one might be:

Why the heck would you write a program to do that when you can calculate it directly?

The point is that there's more than one way to skin a cat, and the fact that the candidate in question didn't immediately start writing for loops and mod operators doesn't mean that he's stupid. If you want to know what the candidate knows, discuss the problem -- find out what he's thinking. If he's stuck or confused, find out where and why. He might lead you to an approach that you never considered.

My question is whether or not I should have given him the answer to the logic questions.

As the interviewer, it's not your place to teach the candidate a lesson. If they really don't know how to write code, there's absolutely no need to embarrass them by dwelling on how much they don't know. If they're interested enough to ask, then by all means feel free to share. Otherwise, finish up the interview, thank them for their time, and move on to the next candidate.


答:
Absolutely, roll your own if you want.  Don't listen to naysayers.  The reason that there are so many frameworks to choose from in the first place is because people ignored the tired 'dont reinvent the wheel' mantra and tried to make something they thought was better.

So, re-invent the wheel if you feel the urge.  You'll learn a lot.  And who knows, maybe a year from now your framework will be the one that everyone is supposed to be using instead of making their own.

Title: Creating my own PHP framework

Body:
Disclaimer: I don't want to start any flame war so there will not be no name of any framework mentioned.

I've been using quite many from the existing PHP frameworks and my experience in each case was similar: everything is nice a the beginning but in the moment you require something non standard you get into lot of problems to fix otherwise simple issues. In case of frameworks following the MVC design pattern there are some issues with the implementation of each layer for example there is a lot of codding used for model and data access with using ORM and presentation is not much more than pure phtml. Some frameworks use their own wrappers for existing PHP functionality and in some cases severely limiting original functionality. Depending on framework you can have additional problems like lack of documentation, slow or non existent development cycle and last but not least speed.

While ago I made my own framework which while doing it's job and being used for few different applications after couple of years more of experience with PHP doesn't seem to be perfect piece of codding. I could write my own framework and use additional experience I've gathered during these years to make it better on the other hand I'm aware that there is quite many better programmers working on creating/upgrading existing frameworks.

So does it make at all nay sense to write my own PHP framework if there is so many possibilities to choose from?


答:
It may be an abuse/misunderstanding of the Facade Pattern. I have seen similar things in a codebase I've worked with. The developers went through a phase when they were crazy about design patterns without understanding the overarching principles of OO design.

A misuse of the Facade pattern results in a blurring of the levels of abstraction across the layers of the application.


问:
Is it okay to use a language that isn't supported by your company for some tasks?
I work for a company that supports several languages: COBOL, VB6, C#, and Java. I use those languages for my primary work, but I often find myself coding some minor programs (e.g. scripts) in Python because I find it to be the best tool for that type of task.

For example: an analyst gives me a complex CSV file to populate some DB tables, so I use Python to parse it and create a DB script.

What's the problem?

The main problem I see is that a few parts of these quick and dirty scripts are slowly gaining importance and:

My company does not support Python

They're not version controlled (I back them up in another way)

My coworkers do not know Python

The analysts have even started to reference them in emails ("launch the script that exports..."), so they are needed more often than I initially thought.

I should add that these scripts are just utilities that are not part of the main project; they simply help to get trivial tasks done in less time. For my own small tasks they help a lot.

In short, if I were a lottery winner to be in a accident, my coworkers would need to keep the project alive without those scripts; they would spend more time fixing CSV errors by hand, for example.

Is this a common scenario? Am I doing something wrong? What should I do?

答:
I can't give you a full answer as to what you should do.  I can only give a single suggestion you can use to start with:

Check the scripts into a repository that all (required) developers can access.  But make very sure to make note of the fact that you've first written these scripts for your own purpose, i.e. to perform a task you'd been given.  Then add that you're only checking in these scripts to allow others the advantage to use them.

After that you'll just need to see how other people respond to that.

ContentLicense: CC BY-SA 4.0


问:
Is there such a concept as "pseudo implementation" in software development?
I'm looking for a label to  describe the practice of using human-based computation methods or other means of "faking" an algorithm for the sake of getting a product or demo off the ground quickly without spending the time to develop an technical/scalable/analytical solution? Eg: using Amazon Turk to count the number of empty tables in a restaurant.

I'm also looking to learn more about this subject, but not sure what to search for. Human-based computation is only one method, I'm interested in the general idea of pseudo-implementation. Any ideas, recommended reading?

答:
This is called Wizard of Oz prototyping.

Wizard of Oz prototyping is a popular approach in HCI to evaluate new human-computer interfaces. It is typically used if a system is expensive to build but can be easily faked by a human sitting in the other room. Thus the name.


答:
Getting the right answer is not the important part of this test.  What you're measuring is someone's approach to problem solving, how they engage with the question, anything creative or interesting they come up with along the way; that kind of stuff.  Even if they get the wrong answer they may still be viable by these criteria.

OK, not knowing the mod operator is inexcusable, and by the metrics I've given this candidate appears to still be a write-off, but I don't believe that just giving the right answer to this candidate is going to be of any benefit.

This comes down to your own personal opinion from here.  Do you want to give interview feedback with a view to helping the candidate do better in future interviews (and so that future interviewers don't have to suffer what you've just gone through)?  If so, couch your feedback in the terms I've just outlined above: tell them that it's not just about the right answer but how they work to arrive at the answer is a critical factor.


问:
Handling optional GPL dependencies
Assume I have a library A which is licensed under a two-clause Free BSD style license. Library A optionally depends on library B (the availability of the dependency is configured at build-time), which is licensed under the GPLv3.

If I distribute both bundled together, the license will need to be GPL. But am I still able to distribute library A under the FreeBSD license? How do I indicate that the license changes, when the use of library B is enabled?

Do I need to distribute two different versions or can I just have one that contains both licenses and states which applies under which conditions? Any example project I can have a look at to see it done?

答:
This portion of the GPLv2 seems to address your situation:

If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

Based on that, it would appear that the source of library A can be distributed under a BSD license, and anyone who enables a build of A+B is responsible for understanding that the resulting combined work is under the GPL.

You asked about the GPLv3 specifically.  I'm less familiar with it, and its wording is less clear:

To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work...

A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.

It sounds as though library A is separate and independent from library B, and I don't think that optionally depending on library B would count as copying from or adapting part of library B, and assuming the intent of GPLv3 is similar to GPLv2, it again appears that the source of library A can be distributed under a BSD license, and anyone who enables a build of A+B is responsible for understanding that the resulting combined work is under the GPL.

I am not a lawyer, this is not legal advice, etc.

Examples of existing libraries:

PoDoFo, a C++ PDF library, is licensed under the LGPL, but it depends on FreeType, which is dual licensed under the GPL and its own attribution-required BSDish license (both of which would offer additional restrictions beyond the LGPL).  PoDoFo's licensing page only mentions its own LPGL; it makes no reference to its dependent libraries'  requirements.

The Chromium Embedded Framework (CEF) has multiple dependencies, with license ranging from BSD to LGPL to "other," but its own code license is simply listed as "New BSD License."

Title: Handling optional GPL dependencies


答:
Accidental complexity is complexity that arises in computer programs or their development process which is non-essential to the problem to be solved. While essential complexity is inherent and unavoidable, accidental complexity is caused by the approach chosen to solve the problem.

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


答:
"Webpage for video upload" will actually upload the video to the web server.  That's just the way HTTPS and an HTML form with a file-upload works.  Make sure to set the right content-type on your form tag properly for a file.  You cannot send other parameters to the server with the same request as a file upload because of that same content-type parameter.  A big problem may be people with big files and/or slow internet that keep your HTTP connection open for 15 minutes or more.  Most people's ISPs have a maximum upload rate of 500Kbps (bits/sec, not bytes/sec) or something really low like that.  Long connections make you a target for DOS attacks.

If you want the file to end up somewhere other than your web server, you'll be writing code on the server side.  Your web application will have to pipe/stream it to that different location.

FTP is very slightly faster than HTTP, maybe 5-10% max, but I think my experience shows it's closer to 1%.  FTP might be better for transferring 2 or more files at the same time, I don't know.  I think all modern browsers support FTP natively as well as HTTP.  To use another protocol as someone suggested, you need server side code.  I'd use HTTP for your first pass.

Someone raised a good point about encryption.  You want that if anyone will send confidential or non-public video.  It will slow things down somewhat, but probably not that much.  HTTPS with a server side certificate will take care of that if you need it.

When transferring large files, you need to use a protocol that ensures that they are not used by the recipient until the copy is complete.  Maybe you touch another file, or send a "all-done transferring myFile2321.avi" message.  Compressing large files and decompressing them after the transfer is often faster than copying them over a network or the internet.  If you pay for bandwith it may be cheaper as well.

So, all in all, those are some details to think about and some suggestions.  I don't see anything wrong with your over-all plan.  Take a look at how YouTube does this, because I think they already do everything you are planning, just in a different context or for a different reason.

Title: Am I sending large amounts of data sensibly?

Body:
I am about to design a video conversion service, that is scalable on the conversion side.

The architecture is as follows:

Webpage for video upload

When done, a message gets sent out to one of several resizing servers

The server locates the video, saves it on disk, and converts it to several formats and resolutions

The resizing server uploads the output to a content server, and messages back that the conversion is done.

Messaging is something I have covered, but right now I am transferring via FTP, and wonder if there is a better way? is there something faster, or more reliable? All the servers will be sitting in the same gigabit switch or neighboring switch, so fast transfer is expected.

EDIT:

The question goes on the server <-> server side of things. The servers are co-located in same LAN, so the security of the interconnection there is not expected to be the main issue.


问:
What is a "task pool"?
I have searched for many websites for a definition of "task pool", but most descriptions are very vague. Anywhere I can find a precise definition of it?

More details.

Are dependencies allowed in task pool?

Can a running task exchange data with other running tasks?

To phrase conversely, are tasks permitted to accept data only prior to start and permitted to publish results only after the task has finished?

What keeps track of the temporary resources (memory, CPU etc) that are used by tasks?

How to define weights that will encourage efficient task assignment?

For example, if one task needs to pass a lot of data to the next task, it may make sense to run the next task immediately following the first task, and as close to the first thread / CPU / machine / cluster (locality) as possible

What about tasks that are not known (do not exist) in the beginning, but were "created" later?

答:
I'm pretty sure you won't find one authorative answer, because it's a term that could mean different things in different contexts.

In terms of C# 4.0 and the Task Parallel Library, a task pool is a collection of pending work items that need to be run.

To grossly simplify the situation(*), tasks are taken from the pool and run by various worker threads in parallel.

(*) In the actual implementation, Tasks aren't taken from the pool one by one as that introduces too much overhead. Instead, they're taken in batches - and not necessarily in the order they were added to the pool.

Title: What is a "task pool"?


答:
I'm not sure this is automatically evil.

If you're calling SomeClass.Log it most certainly is evil but if Log is only being used from WITHIN SomeClass it's cutting down the coupling and I would call it acceptable.


答:
What this programmer is doing is wrapping some code, so that it does not have a direct dependency on the logging module. Without more specific information, it's not possible to give a more specific pattern. (That these wrappers are not useful is your opinion which is impossible to agree or disagree with without much more information.)

Patterns that this may fall under are Proxy, Delegate, Decorator, Composite or some such which have to do with wrapping, hiding or distributing calls.  It may one of such things in an incomplete state of development.


问:
What are the advantages of myBatis over Hibernate?
I've done some research on my own and understand the basic concept. But some insights can only be gained through actual experience.

What are the advantages of myBatis that would make it worth learning a new framework?

In what case would you avoid using it?

答:
Hibernate is well know for too much magic, unexpected behaviour and big learning curve. There are other frameworks out there which are more focused on simplicity and will let you be in control.

myBatis is one of them, my project MentaBean is another one. I've written a blog post about it that might help.


答:
I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience. But again, he didn't ask. What's the right way to handle that situation?

The way I see it, there is no situation to handle.  Assuming that you have rejected his application, the candidate's (apparent) lack of interest is not something you need to concern yourself about.

Indeed, even if he did ask, you don't owe him an explanation.  And if you talked to your HR folks about it, they might advise you that further discussions with the candidate is inadvisable for legal reasons.

It is also worth noting that the FizzBuzz problem has different "best" answers depending on how you ask it.  If you ask for the "simplest" solution and the "most efficient" solution, the best answers are radically different.  And this can colour your judgement unfairly ... if you were unclear in the way that you asked the question.  (On the other hand, a good / experienced candidate would have the foresight to clarify that before starting to code ...)


答:
LabVIEW, the graphical programming language, used by many scientists and engineers (especially in biometrics).

Arguably, it showed the money path of the graphical programming for a much bigger software company.

Title: What are some good End-User Programming solutions you have seen?

Body:
End-User Programming is where regular end users, i.e. non-programmers, are able to customize a program, or create a new one, with minimal training or instruction.

App Inventor for Android is one recent example, but perhaps the most popular example of end-user programming is the spreadsheet.

What examples of end-user programming have you seen used, or believe to be useful? What's the philosophy of the system? What challenges remain?


问:
Is there an open source license that prohibits public hosting, so I can avoid competition?
I am thinking about open sourcing my project, but I want to prohibit public hosting, so noone will put up an alternative website with my code on it, and compete with my site.

Internal networks, like libraries etc. would be welcome to use it.

Are you aware of such a license? I guess this would be even more restrictive than AGPL.

答:
While such a license might exist, it would not be an Open Source license (as per the accepted definition, of which it fails to meet roughly half the conditions), let alone Free (Libre) Software.

You are publishing source code, but that alone doesn't make it Open Source - otherwise, the software I write for my day job (we deliver sources to most of our clients) would also qualify as Open Source.

In case you're not too attached to the Open Source label, just look in other directions. There are probably products around that use a similar licensing model; see if their licenses fit your needs.

And of course, as always: if you want actual legal advice, consult an actual lawyer. More so if this is not just a pet project but something you rely on for your income.


答:
What you are talking about, limiting redistribution, goes against the definitions of open source and free software. If you find such a license, it won’t be either of those.

So, I recommend you get a lawyer and you two come out with the terms of the license you are thinking about, with whatever other restriction you might want to add, and whatever freedom you might want to give to your users.

Some things to ask yourself:

Will users have the right to create derivated works — change the code?

Will users have the right to host their derivated works? (if those are allowed at all)

Will it be possible to fork your project?

What type of changes and what amount of them give the user freedom to freely redistribute your software, if any?

What do you expect to gain by opening the source? Do you expect new contributors? Or do I just want the users to be able to see the code?

What is free software? What is open source software?

Note: You say «I guess this would be even more restrictive than AGPL». The addicional restrictions in the AGPL are to ensure the freedom of the software. They do not limit the users in any way, just demand additional conditions to the developers. You might agree with those additional restrictions or not, but they certainly have nothing to do with the ones you want to impose.

Title: Is there an open source license that prohibits public hosting, so I can avoid competition?

Body:
I am thinking about open sourcing my project, but I want to prohibit public hosting, so noone will put up an alternative website with my code on it, and compete with my site.

Internal networks, like libraries etc. would be welcome to use it.

Are you aware of such a license? I guess this would be even more restrictive than AGPL.


问:
How to design software when using BDD?
I'm working on a project right now and it's my first project using BDD. Up till now, the user stories have proven themselves a very valuable weapon to understand requirements and to specify the solution in a comprehensive, easy to understand language.

My question is this: now that my user stories are complete, how do I design my solution? I understand that I derive behavior tests from my user stories, and I have to do UI design, but am I supposed to use good ol' UML? I'm under the impression that when using user stories, UML is left out; is this correct?

答:
In general userstories are requirements from the customer point of view that most of the time say what to implement (= features) but not how to do it (design, workflow).

If you want to create a new app out of nothing (greenfield-soulution) in a agile/scrum-like manner out of existing userstories i would suggest this workflow:

bring the userstories into an implementition order to find out which story to implement first. Start with stories that have as least dependencies to other stories as possible and that have most business-value. For details see StoryMaps-The new user story backlog is a map

implement the first userstory as nesteted bdd/tdd loops

Title: How to design software when using BDD?


问:
Verify uniqueness of new content
I'm working on a review site, where there is a minor issue with almost duplicate reviews across items. Just a few words are changed. It would be very nice to be able to uncover these duplicates before they are approved by a moderator, and I'm hoping someone could chime in on the best strategy to get there.

The site is running Ruby on Rails on a Postgres database and using Thinking Sphinx for search (all on Heroku), and so far the best option I see is to be pulling all the reviews out of the db and using a module like amatch to compare the strings. Not very efficient, so in this case I guess I'll have to limit the number/age of reviews to scan for dupes.

Anyone got a better idea?

答:
You could put together a SQL query using its own string matching functions: http://www.postgresql.org/docs/8.3/static/fuzzystrmatch.html

You'd need to join the table against itself (or take a cross product by doing SELECT ... FROM table AS t1, table AS t2 ...) and then filter based on the string conditions that you want.

But, at the end of the day, Postgres will need to do table-scans in order to produce the results, so do be careful if you have a large database. Either limit the scope, chunk up the query, or run it at an off-peak time.

Title: Verify uniqueness of new content


问:
Am I sending large amounts of data sensibly?
I am about to design a video conversion service, that is scalable on the conversion side.

The architecture is as follows:

Webpage for video upload

When done, a message gets sent out to one of several resizing servers

The server locates the video, saves it on disk, and converts it to several formats and resolutions

The resizing server uploads the output to a content server, and messages back that the conversion is done.

Messaging is something I have covered, but right now I am transferring via FTP, and wonder if there is a better way? is there something faster, or more reliable? All the servers will be sitting in the same gigabit switch or neighboring switch, so fast transfer is expected.

EDIT:

The question goes on the server <-> server side of things. The servers are co-located in same LAN, so the security of the interconnection there is not expected to be the main issue.

答:
Another option: Consider using a shared storage area, which all the servers can access.

For this, you would need to use a distributed file system. There are several to choose from (NFS, SMB, etc.) - which one is best would be another question :-).

Of course, if you use this route, take care to have some locking mechanism to avoid two servers working on the same file.


问:
Is there an alternative to Google Code Search?
Per the Official Google Blog:

Code Search, which was designed to help people search for open source
  code all over the web, will be shut down along with the Code Search
  API on January 15, 2012.

Google Code Search is now gone, and since that makes it much harder to understand the features it presented, here's my attempt to render them via information I gathered from a cache of the page for the Search Options:

The "In Search Box" just notes the syntax to type the command directly in the main search box instead of using the advance search interface.

Package (In Search Box: "package:linux-2.6")

Language (In Search Box: "lang:c++")

(OPTIONS: any language, actionscript, ada, applescript, asp, assembly, autoconf, automake, awk, basic, bat, c, c#, c++, caja,
cobol, coldfusion, configure, css, d, eiffel, erlang, fortran, go,
haskell, inform, java, java, javascript, jsp, lex, limbo, lisp,
lolcode, lua, m4, makefile, maple, mathematica, matlab,
messagecatalog, modula2, modula3, objectivec, ocaml, pascal, perl,
php, pod, prolog, proto, python, python, r, rebol, ruby, sas, scheme,
scilab, sgml, shell, smalltalk, sml, sql, svg, tcl, tex, texinfo,
troff, verilog, vhdl, vim, xslt, xul, yacc)

File (In Search Box: "file:^.*.java$")

Class (In Search Box: "class:HashMap")

Function (In Search Box: "function:toString")

License (In Search Box: "license:mozilla")

(OPTIONS: null/any-license, aladdin/Aladdin-Public-License, artistic/Artistic-License, apache/Apache-License,
apple/Apple-Public-Source-License, bsd/BSD-License,
cpl/Common-Public-License, epl/Eclipse-Public-License,
agpl/GNU-Affero-General-Public-License,
gpl/GNU-General-Public-License,
lgpl/GNU-Lesser-General-Public-License,
disclaimer/Historical-Permission-Notice-and-Disclaimer,
ibm/IBM-Public-License, lucent/Lucent-Public-License, mit/MIT-License,
mozilla/Mozilla-Public-License, nasa/NASA-Open-Source-Agreement,
python/Python-Software-Foundation-License, qpl/Q-Public-License,
sleepycat/Sleepycat-License, zope/Zope-Public-License)

Case Sensitive (In Search Box: "case:no")

(OPTIONS: yes, no)

Also of use in understanding the search tool would be the still live FAQs page for Google Code Search.

Is there any code search engine that would fully replace Google Code Search's features?

答:
6 November 2012 a regexp code search engine for all Debian packages was announced on the debian-devel mailing list:

http://codesearch.debian.net/

Search queries can be written in regular expression syntax defined by re2.

It is possible to search for a specific file type (C, C++, Perl, Python, Go, Java, Ruby, Shell) where the files have been filtered out by their extension.

Debian is very serious about Software licensing. If you find code in this search engine you can be confident that the software is fulfilling the requirements for being open source software.

It is also great to be able to search in the debian/rules files. They are normally not distributed in source packages outside of Debian. In these files you can see how the package was built for Debian, e.g. which options that were given to the CMake command (if CMake was the build system in the package).


问:
Should business services cross bounded contexts?
Firstly, I am following the convention that a bounded context is synonymous to a department, or possibly one department has 1 to many bounded contexts.

We have a client consultancy department that has a Documentation Service. Documents are stored in the Document Store Service (which is where all documents in the company are stored - it is a utility service), and the Documentation Service stores information about that document (a business service). As it was designed for the client consultancy, it is information relevant to them.

Now health and safety need somewhere to store information about a document. This is different information to client consultancy, but I have been instructed to extend the existing service to account for this extra information. I feel this service is now crossing a bounded context. My worry is that all departments will eventually store there information in here and the service will become bloated, trying to be all things to all departments. Each document record will only store a subset of the information because it will only belong to one department.

It will get worse when different departments want to store the same information but refer to it in a diferent ways, or when two departments want to store different information that they refer to in the same way. In my understanding, this is exactly the reason for bounded contexts.

I feel each department should have it's own business service for information about a document, but use the same utility service to actually store the document.

What would be the correct approach?

答:
There is no reason why your document information service can't be designed so that the pieces of information stored in it stay within their respective bounded contexts.  In fact I imagine this would be a natural consequence of how you might plan to design the system, if it isn't designed this way already.

If your system has logins or groups, and documents are kept in the login/group in which they are created, then this will achieve the above goal.

I am comparing your document information system to a company wiki.  A wiki can be used by an entire >1000 employ organisation and it might contain pages that are terribly important to one person but complete gibberish to another, and yet everything's okay because the respective business units generally have their own mostly discrete set of pages on the wiki that other business units ignore or aren't even aware of.

Yes you may have to extend your application to cover a wider and more general audience, but this is the goal/nightmare of any real application.  Think of any database system - its goal is to solve the data storage problems of everyone everywhere.  It's debatable how well they do it, but they can't be failing because everybody is using them.


问:
@staticmethod vs module-level function
This is not about @staticmethod and @classmethod!  I know how staticmethod works.  What I want to know is the proper use cases for @staticmethod vs. a module-level function.

I've googled this question, and it seems there's some general agreement that module-level functions are preferred over static methods because it's more pythonic.  Static methods have the advantage of being bound to its class, which may make sense if only that class uses it.  However, in Python functionality is usually organized by module not class, so usually making it a module function makes sense too.

Static methods can also be overridden by subclasses, which is an advantage or disadvantage depending on how you look at it.  Although, static methods are usually "functionally pure" so overriding it may not be smart, but it may be convenient sometimes (though this may be one of those "convenient, but NEVER DO IT" kind of things only experience can teach you).

Are there any general rule-of-thumbs for using either staticmethod or module-level functions?  What concrete advantages or disadvantages do they have (e.g. future extension, external extension, readability)?  If possible, also provide a case example.

答:
Technically a static method and a module function behave pretty much identically - In both cases they work like standard functions, the difference being the namespace where they are placed.  So the decision is more one of maintainability/readability.

Generally I would use a static method if some or all of these criteria are met:

There is already an existing class with normal methods

The function relates to objects of the class generally, but not one specific instance

You want to be able to call the method as if it's a non-static method, possibly because you may want to make the method non-static in the future without breaking client code

Title: @staticmethod vs module-level function


问:
Using mod_rewrite for a Virtual Filesystem vs. Real Filesystem
I started working in a department that uses a CMS in which the entire "filesystem" is like this:

create a named file or folder - this file is given a unique node (ex. 2345) as well as a default "filename" (ex. /WelcomeToOurProductsPage) and apply a template

assign one or more aliases to the file for a URL redirect (ex. /home-page-products - can also be accessed by /home-page-products.aspx)

A new Rewrite command is written on the .htaccess file for each and every alias

Server accesses either /WelcomeToOurProductsPage or /home-page-products and redirects to something like /template.aspx?tmp=2&node=2345 (here I'm guessing what it does - I only have front-end access for now - but I have enough clues to strongly assume)

Node 2345 grabs content stored in a SQL Db and applies it to the template.

Note: There are no actual files being created on the filesystem. It's entirely virtual. This is probably a very common thing, but since I have never run across this kind of system before two months ago, I wanted to explain it in case it isn't common. I'm not a fan at all of ASP or closed-sourced systems, so it may be that this is common practice for ASP developers.

My question, that has taken far too long to ask, is: what are the benefits of this kind of system, as opposed to creating an actual file hierarchy? Are there any drawbacks to having every single file server call redirected? To having the .htaccess file hold rewrite rules for every single alias?

答:
The rewrite-rule-per-alias thing must be awful to manage.  You could help somewhat by writing a script that took a spreadsheet or text file or whatever and turned it into a list of rewrite rules.

Filesystems are the bread and butter of an operating system, and so they have been optimized like hell and thus they are fast.  There are corner cases, usually related to storing massive numbers of files in single directories, but these can be mitigated too.  And you know about symbolic links right?

Could you write an ASP script that does all the rewriting?


问:
How to solve cyclic dependencies in a visitor pattern
When programming at work we now and then face a problem with visitors and module/project dependencies.

Say you have a class A in a module X. And there are subclasses B and C in module Y. That means that module Y is dependent on module X. If we want to implement a visitor pattern to the class hierarchy, thus introducing an interface with the handle Operations and an abstract accept method in A, we get a dependency from module Y to module X, which we cannot allow for architectural reasons.

What we do is, use a direct comparison of the types (i.e. instanceof, since we program in Java), which is not satisfying.

My question(s) would be: Do you encounter this kind of problem in your daily work (or do we make poor architectural choices) and if so, how is your approach to solve this?

Here is a minimal example in Java to illustrate my point. Package a has ClassA and the Visitor-Interface over the ClassA Hierarchy:

```<code>package pkg.a;
public abstract ClassA extends ClassA {
    public abstract void accept(ClassAVisitor visitor);
   /* other methods ... */
}

package pkg.a;
import pkg.b.ClassB;
import pkg.b.ClassC;
public interface ClassAVisitor {
    public abstract void handle(ClassB visitee);
    public abstract void handle(ClassC visitee);
}
</code>```

Package b has the concrete classes that extend from ClassA:

```<code>package pkg.b;
import pkg.a.ClassAVisitor;
public ClassB extends ClassA {
    public void accept(ClassAVisitor visitor) {
        visitor.handle(this);
    }
}

package pkg.b;
import pkg.a.ClassAVisitor;
public ClassC {
    public void accept(ClassAVisitor visitor) {
        visitor.handle(this);
    }
}
</code>```

Package a and b have a cyclic dependency.

答:
You can use something like:

```<code>public static class X {
    public void accept(Visitor v){
        if (v instanceof XVisitor){
            ((XVisitor)v).visitX(this);
        }
    }
}
public static interface Acceptor{
    public void accept(Visitor v);
}
public static interface Visitor{
}
public static interface XVisitor extends Visitor {
    public void visitX(X x);
}
</code>```

This way you get rid of cyclic dependency, but introduce using instanceof. But you don't have chain if ifs using instanceof and you have instanceof "uglyness" contained in few classes, but you can add both visitors and acceptors (or visitees?)

PS: in my example, you can get rid if Visitor interface, but for eas of thinking I put it there. And you could make accept and visit methods return something, but that's outside of scope of this idea.
PS2: This idea is not mine, but I don't remeber where I saw it.

Body:
You can use something like:

public static class X {
    public void accept(Visitor v){
        if (v instanceof XVisitor){
            ((XVisitor)v).visitX(this);
        }
    }
}
public static interface Acceptor{
    public void accept(Visitor v);
}
public static interface Visitor{
}
public static interface XVisitor extends Visitor {
    public void visitX(X x);
}

This way you get rid of cyclic dependency, but introduce using instanceof. But you don't have chain if ifs using instanceof and you have instanceof "uglyness" contained in few classes, but you can add both visitors and acceptors (or visitees?)

PS: in my example, you can get rid if Visitor interface, but for eas of thinking I put it there. And you could make accept and visit methods return something, but that's outside of scope of this idea.
PS2: This idea is not mine, but I don't remeber where I saw it.


问:
How to customize web-app (pages and UI) for different customers
We have an ASP.NET web-application which has become difficult to maintain, and I'm looking for ideas on how to redesign it. It's an employee administration system which can be highly customized for each of our customers. Let me explain how it works now:

On the default page we have a menu where a user can select a task, such as Create Employee or View Timesheet. I'll use Create Employee as an example.

When a user selects Create Employee from the menu, an ASPX page is loaded which contains a dynamically loaded usercontrol for the selected menuitem, e.g. for Create Employee this would be AddEmployee.ascx

If the user clicks Save on the control, it navigates to the default page.
Some menuitems involve multiple steps, so if the user clicks Next on a multi-step flow then it will navigate to the next page in the flow, and so on until it reaches the final step, where clicking Save navigates to the default page.

Some customers may require an extra step in the Create Employee flow (e.g. SecurityClearance.ascx) but others may not.

Different customers may use the same ASCX usercontrol, so in the AddEmployee.OnInit we can customize the fields for that customer, i.e. making certain fields hidden or readonly or mandatory.

The following things are customizable per customer:

Menu items

Steps in each flow (ascx control names)

Hidden fields in each ascx

Mandatory fields in each ascx

Rules relating to each ascx, which allows certain logic to be used in the code for that customer

The customizations are held in a huge XML file per customer, which could be 7500 lines long.

Is there any framework or rules-engine that we could use to customize our application in this way? How do other applications manage customizations per customer?

答:
If your regular data is held in a database I'm not entirely sure why you'd want to have all of that customer specific information in an xml file.  Move it into the database.

Next, there are many different kinds of rules engines out there.  Considering you're using asp.net you might want to look at Windows Workflow for at least some of this.  You might read the following: http://karlreinsch.com/2010/02/05/microsoft-rule-engines/

A long time ago I used a product called Haley Rules to drive a c# web app.  It controlled everything from the screens that were available right down to the fields that appeared and whether they were required or not.  It took awhile to get the team on board with how it worked, but once that happened bringing on a new client was extremely simple.  Haley was since gobbled up by Oracle, but was probably the absolute best one out there.

Others you might be interested in are NxBRE and even nCalc.  NxBRE is an actual rules engine which is a port of one built for java.  nCalc on the other hand isn't a rules engine per se.  However, if you can express your logic in simple boolean statements then it is extremely fast.  I'm currently using this to drive page flow in one of our applications.

Some commercial ones include: FlexRule, iLog

OwnerDisplayName: Chris Lively


答:
Your existing rule engine tool supports your web application, which means it meets your needs already. You can use other "Rule Engine" like MS work flow, but IMO it can also end with a hard to maitain situation.

Let's say there is registration portal. It collects general user infomation and save them into database. Simple. we build one protal for one client with several ASCXs and Rules.Then for another client,we add more rules and more controls to these ASCXs. Working in this way, sooner or later we will reach the final straw client. At that time the code base is hard to maitain and devs lost themselves in lots of rules. It is what happened to me.

So to me, it is not about which Rule engine to use.

Then How?

I have raised a question, and one of the answer makes sense to me( thought not a picked answer). In this answer, the guy mentioned what kind of company you are. In your question it is more like which department you are or do you want to seperate your dev teams.

If you are in a archetect teams, build a framework with a rule engine. Create a basic registraion portal as a sample portal.Make DAO,BO decoupled with UI (Seperate layers).

If you are in a customise teams, create customised user control (dont reuse these user control in basic version). What you will recreate is just UI, you can still use DAO,BO as they are not defined in user control, they are at other layers. In this way you get the freedom to define your client specified rules without worring about contaminating other clients rules or introducing new bugs to other client's registrations.

Just realise it is not like an answer to your question. Anyway it is my thoughts after limited xp of working on a engine rule based ,multi-clients web application.

Title: How to customize web-app (pages and UI) for different customers

Body:
We have an ASP.NET web-application which has become difficult to maintain, and I'm looking for ideas on how to redesign it. It's an employee administration system which can be highly customized for each of our customers. Let me explain how it works now:

On the default page we have a menu where a user can select a task, such as Create Employee or View Timesheet. I'll use Create Employee as an example.

When a user selects Create Employee from the menu, an ASPX page is loaded which contains a dynamically loaded usercontrol for the selected menuitem, e.g. for Create Employee this would be AddEmployee.ascx

If the user clicks Save on the control, it navigates to the default page.
Some menuitems involve multiple steps, so if the user clicks Next on a multi-step flow then it will navigate to the next page in the flow, and so on until it reaches the final step, where clicking Save navigates to the default page.

Some customers may require an extra step in the Create Employee flow (e.g. SecurityClearance.ascx) but others may not.

Different customers may use the same ASCX usercontrol, so in the AddEmployee.OnInit we can customize the fields for that customer, i.e. making certain fields hidden or readonly or mandatory.

The following things are customizable per customer:

Menu items

Steps in each flow (ascx control names)

Hidden fields in each ascx

Mandatory fields in each ascx

Rules relating to each ascx, which allows certain logic to be used in the code for that customer

The customizations are held in a huge XML file per customer, which could be 7500 lines long.

Is there any framework or rules-engine that we could use to customize our application in this way? How do other applications manage customizations per customer?

OwnerDisplayName: ValidfroM


问:
What are some good End-User Programming solutions you have seen?
End-User Programming is where regular end users, i.e. non-programmers, are able to customize a program, or create a new one, with minimal training or instruction.

App Inventor for Android is one recent example, but perhaps the most popular example of end-user programming is the spreadsheet.

What examples of end-user programming have you seen used, or believe to be useful? What's the philosophy of the system? What challenges remain?

答:
Interface Builder

Actually we had a designer working on the design of an iphone app and he could easily work on Interface Builder with very short learning curve!


问:
In MVC , DAO should be called from Controller or Model
I have seen various arguments against the DAO being called from the Controller class directly and also the DAO from the Model class.Infact I personally feel that if we are following the MVC pattern , the controller should not coupled with the DAO , but the Model class should invoke the DAO from within and controller should invoke the model class.Why because , we can decouple the model class apart from a webapplication and expose the functionalities for various ways like for a REST service to use our model class.

If we write the DAO invocation in the controller , it would not be possible for a REST service to reuse the functionality right ? I have summarized both the approaches below.

Approach #1

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            new CustomerDAO().save(customer);

    }

 }
</code>```

Approach #2

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            customer.save(customer);

    }

 }

 public class Customer {

   ...........

   private void save(Customer customer){

        new CustomerDAO().save(customer);

   }

}
</code>```

Note-

Here is what a definition of Model is :

Model:
The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

I would need an expert opinion on this because I find many using #1 or #2 , So which one is it ?

答:
From model layer.

To be more precise: from services, which are contained in model layer, because they govern the interaction between domain objects and storage logic abstractions.

Controller should be only responsible for changing the state of model layer. DAOs are part of persistence mechanism. This constitutes a part of domain business and application logic. If you start interacting with DAOs in controller, you would be leaking the domain logic in the presentation layer.

OwnerDisplayName: teresko


答:
In my opinion, you have to distinguish between the MVC pattern and the 3-tier architecture. To sum up:

3-tier architecture:

data: persisted data;

service: logical part of the application;

presentation: hmi, webservice...

The MVC pattern takes place in the presentation tier of the above architecture (for a webapp):

data: ...;

service: ...;

presentation:

controller: intercepts the HTTP request and returns the HTTP response;

model: stores data to be displayed/treated;

view: organises output/display.

Life cycle of a typical HTTP request:

The user sends the HTTP request;

The controller intercepts it;

The controller calls the appropriate service;

The service calls the appropriate dao, which returns some persisted data (for example);

The service treats the data, and returns data to the controller;

The controller stores the data in the appropriate model and calls the appropriate view;

The view get instantiated with the model's data, and get returned as the HTTP response.

Title: In MVC , DAO should be called from Controller or Model

Body:
I have seen various arguments against the DAO being called from the Controller class directly and also the DAO from the Model class.Infact I personally feel that if we are following the MVC pattern , the controller should not coupled with the DAO , but the Model class should invoke the DAO from within and controller should invoke the model class.Why because , we can decouple the model class apart from a webapplication and expose the functionalities for various ways like for a REST service to use our model class.

If we write the DAO invocation in the controller , it would not be possible for a REST service to reuse the functionality right ? I have summarized both the approaches below.

Approach #1

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            new CustomerDAO().save(customer);

    }

 }
</code>```

Approach #2

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            customer.save(customer);

    }

 }

 public class Customer {

   ...........

   private void save(Customer customer){

        new CustomerDAO().save(customer);

   }

}
</code>```

Note-

Here is what a definition of Model is :

Model:
The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

I would need an expert opinion on this because I find many using #1 or #2 , So which one is it ?


答:
When the individual customer needs are so wildly different that shared functionality represents less than 50% of the features for a given customers needs, then there are really only two major ways to handle this:

Writing a custom page for each individual client

This tends to sometimes be an unsavory option for both technical folk as well as business and sales folk.  It can also be unsavory if the client realizes that you are performing a lot of custom development to meet their needs.

Technical considerations

As a developer, high maintainability is one of the central goals that we should strive to accomplish, so writing custom pages for individual customers is counter to this goal.  Assume that a common feature must be added that should affect all customers, now this change must be manually implemented for all clients and tested for each client that has a seperate implementation for that page.  If you have a number of clients then this can simply be untenable over time.

Business considerations

From the business perspective as an ISV, we like to build a product, which is typically more involved than just the software itself.  Selling a software product implies that as a vendor, we have a single package that can fulfill all of the customers needs with minimal to no customization to the core of the product itself.

When product customizations need to occur to accomodate a client, then the product may be a poor fit, or may have just been poorly planned.  It may be that the solution that is being sold cannot actually be considered a product at all, but is simply being marketed that way.  The software business can be tricky like this and is why product owners and sales people make the big bucks because this winning formula for success in selling software can be extraordinarily tricky.  If you don't market it right, or form a product idea correctly then you may not sell or you may sell and be unable to deliver on promises.

Client considerations

All clients like to feel that they are getting a good deal, and when they buy a software product they want to believe that all of their needs are being met out of box.  This is why software products sell more readily and easily than just custom software development, even when the client needs are so inherently specific that no such product could ever exist off the shelf.

If the client finds that you are performing a good deal of custom software development for their needs alone then they lose faith that your product ever had the ability to deliver and that they will end up paying dearly for it in the long run to cover those custom development costs.

When is this a good idea

If the software is in a niche market with a small amount of customers and limited opportunity for growth, then custom web page development for specific features is probably the best choice.

XML based layout and rules engine

Basically you would identify core functionality to be built into pages, and anything customer specific should be defined through a custom layout and rules engine that allows client needs to be customized outside of the code base.
The technical design considerations for this are that

Technical considerations

The client needs at this point become a schema change through XML rather than en expensive maintainability nightmare of a code change.  Controlling layouts through XML to define your view, XML to tie in your model, and rules to define your controller will allow for a solid architecture that will scale as your business grows and also maintain loose coupling, high cohesion, and high maintainability.  These XML documents can be easily maintained through a NoSQL or even traditional RDBMS systems.

Business considerations

Limiting targeted releases to accomodate customers bolsters the strength and scalability of the product as a whole, and leaves the business confident that they have the ability to grow rapidly in a wild and volatile market.  Some disadvantages are the increased complexity of the application and product itself, and the considerations towards increased initial development time and the higher costs associated with this.

Client considerations

Clients can feel confident that their needs are being met through the product without significant cutomization and that their requests and changes can be rapidly accomodated.