问:
Why is Python used for high-performance/scientific computing (but Ruby isn't)?
There's a quote from a PyCon 2011 talk that goes:

At least in our shop (Argonne National Laboratory) we have three
  accepted languages for scientific computing. In this order they are
  C/C++, Fortran in all its dialects, and Python. You’ll notice the
  absolute and total lack of Ruby, Perl, Java.

It was in the more general context of high-performance computing. Granted the quote is only from one shop, but another question about languages for HPC, also lists Python as one to learn (and not Ruby).

Now, I can understand C/C++ and Fortran being used in that problem-space (and Perl/Java not being used). But I'm surprised that there would be a major difference in Python and Ruby use for HPC, given that they are fairly similar. (Note - I'm a fan of Python, but have nothing against Ruby).

Is there some specific reason why the one language took off? Is it about the libraries available? Some specific language features? The community? Or maybe just historical contigency, and it could have gone the other way?

答:
I have used Python extensively for engineering applications and Ruby for web applications.

The problem I see with Ruby as a scientific language is that there are too many syntax options for a given operation.

Python is designed with the following premise "There should be one-- and preferably only one --obvious way to do it".  This makes it MUCH easier to read someones code and determine its intent.  This is key for peer reviews for engineering, etc.

I like Ruby and it is great for certain tasks, but my Ruby code could be syntactically entirely different than a different programmer's code that does the exact same thing.  This causes too much ambiguity in a scientific or engineer environment.


问:
How to customize web-app (pages and UI) for different customers
We have an ASP.NET web-application which has become difficult to maintain, and I'm looking for ideas on how to redesign it. It's an employee administration system which can be highly customized for each of our customers. Let me explain how it works now:

On the default page we have a menu where a user can select a task, such as Create Employee or View Timesheet. I'll use Create Employee as an example.

When a user selects Create Employee from the menu, an ASPX page is loaded which contains a dynamically loaded usercontrol for the selected menuitem, e.g. for Create Employee this would be AddEmployee.ascx

If the user clicks Save on the control, it navigates to the default page.
Some menuitems involve multiple steps, so if the user clicks Next on a multi-step flow then it will navigate to the next page in the flow, and so on until it reaches the final step, where clicking Save navigates to the default page.

Some customers may require an extra step in the Create Employee flow (e.g. SecurityClearance.ascx) but others may not.

Different customers may use the same ASCX usercontrol, so in the AddEmployee.OnInit we can customize the fields for that customer, i.e. making certain fields hidden or readonly or mandatory.

The following things are customizable per customer:

Menu items

Steps in each flow (ascx control names)

Hidden fields in each ascx

Mandatory fields in each ascx

Rules relating to each ascx, which allows certain logic to be used in the code for that customer

The customizations are held in a huge XML file per customer, which could be 7500 lines long.

Is there any framework or rules-engine that we could use to customize our application in this way? How do other applications manage customizations per customer?

答:
Having said that over-flexibility is the cause of many over-complications in software, can you imagine a framework so flexible as to allow you to offer infinite flexibility to your customers?

That said, I would suggest writing a DSL, rather than using XML, for a customisation rules engine.

You can use ANTLR to create a DSL from scratch, or you can write a DSL on top of Boo, which means you don't have to make trivial decisions like code-formatting and operator precedence, you just get to work with what's unique to your domain problem.

This should simplify your current rules engine dramatically and also be more extensible in the future. As an added advantage, if you get it right, it will be more reader-friendly for the end-user, so that they can view their own customisation rules and confirm their correctness.

ContentLicense: CC BY-SA 3.0


问:
How to solve cyclic dependencies in a visitor pattern
When programming at work we now and then face a problem with visitors and module/project dependencies.

Say you have a class A in a module X. And there are subclasses B and C in module Y. That means that module Y is dependent on module X. If we want to implement a visitor pattern to the class hierarchy, thus introducing an interface with the handle Operations and an abstract accept method in A, we get a dependency from module Y to module X, which we cannot allow for architectural reasons.

What we do is, use a direct comparison of the types (i.e. instanceof, since we program in Java), which is not satisfying.

My question(s) would be: Do you encounter this kind of problem in your daily work (or do we make poor architectural choices) and if so, how is your approach to solve this?

Here is a minimal example in Java to illustrate my point. Package a has ClassA and the Visitor-Interface over the ClassA Hierarchy:

```<code>package pkg.a;
public abstract ClassA extends ClassA {
    public abstract void accept(ClassAVisitor visitor);
   /* other methods ... */
}

package pkg.a;
import pkg.b.ClassB;
import pkg.b.ClassC;
public interface ClassAVisitor {
    public abstract void handle(ClassB visitee);
    public abstract void handle(ClassC visitee);
}
</code>```

Package b has the concrete classes that extend from ClassA:

```<code>package pkg.b;
import pkg.a.ClassAVisitor;
public ClassB extends ClassA {
    public void accept(ClassAVisitor visitor) {
        visitor.handle(this);
    }
}

package pkg.b;
import pkg.a.ClassAVisitor;
public ClassC {
    public void accept(ClassAVisitor visitor) {
        visitor.handle(this);
    }
}
</code>```

Package a and b have a cyclic dependency.

答:
What about changing the visitor interface to remove the dependency from a to b?

```<code>package pkg.a;
public abstract ClassA extends ClassA {
    public abstract void accept(ClassAVisitor visitor);
   /* other methods ... */
}

package pkg.a;
public interface ClassAVisitor {
    public abstract void handleB(ClassA visitee);
    public abstract void handleC(ClassA visitee);
}
</code>```

and then

```<code>package pkg.b;
import pkg.a.ClassAVisitor;
public ClassB extends ClassA {
    public void accept(ClassAVisitor visitor) {
        visitor.handleB(this);
    }
}

package pkg.b;

import pkg.a.ClassAVisitor;
public ClassC {
    public void accept(ClassAVisitor visitor) {
        visitor.handleC(this);
    }
}
</code>```

Body:
What about changing the visitor interface to remove the dependency from a to b?

package pkg.a;
public abstract ClassA extends ClassA {
    public abstract void accept(ClassAVisitor visitor);
   /* other methods ... */
}

package pkg.a;
public interface ClassAVisitor {
    public abstract void handleB(ClassA visitee);
    public abstract void handleC(ClassA visitee);
}

and then

package pkg.b;
import pkg.a.ClassAVisitor;
public ClassB extends ClassA {
    public void accept(ClassAVisitor visitor) {
        visitor.handleB(this);
    }
}

package pkg.b;

import pkg.a.ClassAVisitor;
public ClassC {
    public void accept(ClassAVisitor visitor) {
        visitor.handleC(this);
    }
}


问:
As a programmer, are you required to do timesheets?
Timesheets are something that I've never been fond of, but none the less something that is a requirement within my company. They don't bother me so much, but they seem to really grind some other people's gears. I suppose I have a few questions, and feedback would be great.

Are you required to do timesheets, assuming you aren't a contractor? (That is understandable to me).

What is the granularity of timesheets that you would be comfortable with or that you use? (ex: all entries must be under two hours).

Would timesheets ever factor into your reasons for not accepting a job or leaving a current one?

How has management within your organization justified timesheets if you aren't billing to a client?

答:
I work as a web developer / project manager at a small company (10 people in total) and everyone, including the CEO, has to log what they do. Everything that takes more than 5 minutes has to be logged.

A typical timesheet would look like this:

07:46 - 08:01 : Client A - Project B - Programming - Optional remark

08:01 - 08:38 : Client B - Project C - Fixing - Optional remark

08:38 - 08:46 : Client B - Project D - Project Management - Optional remark

08:46 - 09:00 : Client A - Project B - Customer Support - Optional remark

...

Since I'm used to working like this, it wouldn't be a reason to refuse a job. The CEO motivates the use of these kind of detailed timesheets as the perfect way to compare estimates to the actual time spent on a project.

ContentLicense: CC BY-SA 2.5


问:
How to keep a generic process unique?
I'm currently working on a project that makes connection between different banks which send us  information on which that project replies. A part of that project configures the different protocols that are used (not every bank uses the same protocol), this runs on a separate server. These processes all have unique id's which are stored in a database.

But to save time and money on configurations and new processes, we want to make a generic protocol that banks can use. Because of PCI requirements we have to make a separate process for every bank we connect to.

But the generic processes have only 1 unique identifier and therefor we cannot keep them apart. Giving every copy of that process a different identifier is as I see it impossible because they run entirely separate.

So how do I keep my generic process unique?

答: A Universily Unique ID should work for your problem. Since they generate unique IDs across multiple independent systems.</p>

Title: How to keep a generic process unique?


答:
7500 lines of code (XML) is alarming - I think you have to ask yourself how much benefit your users get from the customisation and how much it costs you to provide it. Personally I'd start by trying to reduce the customisation as much as possible.

Next I'd move whatever customisation is left into a database as very simple data (something similar to name value pairs but for each customer and perhaps allowing a type field and a sequence number). Provide a nice simple web interface to this and check that all values entered are valid. The aim being to make it so easy to change that eventually your customers will be able to do it. You could also put system defaults into this structure so you can change the default behaviour via the database.

```<code>create table CustomerSettings(
   customerId         int,
   type               varchar(20),
   name               varchar(20),
   value              varchar(20),
   sequence           int null
);

insert CustomerSettings ( 0, "FORMAT", "emp_no", "^[0-9]+$" ); // default

insert CustomerSettings ( 123, "MENU","main_menu","hire people",1

insert CustomerSettings ( 123, "MENU","main_menu","fire people",2

insert CustomerSettings ( 123, "HIDE","salary",null, null );

insert CustomerSettings ( 123, "FORMAT","emp_no","^[A_E][0-9]+$", null );
</code>```

etc, etc

The web app would first load all the values for a customer or, if no value is present, it would load the default. A new customer would then just run just using the defaults. You could add settings on the fly until the customer is happy.

The data per customer should hopefully be much smaller. Using defaults where possible.

Mike

PS please forgive the formatting, I couldn't make head nor tail out of the info on how to show code in a post.

Title: How to customize web-app (pages and UI) for different customers

Body:
We have an ASP.NET web-application which has become difficult to maintain, and I'm looking for ideas on how to redesign it. It's an employee administration system which can be highly customized for each of our customers. Let me explain how it works now:

On the default page we have a menu where a user can select a task, such as Create Employee or View Timesheet. I'll use Create Employee as an example.

When a user selects Create Employee from the menu, an ASPX page is loaded which contains a dynamically loaded usercontrol for the selected menuitem, e.g. for Create Employee this would be AddEmployee.ascx

If the user clicks Save on the control, it navigates to the default page.
Some menuitems involve multiple steps, so if the user clicks Next on a multi-step flow then it will navigate to the next page in the flow, and so on until it reaches the final step, where clicking Save navigates to the default page.

Some customers may require an extra step in the Create Employee flow (e.g. SecurityClearance.ascx) but others may not.

Different customers may use the same ASCX usercontrol, so in the AddEmployee.OnInit we can customize the fields for that customer, i.e. making certain fields hidden or readonly or mandatory.

The following things are customizable per customer:

Menu items

Steps in each flow (ascx control names)

Hidden fields in each ascx

Mandatory fields in each ascx

Rules relating to each ascx, which allows certain logic to be used in the code for that customer

The customizations are held in a huge XML file per customer, which could be 7500 lines long.

Is there any framework or rules-engine that we could use to customize our application in this way? How do other applications manage customizations per customer?

Body:
7500 lines of code (XML) is alarming - I think you have to ask yourself how much benefit your users get from the customisation and how much it costs you to provide it. Personally I'd start by trying to reduce the customisation as much as possible.

Next I'd move whatever customisation is left into a database as very simple data (something similar to name value pairs but for each customer and perhaps allowing a type field and a sequence number). Provide a nice simple web interface to this and check that all values entered are valid. The aim being to make it so easy to change that eventually your customers will be able to do it. You could also put system defaults into this structure so you can change the default behaviour via the database.

create table CustomerSettings(
   customerId         int,
   type               varchar(20),
   name               varchar(20),
   value              varchar(20),
   sequence           int null
);

insert CustomerSettings ( 0, "FORMAT", "emp_no", "^[0-9]+$" ); // default

insert CustomerSettings ( 123, "MENU","main_menu","hire people",1

insert CustomerSettings ( 123, "MENU","main_menu","fire people",2

insert CustomerSettings ( 123, "HIDE","salary",null, null );

insert CustomerSettings ( 123, "FORMAT","emp_no","^[A_E][0-9]+$", null );

etc, etc

The web app would first load all the values for a customer or, if no value is present, it would load the default. A new customer would then just run just using the defaults. You could add settings on the fly until the customer is happy.

The data per customer should hopefully be much smaller. Using defaults where possible.

Mike

PS please forgive the formatting, I couldn't make head nor tail out of the info on how to show code in a post.


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

答:
I think it depends on the project.

A stake holder includes anyone who has a stake or interest in what the system does because then they will have some requirements to say what it should do. Therefore I wouldn't include developers in a project where the code is simply pushed out the door and forgotten but would include them if they are supporting the project or extending it as it is then the developers require the system to be maintainable/extendable.

OwnerDisplayName: Tom


问:
Question on refactoring and code design
Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My question is, what strategy I should use:

add this field value into the constructor

create 2 subclasses, replace original field usage with some protected method and override it in subclasses

Or create some composite class that will held instance of my class inside and somehow change that value?

Which approach should I use and why?

答:
Option 3 will allow you to enforce atomicity of the Object Creation. You will be able to set the value in the other class since it has an aggregation to your class with the static final field.

Doing so is a simple yet powerful way to increase both the correctness and robustness of a given object: since it cannot fail to be correctly initialized, subsequent methods are free to deal with their own processing, and use whatever fields they need to do said processing, without concern for the correct initialization sequence of the object.

Resource - Reference

Title: Question on refactoring and code design


问:
Is there such a concept as "pseudo implementation" in software development?
I'm looking for a label to  describe the practice of using human-based computation methods or other means of "faking" an algorithm for the sake of getting a product or demo off the ground quickly without spending the time to develop an technical/scalable/analytical solution? Eg: using Amazon Turk to count the number of empty tables in a restaurant.

I'm also looking to learn more about this subject, but not sure what to search for. Human-based computation is only one method, I'm interested in the general idea of pseudo-implementation. Any ideas, recommended reading?

答: A well-known example of this sort of problem is the Mechanical Turk, where a person hid inside and controlled what otherwise appeared to be a chess-playing machine. Mechanical Turk the most widely-used term for it that I've encountered, even though I think I like akuhn's suggestion of Wizard of Oz prototyping as a more evocative and easier-to-explain name.


问:
OOP Design: relationship between entity classes
I have at first sight a simple issue but can't wrap my head around on how to solve. I have an abstract class Compound. A Compound is made up of Structures. Then there is also a Container which holds 1 Compound.

A "special" implementation of Compound has Versions. For that type of Compound I want the Container to hold the Versionof the Compound and not the Compound itself.

You could say "just create an interface Containable" and a Container holds 1 Containable. However that won't work. The reason is I'm creating a framework and the main part of that framework is to simplify storing and especially searching for special data type held by Structure objects. Hence to search for Containers which contain a Compound made up of a specific Structure requires that the "Path" from Containerto Structure is well defined (Number of relationships or joins).

I hope this was understandable. My question is how to design the classes and relationships to be able to do what I outlined.

EDIT:

Kind of translation issue. with version i did not mean in terms of "versioning" but more in terms of "different variety" but fundamentally the same. There is no active / inactive. All are active.

EDIT 2:

Also note that these classes are entity classes and hence complex inheritance and hierarchies can be problematic.

EDIT 3:

Just don't see how either pattern (Composite, decorator) can work. I tried but the problem is the "path traversal", eg. implementing it in the context of Spring-data and QueryDSL.

I've created Class diagramm with comments that might help to understand the issue. Batch = Version.

答: Can you have the special Compound implementation pass invocations of its Compound methods to its active Version? That way the Container wouldn't know that it has a special Compound.</p>


答:
If I understand correctly, Compound is an abstract class. One implementation of a compound doesn't have Versions but another does. As @SteveEmmerson suggested, giving Compound an ActiveVersion property would solve this design problem.

The option I prefer is to apply the Composite pattern. In this design, the implementation of Compound (say, VersionedCompound) would be responsible for which Version's data to present when it's treated like a Compound.

I prefer it because this design is additive, in other words, it does not require refactoring the Compound class.

Title: OOP Design: relationship between entity classes

Body:
I have at first sight a simple issue but can't wrap my head around on how to solve. I have an abstract class Compound. A Compound is made up of Structures. Then there is also a Container which holds 1 Compound.

A "special" implementation of Compound has Versions. For that type of Compound I want the Container to hold the Versionof the Compound and not the Compound itself.

You could say "just create an interface Containable" and a Container holds 1 Containable. However that won't work. The reason is I'm creating a framework and the main part of that framework is to simplify storing and especially searching for special data type held by Structure objects. Hence to search for Containers which contain a Compound made up of a specific Structure requires that the "Path" from Containerto Structure is well defined (Number of relationships or joins).

I hope this was understandable. My question is how to design the classes and relationships to be able to do what I outlined.

EDIT:

Kind of translation issue. with version i did not mean in terms of "versioning" but more in terms of "different variety" but fundamentally the same. There is no active / inactive. All are active.

EDIT 2:

Also note that these classes are entity classes and hence complex inheritance and hierarchies can be problematic.

EDIT 3:

Just don't see how either pattern (Composite, decorator) can work. I tried but the problem is the "path traversal", eg. implementing it in the context of Spring-data and QueryDSL.

I've created Class diagramm with comments that might help to understand the issue. Batch = Version.


答:
We don't make programmers fill out time sheets. We do have a task management system that people don't seem to mind using, which gives us pretty much all the data we need as far as accounting goes. It isn't hard to figure out when something ran way over the expected amount of time verses someone just forgetting to mark an item complete.

It also becomes obvious if someone is just not producing.

A few queries in the bug tracker also helps to show where things might be getting clogged.

We'd rather keep programmers away from administrative tasks whenever possible and trust that people are doing their job.

The only time I'd find granular time keeping reasonable is if the client was being billed by the hour for something. But then, the ultimate reason for doing it becomes obvious and a little more comfortable, time has to be accurately tracked because that is how much the client will be paying. That's a little different than feeling micromanaged for the sake of administration.

I'm all for treating adults like adults.

Title: As a programmer, are you required to do timesheets?

Body:
Timesheets are something that I've never been fond of, but none the less something that is a requirement within my company. They don't bother me so much, but they seem to really grind some other people's gears. I suppose I have a few questions, and feedback would be great.

Are you required to do timesheets, assuming you aren't a contractor? (That is understandable to me).

What is the granularity of timesheets that you would be comfortable with or that you use? (ex: all entries must be under two hours).

Would timesheets ever factor into your reasons for not accepting a job or leaving a current one?

How has management within your organization justified timesheets if you aren't billing to a client?


问:
How to structure a XML-based order form using ASP.NET
First question here; please help me if I'm doing something wrong.

I'm a graphic designer who's trying to teach himself ASP.NET/C#. My server-side background is PHP/WordPress and some ASP Classic, and when I do code I've hand-coded just about everything since I started learning HTML. So, as I've started to learn .NET, my code has been very manual and procedural.

I'm now trying to create a really basic order form that pulls from an XML file to populate the form; there's an image, a title, a price, and selectable quantities. If I was making this form as a static HTML file, I'd have each field named manually and so on postback I could query each field to get the values. But I'm trying to do this dynamically so that I can add/remove items from the form and not have to change the code.

In terms of displaying the XML, I rolled my own by loading XmlDocument and using XmlNodeList and a bunch of foreach loops to get things displayed. Then, I learned about <asp:XmlDataSource> and <asp:Repeater>, which made displaying the XML simpler by a large margin. However, I've had a really hard time getting the data that's been submitted on postback (it was implied on SO that there are better ways to get data than nested RepeaterItems).

So, what I've learned so far is that you can do things a bunch of different ways in .NET. that's why I thought it'd be good to ask for answers regarding the best way to use ASP.NET to display a XML document and dynamically capture the data that's submitted.

Any help is appreciated! I'm using Notepad++ to code .NET 2.0.

答:
I think that part of the issue you may be facing is that ASP.Net tries to manage the naming of the items for your when it's rendered to the client, so in your ASP page you may name your control "txtFirstName" but inside a nested reapeater it will look like "Repeater1$ctl00$Repeater2$ctl00$txtFirstName."  You probably already know that, but the issue is when you make the objects dynamic, as loaded from the XmlDataSource, it doesn't do the mapping for you back to the name.  You can still use the Request object to pull the values.

So, for example, I pulled the XmlDataSource example off of MSDN (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx) and added some checkboxes to the nested repeater that contains the orders.  When I click submit, just as a test, I view the Params collection from the Request object and if they contain the ID of the checkboxes I'm searching for I output their value.

Let me know if this helps, or you need more.

Below is the code

order.xml:

```<code>    <?xml version="1.0" encoding="iso-8859-1"?>
    <orders>
        <order>
        <customer id="12345" />
            <customername>
                <firstn>John</firstn>
                <lastn>Smith</lastn>
            </customername>
        <transaction id="12345" />
        <shipaddress>
            <address1>1234 Tenth Avenue</address1>
            <city>Bellevue</city>
            <state>Washington</state>
            <zip>98001</zip>
        </shipaddress>
        <summary>
           <item dept="tools">screwdriver</item>
           <item dept="tools">hammer</item>
           <item dept="plumbing">fixture</item>
        </summary>
      </order>
    </orders>
</code>```

And the webpage:

```<code><%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>Order</title>
    <script runat="server">
        void btnGetSubmit_Click(Object sender, EventArgs e)
        {
            foreach (string c in this.Request.Params)
            {
                if (c.IndexOf("chkIncludeItem", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    Response.Write(string.Format("{0} - {1}<br />", c, this.Request.Params[c]));
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        XPath="orders/order"
        DataFile="order.xml" />

      <asp:Repeater ID="Repeater1"
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td><%#XPath("customer/@id")%></td>
                <td id="tdFirstName"><%#XPath("customername/firstn")%></td>
                <td id="tdLastName"><%#XPath("customername/lastn")%></td>
              </tr>
              <tr>
                <td>Ship To</td>
                <td><%#XPath("shipaddress/address1")%></font></td>
                <td><%#XPath("shipaddress/city")%></td>
                <td><%#XPath("shipaddress/state")%>,
                    <%#XPath("shipaddress/zip")%></td>
              </tr>
            </table>
            <h3>Order Summary</h3>
            <asp:Repeater ID="Repeater2"
                 DataSource='<%#XPathSelect("summary/item")%>'
                 runat="server">
                <ItemTemplate>
                    <div>

                     <b><%#XPath("@dept")%></b> -
                         <%#XPath(".")%><asp:CheckBox ID="chkIncludeItem" runat="server" /><br />
                    </div>
                </ItemTemplate>
            </asp:Repeater>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

    <asp:Button ID="btnGetSubmit" runat="server" OnClick="btnGetSubmit_Click" Text="Submit" />
  </form>
  </body>
</html>
</code>```

Body:
I think that part of the issue you may be facing is that ASP.Net tries to manage the naming of the items for your when it's rendered to the client, so in your ASP page you may name your control "txtFirstName" but inside a nested reapeater it will look like "Repeater1$ctl00$Repeater2$ctl00$txtFirstName."  You probably already know that, but the issue is when you make the objects dynamic, as loaded from the XmlDataSource, it doesn't do the mapping for you back to the name.  You can still use the Request object to pull the values.

So, for example, I pulled the XmlDataSource example off of MSDN (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx) and added some checkboxes to the nested repeater that contains the orders.  When I click submit, just as a test, I view the Params collection from the Request object and if they contain the ID of the checkboxes I'm searching for I output their value.

Let me know if this helps, or you need more.

Below is the code

order.xml:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <orders>
        <order>
        <customer id="12345" />
            <customername>
                <firstn>John</firstn>
                <lastn>Smith</lastn>
            </customername>
        <transaction id="12345" />
        <shipaddress>
            <address1>1234 Tenth Avenue</address1>
            <city>Bellevue</city>
            <state>Washington</state>
            <zip>98001</zip>
        </shipaddress>
        <summary>
           <item dept="tools">screwdriver</item>
           <item dept="tools">hammer</item>
           <item dept="plumbing">fixture</item>
        </summary>
      </order>
    </orders>

And the webpage:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>Order</title>
    <script runat="server">
        void btnGetSubmit_Click(Object sender, EventArgs e)
        {
            foreach (string c in this.Request.Params)
            {
                if (c.IndexOf("chkIncludeItem", StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    Response.Write(string.Format("{0} - {1}<br />", c, this.Request.Params[c]));
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        XPath="orders/order"
        DataFile="order.xml" />

      <asp:Repeater ID="Repeater1"
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h2>Order</h2>
            <table>
              <tr>
                <td>Customer</td>
                <td><%#XPath("customer/@id")%></td>
                <td id="tdFirstName"><%#XPath("customername/firstn")%></td>
                <td id="tdLastName"><%#XPath("customername/lastn")%></td>
              </tr>
              <tr>
                <td>Ship To</td>
                <td><%#XPath("shipaddress/address1")%></font></td>
                <td><%#XPath("shipaddress/city")%></td>
                <td><%#XPath("shipaddress/state")%>,
                    <%#XPath("shipaddress/zip")%></td>
              </tr>
            </table>
            <h3>Order Summary</h3>
            <asp:Repeater ID="Repeater2"
                 DataSource='<%#XPathSelect("summary/item")%>'
                 runat="server">
                <ItemTemplate>
                    <div>

                     <b><%#XPath("@dept")%></b> -
                         <%#XPath(".")%><asp:CheckBox ID="chkIncludeItem" runat="server" /><br />
                    </div>
                </ItemTemplate>
            </asp:Repeater>
            <hr />
        </ItemTemplate>
    </asp:Repeater>

    <asp:Button ID="btnGetSubmit" runat="server" OnClick="btnGetSubmit_Click" Text="Submit" />
  </form>
  </body>
</html>


问:
In MVC , DAO should be called from Controller or Model
I have seen various arguments against the DAO being called from the Controller class directly and also the DAO from the Model class.Infact I personally feel that if we are following the MVC pattern , the controller should not coupled with the DAO , but the Model class should invoke the DAO from within and controller should invoke the model class.Why because , we can decouple the model class apart from a webapplication and expose the functionalities for various ways like for a REST service to use our model class.

If we write the DAO invocation in the controller , it would not be possible for a REST service to reuse the functionality right ? I have summarized both the approaches below.

Approach #1

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            new CustomerDAO().save(customer);

    }

 }
</code>```

Approach #2

```<code>  public class CustomerController extends HttpServlet {

    proctected void doPost(....)  {

            Customer customer = new Customer("xxxxx","23",1);
            customer.save(customer);

    }

 }

 public class Customer {

   ...........

   private void save(Customer customer){

        new CustomerDAO().save(customer);

   }

}
</code>```

Note-

Here is what a definition of Model is :

Model:
The model manages the behavior 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).

In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

I would need an expert opinion on this because I find many using #1 or #2 , So which one is it ?

答: I'm not sure what the official MVC pattern calls for, but I normally like to have a "service" layer in between the controllers and the DAOs.  The controller pulls data from the request and passes it to the appropriate service class.  The service class is responsible for calling one or more DAOs that pass back model class(es).  Those model classes are then sent back to the controller in order to be sent to the view layer.  Putting the service layer in helps with reuse since multiple controllers can make use of the same service layer methods.</p>


答: Seems like this would be related to crowdsourcing; just minus the public aspect. You might want to include that in your keyword search.

Title: Is there such a concept as "pseudo implementation" in software development?

Body:
I'm looking for a label to  describe the practice of using human-based computation methods or other means of "faking" an algorithm for the sake of getting a product or demo off the ground quickly without spending the time to develop an technical/scalable/analytical solution? Eg: using Amazon Turk to count the number of empty tables in a restaurant.

I'm also looking to learn more about this subject, but not sure what to search for. Human-based computation is only one method, I'm interested in the general idea of pseudo-implementation. Any ideas, recommended reading?


问:
Are there any reliable solutions for annotations/reflection/code-metadata in C?
Not all languages support java-like annotations or C#-like attributes or code metadata in general, however that doesn't mean it is not possible to have in languages that don't have this.

An example is PHP with Stubbles and the Doctrine annotation library.

My question is, is there anything like this for C?, or are there any reliable ways of doing reflection with extended code metadata in C?

Ideally, I'm looking for something that reads javadoc-like comments.

Edit: The reason for me *needing* as opposed to just wanting, is that I need to generate C code and code-metadata from a database, as well as being able to edit that metadada and update the database. The volume of the work (~15,000 variables/structures/functions to generate from this database) justifies the solution.

答:
Have you considered generating code??

Attributes and their associated behavior are just code if you could expand them.  It would take a ton of setup but you'd have full control.  If you're generating this from a database, I think you have an extremely strong case--this is what ORMs do.


问:
Why does DirectX use a left-handed coordinate system?
I considered posting on Stack Overflow, but the question strikes me as being far too subjective since I can't think of a reasonable technical explanation for Microsoft's choice in this matter. But this question has bugged me for so long and the issue keeps coming up in one of my projects, and I have never actually seen an attempt at explaining this:

OpenGL uses a right-handed coordinate system, where the +Z part of the world coordinate system extends toward the viewer.

DirectX uses a left-handed system where the +Z part of the world coordinate extends into the screen, away from the viewer.

I never used the Glide API, so I don't know how it worked, but from what I can gather, it uses a left-handed system as well.

Is there a technical reason for this? And if not, is there some conceptual advantage to a particular handedness of a coordinate system? Why would one choose one over the other?

答:
The thing to understand is that a HUGE amount of programmer time has been wasted converting between left-handed and right-handed coordinate systems, and even more programmer time has been wasted remembering which system was needed at any particular instant.

All of that went away when right-handed coordinate systems became the industry standard.

There are enough coordinate systems in common use already, without doubling the number by introducing a handedness question.  See Minkler & Minkler, "Aerospace Coordinate Systems and Transformations".  If you are in the aerospace coordinate business, doing e.g. flight simulation, you NEED that book.

My guess is that Microsoft didn't have ANYONE on the DirectX project who knew anything about the industry standards, didn't realize that there WAS an industry standard, and figured it didn't matter.

The other possibility, that they knew right-handed systems were the industry standard, and they deliberately made DirectX left-handed, so as to make it HARD for people to convert code that used DirectX to use OpenGL instead, does not bear consideration.  Were I to discover that this was indeed the case, I would find it necessary to embark on a new and presumably short-lived career as an axe-murderer in Redmond.


问:
Good technique for search text tokenization
We are looking for a way to tokenize some text in the same or similar way as a search engine would do it.

The reason we are doing this is so that we can run some statistical analysis on the tokens. The language we are using is python, so would prefer a technique that works in that language, but could probably set something up to use another language if necessary.

Example

Original token:

```We have some great burritos!```

More simplified: (remove plurals and punctuation)

```We have some great burrito```

Even more simplified: (remove superfluous words)

```great burrito```

Best: (recognize positive and negative meaning):

```burrito -positive-```

答:
Python has a great natural language toolkit, the NLTK. It supports word tokenisation out of the box:

```<code>>>> import nltk
>>> input = 'We have some great burritos!'
>>> tokens = nltk.word_tokenize(input)
>>> tokens
['We', 'have', 'some', 'great', 'burritos', '!']
>>> nltk.pos_tag(tokens)
[('We', 'PRP'), ('have', 'VBP'), ('some', 'DT'), ('great', 'JJ'), ('burritos', 'NNS'), ('!', '.')]
</code>```

The last structure includes natural language tags, which allow you to drop words from consideration based on their classification. You probably want to focus on the JJ (adjective) and NN-prefixed (noun) tags.

From there on out you can apply stemming, and detect positive and negative adjectives.

I believe that for adjective classification, however, you'd need to create your own corpus from online resources such as this; the library does give you the tools for this.

Here is a stemming example using the Porter stemming algorithm:

```<code>>>> from nltk.stem.porter import PorterStemmer
>>> PorterStemmer().stem('burritos')
'burrito'
</code>```

O'Reilly published a book on the library, now available online.

Body:
Python has a great natural language toolkit, the NLTK. It supports word tokenisation out of the box:

>>> import nltk
>>> input = 'We have some great burritos!'
>>> tokens = nltk.word_tokenize(input)
>>> tokens
['We', 'have', 'some', 'great', 'burritos', '!']
>>> nltk.pos_tag(tokens)
[('We', 'PRP'), ('have', 'VBP'), ('some', 'DT'), ('great', 'JJ'), ('burritos', 'NNS'), ('!', '.')]

The last structure includes natural language tags, which allow you to drop words from consideration based on their classification. You probably want to focus on the JJ (adjective) and NN-prefixed (noun) tags.

From there on out you can apply stemming, and detect positive and negative adjectives.

I believe that for adjective classification, however, you'd need to create your own corpus from online resources such as this; the library does give you the tools for this.

Here is a stemming example using the Porter stemming algorithm:

>>> from nltk.stem.porter import PorterStemmer
>>> PorterStemmer().stem('burritos')
'burrito'

O'Reilly published a book on the library, now available online.


问:
How do I know if I'm violating MVVM with WPF?
I was recently grabbing an auto generated TreeViewItem from a nested TreeView node in WPF, and I was using ItemContainerGenerator to get it in code behind.  Then I thought to myself I'm certainly violating MVVM right now. </p>

<p>What are some other signs that someone is violating MVVM ? </p>

答:
Anytime your separation layers meld into each other, it's a violation.

For Example

Having a declarative-only View makes it easier for non-programmer UI designers to change the UI. If you have code behind, then they will have to manage that code. The ViewModel doesn't care who is above it, doesn't care what View is consuming it. It is possible to have multiple views, for example a read-only and an edit View.

The ViewModel (VM) shouldn't be talking to the backing data store, that should be the job of the model. So having your VM work with the database directly would be a violation, that's the job of your Model.

My Opinion

Personally I make MVVM my own. There are the design principles I follow to the best of my ability but if the pattern becomes burdensome then I may violate it here or there and note it. It is supposed to make things easier on large projects, not harder.

However, with a lot of the MVVM frameworks there are for you to use now-a-days, it would be best to just pick one that fits and stick with it. These are designed to reduce the burden of the pattern and it should be an absolute best effort to not violate the pattern.

I think I violate the pattern because I use a WCF reference as my Model and talk to it from my ViewModel. I believe I'm supposed to actually create the Model manually and have that talk to WCF directly. I find this to be too much work.


答:
You know when you are violating MVVM when:

The ViewModel is aware of the View. The ViewModel should never know or care if or what is sitting on top of it. It simply is. Sometimes, the ViewModel might need to generate events that should be handled on the View. When I was working with MVVM, we used the Mediator pattern to handle those cases.

The Model is aware of any other component. The layers build up. The View is aware of the ViewModel and the Model (because it databinds against it), the ViewModel is aware of the Model, and the Model is aware of nothing.

There is logic in the View that does anything other than things specific to the implementation of that View. All generic View state and logic should exist in the ViewModel, but sometimes implementation details are needed in the View. These should be sparing and never interested in anything other than View implementation-specific items.

There is one common pattern that runs throughout: separation of concerns. If any layer of MVVM is interested in anything other than its concern, there is a problem.

Title: How do I know if I'm violating MVVM with WPF?

Body:
I was recently grabbing an auto generated TreeViewItem from a nested TreeView node in WPF, and I was using ItemContainerGenerator to get it in code behind.  Then I thought to myself I'm certainly violating MVVM right now. </p>

<p>What are some other signs that someone is violating MVVM ? </p>


问:
Central Exception Handler
Recently I've been thinking about a general ExceptionHandler, that I could initialize once in my app context and inject it everywhere. The idea that it will have quite simple interface with just public void handle(Exception ex), and then according to exception type it should decide what to do, maybe just log it, or show an alert message to the user, or maybe kill the whole app.

The question is, what is the prettiest way to write such handler without lots of instanceofs? Unfortunately googling gives me only the default exception handler for RuntimeException that was introduced in Java 5.

My first idea is to create an enum, that will have Class field for exception type and it will return the appropriate execution point, for example a concrete exception handler that also implements the interface public void handle(Exception ex), but with the required casting already.

UPD
@alex
I thought about this option and there was a reason I didn't felt ok with it. Suppouse we have code that uses jcifs to acces a file. Simple copy to local storage will require three exception wraps: SMBException, MalformedUrlException and IOException. If I don't use Java 7 catching them may result in repeating three times CenralExceptionHandler.handle(e); which is not that readable. Anyway, when I think about it, it's my fault that I can't use Java 7, so maybe your suggestion is the best. But I'm still in doubts.

答:
What?

No.

You could use method overloading, something like

```<code>public void handle(FunnyException e) {
    ...
}

public void handle(NastyException e) {
    ...
}
</code>```

, and when calling handle, the most appropriate method will be called.
:
However, I would say that you basically do three things with Exceptions:

Propagate them using throws

Propagate them wrapping them in another kind of Exception

Catch them and do something about them

1 and 2 are not worth it; calling a generic exception handler would be more verbose than just writing the code required.

3 tends to be longer code, however, it is very unusual that you can catch and treat exceptions in the same way in different parts of your code; if you do, this tends to be a code smell; perhaps you need a broader try statement or some disjoint code needs to be brought together.

So I don't think there's a reason to do what you describe.

OwnerDisplayName: J-unior

Title: Central Exception Handler

Body:
What?

No.

You could use method overloading, something like

public void handle(FunnyException e) {
    ...
}

public void handle(NastyException e) {
    ...
}

, and when calling handle, the most appropriate method will be called.
:
However, I would say that you basically do three things with Exceptions:

Propagate them using throws

Propagate them wrapping them in another kind of Exception

Catch them and do something about them

1 and 2 are not worth it; calling a generic exception handler would be more verbose than just writing the code required.

3 tends to be longer code, however, it is very unusual that you can catch and treat exceptions in the same way in different parts of your code; if you do, this tends to be a code smell; perhaps you need a broader try statement or some disjoint code needs to be brought together.

So I don't think there's a reason to do what you describe.


问:
Is it okay to use a language that isn't supported by your company for some tasks?
I work for a company that supports several languages: COBOL, VB6, C#, and Java. I use those languages for my primary work, but I often find myself coding some minor programs (e.g. scripts) in Python because I find it to be the best tool for that type of task.

For example: an analyst gives me a complex CSV file to populate some DB tables, so I use Python to parse it and create a DB script.

What's the problem?

The main problem I see is that a few parts of these quick and dirty scripts are slowly gaining importance and:

My company does not support Python

They're not version controlled (I back them up in another way)

My coworkers do not know Python

The analysts have even started to reference them in emails ("launch the script that exports..."), so they are needed more often than I initially thought.

I should add that these scripts are just utilities that are not part of the main project; they simply help to get trivial tasks done in less time. For my own small tasks they help a lot.

In short, if I were a lottery winner to be in a accident, my coworkers would need to keep the project alive without those scripts; they would spend more time fixing CSV errors by hand, for example.

Is this a common scenario? Am I doing something wrong? What should I do?

答:
You need to get the situation formalised as it shouldn't really have got to this point. However, these things happen so you need to explain to your boss that you created these scripts for personal use, but they've "escaped" into wider circulation. Admit (if necessary) that you were at fault for not bringing this to his attention sooner.

At the very least the scripts should be put under source control "just in case" - then at least if you aren't available (for what ever reason) your co-workers will have access to the scripts.

Then you either need to convince your boss that Python is the way to go for these or accept that you are going to have to re-write them in a supported language. If the cost of documenting the scripts and educating your co-workers in Python is lower than that of the re-write you might even win the argument.

ContentLicense: CC BY-SA 4.0


问:
.NET - refactoring code
I have inherited and now further develop a large application consisting of an ASP.NET application, VB6 and VB.NET application.

The software was poorly written.  I am trying to refactor the code as I go along.  The changes I am making are not live (they are contained in a folder on my development machine).  This is proving to be time consuming and I am doing this along side other work which is the prioritiy.

My question is: is this a practical approach or is there a better methodology for refactoring code? I don't have any experience with version control software or source control software and I am wandering if this is what I am missing.  I am a sole developer.

答:
Refactoring or not, you should be using source control. It will save your bacon whether the team is one developer or one thousand.

If you try to maintain two concurrent branches of development the current version and the mythically beautiful refactored version, you will never get the codebase refactored the way you want it. It makes far more sense to refactor code has you have a reason to touch it. Carve a little extra time here and there for it. When someone asks you to fix a bug in module A, you refactor a few things. Here and there. Little by little.

Title: .NET - refactoring code


问:
Internationalization messages based in views or in model entities
I have a small webapp in java and I am adding the internationalization support, replacing texts with labels that are defined in dictionary files.

While some texts are obviously unique to each view (v.g. the html title), other refer to concepts from the model (v.g. a ticket, the location or status of such ticket, etc.)

As usual, some terms will appear many times in different locations (vg, in both the edition page and in the search page and in the listings I have a "ticketLocation" label).

My question is: can I organize the labels around the model concepts (so I have a ticket.location label and I use it everywhere such field is labeled) or should I make a different label for each  (so form.ticketLocation and filter.ticketLocation and list.ticketLocation).

I would go for the first option; I have searched for tips and the only thing that I see that could hinder me is due to the length of the string disrupting the design, and even for that I would prefer having to add a ticket.locationShort for places where there is not much space.

What is your opinion/tips/experience?

答:
Short answer: organize around the model concept.

Long answer:

DRY, especially when you are creating the labels for localization purposes.

Every time you repeat a label you are creating more text which you will either have to pay to have translated (hurts your bottom line) or translate yourself (costs you time, which again hurts your bottom line).

Also it can quickly bloat your dictionary to gargantuan size. Which can affect performance. I can think of no better place to adhere as much as possible to the DRY principle then with localization.


答:
I think you should learn source control so that if you make a change that breaks another component, you can easily roll back to the previous version.

With respect to how you are refactoring, there really isn't a better methodology. It is a time consuming process but, when done right, is well worth it. In the book Clean Code, i feel the author has a great approach to refactoring. He suggests that everytime you need to make a change in a file, to also refactor and leave the file in better shape than you found it. This approach can allow you to work on your task then since you are familar with code, it will be easier to refactor.

Title: .NET - refactoring code

Body:
I have inherited and now further develop a large application consisting of an ASP.NET application, VB6 and VB.NET application.

The software was poorly written.  I am trying to refactor the code as I go along.  The changes I am making are not live (they are contained in a folder on my development machine).  This is proving to be time consuming and I am doing this along side other work which is the prioritiy.

My question is: is this a practical approach or is there a better methodology for refactoring code? I don't have any experience with version control software or source control software and I am wandering if this is what I am missing.  I am a sole developer.


答:
Before doing any other refactoring I would start with the basic (which many seems to forget)

Fix the exception handling

I've seen loads of applications that "handles" exceptions. i.e. they try the exception, log it and then rethrow it (and if you are lucky without doing throw ex;). An exception is really handled when the method can deliver the result that it promised. Those are the only catch blocks that should be left.

Remove all those try blocks. In  ASP.NET you can catch (and log the exception + the request) in global.asax.

Getting proper exceptions is vital when refactoring (so that you know where you screw up).

Validate arguments

This is another common problem. Many developers seem to think that they got full control of their application and what they pass to each method. Hence they do not validate the method arguments.

Be polite, throw early. Doing so will also reduce the need for basic logging since the error will be caught early in the call stack instead of deep down.

A bonus is that you have to spend time understanding the methods to be able to validate the arguments. You might even want to document them with your findings until next time you visit them.

Continue on

When that's done you might continue with the rest like refactoring large methods etc.

Title: .NET - refactoring code


答:
It sounds like you need a coordinator that watches and monitors all the other processes and handles database communication. This keeps the processes separate and the coordinator would assign unique identifiers to each process and then handle responses as needed.

The coordinator would be something that executes all the time and can react to the situation at hand. Your description sounds like more someone is kicking off a process manually. This could still be used but they would talk to the coordinator program first and it would do that actions and manage everything with the database.

Title: How to keep a generic process unique?

Body:
I'm currently working on a project that makes connection between different banks which send us  information on which that project replies. A part of that project configures the different protocols that are used (not every bank uses the same protocol), this runs on a separate server. These processes all have unique id's which are stored in a database.

But to save time and money on configurations and new processes, we want to make a generic protocol that banks can use. Because of PCI requirements we have to make a separate process for every bank we connect to.

But the generic processes have only 1 unique identifier and therefor we cannot keep them apart. Giving every copy of that process a different identifier is as I see it impossible because they run entirely separate.

So how do I keep my generic process unique?


问:
Implementing the transport layer for a SIP UAC
I have a somewhat simple, but specific, question about implementing the transport layer for a SIP UAC.

Do I expect the response to a request on the same socket that I sent the request on, or do I let the UDP or TCP listener pick up the response and then route it to the correct transaction from there? The RFC does not seem to say anything on the matter.

It seems that especially using UDP, which is connection-less, that I should just let the listeners pick up the response, but that seems sort of counter intuitive. Particularly, I have seen plenty of UAC implementations which do not depend on having a Listener in the transport layer.

Also, most implementations I have looked at do not have the UAS receiving loop responding on the socket at all. This would tend to indicate that the client should not be expecting a reply on the socket that it sent the request on.

For clarification:

Suppose my transport layer consists of the following elements:

```<code>TCPClient (Sends Requests for a UAC via TCP)
UDPClient (Sends Requests for a UAC vid UDP)
TCPSever (Loop receiving Requests and dispatching to transaction layer via TCP)
UDPServer (Loop receiving Requests and dispatching to transaction layer via UDP)
</code>```

Obviously, the *Client sends my Requests. The question is, what receives the Response? The *Client waiting on a recv or recvfrom call on the socket it used to send the request, or the *Server?

Conversely, the *Server receives my requests, What sends the Response? The *Client? doesn't this break the roles of each member a bit?

Update
I did a packet capture on an SIP Invite transaction between Ekiga and a PolyCom server. Ekiga was the client, and the polycom was the server. In the invite request Ekiga used port 5060 in the via header. 5060 is the port that its UAS is listening on, so that would seem to indicate that the UDPServer is receiving the responses to all requests and not the UDPClient that sent the request. Is this valid reasoning?

答:
When I did my sip stack I build all the messages in the transport layer and than passed them up to the next layer which had to identify the correct transactions.

Doing so also makes everything easier to test.


答:
Refactoring should be done on your live project -- as part of other work.  This has several advantages, most importantly, it actually gets done. Almost as important, your changes are rolled in slowly, so that when you miss something, and break it (and you will), there's one thing brocken and not working and not a hundred.

On a related note, it allocates the "cost" of the refactoring appopriately --if you have a module that is either hardly used, or ugly but problem free, fixing it is less important than a module that is used a lot or actually impeding new development.  So when you are fixing bug X, or adding feature Y, and have to work around prblems in class z, z should be cleaned up.

Title: .NET - refactoring code


问:
How much help should I give during technical interviews?
I'm asked to perform or sit in during many technical interviews. We ask logic questions and simple programming problems that the interviewee is expected to be able to solve on paper. (I would rather they have access to a keyboard, but that is a problem for another time.) Sometimes I sense that people do know how to approach a problem, but they are hung up by nervousness or some second-guessing of the question (they aren't intended to be trick questions).

I've never heard my boss give any help or hints. He just thanks the interviewee for the response (no matter how good or bad it is) and moves on to the next question or problem. But I know something about the rabbit hole that defeat and nerves can lead you down, and how it disables your mind, and I can't help wondering if providing a little help now and then would ultimately help us end up with more capable programmers instead of more failed interviews.

Should I provide hints and assistance for befuddled interviewees (and if so, how far should I go while still being fair to the more prepared candidates)?

答:
I think that this ultimately comes down to your personality as an interviewer, and what you think is important and therefore are really grading the candidate on.

Personally, I value practical / pragmatic capability over academic / esoteric trivia. I'm much more interested in a candidate that can come in, get to work, and contribute effectively in some valuable way to whatever project(s) they are being hired to work on than I am on how good their memory for minutia is.

So, I'll coach a bit if the candidate is stuck on something esoteric, or a rarely used nuance, or an edge case that might be relevant in a made-up interview question but is rarely if ever relevant in real life. Especially anything they could get with a couple of minutes on Google or with a handy desk reference, or "set it and forget it" type things.

However, I won't coach them on real-world, common, mainstream, fundamental, work-a-day things. These are the things I want to be innate to them.


问:
Do functional generics exist and what is the correct name for them if they do?

Consider the following generic class:

public class EntityChangeInfo<EntityType,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}
```

<p>Here <code>EntityType</code> unambiguously defines <code>TEntityKeyType</code>.
So it would be nice to have some kind of types' map:</p>

<pre class="lang-cs prettyprint-override"><code>public class EntityChangeInfo<EntityType,TEntityKey> with map
  < [ EntityType : Person -> TEntityKeyType : int]
    [ EntityType : Car -> TEntityKeyType : CarIdType ]>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}
</code>```

Another one example is:

 public class Foo<TIn> with map
< [TIn : Person -> TOut1 : string, TOut2 : int, ..., TOutN : double ]
  [TIn : Car -> TOut1 : int, TOut2 :int, ..., TOutN : Price ] >
    {
        TOut1 Prop1 {get;set;}
        TOut2 Prop2 {get;set;}
        ...
        TOutN PropN {get;set;}
    }
```

<p>The reasonable question: how can this be interpreted by the compiler?
Well, for me it is just the shortcut for two structurally similar classes:</p>

<pre class="lang-cs prettyprint-override"><code>public sealed class Foo<Person>
{
    string Prop1 {get;set;}
    int Prop2 {get;set;}
    ...
    double PropN {get;set;}
}

public sealed class Foo<Car>
{
    int Prop1 {get;set;}
    int Prop2 {get;set;}
    ...
    Price PropN {get;set;}
}
</code>```

But besides this we could imaging some update of the Foo<>:

public class Foo<TIn> with map
    < [TIn : Person -> TOut1 : string, TOut2 : int, ..., TOutN : double ]
      [TIn : Car -> TOut1 : int, TOut2 :int, ..., TOutN : Price ] >
        {
            TOut1 Prop1 {get;set;}
            TOut2 Prop2 {get;set;}
            ...
            TOutN PropN {get;set;}

            public override string ToString()
            {
                 return string.Format("prop1={0}, prop2={1},...propN={N-1},
                                         Prop1, Prop2,...,PropN);
            }
        }
```

This all can seem quite superficial but the idea came when I was designing the messages for our system. The very first class. Many messages with the same structure should be discriminated by the EntityType.

So the question is whether such construct exists in any programming language?

答:
Yes, this facility does exist in some programming languages.

For example, in Haskell, these are called Functional Dependencies (fundeps are not part of Haskell 98, but they are supported in common implementations like GHC)

In C++, you can achieve this kind of thing with traits classes.


答:
I think you are using generics for something that they were not intended and designed for.

Generics are to allow caller to create specific type from generic pattern. The generic type should never know what type caller will put in. It can limit those types, but never know exact types. Think how would you use those types? You cannot pass this to anything else, because it would mean this something else too needs to be generic and then you get "generic creep" where generic types get propagated through structure. I was there and it is not good at all.

What you are trying to achieve is extremely similar to code generation. You can use T4 or something and generate all required classes from some kind of definition. You should really forget about generics and think in pure OOP. Find something all those messages have in common that the message system can use and implement concrete class for each message type. This will make the design much more flexible, because you are not limited to two fields and will be much cleaner.

Title: Do functional generics exist and what is the correct name for them if they do?

Body:
Consider the following generic class:

public class EntityChangeInfo<EntityType,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}
```

<p>Here <code>EntityType</code> unambiguously defines <code>TEntityKeyType</code>.
So it would be nice to have some kind of types' map:</p>

<pre class="lang-cs prettyprint-override"><code>public class EntityChangeInfo<EntityType,TEntityKey> with map
  < [ EntityType : Person -> TEntityKeyType : int]
    [ EntityType : Car -> TEntityKeyType : CarIdType ]>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}
</code>```

Another one example is:

 public class Foo<TIn> with map
< [TIn : Person -> TOut1 : string, TOut2 : int, ..., TOutN : double ]
  [TIn : Car -> TOut1 : int, TOut2 :int, ..., TOutN : Price ] >
    {
        TOut1 Prop1 {get;set;}
        TOut2 Prop2 {get;set;}
        ...
        TOutN PropN {get;set;}
    }
```

<p>The reasonable question: how can this be interpreted by the compiler?
Well, for me it is just the shortcut for two structurally similar classes:</p>

<pre class="lang-cs prettyprint-override"><code>public sealed class Foo<Person>
{
    string Prop1 {get;set;}
    int Prop2 {get;set;}
    ...
    double PropN {get;set;}
}

public sealed class Foo<Car>
{
    int Prop1 {get;set;}
    int Prop2 {get;set;}
    ...
    Price PropN {get;set;}
}
</code>```

But besides this we could imaging some update of the Foo<>:

public class Foo<TIn> with map
    < [TIn : Person -> TOut1 : string, TOut2 : int, ..., TOutN : double ]
      [TIn : Car -> TOut1 : int, TOut2 :int, ..., TOutN : Price ] >
        {
            TOut1 Prop1 {get;set;}
            TOut2 Prop2 {get;set;}
            ...
            TOutN PropN {get;set;}

            public override string ToString()
            {
                 return string.Format("prop1={0}, prop2={1},...propN={N-1},
                                         Prop1, Prop2,...,PropN);
            }
        }
```

This all can seem quite superficial but the idea came when I was designing the messages for our system. The very first class. Many messages with the same structure should be discriminated by the EntityType.

So the question is whether such construct exists in any programming language?


问:
Build one to throw away vs Second-system effect
On one hand there is an advice that says "Build one to throw away". Only after finishing a software system and seeing the end product we realize what went wrong in the design phase and understand how we should have really done it.

On the other hand there is the "second-system effect" which says that the second system of the same kind that is designed is usually worse than the first one; there are many features that did not fit in the first project and were pushed into the second version usually leading to overly complex and overly engineered.

Isn't here some contradiction between these principles? What is the correct view over the problems and where is the border between these two?

I believe that these "good practices" are were firstly promoted in the seminal book The Mythical Man-Month by Fred Brooks.

I know that some of these issues are solved by Agile methodologies, but deep down, the problem is still the principles still stand; for example we would not make important design changes 3 sprints before going live.

答:
The problem you are referring to means that several things were skipped, hence the resulting system went wrong. Let me describe some of the missing steps:

Quality Management - Do it right the first time! Never use any temporary hacks, or temporary compromises. There shall be no rework needed. All resources are used efficiently and everything you do is a proper contribution to the project.

Feasibility Analysis - Discover business need. Create a business case for the project.

Project Plan - Clearly define your initial scope, plan how the solution will be delivered, create a baseline, stick to the plan. Don't spend time on anything that's not on the critical path.

Requirements Engineering - Elicit business requirements (i.e. capture business processes and determine what business operations should be supported by the computerized system, translate 1:1 business operations to system use cases). Validate & verify! (are we building the right thing? Are we building the thing right?) All requirements must be linked to the original business need.

Software Design - Translate use cases and domain model into component design and solution architecture. All components must be linked to the requirements from RE.

Implementation - Code the software as in the design. All code must be linked to components from SD.

Validation - Unit testing, integration testing, performance, ... (all use cases from RE will now need to be tested)

These are some key aspects of a software process. Mentioned activities are part of Software Engineering. This is how you build the right software solution for the real business need, and you build it on time, on budget, to specification.

Look up these terms to build better software and to get it right the first time:

Feasibility Analysis (esp. how to build a Business Case)

Project Management (esp. Project Plan and Risk Register with Risk Mitigation)

Requirements Engineering  (elicitation, analysis, specification, validation)

Software Design (UML and component-based software engineering)

Software Construction (design patterns, frameworks, defensive programming)

Software Validation (unit testing, UAT, etc.)


问:
Is this possible to re-duplicate the hardware signal on Linux?
Since that every things is a file on the UNIX system. If I have a hardware, for example, a mouse, move from left corner to right corner, it should produce some kinds of file to communicate with the system.

So, if my assumption is correct, is this possible to do following things:

Capture the raw data, which is about moving mouse cursor from left corner to right corner?

Reduplicate the raw data, using a program, same producing speed, and data, in order to "redo" moving mouse cursor from left corner to right corner

答:
Yes you can capture "raw" mouse events using the /dev/input/* device nodes.  You can then replay those events by writing an application that interfaces with the uinput driver.

You can also do this with the XServer by subscribing to mouse events on the root window and using the xtest extension to replay the events.


答:
Actually you are on a right path by mentioning the lack of source control in your development practice/company. This is a must to have for a SOLID application development and proper project maintenance work.

How would you know what set of changes brake the legacy logic? and how would you roll back to previous state without using a version control tools like Git, TFS, SVN, etc ?...

Also better NOT to maintain two different code basis of a project. It is error prone and pain in merger of the code, especially a bigger pain in a team development.

For re-factoring: Install a tool for code refactoring (like, JustCode, Re-sharper, etc..). There are some free add-ons that you may get from NuGet packages as well. It will save you ton of times and provide you hints to take care of the smelling code blocks.

Title: .NET - refactoring code


问:
multi-clients web application,should I use custom user controls or a common user control
Say my company is going to build a complicated asp.net web form education system. One of the module is web based registration. To make it flexiable, we decide to use user control(ascx) with rule-engine (work flow) regulating all business logic behide them. Thus in future,for different clients, we can simply config basic existing rules or adding new rules.(Rules stored in db or XML per client).

Now the question is how to deal with the user controls (ascx)? My opinion is for different client build diffrent user control from scratch. other voice is like reuse existing  user controls.

答:
Well it depends, if each client has their own functions that are unique to how they use the application then yea, build the user controls from scratch.

If they don't, they basically are all doing the same thing just need it branded or whatever for their corporation, then their is no point re-inventing the wheel.

My company handles it like this: We have a central platform that all our websites are based off of. If a particular website and form application isn't that different from our base generic one then we build on top of that central platform.

If the application form is significantly different, then we branch our main platform and create a new project for that individual program. So that we don't end up with a ton of spaghetti program-specific code in our models/controllers.

TLDC: Don't decide now, be flexible, ultimately it should be determined by the client; which one will create the least amount of work, and the most maintainable platform.


答:
John Bartholomew's answer is the correct exposition of the technique you're referring to.

Leaving this incorrect answer here for a short while for posterity as it's relevant related content. Will probably delete tomorrow when you've had time to review the information in case it's valuable to you :)

There are a class of functional languages with a related concept, referred to as "dependent types" the idea being you can create functionality that depends on particular values of a type rather than just the type itself.
(that is my very limited description of the concept; crazy math-nuts people can speak to this more)

Here's the wikipedia for some further reading, it lists a hand full of languages which implement dependent types.

One of the biggest uses of dependent types as I understand them is for proofs, which makes sense if you think about it and is similar to what you're trying to use it for; you're trying to constrain the types to get specific functionality in your type out of a type passed to you; dependent types works similarly but constraining down to the value level which is a very hardy constraint you could see being useful in the context of proving things are interacting in a strictly defined way.

Please; anyone more familiar with the concept of dependent types correct me if I'm off in my understanding. It's a very high level concept and not one I've direct experience with beyond my addiction to reading about various languages, I wouldn't want to be giving incorrect information here.


问:
What software do you use to track time spent on a project?
What software do you use to track time spent on a project?</p>

答:
When I was freelancing, I used Freshbooks, an accounting web app that has a handy pop out timer.

The trick is, remembering to start and stop the timer appropriately. I was longing for something that integrated directly with KDE/Multiple desktop (think one project open per desktop, automatically tracking time spent on each one), but never found anything that managed it.


答:
Well...you could just close the types for convenience:

```<code>public class EntityChangeInfo<TEntityType,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}

public class PersonChangeInfo : EntityChangeInfo<Person,int>
{
}

public class CarChangeInfo : EntityChangeInfo<Car, CarIdType>
{
}
</code>```

Though, it seems something like this would be more flexible:

```<code>public **interface** IEntityChangeInfo<TEntity,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}
</code>```

Also, this might be language dependent but I would suggest that even if you use an enum internally for convenience, you NOT expose the enum in the contract.

```<code>public **interface** IEntityChangeInfo<TEntity,TEntityKey>
{
    int? ChangeTypeId {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}
</code>```

or

```<code>public **interface** IEntityChangeInfo<TEntity,TEntityKey,TChangeType>
{
    TChangeType ChangeType {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}
</code>```

Body:
Well...you could just close the types for convenience:

public class EntityChangeInfo<TEntityType,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKeyType EntityKey {get;}
}

public class PersonChangeInfo : EntityChangeInfo<Person,int>
{
}

public class CarChangeInfo : EntityChangeInfo<Car, CarIdType>
{
}

Though, it seems something like this would be more flexible:

public **interface** IEntityChangeInfo<TEntity,TEntityKey>
{
    ChangeTypeEnum ChangeType {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}

Also, this might be language dependent but I would suggest that even if you use an enum internally for convenience, you NOT expose the enum in the contract.

public **interface** IEntityChangeInfo<TEntity,TEntityKey>
{
    int? ChangeTypeId {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}

or

public **interface** IEntityChangeInfo<TEntity,TEntityKey,TChangeType>
{
    TChangeType ChangeType {get;}
    TEntityKey EntityKey {get;}
    TEntity Entity {get;}
}


问:
What is the difference between requirements and specifications?
I've been tasked with developing requirements and specifications for a project our group is starting.

I realized that I don't know the difference; a Google search just confused me more -- it seems some people say that specifications are requirements, but at a lower level.

答:
Think, you are going to build a high rise building on a land.

Now you need to consider the Requirements before you start, such as:

Architecture or Design Engineer

Soil Test Engineer

Wind Pressure Test Team

Demolisher

Digger

Man Power

Water Supply

Workers living/rest area

Enough Fund

Project Management

Quality Management

Security and Safety Control

Etc.

Now the above contents are part of Requirements to build a high rise building.
From the above team, you get the technical outcome, which they hold as part of profession.

This is exactly, what is happening in software industry, a group of professional people involved to provide knowledge to build the technical specification, such as someone works on UI design, OO design, database design, graphic design, test case design, coding, integration,  deployment team etc.

The above para will be part of handbook, that you can call Technical Specification.


问:
What triggered the popularity of lambda functions in modern mainstream programming languages?
In the last few years anonymous functions (AKA lambda functions) have become a very popular language construct and almost every major / mainstream programming language has introduced them or is planned to introduce them in an upcoming revision of the standard.

Yet, anonymous functions are a very old and very well-known concept in Mathematics and Computer Science (invented by the mathematician Alonzo Church around 1936, and used by the Lisp programming language since 1958, see e.g. here).

So why didn't today's mainstream programming languages (many of which originated 15 to 20 years ago) support lambda functions from the very beginning and only introduced them later?

And what triggered the massive adoption of anonymous functions in the last few years? Is there some specific event, new requirement or programming technique that started this phenomenon?

IMPORTANT NOTE

The focus of this question is the introduction of anonymous functions in modern, main-stream (and therefore, maybe with a few exceptions, non functional) languages.
Also, note that anonymous functions (blocks) are present in Smalltalk, which is not a functional language, and that normal named functions have been present even in procedural languages like C and Pascal for a long time.

Please do not overgeneralize your answers by speaking about "the adoption of the functional paradigm and its benefits", because this is not the topic of the question.

答:
Here the ancestry to the best of my knowledge.

2005: Javascript has most recently brought higher-order programming with lambdas back into mainstream. In particular libraries like underscore.js and jquery. One of the first of these libraries was prototype.js which predates jquery by about year. Prototype is based on the Enumerable module of Ruby, which leads us to…

1996: Ruby's Enumerable module very obviously took inspiration from Smalltalk's collection framework. As has been mentioned by Matz in many interviews, which leads us to…

1980: Smalltalk uses a lot of higher-order programming and provides a collection API that makes heavy use of higher-order programming (eg, GNU Smalltalk's Iterable class). In idiomatic Smalltalk code you won't find any for loops but only high-order enumerations. Unfortunately when Java when Smalltalk's collection framework was ported to Java in 1998 the higher-order enumerations were left out. That is how higher-order programming was phased out of the mainstream for the next ten years to come! Smalltalk has many ancestries, but relevant to OP's question is LISP, which leads us to…

1958: LISP, obviously, has higher-order programming at its core.


问:
Java Dynamic Binding
I am having trouble understanding the OOP Polymorphic principl of Dynamic Binding ( Late Binding ) in Java. I looked for question pertaining to java, and wasn't sure if a overall answer to how dynamic binding works would pertain to Java Dynamic Binding, I wrote this question.

Given:

```<code>class Person
{
     private String name;

     Person(intitialName)
     {
          name = initialName;
     }

     // irrelevant methods is here.

     // Overides Objects method
     public void writeOutput()
     {
          println(name);
     }
}

class Student extends Person
{

     private int studentNumber;

     Student(String intitialName, int initialStudentNumber)
     {
     super(intitialName);
     studentNumber = initialStudentNumber;
     }

     // irrellevant methods here...

     // overides Person, Student and Objects method
     public void writeOutput()
     {
      super.writeOutput();
      println(studentNumber);
     }
  }

class Undergaraduate extends Student
{

     private int level;

     Undergraduate(String intitialName, int initialStudentNumber,int initialLevel)
     {
     super(intitialName,initialStudentNumber);
     level = initialLevel;
     }

     // irrelevant methods is here.

     // overides Person, Student and Objects method
     public void writeOutput()
     {
      super.writeOutput();
      println(level);
     }

  }
</code>```

I am wondering. if I had an array called person declared to contain objects of type Person:

```<code>  Person[] people = new Person[2];
  person[0] = new Undergraduate("Cotty, Manny",4910,1);
  person[1] = new Student("DeBanque, Robin", 8812);
</code>```

Given that person[] is declared to be of type Person, you would expect, for example, in the third line where person[0] is initialized to a new Undergraduate object,to only gain the instance variable from Person and Persons Methods since doesn't the assignment to a new Undergraduate to it's ancestor denote the Undergraduate object to access Person - it's Ancestors, methods and isntance variables...

Thus ...with the following code I would expect

```<code>  person[0].writeOutput();  // calls Undergraduate::writeOutput()
  person[1].writeOutput();  // calls Student::writeOutput()
</code>```

person[0] to not have Undergraduate's writeOutput() overidden method, nor have person[1] to have Student's overidden method - writeOutput().

If I had

```<code>Person mikeJones = new Student("Who?,MikeJones",44,4);
mikeJones.writeOutput();
</code>```

The Person::writeOutput() method would be called.

Why is this not so? Does it have to do with something I don't understand about relating to arrays? Does the declaration Person[] people = new Person[2] not bind the method like the previous code would?

答:
It has nothing to do with arrays, it is the effect of the "late binding". The Java compiler only checks that Person has the writeOutput method, but does not bind the call to that class method. The binding is performed at runtime, where the JVM finds that Person[0] is an UnderGraduate and calls the method definition from UnderGraduate, and not the one from Person.

I understand that C++ works the other way unless you specify virtual, but it is better this way (if you think that a class encapsulates data and methods, you ensure that the methods used are the ones which really matter to the encapsulated data).

Title: Java Dynamic Binding


问:
Should I expect my team to have more than a basic proficiency with our source control system?
My company switched from Subversion to Git about three months ago.  We had weeks of advance notice prior to the switch.  Since I'd never used Git before (or any other DVCS), I read Pro Git and spent a little time spinning up my own repositories and playing around, so that when we switched I'd be able to keep working with minimal pain.  Now I'm the 'Git guy' by default.

With a couple of exceptions, most of my team still has no idea how Git works.  For example, they still think of branches as complete copies of the source code, and even go so far as to clone the repo into multiple folders (one per branch).  They generally look at Git as a scary black box.

Given the fundamental nature of source control in our daily work (not to mention the ridiculous amount of power Git affords us), I'm of the opinion that any dev who doesn't achieve a certain level of proficiency with it is a liability.

Should I expect my team to have at least some understanding of how Git works internally, and how to use it beyond the most basic pull/merge/push operations?  Or am I just making something out of nothing?

答: I have only used Git in a personal setting and not a professional one, and while I do like the power it has and the idea of a more decentralized source control, it has major problems.  Git has leaky abstraction and it takes multiple commands to do simple things (for example to make a change: git add, git commit, then git push).  Also some of the documentation is lacking and/or confusing like with the rebase command description...  "Forward-port local commits to the updated upstream head".  I have no clue what that means, and although I now know you can move commits around and rewrite history with it (another annoyance... why should you be allowed to do this???) I would never have guessed that from that command description.  I think some reading on the part of your team, and some more training provided by you is in order.</p>


答:
Toggl

I use this all the time and I like it.

web based so it will stay synced between multiple computers

decent interface

nice api

integrates with GMail, iGoogle or anything you can put an iframe into.

integrates into Basecamp and FreshBooks

Body: What software do you use to track time spent on a project?</p>


答: Part of what should be looked at is communication skills. If the candidate is unclear about the question, he should ask questions to clarify. This is a good thing, in my opinion. Too often, bad decisions are made because certain assumptions are made when reading specifications or, in this case, processing an interview question. The candidate may answer based upon these assumptions and totally miss the intended point. The question might be flawed, or it might be the candidate. In either case, allowing for clarification via communication demonstrates a valuable skill, one that employers should look for.</p>

Title: How much help should I give during technical interviews?

Body:
I'm asked to perform or sit in during many technical interviews. We ask logic questions and simple programming problems that the interviewee is expected to be able to solve on paper. (I would rather they have access to a keyboard, but that is a problem for another time.) Sometimes I sense that people do know how to approach a problem, but they are hung up by nervousness or some second-guessing of the question (they aren't intended to be trick questions).

I've never heard my boss give any help or hints. He just thanks the interviewee for the response (no matter how good or bad it is) and moves on to the next question or problem. But I know something about the rabbit hole that defeat and nerves can lead you down, and how it disables your mind, and I can't help wondering if providing a little help now and then would ultimately help us end up with more capable programmers instead of more failed interviews.

Should I provide hints and assistance for befuddled interviewees (and if so, how far should I go while still being fair to the more prepared candidates)?


答: Training and understanding are the minimal requirements. Someone in charge should have made sure there was a plan on how your team would use it. You wouldn't adopt a new programming language without guidelines. Driver's training is much more effective when established rules of the road are incorporated.</p>

Title: Should I expect my team to have more than a basic proficiency with our source control system?

Body:
My company switched from Subversion to Git about three months ago.  We had weeks of advance notice prior to the switch.  Since I'd never used Git before (or any other DVCS), I read Pro Git and spent a little time spinning up my own repositories and playing around, so that when we switched I'd be able to keep working with minimal pain.  Now I'm the 'Git guy' by default.

With a couple of exceptions, most of my team still has no idea how Git works.  For example, they still think of branches as complete copies of the source code, and even go so far as to clone the repo into multiple folders (one per branch).  They generally look at Git as a scary black box.

Given the fundamental nature of source control in our daily work (not to mention the ridiculous amount of power Git affords us), I'm of the opinion that any dev who doesn't achieve a certain level of proficiency with it is a liability.

Should I expect my team to have at least some understanding of how Git works internally, and how to use it beyond the most basic pull/merge/push operations?  Or am I just making something out of nothing?


答:
No; I think it's reasonable to expect the following:

Do everyday tasks (commit, push, pull, branch, merge, bisect, etc) without hand-holding.

Do non-routine tasks without repeated instruction.  (A few repetitions is ok - I have to meet someone 2-3 times before their name really sticks.)

If they can't do #1, then the training part of your roll-out was probably insufficient.
If they can't do #2, then first make sure you're explaining things clearly enough before getting too upset.


问:
Accessing the same service more than twice in the nick of time
I have an application that will access interface service A which is to run from windows startup. This service is used by program B and my application functions on B's presence after getting a pointer to A.
The scenario is translated as follows,

```<code>public interface A{}
///my program
public class MyProgram
{
    public MyProgram()
    {
      ProgramB.DoA();
    }
    public A GetA(){}
}

public class ProgramB
{
   void DoA(){}
}
</code>```

The translated source is not true, but that seems to be what I am looking for. In order to eliminate the overhead of allocating and realocating dynamic accesses to the same service used by other processes, would you please provide an actual solution to the problem ?(I am all out of any idea now)

答:
I don't fathom your intent (and the question title is opaque as well), but if I understand what you are asking WCF supports duplex communication.

http://msdn.microsoft.com/en-us/library/ms731064.aspx

If you are running the service (A) and the client (B) on the same box, you can use a NamedPipe binding which is pretty straightforward. There's a tutorial implementation here that might be helpful:

http://www.switchonthecode.com/tutorials/wcf-tutorial-events-and-callbacks

If I've misunderstood your question, please disregard.


答: Another really old example of something akin to anonymous functions / lambdas is call-by-name in Algol 60.  Note however that call-by-name is closer to passing macros as parameters than passing true functions, and it is more fragile / harder to understand as a result.</p>

Title: What triggered the popularity of lambda functions in modern mainstream programming languages?

Body:
In the last few years anonymous functions (AKA lambda functions) have become a very popular language construct and almost every major / mainstream programming language has introduced them or is planned to introduce them in an upcoming revision of the standard.

Yet, anonymous functions are a very old and very well-known concept in Mathematics and Computer Science (invented by the mathematician Alonzo Church around 1936, and used by the Lisp programming language since 1958, see e.g. here).

So why didn't today's mainstream programming languages (many of which originated 15 to 20 years ago) support lambda functions from the very beginning and only introduced them later?

And what triggered the massive adoption of anonymous functions in the last few years? Is there some specific event, new requirement or programming technique that started this phenomenon?

IMPORTANT NOTE

The focus of this question is the introduction of anonymous functions in modern, main-stream (and therefore, maybe with a few exceptions, non functional) languages.
Also, note that anonymous functions (blocks) are present in Smalltalk, which is not a functional language, and that normal named functions have been present even in procedural languages like C and Pascal for a long time.

Please do not overgeneralize your answers by speaking about "the adoption of the functional paradigm and its benefits", because this is not the topic of the question.


问:
Are Scrum and XP comparable things or are they used for different things
Are Scrum and XP comparable things or are they used for different things? what is the main features of each of them? how do they overlap?

I've been reading about both XP and Scrum over the past weeks and something is vague about them for me. Scrum does have a definitive official rulebook but for XP I'm not sure where to look.

答:
To get started with XP, see extreme programming.

Both Scrum and XP are agile methodologies.  As such, they have many things in common - such as a daily short meeting (stand up vs daily scrum) and approaches for dealing with customers.  They also have differences.  XP has some lower level practices such as pair programming as well.

I googled "scrum vs xp" and looked at the first few results.  I like this one best as it covers some tangible examples of differences.  You may read some of the others if interested.  Do note that both XP and Scrum get customized rather than followed literally.  So if a Scrum is X weeks, people may use X-1 weeks.