问:
Is it bad practice to use reflection to do DB inserts with data from an external service?
Our supplier's webservice is returning address objects (~30 fields) and I'm using LINQ and reflection to store the returned data straight into the databse. I loop over the attributes and set the value from the object to the LINQ class.

I'm fairly new to refection and I'm worried this may be bad practice; it saves ~30 lines of code in 3 or 4 methods but I'm afraid it could introduce hard to fix bugs.

EDIT Here is the code. Target is normally a LINQ to SQL entity and input would be a webservice object.

```<code>public static void SetValues(object target, object input)
{
    Type targetType = target.GetType();
    Type inputType = input.GetType();

    PropertyDescriptorCollection inputProperties = TypeDescriptor.GetProperties(inputType);
    PropertyDescriptorCollection targetProperties = TypeDescriptor.GetProperties(targetType);

    foreach (PropertyDescriptor p in inputProperties)
    {
        object value = p.GetValue(input);

        var t = targetProperties.Find(p.Name, false);
        if (t != null && value != null)
        {
            if (value.GetType() == typeof(string) || value.GetType() == typeof(Int64) || value.GetType() == typeof(int) || value.GetType() == typeof(Boolean))
            {
                t.SetValue(target, value);

            }
            else if (value.GetType() == typeof(DateTime) || value.GetType() == typeof(DateTime?))
            {
                if ((DateTime)value > DateTime.MinValue)
                {
                    t.SetValue(target, value);
                }

            }
            else
            {
                t.SetValue(target, value.ToString());
            }
        }

    }
</code>```

答:
Personally, I hate reflection in most cases -- I've seen is used to get around bad design decisions or because people don't know better more often than not.

This is not one of those cases -- really it is a key-value match you are doing and it makes sense if you are willing to always keep field names and types in lock-step.

All that said, you might want to look at AutoMapper as it does this in about 3 lines of code and lots more to boot.


答: From a performance perspective, there is nothing wrong with this code as time it takes to call to the database will dwarf any performance implications of the reflection.  However, you are coupling your domain object to your data object by forcing the property names and types to identical.  If this isn't an issue for you, I think it's fine.</p>

ContentLicense: CC BY-SA 3.0

Title: Is it bad practice to use reflection to do DB inserts with data from an external service?

Body:
Our supplier's webservice is returning address objects (~30 fields) and I'm using LINQ and reflection to store the returned data straight into the databse. I loop over the attributes and set the value from the object to the LINQ class.

I'm fairly new to refection and I'm worried this may be bad practice; it saves ~30 lines of code in 3 or 4 methods but I'm afraid it could introduce hard to fix bugs.

EDIT Here is the code. Target is normally a LINQ to SQL entity and input would be a webservice object.

```<code>public static void SetValues(object target, object input)
{
    Type targetType = target.GetType();
    Type inputType = input.GetType();

    PropertyDescriptorCollection inputProperties = TypeDescriptor.GetProperties(inputType);
    PropertyDescriptorCollection targetProperties = TypeDescriptor.GetProperties(targetType);

    foreach (PropertyDescriptor p in inputProperties)
    {
        object value = p.GetValue(input);

        var t = targetProperties.Find(p.Name, false);
        if (t != null && value != null)
        {
            if (value.GetType() == typeof(string) || value.GetType() == typeof(Int64) || value.GetType() == typeof(int) || value.GetType() == typeof(Boolean))
            {
                t.SetValue(target, value);

            }
            else if (value.GetType() == typeof(DateTime) || value.GetType() == typeof(DateTime?))
            {
                if ((DateTime)value > DateTime.MinValue)
                {
                    t.SetValue(target, value);
                }

            }
            else
            {
                t.SetValue(target, value.ToString());
            }
        }

    }
</code>```


问:
Scrum tool for Product Backlog management
My team and I are very keen on doing Scrum "manual"-style (with paper and scissors). Though, we are struggling to find a tool to manage our backlog.

The main requirements are:

To be able to print the backlog in cards to stick to the whiteboard

To be able to assign backlog items to the releases manually

So far we have not found anything that matches these criteria. Suggestions?

答: We're using Rally. Once the sprint is defined, cards get printed, put up on the board, and we have a feedback loop between the board & the online record. Everyone in the office can see the board, so anyone can know the sprint status.</p>


问:
Are captchas worth the decreased usability?
When is it useful to use a captcha? When is it an unnecessary hindrance? Is a captcha just a quick fix for the lazy/unexperienced programmer, or are they really the best way to prevent spam and bots? </p>

答:
ReCAPTCHA seems to be pretty secure, and will probably outlast any other OCR based CAPTCHA solution. CAPTCHAs are useful when you aren't sure if it's a bot or a human - ie, after the second or third login attempt, or if you allow anonymous commenting. Once a user has authenticated, dump the CAPTCHA.

An alternative that hasn't come up yet is the "SAPTCHA".

ContentLicense: CC BY-SA 2.5


问:
Did concept of ViewModel exist before MVVM?
Today I was having a discussion with a colleague that ViewModel is a general concept and existed before MVVM pattern.

I believe ViewModel term is used anytime you create a class with Model like properties for showing on View that supports data binding like in ASP.NET and even in WinForms.

Is the opposite true? Did Microsoft name it the first time with MVVM?

答:
The MVVM is a specialization of the Presentation Model pattern by Martin Fowler. The Presentation Model pattern is platform independent and MVVM was created to take advantage of the capabilities of WPF (and later on Silverlight).

The Presentation Model was published in 2004 and the MVVM was first presented in blog posting in 2005 by John Grossman.

ContentLicense: CC BY-SA 4.0


问:
Why do many older algorithms papers reference implementations on a PDP-10 or PDP-11?
Take the original Boyer-Moore paper, for instance. It seems every time I look for an algorithm the paper I see referenced is talking about implementation idiosyncrasies on a PDP-10 or PDP-11.

I know these were popular machines at one time, but not so popular as to account for the large number of references I see. Is there a specific reason these machines were used as examples in algorithms papers?

答:
PDPs 10 and 11 (expecially 11/3x, colloquially known as the half past noon series) were not the only one, but they were at the time (and those were the times when you didn't usually find a computer, hell, a calculator in every building), I won't say popular, but not so rare as before.

They were relatively cost efficient, and research institutions and engineering colleges started acquiring them in computing centres for their work. In East Germany a similar (don't know how much similar, though) machine was manufactured.
Programs were written for them (I still have dozens of numerical books with programs written for PDP11) and people, naturally, found no reason to not continue on what was already there.


问:
Distributed transactions and queues, ruby, erlang
I have a problem that involves several machines, message queues, and transactions.  So for example a user clicks on a web page, the click sends a message to another machine which adds a payment to the user's account. There may be many thousands of clicks per second. All aspects of the transaction should be fault tolerant.

I've never had to deal with anything like this before, but a bit of reading suggests this is a well known problem.

So to my questions. Am I correct in assuming that secure way of doing this is with a two phase commit, but the protocol is blocking and so I won't get the required performance?  It appears that DBs like redis and message queuing system like Rescue, RabbitMQ etc don't really help me a lot - even if I implement some sort of two phase commit, the data will be lost if redis crashes because it is essentially memory-only.

All of this has led me to look at erlang - but before I wade in and start learning a new language, I would really like to understand better if this is worth the effort.  Specifically, am I right in thinking that because of its parallel processing capabilities, erlang is a better choice for implementing a blocking protocol like two phase commit, or am I confused?

答:
Based on the comment, you do not have a two-phase commit.  You have two different normal one-phase-commit issues.

A simple (but likely wrong) solution would be to have the web site, when clicked, insert a record in the database.  This can be done transactionally during the web processing, so there is a high probability that the user will know their click was taken.  But at that point they will not know that the payment was made.

A separate system could poll the db (I said it was likely wrong) looking for entries.  If it finds an entry, it can transactionally delete that row, and amend the payment record.  This makes a simple restartable system.

If you want it to be a little more real-time, you could use a queue, with transaction semantics at both ends, and a durable (i.e. disk-based) queue in the middle.

The web click would transactionally enqueue something.  The queue manager would take care of persisting it to disk if that is appropriate.  At the payment end, it can dequeue an item and log the payment.  No two-phase commit required (more-or-less) because you are never really dealing with distributed resources.  If your dequeue server crashed, you should somehow be able to detect if the latest item in the queue is already in the database, but that should be solvable with some kind of request ID in the message.

Unless of course I have completely misunderstood the question.  As I don't understand what two resources you are trying to do the two-phase commit between...


问:
How do you address the gap on your resume after a self-funded sabbatical?
There are a ton of questions on Programmers.SE about whether or not taking extended time off is a good idea and what to do during that time off to maintain your skill level:

https://softwareengineering.stackexchange.com/questions/31536/will-taking-two-years-off-for-school-in-a-related-field-destroy-a-mid-level-devel

https://softwareengineering.stackexchange.com/questions/102009/can-i-take-a-year-off-without-hurting-my-career

If you take a year or two out from being a developer, is it really that hard to get back into it?

https://softwareengineering.stackexchange.com/questions/91176/is-taking-a-break-in-career-to-learn-stuff-a-bad-idea

They've been really helpful, but I still have a question about the logistical details of take a self-funded sabbatical.

I'm coming to the end of a year off from working as a software developer (after 7 years in the field.) I've taken this year to let myself explore interests that I'd never had enough time for: baking, sewing, photography, and making new and interesting friends. During this time, I've also been working on pet development projects in technologies and disciplines that I would never have had the chance to explore otherwise. in addition, I've read all of those software development books I'd never had time to read and kept up with programming news and blogs.

The development projects have all had an eye towards being part of a Micro ISV, but only one of the projects has made it to any sort of production stage. That project is impressive, but not very successful (yet!)

I've got a reasonably active programming blog that I believe reflects a high dedication to software development and demonstrates that I haven't just put my programming skills on a shelf for a year.

My question is: What is the best way to transmit this information to a potential employer at the resume/cover letter level?

I'm reasonably confident that I can explain this sabbatical in an interview setting. I know that at the resume level though, hiring managers will use any excuse they can to throw my resume out (I've done hiring and I would probably have thrown out my own resume if it didn't handle this time off really well, maybe it's karma.) So I feel like the resume/cover letter is the really tricky part in getting a kick-ass new job.

I have a few ideas about what to do, but I'm not sure what the larger community sees as acceptable. Here are the approaches I'm considering:

Put a special section on my resume for the sabbatical time in which I outline the personal projects. If I do this, what's a good way to label it?

Create a personal company name and put these projects in the work
experience section of my resume under that company. This seems like the most go-getter
way to do it, but I'm worried it could be perceived as trickery when
I get to the interview stage. Also if I do this, what do I put as my
title?

Leave my resume as-is and explain everything in my cover letter,
with a link to my active blog.

There's probably something I'm not thinking of, I'm open to any
other ideas.

I know I've included a bunch of special-snowflake information about my personal situation, but I would prefer answers for the more general case. The personal details are here more as an example than as a request for answers designed specifically for me.

答: My suggestion would be to talk to recruiters and fellow developers in the community so that you aren't having to get a resume past HR or other silly games when it comes to finding a place.  With 7 years of experience in the field, you should have enough of a background that you can talk technical details and share battle scars while also knowing enough of what you want that headhunters could place you somewhere so that while you have a gap in your resume, it isn't a big deal if the managers know of you through another source.</p>


答:
Honestly I think you're over thinking it a bit. If you were gaining relevant experience during your time off, then your resume should not even show a break in your work timeline. Instead of a company name just put something like Entrepreneurial Pursuits.

You don't even have to explain in detail each project. The important parts are the technologies you worked on and the business problems you helped overcome. In the end, majority of hiring managers are just playing a game of buzz word search anyways.

Title: How do you address the gap on your resume after a self-funded sabbatical?

Body:
There are a ton of questions on Programmers.SE about whether or not taking extended time off is a good idea and what to do during that time off to maintain your skill level:

https://softwareengineering.stackexchange.com/questions/31536/will-taking-two-years-off-for-school-in-a-related-field-destroy-a-mid-level-devel

https://softwareengineering.stackexchange.com/questions/102009/can-i-take-a-year-off-without-hurting-my-career

If you take a year or two out from being a developer, is it really that hard to get back into it?

https://softwareengineering.stackexchange.com/questions/91176/is-taking-a-break-in-career-to-learn-stuff-a-bad-idea

They've been really helpful, but I still have a question about the logistical details of take a self-funded sabbatical.

I'm coming to the end of a year off from working as a software developer (after 7 years in the field.) I've taken this year to let myself explore interests that I'd never had enough time for: baking, sewing, photography, and making new and interesting friends. During this time, I've also been working on pet development projects in technologies and disciplines that I would never have had the chance to explore otherwise. in addition, I've read all of those software development books I'd never had time to read and kept up with programming news and blogs.

The development projects have all had an eye towards being part of a Micro ISV, but only one of the projects has made it to any sort of production stage. That project is impressive, but not very successful (yet!)

I've got a reasonably active programming blog that I believe reflects a high dedication to software development and demonstrates that I haven't just put my programming skills on a shelf for a year.

My question is: What is the best way to transmit this information to a potential employer at the resume/cover letter level?

I'm reasonably confident that I can explain this sabbatical in an interview setting. I know that at the resume level though, hiring managers will use any excuse they can to throw my resume out (I've done hiring and I would probably have thrown out my own resume if it didn't handle this time off really well, maybe it's karma.) So I feel like the resume/cover letter is the really tricky part in getting a kick-ass new job.

I have a few ideas about what to do, but I'm not sure what the larger community sees as acceptable. Here are the approaches I'm considering:

Put a special section on my resume for the sabbatical time in which I outline the personal projects. If I do this, what's a good way to label it?

Create a personal company name and put these projects in the work
experience section of my resume under that company. This seems like the most go-getter
way to do it, but I'm worried it could be perceived as trickery when
I get to the interview stage. Also if I do this, what do I put as my
title?

Leave my resume as-is and explain everything in my cover letter,
with a link to my active blog.

There's probably something I'm not thinking of, I'm open to any
other ideas.

I know I've included a bunch of special-snowflake information about my personal situation, but I would prefer answers for the more general case. The personal details are here more as an example than as a request for answers designed specifically for me.


答:
but not so popular as to account for the large number of references I see

I strongly disagree. The PDP-11 series was far cheaper than other midrange computers. Some of the cheapest models, such as the PDP-11/34 (started at about $10k) could be purchased on a research grant with money left over for the investigators. This allowed researchers to acquire their own computer during an era when commercially sold "serious" computers tended to start well over $100k. Universities were able to get copies of Unix for free back then, instead of having to pay an additional large sum of money for the operating system to go along with the hardware.

Back then, many companies like IBM were renting their hardware and software. The monthly charges would quickly devour any researchers' grants, and most were too expensive that if the university had one, spare time would be rented out to paying customers.

Title: Why do many older algorithms papers reference implementations on a PDP-10 or PDP-11?

Body:
Take the original Boyer-Moore paper, for instance. It seems every time I look for an algorithm the paper I see referenced is talking about implementation idiosyncrasies on a PDP-10 or PDP-11.

I know these were popular machines at one time, but not so popular as to account for the large number of references I see. Is there a specific reason these machines were used as examples in algorithms papers?


问:
What to do after accidentally erasing many database entries?
Today at work I did an update to production. The update involved replacing old items from two tables with new data. I of course did a back up of the tables before that.

Well, now 6 hours after getting home I realized at shower that there was a foreign key reference on cascade delete for many tables and when I replaced the older data it also removed lots of other data -- I'm not even sure I know all of the data that got removed...

The thing is, there are about 270 tables and I've been to the company for 3 months. I was supposed to do this update today and the CTO was away doing remote work. I tried to contact via Skype and email, but he's away. I figured not to call him at this time of day (late evening here).

What should I be doing here? It's the beginning of weekend and I feel bad leaving the system in such a condition for two days... and especially because I screwed up things.

The client is doing billion dollar business and its the biggest client the company has so this was a major drawback. If the hosting provider does not have nightly backups I will probably get fired. Damn I hate automatic magic like FKs. :(

What would you do in my position?

答:
Let someone know that there is a problem as quickly as possible.

First off, depending on the database vendor and configuration, the DBAs may have the ability to revert the change.  But the options for doing so get harder the more time has elapsed.  Oracle's flashback technology, for example, gives the DBA far more options if the error is noticed quickly than if the error is noticed days from now.

Second, if there is a need to restore from a backup, having the weekend to restore the backup and recover whatever data is needed is much preferable to trying to do the restore and recovery during the week.  It probably takes a few hours at least to get the backup tapes back so, again, time is precious.

Third, from a purely political standpoint, people are going to be far less upset with you about the mistake if you're the one that is sounding the alarm than if someone else discovers the error later.  Everyone makes mistakes.  Not everyone owns up to their mistakes.  I'd much rather have an employee that made a costly mistake, learned a valuable lesson, and had the strength of character to admit the mistake and work to resolve it proactively than to have an employee that made a costly mistake and either tried to hide it or avoid drawing attention to it.


答:
Create a personal company name and put these projects in the work experience section of my resume under that company.

This is generally what folks do, or call it a start-up company that failed.


问:
Decoupling UI code?
In my application I have several event handlers that perform some action in response to user interface events such as a button click or menu selection.  The code in these event handlers looks like this for example:

```<code>void MyDialog::OnCommandLoadFile()
{
    char strFilter[] = { "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||" };

    CFileDialog fileDlg(TRUE, ".txt", NULL, 0, strFilter);

    if( fileDlg.DoModal() == IDOK )
    {
        const std::string path = fileDlg.GetPathName();

        std::vector<std::string> urls;
        int maxNumberOfUrls = settings_->Get<int>(Settings::MaxNumberOfUrls);
        UrlProvider *urlProvider = new FileUrlProvider(path);
        urlProvider->GetUrls(urls, maxNumberOfUrls);

        webMonitoringService_->MonitorUrls(urls);

        DisplayMessage("URLs loaded.");
    }

}
</code>```

This is typical of my event handlers. I don't code monolithic event handlers but they do "glue" various pieces together.  I usually have some business-logic/service classes which the UI has a reference to and in the event handlers I make calls to one or more of these to perform the desired task.

What I'm wondering is is this still too coupled?  If I wanted to turn this into a command line app I'd have to extract bits and pieces from the UI code.  In the above example, there is a compound action going on so should I'm thinking it should look more like:

```<code>void MyDialog::OnCommandLoadFile()
{
    char strFilter[] = { "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||" };

    CFileDialog fileDlg(TRUE, ".txt", NULL, 0, strFilter);

    if( fileDlg.DoModal() == IDOK )
    {
        const std::string path = fileDlg.GetPathName();

        application->MonitorUrlsFromFile(path);

        DisplayMessage("URLs loaded.");
    }

}
</code>```

Is that right? In the above code what would "application" be?  A controller?  Is that the right abstraction for this?  Whenever I need to perform some task in a UI handler, should it always be a one-liner (aside from getting data in or out of text boxes etc.)  Anyone have a pointer to a tutorial that really covers this (in any programming language)?

Furthermore, if in fact you should abstract compound actions, how to you propagate error messages from within the compound abstraction back out to the UI?  An exception hierarchy? Single exception with error code?

UPDATE

I'm looking at the Command Pattern which looks promising.

UPDATE 2

In the end I decided on refactoring my code as described in the Humble Dialog Box paper in the accepted answer.  My understanding is that this is a Model View Presenter (MVP) type pattern and more specifically a Passive View.  The refactoring is going smoothly.  There are some rough edges in my understanding of the full application of the pattern when it comes to things like displaying message boxes and file open dialogs or dealing with event timers but overall I'm happier with my code; the tight coupling was bothering me.

I also found this "bundle": patterns & practices Web Client Developer Guidance: Model View Presenter (MVP) Bundle which has sample MVP code.  It's a web project whereas my current implementation is desktop but I guess that's the beauty of MVP is that it partly doesn't matter.  One thing I got from that was to dependency inject my service layer objects into the presenter rather than new'ing them inside my presenter class.

答:
Your refactoring is fine, especially if MonitorUrlsFromFile() is duplicated code.  You don't need a "decoupling from the UI" sensibility to justify that refactoring; it can be justified on its own merits.

The error propagation scheme depends on a number of factors.  Generally, I use a BackgroundWorker object or thread or something similar to receive status events from a long-running background task, but the project I am currently working on has several business rule validations which will appear on the UI, so my approach is going to change there.

The simplest way to handle basic error propagation is to provide a top-level exception handler in your Main() method or whatever calls your processing loop.

Title: Decoupling UI code?


问:
Patient Record Tracking System

Background

At a medical facility, staff can remove patient records (file folders) from a room. The room is locked using a standard tumbler lock (i.e., no swipe cards).

The medical facility does not have much funding available. All staff members have a computer in their office (some computers are several years old). All staff members, who have permission to fetch file folders, have a computer and a known location.

Problem

A significant amount of time is spent physically "tracking down" the location of patient records. This is inefficient for the person trying to find the files and disrupts other staff who are queried during the search. Eventually (possibly years hence) the records will be digitized.

This is a classic library book check-out problem.

Solution Architecture

This is what I am thinking:

Web service that tracks file folders by ID.

Print QR Code (or bar code) label stickers with ID.

Label all the physical patient record file folders.

Equip all computers with inexpensive scanner (e.g., web cams).

Install QR Code (or bar code) reader software on each computer.

Write software that passes scanned document to code reader software (e.g., press CTRL-F12).

Write a web service that updates a file folder's location given an IP address.

The part that remains is another web service that allows a person to search for an ID. The search result indicates the last known office where the folder was scanned. The tracking process becomes:

Staff takes file folder and returns to office as usual.

Staff holds folder to scanner, presses hot-key.

System audibly (and/or visually) acknowledges new location.

Question

What inexpensive solution would you put in place to substantially reduce the time taken to track down patient records (and curtail disrupting other staff)?

Ideas for hardware components (e.g., inexpensive bar code readers) are appreciated. Inexpensive bar code readers requiring resident driver software that takes several megabytes of RAM, however, would not be feasible (due to older hardware and budget constraints).

The system likely does not need to be perfect, but it should offer a dramatic reduction on the amount of time it takes to locate a physical file folder, with minimal overhead.

Thank you!

答:
My recommendation is to consider RFID instead. Tag the folders with RFID tags. Have scanners on the doors to the offices. Printable tags run about 25 cents each. Wall-mounted RFID readers can be obtained for $100-300 each.

Based on previous experiences, I suspect that when people are in a hurry, they will skip the barcode scanning. RFID is something hand-free that will happen no matter how distracted or hurried the staff are. My local library went to RFID for books, CDs and DVDs. This allows folks to check books out by themselves and replaced barcode readers.

If you prefer to continue with a barcode solution, SystemID is a company that I've dealt with before that has reasonably inexpensive products.

Title: Patient Record Tracking System


答:
MVP, MVC, MVVM, it's all VERY similar. The difference is mainly in exactly where certain things happen, and exactly what layer the user interacts with:

Thick Client/Smart Client - The View classes are the "god object". The code immediately behind the displayed UI knows everything it needs to in order to do its job, including having knowledge of the domain, possibly the DAL (if not using Active Record), and most rules concerning data validation. Most WinForms apps use this architecture, and even many "vanilla ASP.NET" apps have a very thick layer right up against ASP's HTML generator that handles most of this.

MVC - The Controller is the "god object". It is the object most directly interfaced with by the user, and generates or updates an extremely "dumb" presentation layer (View) based on business logic that gives it knowledge about the Model. The Model may contain higher business logic or it may concern itself only with data integrity. The best example I can think of is in video games; the user sees a video screen with the action happening, but for the most part doesn't work directly with that View to do something. Instead there is an HID in his hands, and when he uses it, signals are sent to logic within the Console which incorporate that data and refresh the screen. Some may argue that any app that uses a mouse or keyboard is MVC by this definition, but I would counter that from the concept of the application's top layer (and not the OS on which it resides), wherever there is a cursor or pointer that is the direct target of input via an HID, that is an abstract representation of the user's own hand that interacts with the UI elements.

MVP - The Controller of MVC is replaced with a less-powerful, more single-purpose Presenter. The Presenter still acts as the intermediary between View and Model, but the View often gains a few responsibilities, such as UI event handling. The Presenter acts to provide the View with necessary data from the Model in an easy-to-absorb fashion; either DTOs or bindable properties. This architecture allows for separation of concerns in GUI apps versus Thick/Smart Client architecture, while still allowing the UI to be the layer with which the user is conceptually interacting, and can be accomplished with most languages/architectures.

MVVM - The Presenter gains back some responsibility from the View and becomes a "binding source" for the View. The View provides only the most basic logic, relying instead on "binding points" available on the ViewModel. All the View knows how to do is get and set information provided by "data bindings", and invoke logic exposed through "event bindings". MVVM as a term was coined by Microsoft to describe the Windows Presentation Foundation, in which the View is structured based on XAML markup files that are given logic through defineable bindings to the ViewModel class.

Title: Did concept of ViewModel exist before MVVM?

Body:
Today I was having a discussion with a colleague that ViewModel is a general concept and existed before MVVM pattern.

I believe ViewModel term is used anytime you create a class with Model like properties for showing on View that supports data binding like in ASP.NET and even in WinForms.

Is the opposite true? Did Microsoft name it the first time with MVVM?


答:
Here is what I would suggest:

First take a backup of the database right now to at least preserved what you have at the moment. This will also be helpful if any of the attempts to recover the information that may be lost fails. At least the situation doesn't get worse.

Next get into contact as quickly as you can with the guys running the backups. Then restore that data into a separate database so you can determine what is missing from the live database. This may not be easy but at least it worth trying and it is a start to get everything back on track.

My final recommendation is that you make sure you communicate throughout the process to all stakeholders. Start with your boss as chances are that he will support you or may be able to give you political cover behind the scenes.

Once everybody knows what has happened you will experience a lot of heat. Then apologize and take the initiative to work out a plan to contain and minimize the impact. In my experience, even if stakeholders (including challenging customers) are very angry at you, they still need to you as you are likely to be the best person to resolve the issues. And always remember: It is impossible to over-communicate.

Good luck!

Title: What to do after accidentally erasing many database entries?

Body:
Today at work I did an update to production. The update involved replacing old items from two tables with new data. I of course did a back up of the tables before that.

Well, now 6 hours after getting home I realized at shower that there was a foreign key reference on cascade delete for many tables and when I replaced the older data it also removed lots of other data -- I'm not even sure I know all of the data that got removed...

The thing is, there are about 270 tables and I've been to the company for 3 months. I was supposed to do this update today and the CTO was away doing remote work. I tried to contact via Skype and email, but he's away. I figured not to call him at this time of day (late evening here).

What should I be doing here? It's the beginning of weekend and I feel bad leaving the system in such a condition for two days... and especially because I screwed up things.

The client is doing billion dollar business and its the biggest client the company has so this was a major drawback. If the hosting provider does not have nightly backups I will probably get fired. Damn I hate automatic magic like FKs. :(

What would you do in my position?


答: Call your CTO and (calmly) explain what happened.  You should only call someone after hours in case of an emergency, and it definitely seems that this is an emergency.


答:
What is the best way to transmit this information to a potential employer at the resume/cover letter level?

I've hired people for my team who had one or more sabbaticals in their resume. As a hiring manager I don't see this as a problem as such.

To me it is important that the candidate has a good explanation for the sabbatical. This explanation should be consistent with the overall story. It is not my business to judge, even if I personally wouldn't take a sabbatical for the given reason.

People take sabbaticals for all kinds of reasons. They could be working in a charitable organization, being a stay-home parent for while, using the time to learn new things, taking an extended trip, and a lot more.

I guess the important thing is that the sabbatical doesn't just happen but is a conscious decision by the candidate. It should not be the cover up for something else, e.g., time in jail.

You should definitely include the sabbatical in the resume. Don't blow it out of proportion compared to your other career steps. I probably wouldn't include it in the cover letter unless I was applying for the first job after the sabbatical.

Good luck!


答: The PDP-11 had a very regular instruction set, which made it much easier to write code for than most of its competitors.  That also made prototype implementations easier to understand.  DEC's FORTRAN compilers were also very good, giving the best "bang for the buck" (performance-wise) as it were.</p>


答:
I would record the year on my resume under a separate section titled appropriately ("Sabbatical" maybe), with each interesting project listed as appropriate.

In the cover letter, I'd treat the period as I would any other work experience - and mention any relevant components, as they relate to the work I am applying for.


答:
Don't worry about it. You can leave a gap if not too long and you have enough other significant background.  When I'm hiring and see a candidate I'm interested in with such a gap, I'll just ask.  It's not a dis-qualifier at all.

Caveat ... I would consider a year to be about the max for this technique.


问:
Start to understand an existing project for beginner programmer
I want to understand an existing project to improve myself more, but I am not sure if the project would be overwhelming for me or not. I am not sure if I am capable of understanding it. I even think that I will fail. When I look at projects at a glance, it makes me feel scared to see thousand line of codes.

I don't even know where to start reading code. Do I have to follow by debugging or is there something else?
Can you please guide me in this situation? I am totally getting confused at the start.

Edit : A few thing to specify about my question.

I know C# language and I have learned some WEB technologies like ASP.NET, MVC 2, and Web Forms but I am sure there still will be many thing which I don't know. I label myself as beginner but it is just because of a lack of professional experience in this area. But my OOP understanding is good enough. I am wanting to improve myself on WEB, so I am looking for WEB projects like blog engines which are simpler than others for starting.

答:
A few tacts I've used for diving into an existing codebase:

Read any high-level documentation you can find on the project, and/or try to get an overview of how things work from someone else working on the project.

Trace a few function calls though the code and see what happens.  Try to pick something that looks like it hits at least a few major subsystems.

Try to implement some simple functionality.  It'll probably take a while and a lot of digging through code, but it's a good way to start understanding the code.

Try to diagram the system at a high-level, or an important subsystem at a slightly lower level.  A uml-ish class diagram or sequence diagram will work.  The process of reading the codebase to construct such diagrams can be very educational.


答:
The people thinking up new algorithms and writing about them were in environments where those were the typically available machines. There were other machines around (IBM 370, PDP-9, Burroughs, Univac, Honeywell, Xerox), but DEC had figured out how to sell to those environments where people thought most about algorithms, AI, etc.

This was smart because those environments (universities, research labs) would generate a flow of people into industry who had brand loyalty to DEC.


问:
Do exceptions basically exist to prevent a system from crashing?
Second of all, I was wondering if anyone knew what the difference was between exceptions (in the realm of exception control flow) and Exceptions (such as used in Java).

But are they there to basically protect the system from crashing by terminating the user program?

答:
Exceptions exist to allow Exception Handling, which can avoid crashes but more generally prevent unwanted or unpredictable system behavior. For instance if my program's connection to a database times out it's usually not going to crash the system, but if I was depending on data from the database an exception can allow me to treat this data-less situation differently than normal.

Say by default my program displays a page of data based on what was returned from the database--well crap, I have no data. Instead of presenting a messed up view or continuing a potentially invalid operation I can catch this exception and fall back to a different database, read from local data, ask the user for data or otherwise return the user or system to a safe state (presumably one that will not immediately cause the same exception!)

In addition in systems where user input could be the cause/solution to a problem, exceptions can let a user know detailed and helpful info about the problem. Instead of the too common "An unhandled exception occurred at..." or "Intimidating Error Message Straight from SQL" you can tell the user something helpful or at least understandable like "Could not connect to resource B."


答:
The point of an exception should be to inform the user of exceptional circumstances. If something goes wrong with the system the program should know and be allowed to handle it *appropriately.

That said, no, an exception does not exist to prevent the system from "crashing". An exception it is letting me know there is a problem. How I proceed determines can determine if the system "crashes".

Also note that an exception does not have to terminate an application as you have said. An exception can be handled by the programmer and corrected or turned into some meaningful error to the user.

*The use of checked exceptions (exceptions that are forced to be caught) is a bit of a sore spot. Some (perhaps most) developers find that forced exception handling is cumbersome, unneeded, and just bad practice.

Title: Do exceptions basically exist to prevent a system from crashing?

Body:
Second of all, I was wondering if anyone knew what the difference was between exceptions (in the realm of exception control flow) and Exceptions (such as used in Java).

But are they there to basically protect the system from crashing by terminating the user program?


问:
OO Design principle name?
I think I remember reading somewhere that one of the principles of good OO design is to write methods which take the least derived type possible, but return the most derived type possible?  First, is there such a principle and second, what name would it go by?  I'm looking for the name so that when I mentor other developers I can refer them to it.</p>

答:
I don't remember the "name" for this principle but it certainly exists and is much more general than only OO.

The basic idea is to be lenient on what inputs you accept (so you can accept input from more sources) and stringent on what outputs you produce (so others have to go through less trouble to use it)

Title: OO Design principle name?


答:
Exceptions were created to simplify error-handling.  Without exceptions, error handling logic must be spread throughout an application.  Any function that could possibly result in an error must somehow return an error status, and each call must be followed by a check for error.  Often the caller can do nothing useful in case of error, and can only return an error itself.  Half the application code may be devoted to error handling.  Such code is extremely fragile.  It is all too easy to leave out an error check and crash, or worse, return incorrect results due to an unnoticed error.

With exceptions, errors can be checked only at the point where they can be handled.  Most application code can be written in straight-line fashion, since functions will either return a usable value or throw an exception.


答:
Exceptions allow modern error handling by splitting the error location from the error handler. Sometimes this is used for flow control too.

Unhandled exceptions terminate a program. But these are not different from the former exceptions, just a lazy programmer who forgot to include proper error handlers in every path
makes them visible to the end user. I consider a program terminated by exception as crashed same as any other unexpected end.

OSes are very good an cleaning up crashed processes no matter how they crashed, so exceptions don't add safety for the OS any other way than terminating malfunctioning processes and
releasing their resources.


问:
Is it a good idea to always use Google as the first step to solving a problem?

Possible Duplicate:

  Importance of learning to google efficiently for a programmer?

Avoiding lengthy discussions, as a senior level student in CS, how can I get away from Googling problems I run into? I find myself using it too much; I seemingly reach for the instant answer and then blindly copy and paste code, hoping it works. Anyone can do that. I've read the related threads about being a better programmer, but mostly those recommend practicing on pet projects, which I have done, but again I feel EVERY wall encountered, from design through completion, was hurdled with Google.

Do professionals instantly "research" their problem? Or do you guys step back and try and figure it out yourselves?

I'm talking about both 'algorithm/design' problems as well as compiler issues.

答: I usually Google problems pretty quickly, but there is something to be said for thinking about problems before you search. This will obviously depend on the type of problem, but by thinking about a problem before you read the solution, you will be likely to remember more.</p>


问:
Why do languages such as C and C++ not have garbage collection, while Java does?
Well, I know that there are things like malloc/free for C, and new/using-a-destructor for memory management in C++, but I was wondering why there aren't "new updates" to these languages that allow the user to have the option to manually manage memory, or for the system to do it automatically (garbage collection)?

Somewhat of a newb-ish question, but only been in CS for about a year.

答:
The short and boring answer to this question is that there needs to be a non-garbage collected language out there for the people that write the garbage collectors. It's not conceptually easy to have a language that at the same time allows for very precise control over the memory layout and has a GC running on top.

The other question is why C and C++ don't have garbage collectors. Well, I know C++ has a couple of them around but they aren't really popular because they are forced to deal with a language that wasn't designed to be GC-ed in the first place, and the people that still use C++ in this age aren't really the kind that misses a GC.

Also, instead of adding GC to an old non-GC-ed language, it is actually easier to create a new language that has most of the same syntax while supporting a GC. Java and C# are good examples of this.


答: Before the PC era, PDP10s were the most cost effective computers to give students access.</p>


答:
There's various issues, including...

Although GC was invented before C++, and possibly before C, both C and C++ were implemented before GCs were widely accepted as practical.

You can't easily implement a GC language and platform without an underlying non-GC language.

Although GC is demonstrably more efficient than non-GC for typical applications code developed in typical timescales etc, there are issues where more development effort is a good trade-off and specialized memory management will outperform a general-purpose GC. Besides, C++ is typically demonstrably more efficient than most GC languages even without any extra development effort.

GC is not universally safer than C++-style RAII. RAII allows resources other than memory to be automatically cleaned up, basically because it supports reliable and timely destructors. These cannot be combined with conventional GC methods because of issues with reference cycles.

GC languages have their own characteristic kinds of memory leaks, particularly relating to memory that will never be used again, but where existing references existed that have never been nulled out or overwritten. The need to do this explicitly is no different in principle than the need to delete or free explicitly. The GC approach still has an advantage - no dangling references - and static analysis can catch some cases, but again, there's no one perfect solution for all cases.

Basically, partly it's about the age of the languages, but there will always be a place for non-GC languages anyway - even if it is a bit of a nichey place. And seriously, in C++, the lack of GC isn't a big deal - your memory is managed differently, but it isn't unmanaged.

Microsofts managed C++ has at least some ability to mix GC and non-GC in the same application, allowing a mix-and-match of the advantages from each, but I don't have the experience to say how well this works in practice.

Rep-whoring links to related answers of mine...

https://stackoverflow.com/questions/1529679/how-do-you-program-safely-outside-of-a-managed-code-environment/1529731#1529731

https://stackoverflow.com/questions/1424660/garbage-collection-vs-non-garbage-collection-programming-languages/1496547#1496547

https://stackoverflow.com/questions/4984849/why-circular-referenced-objects-with-del-defined-are-uncollectable-in-python/4984934#4984934

https://stackoverflow.com/questions/5009869/how-to-implement-garbage-collection-in-c/5009984#5009984

Title: Why do languages such as C and C++ not have garbage collection, while Java does?

Body:
Well, I know that there are things like malloc/free for C, and new/using-a-destructor for memory management in C++, but I was wondering why there aren't "new updates" to these languages that allow the user to have the option to manually manage memory, or for the system to do it automatically (garbage collection)?

Somewhat of a newb-ish question, but only been in CS for about a year.


答:
Garbage collection is fundamentally incompatible with a systems language used for developing drivers for DMA-capable hardware.

It's entirely possible that the only pointer to an object would be stored in a hardware register in some peripheral.  Since the garbage collector wouldn't know about this, it would think the object was unreachable and collect it.

This argument holds double for compacting GC.  Even if you were careful to maintain in-memory references to objects used by hardware peripherals, when the GC relocated the object, it wouldn't know how to update the pointer contained in the peripheral config register.

So now you'd need a mixture of immobile DMA buffers and GC-managed objects, which means you have all the disadvantages of both.


问:
Becoming a "maintenance developer"
So I've kind of been getting angry about the current position I'm in, and I'd love to get other developers' input on this.

I've been at my current place of employment for about 11 months now. When I began, I was working on all new features. I basically worked on an entire new web project for the first 5-6 months I was here. After this, I was moved to more of a service oriented role (which was still great, all new stuff for me), and I was in this role for about the past 5-6 months. Here's where the problem comes in.

Basically, a couple of days ago I was made the support/maintenance guy. Now, we have an IT support team, so I'm not talking that kind of support, I'm talking more of a second level support guy (when the guys on the surface can't really get to the root of the issue), coupled with working on maintenance issues that have been lingering in the backlog for a while. To me, a developer with about 3 years of experience, this is kind of disheartening.

With the type of work place this is, I wouldn't be surprised if these support issues take up most of my days, and I barely make it to working on maintenance issues. Also, most of these support issues aren't even related to code, they are more or less just knowing the system architecture, working with making sure services are running/getting started properly, handling/fixing bad data, etc. I'm a developer, so this part sucks. Also, even when I do have time to work maintenance, these are basically just bug fixes/improving bad code, so this sucks as well, however at least it's related to coding.

Am I wrong for getting angry here? I don't want to really complain about it, but to be honest, I wasn't spoken to about this or anything, I was kind of just sent an e-mail letting me know I'm the guy for this type of thing, and that was that. The entire team took a few minutes to give me their "that sucks" talk, because they know how annoying it is to be on support for the type of work we do, so I know I'm not the only guy that knows it's not that great of an opportunity.

I'm just kind of on the fence about how to move forward. Obviously I'm just going to continue working for the time being, no point making a bad impression on anybody, but I'd like to know how you guys would approach this situation, or how you think I should be feeling about it/how you guys would feel.

答:
It's worth noting that the role of maintenance engineer is not one, in a smart organization, given to someone because they're not good enough for something else... it's given to them because they ARE good enough to handle the particular role. Keeping existing systems up and running is an extremely important role and, depending on the company, many millions of dollars can balance on the tip of said engineer(s) doing their job well.

That being said, while most managers will intuitively understand that the role needs a skilled individual to handle it, most don't recognize the achievements of said programmers, and it can be hard to get recognition for your work. It's entirely too easy to be put in the role because you are skilled, and them forgotten about as raises and promotions are handed out later... because the sign of you doing a great job in your role is that nobody notices that you're doing a great job in your role.

It's possible to fight for the recognition you think you deserve for fulfilling the role, but I'm not entirely sure it's worth the large effort involved. Instead, I'd recommend discussing with your manager the concept of (as others have mentioned) rotating the role through the various developers available for it. If possible, have at least one person in the role full time and one person part time. The part timer can learn about the systems and what's involved in maintaining them from the full timer. When it's time to rotate, the part timer can take over as full timer, and a new person comes in as part timer (and learns from the now full timer).

If it makes you feel any better, the people in Ops are in the same position... the sign of a great Ops person is that nobody notices how well they do their job. Only, for an Ops person, they can't really rotate out because it IS their primary role. I'm a big fan of always praising the Ops people I work with, publicly and vocally, because dev is one of the few groups that can see how much better they make everyone else's lives.

That tangent aside... if you do rotate the position of maintenance, the next time you come into the role make sure to give the people before you their chops if you see they did things that make your life easier now that you're back in the role... do so publicly and vocally.

OwnerDisplayName: anon

Title: Becoming a "maintenance developer"


问:
Domain knowledge vs Programming

Possible Duplicate:

  How important is Domain knowledge vs. Technical knowledge?

I often hear from my colleagues and sometimes from interviewers that,

"There is nothing so great in having excellent programming knowledge.
  One must gain the domain knowledge as the 1st priority. If you have a
  good domain knowledge, then writing code for that is not a big deal."

(Here domain knowledge is something related to area you are working in. For example, I work in telecom domain, someone might be in Finance or Pharma or Web development or Embedded and so on.)

I disagree with above passage and think exactly opposite. In my career till now, I have seldom missed any deadline for bugfix or feature enhancement. I have kept changing the domains (within telecom) but stuck with learning the programming techniques. Though I might be wrong.

Questions:

Is my current approach correct ?

Given a choice between domain or programming (with limited time)
which one should be chosen ?

Is there a good future for a person, who is primarily a very good
coder but not so great in a domain (of course initially) ?

I ask this because, I feel that every domain ultimately boil down to code sea in which one has to dive!

答:
If you wish to remain only a programmer, working for a company, then domain knowledge is not necessary but if you have, it is good. If you are a part of a team and you have a program manager, then he should possess little domain knowledge. In your case, you gain a basic domain knowledge while working on a project. For example, if you are involved in the development of a product in Telecom domain, then after a certain period of time, you do get a basic knowledge of the Telecom Services Provider.

From my experience, if you run a company or is a part of business development process, then definitely you should have a domain knowledge. You should also have a knowledge of your competitors.

Anyhow, you should keep your eyes open because you won't remain a programmer life long. In future you may lead projects.

Edited

And also, highly scalable products are possible only when you have excellent domain knowledge.

Title: Domain knowledge vs Programming


答:
One could even define programming as "mapping domain knowledge to code", so obviously mastering both the domain and coding is mandatory. You have to dive in the code sea, yes, but it's not enough. How could  you write the program without knowing what the program is supposed to do? Or, if you know what your program should do, how could you write it if you can't code?

In many cases, the programmer has to know the domain even in more detail than some plain "domain specialist", because the specialist can solve all kind of exceptions and corner cases with his common sense and experience as they turn up, but the programmer has to explicitly handle all those details in the code, before they turn up.

Given a choice between domain or programming (with limited time) which one should be chosen?

At any given moment, the best bet is to improve your weakest point. And, there are easier and harder domains. If you're making mobile phone toy games, then the domain is probably not that hard; the harder part is making the program efficient, portable, good-looking, etc. But if you're making nuclear power plant control program, then it may take years of intensive study to actually master the nuclear physics that your program has to deal with.

Is there a good future for a person, who is primarily a very good coder but not so great in a domain?

You can approach total mastery from either direction, but in the end, you have to master both coding and the domain.

Title: Domain knowledge vs Programming

Body:
Possible Duplicate:

  How important is Domain knowledge vs. Technical knowledge?

I often hear from my colleagues and sometimes from interviewers that,

"There is nothing so great in having excellent programming knowledge.
  One must gain the domain knowledge as the 1st priority. If you have a
  good domain knowledge, then writing code for that is not a big deal."

(Here domain knowledge is something related to area you are working in. For example, I work in telecom domain, someone might be in Finance or Pharma or Web development or Embedded and so on.)

I disagree with above passage and think exactly opposite. In my career till now, I have seldom missed any deadline for bugfix or feature enhancement. I have kept changing the domains (within telecom) but stuck with learning the programming techniques. Though I might be wrong.

Questions:

Is my current approach correct ?

Given a choice between domain or programming (with limited time)
which one should be chosen ?

Is there a good future for a person, who is primarily a very good
coder but not so great in a domain (of course initially) ?

I ask this because, I feel that every domain ultimately boil down to code sea in which one has to dive!


答:
Domain knowledge is good but this is not the responsibility of the programmer. It is the responsibility of business analyst, systems analyst, data modeler, software testers, software architects and sometimes the project manager. Each of these categories require different level of domain knowledge.

The programmer is not supposed to gather or formulate requirements. He/she is supposed to understand requirements and implement these requirements, at least that is in the case in large institutions.

The reason for my argument is that business domain knowledge includes business functions, laws, regulations, interface policies with other businesses, business agreement between organizations, and lots of other details never discussed with developers. Also, programming is not a light skill to acquire and maintain. For example, You can't expect someone to know banking compliance rules, regulations, and OOP.

Nevertheless, a programmer who has worked in a bank for 10 years, would indeed know about banking products and banking system architecture more than a programmer who works for a Telco. This knowledge, makes that programmer more appealing to banking jobs, specially if the new environment uses the same software as the the job seeker environment (for example, same CRM or Credit Card Processing application). In oil companies in Canada, specifically, they usually ask for Oil & Gas expertise from developers - I never been able to justify that.

Domain knowledge allow a programmer to move to other careers if he/she so wishes but defining and documenting domain knowledge is not obvious without a certification, courses or a degree.

In my opinion, the core and foremost important qualification of a programmer should be the technical knowledge in his specialty stack.

Title: Domain knowledge vs Programming


问:
How can I design an efficient moderation system for comments?
Here's the job I want to do:

My project is a website where there will be a lot of comments.
Those comments will be moderated: a moderator will connect, see comments and accept or refuse them.

I need those things:

the comments won't have any "moderator" associated. Which implies that when a moderator connects, the system "assigns" the 20 first comments to this moderator then sends them via an AJAX/JSON request

of course, this implies that those comments musn't be assigned to other moderators

How can I make a design so that I'll be sure "getting the 20 first comments for a moderator" can be an atomic operation?
And there's another thing to think of (I don't know if it may have an impact or not on my problem): if there are say 10 moderators connected, one of them has 20 comments to validate, and this guy leaves his PC for the whole day. I may implement kindof a "timeout" for this moderator, then, when he tries to validate, a message will tell him "sorry this comment has already been moderated by another moderator", and the AJAX script will get a "fresh new 20 comments).

My first idea was the simplest idea:

a moderator connects

a jQuery AJAX script asks the server for 20 comments

the server (1) makes immediately a request of the 20 first free comments to the database

the server (2) "freezes" the 20 free comments

the server (3) makes up a JSON response and sends it

But the operations (2) and (3) are not atomic, what happens if, in-between, another operator asks for the 20 first free comments? They both will get the 20 first free comments. That's not a good solution. I think this is a classical problem of atomic operation on db. Any idea how to design this (or where to look)?

Thank you very much indeed!

答:
You're planning to deal with much concurrent activity, so that means you've got to think in terms of atomic operations. That means using transactions.

Now, you don't want to hold a transaction for a long time as it blocks other transactions, so you have to think about using the transactions to protect minimal state changes and putting guards on the UPDATE operations so that only the things that are supposed to change actually do so.

What would you be wanting to UPDATE? Well, the first step has got to be to introduce an association between the comment and the moderator to whom it is assigned, but you've also got to set a time after which the moderation becomes invalid (so that a separate cleanup job can know to reset the association and let some other moderator have a go). Conceptually then, you're doing:

For the start of moderation:

In one transaction:

Pick 20 comments that are not assigned to a moderator.

For each of those, assign them to the “current” moderator and set an expiry time (e.g., in 15 minutes).

On performance of a moderation action for one comment:

In one transaction:

See whether the comment is still assigned to the “current” moderator.

See whether the expiry time has been reached.

If both conditions are true, update the comment with its new moderation status and remove the association with the moderator.

If either is false, moan!

As a separate cleanup task (performed every X seconds):

In one transaction:

Go through the table of assigned comments, and if the expiry time on an entry is in the past, remove the assignment.

Given the above, you'll probably want to have the relation between comment IDs, moderators and the expiry times in a separate table that is indexed by comment ID (which might even be reasonably the primary key).


答:
Excellent question.

A programmer does not need domain knowledge. A good, well-rounded programmer should have the ability to interpret domain-specific requirements and obtain domain knowledge to solve problems, but in my opinion should promptly forget that information.

You have a choice - do you want to be a subject matter expert, or a technical expert?

If you want to work at one company, or stick to a specific industry, then gather that domain knowledge and climb the rungs. You'll soon shift from being a programmer to being someone who works with the rest of the business, liasing between management / marketing (who have business requirements) and the technical team (who just know how to translate technical problems into code). You'll be the guy who sees the requirements document and thinks "Hey, they forgot about scenario X when the moon is in the seventh house and Jupiter aligns with Mars". You are a subject matter expert.

If you want to have core technical skills, you avoid domain knowledge and keep growing your technical skills. This doesn't mean you should be belligerent and refuse to learn. It just means that gathering this knowledge is not your core focus. There are enough technical challenges in software engineering without focusing on business knowledge if you choose to pursue them. Become a solution architect; drive your organisations technical capabilities. You are a technical expert.

It's a legitimate choice. I choose technical expert every time. It means I can work anywhere, and never be sidetracked into work I don't want to do.

Title: Domain knowledge vs Programming


问:
What to do when time estimation goes wrong?
Let’s say you estimated time for a case to be 3 days.
In day two you notice that the case is growing and new scenarios are popping up which were not counted when the time estimation where done.  The new finding leads to 2 days extra (total 5 days). This is a typical problem that you will face sooner or later as developer.

Which strategy can be used when you are going to notify project leader the new time of delivery?

Often you get the question why? How do you motivate the new time of delivery?

The fact is that many projects don’t put much time on analysis & design during SDLC.

EDIT:
In very complex projects no matter how much reasonable time you put on Analysis & Design there are always surprises since the business rules are too complex. However in such cases I believe the project leader must be aware of the complexity and have right attitude when unexpected surprises comes up. The question is how to tackle project leaders who don’t understand the complexity.

答:
I believe the best strategy is constantly refining your estimation.
I know, I'm saying: your question is somehow misplaced.

Reading Introducing Deliberate Discovery by Dan North I came to the conclusion that placing the estimation effort in the inception phase equals to make a prediction exactly when your ignorance of the problem and the domain is at a maximun level. Face it, you cannot predict what's uncertain, especially if it's still unknown.

Agile methodologies solve this problem breaking the project's life span into several pieces (sprints, in Scrum), and repeating the estimation (sizing stories) each week. Each week, what you know about the problem is refined, and so is the estimation.

To me, an estimation cannot be true or false. It just can be increasily refined. An estimation is not a commitment. That's why it's called estimation.

The best you can do when you are late (and also when you "risk to deliver in advance", because the problem is the same: you have estimated badly) is to escalation and raise the fact to the customer as soon as possible. It's called risk management. The sooner you give a feedback, the more effective the counter-misure will be. Usually that means that, if you have evidences you cannot deliver everything, yu should talk to your customer, tell her you can deliver only the 70% of the commitment and let her decide what's has more business value for her and should deployed first.

I wrote about it here Wrong estimation, help! I’m late! Cut features and stop waterfalling!


答:
This seems to be a variant of Postel's Law, also called the Robustness Principle:

Be liberal in what you expect and coservative in what you send.

Title: OO Design principle name?

Body: I think I remember reading somewhere that one of the principles of good OO design is to write methods which take the least derived type possible, but return the most derived type possible?  First, is there such a principle and second, what name would it go by?  I'm looking for the name so that when I mentor other developers I can refer them to it.</p>


问:
How do mashups work with same-orgin policy?
If Javascript is only allowed to access scripts from the same domain, how can a website create mashups which must read and modify content from another domain?</p>

答: You can use API(of another domain) for that. Your Javascript will call the PHP file(or other script file) that is on your web server(your domain), which will call the API(of another domain using CURL) and get the response to you.  </p>


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
You don't say what technology stack you'll be working in but:

MSDN License

or

Licenses to any software/tool required


问:
Tools for managing a complicated project setup with many frameworks and no documentation
We have to extend a huge java project that makes use of frameworks like maven, spring, struts, freemarker and closure templates.

We do have access to source code but barely any documentation, and we have to extend this system. Our only solution is to find the place in the existing code, where something similar is already done. To find this place, we try to start from the action that is called and then with the help of the debugger try to find out which classes and Spring beans are involved.

The stack traces from the debugger are quite hard to understand, since a lot of reflection is being used.

Does anybody had a similiar setup and could provide a few tipps how to manage such a complicated setup?

答:
how to manage such a complicated setup?

You need two things which are extremely important:

1. Good developers

We are talking reverse engineering here.

There are lots of programmers who can follow a tutorial or copy-paste code they barely understand, or follow the company's training program and roll out working code, but for this kind of situation you need people to do the opposite. Instead of building something, you have to tare something apart and see how it works so that you can later build on it, maintain it, evolve it etc.

Skills are necessary for this, so you need experienced developers. Juniors won't do! Even if they are good developers and hard working people they "haven't yet seen the horrors of war".... if you understand what I mean.

2. Support from management

This is even more important than number one. If you have lots of frameworks, it's a huge project, it's not documented, maybe the business domain is new to you etc, then to get up to speed and be able to enhance the system you need time. You can't just roll up your sleeves and start coding the new features. You must learn, dissect, analyze change a little, test a little etc.

Does management realize this? Are they perfectly aware of the risks that such uncertainty generates? Are they supporting you (they must be the ones to buy you this time, projects don't have the luxury to go on forever) or are they putting pressure because "everything takes to long"?

It's never easy to manage a situation like this, but people are the ones to put your bets on, not tools or UML diagrams.

Best of luck to you!


问:
From TFS to Git
I'm a .NET developer and I've used TFS (team foundation server) as my source control software many times. Good features of TFS are:

Good integration with Visual Studio (so I do almost everything visually; no console commands)

Easy check-out, check-in process

Easy merging and conflict resolution

Easy automated builds

Branching

Now, I want to use Git as the backbone, repository, and source control of my open source projects. My projects are in C#, JavaScript, or PHP language with MySQL, or SQL Server databases as the storage mechanism.

I just used github.com's help for this purpose and I created a profile there, and downloaded a GUI for Git. Up to this part was so easy.

But I'm almost stuck at going along any further. I just want to do some simple (really simple) operations, including:

Creating a project on Git and mapping it to a folder on my laptop

Checking out/checking in files and folders

Resolving conflicts

That's all I need to do now. But it seems that the GUI is not that user friendly. I expect the GUI to have a Connect To... or something like that, and then I expect a list of projects to be shown, and when I choose one, I expect to see the list of files and folders of that project, just like exploring your TFS project in Visual Studio. Then I want to be able to right click a file and select check-in... or check-out and stuff like that.

Do I expect much? What should I do to easily use Git just like TFS? What am I missing here?

答:
I switched from SVN to git one year ago, and I'm very happy about it. However, I'm not relying on any GUI and in case you rigidly refuse command line it may be a problem.

You seem to expect git to work the way you're used to, but it doesn't. It's not hard, but you should take a look at its principles before you proceed.

Creating a project on Git and mapping it to a folder on my laptop

Git is distributed, which means you always work with your local repository, which may be mapped to any number of remotes, including zero. When playing with other's project I'm using two remotes: their git or SVN repository and my own server.

I always start by creating an empty directory and then either git init or git clone SOME-REMOTE-REPOSITORY. This link could help you.

Checking out/checking in files and folders

You missed to write what GUI you're using. Both TortoiseGit and git-gui surely can do it.

Resolving conflicts

For this I'm using git-gui or my favorite text editor.

I expect the GUI to have a Connect To... or something like that

Connect to what, when there may be 0 to N remotes? Git doesn't stay connected to a remote server, it creates the connection only temporarily and only for the few commands working with the remote repository. Most of the work gets done locally.

then I expect a list of projects to be shown

I'm assuming by projects you mean repositories.

I'm afraid there's no such thing. Git on a remote server works strictly with one repository only. Listing all repositories is equivalent to listing all directories containing the subdirectory .git. I'm sure there's something like this on GitHub.

I choose one, I expect to see the list of files and folders of that project, just like exploring

Again, I'm afraid there's no such thing, since git works locally. And again, it wouldn't be of much use. Simply clone the repository and explore it on your computer. While cloning of huge repos takes some time, all subsequent operations are much faster, and you may look at any commit or branch.

Then I want to be able to right click a file and select check-in... or check-out and stuff like that.

Again, git works locally. So it makes no sense to check-in or check-out to a remote repo. Working this way is a waste of time even on a fast LAN. Get the repository to your computer, work with it and git push the changes to the remote. Think about it like about publishing your changes and also making backup. You should commit locally very often.

Before you start your work, git fetch or git pull the changes from the remote in case somebody else may have been working with it.

Do I expect much?

Yes and no. You expect something different from what it offers. You can get something much better, git is powerful, flexible, safe, fast like hell, and can do everything you need, but it can't mimic exactly what a centralized VCS does.

Title: From TFS to Git


答:
Do I expect much?

Yes

What should I do to easily use Git just like TFS?

Nothing. Git is CLI-centric and haven't any good frontend (I know about TortoiseGit, which is not answer, comparing to other Tortoise*). You can try to use SmartGit (beware of Java)

Title: From TFS to Git

Body:
I'm a .NET developer and I've used TFS (team foundation server) as my source control software many times. Good features of TFS are:

Good integration with Visual Studio (so I do almost everything visually; no console commands)

Easy check-out, check-in process

Easy merging and conflict resolution

Easy automated builds

Branching

Now, I want to use Git as the backbone, repository, and source control of my open source projects. My projects are in C#, JavaScript, or PHP language with MySQL, or SQL Server databases as the storage mechanism.

I just used github.com's help for this purpose and I created a profile there, and downloaded a GUI for Git. Up to this part was so easy.

But I'm almost stuck at going along any further. I just want to do some simple (really simple) operations, including:

Creating a project on Git and mapping it to a folder on my laptop

Checking out/checking in files and folders

Resolving conflicts

That's all I need to do now. But it seems that the GUI is not that user friendly. I expect the GUI to have a Connect To... or something like that, and then I expect a list of projects to be shown, and when I choose one, I expect to see the list of files and folders of that project, just like exploring your TFS project in Visual Studio. Then I want to be able to right click a file and select check-in... or check-out and stuff like that.

Do I expect much? What should I do to easily use Git just like TFS? What am I missing here?


答:
The advantages git has come from tossing out a lot of old assumptions about what a VCS should do.  The disadvantages git has come from not being able to leverage prior experience and not being able to do things the way you are used to.

If you are going to switch from something else to git, try to start tabula-rasa (though it is impossible to truly do in practice). Evaluate it based on what it does and how well it does it, not on how it does it compared to how you are used to doing it. It's not that you expect too much, it's that your expectations are orthogonal to what git provides. If you're married to GUI operation, you'll be disappointed.  Git does have gui tools available, but they don't add much.  That's not a failure to provide them so much as there isn't that much that a gui can add. GitK does help, not in day-to-day operations, but rather in visualizing the branch structure and examining or searching history.

Here's a goofy analogy for what I mean by "orthogonal".  One of the things you can do with a newspaper is wrap fish in it, or use it to line a birdcage.  But those are not essential to the function of a newspaper, those are incidental features of the form it comes in.  Expecting git to "check in files", or "allow you to select projects", or provide a "connect to..." is kind of like expecting to be able to wrap fish or line your birdcage with a newspaper's website.

Title: From TFS to Git


问:
Two factor authentication using time base key generator on smartphones
I recently enabled two factor authentication for my Google account. One of the ways of getting the second factor (the key that I have) is to install an Android app on my phone that displays a key for a short duration of time.

What does it take to create a web server solution paired with a smartphone solution?

I am using Windows and .NET on the server side and would be interested in both Android and iPhone apps. Are there existing libraries out there or do I need to start from scratch? Where is some starting documentation and explanations of the techniques used?

答: Look up cryptographic hash functions.  The more popular ones, like SHA-1, should have libraries in almost every language. For example, android has the java.security.MessageDigest class.  You would hash the current date and time down to the minute, together with a long string unique to the individual, then modify the output somehow to make it reasonable to type into a login dialog.</p>


答:
Project estimation is gambling, plain and simple.
There's no reward without risk.

If the manager doesn't understand this, that is the first thing I would explain.

The question is, who covers the risk?

If you're on a fixed-price contract, then you are covering the risk.

If time-and-materials, then he is covering the risk.

So when estimating, it's important to understand that you're guessing, and you need to have an idea how uncertain the estimate is, and who is covering the risk.

Title: What to do when time estimation goes wrong?

Body:
Let’s say you estimated time for a case to be 3 days.
In day two you notice that the case is growing and new scenarios are popping up which were not counted when the time estimation where done.  The new finding leads to 2 days extra (total 5 days). This is a typical problem that you will face sooner or later as developer.

Which strategy can be used when you are going to notify project leader the new time of delivery?

Often you get the question why? How do you motivate the new time of delivery?

The fact is that many projects don’t put much time on analysis & design during SDLC.

EDIT:
In very complex projects no matter how much reasonable time you put on Analysis & Design there are always surprises since the business rules are too complex. However in such cases I believe the project leader must be aware of the complexity and have right attitude when unexpected surprises comes up. The question is how to tackle project leaders who don’t understand the complexity.


答:
It's called an estimate because it is an educated guess. It is not an infallible description of the future, and I have little patience for people that treat software estimates that way. Ultimately, many things will take longer than you expect, in rare instances they may take an order of magnitude more time. This happens even to the finest programmers in the world. How could a manager expect it not to happen to you? If your manager doesn't understand that, she doesn't have much experience. If she pretends not to understand it in order to apply schedule pressure, she is being unreasonable.

The best approach is the most obvious. As soon as you have a clear idea that a feature is going to take longer than expected, discuss it with your manager. There are often ways to proceed that will solve both your problems and your manager's. That is, the portion of the feature that is slowing things down may be relatively unimportant or easy to modify in a way that makes more rapid progress possible. Whatever the case, though, don't be bullied into a second optimistic estimate.


问:
Why do many older algorithms papers reference implementations on a PDP-10 or PDP-11?
Take the original Boyer-Moore paper, for instance. It seems every time I look for an algorithm the paper I see referenced is talking about implementation idiosyncrasies on a PDP-10 or PDP-11.

I know these were popular machines at one time, but not so popular as to account for the large number of references I see. Is there a specific reason these machines were used as examples in algorithms papers?

答: PDP-11s and PDP-10s were used by the leading CS departments of the 1970's: MIT, Stanford, Carnegie-Mellon, Columbia, and others.  Also UNIX and C were originally written for the PDP-11.  DEC's operating systems were both simpler and more powerful than offerings from other manufacturers of the time.</p>


答:
Have you considered mercurial? Like git, it is a DCVS and lets you do all the neat things one can do with a DCVS. Like git there is a pretty good, cloud-based service provider (bitbucket). But, unlike git, the windows story is pretty decent, you are not a 2nd class citizen. You've got good tooling options (TortiseHG) and pretty decent Visual Studio integration (VisualHG).

Nothing is going to be like TFS in visual studio though -- the world just isn't wired that way.

Title: From TFS to Git


问:
At what point would you drop some of your principles of software development for the sake of more money?
I'd like to throw this question out there to interestingly see where the medium is.

I'm going to admit that in my last 12 months, I picked up TDD and a lot of the Agile values in software development. I was so overwhelmed with how much better my development of software became that I would never drop them out of principle. Until...I was offered a contracting role that doubled my take home pay for the year.

The company I joined didn't follow any specific methodology, the team hadn't heard of anything like code smells, SOLID, etc., and I certainly wasn't going to get away with spending time doing TDD if the team had never even seen unit testing in practice. Am I a sell out? No, not completely... Code will always been written "cleanly" (as per Uncle Bob's teachings) and the principles of SOLID will always be applied to the code that I write as they are needed. Testing was dropped for me though, the company couldn't afford to have such a unknown handed to the team who quite frankly, even I did create test frameworks, they would never use/maintain the test framework correctly.

Using that as an example, what point would you say a developer should never drop his craftsmanship principles for the sake of money/other benefits to them personally? I understand that this can be a very personal opinion on how concerned one is to their own needs, business needs, and the sake of craftsmanship etc. But one can consider that for example testing can be dropped if the company decided they would rather have a test team, than rather understand unit testing in programming, would that be something you could forgive yourself for like I did? So given that there is something you would drop, there usually should be an equal cost in the business that makes up for what you drop - hopefully, unless of course you are pretty much out for lining your own pockets and not community/social collaborating ;).

Double your money, go back to RAD? Or walk on, and look for someone doing Agile, and never look back...

答: In short, development methodology is not part of you. It is not a relgion and it is not who you are. It is a tool. Do what you are told, how you are told and make the extra bucks. Thousands of systems were developed and are running today without TDD, Code Smell, etc. In few years no one will know what these terms mean because methodologies come and go more frequent than a city bus. Work hard as you are told and take the money it is appreciated any time and all the time:)</p>


Title: How do mashups work with same-orgin policy?

Body: If Javascript is only allowed to access scripts from the same domain, how can a website create mashups which must read and modify content from another domain?</p>

Body:
Cross-browsers solutions

JSONP

If the API you're trying to access supports JSONP, you only have to provide a javascript function name in your request, then the JSONP returns javascript like myfunc({the:data}); which you can run like a regular javascript, which is why you would create a new <script src="www.website.com/somecall?jsonp=myfunc"> tag to "send a request" (jQuery does this automatically if you use type: jsonp in $.ajax requests).

The downside is that it requires the provider of the API to support JSONP.

Flash

Flash can access cross-domain contents as long as the target website has a crossdomain.xml file at its root that says it allows it, which is usually the case on servers that provide an API).

The downside is that it requires Flash in the user's browser and that the website you get data from must have a crossdomain.xml that allows cross-domains requests.

Server-side script on the same domain name

Server-side languages like PHP have no BS same-domain restrictions, so you could have a script that acts as proxy (e.g. download via one of the http extension like cURL).

The added benefit is that you can cleanup the data (or even mashup multiple sources) on the server, before forwarding it to your webpage/javascript, so you could even extract only the useful part of the data, which is nice when doing mobile webapp where bandwidth can be an issue.

The downside is that all requests have to go thru your server, so that increases the load on your server.

However the benefit is that it would work with any ressource as it doesn't require the target to support crossdomain or jsonp. So if nothing else works, this would.

Solutions specific to some browsers

Internet Explorer

Internet Explorer has Cross Domain Request

Firefox

Firefox 3.5+ has the cross-origin sharing standard, but it requires the ressource you're trying to access to include special headers, e.g. in PHP:

header("content-type: Access-Control-Allow-Origin: *");
header("content-type: Access-Control-Allow-Methods: GET");

A few other major browsers support this too, so if you don't need to support old browsers and if you can get the ressources you're trying to access to send those headers, this may be your best bet, otherwise the server-side script would be my recommendation.

Firefox also has a user setting capability.policy.default.XMLHttpRequest.open, but I wouldn't count on the user changing a setting in his browser.


问:
Is it wrong or bad to use autocomplete?

Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

I have a friend at school who wrote a program in VB.net in notepad, took it home fixed any errors that came up, and then compiled it. He used a textbook to get the hang of the relatively basic methods and properties he'd need (nothing complicated like network sockets etc) and then wrote it without looking much up.

This makes me wonder if it is frowned upon to use or rely on autocomplete? In Objective-c the method names are quite descriptive, and mostly I know what I want to do and now roughly the name of the method I want to use, though not necessarily letter for letter.

I could, if I wanted use the Documentation or headers to find method names, and I do sometimes. But naturally this is slower.

So should I focus more on learning parts of the language, than actually programming for a while, or is it ok to use Auto complete a lot?

Also as a subquestion, is better to know one language without much autocomplete needed. or to rely more on autocomplete and be able to use other languages (although not as efficiently and easily) once the syntax is understood.

答: It is wrong if you need it to code. It is perfectly fine if it something that help you to be more productive.</p>

Title: Is it wrong or bad to use autocomplete?


答:
I don't think it's frowned on. These days most languages come with a large expansive class library (or two!) and having to commit the exact name, and sometimes casing, isn't always necessary. Plus, multiple overloads on a method make this even more cumbersome.

At the end of the day you've got to understand what you're calling/doing. Auto-complete won't help here.!

Title: Is it wrong or bad to use autocomplete?

Body:
Possible Duplicate:

  Should newbies use IDE autocomplete (Intellisense)?

I have a friend at school who wrote a program in VB.net in notepad, took it home fixed any errors that came up, and then compiled it. He used a textbook to get the hang of the relatively basic methods and properties he'd need (nothing complicated like network sockets etc) and then wrote it without looking much up.

This makes me wonder if it is frowned upon to use or rely on autocomplete? In Objective-c the method names are quite descriptive, and mostly I know what I want to do and now roughly the name of the method I want to use, though not necessarily letter for letter.

I could, if I wanted use the Documentation or headers to find method names, and I do sometimes. But naturally this is slower.

So should I focus more on learning parts of the language, than actually programming for a while, or is it ok to use Auto complete a lot?

Also as a subquestion, is better to know one language without much autocomplete needed. or to rely more on autocomplete and be able to use other languages (although not as efficiently and easily) once the syntax is understood.


答:
The tools are there in the IDEs for a reason. As Sean pointed out languages (especially .NET ones) come with extensive class libraries that you cannot hope to remember (despite what interviewers would want you to believe). Would you expect a word processor to come without a spell checker?

With auto-complete you are more productive as you can find the list of available methods/properties/events etc right there in front of you. Otherwise you'd have to either remember (which we've already established is hard) or go and look it up. Both of which take time, thus slowing you down.

You still have to know which of the available methods/properties/events is the correct one to use in the circumstances - no IDE can (yet) write the code for you - that's where your skill as a programmer comes in.

Title: Is it wrong or bad to use autocomplete?