问:
Teaching Programming Concepts Without a Specific Language
I'm teaming up with a guy who has no programming experience. We're using a tool to make our game (RPG Maker) that has an event-based system that allows you to do pretty much everything you want. They have a GUI and a simple text editor for events.

My friend has no programming experience. None. I need him to understand basic stuff, like control flow (if/else, do/while), variables/constants, etc. What can I use to teach him this, bearing in mind that I don't care about specific language syntax?

Ideally, I'm looking for a "programming" book that talks about these ideas (perhaps visually) and doesn't care much about code. Does something like this exist? My "google-fu" failed me.

答: Try Karel the Robot, available on the web and in book form. That's not quite right, actually -- the web page is just a sort of user manual for the language. The book explains the ideas. Get the book, then use the web page to help with the tools.


答: You could use flow-charts (maybe process and sequence diagrams too) or pseudo-code to get started, but eventually you will have to move to Real Code. I think what you are trying to do would be akin to teaching someone to play the violin with only sheet music and no actual instrument. The problem-solving aspect of progamming may not require a specific programming language, but solution implementation sure does.</p>

ContentLicense: CC BY-SA 3.0

Title: Teaching Programming Concepts Without a Specific Language

Body:
I'm teaming up with a guy who has no programming experience. We're using a tool to make our game (RPG Maker) that has an event-based system that allows you to do pretty much everything you want. They have a GUI and a simple text editor for events.

My friend has no programming experience. None. I need him to understand basic stuff, like control flow (if/else, do/while), variables/constants, etc. What can I use to teach him this, bearing in mind that I don't care about specific language syntax?

Ideally, I'm looking for a "programming" book that talks about these ideas (perhaps visually) and doesn't care much about code. Does something like this exist? My "google-fu" failed me.


答: One of the "Learn X the Hard Way" books might be a good way to go. In particular Learn Ruby the Hard Way is an interesting one.  It gives tutorials that your friend can follow and learn some programming and just use one of the interactive Ruby terminals to work the tutorials. He will have also learned a useful language when he is done.</p>


问:
Create Tickets From TODO (or otherwise annotated) comments
Is there any software that will allow me to generate trouble tickets (for Trac, Team Foundation Server, etc.) from TODO or otherwise annotated comments in the source code?</p>

答:
For Trac, there is a plugin called 'codetags' which provides a summary of encoded/tagged source comments without creating an actual ticket for each item.

http://trac-hacks.org/wiki/CodeTagsPlugin

Perhaps with some adaption or further extension, this plugin could help you create a ticket, or a batch of tickets based on tagged comments.


答:
That's kind of like teaching math without all those nasty symbols and numbers, since he doesn't need to care about the difference between roman numerals and arabic. Part of the concept is wrapped up in the implementation, either a pseudo language or a real one.

Luckily, you have a language available to you. Show him the concepts and walk him through what is happening in that. Not only does he learn the idea, but also the implementation he will need to use.

Also, since these ideas apply across languages, have him work through something like A Byte of Python. It goes over these concepts, and has a REPL for easy experimenting. Then, as noted in my comment, show him those concepts in your current language, to connect the two.


问:
Choosing names for integration tests
With unit tests the domain is quite small, so it's easy. I used Osherove's methodName_conditions_result() scheme and found it very clear.

But with integration tests I feel like it would make a very long name, and what do I put in place of methodName? How do I name integration test classes?

Real world examples of integration test names are very welcome. I hope the answers will also help me to better understand these tests.

答:
Integration tests should follow some similar rules to unit tests in that each test should be testing one aspect of a requirement but tests the system as a whole. The class should name the overall thing that is being tested, e.g. "TpcInputValidation" and the naming of the method should reflect expressively what the test is trying to do without being overly wordy, e.g. "shouldRaiseValidationErrorWithBadDates()".

The methods should be testing one concept of the feature and a large number of asserts could indicate otherwise.  (Ref. "Clean Code: A Handbook of Agile Software Craftmanship" p. 132, by Robert Martin).

Title: Choosing names for integration tests


问:
Why does adding more people to a late project make it later?
It's a fairly common adage that adding more programmers to a late project will make matters worse. Why is this?</p>

答:
Introduction overhead

Each new developer has to be introduced to the code base and development process which takes not only the new person's time but also requires assistance from [a] senior developer[s] (guiding them through the build process, explain the testing process, help them with pitfalls in the code base, much more detailed code reviews, etc).

Therefore, the more new developers you add to the project the more time has to be spent to bring them to a point where they can actually contribute to the project.

ContentLicense: CC BY-SA 4.0

ContentLicense: CC BY-SA 2.5


问:
Provide a URL to a CouchDB document attachment without giving the username/password?
I posted this question on DBA, but it got closed and was never reopened even after I rewrote the whole thing to be more specific. I think its more appropriate for programmers anyway :)

Background Information

I have a CouchDB server (Server B) that is accessed by another server running PHP (Server A). My web app (Client-side Javascript) makes a request for a file to Server A. Server A sends requests to Server B with the access credentials (username:password). Server B returns JSON objects that correspond to matched files, then Server A returns that data to the client. The response includes some meta data about the file and a URL to the file on Server B. The actual file data itself is not included in the response.

The Problem

The URL to the document attachment included in the JSON response from Server B includes access credentials (username:password). Server A responds to the client-side request by returning those JSON objects.

The client now has this information:

```<code>https://username:password@host:port/dbname/path/to/file.whatever
</code>```

Currently all data contained within Server B resides in one database instance. If the client has access to the username:password to the CouchDB then all data could be queried with those access credentials. Like so,

```<code>https://username:password@host:port/dbname/_all_docs
</code>```

Server-side considerations

CouchDB on Cloudant

Client-side considerations

The Javascript running on the client requires a URL string to the file. The files that are being referenced are KML layers for Google Maps. A new KML layer is created using this constructor.

What I am looking for

Essentially my solution would come if I can provide a link to a CouchDB document attachment without giving the username/password.

```<code>https://host:port/path/to/file.whatever
</code>```

What I did

I had to enable cURL for PHP on Server A.

```<code>sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
sudo /etc/init.d/apache2 restart
</code>```

Got a bit of code from David Walsh's blog.

My Javascript client code gets a list of JSON file meta data from Server A. This data includes unique DB IDs and file names (No passwords or API keys). I then pass the document ID and filename to another service on Server A which echoes the value of,

```<code>get_data('https://username:password@Server B:port/dbname/path/to/file.whatever');
</code>```

I can now serve out the files to the client without revealing username or password for CouchDB on Server B.

答:
It sounds like you want the documents the end user to receive to be served up directly from the database server.  In general, thats a bad idea.  Particularly if this is a public facing application.  Better to insolate the database they way you have it now.  Is there a particular reason you feel that the db needs to directly hand the client the document?

I would keep everything in your middleware application, and have that handle the document delivery.  Or if you must, create a separate server application that only handles the document transfer between the client and db.  The client would request a document URL, and your app server would fetch it from the db and return it to the client for them.


问:
Programming languages, positional languages and natural languages
Some programming languages are modeled on machine code, like assembly languages. Other languages are modeled on a natural language, the English language. Others are not modeled on either machine code or natural language. Languages such as PROLOG, for example, don't follow either model.

I came across this Perl module Lingua::Romana::Perligata, that allows to write programs using a syntax that is very similar to Latin.

Are there programming languages that have less positional syntax?

Are there other languages or modules that allow you to write in syntaxes inspired by other natural languages, like French, Hebrew or Farsi? There is a very long list on Wikipedia, but most of those projects are dead.

There is a related question on StackOverflow. The answer that was accepted is "Use Google".

答:
Oracle Policy Automation has business rules coded in natural language.  It is worth a look.

An example is:

```<code>Human Resources Policy 100 – Maternity Leave

100.1. The employee is eligible for maternity leave if

a. The employee is female and
b. Either
 i. The employee has given birth to a natural child or
 ii. The employee has taken legal custody of an adopted child
 and
c. The employee is a full time employee and
d. The employee has been employed for at least 12 months continuously
</code>```

The original source of the example.

The official Oracle documentation is here.

Body:
Oracle Policy Automation has business rules coded in natural language.  It is worth a look.

An example is:

Human Resources Policy 100 – Maternity Leave

100.1. The employee is eligible for maternity leave if

a. The employee is female and
b. Either
 i. The employee has given birth to a natural child or
 ii. The employee has taken legal custody of an adopted child
 and
c. The employee is a full time employee and
d. The employee has been employed for at least 12 months continuously

The original source of the example.

The official Oracle documentation is here.


问:
What is the use of Spring's init-method and destroy-method?
While learning Spring framework, I found that Spring framework provides init-method and destroy-methods which can be used to initialize some properties or to do housekeeping stuff.

We can do all those things in the bean's constructor so why do Spring provides these things and in the real world what is the actual use of these two things?

答:
When you use setter-based dependency injection, the init-method makes it possible to perform initialization: the specified method will be called after all the setters have been called.

As per destroy-method, it seems that implementing finalize in Java classes is not a good practice, instead, and many libraries define a close method which may or may not be called from finalize. See this discussion:
https://stackoverflow.com/questions/158174/why-would-you-ever-implement-finalize

EDIT (to clarify things even further)

In setter-based injection methods will be called in the following order:

default constructor

the setters corresponding to each <property> of the bean

the init-method, if specified

In constructor-based injection methods will be called in the following order:

the matching constructor

the init-method, if specified


答:
When I was a kid I was teamed up with other kids and given the task of instructing a Martian how to make a PBJ sandwich.  The Martian knew English but not any of the assumptions one takes for granted in normal conversation.  The teacher played the part of the Martian and we had to eat the result.

Some teams forgot to specify assembly so they just got a couple pieces of bread, one with PB the other with J.

Some teams forgot to specify which side of the bread to attach so they got things like inside-out sandwiches and sandwiches with PB on inside and J on out.

One team got very, very close but then said, "...and press them together."  That one made a mess.

It was supposed to be a lesson on cultural norms but it speaks quite directly to programming as well.


问:
Design: Calling back to the parent class
When modelling an object with children it's common to include the children via composition, as a member of the parent class. Sometimes however the children need to tell the parent something, they need to call a function of the parent. How can this be accomplished using C++? Some options are:

Make the parent class global therefore the child objects will be able to call member functions of the parent object.

Inject the parent object as a, pointer or reference, into every child object. Then when the child needs to tell the parent object something, it can always do so because it has a member variable that it can use.

What are other methods of doing this? Is there a general design pattern or name for this sort of thing?

Note that I'm interested in ideas and solutions in C++ because the details are going to be different in other object-oriented languages. For example point 2 above mentions 'pointers or references' and both are only possible in C++. C++ has language features that are not present in other languages therefore implementations of a solution to the problem will potentially incorporate these language features making the solution different from what someone might come up with in another language.

答:
As others have pointed out, the basic idea of injecting the parent object as a pointer or reference is the way to go - in principle.

This has one drawback: you get a cyclic dependency between the parent and the child. If you want to avoid that, define an abstract base class (an interface) IParent from which your parent inherits. IParent should contain the methods as virtual functions the child wants to call. Then, inject the parent as a reference to IParent. This makes unit testing the child a lot easier, since now you can replace the parent object easily by a mock object.

If your child needs to call just one function of your parent object, a complete IParent class may be oversized. In this case, it will be enough to inject a pointer to the member function into the child, or a functor object encapsulating that member function.


问:
GIS-based data visualization and maintenance tool

Background

Looking to leverage an existing GIS system for exploring organizational data.

Architecture

The following figure represents a high-level overview of the system's desired features:

The most basic usage would be as follows:

The user visits a web site.

The system presents a map (having regions, cities, and buildings).

The user drills-down on the map to a particular building.

The system provides a basic CRUD interface.

The user can view and modify information about personnel (e.g., their assigned teams), equipment (e.g., network appliances), applications, and the building itself (e.g., contact and phone numbers).

Ideally, all the components should be open-source (or otherwise free).

Problem

This must be a small project that needs a quick (but functional) prototype, mostly to confirm whether or not such a system would be useful in the long term.

Questions

What software components would you use to quickly develop a working prototype?

What open-source solutions already exist, if any?

Ideas

Here is what I am thinking:

PostGIS - Define the regions, cities, and sites

Google Maps - Display an interactive, clickable map

geoJSON - Protocol between PostGIS and Google Maps

Seam - CRUD interface

Custom Development

For example, this would entail:

Installation and configuration

Configure SSH for remote logins

Subversion (or git)

PostgreSQL

PostGIS

Java

Tomcat

Seam

JasperReports

Enter GIS information into PostGIS

Aggregate data sources into PostgreSQL database

Develop starting page for map interface

Develop clickable Google Maps interface

Develop summary reports

Develop CRUD interface using Seam for data maintenance

Surely something like this already exists?

Thank you!

答:
Interesting, Im developing a similar system for oil & gas, with Google Maps API v3. We chose to use CouchDB for the part of your diagram that includes GIS data, central repository, and other data sources. The idea behind this is one container to hold disparate sources of data with different types of structure, and also actual data files that represent GIS layers, logs, tickets, etc.

Also the capability of being able to host actual applications directly from the DB server is helpful for processing/uploading data.

Ultimately for our system which was faced with the prospect of bringing together old + messy + unorganized data, This NoSQL + Schema-less setup has made working with different types of data a pleasure.


答:
Here are some thoughts on this issue ...

Need to use current resources to bring the new resources up to speed on what's going on with the project.

New resource might not be familiar with the code base, thus required more time to get acclimated to the code.

now, adding new resources for testing might not be a bad idea ... it might speed up the testing process (if your test cases are well written), and yes using testing tools will help too.

Title: Why does adding more people to a late project make it later?

Body: It's a fairly common adage that adding more programmers to a late project will make matters worse. Why is this?</p>


问:
What is the purpose of whitelisting in Phonegap? Is there a way around it?
I am using the new phonegap 1.5.0 (which is confusingly renamed cordova despite no mention of the rename on the phonegap site), and I'm finding that the white-listing feature on iOS is quite restrictive. I understand that having a whitelist is more secure in that it only allows trusted domains, but what if you want to load urls that have been loaded dynamically? You don't know exactly which domain will be loading, so you can't put it on the whitelist. An example use-case would be ad-serving and opening privacy policies.

Why is the whitelist mandatory, and is there a way around it?

答:
What is the purpose of whitelisting in Phonegap?

As you guessed, it's a security measure. Specifically, it's meant to prevent cross-site scripting attacks as detailed on the Security page of the PhoneGap wiki.

Why is the whitelist mandatory, and is there a way around it?

The question linked by Robert Harvey in the comments explains how to get around it. In short, add an entry to the whitelist with the value * to allow access to any URL. (Think thrice before doing that, though -- make sure you understand the danger that the whitelist is there to mitigate.)


问:
Is it bad coding practice to create something in a get if it does not exist?
So I have a webservice that has something like a getAccount where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account if an exception is thrown with the same info the get is done with.

I am creating a convenience library for clients that will be handling all of the webservice calls inside so they don't need to know how to do the calls themselves.

What I am wondering is in this library if I were to create a getAccount(accountName) that will get the account if it exists, and if it does not then create it and return the info, is that a bad thing to do? Should I leave it to the client to handle the exceptions or simply name it something like getOrCreateAccount? Does it matter?

Is it bad practice to create something in a get operation?

答:
Yes, it matters. In my opinion, it's a generally a bad practice to create something in a procedure that is not documented as having the powers of creation. Either name the procedure getOrCreate... or have a separate create... procedure and then if you really want, have a getOrCreate... that first attempts get..., and if that fails, calls create... and then calls get....

The user of the library will probably not expect the get... procedure to create if the get operation fails. If they suddenly find out that their test calls to get... created a whole tonne of data, they will probably be rather surprised. And how do they clean it up? What if they write code thinking that they will get an error if get... fails and they want to handle that their way?


问:
Using WCF as an API for Database access by the GUI, or no?
Originally I asked this question on Stackoverflow but I was suggested to move the question here.

I've asked this question a while ago in MSDN forums but I'd like a second opinion from StackOverflow since I tried this route and found some CONS, but I'd like to hear more opinions as well.

Scenario:

I have a windows service program, extracting data from files and inserting the extracted data into a MS SQL database. There is a GUI program which does some filtering and calculations and displays the SQL data in realtime. So the GUI basically displays selective records from the database at any moment. It should be also possible for the GUI to insert and update records based on rules. Also The data fetched from the Database can be huge and it would be also nice to allow remote access to the data by the GUI (not critical)

So my question in more details:

1 - should I create a WCF service in my Service program which provides some API to the GUI to access and update records?

PROS:

I can change the backend database and wouldn't need to update the GUI
app.

The GUI would be sql free.

allow the GUI to directly access the Database and fetch and update
itself.

2 - allow the GUI to directly access the Database and fetch and update itself.
PROS:

security already in place faster than option 1 easier to implement

changed in records can trigger data change rather than polling for
   new data for real time display.

The GUI can access data remotly if SQL database access is setup to be accessable
remotely (a possible security risk?)

here is the original question: http://social.msdn.microsoft.com/Forums/pl-PL/architecturegeneral/thread/8ef537c5-9a79-42b5-a6a0-f7278d3f506e

答:
I generally go for the option of having a good service layer between any two dependencies unless it is not possible. I am a big believer in TDD, and it is a lot easier to test anything you can mock or fake out to better control the behavior for which you want to test. Trying to mock up SQL Server isn't as easy as mocking a service. Additionally, GUIs are notoriously hard to test with any kind of consistency as they are usually changing and are sometimes very non-deterministic (multiple events causing multiple outcomes, etc.). With a service, you have the ability to set up a mocked service that implements the interface/contract.
If done right, you can then take your time developing the GUI and writing tests for it prior to having to work out the database schema and windows service.
I would also look at maybe having the windows service update the database through a service layer of some sort as well. It doesn't have to be a "web" service per se. In some ways, I've had luck with these kinds of things being done through a message bus. We used TIBCO's EMS, but you could easily use any JMS implementation and a .NET connector. The advantage of this kind of setup is that you could write your file data to a queue, have a service that takes the data from the queue and updates the database AND notifies your client(s) GUI to refresh their data. A variant of this setup could be that the service actually sends the data to the clients via this topic saving you the added bandwidth of having multiple clients (if you have them) from having to hit the database with a query on every update.</p>


答: No, it is not 'bad practice'.  So long as you and the other developers agree thats how you want it to work, its just fine.  After all, it'd be returning an account, which is what you want.  That the account is created 'under the hood' is irrelevant to the caller. </p>

Title: Is it bad coding practice to create something in a get if it does not exist?

Body:
So I have a webservice that has something like a getAccount where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account if an exception is thrown with the same info the get is done with.

I am creating a convenience library for clients that will be handling all of the webservice calls inside so they don't need to know how to do the calls themselves.

What I am wondering is in this library if I were to create a getAccount(accountName) that will get the account if it exists, and if it does not then create it and return the info, is that a bad thing to do? Should I leave it to the client to handle the exceptions or simply name it something like getOrCreateAccount? Does it matter?

Is it bad practice to create something in a get operation?


问:
Proper & Efficient Structure for an entity layer?

Context

Web application based on the .NET Framework written in C# and following the MVC design pattern.

Question

What is the most efficient way to structure an entity layer consisting on various data inputs?

Background

I am developing an application for a client that requires my reading and writing data from various sources and I would like to build a single entity layer/model to abstract the various data sources so that I only need to query the unified model from code.  Here is an example of the disparate sources:

MS SQL Data Warehouse (about 200 tables of enterprise-wide data

MS Dynamics AX web services

A new MS SQL database that is specific to the application being developed

MS Active Directory for authenticating users and for getting user profile and group information.

In some cases, SharePoint web services.

I have used ADO.NET a good bit (.edmx files and so forth) and fundamentally, I know how to do this but I am struggling a bit with a solid, clean approach.  Do I create two separate .edmx files for the two SQL DBs and then write object classes for the Active Directory, SharePoint and AX stuff?  Do I simply write one big model file?  A whole separarate project just to make the abstraction?

Many thanks!

答:
It sounds like you are trying to model a set of disparate data sources as a single model.

If that is indeed the case, my opinion is that creating a project to make the abstraction is the way to go.

I say that because you are dealing with different TYPES of sources.  For example, if you just had two databases you could put a link between them, and abstract that way.

But, you have a data warehouse, a few web services, and Active Directory to deal with.  I don't know if there would be one way to consolidate across all of those, and even if there were, it could be messy.

Putting the abstraction in a separate project also ensures that you only have to change ONE place when your entities change.   It also ensures that you hide the details of what is going on behind the scenes from your front end. This can be important, particularly when you have to add something else (not if - with that many sources something else will surely come along later).


问:
Agile estimation with tech-debt
When estimating (story points) a story that consists on extending a current functionality with a known tech-debt, should we consider the effort that will be spent to refactor the current code or should we estimate independently of this tech-debt?</p>

答:
In agile if you can do it with out the change then you should not make the change as part of the story.  So in that case you would not include the points for the tech debt.

You score the fastest way you can properly complete the story.  If taking on the tech debt will speed up the story ie tech debt + story = less time than doing the story with out the tech debt then absolutely you should choose the route that includes the tech debt.  But if the story is 3 with out tech debt but 5 with the tech debt then you choose the 3.  You could still choose to go the route of clearing the tech debt but it will have an impact on your velocity.

Title: Agile estimation with tech-debt


问:
What's the difference between Entry Level/Jr/Sr developers?
Other than title and pay, what is the difference?

What different responsibilities do they have.

How knowledgeable/experienced are they?

What is the basic measure to determine where a developer fits into this basic structure?

答:
This will vary but this is how I see it at a place large enough to have distinctions between types of programmers.

I would say entry level and Junior are the same thing. They are just out of school and have less than two years of work experience. They are assigned the least complex tasks and should be supervised fairly closely. Generally they know about 10% of what they think they know. Usually they have not been through the whole development cycle and so often make some very naive choices if given the opportunity to choose. Sadly many of them don't actually care what the requirement is, they want to build things their way. They often have poor debugging skills.

Intermediate level is where many programmers fall. They have more than two years experience and generally less than ten, although some can stay at this level their whole careers. They can produce working code with less supervision as long as they are assigned to relatively routine tasks. They are not generally tasked with high level design or highly complicated tasks that require an in-depth level of knowledge. They may be tasked with the design of a piece of the application though, especially as they are in the zone to become a senior developer.  They are good at maintenance tasks or tasks where they can focus on just their piece of the puzzle, but are not usually expected to consider the application as a whole unless working with senior developers or being prepped for promotion to senior. They can usually do a decent job of troubleshooting and debugging, but they have to really slog through to get the hard ones. They do not yet have enough experience to see the patterns in the problems that point them to the probable place they are occurring. But they are gaining those skills and rarely need to ask for debugging help. They have probably been through the whole development cycle at least once and seen the results of design problems and are learning how to avoid them in the future. Usually they tend to be more likely to take a requirement at face value and not push it back when it has obvious problems or gaps.  They have learned enough to know what they don't know and are starting to gain that knowledge. They are the workhorses of the programming world, they deliver probably 80-90% of the routine code and maybe 10% of the very difficult stuff.

No one who is senior level even needs to ask this question. They are experts in their chosen technology stacks. They are given the hard tasks (the ones nobody knows how to solve) and often get design responsibilties. They often work independently because they have a proven track record of delivering the goods. They are expected to mentor Junior and intermediate developers. Often they are amazing troubleshooters. They have run into those same problems before and have a very good idea of where to look first. Seniors often mentor outside the workplace as well. They generally have at least ten years of experience and have almost always been on at least one death march and know exactly why some things are to be avoided. They know how to deliver a working product and meet a deadline. They know what corners can be cut and what corners should never be cut. They know at least one and often several languages at the expert level. They have seen a lot of "hot new technologies" hit the workplace and disappear, so they tend to be a bit more conservative about jumping on the bandwagon for the next exciting new development tool (but not completely resistant to change - those would be the older Intermediate developers who never make the leap to Senior). They understand their job is to deliver working software that does what the users want, not to play with fun tools. They are often pickier about where they will work because they can be and because they have seen first hand how bad some places can be. They seek out the places that have the most interesting tasks to do. Often they know more about their company's products than anyone else even if they have been there only a few months. They know they need more than programming knowledge and are good at getting knowledge about the business domain they support as well. They are often aware of issues that juniors never consider and intermediates often don't think about such as regulatory and legal issues in the business domain they support. They can and will push back a requirement because they know what the problems with it will be and can explain the same to the laymen.


答:
I don't think you'll be able to do what you want without opening up all the CouchDB documents to all-comers.

The solution is, I believe, to only send back to the client this portion of the returned document URL:

dbname/path/to/file.whatever

And then keep your client talking with Server A:

https://Server A/get_document/dbname/path/to/file.whatever

Server A then just translates this to the return form Server B:

https://username:password@host:port/dbname/path/to/file.whatever

That way the client never needs to know about Server B, and Server B can be locked down away from prying eyes.

Title: Provide a URL to a CouchDB document attachment without giving the username/password?

Body:
I posted this question on DBA, but it got closed and was never reopened even after I rewrote the whole thing to be more specific. I think its more appropriate for programmers anyway :)

Background Information

I have a CouchDB server (Server B) that is accessed by another server running PHP (Server A). My web app (Client-side Javascript) makes a request for a file to Server A. Server A sends requests to Server B with the access credentials (username:password). Server B returns JSON objects that correspond to matched files, then Server A returns that data to the client. The response includes some meta data about the file and a URL to the file on Server B. The actual file data itself is not included in the response.

The Problem

The URL to the document attachment included in the JSON response from Server B includes access credentials (username:password). Server A responds to the client-side request by returning those JSON objects.

The client now has this information:

```<code>https://username:password@host:port/dbname/path/to/file.whatever
</code>```

Currently all data contained within Server B resides in one database instance. If the client has access to the username:password to the CouchDB then all data could be queried with those access credentials. Like so,

```<code>https://username:password@host:port/dbname/_all_docs
</code>```

Server-side considerations

CouchDB on Cloudant

Client-side considerations

The Javascript running on the client requires a URL string to the file. The files that are being referenced are KML layers for Google Maps. A new KML layer is created using this constructor.

What I am looking for

Essentially my solution would come if I can provide a link to a CouchDB document attachment without giving the username/password.

```<code>https://host:port/path/to/file.whatever
</code>```

What I did

I had to enable cURL for PHP on Server A.

```<code>sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
sudo /etc/init.d/apache2 restart
</code>```

Got a bit of code from David Walsh's blog.

My Javascript client code gets a list of JSON file meta data from Server A. This data includes unique DB IDs and file names (No passwords or API keys). I then pass the document ID and filename to another service on Server A which echoes the value of,

```<code>get_data('https://username:password@Server B:port/dbname/path/to/file.whatever');
</code>```

I can now serve out the files to the client without revealing username or password for CouchDB on Server B.


答:
I take a little different approach with unit and integration tests. I try naming them based on features as much as possible. Then when all the tests pass you can see a list of all the features that work and don't work.

canRegisterUser

canHandleInvalidInput

canRelayDocumentBetweenServers

canCreateSchema

canLoginUsingWebService

canLoginUsingBasicAuth

canDeleteDocument

canAddDocument

It is not always pragmatic to name the tests this way, but it can be very helpful especially after reading through hundreds of unit and integration tests. The over all encompassing Class name that holds these methods should also be indicative of the features being tested. It will help with organization.

I'd also suggest naming any unit tests for bugfixes with a unique prefix such as bugfix1002 to prove that the bug has been fixed.

Title: Choosing names for integration tests

Body:
With unit tests the domain is quite small, so it's easy. I used Osherove's methodName_conditions_result() scheme and found it very clear.

But with integration tests I feel like it would make a very long name, and what do I put in place of methodName? How do I name integration test classes?

Real world examples of integration test names are very welcome. I hope the answers will also help me to better understand these tests.


问:
Why do large IT projects tend to fail or have big cost/schedule overruns?
I always read about large scale transformation or integration project that are total or almost total disaster. Even if they somehow manage to succeed  the cost and schedule blow out is enormous. What is the real reason behind large projects being more prone to failure. Can agile be used in these sort of projects or traditional approach is still the best.

One example from Australia is the Queensland Payroll project where they changed test success criteria to deliver the project.

See some more failed projects in this SO question (on Wayback Machine)

Have you got any personal experience to share?

答:
One reason for failures is that a big project is usually a high-profile, important-to-the business project. When projects and tasks are high-profile, it encourages people to lie.

Your boss wants you to estimate your completion status on the high side. He wants to estimate overruns and delays on the low side. When you encounter a problem, he doesn't want to hear that it will add three weeks to the task; he wants to hear you can work it into a couple of hours tonight.

And so on and so forth.

I was on one project several years ago, for a client. I was brought in after the bid and project plan were completed. There was constant pressure to go faster, faster, and ridiculous cost cutting decisions, heavy overloading of staff, no resources for them; no desks, computers, anything.

Finally, I discovered the project was bid at 7 months and 16 million dollars. I estimated on the back of an envelope it should be 24 months and 50 to 100 million. I set up a meeting with my manager and his manager, and presented my case, and how we were NOT coming anywhere near delivering on time or budget; they downplayed all the problems. At the end of the meeting the CIO called and told both these managers essentially what I said, with the exception of the flaw in the original bid.

I had a chance to roll off the project when they changed technologies to one I wasn't skilled at. I spoke with someone much later. The project ended up being cancelled when it was about half done...at 12 months and 35 million dollars.

High profile big projects discourage people saying, "this is a mistake". Mistakes aren't tolerated.


问:
Web API design best practices - having many (similar) operations
I have a web service (axis2) and the server performs 4 primary operations: createX, removeX, getX and updateX

Where X is represented by a combination of 4 values: id1, id2, id3 and id4

So, to simplify developer life, we created 3 extra helper functions:

removeXForId, getXForId and updateXForId where we represent the set of 4 values as 1 Identifier so that the developers who are calling us do not need to pass all those 4 values again and again and just store the unique identifier on their end.

But, we cannot also completely remove removeX, getX and updateX operations completely abd just rely on the unique identifier as some use cases need to pass all 4 set of values.

So, now we have around 7 operations where half (3) of them are duplicate operations with different input values.

Operations:

```<code>/createX
/getX {input: id1, id2, id3, id4}
/getXForId {input: id1234}
/removeX
/removeXForId
/updateX
/updateXForId
</code>```

Is this a good practice?

UPDATE:

getX is exactly the same as getXForId in terms of behavior except the input arguments.

getX takes in 4 inputs: val1, val2, val3 and val4. But getXForId takes in just 1 ID which represents (val1, val2, val3 and val4)

val1, val2, val3 and val4 are some how related to each other, they in combination represent a unique link to a product in our system. So we tried to club them together.

答:
It would make more sense to me to organize the API around resources and use the verbs (GET, PUT, POST, DELETE) that come with the http protocol, in short: Make it more RESTful, that is surely considered good practice.

This is a good succinct talk on API design that also analyzes popular APIs such as facebook's or twitter's.

I am lost on the difference between your /getX and /getXForId so I can't really give you an example of how I would change your API.

Edit

I tried to model the API in Sinatra. It is pretty self explanatory and straight forward. (I saw you are using axis but it's been a while since I did serious Java). If you are serious about RESTful then you probably want to drop the approach with the four ids. However the approach works:

require "sinatra"
require "sinatra/reloader"

def all_ids_given?(ids_given, ids_needed)
  ids_needed.reduce(true){|memo, id| memo &= ids_given.include? id}
end

#Your old /getXForId
get '/X/:combined_id' do |id|
  "Getting X with combined id #{id}\r\n"
end

#Your old /createX
post '/X' do
  post_params = request.body.read
  "Creating a new X with #{post_params} \r\n"
end

#Your old /updateXForId
put '/X/:combined_id' do |id|
  put_params = request.body.read
  "Updating X with combined id #{id}: New values are #{put_params}\r\n"
end

#Your old /removeXForId
delete '/X/:combined_id' do |id|
  "Deleting X with combined id #{id}\r\n"
end

#Your old /getX
get '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    "Getting X with the ids #{params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Your old /updateX
put '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    put_params = request.body.read
    "Updating X with the ids #{params}: New values are #{put_params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Your old /removeX
delete '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    "Deleting X with combined id #{params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Extensibility
get '/X/:combined_id/Y' do |id|
  "Getting all Ys for the X with combined id #{id}\r\n"
end
```

<p>Testing the API with curl:</p>

<pre class="lang-sh prettyprint-override"><code>base_url="http://localhost:4567/"

echo "Getting a X with a combined id"
echo -n "-> "; curl ${base_url}X/id1234
echo "Creating a new X with a list of properties"
echo -n "-> "; curl --data "property_1=test"  ${base_url}X
echo "Updating an existing X with a combined id"
echo -n "-> "; curl -X PUT --data "property_1=test&property_2=another_test"  ${base_url}X/id1234
echo "Deleting an existing X with a combined id"
echo -n "-> "; curl -X DELETE ${base_url}X/id1234

echo "Getting a X with 4 ids"
echo -n "-> "; curl ${base_url}"X?id1=1&id2=2&id3=3&id4=4"
echo "Getting a X with 4 ids, but supplying only 3"
echo -n "-> "; curl ${base_url}"X?id1=1&id3=3&id4=4"
echo "Updating a X with 4 ids"
echo -n "-> "; curl -X PUT --data "property_1=test&property_2=another_test"  ${base_url}"X?id1=1&id2=2&id3=3&id4=4"
echo "Updating a X with 4 ids"
echo -n "-> "; curl -X DELETE ${base_url}"X?id1=1&id2=2&id3=3&id4=4"

echo "\r\nTesting the extensibility"
echo "Getting all Ys for a single X (Unrelated example: /post/2/comments would give all comments to a single post with the id 2)"
echo -n "-> "; curl ${base_url}X/id1234/Y
echo "This won't work for the 4 ids"
echo -n "-> "; curl ${base_url}"X?id1=1&id2=2&id3=3&id4=4/Y"
</code>```

The script returns the following:

```<code>Getting a X with a combined id
-> Getting X with combined id id1234
Creating a new X with a list of properties
-> Creating a new X with property_1=test
Updating an existing X with a combined id
-> Updating X with combined id id1234: New values are property_1=test&property_2=another_test
Deleting an existing X with a combined id
-> Deleting X with combined id id1234
Getting a X with 4 ids
-> Getting X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4"}
Getting a X with 4 ids, but supplying only 3
-> Error: Need arguments for id1, id2, id3 and id4
Updating a X with 4 ids
-> Updating X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4", "property_1"=>"test", "property_2"=>"another_test"}: New values are property_1=test&property_2=another_test
Updating a X with 4 ids
-> Deleting X with combined id {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4"}

Testing the extensibility
Getting all Ys for a single X (Unrelated example: /post/2/comments would give all comments to a single post with the id 2)
-> Getting all Ys for the X with combined id id1234
This won't work for the 4 ids
-> Getting X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4/Y"}
</code>```

What you can see is that nesting resources and the four parameter approach does not work well together. Maybe one could model it differently and do something like /X/:id1/:id2/:id3/:id4.

Body:
It would make more sense to me to organize the API around resources and use the verbs (GET, PUT, POST, DELETE) that come with the http protocol, in short: Make it more RESTful, that is surely considered good practice.

This is a good succinct talk on API design that also analyzes popular APIs such as facebook's or twitter's.

I am lost on the difference between your /getX and /getXForId so I can't really give you an example of how I would change your API.

Edit

I tried to model the API in Sinatra. It is pretty self explanatory and straight forward. (I saw you are using axis but it's been a while since I did serious Java). If you are serious about RESTful then you probably want to drop the approach with the four ids. However the approach works:

require "sinatra"
require "sinatra/reloader"

def all_ids_given?(ids_given, ids_needed)
  ids_needed.reduce(true){|memo, id| memo &= ids_given.include? id}
end

#Your old /getXForId
get '/X/:combined_id' do |id|
  "Getting X with combined id #{id}\r\n"
end

#Your old /createX
post '/X' do
  post_params = request.body.read
  "Creating a new X with #{post_params} \r\n"
end

#Your old /updateXForId
put '/X/:combined_id' do |id|
  put_params = request.body.read
  "Updating X with combined id #{id}: New values are #{put_params}\r\n"
end

#Your old /removeXForId
delete '/X/:combined_id' do |id|
  "Deleting X with combined id #{id}\r\n"
end

#Your old /getX
get '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    "Getting X with the ids #{params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Your old /updateX
put '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    put_params = request.body.read
    "Updating X with the ids #{params}: New values are #{put_params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Your old /removeX
delete '/X' do
  if all_ids_given?(params.keys, ["id1","id2","id3","id4"])
    "Deleting X with combined id #{params}\r\n"
  else
    "Error: Need arguments for id1, id2, id3 and id4\r\n"
  end
end

#Extensibility
get '/X/:combined_id/Y' do |id|
  "Getting all Ys for the X with combined id #{id}\r\n"
end

Testing the API with curl:

base_url="http://localhost:4567/"

echo "Getting a X with a combined id"
echo -n "-> "; curl ${base_url}X/id1234
echo "Creating a new X with a list of properties"
echo -n "-> "; curl --data "property_1=test"  ${base_url}X
echo "Updating an existing X with a combined id"
echo -n "-> "; curl -X PUT --data "property_1=test&property_2=another_test"  ${base_url}X/id1234
echo "Deleting an existing X with a combined id"
echo -n "-> "; curl -X DELETE ${base_url}X/id1234

echo "Getting a X with 4 ids"
echo -n "-> "; curl ${base_url}"X?id1=1&id2=2&id3=3&id4=4"
echo "Getting a X with 4 ids, but supplying only 3"
echo -n "-> "; curl ${base_url}"X?id1=1&id3=3&id4=4"
echo "Updating a X with 4 ids"
echo -n "-> "; curl -X PUT --data "property_1=test&property_2=another_test"  ${base_url}"X?id1=1&id2=2&id3=3&id4=4"
echo "Updating a X with 4 ids"
echo -n "-> "; curl -X DELETE ${base_url}"X?id1=1&id2=2&id3=3&id4=4"

echo "\r\nTesting the extensibility"
echo "Getting all Ys for a single X (Unrelated example: /post/2/comments would give all comments to a single post with the id 2)"
echo -n "-> "; curl ${base_url}X/id1234/Y
echo "This won't work for the 4 ids"
echo -n "-> "; curl ${base_url}"X?id1=1&id2=2&id3=3&id4=4/Y"

The script returns the following:

Getting a X with a combined id
-> Getting X with combined id id1234
Creating a new X with a list of properties
-> Creating a new X with property_1=test
Updating an existing X with a combined id
-> Updating X with combined id id1234: New values are property_1=test&property_2=another_test
Deleting an existing X with a combined id
-> Deleting X with combined id id1234
Getting a X with 4 ids
-> Getting X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4"}
Getting a X with 4 ids, but supplying only 3
-> Error: Need arguments for id1, id2, id3 and id4
Updating a X with 4 ids
-> Updating X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4", "property_1"=>"test", "property_2"=>"another_test"}: New values are property_1=test&property_2=another_test
Updating a X with 4 ids
-> Deleting X with combined id {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4"}

Testing the extensibility
Getting all Ys for a single X (Unrelated example: /post/2/comments would give all comments to a single post with the id 2)
-> Getting all Ys for the X with combined id id1234
This won't work for the 4 ids
-> Getting X with the ids {"id1"=>"1", "id2"=>"2", "id3"=>"3", "id4"=>"4/Y"}

What you can see is that nesting resources and the four parameter approach does not work well together. Maybe one could model it differently and do something like /X/:id1/:id2/:id3/:id4.


答:
Because programming is not basic production line work. Getting up to speed on a software project takes time. New people need to ask lots of questions which leads to negative productivity (ie New person learning, old person teaching them -> no actual work getting done).

To simplify it, imagine a relatively simple one-man project which is scheduled to go for 1 week: on Thursday, you realise that it won't get done on time, that it would take the one programmer more like 6-7 days instead of 5. If you add another programmer at that point, they'll need to workn with programmer1 for at least a few hour or a day or so, ask lots of questions to get up to speed, etc. You probably won't get any net positive productivity for the rest of the week. The new programmer is likely to introduce some extra bugs too (since they won't know the existing code as well as programmer1), so that'll blow out the implementation and testing cycle by another day or two more. The project will easily last a full two working weeks instead of the original one! - And most likely longer than if the first programmer was simply given a couple of extra days to finish it themselves.


问:
Should we avoid object creation in Java?
I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible.

This seems somewhat to defeat the purpose of object oriented programming. If we aren't creating objects then we are just writing one long class C style, for optimization?

答:
There's more to creating a class than allocating memory.
There's also initialization, I'm not sure why that part is not covered by all the answers.
Normal classes contain some variables, and do some form of initialization, and that isn't free.  Depending on what the class is, it may read files, or do any other number of slow operations.

So just consider what the class constructor does, before figuring if it's free or not.


答:
This was really written to help with unit tests, but perhaps you will find that the same rules apply (more or less) to integration tests:

Check out Seven Steps!

My preference is that whatever you call it, it's really the test suite name (fixture name on our card), the effect you're checking, and the assertion message that need to stand out and make the cause of the error clear. If you find that's easiest with Asherove's naming, then I wholeheartedly endorse that. But maybe the trick is you fill in the "method" part with whatever makes the condition, result, and exception make sense.

I'm happy to see a suite named "MakingADeposit" with a test called "AccountDoesntExist" and an error that says "Expected NonesuchAccount exception - none received."

Alternatively if you don't mind me separating the test suite name with "::", I'm okay with "AccountHandling::MakingADeposit_AccountDoesntExist_ThrowsAnException"

The card also suggests that if you don't have a good name, continue onward and give a better name when one occurs to you (hopefully well before submitting the code to CI).

Title: Choosing names for integration tests


答:
Things I've Seen In Web Development:

Too many cooks - Major B&M Retailer where the emphasis suddenly shifted to the web. Suddenly 20 Department heads are dogpiling every initiative to impress the new head cheese. I once had to implement new icons because legal didn't like the look of the old ones.

Excess focus on matching specs over achieving goals - "IE6's icons are slightly faded compared to IE7's. Please drop that launch-date-critical work you're doing and attend to .05% of our customer base to do awful things that will take days to implement and slow down the IE experience even more."

Bad Tools picked by non-devs who couldn't even be bothered to ask their in-house devs for advice.

Bad devs picked by tools - "Why pay 20 competent Java devs a decent salary when we can outsource 200 barely code literate guys who know too little to use version control?" as they simultaneously and with people in different countries, work on the back-ends primarily for 3 large apps.

Bad/Broken Architecture - Layers upon layers of panicked, get-it-done-yesterday code, by people who were fired or are now managers.

Title: Why do large IT projects tend to fail or have big cost/schedule overruns?

Body:
I always read about large scale transformation or integration project that are total or almost total disaster. Even if they somehow manage to succeed  the cost and schedule blow out is enormous. What is the real reason behind large projects being more prone to failure. Can agile be used in these sort of projects or traditional approach is still the best.

One example from Australia is the Queensland Payroll project where they changed test success criteria to deliver the project.

See some more failed projects in this SO question (on Wayback Machine)

Have you got any personal experience to share?


问:
How do you use JavaScript?
I'm not a professional programmer, but having a PhD in an engineering field, I've taught myself many programming languages over the years. The past few years I've been using primarily Ruby, and now I'm trying to learn JavaScript so I can do a bit of web programming.

I guess like a lot of people, I had a mostly negative impression of JavaScript going in, but as I'm studying the language (through the book JavaScript: The Good Parts by Crockford), I find that the functional part of the language is really neat. I dabbled in Haskell a few years ago, so I had some idea about functional programming.

I'm wondering how professional programmers tend to use the language. Do you stick to one paradigm when writing in JavaScript, or do you use it like a swiss army knife, and used different paradigms for different problems? Is there a "most popular" way to use it these days, or does it simply depend on the programmer, problem, company, etc.?

答: I use a good JavaScript framework, such as jQuery or Prototype. It should change your negative impression of JavaScript in general. It has come a long way over the years and it's definitely worth another look.</p>

Title: How do you use JavaScript?


答:
I would say years ago, JavaScript was for making things flash on the screen, and for making cool mouse trailers (to the general developers of the time), and for teaching patience to developers..

Then Ajax gained popularity, which allowed for Javascript to deal with Data. Javascript was a real pain because it was so rudimentary back then and when we had tools like Visual Studio which provides great intellisense for the .NET languages, when compared to Javascript which had little to none, it was a pretty awful experience honestly.. most of my peers hated javascript back then..

Then came jQuery... I told my boss a couple years ago we better learn JavaScript (me C#, him VB), because jQuery took all the work out of JavaScript and gave us some really cool functionality.

Now we have things like Node.js, which is all JavaScript, both client and server.. I'm not going to get into that.. and i'm not sure how i feel about that.. but it's definately a full materialization of JavaScript on the Web anyways..

I remember hearing about Enyo and WebOS, which was pretty much JavaScript, and Windows 8 is pretty JavaScript friendly as mentioned..

And I almost forgot to mention JSON.. JSON is a cool way for passing data around.. again, nice to work with on the client side, and DB's like Mongo seem to like the technology a lot as well

So for Usage you ask?? I would say it is like a swiss army knife.. some can say HTML with JavaScript is all you need when paired with a good webservice layer(s).. I think there's definately still room for a strong platform base (asp.net, and others..) but to each his own

IMO, I think it has it's place on the client end of things.. it's great for making UI updates.. great for making "Partial" post backs, and accessing a local data store (on the client).. and now with HTML 5, I really do see it being the "Flash Killer".. we'll probably start seeing intro's again with a skip button.. lol.. those were the cool days..

For single page applications and applications like that.. it should definitely be considered with one of the frameworks out there like backbone or one of the others (there's a tone).. Security is something to keep in mind, as well as latency.. but that will all vary in importance based on the project at hand..

So really i would say it's a mix of preference and the application at hand.

Title: How do you use JavaScript?

Body:
I'm not a professional programmer, but having a PhD in an engineering field, I've taught myself many programming languages over the years. The past few years I've been using primarily Ruby, and now I'm trying to learn JavaScript so I can do a bit of web programming.

I guess like a lot of people, I had a mostly negative impression of JavaScript going in, but as I'm studying the language (through the book JavaScript: The Good Parts by Crockford), I find that the functional part of the language is really neat. I dabbled in Haskell a few years ago, so I had some idea about functional programming.

I'm wondering how professional programmers tend to use the language. Do you stick to one paradigm when writing in JavaScript, or do you use it like a swiss army knife, and used different paradigms for different problems? Is there a "most popular" way to use it these days, or does it simply depend on the programmer, problem, company, etc.?


答:
What problem does your "combined identifier" operations solve, anyway? You say it is because you don't want to send all of the identifiers separately, yet I imagine you have to send them all regardless of which operation you use. So, unless there is some other problem the "extra" operations are solving, the simple answer is to just not have them.

If you really do want these "extra" operations because it makes the client easier to implement, you could always implement them in the client code and use them when you need them. For example, you could have a function that parses the combined identifier, and then you can use it whenever you need to make an API call. This way the API stays clean and the extra operations are scoped properly.

Title: Web API design best practices - having many (similar) operations

Body:
I have a web service (axis2) and the server performs 4 primary operations: createX, removeX, getX and updateX

Where X is represented by a combination of 4 values: id1, id2, id3 and id4

So, to simplify developer life, we created 3 extra helper functions:

removeXForId, getXForId and updateXForId where we represent the set of 4 values as 1 Identifier so that the developers who are calling us do not need to pass all those 4 values again and again and just store the unique identifier on their end.

But, we cannot also completely remove removeX, getX and updateX operations completely abd just rely on the unique identifier as some use cases need to pass all 4 set of values.

So, now we have around 7 operations where half (3) of them are duplicate operations with different input values.

Operations:

```<code>/createX
/getX {input: id1, id2, id3, id4}
/getXForId {input: id1234}
/removeX
/removeXForId
/updateX
/updateXForId
</code>```

Is this a good practice?

UPDATE:

getX is exactly the same as getXForId in terms of behavior except the input arguments.

getX takes in 4 inputs: val1, val2, val3 and val4. But getXForId takes in just 1 ID which represents (val1, val2, val3 and val4)

val1, val2, val3 and val4 are some how related to each other, they in combination represent a unique link to a product in our system. So we tried to club them together.


问:
What should I consider when deciding if I should use a web service backend instead of traditional MVC?
We're trying to decide what architecture to use for an upcoming web application that will eventually have a mobile portion as well. The core of the project is a social networking web application, and the mobile portion will most likely have a limited subset of the web functionality.

The two options we are looking at is either a complete web service back end, or using a traditional MVC framework for the web application and then developing web services on the side for the mobile application later.

Some arguments for web-service-only route is that it would be "simpler", as we would just have to create 1 web service as opposed to creating both a web service for the mobile portion, and additional database functions/calls for the web application. Using this method, the web application will fetch data from the web services using javascript, which would then generate the html page (sounds kind of like what a traditional MVC framework does, but this way would require everything to be done in javascript).

I'm not feeling good about the idea of using web services only because it doesn't make sense to me, but I am having trouble clarifying my issues with it.

So what should I consider when trying to determine if we should use a complete web-service backend for our project instead of traditional MVC with web services only available when needed for the mobile portion of the app?

I'm looking for a comprehensive answer to this question, not many answers each containing one piece of the answer.

答:
Factors that would push towards a unified service interface include a complex data model, need to enforce business or security rules consistently, encapsulating data models from long upgrade cycles, or having many different types of client applications sharing data. The web services boundary can also be a useful organizational boundary in larger teams - have some developers focus on the API while others build applications on top of it.

In your case, I think the hybrid would be the better choice. It sounds like most of the features will be on the web site, and it would be extra work to build the site on top of an API built mostly for the web application.

As a point of clarification, you can use MVC with web services. In the client you would write data access objects that talk to the web service, and then build controllers on top of those to manage the UI. On the API side, web service interfaces benefit from applying MVC. You could support multiple protocols using alternative views - such as JSON, SOAP, RMI, Avro - while sharing a common model.


答:
Having a separate assembly for the Data Access is a good idea in this case and it makes it easier to point a separate testing project at it to more cleanly test your data access layer. You can develop the entity models as plain classes and then use services to populate them.  You may want to take a look at Entity Framework Code First for the database access as it will get away from the .edmx dependency and keep your entity classes cleaner.

There is a tutorial by Scott Guthrie on using Code First with existing databases.

Title: Proper & Efficient Structure for an entity layer?

Body:
Context

Web application based on the .NET Framework written in C# and following the MVC design pattern.

Question

What is the most efficient way to structure an entity layer consisting on various data inputs?

Background

I am developing an application for a client that requires my reading and writing data from various sources and I would like to build a single entity layer/model to abstract the various data sources so that I only need to query the unified model from code.  Here is an example of the disparate sources:

MS SQL Data Warehouse (about 200 tables of enterprise-wide data

MS Dynamics AX web services

A new MS SQL database that is specific to the application being developed

MS Active Directory for authenticating users and for getting user profile and group information.

In some cases, SharePoint web services.

I have used ADO.NET a good bit (.edmx files and so forth) and fundamentally, I know how to do this but I am struggling a bit with a solid, clean approach.  Do I create two separate .edmx files for the two SQL DBs and then write object classes for the Active Directory, SharePoint and AX stuff?  Do I simply write one big model file?  A whole separarate project just to make the abstraction?

Many thanks!


问:
Slow if use object cross referecing
In OOP, it seems that if an object cross-references another object in its property, ultimately, if such objects are used a lot, the software at the end will be slow because of this.

Is this true? If yes, can we intentionally not do this by getting things done?

答: The performance difference is minor compared to having cleaner and more maintainable code. Take a look at the provided API's for your language and see how common it is for objects to be nested. Classes that only deal with primitives are probably in the minority.</p>

Title: Slow if use object cross referecing


答: I'm not entirely sure I understand the question, but if an object contains another object by reference, then the cost of this is a pointer dereference every time you use the contained object.  That's a trivial cost.</p>

Title: Slow if use object cross referecing

Body:
In OOP, it seems that if an object cross-references another object in its property, ultimately, if such objects are used a lot, the software at the end will be slow because of this.

Is this true? If yes, can we intentionally not do this by getting things done?


问:
Setting variable in constructor or within method
I have a class which contains two methods.

These methods add & remove an object to a datastore.

The class which contains these methods has a no arg constructor but each of the two methods takes a variable amount of parameters for the addition / removal.

Should these methods be static and if not should the method parameters be initialized within the structure as instance variables instead of at the method level ?

pseudo code :

```<code>   class Utility {

       public Utility(){
    }

    public void add(String arg1, int arg2, boolean arg3){
    //add logic here
    }

    public void remove(int arg1, char arg2, float arg3){
    //remove logic here
    }
    }
</code>```

答: If you have no reason to persist the values between method calls, as would appear to be the case from your example code, then the methods should be static.  When you have too many static methods, it's a "smell" that perhaps a new, smaller class is waiting to be "sprouted"; in that new class, what are static methods in the original class might become non-static, and some of the data that is currently passed as parameters might become fields in the new class.</p>

OwnerDisplayName: Carl Manaster


答:
Something to consider regarding if the methods should be static or not is the actual state that the class instances can contain. If the methods are static, then they can not access any state stored in object instances, like DB connections, unless of course the instance is passed-in to the static method (Yuk, ugly).

If there are other class instance variables that need to be accessed by these methods, apart from the DB connection, then these methods probably should not be static.

As for the actual method parameters and storing them, that just depends on the situation at-hand, and is hard to answer. But in general I would not store those values via methods intended to add or remove from a DB, but instead use a constructor or attribute setters, then call add/remove without said attributes. But again, this just depends.

As mentioned in @Carl Manaster's answer, if this class just becomes a container for several static methods, then a refactor should be considered. You may consider a refactor which would involve making some sort of a POJO (or persist-able hierarchy) out of the objects to be persisted and create a separate Persistence class (or class hierarchy) which would take the POJOs as method arguments.

Title: Setting variable in constructor or within method

Body:
I have a class which contains two methods.

These methods add & remove an object to a datastore.

The class which contains these methods has a no arg constructor but each of the two methods takes a variable amount of parameters for the addition / removal.

Should these methods be static and if not should the method parameters be initialized within the structure as instance variables instead of at the method level ?

pseudo code :

```<code>   class Utility {

       public Utility(){
    }

    public void add(String arg1, int arg2, boolean arg3){
    //add logic here
    }

    public void remove(int arg1, char arg2, float arg3){
    //remove logic here
    }
    }
</code>```

OwnerDisplayName: Brady


问:
How in the earth CHRW produce unicode codes given that it only accept 65k possible input?
http://babelstone.blogspot.com/2005/11/how-many-unicode-characters-are-there.html says there are 1 million unicode characters and around 240k of which are already assigned.

1 million > 240k > 65k

However,

http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.chrw says that chrw accept 65k characters.

Not only that chrw accept integer. Integer is 4 bytes in vb.net right and can store way more than 65k characters.

The numbers do not match up and so what am I missing?

答:
Chances are that this method only supports the Basic Multilingual Plane of Unicode. That Plane contains the lower 64k of codepoints and can be represented with a 16 bit data type.

There was a time when the BMP was all the Unicode standard defined and at that time many languages and/or runtimes added "Unicode support". They thought that 16 bit will always be enough and therefore "Unicode" equals "16 bit characters" in many places (even though this is wrong these days). To be fair: The Unicode consortium also thought that 16 bit ought to be enough for everybody.

Unicode 2.0 however introduced additional planes and it was clear that 16 bit are no longer enough for representing every possible Unicode codepoint.

The "solution" to this is usually to use UTF-16 instead of UCS-2. I'm not only faulting .NET for this: Java has fallen into the same trap, having a 16-bit char data type and now having to support String instances that need 2 "characters" to represent a single codepoint.


答:
The only paradigm JavaScript doesn't readily lend itself to is an overly locked one. One of the things I find most offensive about Java, for instance is this idea that everything must originate with classes, that each class is in one file, that there is an impregnable barrier of encapsulation between your code and the enem... I mean the other developers on your team or your dev customers.

When everything is forced OOP, IMO, what you end up with is a whole lot of devs (I didn't say all or most of them) who don't actually know what problems OOP is supposed to solve in the first place. So yes, the tradeoff is that sometimes it can be a touch arcane but we get everything. We get objects that can have factories built to emulate classical OOP if that's what desperately floats your boat (Crockford admits he never really used the one he wrote). We get closures. We get first class functions we can toss around all over the place. Hell we can even reapply methods from objects as if they were methods of other objects at whim. Awful if abused. Stunningly powerful when used wisely. You get the flexibility and the rope to hang yourself rather than having the options snatched away for fear that the lowest common denominator will hang themselves.

The problem on the flip-side where JavaScript stands of course, is code soup. You have to establish some kind of a paradigm or what you end up with is something that is not so nice for the next guy to read or use or modify. The good news is that you can pretty much pick any paradigm you want. I find what works for me at my current job is larger app object structures that act as factories, warehouses, and event routers for event-driven interfaces that enable either total decoupling or something that looks and works more like traditional objects but logs an event name, origin, and params passed every time you fire a method for debug purposes. I continue to use JQuery for bringing cross-browser sanity and insane speed-of-development to the nitty-gritty DOM stuff but then I bury the JQ soup inside my own app architecture so a back end dev never has to make sense out of $('#someId > .someClass :first').click(function(e){.... to figure out what the heck is happening on the front end. But even if your first attempt at structure looks like a bunch of cookie-cutter JavaBeans, it's better to perhaps start with something than nothing. Just don't go nuts with inheritance schemes. I mention this. Everywhere. Because it's the most awful thing you can do in any language and the reason having something less than native classical OOP is not such a big deal.

The real trick to JS is finding the right balance of structure and consistently implemented interface and giving people enough flexibility to use your stuff in a variety of ways without turning your code into an ungainly, unreadable, mess. Fortunately, ugly things are easily wrapped, adapted, and decorated in JS. So how do you use it? You learn it. Really well. Then you write code to explore, invent, assert, or assimilate other development paradigms into your own as needed. What I really love about JS is that I generally find if I put a little thought into design, I can have my cake and eat it too. Stick with DRY, loose-coupling and the elimination of boiler-plate as priorities and any paradigm you adopt in JS is likely to not stink when you know your way around the language well enough. But there's a lot to learn. Partially because the spec is constantly having new features added and occasionally dropping old nasty ones and every new browser is an adventure waiting to happen.

On the matter of functional vs. OOP, I personally use both extensively. I think most experienced JS devs do, without even really realizing they're doing something atypical. My objects and constructors inform architecture and the blocks that tend to interact with one another. The functional nature of JS makes it possible to have the nature of how those objects interact be anything I want.

Title: How do you use JavaScript?


问:
What do you do with a heisenbug?
I've gotten a bug report from one of my users in a section of the software. The scenario is basically a databinding scenario where the user enters info, and that info is printed to pdf.

The problem is, that the functionality:

Is used frequently (about 40 times a week)

Hasn't been updated/modified in months

The area of code is relatively simple to walk through

The validation appears fine (ie, if the information wasn't filled out in the app, validation fires indicating it with a msgbox before the pdf is generated)

But this one user claims that in the past 2 weeks it's happened about 3 times out of 50 and I just can't reproduce it.

So what do you do in the case of a heisenbug?

答: Add some logging to this users code.</p>

Title: What do you do with a heisenbug?

Body: Add some logging to this users code.


问:
How to manage github issues for (priority, etc)?
I'm new to github, and am looking for advice on how to manage issues.  I'm used to having priority and other ordering options but see that none exist.

How do others manages issues during the lifecycle of a bug/feature?

Thanks in advance.

答:
Example of how we use labels on github to manage our projects

Category Labels (could also use all caps to visually separate)

Task

Bug

Feature

Discussion

Priority Label

URGENT

We consider everything to have normal priority and don't really see a need for "low". So that only leaves one label to mark things that need immediate attention.

Status Labels

reviewed (assignee has read it)

queued (assignee will work on it soon)

work in progress (assignee is working on it now)

invalid (if bug it's not reproducible)

need feedback (bat signal to get people to read and comment or provide help)

We keep all documentation in a wiki which includes how-to's, architecture, infrastructure, case studies, planning, and requirements.

Pull-Requests are for code reviews and feature discussion if it is part of a branch

With some creative use of the filtering we can find whatever work we need to do for the day. "Task+URGENT" or "Bug+URGENT" always review issues tagged as "need feedback" and leave a comment even if you don't have anything to add. Of course this works with our team of five but probably not much more than that.

OwnerDisplayName: djf


问:
Working on someone else's code
I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the existing features. The guy who has written the actual code doesn't work in my company any more. I am having a hard time understanding his code and doing my tasks. Whenever I tried modifying the code, I have in some way messed with the working features. What all should I keep in mind, while working over someone else's code?</p>

答:
Does the code have unit tests?  If not, I strongly suggest you start adding them.  This way, you can write new features/bug fixes as failing tests and then modify the code that the test passes.  The more of those you build, the more confidence you will have that your added code has not broken something else.

Writing unit tests for code you do not fully understand will help you understand said code.  Of course, functional tests should be added if they do not already exist. My impression was that those already did exist form the OP question. If I am wrong on that point, then these functional tests should be your first step.

Eagle76dk makes a great point about getting your manager on board for doing this work -- more details in Eagle76dk's post.

In addition as you write these tests I'd encourage you to try to write the tests so that they verify business behavior that the method may have tried to accomplish, not code behavior. Also, don't at all assume the business behaviors you see in the code are the correct ones - If you have someone who could tell you what the application should be doing that is in many cases more valuable than what the code might tell you.

Title: Working on someone else's code


答:
It seems like the typical approach to MVC is to use exactly one Model, one Controller, and one View all tied specifically to a given page type.

But the whole point of separating these concerns is to solve problems exactly like this one. You should be able to have a model and a controller that operate on two different views, your mobile view and your web app view. Or at least a shared model.

The web service thing requires that you have back end devs capable of delivering data in a an easy-to-parse form to front end devs who know how to juggle strings, data, and DOM manipulation, but if they don't have experience at it, I'm not sure I'd trust them to know it's going to be easier. I'd be a bit wary of it because it puts all the burden of structure and organization on the front end, which people tend to be bad at structuring and organizing. If it's a fairly simple app it would seem reasonable to me.

Title: What should I consider when deciding if I should use a web service backend instead of traditional MVC?

Body:
We're trying to decide what architecture to use for an upcoming web application that will eventually have a mobile portion as well. The core of the project is a social networking web application, and the mobile portion will most likely have a limited subset of the web functionality.

The two options we are looking at is either a complete web service back end, or using a traditional MVC framework for the web application and then developing web services on the side for the mobile application later.

Some arguments for web-service-only route is that it would be "simpler", as we would just have to create 1 web service as opposed to creating both a web service for the mobile portion, and additional database functions/calls for the web application. Using this method, the web application will fetch data from the web services using javascript, which would then generate the html page (sounds kind of like what a traditional MVC framework does, but this way would require everything to be done in javascript).

I'm not feeling good about the idea of using web services only because it doesn't make sense to me, but I am having trouble clarifying my issues with it.

So what should I consider when trying to determine if we should use a complete web-service backend for our project instead of traditional MVC with web services only available when needed for the mobile portion of the app?

I'm looking for a comprehensive answer to this question, not many answers each containing one piece of the answer.


答: In addition to a another answer which mentioned unit tests, I would suggest that you make sure everything is in version control so you're able to revert your changes easily. And making small changes to make the code more maintainable.</p>

Title: Working on someone else's code

Body: I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the existing features. The guy who has written the actual code doesn't work in my company any more. I am having a hard time understanding his code and doing my tasks. Whenever I tried modifying the code, I have in some way messed with the working features. What all should I keep in mind, while working over someone else's code?</p>


答:
The first thing to keep in mind is that more time is spent reading code than writing code.  Spend the time to understand how the other guy worked -- his style and approach to problems.

Try to adopt the existing style as much as possible -- otherwise the guy after you will have twice as much adjusting to do.

Dealing with someone else's code is the norm, not the exception, you need to become adept at figuring out how the other guy would have solved a problem or implemented a feature.  Once you've done that, you will find it easier to deal with his code.

Title: Working on someone else's code


答:
Don't be too quick to assume the other guy's code stinks.

But always be suspicious.

But yeah, it takes time to understand another dev's code. The more a function or object is used by multiple parts of the system the more careful you need to be. If you can solve the problem closer to the symptom, that can sometimes be helpful. For example, normalize incoming data from another object on the problem-object's side of the fence after the data is delivered but before anything else happens.

It is a bad sign when changing one thing breaks another unexpectedly. If you have any other more experienced developers you can rely on for help, I'd recommend getting them to look at stuff that's causing you issues. At the very least you may pick up a few things watching them debug.

Title: Working on someone else's code


答:
In an ideal world, all code written by a given developer will be well documented, well structured and comprehensibly tested, both with automatic tools such as unit tests and use case scripts that a user runs through to check that you get the expected result.

However, the first thing you'll learn is we don't live in an ideal world!

A lot of developers don't document their code properly, if at all, they mix business logic with unrelated code, and the only test they do is a quick run through what they expect to be the normal use case.

When working with code like this, the first thing you have to do is establish what it is meant to do.  If there are comments they may give you clues, but don't count on it.  It's my experience that many coders aren't good at explaining themselves and even if they do leave comments they might be meaningless.  However, unless you're the only coder in the company, someone surely must have at least a basic idea of what the code is for and what it's meant to do.  Ask around!

If you have unit tests, then they will make your life a hell of a lot easier.  If you don't, then part of learning the codebase may involve writing unit tests for code that already exists.  Normally this isn't considered good practice because if you write unit tests to fit the existing code, you'll end up with unit tests that think the code works as is (they'll be written to assume that behaviour that's actually a bug is correct), but at least it gives you a baseline.  If you later discover that some behaviour that you thought was correct is in fact wrong, you can change the unit test to test for what the expected result is rather than the result the code gives now.  Once you have a unit test, you can make changes and assess what side-effects any changes you make have.

Finally, the best resource you have when dealing with an undocumented piece of code is to ask the end users.  They may know nothing about code, but they know what they want the application to do.  Requirements gathering is the first stage in any project, and talking with the prospective users of the system to be developed is always an important part of that.  Just think of it as doing the requirements capture stage for a new project that just happens to already have been built.

Do bear in mind that even well-written and well-documented code can be difficult for an outsider to understand.  Code is essentially an expression of how the person who wrote it was thinking at the time, and everyone has their own unique thought process.  You'll have to learn to be a bit patient, and to be a detective.  Being able to get into another person's thought process is difficult, but it's an essential skill for a programmer doing maintenance on existing code.  As most coding (about 70%) is related to maintaining existing code, it's an important skill to learn.

Oh, and now that you've seen the pain that poorly-documented, untested and jumbled code can cause, you'll not do it to the next poor developer to come along, right?  :)  Learn from your predecessor's mistakes, comment your code well, make sure that every module has a clearly defined responsibility that it sticks to, and make sure you have a comprehensive set of unit tests that you either write first (for TDD methodologies) or at least alongside the code being developed.

Title: Working on someone else's code


问:
Good workflow for software development with scrum and continuous integration
I'm studying an approach to understand better how the continuous integration workflow fits better in a software development company with the scrum method.

I'm thinking something like this:

Would that be a nice workflow?

答:
You're some of the way there, but I'd expand your diagram somewhat:

Basically (if your version control will allow it, i.e. if you're on hg/git), you want each developer/dev pair to have their own "personal" branch, which contains a single user story they're working on. When they complete the feature, they need to push into a central branch, the "Release" branch. At this point, you want the dev to get a new branch, for the next thing they need to work on. The original feature branch should be left as-is, so any changes that need to be made to it can be made in isolation (this is not always applicable, but it's a good starting point). Before a dev returns to work on an old feature branch, you should pull in the latest release branch, to avoid weird merge issues.

At this point, we've got a possible release candidate in the form of the "Release" branch, and we're ready to run our CI process (on that branch, obviously you can do this on each developer branch, but this is fairly rare in larger dev teams at it clutters up the CI server). This might be a constant process (this is ideally the case, the CI should run whenever the "Release" branch is changed), or it might be nightly.

At this point, you'll want to run a build, and get a viable build artefact from the CI server (i.e. something you could feasibly deploy). You can skip this step if you're using a dynamic language! Once you're built, you're going to want to run your Unit Tests, as they are the foundation of all the automated tests in the system; they're likely to be quick (which is good, as the entire point of CI is to shorten the feedback loop between development and testing), and they're unlikely to need a deploy. If they pass, you're going to want to automatically deploy your application to a test server (if possible), and run any integration tests you have available. The integration tests may be automated UI tests, BDD tests, or standard integration tests using a Unit Testing framework (i.e. "unit" tests that require more state).

By this point, you should have a fairly comprehensive indication of whether the build is viable. The final step I'd normally setup with a "Release" branch is to have it automatically deploy the release candidate to a test server, so your QA department can do manual smoke tests (this is often done nightly instead of per-checkin so as to avoid messing up a test cycle). This just gives a quick human indication of whether the build is really suitable for a live release, as it's fairly easy to miss things if your test pack is less than comprehensive, and even with 100% test coverage it's easy to miss something that you can't (shouldn't) test automatically (such as a mis-aligned image, or a spelling mistake).

This is, really, a combination of Continuous Integration and Continuous Deployment, but given that the focus in Agile is on lean coding and automated testing as a first-class process, you want to aim to get as comprehensive an approach as possible.

The process I've outlined is an ideal-case scenario, there are many reasons why you might abandon parts of it (for example, developer branches are simply not feasible in SVN), but you want to aim for as much of it as possible.

As for how the Scrum sprint cycle fits into this, ideally you want to have your releases happen as often as possible, and not leave them until the end of the sprint, as getting quick feedback as to whether a feature (and build as a whole) is viable for a move to production is a key technique for shortening your feedback loop to your Product Owner.


问:
wizard-like data collection implementation help (next, next, finish)
I'm beginning to build an interface for our field techs to close out work orders and we have many different required paper forms for different customers.  I had hoped to build a system where i can set up a Page for each form (all in .Net 4.0/wpf and possibly using caliburn.micro if it's not a bad choice), and based on rules, display certain pages automatically.  I've started out by setting up a basic framework consisting of a wpf form with 3 buttons (back, next/finish, cancel) and a Frame.  In the end i hope to have an object i can pass an identifier that will go get all the information it needs, decide which pages to show, show them in order, and update our database when the user clicks finish.

Is there anything specific i should be researching/learning to make my job easier, or my finished product more robust/reliable?  What would be a good approach to decide which pages to show?  Mostly it would be based on something like Show this form if Customer is X but i'd like to be able to be more complex(extensible?) than that if i need.  In the end, each page/form will probably also generate a PDF file of the customer's actual form, filled in.  Sounds like a routine thing to have, but i've never personally implemented or used anything that did it, myself, so i'm going in blind.  would the hosting window ask the page if they need to be shown?  should the pages speak up themselves?  should the hosting window pass the entire data object to a bool function ShouldIShowYou() and let the page sort it out?  there has to be some mechanism already in place for me to "register" a page as being for a certain "something," but i'm not sure what it is.  I'd like it to be fairly easily updated, but the app is deployed via clickonce and total number of users will be under 100 for the foreseeable future.  just adding a new page object + logic to the collection and re-deploying shouldn't cause trouble.

a few other questions i had:

could(should) i implement this as a transaction in .net, where i could start a transaction when the window/object is created, have each individual page in the frame do it's own data work (via a shared wcf proxy), then commit the transaction after everything works out?

should each page just build up an object and the main window pass the object back and have the originating application do the data work?  e.g. make the whole segment of the application be data-unaware.  not sure this would work out very well, sounds like a maintenance nightmare.

is this the wrong place to put this kind of question?  i'm not looking for code, so it didn't feel right in overflow.  this is more of a "what are the words to describe what i'm trying to do" question.

Thanks!

i'll re-read this 10 or 12 times over the course of the day and try to clarify if i can.  My brain-speak don't always make gud words.

答:
A lot of the design for a system like this comes down to the users really, how connected they are and what sort of connections they have. Also - how important it is to you to have the results straight away, or whether a 'sync' approach is ok...

'Field techs' sounds like the sort of people who will be working in a disconnected way?

So you'll probably want to be looking at some way of storing results and syncing them when online? That leads to a whole ream of things like SQL CE, maybe embedded RavenDB, something on the local machine (maybe even a simple CSV). When they are online - sync to a service which can collate all the responses.

In terms of the pages themselves, depending on how many there are / planned to be in the long term either just whack them all into the project, or if they can be grouped, maybe individual class libraries for each group of pages. Then either deploy the lot (if the package is a moderate size & the field techs have decent connections) or bring them down on demand, or maybe even distribute them separately and use something like MEF to load them dynamically.

You've tagged the question with MVVM so, you know about the pattern. The VM's should be directing your pages, the 'next' command will (or should!) know which page to load next. In terms of which pages to show based on which customer, to make it more 'generic' you'd probably want to store the customer information somewhere, maybe in the service - and sync that down to the field techs when they sync up / install the software.

You can do things like code string expressions in databases to dynamically generate rules (http://www.fidelitydesign.net/?p=333), and add super-complexity - however I would avoid making the code more complex - start simple, get it working and then hit the complexity if it's needed.

For PDF generation, I would google for XAML PDF Generation, or if you have the data in a database at that point, the world is your oyster, there are some great free PDF writers (iTextSharp etc) and some not-so-free - but also good (PDFKit). Depends on whether you have a tight budget, or a not so tight budget :)