问:
Is this overkill? Using MDX queries and cubes instead of SQL stored procedures
I am new to Microsoft's SQL Server Analysis Services Cubes and MDX queries.  Where I work we have a daily sales table in SQL Server 2005 that already contains an aggregate of sale information per store per day. At this time it contains only 164,000+ rows. We have a sales cube dedicated to this table that about 15 reports are based off of. Now, I should also note that we generate reports based on our own fiscal year criteria: a 13 period year (1 month equals 28 days etc.).

Is this overkill? At what point is it justified to begin using SSAS Cubes/MDX over plain old SQL Server stored procedures? Since I have always been just using plain old SQL am I tragically late to the MDX party?

答:
You're really asking the wrong questions. The big ones are “Does it work currently?” and “Does it produce results rapidly enough?” If they're both true, it's going to be a terribly hard sell to change to anything else, even if it happens to be more efficient to do it some other way. That's because any change has risk; in particular, the risk of someone doing something stupid and breaking things by accident. To change anything, you have to show that the benefit of changing outweighs the inevitable risk (bearing in mind that most people are not very good at understanding risk in the first place, and that not all risk is monetary).

As for why this sort of solution was used in the first place, it might be that this was simply technology that the developers knew they could make work in a reasonable amount of time, or it might actually be advantageous in some way that you don't know about yet. Your first step needs to be to find out what the history of the system is.


问:
A programmer should concentrate on at least how many languages?
For me I am C# and Java person. I find these 2 languages are quite similar so its easier for me to crossover each other. I'm not sure if its good idea to pick up other different languages. Any thoughts?</p>

答:
concentrate on none. focus on learning and writing clean code; clear, expressive, simple and, most important, not duplicated.

go for the principles of that type of programming, the basics (for example, encapsulation for OOP; what is means and what it implies) and learn some principles

this stuff will make your job easier. this will even make it easier for the people that work with your or after you.

ya, you have to know the syntax pretty well, too. but that not something what takes your focus a long time

and ya, you must understand pretty well the technologies you use, too. but those can be prioritized according to the level of complexity your business requires.

the last two are not of a main focus, but of some focus

ContentLicense: CC BY-SA 2.5


问:
Is 100% code coverage a pipe dream?
Is it feasible to expect 100% code coverage in heavy jquery/backbonejs web applications?  Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around 92%-95% in javascript/jquery? </p>

答:
Who tests the tests?

It is very naive at best and unrealistic even in the theoretical sense and impractical in a business sense.

It is unrealistic with code that has high cyclomatic complexity. There are too many variables to cover every combination.

It is unrealistic with code that is heavily concurrent. The code is not deterministic so you can't cover every condition that might happen because behavior will change on every test run.

It is unrealistic in a business sense, it only really pays dividends to write tests for code that is critical path code, that is code that is important and code that may change frequently.

Testing every line of code isn't a good goal

It is very expensive to write tests, it is code that has to be written and tested it self, it is code that has to be documented in what it actually trying to test, it is code that has to be maintained with business logic changes and the tests fail because they are out of date. Maintaining automated tests and the documentation about them can be more expensive than maintaining the code sometimes.

This is not to say that unit test and integration tests aren't useful, but only where they make sense, and outside of industries that can kill people it doesn't make sense to try and test every line of code in a code base. Outside these critical kill lots of people quickly code bases, it is impossible to calculate a positive return on investment that 100% code coverage would entail.

Halting problem:

In computability theory, the halting problem is the problem of
determining, from a description of an arbitrary computer program and
an input, whether the program will finish running or continue to run
forever.

Alan Turing proved in 1936 that a general algorithm to solve the
halting problem for all possible program-input pairs cannot exist. A
key part of the proof was a mathematical definition of a computer and
program, which became known as a Turing machine; the halting problem
is undecidable over Turing machines. It is one of the first examples
of a decision problem.

Since you can not even prove something works 100% why make that your goal?

Plain and simple, in most cases it doesn't make any business sense.

ContentLicense: CC BY-SA 3.0

Title: Is 100% code coverage a pipe dream?


问:
Validation and authorization in layered architecture
I know you are thinking (or maybe yelling), "not another question asking where validation belongs in a layered architecture?!?"  Well, yes, but hopefully this will be a little bit of a different take on the subject.

I am a firm believer that validation takes many forms, is context-based and varies at each level of the architecture.  That is the basis for the post - helping to identify what type of validation should be performed in each layer.  In addition, a question that often comes up is where authorization checks belong.

The example scenario comes from an application for a catering business. Periodically during the day, a driver may turn in to the office any excess cash they've accumulated while taking the truck from site to site.  The application allows a user to record the 'cash drop' by collecting the driver's ID, and the amount.  Here's some skeleton code to illustrate the layers involved:

```<code>public class CashDropApi  // This is in the Service Facade Layer
{
    [WebInvoke(Method = "POST")]
    public void AddCashDrop(NewCashDropContract contract)
    {
        // 1
        Service.AddCashDrop(contract.Amount, contract.DriverId);
    }
}

public class CashDropService  // This is the Application Service in the Domain Layer
{
    public void AddCashDrop(Decimal amount, Int32 driverId)
    {
        // 2
        CommandBus.Send(new AddCashDropCommand(amount, driverId));
    }
}

internal class AddCashDropCommand  // This is a command object in Domain Layer
{
    public AddCashDropCommand(Decimal amount, Int32 driverId)
    {
        // 3
        Amount = amount;
        DriverId = driverId;
    }

    public Decimal Amount { get; private set; }
    public Int32 DriverId { get; private set; }
}

internal class AddCashDropCommandHandler : IHandle<AddCashDropCommand>
{
    internal ICashDropFactory Factory { get; set; }       // Set by IoC container
    internal ICashDropRepository CashDrops { get; set; }  // Set by IoC container
    internal IEmployeeRepository Employees { get; set; }  // Set by IoC container

    public void Handle(AddCashDropCommand command)
    {
        // 4
        var driver = Employees.GetById(command.DriverId);
        // 5
        var authorizedBy = CurrentUser as Employee;
        // 6
        var cashDrop = Factory.CreateCashDrop(command.Amount, driver, authorizedBy);
        // 7
        CashDrops.Add(cashDrop);
    }
}

public class CashDropFactory
{
    public CashDrop CreateCashDrop(Decimal amount, Employee driver, Employee authorizedBy)
    {
        // 8
        return new CashDrop(amount, driver, authorizedBy, DateTime.Now);
    }
}

public class CashDrop  // The domain object (entity)
{
    public CashDrop(Decimal amount, Employee driver, Employee authorizedBy, DateTime at)
    {
        // 9
        ...
    }
}

public class CashDropRepository // The implementation is in the Data Access Layer
{
    public void Add(CashDrop item)
    {
        // 10
        ...
    }
}
</code>```

I've indicated 10 locations where I've seen validation checks placed in code.  My question is what checks you would, if any, be performing at each given the following business rules (along with standard checks for length, range, format, type, etc):

The amount of the cash drop must be greater than zero.

The cash drop must have a valid Driver.

The current user must be authorized to add cash drops (current user is not the driver).

Please share your thoughts, how you have or would approach this scenario and the reasons for your choices.

答:
Your first business rule

The amount of the cash drop must be greater than zero.

looks like an invariant of your CashDrop entity and of your AddCashDropCommand class. There are a couple of ways that I enforce an invariant like this:

Take the Design By Contract route and use Code
Contracts
with a combination of Preconditions, Postconditions and a
[ContractInvariantMethod] depending on your case.

Write explicit code in the constructor / setters that throws an
ArgumentException if you pass in an amount that is less than 0.

Your second rule is broader in nature (in light of the details in the question): does valid mean that the Driver entity has a flag indicating that they can drive (i.e. not had their driving license suspended), does it mean that the driver was actually working that day or does it mean simply that the driverId, passed in to the CashDropApi, is valid in the persistence store.

In any of these cases you will need to navigate your domain model and get the Driver instance from your IEmployeeRepository, as you do in location 4 in your code example. So, here you need to make sure that the call to the repository does not return null, in which case your driverId was not valid and you can not proceed with the processing any further.

For the other 2 (my hypothetical) checks (does the driver have a valid driving license, was the driver working today) you are executing business rules.

What I tend to do here is use a collection of validator classes that operate on entities (just like the specification pattern from Eric Evans book - Domain Driven Design). I have used FluentValidation to build these rules and validators. I can then compose (and therefore reuse) more complex / more complete rules from simpler rules. And I can decide which layers in my architecture to run them. But I have them all encoded in one place, not scattered across the system.

Your third rule relates to a cross-cutting concern: authorization. Since you are already using an IoC container (assuming that your IoC container supports method interception) you can do some AOP. Write an apsect that does the authorization and you can use your IoC container to inject this authorization behavior where it needs to be. The big win here is that you have written the logic once, but you can reuse it across your system.

To use interception via a dynamic proxy (Castle Windsor, Spring.NET, Ninject 3.0, etc) your target class needs to implement an interface or inherit from a base class. You would intercept before the call to the target method, check the authorization of the user and prevent the call from proceeding to the actual method (throw an excption, log, return a value indicating failure, or something else) if the user does not have the right roles to perform the operation.

In your case you could intercept the call to either

```<code>CashDropService.AddCashDrop(...)

AddCashDropCommandHandler.Handle(...)
</code>```

Problems here maybe that CashDropService can not be intercepted because there is no interface / base class. Or AddCashDropCommandHandler is not being created by your IoC, therefore your IoC can not create a dynamic proxy to intercept the call. Spring.NET has a useful feature where you can target a method on a class in an assembly via a regex, so this may work.

Hope this gives you some ideas.

Body:
Your first business rule

The amount of the cash drop must be greater than zero.

looks like an invariant of your CashDrop entity and of your AddCashDropCommand class. There are a couple of ways that I enforce an invariant like this:

Take the Design By Contract route and use Code
Contracts
with a combination of Preconditions, Postconditions and a
[ContractInvariantMethod] depending on your case.

Write explicit code in the constructor / setters that throws an
ArgumentException if you pass in an amount that is less than 0.

Your second rule is broader in nature (in light of the details in the question): does valid mean that the Driver entity has a flag indicating that they can drive (i.e. not had their driving license suspended), does it mean that the driver was actually working that day or does it mean simply that the driverId, passed in to the CashDropApi, is valid in the persistence store.

In any of these cases you will need to navigate your domain model and get the Driver instance from your IEmployeeRepository, as you do in location 4 in your code example. So, here you need to make sure that the call to the repository does not return null, in which case your driverId was not valid and you can not proceed with the processing any further.

For the other 2 (my hypothetical) checks (does the driver have a valid driving license, was the driver working today) you are executing business rules.

What I tend to do here is use a collection of validator classes that operate on entities (just like the specification pattern from Eric Evans book - Domain Driven Design). I have used FluentValidation to build these rules and validators. I can then compose (and therefore reuse) more complex / more complete rules from simpler rules. And I can decide which layers in my architecture to run them. But I have them all encoded in one place, not scattered across the system.

Your third rule relates to a cross-cutting concern: authorization. Since you are already using an IoC container (assuming that your IoC container supports method interception) you can do some AOP. Write an apsect that does the authorization and you can use your IoC container to inject this authorization behavior where it needs to be. The big win here is that you have written the logic once, but you can reuse it across your system.

To use interception via a dynamic proxy (Castle Windsor, Spring.NET, Ninject 3.0, etc) your target class needs to implement an interface or inherit from a base class. You would intercept before the call to the target method, check the authorization of the user and prevent the call from proceeding to the actual method (throw an excption, log, return a value indicating failure, or something else) if the user does not have the right roles to perform the operation.

In your case you could intercept the call to either

CashDropService.AddCashDrop(...)

AddCashDropCommandHandler.Handle(...)

Problems here maybe that CashDropService can not be intercepted because there is no interface / base class. Or AddCashDropCommandHandler is not being created by your IoC, therefore your IoC can not create a dynamic proxy to intercept the call. Spring.NET has a useful feature where you can target a method on a class in an assembly via a regex, so this may work.

Hope this gives you some ideas.


问:
Setters or constructor for many variables?

Possible Duplicate:

  Are there guidelines on how many parameters a function should accept?

I have got class with 30 variables (it is an application form), so I wonder what is the best practice to organize class creation.

Should I use huge constructor:

```<code>MyClass mc = new MyClass(a, b, c, d)
</code>```

Or setters:

```<code>MyClass mc = new MyClass();
mc.setA(a);
mc.setB(b);
mc.setC(c);
mc.setD(d);
</code>```

What is the best practice in OOP for such a situation? I saw a similar question, but I don't need immutability.

答: Assuming you're not in a language that makes it convenient to write named parameters (e.g., Python or Common Lisp), you should consider whether your objects are considered to be read-only or read-write. If the former, you must set values from the constructor, but otherwise it's really up to you as long as you have setters (or your language's equivalent). Given that you're dealing with 30 variables though, I'd really consider using something which would let you avoid having to write out constructors with that many arguments. Even 10 would be rather too many for sanity…

ContentLicense: CC BY-SA 4.0


问:
Avoiding new operator in JavaScript -- the better way
Warning: This is a long post.

Let's keep it simple. I want to avoid having to prefix the new operator every time I call a constructor in JavaScript. This is because I tend to forget it, and my code screws up badly.

The simple way around this is this...

```<code>function Make(x) {
  if ( !(this instanceof arguments.callee) )
  return new arguments.callee(x);

  // do your stuff...
}
</code>```

But, I need this to accept variable no. of arguments, like this...

```<code>m1 = Make();
m2 = Make(1,2,3);
m3 = Make('apple', 'banana');
</code>```

The first immediate solution seems to be the 'apply' method like this...

```<code>function Make() {
  if ( !(this instanceof arguments.callee) )
    return new arguments.callee.apply(null, arguments);

  // do your stuff
}
</code>```

This is WRONG however -- the new object is passed to the apply method and NOT to our constructor arguments.callee.

Now, I've come up with three solutions. My simple question is: which one seems best. Or, if you have a better method, tell it.

First – use eval() to dynamically create JavaScript code that calls the constructor.

```<code>function Make(/* ... */) {
  if ( !(this instanceof arguments.callee) ) {
    // collect all the arguments
    var arr = [];
    for ( var i = 0; arguments[i]; i++ )
      arr.push( 'arguments[' + i + ']' );

    // create code
    var code = 'new arguments.callee(' + arr.join(',') + ');';

    // call it
    return eval( code );
  }

  // do your stuff with variable arguments...
}
</code>```

Second – Every object has __proto__ property which is a 'secret' link to its prototype object. Fortunately this property is writable.

```<code>function Make(/* ... */) {
  var obj = {};

  // do your stuff on 'obj' just like you'd do on 'this'
  // use the variable arguments here

  // now do the __proto__ magic
  // by 'mutating' obj to make it a different object

  obj.__proto__ = arguments.callee.prototype;

  // must return obj
  return obj;
}
</code>```

Third – This is something similar to second solution.

```<code>function Make(/* ... */) {
  // we'll set '_construct' outside
  var obj = new arguments.callee._construct();

  // now do your stuff on 'obj' just like you'd do on 'this'
  // use the variable arguments here

  // you have to return obj
  return obj;
}

// now first set the _construct property to an empty function
Make._construct = function() {};

// and then mutate the prototype of _construct
Make._construct.prototype = Make.prototype;
</code>```

eval solution seems clumsy and comes with all the problems of "evil eval".

__proto__ solution is non-standard and the "Great Browser of mIsERY" doesn't honor it.

The third solution seems overly complicated.

But with all the above three solutions, we can do something like this, that we can't otherwise...

```<code>m1 = Make();
m2 = Make(1,2,3);
m3 = Make('apple', 'banana');

m1 instanceof Make; // true
m2 instanceof Make; // true
m3 instanceof Make; // true

Make.prototype.fire = function() {
  // ...
};

m1.fire();
m2.fire();
m3.fire();
</code>```

So effectively the above solutions give us "true" constructors that accept variable no. of arguments and don't require new. What's your take on this.

-- UPDATE --

Some have said "just throw an error". My response is: we are doing a heavy app with 10+ constructors and I think it'd be far more wieldy if every constructor could "smartly" handle that mistake without throwing error messages on the console.

答:
I actually wrote a post about this. http://js-bits.blogspot.com/2010/08/constructors-without-using-new.html

```<code>function Ctor() {
    if (!(this instanceof Ctor) {
        return new Ctor();
    }
    // regular construction code
}
</code>```

And you can even generalize it so you don't have to add that to the top of every constructor. You can see that by visiting my post

Disclaimer I don't use this in my code, I only posted it for the didactic value. I found that forgetting a new is an easy bug to spot. Like others, I don't think we actually need this for most code. Unless you're writing a library for creating JS inheritance, in which case you could use from one single place and you would already be using a different approach than the straight forward inheritance.

Body:
I actually wrote a post about this. http://js-bits.blogspot.com/2010/08/constructors-without-using-new.html

function Ctor() {
    if (!(this instanceof Ctor) {
        return new Ctor();
    }
    // regular construction code
}

And you can even generalize it so you don't have to add that to the top of every constructor. You can see that by visiting my post

Disclaimer I don't use this in my code, I only posted it for the didactic value. I found that forgetting a new is an easy bug to spot. Like others, I don't think we actually need this for most code. Unless you're writing a library for creating JS inheritance, in which case you could use from one single place and you would already be using a different approach than the straight forward inheritance.


答:
The answer depends on how you use the class...

If you want your class to be immutable, you'll have to use constructor parameters.

If you want your class to be deserializable by relection based (de)serializers, you will need a default constructor and setters.

If your class isn't supposed to be immutable and you want consumers to be able to change all the properties during the objects' lifetime, then you will need to add setters anyway (or add modification methods, which may seem less straightforward to consumers).

If you do use the default constructor and properties approach, then you must make sure that the consumers can not invalidate the object's state by setting in an unexpected order, that default values are valid and that all the setters check things like ranges before applying the changes.

If you have two (or more) dependant properties, either encapsulate them in a class, or make sure that if either of them is set (e.g. X is set), it changes the other's value (e.g. Y's value) if (Y's) current value doesn't not go together with the new value (of X).

Also, consider if your class really should be one class:

If it has 30 parameters, you may be breaking the OO principle of encapsulation - where each class does one thing and does everything for that one thing.

Perhaps you should be using composition of a few classes or, if you have a lot of common parameters between classes, perhaps you need one or more vertical classes that handles a specific aspect and can act on multiple classes (either using reflection or using additional classes in a visitor pattern).

Title: Setters or constructor for many variables?

Body:
Possible Duplicate:

  Are there guidelines on how many parameters a function should accept?

I have got class with 30 variables (it is an application form), so I wonder what is the best practice to organize class creation.

Should I use huge constructor:

```<code>MyClass mc = new MyClass(a, b, c, d)
</code>```

Or setters:

```<code>MyClass mc = new MyClass();
mc.setA(a);
mc.setB(b);
mc.setC(c);
mc.setD(d);
</code>```

What is the best practice in OOP for such a situation? I saw a similar question, but I don't need immutability.


答:
For an impressive, real world example of 100% branch coverage, see How SQLite is Tested.

I realize your question specifically asks about javascript which is an entirely different type of software product, but I want to bring awareness to what can be done with sufficient motivation.

Title: Is 100% code coverage a pipe dream?

Body: Is it feasible to expect 100% code coverage in heavy jquery/backbonejs web applications?  Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around 92%-95% in javascript/jquery? </p>


答:
I'd say unless the code is designed with specific goal of allowing 100% test coverage, 100% may be not achievable. One of the reasons would be that if you code defensively - which you should - you should have sometimes code that handles situations that you're sure shouldn't be happening or can't be happening given your knowledge of the system. To cover such code with tests would be very hard by definition. To not have such code may be dangerous - what if you're wrong and this situation does happen one time out of 256? What if there's a change in unrelated place which makes impossible thing possible? Etc. So 100% may be rather hard to reach by "natural" means - e.g., if you have code that allocates memory and you have code that checks if it has failed, unless you mock out memory manager (which may not be easy) and write a test that returns "out of memory", covering that code might be difficult. For JS application, it may be defensive coding around possible DOM quirks in different browsers, possible failures of external services, etc.  </p>

<p>So I would say one should strive for being as close to 100% as possible and have a good reason for the delta, but I would not see not getting exactly 100% as necessarily failure. 95% can be fine on a big project, depending on what the 5% are. </p>

Title: Is 100% code coverage a pipe dream?

Body:
I'd say unless the code is designed with specific goal of allowing 100% test coverage, 100% may be not achievable. One of the reasons would be that if you code defensively - which you should - you should have sometimes code that handles situations that you're sure shouldn't be happening or can't be happening given your knowledge of the system. To cover such code with tests would be very hard by definition. To not have such code may be dangerous - what if you're wrong and this situation does happen one time out of 256? What if there's a change in unrelated place which makes impossible thing possible? Etc. So 100% may be rather hard to reach by "natural" means - e.g., if you have code that allocates memory and you have code that checks if it has failed, unless you mock out memory manager (which may not be easy) and write a test that returns "out of memory", covering that code might be difficult. For JS application, it may be defensive coding around possible DOM quirks in different browsers, possible failures of external services, etc.

So I would say one should strive for being as close to 100% as possible and have a good reason for the delta, but I would not see not getting exactly 100% as necessarily failure. 95% can be fine on a big project, depending on what the 5% are.


答:
If you are starting out with a new project, and you are strictly using a test-first methodology, then it is entirely reasonable to have 100% code coverage in the sense that all of your code will be invoked at some point when your tests have been executed. You may not however have explicitly tested every individual method or algorithm directly due to method visibility, and in some cases you may not have tested some methods even indirectly.

Getting 100% of your code tested is potentially a costly exercise, particularly if you haven't designed your system to allow you to achieve this goal, and if you are focusing your design efforts on testability, you are probably not giving enough of your attention to designing your application to meet it's specific requirements, particularly where the project is a large one.  I'm sorry, but you simply can't have it both ways without something being compromised.

If you are introducing tests to an existing project where testing has not been maintained or included before, then it is impossible to get 100% code coverage without the costs of the exercise outweighing the effort. The best you can hope fore is to provide test coverage for the critical sections of code that are called the most.

Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around 92%-95% in javascript/jquery?

In most cases I would say that it you should only consider your sprint to have 'failed' if you haven't met your goals. Actually, I prefer not to think of sprints as failing in such cases because you need to be able to learn from sprints that don't meet expectations in order to get your planning right the next time you define a sprint. Regardless, I don't think it's reasonable to consider the code coverage to be a factor in the relative success of a sprint. Your aim should be to do just enough to get everything to work as specified, and if you are coding test-first, then you should be able to feel confident that your tests will support this aim. Any additional testing you feel you may need to add is effectively sugar-coating and thus an added expense which can hold you up in completing your sprints satisfactorily.

Title: Is 100% code coverage a pipe dream?


问:
Truly useful UML diagrams
UML has a jungle of Diagrams.

Profile Diagrams, Class Diagrams, Package Diagrams...

However, (IMH-and-not-too-experienced-O) I quite see that doing each and every diagram is  overkill.

Therefore, which UML Diagrams are more suitable in a web context, more expecificly a blog (we want to build it from scratchs).

I understand that just because I used UML Diagrams does not imply that our code would be great and brilliant... but, it certainly would be better than just unplanified code...

答:
The diagram is less important than the conversations you have when communicating concepts between the various stakeholders in a project. After years of developing software, I've found myself trying to capture information diagrammatically even less in recent years than I used to when I was just starting out. Nowadays, I might draw up a few simple use-cases on a whiteboard when discussing concepts, and I'll often resort to a simple but classic flowchart if I am trying to gain some understanding about how a customer wants a system to work. If I am particularly concerned, I'll use the camera on my phone to capture the image on the whiteboard  to help me remember specific things.

Heavily documented up-front design isn't very lean. It discourages change and fixates your thinking around a single plan of attack that might end up totally wrong for the project overall. You want to be able to defer as much of your design as you can to the last minute in order to reduce the chances that a big change will mess up your designs and schedules later on. This is not to say that UML shouldn't be used, but rather that it should be used sparingly, as a means to improve the communication of concepts, and not as a means to define the systems you are intending to build.

Title: Truly useful UML diagrams


问:
What is the role of traditional issue tracker when Scrum / Kanban board is used?
From a very high level view, to me it seems there are generally 2 types of Project Management tools:

Traditional issue trackers like Fogbugz, JIRA, BugZilla, Trac, Redmine etc.

Virtual card boards / agile project management tools like Pivotal Tracker, GreenHopper, AgileZen, Trello etc.

Sure, they overlap in one way or another, e.g. Pivotal Tracker tasks can be imported to JIRA, GreenHopper itself is implemented on top of JIRA issue base etc. but I think one can still see the difference in orientation between those two types of tools.

Traditional issue tracker seems to be used even in companies otherwise doing agile project management. My question is, why do they do that? I also feel that we should use an issue tracker in my company but when I'm thinking about it, I'm not actually sure why should we need it.

For example, Trello development seems to be managed by using Trello itself (see this virtual wall) even though they have access to Fogbugz, one of the best issue trackers around. So maybe we don't need traditional issue tracker when we'll be doing 100% of our work in an agile manner using one of the agile PM tools?

答:
Issue tracking isn't project management, even though many of the tools are designed to allow you to do both, so therefore one system doesn't really replace the other,

A Kanban board gives you a lovely overview of the work you have that is current and outstanding, and let's you know at a glance what the priorities are, whereas an issue tracker allows you to tie your issues to your version control system, and works better as a means of logging everything that should be in your Kanban backlog, but with additional detail that would otherwise make your Kanban board a real mess to read.

The thing is that the two concepts work well together and support each other nicely. Of course, if you have a system that can give you the best of both worlds inside one neat application, then it may blur the lines a little, however the concepts still remain reasonably separate.


问:
For what problems is object oriented programming not a good choice?
Somewhat inspired by this question: For what common problems is functional programming not a good fit? - but nevertheless a question which I always wanted, but was too afraid to ask.

I've been in ... well, let's call it engineering software development practically all my life, and in all that time, although OO had always been there (well, most of that time) I've never had the need to use "its ways", nor to learn that paradigm. We've always used rather simple program structures, routines/functions/modules and although it is opposite to today's best practices managing those programs (programs up to roughly 300k LOC, nothing too big) never proved to be difficult, let alone impossible.

So I wanted to ask you, what would be the sorta problems for which object oriented paradigm would not be a good choice? In comparison to procedural programming ?

答:
concurrency: the locking mechanism seems kind of problematic; only some very good developers are put to work on the threading part of projects

extending: don't know how extandable the current OO languages are. only know that Java is bad. therefor DSLs (domain-specific languages) have to be implemented as Frameworks. Clojure on the other hand (that is functional), has macros.


问:
Does groovy call partial application 'currying'?
Groovy has a concept that it calls 'currying'.  Here's an example from their wiki:

def divide = { a, b -> a / b }

def halver = divide.rcurry(2)

assert halver(8) == 4

My understanding of what's going on here is that the right hand argument of divide is being bound to the value 2.  This seems like a form of partial application.

The term currying is usually used to mean transforming a function that takes a series of arguments into a function that only takes one argument and returns another function.  For example here is the type of the curry function in Haskell:

curry :: ((a, b) -> c) -> (a -> (b -> c))

For people who haven't used Haskell a, b and c are all generic parameters.  curry takes a function with two arguments, and returns a function that takes a and returns a function from b to c.  I've added an extra pair of brackets to the type to make this more clear.

Have I misunderstood what's going on in the groovy example or is it merely misnamed partial application?  Or does it in fact do both: that is to say convert divide into a curried function and then partially apply 2 to this new function.

答:
Groovy borrowed the naming of its curry methods from numerous other non-pure FP languages which also use similar naming for partial application - perhaps unfortunate for such FP-centric functionality. There are several "real" currying implementations being proposed for inclusion in Groovy. A good thread to start reading about them is here:

http://groovy.markmail.org/thread/c4ycxdzm3ack6xxb

The existing functionality will remain in some form and backwards compatibility will be taken into consideration when making a call on what to name the new methods etc. - so I can't say at this stage what the final naming of the new/old methods will be. Probably a compromise on the naming but we'll see.

For most OO programmers the distinction between the two terms (currying and partial application) is arguably largely academic; however, once you are used to them (and whoever will maintain your code is trained to read this style of coding) then point-free or tacit style programming (which "real" currying supports) allows certain kinds of algorithms to be expressed more compactly and in some cases more elegantly. There is obviously some "beauty lies in the eyes of the beholder" here but having the ability to support both styles is in keeping with Groovy's nature (OO/FP, static/dynamic, classes/scripts etc.).


问:
Learn programming backwards, or "so I failed the FizzBuzz test. Now what?"

A Little Background

I'm 28 today, and I've never had any formal training in software development, but I do have two higher education degrees equivalent to a B.A in Public Relations and an Executive MBA focused on Project Management. I've worked on those fields for about 6 years total an then, 2,5 years ago I quit/lost my job and decided to shift directions.

After a month thinking things through I decided to start freelancing developing small websites in WordPress. I self-learned my way into it and today I can say I run a humble but successful career developing themes and plugins from scratch for my clients - mostly agencies outsourcing some of their dev work for medium/large websites.

But sometimes I just feel that not having studied enough math, or not having a formal understanding of things really holds me behind when I have to compete or work with more experienced developers. I'm constantly looking for ways to learn more but I seem to lack the basics.

Unfortunately, spending 4 more years in Computer Science is not an option right now, so I'm trying to learn all I can from books and online resources. This method is never going to have NASA employ me but I really don't care right now. My goal is to first pass the bar and to be able to call myself a real programmer.

I'm currently spending my spare time studying Java For Programmers (to get a hold on a language everyone says is difficult/demanding), reading excerpts of Code Complete (to get hold of best practices) and also Code: The Hidden Language of Computer Hardware and Software (to grasp the inner workings of computers).

TL;DR

So, my current situation is this: I'm basically capable of writing any complete system in PHP (with the help of Google and a few books), integrating Ajax, SQL and whatnot, and maybe a little slower than an experienced dev would expect due to all the research involved.

But I was stranded yesterday trying to figure out (not Google) a solution for the FizzBuzz test because I didn't have the if($n1 % $n2 == 0) method modulus operator memorized.

What would you suggest as a good way to solve this dilemma? What subjects/books should I study that would get me solving problems faster and maybe more "in a programmers way"?

EDIT - Seems that there was some confusion about what did I not know to solve FizzBuzz.

Maybe I didn't express myself right: I knew the steps needed to solve the problem. What I didn't memorize was the modulus operator. The problem was in transposing basic math to the program, not in knowing basic math.

I took the test for fun, after reading about it on Coding Horror. I just decided it was a good base-comparison line between me and formally-trained devs.

I just used this as an example of how not having dealt with math in a computer environment before makes me lose time looking up basic things like modulus operators to be able to solve simple problems.

答:
So you couldn't solve the FizzBuzz problem. Big deal. Now you can, and I bet you'll never forget all the myriad ways how. Try not to be so eager to brand yourself a bad programmer simply because you couldn't solve one stupid problem off the top of your head.

That's one issue. The other is that you seem to feel a bit behind the programming learning curve. As others have said, keep coding and keep reading. The more you do, the better you'll get. It's as simple as that. Start with whatever you feel is the biggest hole in your background and proceed from there.


答:
There are (at least) three different ways a team could work. Choose the one that works for your team.

1. Detail vs. High-Level Overview

Use the issue tracker to keep track of individual tasks. Use the card board to maintain a big picture of the major features, as a summary of the tasks in the issue tracker.

2. Bugs vs. Features

Use the issue tracker to keep track of individual bugs and customer service requests. Use the card board to keep track of new features under development.

3. Milestone software delivery vs. continuous software delivery

Use an issue tracker if you deliver large blocks of new functionality irregularly (for example, if you are the Windows team and there's a new version every few years). It is ideal for a development process in which large, completed projects are delivered to customers all at once (that includes games, embedded software, and traditional software based on annual or semi-annual releases).

Use a card board if you are delivering new features continuously to customers as they are developed, for example, on a web team that has continuous or very frequent delivery of value to customers. In this scenario your software development process is almost like an assembly line and less like a project with a beginning and an end.

Title: What is the role of traditional issue tracker when Scrum / Kanban board is used?

Body:
From a very high level view, to me it seems there are generally 2 types of Project Management tools:

Traditional issue trackers like Fogbugz, JIRA, BugZilla, Trac, Redmine etc.

Virtual card boards / agile project management tools like Pivotal Tracker, GreenHopper, AgileZen, Trello etc.

Sure, they overlap in one way or another, e.g. Pivotal Tracker tasks can be imported to JIRA, GreenHopper itself is implemented on top of JIRA issue base etc. but I think one can still see the difference in orientation between those two types of tools.

Traditional issue tracker seems to be used even in companies otherwise doing agile project management. My question is, why do they do that? I also feel that we should use an issue tracker in my company but when I'm thinking about it, I'm not actually sure why should we need it.

For example, Trello development seems to be managed by using Trello itself (see this virtual wall) even though they have access to Fogbugz, one of the best issue trackers around. So maybe we don't need traditional issue tracker when we'll be doing 100% of our work in an agile manner using one of the agile PM tools?


问:
Does using GCC specific builtins qualify as incorporation within a project?
I understand that linking to a program licensed under the GPL requires that you release the source of your program under the GPL as well, while the LGPL does not require this. The terminology of the (L)GPL is very clear about this.

```<code>#include "gpl_program.h"
</code>```

means you'd have to license GPL, because you're linking to GPL licensed code. And

```<code>#include "lgpl_program.h"
</code>```

means you're free to license however you want, so that it doesn't explicitly prohibit linking to LGPL source. Now, my question about what isn't clear is:

[begin question]

GCC is GPL licensed, compiling with GCC, does not constitute "integration" into your program, as the GPL puts it; does using builtin functions (which are specific to GCC) constitute "incorporation" even though you haven't explicitly linked to this GPL licensed code? My intuition tells me that this isn't the intention, but legality isn't always intuitive. I'm not actually worried, but I'm curious if this could be considered the case.

[end question]

[begin aside]

The reason for my equivocation is that GCC builtins like __builtin_clzl() or __builtin_expect() are an API technically and could be implemented in another way. For example, many builtins were replicated by LLVM and the argument could be made that it's not implementation specific to GCC. However, many builtins have no parallel and when compiled will link GPL licensed code in GCC and will not compile on other compilers. If you make the argument here that the API could be replicated by another compiler, couldn't you make that identical claim about any program you link to, so long as you don't distribute that source?

I understand that I'm being a legal snake about this, but it strikes me as odd that the GPL isn't more specific. I don't see this as a reasonable ploy for proprietary software creators to bypass the GPL, as they'd have to bundle the GPL software to make it work, removing their plausible deniability. However, isn't it possible that if builtins don't constitute linking, then open source proponents who oppose the GPL could simply write a BSD/MIT/Apache/Apple licensed product that links to a GPL'd program and claim that they intend to write a non-GPL interface that is identical to the GPL one, preserving their BSD license until it's actually compiled?

[end aside]

Sorry for the aside, I didn't think many people would follow why I care about this if I'm not facing any legal trouble or implications. Don't worry too much about the hypotheticals there, I'm just extrapolating what either answer to my actual question could imply.

答: If by "builtin functions", you mean stuff like strlen() and read(), you're barking up the wrong tree.  GCC doesn't supply those, the C library from which you load the standard headers and against which you link your code does.  It's that package's license you need to be concerned about.


答:
You need as many as required to understand and communicate the system.  For blogging software, I wouldn't think you need many.  Model as much as you need to understand the system.  Stop modelling when it stops adding you your understanding.

If you are new to UML you may want do a few diagrams in detail to increase your understanding of the diagrams.   Once you understand a diagram type well enough you can do it in your mind, the need for actual diagrams becomes less.

If you date your diagram versions, it will help you judge whether they are likely to be current.  Comparing the current design to older diagrams can be useful in determining which areas of the project varied significantly from the original design.

Unless you are using tools which generate the code from diagrams or embed the diagram specification in code the are likely to fall out of sync with the code.  Detailed diagrams will tend to become significantly more incorrect over time. than overview diagram.  Overview diagrams will also be require less maintenance to keep them current.

You may find it useful to generate diagrams that:

Outline the actors and how they use the system.

Outline the structure of packages within the system.  Note which packages contain reusable components.

Model the database structure.

Sequence diagrams are useful to design standard components.  If you have many similar components, model one and use it as a pattern for the others.   Consider code reuse in cases like this.

Generate diagrams which are useful in planning the project.  If a diagram is not necessary to understand and/or communicate something about the project, don't waste time on it.  Feel free to use a non-UML diagram if it aids understanding.  UML may not be the best way to model the database.

Title: Truly useful UML diagrams

Body:
UML has a jungle of Diagrams.

Profile Diagrams, Class Diagrams, Package Diagrams...

However, (IMH-and-not-too-experienced-O) I quite see that doing each and every diagram is  overkill.

Therefore, which UML Diagrams are more suitable in a web context, more expecificly a blog (we want to build it from scratchs).

I understand that just because I used UML Diagrams does not imply that our code would be great and brilliant... but, it certainly would be better than just unplanified code...


答:
I don't know if there is a clear answer, so I'm just reporting my experience...

For years I was completely sold on true bug tracking systems, like FogBugz, Jira, Trac, etc.  However, I recently took a job where we are Agile (truly being agile, not just doing Agile).  We don't have long, historical lists of bugs or nice-to-have items.

There's just no use for such a tool.  Anything that's important we get to pretty quick.  Anything not so important, well, what's the point?

It is quite liberating to not have a huge backlog of stuff we know we won't have time to do, while at the same time knowing we are delivering the best value every day.


问:
I'm doing 90% maintenance and 10% development, is this normal?
I have just recently started my career as a web developer for a medium sized company. As soon as I started I got the task of expanding an existing application (badly coded, developed by multiple programmers over the years, handles the same tasks in different ways, zero structure).

So after I had successfully extended this application with the requested functionality, they gave me the task to fully maintain the application. This was of course not a problem, or so I thought. But then I got to hear I wasn't allowed to improve the existing code and to only focus on bug fixes when a bug gets reported.

From then on I have had three more projects just like the above, that I now also have to maintain. And I got four projects where I was allowed to create the application from scratch, and I have to maintain those as well.

At this moment I'm slightly beginning to get crazy from the daily mails of users (read managers) for each application I have to maintain. They expect me to handle these mails directly while also working on two other new projects (and there are already five more projects lined up after those). The sad thing is I have yet to receive a bug report on anything that I have coded myself. For that I have only received the occasional let's-do-things-180-degrees-different change requests.

Anyway, is this normal? In my opinion I'm doing the work equivalent of a whole team of developers.

Was I an idiot when I initially expected things to be different?

I guess this post has turned into a big rant, but please tell me that this is not the same for every developer.

P.S. My salary is almost equal if not lower than that of a cashier at a supermarket.

答:
Perhaps you're in a position to go to a manager and say: "Look, I'll be frank with you. My pay is terrible, I could get N times this as an entry level programmer at X.

I am doing way too much stuff with A, B and C. I can't maintain this. Honestly, and no offense intended, I'm going to walk out of this room with this either fixed, or with my resignation letter left with you. Now that this is all out in the air, how can we work together to make this right?"


问:
When is an object oriented program truly object oriented?
Let me try to explain what I mean:

Say, I present a list of objects and I need to get back a selected object by a user. The following are the classes I can think of right now:

```<code>ListViewer

Item

App [Calling class]
</code>```

In case of a GUI application, usually click on a particular item is selection of the item and in case of a command line, some input, say an integer representing that item. Let us go with command line application here.

A function lists all the items and waits for the choice of object, an integer. So here, I get the choice, is choice going to conceived as an object?
And based on the choice, return back the object in the list.

Does writing this program like the way explained above make it truly object oriented? If yes, how? If not, why?

Or is the question itself wrong and I shouldn't be thinking along those lines?

答:
To Answer this question...let us go step-by-step

Firstly, what is the program flow? Following is a proposed flow:

Map the possible user_inputs to the items-to-be-displayed

Display the list of items and the corresponding options for the user

Accept user_input

locate the item that matched the user_input and return that to the calling program.

If an object oriented approach is to be followed the fundamental rule is:
Every User-Defined-Data-Type (Data structure) or Class (Type) should be manipulated or operated upon within the Class/Type scope. It shall not be operated upon from the outside!

Hence, You need to add two more classes to your existing Class/Type definitions - Option and OptionList. You program may look thus...(overview only)

```<code>App {
 ....
 ListViewer lv = new ListViewer();
 ....
 Item item = lv.getSelectedItem();

}

ListViewer {
private OptionsList optionsList;

public boolean addItem(Item item){
 ...
 optionsList.addOption(optionRef, item);
 ....
}
public int displayList(){ }

public Item getSelectedItem(){ }

}

OptionList {
 private Options[] options;
 public boolean addOption(ref, Item){ }
 public Option getSelectedOption(optionRef oRef){ }

}

Option {
 private int optionRef; /* Type based on what the user_input type is going to be*/
 private Item optionValue;

 public Item getValue(){ }

}
</code>```

Now, why am I claiming that this Object Oriented? I could as well declare an array of Items in ListViewer and achieve the same thing. That is precisely the point, the items-Array in ListViewer would be a structure that is operated upon from the outside!

Further, the Type of "choice" in your question is determined by the kind of user_input.

I would like to put the above ideas in another way:
A statement to add two numbers can be written in a number of ways,
1. sum = num1 + num2
2. sum = add(n1, n2) /* function oriented /
3. sum = num1.add(num2) / object oriented */

Finally, What different contributors have said about OO still stands. But, all that stems from the concept of the data structure (data) having the operations (programs) rather data and programs being viewed separately.

That simple paradigm shift... unifying data and programs into a new unit called "Class/Object" has given us so much agony and ecstasy:-)

Body:
To Answer this question...let us go step-by-step

Firstly, what is the program flow? Following is a proposed flow:

Map the possible user_inputs to the items-to-be-displayed

Display the list of items and the corresponding options for the user

Accept user_input

locate the item that matched the user_input and return that to the calling program.

If an object oriented approach is to be followed the fundamental rule is:
Every User-Defined-Data-Type (Data structure) or Class (Type) should be manipulated or operated upon within the Class/Type scope. It shall not be operated upon from the outside!

Hence, You need to add two more classes to your existing Class/Type definitions - Option and OptionList. You program may look thus...(overview only)

App {
 ....
 ListViewer lv = new ListViewer();
 ....
 Item item = lv.getSelectedItem();

}

ListViewer {
private OptionsList optionsList;

public boolean addItem(Item item){
 ...
 optionsList.addOption(optionRef, item);
 ....
}
public int displayList(){ }

public Item getSelectedItem(){ }

}

OptionList {
 private Options[] options;
 public boolean addOption(ref, Item){ }
 public Option getSelectedOption(optionRef oRef){ }

}

Option {
 private int optionRef; /* Type based on what the user_input type is going to be*/
 private Item optionValue;

 public Item getValue(){ }

}

Now, why am I claiming that this Object Oriented? I could as well declare an array of Items in ListViewer and achieve the same thing. That is precisely the point, the items-Array in ListViewer would be a structure that is operated upon from the outside!

Further, the Type of "choice" in your question is determined by the kind of user_input.

I would like to put the above ideas in another way:
A statement to add two numbers can be written in a number of ways,
1. sum = num1 + num2
2. sum = add(n1, n2) /* function oriented /
3. sum = num1.add(num2) / object oriented */

Finally, What different contributors have said about OO still stands. But, all that stems from the concept of the data structure (data) having the operations (programs) rather data and programs being viewed separately.

That simple paradigm shift... unifying data and programs into a new unit called "Class/Object" has given us so much agony and ecstasy:-)


答:
I don't think you can necessarily master a language without having enough understanding of other languages to see that language "from the outside" as it were. Each different language brings something else to the table and the concepts they bring are things you can take back to the main languages you work with.

So time spent learning to use other languages is never wasted even if you are not planning to use them commercially.

The old adage is to learn a language every year and I'd certainly say for the first ten years or so you need to do that. Maybe beyond that you could choose between exploring some of the ones you already know in more depth ( perhaps updating your knowledge of ones you learned a few years back ) or working with particular libraries rather than just accumulating new languages endlessly, but keeping an eye on exploring the practice of programming through working with different languages is certainly an aid to your development as a programmer.

Title: A programmer should concentrate on at least how many languages?

Body: For me I am C# and Java person. I find these 2 languages are quite similar so its easier for me to crossover each other. I'm not sure if its good idea to pick up other different languages. Any thoughts?</p>


答:
Full disclosure: I'm a little biased because I'm the GreenHopper product manager at Atlassian, but I've also been involved with Agile development outside Atlassian for a long time

Having just an Agile planning tool or just an issue tracker is definitely viable. The problem is that it's sub optimal. In my experience it's sub optimal because:

Product planning usually occurs at the Epic and Story level in a backlog. Agile planning tools are great here

Yet as the old saying goes, no plan survives first contact with the enemy. In this case after your first few releases you are bound to end up with bugs (and other feedback) that is logged by QA, customers, support etc. These need to feed back in to your planning but not overwhelm it

As such, having just an Agile planning tool is great, but as your product matures and you get more external input it becomes harder and harder to effectively manage that input. Some of these external contributors simply can't contribute in a 'managed Agile backlog' type of way, they just want to submit their issue and move on. That's where having an issue tracker allows you to engage these contributors and successfully manage the ongoing business of keeping product development going.

I'd say that you need both tools. You also really need them to be integrated, otherwise you'll spend all of your time trying to keep the two in sync.


问:
CodePlex and Google Code Concerns
I was wondering about the risks involved with hosting on Microsoft CodePlex and Google Code. Let's say I host a project on one of them and it ends up taking off and getting tons of downloads.

I was wondering if it is possible (or maybe has already happened) for either Microsoft or Google to rebrand the project and turn it into closed-source?

The reason I ask is because Microsoft and Google are multi-billion dollar companies and your average lawyer would have to be crazy to try and fight them.

答:
First things first: I'm not a lawyer.

Depending on the licence you use, these companies may be free to branch your product into either a closed-source project or another open-source competitor (perhaps so they can steer the development). It's always a risk (and a benefit) of using free/open-source licences.

However, if you have reason to suspect that your project is being used outside its licence agreement (by any company, not just Google or Microsoft), you'd do best in not contacting your average lawyer. There are organizations that are passionate about helping you battle in court, such as the Free Software Foundation (Europe, US, and many places). A recent example is the FSF taking Cisco to court, accused of violating the GPL licence.

In summary, to adress your question: yes it is possible. And yes, it has happened before.

Microsoft has previously been accused of "stealing" code from projects on CodePlex and use in their products. I recall that they took parts from the ImageMaster project, used for burning DVDs and used in their own DVD tool [source].

Law is tricky, but I hope I could provide an insight. Cheers!

Title: CodePlex and Google Code Concerns


问:
use of script tag in different position of page
I found that sometimes the script don't run properly when I add script tag in the head section. But when I add script right before the ending tag of body it works fine.

What is the difference between adding script in head tag

                        OR

on just before ending body tag

                        OR

right after the control?

I found this issue very often when I use JQuery..

答:
It is very simple in fact. If your script is not bound to a document ready event, it will fire up instantly, that is, when the page is being loaded, NOT when it has loaded. What it means is that the HTML controls/tags below your script tag have not been added yet to the DOM. And as such, attempting to interact with them will not work.

If you place your script tags after the control/tag is created, the tag is in the DOM and jquery "sees" it.

For these reasons it is always recommended to bind your javascript to a document "ready" function, so that it will fire only when the DOM tree has been properly and completely instantiated.

For a more detailed explanation, you might be interested in reading this post, about the "ready" function.

Also, check out https://stackoverflow.com/q/1307929/866172 if you are interested in knowing how the web page is loaded by the browser (hint: top to bottom, or "as it is seen"). The advice in the top answer is to place the script tag at the end of the document, which makes sense, but if you are using jquery, whatever the place of your script tag is, if you wrap your code in a "ready" function you won't have any problems.


问:
Web workflow solution - how should I approach the design?
We've been tasked with creating a web based workflow tool to track change management. It has a single workflow  with multiple synchronous tasks for the most part, but branch out at a point to tasks running in parallel which meet up later on. There will be all sorts of people using the application, and all of them will need to see their outstanding tasks for each change, but only theirs, not others. There will also be a high level group of people who oversee all changes, so need to see everything. They will need to see tasks which have not been done in the specified time, who's responsible etc.

The data will be persisted to a SQL database. It'll all be put together using .Net.

I've been trying to learn and implement OOP into my designs of late, but I'm wondering if this is moot in this instance as it may be better to have the business logic for this in stored procedures in the DB. I could use POCO's, a front end layer and a data access layer for the web application and just use it as a mechanism for CRUD actions on the DB, then use SP's fired in the DB to apply the business rules.

On the other hand, I could use an object oriented design within the web app, but as the data in the app is state-less, is this a bad idea? I could try and model out the whole application into a class structure, implementing interfaces, base classes and all that good stuff. So I would create a change class, which contained a list of task classes/types, which defined each task, and implement an ITask interface etc. Put end-user types into the tasks to identify who should be doing what task.  Then apply all the business logic in the respective class methods etc.

What approach do you guys think I should be using for this solution?

答:
I would suggest following the 3-tier architecture for this application, this would mean that you will be keeping the user-interface, business logic and the database in different layers. The user interface that will mainly be look ‘n’ feel of the interface, will be the first layer. Then to provide the functional tools to the users and get the inputs/collect data from the users, this should be business logic layer, which will done through classes and its objects & functions. The interaction with the database that can be fetching the data, inserting the data, updating the data or deleting the data should be done through the database layer, which can be handled through SPs and Triggers defined in the database and executed from the classes defined in the business logic layer.

This will make your applications not just robust and fast but will also give you the flexibility of different skill set resources working on different layer like – designers working on the user interface, developers working on the business logic and the database administrators working on the database layer.

I hope this helps.


问:
What does the Spring framework do? Should I use it?  Why or why not?
So, I'm starting a brand-new project in Java, and am considering using Spring.  Why am I considering Spring?  Because lots of people tell me I should use Spring!  Seriously, any time I've tried to get people to explain what exactly Spring is or what it does, they can never give me a straight answer.  I've checked the intros on the SpringSource site, and they're either really complicated or really tutorial-focused, and none of them give me a good idea of why I should be using it, or how it will make my life easier.  Sometimes people throw around the term "dependency injection", which just confuses me even more, because I think I have a different understanding of what that term means.

Anyway, here's a little about my background and my app :

Been developing in Java for a while, doing back-end web development.  Yes, I do a ton of unit testing.  To facilitate this, I typically make (at least) two versions of a method : one that uses instance variables, and one that only uses variables that are passed in to the method.  The one that uses instance variables calls the other one, supplying the instance variables.  When it comes time to unit test, I use Mockito to mock up the objects and then make calls to the method that doesn't use instance variables.  This is what I've always understood "dependency injection" to be.

My app is pretty simple, from a CS perspective.  Small project, 1-2 developers to start with.  Mostly CRUD-type operations with a a bunch of search thrown in.  Basically a bunch of RESTful web services, plus a web front-end and then eventually some mobile clients.  I'm thinking of doing the front-end in straight HTML/CSS/JS/JQuery, so no real plans to use JSP.  Using Hibernate as an ORM, and Jersey to implement the webservices.

I've already started coding, and am really eager to get a demo out there that I can shop around and see if anyone wants to invest.  So obviously time is of the essence.  I understand Spring has quite the learning curve, plus it looks like it necessitates a whole bunch of XML configuration, which I typically try to avoid like the plague.  But if it can make my life easier and (especially) if make it can make development and testing faster, I'm willing to bite the bullet and learn Spring.

So please.  Educate me.  Should I use Spring?  Why or why not?

答:
Used to be we wrote simple, efficient, fast applications and web services using just core Java, Servlets and JSP, html and xml, JDBC API. It was good enough; JUnit was a good tool to test. We rested easy that our code worked.

Hibernate came along to simplify SQL and enable true mapping of Database tables with Java objects, allowing hierarchical relationships to be reflected in the Object Relations Mapping or ORM as we call it. I loved it. Especially that we did not have to map the ResultSet back into a Java object or data type.

Struts came along to add the Model View Controller pattern to our Web apps, it was good.

EJBs were a huge overhead and pain and annotations made code look like chicken scratch and now Spring got sprung on us innocent folks. It just seems overdoing to me.

For example we now package our simple jdbc url, user, pass into jdbc.properties first, then into hibernate properties second and then into Spring beans third time!

Versus all that, consider getting a connection where you need it is really as simple as shown below in pure java, which is what we really are doing after going through all that hot air stuff with Spring:

```<code>Connection connection = DriverManager.getConnection(url, user, pass);
</code>```

That is in itself self-explanatory that its a big round about and wrapping round and round to do a simple thing fast and easy with no other big benefits really. It's like wrapping tons and tons of gift paper around a tiny nice gift which is all you really keep anyway.

Another example is a batch update. With Spring it is convoluted involving quite a few classes, interfaces before you can use the JdbcTemplate to do a batch update. With plain jdbc its simply:

```<code>Statement statement = connection.createStatement();
statement.addBatch(sqlquery);
statement.executeBatch();
</code>```

Can't get simpler or faster than that.

I do not support this framework. Sorry. Who on earth wants injections every time they need anything?

Body:
Used to be we wrote simple, efficient, fast applications and web services using just core Java, Servlets and JSP, html and xml, JDBC API. It was good enough; JUnit was a good tool to test. We rested easy that our code worked.

Hibernate came along to simplify SQL and enable true mapping of Database tables with Java objects, allowing hierarchical relationships to be reflected in the Object Relations Mapping or ORM as we call it. I loved it. Especially that we did not have to map the ResultSet back into a Java object or data type.

Struts came along to add the Model View Controller pattern to our Web apps, it was good.

EJBs were a huge overhead and pain and annotations made code look like chicken scratch and now Spring got sprung on us innocent folks. It just seems overdoing to me.

For example we now package our simple jdbc url, user, pass into jdbc.properties first, then into hibernate properties second and then into Spring beans third time!

Versus all that, consider getting a connection where you need it is really as simple as shown below in pure java, which is what we really are doing after going through all that hot air stuff with Spring:

Connection connection = DriverManager.getConnection(url, user, pass);

That is in itself self-explanatory that its a big round about and wrapping round and round to do a simple thing fast and easy with no other big benefits really. It's like wrapping tons and tons of gift paper around a tiny nice gift which is all you really keep anyway.

Another example is a batch update. With Spring it is convoluted involving quite a few classes, interfaces before you can use the JdbcTemplate to do a batch update. With plain jdbc its simply:

Statement statement = connection.createStatement();
statement.addBatch(sqlquery);
statement.executeBatch();

Can't get simpler or faster than that.

I do not support this framework. Sorry. Who on earth wants injections every time they need anything?


答:
I would say that you need to adapt UML diagrams to the modeling level of all  stakeholders and the time you have to complete the project.

If the team doesn't know UML and have no time then only class diagram coming from reversed code is possible. Each member can add his/her comments in the class diagram which is already a good solution for documentation. In this case the model is only a graphical view of the code. This would cover almost 90% of modeling needs if done carefully and will not add any extra time to the project.

If you have advanced stakeholders knowledge then all diagrams could bring real value to the project in order to cover full modeling project needs. This could add significant time to project delivery but the delivery quality is expected to be better.

UML is cool, brilliant and canbe  adapted to any project if use with moderation.
Don't drink and drive for example at the same time :-)

Title: Truly useful UML diagrams


问:
faster algorithm for finding all subsets
This is the algorithm (pseudocode) I have right now for finding all subsets for a given set with length k:

```<code>void allSubsets(set[]) {
    for (i = 0; i<k; i++) {
        for (j = i + 1; j<k; j++) {
            print(set[i...j]);
        }
    }
}
</code>```

But it's run-time is O(n^2). Can anybody improve this?

答: From what I understand this doesn't work. You wouldn't find "AC" in the set "ABCD" (i.e. holes). To find all subsets think that each element is either inside the subset or not. Which is basically a binary yes, no. Therefore you can cycle over all numbers with k 0/1 bits to find all combinations.</p>


问:
What is the term for a really BIG source code commit?
Sometimes when we check the commit history of a software, we may see that there are a few commits that are really BIG - they may change 10 or 20 files with hundreds of changed source code lines (delta). I remember that there is a commonly used term for such BIG commit but I can't recall exactly what that term is. Can anyone help me? What is the term that programmers usually use to refer to such BIG and giant commit?

BTW, is committing a lot of changes all together a good practice?

UPDATE: thank you guys for the inspiring discussion! But I think "code bomb" is the term that I'm looking for.

答:
Usually many people tend to make big commit using centralized VCS, especially the server enforce good commit policy. That is the commit must pass all tests and the tests take longer time (longer than a few seconds). So developers do not want to wait so long to commit multiple times and break down changes into multiple small commits.

And developers that are green to VCS may forget to break down changes into multiple small commits. They only remember to commit when they release the program to QA team. Worse still, to avoid others to see buggy code, they do not commit before successfully passed QA testing.
Last, they did not realize that they have committed output binaries, temporary files and linker output, which really produce "big" commit.


问:
What term is used to describe running frequent batch jobs to emulate near real time
Suppose users of application A want to see the data updated by application B as frequently as possible.  Unfortunately app A or app B cannot use message queues, and they cannot share a database. So app B writes a file, and a batch job periodically checks to see if the file is there, and if load loads it into app A.

Is there a name for this concept?  A very explicit and geeky description:
"running very frequent batch jobs in a tight loop to emulate near real time".

This concept is similar to "polling".  However polling has the connotation of being very frequent, multiple times per second, whereas the most often you would run a batch job would be every few minutes.

A related question -- what is the tightest loop that is reasonable.  Is it 1 minute of 5 minutes or ...? Recall that the batch jobs are started by a batch job scheduler (e.g. Autosys, Control M, CA ESP, Spring Batch etc.) and so running a job too frequently would causes overhead and clutter.

答:
You were correct the  first time, polling is the correct term to use in this situation. Whether you are polling at 1 mHz or at 1 MHz, it is still polling.

 Note milli Hertz is not a unit I've ever see used, a poll rate of once every million seconds (11.6 days) having limited use. *8')

From the wikipedia polling page:

Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity.

In this case, the batch job is the client, while the file is the mechanism allowing the client to synchronise with the external device (application B).

Determining a suitable poll rate can be a tricky business.

If the client polls too frequently then it could end up starving the device (possibly another process on the same multitasking system) of the resources it needs to source the data needed by the client quickly enough, slowing the whole system down.

Poll too infrequently and your client could be sat idly waiting for the next poll while there is data sat waiting to be processed.

Both cases can result in the sytem running sub-optimally.

As an example of the former, I have seen system which has spent so long servicing "is there new data" requests that it had no time left to actually prepare the data being asked for (a form of livelock).

For the latter, I have a device with a 60 second poll period. Since I might need 3 round trip communications to complete a single transaction with it, each transaction may take anywhere between 3 and 6 minutes (each request happens just before a poll to each requests happens just after a poll).


答:
Whether your project is on Google Code or CodePlex in particular is not the important thing. If the project is open source, and the source is somewhere public-- and ALL of CodePlex, Google Code, Github, Sourceforge, etc. have these qualities-- then people, any people who want to, can come by, download the code, and use it in their own projects.

Microsoft used to do this kind of thing pretty regularly, witness the TCP/IP stack they used in 90s-era versions of Windows that was snatched out of BSD complete with identifying bugs, or the Stac Electronics case. I can't imagine they've stopped, unless the weirdness of their computing environment prevents it.

I haven't heard about Google doing it, but I would be entirely un-shocked. They've got a few thousand coders who are encouraged to go out and do whatever random thing they think up one day a week-- some of those guys are going to be thinking "my project would work, if only I could flamboozle the grammistans... is there a library for that?"

tl;dr If you put your code in places where people can see it, people from Big Companies can see it too.

Title: CodePlex and Google Code Concerns

Body:
I was wondering about the risks involved with hosting on Microsoft CodePlex and Google Code. Let's say I host a project on one of them and it ends up taking off and getting tons of downloads.

I was wondering if it is possible (or maybe has already happened) for either Microsoft or Google to rebrand the project and turn it into closed-source?

The reason I ask is because Microsoft and Google are multi-billion dollar companies and your average lawyer would have to be crazy to try and fight them.


问:
Is 100% code coverage a pipe dream?
Is it feasible to expect 100% code coverage in heavy jquery/backbonejs web applications?  Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around 92%-95% in javascript/jquery? </p>

答:
I don't do this as a matter of course, but I have done it on two large projects. If you've got a framework for unit tests set up anyway, it's not hard exactly, but it does add up to a lot of tests.

Is there some particular obstacle you are encountering that is preventing you from hitting those last few lines? If not, if getting from 95% to 100% coverage is straightforward, so you might as well go do it. Since you're here asking, I'm going to assume that there is something. What is that something?

Title: Is 100% code coverage a pipe dream?


问:
Designing configuration for subobjects
I have the following situation: I have a class (let's call it Main) encapsulating a complex process. This class in turn orchestrates a sequence of subalgorithms (AlgoA, AlgoB), each one represented by an individual class.

To configure Main, I have a configuration stored into a configuration object MainConfig. This object contains all the config information for AlgoA and AlgoB with their specific parameters. AlgoA has no interest to the information relative to the configuration of AlgoB, so technically I could have (and in practice I have) a contained MainConfig.AlgoAConfig and MainConfig.AlgoBConfig instances, and initialize as AlgoA(MainConfig.AlgoAConfig) and AlgoB(MainConfig.AlgoBConfig).

The problem is that there is some common configuration data. One example is the printLevel. I currently have MainConfig.printLevel. I need to propagate this information to both AlgoA and AlgoB, because they have to know how much to print. MainConfig also needs to know how much to print. So the solutions available are

I pass the MainConfig to AlgoA and AlgoB. This way, AlgoA has technically access to the whole configuration (even that of AlgoB) and is less self-contained

I copy the MainConfig.printLevel into AlgoAConfig and AlgoBConfig, so I basically have three printLevel information repeated.

I create a third configuration class PrintingConfig. I have an instance variable MainConfig.printingConfig, and then pass to AlgoA both MainConfig.AlgoAConfig and MainConfig.printingConfig.

Have you ever found this situation? How did you solve it ? Which one is stylistically clearer to a new reader of the code ?

答:
I would say it's better to have multiple small classes with a single responsibility than one big god-configurator, even if that means you will have some duplication.

If the duplicate logic is complicated, (I'm assuming that printLevel was just an oversimplified example) then you can solve it with creating an object specifically for printLevel and packing it in the others.

In your example, this would mean

delete MainConfig completely and put the common printing configuration in a PrintConfig

aggregate the new class where it's needed, for ex AlgoAConfig.PrintConfig and AlgoBConfig.PrintConfig

Title: Designing configuration for subobjects


问:
Why are side-effects considered evil in functional programming?
I feel that side effects are a natural phenomenon. But it is something like taboo in functional languages. What are the reasons?

My question is specific to functional programming style. Not all programming languages/paradigms.

答:
Well, IMHO, this is quite hypocritical. Nobody likes side effects, but everybody needs them.

What is so dangerous about side effects is that if you call a function, then this possibly has an effect not only on the way the function behaves when it is called next time, but possibly it has this effect on other functions. Thus side effects introduce unpredictable behavior and nontrivial dependencies.

Programming paradigms such as OO and functional both address this problem. OO reduces the problem by imposing a separation of concerns. This means the application state, which consists of a lot of mutable data, is encapsulated into objects, each of which is responsible for maintaining its own state only. This way the risk of dependencies is reduced and problems are far more isolated and easier to track.

Functional programming takes a far more radical approach, where the application state is simply immutable from the perspective of the programmer. This is a nice idea, but renders the language useless on its own. Why? Because ANY I/O-operation has side effects. As soon as you read from any input stream, you application state is likely to change, because the next time you invoke the same function, the result is likely to be different. You may be reading different data, or - also a possibility - the operation might fail. The same is true for output. Even output is an operation with side effects. This is nothing you realize often nowadays, but imagine you have only 20K for your output and if you output any more, your app crashes because you're out of disk space or whatever.

So yes, side effects are nasty and dangerous from the perspective of a programmer. Most bugs come from the way certain parts of the application state are interlocked in a nearly obscure way, through unconsidered and oftentimes unnecessary side effects. From the perspective of a user, side effects are the point of using a computer. They don't care for what happens inside or how it is organized. They do something and expect the computer to CHANGE accordingly.


问:
Truly useful UML diagrams
UML has a jungle of Diagrams.

Profile Diagrams, Class Diagrams, Package Diagrams...

However, (IMH-and-not-too-experienced-O) I quite see that doing each and every diagram is  overkill.

Therefore, which UML Diagrams are more suitable in a web context, more expecificly a blog (we want to build it from scratchs).

I understand that just because I used UML Diagrams does not imply that our code would be great and brilliant... but, it certainly would be better than just unplanified code...

答:
Apart from a few big-picture diagrams that will be used to communicate the overall architecture of your application in terms of servers, layers or big modules, I don't think you can predict which diagrams you'll need beforehand.

Wait until the last responsible moment. You'll see when you need them. Usually, it's either

during a conversation with the customer/domain expert/analyst, to clarify a use case

or just before starting to code, to flesh out a first version of your design.

Anyway, your models will probably become obsolete as soon as you've written a few lines of code or gotten a first customer feedback, so don't bother planning everything in advance or polishing your diagrams that much.

Title: Truly useful UML diagrams


答:
Short answer: Any use of GCC for compiling code is, always was and always will be safe.

__builtin_expect()&co. are mostly not functions but syntax extensions. More similar to + operator or for keyword than library function. For example __builtin_expect() generates no instructions at all, it just tells the compiler to order the branches so that the particular case is more efficient than the other (cpu predicts the jump in particular way, fewer jumps on that path, etc.). Even for those "builtins" that do generate code, it's like any other code generated by primitive language construct. It constitutes normal use of the compiler and normal use is never covered by GPL.

However some language constructs, whether defined by C/C++ standard or GCC extensions including any __builtin* and __sync* and such may generate calls to the gcc library (i.e. libgcc.a). This library is covered by GPL, but a special exception is provided that allows linking it with any code and distributing the resulting binary under any license whatsoever.

The same exception applies to GNU stdlibc++ (libstdc++.a/libstdc++.so), so you are safe with standard C++ library as well.

The standard C library (which comes with operating system, not gcc), GNU libc (in case of Linux), is however covered by LGPL, which only allows dynamic linking of code under different license. Since standard C library contains the system call interface that is often updated to take advantage of improvements in newer kernels it is not recommended to always link this one dynamically anyway.

Title: Does using GCC specific builtins qualify as incorporation within a project?

Body:
I understand that linking to a program licensed under the GPL requires that you release the source of your program under the GPL as well, while the LGPL does not require this. The terminology of the (L)GPL is very clear about this.

```<code>#include "gpl_program.h"
</code>```

means you'd have to license GPL, because you're linking to GPL licensed code. And

```<code>#include "lgpl_program.h"
</code>```

means you're free to license however you want, so that it doesn't explicitly prohibit linking to LGPL source. Now, my question about what isn't clear is:

[begin question]

GCC is GPL licensed, compiling with GCC, does not constitute "integration" into your program, as the GPL puts it; does using builtin functions (which are specific to GCC) constitute "incorporation" even though you haven't explicitly linked to this GPL licensed code? My intuition tells me that this isn't the intention, but legality isn't always intuitive. I'm not actually worried, but I'm curious if this could be considered the case.

[end question]

[begin aside]

The reason for my equivocation is that GCC builtins like __builtin_clzl() or __builtin_expect() are an API technically and could be implemented in another way. For example, many builtins were replicated by LLVM and the argument could be made that it's not implementation specific to GCC. However, many builtins have no parallel and when compiled will link GPL licensed code in GCC and will not compile on other compilers. If you make the argument here that the API could be replicated by another compiler, couldn't you make that identical claim about any program you link to, so long as you don't distribute that source?

I understand that I'm being a legal snake about this, but it strikes me as odd that the GPL isn't more specific. I don't see this as a reasonable ploy for proprietary software creators to bypass the GPL, as they'd have to bundle the GPL software to make it work, removing their plausible deniability. However, isn't it possible that if builtins don't constitute linking, then open source proponents who oppose the GPL could simply write a BSD/MIT/Apache/Apple licensed product that links to a GPL'd program and claim that they intend to write a non-GPL interface that is identical to the GPL one, preserving their BSD license until it's actually compiled?

[end aside]

Sorry for the aside, I didn't think many people would follow why I care about this if I'm not facing any legal trouble or implications. Don't worry too much about the hypotheticals there, I'm just extrapolating what either answer to my actual question could imply.


答:
initial commit - the project that was not under revision control thrown into SVN

refactoring - the architect has brilliant idea about changing class names from/to Smurf Naming Convention or changed the root of package hierarchy

code format - the architect have decided to change the code indent from 4 to 3 spaces or change line endings from Unix to Windows (or revert)

Friday commit - Joe is always commiting his whole week work on Fridays at 16:30

uuups commit - Ted has by mistake deleted root directory, commited that, and now he pumps once again the whole file hierarchy into SVN

Title: What is the term for a really BIG source code commit?

Body:
Sometimes when we check the commit history of a software, we may see that there are a few commits that are really BIG - they may change 10 or 20 files with hundreds of changed source code lines (delta). I remember that there is a commonly used term for such BIG commit but I can't recall exactly what that term is. Can anyone help me? What is the term that programmers usually use to refer to such BIG and giant commit?

BTW, is committing a lot of changes all together a good practice?

UPDATE: thank you guys for the inspiring discussion! But I think "code bomb" is the term that I'm looking for.


问:
IValidatableObject vs Single Responsibility
I like the extnesibility point of MVC, allowing view models to implement IValidatableObject, and add custom validation.

I try to keep my Controllers lean, having this code be the only validation logic:

```<code>if (!ModelState.IsValid)
    return View(loginViewModel);
</code>```

For example a login view model implements IValidatableObject, gets ILoginValidator object via constructor injection:

```<code>public interface ILoginValidator
{
    bool UserExists(string email);
    bool IsLoginValid(string userName, string password);
}
</code>```

It seems that Ninject, injecting instances in view models isn't really a common practice, may be even an anti-pattern?

Is this a good approach? Is there a better one?

答:
Personally, to me your design seems clean.

IValidatableObject means the view model will provide some validation that can't be provided by simple attributes - injecting the real validator which will call services / databases / whatever keeps your design clean and ensures you don't violate the single responsibility principle - View Models are responsible, essentially, for transferring data and validating the data that is transferred (whether it be through attributes or IValidatableObject or both).


问:
What are the Pros and Cons of the GPL?
I'm looking at licensing some open source software and am looking at the GPL.  What are the pros and cons of using this license?</p>

答:
Choosing GPL is the ideological step:

You are giving the advantage to free software developers, because they can use your library, and the commercial players can't (at least as long they don't want to release their product as GPL). Corporations must pay their workers to write the library that has the same functionality. You're promoting free software in that way.

Choosing less restricted licence, such as MIT is more practical:

You can use your library yourself, when coding for money (as freelancer, as employee). However, everyone can, so you're helping in that way the corporations to save money, although they are already rich without it.

Title: What are the Pros and Cons of the GPL?


答:
Having a dedicated object for validation guarantees that you respect SRP indeed - which was already the case anyway since it's a typical responsibility of a view model to validate its data.

As for injecting instances into view models, I can't see anything wrong with that. There's virtually no limit to what can be injected into what.

Title: IValidatableObject vs Single Responsibility

Body:
I like the extnesibility point of MVC, allowing view models to implement IValidatableObject, and add custom validation.

I try to keep my Controllers lean, having this code be the only validation logic:

```<code>if (!ModelState.IsValid)
    return View(loginViewModel);
</code>```

For example a login view model implements IValidatableObject, gets ILoginValidator object via constructor injection:

```<code>public interface ILoginValidator
{
    bool UserExists(string email);
    bool IsLoginValid(string userName, string password);
}
</code>```

It seems that Ninject, injecting instances in view models isn't really a common practice, may be even an anti-pattern?

Is this a good approach? Is there a better one?


问:
Is there a pattern or logical structure I can follow for Event Log Numbers?
What are some ideas or structure I can use when assigning  EventID to events that will be saved to the Windows Event Log?

Some options I've considered

Sequential  (0... int.Max)

Multiple of 10, where the "0" is replaced with how noisy the debugLevel is set.

xxx0 may represent exceptions, critical information, start, stop etc.

...?

What numbering approach gives you the most insight when a user describes the event in an email or phone?

What is the most useful to support staff?

答:
I think a combination of sequential with a prefix to indicate category & severity could be good. You could have the first 2 (or 3) digits for severity, the next few for category, and then a sequential number. The whole string would indicate what kind of problem it is and also be easy to trace back to the log file. The problem is that in your code, you now have 3 numbers to log instead of one (if you were to only use a sequential number). If you can use alphabetic characters (such as "E", "I", "W") that could also be useful.

If you're logging to a table rather than a file, then the category, severity, etc, should be in columns separate from the ID.


答: use a standard sequential ordering for EventID, if you want to differentiate between logging levels use a separate column. Your alternate idea violates first normal form, and would make creating queries filtered by type far more difficult than they need be.</p>

Title: Is there a pattern or logical structure I can follow for Event Log Numbers?

Body:
What are some ideas or structure I can use when assigning  EventID to events that will be saved to the Windows Event Log?

Some options I've considered

Sequential  (0... int.Max)

Multiple of 10, where the "0" is replaced with how noisy the debugLevel is set.

xxx0 may represent exceptions, critical information, start, stop etc.

...?

What numbering approach gives you the most insight when a user describes the event in an email or phone?

What is the most useful to support staff?


答:
Event ID, along with the Source, should uniquely identify each event.  That means that your support person when told the source / number should know what error has occurred and the steps that need to be taken to fix it.

We use a lookup table in our database that stores Number, Description, Type, Severity.  That way support staff can look up a number (say 5000) and know that it means "record locked by another user".  Create a number for each known exception and support becomes much easier.

I strongly recommend against using sequential numbers if there is no other meaning assigned to them.  That will give your help desk people no extra information.


问:
Best way to update UI when dealing with data synchronization
I'm working on a bug at work. The app is written in Objective-C for iOS based device, for the iPad. I'm the new guy there and I've been given a hard task. Sometimes, the UIButton text property does not show the correct state when syncing. Basically, when the app is syncing, my UI control would say "Syncing" and when its not syncing it'll display "Updated @ [specific date]". Right now there is a property on the app delegate called "SyncInProgress". When querying / syncing, occurring on background thread, it updates a counter. The property will return a bool checking expression 'counter > 0'.

There are three states I need to deal with.
Sync has started.
Sync is updating tables.
Sync finished.

These items need to occur in order.

My coworker suggested to take a state based approach instead of just responding to events. I'm not sure about how to go about that.

Would it be best to have the UI receive a notification to determine what state its in or to pull every so often if state changed?

Here are two posts that I put on stackoverflow, in the last few days, that relate to this.

https://stackoverflow.com/questions/11025469/ios-syncing-using-a-state-approach-instead-of-just-reacting-to-events

https://stackoverflow.com/questions/11037930/viewcontroller-when-viewwillappear-called-does-not-always-correctly-reflect-stat

Any ideas that anyone might have to very much appreciated.

Thanks,

developerDoug

答: If you're downloading the data for syncing using something like NSURLConnection, there are delegate call backs for when the connection is made (sync started), data is being downloaded (syncing) and data has finished downloading (sync finished). Even if you're not using NSURLConnection, specifically, most asynchronous web connection frameworks have this same sort of delegation pattern. </p>