答:
If saving a 1% is really that important, you will test and measure. It's the only way to know if it work out to your advantage for the specific files you are dealing with (you could even also have your program try both and keep the smallest version, therefore ensuring you always pick the most optimum solution wrt. to size).

If not, I'd just do the simpler thing.

Title: Should I decompress zips before I archive?

Body:
I am writing a small personal archiving tool. I frequently work with a lot of client databases for short periods, what my tool will do is in overnight batch jobs it will detach the database and zip up the database files and any extra files that where sitting in the folder that the database resided in and move it to a network storage drive.

My question is quite frequently there will be zip files sitting inside the folder (the most common one would be the client's original backup before I did the processing on it). Would it be better to unzip the file to a unique sub-folder name, delete the zip, then compress the whole parent folder, or are compression algroithoms good enough that I could leave the file zipped (it was likely done with a 7zip Fastest setting) and my archiving (which will be a 7zip Ultra setting) will just compress (mostly) the difference between the two compression levels?

If I can get another 1% off of a 20GB database file it may be worth it to do the decompression.


问:
Should I decompress zips before I archive?
I am writing a small personal archiving tool. I frequently work with a lot of client databases for short periods, what my tool will do is in overnight batch jobs it will detach the database and zip up the database files and any extra files that where sitting in the folder that the database resided in and move it to a network storage drive.

My question is quite frequently there will be zip files sitting inside the folder (the most common one would be the client's original backup before I did the processing on it). Would it be better to unzip the file to a unique sub-folder name, delete the zip, then compress the whole parent folder, or are compression algroithoms good enough that I could leave the file zipped (it was likely done with a 7zip Fastest setting) and my archiving (which will be a 7zip Ultra setting) will just compress (mostly) the difference between the two compression levels?

If I can get another 1% off of a 20GB database file it may be worth it to do the decompression.

答: Compressing a zip file often results in a larger image, because of the associated overhead and incompressibility.  If size is the primary consideration, you will almost always be better off by decompressing it first.  However, if that's the case and the zip files are usually nothing more than previous backups, I would seriously look into seeing if they're safe to omit from your archive, or at least back it up fully once then omit it from future backups unless it has changed.

ContentLicense: CC BY-SA 3.0


问:
Can SQL Server and Mongo be used together?
We have a large news-oriented site that has high web traffic. The architecture is your often seen DB - Repo Layer - Services Layer - Asp.Net MVC. The problem that we've been seeing is around read performance. It turns out that all this DDD domain object stuff is great, in theory, for business rules, but has made life harder when it comes to optimizing read performance.

As a solution, I'm considering something entirely new (for us): using noSQL. I'd like to use a noSQL database for data being presented on our website. We can't get rid of our SQL Server (at least not anytime soon), but it seems to me that a practical step would be to use Mongo as a query database for all new development.

My question is whether it is possible to use SQL Server as your database of record and Mongo as your query database together?

So when one of our editors updates a record, the data will be stored in SQL Server. This is necessary, because there is too much legacy code that cannot be re-written overnight.

But when a viewer on the web site views an article or a list of articles, I'd like to take advantage of the performance of Mongo versus SQL Server. In order to keep data somewhat current, let's say 15 minutes old or less, SQL Server data would need to refresh Mongo. RDBMS have replication tools for operations like this and I'm wondering if there exists anything to do the same from SQL Server to Mongo. Lync server, maybe?

答: Yes.  On my current project, we're getting data and storing it in SQL Server, and then building search indices using Lucene/Solr and storing those in MongoDB.  Populating MongoDB is done with a custom loader, though -- no SQL Server replication or automatic refresh.</p>


问:
How to manage your functional documentation?
Our functional / business documentation is spread across Word files on our corporate Intranet.  It's difficult to find and update information.  There has to be a better way.  Any ideas?

We had thought a Wiki would work great. Would seem to be an easy way to find information and easy for individual developers and analysts to add bits of documentation quickly and easily.  We'd be curious to know if other development (or business analysis) teams use Wiki's with success.

The target for this documentation is the internal development team: developers, qa, and to a lesser extent business analysts.

答:
It's difficult to find and update information.

For whom?

Seriously.

There has to be a better way.

Actually, it may have a really good organization for particular users.

Other users may find it "difficult to find and update".

The most important thing to ask yourself is this:

Who is the audience?

If you have more than one audience, you may need documentation in more than one location.  What you have may actually be optimal.

Once you know who the audience is, you need to clearly understand their use cases.

What do they want to know?

Until you have these two things clearly defined, there's no way to choose between your existing organization, a Wiki or -- perhaps -- less documentation with a better focus.

Since you didn't describe your audience or your use cases, we can't provide any advice at all.


答:
You've run into a problem that many have before you...a database optimized for reading is seldom good for write efficiency and vice versa. One approach that has evolved from this read-write impediment is CQRS (Command Query Responsibility Segregation). Despite Wikipedia linking the two together CQRS and CQS are technically different. CQS just demands that a method either make a change (command) or ask information (query) never both.

CQRS takes it a step further and specifies that you have a separate model for Queries and Commands. This single step enables things like separating your read and write database. Which is what you want to do.

I can't say that I'm an expert on Mongo or configuring it to work with SQL Server. But from my understanding, people use Mongo as a denormalized view of their transactional database. Updating Mongo from the transactional db might come down to running a SQL Agent. Or having a separate service to poll the database.

An even better alternative would be to have your Command service fire an event whenever an update is made. You would then have a service that listened for that event and updated the MongoDB with that information. That is the fundamental approach to Event Sourcing (search for Event Sourcing on the page).

Greg Young, one of the thought leaders in the DDD world is currently writing a book in the Fowler Signature Series on CQRS called Event-Centric (it used to be called CQRS). Fowler has written a post on his bliki describing the approach

Title: Can SQL Server and Mongo be used together?

Body:
We have a large news-oriented site that has high web traffic. The architecture is your often seen DB - Repo Layer - Services Layer - Asp.Net MVC. The problem that we've been seeing is around read performance. It turns out that all this DDD domain object stuff is great, in theory, for business rules, but has made life harder when it comes to optimizing read performance.

As a solution, I'm considering something entirely new (for us): using noSQL. I'd like to use a noSQL database for data being presented on our website. We can't get rid of our SQL Server (at least not anytime soon), but it seems to me that a practical step would be to use Mongo as a query database for all new development.

My question is whether it is possible to use SQL Server as your database of record and Mongo as your query database together?

So when one of our editors updates a record, the data will be stored in SQL Server. This is necessary, because there is too much legacy code that cannot be re-written overnight.

But when a viewer on the web site views an article or a list of articles, I'd like to take advantage of the performance of Mongo versus SQL Server. In order to keep data somewhat current, let's say 15 minutes old or less, SQL Server data would need to refresh Mongo. RDBMS have replication tools for operations like this and I'm wondering if there exists anything to do the same from SQL Server to Mongo. Lync server, maybe?


问:
How to architect enterprise desktop applications for Windows 8
I think I have a grasp on the expectations of consumer application development for Windows 8.  Create a new Metro-based UI on top of WinRT, deploy it to your customer via the Marketplace, and everyone wins.  Seems simple enough.  Unfortunately, I'm not in that business.

I work on internal, line-of-business applications for a large enterprise.  We currently use .NET technologies such as WPF and Silverlight in order to create rich UIs that can be easily deployed to our users via the web or ClickOnce.  The applications can support WinXP and Win7 without too much headache, and our developers get to use XAML which is a very solid UI technology.

It seems like WPF and Silverlight have questionable futures at this point, so it is a bit worrisome to continue investing in those.  But a Metro UI doesn't seem appropriate for enterprise applications, and the WinRT API is quite limiting with regards to "typical" things that enterprise applications need to do.

How should I be architecting my XAML-based applications, currently being deployed to WinXP and Win7, so that they will be supportable and evolvable on Win8?

Assume for the purposes of this question that the features provided by HTML5 on top of ASP.NET are not adequate for the applications I'm looking to create.  I understand that I can use HTML5 for some applications, but I'm trying to figure out what I should do when that isn't enough.

Edit #1:
This is in response to @Emmad Kareem's comment.  I do agree that Silverlight/WPF are viable in the short term (2-5 years).  However, the applications we produce have potentially very long lifetimes (10-20+ years).  So survivability in the long term for a given technology is a concern for us.  Also, we have some concern that it will be more and more difficult to find developers that are interested in Silverlight / WPF development if those technologies are considered "dead" by the community.  I just want to understand my options and make a decision with my eyes open.

答:
My take on this is that you should not focus too much on the implementation details of your applications. If you look at a bigger picture, you can isolate your technology dependencies. By isolatin the dependency on e.g. xaml/wpf/silverlight you ensure that you can replace the ui component/technology with a next generation technology and therefore guarantee continuity even in 20 years time. This will also help decoupling your systems components and therby the impact of having to perform such a replacement. (In this I make an assumption that for providing continuity it's okay to tinker with a solution to get it going on a next generation platform)

An other way of providing isolation from these technology dependencies is enabling virtualization. If you craft your applications in such a manner that you are able to run them in a vm, you will be able to do so in 20 years time!


答:
We've applied sharepoint for this, it has full text search for word doc's integrates nicely into Word and all the other Office apps. It provides version control and explorer integration so file management becomes pretty easy. It does however require a lot of upfront thinking/analysis on who-can-access-what to define search scopes, document access etc. </p>

<p>We tried a wiki but for non techies that somehow was too challenging (especially publishing images into wiki text). If you like you can mix the wiki with the document library, sharepoint has a basic wiki component as well.  </p>

Title: How to manage your functional documentation?

Body:
Our functional / business documentation is spread across Word files on our corporate Intranet.  It's difficult to find and update information.  There has to be a better way.  Any ideas?

We had thought a Wiki would work great. Would seem to be an easy way to find information and easy for individual developers and analysts to add bits of documentation quickly and easily.  We'd be curious to know if other development (or business analysis) teams use Wiki's with success.

The target for this documentation is the internal development team: developers, qa, and to a lesser extent business analysts.

Body:
We've applied sharepoint for this, it has full text search for word doc's integrates nicely into Word and all the other Office apps. It provides version control and explorer integration so file management becomes pretty easy. It does however require a lot of upfront thinking/analysis on who-can-access-what to define search scopes, document access etc.

We tried a wiki but for non techies that somehow was too challenging (especially publishing images into wiki text). If you like you can mix the wiki with the document library, sharepoint has a basic wiki component as well.


问:
Algorithm to determine fastest route?
Let's say we're going from 1 to 5. The shortest route will be 1-4-3-5 (total: 60 km).

We can use Dijkstra's algorithm to do that.

Now the problem is, the shortest route is not always the fastest one, because of traffic jams or other factors.

For example:

1-2 is known to have frequent traffic jams, so it should be avoided.

Suddenly a car accident happens along 4-3, so it should be avoided too.

Etc...

So probably we can speed on the route 1-4-5, because of no traffic jams/accidents, so will arrive at 5 faster.

Well that's the general idea, and I haven't think about more details yet.

Is there any algorithm to solve this problem?

答: Since you brought congestion into the picture, be careful you don't get caught by Braess' Paradox. If everyone chooses the optimal path, it results in worse travel time for everyone.</p>

Title: Algorithm to determine fastest route?


问:
In-house versus Software-development Environment
In the industry, there is a distinction made between an 'in-house development' environment where the software developers are writing code which will be used by the company itself and a proper 'software development' environment where software is built to be sold/distributed to the public.

Among others, one obvious difference between the two is that a software-development-oriented company will typically adhere to some sort of software development life cycle such as spec-writing, testing, building etc. whereas the in-house-oriented shop will usually do things in a more casual way since they themselves are the end-users and can always fix something that wasn't done right.

As a student (like most other students), I kind of expected myself to wind up working in a software development environment, but I ended up getting my first position at a firm which operates in more of an in-house fashion.

At times, I wonder whether I am missing out on the full-fledged software development experience. Is there a basis for this feeling? Should I seek to join a proper software development environment?

答:
In my experience, the distinction you are making between "in house" and "distributable product" is false.

There are companies that take their software development process seriously and those that don't. Whether they are "in house" or "bespoke" or "shrink wrap" tends to not come into it as much (though if they are "shrink wrap" providers, if they don't have process they will probably not be in business for long).

You should look for a place that has the standards of development you are looking for - when interviewing you need to ask these questions to ensure the place is to your liking in this respect (as well as other).


答:
We introduced a Wiki some years ago into our company, for mainly the same purpose you described. Today, I have mixed feelings about the success. There are some very good articles, and some teams are using the Wiki well, but there is also a lot of garbage, someone started them once, with the notion of "I will complete the article later" but no one feels responsible for doing the necessary editorial work. </p>

<p>So  when you are going to install a Wiki, don't underestimate the effort needed to fill the thing with useful content. Have some people responsible for the main structure and for cleaning up things. Make sure everyone knows what the Wiki should be used for (and for what it should not), and talk to your executives if they are willing to make it obligatory that certain parts of the business documentation must be "Wiki"-only. </p>

Body:
We introduced a Wiki some years ago into our company, for mainly the same purpose you described. Today, I have mixed feelings about the success. There are some very good articles, and some teams are using the Wiki well, but there is also a lot of garbage, someone started them once, with the notion of "I will complete the article later" but no one feels responsible for doing the necessary editorial work.

So  when you are going to install a Wiki, don't underestimate the effort needed to fill the thing with useful content. Have some people responsible for the main structure and for cleaning up things. Make sure everyone knows what the Wiki should be used for (and for what it should not), and talk to your executives if they are willing to make it obligatory that certain parts of the business documentation must be "Wiki"-only.


答:
You may read this article

http://www.joelonsoftware.com/items/2007/12/04.html

of Joel Spolsky, which is exactly dealing with your question.

I am in a position where I had to work on both the last years - a medium-sized software product beeing sold, and some in-house software. From that experience, I can tell you there are differences between those two platforms, but the situation is not that bad as Joel described it.

For example, most of our in-house software has to run only in a very restricted environment. Lots of tools just working with a certain spreadsheet or database version, with a specific network environment, with a restricted number of users, no installation routine needed etc. That makes a lot of things easier and quicker to develop as compared to new features introduced into our shipping product. On the other hand, that does not mean my code for the "in-house" programs has lower quality or is written in a more "casual way".

Title: In-house versus Software-development Environment

Body:
In the industry, there is a distinction made between an 'in-house development' environment where the software developers are writing code which will be used by the company itself and a proper 'software development' environment where software is built to be sold/distributed to the public.

Among others, one obvious difference between the two is that a software-development-oriented company will typically adhere to some sort of software development life cycle such as spec-writing, testing, building etc. whereas the in-house-oriented shop will usually do things in a more casual way since they themselves are the end-users and can always fix something that wasn't done right.

As a student (like most other students), I kind of expected myself to wind up working in a software development environment, but I ended up getting my first position at a firm which operates in more of an in-house fashion.

At times, I wonder whether I am missing out on the full-fledged software development experience. Is there a basis for this feeling? Should I seek to join a proper software development environment?


答:
Dijkstra

As said before, it is not only used for shortest distance. I believe this animation gives a good understanding of the "power" (for lack of a better word) of Dijkstra:

Title: Algorithm to determine fastest route?

Body:
Let's say we're going from 1 to 5. The shortest route will be 1-4-3-5 (total: 60 km).

We can use Dijkstra's algorithm to do that.

Now the problem is, the shortest route is not always the fastest one, because of traffic jams or other factors.

For example:

1-2 is known to have frequent traffic jams, so it should be avoided.

Suddenly a car accident happens along 4-3, so it should be avoided too.

Etc...

So probably we can speed on the route 1-4-5, because of no traffic jams/accidents, so will arrive at 5 faster.

Well that's the general idea, and I haven't think about more details yet.

Is there any algorithm to solve this problem?


问:
How does Assembla compare to FogBugz + Kiln
I'm choosing a project management solution and narrowed it down to either Assembla or FogBugz + Kiln. These were my criteria:

Hosted service but with an option to go to a custom installation (rules out e.g. Codebase HQ)

Centered around projects, not repositories (GitHub, although having added some PM features recently, seems to be repo-centered)

Git repository hosting a must, SVN + Mercurial nice to have

Popular service with (at least somewhat) guaranteed continuity - both FogBugz and Assembla seem to be amongst the most popular PM solutions

Wikis, discussions, code reviews, user management etc. The more features, the better. This rules out (otherwise a very nice service) BitBucket and others. Both FogBugz and Assembla seem quite feature packed.

I'm looking for someone who has experience with both FogBugz and Assembla and could compare them. This is what I've gathered so far from feature pages / screenshots / random mentions on the web:

FogBugz seems to have quite a nice UX. Assembla makers are certainly trying hard and the screenshots don't look that bad but it still feels less elegant.

FogBugz is offered with Kiln which I'm sure is a nice product but I'd prefer Git over Mercurial. I know FogBugz can be used with other SCM services but I'd rather have one integrated solution out of the box.

Assembla is cheaper, actually much cheaper should there be more than a few users.

Maybe I'm wrong, these are just my first impressions. If someone could offer a more complete / educated comparison I would be grateful.

答: I do not have experience with Fogbugz/Kiln so I can not directly answer the comparison question BUT I can say that Assembla is great. I have used it for a handful of projects and used both their Subversion and git which is nicely integrated their ticket and collaboration tools. It worked very well. </p>


问:
How should I introduce a coding standard to my team?
First a bit of background:  My current development manager is taking another opportunity the end of this week, leaving our team with four fulltime developers, a part-time intern and a web designer (who is technically part of Marketing, not AppDev).  At this time we aren't promoting or hiring a new manager.

The previous manager never would take the time to come up with a set of coding standards to adhere to (to put this in perspective: My one-year anniversary at this job is in two weeks and I've been talking to him about standards since I started).  Due to this, all of us four developers write code our own way: Some of us follow the Microsoft naming conventions for .NET, some use Hungarian notation, some use a mix (e.g. mixing PascalCase and camelCase for parameter names), and it's entirely random when you open a code file what standard it will follow - about the only thing consistent is that braces are on separate lines.

Two out of my three co-workers have approached me to create a standard coding document that we can use and enforce moving forward (although I am technically not the most senior developer, the fourth developer having been here for several years, two co-workers and the intern look to me for advice/guidance but we do not have a team lead).  I have been meaning to do this for a while but the now-departing manager would always put it on the backburner; his departure now gives us a chance to take some time and configure things correctly to facilitate a proper software environment and not the rushed hodgepodge we currently have.

How should I go about doing this and introducing this standard to my team without causing friction?  I don't want to make it look like I'm "taking over", although were I offered the manager position I would accept it.  As I said two out of three other developers are on board with me creating one, but the fourth (the true "senior" in length of time) may or may not accept it.  I plan to start with the .Net conventions from Microsoft (e.g. do not use Hungarian Notation), add some personal preference (e.g. _camelcase for fields) and specifically call out certain strange practices we use here as not to be used (e.g. naming a class with an underscore at the start), but what else should I include?  I don't want to get into architectural guidelines as that will cause friction and we have a very large, and smelly, existing codebase that wouldn't adhere to it, and we're nowhere near at the point of coming up with a refactoring strategy.

To summarize:  Beyond basic naming conventions what, if anything, should I include in a coding standards document (examples would be great - I haven't managed to find any concrete examples of what such a document should look like), and how should I present it to my team without sounding like the new dictator.

答:
How should I go about doing this and introducing this standard to my team without causing friction?

You also say:

Two out of my three co-workers have approached me to create a standard coding document that we can use and enforce moving forward

Looks like you already have some buy-in from most of the team. Make creation of the document something that is done by all of you (all four if possible). If this is too time consuming, come up with your document and show it as a draft to your colleagues. Once all of you have agreed and finalized a version you are good to go.

A good place to start is a look at the different stylecop rules - you don't have to adhere to them all, but these will give you an idea of what your document should contain. As an added bonus, you can easily implement stylecop in your solutions and even integrate into an automated build (failing the build if there are violations).

To summarize:

Look at existing tools and standards to decide what you want in yours.

In order to avoid looking like a dictator, make the change a collaborative one.


答:
A long time ago, I read a book on Agile Project Management (I wish I could remember the title), where the author distinguished systems based on their levels of tolerance for system defects. Tolerance for defects could range from very high -- for example, a utility used by other developers (where bugs are merely an inconvenience), to very low -- for example, a system which is running life support for astronauts (where a bug could be life-threatening).

The author's point was that the development methodology (and formality) needed to be scoped to the failure tolerance (or criticality) of the system. I think this distinction is the most important one, as opposed to distinguishing between in-house development versus software for general distribution.

Imagine a hospital which has in-house developers building medical record systems which could impact quality of medical care.  In this case, the in-house shop would likely be more rigorous than a web site consultancy, who is building web products to be used by the general public.


答:
With something like coding conventions, I would say that any specific convention should be 100% unanimous or find some middle ground that makes it 100% unanimous.

Set a deadline for the document to be completed, this will force others to take it seriously.

Do the work of compiling the document, nobody will feel like helping you but if you own the work then nobody will fight you on it.

Send out proposals for various coding conventions based on different styles that exist in the codebase now.  Gather feedback, and set up a meeting where they can be voted on.

Nobody leaves the meeting until each convention has come to 100% unanimous agreement

New people to the team will have to abide by the document and will have no say.  It is like the Constitution at that point.

Oh and no Hungarian notation.  Seriously, I would rather papercut my eyes than have to look at code in Hungarian notation.

Title: How should I introduce a coding standard to my team?

Body:
First a bit of background:  My current development manager is taking another opportunity the end of this week, leaving our team with four fulltime developers, a part-time intern and a web designer (who is technically part of Marketing, not AppDev).  At this time we aren't promoting or hiring a new manager.

The previous manager never would take the time to come up with a set of coding standards to adhere to (to put this in perspective: My one-year anniversary at this job is in two weeks and I've been talking to him about standards since I started).  Due to this, all of us four developers write code our own way: Some of us follow the Microsoft naming conventions for .NET, some use Hungarian notation, some use a mix (e.g. mixing PascalCase and camelCase for parameter names), and it's entirely random when you open a code file what standard it will follow - about the only thing consistent is that braces are on separate lines.

Two out of my three co-workers have approached me to create a standard coding document that we can use and enforce moving forward (although I am technically not the most senior developer, the fourth developer having been here for several years, two co-workers and the intern look to me for advice/guidance but we do not have a team lead).  I have been meaning to do this for a while but the now-departing manager would always put it on the backburner; his departure now gives us a chance to take some time and configure things correctly to facilitate a proper software environment and not the rushed hodgepodge we currently have.

How should I go about doing this and introducing this standard to my team without causing friction?  I don't want to make it look like I'm "taking over", although were I offered the manager position I would accept it.  As I said two out of three other developers are on board with me creating one, but the fourth (the true "senior" in length of time) may or may not accept it.  I plan to start with the .Net conventions from Microsoft (e.g. do not use Hungarian Notation), add some personal preference (e.g. _camelcase for fields) and specifically call out certain strange practices we use here as not to be used (e.g. naming a class with an underscore at the start), but what else should I include?  I don't want to get into architectural guidelines as that will cause friction and we have a very large, and smelly, existing codebase that wouldn't adhere to it, and we're nowhere near at the point of coming up with a refactoring strategy.

To summarize:  Beyond basic naming conventions what, if anything, should I include in a coding standards document (examples would be great - I haven't managed to find any concrete examples of what such a document should look like), and how should I present it to my team without sounding like the new dictator.


答: As long as you are not the new manager of your team, you need consensus about having a coding standard at all (and if you were the manager, you should really try hard to get consensus in the team before make such a decision "from above"). And it may sound simple, but only talking - especially talking with the fourth developer - can solve this.</p>


答:
Do you have a company Wiki? Or, failing that, a server that you can drop one on?

If so then just create a page. Call it a living document. Put down a few non-contentious standards and encourage everyone else to collaborate. Keep adding items every few weeks, encourage discussion but in a way that says "if no one disagrees then we should expect this to be followed." If you can, convince everyone to subscribe to the standards documents, so you can see any changes your colleagues make.

Also try to get the team to begin code-reviews. Every job goes through two developers. This will encourage discussion and standards enforcement, and make it so that everyone is equal, not one developer dictating the rules.

Edit in response to comment:

You can sell code-reviews as a way for Dev #4 to spread his wisdom. Even when his code is being reviewed, it is an opportunity for people to see his magical code and bask in awe at it. Really, it is a way of promoting discussion. Where the coder and reviewer can't agree, it should go to the team. Where the team can't agree, research should be done.

Speaking of research, do some on code reviews. No one whose opinion counts for much thinks they're a bad idea. Put it to the team, including the CIO, in an email with lots of links. It's hard to argue against them without looking like an obstructive idiot.

Here are a few to get you started:

http://www.codinghorror.com/blog/2006/01/code-reviews-just-do-it.html

http://scientopia.org/blogs/goodmath/2011/07/06/things-everyone-should-do-code-review/

http://blogs.sas.com/sasdummy/index.php?/archives/264-Are-you-too-good-for-code-reviews.html

As for a Wiki, I really would recommend taking the time to set one up (Wikis give the illusion of collaboration, even when it isn't really there). But if you can't then a Word document on a shared drive will do the job.


答:
Coding standards are going to be a challenge to get accepted.  Some people like to code in their sandbox and just do their thing despite the fact it can cause issues if it breaks and others are trying to fix it.

If you're using Visual Studio with .NET take a look at StyleCop.  You can use the pre-defined rulesets or write your own.  Then get everyone to agree before code reviews (if you have them) that you should adhere to the settings.


答:
Comment and whitespace standards are good, along with tools to migrate between different styles. I use tabs in my python code, which is considered bad style. However, a simple VIM function converts between the two as necessary.

Also, think about code comprehension levels. The purpose of a style is to communicate information to the programmer reading the code. If you can understand reduce(lambda x, y: x+y, map(lambda x: x + 1, theList)), but your co-workers would rather see:

```<code>for pos,item in enumerate(theList):
    theList[pos] = item + 1
tmp = 0
for item in theList:
    tmp = tmp + item
</code>```

Then this is important to hash out. Same with white space. You need to figure out what level of code compression everyone is comfortable with.

Finally, how do new projects, and current projects, get cut up? One class per file, utility functions follow a naming scheme, no global variables or scope leakage, random project files are orthogonal and loosely coupled, and so on. This provides an important understanding base for everyone. It doesn't matter what the coding standard is, if every project is so intertwined that I have to go through the whole code base and really grok the project before I twiddle foo().

Body:
Comment and whitespace standards are good, along with tools to migrate between different styles. I use tabs in my python code, which is considered bad style. However, a simple VIM function converts between the two as necessary.

Also, think about code comprehension levels. The purpose of a style is to communicate information to the programmer reading the code. If you can understand reduce(lambda x, y: x+y, map(lambda x: x + 1, theList)), but your co-workers would rather see:

for pos,item in enumerate(theList):
    theList[pos] = item + 1
tmp = 0
for item in theList:
    tmp = tmp + item

Then this is important to hash out. Same with white space. You need to figure out what level of code compression everyone is comfortable with.

Finally, how do new projects, and current projects, get cut up? One class per file, utility functions follow a naming scheme, no global variables or scope leakage, random project files are orthogonal and loosely coupled, and so on. This provides an important understanding base for everyone. It doesn't matter what the coding standard is, if every project is so intertwined that I have to go through the whole code base and really grok the project before I twiddle foo().


问:
Separating the UI from its event handlers and database queries
Is it a good practice to separate the handlers and database queries in different classes?

There will be a separate class containing all the necessary event handlers, and there would also be another class for database queries?

答:
+1 for Emmad Kareems answer, but I would also add that your database queries should be implemented  (if possible) as stored procedures in your database becase they are easier to unit test/debug (because you can run them without your code). They make change easier as for some changes you only need to change the procedure, and not your code base. They also run faster because the DB engine will pre compile them and store statistics on them which it probably wont do for queries that are coded into you app.

And yes, the N teir approach works with any language you like - even scripting languages - you just need to find the correct pattern/code/library for the situation.


问:
when to load partial views
When creating a website, when should you load partial view and when should you do a complete page refresh?

I was looking at github's site and noticed that pretty much the only place they do partial loading is in a project's folder area.  I could see a couple places where they could have but didn't(tab navigation: feed, your actions, ...). But, Google plus does partial loads for search, and clicking on any of the header navigation buttons (pictures, games, circles, ...).

Why would you not do partial loading if the main container stays the same and the content is the only thing that is changing?

答:
I think partial loading is for improving user experience. For me I think you should use partial loading when ever you think partial loading will improve initial page loading. Also, partila loading should be used in places where you don't want users to be inconvinienced with full page reload.
Where to and where not to use, mainly depend on your site userbility, sites with a lot of user interaction might benefit more from partial page loading. The fact that certain big did or did not use partal loading does not make it right or wrong to use it to your site.  </p>

Title: when to load partial views


问:
Is there a subset of programs that avoid the halting problem
I was just reading another explanation of the halting problem, and it got me thinking all the problems I've seen that are given as examples involve infinite sequences. But I never use infinite sequences in my programs - they take too long. All the real world applications have lower and upper bounds. Even reals aren't truly reals - they are approximations stored as 32/64 bits etc.

So the question is, is there a subset of programs that can be determined if they halt? Is it good enough for most programs. Can I build a set of language constructs that I can determine the 'haltability' of a program. I'm sure this has been studied somewhere before so any pointers would be appreciated. The language wouldn't be turing complete, but is there such a thing as nearly turing complete which is good enough?

Naturally enough such a construct would have to exclude recursion and unbounded while loops, but I can write a program without those easily enough.

Reading from standard input as an example would have to be bounded, but that's easy enough - I'll limit my input to 10,000,000 characters etc, depending on the problem domain.

tia

[Update]

After reading the comments and answers perhaps I should restate my question.

For a given program in which all inputs are bounded can you determine if the program halts. If so what are the constraints of the language and what are the limits of the input set. The maximal set of these constructs would determine a language which can be deduced to halt or not. Is there some study that's been done on this?

[Update 2]

here's the answer, it's yes, way back in 1967
from http://www.isp.uni-luebeck.de/kps07/files/papers/kirner.pdf

That the halting problem can be at least theoretically solved for ﬁnite-state
systems has been already argued by Minsky in 1967 [4]:
“...any ﬁnite-state machine, if left completely to itself, will fall eventually into a
perfectly periodic repetitive pattern. The duration of this repeating pattern cannot
exceed the number of internal states of the machine...”

(and so if you stick to finite turing machines then you can build an oracle)

答:
here's the answer, it's yes, way back in 1967 from http://www.isp.uni-luebeck.de/kps07/files/papers/kirner.pdf

That the halting problem can be at least theoretically solved for ﬁnite-state systems has been already argued by Minsky in 1967 [4]: “...any ﬁnite-state machine, if left completely to itself, will fall eventually into a perfectly periodic repetitive pattern. The duration of this repeating pattern cannot exceed the number of internal states of the machine...”

(and so if you stick to finite turing machines then you can build an oracle)

Of course how long this takes is another question


问:
Creating crossplatform TCP proxy/gateway that would handle maximum possible clients simultaneously on 1GB ethernet pipe?
So what I wonder about is preaty simple - having in mind next architecture:

```<code>         -> computing unit "A"
        /
gateway --> computing unit "B" same as A
        \
         -> computing unit "C" same as A
</code>```

We do not care to which unit to forward request so we should forward them one by one to A than to B than to C and than to A, etc.

I wonder in what language, using what framework it is possible to create such crossplatform TCP proxy/gateway (not ethernet card dependent) that would redirect incoming requests into internal nodes via simple rool, and would be capable to get as much as possible from ethernet cable load in/out capabilety - receive and send as much as possible?

I started to wonder after I read this nice 2003 article...

答:
By maximum number of client I guess you're also wanting high throughput, otherwise the number of clients would be limited by the number of ports.  For the highest possible throughput/performance you'll want native code.

I would look at C++ with Boost asio.  With asio you would still want to:

Ensure you have efficient buffer management.  Asio provides some support for this.

Tune your socket receive/transmit buffer size.

Ensure you have properly set socket options (e.g. you may want TCP_NODELAY).

Profile your application under load to see that it's doing what you think it's doing.

Also keep in mind you won't realistically get more than 700-800Mbps on a 1GBps adaptor.

If performance is less of an issue there are many choices, node.js would be interesting.


问:
How do you maximise the knowledge that you gain from a programming book?
Not because I care how long it takes someone to read a book, but more because I'm interested in how people get the knowledge from a book (or I guess other sources) into their brains in the best, most efficient way.

Personally I take a multi-pass approach (from my answer to the original question):

Skim through contents, dip in and read anything with an interesting looking heading and finally gawp at any nice diagrams and illustrations. I won't take much in at this stage, but it gives me a mental view of the book (an hour or so at most)

First pass through the book, generally I'll read the opening chapters thoroughly for a book that is either very heavy going or introduces something completely new. For books that cover a subject I already know about I'll skim or skip bits that seem trivial. The remainder of the book I'll go through reasonably quickly but not so quickly that I'm just page flipping. (about a week)

Not all books that I read make it this far, but if I find a book interesting or useful enough I'll then study it properly. I will go through the book at a slower pace and do some or all of the examples, try out code, etc. I will often skip entire chapters here unless the book is really good (1-3 weeks depending on the book).

Finally when I've finished reading it and am reading other books I will often dip into it again and again to cross-reference, compare, look things up, browse, etc - so many of my favourite books don't just end up gathering dust on the bookshelf.

I rarely take notes when reading (although I may do some planning on paper if I'm working through something like a code sample). I've also considered starting to use a personal kanban for organising my progress, but have never quite got around to using that technique. Mindmaps are another thing I like the idea of but rarely do.

What other methods to people have? How successful do you find them? Are there any commonly recommended techniques that you feel are a waste of time?

答:
Highlight anything that surprised you.  It will make it easier to find it in the future.

Write in the margins extensively.

If you loan your book to someone, ask the person to follow these same rules, ideally in different colors.  This adds value to your book.

ContentLicense: CC BY-SA 2.5


答:
Beyond basic naming conventions what, if anything, should I include in a coding standards document

Nothing.

Take your time.  Go slow.  Don't waste time writing.  Coding conventions only work when they're part of the common culture.

If they're not part of the culture, they're simply ignored.

How should I go about doing this and introducing this standard to my team

Code reviews.  It's a great place to introduce the problem that's solved by coding conventions.

Most of the time, conventions are simply a waste of time.  When you have an actual problem (i.e., unreadable programs) that you can solve through coding conventions, you can get to 100% compliance quickly.

Coding conventions which are merely personal preference don't solve a problem.  And indeed, during a code review, you may find out something better and actually change your personal preference.

Don't canonize too  much in a coding conventions document.  Work cooperatively to arrive at a common understanding.

I don't want to get into architectural guidelines as that will cause friction and we have a very large, and smelly, existing codebase that wouldn't adhere to it,

Bad policy.

An architectural standard is never something with 100% adherence.  It can't be.  It's always a "forward-looking" description, toward which development evolves.

Every good architectural idea will lead to a new architectural direction.  And that's what innovation looks like -- a path, not a goal.

and we're nowhere near at the point of coming up with a refactoring strategy.

Good.  Don't develop one.  By that I mean "don't stifle innovation by writing down too many things which may or may not be best possible approach."


问:
Software Development - Project, 1 Programmer - What if hit by bus?
The company I am currently working for has me developing a bunch of internal mission critical software. I have one other person that works for me but he's more of a testing guy and not really a developer. The company is concerned about some of these projects and what happens if I am hit by a bus. How does the company pick back up after something like that when there is only one person that knows the code base. One person that knows the current status of the project.

I explained that with my documentation and with the documentation with in the code that they would really only need to hire another programmer that understands the languages that were used and that they could be up to speed pretty quickly.

They suggested an outside firm that might be "kept up to date" on a monthly basis that could "take over" in the event something happened. I just don't see how this could be helpful beyond paying someone for the sake of paying them. Worse I envision a day a month being wasted discussing the project with this consulting firm. I see how this could be helpful I just don't see it as anymore helpful than hiring a programmer after my untimely demise.

Thoughts? Similar situation and how its currently being handled where you work?

答:
I know your pain. The company I work for has 20+ developers, and everybody has his knowledge.

The overlapping bits are really... bits, so if someone goes missing (vacation, ilness, etc) and something happens to the tools they're managing, you're screwed.

The problem is they know the situation and don't care all that much, maybe they haven't hit their face dead on yet.


答:
My first advice is when the action suggests it, use navigation. This doesn't tell a lot but think of nav buttons or links to articles from the same page, etc where users intuitively awaits full navigation responses.

Partial page request are for places where a new rendered page is too much, like photos slides, little pieces of information, or adding a post like here. You wouldn't expect a PPR when clicking on a stackexchange question but you do when voting up a question.

In addition, PPR and browser history is sometimes difficult to implement. Don't work in vain when users won't expect, need or appreciate partial loading.

Title: when to load partial views

Body:
When creating a website, when should you load partial view and when should you do a complete page refresh?

I was looking at github's site and noticed that pretty much the only place they do partial loading is in a project's folder area.  I could see a couple places where they could have but didn't(tab navigation: feed, your actions, ...). But, Google plus does partial loads for search, and clicking on any of the header navigation buttons (pictures, games, circles, ...).

Why would you not do partial loading if the main container stays the same and the content is the only thing that is changing?


问:
Using GPL licensed jQuery scripts on website with ads
I'm making a web application that will generate revenue from displaying ads. The system is meant for me to run and not sold/distributed to anyone else.

My questions are:

Can I use GPL licensed jQuery scripts on the website?

Can I use GPL licensed scripts while generating ad revenue from the page?

Do I need to provide my sites source to everyone if I use GPL licensed scripts?

答:
Can I use GPL licensed jQuery scripts on the website?

Absolutely.

Can I use GPL licensed scripts while generating ad revenue from the page?

Absolutely. The GPL has nothing to do with whether your website - or any application - is for profit or not.

Do I need to provide my sites source to everyone if I use GPL licensed scripts?

That's an extremely tricky one. If you have not modified the scripts themselves you don't need to provide any source. Whenever a user visits your site, they essentially download the full client side source code, that usually includes every bit of HTML, CSS and Javascript. Richard Stallman1, has indirectly acknowledged that behaviour as a valid sharing of GPL code, in his Javascript Trap article.

Javascript does not really have the "linking" concept, in the sense of "compiled against", and that's true for every interpreted language. Adding the fact that all your client side code is distributed by default, I think you are perfectly fine.

But if you are using any kind of minification/obfuscation on the scripts themselves, that might count as modification so you have to at least make sure that you preserve the original licence as it was and that there is a simple way of others to use the scripts, if they choose to. I have no idea what applies when the original author chooses to distribute the scripts in minified versions and you are using them instead of the full ones.

Now if you have modified the scripts themselves in any way, that's a different matter. You absolutely have to make sure that you distribute the modified scripts in a way that's compatible with the GPL - a way that makes it easy for others to use them if they choose to, and distribution via the browser doesn't count.

In that case, I'd probably share the modified source in a public repository, under a compatible license and link to the repository from my site. Think of something like a section in an "about" page that says something like:

This website is made possible by these fine open source projects:

PHP

MySQL

jQuery and jQuery UI

jQuery Horizontal Accordion

Full source code of my modified version of the jQuery Horizontal Accordion plugin can be found here.

And a collection of smart little scripts I've build, available here.

The last part is not absolutely necessary, you can licence and distribute your own original scripts as you want - but since you already distribute their full source code it'd be nice if you released canonical (non minified/obfuscated) versions of them as open source.

Finally, jQuery core is dual licensed under the MIT Licence and the GPL. So in any case, if you are doing something incompatible with the GPL but compatible with MIT, you are fine. That's for jQuery core, not anything else that has jQuery in its name or is based upon it.

1 Bulgarian folk dance enthusiast and popular singer.

Disclaimer: Not a lawyer, treat all of the above as guesses. If you can afford it, consult with a lawyer.


答:
We are using Sharepoint to store documentation. We use the following directory structure for each project:

Requirements - Statements that identify attributes, capabilities, characteristics, or qualities of a system. This is the foundation for what shall be or has been implemented.

Architecture/Design - Overview of software. Includes relations to an environment and construction principles to be used in design of software components.

Technical - Documentation of code, algorithms, interfaces, and APIs.

End User - Manuals for the end-user, system administrators and support staff.

Marketing - How to market the product and analysis of the market demand.

Taken from http://en.wikipedia.org/wiki/Software_documentation


问:
Pattern for a web application
I'm developing a web application for a university project. My professor wants we to use a multi-tier architecture (Client, Web, Business and Data tiers) with EJB. For the Web and Business I have chosen to use the MVC pattern. Anyway, little by little, I build the tiers in this way: the View (JSP and Servlet) ALWAYS forwards any request from the client to the Controller (Session Beans), which checks if the user can see the page, and if he can it sends to the Servlet the right data (taken from the Entities).

Since the MVC pattern provides an interaction between Model and View, I think that I don't use it (my View interacts only with the Controller). So I'm asking: which is the name for the pattern I'm using? Or is it still the MVC?

答:
I believe you may be actually using MVC, or a sort of MVVP, depending on what the entities you pass to the views are.

The views and model may not be interacting directly, but that depends directly on how the view accesses the data it needs (calling certain methods on the model/entities) and how the model implements its logic (which may in fact be a real model implementing data access, just a DTO or maybe a View-Model).

I would say you are still using MVC, but you are on a gray area were several things could be discussed. I could argue that you're still on an area that is MVC-like but could deviate from it.

Title: Pattern for a web application


答:
I've worked for software houses, marketing agencies, mobile phone telcos and banks, one thing I'll say, its the company's culture and industry which dictates the level of processes applied. The most rigorous, slow, restrictive and tested environment I ever experienced was in-house development for a bank. The most casual was a marketing agency.

I'd recommend learning from this experience and use it to decided your future direction for your next job. The software development industry isn't a science, its art/science hence the variation and differences from company-to-company. It's more important you learn to do things right regarding your code. Although making a mental note of the failures or lack of processes is useful, so when your manager you can implement a better processes.


问:
Introducing Programming To a Mathematician
I currently am a programmer, I'm almost 16 years of age and have pretty much narrowed my careers down to something involving a Computer Science degree or Electrical Engineering degree (I know they are quite different but this question is about my friend) but my friend isn't so sure.

He is very interested in maths and is very good at it and I think he would enjoy programming but he isn't willing to try it (edit he is willing to try but has never done before). Can anyone give me an suggestions for a language or tool that he could dabble in programming (at a reasonably basic level I assume) to solve maths problems or involve some kind of maths.

As I say he enjoys maths a lot but I think he would enjoy programming, the problem is I don't want him to be put off by the stuff that isn't relevant at introductory levels such as memory allocation et al. I know that is very important but the point is that I want him to learn a bit of programming with maths then hopefully if he is interested enough he can start learning programming as programming.

Edit:
Its not that he's completely uninterested - more that he hasn't actively explored the area before, maybe because he isn't informed about it. I wouldn't want to force him to do something he doesn't want to, I see this as more of a little push so that he can learn about programming. If he doesn't like it - fair enough, I can't control that and don't want to but if he turns out to enjoy it - this push will have been the right thing.

答:
I'm a graduate student in mathematics, and did my undergraduate in computer science. I keep a blog called Math ∩ Programming in which I explore applications of mathematics to programming (and vice versa), and I have to admit I find most of the less-mathematical aspects of computer science rather dry and uninspired (basically, my opposition to all of the ridiculous hacks that go into systems programming in my experience in industry).

On the other hand, on my blog I look at problems like facial recognition (quite a bit of linear algebra), encryption methods, Turing machines and cellular automata, models for predicting serial killer activity, search engines, and a bunch of other mathematical concepts. The best part is that I get to implement the ideas, and any of my own!

To get your friend to love programming like the rest of us do, find him a truly interesting project. The programming aspect won't stick without his working toward a product he finds beautiful. As for languages, I recommend Mathematica, Racket (a very friendly, but still powerful Scheme derivative), Python, and Haskell. Mathematica is probably the best, because he can selectively implement his own mathematical functions, and use Mathematica's built in libraries to finish the project (e.g., write a function which computes Fourier coefficients, and then use Mathematica to do the rest of the analysis, such as filtering, image generation, etc.). Even the basic topics like integration give some fascinating projects (different quadrature rules, monte carlo integration, a gentle transition into machine learning with large data sets).

Also, it seems like a lot of the responses here are from people who don't do mathematics, or who haven't used the languages they're suggesting to do mathematical software. The reason people recommend Haskell is because it's as close to a literal implementation of category theory as possible, and fits well with some mathematical definitions of some basic concepts. But if your friend is close to your age, then he is not ready for category theory mathematically (that maturity is more or less useless until graduate school, and wicked hard to teach yourself), and as a first language Haskell has the steepest learning curve of the languages suggested (perhaps Prolog is steeper). I used Haskell to implement a Javascript compiler, and I ended up with a very beautiful elegant piece of code, but for intuitive things like variable mutation, you already have to dabble in nontrivial monads.

Python and Mathematica will be much friendlier, and Mathematica has the shallowest learning curve simply because all of the libraries is packaged into a nice user interface with awesome documentation (just hit F1!). On the other hand, there is one book I have heard of (but not read) which provides both a transition to advanced mathematics and an introduction to Haskell simultaneously. It seems to have positive Amazon reviews, so you might want to check it out. He can move up to languages like C# and Java if he ever wants to do industry stuff, but more likely he'll never need to enter that jungle (and lots of industry mathematics stuff is pure Matlab anyway).

But like I said, with the right project learning the language becomes a joy, whatever the project may be.


答:
This is really a job for HAProxy. In fact, if I recall correctly he recently saturated a 10Gbs Ethernet card using haproxy on something like an old Celeron processor.

If you really want to rewrite the wheel, at least start with the HAProxy source code. Its open source.

Title: Creating crossplatform TCP proxy/gateway that would handle maximum possible clients simultaneously on 1GB ethernet pipe?

Body:
So what I wonder about is preaty simple - having in mind next architecture:

```<code>         -> computing unit "A"
        /
gateway --> computing unit "B" same as A
        \
         -> computing unit "C" same as A
</code>```

We do not care to which unit to forward request so we should forward them one by one to A than to B than to C and than to A, etc.

I wonder in what language, using what framework it is possible to create such crossplatform TCP proxy/gateway (not ethernet card dependent) that would redirect incoming requests into internal nodes via simple rool, and would be capable to get as much as possible from ethernet cable load in/out capabilety - receive and send as much as possible?

I started to wonder after I read this nice 2003 article...


问:
Create a behavior/Component based system for games

Background

I do game development as a hobby, and am looking for a better way to design them. Currently, I am using a standard OOP approach (I have been doing enterprise development for 8 years so it comes nartually). Take for example a "baddie"

```<code>public class Baddie:AnimatedSprite //(or StaticSprite if needed, which inherit Sprite)
{
    //sprite base will have things like what texture to use,
    //what the current position is, the base Update/Draw/GetInput methods, etc..
    //an AnimatedSprite contains helpers to animated the player while
    //a StaticSprite is just one that will draw whatever texture is there
}
</code>```

The problem

Lets say I am making a 2d platformer, and need the baddie to be able to Jump. Usually what I do is add the appropriate code in the Update/GetInput methods. Then if I need to make the player crawl, duck, climb, etc... the code will go there.

If I'm not careful, those methods get cluttered, so I end up creating methods pairs like this

CheckForJumpAction(Input input) and DoJump()

CheckforDuckAction(Input input) and DoDuck()

so GetInput looks like

```<code>public void DoInput(Input input)
{
    CheckForJumpAction(input);
    CheckForDuckAction(input);
}
</code>```

and Update looks like

```<code>public void Update()
{
    DoJump();
    DoDuck();
}
</code>```

If I go and create another game where the player needs to jump and duck, I usually go into a game that has the functionality and copy it over. Messy, I know. Thats I why I'm looking for something better.

Solution?

I really like how Blend has behaviors I can attach to an element. I have been thinking about using the same concept in my games. So lets look at the same examples.

I would create a base Behavior object

```<code>public class Behavior
{
    public void Update()
    Public void GetInput()
}
</code>```

And I can create behaviors using that. JumpBehavior:Behavior and DuckBehavior:Behavior

I can then add a collection of behaviors to the Sprite base and add what I need to each entity.

```<code>public class Baddie:AnimatedSprite
{
    public Baddie()
    {
        this.behaviors = new Behavior[2];
        this.behaviors[0] = new JumpBehavior();
        //etc...
    }

    public void Update()
    {
        //behaviors.update
    }

    public GetInput()
    {
        //behaviors.getinput
    }
}
</code>```

So now If I wanted to use Jump and Duck in many games, I can just bring the behaviors over. I could even make a library for the common ones.

Does it work?

What I can't figure out is how to share state between them. Looking at Jump and Duck, both affect not only the current portion of the texture being drawn, but also the state of the player. (Jump is going to apply a decrementing amount of upward force over time, while duck is just going to stop movement, change the texture and the collision size of the baddie.

How can I tie this together so it works? Should I create dependency properties between the behaviors? Should I have each behavior know about the parent and directly modify it? One thing I thought was being able to pass a delegate into each behavior to get executed when it is triggered.

I'm sure there are more issues I am looking over, but the entire purpose is for me to be able to easily reuse these behaviors between games, and entities in the same game.

So I turn it over to you. Care to explain how/if this can be done? Do you have a better idea? I'm all ears.

答: Take a look at this presentation. Sounds pretty close to the kind of pattern you're looking for. This pattern supports behaviours and attachable properties. I don't think the presentation mentions it, but you can also create attachable events. This idea is similar the dependency properties used in WPF.</p>


问:
How to build a .Net app which runs on desktop and as a Windows Service
Ok, I hope this is not too much confusing (with my poor English). I want to build a small .Net 4.0 app which monitors several other applications on a Windows Server OR on a regular Windows PC. It will have a WPF GUI with a variety of graphical controls.

The app will be used in the following scenarios:

If installed on a PC it should run as a “normal” single Windows
desktop app

If installed on a Server, it should run as a Windows Service.  To use/manage the app it must have the same WPF GUI as in scenario 1 and the GUI should be run on the Server or on a remote PC

At the moment I consider to write the application logic and connect it to the WPF GUI using a self-hosted WCF Data Service IN BOTH SCENARIOS. Since I’m not a pro developer I suppose it’s possible that I've missed something ;-)

Will this work? Are there other/better solutions? Any answer or comment is highly appreciated.

答:
You will need to write two separate parts: the service back end (which has no GUI) and the front end controller (the GUI). They will need to communicate using some form of windows interprocess communication.

Doing this as a single application may be possible, but in the windows service case it would have no GUI so still need a separate one. If you are really clever you might be able to write a single program that can be both the front and back end parts, but this probably makes the program more complicated than it needs to be.

Remember on Windows Vista and above a service has no interaction with the desktop at all.

As you say you are not a pro developer, this will be a big challenge to you. Doing what you want is complex. It is easier in .net than in plain WIN32, but be aware that your application then has a reliance on the .net framework being installed (you may need to choose your framework version carefully).


答:
Short answer: Use ZMQ

Long answer: With the input given in your question, I assume the following and have the given the short answer

You just forward the requests to the computing machines

The computing machine does the rest of the work

You want a cross platform TCP/IP framework

But there are other things to consider such as

The number of requests you would be receiving per second(1 GBPs is still big)

Is your job over only with forwarding requests to the machines because computing machines most often return results to the machine which called it (similar to master-slave nodes)

What would be the average size of your requests?

What in case you start increasing your computing machines?

Are you trying an architecture for distributed computing?

Finally and most importantly, do you need a forwarding client or a message queue?

ZMQ addresses all of the above but in my opinion, you may go for RabbitMQ if you are good with centralized message queues


答: Not sure this will be so difficult. Do your front end code as Silverlight or WPF, back end in WCF. The Silverlight oriented WCF-RIA will make most of the data plumbing fairly simple.</p>

Title: How to build a .Net app which runs on desktop and as a Windows Service

Body:
Ok, I hope this is not too much confusing (with my poor English). I want to build a small .Net 4.0 app which monitors several other applications on a Windows Server OR on a regular Windows PC. It will have a WPF GUI with a variety of graphical controls.

The app will be used in the following scenarios:

If installed on a PC it should run as a “normal” single Windows
desktop app

If installed on a Server, it should run as a Windows Service.  To use/manage the app it must have the same WPF GUI as in scenario 1 and the GUI should be run on the Server or on a remote PC

At the moment I consider to write the application logic and connect it to the WPF GUI using a self-hosted WCF Data Service IN BOTH SCENARIOS. Since I’m not a pro developer I suppose it’s possible that I've missed something ;-)

Will this work? Are there other/better solutions? Any answer or comment is highly appreciated.


问:
Advice/Approach for distilling homogenous code and building common code for a team
I work for the State of California. Our programming team in my opinion is not really a 'team' in that we usually work solo on projects throughout the application/systems complete life-cycle.

The end result is a lot of developers are 'reinventing the wheel'... writing their own data layers, even though the vast majority of us work on the same Oracle DB... writing their own security stuff... the list goes on.

I can't change the mentality of my employees, and don't have any realistic ambitions in regards to changing our team process... but my goal is to get our team to work together a little more, at least to build common building block pieces that we can all use for boilerplate functionality.

The obvious benefits are, testing and support are much more maintainable when all our users are familiar with a common piece, time to production is less when you aren't writing the same repository someone else already did, and we can focus on providing better solutions to the unique problems our apps must solve... etc.

I'm preaching to the choir, I'm sure.

The trick is, the State does not like change, neither do its employees. Managers often disregard new ideas simply because they like to avoid friction and would rather continue on as is.

There are similar questions out there, but what I am looking for is advice on how any of you may have faced a similar situation, and any direction toward getting a 'grass roots' kind of effort going to have an easier time approaching management.

EDIT:
Just to clarify a few things:

the scope I'm looking for is within the IT shop of my State Agency. I'm not trying to coordinate across several departments. Got get people off the training wheels before asking them to ride motorcycles.

Security is not much of a concern, most of our applications are internal and written in Windows Forms distributed on Citrix (ugh.) and nearly all use the same enterprise tables in Oracle... very few if any apps are "classified" so to speak. it shouldn't hinder collaboration.

I have gone so far as to setup a NuGet feed, with a couple of boilerplate pieces of code packaged, and written a few repos for Oracle, sent out some emails, but received little feedback. I've got about 1/3 of our team using ReSharper, and send emails from time to time with tips... again, not a whole lot of feedback.

答:
Could you consider teaming up with one or two of your co-workers to help start building a common framework?  That would be my suggestion for a starting point as you will need allies and some of the benefits may reveal themselves after some time working together so that things aren't so isolated.  You may have to have a few discussions with co-workers to see how receptive some are to these ideas and which are the early adopters that you could use to get this off the ground.

My main theme would be to consider baby steps here.  Little changes periodically may work just fine.


答:
The first step will be to advertise (among anyone interested and working for the same employer) what you have.

Like the faculty offices of colleges, have posters illustrating the architecture, functionality and designs of the parts you have. This is the "inventory" or "asset" of the State.

A second question is whether employers are allowed to see other's source code. If this is not allowed, collaboration will be very difficult (unless you can get support at the State level).

When it comes to security, it is likely that the State already has some information security mandates that has to be met by all projects. It may be a good starting point for standardization.

Some kind of work, esp. "customization projects", will always be solo work, because this is where they belong.

Title: Advice/Approach for distilling homogenous code and building common code for a team

Body:
I work for the State of California. Our programming team in my opinion is not really a 'team' in that we usually work solo on projects throughout the application/systems complete life-cycle.

The end result is a lot of developers are 'reinventing the wheel'... writing their own data layers, even though the vast majority of us work on the same Oracle DB... writing their own security stuff... the list goes on.

I can't change the mentality of my employees, and don't have any realistic ambitions in regards to changing our team process... but my goal is to get our team to work together a little more, at least to build common building block pieces that we can all use for boilerplate functionality.

The obvious benefits are, testing and support are much more maintainable when all our users are familiar with a common piece, time to production is less when you aren't writing the same repository someone else already did, and we can focus on providing better solutions to the unique problems our apps must solve... etc.

I'm preaching to the choir, I'm sure.

The trick is, the State does not like change, neither do its employees. Managers often disregard new ideas simply because they like to avoid friction and would rather continue on as is.

There are similar questions out there, but what I am looking for is advice on how any of you may have faced a similar situation, and any direction toward getting a 'grass roots' kind of effort going to have an easier time approaching management.

EDIT:
Just to clarify a few things:

the scope I'm looking for is within the IT shop of my State Agency. I'm not trying to coordinate across several departments. Got get people off the training wheels before asking them to ride motorcycles.

Security is not much of a concern, most of our applications are internal and written in Windows Forms distributed on Citrix (ugh.) and nearly all use the same enterprise tables in Oracle... very few if any apps are "classified" so to speak. it shouldn't hinder collaboration.

I have gone so far as to setup a NuGet feed, with a couple of boilerplate pieces of code packaged, and written a few repos for Oracle, sent out some emails, but received little feedback. I've got about 1/3 of our team using ReSharper, and send emails from time to time with tips... again, not a whole lot of feedback.


问:
How to write a command interpreter/parser?
Problem: Run commands in the form of a string.

command example:

/user/files/ list all;
equivalent to:
/user/files/ ls -la;

another one:

post tw fb "HOW DO YOU STOP THE TICKLE MONSTER?;"

equivalent to:
    post -tf "HOW DO YOU STOP THE TICKLE MONSTER?;"

Current solution:

```<code>tokenize string(string, array);

switch(first item in array) {
    case "command":
        if ( argument1 > stuff) {
           // do the actual work;
        }
}
</code>```

The problems I see in this solution are:

No error checking other than nested ifs-else inside each case. The
script becomes very big and hard to mantain.

Commands and responses are hardcoded.

No way of knowing if flags are correct or missing parameters.

Lack of intelligence to suggest "you might wanted to run $command".

And the last thing I can't address is synonyms in different encodings, example:

```<code>case command:
case command_in_hebrew:
    do stuff;
break;
</code>```

The last one might be trivial, but well, what I want to see is the solid fundations of this kind of program.

I'm currently programming this in PHP but might do it in PERL.

答:
You have not given many specifics about your grammar, just some examples. What I can see is that there are some strings, whitespace and a (probably, your example is indifferent in your question) double quoted string and then one ";" at the end.

It looks like that this could be similar to PHP syntax. If so, PHP comes with a parser, you can re-use and then validate more concretely. Finally you need to deal with the tokens, but it looks like that this is simply from left to right so actually just an iteration over all tokens.

Some examples to re-use the PHP token parser (token_get_all) are given in the answers to the following questions:

reliably convert string containing PHP array info to array

PHP dynamically accessing variable value

Both examples contain a simple parser as well, probably something like those is fitting for your scenario.

OwnerDisplayName: hakre


答:
I have written programs that work like that.  One was an IRC bot which has similar command syntax.  There is a huge file that is a big switch statement.  It works -- it works fast -- but it's somewhat difficult to maintain.

Another option, which has a more OOP spin, is to use event handlers.  You create a key-value-array with commands and their dedicated functions.  When a command is given, you check if the array has the given key.  If it does, call the function.  This would be my recommendation for new code.

Title: How to write a command interpreter/parser?

Body:
Problem: Run commands in the form of a string.

command example:

/user/files/ list all;
equivalent to:
/user/files/ ls -la;

another one:

post tw fb "HOW DO YOU STOP THE TICKLE MONSTER?;"

equivalent to:
    post -tf "HOW DO YOU STOP THE TICKLE MONSTER?;"

Current solution:

```<code>tokenize string(string, array);

switch(first item in array) {
    case "command":
        if ( argument1 > stuff) {
           // do the actual work;
        }
}
</code>```

The problems I see in this solution are:

No error checking other than nested ifs-else inside each case. The
script becomes very big and hard to mantain.

Commands and responses are hardcoded.

No way of knowing if flags are correct or missing parameters.

Lack of intelligence to suggest "you might wanted to run $command".

And the last thing I can't address is synonyms in different encodings, example:

```<code>case command:
case command_in_hebrew:
    do stuff;
break;
</code>```

The last one might be trivial, but well, what I want to see is the solid fundations of this kind of program.

I'm currently programming this in PHP but might do it in PERL.

OwnerDisplayName: FakeRainBrigand


答:
Have you already tried something like http://qntm.org/loco? This approach is much cleaner than any handwritten ad hoc, but won't require a standalone code generation tool like Lemon.

EDIT: And a general trick for handling command lines with complex syntax is to combine the arguments back into a single whitespace-separated string and then parse it properly as if it is an expression of some domain-specific language.

OwnerDisplayName: SK-logic


问:
How to : Nextag and such other dynamic data pulling website
Yesterday, I came across Nextag which is a website for comparing prices of various products from different retailers. Is this site automated?

Can the process of data pulling from various sites can be automated for comparison with each other. I tried understanding a hell lot, but could not realize this fact and now think that they ought to be manually managed because on every other retailer site, the product name was different and it was very hard to recognize a similarity for a specific product.

I have made such a system in which one can add a product and then add the respective retailers and their pricess. Every thing is manual in here. Today, I will be entering the data into the system, but thought it would be better to know if there is a way to automate this thing. Or I am going the right way as there can't be an automation for such system, because the data has no similarities.

答:
The could be a number of methods with varying difficulty:

A very advanced method could be using a web-crawler ( writing one )
to meet your specific needs of finding and pulling data from sources
that interest you/your app.

An easier approach: Find out the sources manually which provide the
relevant data. Get the RSS feeds of those websites and make your
application update its database automatically.


答:
The trouble is...

the obvious benefits

may not be so obvious to the people around you, especially if they are not devs. I've worked for both State governments and the Federal government so I can empathize with your situation. In my experience you need to show them the money. Start equating changes to numbers (e.g. metrics) and then equate metrics to money. I realize this is no fun and I realize you shouldn't have too, but this is often the way of things. All the states are in a budget crunch and showing them how they can meet greater demands without needed more money, the more attractive your ideas may become.

Along the way you may find that something you want to do sounds (or feels) better but the numbers don't support you. If that happens, you may be embarking on a technology religious debate which can really upset; or completely derail; other progress you’re making. In that case, give it up and move on to the next idea. Come back to those once everyone is more open to changes.

For metrics... start with the classics, they work well in most cases.

Time / Schedules (Could include performance of the system)

Money (Spent and Saved)

Material

Defects (Rates, Severity, Visibility to end-users)

Reliability (in government terms this is Ao [Operational Availability] and MTBF Mean Time Between Failures)

Good Luck!


答:
Such applications face two important challenges:

Gathering the data, and

Making sense of the data.

Gathering the data

A variety of techniques may be employed, depending on what's supported by each source site:

Simple web crawler

Anything from a simple curl script to a full fledged custom web crawler.

Web services

The optimal way, if source site supports them. Any kind of web service, from RSS to SOAP, that's their point, to provide a method of communication between two sites over the web.

Black magic stuff

Depending on the relation of the source and target sites, this can be anything really. I've seen one site that literally send SQL dumps of it's database to another site, via ftp. That's definitely not recommended, but it's a good example of a weird counter-intuitive approach you never thought existed, until you saw it with your own eyes.

By hand

Obviously not recommended. But under very specific circumstances and for very small sets of data it might prove to be the optimal solution.

The automated techniques commonly require some time-based background process, and for websites the obvious example is a cron script. Scheduling plays an important part in the process as you need to schedule the gathering process(es) according to:

How often products are modified (created / deleted)

How often product information is modified

Bandwidth restrictions (on your site and each source site)

I've separated 2 from 1, as I've seen them treated as separate processes, with different workflows and scheduling. For example I've worked on a similar site that had a vendor that added new products only on Mondays. So we only checked on Tuesdays, at 00:00.

Making sense of the data

This is where the fun begins! Heterogeneous data is always a blast to work with! Every bit of data you gather will most probably follow a unique structure. If you are lucky enough to gather the data via a web service, chances are that their structures will make sense and you can build a combined index relatively easy.

But if there's at least one site you have to crawl, or its web service structure doesn't really makes sense, then your index is not going to be that easy to build. The most common problem is the one you've identified:

For example, in case of iPhone, some websites name Apple iPhone, while some name it iPhone 4S. How can one make sure that the sync is maintained.

There's no single answer to that, it depends on data size, volume, complexity etc. It can be as simple as building and maintaining an associative index by hand:

```<code>tokenA1 == tokenB1 == token1
tokenA2 == tokenB5 == token2
tokenA5 == tokenB2 == token3
</code>```

or as complex as building a custom algorithmic solution to discover the associations automatically. Some relevant buzzwords are:

Pattern matching:

In computer science, pattern matching is the act of checking some sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact. The patterns generally have the form of either sequences or tree structures.

Pattern recognition:

In machine learning, pattern recognition is the assignment of some sort of output value (or label) to a given input value (or instance). An example of pattern recognition is classification, which attempts to assign each input value to one of a given set of classes (for example, determine whether a given email is "spam" or "non-spam")

Information extraction:

Information extraction (IE) is a type of information retrieval whose goal is to automatically extract structured information from unstructured and/or semi-structured machine-readable documents. In most of the cases this activity concerns processing human language texts by means of natural language processing (NLP).

Document retrieval:

Document retrieval is defined as the matching of some stated user query against a set of free-text records. These records could be any type of mainly unstructured text, such as newspaper articles, real estate records or paragraphs in a manual.

Statistical classification:

In machine learning, statistical classification is the problem of identifying the sub-population to which new observations belong, where the identity of the sub-population is unknown, on the basis of a training set of data containing observations whose sub-population is known. Therefore these classifications will show a variable behaviour which can be studied by statistics.

Data mining:

Data mining (the analysis step of the knowledge discovery in databases process,1 or KDD), a relatively young and interdisciplinary field of computer science2 is the process of discovering new patterns from large data sets involving methods at the intersection of artificial intelligence, machine learning, statistics and database systems

One algorithm (or variation of1) I've seen used in a somewhat comparable scenario is the k-nearest neighbor algorithm:

In pattern recognition, the k-nearest neighbor algorithm (k-NN) is a method for classifying objects based on closest training examples in the feature space.

Normally, it won't be that hard, my intention is more to illustrate the spectrum of possible solutions than pinpointing an optimal solution. There isn't a single one, the optimal solution will be different for each target site and almost in every scenario you'll need to mix and match.

A possible solution of average difficulty that would work for a wide range of source sites could be build around a text search engine / information retrieval library, like Apache Lucene, or even just a few well written regular expressions.

And of course, to make matters worse, there isn't a single workflow. The simplest I can think of are:

Gather the data first, then analyse,

Analyse the data while gathering.

Which highly depends on your data storage, and it might even depend on your hardware. It will also depend on how you gather the data, multiple requests for lots of data pose the risk of hurting the target site, so the workflow may even be different per site.

It's a grand mess! Make sure you ask for a lot of money if ever involved in such a project...

1 To be perfectly honest it might have been something different entirely, at the time I was told it was a naive nearest neighbor search, but was too young and impressionable to deeply investigate. It worked, though, and it looked like NNS.

Title: How to : Nextag and such other dynamic data pulling website

Body:
Yesterday, I came across Nextag which is a website for comparing prices of various products from different retailers. Is this site automated?

Can the process of data pulling from various sites can be automated for comparison with each other. I tried understanding a hell lot, but could not realize this fact and now think that they ought to be manually managed because on every other retailer site, the product name was different and it was very hard to recognize a similarity for a specific product.

I have made such a system in which one can add a product and then add the respective retailers and their pricess. Every thing is manual in here. Today, I will be entering the data into the system, but thought it would be better to know if there is a way to automate this thing. Or I am going the right way as there can't be an automation for such system, because the data has no similarities.

Body:
Such applications face two important challenges:

Gathering the data, and

Making sense of the data.

Gathering the data

A variety of techniques may be employed, depending on what's supported by each source site:

Simple web crawler

Anything from a simple curl script to a full fledged custom web crawler.

Web services

The optimal way, if source site supports them. Any kind of web service, from RSS to SOAP, that's their point, to provide a method of communication between two sites over the web.

Black magic stuff

Depending on the relation of the source and target sites, this can be anything really. I've seen one site that literally send SQL dumps of it's database to another site, via ftp. That's definitely not recommended, but it's a good example of a weird counter-intuitive approach you never thought existed, until you saw it with your own eyes.

By hand

Obviously not recommended. But under very specific circumstances and for very small sets of data it might prove to be the optimal solution.

The automated techniques commonly require some time-based background process, and for websites the obvious example is a cron script. Scheduling plays an important part in the process as you need to schedule the gathering process(es) according to:

How often products are modified (created / deleted)

How often product information is modified

Bandwidth restrictions (on your site and each source site)

I've separated 2 from 1, as I've seen them treated as separate processes, with different workflows and scheduling. For example I've worked on a similar site that had a vendor that added new products only on Mondays. So we only checked on Tuesdays, at 00:00.

Making sense of the data

This is where the fun begins! Heterogeneous data is always a blast to work with! Every bit of data you gather will most probably follow a unique structure. If you are lucky enough to gather the data via a web service, chances are that their structures will make sense and you can build a combined index relatively easy.

But if there's at least one site you have to crawl, or its web service structure doesn't really makes sense, then your index is not going to be that easy to build. The most common problem is the one you've identified:

For example, in case of iPhone, some websites name Apple iPhone, while some name it iPhone 4S. How can one make sure that the sync is maintained.

There's no single answer to that, it depends on data size, volume, complexity etc. It can be as simple as building and maintaining an associative index by hand:

tokenA1 == tokenB1 == token1
tokenA2 == tokenB5 == token2
tokenA5 == tokenB2 == token3

or as complex as building a custom algorithmic solution to discover the associations automatically. Some relevant buzzwords are:

Pattern matching:

In computer science, pattern matching is the act of checking some sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact. The patterns generally have the form of either sequences or tree structures.

Pattern recognition:

In machine learning, pattern recognition is the assignment of some sort of output value (or label) to a given input value (or instance). An example of pattern recognition is classification, which attempts to assign each input value to one of a given set of classes (for example, determine whether a given email is "spam" or "non-spam")

Information extraction:

Information extraction (IE) is a type of information retrieval whose goal is to automatically extract structured information from unstructured and/or semi-structured machine-readable documents. In most of the cases this activity concerns processing human language texts by means of natural language processing (NLP).

Document retrieval:

Document retrieval is defined as the matching of some stated user query against a set of free-text records. These records could be any type of mainly unstructured text, such as newspaper articles, real estate records or paragraphs in a manual.

Statistical classification:

In machine learning, statistical classification is the problem of identifying the sub-population to which new observations belong, where the identity of the sub-population is unknown, on the basis of a training set of data containing observations whose sub-population is known. Therefore these classifications will show a variable behaviour which can be studied by statistics.

Data mining:

Data mining (the analysis step of the knowledge discovery in databases process,1 or KDD), a relatively young and interdisciplinary field of computer science2 is the process of discovering new patterns from large data sets involving methods at the intersection of artificial intelligence, machine learning, statistics and database systems

One algorithm (or variation of1) I've seen used in a somewhat comparable scenario is the k-nearest neighbor algorithm:

In pattern recognition, the k-nearest neighbor algorithm (k-NN) is a method for classifying objects based on closest training examples in the feature space.

Normally, it won't be that hard, my intention is more to illustrate the spectrum of possible solutions than pinpointing an optimal solution. There isn't a single one, the optimal solution will be different for each target site and almost in every scenario you'll need to mix and match.

A possible solution of average difficulty that would work for a wide range of source sites could be build around a text search engine / information retrieval library, like Apache Lucene, or even just a few well written regular expressions.

And of course, to make matters worse, there isn't a single workflow. The simplest I can think of are:

Gather the data first, then analyse,

Analyse the data while gathering.

Which highly depends on your data storage, and it might even depend on your hardware. It will also depend on how you gather the data, multiple requests for lots of data pose the risk of hurting the target site, so the workflow may even be different per site.

It's a grand mess! Make sure you ask for a lot of money if ever involved in such a project...

1 To be perfectly honest it might have been something different entirely, at the time I was told it was a naive nearest neighbor search, but was too young and impressionable to deeply investigate. It worked, though, and it looked like NNS.


问:
Forward and backward fourier transform image in java
Can anyone suggest a java library to perform forward and backward Fourier transform on images? Either RGB or gray-scale or binary , that doesn't matter since I've converted the image to all these ;)

I do searched but most of the image processing libraries like marvin, JAI etc don't have Fourier transform. So I thought anyone who have done this earlier could suggest me one

答:
JAI (Java Advanced Imaging API) has classes DFTDescriptor and IDFTDescriptor which seem to match.

API docs for DFTDescriptor describe it as follows:

...The "DFT" operation computes the discrete Fourier transform of an image.

for inverse transform, there is IDFTDescriptor:

...The "IDFT" operation computes the inverse discrete Fourier transform of an image.


答: JTransforms is probably the fastest Java FFT library around. It's a generic (not particularly "image") DFT (and DCT and DST and DHT) transformer and works on double[] arrays so you would need to implement the image -> double[] -> image transforms yourself though.

Title: Forward and backward fourier transform image in java

Body:
Can anyone suggest a java library to perform forward and backward Fourier transform on images? Either RGB or gray-scale or binary , that doesn't matter since I've converted the image to all these ;)

I do searched but most of the image processing libraries like marvin, JAI etc don't have Fourier transform. So I thought anyone who have done this earlier could suggest me one