问:
Is it poor technique to have functions within a class depend on one another in a "cascade" type fashion?
I am fairly new to PHP and OOP.  Having said that, I wanted to know how independent functions should be within a class.  I know that each function should be responsible for doing just one thing.  However, as you can see in my class below, I occasionally find myself creating functions that build upon one another in a "cascade" type fashion.

Is this good practice?  Is there a different way I should be structuring this class/these types of functions?  I want to make sure I am developing good habits.

Thanks in advance for your help.

```<code>class PubMedQuery {

private $query;
private $searchParameters;
private $searchURL;
private $fetchParameters;
private $fetchURL;
private $searchResults;
private $fetchResults;
private $matches;
private $matchRegex;
private $emailAddresses;

public function __construct($query) {
    $this->query = $query;
}

public function setSearchParameters() {
    $this->searchParameters = array(
        'db'         => 'pubmed',
        'term'       => $this->query,
        'retmode'    => 'xml',
        'retstart'   => '0',
        'retmax'     => '1000',
        'usehistory' => 'y'
    );
}

public function getSearchParameters() {
    return $this->searchParameters;
}

public function setFetchParameters() {
    $this->fetchParameters = array(
        'db'        => 'pubmed',
        'retmax'    => '1000',
        'query_key' => (string) $this->searchResults->QueryKey,
        'WebEnv'    => (string) $this->searchResults->WebEnv
    );
}

public function getFetchParameters() {
    return $this->fetchParameters;
}

public function setSearchURL() {
    $this->baseSearchURL = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils /esearch.fcgi?';
    $this->searchURL = $this->baseSearchURL . http_build_query($this->getSearchParameters());
}

public function getSearchURL() {
    return $this->searchURL;
}

public function setFetchURL() {
    $this->baseFetchURL = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?';
    $this->fetchURL = $this->baseFetchURL . http_build_query($this->getFetchParameters());
}

public function getFetchURL() {
    return $this->fetchURL;
}

public function setSearchResults() {
    $this->setSearchParameters();
    $this->setSearchURL();
    $this->searchResults = simplexml_load_file($this->getSearchURL());
}

public function getSearchResults() {
    $this->setFetchParameters();
    $this->setFetchURL();
    return file_get_contents($this->getFetchURL());
}

public function setEmailAddresses() {
    $this->matches = array();
    $this->matchRegex = '/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/';
    preg_match_all($this->matchRegex, $this->getSearchResults(), $this->matches);
    $this->emailAddresses = array_unique(array_values($this->matches[0]));
}

public function getEmailAddresses() {
    $this->setSearchResults();
    $this->getSearchResults();
    $this->setEmailAddresses();
    return $this->emailAddresses;
}
}

//Example using search term "psoriasis"
$query  = new PubMedQuery('psoriasis');
echo implode('<br />', $query->getEmailAddresses());
</code>```

答:
To answer your question, no, it's not at all bad practice to divide the internals of a class across multiple methods as you've done here. As the other answers and comments have said, it's actually good practice.

You're on the right track, but I did see a couple of things that I think need attention. From the example you give outside the class definition, it appears that the primary use of objects derived from this class is (roughly) to extract email addresses from a PubMed query. You've divided the general tasks needed to do this throughout the class appropriately; however, many of these tasks merely set some immutable information. Do these sorts of methods, e.g. setSearchParameters(), really need to be accessible outside the class? I would argue that no, they don't- because most of these methods do nothing beyond getting or setting private member variables.

I bring up the whole encapsulation issue because one way you could improve your code would be to drop some of the private member variables unless you absolutely need them. I don't know the requirements of your project, but it appears to me that each PubMed query being made is represented by its own object. If so, is it necessary to make, for instance, the $searchParameters variable a class member? Why not simply do something like:

```<code>public function setSearchParameters() {
    return array(
        'db'         => 'pubmed',
        'term'       => $this->query,
        'retmode'    => 'xml',
        'retstart'   => '0',
        'retmax'     => '1000',
        'usehistory' => 'y'
    );
}
</code>```

And then, for the next method in the sequence:

```<code>public function setSearchURL() {
    $baseSearchURL = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils /esearch.fcgi?';
    return $baseSearchURL . http_build_query($this->setSearchParameters());
</code>```

}

Why do this? Try to think about what a member variable really is- it's a representation of the state of the object in question. The $query member makes sense; it represents the basic state of the PubMedQuery object. Working backwards from the top-level method, getEmailAddresses(), everything in the object essentially depends on the $query member. At least in the code you've provided, the other methods simply operate on this member variable in succession. (I'd probably set the $baseSearchURL variable as a constant instead of a variable, but that's beyond the scope of this answer).

Removing the $searchParameters member variable and structuring your code more like what is shown above also gets rid of the need for the getter method, which reduces coupling. If for some reason another object needs the non-member $searchParameters variable produced by the setSearchParameters method, you can keep that method public. If you're sure no other objects will need it, make it private or protected. Again, I don't know your requirements, but I suspect nothing beyond your top-level method really needs to be public. To further reduce coupling, if you do make only your top-level method public, you can define it as an interface method. This way, objects that depend on your PubMedQuery object can depend on the interface instead.

I generally tend to try and rethink the design of a class if I wind up with more than a few member variables. If it turns out I really need an object to keep track of that many states, I start thinking that maybe I might want to refactor some of the code of that object into other objects. An object should only have one responsibility. I'm sure cases exist, but I personally have never had to make an object that needed to keep track of more than four or five member variables at most in order to fulfill that responsibility.

Overall, you're definitely on the right track. Subdividing the overall responsibility of an object into multiple methods that depend upon one another within a class is definitely good practice. What I've discussed here is simply taking things to the next level.

Body:
To answer your question, no, it's not at all bad practice to divide the internals of a class across multiple methods as you've done here. As the other answers and comments have said, it's actually good practice.

You're on the right track, but I did see a couple of things that I think need attention. From the example you give outside the class definition, it appears that the primary use of objects derived from this class is (roughly) to extract email addresses from a PubMed query. You've divided the general tasks needed to do this throughout the class appropriately; however, many of these tasks merely set some immutable information. Do these sorts of methods, e.g. setSearchParameters(), really need to be accessible outside the class? I would argue that no, they don't- because most of these methods do nothing beyond getting or setting private member variables.

I bring up the whole encapsulation issue because one way you could improve your code would be to drop some of the private member variables unless you absolutely need them. I don't know the requirements of your project, but it appears to me that each PubMed query being made is represented by its own object. If so, is it necessary to make, for instance, the $searchParameters variable a class member? Why not simply do something like:

public function setSearchParameters() {
    return array(
        'db'         => 'pubmed',
        'term'       => $this->query,
        'retmode'    => 'xml',
        'retstart'   => '0',
        'retmax'     => '1000',
        'usehistory' => 'y'
    );
}

And then, for the next method in the sequence:

public function setSearchURL() {
    $baseSearchURL = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils /esearch.fcgi?';
    return $baseSearchURL . http_build_query($this->setSearchParameters());

}

Why do this? Try to think about what a member variable really is- it's a representation of the state of the object in question. The $query member makes sense; it represents the basic state of the PubMedQuery object. Working backwards from the top-level method, getEmailAddresses(), everything in the object essentially depends on the $query member. At least in the code you've provided, the other methods simply operate on this member variable in succession. (I'd probably set the $baseSearchURL variable as a constant instead of a variable, but that's beyond the scope of this answer).

Removing the $searchParameters member variable and structuring your code more like what is shown above also gets rid of the need for the getter method, which reduces coupling. If for some reason another object needs the non-member $searchParameters variable produced by the setSearchParameters method, you can keep that method public. If you're sure no other objects will need it, make it private or protected. Again, I don't know your requirements, but I suspect nothing beyond your top-level method really needs to be public. To further reduce coupling, if you do make only your top-level method public, you can define it as an interface method. This way, objects that depend on your PubMedQuery object can depend on the interface instead.

I generally tend to try and rethink the design of a class if I wind up with more than a few member variables. If it turns out I really need an object to keep track of that many states, I start thinking that maybe I might want to refactor some of the code of that object into other objects. An object should only have one responsibility. I'm sure cases exist, but I personally have never had to make an object that needed to keep track of more than four or five member variables at most in order to fulfill that responsibility.

Overall, you're definitely on the right track. Subdividing the overall responsibility of an object into multiple methods that depend upon one another within a class is definitely good practice. What I've discussed here is simply taking things to the next level.


问:
What are these different Java versions for?
I am just about to start my Java journey, ( I've already dabbled in C++) but I am getting really confused about all the different versions of Java:

JavaSE

JavaEE

JavaFX

etc.

Can someone explain these in detail?

答:
Java Proper

Java Standard Edition is the "normal" version designed for general computing. It, like all other variants of Java, is a strongly, statically typed, bytecode-compiled, Object-Oriented language run on a virtual machine with fully automatic garbage collection. It has most of the features of the language. Examples of applications would be applications like Minecraft or ArgoUML. It can be run as a stand-alone desktop application or an embedded application on a web page as an Applet.

Java Enterprise Edition is not a different language but are Interface specifications designed to produce software that runs inside an Application Server implementation. The main difference here is that it is designed for deployment to Application Servers that conform to the Enterprise Edition Interface specifications; Java SE can be used to write stand-alone servers but doesn't include standardized Interfaces and specifications purpose-built to in the way Java EE is. Examples would be applications designed to run on Glassfish ( Java EE reference implementation ), JBoss, etc.

Java Micro Edition is Java designed to run on Mobile devices. It should be noted that this is not the same thing as Android. Java ME is designed to deal with mobile hardware better than Java SE. I use a Pantech Ease as a mobile phone, it runs Java ME.

Java Card is even "smaller" aimed at really low-end devices like Smart ATM cards. Yes, some of them actually have Java on them.

JavaFX is a framework designed to build Rich Internet Client GUI Applications.

JVM language Family

First, the JVM. This is a stack-based virtual machine running compiled bytecode which looks a lot like assembly language. Optimization can make it run quite fast for very specialized situations.

That's it for the actual Oracle Java Stuff, now for the stuff people commonly use on the JVM. All of these languages feature Java interop and can typically call most or all of the Java libraries.

Groovy is an Object-Oriented, dynamically typed language with a more succinct syntax that is billed as an easier, more powerful alternative to Java. It was designed as a kind of extension language to Java, allowing nearly drag and drop of Java files into Groovy programs. It has a framework commonly associated with it for web development known as Grails.

Scala is a fairly recent (2003) hybrid object-oriented/functional language that is designed to be highly scalable, hence the name. Twitter is a heavy user of Scala.

Clojure is a recent (2007) functional language of the Lisp family. It's designed for heavy concurrent programming from the outset. I don't have a good software example for this one but there are a number of companies using it.

Jython and JRuby are the Java bytecode versions of Python and Ruby respectively.

There are a number of other languages for the JVM out there like Jaskell (Haskell for the JVM) but they tend to be obscure/academic experiments.

Related Stuff

Android uses Java but runs on the Dalvik register-based machine. Dalvik is currently the object of a lawsuit against Google, its adopter. Android is essentially Java SE with a different set of Libraries.

Netbeans and Eclipse are the two most widely talked about Java IDEs. Asking questions about one vs the other will invoke closure and I don't mean the programming concept.

Unrelated Stuff

Javascript is not Java...at all. It was named that to take advantage of Java's popularity and the confusion has been annoying ever since.

The Rhino in the Room

Rhino is a Javascript interpreter that turns Javascript Code into Java code that can then be run somewhere. It's not a separate language "per se" but like anything else has its own set of quirks. Rhino is developed by Mozilla as an alternative to their C-based SpiderMonkey interpreter. Rhino is typically used to embed Javascript within a Java program.

Nashorn, developed by Oracle (possibly with German levels of efficiency) for the JDK 8, appears to be the new standard for embedded Javascript within Java. This would mean that Rhino is no longer used for the main implementation of Java. What this means for the Rhino project is unclear at this time.

ContentLicense: CC BY-SA 3.0

ContentLicense: CC BY-SA 4.0


问:
Model independency in MVC and most efficient way to do method calls
TLDR: Are models supposed to be application-dependant and totally worthless when starting a new application, or are you supposed to design models independently so that they act as stand-alone classes/libraries? (This would make little sense with a framework such as CodeIgniter where you extend the CI_Model which obviously won't be there in your Kohana project.) I've also read several similar questions to some of my points here, but this is the main point which I have not found an answer to.

I've been using CodeIgniter for quite a while which introduced me to the MVC pattern. Even though it took a while to get into it has paid off the more I've read, reflected and inspired myself about it, however there is something that has always been constantly annoying me; how to properly put together a valid, efficient and working composition of objects.

Considering the three different workareas of the MVC structure I use (controller, model and library - yes, I said library, for independent class inclusion), I've had a hard time deciding whether the model should act as an independent class itself or only act as a structure to the application as the so-called 'black box', 'business model' or 'fat model'.

I do keep my controllers 'skinny' and try to do so because all documentation I've read have tried to point that out, but since the controller is application-specific and not independent (in such a way that I could just take it from the application and apply it to another totally different application), I've come in confusion if the model is supposed to act in a similar fashion, simply being a pair of organized 'fat' classes being tied to the main application, losing all their worth if moved to a totally new project.

And exactly this is the core of my problem and I really need to get a crystal-clear definition about this. To help you further understand what I mean I can give a few examples:

I'm making an application with PHP at the moment where I have a model called users.php. Within this class I have methods working against the 'users' table, such as this:

```<code>/**
     * Runs the login credentials against the database
     * @param string - username
     * @param string - password
     * @return user_id / false
     * */
    public function verifyLogin($username, $password) {

        $password = $this->_hashPassword($password);

        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $this->db->where('activated', 1);
        $this->db->where('deleted', 0);

        $query = $this->db->get(DB_PREFIX.'users');

        if ($query->num_rows() > 0) {
            $r = $query->result_array();
            return $r[0]['id']; // User ID
        }

    }
</code>```

The model is loaded into the framework and I call this method from the controller like this:

```<code>$this->users->verifyLogin($_POST['login_username'], $_POST['login_password']);
</code>```

The way I used to call it before was $this->users->verifyLogin();, letting the model simply take the $_POST variables and figuring it all out by itself. I just changed this as I would assume that controlling all input and output should go through the controller, virtually leaving the model 'actually fully encapsulated' even to me as the author of the code.

This shows the connection between my Controller and my Model, but what if I decided to use an independent library, say a Validation class I had made? Where would I implement this stand-alone class? Let's pretend this is a snippet of my application where I use my poorly designed validation class to give me an exception:

```<code>require_once('validator-class.php');

$val = new Validator($_POST['login_username']);

try {
$val->max_length(16)
    ->min_length(4)
    ->alpha_numeric();
}
</code>```

Would I put this code into the controller or the model for best effect? If the model would be application-dependant, it would make most sense to delegate/call the methods of the library class from within the model and then very easily just call the model in a more simplified fashion such as a save() method where everything would be taken care of behind the scenes.

I've come to wonder if the controller is supposed to be used as a 'main area' for connecting the dots, being the place where I would call the methods of every class, delegate them to the model etc. while keeping the model 100 % outside-class-clean, only relying on itself solely and surely. But then again, if the model is supposed to be application-dependant, this would make little sense as I would not take the model with me to a new project and should instead just do all the calling and messy procedures within the encapsulated class.

I must apologize for the long explanation, but I struggle with even using the MVC pattern with this question in mind to the extent I'm seriously considering just letting go and moving back to the hard, pure PHP. Some help would be very appreciated. Also, a few tips on documenting class methods would be very welcome as a bonus.

Thanks a great deal!

答:
Would I put this code into the controller or the model for best effect?

Validation is part of your application domain and therefore should be located in your model. All functionality which is specific to the web interface, e.g. handling HTTP requests, cookies, session data, should be located in your controller or view.

Think of your model as the whole application without a user interface. You should be able to extend your application with an additional interface, e.g. web service, without changes (or only little changes) to the model. Also, all interfaces have to obey to the very same business rules, e.g. username may only consist of alphanumeric characters.

The way you changed your $this->users->verifyLogin($_POST['login_username'], $_POST['login_password']); method is the right way to go. By doing this the verifyLogin method does not depend on an HTTP POST request (with some specific parameter names) but instead can be used in various situations thus improving code quality, maintainability and separation of concerns.

To cite Wikipedia:

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


问:
Is C a MUST-learn language for programmer?

Possible Duplicate:

  I don't know C. And why should I learn it?

I start my programming from Java, and learned PHP. Also, because of the work, I learned Objective-C. But most of the programmer learn from C. So, is this necessary for a programmer to learn C? If yes, how important it is? Please drop your comments, thanks.

答: I'm a programmer and I don't know C</p>

Body: I'm a programmer and I don't know C


答:
Necessary is probably not the correct word.  However, the languages you are familiar with probably come from C (I think Java and PHP do, but I'm not positive) and C is a great language if you are interested in systems/low level programming.  It would probably be beneficial.

Is it ever not better to have a broader range of tools? :P

Title: Is C a MUST-learn language for programmer?

Body:
Possible Duplicate:

  I don't know C. And why should I learn it?

I start my programming from Java, and learned PHP. Also, because of the work, I learned Objective-C. But most of the programmer learn from C. So, is this necessary for a programmer to learn C? If yes, how important it is? Please drop your comments, thanks.


答:
No. Not really.

The reason why "most of the programmer learn from C" is that it is taught in most colleges as the (one of the) first programming language(s), along with some LISP variant.

I was taught C as the first language in my degree, without LISP. So if you asked about my first language, I would have said C, but without any bearing on the kind or level of programming I have (which I think has a lot of scope for improvement).


答:
The simple answer is no.

The reason why people think that C language is kind of must is because other languages such as Java, mainly C++ all borrow's some principles from C and adds more functionalities on to their languages.

So, is this necessary for a programmer to learn C?

No, but it is necessary for any programmer to have programmatic thinking. Thats what I guess the most important.


问:
Alternativates to HTML Help
We currently use a system called AsciiDoc which allows us to create documentation in a simple text markup. From that we can generate multiple output formats. We only make use of the pdf output and chm output formats.

I was wondering if there was an alternative to chm? What I am looking for is something that can be used off-line (this is important because quite a few of our users are in very remote places) with our software. It should have an index (it can be as simple as an html page with hyperlinked terms), it should be searchable and it should have a mechanism that allows specific entries to be called up from the code (similar to context sensitive help).

The two things that are against PDF in this case is:

Context sensitive help isn't an option

Generally the document is rather large

PDF is more suitable to printed documentation than context sensitive help

What I would like is to use html. The only problem with html is that I can't seem to figure out how to automatically provide a keyword search (other than the browsers ctrl+f functionality - I would like something more apparent). I also can't seem to find a method to automatically generate a hyperlinked index of key words. Context sensitive help would be simple because of the section tags - I could simply pass the url of the page and section that I am interested into the default browser and that page should load up to the correct section.

My requirements sound an awful lot like chm - they do. I modeled my requirements off chm. The only reason I don't like chm is because of the way the code interacts with it using mapids and such. I would much rather use store a plain text list (that is automatically generated for me) that my code can use to access the context sensitive portion of the documentation.

I am envisioning a script that would go through the html output files and generate an index page that simply contains a list of keywords that it found. obviously there should be word exclusion mechanism to ignore words like: the, it, is, etc.. This part would be relatively easy to write. The second part would need a script of some sort to put together a database of keywords and their location within the html text. I think this would be the tricky part along with providing the search mechanism within the browser.

Any ideas on alternatives would be appreciated. I would love to use a wiki or set of static html pages hosted on a webserver somewhere, but we have a critical offline usage requirement. Simply placing the html on the local drive doesn't provide us with the search requirements that we need.

EDIT:

I design software that is used by the mining industry. A lot of mines are very remote and do not have access to the internet in any meaningful way. There is nothing wrong with pdf or html or chm (except that it is getting old). If I could display a pdf file at the correct location (i.e. context sensitive help) I would use it. I am almost tempted to write my own - basically it would be a portable wiki. Speaking of that, if you suggest portable wiki - you have to think of the end user which may have no experience in using such tools. It has to be dead simple. That was the beauty of chm, it is a pain to work with but the end users like it.

答: We've been using Adobe RoboHelp to generate various styles of offline help documentation. It provides many output and integration options for content. The great thing about this tool is you can hand it to non developers and get great content with little effort integrates into your solution. </p>

Title: Alternativates to HTML Help


答:
I believe that is is very important to know at least one native compiled language for every programmer who writes desktop applications (and for system programmers of course). And most native APIs are in C++ or C.

If you know only languages such as Java or python you will do well most of time but as soon as you need some obscure not-often-used function (optimisation, some kind of hooks, integration with platform for better UX etc.) you will find yourself in a trap.

It's probably very rarely needed if you are writing web sites/services/servers/enterprise apps. The thing is I can't imagine myself writing only such (web) applications. It's probably only me but I find system programming, desktop apps, web apps and services and scripts all interesting and don't want to restrict myself to specific area.


问:
Is the Product Owner also a developer on your team?
I'm confused about the PO's responsibility here. I was a developer on a Game Feature Team, but  also a PO. The daily work of the developer is almost full time, so I have to work over time to take care my PO duty, and the responsibility of PO seems to be against developer's thoughts.

As a PO, I will chose more features next sprint. Otherwise, I will tell myself not to do so, because I'm a team member to develop those features. This situation makes me confused, so I want to hear some ideas from you guys.

I'm a new to Scrum and Game Dev (about 1 and half year), and also new to here and English.

答: Almost always a bad idea. We had a project manager who was a product owner and that was conflicting enough. </p>

OwnerDisplayName: Charlie

OwnerDisplayName: Moin Zaman


答: In my experience, the product owner is either a PM/TPM or a member of the business team. While it isn't impossible for the PO to be a dev, there is some danger of conflict of interest. If your product is highly technical, the PO should have a dev background. If it is less technical and more end-user focused, then a PO with biz experience is critical.</p>

Title: Is the Product Owner also a developer on your team?

Body:
I'm confused about the PO's responsibility here. I was a developer on a Game Feature Team, but  also a PO. The daily work of the developer is almost full time, so I have to work over time to take care my PO duty, and the responsibility of PO seems to be against developer's thoughts.

As a PO, I will chose more features next sprint. Otherwise, I will tell myself not to do so, because I'm a team member to develop those features. This situation makes me confused, so I want to hear some ideas from you guys.

I'm a new to Scrum and Game Dev (about 1 and half year), and also new to here and English.

OwnerDisplayName: ObscureRobot


问:
How to convince a teammate, who sees oneself as senior, to learn SVN conceptual basics?
To start with some background, I took up a new developer position this summer and ended up being the newest member on the team, yet with most experience under the belt.

So far I have managed to push sanity initiatives through easily enough because of low adoption costs (in terms of time and effort). However things have leveled up a bit.

One of my teammates, although experienced, does not really understand SVN. Naturally, blank areas on his mental map depicting oceans of SVN cause him to adopt rather strange usage patterns.

For example, he had declared a policy of "1 SVN commit per day per developer" because otherwise "the server would soon run out of disk space". When I explained him that SVN commits are deltas, not full copies, he responded with doubt and even today I'm not entirely sure if he understands what it means.

We also had a heated argument about whether to include Eclipse .project configuration in SVN. My teammate insisted we should, although it has caused numerous pointless conflicts. I was against keeping individual developer configuration files in SVN. Finally, it turned out that my teammate had a practice of re-checkouting the entire source tree after every commit to just make sure "code committed into repository works". That was the reason he was so adamant in keeping the project configuration in SVN - so it would be easy to re-import the project. When I explained that commit synchronizes working copy to remote byte-by-byte which makes re-checkout unnecessary, my teammate responded with doubt again and eventually waved the whole issue off as insignificant.

In my opinion, our team wastes time by resolving SVN conflicts in project configuration files which contain only developer-specific settings that need not be shared to SCM at all. All this mess because someone tailored the process around incorrect assumptions.

How can I convince a teammate, who sees oneself as senior, to get a better understanding of SVN basics?

答:
This is pretty much a case of "lack of authority" and a person who applies the power of his own fear to keep things "under control" </p>

<p>To resolve this find someone that has inspired your teammate or someone who he respects and that is able to explain the urgence of using something like SVN. That way his fear for change and basically "losing authority" is not in play beacause it is not a team member telling him what to do. I would refrain from using someone like a manager to speak to this guy because that only adds pressure and might even create a more stressful situation for yourself. </p>

Body:
This is pretty much a case of "lack of authority" and a person who applies the power of his own fear to keep things "under control"

To resolve this find someone that has inspired your teammate or someone who he respects and that is able to explain the urgence of using something like SVN. That way his fear for change and basically "losing authority" is not in play beacause it is not a team member telling him what to do. I would refrain from using someone like a manager to speak to this guy because that only adds pressure and might even create a more stressful situation for yourself.


问:
App shell using MEF
I am designing an WPF app shell using MEF. I would like to have the app start a "view" upon startup. I also would like the option of having another add-in have a "startup" attribute and then the app would load that one instead. I've made an interface:

```<code>[InheritedExport]
public interface IStartupParams
{
    /// <summary>Gets or sets the WindowMode property.</summary>
    WindowMode WindowMode { get; set; }

    /// <summary>Gets or sets the NavigateUri property.</summary>
    string NavigateUri { get; set; }

    /// <summary>Gets or sets the Priority property.</summary>
    int Priority { get; set; }
}
</code>```

So the app would load multiple IStartupParams concrete classes and select the one with the highest priority.

What do you guys thing about this design? Any ideas?

答: Since you like the startup of items of your app to be configured, I would most certainly push out these configuration items into an external source (appsettings). That way you are able to restore original startup without having to hardcode anything and it will also be easy to accomodate the extensibility and priorities you're describing. </p>

Title: App shell using MEF


答:
I've been programming for a very long time (yes I remember a time before PC's) and have a lot of different languages that I have worked on.

Each language tends to borrow from the ones before and for that reason alone knowing your way around a few of the "root" languages can give you insight into why things are the way they are (uncluttered by more modern methods), in the same way as fixing a Model-T will tell you more about engines than fixing a Ferrari.

However, while my knowledge of assembly language gives me the odd clue as to why some things work the way the do (or more often why they don't work), would I learn assembly language now if I was starting out again? No, my time is more valuable than that.

And while C is more common than assembly language, the same applies. Unless you plan to work in C or have a lot of spare time, I would say your time would be better spent in more modern languages. The more of them you know, the more you will "see" the common roots, with the added benefit of making yourself more marketable in the current workplace.

Just the opinion of an old warhorse.


答:
As a programmer (assuming you are a good one) you will be invested in your code. As a owner or manager you need to be invested in the product.

These are not always the same thing. And when they are not you will have big problems.

I've always said that the role of a good manager is to block the crap from above and to steal my code away from me when it's good enough. Without a manager I could work on a single function for the rest of my life, forever improving it.

Owners need to look at the big picture, programmers need to look at the details. You can't do both unless you are God!


答:
As a leader, manager and team member, I have had to deal with resolving professional and personality conflicts on many levels. No matter what role I am hired into, I typically get accepted as the leader even when I do not want the role. The reason for this is the way I deal with these conflicts.

Unlike many of the people here, I do not agree that dealing with this situation is a "give up" or "show him a new tool" or "wait for him to fall on his butt or disapper". Most importantly, it is never a good idea to wait until roles are more firmly defined. Those roles get defined by people who do not wait, by their convictions, ethics and ability to deal with critical situations whether they involve people or not.

There are several methods to dealing with the type of person you are describing in these situations. The first and foremost step is to investigate why he is behaving the way that he is. It has little to do with what he knows or doesn't know. He could easily have found out this information previously, so the question really is one of two things: "Why didn't he?" or "Why is he rejecting the information he is being provided?" This will aid you into finding what exactly needs to be addressed.

In my experience, programmers (including myself) refuse good practices or new tools for just a few reasons:

The source is not credible. In an industry that becomes more and more polarized each day between the "cult of Mac" and the "MS worshippers"; between "Open Source Ideology" and "Proprietary Practicality"... etc etc  --  There are many who always have doubts about the information provided and its potential of corruption due to the bias of the submitter or the writer, even when that information is verified as credible.

Prolonged Bad Experiences... with a similar or even the same technology or practice. Nothing is perfect when it starts, and many start out with less than 1/4 of the features than they end up with. It is entirely possible that he had many hours or days or even weeks working with either an inferior product or the same one during a poorly implemented phase.

A "Credible" Source... conflicts with the information he is being presented. By "credible", I mean some person or entity that he trusts. Many people tend to elevate the people that we trust to levels that do not represent reality. This source does not even have to have imposed this belief upon the person. Most often, we do it ourselves. It often gives us something or someone to aspire to be like, in at least one aspect.

Lack of security This was highlighted by a previous poster. Our programs become assets from the second we start working on them. Not just to the companies we work for, but for the people we work with. This is not simply a control issue. Some of us want to be able to show our neat stuff to the people we care about. Some of us want to make sure that it isn't harmed by an outside person or product. For some, it is an extension of how we think and feel, even. It houses some of our philosophies and ideologies and exposes our intellectual cores. For many, it is our future, whether it is for a class, an employer, or client. For some it is all of those. "Security" in this sense does not apply to the data, necessarily, or the code. It really applies to our sense of safety in protecting whichever of these is most important to us.

Finding out which is the factor is frequently quite easy. Get the person into a neutral setting. Explain to the person what you are observing, in general. Ask the person honestly what is causing this behavior. Now, it doesn't always go well, but most adults respond pretty well when you seem to want to help someone who seems to be acting irrationally. Chances are he is not acting irrationally, but isn't aware that nobody can understand what is really going on.

Once you find out what the issue actually is, you can equip yourself with the proper tools to deal with it. If it is scenario #1, encourage him to do the research from the sources he trusts and (this is important) get back to you with his own findings. This will tell him that his own information holds value with you. In the case of scenario #2, provide accurate comparisons to what is different now than before. Encourage him to give it a try, but have a back-up plan for if it goes awry. For scenario #3, tell him to requery his source with YOUR information. Chances are his source does not hold the views that he thinks he does, but did at one time. Most of us adapt over time, so his viewpoint has probably changed. If he is not willing, encourage him to introduce you to his source. And finally, for scenario #4, assure him that his worries are your own. (They should be on some level) Demonstrate how this "new" tool can protect his interests and increase his security. And if it can't, provide some additional alternatives to help his sense of security while taking advantage of the benefits of a repository.

I know all of this sounds too simple to work, but sometimes it simply does. In fact, the more sincere you are, the more often it does. By addressing his needs, you are addressing the needs of the team, whether he is a "senior" or not, because he is a part of the team. Showing him that you want to be on the same page as him, but simply are not, might encourage him to begin to work together with you. If you have done all of this, and still reach no resolution, then you have done all you can short of speaking with the team leader.

FuzzicalLogic

Title: How to convince a teammate, who sees oneself as senior, to learn SVN conceptual basics?

Body:
To start with some background, I took up a new developer position this summer and ended up being the newest member on the team, yet with most experience under the belt.

So far I have managed to push sanity initiatives through easily enough because of low adoption costs (in terms of time and effort). However things have leveled up a bit.

One of my teammates, although experienced, does not really understand SVN. Naturally, blank areas on his mental map depicting oceans of SVN cause him to adopt rather strange usage patterns.

For example, he had declared a policy of "1 SVN commit per day per developer" because otherwise "the server would soon run out of disk space". When I explained him that SVN commits are deltas, not full copies, he responded with doubt and even today I'm not entirely sure if he understands what it means.

We also had a heated argument about whether to include Eclipse .project configuration in SVN. My teammate insisted we should, although it has caused numerous pointless conflicts. I was against keeping individual developer configuration files in SVN. Finally, it turned out that my teammate had a practice of re-checkouting the entire source tree after every commit to just make sure "code committed into repository works". That was the reason he was so adamant in keeping the project configuration in SVN - so it would be easy to re-import the project. When I explained that commit synchronizes working copy to remote byte-by-byte which makes re-checkout unnecessary, my teammate responded with doubt again and eventually waved the whole issue off as insignificant.

In my opinion, our team wastes time by resolving SVN conflicts in project configuration files which contain only developer-specific settings that need not be shared to SCM at all. All this mess because someone tailored the process around incorrect assumptions.

How can I convince a teammate, who sees oneself as senior, to get a better understanding of SVN basics?


答:
It might seem as a bit akward but there really shouldn't be any reason for these roles to be combined. For one, someone has trusted you with this role, therefore your team has to respect that. Secondly you are now in a position where you can prioritze the work that has to be done so you can always explain why things are going the way they are. Third, you are in the team so you are carrying you share of the workload. Finally, it is a job, if you have to work hard that's fine. A team always needs to remember to add value to their project, it's not about free hand out's. </p>

<p>What it comes down to is "Have you got the goods to make these decissions?" If you think you have, do it! </p>

Body:
It might seem as a bit akward but there really shouldn't be any reason for these roles to be combined. For one, someone has trusted you with this role, therefore your team has to respect that. Secondly you are now in a position where you can prioritze the work that has to be done so you can always explain why things are going the way they are. Third, you are in the team so you are carrying you share of the workload. Finally, it is a job, if you have to work hard that's fine. A team always needs to remember to add value to their project, it's not about free hand out's.

What it comes down to is "Have you got the goods to make these decissions?" If you think you have, do it!


答: No, not at all. Youll spend your time learning techniques that are totally redundant- like that terrible GOTO-cleanup. The thing is that even if you have to use a native language, you can still use C++, so there are some language features that, in the vast majority case, you'll simply never have to do without.</p>


问:
Acceptance tests done first...how can this be accomplished?
The basic gist of most Agile methods is that a feature is not "done" until it's been developed, tested, and in many cases released.  This is supposed to happen in quick turnaround chunks of time such as "Sprints" in the Scrum process.

A common part of Agile is also TDD, which states that tests are done first.

My team works on a GUI program that does a lot of specific drawing and such.  In order to provide tests, the testing team needs to be able to work with something that at least attempts to perform the things they are trying to test.  We've found no way around this problem.

I can very much see where they are coming from because if I was trying to write software that targeted some basically mysterious interface I'd have a very hard time.  Although we have behavior fairly well specified, the exact process of interacting with various UI elements when it comes to automation seems to be too unique to a feature to allow testers to write automated scripts to drive something that does not exist.  Even if we could, a lot of things end up turning up later as having been missing from the specification.

One thing we considered doing was having the testers write test "scripts" that are more like a set of steps that must be performed, as described from a use-case perspective, so that they can be "automated" by a human being.  This can then be performed by the developer(s) writing the feature and/or verified by someone else.  When the testers later get an opportunity they automate the "script" for regression purposes mainly.  This didn't end up catching on in the team though.

The testing part of the team is actually falling behind us by quite a margin.  This is one reason why the apparently extra time of developing a "script" for a human being to perform just did not happen....they're under a crunch to keep up with us developers.  If we waited for them, we'd get nothing done.  It's not their fault really, they're a bottle neck but they're doing what they should be and working as fast as possible.  The process itself seems to be set up against them.

Very often we end up having to go back a month or more in what we've done to fix bugs that the testers have finally gotten to checking.  It's an ugly truth that I'd like to do something about.

So what do other teams do to solve this fail cascade?  How can we get testers ahead of us and how can we make it so that there's actually time for them to write tests for the features we do in a sprint without making us sit and twiddle our thumbs in the meantime?  As it's currently going, in order to get a feature "done", using agile definitions, would be to have developers work for 1 week, then testers work the second week, and developers hopefully being able to fix all the bugs they come up with in the last couple days.  That's just not going to happen, even if I agreed it was a reasonable solution.  I need better ideas...

答: Maybe writing coded UI tests can help you out. If you are working with Visual studio 2010 you can use an add-in called "coded ui test" for recording and coding a very specific script for interacting with the UI of your app. Recording an interaction into a script introduces an extra level of abstraction which guards you aganist small changes in the UI. However introducing this form of testing also introduces the burden of maintaining the tests. </p>


答: C is the lingua franca of programming languages. A programmer not knowing C is much like a scientist not knowing english. Sooner or later you are going to run into a piece of C-code, in the form of an API, code sample, some legacy code, or having to write a kernel module for Linux.


答:
Acceptance test-driven development (distinct from, but complementary to test-driven development) is a great way to ensure that you have the requirements nailed before you begin coding.

On my team we (product owner, QA analysts and developers) sit together and use FitNesse two write acceptance tests. These sessions are usually driven by QA but we all participate. These won't run straight away since some development effort is needed to add the fixtures (the glue between the wiki pages and the production code). These tests form the acceptance criteria for a story. FitNesse is designed to interact with the layer below the UI.

As developers we then work to make these acceptance tests pass. We use TDD for this, but TDD should not be confused with ATDD.

Once the FitNesse pages turn green we are almost done we still have some work to do (exploratory testing, usually lead by QA, and so forth).

Title: Acceptance tests done first...how can this be accomplished?

Body:
The basic gist of most Agile methods is that a feature is not "done" until it's been developed, tested, and in many cases released.  This is supposed to happen in quick turnaround chunks of time such as "Sprints" in the Scrum process.

A common part of Agile is also TDD, which states that tests are done first.

My team works on a GUI program that does a lot of specific drawing and such.  In order to provide tests, the testing team needs to be able to work with something that at least attempts to perform the things they are trying to test.  We've found no way around this problem.

I can very much see where they are coming from because if I was trying to write software that targeted some basically mysterious interface I'd have a very hard time.  Although we have behavior fairly well specified, the exact process of interacting with various UI elements when it comes to automation seems to be too unique to a feature to allow testers to write automated scripts to drive something that does not exist.  Even if we could, a lot of things end up turning up later as having been missing from the specification.

One thing we considered doing was having the testers write test "scripts" that are more like a set of steps that must be performed, as described from a use-case perspective, so that they can be "automated" by a human being.  This can then be performed by the developer(s) writing the feature and/or verified by someone else.  When the testers later get an opportunity they automate the "script" for regression purposes mainly.  This didn't end up catching on in the team though.

The testing part of the team is actually falling behind us by quite a margin.  This is one reason why the apparently extra time of developing a "script" for a human being to perform just did not happen....they're under a crunch to keep up with us developers.  If we waited for them, we'd get nothing done.  It's not their fault really, they're a bottle neck but they're doing what they should be and working as fast as possible.  The process itself seems to be set up against them.

Very often we end up having to go back a month or more in what we've done to fix bugs that the testers have finally gotten to checking.  It's an ugly truth that I'd like to do something about.

So what do other teams do to solve this fail cascade?  How can we get testers ahead of us and how can we make it so that there's actually time for them to write tests for the features we do in a sprint without making us sit and twiddle our thumbs in the meantime?  As it's currently going, in order to get a feature "done", using agile definitions, would be to have developers work for 1 week, then testers work the second week, and developers hopefully being able to fix all the bugs they come up with in the last couple days.  That's just not going to happen, even if I agreed it was a reasonable solution.  I need better ideas...


问:
RFC: Extending the MVC Design Pattern
I've been using the MVC pattern in my applications for years (with full separation of the controller from its views).

Having to implement several hundred views to represent a little over 100 model's for a potential contract, this time around I'd like to reduce the development time of my UI tasks and also add a few additional features (view decoration, etc).

I'm curious to find out if anyone has used or even implemented a design such as the one I'll explain bellow and if so, what were your pros and cons were.

Without getting into too much detail, I'm going to simply elaborate on an example of an API I have been juggling with in my head for a few days along with some explanations a bit later on, so here goes:

```<code>Model m = dao.getInstance(ID);  // ie: possibly fetch it from a database

VTextField text = new VTextField();  // simply 'extends' the Swing components

text.setModel(m);

Decorator deco = DecoratorFactory.getInstance();  // specific to a customer

text.setDecorator(deco);

Controller c = ControllerFactory.getInstance(m);

text.setController(c);

Validator v = ValidatorFactory.getInstance(m);  // get the current validator

c.setValidator(v, "validateText");
</code>```

So in the example above, the idea is that I will have the same application for several clients.  Although each have accepted the general usability, each want their branded L&F to it, some based on business rules (ie: a text field has errors, the background of text-field should be in yellow with red fonts... an other want the text in black and the background yellow with a red border).

What I was thinking was that on any event (on focus, loss focus, key typed, etc), the component would basically invoke the controller. In turn, the controller (through reflection) would invoke the validator.  If validation passes, the controller simply updates the model.  If validation fails, the controller does not update the model.

The controller would keep a state of all of this (viewing, editing, editing with error, etc) and would delegate to the decorator which would adjust the L&F of each component based on client demands.

This would avoid a ton of 'if/else' blocks directly in a single controller.  The controller, validator and decorator knows which concrete instance to load based on which client is running the application.  This way, I can separate the logic for each client and reuse when it is shared behavior.

The decorator doesn't overide the paintXXX() methods, but simply calls the 'setBackground(c)', 'setBorder(b)' and all of these setter methods already available in the Swing components.  The reason I extend each component is simply to add the 'setModel(m)' and 'setController(c)' methods along with any framework logic I'll need.  When the component is in 'view' mode, it usually doesn't paint the border and background and all that stuff (looks more like a traditional web page).  When it is in 'edit' mode then it looks more like a Swing component.

When I design application UI's I usually stick to only a few major components (JTextField, JTextArea, JPanel, etc).  So it wouldn't be too much work on that side.

I have not started to implement any of this stuff just yet, so if you know of existing libraries which does something similar, please point them out.

My only real issues I have at this time is how to handle cases where component depend on each other.  For example, two text fields having an int value.  If one field is odd then the other must also be odd and if one is even, then the other must be even.  When the validation occurs, the validator would need the value of the other text field to properly validate... so I still have not ironed out that part.

答:
I'm not really all that sure what your question really is, but if it's an “Am I on the right lines?” then it would seem so to me, yes. The pattern of calls and constructions is a lot like the patterns of beans created in a Spring-driven application, and Spring is well-known for promoting a lot of good practices and sensible patterns (except that Spring lets you do a lot more by automatically wiring things together).

The only thing to beware of is creating hyper-generalized “do-anything engines” where everything is driven by semantic business rules expressed in XML stored in a complex database looked up using an enterprise service bus that is configured by … Well, you get the picture. I've seen a number of projects that tried to allow people to have applications driven by descriptions not created by programmers but instead by some business unit, and they've never really worked out all that well (unless you're a gigantic three-letter global services company that wants to have even greater amounts of customer lock-in[*]). So don't be afraid of writing code for specific clients; instead, think in terms of refactoring common parts when you find that several clients need the same thing.

[* There are quite a few such firms, really. I've worked with several, and their attitudes are almost totally interchangeable. ]

Title: RFC: Extending the MVC Design Pattern


问:
How can I track programming productivity on a daily basis?
How can I track that I'm developing software more or less productive than the previous days? </p>

答:
Agree with Lorenzo, define the productivity.

I also did this:
1. Break down all the tasks (high level or low level break down).
2. Estimate the working hours for each task (don't forget to set delay buffer for each task).
3. Finish the task.
4. Review back each of task and see if you are productive enough or not.

ContentLicense: CC BY-SA 2.5


答:
I recently read Driving Technical Change: Why People on Your Team Don't Act on Good Ideas, and How to Convince Them They Should, which is published by The Pragmatic Programmers. This book provides background that you should know before trying to introduce technical change, a number of patterns in people who oppose or refuse to change, techniques for implementing the changes, and then strategies for maximizing the use of these techniques and all of the people around you.

Based on your post, I'd say that your teammate probably falls into the Uninformed or the Cynic pattern, but he might also be a case of the Irrational. Some of the techniques recommended to counter these types of people are to gain experience within the target environment so you can find any issues and present answers to problems that other people will run into before they happen, solve the right problem, deliver the message passionately but without being over zealous, demonstrate the techniques by clearly showing the advantages of your methods and tools and sell them organically (but don't create problems just to solve them), and get publicity and buy in from the rest of your team. However, if he's Irrational, there's not much you can do but be prepared to counter their irrationality and not let other people fall victim to their persuasion.

Finally, then you begin to use these techniques, you need an overall strategy. It's important to not let those who are actively hostile or irrational slow you down - ignore them. Instead, find people who you can demonstrate and convince that you have a better way and apply the appropriate techniques based on them as an individual. Once more people see the improvements your knowledge offers, use them to continue to convince others. Finally, use this grassroots effort to convince management that there is a better way, but be sure to put it in terms that they can understand (time, money, quality).


答:
Maybe the Model View ViewModel (MVVM) design pattern, an extension to MVC, is suitable for you. It allows seperation of concerns such that UI-designers can focus on their job without dealing with the  business logic, i.e. they can focus on the various L&F, as you wanted.

Such frameworks (e.g. Microsoft's WPF and Silverlight) are very powerful and expressive. The ViewModel is an abstraction of the view with data binding between the view and the model. I'm sure you can implement your ideas with these concepts and avoid serious issues.

To get an overview of these frameworks and the power of MVVM, I suggest this hanselminutes podcast about MVVM.

Title: RFC: Extending the MVC Design Pattern

Body:
I've been using the MVC pattern in my applications for years (with full separation of the controller from its views).

Having to implement several hundred views to represent a little over 100 model's for a potential contract, this time around I'd like to reduce the development time of my UI tasks and also add a few additional features (view decoration, etc).

I'm curious to find out if anyone has used or even implemented a design such as the one I'll explain bellow and if so, what were your pros and cons were.

Without getting into too much detail, I'm going to simply elaborate on an example of an API I have been juggling with in my head for a few days along with some explanations a bit later on, so here goes:

```<code>Model m = dao.getInstance(ID);  // ie: possibly fetch it from a database

VTextField text = new VTextField();  // simply 'extends' the Swing components

text.setModel(m);

Decorator deco = DecoratorFactory.getInstance();  // specific to a customer

text.setDecorator(deco);

Controller c = ControllerFactory.getInstance(m);

text.setController(c);

Validator v = ValidatorFactory.getInstance(m);  // get the current validator

c.setValidator(v, "validateText");
</code>```

So in the example above, the idea is that I will have the same application for several clients.  Although each have accepted the general usability, each want their branded L&F to it, some based on business rules (ie: a text field has errors, the background of text-field should be in yellow with red fonts... an other want the text in black and the background yellow with a red border).

What I was thinking was that on any event (on focus, loss focus, key typed, etc), the component would basically invoke the controller. In turn, the controller (through reflection) would invoke the validator.  If validation passes, the controller simply updates the model.  If validation fails, the controller does not update the model.

The controller would keep a state of all of this (viewing, editing, editing with error, etc) and would delegate to the decorator which would adjust the L&F of each component based on client demands.

This would avoid a ton of 'if/else' blocks directly in a single controller.  The controller, validator and decorator knows which concrete instance to load based on which client is running the application.  This way, I can separate the logic for each client and reuse when it is shared behavior.

The decorator doesn't overide the paintXXX() methods, but simply calls the 'setBackground(c)', 'setBorder(b)' and all of these setter methods already available in the Swing components.  The reason I extend each component is simply to add the 'setModel(m)' and 'setController(c)' methods along with any framework logic I'll need.  When the component is in 'view' mode, it usually doesn't paint the border and background and all that stuff (looks more like a traditional web page).  When it is in 'edit' mode then it looks more like a Swing component.

When I design application UI's I usually stick to only a few major components (JTextField, JTextArea, JPanel, etc).  So it wouldn't be too much work on that side.

I have not started to implement any of this stuff just yet, so if you know of existing libraries which does something similar, please point them out.

My only real issues I have at this time is how to handle cases where component depend on each other.  For example, two text fields having an int value.  If one field is odd then the other must also be odd and if one is even, then the other must be even.  When the validation occurs, the validator would need the value of the other text field to properly validate... so I still have not ironed out that part.


问:
Using a TFS Build Process Template (Workflow) for Deployment
I'm thinking of using TFS Build workflows for complex deployments. We have some that may need to deploy:

Web applications and services

Database

SSRS Reports

SSIS Packages

Who knows what else

I like the fact that I can give the workflow some basic parameters like which build to deploy and it would just run. Potentially, some parts might need human approval, and I know that workflow can handle that too. An example is that we might use the workflow to create a change script from our Visual Studio Database Projects, but the DBA group will want to approve the script before it is run.

I'm interested to know whether others have used "builds" for this in the past, and what problems were found.

答:
We've used TFS to trigger our builds but used msbuild to build our projects. The main advantage is that we have a build script that we can change an keep under version control. Thing is with workflows e.g. : how are you going to build an older version of your project? With a build script you just get the older version  from source control and off you go. It's also nice to be able to fiddle around with it and switch different options on/off.

If you're dead certain you have a fixed build cycle, then you  probably can pull it off, otherwise having a script is probably the safer and more felxible option.


问:
VPN or TLSv1 for securing a programs protocol from field device to mainframe
I am working on a product that requires devices to exists anywhere in the world hooked up to the internet though cell modems or on WLAN lines which communicates to a server(s) that exists elsewhere in the world.

When deigning the networking portion of the program i cant figure what the best option is for securing the communication between the server and end device.

From my searches iv'e come up with two options.

Option 1: Using a host to host vpn connection between the two devices.

Pros: VPN software seems to be well tested and does not require extra programming for the network protocol. The IT department is more comfortable with it because of using software that is already tested and they comfortable with vpn.

Cons: Since my end devices are linux on OMAP platforms cross compiling the vpn software if not already done could be tricky. Dealing with firewalls and routers behind the end devices network. Setup of the connection can be tricky.

Option 2: Implementing the TLSv1 protocol in my program to deal with the encryption.

Pros: Does not require extra software to be running on the device. Only relies on the encryption libraries as a dependency. Don't have to worry about dealing with nats and firewalls because the protocol will only require one tcp port to be open.

Cons: Extra coding to the network software. IT is skeptical because our program is responsible for securing the protocol.

FYI: For implementing the TLSv1 i would use http://www.gnu.org/software/gnutls/

答: My advise would be figure out what type of communication style is required, one way or two way. If you are looking at a one way communication pattern then it's probably safe to say use something lightweigth and bog standard as https as TLS. If however there is two way communication required looking into vpn is a great option. Big drawback of vpn connections is connection setup requires quite a lot of time (relatively speaking). If the user has to wait for this setup than that would be less than ideal. In that case custom TLS would be the preferrable option. </p>


问:
Architecture of interaction modes ("paint tools") for a 3D paint program
We are developing a Qt-based application to navigate through and paint on a volume treated as a 3D pixel graphic. The layout of the app consists of three orthogonal slice views on which the user may paint stuff like dots, circles etc. and also erase already painted pixels. Think of a 3D Gimp or MS Paint.

How would you design the the architecture for the different interaction modes (i.e. paint tools)?

My idea is:

use the MVC pattern

have a separate controler for every interaction mode

install an event filter on all three slice views to collect all incoming user interaction events (mouse, keyboard)

redirect the events to the currently active interaction controler

I would appreciate critical comments on that idea.

答: Typically MVC is a style in which relatively large operations are defined. That doesn't really  align well with the intricate operations that you define as painting a 3d pixel. I'd suggest taking a look at another style closely related to MVC which is MVVM. It allows for a closer binding between the object one is operating on by means of your different tools and having a view for that object.</p>


答:
As it's defined in traditional Scrum, there isn't a problem with a Developer also functioning as a Product Owner. However, you do need to take care when planning to account for anyone who is performing their role part-time, either because they are working on multiple projects or because they have multiple roles on the same team. In your case, you can not count yourself as a full-time developer because you need to budget time in each iteration to perform the duties of the Product Owner.

I think that you also have a misunderstanding of what the Product Owner does. It is not your responsibility to choose which features go into an iteration. Instead, it's your job to be the voice of the customer on the project, when it comes to introducing new stories, assigning priorities to these new stories, and ensuring that the implementation of each story is acceptable through the creation and execution of acceptance tests. The choice of stories is based on the velocity of the team and the prioritized backlog, not by how many stories the Product Owner wants to implement.


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答: Supplement and Multivitamin ....

Body: Supplement and Multivitamin ....


答:
Don't try to "convince" this guy of anything. People (even programmers) are not going to respond to or respect reasonable/logical arguments from someone they see as junior to them. So don't waste your breath. Instead, work on building a level of trust with this person. This person will listen to what you have to say only when he is open to it.

In the meantime, you have real problems:

The guy checks his .project file into the repo: just ignore it. you don't have to modify the file, neither does anyone else on the team who knows better. Let it go. If it gives your "senior member" a warm, happy feeling like a security blanket then so be it.

There is a perceived budget on disk space: This is the reason Mr. Senior dictates 1 commit a day. Is the shortage on space real or perceived? Even if it is just perceived, maybe there's something you can do to change that perception. That should be dealt with immediately - if you take the initiative it also helps to build trust.

I might also add that this guy will be willing to adopt better SVN practices when he thinks they were his ideas. That will take some forethought on your part, and he will likely take the credit for establishing better practices - but you are OK with that.


问:
Are developers a stakeholder in a system
Are developers of a product considered stakeholders?</p>

答:
Generally, yes, developers are stakeholders on a software project. That's consistent with the dictionary definition of the term. Here are a few definitions of stakeholder, from various publications:

Karl Wieger's Software Requirements:

stakeholder A person, group, or organization that is actively involved in a project, is affected by its outcome, or can influence its outcome.

Ian Sommverville's Software Engineering 8:

The term stakeholder is used to refer to any person or group who will be affected by the system, directly or indirectly. Stakeholders include end-users who interact with the system and everyone else in an organisation that may be affected by its installation. Other system stakeholders may be engineers who are developing or maintaining related systems, business managers, domain experts, and trade union representatives.

Roger S. Pressman's Software Engineering: A Practitioner's Approach (6th Edition) defines five groups or stakeholders: senior managers who define business issues, project/technical managers who organize and control the practitioners, the practitioners who engineer the system, customers who specify the requirements for the software, and end-users who will interact with the delivered system.

Scott Ambler's Active Stakeholder Participation: An Agile Best Practice:

My definition of a project stakeholder is anyone who is a direct user,
  indirect user, manager of users, senior manager, operations staff
  member, the "gold owner" who funds the project, support (help desk)
  staff member, auditors, your program/portfolio manager, developers
  working on other systems that integrate or interact with the one under
  development, or maintenance professionals potentially affected by the
  development and/or deployment of a software project.

...

In this definition I have chosen to exclude the developers who are
  working on the project.  This may seem strange at first because
  developers clearly have an important stake in the projects that they
  work on.  Yes, developers are definitely project stakeholders.  Why do
  I continue to distinguish between developers and project stakeholders?
  Because I want convenient terms to distinguish them, I really don’t
  like “developer stakeholder” and “non-developer stakeholder”, and
  because they have different roles to play on a project.

In practice, I've typically seen stakeholders broken down into groups, and one group contains the people building the system. It is important to recognize that, when building a system, the developers do have needs and concerns that need to be balanced with the needs of everyone else. However, these need to be prioritized and taken into consideration with every other need.

OwnerDisplayName: Tom


问:
Which CS courses are a "must" for a web developer
My goal is to learn how to program a website with Python/Django in the next year. From what I've understood, I also have to learn HTML, CSS, JavaScript.

I understand in order to build a website, I will need to find a co-founder whose skills far exceed mine. But still, the situation will be way different if I'm a person who's closer to his/her level and has dedicated a lot of time teaching himself than every other "I have an idea, just need a tech co-founder" type of guy.

I do plan to pursue a degree in computer science, but after finishing high school last May decided to take an year off, so I am free to learn programming in the next 10 months.

For now, I have the chance to attend some college courses in a top institution. Which ones are a must for a web developer so that I don't have any gaps in my understanding of programming and write "sophisticated code"?

EDIT:Thank you all for the help!From the courses suggested I may be able to attend some/none/all of OOP(with Java),Networks and Graphics,SE-Algorithms,Discrete Math for Comp.Scientists,Databases,Information Retrieval and Data Mining.Which of those are more important for Web development with Django?

I've read a lot of times people saying that self-taught programmers had gaps in their knowledge, didn't write clear code.This is why I'm asking which CS courses can fill those gaps? Not only in practical skills,but in mindset,way of thinking.

答:
First, understand that a CS degree is generally not vocational education.  Many of the courses develop the logical thinking that is required to solve complex problems.  These courses are heavily math and computer science focused.

With the exception of 2-3 classes, what they do not do is teach you a specific set of languages so you can go get a job as a "X" Developer. Teaching yourself basic web programming for Javascript/HTML/PHP (or some other serverside language) generally takes just a few months of self-training.

It is a good idea to get a degree in computer science.  This should be a part of an overall plan to self-improvement that takes years of practice and self-discipline.

If all you care to do is build a single website to make a profit, then writing good code is not a high priority.  In this case, a CS degree would not provide much benefit at all.

As a beginner, you simply are not going to be good.  Accept this fact.  It will make you less close minded to the more experienced devs you will be working with.  An open mind will also make you more accepting of ideas that conflict with what you believe is best-practice.

If your goal is to just build a website, then signup at a community college for an intro to web programming course.  Or, anything Javascript/HTML/pick your web language.  These classes are meant to prepare you to do the basics of web work on the job.  As I said in the beginning, Computer science is not meant for this type of training.


答:
For "Web Development" as such, I don't think there's a lot of courses in the standard set that are geared right toward that track.  When talking about undergrad courses, you'll find that most of them geared to "Web" stuff will usually be very basic, and will border on clerical in their approach.

I would recommend that you split your time and take the of the foundational undergrad courses which will allow you to become a good programmer, while at the same time doing self-study on your own for the discipline of web programming.  Buy a good book on CSS.  Buy a good book on Javascript and HTML 5.  Take Intro to CS, and, learn how to program in Java that way.  Take a class on networking, with a focus on TCP/IP if at all possible.

But most importantly:  Find a project you want to do, and start it.  You seem to have an idea of what it is, so I would just say, "start it on your own, on your own PC".  In the process of doing this, you won't learn everything you need to create a top-notch website, but you'll learn what it is that you really need to focus on in your self-study to do so.  You'll make mistakes.  You'll write terrible code.  But that's OK.  I'm willing to bet that once you are taking your courses, you'll be able to back-fill your knowledge and draw lines directly from your studies to your previous work.

Title: Which CS courses are a "must" for a web developer

Body:
My goal is to learn how to program a website with Python/Django in the next year. From what I've understood, I also have to learn HTML, CSS, JavaScript.

I understand in order to build a website, I will need to find a co-founder whose skills far exceed mine. But still, the situation will be way different if I'm a person who's closer to his/her level and has dedicated a lot of time teaching himself than every other "I have an idea, just need a tech co-founder" type of guy.

I do plan to pursue a degree in computer science, but after finishing high school last May decided to take an year off, so I am free to learn programming in the next 10 months.

For now, I have the chance to attend some college courses in a top institution. Which ones are a must for a web developer so that I don't have any gaps in my understanding of programming and write "sophisticated code"?

EDIT:Thank you all for the help!From the courses suggested I may be able to attend some/none/all of OOP(with Java),Networks and Graphics,SE-Algorithms,Discrete Math for Comp.Scientists,Databases,Information Retrieval and Data Mining.Which of those are more important for Web development with Django?

I've read a lot of times people saying that self-taught programmers had gaps in their knowledge, didn't write clear code.This is why I'm asking which CS courses can fill those gaps? Not only in practical skills,but in mindset,way of thinking.


答: You should take Web Programming obviously. Also I'd recommend a course on Networking so that you understand the fundamentals of how the internet operates. I'd recommend at least one class on Human Computer Interaction and/or User Design. Classes on Data Mining are a good idea given the prominence of that field in modern Web Development. A class on Database theory would be useful for designing heavier web applications. A class in Data Visualization would probably also be useful to dealing with how to display data in a way that will be useful to users of the sites or web applications that you build. Some courses in Graphic Design and Media Analysis might also be useful. Some universities combine Computer Science with those disciplines into a degree typically called something like Interactive Design or Computational Media, essentially technology/art degree hybrids.</p>


答: Yes - for a system that will live on and be maintained. Developers are likely to work with the code to fix bugs and introduce new features long after the initial team closed the project. An important requirement for long lived systems are maintainability and who should put their stakes in this if not developers?</p>

Title: Are developers a stakeholder in a system

Body: Are developers of a product considered stakeholders?</p>


问:
Why use services (REST/SOAP) instead of a library?
Let's say you're looking at breaking up your applications into services.  Are there any good reasons to adopt a SOA approach vs. just creating a library API that can be loaded by the applications that need it.</p>

答: If there is a change to an SOA service, then that SOA service will have to be redeveloped, retested and redeployed. All applications that consume that service can continue to do so. A change to a library in a DLL will mean all consumers of that library will have to be redeveloped to reference that DLL, they will all have to be retested and they will all have to be redeployed. There is also the danger this may not happen properly, and different applications will have different versions of the DLL. Sometimes this might not be a problem - perhaps every system should have the version of the library that was present at deployment time (you may have updated your logging system to have helpful new features - do you really need to update every system with it?) in this case a library is fine. But say you have a service for calculating tax rate, and the tax laws change. You don't want to have to update every system to incorporate this change, it would be better to do it in one place. In this case a service is a better option.


问:
Communication Between Different Technologies in a Distributed Application
I had to a incorporate several legacy applications and services in a network-distributed application. The existing services and applications are written using different languages and technologies, including: java, C#.Net and C++; all running on MS Windows machines. Now I'm wondering about the communication mechanism between them. What is the simple and standard way? Thanks! PS. communications include simple message sending and remote method invocations.</p>

答: I absolutely recommend 'Enterprise Integration Patterns' by Gregor Hohpe and Bobby Wolfe. It suggests patterns for using messaging for exactly your problem.</p>


问:
How clean should new code be?
I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability.

How clean should I require my team members' code to be if we are not short on time?

In my view, we should clean up old code we modify; adding a line to a method means you clean up that method.

But what about new code?

We could make it sparkling clean, so that if another coder comes along tomorrow and makes a small modification, she doesn't have to clean it up at all. But that means if no-one ever reads that piece of code again, we've wasted time making it sparkling clean.

Should we aim for "almost clean" and then clean it up further on future visits? But that would mean not getting the full value for the understanding we had when we wrote it in the first place.

Right now, I'm going for "sparkling clean"; partly as a tutorial for my colleagues who are not as picky as I.

答:
It depends. I would make two cases, one for new code and one for existing code.

For new code I would recommend using test-driven development (TDD) plus merciless refactoring as standard practices. Make it as simple as you possibly can by refactoring and stop only when you cannot think of any improvement anymore. While this may sound like a lot of effort at the time you will find that it pays off times and times again. In other words, yes, make it "sparkling clean".

For existing code, however, I would be much more careful. It depends on the quality and coverage of your test suite. Typically existing code is code that has been in use for quite some time. This also means probably most of the bugs have been fixed. When you now start changing this code you want to make sure you don't break anything that works. My recommendation would be to write tests first. Heaps of them to ensure that you clearly understand what the existing code does but also to ensure when you start cleaning it up you don't accidentally break anything.

Your choice of approach also depends on what tools you have available. Refactoring and unit test support can be quite different for different languages. Make sure you get the best possible tools. Regardless of price, they are worth it.

There are more aspects to working with legacy code. I would recommend to consider reading Mike Feather's book "Working Effectively With Legacy Code". Good luck!

Title: How clean should new code be?


答:
In my experience, making new code clean is actually not that difficult. Typically you have a single clean concept in your mind about what the code is supposed to do, how to implement it etc. so it is fairly easy to arrange the code to reflect this one thing clearly (a least according to one's current understanding - returning to the same piece of code 6 months later may reveal some surprises ;-).

The problem comes when the existing code needs to be modified / extended. Then it starts to get more complex, the original clear architectural / design vision is getting blurred, so we need to spend conscious effort to refactor and keep code entropy under control.

Creating a piece of code as clean as it could be would certainly make future extensions and maintenance easier. If there are future modifications, that is. Otherwise, as you note, the effort is "wasted" - at least in the direct sense. However, there are additional things to consider:

That a piece of code has never been modified up to now does not mean that it never will be

Any piece of code is typically read many more times than it is modified

It is better to get used to writing clean code as a habit, rather than trying to decide every time whether this particular piece of code is important or critical enough to be made cleaner. Thinking about this may take more time than actually improving the code, and some developers may easily start using this rule to justify their laziness or resistance to the new ways

The more you practice a skill, the better you get at it*; and writing clean code is important enough to be practiced constantly.

All in all, thes arguments sort of lead to the opposite of YAGNI: in this case You Are Gonna Need It. If you have the time, write as clean code as you can. (But no cleaner - at some point the rule of diminishing returns kicks in, so we should stop and find some better thing to do. To avoid endlessly polishing the same 3 lines of code we need to focus on meaningful changes which represent real improvement in readability / maintainability.)

*I haven't heard any healthy adult complaining about how hard walking is, but witnessing a baby or an injured person trying to (re)learn it makes you realize how complex an achievement it actually is. Still, most of us does it all the time without even consciously thinking about it.

Title: How clean should new code be?

Body:
I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability.

How clean should I require my team members' code to be if we are not short on time?

In my view, we should clean up old code we modify; adding a line to a method means you clean up that method.

But what about new code?

We could make it sparkling clean, so that if another coder comes along tomorrow and makes a small modification, she doesn't have to clean it up at all. But that means if no-one ever reads that piece of code again, we've wasted time making it sparkling clean.

Should we aim for "almost clean" and then clean it up further on future visits? But that would mean not getting the full value for the understanding we had when we wrote it in the first place.

Right now, I'm going for "sparkling clean"; partly as a tutorial for my colleagues who are not as picky as I.


问:
How can I tactfully suggest improvements to others' badly designed code during review?
I'm a great believer in clean code and code craftsmanship, though I'm currently at a job where this isn't regarded as a top priority. I sometimes find myself in a situation where a peer's code is riddled with messy design and very little concern for future maintenance, though it's functional and contains little to no bugs.

How do you go about suggesting improvements in a code review when you believe there is so much that needs changing, and there's a deadline coming up? Keep in mind that suggesting the improvements be made after the deadline may mean they'll be de-prioritized altogether as new features and bug-fixes come in.

答:
I always start my comment with "I would", which signals that mine is simply one of many views.

I also always include a reason.

"I would extract this block into a method because of readability."

I comment on everything; big and small. Sometimes I make more than a hundred comments on a change, in which case I also recommend pair-programming, and offer myself as wing-man.

I'm trying to establish a common language for reasons; readability, DRY, SRP, etc.

I've also created a presentation on Clean Code and Refactoring explaining why and showing how, which I held to my colleagues. I've held it three times so far, and a consultancy we're using asked me to hold it again for them.

But some people won't listen anyway. Then I'm left with pulling rank. I'm the design lead. Code quality is my responsibility. This change will not get through on my watch in its current state.

Please note that I'm more than willing to back down on any comment I make; for technical reasons, deadlines, prototypes, etc. I've still got lots to learn about coding too, and will always listen to reason.

Oh, and I recently offered to buy lunch to the first one on my team who submitted a non-trivial change on which I didn't have any comment. (Hey, you have to have fun too. :-)


答:
Always go for as clean possible at the time of writing. Saving time writing sloppy code is a false economy, a price is paid for every short cut every single time you fix a bug or modify your code.

Refractoring old code is less clear cut and depends on the judgment of the coder at the time. Sometimes its "right" to write in a less clean style that's consistent with other code. Refractoring existing code is both hard and time consuming. Sometimes its not festable to rewrite large chunks of working code for one modification.

Title: How clean should new code be?


答:
My experience:

A piece of code longer than 20 lines, written as a proof-of-concept, will not get re-written when the concept thus proved is needed, but rather bent to somewhat fit the needs of the production code.

Usually, this goes with the promise to re-write it later, when there is time to do it all properly. However, this time never comes, so this piece of test code will be stuck in production code forever.

Any software project larger than, say, 2 man months stands on the shoulders of at least one piece of such proof-of-concept toying-with-the-idea code, big projects are built on many of them. And nobody is going to replace these pieces of code which usually are underlying vital features of the application, threatening to bring it all down on a single error.

Too many big projects sooner or later trip over such code.

My solution:

Anything over 20 lines of code has to be rock-solid and bullet-proof. Properly design the whole thing, do not use hacks to save time, put effort into picking good identifiers, refactor as soon as you see the need,... The whole enchilada.

While 80% of these snippets are indeed thrown way, the rest will end up at the heart of some code that keeps the company afloat a decade down the road. That prospect excuses any amount of effort poured into a small, seemingly one-off, program.

Title: How clean should new code be?


答:
For each programmer on the team, the answer should always be "a little cleaner than the code I wrote last week."

Too often, having a specific hard rule in an organization's coding standards leads to a disconnect between what is officially supposed to happen and what actually happens. Most programmers of average skill can't or won't suddenly change their ways overnight, and even if they do hit the standards regularly, they will have their off days. In the real world, it's more practical to focus on improvement than perfection.

Title: How clean should new code be?


问:
Is there a general pattern that could be used to describe Data Migration?
In our company we have to dismiss a software and introduce a new one. I have received the task to follow and take care of the whole data migration.

We use 3 different data sources (each containing different kind of information), whose records have to be merged into a unique target DB. Since the new DB has a different schema also some mapping steps are required to coincile data from the two environments.

Technically it is everything clear, but I have to describe in a "proof of concept" the migration process. About data migration is there a general pattern that could be used to describe it?

I will describe the involved systems, which data will be moved, the mapping tables used and the planned tests to ensure data quality. However can anyone suggest a different approach? Maybe in this way I can realize that I am missing something in my documentation.

答: Data migration as you describe it is similar to the Extract, Transform and Load (ETL) process; which is mostly used to load operational data into data warehouses, but can be generalized to tackle any data migrations. A number of strategies related to ETL can be found here.</p>


问:
Drawing thread interaction
I'd like to draw (pen and pencils) threads interaction in a UML(-like) notation. I don't insist on UML, anything that is obvious to the reader should do.

I started with sequence diagrams, but I don't feel this is the best way to do that. All the time, there would be "action initiators" coming from off-screen which kinda break the SSD idea. I inherited a medium size code base with around 9 - 10 threads each owning a state machine and I'm trying to figure out how it works.

How should I visualize thread interaction?

答: The Lawrence Livermore National Laboratory has some good guides on Parallel Computing and Programming. In particular, the guide to Posix Threads has some very well done charts that illustrate how to visualize threads and their interaction.</p>

Title: Drawing thread interaction


问:
Are there laws to protect us from hackers who disclose vulnerabilities prior to alerting the vendor?
Take the example of the recent ASP.NET (and Java Server Faces) vulnerability disclosure at a Hacker conference in Brazil.  It's my understanding that the poet tool was demonstrated before Microsoft was even aware of the issue.

Are there laws to protect legitimate customers from people who encite the hacker community to start hacking all the ASP.NET servers they can?  Who knows how many legitimate businesses were compromised between when the tool was demoed and the patch was applied to the server.

答: Many EULA prohibit reverse engineering. This could be a possible angle of legal attack.</p>