问:
Is this considered repeating code?
C#/ASP.net:

```<code>/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return BasketItems.Where(c => c.GroupID == GroupID).SingleOrDefault() != null;
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
    return BasketItems.Where(c => c.GroupID == GroupID && c.ArtworkDate == ArtworkDate).SingleOrDefault() != null;
}
</code>```

Some people I spoke to consider this to be repeating code, whereas I don't consider it to be repeating essentially because the repeating code are all things you would have to pass to a method anyway if you wanted to adopt another technique. I don't think it's possible this can be simplified, or broken up into a more simplified version any further, therefore it's not repeated code.

Is this a reasonable thing to say?

答:
If you don't intend to add any additional logic to those methods then yes, you're duplicating code. You're better off with BasketItems.Any(c => /* insert condition here */).

However, if you have lots of places in code where you use it you could do something like this:

```<code>public bool IsInBasket(List<BasketItem> basketItems, Expression<Func<BasketItem, bool>> filter)
{
    return basketItems.Any(filter.Compile());
}
</code>```

Title: Is this considered repeating code?

Body:
If you don't intend to add any additional logic to those methods then yes, you're duplicating code. You're better off with BasketItems.Any(c => /* insert condition here */).

However, if you have lots of places in code where you use it you could do something like this:

public bool IsInBasket(List<BasketItem> basketItems, Expression<Func<BasketItem, bool>> filter)
{
    return basketItems.Any(filter.Compile());
}


答:
No, it's not repeated code; it's using polymorphism to allow callers to use two different overloads.

If the code were longer in each method, I would refactor the common parts into their own method, but the linq statements are already sufficiently terse (assuming you use Any() as suggested by others).

ContentLicense: CC BY-SA 3.0

Title: Is this considered repeating code?

Body:
C#/ASP.net:

```<code>/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return BasketItems.Where(c => c.GroupID == GroupID).SingleOrDefault() != null;
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
    return BasketItems.Where(c => c.GroupID == GroupID && c.ArtworkDate == ArtworkDate).SingleOrDefault() != null;
}
</code>```

Some people I spoke to consider this to be repeating code, whereas I don't consider it to be repeating essentially because the repeating code are all things you would have to pass to a method anyway if you wanted to adopt another technique. I don't think it's possible this can be simplified, or broken up into a more simplified version any further, therefore it's not repeated code.

Is this a reasonable thing to say?


问:
How do I handle refactoring that takes longer than one sprint?
I work with a code base that is over 500K lines of code. It is in serious need of refactoring. There have been refactoring efforts identified that will take longer than the normal two week sprint. These can't be broken up into smaller tasks as I have seen suggested in other answers on this site. The product needs to work at the end of the iteration, and partial refactoring will leave the system in an unusable state as the dependency between items is horrible. So what would be the best way to approach this hurdle? Again I mention, breaking it down into smaller pieces is is not an option, that has already been done.

Update:
People seem to need an explanation of why this can't be fit into a 2 week sprint. There is more involved in a sprint than just writing code. We have a policy of no code without tests. That policy did not always exist and a large portion of the codebase does not have them. Also some of our integration tests are still manual tests. The issue is not that the refactoring itself is so large. It is with the fact that small changes have an effect on many parts of the system, and we need to ensure that those parts still operate correctly.

We can't put off or extend a sprint because we have monthly hotfixes. So this change extending past a sprint cannot stop the other work being added to the hotfix.

Refactoring vs Redesign:
Just because our development process is not efficent enough to handle this refactoring in a two week cycle does not warrant renaming it to a redesign. I would like to believe that in the future we could accomplish the exact same task within a two week cycle as our process improves. The code in question here has not had to change in a very long time, and is quite stable. Now, as the direction of the company is becoming more adaptable to change, we want this portion of the code base to be as adaptable as the rest. Which requires refactoring it. Based on the answers here, it is becoming apparent that there is missing scaffolding necessary to make this refactoring work in the time frame of normal sprints.

Answer:

I am going to do the branch and merge approach that Corbin March suggested the first time so we can learn more about these problem areas and how to identify the missing tests. I think moving forward, we should take the approach that Buhb suggested of identifying the areas that are missing tests and implement those first, then do the refactoring. It will allow us to keep to our normal two week sprint cycle, just like many here have been saying should always be the case for refactoring.

答: Dedicate one sprint to figuring out how to keep the code functioning properly mid-refactor.  This can take the form of deprecated methods and classes, wrappers, adapters, and the like.  Your refactoring may make the code dirtier for a short time in order to be cleaner long-term; that's OK.  Right now you're saying it can't be done.  I don't think that's right - think about what your process would be like if it could be done, think about what steps you can take to make it so.  Then dive in.


问:
What are the absolute, minimal requirement for containing SE Asian charsets for an embedded system project?
I work for a company that has begun integrating embedded computer systems into our products that we manufacture.  We have a pretty wide range of products and they are distributed across the globe.  Additionally, we've designed a few integrated boards that can serve multiple purposes depending on the firmware that has been flashed to the system.  This way we don't have to redesign our computer hardware for our various products-- all we have to do is re-write the firmware layer to meet the specific product's needs.

Because of these hardware limitations, changing our hardware takes an act of congress but writing new software is much simpler.

One of our products has a new requirement that we haven't had to previously implement, which is the need for user-inputted text.

Currently, we've been able to store international text in resources and only the necessary font characters are compiled to bit-mapped images.  This means that we've been able to store highly-ideographic languages like Chinese and Japanese text in a minimal amount of space because we only use a very small percentage of the entire language set.

Since this new product will require that our users input text, we will have to implement an extensive character set.  As primarily a PC developer, I'm quite familiar with ASCII, Unicode, UTF-8, etc., however, implementing a full character set of any of these languages isn't feasible because we have a limited amount of FRAM on the board to store the font data.

My management is hoping that there is a minimal character set that can be used for highly ideographic languages.  I believe there is a phonetic alphabet for Japanese (the Hiragana?)  Are there similar phonetic alphabets for the Chinese, Korean, Vietnamese, etc. languages as well and, if so, could speakers of these languages communicate with such a narrow character set?  I'm pretty sure the answer to that question is "absolutely, no" but it's a question worth asking.

Management has set a "soft" requirement that we can only have a limited character set of about 8,000 characters covering all major languages in common use.  If this is not possible, we need to look for some form of alternative method for meeting our needs based off of our limited hardware resources.

I'm sure this problem has had to have been solved before.  Does anyone have experience working within such constraints while needing an extensive font and character encoding system?  If so, what nuggets of wisdom can you offer?

答:
This is an excellent question.

To tackle your answer one language at a time;

Vietnamese

Vietnamese is not using ideographic characters anymore, but its Latin set is quite wide: look at the example to see how many diacritics it uses:

Tiếng Việt, hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam. Đây là tiếng mẹ đẻ của khoảng 85% dân cư Việt Nam, cùng với gần ba triệu người Việt hải ngoại, mà phần lớn là người Mỹ gốc Việt. Tiếng Việt còn là ngôn ngữ thứ hai của các dân tộc thiểu số tại Việt Nam.

The reason is that every Vietnames syllable has one of six tone marks that impact pronouncing — in addition to having one non-standard consonant glyph and six non-standard vowels.

Unicode composes tone marks over vowels; if you have an ability to compose glyphs, you'll only need 13 extra glyphs for Vietnamese, but if not, you'll need 1 extra consonant + 12 vowels * 6 tones + 6 new vowels toneless = 79 extra glyphs, in downcase and uppercase.

Korean

Korean is bad news. Korean is written though an alphabet called Hangul, which, while technically being an alphabet of only 68 letters (called jamo), is actually written in syllable-sized blocks, constructed out of jamo.

An example of how Korean text looks:

한글 또는 조선글은 한국어의 고유 문자로서, 1443년 조선 제4대 임금 세종이 훈민정음(訓民正音)이라는 이름으로 창제하여 1446년에 반포하였다. 이후 한문을 고수하는 사대부들에게는 경시되기도 하였으나, 조선 왕실과 일부 양반층과 서민층을 중심으로 이어지다가 1894년 갑오개혁에서 한국의 공식적인 나라 글자가 되었고, 1910년대에 이르러 한글학자인 주시경이 '한글'이라는 이름을 사용하였다.

Unicode has 11,172 completed block characters — but if you're willing to code the logic to compose the final “blocks” yourself, you can save on character set greatly.

Basically, all syllables can be split in two categories — consonant+vowel and consonant+vowel+final, where final can be a vowel, a consonant or a composite. CV syllables are constructed with C on left and V on right; CVF consonants are composed with CV block on top (left-to-right), and final on bottom.

So, basically, you need:

19 initials, in two forms

21 medials, in two forms

28 finals

for a total of 108 symbols. (I'm not absolutely sure there are no “ligatures” in Korean, so that sometimes a constructed block looks different than the combination of components, but that's the best we'll get for now).

Japanese

As you've correctly noticed, Japanese has a phonetic alphabet — but actually, not just one, but two! Hiragana and Katakana are syllabaries, both with 48 of the same syllables, but used in different contexts (katakana is used for foreign words, hiragana is used for grammar).

Sadly (for our purposes), Japanese is almost impossible to fully write using only these two alphabets — Chinese characters, or kanji, as they're known in this context, are essential to any Japanese text.

Obligatory writing example:

仮名（かな）とは、漢字をもとにして日本で作られた文字のこと。現在一般には平仮名と片仮名のことを指す。表音文字の一種であり、基本的に1字が1音節をあらわす音節文字に分類される。漢字に対して和字（わじ）とも言う。ただし和字は和製漢字を意味する事もある。

Besides kanji, you'll need 103 glyphs to map two phonetic alphabets + 7 common kanji that do not exist in Chinese.

CKJ Punctuation

Not an expert on this one, but both Chinese and Japanese use classical, East Asian punctuation. Unicode has 64 symbols dedicated to CJK punctuation and symbols.

Chinese

So, we have 7631 characters remaining in our “budget”. Will it be enough to cover Chinese characters?

漢字為上古時代的華夏族人所發明創製並作改進，目前确切歷史可追溯至約公元前1300年商朝的甲骨文、籀文、金文。再到秦朝的小篆，發展至漢朝隸變，至唐代楷化為今日所用的手寫字體標準——正楷。汉字是迄今为止连续使用时间最长的主要文字，也是上古时期各大文字体系中唯一传承至今的文字，期間東亞諸國都有一定程度地自行創製漢字。

With over 100,000 characters in existence, it is essentially impossible to fully cover Chinese characterset, the actively used subset is much smaller. 2000-3000 characters are said to be enough for general literacy (HSK, TOEFL-like test of Mandarin Chinese, requires knowledge of 2800 characters for its highest level, HSK Advanced), 4000-5000 characters are enough for an educated person.

Keeping in mind that there are Simplified and Traditional characters (former are used in PRC, latter - in Taiwan), which differ for a lot of characters, remaining 7600 symbols, I'd say, would be just enough to cover most use cases for both charactersets.

Feel free to ask if you have any questions!


问:
How to handle "can you add just a few more fields" type of requests from customers?
Very commonly we have feature requests for fields that only one customer wants. This, at best, clutters the application's code. Often when we look in their database a few months after adding the fields, we can see that they are not actually even using the extra fields. Also, it's quite an old application so adding a single field requires multiple code changes, changing reports, and making sure that it doesn't affect other customers who do not need to see the field.

How can we make sure that a customer actually needs these feature requests?

How do we politely say "you don't really need that"?

Currently we are beginning to charge for certain feature requests. (Previously, feature requests were free usually) Is there anything else we can do?

答:
If the customer has total ownership of the application, then do what they ask. Let them blow their money; it's theirs.

However, if you don't then you want to go to a solution for these auxiliary fields that involves storing them outside of the core datamodel. You can then use something like a database view to merge the extra fields back in for this particular customer. (There are a few ways to do the auxiliary store, depending on what the nature of the data being stored is; the simplest is just a table that has the same primary key as some PK in your main table, but that's inefficient when the use of the field is very sparse. It's only truly a problem when they want features of the field that require things like indexing.)

You can also put off the customers' requests saying that you've not got sufficient resources to implement them at this stage. It really helps if at that point you point to your roadmap which says (your best estimate at) when it will become possible to implement what they want cheaply. And you should prioritize getting the application into a state where it becomes possible to support the features cheaply, as that meta-feature becomes a core selling feature of your main application.


答:
Technically, it is repeated code.  However, where your colleagues are mistaken is in thinking that repeated code is always bad.  In this case, the clarity the repetition adds far outweighs the harmful aspects of repetition, such as creating multiple points of failure.  Taking any design heuristic to extremes is unlikely to produce the best design.  You have to understand the reasons behind the heuristic.

Now, if you had pages of these functions, each with slightly different combinations of criteria, then the DRY rule becomes the dominant factor.  The trick is to recognize the balance point and refactor your code when it grows like that.

On a side note, I wanted to point out that when you repeatedly pass the same object as the first argument to a static function, that's a good sign it would probably fit better as an instance method, i.e. basketItems.isInBasket(groupID).

Title: Is this considered repeating code?


答:
I didn't put this in a compiler, but, ideally, when you do overloading, you don't duplicate code from one method to another.

You code the complete method, and each overload calls it, passing nulls where it doesn't have parameters, and you end up with something like:

```<code>/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    //return BasketItems.Where(c => c.GroupID == GroupID).SingleOrDefault() != null;
    return isItemInBasket(BasketItems, GroupID, null)
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Where(c => c.GroupID == GroupID && (ArtworkDate.HasValue ? c.ArtworkDate == ArtworkDate.Value : true)).SingleOrDefault() != null;
}
</code>```

When you end up with more and more overloads, you only need to change the one complete method (albeit more complicated method).  And each of your other methods are just wrappers, removing duplication.

Title: Is this considered repeating code?

Body:
I didn't put this in a compiler, but, ideally, when you do overloading, you don't duplicate code from one method to another.

You code the complete method, and each overload calls it, passing nulls where it doesn't have parameters, and you end up with something like:

/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    //return BasketItems.Where(c => c.GroupID == GroupID).SingleOrDefault() != null;
    return isItemInBasket(BasketItems, GroupID, null)
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Where(c => c.GroupID == GroupID && (ArtworkDate.HasValue ? c.ArtworkDate == ArtworkDate.Value : true)).SingleOrDefault() != null;
}

When you end up with more and more overloads, you only need to change the one complete method (albeit more complicated method).  And each of your other methods are just wrappers, removing duplication.


答:
It is very borderline. I'm not fond of the unit tests you'd have to write.

I would rather see a method on the BasketItem which reads

```<code>public bool isInBasket(int GroupID, DateTime? ArtworkDate)
{
    return this.GroupID == GroupID &&
           this.ArtworkDate == ArtworkDate ?? this.ArtworkDate;
}
</code>```

And then

```<code>/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return isItemInBasket(BasketItems, GroupID, null);
}

public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Any(c => c.isInBasket(GroupID, ArtworkDate)) != null;
}
</code>```

I might go further and put an interface on BasketItem so that I can put fake responses on these tests.

All that said, I wouldn't fail you on a code review for your code, I'd just warn you that if it got more complicated then it would be a problem.

Edit: Actually, reading that back, I've just noticed that it demonstrates the point. Because now it doesn't make sense. This forces me to reconsider my naming.

```<code>public bool isInGroup(int GroupID, DateTime? ArtworkDate)
{
    return this.GroupID == GroupID &&
           this.ArtworkDate == ArtworkDate ?? this.ArtworkDate;
}
</code>```

And then

```<code>/// <summary>
/// Is a group in the basket already? (do I even need this comment any more?)
/// </summary>
public static bool isGroupInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return isItemInBasket(BasketItems, GroupID, null);
}

public static bool isGroupInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Any(c => c.isInGroup(GroupID, ArtworkDate)) != null;
}
</code>```

Further Edit: Actually, the further we go down this road, the more I think I see the problem. Everyone, myself included, who feels it is duplicated is reacting to the method overload, which instinctively should be one method calling another.

But in reality, the second method is doing something very, very different. And the fact that none of us can understand what that ArtworkDate field is for suggests that maybe the name of the second method should be changed. isGroupInBasketAnd...What?

I think that you see the code as non-duplicated because you know how different it is, but everyone else looks, sees the same name and thinks it's just a standard overload, a bit of syntactic sugar.

Title: Is this considered repeating code?

Body:
It is very borderline. I'm not fond of the unit tests you'd have to write.

I would rather see a method on the BasketItem which reads

public bool isInBasket(int GroupID, DateTime? ArtworkDate)
{
    return this.GroupID == GroupID &&
           this.ArtworkDate == ArtworkDate ?? this.ArtworkDate;
}

And then

/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return isItemInBasket(BasketItems, GroupID, null);
}

public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Any(c => c.isInBasket(GroupID, ArtworkDate)) != null;
}

I might go further and put an interface on BasketItem so that I can put fake responses on these tests.

All that said, I wouldn't fail you on a code review for your code, I'd just warn you that if it got more complicated then it would be a problem.

Edit: Actually, reading that back, I've just noticed that it demonstrates the point. Because now it doesn't make sense. This forces me to reconsider my naming.

public bool isInGroup(int GroupID, DateTime? ArtworkDate)
{
    return this.GroupID == GroupID &&
           this.ArtworkDate == ArtworkDate ?? this.ArtworkDate;
}

And then

/// <summary>
/// Is a group in the basket already? (do I even need this comment any more?)
/// </summary>
public static bool isGroupInBasket(List<BasketItem> BasketItems, int GroupID)
{
    return isItemInBasket(BasketItems, GroupID, null);
}

public static bool isGroupInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate)
{
    return BasketItems.Any(c => c.isInGroup(GroupID, ArtworkDate)) != null;
}

Further Edit: Actually, the further we go down this road, the more I think I see the problem. Everyone, myself included, who feels it is duplicated is reacting to the method overload, which instinctively should be one method calling another.

But in reality, the second method is doing something very, very different. And the fact that none of us can understand what that ArtworkDate field is for suggests that maybe the name of the second method should be changed. isGroupInBasketAnd...What?

I think that you see the code as non-duplicated because you know how different it is, but everyone else looks, sees the same name and thinks it's just a standard overload, a bit of syntactic sugar.


答: Not every task can be done in an (artificial) 2-week sprint, so common sense is called for. If it can't be broken down any more, and it must be done, just get on and do it. The process is not more important than the end result, and should be seen as a guideline rather than a never-to-be-broken law.</p>

Title: How do I handle refactoring that takes longer than one sprint?

Body:
I work with a code base that is over 500K lines of code. It is in serious need of refactoring. There have been refactoring efforts identified that will take longer than the normal two week sprint. These can't be broken up into smaller tasks as I have seen suggested in other answers on this site. The product needs to work at the end of the iteration, and partial refactoring will leave the system in an unusable state as the dependency between items is horrible. So what would be the best way to approach this hurdle? Again I mention, breaking it down into smaller pieces is is not an option, that has already been done.

Update:
People seem to need an explanation of why this can't be fit into a 2 week sprint. There is more involved in a sprint than just writing code. We have a policy of no code without tests. That policy did not always exist and a large portion of the codebase does not have them. Also some of our integration tests are still manual tests. The issue is not that the refactoring itself is so large. It is with the fact that small changes have an effect on many parts of the system, and we need to ensure that those parts still operate correctly.

We can't put off or extend a sprint because we have monthly hotfixes. So this change extending past a sprint cannot stop the other work being added to the hotfix.

Refactoring vs Redesign:
Just because our development process is not efficent enough to handle this refactoring in a two week cycle does not warrant renaming it to a redesign. I would like to believe that in the future we could accomplish the exact same task within a two week cycle as our process improves. The code in question here has not had to change in a very long time, and is quite stable. Now, as the direction of the company is becoming more adaptable to change, we want this portion of the code base to be as adaptable as the rest. Which requires refactoring it. Based on the answers here, it is becoming apparent that there is missing scaffolding necessary to make this refactoring work in the time frame of normal sprints.

Answer:

I am going to do the branch and merge approach that Corbin March suggested the first time so we can learn more about these problem areas and how to identify the missing tests. I think moving forward, we should take the approach that Buhb suggested of identifying the areas that are missing tests and implement those first, then do the refactoring. It will allow us to keep to our normal two week sprint cycle, just like many here have been saying should always be the case for refactoring.


答: Start a maintenance window during which no further development is performed. Perform the redesign, then resume development sprints. </p>


问:
How to deal with potential enterpreneur developer in a IT startup
In a software startup, how can we deal with the main developers/programmers of the company who are good at design and communication, and also have entrepreneurial skills?

How do we get them work for us and avoid any kind of competition from them to our business?

How can we convince the lead programmer that our startup is the place for him?

答:
If you see these people as both a software developer and a sales developer, you should give them the opportunity to make a good salary and have equity in your company. Going on their own is a risk that you can help them avoid.

Those that are really good programmers with no apptitude or interest for sales or understanding of your domain, I'd call their bluff. Nothing better than a competitor that doesn't know what they're doing.


答:
Lots of cash, and make sure that as a good manager you handle anything he doesn't want to deal with. Specifically, if you ask him to do something and he says he doesn't want to, then say ok and get someone else to do it. If you think that's primadonna/cowboy/immature behavior, you'll be right, and you'll also be looking for someone else to replace him when he leaves.

The top-notch developer is in high demand so you need to be extra nice to him. Imagine you just hired Tom Hanks to work on your movie, and you're going to make $500,000,000, so if Tom Hanks wants a bottle of french sparkling water, you're gonna jump and go get it for him. Treat your developer like that, and he'll want to work for you.

If you don't want to do that, you've condemned yourself to making B movies and software.

Title: How to deal with potential enterpreneur developer in a IT startup

Body:
In a software startup, how can we deal with the main developers/programmers of the company who are good at design and communication, and also have entrepreneurial skills?

How do we get them work for us and avoid any kind of competition from them to our business?

How can we convince the lead programmer that our startup is the place for him?


问:
Should I understand SVN before I jump to GIT?
I work in a department where no one has ever used source control before, including myself.

I am trying to push the concept. I have spent a little while researching SVN. I some basics learned. I can Create/update/checkout/commit with command line and from Tortoise. I am starting to learn how to tag and branch but still confused a lot about conflicts between branches and trunk etc. I am still learning, but I do not have a physical person who can show me anything. Its all from books/tutorials and trial and error.

From what I have read online it seems like git is the better thing to know, but its also more complicated. I don't want to overwhelm myself. Should I continue to master svn before moving to git or would I be wiser to just jump to git now?

Are there pros and cons to both approaches?

答:
Wow; 12 answers and everyone is still begging the question...

No, Subversion is not a prerequisite for Git.

There is no clean mapping between Subversion and Git -- if you plan to learn both, you will just have to suffer through the fact that they use the same terms for different actions. (And different terms for the same actions.)

svn commit is a different thing than git commit.

branches in svn and git are very different

an svn repository is more like a git remote (but not really)

a git repository is more like an svn working copy (but not really)

These are two tools divided by a common language.

Your question, and most of the other answers, presume that git is some kind of svn++; A "better svn". It isn't. The two are different tools that work in the same space, like a car and a motorcycle.

I would suggest that you pick one, master it, and start using it on your team. Learning version control is going to be hard for people who have not used it before. Your VCS is going to be an important part of your infrastructure, and learning to trust it involves building new work habits. That takes a while.

(Either way, make sure you have your sysadmins back up the master repository -- losing your source control would be catastrophic.)

ContentLicense: CC BY-SA 2.5


问:
How do you prevent the piracy of your software?
Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>

答:
Yes it is still useful, but don't spend to much time and money on that. If your software worth it, it will be purchased AND cracked. Regardless the efforts you put in the protection mechanism.

Too much protection as well as no protection will affects sales.


答:
We have two types of works at our hand:

Man-hour works

Genius works

Refactoring usually consists of the first type of work, since a lot of methods are known already to developers like DRY, SRP, OCP, DI, etc. Thus when a project takes two months to be refactored, it simply takes two months, there is no way around it. Thus, my suggestion would be to not refactor the original project, and let it work on its current situation. Stop receiving new requests and requirements from stakeholders and product owner. Then let the team work on the project till it gets refactored and ready to go.


问:
Any best practices for a distributed agile team?
Our scrum teams are split geographically (not ideal I know!) due to specific knowledge only being available in certain countries.
So one team of say 7 members, has the business person in one city, 2 devs in another, 2 other devs in another and 2 qa's in another.

Any suggestions for how to manage this type of graphically dispersed team? Any best practices?

How do you do standups? via skype video? do we ensure that people travel every 6 weeks (the half time of trust apparently)? how do we do the task board? Virtually or via video?
would kanban work better in this setup?

答:
Our team had a similar situation, we had 2 developers that worked remotely, in different states.

For planning, we had an all day remote meeting with everyone in the team that could be together work together in the same room, then we would share desktops with the remote folks.

Our scrum wall was through Excel. We would break PBI's down together and then add them to the excel sheet. This process was pretty tedious and sometimes it would cause people to drift off. The hardest part was getting everyone's participation.

Our stand ups are getting everyone that can get together in a meeting room with a speaker phone, then sharing an excel based burn down sheet and everyone giving their update. This would also be put on a scrum wall in that meeting room for the larger group that was together. For the devs on the phone, we would place their tasks on the wall, but just have someone move them when they give updates.

There are virtual task boards that are available for purchase, so I encourage you to look at that. We had contractors from Avanade that had created one and licensed us to use it, we tried it but ultimately gave it up.

I hope this helps.


答:
Assuming you are using .net 4.0. You end up with just one method with an optional parameter</p>

```<code>public static bool IsItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate = null)
{
    var artWorkDate = ArtworkDate ?? DateTime.Now;
    return BasketItems.Any(c => c.GroupID == GroupID && c.ArtworkDate == artWorkDate);
}
</code>```

Title: Is this considered repeating code?

Body:
Assuming you are using .net 4.0. You end up with just one method with an optional parameter

public static bool IsItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime? ArtworkDate = null)
{
    var artWorkDate = ArtworkDate ?? DateTime.Now;
    return BasketItems.Any(c => c.GroupID == GroupID && c.ArtworkDate == artWorkDate);
}


问:
Is it a bad practice to stop providing support for outdated software if updates are free and easy?
Providing support for outdated software is both unexciting and expensive. If people are still using the version which was sold ten years ago, it means that they will find bugs which do not exist in next versions, their software may not work as expected on a new hardware or operating system, etc. The support people must also be trained to use this old version.

This is unavoidable in several cases:

When every next version of the software is paid, you can't force everyone to spend their money every two years to buy the next version. Example: Microsoft has still to support Windows XP, since it is understandable that people don't want to pay hundreds of dollars for Windows Vista, then Seven, then Windows 8.

When the update is complicated. Example: when you know that installing SP2 of Microsoft SQL Server 2008 may render your server completely unusable, you may want to postpone installing updates and stay with and outdated version which has one strong point: it works.

When legacy systems or security considerations are involved. Example: auto-updating a space shuttle software every week may have some disadvantages. In the same way, you can't update hardware if the legacy software requires the old hardware to run.

Now, let's say that the update process is as well done as in Google Chrome. The user doesn't have to bother with the updates; there are no security or legacy reasons to not to update, and the updates are free.

In this case, is it a bad practice, for a company, to stop providing any support for the versions outdated for a few months, and ask their customers to update their software first, then contacting the support if the problem persists?

答: I personally think you need to announce, in advance (at least one year, but three is better) that you will discontinue support. It would also be good to say, with version of the software being sold, what the expected support horizon looks like. Unbuntu is like that. </p>


答: To be honest with you, I thought about 10 minutes, and I didn't find any problem with stopping support for outdated versions and asking users to update. It's just too logical to have a problem with. I mean, new version is free, and what's better than using something free of charge?

Title: Is it a bad practice to stop providing support for outdated software if updates are free and easy?

Body:
Providing support for outdated software is both unexciting and expensive. If people are still using the version which was sold ten years ago, it means that they will find bugs which do not exist in next versions, their software may not work as expected on a new hardware or operating system, etc. The support people must also be trained to use this old version.

This is unavoidable in several cases:

When every next version of the software is paid, you can't force everyone to spend their money every two years to buy the next version. Example: Microsoft has still to support Windows XP, since it is understandable that people don't want to pay hundreds of dollars for Windows Vista, then Seven, then Windows 8.

When the update is complicated. Example: when you know that installing SP2 of Microsoft SQL Server 2008 may render your server completely unusable, you may want to postpone installing updates and stay with and outdated version which has one strong point: it works.

When legacy systems or security considerations are involved. Example: auto-updating a space shuttle software every week may have some disadvantages. In the same way, you can't update hardware if the legacy software requires the old hardware to run.

Now, let's say that the update process is as well done as in Google Chrome. The user doesn't have to bother with the updates; there are no security or legacy reasons to not to update, and the updates are free.

In this case, is it a bad practice, for a company, to stop providing any support for the versions outdated for a few months, and ask their customers to update their software first, then contacting the support if the problem persists?


答: I recommend starting with the book Working Effectively with Legacy Code, by Michael Feathers. He covers a variety of techniques to reduce the scope of refactoring-style changes.</p>


答:
Not really.  Any copy protection has to be 100% perfect, (which we all know is impossible,) or else all it will take is for one person anywhere in the world to come up with a working crack and post it on the Web.

If you want people to pay money for your product, copy protection is not the answer.  It never has worked and never will.  The answer lies in Economics 101: people will pay money for your product if they perceive its value to them as being greater than the price you are asking for it.  Otherwise, they won't.  Period.

Title: How do you prevent the piracy of your software?

Body: Is it still worth it to protect our software against piracy? Are there reasonably effective ways to prevent or at least make piracy difficult?</p>


答:
Just do a 3, 4 or 5 week sprint. Who cares? You're obviously convinced that nothing can be done in a shorter time-frame, so stop fighting it.

Just don't tell your fellows at The Royal Society of Blind Agile Adherance.


答: You might want to support versions n-2 and n-1 (or just n-1) along with version n where n is the current version, just to give people a bit of time to upgrade.  But you can't support something forever - it's just not realistic.  </p>


答:
I think it largely depends on how your software is being used.  If there is the chance that a user will incorporate your software in an automated system, be it a kiosk, a build script, a remote server, etc., then it is likely that those types of users will be resistant to upgrading no matter how "free" and "easy" it may seem to the developer.

The problem is that once software is entrenched in a mission critical[1] system, the risk of any change to a part of that system quickly mounts.  Any change has the possibility of breaking something which means that "free" is no longer free.

The original question tries to rule out this type of "legacy" or "security" issue, but doing so requires a big leap of faith in terms of predicting the way that the software will actually be used.  One only has to look at the number of strange Windows bugs that are maintained because various programs became dependent on the specific behavior to understand that real world use is not always usage as designed.

Having said all that, it probably comes down to more of a business decision than a programming one, barring the loss of critical information, resources, or code.  Does the financial benefit of providing or being able to provide support for an outdated version outweigh the cost of the capacity to provide that support?

[1]: as defined by the user


问:
Tutorial for getting started with bare bone rails
I am trying to pick up Rails, but there are a ton of things that it does that it's not under my control and that's scary (http://blog.zawodny.com/2011/06/13/i-actually-tried-learning-rails/). Is there a tutorial where it explains only the exact things you need to do in order to pick up the framework? (specs, controllers and views)</p>

答:
I've never gone through it, but a number of people that I know have used the Rails for Zombies tutorial. Those who put effort into it have had success with at least getting a basic handle on Rails. There's also another Ruby on Rails tutorial with books and screencasts that appears to be up-to-date with Rails 3.1. If those don't work out, there's also this list of Rails tutorials.

With the pace that Rails changes, I'm not sure exactly how up-to-date any of these are. You're probably going to want to keep an eye on that. I would suspect that it isn't too hard to learn one and get up-to-speed with the latest changes, but there might be problems if you are trying to running a different version than the tutorial covers.

As an aside, I would like to address two things, one from your post and another from the blog entry you linked to.

there are a ton of things that it does that it's not under my control and that's scary

Ruby on Rails emphasizes Convention over Configuration. This means that you give up control in order to make things easier. It's part of the "Rails way" of approaching a problem. If you have a desire to learn the Rails framework, you should also be learning and embracing the conventions of the framework.

I still think Ruby is a cool language and I’d like to tinker with it more. But Rails is not the best way to learn Ruby.

I don't know why you would learn Rails to learn Ruby. That's like saying learning ASP.NET MVC 3 is going to teach you C# or CodeIgniter is going to teach you PHP. Yes, you need to know a bit about Ruby to work with Rails, C# to work with ASP.NET MVC 3, and PHP to work with CodeIgniter, but there's a clear distinction between the language and the framework.


答:
If you set up the problem in the way you do by explicitly saying that there are no legacy reasons not to upgrade, everyone is going to agree that there is no reason to support older versions.  Eliminating legacy reasons not to upgrade, however, is much easier said than done.

Does the new version make any change to the UI?  If so, that may mean that the screen shots and screen recordings that a company has put together to show users how to perform a particular task need to be re-recorded.  That may mean that users have to spend some time adjusting to the new UI in order to do the same things they've always done.

Can you really guarantee that upgrades are risk-free?  You use the example of the SQL Server 2008 SP2 installer causing the server to become unusable.  Microsoft spent a lot more time and money testing the SP2 installer than most companies can afford to spend testing every possible configuration that might affect the installer.  SQL Server is an enterprise product so there is, generally, less variability in what people have installed on their servers than there is when you look at consumer boxes.  And there is a ton of time between SQL Server service packs so there is little rush to get software out the door.  And yet, in your example, Microsoft still failed to deliver.  That should demonstrate how difficult it is to ship a 100% risk-free upgrade even if everything lines up in your favor.  And even if you could deliver a completely 100% risk-free upgrade, how does your customer know that your upgrades, unlike every other upgrade they have to deal with, are risk-free?

Does the new version make any changes to existing functionality?  Even if you're just fixing a bug, once you have enough customers, it's likely that someone somewhere will depend on that buggy behavior.  Think of all the sites, for example, that have been optimized for some version of some browser that don't work or look terrible when the bugs in the old browser's handling of some HTML element are fixed.

If you recognize that there are valid legacy reasons not to upgrade, you're well within your rights to make a policy decision that ease of maintenance and streamlining support outweighs the legacy needs of customers.  Whether that is the right decision will, of course, depend on how large the legacy problems are and how costly it is to support old versions. But you're much more likely to make the right trade-off if you approach the problem by assuming that there are many sources of legitimate legacy issues and figuring out how to quantify those issues than if you start from the assumption that there are no legacy issues.


答:
Its not inherently bad practice, no.  For my software, I only make 'fixes' for the current release.  I'll help a user of an older version if there's a work-around.  But I wont make code changes.  Worst case, I'll give the user an upgrade to the new version.

But it really depends on the nature of your software and what support promises/contracts you have.  Supporting only the current version may not be acceptable for certain software used by organizations.  But for consumer grade software, its fine.

When it comes to free software (Chrome), its definately not bad practice.  They are doing the user a favor by offering software for free.  They owe the end user nothing.


答:
I think what you are looking for here is a proper release and support process.

Obviously, all this needs to be defined according to your goals and market (eg, Consumer vs Enterprise).

First of would be setting up a proper Product Lifecycle for released software. For example you might want to have stages such as:

Generally Available - Able to be purchased, actively marketed, supported.

End of Marketing - Available on request, supported

End of Life - No longer Available, no longer supported (except under exceptional cases)

You will want to have a known process where by moving a product from one stage to the next is announced a certain amount of time in advance. In some cases and depending on contracts, this would be a legal requirement.

As pointed out by Scott's answer where by version n is GA, n-1 is EOM and n-2 is EOL. Adjust this according situation (eg, more previous versions still only in EOM).

From here, you would probably want to set up some form of ongoing maintenance agreement. That is to say, after someone purchases a product they are support for period 'x'. To remain supported they must pay an ongoing fee. There are several strategies for how to handle this fee and product upgrades, including:

Constant maintenance fee (such as % of original price)

Constant maintenance fee until period 'y' after a new release, then increasing 'z'% each period

Free upgrades

Discounted upgrades

Full price upgrades

There are several benefits in this for you. Firstly, it gives you a ongoing revenue stream that helps pay for support. Secondly, it can encourage your users to upgrade to newer versions.

Ultimately, it does highly depend on your situation, but it is almost always universally true that you should

Have a plan in place

Make sure your customers are aware of the plan

Have it in the contracts

Follow the plan

Lest you be accused of bad practice.


答:
This really depends on the circumstance. I think you can use your common sense to decide when it makes sense.

In most circumstances, I would say that giving old versions support for one year would be appropriate, as long as you make sure that the customer understands this.

I would also say that you should provide full support to the upgrade process from a version that is up to 5 years old or more.

Ie. you should support old versions enough to be able to upgrade them to a version that you can support. If you can't support the upgrade, you need to support the old version.


问:
I'm writing about language syntax. Is there a language out there in which parameters are placed inside method name?
in JavaScript:

function getTopCustomersOfTheYear(howManyCustomers, whichYear) {
   // Some code here.
}
getTopCustomersOfTheYear(50, 2010);
```

<p>in C#:</p>

<pre class="lang-cs prettyprint-override"><code>public List<Customer> GetTopCustomersOfTheYear(int howManyCustomers,
 int whichYear)
{
   // Some code here
}
List<Customer> customers = GetTopCustomersOfTheYear(50, 2010);
</code>```

in PHP:

public function getTopCustomersOfTheYear($howManyCustomers, $whichYear)
{
   // Some code here
}
$customers = getTopCustomersOfTheYear(50, 2010);
```

<p>Is there any language out there which support this syntax:</p>

<pre class="lang-c prettyprint-override"><code>function GetTop(x)CustomersOfTheYear(y)
{
    // Some code here
}
returnValue = GetTop(50)CustomersOfTheYear(2010);
</code>```

Isn't it more semantic, more readable form of writing a function?

Update: The reason I'm asking this question is that, I'm writing an article about a new syntax for a new language. However, I thought that having such syntax for declaring methods could be nicer and more friendly to developers and would decrease learning-curve of the language, because of being more closer to natural language. I just wanted to know if this feature has already been contemplated upon or not.

答:
While not a programming language per se, Cucumber takes parameters in the middle of function names, which can include spaces and are meant to look like English.

The 'functions' are defined in Ruby however

# definition
Given /^I calculate (.*) times (.*)$/ do |x, y|
    @result = x.to_i * y.to_i
end

Then /^the result should be (.*)$/ do |v|
    @result.should == v.to_i
end

# usage
Scenario:
    Given I calculate 6 times 9
    Then the result should be 42
```


答:
This depends on your definition of "language", but the robotframework testing framework lets you define keywords this way. From their documentation on embedded arguments:

```<code>Select ${animal} from list | Open page | pet selection
                            | Select item from list | animal_list | ${amimal}
</code>```

The above declares a new keyword (essentially a function) named "select ${animal} from list" where '${animal}' is a parameter. You call it like "select cat from list"

Title: I'm writing about language syntax. Is there a language out there in which parameters are placed inside method name?

Body:
in JavaScript:

function getTopCustomersOfTheYear(howManyCustomers, whichYear) {
   // Some code here.
}
getTopCustomersOfTheYear(50, 2010);
```

<p>in C#:</p>

<pre class="lang-cs prettyprint-override"><code>public List<Customer> GetTopCustomersOfTheYear(int howManyCustomers,
 int whichYear)
{
   // Some code here
}
List<Customer> customers = GetTopCustomersOfTheYear(50, 2010);
</code>```

in PHP:

public function getTopCustomersOfTheYear($howManyCustomers, $whichYear)
{
   // Some code here
}
$customers = getTopCustomersOfTheYear(50, 2010);
```

<p>Is there any language out there which support this syntax:</p>

<pre class="lang-c prettyprint-override"><code>function GetTop(x)CustomersOfTheYear(y)
{
    // Some code here
}
returnValue = GetTop(50)CustomersOfTheYear(2010);
</code>```

Isn't it more semantic, more readable form of writing a function?

Update: The reason I'm asking this question is that, I'm writing an article about a new syntax for a new language. However, I thought that having such syntax for declaring methods could be nicer and more friendly to developers and would decrease learning-curve of the language, because of being more closer to natural language. I just wanted to know if this feature has already been contemplated upon or not.

Body:
This depends on your definition of "language", but the robotframework testing framework lets you define keywords this way. From their documentation on embedded arguments:

Select ${animal} from list | Open page | pet selection
                            | Select item from list | animal_list | ${amimal}

The above declares a new keyword (essentially a function) named "select ${animal} from list" where '${animal}' is a parameter. You call it like "select cat from list"


问:
How to automate a tasks system in a CMS software
I'm currently developing v2.0 of my personal cms. However, I'm stuck. I strongly feel that my old solution for "tasks" is not very dynamic and must be revisited. Currently I'm looking the whole concept of how to dynamically add tasks and run them.

What I mean by task system

Like always in cms software, there are a lot of content, such as images, dynamic files, database entries, etc. I created my own task system aka. The Parser (sounds evil right?) It is made of two files, one parser-classes and other the triggers with the $parser = new ParserClasses(); (I hope you understand what I mean.) Some of the features the parser does:

First turn off the site (after the parser is done, turn it back on)

Checks for active files (files that don't have parent mysql entry, will be deleted)

Clears out old cache

Generates new static cache

Deals with languages and translation related cache

and other tasks related to cms management and maintenance

Why do I want to make it more automatic

Basically all plugins and some themes (add-ons in general,) use this task system. But the problem is that it's not very dynamical, because all functions sit in one huge class. This means that the add-on cannot be installed without opening your php editor.

How I was planning to do it

First I would create my own task language, with preset functions to handle files, cache,  etc. (very broad example: GenerateFreshCache('pages')). Now, storing it is the issue.. My ideas are:

To create tasks-table in mysql database. Then add tasks there, with my task language. Later while() them from the database and eval(). (This is a good way, because I can add scheduled times and similar in function, for CRON jobs. Or even categorize the tasks.)

Add .php files to some folder, where they get loaded. They will probably use the same task language, but don't need to be eval()'ed. (I'm scared that this would slow down the parser, because so many files are getting included.)

However, I'm not sure about those ideas and I'm hoping someone has already come across this functionality and can give me pointers. All crazy ideas and concepts are welcome, thanks in advance.

Conclusion

Thanks to everyone who replied. I picked the answer, that helped me the most and not "ohh, too much work, use framework". My task systems core is done and working. Took 2-3 days and currently ~600 lines of code and two classes (outer and inner core.) I finally ended up with two mysql tables, one with tasks (task db) and another with combos (multiple tasks combined together for easier run.) Also, added some features so it would be safe to run via ajax (cant really talk about that, top secret^^). There are might be too many loops, handling the tasks parsing, however this makes adding new tasks very very simple.. Just add it to tasks DB and add the task to cron-list-automatic-run-list or run it straight up via the admin panel.

答:
Each module can register callbacks to occur when you task system runs. Each module will have a file in it that your task system will include before running that will setup the callbacks.

/module.name/task.php

```<code>\Task\System::regster('startup', function()
{
    // do something
});

\Task\System::regster('shutdown', function()
{
    // do something
});
</code>```

/task.php

```<code>foreach($modules as $module)
{
    require($module . '/task.php');
}

\Task\System::run();
</code>```

Body:
Each module can register callbacks to occur when you task system runs. Each module will have a file in it that your task system will include before running that will setup the callbacks.

/module.name/task.php

\Task\System::regster('startup', function()
{
    // do something
});

\Task\System::regster('shutdown', function()
{
    // do something
});

/task.php

foreach($modules as $module)
{
    require($module . '/task.php');
}

\Task\System::run();


答:
Give it away :)

Given that virtually all anti-piracy measures can be circumvented if someone is determined enough there's an argument for not doing anything.

Make your software useful and offer support to those that pay, thus getting the revenue and dedicated users.

One way to get revenue could be to have a "pro" version that unlocks extra features that needs to be paid for. This seems to be a popular approach. You need to be make sure that the unlocking of the pro features is a) easy for the customer but b) hard for the hacker.


问:
Pointless Code In Your Source
I've heard stories of this from senior coders and I've seen some of it myself. It seems that there are more than a few instances of programmers writing pointless code. I will see things like:

Method or function calls that do nothing of value.

Redundant checks done in a separate class file, object or method.

if statements that always evaluate to true.

Threads that spin off and do nothing of note.

Just to name a few. I've been told that this is because programmers want to intentionally make the code confusing to raise their own worth to the organization or make sure of repeat business in the case of contractual or outsourced work.

My question is. Has anyone else seen code like this? What was your conclusion was to why that code was there?

If anyone has written code like this, can you share why?

答: Sometimes I'll have a global boolean set to true, and later in my code an if( bool ), then during runtime, I might set a breakpoint at the if statement, and switch the boolean to test something. </p>

Title: Pointless Code In Your Source


答:
In the project I am working for at the moment, we are using 4-week sprints. And sometimes we cannot finish a user story and we just restart it during the following sprint.

However, IMHO it should be possible to break up a refactoring into smaller stories that fit in a 4-week sprint. If you cannot bring the code into a consistent state within 4 weeks, I have the feeling that you are rewriting your application rather than refactoring it.


答: Have you used other web frameworks?  They all perform a lot of work before your code gets control.  The main difference is that the Rails API provides a lot more than methods to call.  Rails uses the dynamic features of Ruby to define DSLs for web components.  There is a language for controllers, and a language for domain objects, etc.  I have found the Rails documentation to be quite readable, but you do have to read it, and it may take you a little while to get into the Rails mindset.  However, when you do I think you will find developing with Rails to be quite enjoyable.</p>

Title: Tutorial for getting started with bare bone rails

Body: I am trying to pick up Rails, but there are a ton of things that it does that it's not under my control and that's scary (http://blog.zawodny.com/2011/06/13/i-actually-tried-learning-rails/). Is there a tutorial where it explains only the exact things you need to do in order to pick up the framework? (specs, controllers and views)</p>


问:
Implementing technical paper algorithms in C++ or MATLAB
I am an Electrical Engineering undergrad. I've reading many technical papers about Signal and Image processing algorithms (reconstruction, segmentation, filtering, etc). Most of the algorithms shown in these papers are defined over continuous time and continuous frequency, and often give the solutions in terms of complicated equations. How would you implement a technical paper from scratch in C++ or MATLAB in order to replicate the results obtained in said paper?

More specifically, I was looking at the paper "A general cone-beam reconstruction algorithm" by Wang et al (IEEE Trans Med Imaging. 1993;12(3):486-96), and I was wondering, how do I even start implementing their algorithm?
Equation 10 gives you the formula of the reconstructed image at . How would you code that up? Would you have a for-loop going through each voxel and computing the corresponding formula? How would you code functions of functions in that formula? How would you evaluate functions at arbitrary points?

I've read the book "Digital Image Processing" by Gonzalez and Woods but I'm still at a loss. I have also read about the Numerical Recipes book series. Would that be the correct way?

What are your experiences programming algorithms from research papers? Any tips or suggestions?

答:
Numerical methods.  It's usually a upper-division university course and textbook.

DSP is usually near the intersection of numerical methods and efficient implementation.  If you ignore efficiency, then what you might be looking for is any numerical approximation method that might produce an "accurate enough" result for the technical paper's equation(s) of interest.  Sometimes one might be dealing with sampled data, where the sampling theorems will put some bounds on both the data acquisition method (pre-filtering) and the range or quality of results you can get given that data.

Sometimes Matlab, numerical recipes, or various image/signal processing libraries will have efficient algorithms or code for the desired numerical solution.  But sometimes you may have to roll your own, so it helps to know the math behind various the numerical solution methods.  And that's a big subject in its own right.

OwnerDisplayName: Damian


答: A professor of mine related a story to us one day that a previous employer would pay them based on the number of lines that they completed. So, they wrote several multi-dozen lined functions that were never called. Seems like a great reason to write pointless code.</p>

Title: Pointless Code In Your Source

Body:
I've heard stories of this from senior coders and I've seen some of it myself. It seems that there are more than a few instances of programmers writing pointless code. I will see things like:

Method or function calls that do nothing of value.

Redundant checks done in a separate class file, object or method.

if statements that always evaluate to true.

Threads that spin off and do nothing of note.

Just to name a few. I've been told that this is because programmers want to intentionally make the code confusing to raise their own worth to the organization or make sure of repeat business in the case of contractual or outsourced work.

My question is. Has anyone else seen code like this? What was your conclusion was to why that code was there?

If anyone has written code like this, can you share why?


问:
Handling requests RESTfully?
There is a push in modern scripting frameworks to use RESTful request routing instead of a one-size-fits-all URL path routing.

```<code>respond('GET',    '/posts',       callback);
respond('POST',   '/post/create', callback);
respond('PUT',    '/post/[i:id]', callback);
respond('DELETE', '/post/[i:id]', callback);
</code>```

vs

```<code>respond('/posts',       callback);
respond('/post/create', callback);
respond('/post/[i:id]', callback);
respond('/post/[i:id]', callback);
</code>```

I must confess that I am still using the old-and-busted method where the resource is accessible at the given URL regardless of the request type.

Is there anything I'm missing by using the old format?

答: In my view what you are missing on, is the inherent architecture of a RESTful API. From an implementation point of view, the separation of request, resource and callback function, that REST imposes, encourages you to use an architecture which, by design, is clear and understandable. Separation of concepts in distinct parts is very important, especially when dealing with security-sensitive applications like web APIs. It reduces the complexity of development, testing and maintentance, and thus makes them quite easier to handle.</p>

Title: Handling requests RESTfully?


答:
Whether you know frameworks or not, I'd suggest using the RailsTutorial.org site.  It's a great start for newbies or those experienced with frameworks in other languages.

This is one of the best beginner resources because you can actually get from start to finish without show-stopping bugs.  It's been updated and just works with Rails 3.0 out of the box. The author Michael Hartl is updating it for 3.1 and the online version includes an addendum to convert the example over to 3.1 if you wanted to dive into that.

As far as giving up control, well I guess that's true, but it is used on a lot of product sites.  That's a trade-off for the power of Rails.  I'd suggest giving up that control unless you like writing frameworks from scratch. :)


问:
Is Silverlight only for eye-candy, or does it have a use in business?
Granted that Silverlight may make eye-popping websites of great beauty, is there any justification for using it to make practical web applications that have serious business purposes?  I'd like to use it (to learn it) for a new assignment I have, which is to build a web-based application that keeps track of the data interfaces used in our organization, but I'm not sure how to justify it, even to myself.

Any thoughts on this?  If I can't justify it then I will have to build the app using the same old tired straight ASP.NET approach I've used (it seems) a hundred times already.

答: I am expecting that in a few years, HTML5, CSS3, and modern JIT-enabled Javascript interpreter and other technologies like WebM and WebGL will outflunk both Flash and Silverlight. Rich web applications will be written directly in HTML/CSS and Javascript, instead of piggybacking on Flash/Silverlight plugins.</p>


答:
In our shop, when we have large refactoring or rewriting tasks that can't be completed in a release window, we leave the functionality as-is in the system.  But, we start on the new, refactored lego-block functions as time permits.  Eventually, we get to a state where we have enough lego-blocks done, that a sprint provides sufficient time to plug the lego blocks into the application and turn it on for the users.

More concisely, we break up or rework large functions using new names.  Then, at the end, we use our renamed, refactored work instead of the nasty old code.


问:
Mahout's Flexibility for generating recommendations
I am currently working on a system that will generate product recommendations like those on Amazon: "People who bought this also bought this.."

This is how I plan to do it:

Process the data using Apache Mahout and generate recommendations(data is stored in MySQL), currently item based only.

Apply a clustering algorithm to make cluster of users and then apply the association rules subjective to each cluster.

My questions are:

Will Mahout provide me enough flexibility to tweak the existing algorithms according to my needs. If yes, how?

Is there a better alternative like R?

答:
As I think we've already discussed in some detail on other threads -- yes you can do things like clustering and collaborative filtering in Mahout. How you do it depends on exactly what you want to do, and it's not entirely clear here. I don't know how you intend to use clustering with recommenders here nor what an association rule is in this context.

But it's open source, so it's the most flexible thing possible: you can make it do whatever you like. So I suppose "yes" is the first answer.

R is not a platform, so I don't think you can view it as somehow an alternative to Mahout.

OwnerDisplayName: samridhi


问:
How should I handle invalid user input?
I have been thinking about this issue for a while and I would be curious to have opinions from other developers.

I tend to have a very defensive style of programming. My typical block or method looks like this:

```<code>T foo(par1, par2, par3, ...)
{
    // Check that all parameters are correct, return undefined (null)
    // or throw exception if this is not the case.

    // Compute and (possibly) return result.
}
</code>```

Also, during the computation, I check all pointers before dereferencing them. My idea is that, if there is some bug and some NULL pointer should appear somewhere, my program should handle this nicely and simply refuse to continue the computation. Of course it can notify of the problem with an error message in the log or some other mechanism.

To put it in a more abstract way, my approach is

```<code>if all input is OK --> compute result
else               --> do not compute result, notify problem
</code>```

Other developers, among them some colleagues of mine, use another strategy. E.g., they do not check pointers. They assume that a piece of code should be given correct input and it should not be responsible for what happens if the input is wrong. Also, if a NULL pointer exception crashes the program, a bug will be found more easily during testing and have more chances of being fixed.

My answer to this is normally: but what if the bug is not found during testing and appears when the product is already being used by the customer? What is a preferred way for the bug to manifest itself? Should it be a program that does not perform a certain action, but can still continue to work, or a program that crashes and needs to be restarted?

Summarizing

Which of the two approaches to handling wrong input would you advise?

```<code>Inconsistent input --> no action + notification
</code>```

or

```<code>Inconsistent input --> undefined behaviour or crash
</code>```

Edit

Thanks for the answers and suggestions.
I am a fan of design by contract too. But even if I trust the person who has written the code calling my methods (maybe it is myself), there can still be bugs, leading to wrong input. So my approach is to never assume a method is passed correct input.

Also, I would use a mechanism to catch the problem and notify about it. On a development system, it would e.g. open a dialog to notify the user. In a production system it would just write some information to the log. I do not think that extra checks can lead to performance problems. I am not sure if assertions are enough, if they are switched off in a production system: maybe some situation will occur in production that had not occured during testing.

Anyway, I was really surprised that many people follow the opposite approach: they let the application crash "on-purpose" because they maintain that this will make it easier to find bugs during testing.

答:
You already have the right idea

Which of the two approaches to handling wrong input would you advise?

Inconsistent input --> no action + notification

or better

Inconsistent input --> appropriately handled action

You can't really take a cookie cutter approach to programming (you could) but you'd end up with a formulaic design which does things out of habit rather than from conscious choice.

Temper dogmatism with pragmatism.

Steve McConnell said it best

Steve McConnell pretty much wrote the book (Code Complete) on defensive programming and this was one of the methods that he advised that you should always validate your inputs.

I don't recall if Steve mentioned this, however you should consider doing this for non-private methods and functions, and only others where deemed necessary.

Title: How should I handle invalid user input?


答:
There should definitely be a notification, such as a thrown exception. It serves as a heads up to other coders who may be misusing code you wrote (trying to use it for something it wasn't intended to do) that their input is invalid or results in errors. This is very useful in tracking down errors, whereas if you simply return null, their code will continue along until they try to use the result and get an exception from different code.

If your code encounters an error during a call to some other code (perhaps a failed database update) which is beyond the scope of that particular piece of code, you really have no control over it and your only recourse is to throw an exception explaining what you know (only what you are told by the code you've called). If you know that certain inputs will inevitably lead to such a result, you can just not bother executing your code and throw an exception stating which input is not valid and why.

On a more end-user related note, it is best to return something descriptive yet simple so that anyone can understand it. If your client calls and says "the program crashed, fix it", you have a lot of work on your hands tracking down what went wrong and why, and hoping you can reproduce the problem. Using proper handling of exceptions can not only prevent a crash, but provide valuable information. A call from a client saying "The program is giving me an error. It says 'X Y Z is not valid input for method M, because Z is too large", or some such thing, even if they have no idea what it means, you know exactly where to look. Additionally, depending on your/your company's business practices, it might not even be you fixing these problems, so it is best to leave them a good map.

So the short version of my answer is that your first option is the best.

```<code>Inconsistent input -> no action + notify caller
</code>```

Title: How should I handle invalid user input?

Body:
I have been thinking about this issue for a while and I would be curious to have opinions from other developers.

I tend to have a very defensive style of programming. My typical block or method looks like this:

```<code>T foo(par1, par2, par3, ...)
{
    // Check that all parameters are correct, return undefined (null)
    // or throw exception if this is not the case.

    // Compute and (possibly) return result.
}
</code>```

Also, during the computation, I check all pointers before dereferencing them. My idea is that, if there is some bug and some NULL pointer should appear somewhere, my program should handle this nicely and simply refuse to continue the computation. Of course it can notify of the problem with an error message in the log or some other mechanism.

To put it in a more abstract way, my approach is

```<code>if all input is OK --> compute result
else               --> do not compute result, notify problem
</code>```

Other developers, among them some colleagues of mine, use another strategy. E.g., they do not check pointers. They assume that a piece of code should be given correct input and it should not be responsible for what happens if the input is wrong. Also, if a NULL pointer exception crashes the program, a bug will be found more easily during testing and have more chances of being fixed.

My answer to this is normally: but what if the bug is not found during testing and appears when the product is already being used by the customer? What is a preferred way for the bug to manifest itself? Should it be a program that does not perform a certain action, but can still continue to work, or a program that crashes and needs to be restarted?

Summarizing

Which of the two approaches to handling wrong input would you advise?

```<code>Inconsistent input --> no action + notification
</code>```

or

```<code>Inconsistent input --> undefined behaviour or crash
</code>```

Edit

Thanks for the answers and suggestions.
I am a fan of design by contract too. But even if I trust the person who has written the code calling my methods (maybe it is myself), there can still be bugs, leading to wrong input. So my approach is to never assume a method is passed correct input.

Also, I would use a mechanism to catch the problem and notify about it. On a development system, it would e.g. open a dialog to notify the user. In a production system it would just write some information to the log. I do not think that extra checks can lead to performance problems. I am not sure if assertions are enough, if they are switched off in a production system: maybe some situation will occur in production that had not occured during testing.

Anyway, I was really surprised that many people follow the opposite approach: they let the application crash "on-purpose" because they maintain that this will make it easier to find bugs during testing.

Body:
There should definitely be a notification, such as a thrown exception. It serves as a heads up to other coders who may be misusing code you wrote (trying to use it for something it wasn't intended to do) that their input is invalid or results in errors. This is very useful in tracking down errors, whereas if you simply return null, their code will continue along until they try to use the result and get an exception from different code.

If your code encounters an error during a call to some other code (perhaps a failed database update) which is beyond the scope of that particular piece of code, you really have no control over it and your only recourse is to throw an exception explaining what you know (only what you are told by the code you've called). If you know that certain inputs will inevitably lead to such a result, you can just not bother executing your code and throw an exception stating which input is not valid and why.

On a more end-user related note, it is best to return something descriptive yet simple so that anyone can understand it. If your client calls and says "the program crashed, fix it", you have a lot of work on your hands tracking down what went wrong and why, and hoping you can reproduce the problem. Using proper handling of exceptions can not only prevent a crash, but provide valuable information. A call from a client saying "The program is giving me an error. It says 'X Y Z is not valid input for method M, because Z is too large", or some such thing, even if they have no idea what it means, you know exactly where to look. Additionally, depending on your/your company's business practices, it might not even be you fixing these problems, so it is best to leave them a good map.

So the short version of my answer is that your first option is the best.

Inconsistent input -> no action + notify caller


问:
How do I handle refactoring that takes longer than one sprint?
I work with a code base that is over 500K lines of code. It is in serious need of refactoring. There have been refactoring efforts identified that will take longer than the normal two week sprint. These can't be broken up into smaller tasks as I have seen suggested in other answers on this site. The product needs to work at the end of the iteration, and partial refactoring will leave the system in an unusable state as the dependency between items is horrible. So what would be the best way to approach this hurdle? Again I mention, breaking it down into smaller pieces is is not an option, that has already been done.

Update:
People seem to need an explanation of why this can't be fit into a 2 week sprint. There is more involved in a sprint than just writing code. We have a policy of no code without tests. That policy did not always exist and a large portion of the codebase does not have them. Also some of our integration tests are still manual tests. The issue is not that the refactoring itself is so large. It is with the fact that small changes have an effect on many parts of the system, and we need to ensure that those parts still operate correctly.

We can't put off or extend a sprint because we have monthly hotfixes. So this change extending past a sprint cannot stop the other work being added to the hotfix.

Refactoring vs Redesign:
Just because our development process is not efficent enough to handle this refactoring in a two week cycle does not warrant renaming it to a redesign. I would like to believe that in the future we could accomplish the exact same task within a two week cycle as our process improves. The code in question here has not had to change in a very long time, and is quite stable. Now, as the direction of the company is becoming more adaptable to change, we want this portion of the code base to be as adaptable as the rest. Which requires refactoring it. Based on the answers here, it is becoming apparent that there is missing scaffolding necessary to make this refactoring work in the time frame of normal sprints.

Answer:

I am going to do the branch and merge approach that Corbin March suggested the first time so we can learn more about these problem areas and how to identify the missing tests. I think moving forward, we should take the approach that Buhb suggested of identifying the areas that are missing tests and implement those first, then do the refactoring. It will allow us to keep to our normal two week sprint cycle, just like many here have been saying should always be the case for refactoring.

答: If you have the luxury of delaying the refactoring, I suggest focusing coming iterations on adding unit test and automated integration tests to the point where you can comfortably refactor the codebase, and then refactor in a single sprint.</p>


问:
what is the correct/best way to populate a secondary property of an MVC Model and how do I unit test it?
I'm building an web application is ASP.NET MVC 3 (.NET 4) and trying to unit test as much as possible.

I have a controller action Details(int customerId) which should display a view who's model is a Customer

```<code>public class Customer
{
    public int? Id { get; set; }

    [Required]
    [Display(Name = "Customer Name")]
    public string Name { get; set; }

    ...

    public IList<CustomerComment> Comments { get; set; }
}
</code>```

The controller action looks like this:

```<code>public ActionResult Details(int customerId)
{
    var model = service.Get(customerId);
    if (model != null)
        return View(model);

    return RedirectToAction("Index");
}
</code>```

As you can see, this directly calls service.Get

```<code>public Customer Get(int id)
{
    return repository.Get(id);
}
</code>```

The service has an ICustomerRepository injected in it and calls the Get method of that repository directly.

My question regards populating the Comments collection.

How/where should the Comments be populated and how do I test it?

The Details view is the only place that displays the list of comments, so it needs this data. I can see two ways of populating this.

Do it all in the ICustomerRepository.Get implementation.

This might lead to a situation down the line where I'm using Get but not displaying the comments. This would mean I'm doing an expensive (maybe) JOIN but not using the results.

Have an ICustomerCommentsRepository/Service injected into either my Service or Controller which is used to populate the Comments when required.

Is there a preference?

Secondly, how would you test this?

In the second instance, I could assert that ICustomerCommentsRepository.Populate(Customer customer) is called on my mock by the Controller/Service.

In the first situation all the responsibility lies in my repository so in a Unit Test sense, is untestable as the concrete implementation used in the actual app needs to speak to the DB and so is an integration test.

Am I missing something? Would the ICustomerCommentsRepository be a bad idea?

答:
IMO You should keep your repositories per Aggregate Root

You may not be doing DDD, however I belive this is still valid advice in your case.

You're retreiving a Customer from a repository (db, in memory store, list of customers, etc) and you may or may not want to populate your list of comments.

Break the functions of ICustomerRepository up to represent your fetching strategies

It looks like you need to have 2 fetching strategies.

Fetch customer but lazy load comments until needed (lazy load comments)

Fetch customer and eager load comments (will always need them)

This will determine the methods that you may implement on ICustomerRepository

```<code>// lazy loads comments list as these may not be used
public Customer Get(long customerId) {}

// eager loads comments (as effeciently as possible)
public Customer GetWithComments(long customerId) {}
</code>```

Only create a separate repository if you will use it directly

Only create a separate ICommentsRepository if you will use it directly.  Using it indirectly along with another repository is separating a singular concern.  A repository pattern is not limited to a single table but a single responsibility.

Body:
IMO You should keep your repositories per Aggregate Root

You may not be doing DDD, however I belive this is still valid advice in your case.

You're retreiving a Customer from a repository (db, in memory store, list of customers, etc) and you may or may not want to populate your list of comments.

Break the functions of ICustomerRepository up to represent your fetching strategies

It looks like you need to have 2 fetching strategies.

Fetch customer but lazy load comments until needed (lazy load comments)

Fetch customer and eager load comments (will always need them)

This will determine the methods that you may implement on ICustomerRepository

// lazy loads comments list as these may not be used
public Customer Get(long customerId) {}

// eager loads comments (as effeciently as possible)
public Customer GetWithComments(long customerId) {}

Only create a separate repository if you will use it directly

Only create a separate ICommentsRepository if you will use it directly.  Using it indirectly along with another repository is separating a singular concern.  A repository pattern is not limited to a single table but a single responsibility.


问:
What was the first hierarchical file system?
"Directories containing directories and files" seems to have been around forever, but there must have been a first.</p>

答:
I think Multics introduced the first hierarchical filesystem and presented it at the 1965 Fall Joint Computer Conference.  (The reference is one of the papers from that conference, describing the filesystem.)

Unix of course also has an hierarchical filesystem, which it seems to have inherited from Multics.

The wikipedia article on Unix says:

Unix also popularized the hierarchical file system with arbitrarily nested subdirectories, originally introduced by Multics. Other common operating systems of the era had ways to divide a storage device into multiple directories or sections, but they had a fixed number of levels, often only one level. Several major proprietary operating systems eventually added recursive subdirectory capabilities also patterned after Multics. DEC's RSX-11M's "group, user" hierarchy evolved into VMS directories, CP/M's volumes evolved into MS-DOS 2.0+ subdirectories, and HP's MPE group.account hierarchy and IBM's SSP and OS/400 library systems were folded into broader POSIX file systems.

The earliest hierarchical file system with which I had personal experience at the time of its release was ODS-2, introduced with VMS in 1979.

OwnerDisplayName: Kent Beck

OwnerDisplayName: Don Roby


答:
I am by no means sure about this information, but wasn't the ICL system for storing on high speed drums (concrete cored) a hierarchical system? This is at about the same time as the ICL CAFS system which (like Don's answer) was first introduced in 1965.

EDIT

The ICL system may fall into the category (described by Don from the Wikipedia article ) as having a fixed number of levels. I don't know where to find the information to resolve whether or not it was truly hierarchical. The ICL system was developed from the LEO range (of several companies that were combined to form ICL) which did not (AFAIK) have any persistent storage - being reliant on mercury delay lines for temporary storage.

Title: What was the first hierarchical file system?

Body: "Directories containing directories and files" seems to have been around forever, but there must have been a first.</p>

OwnerDisplayName: Chris Walton


问:
Ideas on making potential customer trust the web-site database
I'm developing a site for a potential customer who will need a lot of features for members and the various roles they will have, but also wants to have confidence in the "database".  It is this latter item that makes them want to purchase a canned system from someone "established", that is both rather expensive, and is generic / not as customizable to what is needed.

Do you have any thoughts or ideas on what I can do to inspire confidence in them that the database will be solid?   I've thought about generating test data to fill the database, doing database backups, and readily being able to switch between database, and ?

I'm implementing the web-site using Grails and am currently using a MySql database.  Customer is very small ... just worried about the scenario of their stuff really "taking off", becoming large fast.

I guess I'm just looking for high level thoughts from some of you experts out there (but specifics/references don't hurt either! :-)

Thanks, Ray

P.S.   The Grails Security Core and UI plugins look really cool for all the user / role / security stuff, got all that plugged in and working in a couple hours yesterday ... thanks Grails framework and plugin developers!!

答:
if I was the customer here, I'd be worrying about your database design skill the most, and not as much about backups.  You can change/improve backup procedures the day before it goes live, but... if the site becomes slow, has bugs, is difficult or slow to implement new features they will have wasted their time and money.

When you hire someone to write custom software for you, you are making a long term investment in that software and resulting data. If the tables design is awful, then you end up with a "crappy legacy" application that is hard to support, maintain, and add features to.  How many times do your see a crazy question on SO and the root cause is because of some fundamental table design problem and the 10 hopes needed to jump through to work around that?

OwnerDisplayName: Ray K

OwnerDisplayName: KM


答:
Their concern is probably justified although the product they are looking at is probbaly not very good from a data perspective either (I've sadly worked with a lot of COTS products through the years).

In the first place, from the content of your question, you clearly don't understand database design issues well enough to be designing one.

First you need to find out what their concerns actually are. Most clients don't care about changing the db backend. They are responsible for setting up the backups generally. And flexibility is the kiss of death in database development. Fast is far more important than flexible. A good database designer should be able to design at least 95% of the needs without resorting to flexible structures.

Possible concerns:

Is my data going to be secure? Show them you have a plan for encrypting personal data and that you understand how to avoid SQL injection attacks. Let them know you understand database permissions and security.

Will it perform fast enough? Show them you have expertise in high avaiability, high performance database design. Such expertise generally takes about ten years to get and does not involve using automated tools to generate your database.

Who will I get support from if you go out of business? Using an established COTS product gives reassurance that their product will still be supported next year.

How am I going to get my existing data migrated to your system? Do you have a migration plan built or expertise in doing migrations - I guarantee the COTS product does.

If they have a concern about your ability to build a database that can grow as their user base grows, show them the stats on the size your db backend can get to. Show them how you have designed the database structure for partioning as the number of records gets larger. Show them that you are planning to test under load and with large amounts of test data to prove that the system can perform well past the first year of operation.  Show them how you intend to make sure the data retains integrity over time. Show them basically that the database isn't an afterthought (to most busnesses it is more critical than the application) and that you intend to apply the same level of professionalism to the datbase design as to the application design.

Title: Ideas on making potential customer trust the web-site database

Body:
I'm developing a site for a potential customer who will need a lot of features for members and the various roles they will have, but also wants to have confidence in the "database".  It is this latter item that makes them want to purchase a canned system from someone "established", that is both rather expensive, and is generic / not as customizable to what is needed.

Do you have any thoughts or ideas on what I can do to inspire confidence in them that the database will be solid?   I've thought about generating test data to fill the database, doing database backups, and readily being able to switch between database, and ?

I'm implementing the web-site using Grails and am currently using a MySql database.  Customer is very small ... just worried about the scenario of their stuff really "taking off", becoming large fast.

I guess I'm just looking for high level thoughts from some of you experts out there (but specifics/references don't hurt either! :-)

Thanks, Ray

P.S.   The Grails Security Core and UI plugins look really cool for all the user / role / security stuff, got all that plugged in and working in a couple hours yesterday ... thanks Grails framework and plugin developers!!

OwnerDisplayName: HLGEM


答:
+1 on Corbin March's answer, thats exactly what I was thinking.
It sounds like your code-base is a bit ugly and it's going to take more than a single sprint cycle to clean it up.

So just like Corbin said,

branch it into a "refactoring project"

test your branch change

promote to your test environment for QA testing

incrementally merge it back into the trunk until the refactoring is done.

I'm sure you wouldn't have any problems selling this to your dev manager, if your PM's are having a hard time seeing it then explain to them that Rome wasn't built in a day and cleaning up all the garbage thrown into Rome's streets isn't going to be done in a day either. The refactoring will take a while but it'll be well worth it in the end in terms of easier maintenance, quicker enhancement releases, less production tickets, and a more fulfilled SLA.


答: One good reason to learn Silverlight is that it will set you up for developing apps for the Windows Phone 7 platform. I can't offer you any hot tips on how to justify using Silverlight for a web project, but that's one more reason why it's a good idea for you to try to do so. :)

Title: Is Silverlight only for eye-candy, or does it have a use in business?

Body:
Granted that Silverlight may make eye-popping websites of great beauty, is there any justification for using it to make practical web applications that have serious business purposes?  I'd like to use it (to learn it) for a new assignment I have, which is to build a web-based application that keeps track of the data interfaces used in our organization, but I'm not sure how to justify it, even to myself.

Any thoughts on this?  If I can't justify it then I will have to build the app using the same old tired straight ASP.NET approach I've used (it seems) a hundred times already.


问:
Why is DRY important?
Quite simple, why would I want to write code that works for all cases and scalable data when all I need to do is repeat the same process a few times with a few minor tweaks?

I'm unlikely to need to edit this again any time soon.

It looks like a lot of less work to just go...

```<code>function doStuff1(){/*.a.*/}
function doStuff2(){/*.b.*/}
function doStuff3(){/*.c.*/}
</code>```

And if I ever need to add something...

```<code>function doStuff4(){/*.d.*/}
</code>```

And if I need to remove it, I remove it.

It's harder to figure out how to make all of those into one straight-forward pattern that I can just feed data into and deal with all the cases, and make a bunch of changes I don't feel like I'm ever going to have to do.

Why be DRY when it looks like a quick cut+paste is going to be so much less work?

答: I don't see the key points of my answer above, so here goes.  Don't look at DRY so much as a rule against doing something.  It may be phrased like that but it can really serve a quite different and positive purpose.  It's a signal to stop, think, and find a better answer.  It challenges me to look for opportunities to design a better solution.  It's the good side of a bad smell in my code that induces me to rethink my design and makes me do it a whole lot better.  DRY isn't about just an itty bitty syntax violation.  It challenges me to modularize.  It challenges me to componentize.  It signals repetition that reminds me to think about using templates and code generation instead of brute force and ignorance. It helps me figure out that I should find some time to automate my automation.  It leads you to a parsimonious lifestyle!  It helps you to spend more of your time doing cooler new stuff rather than nitpicky old boring details.  And it gives you good manners, good breath, and a healthy lifestyle!  Well, perhaps I wax a bit astray ....

Title: Why is DRY important?


问:
Thoughts on Development using Virtual Machines
I'll be working as a development lead for a startup and I've suggested that we use VMs for development.  I'm not talking about each developer having a desktop with VMs for testing/development, I mean having a server rack where all VMs are managed and have the developers work from a microPC (ChromeOS anyone?) locally, or even remotely from their home computer.

To me, the benefits are the fact that it's extremely scalable, cheaper in the long run, easier to manage and that we utilize the hardware its maximum potential.  As for cons, I can't think of any particular showstoppers other than we'll need someone to setup/maintain said setup.

I was hoping that some of you might of had a similar setup at your place of employment and be able to weight in with your opinions.  Thanks.

答:
What are you hoping to save, as a fraction of the development budget?  It seems to me that you are worrying about an epsilon.  The cost of machines for developers is less than 5% of the total cost to keep a developer on staff.  Therefore the only important question is "will it save developers time?"  It could, if they don't have to spend time installing and upgrading development software.  Or it could cost time, if the network goes down, or the server goes down, or, most likely, if the responsiveness across the net is the least bit lacking.  Modern development depends on keystroke-by-keystroke interaction with an IDE, or at least a very intelligent editor.  Delaying that interaction by even a few tens of milliseconds destroys developer productivity.  There is also the cost for developers to learn this new way of working.  If that takes even one day per developer, you have already spent more in labor than the cost of a new desktop.

These are not objections to VMs, but potential objections to remote development.