答:
Theoretically @JVXR is is right. Waterfall means you get requirements, plan the work, set the price and delivery schedule an off you go. At the end, it all comes together, often the requirements were wrong or changed, the work was more than expected and it turns to a big ball of mud. Agile promises to solve all the problems of waterfall by doing small bits of work in response to changing needs and increase knowledge, regularly delivering something that value to the customer, and stopping when the customer decides the job is done (in reality - when the money runs out).

Waterfalls problems are well known and documented, and therefore easy to suggest solutions to. Agile has it's problems also, however they are less well known and even less well documented - we, as an industry, tried waterfall and failed miserably. Now were are trying Agile, and failing (slightly less miserably, but still failing), and no one wants to suggest it's not working until they can see/sell a better solution.

As a result, for every 100 software houses, there are probably 200 claimed 'agile' processes in use (Many shops have more than one team, and part of agile is a team can do it however they like. Maybe 10 of these processes are truly Agile, the rest are best described as waterfall in drag (i.e. Waterfall without the documentation)


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

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

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

答:
Other than startup cost I don't know there is a theoretical reason why a JIT platform would not perform as well as a native code platform.

There are other language features, like garbage collection, that mean that Java will use more resources and probably be slower but it is very easy to overstate this advantage.

In practice however, there are different programming cultures around C++ than Java. This results in Java designs often being more abstracted, relying more on reflection and various runtime linking patterns that make it hard or even impossible to optimize quite as well. Yes you could do all these same things in C++ and make it slower but in my humble opinion, there is less cultural acceptance of that in the C++ community. I think this is partly due to C++'s reputation for "being fast" - so its self-fulfilling!

For things like device drivers and some embedded applications you have no choice but to use C/C++ but most developers will not encounter these scenarios.

ContentLicense: CC BY-SA 2.5


问:
Why do we have to use break in switch?
Who decided (and based on what concepts) that switch construction (in many languages) has to use break in each statement?

Why do we have to write something like this:

```<code>switch(a)
{
    case 1:
        result = 'one';
        break;
    case 2:
        result = 'two';
        break;
    default:
        result = 'not determined';
        break;
}
</code>```

(noticed this in PHP and JS; there are probably many other languages using this)

If switch is an alternative of if, why we can't use the same construction as for if? I.e.:

```<code>switch(a)
{
    case 1:
    {
        result = 'one';
    }
    case 2:
    {
        result = 'two';
    }
    default:
    {
        result = 'not determined';
    }
}
</code>```

It is said that break prevents the execution of the block following the current one. But, does someone really run into the situation, where there was any need for execution of the current block and following ones? I didn't. For me, break is always there. In every block. In every code.

答:
I think that with all written above - the main outcome of this thread is that if you are to design a new language - the default should be that you do not need to add a break statement and the compiler will treat it as if you did.

If you want that rare case where you want to continue on to the next case - simply state it with a continue statement.

This can be improved so that only if you use curly brackets inside the case then it doesn't go on so that the example with the months above of several cases performing the same exact code - would always work as expected without needing the continue.

ContentLicense: CC BY-SA 4.0

Title: Why do we have to use break in switch?

ContentLicense: CC BY-SA 3.0


问:
Has "Not everyone can be a programmer" been studied?
An old adage that many programmers stick to is "It takes a certain type of mind to learn programming, and not everyone can do it."

Now I'm sure that we all have our own trove of anecdotal evidence, but has this been studied scientifically?

答:
When I started out it was common to sit an "aptitude test" before you got a programming job. There were not so many computer science graduates, so it was common to recruit from other disciplines.

The tests were similar to what you see on IQ tests (what's the next number in the sequence, etc.).

The anecdotal evidence was that while not everyone who passed the test became a good programmer, no one who failed the test but was hired for other reasons ever became a good programmer.

Sadly HR drones did not understand these tests (and failed when they took them!), so recruitment these days depends on things HR drones understand -- good college, communication and suit wearing skills.

This is pretty much the reason large IT departments have lots of people who are great at PowerPoint shows and very few good programmers.


问:
Does software testing methodology rely on flawed data?
It’s a well-known fact in software engineering that the cost of fixing a bug increases exponentially the later in development that bug is discovered. This is supported by data published in Code Complete and adapted in numerous other publications.

However, it turns out that this data never existed. The data cited by Code Complete apparently does not show such a cost / development time correlation, and similar published tables only showed the correlation in some special cases and a flat curve in others (i.e. no increase in cost).

Is there any independent data to corroborate or refute this?

And if true (i.e. if there simply is no data to support this exponentially higher cost for late discovered bugs), how does this impact software development methodology?

答:
Does software testing methodology rely on flawed data?

Yes, demonstrably. Examining the Agile Cost of Change Curve shows that part of Kent Beck's work on XP (I'm not sure whether it was part of his motivation or his justification) was to "flatten the curve" of defect costs, based on knowledge of the "exponential" curve that lies behind the Code Complete table. So yes, work on at least one methodology - the one that did most to popularise test-first development - is at least in part based on flawed data.

Is there any independent data to corroborate or refute this?

Yes, there certainly is other data you can look to - the largest study I'm aware of is the analysis of defects done at Hughes Aircraft as part of their CMM evaluation program. The report from there shows how defect costs depended with phase for them: though the data in that report don't include variances so you need to be wary of drawing too many "this thing costs more than that thing" conclusions. You should also notice that, independent of methodology, there have been changes in tools and techniques between the 1980s and today that call the relevance of these data into question.

So, assuming that we do still have a problem justifying these numbers:

how does this impact software development methodology?

The fact that we've been relying on numbers that can't be verified didn't stop people making progress based on anecdotes and experience: the same way that many master-apprentice trades are learned. I don't think there was a Journal of Evidence-Based Masonry during the middle ages, but a whole bunch of big, impressive and long-lasting buildings were nonetheless constructed with some observable amount of success. What it means is that we're mainly basing our practice on "what worked for me or the people I've met"; no bad thing, but perhaps not the most efficient way to improve a field of millions of people who provide the cornerstone of the current technological age.

I find it disappointing that in a so-called engineering discipline doesn't have a better foundation in empiricism, and I suspect (though clearly cannot prove) that we'd be able to make better, clearer progress at improving our techniques and methodologies were that foundation in place - just as clinical medicine appears to have been transformed by evidence-based practice. That's based on some big assumptions though:

that the proprietary nature of most software engineering practice does not prevent enough useful and relevant data being gathered;

that conclusions drawn from these data are generally applicable (because software engineering is a skilled profession, personal variances in experience, ability and taste could affect such applicability);

that software engineers "in the field" are able and motivated to make use of the results thus obtained; and

that we actually know what questions we're supposed to be asking in the first place. This is obviously the biggest point here: when we talk about improving software engineering, what is it that we want to improve? What's the measurement? Does improving that measurement actually improve the outcome, or does it game the system? As an example, suppose the management at my company decided we were going to decrease the ratio between actual project cost and predicted project cost. I could just start multiplying all my cost estimates by a fudge factor and I'd achieve that "goal". Should it then become standard industry practice to fudge all estimates?


问:
Software Management Tools for Agile Process Development
We would like to implement the Agile/ Scrum process in our daily software management, so as to provide better progress visibility and feature managements, here are some of the activities that we want to do:

Daily stand-up

Release cycles of 6 weeks with 3 2-week iterations.

Having a product back-log of tasks (integrate with bugzilla) and bugs estimated out.

Printing a daily burn down to make velocity visible. When used as motivator, it's great.

Easy feature development tracking and full blown visibility, especially for the sales and stake holders ( this means that it must be a web based tool).

My team is distributed, so physical whiteboards aren't feasible.

Is there such a web based tool that meets our needs? I heard icescrum may be one, but I've never used it so I don't know.

There are a few more suggestions as here, but I've never heard of them, anyone cares to elaborate or suggest new tools?

答: In our experience, after using several tools, the best one is a whiteboard and sticky notes... maybe several whiteboards and a lot of sticky notes ;)</p>


答:
I really think that Trello can help you here. It's web based, the tag line 'your entire project at a glance' is exactly what you are looking for.

You could hook in your issue tracker, with trello to illustrate tasks, and bugs associated. Daily gains could be shown with trello...

Have a look at this page and perhaps contact a member of staff for ideas, or perhaps give this great article a read.

Title: Software Management Tools for Agile Process Development

Body:
We would like to implement the Agile/ Scrum process in our daily software management, so as to provide better progress visibility and feature managements, here are some of the activities that we want to do:

Daily stand-up

Release cycles of 6 weeks with 3 2-week iterations.

Having a product back-log of tasks (integrate with bugzilla) and bugs estimated out.

Printing a daily burn down to make velocity visible. When used as motivator, it's great.

Easy feature development tracking and full blown visibility, especially for the sales and stake holders ( this means that it must be a web based tool).

My team is distributed, so physical whiteboards aren't feasible.

Is there such a web based tool that meets our needs? I heard icescrum may be one, but I've never used it so I don't know.

There are a few more suggestions as here, but I've never heard of them, anyone cares to elaborate or suggest new tools?


答:
I'll chuck Jira in there with GreenHopper plug in which does white boarding stuff of tasks.
It's $10 for each for a 10 user license. Lots more for more users though.

I have to say though, Cardboard cards and white boards are still the best way.


答:
I'm going to preface this with the fact that most of what I'm finding comes from the 1970s and early 1980s. During this time, sequential process models were far more common than the iterative and/or incremental approaches (the Spiral model or the agile methods). Much of this work is built on these sequential models. However, I don't think that destroys the relationship, but one of the benefits of iterative/incremental approaches is to release features (an entire vertical slice of an application) quickly and correct problems in it before dependencies are injected and complexity of each phase is high.

I just pulled out my copy of Software Engineering Economics and found a reference to the data behind this chart in Chapter 4. He cites "Design and Code Inspections to Reduce Errors in Program Development" by M.E. Fagan (IEEE, PDF from UMD), E.B. Daly's "Management of Software Engineering", W.E. Stephenson's "An Analysis of the Resources Used in Safeguard System Software Development" (ACM), and "several TRW projects".

...the relative cost of correcting software errors (or making other
  software changes) as a function of the phase in which the corrections
  or changes are made. If a software requirements error is detected and
  corrected during the plans and requirements phase, its correction is a
  relatively simple matter of updating the requirements specification.
  If the same error is not corrected until the maintenance phase, the
  correction involves a much larger inventory of specifications, code,
  user and maintenance manuals, and training material.

Further, late corrections involve a much more formal change approval
  and control process, and a much more extensive activity to revalidate
  the correction. These factors combine to make the error typically 100
  times more expensive to correct in the maintenance phase on large
  projects than in the requirements phase.

Bohem also looked at two smaller, less formal projects and found an increase in cost, but far less significant than the 100 times identified in the larger projects. Given the chart, the differences appears to be 4 times greater to fix a requirements defect after the system is operational than in the requirements phase. He attributed this to the smaller inventory of items that comprise the project and the reduced formality that led to the ability to implement simpler fixed faster.

Based on Boehm in Software Engineering Economics, the table in Code Complete is rather bloated (the low end of the ranges is often too high). The cost to make any change within phase is indeed 1. Extrapolating from Figure 4-2 in Software Engineering Economics, a requirements change should be 1.5-2.5 times in architecture, 2.5-10 in coding, 4-20 in testing, and 4-100 in maintenance. The amount depends on the size and complexity of the project as well as formality of the process used.

In Appendix E of Barry Boehm and Richard Turner's Balancing Agility and Discipline contains a small section on the empirical findings regarding the cost of change.

The opening paragraphs cite Kent Beck's Extreme Programming Explained, quoting Beck. It says that if the cost of changes rose slowly over time, decisions would be made as late as possible and only what was needed would be implemented. This is known as the "flat curve" and it is what drives Extreme Programming. However, what previous literature found was the "steep curve", with small systems (<5 KSLOC) having a change of 5:1 and large systems having a change of 100:1.

The section cites the University of Maryland's Center for Empirically Based Software Engineering (sponsored by the National Science Foundation). They performed a search of available literature and found that the results tended to confirm a 100:1 ratio, with some results indicating a range of 70:1 to 125:1. Unfortunately, these were typically "big design up front" projects and managed in a sequential manner.

There are samples of "small commercial Java projects" run using Extreme Programming. For each Story, the amount of effort in error fixing, new design, and refactoring was tracked. The data shows that as the system is developed (more user stories are implemented), the average effort tends to increase in a non-trivial rate. Effort in refactoring increases about 5% and efforts toward effort fixing increases about 4%.

What I'm learning is that system complexity plays a great role in the amount of effort needed. By building vertical slices through the system, you slow down the rate of curve by slowly adding complexity instead of adding it in piles. Rather than dealing with the mass of complexity of requirements followed by an extremely complex architecture, followed by an extremely complex implementation, and so on, you start very simply and add on.

What impact does this have on the cost to fix? In the end, perhaps not much. However, it does have the advantages of allowing for more control over complexity (through the management of technical debt). In addition, the frequent deliverables often associated with agile mean that the project might end sooner - rather than delivering "the system", pieces are delivered until the business needs are satisfied or have changed drastically that a new system (and therefore a new project) is needed.

Stephen Kan's Metrics and Models in Software Quality Engineering has a section in Chapter 6 about the cost effectiveness of phase defect removal.

He starts off by citing Fagan's 1976 paper (also cited in Software Engineering Economics) to state that rework done in high level design (system architecture), low-level design (detailed design), and implementation can be between 10 and 100 times less expensive than work done during component and system level testing.

He also cites two publications, from 1982 and 1984, by Freedman and Weinberg that discuss large systems. The first is "Handbook of Walkthroughs, Inspections, and Technical Reviews" and the second is "Reviews, Walkthroughs, and Inspections". The application of reviews early in the development cycle can reduce the number of errors that reach the testing phases by a factor of 10. This reduction in the number of defects leads to reduced testing costs by 50% to 80%. I would have to read the studies in more detail, but it appears that the cost also includes finding and fixing the defects.

A 1983 study by Remus, "Integrated Software Validation in the View of Inspections/Review", studied the cost of removing defects in different phases, specifically design/code inspections, testing, and maintenance, using data from IBM's Santa Teresa Laboratory in California. The cited results indicate a cost ratio of 1:20:82. That is, a defect found in design or code inspections has a cost-to-change of 1. If the same defect escapes into testing, it will cost 20 times more. If it escapes all the way to a user, it will multiple the cost-to-correct by up to 82. Kan, using sample data from IBM's Rochester, Minnessota facility, found the defect removal cost for the AS/400 project to be similar at 1:13:92. However, he points out that the increase in cost might be due to the increased difficulty to find a defect.

Gilb's 1993 ("Software Inspection") and 1999 ("Optimizing Software Engineering Specification and Quality Control Processes") publications on software inspection are mentioned to corroborate the other studies.

Additional information might be found in Construx's page on Defect Cost Increase, which provides a number of references on the increase in defect-repair cost. It should be noted that Steve McConnell, author of Code Complete, founded and works for Construx.

I recently listened to a talk, Real Software Engineering, given by Glenn Vanderburg at Lone Star Ruby Conference in 2010. He's given the same talk at Scottish Ruby Conference and Erubycon in 2011, QCon San Francisco in 2012, and O'Reilly Software Architecture Conference in 2015. I've only listened to the Lone Star Ruby Conference, but the talk has evolved over time as his ideas were refined.

Venderburg suggests that the all of this historical data is actually showing the cost to fix defects as time progresses, not necessarily as a project moves through phases. Many of the projects examined in the previously mentioned papers and books were sequential "waterfall" projects, where phase and time moved together. However, a similar pattern would emerge in iterative and incremental projects - if a defect was injected in one iteration, it would be relatively inexpensive to fix in that iteration. However, as the iterations progress, lots of things happen - the software becomes more complex, people forget some of the minor details about working in particular modules or parts of the code, requirements change. All of these will increase the cost of fixing the defect.

I think that this is probably closer to reality. In a waterfall project, the cost increases because of the amount of artifacts that need to be corrected due to an upstream problem. In iterative and incremental projects, the cost increases because of an increase in complexity in the software.

Title: Does software testing methodology rely on flawed data?

Body:
It’s a well-known fact in software engineering that the cost of fixing a bug increases exponentially the later in development that bug is discovered. This is supported by data published in Code Complete and adapted in numerous other publications.

However, it turns out that this data never existed. The data cited by Code Complete apparently does not show such a cost / development time correlation, and similar published tables only showed the correlation in some special cases and a flat curve in others (i.e. no increase in cost).

Is there any independent data to corroborate or refute this?

And if true (i.e. if there simply is no data to support this exponentially higher cost for late discovered bugs), how does this impact software development methodology?


问:
Using XML as data storage
I was thinking about the XML format and the following quote:

“XML is not a database. It was never meant to be a database. It is never going to be a database. Relational databases are proven technology with more than 20 years of implementation experience. They are solid, stable, useful products. They are not going away. XML is a very useful technology for moving data between different databases or between databases and other programs. However, it is not itself a database. Don't use it like one.“ -Effective XML: 50 Specific Ways to Improve Your XML by Elliotte Rusty Harold (page 230, Part 4, Item 41, 2nd paragraph)

This seems to really stress that XML should not be used for data storage and should only be used for program to program interoperability.

Personally, I disagree and .NET's app.config file that's used to store a program's settings is an example of data storage in an XML file. However for databases rather than configurations etc XML should not be used.

To develop my point, I will use two examples:

A) Data about customers with fields that are all on one level i.e. there are a number of fields all relating to one customer with no children

B) Data about configuration of an application where nested fields and properties make a lot of sense

So my question is, Is this still a valid statement and is it now acceptable to store data using XML?

EDIT: I've sent an email to the author of that quote to ask for his input/extra context.

答:
The term database can refer to either the raw data only, or the database management system as well.  This definition makes a big difference in the entire argument.

If we use the RDBMS definition, then XML has very little in that sense.  You get very little in terms of ACID guarantees (you'd have to write your own code to accomplish those).  If you need those (and most transactional systems do), you are already in major trouble.  I could give a list of hundreds of features which are taken for granted with RDBMSes, which you'd have to reinvent and reimplement.  Think security models, replication, backups, just to name a few basic ones.

In the above sense, no, XML is not a database, and you shouldn't try to use it as one.

If we use the "raw data" definition, XML fares a lot better, but still not that great.  As others have pointed out though, it is hugely verbose in general, typically lacking binary encoding, and having duplicate tags, etc.  These are trade-offs made so that XML can be human-readable - basically, efficiency is the enemy of this requirement.  XML is also not a particularly good fit for even the simplest situations where you are inserting records continuously.  Assuming you want your XML file to be valid, you need a single closing tag, which means that appending a record means you need to shift up the tags at the end.  This is pretty expensive (how do we know where that tag begins? what if there are multiple "tables", do we just move up the entire file?), and if you want to work around it, you'll reinvent a similar approach to many databases - spreading out tables over multiple files, and dynamically growing those files as needed.

There are situations where XML is appropriate - config files are a great example, because they are typically small and human readability is an excellent feature to have.  Having a database just for a config file may be overkill.

Databases, on the other hand, are excellent when you have thousands (or millions / billions) of records, and have many users concurrently updating them.  So yes, XML is not a database, and you shouldn't use it like one.  Your example happens to be one of those situations where you didn't need a DB in the first place, and XML is the better fit.

The way I see it is this:  if you use XML as a DB (say, as a backing store for a transactional system), you will end up reinventing and rewriting an RDBMS.  That's a really poor way to spend your time and energy.  I think this is what that quote was saying as well.

Title: Using XML as data storage


问:
Estimating time for planning and technical design using Evidence Based Scheduling
I'm at the beginning of a development project in a large organization.

The Functional Requirements are currently being worked out and documented with our business stakeholders by our Enterprise Design department.

I'm required to produce Technical Design Documents and manage the team to actually build the solution.

I'm wanting to try Evidence Based Scheduling, but as I understand, part of that is breaking the job down into small tasks that are less than 14 hours in duration, which requires me to have already done the Technical Design.

Therefore, can Evidence Based Scheduling only be used after the Technical Design has been done?

How do you then plan and estimate the time it may take to come up with the Technical Design?

答:
Therefore, can Evidence Based Scheduling only be used after the Technical Design has been done?

If you don't know what you're going to build, how could you possibly know how long it's going to take?

So yes, you definitely need to have at least a draft of the design, and you need to let the programmers in your team to estimate their parts (as is emphasized in the article you linked to). You also need to have prior experience of comparable projects. Otherwise you don't know the relationship between your team's estimations and the reality. If you don't have prior experience, then you have to wait until you have some evidence to base the calculations on.

Then you'll refine the design as you go on, and the estimate will improve. At any point in time, your schedule will be as good as it possibly can; it's based on evidence, not on guess or hope.

Evidence Based Scheduling, or Story Points & Velocity etc. are just fancy words for a simple linear estimator: if it has taken T amount of time to do X % amount of the job, then there's likely (1-X)*T/X amount of time left - provided that the total amount of work stays constant. This sort of estimator is popular because:

It's extremely simple.

It has been found to work reasonably well in practice.


问:
What is Continous Integration (CI) and how is it useful?
Can some one explain to me the concept of Continious Integration, how it works in an easy to understand way? And why should a company adopt  CI in their code delivery workflow? I am a developer and my company (mainly the build team ) uses Team City. As a developer I always  checkout, update and commit code to SVN but never really had to bother about TeamCity or CI in general. So I  would like to understand what is the usefulness of CI? Is CI a part of Agile methodologies?</p>

答:
Continous Integration in nutshell means that you save your work, you push it to the document management system (SVN in your case), all test are run automatically (both unit, integration, functional, etc. tests) and the application is compiled and prepared for delivery (ie. ISO image is created). Continuous Integration is not the same with Continous Delivery. Delivery is still done in different moments. CI ensures the product could be delivered if needed, nothing more.

Whenever something goes wrong, the team gets a notification. Usually at that point all work is halted and all efforts are concentrated on making sure the product is in a stable way. No pushes and commits happen on the repository while the system is not green.

CI ensures that the product is always in a stable state and potentially can be delivered any time. Please note that stable does not mean feature complete. There may also be half-implemented features, but the system can be stable.

CI is usually associated with Agile methodologies, however I do not personally know the exact history of CI.


答:
You can estimate how long the technical design itself will take using evidence-based scheduling if you correlate the effort for past technical designs with sizes of their corresponding enterprise designs. It would be the same principle applied to different type of work.

There is really no specific limit how well broken down the work has to be. It's just the less you break it down, the less precise the estimate will be. With the enterprise design you can easily be off several times. But the business people often need at least something to know whether it's worth continuing the negotiations and risking the effort for design (if the project turns out too expensive) and correlating past project sizes with sizes of their enterprise designs is the best you can do for them in that case.

Title: Estimating time for planning and technical design using Evidence Based Scheduling

Body:
I'm at the beginning of a development project in a large organization.

The Functional Requirements are currently being worked out and documented with our business stakeholders by our Enterprise Design department.

I'm required to produce Technical Design Documents and manage the team to actually build the solution.

I'm wanting to try Evidence Based Scheduling, but as I understand, part of that is breaking the job down into small tasks that are less than 14 hours in duration, which requires me to have already done the Technical Design.

Therefore, can Evidence Based Scheduling only be used after the Technical Design has been done?

How do you then plan and estimate the time it may take to come up with the Technical Design?


问:
What made object oriented programming successful?
What is that feature according to you that has made object oriented programming so much successful ?

Message Passing

Inheritance

Polymorphism

Encapsulation

Or some other feature that you may like to introduce.

Also I would like to know that what is the connection between Abstract Data type and Object Oriented programming?

答: Graphical user interfaces. In the late eighties, early nineties, when Macs, Amigas, Atari STs, Windows and GEM began to replace character based user interfaces, it became obvious that languages like C are not well-suited to write GUI programs. While traditional data processing is considered as a "input data -> processing -> output data" schema, which could be done in a procedural language just as well, OOs features just came handy to handle the inherent complexity of a GUI.


答:
Continuous integration means: integrating the code into a product that actually runs and can be tested happens all the time, not (as was previously the case) as a separate activity late in the development lifecycle.

It requires the build process of the application to be completely automated, and an automated test suite, and a server that builds the current state of the code and runs the test suite on it. This should happen daily, or even after each code checkin.

The advantage is that there is immediate feedback about code changes that cause compilation errors (e.g. because the developer failed to check in all the changes or uses some component not present in the build system) or test case failures. This makes such errors much easier to fix, as you know which change caused them and the person responsible still has fresh memories of what they did.

Without CI, all these errors emerge together at the same time during the integration stage, which makes them extremely hard to fix.

Title: What is Continous Integration (CI) and how is it useful?

Body: Can some one explain to me the concept of Continious Integration, how it works in an easy to understand way? And why should a company adopt  CI in their code delivery workflow? I am a developer and my company (mainly the build team ) uses Team City. As a developer I always  checkout, update and commit code to SVN but never really had to bother about TeamCity or CI in general. So I  would like to understand what is the usefulness of CI? Is CI a part of Agile methodologies?</p>


问:
Should I use a relational datamodel or Cassandra with ColumnFamily based indexes?
Currently we are working on some storage problems for log data from various servers and communication message logs (HTTP(S), XMPP). There will be many write operations and for read operations we will use search queries with filters.

Should we stick with the classic relation database schema solution or concentrate on Cassandra with ColumnFamily based indexes?

答:
You can stay relational and be NoSQL at the same time, if you can partition data(perhaps by time) with PlayORM/Cassandra so that you can do "scalable JQL" like:

@NoSqlQuery(name="findJoinOnNullPartition", query="PARTITIONS t(:partId) select t FROM TABLE as t INNER JOIN t.security as s where s.securityType = :type and t.numShares = :shares")

It also supports of course the full ManyToOne, OneToMany, etc, but they work slightly different from Hibernate as this is NoSQL after all.


问:
Is my use case diagram correct?
NOTE: I am self studying UML so I have nobody to verify my diagrams and hence I am posting here, so please bear with me. This is the problem I got from some PDF available on Google that simply had the following problem statement:

Problem Statement:

A library contains books and journals. The task is to develop a
computer system for borrowing books. In order to borrow a book
the borrower must be a member of the library. There is a limit on the
number of books that can be borrowed by each member of the library.
The library may have several copies of a given book.
It is possible to reserve a book.
Some books are for short term loans only. Other books may be
borrowed for 3 weeks. Users can extend the loans.

1. Draw a use case diagram for a library.

2. Give a use case description for two use cases:

• Borrow copy of book

• Extend loan

Diagram:

Use case description:

1. Borrow a copy of the book: If the person wishes to borrow a book from Derpville Public Library, he/she must be a member of the library in which case they will be allowed to issue a certain number of books. If the person is not a member, the book will not be issued to them for taking away, rather they will have to sit and read in the library.

2. Extending loan: Some books will be lent for 3 weeks while others will be lent for more than 3 weeks in which case the person borrowing has to come to the library and get the date extended. There is a limit on how much the user can extend the date of a particular book.

答:
first impressions:

I'd say your include arrows are the wrong way round, it's a little odd that Validate membership isn't included in extend return date? and I'd also be tempted to split these into two or three separate diagrams (so we don't have crossing lines).

However, I'd also say that take 'correct uml' with a pinch of salt, if the diagram is useful to you, and to what you want to communicate, then it is doing its job already.

Title: Is my use case diagram correct?


答:
CI is useful, when you have:

Code compilation

Actual set of tests

Reports, that based on you source code(code coverage, violence of code standards, etc..)

Routine that you do periodically, after code compiled successfully

List can be continued..


问:
Deploying a very simple application
I have a very simple working console application written in C++ linked with a light static library. It is just for testing purposes. Now that the coding part is done, I would like to know the process of actually deploying the program. I wrote a very basic CMakeLists.txt that create makefiles or VS projects to build the sources. I also have a program that calls the static library in order to make some google tests.

To me, the deployment of this application goes like this:

to developers : the src directory with the CMakeLists.txt file (multi-platform distribution) with a README.txt and an INSTALL.txt

to users : the executable and a README.txt

git repo : everything mentioned above plus the sources for testing and the gtest external lib

A this point : considering the complexity of my application, am I doing it right?

Is there any reference that would formalize this deployment process so I can get better and go further ? Say I would like to add dynamic libraries that can be updated, external libraries like boost : how should I package this to deploy it in a professional way?

答:
The complexity of your application is not the main factor - your audience is what makes the difference. So this is not really a technical problem, more an organizational one. If you build an application

just for yourself, you obviously have no effort to deploy

for a colleague who wants to use it, working next room to you: you can install it once for him

for some other people in your company: you may write an installation doc, or write some installation scripts

for other developers in your company: just put it into your common source code repo, they can check out the sources by themselves from there (make sure they can easily rebuild the program)

for other developers outside of your company: you may have to make your program cross-platform

for other users world-wide: you may provide a full-blown installer for each target system you have in mind.

Also, the question what to do with "dynamic libraries" can only be answered depending on the audience. Users of your application are typically not interested in what libs you have used, they just want your application to "work", so make sure the library version you have used at development time will be provided with your application (or at least can be easily installed). In contrast, other devs will most probably want to know which lib version to install/use to get your application compiled.

If you want something to read, google for "software deployment book", you will find plenty of literature, mostly system dependent.

Title: Deploying a very simple application


问:
what's the name of this pattern?
I see this a lot in frameworks.

You have a master class which other classes register with.

The master class then decides which of the registered classes to delegate the request to. An example based passed in class may be something this.

```<code>public interface Processor {
  public boolean canHandle(Object objectToHandle);
  public void handle(Object objectToHandle);
}

public class EvenNumberProcessor extends Processor {
  public boolean canHandle(Object objectToHandle) {
     if (!isNumeric(objectToHandle)){
      return false
     }
     return isEven(objectToHandle);
   }

   public void handle(objectToHandle) {
     //Optionally call canHandleAgain to ensure the calling class is fufilling its contract
     doSomething();
   }
 }

public class OddNumberProcessor extends Processor {
  public boolean canHandle(Object objectToHandle) {
     if (!isNumeric(objectToHandle)){
      return false
     }

    return isOdd(objectToHandle);
  }

   public void handle(objectToHandle) {
     //Optionally call canHandleAgain to ensure the calling class is fufilling its contract
     doSomething();
   }
 }

//Can optionally implement processor interface
public class processorDelegator {

  private List processors;
  public void addProcessor(Processor processor) {
    processors.add(processor);
  }

  public void process(Object objectToProcess) {
     //Lookup relevant processor either by keeping a list of what they can process
     //Or query each one to see if it can process the object.

     chosenProcessor=chooseProcessor(objectToProcess);
     chosenProcessor.handle(objectToProcess);
  }

}
</code>```

Note there are a few variations I see on this. In one variation the sub classes provide a list of things they can process which the ProcessorDelegator understands.  The other variation which is listed above in fake code is where each is queried in turn.

This is similar to chain of command but I don't think its the same as chain of command means that the processor needs to pass to other processors.

The other variation is where the ProcessorDelegator itself implements the interface which means you can get trees of ProcessorDelegator which specialise further.  In the above example you could have a numeric processor delegator which delegates to an even/odd processor and a string processordelegator which delegates to different strings.

My question is does this pattern have a name?

答:
The over-all pattern of the code presented here is Strategy because it lets the underlying algorithm vary independently of the clients that use it.  A Chain of Responsibility in the chooseProcessor() method determines which underlying algorithm is used by giving more than one client a chance to handle a request.

If your example focused on the implementation of the chooseProcessor() method, I could see Chain of Responsibility being the dominant pattern, but since only two comments are given and no implementation, your example clearly focuses on the Strategy method.

Title: what's the name of this pattern?


问:
Choosing the right version control system for .NET projects
I'm getting ready for my first "bigger" .NET project (ASP.NET MVC 3/4) on which I'm going to lead another 2 programmers and right now I'm choosing the right version control system for the job (plus I'm gonna use it for my future development too).

My problem is that I did't use any version control system before, so I would like it to have as fast learning curve and intuitive merging as possible.

So far I quickly looked at VisualSVN (I like the Visual Studio integration in it), but I'm reading everywhere how Git is awesome and dunno which one to choose (not limited to these two).. Maybe I'm ovethinking this but I like when everything goes smoothly:)

I'd like to hear some opinions from people who used multiple version control systems (preferably on VS projects) what do you think is the less complicated and effective version control system for such a use (one to 5 man projects)?

答:
We have been using both TFS and git with Visual Studio without any problems

If all you need is a version control system, I would go with git.

It's free

It integrates nicely through a plugin

It's fast

As a DVCS, it allows you to commit even when not connected to any central repository.

If you need a complete ALM solution, go with TFS.

Integrates even better

Also fast

ALM allows you to track your work without the need for any other third party solution.


答:
I won't list the differences between the many source control systems out there. There are literally hundreds of articles online doing just that.

What I will do is give you my experience working with both Git and Mercurial on .NET projects.

Using Git:

Pretty decent integration using some free tools. Installation is a bit of an exercise in wierd-ville, not difficult but strange. It doesn't feel like a part of Windows and forces you to install cygwin and asks you questions that more likely than not are alien for Windows developers.

Using Mercurial:

Installing Mercurial on Windows is really simple and feels like a Windows application. Launch setup and click next next next.

You can use TortoiseHG to install Mercurial and TortoiseHg which is a great utility for working with Mercurial repositories.

There is a tool that integrates with Visual Studio called VisualHg. It gives some fantastic icons right beside each file letting you know that something has changed and is waiting to be committed. It's really lightweight, I've used it on projects with hundreds of files.

You can save a remote repository (and why wouldn't you!) on BitBucket for free. Your project sounds commercial, just save it as private - for free. (for up to five people)

Get up to speed on Mercurial using http://www.hginit.com - Give the website two hours of your time and you'll have enough working knowledge of Mercurial to start working.

Both version control systems are pretty much the same, ultimately I'd go with Mercurial because it has:

Private repository hosting with BitBucket for free.

You'll be able to grasp it easier as it's a bit more straight forward.

You can also find a great table comparing the Big Kahunas of source control on Veracity's official website:

http://veracity-scm.com/

Title: Choosing the right version control system for .NET projects

Body:
I'm getting ready for my first "bigger" .NET project (ASP.NET MVC 3/4) on which I'm going to lead another 2 programmers and right now I'm choosing the right version control system for the job (plus I'm gonna use it for my future development too).

My problem is that I did't use any version control system before, so I would like it to have as fast learning curve and intuitive merging as possible.

So far I quickly looked at VisualSVN (I like the Visual Studio integration in it), but I'm reading everywhere how Git is awesome and dunno which one to choose (not limited to these two).. Maybe I'm ovethinking this but I like when everything goes smoothly:)

I'd like to hear some opinions from people who used multiple version control systems (preferably on VS projects) what do you think is the less complicated and effective version control system for such a use (one to 5 man projects)?


答:
Git has a higher learning curve than SVN, but gives you way more features and is way faster (even small svn repositories can get excruciatingly slow for some features e.g. showing a graph log)

Mercurial is also a viable alternative, its simpler than git, but pretty much as powerful and fast. It also arguably fits better into a windows environment, though git nowadays is much better in this respect

While SVN is simpler I'd also say it takes a bit more discipline to use, i.e. it is simpler because it makes the user do some of the work for it (e.g. merges require more information from user usually, and tags rely on you not committing to as they are really the same as branches)

overall I'd pick Mercurial or Git, with a slight preference for mercurial if you already know python (mercurial can be extended with python hooks) or want a simpler interface. I wouldn't pick svn for myself, and would only really consider it if you already have a large number of developers who are familiar with it.

Expanding on Doc Browns comment; I'd agree VS integration is not really necessary if you are happy with either command line or an explorer shell extension (tortoiseX) however all the major players have VS plugins (personally I tend to avoid these as I find doing everything through tortoise is good enough and I don't like having to many plugins installed as VS can get a bit unstable)


答:
I've been using SourceGear Vault for years and we are very happy with it. Setup and configuration is extremely simple and it just works. Integration with Visual Studio is perfect. Support is very good too.

If you are after the less complicated alternative, SourceGear Vault is definitely much simpler to set up and use than the average DVCS.


问:
How does one handle sensitive data when using Github and Heroku?
I am not yet accustomed with the way Git works (And wonder if someone besides Linus is ;)).

If you use Heroku to host you application, you need to have your code checked in a Git repo. If you work on an open-source project, you are more likely going to share this repo on Github or other Git hosts.

Some things should not be checked in the public repo; database passwords, API keys, certificates, etc...
But these things still need to be part of the Git repo since you use it to push your code to Heroku.

How to work with this use case?

Note: I know that Heroku or PHPFog can use server variables to circumvent this problem. My question is more about how to "hide" parts of the code.

答:
Several ideas...  Public Key Cryptography is the most flexible answer.

Obfuscation (for code only)

For the parts of the code you want to hide, could you put them in a different project, compile them, and check in only the compiled code, not the source?  This is not encryption and not suitable for encrypting passwords or keys.  People can still reverse-engineer your compiled code, but they don't get the source.

Private GIT repository

Does it have to be a public git repository?

Server Storage

Can you store this info in a protected file in the home directory of the user account the application runs under?  I would copy the way ssh does this with ~/.ssh/id_rsa and a chmod of 600.  Failing that, an environment variable could be used.  You need somewhere on the server to store some kind of key, or there is no way you can protect anything.

Symmetric Cryptography (just for you)

If you are the sole developer, you could put a key on the server and have that same key on your machine and use a symmetric encryption scheme to protect some data like a password or certificate.  Sharing a symmetric key with friends gets messy.

Asymmetric Cryptography (for multiple developers)

If other developers need to check secret things into a public git repository, , public-key/private-key (asymmetric) cryptography was made for this kind of thing.  Install a private key on your your server (do not check it into source control!) and generate a public key from it.  Encrypt your secret data using the server's public key.  Only the server can decrypt that data using its private key.  You can even check the public key into source control so that other people can encrypt data using the same public key and only the server can decrypt it.

Tool

Openssl is probably the only cryptography tool you'll ever need.  Do not write your own cryptography algorithm or your own implementation of a published algorithm.

Closing thoughts

If the "server" is a web server that uses https, then you should already have a secure keystore of some kind on the server to store the private key in.  It's kind of mind-blowing that a hosting company wouldn't make allowances for this. Maybe they have some hints on how others solve the challenge you are facing?


问:
Is my sequence diagram correct?
NOTE: I am self studying UML so I have nobody to verify my diagrams and hence I am posting here, so please bear with me. This is the problem I got from some PDF available on Google that simply had the following problem statement:

Problem Statement:
A library contains books and journals. The task is to develop a computer system for borrowing books. In order to borrow a book the borrower must be a member of the library. There is a limit on the number of books that can be borrowed by each member of the library. The library may have several copies of a given book. It is possible to reserve a book. Some books are for short term loans only. Other books may be borrowed for 3 weeks. Users can extend the loans.
Draw a use case diagram for a library.

I already drew the Use Case diagram and had it checked by a community member. This time I drew  sequence diagrams for borrowing a book and extending the date of return.

Please let me know if they are correct.

I drew them using Visual Paradigm and I dont know how to keep a control of the sequence numbers. If you do, please let me know :)

Diagrams

答:
They seem to be correct enough to understand what is going on, which in my opinion is all you need for UML. However if you want to be more technically correct:

Request membership card appears to be a return when it should presumably be a message with provide membership card as a return?

confirm membership may not need to go back to the person, but a request for the book name probably should

Title: Is my sequence diagram correct?


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

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

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

答:
Yes you should start researching CASE tools.

Because you need evidence to back up your assertion that they won't help. You never know, you might find that they will help.

Because your employer told you to.

I won't repeat the points laid out by David Kaczynski in his excellent answer as they are exactly the steps you should follow.


答:
The situation warrants an analytical approach to the decision.  The bottom line will be "Does the CASE tool provide a value to the business?"  Often, management will want developers to adopt a methodology or tool because they have heard good things about it, regardless of how well it fits into the current processes and culture of the organization.

If your employer has asked you to look into CASE tools, as ChrisF points out, you should oblige (this is a workplace issue, not programming).  Some factors that would affect the adoption of a CASE tool include:

For which of your processes are there CASE tools available,

An estimation of how many person-hours would be needed to adopt the new tool(s),

How would the process(es) change with the adoption of the new tool(s),

or What kind of positive (or negative) impact would be measurable from adopting the new tool(s)

Think of this as an opportunity to upgrade your development environment and processes.  It may be that your current processes are a perfect match for your organization's culture, but you owe it to your employer and your team to do the appropriate research.

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

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

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

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


问:
Interfaces on an abstract class
My coworker and I have different opinions on the relationship between base classes and interfaces.  I'm of the belief that a class should not implement an interface unless that class can be used when an implementation of the interface is required.  In other words, I like to see code like this:

```<code>interface IFooWorker { void Work(); }

abstract class BaseWorker {
    ... base class behaviors ...
    public abstract void Work() { }
    protected string CleanData(string data) { ... }
}

class DbWorker : BaseWorker, IFooWorker {
    public void Work() {
        Repository.AddCleanData(base.CleanData(UI.GetDirtyData()));
    }
}
</code>```

The DbWorker is what gets the IFooWorker interface, because it is an instantiatable implementation of the interface.  It completely fulfills the contract.  My coworker prefers the nearly identical:

```<code>interface IFooWorker { void Work(); }

abstract class BaseWorker : IFooWorker {
    ... base class behaviors ...
    public abstract void Work() { }
    protected string CleanData(string data) { ... }
}

class DbWorker : BaseWorker {
    public void Work() {
        Repository.AddCleanData(base.CleanData(UI.GetDirtyData()));
    }
}
</code>```

Where the base class gets the interface, and by virtue of this all inheritors of the base class are of that interface as well.  This bugs me but I can't come up with concrete reasons why, outside of "the base class cannot stand on its own as an implementation of the interface".

What are the pros & cons of his method vs. mine, and why should one be used over another?

答:
I would ask the question, what happens when you change IFooWorker, such as adding a new method?

If BaseWorker implements the interface, by default it will have to declare the new method, even if it's abstract.  On the other hand, if it doesn't implement the interface, you'll only get compile errors on the derived classes.

For that reason, I'd make the base class implement the interface, since I might be able to implement all the functionality for the new method in the base class without touching the derived classes.

Title: Interfaces on an abstract class


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答: I'm from the Philippines. Most people code, document, and name variables in English here. Also, I find English to be one of the most suitable language to use in programming because it has richer vocabulary than most languages out there.</p>


问:
Scrum: How to work on one story at a time
I was nominated as scrum master in a new formed scrum team. We have already done some sprints. In the beginning I tried to make my team to work on one story at a time. But it didn't work.
My team had difficulties to distribute the tasks in a way that they can work simultaneously on one story. Maybe we are doing something wrong?

For example: we have a story to create a new dialog. We create the following tasks:

Create Model classes

Read model data from database

Connect model classes with view

Implement dialog handling

Save data on close

Test Documentation

Solution Description

Can theses tasks be done by more than one person at a time? The tasks - more or less - build upon each other.
Or do we design the tasks in a wrong way?

答:
Why should all the team work on a single story?

Why not make stories small enough (and independent enough) so that one person (or better, one pair doing pair-programming) can work on a single story. This process also helps better define the requirements and think more both about the problem and the implementation. Estimates may also be become more accurate, but no guaranties here.


答: While this depends heavily on the size of the user story, in many cases only one developer should be assigned to a story to avoid having your developers step on each others toes. Though larger or very complex stories may require more developers, but it may also be possible to break those stories into many smaller stories that can be individually assigned.</p>

Title: Scrum: How to work on one story at a time

Body:
I was nominated as scrum master in a new formed scrum team. We have already done some sprints. In the beginning I tried to make my team to work on one story at a time. But it didn't work.
My team had difficulties to distribute the tasks in a way that they can work simultaneously on one story. Maybe we are doing something wrong?

For example: we have a story to create a new dialog. We create the following tasks:

Create Model classes

Read model data from database

Connect model classes with view

Implement dialog handling

Save data on close

Test Documentation

Solution Description

Can theses tasks be done by more than one person at a time? The tasks - more or less - build upon each other.
Or do we design the tasks in a wrong way?


答:
What we generally do is breakdown the stories into dev / infra / analyst subtasks.

Generally anything thats more than a days work is a story.

Once the tasks are broken down, one or max of two developers work on a
story, depending on the no: of tasks at hand. Usually its one.

We log the time spent, and update the remaining estimate at the end
of the day before we leave or before the daily stand up.

Subtasks are created for any new issues that come up while working.

A Story thats more than 2 weeks work is considered as an Epic.

An Epic can be made up of many stories


答:
It seems like a big paradigm shift indeed from Agile to CASE/MDA oriented development with code generation. Not necessarily from a project management point of view (a CASE approach won't conflict with the concepts of iterations, user stories, quick feedback or continuous improvement) but definitely so from a "software craftsmanship" perspective - it means less control over the code produced, generated code that will probably be unreadable, rigid, harder to test, constantly in need of sync with the model, and so on.

From what you describe, what your employer needs is easily understandable :

Better documentation in order to avoid knowledge loss if a developer was to leave the team.

A faster development process.

As a software professional, you definitely can (and should) tell him about your doubts on the CASE approach's ability to match these expectations. It is also your duty to start looking at CASE tools if he demands so. Just trying out one of them doesn't mean 1/ that the results will be satisfying (I'm especially thinking about the potentially big code generation overhead which kind of conflicts with the need to develop faster) and 2/ that you can't find a compromise where some features of the CASE tool (diagrams, documentation generation) will be used while preserving the existing agile context.

Here's an interesting article about CASE tools in an Agile environment and their possible benefits/drawbacks : http://www.agilemodeling.com/essays/simpleTools.htm


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

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

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

答:
It depends.  I'd argue that for long-running processes, Java is about as good a choice as C or C++ is.  Compiled languages get up and running a lot more quickly.  However, in a JITed runtime, the optimizer has better information because it happens at runtime.

Lastly, don't forget about OCaml.  It's a compiled object-oriented language that can run at near-C speeds.


答: One of the benefits you would get out of investigating / implementing CASE tools is that you will have acquired a more marketable skill set for future employment.  I think that many of your concerns are noteworthy, but, as pointed out by David Kaczynski, this is not a programming question so much as it is a employer / employee relationship question.  Another benefit of CASE tools is that once learned, your company will be in a position to take on a wider range of projects of greater complexity.  It may very well be that a contract your employer is looking to get requires, or places preference toward the use of CASE tools.</p>


答:
A big part of SCRUM is that the team should be making these kinds of decisions. The backlog should have the user stories with hopefully enough information for tasks to be generated.

While it may be possible to coerce a user story into an item that the whole team can work on simultaneously, what's more important is that the team picks the items to work on, defines the tasks to finish the user story, and uses the daily stand up to see if you are on track with the promised work.

The pain you are feeling in trying to work on just one story at a time needs to be acknowledged by the team and in sprint retrospective potential solutions needs to be brought up. Figure out what you are doing right and what things need to be improved.

Using your example of the difficulty in distributing tasks that can be worked on simultaneously, one possible solution is to take on multiple stories and delievery 3 or 4 items in a sprint. Since the tasks for this user story build on top of each other it will be difficult to distribute the work. So rather than fight that embrace it.


问:
Code Measuring and Metrics Tools?
I'm in the process of setting up a build server for personal projects.  This server will handle all the normal CI stuff, including running large suites of tests (unit, integration, automated UI).  While I'm working out the kinks for including code coverage output with MSTest, it occurs to me that there may be lots of tools out there which give me additional metrics other than just code coverage.

FxCop comes to mind as an example.  Though I'm sure there are others.  Anything that can generate useful reportable data and metrics would be good.  Whether it's class dependency charts (looking for Law of Demeter violations, for example), analyses of the uses of classes/functions (looking for a function that isn't used in the system other than just the tests, for example), and so on.

I'm not sure the right way to formulate the question, since polling questions or "What's your favorite code analysis tool" aren't very good.  But I'm essentially just looking for recommendations on what metrics to gather and the tools that can gather them.

The eventual vision for something like this is to have the CI server run a bunch of automated tests and analysis tools and track performance metrics over time.  Imagine a dashboard full of graphs plotting these metrics over time.  The lines should all relatively be at an equilibrium, and if one starts to stray toward the negative then it's an early indication of problems with the code.  In the age old struggle to quantify code quality with management, this sounds like a potentially helpful means of doing just that.

答:
My quick suggestions for tools based on what we have running on our CI server that builds our .NET projects.

NCover - code coverage of your unit tests

Microsoft Visual Studio Code Metrics PowerTool

Maintainability Index

Cyclomatic Complexity

Depth of Inheritance

Class Coupling

Lines Of Code (LOC)

Jenkins Task Scanner Plugin - high / medium / low task counts

StatSVN (or similar for your particular SCM)

code growth and churn

who's committing where

A Static Analysis tool (Klocwork, Coverity) - look for SPMs (Silly Programmer Mistakes)

These are the metrics we pay attention to on a daily basis

Unit Test Results

Code Coverage - we want our unit testing to cover 100% of the code

Open Tasks - this helps us track how much work is still left

Code Churn - lots of churn means it's not stable yet and helps predict end-dates

Code Size - if there is a lot of code being added, it's not done yet.

Static Analysis results

The other metrics are used more as indicators of "improvement opportunities" in the code.

For completeness, here are some other tools that have been mentioned.  (We don't currently use them, but they are worth the mention.)

nDepend

Title: Code Measuring and Metrics Tools?


问:
Externalising SQL Queries in Java
What are the advantages and disadvantages of externalising SQL queries in Java (or similar general-purpose object-oriented programming language.  Externalizing means storing all SQL in a separate non-java file or files.  Several good examples are here.

Does it make debugging harder or easier?

答:
I think this becomes more relevant when you have a larger project, and have dedicated 'database developers' who co-incidentally happen to be SQL ninjas too.

Pros:

There is a clean separation of responsibilities. Devs do the coding db developers write the scripts.

If both do a good job and the db design is right, the application will beat all other ORM frameworks hands down in performance.

Cons:

App developers and DB developers wont agree usually (I am the best driver syndrome)

If something goes wrong there will be too much of finger pointing.

I had worked on a project that used this approach, using iBatis - Currently myBatis

OwnerDisplayName: shamis

Title: Externalising SQL Queries in Java


答:
What makes you think it's any kind of pattern at all? Maybe it's just (gosh) some code. So I'mma go with "None".

I mean, fundamentally, what makes a pattern a pattern is that you label it that way and then the other developers need much less additional documentation to understand how it works. But since you haven't given it any name, and I'm not at all sure how on earth it works or what the point is, even after reading the full implementation (for example, the chooseProcessor method, a vital component, appears to be missing). So it appears to me that, in all the ways that count, it's not a pattern.

I mean, if only you could do simply have some kind of type system to distinguish what items each Processor can accept and then you could register those Processors with uh, uh, uh, a compiler, and then it would implement all the logic for you. A man can dream.

Title: what's the name of this pattern?

Body:
I see this a lot in frameworks.

You have a master class which other classes register with.

The master class then decides which of the registered classes to delegate the request to. An example based passed in class may be something this.

```<code>public interface Processor {
  public boolean canHandle(Object objectToHandle);
  public void handle(Object objectToHandle);
}

public class EvenNumberProcessor extends Processor {
  public boolean canHandle(Object objectToHandle) {
     if (!isNumeric(objectToHandle)){
      return false
     }
     return isEven(objectToHandle);
   }

   public void handle(objectToHandle) {
     //Optionally call canHandleAgain to ensure the calling class is fufilling its contract
     doSomething();
   }
 }

public class OddNumberProcessor extends Processor {
  public boolean canHandle(Object objectToHandle) {
     if (!isNumeric(objectToHandle)){
      return false
     }

    return isOdd(objectToHandle);
  }

   public void handle(objectToHandle) {
     //Optionally call canHandleAgain to ensure the calling class is fufilling its contract
     doSomething();
   }
 }

//Can optionally implement processor interface
public class processorDelegator {

  private List processors;
  public void addProcessor(Processor processor) {
    processors.add(processor);
  }

  public void process(Object objectToProcess) {
     //Lookup relevant processor either by keeping a list of what they can process
     //Or query each one to see if it can process the object.

     chosenProcessor=chooseProcessor(objectToProcess);
     chosenProcessor.handle(objectToProcess);
  }

}
</code>```

Note there are a few variations I see on this. In one variation the sub classes provide a list of things they can process which the ProcessorDelegator understands.  The other variation which is listed above in fake code is where each is queried in turn.

This is similar to chain of command but I don't think its the same as chain of command means that the processor needs to pass to other processors.

The other variation is where the ProcessorDelegator itself implements the interface which means you can get trees of ProcessorDelegator which specialise further.  In the above example you could have a numeric processor delegator which delegates to an even/odd processor and a string processordelegator which delegates to different strings.

My question is does this pattern have a name?


问:
Should a programmer take writing lessons to enhance code expressiveness?
Given that programmers are authors and write code to express abstract thoughts and concepts, and good code should be read by other programmers without difficulties and misunderstandings, should a programmer take writing lessons to write better code?

Abstracting concepts and real world problems/entities is an important part of writing good code, and a good mastery of the language used for coding should allow the programmer to express his thoughts more easily, or in a better way. Besides, when trying to write or rewrite some code to make it better, much time can be spent in deciding the names for functions, variables or data structures.

I think this could also help to avoid writing code with more than one meaning, often cause of misunderstanding between different programmers. Code should always express clearly its function unambiguously.

答:
When programming projects fail it's usually due to failed communication, generally around requirements.  Though a mediocre grasp of English may be sufficient to actually write code, being a good communicator is essential for writing the right code.  In this age of remote-working, text-based communication, English writing is a very important communication skill.

That said, your question is written in a very clear and concise manner - better than most programmers I have worked with.  Not having seen your code, I'd suggest you concentrate on expressing yourself in the coding language of your choice.  For Java, I recommend Joshua Bloch's book, "Effective Java."


问:
Questions to ask before someone leaves
Apart from the obvious questions relating to specific project work someone is working on are there any questions I should be asking a fellow dev who is leaving the company?

So far I am thinking about;

Locations of things on the server he uses that not maybe everyone does.

Credentials he has set up that we wouldn't have needed.

Client details he has not yet saved into our CRM system.

答: Has he checked in everything to source control! Very annoying to find out after his old machine has been reformatted that the last three months of work he did wasn't checked in and no one else has it.</p>

Title: Questions to ask before someone leaves


答:
Just to add to @JVXR Answer, another major benefit is the ability to support multiple DB Engines. For Example, You can easily swap out SQL Sever TSQL for Oracle Pl-Sql.

This is particularly useful if you are selling packaged software, you can allow the client to  use what ever DB they already own and can support with no additional cost.

Title: Externalising SQL Queries in Java

Body:
What are the advantages and disadvantages of externalising SQL queries in Java (or similar general-purpose object-oriented programming language.  Externalizing means storing all SQL in a separate non-java file or files.  Several good examples are here.

Does it make debugging harder or easier?


问:
Improving performance for grepping over a huge file
I have FILE_A which has over 300,000 lines and FILE_B which has over 30 million lines. I created a Bash script that greps each line in FILE_A over in FILE_B and writes the result of the grep to a new file.

This whole process is taking over 5 hours.

How can I improve the performance of my script?

I'm using grep -F -m 1 as the grep command. FILE_A looks like this:

```<code>123456789
123455321
</code>```

and FILE_B is like this:

```<code>123456789,123456789,730025400149993,
123455321,123455321,730025400126097,
</code>```

So with Bash I have a while loop that picks the next line in FILE_A and greps it over in FILE_B. When the pattern is found in FILE_B, I write it to file result.txt.

```<code>while read -r line; do
   grep -F -m1 $line 30MFile
done < 300KFile
</code>```

答:
Here is a Perl answer for posterity. I routinely do this for matching 1M lines to 30-35M lines. It takes around 10 seconds to finish.

First, hash up FILE_A:

```<code>my %simple_hash;
open my $first_file, '<', 'FILE_A' or die "What have you done?! $!";
while (<$first_file>) {
  chomp;                 ## Watch out for Windows newlines
  $simple_hash{$_} = 1;  ## There may be an even faster way to define this
}
close $first_file;
</code>```

Then, if your big file is delimited and know what column to go after, check for just the existence of the hash key as you run down FILE_B, which is much, much faster than checking for equality or regular expression matching:

```<code>open my $second_file, '<', 'FILE_B' or die "Oh no, not again.. $!";
while (<$second_file>) {
  my ($col1, undef) = split ',';
  if (exists($simple_hash{$col1}) {
    print $_;
  }
}
close $second_file;
</code>```

If your larger target file isn't nicely parse-able, then this script loses its value as so much of its speed comes from not having to fire up the regular expression engine.

Body:
Here is a Perl answer for posterity. I routinely do this for matching 1M lines to 30-35M lines. It takes around 10 seconds to finish.

First, hash up FILE_A:

my %simple_hash;
open my $first_file, '<', 'FILE_A' or die "What have you done?! $!";
while (<$first_file>) {
  chomp;                 ## Watch out for Windows newlines
  $simple_hash{$_} = 1;  ## There may be an even faster way to define this
}
close $first_file;

Then, if your big file is delimited and know what column to go after, check for just the existence of the hash key as you run down FILE_B, which is much, much faster than checking for equality or regular expression matching:

open my $second_file, '<', 'FILE_B' or die "Oh no, not again.. $!";
while (<$second_file>) {
  my ($col1, undef) = split ',';
  if (exists($simple_hash{$col1}) {
    print $_;
  }
}
close $second_file;

If your larger target file isn't nicely parse-able, then this script loses its value as so much of its speed comes from not having to fire up the regular expression engine.


问:
Best Method of function parameter validation
I've been dabbling with the idea of creating my own CMS for the experience and because it would be fun to run my website off my own code base.

One of the decisions I keep coming back to is how best to validate incoming parameters for functions.

This is mostly in reference to simple data types since object validation would be quite a bit more complex.

At first I debated creating a naming convention that would contain information about what the parameters should be, (int, string, bool, etc) then I also figured I could create options to validate against.  But then in every function I still need to run some sort of parameter validation that parses the parameter name to determine what the value can be then validate against it, granted this would be handled by passing the list of parameters to function but that still needs to happen and one of my goals is to remove the parameter validation from the function itself so that you can only have the actual function code that accomplishes the intended task without the additional code for validation.

Is there any good way of handling this, or is it so low level that typically parameter validation is just done at the start of the function call anyway, so I should stick with doing that.

答:
Based on the comment "one of my goals is to remove the parameter validation from the function itself so that you can only have the actual function code that accomplishes the intended task without the additional code for validation", you may want to look at using AOP for method validation. Hopefully the technologies you are using can support that paradigm.

In this case, your validator would be an aspect and would not pollute the business logic of your function. This should add the benefit of making your validation logic readily reusable and will help support unit testing.


答:
I think you could use design by contract in the sense that the code of your CMS is not doing much of a validation, trusting to the input of the external layer. The external layer though should be strict, maybe even a bit paranoid about the input.

By external layer I mean the extension points of your cms e.g. the controller class that gets extended, the objects that accept extension through strategies or visitor etc. Of course, as already noted, you may use AOP (it is now available in PHP with getDocComment-like "hacks")

Of course this may be a little of over-engineering, but that is what I would do.

Title: Best Method of function parameter validation

Body:
I've been dabbling with the idea of creating my own CMS for the experience and because it would be fun to run my website off my own code base.

One of the decisions I keep coming back to is how best to validate incoming parameters for functions.

This is mostly in reference to simple data types since object validation would be quite a bit more complex.

At first I debated creating a naming convention that would contain information about what the parameters should be, (int, string, bool, etc) then I also figured I could create options to validate against.  But then in every function I still need to run some sort of parameter validation that parses the parameter name to determine what the value can be then validate against it, granted this would be handled by passing the list of parameters to function but that still needs to happen and one of my goals is to remove the parameter validation from the function itself so that you can only have the actual function code that accomplishes the intended task without the additional code for validation.

Is there any good way of handling this, or is it so low level that typically parameter validation is just done at the start of the function call anyway, so I should stick with doing that.


问:
Get system info from C program?
I'm writing a little program in C that I want to use to output some system stats to my HD44780 16x2 character display. The system I'll be working with is a Debian ARM system and, although irrelevant, the display is on the GPIO header.(The system is a Raspberry Pi).

As an initial (somewhat unambitious) attempt, I'd like to start with something simple like RAM and CPU usage (I'm new to C).

I understand that if I make external command calls I need to fork() and execve() (or some equiv that will let me return the results), what I would like to know is how I go about getting the information I want in a nice clean format that I can use.

Surely I will not have to call (for e.g);

```<code>free -h
</code>```

And then use awk or similar to chop out the piece I want? There must be a cleaner way?

The question should be seen as more of a generic, what is best practice for getting info about the system in C (the RAM/CPU usage are just an initial example).

答:
Information about the state of the system is beyond the scope of the C language specification, so anything you do will be specific to the system where your program will run.

Since you've identified a target environment (Linux) and a program that provides some of the information you're after (free(1)), your best bet would be to acquire and examine the source for that program, learn how it works and use what you've learned in your own program.  (This would certainly be much better than spawning copies of the utility and picking the output apart.)

Title: Get system info from C program?


答:
The general solutions to this problem are type safety (so that values are valid by construction) and encapsulation (so that values cannot be invalidated after construction). If your inputs and outputs have meaningful types, then the constructors of those types can enforce the properties you want. If validation is centralised, you don’t have to repeat it.

Let’s talk in pseudocode for a moment. As a contrived example, consider a function area(w, h) that computes the area of a rectangle. If you type the function as:

```<code>int area(int w, int h)
</code>```

Then there is no guarantee that any of the invariants hold:

w and h are lengths

Being lengths, they must be non-negative

The result is an area

To enforce input constraints, you can always add validation to the function body:

```<code>int area(int w, int h) {
    assert(w >= 0);
    assert(h >= 0);
    return w * h;
}
</code>```

Not only is this cumbersome, but it remains the responsibility of the caller to validate the result. If we use types that represent our units:

```<code>Area area(Length w, Length h) {
    return w * h;
}
</code>```

Then nobody can give us a Volume when we expected a Length, and since a length cannot be negative, we don’t need to check for that.

PHP doesn’t enforce types statically, but you can prevent the construction of invalid objects by throwing exceptions from constructors that receive invalid inputs, and using immutable objects or accessors to prevent later invalidation.

Body:
The general solutions to this problem are type safety (so that values are valid by construction) and encapsulation (so that values cannot be invalidated after construction). If your inputs and outputs have meaningful types, then the constructors of those types can enforce the properties you want. If validation is centralised, you don’t have to repeat it.

Let’s talk in pseudocode for a moment. As a contrived example, consider a function area(w, h) that computes the area of a rectangle. If you type the function as:

int area(int w, int h)

Then there is no guarantee that any of the invariants hold:

w and h are lengths

Being lengths, they must be non-negative

The result is an area

To enforce input constraints, you can always add validation to the function body:

int area(int w, int h) {
    assert(w >= 0);
    assert(h >= 0);
    return w * h;
}

Not only is this cumbersome, but it remains the responsibility of the caller to validate the result. If we use types that represent our units:

Area area(Length w, Length h) {
    return w * h;
}

Then nobody can give us a Volume when we expected a Length, and since a length cannot be negative, we don’t need to check for that.

PHP doesn’t enforce types statically, but you can prevent the construction of invalid objects by throwing exceptions from constructors that receive invalid inputs, and using immutable objects or accessors to prevent later invalidation.


问:
Critique of the IO monad being viewed as a state monad operating on the world
The IO monad in Haskell is often explained as a state monad where the state is the world. So a value of type IO a monad is viewed as something like worldState -> (a, worldState).

Some time ago I read an article (or a blog/mailing list post) that criticized this view and gave several reasons why it's not correct. But I cannot remember neither the article nor the reasons. Anybody knows?

Edit: The article seems lost, so let's start gathering various arguments here.
I'm starting a bounty to make things more interesting.

Edit: The article I was looking for is Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell by Simon Peyton Jones. (Thanks to TacTics's answer.)

答:
The problem with IO a = worldState -> (a, worldState) is that if this were true then we could prove that forever (putStrLn "Hello") :: IO a and undefined :: IO a are equal.  Here is the proof courtesy of dolio (2010, irc):

```<code>forever m
 =
m >> forever m
 =
fix (\r -> m >> r)
 = {definition of >> for worldState -> (a, worldState)}
fix (\r -> \w -> r (snd $ m w))
</code>```

Lemma: (\r w -> r (snd $ m w)) ⊥ = ⊥

```<code>(\r w -> r (snd $ m w)) ⊥
  =
\w -> ⊥ (snd $ m w))
  =
⊥ . snd . m
  =
⊥
</code>```

Therefore forever m = fix (\r -> \w -> r (snd $ m w)) = ⊥

In particular forever (putStrLn "Hello") = ⊥ and hence forever (putStrLn "Hello") and undefined are equivalent programs.  However, clearly they are not supposed to be considered equivalent programs, in theory or in practice.

Notice that this model is wrong even without invoking concurrency.

Body:
The problem with IO a = worldState -> (a, worldState) is that if this were true then we could prove that forever (putStrLn "Hello") :: IO a and undefined :: IO a are equal.  Here is the proof courtesy of dolio (2010, irc):

forever m
 =
m >> forever m
 =
fix (\r -> m >> r)
 = {definition of >> for worldState -> (a, worldState)}
fix (\r -> \w -> r (snd $ m w))

Lemma: (\r w -> r (snd $ m w)) ⊥ = ⊥

(\r w -> r (snd $ m w)) ⊥
  =
\w -> ⊥ (snd $ m w))
  =
⊥ . snd . m
  =
⊥

Therefore forever m = fix (\r -> \w -> r (snd $ m w)) = ⊥

In particular forever (putStrLn "Hello") = ⊥ and hence forever (putStrLn "Hello") and undefined are equivalent programs.  However, clearly they are not supposed to be considered equivalent programs, in theory or in practice.

Notice that this model is wrong even without invoking concurrency.


答:
Well... I would create a validator class. All input from the user would go through that. If validation fails, code returns.

Now, you could use a single Validator interface and create different validation rules or use just one Validator object which know all the validation rules you need.

Than, when you are sure that a 'telephone number' is really a 'number' and not a characters, than you call the function which has that as parameter.

Functions / methods should usually not check for parameter validity, however, in some situations you will still need to check a few things. If something goes wrong with a function, it should throw and exception.

So, you filter out user input as close to the user as possible and than you throw exceptions for unforeseen cases as deep as possible in your logic.

UPDATE: Also, you may consider for implementation the Observer Design Pattern, or maybe a Mediator if needed.