问:
What techniques help retain programming knowledge?
How do you remember programming related stuff? Have you had the feeling that you've encountered the error you have before you right now, a few years ago and you could swear you knew the cause then but now you've forgotten it?

Did you work with the xsl's string parsing some time ago but now you can't remember exactly which are the string functions altogether from xsl and you have to start from scratch? Or perhaps you forget about some feature from Apache Commons like "filtering a collection by some predicate" that you surely used in the past.

So how do you do it? I tried having a blog but when I develop apps, I never find the time to update the blog or write about my experiences. Also, using a wiki is a nice thing but then I found it difficult to keep a clean separation between them since many times I needed to change a blog post to add new information about that topic. This made me think that I actually should have put this topic in the wiki instead of the blog.

Do you have any systems that help you remember about your programming experience? What's your setup?

答:
Forgetting things is normal. Not remembering some tricks that helped you in the past is also normal. This is the first step one should acknowledge. Then there are some ways you can "store" knowledge for further revision:

Find time and blog about it. The future-you will be very thankful to the present-you;

Work with tiny demos and archive them in some way. You will surely step through this archive many times;

Make use of your stackexchange profile. Mark interesting questions/problems/issues/tips/tricks as favorites for further investigation;

Keep doing, keep programming. The more you use a certain part of a framework, the more you familiarize with it and the more you remember.


问:
Advantages of using business logic in model
In an MVC framework i have often heard that use business logic in a model. But i think using the business logic in controller would run faster as view is directly connected to controller. I want to know what are the advantages of using a business logic in model?</p>

答:
The key is:

Separation of concerns

In an ideal world you want any given piece of code to do one thing and to do that well. So you want to try and avoid mixing up display logic and business logic and storage logic and everything else.

This separation provides a variety of benefits - testability (as suggested) is an important one (though to my mind it's almost a bonus), but also the fact that the code should be easier to understand at any given level and hence easier to maintain, that the business model/logic (in particular) is more portable (from web to native app) or that you can change the UX (say from MVC pages to a fully separated javascript app using a web API) - finally, if nothing else, the cummulative experience of a huge number of programmers tells us that it - separation of concerns - is a good thing.

On contemporary server hardware performance just shouldn't be an issue unless you're doing seriously funky stuff and then you don't want to have bound up in the user interface layers because you can't then attempt to deal with the performance issues in isolation.

ContentLicense: CC BY-SA 3.0


答:
Well, maybe my case is particular ... but : I have every scrap of software i wrote since 76 on my laptop, programs, scripts, configurations, etc. So over time (must confess), my memory burden has shifted from remembering 'stuff' to remembering meta-data about stuff. Sure, a lot of it is not relevant anymore, but what i find that the hard part is having the ideas, not actually implementing them. So meta-data is basically an index of what 'ideas' can be found where.

When I hit new turf, nowadays, i tend to find some large code base that uses the new aspects, and spend some quality time with the code base. I study it, try to make it work in a test environment, then try to augment it so I can ease into new tools (libraries, languages, build technology, etc...). This process allows me to map out my patterns, ideas, onto an example. I may take time to do a few such mini-projects, and pick as a reference the one with which i feel the most at home. Once that is done, I will eventually re-purpose that code base to build the skeleton of my own apps.

When personal archives fail, i hit the net, to which i recently added SO. I will get a hit on 'new' concepts (new from a personal standpoint) on SO before gaagle. In fact, i rarely (nowadays) return to gaagle. The First relevant answer on there is typically a link to some interesting questions on SO.

Title: What techniques help retain programming knowledge?

Body:
How do you remember programming related stuff? Have you had the feeling that you've encountered the error you have before you right now, a few years ago and you could swear you knew the cause then but now you've forgotten it?

Did you work with the xsl's string parsing some time ago but now you can't remember exactly which are the string functions altogether from xsl and you have to start from scratch? Or perhaps you forget about some feature from Apache Commons like "filtering a collection by some predicate" that you surely used in the past.

So how do you do it? I tried having a blog but when I develop apps, I never find the time to update the blog or write about my experiences. Also, using a wiki is a nice thing but then I found it difficult to keep a clean separation between them since many times I needed to change a blog post to add new information about that topic. This made me think that I actually should have put this topic in the wiki instead of the blog.

Do you have any systems that help you remember about your programming experience? What's your setup?


答:
"Remember the painting, forget the fine strokes"

It is absolutely normal not to remember the finer details. However what you should worry about is forgetting the major things. If you fixed a bug you should at least have a conceptual idea about what the issue was.

Bookmarks, blogs, notebooks are all fine for storing away those finer details. But ultimately you still need to remember the bigger "picture". Otherwise re-discovering those "finer" details  will be that much harder.


答:
Everyone may have his own style that he/she is used to it, For me, I separate knowledge in categories:

Books

Articles

Collections (Stuff I find interesting limited to few paragraphs - I actually copy the information and sometimes annotate the source) - For example: OODevelopment, Generics,...etc.

Re-usable code (text and snippets) - Each on a separate file under a good tree organization. E.g. DataValidation node would contain many techniques for validating different data items, each in a separate file

Completed projects

Personal Video Tutorials (I sometimes record videos of how to do things when too many steps are involved).

Links

I organize the above by subject, with each subject in an appropriate tree structure.

Some times there are overlapping things but I manage to find what I want.

Also, using Google Desktop, finding text or files is very fast.


问:
Is there any evidence that graphic interfaces tend to mess with SVN- and Git-repositories?
In my company I am faced with assertion that graphic interfaces for VCSs like SVN or (especially) Git tend to mess repositories - especially regarding branching.

Being a passionate Windows and GUI user, I have a hard time believing this is true.

For Git especially, I accept that some moves are too complex for conduction via a GUI. But what is the real background of this accusation?

答: Ignorance. Since that answer is too short, TortoiseSVN and TortoiseGit served me well until I saw the light and started using the shell, but that doesn't mean either tool is simple to use. If you don't understand the underlying functionality, the leaky abstractions and information hiding that is necessary to make a GUI which is more user friendly than the shell equivalent makes it really difficult to understand what is really going on below.


问:
Odd company release cycle: Go Distributed Source Control?
Sorry about this long post, but I think it is worth it.

I have just started with a small .NET shop that operates quite a bit differently to other places that I have worked. Unlike any of my previous positions, the software written here is targeted at multiple customers and not every customer gets the latest release of the software at the same time. As such, there is no "current production version." When a customer does get an update, they also get all of the features added to the software since their last update, which could be a long time ago. The software is highly configurable and features can be turned on and off: so called "feature toggles." Release cycles are very tight here, in fact they are not on a schedule: when a feature is complete the software is deployed to the relevant customer.

The team only last year moved from Visual Source Safe to Team Foundation Server. The problem is they still use TFS as if it were VSS and enforce Checkout locks on a single code branch. Whenever a bug fix gets put out into the field (even for a single customer) they simply build whatever is in TFS, test the bug was fixed and deploy to the customer! (Myself coming from a pharma and medical devices software background this is unbelievable!). The result is that half baked dev code gets put into production without being even tested. Bugs are always slipping into release builds, but often a customer who just got a build will not see these bugs if they don't use the feature the bug is in. The director knows this is a problem as the company is starting to grow all of a sudden with some big clients coming on board and more smaller ones.

I have been asked to look at source control options in order to eliminate deploying of buggy or unfinished code but to not sacrifice the somewhat asynchronous nature of the teams releases.  I have used VSS, TFS, SVN and Bazaar in my career, but TFS is where most of my experience has been.

Previously most teams I have worked with use a two or three branch solution of Dev-Test-Prod, where for a month developers work directly in Dev and then changes are merged to Test then Prod, or promoted "when its done" rather than on a fixed cycle. Automated builds were used, using either Cruise Control or Team Build. In my previous job Bazaar was used sitting on top of SVN: devs worked in their own small feature branches then pushed their changes to SVN (which was tied into TeamCity). This was nice in that it was easy to isolate changes and share them with other peoples branches.

With both of these models there was a central dev and prod (and sometimes test) branch through which code was pushed (and labels were used to mark builds in prod from which releases were made...and these were made into branches for bug fixes to releases and merged back to dev). This doesn't really suit the way of working here, however: there is no order to when various features will be released, they get pushed when they are complete.

With this requirement the "continuous integration" approach as I see it breaks down. To get a new feature out with continuous integration it has to be pushed via dev-test-prod and that will capture any unfinished work in dev.

I am thinking that to overcome this we should go down a heavily feature branched model with NO dev-test-prod branches, rather the source should exist as a series of feature branches which when development work is complete are locked, tested, fixed, locked, tested and then released. Other feature branches can grab changes from other branches when they need/want, so eventually all changes get absorbed into everyone elses. This fits very much down a pure Bazaar model from what I experienced at my last job.

As flexible as this sounds it just seems odd to not have a dev trunk or prod branch somewhere, and I am worried about branches forking never to re-integrate, or small late changes made that never get pulled across to other branches and developers complaining about merge disasters...

What are peoples thoughts on this?

A second final question: I am somewhat confused about the exact definition of distributed source control: some people seem to suggest it is about just not having a central repository like TFS or SVN, some say it is about being disconnected (SVN is 90% disconnected and TFS has a perfectly functional offline mode) and others say it is about Feature Branching and ease of merging between branches with no parent-child relationship (TFS also has baseless merging!). Perhaps this is a second question!

答:
Ad main question: I believe what you are talking about is exactly what git successful branching model (and the helper tool git flow to support it) is about. Have a master branch, that is always in deployable state and do all work on feature branches.

You can also use the process used by git itself, which is derived from the same basic principle. In git-core development, all work happens on feature branches. The feature branches are submitted to integrator, who runs a script to merge all of them to create a branch named pu (proposed updates). Various people take this branch and work with it to test it.

Instead of integrator, you can have continuous integration server do this merge at the begining of a build. That way whenever anybody of the team pushes changes to the central repository as a feature branch (probably using some naming convention to tell which branches should be selected).

In git the feature branch than proceeds to next, master or maint depending on which release it's targeting at (maint is for bugfixing current release, master for current in-preparation release and next for the one after that), but you won't have that many.

While the features are in pu ("cooking" in git maintainer's terminology), they are rewound and the pu branch is discarded and created again each time, which makes it easier to review, but unsuitable for basing other work on. When the feature branch is merged into one of the mainlines, it is closed for rewinds and further fixes are done as new commits.

I personally would recommend git best. It's a bit harder to learn initially, because it grows more organically, but in the end it seems most flexible. But any of the three distributed systems, git, mercurial and bazaar will serve you well (and you can often even mix them, e.g. mercurial can pull and push to/from git repository and I believe so can bazaar).

Ad second question: I was taught that "distributed", in general, means that you can move objects around and they keep their identity. Which is exactly what distributed version control does: you clone the repository and it contains the same commits and allows doing the same things with them. The ease of branching and the disconnected operation are the main user-level features that follow from the principle of moving commits around and the directed graph layout that allows it.


答:
In my experience, a well designed GUI front end, like TortoiseHG doesn't in itself cause problems, what does cause problems however are user misunderstandings and inattentiveness.

I use thg as an example because my exposure to TortoiseSVN and TortoiseGit is limited.

With a GUI tool, it is very easy for an inexperienced user not to notice that the tool is going to do something they don't expect. For instance, with Mercurial, you can have an arbitrary number of unnamed remote heads. Normally Hg will complain if you try to push an unnamed remote head, but if you have the 'force push' option checked in the GUI, it won't complain and just push up the head anyway. This can result in confusion as people wonder what is this branch for, is it stable and should I be using it?.

With a command line tool, such situations will result in an error or warning being displayed and the users will need to understand the error in order to work out how to either correct the error (merge in the branch that is causing the error) or ignore it (rename the branch so it's purpose is obvious and then force the push if it shouldn't be merged right now).

Ultimately, while GUI tools make it easier to get started with a VCS, they are not a substitute for understanding how the VCS actually works. This is why many people recommend learning the command line first and then migrating certain tasks to GUI tools later to optimise your workflow.

Title: Is there any evidence that graphic interfaces tend to mess with SVN- and Git-repositories?

Body:
In my company I am faced with assertion that graphic interfaces for VCSs like SVN or (especially) Git tend to mess repositories - especially regarding branching.

Being a passionate Windows and GUI user, I have a hard time believing this is true.

For Git especially, I accept that some moves are too complex for conduction via a GUI. But what is the real background of this accusation?


答:
Like others, I keep track of things using bookmarks.

I used to use Delicious, but have now moved to Pinboard.

But I don't use this way as much as I used to. It seems like every programming problem I come across is a small google search away. And in the last year or so, I've started using Stackoverflow as one of my search terms!

Whenever I come acoss a SO question for a particularly difficult issue, I favourite it to track it so this is another form of bookmarking.


问:
As a Europe-based company, is it possible to write a custom iPad application for a customer?
Our customer wants us to write a custom application for him that he can use on a handful of iPads in his company. This application is probably only useful for this one customer (maybe for two or three more in the future, but only after additional customization).

I read that if the customer subscribes to Apple's Volume Purchasing Program, we are able to provide him with a custom B2B application. This, however, seems to be restricted to US developers (or customers? or both?).

What are the alternatives for Europe-based (or, more generally, non-US) software developers and their local customers?

答:
The "correct" solution to this is that your client creates an Enterprise Account with Apple to develop in-house apps. You create that app and sign it with profile/identity of your client.

Yes, your client will have to pay a (rather small) yearly fee. But with any luck they will want more apps anyway. :)

You could of course create the Enterprise account for yourself, telling Apple that you'd develop for yourself and use it to distribute that app to any clients that want to go this way. You won't set up a shop system anyway and Apple would probably not notice or care. But it would be a breach of the Enterprise Account contract and thereby I do NOT recommend doing this. Your client will probably gladly pay the yearly developer fee.


答:
What defines a DVCS?

The distributed in DVCS means that every clone of a repository has all of the information required to commit, update, branch, merge or search for any revision in that repository, without ever touching a server. The only thing you can do offline in svn is actually edit the files - you need server access for almost all svn commands, including doing something as simple as grepping an svn log, so it is actually closer to 0% than to 90%!

Any authoritative central repository that you might set up in a DVCS workflow is just another clone, and the only time you need to interact with it are when you pull down other peoples updates or when you push your own changes so that other people can see them, pretty much everything else can be done off-line.

What branching model is appropriate?

I've been in the situation you are in right now. Such systems can be a real pain but you have to understand the pragmatic reasons they became like this and realise that they are not beyond redemption. Many tools have been developed which can help manage this sort of complexity.

First of all, whatever you do, don't show people the successful git branching model, it will just confuse them and turn them off. Instead, develop your own model that reflects your existing workflow, yet solves the problems with your existing workflow.

Some resources which you may want to consider include things like git submodules which will allow different customer releases to specify different combinations of customer configuration, application modules and libraries. Another option would be the use of a patch management system to apply customer/product specific patch queues.

Both of these options will provide much greater flexibility, transparency and safety than your current workflow, and could be easier to use than an even more complex branch only strategy. I certainly wish I'd has access to these tools when I was in your situation.

For more information on these options, see my answers to Strategy to use version control on a modular system, How to Use Subversion Repository Inside Git Repository? and Source/Version control for application used by multiple companies.

Ultimately, this is really something you will have to develop with the rest of the team. If you have the vision to propose something which works better then what you already have, and can get the buy-in of your fellow developers, then you will have a much easier time of it.

The most important thing is to show your colleagues how what you propose will make their lives easier. Once they are convinced, you stand a much better chance of getting management to throw away their investment in TFS and start using a model more appropriate to your working methods.

Title: Odd company release cycle: Go Distributed Source Control?

Body:
Sorry about this long post, but I think it is worth it.

I have just started with a small .NET shop that operates quite a bit differently to other places that I have worked. Unlike any of my previous positions, the software written here is targeted at multiple customers and not every customer gets the latest release of the software at the same time. As such, there is no "current production version." When a customer does get an update, they also get all of the features added to the software since their last update, which could be a long time ago. The software is highly configurable and features can be turned on and off: so called "feature toggles." Release cycles are very tight here, in fact they are not on a schedule: when a feature is complete the software is deployed to the relevant customer.

The team only last year moved from Visual Source Safe to Team Foundation Server. The problem is they still use TFS as if it were VSS and enforce Checkout locks on a single code branch. Whenever a bug fix gets put out into the field (even for a single customer) they simply build whatever is in TFS, test the bug was fixed and deploy to the customer! (Myself coming from a pharma and medical devices software background this is unbelievable!). The result is that half baked dev code gets put into production without being even tested. Bugs are always slipping into release builds, but often a customer who just got a build will not see these bugs if they don't use the feature the bug is in. The director knows this is a problem as the company is starting to grow all of a sudden with some big clients coming on board and more smaller ones.

I have been asked to look at source control options in order to eliminate deploying of buggy or unfinished code but to not sacrifice the somewhat asynchronous nature of the teams releases.  I have used VSS, TFS, SVN and Bazaar in my career, but TFS is where most of my experience has been.

Previously most teams I have worked with use a two or three branch solution of Dev-Test-Prod, where for a month developers work directly in Dev and then changes are merged to Test then Prod, or promoted "when its done" rather than on a fixed cycle. Automated builds were used, using either Cruise Control or Team Build. In my previous job Bazaar was used sitting on top of SVN: devs worked in their own small feature branches then pushed their changes to SVN (which was tied into TeamCity). This was nice in that it was easy to isolate changes and share them with other peoples branches.

With both of these models there was a central dev and prod (and sometimes test) branch through which code was pushed (and labels were used to mark builds in prod from which releases were made...and these were made into branches for bug fixes to releases and merged back to dev). This doesn't really suit the way of working here, however: there is no order to when various features will be released, they get pushed when they are complete.

With this requirement the "continuous integration" approach as I see it breaks down. To get a new feature out with continuous integration it has to be pushed via dev-test-prod and that will capture any unfinished work in dev.

I am thinking that to overcome this we should go down a heavily feature branched model with NO dev-test-prod branches, rather the source should exist as a series of feature branches which when development work is complete are locked, tested, fixed, locked, tested and then released. Other feature branches can grab changes from other branches when they need/want, so eventually all changes get absorbed into everyone elses. This fits very much down a pure Bazaar model from what I experienced at my last job.

As flexible as this sounds it just seems odd to not have a dev trunk or prod branch somewhere, and I am worried about branches forking never to re-integrate, or small late changes made that never get pulled across to other branches and developers complaining about merge disasters...

What are peoples thoughts on this?

A second final question: I am somewhat confused about the exact definition of distributed source control: some people seem to suggest it is about just not having a central repository like TFS or SVN, some say it is about being disconnected (SVN is 90% disconnected and TFS has a perfectly functional offline mode) and others say it is about Feature Branching and ease of merging between branches with no parent-child relationship (TFS also has baseless merging!). Perhaps this is a second question!


答:
My key is

Variety

Repetition.  Once can be fleeting.  Seeing the 100th occurrence makes a difference!

Memory by fingers.  I remember code much better when I've actually typed it a few times.

Code Library - Keep a personal stash of code and tricks you have used and seen.

Centralization.  I keep 1 file with all my usernames (hundreds) on 1 pc.  I apply security to it.

Discipline - you mentioned not have time / making the effort to update your own blog, etc.  That you just have to work harder on and make sure you do it.

Acceptance - skills and techniques and things you learned lass week will be fresh.  Some of the items you say 3 years ago will be hard to remember.  That's normal as the brain makes room for more.

Multiple senses - sometimes I use mnemonics, sometimes I drop a picture with key concepts drawn in distinctive ways.  I read, I listen to podcasts, I watch video's, I use color in editors.  The more sense I use the better.

Mnemonics, e.g. css border order Tarball (TaRBalL) TopRightBottomLeft. I also use colors and shapes to remember words and themes.  Often the more bizarre, the more memorable!

Continued Use- This is the 'use it or lose it' effect.  All knowledge fades over time.  Time++ Fade++

The Stack Exchange Network -
I'm using Stack Overflow in multiple areas to try and keep as many different skills and techniques 'current' and 'remembered' even if I'm not using them in my current job/project.

Dropbox -  I keep commnon small files with memory related items

Books - I still like the fool and feel of physical books.  I also have multiple kindles and other on-line technical books that I can refer to anywhere.  Obviously my technical library can be accessible anywhere when it is digital which is huge.

The Google effect - no list of items would really be complete without mentioning this.  This is more about what you don't need to remember - because you can google it and find it.  This is an important consideration too.  As more people become more adept at this way of getting knowledge the need to actually memorize any given fact is falling.  However this is also 'raising the bar' for knowledge workers who are finding more and more that a deep conceptual understanding is required to perform in the current environment.  Of course which out for CME's!

My own Blog

My own bookmarks site.

How do I keep my blog and my bookmarks updated?  Well at the end of the day I think it is discipline and niftyness, i.e. yes, there is a certain amount of dedication required for it.  However if you went to school for a degree and paid $100,000 (or even $10,000) or you are self-taught, you know the meaning of dedication and persistence.  This is no different.  The niftyness, or 'nifty factor' is that when you see a cool web site with a cool tutorial or technique or whatever, or you overcome a tough thorny problem, you go "hey that's nifty!" - so when you feel this (or whatever catchphrase you use), now associate that with "I must blog that or record that bookmark".  There's a good chance you're not at a pc, updating your blog at that very moment, so send yourself an email, or a text or even a voicemail, or a new task in your task list - whatever works for you - to remind yourself to do it!  For instance my android phone has a tasks app that is useful for this.


问:
Is it better to build HTML Code string on the server or on the client side?
The result of the following process should be a html form. This form's structure varies from one to user. For example there might be a different number of rows or there may be the need for rowspan and colspan.

When the user chooses to see this table an ajax call is made to the server where the structure of the table is decided from the database. Then I have to create the html code for the table structure which will be inserted in the DOM via JavaScript.

The following problem comes to my mind: Where should I build the HTML code which will be inserted in the DOM? On the server side or should I send some parameters in the ajax call method and process the structure there?

Therefore the main question involves good practice when it comes to decide between Server side processing or client side processing.

Thank you!

答: Definitely server side.  If you do it server side, you will be able to take advantage of many more programming tools and libraries to do this sort of task.  The processing for this task could get really complicated as the types of forms you want to create get more and more complex and the number of different types of forms gets greater and greater, so you'd really be limiting yourself by handling it client-side.</p>


问:
Extra class for writing data to some backend?
What is the common practice to write classes which take some data class and store it to some backend? In my case I have table classes (columns, headers, etc.) which are written to Excel. So I have a class Table with the data and a class ExcelDocument with access operations and basic writing (cells, ...).

Where would I put the code which knows how to deal with Table data and knows how to write that the ExcelDocument? Both might be subject to refactoring at some point.

Do I use Table.write_to_excel(excel) or ExcelDocument.write_table(table) or even some need intermediate class?
With the concept "a class should serve just one purpose" I'd most likely write an intermediate class?

答:
You're right, those classes should serve a single purpose as they represent your model.  You should write a service class that transforms one of those classes into the other when necessary.

Structurally, service classes and model classes are the same, but they are there to define the seperate concerns of different tiers of an MVC implementation, for instance.  A concrete service class defines the API of an external service, like transforming a data table into an excel spreadsheet, and a model class defines the API of the application's data model.

So, while the base classes may be similar, the concrete classes created by extending these base classes serve two entirely different purposes.


答:
I would consider modeling your output format as a separate class. In other words, go with your ExcelDocument idea. This lends itself well to the something like the Strategy pattern if you need to support multiple back end formats, now or in the future.

You would have an interface that defines the operations that you perform on the data store, such as reading and writing. You then implement that interface in a number of subclasses, each designed to handle a specific type of backend, such as CSV files, Excel XLS files, insert-flavor-here SQL database. If you only have one output now, you don't necessarily need the interface, but if you know for sure that you'll be adding more formats in the future, take care of the class hierarchy now.

Of course, it does depend on how complex these actions are. You might favor decomposing into both "reader" and "writer" classes instead of putting everything in one. This might also be more in line with the Single Responsibility Principle.

Title: Extra class for writing data to some backend?

Body:
What is the common practice to write classes which take some data class and store it to some backend? In my case I have table classes (columns, headers, etc.) which are written to Excel. So I have a class Table with the data and a class ExcelDocument with access operations and basic writing (cells, ...).

Where would I put the code which knows how to deal with Table data and knows how to write that the ExcelDocument? Both might be subject to refactoring at some point.

Do I use Table.write_to_excel(excel) or ExcelDocument.write_table(table) or even some need intermediate class?
With the concept "a class should serve just one purpose" I'd most likely write an intermediate class?


答:
You can approach this problem with a dependency injection mindset:  The table should expose an interface that it requires to write itself to a persistent store.

You could pass this into the Table constructor:

```<code>Table(ITableWriter tableWriter)
{
    _tableWriter = tableWriter;
}
</code>```

And then Table implements something like:

```<code>void Write(string writeID)
{
    //for all rows in the table
    _tableWriter.Write(writeID, rowToWrite);
}
</code>```

Then your calls could be:

```<code>var excelWriter = new ExcelWriter(); // implements ITableWriter
var table = new Table(excelWriter);
table.Write("DocumentName");
</code>```

The trick is then to define the ExcelWriter class that implements the ITableWriter interface, with the deliverable being an Excel document.

That way, should you need to write the table somewhere else (to another database? to a flat file?) you won't have to change the Table class, just produce another implementation of the ITableWriter interface.

As added bonus, you can mock the ITableWriter interface for separate testing of your Table class.

Body:
You can approach this problem with a dependency injection mindset:  The table should expose an interface that it requires to write itself to a persistent store.

You could pass this into the Table constructor:

Table(ITableWriter tableWriter)
{
    _tableWriter = tableWriter;
}

And then Table implements something like:

void Write(string writeID)
{
    //for all rows in the table
    _tableWriter.Write(writeID, rowToWrite);
}

Then your calls could be:

var excelWriter = new ExcelWriter(); // implements ITableWriter
var table = new Table(excelWriter);
table.Write("DocumentName");

The trick is then to define the ExcelWriter class that implements the ITableWriter interface, with the deliverable being an Excel document.

That way, should you need to write the table somewhere else (to another database? to a flat file?) you won't have to change the Table class, just produce another implementation of the ITableWriter interface.

As added bonus, you can mock the ITableWriter interface for separate testing of your Table class.


问:
What is the best approach for database design with lots of columns?
I am writing a query based financial application. It lets the user to write complicated equations (much like WHERE part of an SQL query) and find companies matching those criteria.

For the above, I currently have more than 500 columns in the database table (each column representing a financial field).

Example of Columns are:
company_name, sales_annual_00, sales_annual_01, sales_annual_02, sales_annual_03, sales_annual_04, protit_annual_00, profit_annual1...(over 500 such columns).

The number of rows is around 5000.

Going forward, I would like to further increase the number of columns/financial-fields.

For the above I would like to get help regarding:

1) What is the best database design approach? Is it ok to have these many number of columns?

2) How can it be normalized? (User can use any of these fields in search criteria).

3) Is it ok to stick with MySQL, or modern document based databases like MongoDB should be better for it?

P.S. (Update): I have been using MySQL till now and a running example of the usage is at: http://screener.in/companies/89/Formula--
In above there around 500 fields/columns to create your query on, however, I seek to increase that number to much more in future.

答:
If this site is going to be used for ad-hoc reporting, and you anticipate a large number of rows, you should design the database as a Data Warehouse.  This shifts the focus from normalization to performance and query efficiency, which sounds appropriate for the application you've described.

To learn more about this, look into Dimensional Modeling.  Those tables with large numbers of columns representing numeric data would most likely be "Fact" tables and the smaller, more descriptive tables would be "Dimension" tables.

Ralph Kimball has published lots and lots of good information about designing, implementing, and maintaining data warehouses.  Read his stuff!

ContentLicense: CC BY-SA 4.0


答:
It is OK to have many columns if there truly are many different aspects of an entity. But sales_annual_01, sales_annual_02 etc. just scream "bad design". If you have multiple versions of essentially the same attribute, almost certainly they should be in a separate table which you can join to your table if needed - that way you don't have to update an unknown number of places in your logic oncen the powers that be suddenly demand seven-year reports rather than five-year reports (which you know they will, eventually).

(Note that if you do have the scenario that CFL_Jeff suspects, this is less relevant: normalization isn't as important when you won't be changing your data or your schema and performance is the foremost requirement.)

Title: What is the best approach for database design with lots of columns?

Body:
I am writing a query based financial application. It lets the user to write complicated equations (much like WHERE part of an SQL query) and find companies matching those criteria.

For the above, I currently have more than 500 columns in the database table (each column representing a financial field).

Example of Columns are:
company_name, sales_annual_00, sales_annual_01, sales_annual_02, sales_annual_03, sales_annual_04, protit_annual_00, profit_annual1...(over 500 such columns).

The number of rows is around 5000.

Going forward, I would like to further increase the number of columns/financial-fields.

For the above I would like to get help regarding:

1) What is the best database design approach? Is it ok to have these many number of columns?

2) How can it be normalized? (User can use any of these fields in search criteria).

3) Is it ok to stick with MySQL, or modern document based databases like MongoDB should be better for it?

P.S. (Update): I have been using MySQL till now and a running example of the usage is at: http://screener.in/companies/89/Formula--
In above there around 500 fields/columns to create your query on, however, I seek to increase that number to much more in future.


答:
If I understand you correctly, this data is built out regularly and used By the end-user as a read-only data source… So the Key requirement is to have an easy structure for the user to report off of.

Assuming the above is true. You are doing a good job by saying Normalization is not important in this case I’ll just give the user one giant table to make his life easier.  (You can cross off #2)

Going NoSQL (MongoDB) will make your Non-Tech users life a living hell, with only 5000 rows there is no way you are having performance issues (You can cross off #3 and stick with MySQL)

So what are left is the issue of too many columns. Honestly is not the approach I would take. but it’s not that that big of a deal either.

I would make Year a column then add a static set of columns for sales_annual, profit_annual ect.. (But there is a chance your user won’t like this, so talk to him\her fist. )


问:
Input to program without command-line arguments
Let's assume that there are no command-line arguments. How do you pass input data to a program?

I'm thinking you'd write the input to a file with a specific name, such that the program knows to open and read it as input. However, how would one discover the name of that file? Usually, running a command-line program without arguments or with some standard help argument (e.g. \?) produces some instruction on how to use it. But given an environment with no command-line arguments, how does one discover how to operate a program?

答:
You can use tools to display all the hardcoded strings inside the application, and hopefully the filename will show up.

Check OllyDBG on Windows and strings on Linux (it's a cmd-line application).

A more complex solution: fire up your favorite asm debugger (OllyDBG, GDB) and get your hands dirty.


问:
Where Can I List My Opensource Project?

Possible Duplicate:

  How can I get the word out about a new (open-source) library I've developed?

I have hosted my latest project, a JVM-based MIDI processor/API called Mjdj MIDI Morph, on Github (here and here). Now I need to bring some interest to it, even if it's negative interest (so I can improve it). I've looked up open source list on Google and end up with such things as this page on Wikipedia, which makes it quite clear that they don't want your project if it's new. Where should I list my project? Short of adwords and talking it up in forums and trade shows, where should I submit my URLs?

答:
If above doesn't work, try posting it on your site and get some traffic by link exchange techniques. </p>

<p>( Not sure if this works ) </p>

ContentLicense: CC BY-SA 2.5

Title: Where Can I List My Opensource Project?

Body:
If above doesn't work, try posting it on your site and get some traffic by link exchange techniques.

( Not sure if this works )


答:
Sherlock Holmes once said something like "A man's mind is like an attic. If you fill it up with trivialities, there is no room for anything truly important. For all of these details, we have the encyclopedia."

Unless you have a photographic memory, and the problems therein, you won't remember everything. Build a set of resources, a personal library of both information and problem solving techniques.

You may not remember the answer, and you may not even remember where the answer is written down. But, if you know how to solve the problem, then you can always find the answer again. Hopefully, this will include documenting your solution in a searchable and reusable fashion.


答:
In the .NET world, this is achieved with the use of an app.config file included with your source code. This is copied to the output folder with a name following the convention "MyApp.exe.config" where your application is "MyApp.exe".

I don't know if there are similar conventions for other languages.

Title: Input to program without command-line arguments

Body:
Let's assume that there are no command-line arguments. How do you pass input data to a program?

I'm thinking you'd write the input to a file with a specific name, such that the program knows to open and read it as input. However, how would one discover the name of that file? Usually, running a command-line program without arguments or with some standard help argument (e.g. \?) produces some instruction on how to use it. But given an environment with no command-line arguments, how does one discover how to operate a program?


问:
How can I advocate a semi-strict release schedule in a risk-averse environment?
Recently I've been increasingly plagued by what I would have to describe as one of my most frustrating and morale-killing experiences in this profession: Having to sit on a release that has been tested, re-tested, staged, and for all intents and purposes is ready to ship/deploy.

As an all-around solutions guy and not just a hardcore coder, I do understand and have even advocated the need for proper change control. But lately, the tenuous balance between covering our bases and shipping on time has gone all lopsided, and I've had little to no success in restoring it to something sane.

I'm looking for compelling arguments to help convince risk-averse management that:

The dev team should (or must) be able to set its own release schedule - within reason of course (1-3 months should be conservative enough for all but the biggest Fortune 500 companies);

Software releases are important milestones and should not be treated cavalierly; in other words, unnecessary delays/stoppages are highly disruptive and should be considered only as a last resort to some critical business issue; and

External (non-dev/non-IT) entities who want (or demand) to be involved as stakeholders have a responsibility to cooperate with the dev team in order to meet the release schedule, especially in the last week or so before the planned ship date (i.e. user testing/staging).

The above are assertions that ring true for me based on experience, but it looks like I'm now in the position of having to prove it - so I'm asking for something a little meatier here, if such a thing exists.

Can anyone who has had to "sell" the idea of a fixed (or maybe semi-flexible) release cycle to management give some pointers on what arguments/strategies are effective or persuasive and what is not? Aside from the obvious schedule contention and sunk costs, is there any hard data/evidence that would be useful in making the case that shipping is actually important, even in a "corporate" setting?

Alternatively, I'm open to hearing constructive arguments about why schedule flexibility (even over a period of weeks/months) is more important than shipping on schedule; it's hard for me to believe right now but maybe they know something I don't.

Note we have staged releases, and this went through every stage except production. Issues are tracked using a commercial bug tracker and every issue - 100% of them - that was assigned to this release was closed out. I realize it's difficult to believe and that's really precisely the point - it makes no sense that a 100%, feature-complete, fully-tested, approved-by-stakeholders release would be delayed by management for unexplained reasons, but that's what happened, that's what's been happening, that's the problem to be solved.

答:
First thing to consider is to make sure your releases aren't high risk.

Ideally, your change requests should have section called like Risk Mitigation, containing instructions on how to rollback to prior version if things go wrong. Risk-wise, no amount of prior testing can substitute a simple option to rollback the change.

In risk-averse environment, I can not imagine a way to make irreversible changes painless.

If many/most of your releases fall into this category, you may want to reconsider your architecture.

The risk of NOT releasing is to be exposed, if you want dev team schedule to be treated seriously.

If your releases deliver fixes for production / support issues and outages, this is fairly easy to do by just listing these and pointing out that production is at risk of repeating these unless it's upgraded.

A really effective measure available to dev team to fight against release slippages it to make sure that risk of not releasing increases over time. This can be achieved with internal releases running at fixed schedule, providing "cumulative" list of solutions to production issues.

Simply speaking, guys blocking your release XX need to be aware not only that they incur the risk of having N kinds of production issues to remain unresolved, but also that week (or month) later, they will have release XX+1 in their approval queue, blocking which will incur the risk of N+M kinds of production issues remain unresolved - and that this will also be the case with XX+2 and further "internal" releases supplied by dev team.

The way described above essentially makes tighter and more explicit connection between your application updates and production issues.

Because of that, you may expect more involvement into production issues escalations. You may use these as opportunity to promote your vision of stricter scheduled updates. You may even trigger some escalations yourself to speed up the process of adopting your desired approach.

"...recommend to consider upgrading application to newer version (XX or later). The one that is currently deployed to your environment (XX-2) is severely outdated - two major releases behind the current codebase. As a result, details for such simple failures are deeply hidden in logs and undecipherable garbage is reported by application to clients instead of clear failure descriptions - causing users and support to waste time investigating issues that are really quite simple"

Above is a comment I added some time ago in support issue tracker for the ticket related to particular production incident. Soon after that, "stakeholders" contacted dev team asking how to keep track about our releases and how they can help in deploying to their environment. Oh and they also quickly upgraded from XX-2 version, too. :)

When production escalation happens, you better be prepared to present your vision quickly and clearly.

One thing you'll find useful is to pick and track who's responsible for particular release slippage. Basically, you need to be able to quickly and clearly answer to question like "who holds responsibility for the fact that planned release did not happen?" If you're not ready, they may choose the path of least resistance and put the blame on you. As pointed out in comments to another answer, "You could get yourself in hot water that your management is trying to protect you from."

The last but not the least,

it'll take time

(you probably already know that but it looks worth stating explicitly)

What you look for can be described as attitude change, from "it is risky to release" to "it is risky NOT to release". Attitude changes rarely happen overnight, patience might be needed to get the shift completed.


答:
Popular convention seems to be for programs to use standard streams for stuff like that:

In computer programming, standard streams are preconnected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution...

You can see how it works using whatever command interpreter is available in your OS. In Windows, you may launch DOS shell and type help. In Unix you launch shell and type man.


答:
For 5000 lines at 500 fields per line, the only reason to use a relational database is that your users all know how to use SQL to do queries, and you plan to give them raw SQL.

The moment you give them anything other that raw SQL to do their searches, you are far better off throwing away your DBMS and making this a straight sequential one-pass scan on a flat text file.  5000 x 500 = 2.5e6, so you have 2.5 million individual fields.  Assuming average of 10 bytes per field, that's 25 million bytes.  That's a memory-resident array on a single PC and initially reading the sucker into memory is what's going to kill you.  Assuming average of 100 bytes per field, that's still only 250 million bytes.  Maybe you page it, 50 million bytes at a whack.

Just because you have data doesn't mean you have to use a database management system.


答:
Try this division to tables:

```<code>Companies
(
    CompanyPK PK,
    Name
)

Sales
(
    CompanyPK PK,
    Year PK,
    Value
)

Expenses
(
    CompanyPK PK,
    Year PK,
    Value
)
</code>```

This way you can have multiple years per company and take into consideration that some companies might have not existed in a given year.
Also you will not need to move data around each year - just add rows.

Profit would be a calculation (Sales = Expenses), so you don't need a table/columns for that.

If you have many different non-calculated fields, then consider a dictionary approach instead...

```<code>Companies
(
    CompanyPK PK,
    Name
)

Fields
(
    FieldTypePK PK,
    CompanyPK PK,
    Year PK,
    Value
)

FieldTypes
(
    FieldTypePK PK,
    Name
)
</code>```

Example of usage for second option:

```<code>select
    c.CompanyPK,
    c.Name
from Companies c
inner join Fields f1
on f1.CompanyPK = c.CompanyPK
inner join Fields f2
on f2.CompanyPK = c.CompanyPK
where f1.FieldPK = 1 and f1.Year = 2012 and f1.Value > 1000000
and f2.FieldPK = 2 and f2.Year = 2012 and f2.Value < 50000
</code>```

Body:
Try this division to tables:

Companies
(
    CompanyPK PK,
    Name
)

Sales
(
    CompanyPK PK,
    Year PK,
    Value
)

Expenses
(
    CompanyPK PK,
    Year PK,
    Value
)

This way you can have multiple years per company and take into consideration that some companies might have not existed in a given year.
Also you will not need to move data around each year - just add rows.

Profit would be a calculation (Sales = Expenses), so you don't need a table/columns for that.

If you have many different non-calculated fields, then consider a dictionary approach instead...

Companies
(
    CompanyPK PK,
    Name
)

Fields
(
    FieldTypePK PK,
    CompanyPK PK,
    Year PK,
    Value
)

FieldTypes
(
    FieldTypePK PK,
    Name
)

Example of usage for second option:

select
    c.CompanyPK,
    c.Name
from Companies c
inner join Fields f1
on f1.CompanyPK = c.CompanyPK
inner join Fields f2
on f2.CompanyPK = c.CompanyPK
where f1.FieldPK = 1 and f1.Year = 2012 and f1.Value > 1000000
and f2.FieldPK = 2 and f2.Year = 2012 and f2.Value < 50000


答:
It really depends on the GUI. First time users find TortoiseGit very confusing and would basically brute-force their way to getting something checked-in, which means that they might or might not mess up the repository. In a hackathon I participated in a few months ago first time users were able to break the repository (fast forwards, bad merges, etc) on several occasions. They weren't able to get a good overview of what's going on. git-gui and especially SmartGit were much much easier to comprehend and work with (git-gui however being very limited in functionality).

(Moved to be an answer as per the comments to my comment).


答:
Firstly, DVCS is a red-herring for the problems you have - the version control tool in use is not the root of the issues that have to be resolved. It may be that there are aspects of DVCS solutions that are "better" than TFS but its not what needs to be fixed at this point.

You've identified that you need a workable branching structure that fits your organisation - I think you'll find you still have a trunk, when a feature is complete it gets merged back into the trunk and get closed off. There are some nice thoughts about how you implement common dependencies too.

You also need to get continuous integration working (no reason not to have an automated build for each and every active branch to give you confidence that you can build that branch and that it passes the relevant tests). I am uncomfortable where a commit (or at least a "push") doesn't trigger a build for me.

And you need to start in on automated testing at all levels but especially unit tests and integration tests to start to reduce the chances of new bugs escaping into the wild. This last is huge and something I'm still struggling with but its clear that once you know you can build things at all this will have the most value.

You need to combine this with making sure that your deployment packages come from you build server and that deployment is automated as far as possible (you should be able to go from build server artifact to live deployed code with minimal effort and minimal stress).

Hmm, I assumed that there is a nice well ordered issue tracking setup... you need that too and to be confident that it is being used properly. Ideally you want your live applications to feed back errors to this system (or for triage) automatically.

Lastly, don't try to solve all your problems at once - build and test would seem to me to be the places you should focus first.


答:
1) What is the best database design approach? Is it ok to have these
  many number of columns?

2) How can it be normalized? (User can use any of these fields in
  search criteria).

This is just terrible database design. The most obvious fix is, that you need to have it in third normal form:

```<code>Companies (
company_name,
...
)

FinancialResults (
period,
sales_annual,
profit_annual,
...
)
</code>```

The EAV-style approach you can see in some answers is not the most efficient way and will be pain in the backside to extract data from.

3) Is it ok to stick with MySQL, or modern document based databases
  like MongoDB should be better for it?

Yes, MySQL will do perfectly fine for that. It's not the type, volumne or throughput of data for which you'd have to consider no-SQL solutions. And no-SQL solution will not work efficiently if you can query on any of the columns.

Body:
1) What is the best database design approach? Is it ok to have these
  many number of columns?

2) How can it be normalized? (User can use any of these fields in
  search criteria).

This is just terrible database design. The most obvious fix is, that you need to have it in third normal form:

Companies (
company_name,
...
)

FinancialResults (
period,
sales_annual,
profit_annual,
...
)

The EAV-style approach you can see in some answers is not the most efficient way and will be pain in the backside to extract data from.

3) Is it ok to stick with MySQL, or modern document based databases
  like MongoDB should be better for it?

Yes, MySQL will do perfectly fine for that. It's not the type, volumne or throughput of data for which you'd have to consider no-SQL solutions. And no-SQL solution will not work efficiently if you can query on any of the columns.


答:
Switch to a normalized structure. SQL is fundamentally integrated to this design choice. Failure to comply will cause you problems. Either your users will truly understand SQL, and will have no problem, or your front end needs to do the heavy lifting and mask the fact that all of these columns are normalized away.

Secondly, use UUIDs! This will prevent a massive amount of grief in the connecting of your disparate data on the fly. And, your search criteria fits what the user asks. If they want all records from 2010 for company Foo, then that's just an inner join of the records table on the company table where company name = Foo and an inner join on the years table where year = 2010.

Finally, your performance will be very fast with a proper setup, because you aren't breaking the SQL design (see item 1). SQL is all about sets so setting things up for queries like the example in item 2 will work very fast. If everything is in one big table, all of a sudden the front end has to wait for every single row to be returned across a network, and then it has to read every single row and check it against the search criteria. This is not procedural programming, do not pretend it is.

For an excellent post on all of this, read this article.


问:
Ubuntu, OpenSuse, the world of linux for a web-developer
I'm learning web development. My main OS is windows 7 but I've used Linux and currently dual-booting with Ubuntu. My Linux knowledge however, is pretty limited. I can work with the command line on simple tasks but that's pretty much it. I don't do any shell scripting, don't know very well the most important commands, nor the system in general.

I am interested in web development. Should I get myself familiarized more with Linux ?  Is it a must for future job positions considering my field of interest?

答:
If you want to do web development on Linux you should get to know Linux well. The truth is that if an employer uses a web technology that doesn't require windows, they will save themselves some money and give their developers Linux machines.

Such employers will want employees who are productive on Linux, so regardless of your knowledge of a framework or IDE, knowing Linux helps you be more productive, and consequently the employer will be more profitable.

Linux workflows are often different to Windows workflows. You can automate linux more easily with small command line tools, both existing and custom coded by yourself. Knowing the environment helps you to achieve this. One of the biggest paradigm shifts for example is probably "where are things" with regards to configuration files, and the fact that in Linux you are more likely to edit configurations in a text editor than click through a configuration dialog.

Another way to think of it: You are being considered besides 1 other potential employee who is on par with you on language/framework skills, but he knows Linux better.

ON THE OTHER HAND

There are many Windows based web development Jobs, or mixed environments where you might do some PHP and .Net in the same job position. ASP .Net MVC is great fun, and that requires Windows knowledge. IIS can even run PHP applications these days

My final recommendation would be that if you like web development the best option would be to know Windows and Linux very well. Linux has gotten increasingly easy to use, so it's not that much effort to learn anymore. In many cases development is on Windows but the servers are Linux. It would also be good for you to settle in to the web development framework you like the most, and see on what kind of platforms it runs. Then focus on it's primary runtime platform as your specialty.


答:
Server-side

Pros: More controllable, easier to debug, less dependent on client's browser

Cons: More server load, higher network traffic and latency

Client-side

Cons: Depends on decent JS/DOM implementation in the browser.

Pros: Performance, performance, performance. Less server load (thus faster server response), much less network traffic, and thanks to previous two much less latency.

For example LinkedIn's Engineering Team article
"Blazing fast node.js: 10 performance tips from LinkedIn Mobile" as one of the points talks about that issue.

Title: Is it better to build HTML Code string on the server or on the client side?

Body:
The result of the following process should be a html form. This form's structure varies from one to user. For example there might be a different number of rows or there may be the need for rowspan and colspan.

When the user chooses to see this table an ajax call is made to the server where the structure of the table is decided from the database. Then I have to create the html code for the table structure which will be inserted in the DOM via JavaScript.

The following problem comes to my mind: Where should I build the HTML code which will be inserted in the DOM? On the server side or should I send some parameters in the ajax call method and process the structure there?

Therefore the main question involves good practice when it comes to decide between Server side processing or client side processing.

Thank you!


答: Just run your server in a virtual machine with linux. You can use VMWare or VirtualBox. Then you connect to the guest machine via Putty and learning linux command line is just a matter of time then and comes totally natural.</p>

Title: Ubuntu, OpenSuse, the world of linux for a web-developer

Body:
I'm learning web development. My main OS is windows 7 but I've used Linux and currently dual-booting with Ubuntu. My Linux knowledge however, is pretty limited. I can work with the command line on simple tasks but that's pretty much it. I don't do any shell scripting, don't know very well the most important commands, nor the system in general.

I am interested in web development. Should I get myself familiarized more with Linux ?  Is it a must for future job positions considering my field of interest?


问:
How you prepared for your .NET interview?
I gave many interviews in the last few years and each time I found the interviewers are not satisfied with what I know. My first company only developed desktop Windows applications using .NET. They had nothing to do with features like: Remoting etc. We also had limited use of Generics, Reflection and Multi-threading.

When I appeared for the interviews, I was asked questions on above features even when I told them that I don't have real-life experience.

Now the .NET interviews are even more complex. Seeing my experience, the interviewers target the latest framework. I have no real-life exposure to the new features and technologies like WPF, WCF etc.

Please suggest me how to effectively prepare for the .NET interview. I have 3 years experience in .NET but I only developed Windows based applications. At present I work on .NET Framework 3.5. I never worked on ASP.NET, as in my present company I work on PHP for web-applications.

答:
This is not meant to be a holistic answer, just to highlight a few points to get the ball rolling:

Know the core e.g. CLR, GAC, GC, OO etc

Familiar with the language, syntax and features (C#, VB.NET minimal and their respective features e.g. C#3.0 vs C#2.0)

Understand what your future company is doing. My company is still am doing v2.0 for some years to come, so 3.5/4.0 are nice to have but not mandatory. Some might be at the cutting edge, WCF/WF/Silverlight/Lamda etc

Convince them that though you might not have experience, you can pick up new stuff quickly


答:
Over the last year Evernote became a program I could not do without.I copy everything into Evernote. Code Snippeds, Screenshoots, Contact data, Version History and so on. So I don't have to remember so much details. I just know it's in there somewhere.

The basic version is free. So try it!


答:
Keep your own notes, expressing things in your own words.  Your target audience is you, nobody else, so you can afford to be terse.   (A blog post however really needs to be clear and well-edited, which is time-consuming.)  If you find good articles/blogposts, record the URL, but still explain things out in your own words.

I keep a large hierarchy of small, short, single-topic files.  The files are mostly free-form, but I'm switching over to using Markdown.  Search using grep/find.  I keep the folder in my DropBox, so it's always available to me.


问:
Is it a waste of time to free resources before I exit a process?
Let's consider a fictional program that builds a linked list in the heap, and at the end of the program there is a loop that frees all the nodes, and then exits. For this case let's say the linked list is just 500K of memory, and no special space managing is required.

Is that a waste of time, because the OS will do that anyway?

Will there be a different behavior later?

Is that different according to the OS version?

I'm mainly interested in UNIX based systems, but any information will be appreciated. I had today my first lesson in OS course and I'm wondering about that now.

Edit: Since a lot of people here are concerned about side effects, and general 'good programming practice' and so. You are right! I agree 100% with your statements. But my question is only hypothetical, I want to know how the OS manages this. So please leave out things like 'finding other bugs when freeing all memory'.

答: On multi-user systems, the OS will always free such resources because it would be a security risk if it didn't. Your memory contents might end in someone else's process!</p>


问:
Should I create my own Assert class based on these reasons?
The main reason I don't like Debug.Assert is the fact that these assertions are disabled in Release. I know that there's a performance reason for that, but at least in my situation I believe the gains would outweigh the cost. (By the way, I'm guessing this is the situation in most cases). And yes, I know that you can use Trace.Assert instead. But even though that would work, I find the name Trace distracting, since I don't see this as tracing.

The other reason to create my own class is laziness I guess, since I could write methods for the most usual cases like Assert.IsNotNull, Assert.Equals and so forth.

The second part of my question has to do with using Environment.FailFast in this class. Would that be a good idea? I do like the ideas put forth in this document. That's pretty much where I got the idea from.

One last point. Does creating a design like this imply having an untestable code path, as described in this answer by Eric Lippert on a different (but related) question?

答: If Trace has all the functionality you need and you really can't bare the name "Trace" can you just inherit from it to mask the name?</p>


答: The cleanup routine may be useful if you do it periodically to regain space, or to prove that you are able to reclaim exactly as many nodes as you allocated, to verify that there are no memory leaks. But as housekeeping immediately before the process dies, it makes no sense, since the OS regains control of that entire arena of memory at that instant. </p>

Title: Is it a waste of time to free resources before I exit a process?

Body:
Let's consider a fictional program that builds a linked list in the heap, and at the end of the program there is a loop that frees all the nodes, and then exits. For this case let's say the linked list is just 500K of memory, and no special space managing is required.

Is that a waste of time, because the OS will do that anyway?

Will there be a different behavior later?

Is that different according to the OS version?

I'm mainly interested in UNIX based systems, but any information will be appreciated. I had today my first lesson in OS course and I'm wondering about that now.

Edit: Since a lot of people here are concerned about side effects, and general 'good programming practice' and so. You are right! I agree 100% with your statements. But my question is only hypothetical, I want to know how the OS manages this. So please leave out things like 'finding other bugs when freeing all memory'.


答: My main problem with your approach is that a leak detection tool (like Valgrind) will report it and you will start ignoring it. Then, some day a real leak may show up, and you'll never notice it because of all the noise.</p>


答:
The main reason I don't like Debug.Assert is the fact that these assertions are disabled in Release

What you're looking for are Code Contracts; a library from Microsoft that lets you make assertions that shouldn't be violated (IE, null arguments or a bank account variable going lower than zero just before a calculation of interest).

They offer several ways to express your constraints and a static checker to warn you about pitfalls in your codebase without ever running any code.

Look into "Design by contract" for non-.NET information on this.

Title: Should I create my own Assert class based on these reasons?

Body:
The main reason I don't like Debug.Assert is the fact that these assertions are disabled in Release. I know that there's a performance reason for that, but at least in my situation I believe the gains would outweigh the cost. (By the way, I'm guessing this is the situation in most cases). And yes, I know that you can use Trace.Assert instead. But even though that would work, I find the name Trace distracting, since I don't see this as tracing.

The other reason to create my own class is laziness I guess, since I could write methods for the most usual cases like Assert.IsNotNull, Assert.Equals and so forth.

The second part of my question has to do with using Environment.FailFast in this class. Would that be a good idea? I do like the ideas put forth in this document. That's pretty much where I got the idea from.

One last point. Does creating a design like this imply having an untestable code path, as described in this answer by Eric Lippert on a different (but related) question?


答:
You could look at COM, as implemented by Microsoft. In that system, the OS loads your DLL into memory when someone needs an object of your type. If anyone needs to pass information to that object, it can use the standard IUnknown::QueryInterface(GUID) method to obtain an well-known interface, and then pass information via that interface.

Of course, if your object doesn't have such an interface, it'd return E_NO_INTERFACE. But that's no different (just eassier to debug) than a CLI program ignoring its arguments.


答:
Many Operating Systems already have the concept of "environment variables". This is a set of named values that are passed to every process, in addition to the command line arguments. Using C, you'd access them with getenv().

Similar to the /? convention for command lines, the OS writer can define a convention that the presence of a HELP variable in the environment means that a program should show usage information. In C code: if (getenv("HELP")) { ShowHelp(); }


答:
I don't quite understand what the OP is really asking, but it is fairly common for command line programs to use environmental variables as inputs in lieu of command line parameters.

Of course that begs the question of where did the environmental variables come from.


答:
If you are 100% sure not other process is referencing you linked list and the nodes therein, OK.

100% is a pretty high number, though.  Was your list referenced by some persistence code that's being pooled?  Does a UI component still have a handle on it?  Anything else?

Memory leaks generally don't happen on purpose.


问:
What Are Some Advantages/Disadvantages of Using C over Assembly?
I'm currently studying engineering in Telecommunications and Electronics and we have migrated from assembler to C in microprocessor programming.  I have doubts that this is a good idea.  What are some advantages and disadvantages of C compared to assembly?

The advantages/disadvantages I see are:

Advantages:

I can tell that C syntax is a lot easier to learn
than Assembler syntax.

C is easier to use for making more complex programs.

Learning C is somehow more productive than learning assembler cause there is more developing stuff around C than Assembler.

Disadvantages:

Assembler is a lower level programming language than C,so this makes it a good for programming directly to hardware.

Is a lot more flexible alluding you to work with memory,interrupts,micro-registers,etc.

答:
we have migrated from assembler to C in microprocessor programming. I have doubts that this is a good idea

Fear not, nobody develops new programs in 100% assembler any longer. Nowadays, C can be used even for the tiniest, crappiest 8-bit architectures. However, knowing some assembler makes you a significantly better C programmer. Also, there are always some small detail or two in a program that need to be written in assembler.

I can tell that C syntax is a lot easier to learn than Assembler syntax.

Yes the syntax is easier, certainly. However, learning the whole C language with all the annoying details is far more complex than learning all the details of a particular assembler. C is a much larger and wider language.
But then again, you might not need to learn all the details.

C is easier to use for making more complex programs.

Indeed, C provides mechanisms for modular program design, such as encapsulation and local scopes/local variables. And C has a standard library, plus an enormous amount of resources written during the past 30 years. And most importantly, C is portable.

Learning C is somehow more productive than learning assembler cause there is more developing stuff around C than Assembler.

C has plenty of pre-made functionality, libraries and resources, so there will be less re-inventing of the wheel. But apart from that, your statement is subjective. I believe it is a matter of personal preference.

For example, I am an experienced C programmer, occasionally programming C++. I find myself far less productive in C++, because I don't know that language as well as I know C. But just because I feel that way, it doesn't necessarily mean that programming in C is more productive than programming in C++. An experienced C++ programmer would surely have the opposite opinion.

And there are many aspects to "productive". A very important aspect is maintenance time, and especially the time it takes to fix bugs induced by maintenance. C is far easier to maintain than assembler.

Assembler is a lower level programming language than C,so this makes it a good for programming directly to hardware.

Hardware programming can be done directly in either language. The only things you can't do in C are accessing stack pointers and condition registers etc, of the CPU core itself. So if by hardware programming you mean talking with your own CPU, then yes, assembler allows a bit more than C. If you mean accessing external hardware, then assembler holds no benefit over C. But perhaps disadvantages, as it is often harder to write generic assembler code for a particular external device, than generic C code.

Is a lot more flexible alluding you to work with memory,interrupts,micro-registers,etc.

This is not correct. C allows you to do all of that too, although you might have to rely on compiler-specific C code such as the interrupt keyword.

In the end, you need to know both languages to program MCUs, with emphasis on C.


问:
Exposing warnings\errors from data objects (that are also list returned)
I'm exposing Data objects via service oriented assembly (which on future usages might become a WCF service).

The data object is tree designed, as well as formed from allot of properties.Moreover, some  services return one objects, others retrieve a list of them (thus disables throwing exceptions).

I now want to expose data flow warnings and wondering what's the best way to do it having to things to consider: (1) separation (2) ease of access. On the one hand, I want the UI team to be able to access a fields warnings (or errors) without having them mapping the field names to an external source but on the other hand, I don't want the warnings "hanged" on the object itself (as I don't see it a correct design).

I thought of creating a new type of wrapper for each field, that will expose events and they'll have to register the one's they care about (but totally not sure) I'll be happy to hear your thoughts. Could you please direct me to a respectful design pattern? what pattern will do best here?

答: Tackled similar problem few days back by using Observer pattern. Create observer classes in the main assembly of the service. Attach error message observer to it. You can also attach error log as an observer. </p>


问:
How is a software backdoor implemented?
The wikipedia article on Limewire says that "LimeWire 5.5.11 and newer have been disabled using a backdoor installed by the company".

How are such backdoors implemented? Is it as simple as the the program going out and checking a web service and disabling itself? If it's in fact so simple, it has to be stored somewhere on the user's drive (in a plist, or in the registry for example). It's hard to imagine no one has in fact figured out a way to turn that flag off and use the program.

答:
The typical concept of a back door in software is one which allows the creator undisclosed and unwanted access to installations of his software. The simplest method would be to hard-code additional credentials to the system.

There is an important distinction between this meaning and a piece of software that routinely checks for updates, even though they function entirely the same. The user knows and wants it to happen. It's only a cultural shift that turns the outrageous transgression of altering my machine into a typical and daily occurrence that happens with today's software. But at least they're usually nice enough to ask first.

Title: How is a software backdoor implemented?


答:
I'm going for a straight-man answer.

You read the user's manual. Then you use some sort of input device like a keyboard or mouse to control the program. If the program requires a large amount of data, you can direct it to a file. Directing a program to a file has varied widely through the ages, but has standardized to OS typical popup windows.

If it's a command line program, with no command line arguments, then you are dependent on the program's interface. At some point you probably have to type in the path to the file name.


问:
Can you/should you develop components for ASP.NET MVC?
Following from the previous question I've started to wonder - is it possible to implement "Components" in ASP.NET MVC (latest version)? And should you?

Let's clarify what I mean with a "component". With that I mean a "control" (aka "widget"), similar to those that ASP.NET webforms is built upon. A gridview might be a good example. In webforms I can place on my form a datasource component (one line of code), a gridview component (another line of code) and bind them together (specify an attribute on the gridview). In the codebehind file I fill the datasource with data (a few lines of DB-querying code), and I'm all set.

At this point the gridview is a fully functional standalone component. I can open the form, and I'll see all the data. I can sort it by clicking on the column headers; it is split into several pages; I can drag the column headers around and rearrange columns; I can turn on "grouping" mode; etc. And I don't need to write another line of code for any of it. The gridview, as a component, already has all the code tucked away in its classes and assemblies. I just place it on the form, initialize it, and it Just Works. At some times (like sorting or navigation to a different page) it will also perform ajax callbacks to the server, but those too will be handled internally, with my code having no knowledge at all about it. And then there are also events that I can attach if I want to get notified when something happens.

In MVC I cannot see a way of doing this cleanly. Sure, there are the partial views, but those only handle half of the problem - they render the initial HTML. Some more can be achieved with client-side Javascript (like column re-arranging), but when the grid needs to do an ajax callback (say, to fetch the next page of data), my code will have to get involved and process that request. At best I guess I can provide some helper methods to process it, but I'll have to write the code that calls them, and also provide a controller method with signature matching the arguments of that callback.

I guess that I could make some hacks with global events or special routes or something, but that just seems... hackish. Unelegant. Perhaps this is not the MVC way? Although I've completed one project in it, I'm still far from being an MVC expert. But then what is? In the intranet application that we're building there are dozens upon dozens of such grids. Naturally I want them all to have a unified look & behavior, and I don't want to repeat the same code all over the place.

So what's the "MVC" approach to this problem?

答: MVC approach to this problem would be to build a jquery UI plugin and have that render your UI. You could also provide some classes to help feed it data. I don't think there is the same drag-n-drop deployment requirement in MVC for good reason.</p>


问:
How important is the ability to touch-type?
Did you learn to touch-type when you were already working as a programmer?  If so how did it affect your productivity?  Or are you still unable to touch type and do you think it holds you back?

According to Steve Yegge it is essential,

Personally I did not notice much difference, possibly because I was spending less than 25% of my work time actually typing (I was working on a large legacy project at the time and I was spending more time on reading and debugging existing code.)

答:
Did you learn to touch-type when you were already working as a programmer?

No.  I still cannot touch type properly.  My fingers go all over the place, and I'm mostly two fingers on each hand, and not very accurate.  (I learned to type the hard way ... on an IBM 026 card punch in the 1970's.)

If so how did it affect your productivity? Or are you still unable to touch type and do you think it holds you back?

I don't think it holds me back.  Most of the time I'm thinking rather than typing.


答:
Of course you can, you just have to reimplement all the things webforms does out of the box to make it work but in an efficient manner.

There's no reason you can't have a partial template which renders a "widget" and also progressively enhances that widget with javascript and ajax functionality.

You will have to write some lines of code on the "backend" to support the ajax. Whether thats hundreds of lines of HTTP handling code or 2 lines depends on how much abstraction you push into a framework layer.

Title: Can you/should you develop components for ASP.NET MVC?

Body:
Following from the previous question I've started to wonder - is it possible to implement "Components" in ASP.NET MVC (latest version)? And should you?

Let's clarify what I mean with a "component". With that I mean a "control" (aka "widget"), similar to those that ASP.NET webforms is built upon. A gridview might be a good example. In webforms I can place on my form a datasource component (one line of code), a gridview component (another line of code) and bind them together (specify an attribute on the gridview). In the codebehind file I fill the datasource with data (a few lines of DB-querying code), and I'm all set.

At this point the gridview is a fully functional standalone component. I can open the form, and I'll see all the data. I can sort it by clicking on the column headers; it is split into several pages; I can drag the column headers around and rearrange columns; I can turn on "grouping" mode; etc. And I don't need to write another line of code for any of it. The gridview, as a component, already has all the code tucked away in its classes and assemblies. I just place it on the form, initialize it, and it Just Works. At some times (like sorting or navigation to a different page) it will also perform ajax callbacks to the server, but those too will be handled internally, with my code having no knowledge at all about it. And then there are also events that I can attach if I want to get notified when something happens.

In MVC I cannot see a way of doing this cleanly. Sure, there are the partial views, but those only handle half of the problem - they render the initial HTML. Some more can be achieved with client-side Javascript (like column re-arranging), but when the grid needs to do an ajax callback (say, to fetch the next page of data), my code will have to get involved and process that request. At best I guess I can provide some helper methods to process it, but I'll have to write the code that calls them, and also provide a controller method with signature matching the arguments of that callback.

I guess that I could make some hacks with global events or special routes or something, but that just seems... hackish. Unelegant. Perhaps this is not the MVC way? Although I've completed one project in it, I'm still far from being an MVC expert. But then what is? In the intranet application that we're building there are dozens upon dozens of such grids. Naturally I want them all to have a unified look & behavior, and I don't want to repeat the same code all over the place.

So what's the "MVC" approach to this problem?


答:
In the case of Borland's Interbase (now called Firebird), there was a hidden super-user that the system required in order to work. This hidden super-user could not be disabled, and it had a known password that could not be changed (until a patch became available to do so). This would allow anyone who knew the hardcoded username/password combination to access any installation. Disabling this account breaks the system because it can no longer authenticate users.

CERT advisory on Interbase.

Is it as simple as the the program going out and checking a web service and disabling itself?

This is generally how many forms of license management work. Some simply check to see if "my serial number" is in use, and if so, they exit. Some use a form of PKI and revoke local certificates if the license is invalid. For example, Adobe Reader pings crl.adobe.com when it starts to see if any licenses have been revoked, as the key to enable plugins to work in the free reader require a digital key. If a plug-in does things that violate the licence, the cert enabling it will be revoked. License management is a very complicated process because you've got to stay one step ahead of the crackers, and even minor bugs in your licensing code will cause major customer problems.

Title: How is a software backdoor implemented?

Body:
The wikipedia article on Limewire says that "LimeWire 5.5.11 and newer have been disabled using a backdoor installed by the company".

How are such backdoors implemented? Is it as simple as the the program going out and checking a web service and disabling itself? If it's in fact so simple, it has to be stored somewhere on the user's drive (in a plist, or in the registry for example). It's hard to imagine no one has in fact figured out a way to turn that flag off and use the program.


问:
How often are comments used in XML documents?
I'm currently developing a web-based XML managing program for a client (though I may 'market' it for future clients). Currently, it reads an XML document, converts it into manageable Javascript objects, and ultimately spits out indented, easy to read XML code. Edit: The program would be used by clients that don't feel like learning XML to add items or tags, but I (or another XML developer) may use the raw data for quick changes without using an editor.

I feel like fundamentally, its ready for release, but I'm wondering if I should go the extra mile and allow support for remembering (and perhaps making) comments before generating the resulting XML.

Considering that these XML files will probably never be read without a program interpreting it, should I really bother adding support for comments? I'll probably be the only one looking at raw files, and I usually don't use comments for XML anyway.

So, are comments common/important in most XML documents?

答:
Considering that these XML files will probably never be read without a program interpreting it

Then what value is there in a program whose entire purpose is to produce "indented, easy to read XML code"?

I know that I've seen a lot of comments in XML configuration files (Java frameworks and the like). Pretty much none in data files.

The real question is who you expect to use the program and for what purpose. We can't answer that for you.


答: Cleanup routines can have bugs just like any other code.  A sad sight is a program that does what you want except that it hangs or crashes at exit.  General practice is to have code clean up after itself, but memory cleanup at process exit is a case where you don't have to.</p>


问:
Should devs, testers and business users have one unified test script?
In development, I would normally have my own test scripts that would document the data, scenarios and execution steps that I plan to test; this is my dev test plan. When the functionality has been deployed to Test, testers test it using their own test script that they wrote. In UAT, the business user then tests using their own test plan.

In retrospect, it looks like this provides a better coverage, with dev tests having a mix of black and white box testing, while testers and business users focus on black box testing. But on the other hand, this brings up distinct test cases that only are executed per stage (ie. some cases which testers thought of are only executed on Test stage) and it would like the dev missed it, which makes it a finding/bug.

Is it worth consolidating the test scripts from the start? Thus using one unified test script, or is it abit difficult to do this upfront?

答: They don't need a unifed test script as the things they test and the way they perform tests are often supposed to be differnt, what they need is a unified requirement that all parties are working off of. If UAT and QA are testing things the developer never thought of, then it is time to be looking at the requirements.</p>


答:
Yes, create your own Assert if it fulfils your requirements

Some companies have no 'release' build - the single build that they use has compiler optimisations disabled, ASSERT-like macros still in place and a ton of logging. Being able to dynamically enable/configure ASSERT behaviour at runtime is helpful here. You want ASSERT-like behaviour in that if something doesn't pass a test, do something about it rather than let the program continue but being able to toggle abort, logging, timing, stat collection and throw-an-exception behaviour at runtime is hugely useful, especially if you have large server applications with lots of clients and which can have long uptimes.

System.Diagnostics.Assert certain does the abort behaviour and System.Diagostics.Trace does the logging, but it may well suit your purposes to have some blend thereof which was configurable through .config or Registry means and gave you access to whatever you need to ensure that the quality of your software meets your requirements.

I can't predict what would be useful to you, but as a starting point:

Is a failing conditional fatal, a warning or trace.

Should the code abort, throw, log, email or SMS the issue.

Whether to keep stats on the above items.

Whether allow live configuration of all these (useful for server processes).


答:
Yes it is possible to create reusable widgets that play nicely with ASP.NET MVC. As an example, Telerik has two control suites that are "targeted" at the ASP.NET MVC developer. The first is the Telerik Extensions for MVC. These are implemented as HTML Helpers that spit out the appropriate markup (html and jQuery). The second is the Kendo framework which is a pure jQuery based framework that happens to work well with MVC (but also plays nicely with other web frameworks out there).

Both of these are pretty good examples of how to create re-usable widgets that can be dropped in with a few lines of code. The beauty of these frameworks lie in their exstensibility both in terms of functionality as well as look and feel.


问:
What is the name of this tree?
It has a single root and each node has 0..N ordered sub-nodes . The keys represent a distinct set of paths. Two trees can only  be merged if they share a common root. It needs to support, at minimum: insert, merge, enumerate paths.

For this tree:

```
The
 +--------+----------------+
 |        |                |
cat      cow              dog
 +        +--------+       +
 |        |        |       |
drinks   jumps    moos    barks
 +
 |
milk
```

the paths would be:

The cat drinks milk

The cow jumps

The cow moos

The dog barks

It's a bit like a trie. What is it?

答: By Wikipedia, it looks like your tree is specified by the two properties arborescence and ordered tree (scroll down to find the definition "ordered tree or plane tree.")</p>

Title: What is the name of this tree?


问:
Criteria for a language to be considered "object oriented"
I had a discussion about OO programming today and by browsing the internet I found a lot of different specifications for object oriented languages.

What are the requirements for a language to be object oriented? For myself an object oriented language must have classes, inheritance and encapsulation.

Is C an object oriented language just because you can use structs and program with an object oriented design? Why/ why not?

Are there any good sites/articles about this? And please, no Wikipedia links because I've already been there.

答:
The only realistic requirement for a language to be OOP is that it's possible to expend at least a good proportion of the time actually dealing with OOP instead of hacking around it's deficiencies. Something like  e.g. C is hardly great, but it's usable. If you're desperate.

Which programming languages are purest OOP? Which denominations are the purest Christians? There's no way you could possibly get a correct or objective answer to that question- there's not even any useful definition of "pure". And secondly, even if you could pick the language which had no other non-OOP features and was "pure" in the scientific definition, i.e., only of one thing, then it would be a terrible language. OOP is not some wonder-child, it's not good for everything by miles, and only offering OOP sends a language right down the pile of awful.


答: You can create .bat file with your arguments in it.</p>


答:
Liskov substitution principle is pretty much the defn of Object Orientated.

Although in practice encapsulation and data hiding are probably more useful

Title: Criteria for a language to be considered "object oriented"

Body:
I had a discussion about OO programming today and by browsing the internet I found a lot of different specifications for object oriented languages.

What are the requirements for a language to be object oriented? For myself an object oriented language must have classes, inheritance and encapsulation.

Is C an object oriented language just because you can use structs and program with an object oriented design? Why/ why not?

Are there any good sites/articles about this? And please, no Wikipedia links because I've already been there.