答:
when I make decisions based on assumptions [...] I get corrected

Then don't make so many assumptions - clarify beforehand, ask! If the person you have to ask is not available all the time, prepare a list of questions. And repeat that whenever new questions arise, regularly, perhaps daily!

This process happens multiple times throughout a project [...] with broken windows all through it.

When you improve your code multiple times, it obviously should become better, not worse. If your code gets worse, that is almost everytime a sign that you try to add new requirements to your existing methods and classes again and again, without any restructuring of your code, until they got too big or too complicated. You can avoid that by starting to refactor more early. Every new requirement you add should be an occasion to refactor your code along the process so the new requirement can be added more easily. If you need more help, you will find plenty of information about refactoring on this site.

what should be the minimal design/scope documentation I receive before I begin development

Your misconception here is - "someone else writes down all the information for me, then I start to code". When you have asked your list of questions, write the answers down and add them to the spec or design documentation. Then implement what you are sure about, until new questions arises. It is virtually impossible to foresee all the questions you will have for the one who writes the design/scope documentation, so don't expect him to do that. Better see it as an incremental process. When you have no questions any more, and you have written down all the answers you got, then your design/scope documentation is complete.

Title: What should be the minimal design/scope documentation before development begins?

Body:
I am a junior developer working on my own in the programming aspect of projects.

I am given a png file with 5-6 of the pages designed, most times in specific detail. From this I'm asked to develop the back end system needed to maintain the website, usually a cataloging system with products, tags and categories and match the front end to the design.

I find myself in a pickle because when I make decisions based on assumptions about the flow of the website, due to a lack of outlining details, I get corrected and am required to rewrite the code to suit what was actually desired.

This process happens multiple times throughout a project, often times on the same detail, until it's finally finished, with broken windows all through it.

I understand that projects have scope creep, and can appreciate that I need to plan for this, but I feel that in this situation, I'm not receiving enough outlining details to effectively plan for the project, resulting in broken code and a stressed mind.

What should be the minimal design/scope documentation I receive before I begin development?


问:
What are the benefits and drawback of documentation vs tutorials vs video tutorials
Which types of learning resources do you find the most helpful, for which kinds of learning and/or perhaps at specific times?

Some examples of types of learning you could consider:

When starting to integrate a new SDK inside an existing codebase

When learning a new framework without having to integrate legacy code

When digging deeper into an already-used SDK that you may not know very well yet

For example - (video) tutorials are usually very easy to follow and tells a story from beginning to end to get results, but will nearly always assume starting from scratch or a previous tutorial.  Therefore such a resource is useful for quick learning if you don't have legacy code around, but less so if you have to search for the best-fit to the code you already have.

SDK Documentation on the other hand is well-structured but does not tell a story.  It is more difficult to get to a specific larger result with documentation alone, but it is a better fit when you do have legacy code around and are searching for perhaps non-obvious ways of employing the SDK or library.

Are there other forms of resources that you find useful, such as interactive training?

答: None of those enumerated. The best source of learning is represented by books. They are more detailed than a tutorial pointing out details and are not so blunt in expressing ideas like documentation.

ContentLicense: CC BY-SA 3.0


问:
Why use try … finally without a catch clause?
The classical way to program is with try ... catch. When is it appropriate to use try without catch?

In Python the following appears legal and can make sense:

```<code>try:
  #do work
finally:
  #do something unconditional
</code>```

However, the code didn't catch anything. Similarly one could think in Java it would be as follows:

```<code>try {
    //for example try to get a database connection
}
finally {
  //closeConnection(connection)
}
</code>```

It looks good and suddenly I don't have to worry about exception types, etc. If this is good practice, when is it good practice? Alternatively, what are the reasons why this is not good practice or not legal? (I didn't compile the source. I'm asking about it as it could be a syntax error for Java. I checked that the Python surely compiles.)

A related problem I've run into is this: I continue writing the function/method, at the end of which it must return something. However, it may be in a place which should not be reached and must be a return point. So, even if I handle the exceptions above, I'm still returning NULL or an empty string at some point in the code which should not be reached, often the end of the method/function. I've always managed to restructure the code so that it doesn't have to return NULL, since that absolutely appears to look like less than good practice.

答:
At a basic level catch and finally solve two related but different problems:

catch is used to handle a problem that was reported by code you called

finally is used to clean up data/resources that the current code created/modified, no matter if a problem occurred or not

So both are related somehow to problems (exceptions), but that's pretty much all they have in common.

An important difference is that the finally block must be in the same method where the resources got created (to avoid resource leaks) and can't be put on a different level in the call stack.

The catch however is a different matter: the correct place for it depends on where you can actually handle the exception. There's no use in catching an exception at a place where you can do nothing about it, therefore it's sometimes better to simply let it fall through.


答:
I think that all tree are important, but, to me, you have to take them in the right order. I've learned iOS Dev by myself. So my experience leads me to tell you to go for the easiest first and then get deeper into it.

So I have started with video tutorials, then some tutorials and finally books.

Because learning new stuff is hard to add to your current work load, you have to pay attention to your motivation. So, start with a TV-like approach and when you're at ease with new concepts and terms, dig into the real references.

Title: What are the benefits and drawback of documentation vs tutorials vs video tutorials

Body:
Which types of learning resources do you find the most helpful, for which kinds of learning and/or perhaps at specific times?

Some examples of types of learning you could consider:

When starting to integrate a new SDK inside an existing codebase

When learning a new framework without having to integrate legacy code

When digging deeper into an already-used SDK that you may not know very well yet

For example - (video) tutorials are usually very easy to follow and tells a story from beginning to end to get results, but will nearly always assume starting from scratch or a previous tutorial.  Therefore such a resource is useful for quick learning if you don't have legacy code around, but less so if you have to search for the best-fit to the code you already have.

SDK Documentation on the other hand is well-structured but does not tell a story.  It is more difficult to get to a specific larger result with documentation alone, but it is a better fit when you do have legacy code around and are searching for perhaps non-obvious ways of employing the SDK or library.

Are there other forms of resources that you find useful, such as interactive training?


问:
Event sourcing and persistence
I'm reading up on event sourcing and have a question regarding persistence.

I can still have a DB with all entities, right? Or should the events be replayed every time the application is started to get the latest version of each entity in the memory? Seems like a waste on larger systems (as in large amount of data)?

The point with event sourcing is that I can can replay the events to populate a data store if required? (or analyze the data)

答:
You will benefit the most from the event sourcing when you decide to change your system architecture also. Going towards a CQRS style architecture combined with DDD will bring up the true benefits of an event sourcing, at least in my opinion.

Building an event store that behaves well in large systems is not an easy task indeed. Replaying all the data might be expensive indeed, depends a lot on the amount of data that needs to be replayed. But there are techniques that might help you with this, one of them being the concept of a snapshot. The replay is done only from a certain point forward. The advantages that an event store bring into your system are invaluable. Having everything that happened in your system replay-able, all the data in every moment is a great thing. Think about analysis, about bug reproduction, about statistics.

There are a lot of great event stores, the last one was just released yesterday Event Store and it seems like a really good one.

The traditional database can be kept for the query part of your system to build up DTO's with the requested data. This database can be organized and optimized considering the query needs of your application and clients.

I wrote a detailed article about what are the benefits and how does a CQRS architecture combined with event sourcing really looks like. You can check it out  CQRS, Domain Events and DDD review.

Title: Event sourcing and persistence


问:
Is the book "Structure and Interpretation of Computer Programs" a good read for Java programmers?
This may be subjective and likely to be closed but I still wanted to know if its really helpfull to read Structure and Interpretation of Computer programs.

Structure and Interpretation of Computer Programs

The book does not use Java. Not that I wanted to learn Java. I am just curious as to know if it be will useful read to be a better programmer and what are the things that I can gain from the book or are their any other alternatives to this book more suited to Java programmers?

答:
Well, I don't know if this book will help you, but when I worked myself through that book about 20 years ago, it definitely improved my programming skills (independently of any programming language). And I guess especially a Java programmer will get some new insights he/she won't get by sticking only to Java.

Joel Spolsky 2005 wrote a nice article about Java and SICP which may be of interest for you:

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html


问:
Revamp application
I am a software developer having an experience of 3 yrs. I want to play with latest technologies always. But this is not practical. Because say, I developed a web application in .Net 3.5, now its 30% done. After the release of .Net 4.0, my mind is always goes with .Net 4.0. I think like this, lot of features are in new version, so why shouln't I implement those versions in my application.

When I worked with IT companies, most of them code with very old versions, some body use VB.NET, C, even Classic ASP.

So what might be the points should I consider if I revamp an application?

答:
I do the following to make my applications more flexible for future adaption of new technologies.

(1) Divide larger applications into multiple components with well defined interfaces. For example if I developed a Windows Form + basic ADO.net application on .net 2.0, later I want to convert the UI to WPF without affecting data persistence, or use entity framework for data persistence without affecting UI, having them in different projects with well defined interfaces will definitely help.

(2) If I know I will want to adapt new technologies some time down the track with a long dragging projects, I allow some tech debts budget, and have comprehensive unit tests. For example, if I want to convert a component's data searching routines to LINQ but cannot be bothered converting them all at once, I'd allow some extra time each time I touch the component, so I can convert a little each time, and gradually complete the change. Unit tests will make sure I have not broken the logic.

In summary, if you feel you absolutely want the new technologies when they become available, making sure components are well decoupled and a good unit test coverage from day 1 will definitely help.

Title: Revamp application


答:
I can still have a DB with all entities, right? Or should the events be replayed every time the application is started to get the latest version of each entity in the memory?

The answer depends on your application's requirements. I have seen it done both ways.

One extremely successful software package for small accounting firms reads its CQRS log every time on start-up. The raw amount of data was relatively small, so the start-up time was under a minute even on slower computers. They have been doing CQRS for more than a decade before the practice became popular. They knew they were on to something good when they realized that they can upgrade their client data again and again without running into troubles that they see with their larger systems.

In systems with larger volumes of data and/or systems that rely on RDBMS functionality for implementing the query side you have a database for the "current view" of the event-sourced data (you can even have multiple such views). The advantage of this approach is that it lets you build the query side using the familiar technologies.

Title: Event sourcing and persistence

Body:
I'm reading up on event sourcing and have a question regarding persistence.

I can still have a DB with all entities, right? Or should the events be replayed every time the application is started to get the latest version of each entity in the memory? Seems like a waste on larger systems (as in large amount of data)?

The point with event sourcing is that I can can replay the events to populate a data store if required? (or analyze the data)


问:
Is there any professional way to illustrate difference between 2 diagrams?
I made a documented which is to describe the difference between the same logical structure from different version ( e.g Structure A from version 8 and Structure A from version 9 ).

Luckily I've got the logical structure diagram from the 2 functional specification. I've managed to copy the image of each logical structure and paste them in MS Word and compare the 2 version side by side.

I don't know if there is a standard way to illustrate the difference. I simply draw a cross over the removed logical member from the previous version and draw a rectangle around the new logical member of the next version. I know my way is kinda childish. I am wondering how to present them professionally.

In addition, You won't believe this, but MS Word doesn't have a shape of CROSS, so I am actually using a multiplication sign that look like a giant monster:

This is why I hate myself. Unlike 2 separated lines, this shape is easy to use, draw and resize. I am wondering if MS Word would care about a normal cross.

答:
If you have version control, then it should take care of this problem.

In MS word, you should be able to use a build in mechanism to review the changes in the text, which i hope you are already aware and utilize.

However, for mentioned diagram differences you may use your approach by showing original diagram with additions in Red colored drawings (no reason to show side-by-side). I think your approach showing red crosses for discarded parts is a good one.  However, in the beginning of the document, you have to provide some brief instruction to notify the reader about your conventions that you have used to differentiate the diagrams.


答:
I know my way is kinda childish.

That is debatable.  If it is actually necessary to explicitly show that a node has been deleted, then (IMO) a simple corner-to-corner is a reasonable way to do it.  I've seen this kind of notation used in text books.

The bottom line is that getting the information across to the reader clearly is more important than "childish" versus "professional".

I am wondering how to present them professionally.

I suppose you could overlay it with "Deleted" in a distinctive text style.

Title: Is there any professional way to illustrate difference between 2 diagrams?

Body:
I made a documented which is to describe the difference between the same logical structure from different version ( e.g Structure A from version 8 and Structure A from version 9 ).

Luckily I've got the logical structure diagram from the 2 functional specification. I've managed to copy the image of each logical structure and paste them in MS Word and compare the 2 version side by side.

I don't know if there is a standard way to illustrate the difference. I simply draw a cross over the removed logical member from the previous version and draw a rectangle around the new logical member of the next version. I know my way is kinda childish. I am wondering how to present them professionally.

In addition, You won't believe this, but MS Word doesn't have a shape of CROSS, so I am actually using a multiplication sign that look like a giant monster:

This is why I hate myself. Unlike 2 separated lines, this shape is easy to use, draw and resize. I am wondering if MS Word would care about a normal cross.


问:
Data structure: sort and search effectively
I need to have a data structure with say 4 keys . I can sort on any of these keys. What data structure can I opt for? Sorting time should be very little.

I thought of a tree, but it will be only help searching on one key. For other keys I'll have to remake the tree on that particular key and then find it. Is there any data structure that can take care of all 4 keys at the same time?

these 4 fields [source ip, destination ip, source port, destination] are of total 12 bytes and total size for each record - 40 bytes.. have memory constraints too...

around one lac records

operations are : insertion, deletion, sorting on different keys.

For printing , sorting the records on any of one keys should not take more than 5 seconds.

答:
1. If you rarely add and remove data

What about using the same technique as the one used in RDBMS with indexes?

In other words, you'll have the unordered set containing the data, and four ordered sets containing the keys and the pointers to the items in the data set.

Of course, this may cause performance issues if you need to frequently add and remove lots of data.

2. If data is added or removed frequently

You can slightly modify the algorithm to reduce the performance impact of sorting the four index sets every time you add or remove an item. You may, for example, have four unordered index sets, create from them the sorted sets when needed, and invalidate those sorted sets when an element is added or removed.

3. Profile

Note that profiling is important, since you can't possibly guess where the bottleneck will be. Remember than:

When you remove an item from the data set, removing four keys from four index sets is fast, since those sets are already ordered;

When you add an item, adding four keys to the index sets is not hugely slow: you just have to walk through the sets, and insert the keys at the appropriate position:

Let the list be:

```<code> 3, 7, 8, 12, 16, 22, 23, 24, 27
</code>```

If you need to add the value 25, position yourself at the middle of the list:

```<code> 3, 7, 8, 12, 16, 22, 23, 24, 27
              ↑
</code>```

Since 25 is greater then 16, go to the right:

```<code> -, -, -, --, --, 22, 23, 24, 27
                         ↑
</code>```

And again to the right:

```<code> -, -, -, --, --, --, --, 24, 27
                             ↑
</code>```

Found the position.

Body:
1. If you rarely add and remove data

What about using the same technique as the one used in RDBMS with indexes?

In other words, you'll have the unordered set containing the data, and four ordered sets containing the keys and the pointers to the items in the data set.

Of course, this may cause performance issues if you need to frequently add and remove lots of data.

2. If data is added or removed frequently

You can slightly modify the algorithm to reduce the performance impact of sorting the four index sets every time you add or remove an item. You may, for example, have four unordered index sets, create from them the sorted sets when needed, and invalidate those sorted sets when an element is added or removed.

3. Profile

Note that profiling is important, since you can't possibly guess where the bottleneck will be. Remember than:

When you remove an item from the data set, removing four keys from four index sets is fast, since those sets are already ordered;

When you add an item, adding four keys to the index sets is not hugely slow: you just have to walk through the sets, and insert the keys at the appropriate position:

Let the list be:

 3, 7, 8, 12, 16, 22, 23, 24, 27

If you need to add the value 25, position yourself at the middle of the list:

 3, 7, 8, 12, 16, 22, 23, 24, 27
              ↑

Since 25 is greater then 16, go to the right:

 -, -, -, --, --, 22, 23, 24, 27
                         ↑

And again to the right:

 -, -, -, --, --, --, --, 24, 27
                             ↑

Found the position.


问:
What are the most popular IDEs per language?
This has nothing to do with having a favourite editor or anything like that. I was just wondering, per language, what are the most popular Integrated Development Environments? Maybe a top 2-3 if there is some contention. (Perceived popularity is enough)

Thus Far:

C# - Visual Studio, SharpDevelop

Java - Eclipse, NetBeans, IDEA

Objective-C - Xcode

Delphi - RAD Studio

Object Pascal - Delphi, Lazarus

C, C++ - Visual Studio, Vim

PL/SQL - RapidSQL, Oracle SQLDeveloper

PHP - Eclipse, NetBeans, Nusphere PHPed

Actionscript (AS2, AS3) - FlashDevelop

Flex - Flash Builder 4

Python - Eclipse, IDLE

Perl - Padre

Common Lisp - Lispworks, Emacs

Ruby - TextMate

Haskell - Vim

Fortran - Vim

Visual Basic - Visual Studio

答:
Not exactly freeware, but I'd use whats necessary.

C/C++ Win — Visual Studio 2010

C/C++/Fortran Linux —Netbeans

HTML/CSS — Dreamweaver

Perl — Activestate Komodo

PHP — Activestate Komodo

Python — Activestate Komodo

TCL — Activestate Komodo

ContentLicense: CC BY-SA 2.5


答: Keep your data in a hash table keyed by a UUID.  Then keep four indexes, each with two fields: the search key, and the UUID of the data.  You search the indexes to find the key, then use the key to get the data from the hash table.  Retrieving the data from the hash table is O(1), searching the index depends on the implementation (O(log N) for a red-black tree, O(M) for a trie, O(1) for a hash table).</p>

Title: Data structure: sort and search effectively

Body:
I need to have a data structure with say 4 keys . I can sort on any of these keys. What data structure can I opt for? Sorting time should be very little.

I thought of a tree, but it will be only help searching on one key. For other keys I'll have to remake the tree on that particular key and then find it. Is there any data structure that can take care of all 4 keys at the same time?

these 4 fields [source ip, destination ip, source port, destination] are of total 12 bytes and total size for each record - 40 bytes.. have memory constraints too...

around one lac records

operations are : insertion, deletion, sorting on different keys.

For printing , sorting the records on any of one keys should not take more than 5 seconds.


答: Are you planning on being a "JAVA programmer" for the rest of your life? Then there are probably better books to read. If you want to be a good programmer in general then it is an excellent read. Here is why. There are certain tools every good programmer needs in their toolbox. One is a thorough knowledge of data structures and algorithms (if you don't believe me, go interview at Microsoft, Google, Amazon etc...), accompanying algorithms is complexity analysis, recursion, and a sound understanding of pointers doesn't hurt. When it comes to algorithm analysis, recursive processes, and the functional paradigm in general, I can't think of a better or more challenging book than SICP.</p>

Title: Is the book "Structure and Interpretation of Computer Programs" a good read for Java programmers?

Body:
This may be subjective and likely to be closed but I still wanted to know if its really helpfull to read Structure and Interpretation of Computer programs.

Structure and Interpretation of Computer Programs

The book does not use Java. Not that I wanted to learn Java. I am just curious as to know if it be will useful read to be a better programmer and what are the things that I can gain from the book or are their any other alternatives to this book more suited to Java programmers?


问:
Let a model instance choose appropriate view class using category. Is it good design?
Assume I have abstract base model class called MoneySource. And two realizations BankCard and CellularAccount. In MoneysSourceListViewController I want to display a list of them, but with ListItemView different for each MoneySource subclass.

What if I define a category on MoneySource

```<code>@interface MoneySource (ListItemView)
- (Class)listItemViewClass;
@end
</code>```

And then override it for each concrete sublcass of MoneySource, returning suitable view class.

```<code>@implementation CellularAccount (ListItemView)
- (Class)listItemViewClass
{
    return [BankCardListView class];
}
@end

@implementation BankCard (ListItemView)
- (Class)listItemViewClass
{
    return [CellularAccountListView class];
}
@end

@implementation MoneySourceListController
- (ListItemView *)listItemViewForMoneySourceAtIndex:(int)index
{
    MoneySource *moneySource = [items objectAtIndex:index];
    Class viewClass = [moneySource listItemViewClass];
    ListItemView *view = [[viewClass alloc] init];
    [view setupWithMoneySource:moneySource];
    return [view autoreleased];
}
@end
</code>```

so I can ask model object about its view, not violating MVC principles, and avoiding class introspection or if constructions.

Thank you!

答:
Have a read of Martin Fowler's article on MVC.

The short synopsis is that your structure is wrong.  From the 4th paragraph discussing MVC: Model objects are completely ignorant of the UI.  And in your question, you're discussing how the Model can return different types of Views.

That you're having the model return the view is probably the first thing that I would fix.  The Controller could / should have the logic that modifies what the View displays based upon which Model is being used.

Edit

Still wrong*, sorry.

*wrong == not following MVC or its variants.

The Model is nothing more (and nothing less) than the method to access the data.

The Model and the View should have no idea of each other, and having the Model return a View type violates this principle.

The core issue here is that your logic for object instantiation is at the wrong place.  The Controller, not the Model, is the appropriate place for this logic.  Your use of categories is orthogonal (ie. unrelated) to this design issue.

To be a little bit more concrete, I'm going to simplify the example and assume that the MoneySourceListController is told what type of account is in play.  Another View & Controller could pass that information along or it could be derived from a Customer object that's part of the domain.  For that matter, it could be another area of the MSLController and some static portion of the View.

Once the MSLController knows what type of an account is required, it needs to do two things.

Create the associated View based upon the logic in MSLController regarding account types.

Create the associated Model class, again based upon the logic in MSLController regarding account types.

The Controller is the traffic cop that determines which View(s) and which Models get created.  I would have to go back an re-read all of Fowler's article to determine if there is a strict 1:1 ratio between Controller and View or if a Controller can have multiple Views.  It's a nuance of MVC vs. MVP vs. MVVM that I don't pay too much attention to.  I asked a related question for MVVM.

From your point of view, I'm assuming you're trying to use MVC to increase your ability to scale and maintain your app.  Having the Controller create the Model(s) and View(s) as I outlined above will give you those benefits.


问:
Purpose of NOP instruction and align statement in x86 assembly
It has been a year or so since I last took an assembly class. In that class, we were using MASM with the Irvine libraries to make it easier to program in.

After we'd gone through most of the instructions, he said that the NOP instruction essentially did nothing and not to worry about using it. Anyway, it was about midterm and he has some example code that wouldn't run properly, so he told us to add a NOP instruction and it worked fine. I asked I'm after class why and what it actually did, and he said he didn't know.

Anybody know?

答:
A nop may be used in a a delay slot when no other instruction may be reordered to be placed in there.

```<code>lw   v0,4(v1)
jr   v0
</code>```

In MIPS, this would be a bug because at the time the jr was reading the register v0 the register v0 hasn't been loaded with the value yet from the previous instruction.

The way to fix this would be:

```<code>lw   v0,4(v1)
nop
jr   v0
nop
</code>```

This fills the dealy slots after the load word and jump register instructions with a nop so that the load word instruction is completed before the jump register command is executed.

Further reading - a bit on SPARC filling of delay slots.  From that document:

What can be put into the delay slot?

Some useful instruction that should be executed whether you branch or    not.

Some instruction that does useful work only when you branch (or when    you don't branch), but doesn't do any harm if executed in the
  other    case.

When all else fails, a NOP instruction

What MUST NOT be put into the delay slot?

Anything that sets the CC that the branch decision depends on. The branch instruction makes the decision on whether to branch or not
  right away but it doesn't actually do the branch until after the delay
  instruction. (Only the branch is delayed, not the decision.)

Another branch instruction. (What happens if you do this is not even defined! The result is unpredictable!)

A "set" instruction. This is really two instructions, not one, and only half of it will be in the delay slot. (The assembler will warn
  you about this.)

Note the third option in the what to put into the delay slot.  The bug that you saw was likely someone filling one of the things that must not be put into the delay slot.  Putting a nop in that location would then fix the bug.

Note: after re-reading the question, this was for x86, which doesn't have delay slots (branching instead just stalls the pipeline).  So that wouldn't be the cause/solution to the bug.  On RISC systems, that could have been the answer.

Body:
A nop may be used in a a delay slot when no other instruction may be reordered to be placed in there.

lw   v0,4(v1)
jr   v0

In MIPS, this would be a bug because at the time the jr was reading the register v0 the register v0 hasn't been loaded with the value yet from the previous instruction.

The way to fix this would be:

lw   v0,4(v1)
nop
jr   v0
nop

This fills the dealy slots after the load word and jump register instructions with a nop so that the load word instruction is completed before the jump register command is executed.

Further reading - a bit on SPARC filling of delay slots.  From that document:

What can be put into the delay slot?

Some useful instruction that should be executed whether you branch or    not.

Some instruction that does useful work only when you branch (or when    you don't branch), but doesn't do any harm if executed in the
  other    case.

When all else fails, a NOP instruction

What MUST NOT be put into the delay slot?

Anything that sets the CC that the branch decision depends on. The branch instruction makes the decision on whether to branch or not
  right away but it doesn't actually do the branch until after the delay
  instruction. (Only the branch is delayed, not the decision.)

Another branch instruction. (What happens if you do this is not even defined! The result is unpredictable!)

A "set" instruction. This is really two instructions, not one, and only half of it will be in the delay slot. (The assembler will warn
  you about this.)

Note the third option in the what to put into the delay slot.  The bug that you saw was likely someone filling one of the things that must not be put into the delay slot.  Putting a nop in that location would then fix the bug.

Note: after re-reading the question, this was for x86, which doesn't have delay slots (branching instead just stalls the pipeline).  So that wouldn't be the cause/solution to the bug.  On RISC systems, that could have been the answer.


问:
Java heap space
In Java/JVM, why do we call the memory place where Java creates objects as "Heap"?

Does it use the Heap Data Structure to create/remove/maintain the objects?

As I read in the documentation of Heap data structure, the algorithm compares the objects with existing nodes and places them in such a way that Parent object is "greater" than the children. ( Or "lesser" in case of min heap). So in JVM, how are the objects compared against each other before placing them in the heap?

答:
The heap as in the memory available for dynamic memory allocation has nothing to do with the heap as in any data structure or the heap invariant (which is in fact related to the data structure). "Heap" is just a common word, and was chosen for both concepts independently (Wikipedia notes that the term was used for data structure first, but no mention of influence).

While it is probably possible to construct a memory management system which uses a heap data structure (or rather, a priority queue) in some places, I am not aware of any existing algorithm that does it, and I doubt it would be useful, outside perhaps some very specific niche.

Title: Java heap space


答:
I think you are skipping the concept of viewmodel or mixing up that with model.

It is correct to say that your controller should have define which view should be displayed. However, ideally each view should have their dedicated viewmodel for specific scenarios like: when your model is big or view needs some other information - which has all minimal set of data elements that your view is supposed to render.

Basically, your viewmodel may consist from a single model or multiple-models. However, it should have only minimal set of data elements that your view requires.

In addition, you may manage your role access security through your view-models as well.

Title: Let a model instance choose appropriate view class using category. Is it good design?

Body:
Assume I have abstract base model class called MoneySource. And two realizations BankCard and CellularAccount. In MoneysSourceListViewController I want to display a list of them, but with ListItemView different for each MoneySource subclass.

What if I define a category on MoneySource

```<code>@interface MoneySource (ListItemView)
- (Class)listItemViewClass;
@end
</code>```

And then override it for each concrete sublcass of MoneySource, returning suitable view class.

```<code>@implementation CellularAccount (ListItemView)
- (Class)listItemViewClass
{
    return [BankCardListView class];
}
@end

@implementation BankCard (ListItemView)
- (Class)listItemViewClass
{
    return [CellularAccountListView class];
}
@end

@implementation MoneySourceListController
- (ListItemView *)listItemViewForMoneySourceAtIndex:(int)index
{
    MoneySource *moneySource = [items objectAtIndex:index];
    Class viewClass = [moneySource listItemViewClass];
    ListItemView *view = [[viewClass alloc] init];
    [view setupWithMoneySource:moneySource];
    return [view autoreleased];
}
@end
</code>```

so I can ask model object about its view, not violating MVC principles, and avoiding class introspection or if constructions.

Thank you!


答:
I think Structure and Interpretation of Computer Programs is a great book to read. However, there are are a couple of problems with it.

The biggest problem in my experience is that, while the book requires absolutely no programming knowledge, and is geared to complete newbies, it is geared to complete newbies who study at MIT. And so, while it does not assume any programming knowledge, it does assume quite a bit of domain knowledge, e.g. in the fields of electrical engineering, physics and math. Note: these have nothing to do with the concepts being taught, they are just needed to understand the exercises and examples.

Greater people than me have explained it much better, in a cleverly titled paper The Structure and Interpretation of the Computer Science Curriculum. Thankfully, they aren't just whiners, they wrote their own book instead: How to Design Programs. If you think about reading SICP, you might want to read HtDP first: it covers much the same ground as SICP, but it only assumes average high-school level domain knowledge. (In fact, it is written to be taught to high school kids.)

After you have finished HtDP, you can still go back and read SICP, since now some missing bit of domain knowledge won't be as harmful anymore because you have seen the concept before.

Note: there is a draft for a second edition of HtDP, which you might want to read instead of the first edition. The material about imperative programming has been removed, and is going to be covered in the as-of-yet unwritten second volume How to Design Components, but you can take those either from the first edition or from SICP or both.


答: If you wanted to use a Heap to implement garbage collection you'd probably order the objects by reference count in a Min-Heap, regularly pull the zeroed ones off. I'm not saying this is how it's done or anything, but a cheap n quick possibility.</p>

Title: Java heap space

Body:
In Java/JVM, why do we call the memory place where Java creates objects as "Heap"?

Does it use the Heap Data Structure to create/remove/maintain the objects?

As I read in the documentation of Heap data structure, the algorithm compares the objects with existing nodes and places them in such a way that Parent object is "greater" than the children. ( Or "lesser" in case of min heap). So in JVM, how are the objects compared against each other before placing them in the heap?


答:
Keeping four keys sorted is not really any different than keeping one key sorted.

Since you say that sort time should be very little, you are pretty much limited to using some sort of tree-like structure (tree, skip-list, trie, etc.).  Which one is best for your application depends on the nature of the keys; if you can use a bitwise trie, that's very likely the best.  Otherwise, you can select from among the many tree variants depending on how you want to trade off insertion time and lookup time/memory usage.  For example, AVL trees are more dense than red-black trees, which means that insertion/deletion into AVL trees is slower (more work to maintain the dense structure), but lookup is faster and memory usage is less.  If you tend to access the same few elements repeatedly, a splay tree is preferable.

Once you have an appropriate data structure selected for a single key, you just duplicate it as many times as you need for all the keys you want to sort on.  If each element needs to be able to, for example, know how to get to "next" and "previous", you can have each element store a single pointer to a structure containing all of your trees.


答:
In general on the 80x86, NOP instructions are not required for program correctness, though occasionally on some machines a strategically-placed NOPs could cause code to run more quickly.  On the 8086, for example, code would be fetched in two-byte chunks, and the processor had an internal "prefetch" buffer which could hold three such chunks.  Some instructions would execute faster than they could be fetched, while other instructions would take awhile to execute.  During slow instructions, the processor would attempt to fill the prefetch buffer, so that if the next few instructions were fast they could be executed quickly.  If the instruction following the slow instruction starts on an even word boundary, the next six bytes worth of instructions will be prefetched; if it starts on an odd byte boundary, only five bytes will be prefetched.  If I recall, a NOP took three cycles and a memory fetch took four, so if prefetching the extra byte would save a memory cycle, adding a "NOP" to cause the instruction after a slow one to start on an even word boundary could sometimes save a cycle.

Such memory alignment issues may affect program speed, but they won't generally affect correctness.  On the other hand, there are some prefetch-related issues on those older processors where a NOP could affect correctness.  If an instruction alters a code byte which has already been prefetched, the 8086 (and I think the 80286 and 80386) will execute the prefetched instruction even though it no longer matches what's in memory.  Adding a NOP or two between the instruction that alters memory and the code byte which is altered may prevent the code byte from being fetched until after it has been written.  Note, by the way, that many copy-protection schemes exploited this sort of behavior; note too, however, that this behavior is not guaranteed.  Different processor variations may handle prefetch differently, some may invalidate prefetched bytes if the memory from which they were read is modified, and interrupts will generally invalidate the prefetch buffer; code will get re-fetched when the interrupts return.

Title: Purpose of NOP instruction and align statement in x86 assembly

Body:
It has been a year or so since I last took an assembly class. In that class, we were using MASM with the Irvine libraries to make it easier to program in.

After we'd gone through most of the instructions, he said that the NOP instruction essentially did nothing and not to worry about using it. Anyway, it was about midterm and he has some example code that wouldn't run properly, so he told us to add a NOP instruction and it worked fine. I asked I'm after class why and what it actually did, and he said he didn't know.

Anybody know?


问:
Single statement if block - braces or no?
Which is better/more generally accepted?

This:

```<code>if(condition)
{
  statement;
}
</code>```

Or:

```<code>if(condition)
  statement;
</code>```

I tend to prefer the first one, because I think it makes it easier to tell what actually belongs in the if block, it saves others from adding the braces later (or creating a bug by forgetting to), and it makes all your if statements uniform instead of some with braces and some without.  The second one, however, is still syntactically correct and definitely more compact.  I'm curious to see which is more generally preferred by others though.

答:
Personally I go with brackets.

Why?

Well if anyone comes along and needs to add code into the if statement it's 100% clear where the scope is.

It keeps the format of if statements consistent no matter how many statements there are in the block.

However, if the project style is to go without, stick to that.


问:
Misunderstanding Scope in JavaScript?
I've seen a few other developers talk about binding scope in JavaScript but it has always seemed to me like this is an inaccurate phrase. The Function.prototype.call and Function.prototype.apply don't pass scope around between two methods; they change the caller of the function - two very different things. For example:

```<code>function outer()
{
    var item = { foo: 'foo' };
    var bar = 'bar';
    inner.apply(item, null);
}

function inner()
{
    console.log(this.foo); //foo
    console.log(bar);      //ReferenceError: bar is not defined
}
</code>```

If the scope of outer was really passed into inner, I would expect that inner would be able to access bar, but it can't. bar was in scope in outer and it is out of scope in inner. Hence, the scope wasn't passed. Even the Mozilla docs don't mention anything about passing scope:

Calls a function with a given this value and arguments provided as an array.

Am I misunderstanding scope or specifically scope as it applies to JavaScript? Or is it these other developers that are misunderstanding it?

答: When you call inner.apply(item, null) you are calling inner() as though it were a method of the item object which has foo defined on it.  That sets the this object in inner() to be item.  You aren't really exposing the scope of the outer() function to the inner() function.  You are passing the object (and can therefore access its attributes).  You are not passing the lexical scope of the function which defined that object.

Title: Misunderstanding Scope in JavaScript?


答:
You are correct. It's better to think in terms of object context than scope with call and apply. However, this following example might be seen as making a scope accessible to another object context:

```<code>function objFactory(){
    var someProperty = 'a property of some sort';
    this.getSomeProperty = function(){ return someProperty; };
}

var someObj = new objFactory(),
somePlainObj = {};

'a property of some sort' === someObj.getSomeProperty.apply(somePlainObj);//true
</code>```

I may not have the exact details right but I think JS objects built from function constructors are basically just functions that are copied (along with their scopes - js scopes are function only), executed, and then simply never garbage collect (so all values are persistent) and assigned to a namespace you can access their internally defined properties via altered 'this' rules when you invoke with the 'new' keyword. But the internal vars aren't really private properties exactly (although we tend to think of them that way). They're function constructor properties accessed by the methods via closure.

But the first part of the process is still like a function firing. That makes the internal var accessed via closure which is like a copy of the scope at the moment the constructor was finished with the function execution step.

Title: Misunderstanding Scope in JavaScript?

Body:
I've seen a few other developers talk about binding scope in JavaScript but it has always seemed to me like this is an inaccurate phrase. The Function.prototype.call and Function.prototype.apply don't pass scope around between two methods; they change the caller of the function - two very different things. For example:

```<code>function outer()
{
    var item = { foo: 'foo' };
    var bar = 'bar';
    inner.apply(item, null);
}

function inner()
{
    console.log(this.foo); //foo
    console.log(bar);      //ReferenceError: bar is not defined
}
</code>```

If the scope of outer was really passed into inner, I would expect that inner would be able to access bar, but it can't. bar was in scope in outer and it is out of scope in inner. Hence, the scope wasn't passed. Even the Mozilla docs don't mention anything about passing scope:

Calls a function with a given this value and arguments provided as an array.

Am I misunderstanding scope or specifically scope as it applies to JavaScript? Or is it these other developers that are misunderstanding it?

Body:
You are correct. It's better to think in terms of object context than scope with call and apply. However, this following example might be seen as making a scope accessible to another object context:

function objFactory(){
    var someProperty = 'a property of some sort';
    this.getSomeProperty = function(){ return someProperty; };
}

var someObj = new objFactory(),
somePlainObj = {};

'a property of some sort' === someObj.getSomeProperty.apply(somePlainObj);//true

I may not have the exact details right but I think JS objects built from function constructors are basically just functions that are copied (along with their scopes - js scopes are function only), executed, and then simply never garbage collect (so all values are persistent) and assigned to a namespace you can access their internally defined properties via altered 'this' rules when you invoke with the 'new' keyword. But the internal vars aren't really private properties exactly (although we tend to think of them that way). They're function constructor properties accessed by the methods via closure.

But the first part of the process is still like a function firing. That makes the internal var accessed via closure which is like a copy of the scope at the moment the constructor was finished with the function execution step.


答: Look at http://howtonode.org/, the series of articles "Learning JavaScript with Object Graphs". apply and call are the most magical thing in JS (probably along with closure scoping), you cannot fully understand it unless you understand the basics.

Title: Misunderstanding Scope in JavaScript?


问:
How to decide how backward-compatible my new Mac OS X application should be?
I'm currently contemplating writing an OS X version of my Windows software. My Windows application still supports Windows XP, and I know that if I drop support for it now, our customers will cry bloody murder.

I'm new to OS X development, and as I learn the technology, APIs, etc., I realized that if I'm going to provide comparable level of backward compatibility (e.g. down to OS X 10.5), I would not be able to use many things that look very useful and relevant in my case (ARC, XPC communications, many others). This is quite different from Windows, in my opinion, where there are very little changed between Windows XP and Windows 7 from desktop application developer's standpoint.

So, on one hand, it seems like a complete waste to stick to 2007 or 2009-level API in 2012. On the other hand, according to NetMarketShare report and Stat Owl report Mac OS X 10.5 and 10.6 market share is still 11% and 35%-40% respectively. However, I'm not sure if these older OS users are my target audience (buyers of software utilities) if they didn't bother to upgrade their OS...

My question: Are there any other reasons I should take into account when deciding if I target 10.5 or 10.6 or 10.7 for a new application?

答:
You'll probably find that the majority of people that did not upgrade, are also not installing new applications and only use the ones they already have.

Depending on what your application is going to do, it may even be much more difficult to develop it to support older systems and at the same time work on newer systems according to the newer system conventions. If you already had an application developed for the older system things would be somewhat different as you would just upgrade it dropping support for the older system and letting people that did not upgrade use the older version. But if you start from scratch, depending on what your application is going to do, I wouldn't be too much surprised if it turned out that it would be easier to write two different applications and that the one for the old system took longer to write than the one for the new system.

I'd say targeting 10.4 Tiger is a total nonsense. Supporting 10.7 Lion is probably almost a must. Since you are writing a new application, people with 10.8 Mountain Lion will expect full support for Mountain Lion paradigms (not having it would cast a very bad shadow on your app even in the eyes of those that did not upgrade).

So 10.8 and 10.7 support having on both the native feeling of the platform is your first priority. That may already give you some headache. How back to go really depends on how long you think it'll take you to develop the application and what features your application will have. If you are going to integrate with iCloud to support inter-machine synchronization and maybe also integration with iPhone/iPad, you probably should forget anything below 10.7 or do a different application altogether for those systems. On the other hand if your application does not have data, has no reason to integrate across the different systems owned by the same user (or does it in a proprietary way), is not going to use any of the new APIs or any of the APIs that have changed, then maybe support for 10.6 Snow Leopard and 10.5 Leopard could be added without too much trouble.

But before you even think of supporting earlier than 10.7 systems, you should absolutely verify that there is a real demand for it. Do not just look at the % of still alive machines with those systems. You should verify that those users actually are still buying new applications (which, IMHO is unlikely).


问:
Branching strategy for parallel development that won't be in the same release?
My team is working on a product, which for business reasons needs to be released on a regular schedule. An issue has arisen where we want to do development in parallel for the upcoming release, as well as the 'next' release. This is to become standard practice, so it's not as straightforward as cutting a feature branch for the new work. We'll continually have 2+ teams working on different releases of the same product.

Is there an SCM best practice for this sort of arrangement?

答:
One interesting alternative I read about recently is what Martin Fowler calls a Feature Toggle.  The idea is that you can avoid branching by just turning off the features that have some code but aren't ready yet.

Whether it's worth it depends on how painful each option is, and Fowler is speaking from an Agile perspective in which it's important that everyone feels free to refactor, which branching can inhibit.


问:
Is it really free to deploy SharpDevelop apps?
I'm trying SharpDevelop to develop c# applications. Regardless of the language and the IDE, is it free to deploy applications that use WinForms?

I've been developing with MonoDevelop just because it has a designer for Gtk# (client doesn't want to pay more for licences as to use VS...), but it's too buggy and it's making us lose lots of time. SharpDevelop looks great at first sight, but I wouldn't like the user or us to have problems with legal software.

Thank you for the data! Warm regards.

答:
A quick look at SharpDevelop's website would indeed imply that it's a free IDE and compiler.  I didn't find anything that would create a legal encumbrance.

For your broader question, what makes you think that it would not be free to deploy a windows application?  Yes, you have to put the programming effort into it, but you are free to deploy your creation for free.  And yes, you have to find some sort of hosting site in order to distribute the binaries, but there are a number of free sites that will help you out there too.


问:
Worst coding standard you've ever had to follow?
Have you ever had to work to coding standards that:

Greatly decreased your productivity?

Were originally included for good reasons but were kept long after the original concern became irrelevant?

Were in a list so long that it was impossible to remember them all?

Made you think the author was just trying to leave their mark rather than encouraging good coding practice?

You had no idea why they were included?

If so, what is your least favorite rule and why?

Some examples here

答:
Hungarian notation

Sample extracted from "Charles Simonyi's explication of the Hungarian notation identifier naming convention" on MSDN.

```1  #include “sy.h”
2  extern int *rgwDic;
3  extern int bsyMac;
4  struct SY *PsySz(char sz[])
6      {
7      char *pch;
8      int cch;
9      struct SY *psy, *PsyCreate();
10      int *pbsy;
11      int cwSz;
12      unsigned wHash=0;
13      pch=sz;
14      while (*pch!=0
15        wHash=(wHash11+*pch++;
16      cch=pch-sz;
17      pbsy=&rgbsyHash[(wHash&077777)%cwHash];
18      for (; *pbsy!=0; pbsy = &psy->bsyNext)
19        {
20        char *szSy;
21        szSy= (psy=(struct SY*)&rgwDic[*pbsy])->sz;
22        pch=sz;
23        while (*pch==*szSy++)
24            {
25            if (*pch++==0)
26              return (psy);
27            }
28        }
29      cwSz=0;
30      if (cch>=2)
31        cwSz=(cch-2/sizeof(int)+1;
32      *pbsy=(int *)(psy=PsyCreate(cwSY+cwSz))-rgwDic;
33      Zero((int *)psy,cwSY);
34      bltbyte(sz, psy->sz, cch+1);
35      return(psy);
36      }```

Body:
Hungarian notation

Sample extracted from "Charles Simonyi's explication of the Hungarian notation identifier naming convention" on MSDN.

1  #include “sy.h”
2  extern int *rgwDic;
3  extern int bsyMac;
4  struct SY *PsySz(char sz[])
6      {
7      char *pch;
8      int cch;
9      struct SY *psy, *PsyCreate();
10      int *pbsy;
11      int cwSz;
12      unsigned wHash=0;
13      pch=sz;
14      while (*pch!=0
15        wHash=(wHash11+*pch++;
16      cch=pch-sz;
17      pbsy=&rgbsyHash[(wHash&077777)%cwHash];
18      for (; *pbsy!=0; pbsy = &psy->bsyNext)
19        {
20        char *szSy;
21        szSy= (psy=(struct SY*)&rgwDic[*pbsy])->sz;
22        pch=sz;
23        while (*pch==*szSy++)
24            {
25            if (*pch++==0)
26              return (psy);
27            }
28        }
29      cwSz=0;
30      if (cch>=2)
31        cwSz=(cch-2/sizeof(int)+1;
32      *pbsy=(int *)(psy=PsyCreate(cwSY+cwSz))-rgwDic;
33      Zero((int *)psy,cwSY);
34      bltbyte(sz, psy->sz, cch+1);
35      return(psy);
36      }


答:
The first is better because the second is error-prone.  For example, let's say you are temporarily commenting out code to debug something:

```<code>if(condition)
//      statement;
otherStatement;
</code>```

Or adding code in a hurry:

```<code>if(condition)
    statement;
    otherStatement;
</code>```

This is obviously bad.  On the other hand, the first one does feel too verbose at times.  Therefore, I prefer to just put everything on one line if it's sufficiently short and simple:

```<code>if(condition) statement;
</code>```

This cuts down on syntactic noise while making the construct look like it does what it actually does, making it less error-prone.  Provided that this syntax is only used for very simple, short conditions and statements, I find it perfectly readable.

Title: Single statement if block - braces or no?

Body:
Which is better/more generally accepted?

This:

```<code>if(condition)
{
  statement;
}
</code>```

Or:

```<code>if(condition)
  statement;
</code>```

I tend to prefer the first one, because I think it makes it easier to tell what actually belongs in the if block, it saves others from adding the braces later (or creating a bug by forgetting to), and it makes all your if statements uniform instead of some with braces and some without.  The second one, however, is still syntactically correct and definitely more compact.  I'm curious to see which is more generally preferred by others though.

Body:
The first is better because the second is error-prone.  For example, let's say you are temporarily commenting out code to debug something:

if(condition)
//      statement;
otherStatement;

Or adding code in a hurry:

if(condition)
    statement;
    otherStatement;

This is obviously bad.  On the other hand, the first one does feel too verbose at times.  Therefore, I prefer to just put everything on one line if it's sufficiently short and simple:

if(condition) statement;

This cuts down on syntactic noise while making the construct look like it does what it actually does, making it less error-prone.  Provided that this syntax is only used for very simple, short conditions and statements, I find it perfectly readable.


答:
I've seen stuff like this get managed on open source projects, though admittedly I have limited experience.

imagine this branching structure.

-- R0 ---> R1 --->---> R2 --->--->- R3

.../.........../................./.................../

--->---> trunk --->--->--->--->--->--->

|(clone)...../..../../...../...../../..../

-->--->---> version next --->--->--->

In this scenario, you take snapshots of the trunk every time you make a release, and this becomes the final code for that version. Version next is a clone of the trunk at some arbitrary point in time. As new features are developed, they can be pushed into the trunk whenever management decides they are ready.

ALSO: Ideally you would include which SCM in the description of the question, because things like perforce behave very differently from git.

Title: Branching strategy for parallel development that won't be in the same release?

Body:
My team is working on a product, which for business reasons needs to be released on a regular schedule. An issue has arisen where we want to do development in parallel for the upcoming release, as well as the 'next' release. This is to become standard practice, so it's not as straightforward as cutting a feature branch for the new work. We'll continually have 2+ teams working on different releases of the same product.

Is there an SCM best practice for this sort of arrangement?


问:
What are the advantages of using a template language?
I work on a CakePHP app and the views consist of raw html with embedded php echo statements, which over time has gotten rather messy. Before I go in and rewrite the code, I'm wondering if it makes sense to rewrite the views with a template engine, such as Twig or Smarty, but I don't have experience with template engines. What are all the advantages of using a template engine?</p>

答: Im my opinion, a template engine is only worthwhile if your project requires the ability for users to create custom themes.  You spent a lot of years learning PHP right? Unless you want other "non php" people to edit the theme then just use PHP in the layouts.  A templating engine takes time to learn, and adds an additional overhead to your script.</p>


答:
There are no legal constraints to deploy, distribute, sell or give away applications you have created with the .Net framework, whether in C# or VB.net even if those programs use WinForms (or aspx for that matter). You could license such applications as you see fit, be it under a closed source license or open source software license.

You could develop such apps without an IDE (although it could be argued that it would be less productive). The reason you are paying when you buy Visual Studio is for the tool itself, which in my opinion is quite good, not to have some right to distribute your apps.

If you do not want to pay for Visual Studio or work without an IDE, there are alternatives like you mentioned; MonoDevelop, SharpDevelop and Visual Studio Express being some of them.

Regarding the purchase of the license

On another note, I noticed you mentioned the client is not willing to pay for Visual Studio licenses.

Unless these are out of the ordinary or very specific, I would expect an independent contractor or a software development company I would hire to develop software to provide it's own tools like Visual Studio or Resharper. I say that as an independent contractor myself.

Of course, I do not know your specific situation. You may be working integrated in the client existing team and required to use his hardware and software. In that case, disregard this last statement.

Title: Is it really free to deploy SharpDevelop apps?

Body:
I'm trying SharpDevelop to develop c# applications. Regardless of the language and the IDE, is it free to deploy applications that use WinForms?

I've been developing with MonoDevelop just because it has a designer for Gtk# (client doesn't want to pay more for licences as to use VS...), but it's too buggy and it's making us lose lots of time. SharpDevelop looks great at first sight, but I wouldn't like the user or us to have problems with legal software.

Thank you for the data! Warm regards.


答:
I always use brackets just to be safe.

It's fine when you write it, but you know somebody will come along in the future and insert another statement without putting brackets around it.


答:
Yes, definitely worth it.

While PHP is sort of a template language, the syntax is, as you have observed, clumsy and does not help readability much. Short tags alleviate the verbosity a bit, but as soon as conditionals and iteration come into play, things do get messy.

Also, PHP does not take care of encoding output for you; if you do the following:

```<code><a href="<?= $_GET['some_url'] ?>">Click here!</a>
</code>```

...then you have yourself a big fat XSS vulnerability; a proper template engine defaults to HTML-encoding any variables you interpolate, unless explicitly overridden. This means you can't accidentally run into this common security pitfall.

With these two in mind, compare:

```<code><ul>
    <?php foreach ($items as $item): ?>
    <li><a href="<?= htmlspecialchars($item['url']) ?>"><?= htmlspecialchars($item['title']) ?></a></li>
    <?php endforeach; ?>
</ul>
</code>```

vs.:

```<code><ul>
    {%foreach items as item%}
    <li><a href="{item.url}">{item.title}</a></li>
    {%end%}
</ul>
</code>```

Another advantage, more a psychological one than technical, is that a template engine enforces (or at least strongly suggests) that you keep you presentation code separated from application logic.

One thing to keep in mind, though; PHP was not intended for writing parsers and such, and so template engines written in pure PHP can be quite slow. Some of them are implemented in a more suitable language and exposed as PHP modules; you may also find others that can compile to raw PHP, which, once compiled, can be called directly.

Title: What are the advantages of using a template language?

Body: I work on a CakePHP app and the views consist of raw html with embedded php echo statements, which over time has gotten rather messy. Before I go in and rewrite the code, I'm wondering if it makes sense to rewrite the views with a template engine, such as Twig or Smarty, but I don't have experience with template engines. What are all the advantages of using a template engine?</p>

Body:
Yes, definitely worth it.

While PHP is sort of a template language, the syntax is, as you have observed, clumsy and does not help readability much. Short tags alleviate the verbosity a bit, but as soon as conditionals and iteration come into play, things do get messy.

Also, PHP does not take care of encoding output for you; if you do the following:

<a href="<?= $_GET['some_url'] ?>">Click here!</a>

...then you have yourself a big fat XSS vulnerability; a proper template engine defaults to HTML-encoding any variables you interpolate, unless explicitly overridden. This means you can't accidentally run into this common security pitfall.

With these two in mind, compare:

<ul>
    <?php foreach ($items as $item): ?>
    <li><a href="<?= htmlspecialchars($item['url']) ?>"><?= htmlspecialchars($item['title']) ?></a></li>
    <?php endforeach; ?>
</ul>

vs.:

<ul>
    {%foreach items as item%}
    <li><a href="{item.url}">{item.title}</a></li>
    {%end%}
</ul>

Another advantage, more a psychological one than technical, is that a template engine enforces (or at least strongly suggests) that you keep you presentation code separated from application logic.

One thing to keep in mind, though; PHP was not intended for writing parsers and such, and so template engines written in pure PHP can be quite slow. Some of them are implemented in a more suitable language and exposed as PHP modules; you may also find others that can compile to raw PHP, which, once compiled, can be called directly.


问:
Is it any good to use binary arithmetic in a C++ code like "C style"?
I like the fact that the C language lets you use binary arithmetic in an explicit way in your code, sometimes the use of the binary arithmetic can also give you a little edge in terms of performance; but since I started studying C++ i can't really tell how much i have seen the explicit use of something like that in a C++ code, something like a pointer to pointer structure or an instruction for jumping to a specific index value through the binary arithmetic.

Is the binary arithmetic still important and relevant in the C++ world?
How i can optimize my arithmetic and/or an access to a specific index?
What about the C++ and the way in which the bits are arranged according to the standard?

... or i have taken a look at the wrong coding conventions ... ?

答:
I make use of binary arithmetic in virtually ALL computer languages I've programmed with. For example, take the addition operator +:

```<code>int sum = x + y; // compiler probably implements this as binary arithmetic!
</code>```

I would find it hard to program in a language that did not support arithmetic, and I would find it hard to believe that arithmetic operations were not implemented by your compiler/interpreter using binary arithmetic (such as using base-10 arithmetic).

http://en.wikipedia.org/wiki/Arithmetic#Arithmetic_operations

http://www.binarymath.info/

http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/BinaryMath.html

TL;DR: Use the right terminology (bitwise ≠ binary), else you get pendatic answers like this.

Body:
I make use of binary arithmetic in virtually ALL computer languages I've programmed with. For example, take the addition operator +:

int sum = x + y; // compiler probably implements this as binary arithmetic!

I would find it hard to program in a language that did not support arithmetic, and I would find it hard to believe that arithmetic operations were not implemented by your compiler/interpreter using binary arithmetic (such as using base-10 arithmetic).

http://en.wikipedia.org/wiki/Arithmetic#Arithmetic_operations

http://www.binarymath.info/

http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/BinaryMath.html

TL;DR: Use the right terminology (bitwise ≠ binary), else you get pendatic answers like this.

ContentLicense: CC BY-SA 4.0


问:
What benefits can I get upgrading my ASP.NET (Webform) + DAL(EF) + Repository + BLL structure to MVC?
I'm in the process of defining an approach that may best fit our needs for a big web application development.
For now, I'm thinking going with an ASP.NET Architecture with a DAL using Entity Framework, a Repository concept to not access DAL directly from BLL and a BLL that call the repository and make every manipulations necessary to prepare data to push in a presentation layer (.aspx files).

I don't plan to use ASP.Net controls and prefer to keep things simple and lightweight using plain html, jQuery UI controls and do most of the server calls with jQuery Ajax. Sometimes, when needed, I plan to use handlers (.ashx) to call BLL methods that will return JSON or HTML to client for dynamic stuff.

My solution also has a test project that Mock the Repository with in-memory data to not repose on database for testing BLL methods...

It may be usefull to add that we will build a big application over this architecture with hundreds of tables and store procedures with a lot of reading and writing to database.

My question is, having this architecture in mind, Is there any evident advantages that I can obtain by using an MVC3 project instead of the described architecture base on Webform? Do you see any problem in this architecture that may cause us problem during the next steps of development?

I know the MVC pattern for using it in others projects with Django... but the Microsoft MVC implementation look so much more complex and verbose than Django MVC and it's why I'm hesitating (or waiting for a little push?) right now before jumping into it... We are in a real project with deadlines and don't want to slow the development process without any real benefits.

答:
In my opinion, I would go with MVC. There's a lot of "nice to have" reasons. Model based views, attribute driven authentication, routing control, etc.. MVC will allow you to more cleanly separate the UI from the code layer too. My biggest complaint with ASP.net web-forms is the page event life-cycle especially when used with Master pages and controls. It is a real pain to get everything to render correctly. Lately, in my MVC projects i'll render out a view, which is tied to a model, and then subsequent updates use jQuery to make ajax calls and only update the page where it's needed.

I"ve only had experience with asp.net MVC, no other MVC frameworks, but it's actually much easier to deal with than it may seem. As long as you have some sort of "View Models" which encompass the data needed for a view, getting it on the page is very straightforward. Once you embrace the "simplicity" of MVC, no setting values based on properties in the codebehind, foreach loops on the view, and simple model bound partial views, it's actually a very nice experience.

There's a bit of a learning curve though to get away from asp.net tendencies, and it'll force you to add "layers" to the app to keep things organized, but i think it's the way to go. You can definitely apply the same concepts to WebForms, but again, the defining argument for me is the page events, i do not miss them at all..

The only slowness will come with learning what works for you guys.  Once you get a handle on it, it'll be quick clean development, and if you go the right direction, you could end up with a well defined service layer. (obviously the same can be said with webforms, but you get full Clientside control with MVC (no viewstate or wacky control names)). I totally recommend moving away from webForms.

OwnerDisplayName: Etienne


答: The term "heap" here does not relate to the data structure; instead it has the more general meaning of "a big pile of memory to throw things on top of", as opposed to the "stack", which is much more strictly ordered. C#'s "heap" is similar.</p>

Title: Java heap space


答:
We have had this argument more than once here, and the overall consensus is to always use braces. The main reasons are about readability/maintainability.

If you need to add code to the if block, you don't need to remember/search for braces.  When future programmers read the code, the braces are always unambiguous.

On the plus side, ReSharper will automatically add the braces for lazy programmers in Visual Studio, and I assume there are addons for other IDEs that will do so as well.


问:
is it allowed to create a app with overscroll feature?
As Apple won lawsuits against Motorola and Samsung with the so called overscroll patent, I am asking myself what the legal consequences of releasing an application with such a feature are?

I think if one releases the app in IOS it would be okay, but what happens in Android or Windows? Am I getting sued?

What happens if I am writing an app for the browser?

Isn't this overscroll patent a design patent? If this is true, all apps that use overscrolling and not written by Apple, would be illegal.

Very confusing.

Can anyone explain is?

答:
The courts should never have allowed Apple to sue using that patent, but the simple solution is not to do overscroll anywhere but on iOS.

Be creative. Come up with a different way elsewhere. Overscroll isn't the only way of showing that a user has reached the end.

On Android 4.0+, they create a glow at the bottom (or top) that grows as the user continues to try scrolling.
Example: http://3.bp.blogspot.com/-b6FU3amRLn0/T221H_SFK6I/AAAAAAAAADg/-ynw9wexjjk/s1600/Overscroll.png

So, pull out some creativity.


问:
Should I listen to my employer and use CASE tools?
My employer (Not a Developer) thinks that CASE tools will help us improve our development process and documentation. I am not sure about that, we are a small team of 5 developers building mobile banking solutions for local clients. I think CASE tools will be a waste of time and money as they need to be purchased and we will need some time before we get used to them and be efficient working with them for modeling and stuff. Code generation is another issue, I really think that the CASE generated code won't be as good as code written by good developers.

I think that if we stick with agile principles, design patterns, use TDD, and keep our code clean. we should be good. And as far as Analysis and Design, I think simple UML diagrams on whiteboard should do the trick. Documentation is good and important, but should be made as little as possible and we should not focus on Docs and forget the code. This is what i think.

Am I correct? or should I listen to my employer and start researching for an appropriate CASE Tool?

答:
You are mixing the problem and the solution and your boss is trying to help, with more or less success. To challenge your boss you must have clear what is your role in the organization. If he is the CEO and you are the CTO the decision is yours and the CEO should just point on what business aspects are affected by the lack of documentation. Your obligation will be then to solve the business problem, with a CASE tool or any other solution you come out with.

Regarding the specific suggestion of using CASE tools, I think you must choose it properly so that you achieve your goal without overloading your team with extra work. If documentation is what you want to improve you may have enough with a tool that is able to generate diagrams from the code, not necessarily to generate the code from the graphical diagram. An example of such a tool is Codelogic. I used some years ago to make sure that our designs where clean and clear to be understood and it was quite easy to use. If as you express money is another concern you can probably look in the open source (I cannot help here but would be interested on the result of any research).

The alternative to CASE tools can also help. Measuring things like cyclomatic or other complexity measures will keep your design well structured and developers focused on the code. Better comments on your code, Javacode-like, can also help to improve documentation.

Honestly, I think if you consider that CASE tools don't help your boss must know it. If he is a good boss he will value your opinion. I have never liked an employee who just does what he is told without critical analysis. But of course, as David suggests, any discussion should be hold on strong and objective arguments.


答: I'd try to make your employer realize that he/she has gotten things backwards. If there is room for investment for the software team, you should identify what your bottlenecks or quality problems are. IF it turns out that you have most room for improvement in documentation and development process areas, you should identify what changes has biggest ROI with regards to improving these areas. That might or might not turn out to be starting to use CASE tools.

Title: Should I listen to my employer and use CASE tools?

Body:
My employer (Not a Developer) thinks that CASE tools will help us improve our development process and documentation. I am not sure about that, we are a small team of 5 developers building mobile banking solutions for local clients. I think CASE tools will be a waste of time and money as they need to be purchased and we will need some time before we get used to them and be efficient working with them for modeling and stuff. Code generation is another issue, I really think that the CASE generated code won't be as good as code written by good developers.

I think that if we stick with agile principles, design patterns, use TDD, and keep our code clean. we should be good. And as far as Analysis and Design, I think simple UML diagrams on whiteboard should do the trick. Documentation is good and important, but should be made as little as possible and we should not focus on Docs and forget the code. This is what i think.

Am I correct? or should I listen to my employer and start researching for an appropriate CASE Tool?


问:
Actor library / framework for C++
In the C++ project I am working on, we have an application consisting of
several processes deployed on different machines. This network of
processes is dynamic since processes (clients or background services)
can be started and terminated during the application's lifetime.

We have already a module that allows to transport arbitrary data over
the network through RPC, and we are using it to exchange information
(such as status information, progress information, error codes, etc)
between the processes. We would like to have a more abstract layer
to handle asynchronous communication (currently, the RPC is executed
synchronously), and to allow processes to be started and terminated
dynamically and still find each other.

We recently looked for a solution and we think we can use something
like Scala actors and remote actors (see e.g. this tutorial).
Another language using the actor model that has been around longer
than Scala is Erlang (see also this question).

Actors are objects that have a behaviour and a mailbox, share no data.
Actors are executed concurrently, and communicate through asynchronous
message exchange. As part of their behaviour, actors can create other actors.
Messages are also represented as objects.

The simplest case is that actors live in the same process.
In this case they can address each other using
a handle (reference, pointer, unique identifier). The actor implementation
hides the underlying threads and any other details.
When actors live in different processes (and possibly on different
machines in a network) they are identified by an IP address, a port and
a name. In this case we speak of remote actors
(see the short example at the top of this page).

In our case, we would have one actor on each process, taking care of
all the communication, i.e. we need some kind of remote actors.

On wikipedia I have found some links to actor libraries for C++ and
I have started to look at Theron. Theron seems a very well-written
and documented library but, to my understanding, it does not support
remote actors: all actors must live within the same process. It is possible
to create several actor pools (frameworks), but all these pools must
live in the same process.

So I wanted to ask if someone knows other C++ libraries
that support the remote actor concept as sketched above.

EDIT

This question has been edited wrt the original question, following
indications from programmers-meta discussion.

UPDATE

Other frameworks I have looked at are libcppa (should support
remote actors, but it is still under development, currently version 0.1),
actor-cpp (also under development), and libactor, which is
in C (the web site says it "is usable, although it may not be ready for production").

答:
Maybe the QP/C++ active object (actor) framework would fit the bill? QP/C++ has been designed primarily for real-time embedded systems, but it runs very well on Linux (with P-threads) and Windows (Win32 threads).

QP/C++ is a mature, open source framework, now celebrating 10 years on the market. It is very lightweight by design and does not support remote active objects, but this capability can be added by means of the "Remote Proxy" design pattern. In this way, you can reuse your existing communication protocol over the network(s). The benefit of using Proxies is that active objects won't know that they communicate remotely, so you can partition your system as you like without changing active objects. All you need to do is develop your Proxies.

The QP framework also provides strong support for hierarchical state machines (UML Statecharts) to model the behavior of the event-driven active objects. The framework provides an easy way to code HSMs manually in highly readable code, but you can also use the free QM modeling tool to draw statecharts and generate the QP code automatically. Please visit state-machine.com for more information.

Title: Actor library / framework for C++


问:
"Opportunity" to take over maintenance of a small internal website. What should I do?
I have been offered an "opportunity" to take over maintenance of a small internal website run by my group that provides information about schedules and photos of events the groups done.

My manager sent me the link to the site and I checked it out. The site looked clean and neat but loaded in ~5 seconds. I thought this was a little long considering the site really didn't contain a lot of content. This prompted me to take a look under the hood at the pages source code. To my horror it'd been totally hacked together using nested tables!

I'm new so I really can't say no to this "opportunity" so what should I do with it?

Every fiber of my being feels that the only correct thing to do is overhaul the site using CSS, Div's, Span's and any other appropriate tags that a sane/good web developer would used to begin with instead of depending on the render incentive magic of tables.

But I'd like to ask programmers with more experienced then me, who have been in this situation. What should I do?

Is my only realistic option to leave the horror as is and only adjusting the content as requested? I'm really torn between good development and the corporate reality I'm part of. Is there some kind of middle ground where things can be made better even if they're not perfect?

Thanks ahead of time.

Edit:

I've been looking into this a little deeper and noticed an extension type that rendered as HTML but was actually ".cfm". After looking into it I found out this was a ColdFusion file. Which is apparently an Adobe WYSIWIG program which must have been used by my predecessor to create this site.

This means maintenance will be trivial once I get a copy of ColdFusion. I will probably still need to do things like create thumb nails and move some of the content on the home page elsewhere to improve load times. I doubt I can go much further in optimizing the site past this without throwing out ColdFusion.

I am very grateful for all the good advice and will keep it in mind for future "Opportunities".

答:
IF the site is working and only available to internal users and no one is complaining about the timeliness of the page loads,  i don't think that it's justified to spend anything other than spare time converting it to "table-less" as it's "kind of" subjective. If you've got lots of time on your hands, then sure, it wouldn't hurt.

But if you go in and say:

"Hey bossman, check out how i changed the table's to divs!! BOO-YAH! Did you see how fast that loaded!!!"

he might talk to your manager about getting you some more work.. LOL

Now, if you could spin it and say, "hey Mr. Manager, look what i learned in the process of speeding up our company photo site!!" Maybe, they'll say, GREAT!! Now update all our websites!! ...maybe that's great???

You could also turn it into a learning experience and use it as a chance to showcase your abilities /  methodologies and maybe even introduce new technologies, and that could turn some heads.. but moving the HTML from tables to div's and increasing the load times isn't going to bring that much value... not that it wouldnt be appreciated, but if there's other stuff to do, that'd probably be on the bottom of the list..

..good luck!!!


问:
Object Oriented Programming Language performance ranking
After reading this post about ideal programming language learning sequence, I am wondering what would have been the answers if the question was performance -instead of learning- oriented ?

Since there are many programming languages I chose to ask the question for OOL to be the least subjective. But any thought or comparison about no-OOL are appreciated :D

If we omit the programming effort, time and costs. What is your ranking of the most powerful object oriented languages ?

答:
C++

Basically all contemporary numerical simulation packages are written in either real C++ or use some C++ features on top of a large C body.

Traditionally, many packages were written in Fortran, especially in Physics, here —

in the list QC and Solid State Sim Packages you may see a "language column".

Here is something similar for Physical Chemistry/ Molecular Modelling —

Molecular Dynamics Packages.

Regards

rbo


答:
There are two ways to look at this. First, is making improvements to the web site something that will get you visibility at work? If so, definitely take the opportunity. It may not be the most pleasant task but it may open other doors for you in the future.

Second, should you rewrite the website? The web site is probably very old, from a time when nested tables was the only way to guarantee correct layout so make sure the browsers used to view the site will layout correctly using the new mark up.

If so, when you get time or when you fix or improve an area, also take the time to speed up the page. Make sure to profile the changes before and after then demo the changes to your boss and gauge his or her reaction. If he or she does not care, speed up the first few pages (so you know you can do it) then do the minimum required thereafter. You have learned everything you can. Otherwise, work through the pages as time allows and keep up the visibility.

Title: "Opportunity" to take over maintenance of a small internal website. What should I do?

Body:
I have been offered an "opportunity" to take over maintenance of a small internal website run by my group that provides information about schedules and photos of events the groups done.

My manager sent me the link to the site and I checked it out. The site looked clean and neat but loaded in ~5 seconds. I thought this was a little long considering the site really didn't contain a lot of content. This prompted me to take a look under the hood at the pages source code. To my horror it'd been totally hacked together using nested tables!

I'm new so I really can't say no to this "opportunity" so what should I do with it?

Every fiber of my being feels that the only correct thing to do is overhaul the site using CSS, Div's, Span's and any other appropriate tags that a sane/good web developer would used to begin with instead of depending on the render incentive magic of tables.

But I'd like to ask programmers with more experienced then me, who have been in this situation. What should I do?

Is my only realistic option to leave the horror as is and only adjusting the content as requested? I'm really torn between good development and the corporate reality I'm part of. Is there some kind of middle ground where things can be made better even if they're not perfect?

Thanks ahead of time.

Edit:

I've been looking into this a little deeper and noticed an extension type that rendered as HTML but was actually ".cfm". After looking into it I found out this was a ColdFusion file. Which is apparently an Adobe WYSIWIG program which must have been used by my predecessor to create this site.

This means maintenance will be trivial once I get a copy of ColdFusion. I will probably still need to do things like create thumb nails and move some of the content on the home page elsewhere to improve load times. I doubt I can go much further in optimizing the site past this without throwing out ColdFusion.

I am very grateful for all the good advice and will keep it in mind for future "Opportunities".


问:
When creating a library for a simple program, what must I do to protect others from its lack of thread safety?
When creating a library for a simple program, is it more cost effective to make it thread safe or is there a way to detect the program's use in a multithreaded program and ASSERT() or otherwise determine (preferably at compile or link time) that it may create problems.

Related help for this question would be automated tool support for finding potential problems with thread safety, programming language features that enforce it,

答:
It depends on the cost to make it thread safe (in terms of development time and effort). Things to consider include:

Making a library thread safe can be challenging, particularly when dealing with lower level thread primitives, such as Java's synchronized and C#'s lock keywords, when efficiency or speed is critical.

Some environments provide higher level abstractions like C# 4.5's await and async keywords. Use them if available.

Use thread-safe library classes, like those in .Net's System.Collections.Concurrent namespace.

Thread safety may impact the code's portability. For example, C code using pthread mutexes will not work on Windows without additional library support.

It also depends on how likely the library will be used in a multi-threaded environment and the conventions for the language used. For example, Microsoft original class library design guidelines stated that non-static members need not be thread safe.

Either way, the best approach is to clearly document what is and what is not thread safe.


问:
What's wrong performing unit test against concrete implementation if your frameworks are not going to change?
First a bit of background: We are re-architecting our product suite that was written 10 years ago and served its purpose. One thing that we cannot change is the database schema as we have 500+ client base using this system. Our db schema has over 150+ tables. We have decided on using Entity Framework 4.1 as DAL and still evaluating various frameworks for storing our business logic.

I am investigation to bring unit testing into the mix but I also confused as to how far I need to go with setting up a full blown TDD environment. One aspect of setting up unit testing is by getting into implementing Repository, unit of work and mocking frameworks etc. This mean there will be cost and investment on the code-bloat associated with all these frameworks. I understand some of this could be auto-generated but when it comes to things like behaviors, that will be mostly hand written. Just to be clear, I am not questioning the important of unit testing your code. I am just not sure we need all its components (like repository, mocking etc.) when we are fairly certain of storage mechanism/framework (SQL Server/Entity Framework). All that code bloat with generic repositories make sense when you need a generic layers with ability to change this whenever you like however its very likely a YAGNI in our case. What we need is more of integration testing where we can unit-test our code with concrete repository objects and test data in database. In this scenario, just running integration test seem to be more beneficial in our case. Any thoughts if I am missing any thing here?

答:
Your tests will be much slower if they all hit the database, so you probably won't be able to run them nearly as often, or you will spend a lot of time waiting for them.  This is a big deal, because you want to run your tests quite a lot.

Also, it's tough to get a huge benefit out of re-architecting if you can't touch the schema.  You might take a look at Evolutionary Database Design which talks about how to develop against a changing schema.  I admit that data migration is hard, but so is re-architecting an application, and you are taking that on.


答:
Apart from speed as psr mentioned, unit tests avoid hitting the database/repository to help isolate errors. The solution is not creating a generic repository. Instead, it is allowing the repository to be swapped out for a test repository that checks whether the business layer/model is making the correct repository calls. Similarly, a stub business layer/model can make test calls to a repository in a known state and compare the results to known correct values.

Doing an integration test using the repository is also a good idea but serves a different purpose to your unit tests. The challenge with doing the full integration tests as part of unit testing is ensuring tests and test data do not interfere with or impact others, such as a developer working on changes.

Title: What's wrong performing unit test against concrete implementation if your frameworks are not going to change?

Body:
First a bit of background: We are re-architecting our product suite that was written 10 years ago and served its purpose. One thing that we cannot change is the database schema as we have 500+ client base using this system. Our db schema has over 150+ tables. We have decided on using Entity Framework 4.1 as DAL and still evaluating various frameworks for storing our business logic.

I am investigation to bring unit testing into the mix but I also confused as to how far I need to go with setting up a full blown TDD environment. One aspect of setting up unit testing is by getting into implementing Repository, unit of work and mocking frameworks etc. This mean there will be cost and investment on the code-bloat associated with all these frameworks. I understand some of this could be auto-generated but when it comes to things like behaviors, that will be mostly hand written. Just to be clear, I am not questioning the important of unit testing your code. I am just not sure we need all its components (like repository, mocking etc.) when we are fairly certain of storage mechanism/framework (SQL Server/Entity Framework). All that code bloat with generic repositories make sense when you need a generic layers with ability to change this whenever you like however its very likely a YAGNI in our case. What we need is more of integration testing where we can unit-test our code with concrete repository objects and test data in database. In this scenario, just running integration test seem to be more beneficial in our case. Any thoughts if I am missing any thing here?