问:
Ruby workflow in Windows
I've done some searching and quite haven't come across the answer I am looking for. I do not think this is a duplicate of this question. I believe Windows could be a suitable development environment based on the mix of answers in that question.

I have been developing in Ruby (mostly Rails but not entirely) for about a year now for personal projects on a Macbook Pro however that machine has faced an untimely death and has been replaced with a nice Windows 7 machine. Ruby development felt almost natural on the Mac after doing some research and setting up the typical stack. My environment then included the standard (Linux like) stuff built into OSX, Text Wrangler, Git, RVM, et al. Not too much of a deviation from what the 'devotees' tend to assume.

Now I am setting up my new Windows box for continuing that development. What would my development environment look like? Should I just cave and run Linux in a VM? Ideally I would develop in Windows native. I am aware of the Windows Ruby installer. It seems decent but its not exactly as nice as RVM in the osx/linux world. Mercurial/Git are available so I would assume they play into the stack. Does one develop entirely in Windows? Does one run a webserver in a Linux VM and use it as a test bed while developing in Windows? Do it all in a VM?

What does the standard Windows Ruby developer environment look like and what is the workflow? What would a typical step through be for adding a new feature to an ongoing project and what would the technology stack look like?

答:
I develop Ruby for both on Windows and Linux, and Linux is far far easier to work with in the long run.

If you like to "just do it" and not fight with..just weird stuff, then I would definitely be running a Linux VM. It's just much easier and more fun that way.

While this may not directly be the answer you're looking for I personally run a separate Linux box and then SSH into it from my Windows laptop. I do all my dev stuff on Linux and then only work on Windows when there is no alternative (client runs nothing but Windows boxes for example).

You could duplicate a similar environment with a Linux VM.

There are so many more tools and less incompatibilities on Linux. It's a joy to develop on it, while on Windows you many times bump into strange quirks or problems which eventually interrupts a smooth work flow. It's just less of a hassle on Linux. However if you're willing to put a little extra effort into it then I'm sure you CAN get something decent on Windows. But for fun factor, the points go to Linux.

Title: Ruby workflow in Windows


问:
Understanding already existing complex code base

Possible Duplicate:

  What is the most effective way to add functionality to unfamiliar, structurally unsound code?

Till now, all I have worked on is with Java projects that I build from scratch (mostly course projects and some hobby stuff). But now, I have come across a huge code base of about 46000 lines spread across around 200 classes. Additionally there are around 10 dependent libraries.

The problem is not only that I have never worked with someone else's code before, but I have not worked with such a huge code-base before too.

I am asked to completely understand the code-base and suggest improvements to the existing design. Now, I am kind of stuck. I start with some part of the code and then by the time I reach some other part of the code, I have lost the working details of the previous part.

I could really use your suggestions and experiences to deal with this issue. How do I proceed/document the details of the classes to understand the code better?

Edit:
This is a university level research project. Students have developed it over couple of years and the bad part: The students who wrote this have already graduated. The existing documentation (only in the form of Javadocs, not UML stuff) is a lot but not helpful in terms of understanding the application design.

答:
Welcome the world of software development.  Most of the time you are going to:

Work with a large preexisting code base.

There will be limited documentation.

The original creators are long gone.

No one will really know the system end to end.

Most of the time you are going to be tossed in and expected to figure it out.  Sure there will people along the way and some amount of documentation to help but in the end it is up to you to make sense of things.  I think that this making sense of things is different for each person and is a skill that really makes a difference.

From my experiences/observations of how others do it here is what I see that works:

Approaching it in way that you find the skeleton of the system first and then start filling in the details.

Writing down call trees that show how to get from one place to the other in the code.  Many times this is just one particular area not the whole system.

Use of tools that help you understand the code.  I use the search function and references function of Slickedit.  I also think that eclipse has some tools like this.

Experimentation on how the system works.  Often times I use a high level of tracing/printfs with testing different things to help me understand the flow.

In the end the thing that helps the most is Repetition!  The more times that you go through things the easier it is to know whats what. In industry we often times say that it will take a few months before you can consider someone to have the knowledge to be effective.  This is because of the learning curve.

Lastly in my own experience I feel like there are a few stages to understanding a large new code base:

Stage 1: Getting your bearings.  In this stage it is all about learning where things are and getting familiar.  I would say that you should expect to be able to make small changes successfully.

Stage 2: You are familiar with where things are and are capable of making medium sized changes with some luck.  I would say that at this point you would need a fair amount of help to get things right but you can get things done.

Stage 3: You have a very good understanding of the code and are capable of making large complicated changes.  The most common problem at this level is that an incomplete system level understanding causes you to introduce bugs.  Still you are very effective.

Stage 4: You have a complete understanding and can bend the system to your will.  I would say that very few actually ever get here.

ContentLicense: CC BY-SA 3.0


问:
Passing member variable as a method parameter
In a project, I've found a code like this:

```<code>class SomeClass
{
    private SomeType _someField;

    public SomeType SomeField
    {
        get { return _someField; }
        set { _someField = value; }
    }

    protected virtual void SomeMethod(/*...., */SomeType someVar)
    {
    }

    private void SomeAnotherMethod()
    {
        //.............
        SomeMethod(_someField);
        //.............
    }

};
</code>```

How do I convince my teammates that this is bad code?

I believe this is an unnecessary complication.  Why pass a member variable as a method parameter if you already have access to it?  This is also a violation of encapsulation.

Do you see any other issues with this code?

答:
I think this is a valid topic, but the reason you are getting mixed responses is because of the way the question was formed. Personally, I had the same experiences with my team where passing members as arguments was unnecessary and convoluted the code. We'd have a class that works with a set of members but some functions access members directly and other functions would modify the same members through parameters (i.e. use completely different names) and there was absolutely no technical reason for doing that.  By technical reason, I mean an example that Kate provided.

I would recommend to take a step back and instead of focusing exactly on member passing as parameters, initiate discussions with your team on clarity and readability. Either more formally, or just in hallways, discuss what makes some code segments easier to read and other code segments more difficult. Then identify quality measures or attributes of clean code that as a team you would want to strive for. After all, even when working on green field projects, we spend more than 90% of time reading and as soon as the code is written (let's say 10-15 minutes later) it goes into maintenance where readability is even more important.

So for your specific example here, the argument I would use is that less code is always easier to read than more code.  A function that has 3 parameters is harder for the brain to process than a function that has none or 1 parameter. If there's another variable name, the brain has to keep track of yet another thing when reading the code.  So to remember "int m_value" and then "int localValue" and remember that one really means the other is always more expensive for your brain then simply working with "m_value".

For more ammunition and ideas, I would recommend picking up a copy of Uncle Bob's Clean Code.


问:
How can I advocate a semi-strict release schedule in a risk-averse environment?
Recently I've been increasingly plagued by what I would have to describe as one of my most frustrating and morale-killing experiences in this profession: Having to sit on a release that has been tested, re-tested, staged, and for all intents and purposes is ready to ship/deploy.

As an all-around solutions guy and not just a hardcore coder, I do understand and have even advocated the need for proper change control. But lately, the tenuous balance between covering our bases and shipping on time has gone all lopsided, and I've had little to no success in restoring it to something sane.

I'm looking for compelling arguments to help convince risk-averse management that:

The dev team should (or must) be able to set its own release schedule - within reason of course (1-3 months should be conservative enough for all but the biggest Fortune 500 companies);

Software releases are important milestones and should not be treated cavalierly; in other words, unnecessary delays/stoppages are highly disruptive and should be considered only as a last resort to some critical business issue; and

External (non-dev/non-IT) entities who want (or demand) to be involved as stakeholders have a responsibility to cooperate with the dev team in order to meet the release schedule, especially in the last week or so before the planned ship date (i.e. user testing/staging).

The above are assertions that ring true for me based on experience, but it looks like I'm now in the position of having to prove it - so I'm asking for something a little meatier here, if such a thing exists.

Can anyone who has had to "sell" the idea of a fixed (or maybe semi-flexible) release cycle to management give some pointers on what arguments/strategies are effective or persuasive and what is not? Aside from the obvious schedule contention and sunk costs, is there any hard data/evidence that would be useful in making the case that shipping is actually important, even in a "corporate" setting?

Alternatively, I'm open to hearing constructive arguments about why schedule flexibility (even over a period of weeks/months) is more important than shipping on schedule; it's hard for me to believe right now but maybe they know something I don't.

Note we have staged releases, and this went through every stage except production. Issues are tracked using a commercial bug tracker and every issue - 100% of them - that was assigned to this release was closed out. I realize it's difficult to believe and that's really precisely the point - it makes no sense that a 100%, feature-complete, fully-tested, approved-by-stakeholders release would be delayed by management for unexplained reasons, but that's what happened, that's what's been happening, that's the problem to be solved.

答:
Go away from that company, they don't understand software. But seriously, software is what makes the system work, imagine if you were making cars, are car factories slow? do they wait on car releases? Are they incremental and bureaucratic? No, they try to do things the fastest and cleanest way possible. You have a management problem and you should work on it as a management conflict, try to speak them into their terms. Ask what risk means to them, then try to minimize it. The feelings of your devs are also important, since they must cope with the decisiones that will be made by your intervention. Will they be happy doing all nighters to ship on time? What would the prizes/penalizations be? Etc.
Now i will give you a practical approach to this problem, a bit extreme, but ask for an audit. That will give you tools to talk to management about the problems you see, but from an external standpoint, and will also improve your image with them.</p>


答:
GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

```<code>invalidateRect(m_frame);
</code>```

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

```<code>invalidateFrame();
</code>```

But why add a special method just for this when you can use the more general invalidateRect()? Or, if you did choose to provide invalidateFrame(), you'd very probably implement it in terms of the more general invalidateRect():

```<code>View::invalidateFrame(void)
{
    invalidateRect(m_frame)
}
</code>```

Why pass variable as method parameter, if you already has access to it?

You should pass instance variables as parameters to your own method if the method doesn't operate specifically on that instance variable. In the example above, the view's frame is just another rectangle as far as the invalidateRect() method is concerned.

Title: Passing member variable as a method parameter

Body:
In a project, I've found a code like this:

```<code>class SomeClass
{
    private SomeType _someField;

    public SomeType SomeField
    {
        get { return _someField; }
        set { _someField = value; }
    }

    protected virtual void SomeMethod(/*...., */SomeType someVar)
    {
    }

    private void SomeAnotherMethod()
    {
        //.............
        SomeMethod(_someField);
        //.............
    }

};
</code>```

How do I convince my teammates that this is bad code?

I believe this is an unnecessary complication.  Why pass a member variable as a method parameter if you already have access to it?  This is also a violation of encapsulation.

Do you see any other issues with this code?

Body:
GUI frameworks typically have some sort of 'View' class that represents things drawn on the screen, and that class usually provides a method like invalidateRect(Rect r) to mark part of its drawing area as needing to be redrawn. Clients might call that method to request an update to part of the view. But a view might also call its own method, like:

invalidateRect(m_frame);

to cause redrawing of the entire area. For example, it might do this when it's first added to the view hierarchy.

There's nothing wrong with doing this -- the view's frame is a valid rectangle, and the view itself knows that it wants to redraw itself. The View class could provide a separate method that takes no parameters and uses the view's frame instead:

invalidateFrame();

But why add a special method just for this when you can use the more general invalidateRect()? Or, if you did choose to provide invalidateFrame(), you'd very probably implement it in terms of the more general invalidateRect():

View::invalidateFrame(void)
{
    invalidateRect(m_frame)
}

Why pass variable as method parameter, if you already has access to it?

You should pass instance variables as parameters to your own method if the method doesn't operate specifically on that instance variable. In the example above, the view's frame is just another rectangle as far as the invalidateRect() method is concerned.


问:
What are some things you have read that inspired and guided you as a programmer?
For example, being a beginner, I find a lot of inspiration and direction from reading this post by Bryan Woods.</p>

答:
Read the speech given by Alex Stepanov at Adobe. At the end of 5 years this will seperate the GREAT ones from the GOOD ones.

http://www.scribd.com/doc/210467/Speech-by-Alex-Stepanov

ContentLicense: CC BY-SA 2.5


问:
Backtrack My "Education"
A while ago, I decided to start programming. I really, just jumped into a language (Perl) and went from there. What I regret is that I just jumped in:

I didn't learn the basics (if you would call them basics).

I didn't learn about Computer Science.

This issue, I believe, is holding me back from my true potential. Where should I "restart"? Are there any books, articles, etc. that I should read? Are there any topics an experienced programmer should know? What's your advice?

答: Learn about algorithms in it's most basic form, forget about languages for a while. Sorting vectors, words, etc. Freepascal is a nice language to start with these things, i love Perl but with all it's shortcuts and cool stuff, you'll often be neglecting the inherent algorithm of the program.</p>

Title: Backtrack My "Education"


答:
You are missing if the parameter ( "argument" ) is reference or read-only.

```<code>class SomeClass
{
    protected SomeType _someField;
    public SomeType SomeField
    {
        get { return _someField; }

        set {
          if (doSomeValidation(value))
          {
            _someField = value;
          }
        }
    }

    protected virtual void ModifyMethod(/*...., */ ref SomeType someVar)
    {
      // ...
    }

    protected virtual void ReadMethod(/*...., */ SomeType someVar)
    {
      // ...
    }

    private void SomeAnotherMethod()
    {
        //.............

        // not recommended, but, may be required in some cases
        ModifyMethod(ref this._someField);

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

        // recommended, but, verbose
        SomeType SomeVar = this.someField;
        ModifyMethod(ref SomeVar);
        this.someField = SomeVar;

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

        ReadMethod(this.someField);
        //.............
    }

};
</code>```

Many developers, usually assign directly the internal fields of a variable, in the constructor methods. There are some exceptions.

Remember that "setters" can have additional methods, not just assignament, and sometimes, even be virtual methods, or call virtual methods.

Note: I suggest keep the internals fields of properties as "protected".

Body:
You are missing if the parameter ( "argument" ) is reference or read-only.

class SomeClass
{
    protected SomeType _someField;
    public SomeType SomeField
    {
        get { return _someField; }

        set {
          if (doSomeValidation(value))
          {
            _someField = value;
          }
        }
    }

    protected virtual void ModifyMethod(/*...., */ ref SomeType someVar)
    {
      // ...
    }

    protected virtual void ReadMethod(/*...., */ SomeType someVar)
    {
      // ...
    }

    private void SomeAnotherMethod()
    {
        //.............

        // not recommended, but, may be required in some cases
        ModifyMethod(ref this._someField);

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

        // recommended, but, verbose
        SomeType SomeVar = this.someField;
        ModifyMethod(ref SomeVar);
        this.someField = SomeVar;

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

        ReadMethod(this.someField);
        //.............
    }

};

Many developers, usually assign directly the internal fields of a variable, in the constructor methods. There are some exceptions.

Remember that "setters" can have additional methods, not just assignament, and sometimes, even be virtual methods, or call virtual methods.

Note: I suggest keep the internals fields of properties as "protected".


问:
Service Registry - is it needed?
Suppose you develop a system that has multiple services (implemented by different teams, in different countries, using different technologies including java, php, c#, c++ and more). Let's assume that despite using different technologies, somehow you have agreed to integrate using RESTful APIs.

Does such a system need a Service Registry?

I understand that basically it's not mandatory, since each service may have its own configuration where the service it uses are located.
However, creating a central location makes the life of operations easier: they don't need to configure the same service multiple times.

But creating a Service Registry may be complex. It's another system in the solution and it requires resources and even more important ownership. Who will owner it?

I can think about more pros and cons of a Service Registry. So what do you think?

答:
In a complex system like you describe, I would say that the configuration of that system is at least as important, if not more so, than any individual component. Often in my experience, when a complex system I work on is not working, it is the configuration, not any individual component, that is responsible for the failure. An analogy I like to use is that of a lock: only when all the tumblers are aligned properly will it open.

So I recommend that you put a lot of effort into making correct configurations easy to set up, monitor, and deploy. Whether you use a separate service registry or some other mechanism is up to you. Recently I have taken to packaging configuration information as Debian packages (we use Ubuntu) that are installed from a central repository. Others use third-party systems like ZooKeeper.

So to answer your specific questions, a qualified yes to having a service registry. Qualified because the exact form of the management system is less important than having one and using it well. Its owner should be the same person or group that is responsible for a correctly functioning system. This might be the developers themselves (a DevOps organization), or perhaps a dedicated Operations team (more traditional). The initial set up of the systems should be a joint endeavor with all stakeholders participating in the specification of the configuration. Once that is done, a small group or person can handle the implementation.

Title: Service Registry - is it needed?


问:
When is Java a good choice for web development?
When is Java a good choice for web development?

Please do not say "When you have a development team that knows only Java."

答:
Java is a statically typed language, and is cheaper than the other statically typed languages used for web development, namely C# and VB.net, if your company does not have an MSDN subscription.
Statically typed languages are good for medium to big projects, complex domain rules, and a lot of back-end code, because you can organize better your classes and IDEs will help you to find errors in your code.

With dynamically typed languages, like PHP, Python, Ruby, your development will be much faster, but you will have to test your code much better. If you don't have much time and money and your requirements change very quickly and you don't have to do very complex calculations, dynamic languages are much better.


答:
Some strategies:

Create an inheritance diagram. There are tools that'll do this for you, but even drawing it by hand could be helpful.

Of the 200 classes, you'll probably find that a dozen or so are really important. These will be the classes that are close to the root of the inheritance tree. The others will be variations on a theme, and once you know what their superclasses do, you'll have a pretty good idea how all those leaf classes work too.

Make notes. Using a wiki can be helpful here. Eventually, you might turn some of your notes into better documentation than currently exists.

Draw diagrams of the objects that are created and how they relate to each other.

Use a debugger to step through sections you don't understand.

Use a profiling tool to find performance issues without worrying too much about exactly what's going on in the code. Just put the application through its paces while you record performance metrics. Knowing where the application spends most of it's time can a) give you insight into how it works and b) suggest areas for improvement without you needing to understand every detail.

Title: Understanding already existing complex code base

Body:
Possible Duplicate:

  What is the most effective way to add functionality to unfamiliar, structurally unsound code?

Till now, all I have worked on is with Java projects that I build from scratch (mostly course projects and some hobby stuff). But now, I have come across a huge code base of about 46000 lines spread across around 200 classes. Additionally there are around 10 dependent libraries.

The problem is not only that I have never worked with someone else's code before, but I have not worked with such a huge code-base before too.

I am asked to completely understand the code-base and suggest improvements to the existing design. Now, I am kind of stuck. I start with some part of the code and then by the time I reach some other part of the code, I have lost the working details of the previous part.

I could really use your suggestions and experiences to deal with this issue. How do I proceed/document the details of the classes to understand the code better?

Edit:
This is a university level research project. Students have developed it over couple of years and the bad part: The students who wrote this have already graduated. The existing documentation (only in the form of Javadocs, not UML stuff) is a lot but not helpful in terms of understanding the application design.


答:
I see one strong reason for passing member variables as function arguments to private methods - function purity. Member variables are effectively a global state from the point of view, what's more, a mutable global state if said member changes during the method's execution. By replacing member variable references with method parameters, we can effectively make a function pure. Pure functions don't depend on an external state and have no side effects, always returning the same results given the same set of input parameters - thus making testing and future maintenance easier.

Sure it's neither easy nor practical to have all your methods as pure methods in an OOP language. But I believe you gain much in terms of code clarity by having the methods that handle complex logic pure and using immutable variables, while keeping the impure "global" state handling separated within dedicated methods.

Passing member variables to a public function of the same object when calling the function externally would however constitute a major code smell in my opinion.


问:
Are ads within average Android applications profitable?
I know ads can be profitable for some incredibly popular applications, but how do average applications fare? </p>

<p>I am about to release an application and I think it will be pretty popular, but it's not the next Angry Birds. I guess there will be a few thousand users. Would a few thousand users that use the application about 15~20 minutes once or twice a day net any actual profits? </p>

答:
I'm actually the owner of the blog @Mona mentions, and thought I'd chip in with some feedback about the current state of things.

To answer the question - Yes, ads can be profitable for your average Android app. It all depends on how much capital you're investing in the app.

If all you're putting into it is your time, and you're getting a few thousand people with 15-20 minutes per day total usage, you should be able to make a decent profit. Here's a few quick calculations for you:

15 minutes per day = 900 seconds

90 second refresh rate for ads = 10 ads per person, per day

2,000 daily users = 20,000 daily impressions (assuming 100% fill rate)

eCPM of $0.70 = $14 per day

$14 per day = $420 per month, or about $5000 per year

Some caveats with these calculations though:

15-20 minutes is a long time for somebody to spend with your app. Most casual apps only get about 1-2 minutes average visit length.

You'll never get 100% fill rate on your ads, so figures will be slightly less than this. However, with AdMob I've achieved >94% fill rate, which is close to 100%.

Your eCPM will always vary, depending on ad network, time of year, and CTR. In my experience, $0.70 is a safe bet if you're doing things right. Some developers are actually getting over $1.00 eCPM, which would bring these figures up to $7000/year.

If you're chasing more info from actual developers regarding eCPM and level of profitability, you could checkout the Income Reports forum on my website. A number of people are sharing details here about their own earnings with moderately successful Android apps.

Velti also have an interesting "State of Mobile Advertising" report which covers many of these details on a global scale.


问:
What are your experiences selling on the Android Market? 1 year on
Follow up to this question

So a lot has changed in the smartphone market in the last year (Specifically Androids market share, OS updates and marketplace updates). Given these changes I think it is appropriate to ask this question again.

I would love to quit my job and write Android apps fulltime. :-)

Is this yet feasible for the average lone developer? What have volumes been like?

(Happy to turn this into a community wiki before all the Grinch's start moaning but looks like I don't have the option)

答:
It's definitely feasible, but will take some effort (as everything does!) I've made over $20,000 in the past 6 months from ads in my free Android apps. I'm blogging about it on my website, and getting a lot of feedback from other independent developers who are making similar amounts of money.

A few points that are worth considering:

It's much easier to produce a successful ad-supported (free) app than a successful paid app on Android. iOS is the opposite - paid apps rule the roost over there.

You need a lot of downloads to make much money from ads. And I mean a lot. Preferably millions.

It's a volatile marketplace. Nothing is guaranteed. I've seen my income skyrocket one day, only to collapse the next. Don't write apps if you're looking for a stable job.

Having said all that, it's definitely an exciting area field to work in :) I'm really enjoying being an Android developer, and while I haven't quit my day job, the income is a nice supplement.

See my answer to this question for some more info about what it takes to make a profit from Android apps.

OwnerDisplayName: Maxim Gershkovich


问:
How do I approach this PHP/MYSQL query?
I have a reservation system that I have coded and my final task is to allow the user to enter a set of dates and then show them all available options.

The reservation table is set up with unit_id, check_in and check_out. There are twelve different unit numbers.

So I have to somehow iterate through them and find the units that have no taken dates during the date range the user has put in. Just having some trouble conceptualizing what needs to happen.

Pseudo code

```<code>$units = array (all the units);

foreach($units as $key = $value){

    Run a query searching through all reservations for that unit,
    if the unit is available, add to our $available_units array for the view later

}
</code>```

Checking availability has me stumped too though. What is the most efficient way to use the customers available date range and compare to the date ranges in the db?

答:
I built a reservation system a while ago and faced a similar problem. It was slightly different in that I had a fixed number of spots (units) to fill (they weren't indexed).

My solution was similar to the answer posted by @rrufai, except that in my case that query would give me the reservations for that date range, not the availability.

I created a MySQL function that performed a query that retrieved the number of reservations for a given day, and returned that number. From there that was subtracted from the number of spots available in total, giving me the available spots. In your case your function could return a list of taken units, then from that work out what ones are free (i.e. not in that list).

I reduced it to looking per day (so I would run the function for n days the user was searching for, although I imagine you could do the whole thing in a single function/procedure.

Title: How do I approach this PHP/MYSQL query?


答: What no one touched on is that SomeMethod is protected virtual. Meaning that a derived class can use it AND re-implement its functionality. A derived class would not have access to the private variable and thus could not provide a custom implementation of SomeMethod that depends on the private variable. Instead of taking the dependency on the private variable, the declaration requires the caller to pass it in.</p>


问:
What advantages does developing applications for smartphones have over developing the same application as a web application?
Let's take the Facebook application as an example. Why did they develop an application when the users could just access to their page and do the same? For me that represents more maintenance and more cost because for each feature added to the web application that feature will have to be added to the smartphone application as well.

So why would I want to develop more than once (for each patform iOS, Android, etc) when I could just have one web application? What benefits do I get? The only one that comes to my mind is GPS feature.

EDIT:

My question is more oriented towards business applications that are going to be used only by some members of the company, it's not about selling the application (private use). So contrary to what some answers say about that by developing as a smartphone application it will benefit from more sells because of the "smartphone stores" for me this point is not important because the application is for private use.

By developing the application as a web application it means that it can be accessed through smartphone browser and also in a PC (any capable browser), but developing as a native application would limit this to only some kind of smartphone so we would be limiting  the use.  On the other hand developing it as a web application means that in order to access the application an Internet connection must be available.

So keeping this in mind how would you convince your boss to write the application for a given smartphone platform (iOS/Android) vs developing it as a web application?

答:
It depends on your circumstances!

Web applications are currently unable to access many of the phone's features (camera, accelerometer, etc). PhoneGap might suffice; it lets you build a web application, then create device-specific deployable versions. Still, it isn't a perfect replacement for a native application.

On the other hand, you might be able to quickly create a web application that your customers can start using immediately. Or you might not need any of those nifty phone features. If you're trying to be first to market, a web application can be a great way to start gaining customers NOW. It might buy you some breathing room to work on those killer ios and android apps. Even after you do create the native apps, I would be good to allow your other customers to access you via blackberry, windows, and other types of mobiles with browsers.


问:
When to reintegrate feature branch?
From SVN 1.5, it supports reintegrate feature. I wonder when I should reintegrate. Should it be done before release or after release?

If I do it

Before release

Pro: It is not forgettable to merge with trunk.

Con: Merged version can be different from QAed version.

After release

Pro: Releasing version is same with QAed version.

Con: Some feature from trunk can be missed.

So, when do you reintegrate?

答:
Specific practices for using version control may differ from one organization to another, but the idea behind a feature branch is that it's a place where you can work on some feature of the overall project. If you want that code to make it into a given release, you'd better merge the code back to trunk (or whatever branch you use as a main development branch) before you do a release. The --reintegrate option that you're asking about is a signal to svn that it should ignore the changes that have been made to your branch as a result of merges from the main branch or trunk.

So, merge (with --reintegrate) when your feature is done and ready for testing.

Title: When to reintegrate feature branch?


答:
tl;dr: Write docs, write tests. Turn understanding into making.

Full version:

Not so long ago I too got to work on existing projects for the first time at a company, and had to get up to speed quickly.

I found that all projects invariably suffer from the very serious issue: insufficient documentation and testing. This is very bad from the point of project success.

High bus factor. Few people really understand how stuff works, except for maybe one lead developer who's assigned to work on project.

Communication is hard since there's no common picture of architecture one can refer to. Well-informed architecture improvement decisions are hard to make.

It's hard on people. Newcomers struggle to understand a program.

So what worked for me is turning understanding into making.

If there's a particular task I have to do at new project, I'd go about it in the way that allows me to gather the most information about the system.

If there's no task, but ‘just’ an overall understanding is required (which seems to be your case), then I'd write documentation.

Writing documentation to get general understanding

I found that it's hard to make the brain understand complex abstract systems. However, the same understanding comes easily if you're making something (it's probably somehow related to the concept of “flow”).

It's kind of a hack. I think most people enjoy making quality products and take pride in their work, so you can make documentation the end product. You'll get to learn new tools (documentation system like Sphinx, for example) and solve difficult problems of how to convey your understanding, as it emerges, to the target audience. You'll have an end-product to show yourself and others, and people will thank you later, which is a great motivator.

Don't forget the meta-documentation: it's frustrating when your docs go obsolete because others don't bother updating them. Document briefly the development workflow—versioning, testing, documentation and coding style guide, etc.

Writing tests

If I got a particular task at hand—new feature or bugfix—I'd first write a test for it first.

To write a test, I have to understand how test suite works and have it up-and-running. This usually isn't obvious, so I briefly document it. Test suite often has a lot of its own problems like unit tests and integration tests all mixed up, so I also note down the ideas on how to fix it later. Sometimes test suite doesn't work or a all tests fail, so I fix it. There are cases when the test suite is entirely absent, which is a chance to learn how to set up one.

Then I write a test. If it's a large task, I write a high-level “integration” test first. When writing unit tests, the first task is to figure out which unit(s) should implement necessary functionality. This will give you quite a bit of architecture understanding. After that, writing the code implementing the feature is easy.

Writing a test may well become a bigger task than implementing a feature or fixing a but. However, it's rewarding later. Once there's a solid test suite, you (or other developers) can learn a lot by trying to improve random things and see if tests pass.


答:
In terms of guidance

The book The Elements of Programming Style by Kernighan and Plauger was very influential for me when I was learning C. The book was already considered "obsolete" by the time I read it, due to its use of PL/I and Fortran samples, but the tips transcended both languages.

Before reading that book, I was convinced "style" was about what I now consider trivial issues, like formatting (how many spaces for a tab? where do you place the curlies?). But style is what you have once you remove formatting and naming conventions. Is it easier to construct a string backwards and then reverse it? Then construct it backwards and reverse it.

Another book from Kernighan and Plauger, Software Tools, was also helpful, but not quite as good. And the much newer book The Practice of Programming, by Kernighan and Pike is also useful, but a far cry from The Elements of Programming Style. I wish I still had my copy. It's worth it for every programmer to read.

I grew an appreciation of testing and QA after reading Glenford Myers The Art of Software Testing. It showed me that testing was a real creative activity, and not just something for computer science majors who don't like to program. Perhaps with the growing popularity of Test-Driven Development more people will turn to Myers's book.

And I cannot think of a better introduction to the notion of abstraction than the book The Structure and Interpretation of Programs, which is available free online. It introduces the Scheme programming language, but hits upon many other topics in computer science, including declarative programming.

In terms of inspiration

In my academic career, I was inspired by the concept of Aspect-Oriented Programming. You can read some of the very early papers on AOP and end up with half a page of notes for ideas.

I also think the progress of Church and Turing is very inspiring. In the 1930s, before computers were even made, scientists and mathematicians were programming in a higher-order programming language: Lambda calculus. The construction of Church numbers and the predecessor function is probably one of the most clever programming constructs ever. It shows you how to make something from almost nothing.

Title: What are some things you have read that inspired and guided you as a programmer?

Body: For example, being a beginner, I find a lot of inspiration and direction from reading this post by Bryan Woods.</p>


问:
How should "git add /**" work?
As noted in this question, I ran into an issue with git add /**.... I can't actually find any documentation on the "/**" form of path specifications - possibly because it's hard to google.

How is it meant to work, exactly? I'm particularly curious that git add /\*\*.py can work but git add /path/foo.py won't - why is the slash allowed at the start of the string with the ** notation?

EDIT more info:

```<code>$ echo /**.py
/**.py
</code>```

(This version of Bash doesn't support shopt -s globstar)

Yet:

```<code>$ git add /**.py
</code>```

adds (silently) a file three directories beneath the current directory. Git apparently doesn't do any globbing at all, so I'm really curious what's going on here.

These also work:

```<code>`git add '/**.py'`
`git add /*******.py`
</code>```

This doesn't:

```<code>`git add **.py`
</code>```

This seems to add all files anywhere in the current working directory.

(Bash 3.2.48 on OSX)

答:
Globs are resolved by the shell when you run such a command, not by git. Try echo /** to see what that resolves to. There is a recursive glob pattern in Bash which uses this syntax, but you have to shopt -s globstar to enable it (it seems to be disabled by default).

git add /\*\*.py tries to add a file called literally **.py. While it's possible to create such a file, it's probably not intended.

git /path/foo.py is meaningless - I assume you meant git add /path/foo.py.

In all these commands, you should remove the initial slash - You generally want to refer to files in a repository by their path relative to $PWD.

echo /**.py will print /**.py unless shopt nullglob is off or you actually have a .py file in the root directory.

Title: How should "git add /**" work?


答:
This makes sense if the method is a utility method. Say for instance you need to derive a unique short name from several free text strings.

You would not want to code up a separate implementation for each string, instead passing the string to a common method makes sense.

However if the method always works on a single member it seems a bit dumb to pass it as a parameter.


问:
Best practices for upgrading user data when updating versions of software
In my code I check the current version of the software on launch and compare it to the version stored in the user's data file(s).  If the version is newer, then I call different methods to update the old data to the newer data version, if necessary.

I usually have to make a new method to convert the data with each update that changes user data in some way, and cannot remove the old ones in case there was someone who missed an update.  So the app must be able to go through each method call and update their data until they get their data current.  With larger data sets, this could be a problem.

In addition, I recently had a brief discussion with another StackOverflow user this and he indicated he always appended a date stamp to the filename to manage data versions, although his reasoning as to why this was better than storing the version data in the file itself was unclear.

Since I've rarely seen management of user data versions in books I've read, I'm curious what are the best practices for naming user data files and procedures for updating older data to newer versions.

Edit:
The 'date stamp' stemmed form a discussion here:

https://stackoverflow.com/questions/8104812/does-releasing-a-new-version-of-the-app-delete-files-of-the-older-one/8104906#8104906

Since the question is too open-ended, I should say I'm looking for the recommended procedures for upgrading user data between versions.

If possible, it would be nice to see iOS / objective-c practices, but it's not required.

答:
In terms of iOS / objective-c, one of the best practices is to use key-value data, along with NSCoder. This allows you to update older data in a fairly straight forward manner.

Another option is to simplify things down to an NSDictionary and save the data out in JSON format (or similar). This has the advantage of significantly simpler common use, re-ordering of data elements between versions is easier to handle (typically you don't have to do anything) but the drawbacks of placing limitations on the data types that can be used and having to check for missing values as a separate process.

If the format of the value for a key changes you can, in some cases, get automated conversion during load (ex: [dataValue intValue] -> [dataValue stringValue] if dataValue is changed from an integer to a string). If needed, you can check the type manually (isKindOfClass/isMemberOfClass) and covert as needed.

As to whether or not to use a date stamp in addition to a version in the data, that depends on what you are attempting to accomplish. If you are just wanting to track compatibility of data between releases of the application then a date stamp has no more meaning than a version # (and perhaps less since it's harder to relate back to the app).

Personally, I use the the NSDictionary/JSON method where I can, and only use the NSCoder setup when I have complex data. If you have large structures that you feel may need updating several times over the course of your application's life span the I'd suggest using the NSCoder setup since it provides the cleanest method of updating data on the fly with the least amount of overhead.

Lastly, for straight C I use a setup for structures that provides simple version checking and data verification. Each struct that I (may) need to be able to update is layer out something like:

```<code>version
element1
.
.
elementX
id_tag
</code>```

Version # is readable in a hex editor (ex: 0x00010000 == 1.0) and the tag is a 4 byte ResType (ex: 'pDat', 'TXT2', etc). I put the id_tag at the end after running into instances of other programmers updating my structures and not updating the version #. Doing so would cause any code attempting to use new data to fail because it's check to validate the data based on the old version # would not find the id_tag in the correct spot. It's not full proof (changing a 4 byte int to a 4 byte float would go unnoticed for instance) but it's decent, cheap, and helpful when viewing a data file with a bunch of these structures in a hex editor.

Hope that helps.

Body:
In terms of iOS / objective-c, one of the best practices is to use key-value data, along with NSCoder. This allows you to update older data in a fairly straight forward manner.

Another option is to simplify things down to an NSDictionary and save the data out in JSON format (or similar). This has the advantage of significantly simpler common use, re-ordering of data elements between versions is easier to handle (typically you don't have to do anything) but the drawbacks of placing limitations on the data types that can be used and having to check for missing values as a separate process.

If the format of the value for a key changes you can, in some cases, get automated conversion during load (ex: [dataValue intValue] -> [dataValue stringValue] if dataValue is changed from an integer to a string). If needed, you can check the type manually (isKindOfClass/isMemberOfClass) and covert as needed.

As to whether or not to use a date stamp in addition to a version in the data, that depends on what you are attempting to accomplish. If you are just wanting to track compatibility of data between releases of the application then a date stamp has no more meaning than a version # (and perhaps less since it's harder to relate back to the app).

Personally, I use the the NSDictionary/JSON method where I can, and only use the NSCoder setup when I have complex data. If you have large structures that you feel may need updating several times over the course of your application's life span the I'd suggest using the NSCoder setup since it provides the cleanest method of updating data on the fly with the least amount of overhead.

Lastly, for straight C I use a setup for structures that provides simple version checking and data verification. Each struct that I (may) need to be able to update is layer out something like:

version
element1
.
.
elementX
id_tag

Version # is readable in a hex editor (ex: 0x00010000 == 1.0) and the tag is a 4 byte ResType (ex: 'pDat', 'TXT2', etc). I put the id_tag at the end after running into instances of other programmers updating my structures and not updating the version #. Doing so would cause any code attempting to use new data to fail because it's check to validate the data based on the old version # would not find the id_tag in the correct spot. It's not full proof (changing a 4 byte int to a 4 byte float would go unnoticed for instance) but it's decent, cheap, and helpful when viewing a data file with a bunch of these structures in a hex editor.

Hope that helps.


问:
What electronic user-story-mapping tools can you recommend?
Agile software development relies heavily on a work item type called user stories.  For example, you have a backlog full of user stories and you can select a few of them to work on during the next sprint.

But where and how do you find user stories to put into the backlog?  There is a popular technique for doing that called story mapping.  Jeff Patton invented it and here is the definitive guide on how to do it.

The question is, what electronic tools are out there that support Patton's story-mapping technique?

I've done a bit of research, found Pivotal and Rally plug-ins (but I'm not a customer of either) and I'm currently experimenting with SilverStories.

What other tools are out there?  What have you used?  What do you (not) recommend?  Why?

UPDATE: Some people who wrote comments seem to lean towards an answer that applying this technique is simply impossible with an electronic tool and we should just accept that.  Can't someone write it up as an answer?

UPDATE (to clarify the question in light of Alex Feinman's comment): the question is about identifying options for story-mapping.  Since Jeff Patton's technique can obviously be done on a white-board with stickies, the question focuses on additional options that might be provided with electronic tools.  (Premature) commitment to any particular tool or class of tools is not the point of this question.

答:
Take a look at Jama's contour.  It's a requirements management tool, but it is quite lightweight compared to the competitors and you can next stories under other ones.  It may not have the card visualisation gear you want.

Now that I think about it you could probably mock his with MS project as well.


问:
Can 'Agile' be applied to Healthcare IT teams?
Can Agile be employed in a field like Healthcare IT, where so much of patient care depends on the quality and timely delivery of systems? </p>

答: Yes, one of the premises of agile development is customer involvement.  This is critical in healthcare IT systems and processes.  Healthcare IT departments will make better decisions if a customer representative is involved and giving input about how the decisions will affect patient care.</p>

OwnerDisplayName: Paul Moutray

OwnerDisplayName: GenuineRex


答:
I do understand your question. A good example of Agile development is building a website for someone. Usually a customer doesn't know exactly what he/she wants, so there's a lot of interaction with the customer.

Healthcare IT might seem like a very predefined field in the computer science; with it's strict standards (DICOM, HL7) it seems like there's only one way to implement them, but there's also a lot of preferences and decision making.

In my opinion, whatever product you're making, you're not able to determine ALL the requirements ahead of time, so an agile software development method works very nicely.

Title: Can 'Agile' be applied to Healthcare IT teams?

Body: Can Agile be employed in a field like Healthcare IT, where so much of patient care depends on the quality and timely delivery of systems? </p>

OwnerDisplayName: Timo Willemsen


答:
Yes, agile development absolutely has a role in Healthcare IT development. No one, not the end-user, not the patient and certainly not the development team is well served by a poorly done development process. Considering some of the principles that underly the Agile manifesto (list shamelessly ripped from Wikipedia with my commentary):

Customer satisfaction by rapid delivery of useful software. When isn't this an objective?

Welcome changing requirements, even late in development. Healthcare IT integrates into a field that, while absolutely inundated with technology, isn't particularly IT focused. The potential for a system being designed to "get it right" right off the bat is pretty low.

Working software is delivered frequently (weeks rather than months). As an end-user of some of this stuff, god would I love this. Rapid, working changes are invaluable, and what turns Healthcare IT from "that thing we need to do" to "that thing that changes the way I do my job".

Working software is the principal measure of progress. Makes sense in most applications, so there's really no reason it wouldn't span to HIT.

Sustainable development, able to maintain a constant pace. You see this all over healthcare, from infection surveillance to HIT to facilities. Healthcare isn't a boom-or-bust cycle, its a constant drumbeat.

Close, daily co-operation between business people and developers. Most HIT isn't a developer tool. It's a tool made by developers. Contact with the client is, and should be, key. It's also much easier to get a system adopted if it works and integrates into the clients workflow, rather than needing to be tacked on, patched, etc.

Face-to-face conversation is the best form of communication (co-location). From my interaction with clinicians, it's way easier to get stuff done in person, preferably with pads of paper, than any other way.

Projects are built around motivated individuals, who should be trusted. This is something that will make your life better - so yeah, it should be adopted ;)

Continuous attention to technical excellence and good design. This is again one of those "everyone should do this, so of course you should" thing. But consider the complexity of HIT systems, and the myriad ways they end up being used, day-in, day-out. A shoddy system isn't going to cut it.

Simplicity. It should work out of the box. It should work well, all the time, and in the way it's supposed to. People are idiots. Healthcare workers are people. Therefore...you know the rest. Simplicity helps.

Self-organizing teams. This one might be a little more of a stretch for HIT. Honestly, I'm not confident enough to say one way or the other whether self-organization in this setting is good or not.

Regular adaptation to changing circumstances. HIT is an active, growing industry with complex, changing regulatory burdens. Being able to adapt seems like a decent idea.

OwnerDisplayName: EpiGrad


答:
As noted, the answer is yes.

When applying Agile to regulated or high risk areas you must define "Done" at each iteration such that regulatory compliance and other risk mitigation strategies are included. For instance, this may require QA documentation, requirements traceability, security audit and other actions to be completed on every iteration.

There's good art and practice, for instance, for application of Agile approaches to FDA regulated environments.

OwnerDisplayName: Arien Malec


答:
Some disciplines are already agile in nature.  Nursing, for example, relies on a an 'assessment-evaluation-planning-intervention' cycles that depends on multiple iterations of diagnosis/prognosis to incrementally achieve final outcomes.

However, it would be a fatal conflation to try to suggest that health care services provided in such a manner are specifically suited to an essentially single-instance application of Agile software development toward a software tool or system for use in said service delivery.

OwnerDisplayName: Stephen


答: I think it is possible, but the industry needs a huge paradigm shift. I'm in my second year as a health care developer, and trust and self organizing are not anywhere apparent. Healthcare would greatly benefit from formally adopting agile, since it's mostly chaos anyway, with iterative development called "thrash" and late changing requirements because, well, big design upfront doesn't work anyway.</p>


答:
The discussions surrounding the use of Agile Medical Device Software Development in a FDA regulated setting have been around for awhile and are relevant to this question. Here are some reasons why:

The Waterfall vs. Iterative development pros and cons are essentially the same and would need to be considered for any Health IT project.

The FDA mandated quality systems (see General Principles of Software Validation; Final Guidance for Industry and FDA Staff) for medical device software development used is the industry gold standard. It should be noted that these regulations do not dictate any particular development methodology. In any case, the quality of Health IT software would be vastly improved if these best practices were followed by all.

Most Heath IT software development does not
currently operate under these FDA regulatory standards. As the
barriers for medical device interoperability continue to fall, in
particular for mobile platforms, this is likely going to
change -- see FDA Addresses Mobile Medical Apps.

Also, if you are developing commercial Health IT software you have to ask yourself if you are creating a medical device data system (MDDS): Is My Product a MDDS?

OwnerDisplayName: Bob Nadler


答:
The short answer is "Yes". A longer but more accurate answer is "If you take it seriously."

There are a few themes to keep in mind, which I like to separate into concerns related to (a) patient safety & product quality, and (b) industry regulation.

On the safety and quality side, keep in mind that making safe software is difficult.  A few good programmers with some domain knowledge can crank out incredibly useful software that's pretty safe. If they are part of the deployment in a local clinical setting, and can keep responding and adjusting to events during deployment and use of the software, the software might provide value, saving or improving lives with only a few injuries or deaths relate to use errors or software bugs.  But the software will require the programmers to be there, all the time, responding, co-evolving the software as the use of the software evolves.  This is not a scalable process and when the programmers die or get bored the system can easily become very hazardous very quickly. In order to improve these outcomes and make safe software, there are important development process steps that need to be taken while the software is developed.  A good "out of the box" introduction to these can be found in the international standard for development of medical device software, ISO/IEC 62304. The main concept is safety risk management at all stages - during use case analysis and story development, requirements elucidation, system and architectural design, implementation, unit and integration testing. Being agile won't make any of this work go away, or be less difficult, but by focusing on value creation and eliminating work (such as unneeded features, or excessive verification test/fix cycles) that does not create value, agile development can allow a team to integrate this work into development, resulting in safer software developed in the same time. The iterative development practices commonly used by agile teams are very well suited to getting the safety risk management work done, evolving throughout the life of the project rather than being an afterthought. And after the software is operational, feedback from the users and any events even potentially leading to injury need to be considered, individually, and in aggregate, to keep the software safe to use. Agile can help here if it provides a fast-track, safe process for incorporating changes without breaking other parts of the system - which in turn once again requires a good architecture and well-understood design interactions that were created when the software was developed.

The second concern is regulatory.  In an ideal world, safety regulations would apply to all products that could be sufficiently dangerous, and a vendor would be able to comply by doing some simple things once they started to cross the line.  In practice, global regulations are complex and fast-moving in this industry, meaning that one day you can be developing a small iPhone app that shows some medical data, and the next you are expected to comply with ISO and FDA standards for "quality management system", or QMS.  That can be scary for companies that have not had a formal QMS in the past. And agile can exacerbate this because you might start out with a product concept, and through evolutionary development enter unwittingly into a regulated intended use (such as displaying clinical diagnosis data to a user). It's October 2011; my advice to any company contemplating marketing a product that has "health", "medical", "healthcare" in the category name is that they should have a plan for when the product they make becomes regulated by one or more medical device regulators worldwide.  Here again agile can help, because the agile practices generally produce (or easily could produce) compliant outputs to satisfy regulatory customers both for pre-market clearance submissions (like FDA 510k), certification (like ISO 13485), and post-market operations.  Test-first development fits right into medical software. Continuous integration, automated unit testing, and SCRUM sprint metadata can provide complete objective evidence that risk management and proper verification are done not just as an afterthought but baked in to the development process. In most cases I think agile produces more artifacts than "waterfall", perhaps not in the same form.  But conversion of the outputs into something satisfying regulators is a relatively small problem to solve.

So in summary... yes Virginia, there is agile for healthcare IT (and other medical device) software development.  Like all things agile, it takes dedication to process, business support, and courage.

OwnerDisplayName: Dave Deaven


问:
What non-programming books should a programmer read to help develop programming/thinking skills?
There are a lot of questions about what programming books should be on the programmer's bookshelf. How about non-programming related books that can help you become a better programmer or developer? It would also be interesting to know why they would help.

My first choice would be Sun Tzu's "Art of War" (however cliché), because it made it obvious that the success of any project depends on the strength of its weakest link (and warfare is a big project).

答:
The single best book on writing I've ever read is The Sense of Structure: Writing from the Reader's Perspective.

It can help you think logically about your writing. It gives concrete advise about the structure of what you say. It's not a book about grammar mistakes or rules, nor a bunch of platitudes-- which distinguishes itself from most other writing books. [At least that I've seen, and I've read "the classics" too.]

Better writing can help you compose better emails, write write clearer comments, and help you realize what you think it important or not.


答:
The short answer:  Yes.  There is a good blog about Agile in High-Assurance Environments that gives some tips.

However, there are some compromises that need to be made.  Consider the Agile Manifesto:

Individuals and interactions over processes and tools

Working software over comprehensive documentation

Customer collaboration over contract negotiation

Responding to change over following a plan

The regulatory bodies value the left-hand side as much as agile teams do, but they require more emphasis on the right-hand side than a typical agile team would do.  The FDA, for instance, requires that you validate your processes and tools, asks for fairly comprehensive design and test documentation, and definitely requires a good deal of planning.

On the flip side, many agile principles fit very well into the healthcare world, including:

TDD and Pair Programming - increase quality

Tight Customer Feedback Loops - early validation is great

Iterative Planning - regulatory bodies are all about planning

OwnerDisplayName: Lynn


答:
AAMI is actively working on a Technical Information Report entitled:

AAMI TIR SW1, Guidance on the use of agile practices in the development of medical device software.

I've heard that it may be published in 2012.

It discusses the alignment of the principles of the Agile Manifesto (see EpiGrads answer) with the regulatory requirements, typical processes and other product practicalities associated with medical device software.


问:
What and how to unit test a django web application?
I am writing unit tests for a web frontend implemented in Django.
I have written unit tests that check that all views return the correct status code (200, 302 etc) so that template errors (which give 500) are found. I also do HTML validation with tidylib.

What else is there I should (or can) do?

Models are unit tested elsewhere, forms have dependencies (namely on models) so is there way to unit test them - in general case there is something one can do, but what can I do (without a huge effort) leveraging the Django/python unit test framework?

答:
If you look at the Model-Template-View triads, each distinct component and any intermediary component in between can be tested separately. Say you have a Foo model and need to add controllers for CRUD behavior in a simple and straightforward manner:

You unit test the Foo model to assert that the business logic is implemented.

You unit test FooForm to assert form.is_valid() is returning expected results for the inputs your tests supply directly.

You only need to assert that the class-based CRUD views are working with the Foo model and FooForm respectively.

In general, there's no extensive frontend testing happening in Django projects, especially those that utilize class-based views and unit test the views directly, you won't see any assertContains/assertNotContains tests at all, although the LiveServerTestCase is going to change that a bit, at least when it comes to asserting behavior for project's that aren't already writing JavaScript tests in one of the testing frameworks.

It's as if you have your backend hat on when your writing unit tests. If you want to add a success message to the CUD views, you'd assert that a success-level message has been added to the list of user's messages after a successful request, but you won't care whether that message is a part of the response or not. Similarly, we test that the context is populated with the correct Foo objects for a request, but we don't care if and how they're displayed.

And this is where Lettuce comes into play, especially if you want to test your application's behavior from a user's perspective. It's appropriate to work with the content of a response object and to ignore the underlying implementations that produced the response. Here you won't care whether or not there is a success-level message associated with a user, you'll just want to make sure it's there in the response and you won't care whether the appropriate Foo objects are in the context, you'll want to assert that their content is present in the response.


问:
Should programmers have access to PHI for development and testing?
My responsibilities at a small company are mostly programming-related, but I also perform a number of other roles that definitely require access to PHI1. In larger organizations with clearer delineation of responsibilities, is it prudent to provide programmers with only dummy data and never actual PHI?

1 Protected Health Information, as outlined by the US legislation that governs patient privacy, HIPAA.

答: There is no reason for programmers to see real patient data. Yes they need to work with data to test and develop systems but dummy data can be built from real data e.g. scambled identifiers, swapping data with other patients etc. Worse case you would have to create dummy data from scratch and this could never cover all scenarios for testing etc. In my opinion (note, I'm not a lawyer) I can't see how using identifiable patient would be ethical or legal in the UK under the Data Protection Act and/or following the Caldicott Principles.</p>

OwnerDisplayName: John Straka

OwnerDisplayName: ajudson


答: I always found Coding Horror and Joel on Software to be inspiring on certain blog posts. They also always made me feel good because I understood what they were talking about and made me think of myself as a programmer.</p>


答:
In our company there's a special section in the employment contract that states that data from  production systems is confidential and should be treated like that.

In the past our development teams worked against copies of production data which makes developing very easy, but makes automated tests very hard. We're now moving to fixed sets of data that can be used in automated tests and in daily development. When building these datasets we try to take real life examples and anonymise them.
We see that developing against these datasets (if there are enough) is as easy as developing against real time data.

Title: Should programmers have access to PHI for development and testing?

Body:
My responsibilities at a small company are mostly programming-related, but I also perform a number of other roles that definitely require access to PHI1. In larger organizations with clearer delineation of responsibilities, is it prudent to provide programmers with only dummy data and never actual PHI?

1 Protected Health Information, as outlined by the US legislation that governs patient privacy, HIPAA.

OwnerDisplayName: nickvane


答:
I don't think programmers should use unanonymized data in day to day development and testing.

I would not exclude the possibility though. In situations where you need programmers to help with acute support cases, it can be a very bad idea to work with something else than the true patient data.

Imagine you need to explain to your customer that you needed to provide them with multiple patches for the same problem, because your programmers weren't allowed to work with production data, and fixed the wrong bug.

OwnerDisplayName: jdv


答:
In general no, programmers should not need access to real patient data.

Practically however, in some cases programmers require access to real, non-anonymized data when bugs can only be reproduced with particular data (problems related to character encodings, especially with something like DICOM which can have a lot of edge conditions with Japanese names).  In these cases there should be policies and procedures in place to deal with these situations (customer agreement and notifications, encryption methods if the data leaves the customer site, retention policies - usually delete the data as soon as it is no longer needed, etc.).

OwnerDisplayName: Peter Tate


答:
Absolutely not on a routine basis. A simulated data set for development purposes is almost trivially easy to construct from real data, and entirely purges PHI from the process.

I wouldn't even have the programmers do that - I would probably turn to a biostatistician or another member of the institution's staff who already has access to those kinds of records. The PHI should be pulled once, to make sure you're developing for something that looks like what the final data should look like, but records from real people shouldn't be used. Too much risk of exposure for very little return.


答: The answer is it depends. If you can refresh the development environments using good masking algorithms, there shouldn't be any need to use production data. The relationships should be considered for masking so that the data is still in tact and just the PHI is masked using algorithms. This ensures that you are using production data and still ensuring PHI compliance. </p>

OwnerDisplayName: kishore


答:
HIPAA makes it pretty clear that access to PHI should be limited as much as possible without putting an undue burden on being able to perform the required tasks.  That would apply to programmers as much as doctors.

This is even more important since thanks to the HITECH Act business associates are now required to comply with HIPAA just like the other healthcare providers.

OwnerDisplayName: techguy


答:
always reintegrate before release. You then get a chance to test and find your bugs, and if there are any, you can either fix them on trunk, or create a new branch to fix the bugs before reintegrating them and repeating the release procedure all over again.

This is the way you should do it - its repeatable, and you know exactly where you are at each step of the way. You can always reproduce what you have, easily.

Merging the branch after release means you have released 'beta' code. If you ever want to revert to the released software some point in the future, you will find it difficult to get an exact copy.

You will never get the QAd version different from the release version - as the QA team will only ever work with the version that you've delivered to them, ie the one you've just merged into trunk.

Title: When to reintegrate feature branch?

Body:
From SVN 1.5, it supports reintegrate feature. I wonder when I should reintegrate. Should it be done before release or after release?

If I do it

Before release

Pro: It is not forgettable to merge with trunk.

Con: Merged version can be different from QAed version.

After release

Pro: Releasing version is same with QAed version.

Con: Some feature from trunk can be missed.

So, when do you reintegrate?


答: Uncle Bob Martin's programming posts. It is no longer active as Robert Martin is now posting videos on his new blog.</p>


问:
Understanding already existing complex code base

Possible Duplicate:

  What is the most effective way to add functionality to unfamiliar, structurally unsound code?

Till now, all I have worked on is with Java projects that I build from scratch (mostly course projects and some hobby stuff). But now, I have come across a huge code base of about 46000 lines spread across around 200 classes. Additionally there are around 10 dependent libraries.

The problem is not only that I have never worked with someone else's code before, but I have not worked with such a huge code-base before too.

I am asked to completely understand the code-base and suggest improvements to the existing design. Now, I am kind of stuck. I start with some part of the code and then by the time I reach some other part of the code, I have lost the working details of the previous part.

I could really use your suggestions and experiences to deal with this issue. How do I proceed/document the details of the classes to understand the code better?

Edit:
This is a university level research project. Students have developed it over couple of years and the bad part: The students who wrote this have already graduated. The existing documentation (only in the form of Javadocs, not UML stuff) is a lot but not helpful in terms of understanding the application design.

答:
I have been working on a complex code base for more than a year now. See if my insights can help you:

Your insights are right, by the time you reach a different part of the code, you forget about the previous part. It can be a never ending cycle. The important lesson to take away here is that the product cannot work without all the parts working properly. Even, if one part fails, the product doesn't work. See it from another angle: if you improve one part dramatically, it still MIGHT NOT result in better working of the product, which is your main goal here.

So, at First: Don't be a developer. Be a tester.

Don't try to understand part by part. Understand the whole product and its working when all parts are together. From a production environment(i.e., a non development environment - no debug points), test the product. Then, just like every tester does, log the problems you face into a bug tracker. Assign the severity and priority to it. As this software existed for quite some time, see if there is already a bug tracker created. If there is one already, you are lucky. Add to those and take time and verify each of the existing ones. At the end of this cycle, you understand the product from a user point of view(you definitely shouldn't miss it) and also a QA point of view. Due course, you might even realize that a line of code will fix the bug, and those who coded it didn't do so as there was no real need back then.

Second Step: Wear you designer cape

Break the product into several parts(not literally or according to your convenience, but according to how they work together). May be your work uptil now or existing knowledge might come into play. Then, try to understand how they work with each other as well as with the 10 dependent libraries. Then, for each tracked bug, write your notes identifying entities of code(e.g.: This change involves modifying classes X,Y,Z, etc.). Probably, by the end of this step, you will have FEW hints of what are the problems with current architecture and what can be improved.

Then, you can decide if the current architecture/design is sufficient and you can go with improving the software OR if the product needs a better design or changes in the existing design.

House of Cards

Also, since complex products come with a lot of code, we might not be in a position to pick up a few things and tweak or improve them. This is because the whole system can be intertwined in such a way that making change to one of the classes is equivalent to changing the position of one card in a house of cards, you never know which end might break. In my experience, this has been true. I have picked a part, improved its code, unaware of the contracts it had with other parts of the code and ended up abandoning the code and realizing my mistake. So, instead of trying to understand parts, try and understand it is a whole.

Prioritize your concerns

You need to keep in mind what you are trying to improve:

Do you want the product to be faster?

Of course you do. But is it the primary of the concerns? Is it being slow? If yes, create performance criteria, identify bottlenecks and improve on those parts. Test again.

Do you want to improve the usability?

Then it's pretty much the API/UI side.

Do you want to improve the security?

Then it's the boundaries you should be exploring.

I have provided only 3 examples, but there are a lot more to look for.

Latest and Best Documentation

I have read here in one of the posts that the latest and best documentation is the code itself. Even if you create a good amount of documentation today, it is history after a while. So, code is your latest piece of documentation. So, whenever you browse through some code, write your understanding in the comments there. While passing the code base, caution them to depend NOT ONLY on comments!


问:
Displaying the number of registered users to a website
I am building an online game much like Mafia Wars. I was thinking of displaying the number of registered users on the home page, but then I thought:

"What if a new user sees that the total number of registered users
  is 5?!" :D

That would be too embarrassing to my still growing game. Then another thought came by:

"Why don't I display 500 instead?!" ;)

Nobody would know if there is actually 500 users registered to my website unless of course they start actually playing and interacting with other players.

However, I just have a feeling that this isn't ethical. What if this generates a negative publicity to my website?!!

What's your opinion should I fake the number? or should I honestly display it? or should I wait till I have 1000 real account then start displaying the number?

And most importantly is this legal?! :D

答:
The legality or otherwise of this will depend on where you are and where your customers are.

However, it is misleading, unethical and misrepresentation - any of which might get you in trouble with someone.

In the initial stages of the life of the game simply don't show the number. Wait until you have a real number to show.

An alternative might be to show the number of new registrations per week or day (assuming that this is a reasonably large number). This way you could still advertise the game as being popular and also encourage users by advertising the number of new people they can play with/against.


答:
User Story 1: Lie to 5 existing users

Since we have only 5 users, we have decided to lie to them and tell them there are 500 users.

Do you really think that these 5 users won't find it strange for a website to be dead even though it claims to have 500 users?

User Story 2: Remind 5 existing users of how inactive the site is

Let our existing users know that there are only 5 of them, so they might as well leave the site.

User Story 3: Scrap user story 1 and user story 2

Scrap first two user stories and concentrate on how you can increase the traffic. Neither user story 1 or user story 2 will generate more traffic.

Title: Displaying the number of registered users to a website

Body:
I am building an online game much like Mafia Wars. I was thinking of displaying the number of registered users on the home page, but then I thought:

"What if a new user sees that the total number of registered users
  is 5?!" :D

That would be too embarrassing to my still growing game. Then another thought came by:

"Why don't I display 500 instead?!" ;)

Nobody would know if there is actually 500 users registered to my website unless of course they start actually playing and interacting with other players.

However, I just have a feeling that this isn't ethical. What if this generates a negative publicity to my website?!!

What's your opinion should I fake the number? or should I honestly display it? or should I wait till I have 1000 real account then start displaying the number?

And most importantly is this legal?! :D


答:
When the number is in the single digits there will nobody to play at the same time you are on. For some games that would be deadly. Team first person shoot games with nobody else on line would be a problem. Hangman like games would take days to play.

If you are charging to register, you have to be honest with the number of people registered and the number currently on line. If you are not they will be moving quickly to cancel the monthly fee, or even ask for a refund.

For a free game, people will not play if the speed of play and the percentage of time they get a live player doesn't meet their expectations. If they expect to see dozens every time they log on, but never see anybody they will quickly stop visiting. Thus hurting you ability to grow.

You should report real numbers, and spend a lot of time getting people to the free version of the site/app. Once the numbers reach a high enough number you can roll out your paid version. This could include extra features, powers or lifelines.


问:
Merits of a "Message Passing" system vs. an "Event Based" system
My question is coming from an somewhat uneducated perspective.

What are the relative merits of a "message passing" system vs an "event based" system.

Why would one choose one over the other? What are their strengths and weaknesses?

I would like to know not just "in theory", but also "in practice".

EDIT:

Specific problem:

I want to build system of plug-able components which behave as small scale services (each performing some small task and or providing some piece of information).

The services can:

be layered so that the output of one service can act as one of the inputs to another

have containment hierarchies so that one service can be contained by another without a specific input-output relationship as mentioned in the previous sentence

The goal of the system is to translate a single flow of low level events in another system into higher level information and functionality, and in addition provide a channel back to the other system providing a single series of events.

I can provide more detail if this isn't enough.

After looking around some more. This and this probably describes my situation better.

This looks like it may be a good fit for my situation: http://akka.io/

答:
In my experience the only specific difference is that in most message passing systems, the sender of the message is aware of (and often declares) who the recipient of the message is.

So instead of raising an event and anyone who is sucscribed to the event getting it, the sender defines some id of the intended recipient(s) or logical group of recipients and then either sends the message directly to them, or goes through a message broker (though the OS can be seen as a message broker in an event based system).

Obviously there's the case of threading that Telastyn mentions with C#'s implementation of events, but you can still create your own pub/sub model that executes on different threads.


答:
"Why don't I display 500 instead?!" ;)

Because that's dishonest. Do you need more reason than that? If you're going to lie about the number of users, what else would you do? Would you rig the game so that your friends do better? And even if you wouldn't, why should your users believe you once they discover that there aren't really 499 other players?

IANAL, but if you use a made-up number of "registered users" to entice people to join your game (and really, why else would you bother displaying the number?), that might be fraud. And legal or not, it's certainly not ethical.

I think you'd be wise to simply not display the number if it's below some threshold. Use some other marketing tactic to encourage early adopters to try the game. For example, SO has a silver 'beta' badge that was only awarded to those people who took part in the private beta phase of the site. You could do something similar by offering early users some sort of bonus for jumping in early. It doesn't even have to be a special resource like the beta badge -- it could just be the possibility of accumulating resources (wealth, weapons, experience, etc.) before there's much competition.


答:
Making up the number of registered users because the REAL number of registered users embarrasses you is simply unethical. It is lying, and if anyone ever found out, you would probably lose many customers as well as trust and good-will with the community. Would you want to play a multi-player game made by a company that deliberately lied about the number of online players? Don't do it!

Why not have a very simple piece of code that says

```<code>if numberOfUsers > 500 then
    bannerMessage := "More than 500 registered users! Play today!"
else
    //You could also have a random number generator choose one of n messages that says something like "Play now!", "Have Fun today!", etc...
    bannerMessage := "Sign up to play today!"
end if;
</code>```

Another possibility, though this might only apply to certain types of games, is to have some "bots" (AI-players) always online, in case the number of human players online falls below a certain threshold. I've seen this most often in online first-person-shooter games (though there's no reason it couldn't be done with the other games - but that's what I played the most of, so that's mostly where I saw it). I forget which one but I am pretty sure there was at least one where the game host could configure a minimum  number of players in the game  and if there weren't enough human players to meet that number, the rest of the players would be filled in with bots.

Body:
Making up the number of registered users because the REAL number of registered users embarrasses you is simply unethical. It is lying, and if anyone ever found out, you would probably lose many customers as well as trust and good-will with the community. Would you want to play a multi-player game made by a company that deliberately lied about the number of online players? Don't do it!

Why not have a very simple piece of code that says

if numberOfUsers > 500 then
    bannerMessage := "More than 500 registered users! Play today!"
else
    //You could also have a random number generator choose one of n messages that says something like "Play now!", "Have Fun today!", etc...
    bannerMessage := "Sign up to play today!"
end if;

Another possibility, though this might only apply to certain types of games, is to have some "bots" (AI-players) always online, in case the number of human players online falls below a certain threshold. I've seen this most often in online first-person-shooter games (though there's no reason it couldn't be done with the other games - but that's what I played the most of, so that's mostly where I saw it). I forget which one but I am pretty sure there was at least one where the game host could configure a minimum  number of players in the game  and if there weren't enough human players to meet that number, the rest of the players would be filled in with bots.


答:
Is this Legal?: Probably, as long as you don't accept money based on the number (e.g. from advertisers or from people who specifically want to play the game with other people). Otherwise, you're effectively lying to them to make money, aka Fraud.

Is this Ethical?: Of course not. Generally, when you have to ask on a website if something is ethical, then it's unethical. If something can be described as lying, it's unethical. If you're worried it might be illegal, it's unethical.

What to Do: FOCUS ON THE PRODUCT. Is displaying the number of users going to affect the end product? No. Is it going to take up time to write that could be going on the product? Yes. Is it going to demonstrate the actual quality of the product? No. Is it going to encourage people to use your product? Slightly, but they will immediately feel cheated when they work out you've lied to them, and thus blacklist you.

There are better ways to advertise yourself than going "Look how many people like meeeeee!" Do one of them instead.


答:
I have a very reliable rule of thumb when it comes to metrics: If I'm not proud of a value, I don't advertise the value.

First of all, let's talk about what that doesn't mean. It doesn't mean lying. This can be tricky sometimes, but there's a difference between lying and lack of disclosure. For example, I'm still in college, and I don't put my GPA on my resume. I do this because my GPA is less than stellar, and while there are understandable reasons, I can't fit an explanation on my resume, so I leave it off. If someone asks me about it in an interview, I'll tell them my GPA without hesitation, but then I've got a chance to tell the story behind it. If all someone has to go on is a metric, and the metric is bad, they'll jump to conclusions. Don't give them the chance if you know the conclusion they'll jump to isn't correct. If someone asks, tell them, but don't advertise it if you don't have to.

So what I'd recommend is actually right in your question:

should I wait till I have 1000 real account then start displaying the number?

Post milestones, and once you reach a reasonable minimum, post a dynamic counter. Brag about success, but wait to draw attention to it until it's something you're proud of. Never forget about metrics you're not proud of, because those are areas you want to invest in, but you don't need to shout it to the world until you're doing something about it.


问:
Querying types in a co- or contravariant way
I posted a c# feature request here; however, I do not get a lot of attention there. Therefore I am asking you here, what you think of it.

The in and out keywords in generic type declarations are useful; however, due to their nature, their application is limited to a small number of types. What I am suggesting here, is to be able to use them in declarations of variables, fields, parameters and possibly properties in order to restrict the set of possible operations on any generic type in a dynamic and temporary way. This would considerably increase the cases where co- and contravariance could be used.

Examples

// A List of a more derived type can be passed
public void ReadList(IList<out MyType> list)
{
    MyType item = list[0];  // OK
    list[0] = new MyType(); // DISALLOWED because of "out" keyword!
    list.Add(new MyType()); // DISALLOWED because of "out" keyword!
}

// A List of a less derived type can be passed
public void WriteList(List<in MyType> list)
{
    MyType item = list[0];  // DISALLOWED because of "in" keyword!
    list[0] = new MyType(); // OK
    list.Add(new MyType()); // OK
}
```

<p>--</p>

<p><strong>UPDATE</strong></p>

<p>Taken these declarations</p>

```class LessDerived { }

class MyType : LessDerived { }

class MoreDerived : MyType { }
```

<p>You could use the methods shown above like this</p>

```var listOfLessDerived = new List<LessDerived>();
var listOfMyType = new List<MyType >();
var listOfMoreDerived = new List<MoreDerived>();

ReadList(listOfMyType);
ReadList(listOfMoreDerived);

WriteList(listOfMyType);
WriteList(listOfLessDerived);
```

答:
The in and out keywords in generic type declarations are useful; however, due to their nature, their application is limited to a small number of types. What I am suggesting here, is to be able to use them in declarations of variables, fields, parameters and possibly properties in order to restrict the set of possible operations on any generic type in a dynamic and temporary way.

Java has this feature. An interesting fact: the "call site" variance feature in Java and the "declaration site" variance feature in C# were both designed in large part by my colleague Mads Torgersen.

I am asking you here, what you think of it.

It's a reasonable feature with many interesting scenarios. We considered it and rejected it. The benefits did not outweigh the costs.