答: To seemingly play the devil's advocate here, I think frameworks ("good" ones, anyway) can actually go a long way toward furthering a programmer's education. A well-engineered framework will solve a lot of problems, and by using the framework, the programmer can come to understand what problems are being solved, and how. In my mind, a framework is (/should be) a crystallization of programming best-practices, and can teach a programmer by example.

Title: Is the abundance of frameworks dumbing down programmers?

Body:
With all of the frameworks available these days, ORMs, dependency injection (DI), Inversion of control (IoC), etc., I find that many programmers are losing or don't have the problem solving skills needed to solve difficult issues. Many times, I've seen unexpected behaviour creep into applications and the developers unable to really dig in and find the issues. It seems to me that deep understanding of what's going on under the hood is being lost.

Don't get me wrong, I'm not suggesting these frameworks aren't good and haven't moved the industry forward, only asking if, as a unintended consequence, developers aren't gaining the knowledge and skill needed for deep understanding of systems.


问:
How do you maintain focus when a particular aspect of programming takes 10+ seconds to complete?
I have a very difficult time focusing on what I'm doing (programming-wise) when something (compilation, startup time, etc.) takes more than just a few seconds.  Anecdotally it seems that threshold is about 10 seconds (and I recall reading about study that said the same thing, though I can't find it now).  So what typically happens is I make a change and then run the program to test it.  That takes about 30 seconds, so I start reading something else, and before I know it 20 minutes have passed, and then it takes (if I'm lucky!) another 10+ minutes to deal with the context switch to getting back into programming.

It's not an exaggeration to say that some things that should take me minutes literally take hours to complete.

I'm very curious about what other programmers do to combat this tendency (or if I'm unique and they don't have this tendency?).  Suggestions of any type at all are welcome - anything from "sit on your hands after hitting the compile button", to mental tricks, to "if it takes 30 seconds to start up something to test a change, then something's wrong with your development process!"

答: I have the same problem, and the solution for me has been to spend the time doing something which will not get you sucked in. For me, this is usually either (1) filling up a water bottle, or (2) standing up and taking a 30-second walk around the office to stretch my legs, which need the movement anyway. You can get lost browsing the internet; you rarely get lost walking around your own cubicle.</p>

ContentLicense: CC BY-SA 3.0


答: I agree with what @retracile is suggesting, but note that according to the Zen programming rules you should focus on only one task at a time. Answering to phone calls, browsing the Web, social networking, or even doing multitasking will most likely decrease your productivity. Use the short waiting delay to think about the existing task/solution and what you can do to improve it.</p>

Title: How do you maintain focus when a particular aspect of programming takes 10+ seconds to complete?

Body:
I have a very difficult time focusing on what I'm doing (programming-wise) when something (compilation, startup time, etc.) takes more than just a few seconds.  Anecdotally it seems that threshold is about 10 seconds (and I recall reading about study that said the same thing, though I can't find it now).  So what typically happens is I make a change and then run the program to test it.  That takes about 30 seconds, so I start reading something else, and before I know it 20 minutes have passed, and then it takes (if I'm lucky!) another 10+ minutes to deal with the context switch to getting back into programming.

It's not an exaggeration to say that some things that should take me minutes literally take hours to complete.

I'm very curious about what other programmers do to combat this tendency (or if I'm unique and they don't have this tendency?).  Suggestions of any type at all are welcome - anything from "sit on your hands after hitting the compile button", to mental tricks, to "if it takes 30 seconds to start up something to test a change, then something's wrong with your development process!"


答:
Do something for your health:

Standup, walk away from your computer and do some hand and arm stretching exercises. This will take 2-5 minutes max. Your future self not suffering from RSI will thank you for this.

Also, regarding the 2-5 minute break, have a read through the Pomodoro technique. This is based on the idea of having frequent short breaks to take your mind off your current task and let things sink in a little. It's a short enough break not to loose your train of thought completely but long enough to give your brain a breather.


问:
Where should a programmer explain the extended logic behind the code?
I have developed a few quantitative libraries in C# where it is important to understand not only the classic information that goes with the XMLDoc comments (which contains basic information with the method signature) but also the mathematical formulas being use within the methods.

Hence I would like to be able to include extended documentation with the code, which could contain, for example Latex formulas, graphs, and so on.

Do you think such information should be included in the API documentation?

Or should it be included in a dev blog for examples?

Are there common tools that are usually used for this kind of purposes?

答:
If you feel that it is necessary to document the innards of a method in your API, then you probably haven't defined/modularized the interface very well.

A well written API shouldn't REQUIRE the programmer to understand how the internals work. Also, by unnecessarily documenting the way it works you are breaking the abstraction layer and locking yourself into a specific implementation, which is not good either.


问:
Why do you have to manually type variable names while debugging?
I've seen this in a lot of IDEs (even in the most popular and heavily used ones, like Visual Studio): if you want to watch a variable's value, you have to manually type its name in the Watches section of the debugger. Why can't there just be a list of all of them with checkboxes next to them ?

The developer can then just check the box next to the one he wants to watch and that's it. Variables with identical names can probably be numbered in some way (for example a, b, x(1), x(2), c, etc.

I've seen some exceptions to this (NetBeans or BlueJ), but there are exceptions to everything, right ?

Maybe it's a stupid question, maybe not, but I've always wondered why this is so.

答:
In Visual Studio, I think what you are looking for is the Locals window.

NetBeans has a similar feature:


答: I've actually never seen an IDE (haven't worked with Visual Studio though) where the debugger didn't have a view that shows you all the the variables of the current stack frame. A "watch expression" view is provided separately because it allows you to have complex expressions (that may include method calls as well as variables) computed automatically.</p>

Title: Why do you have to manually type variable names while debugging?

Body:
I've seen this in a lot of IDEs (even in the most popular and heavily used ones, like Visual Studio): if you want to watch a variable's value, you have to manually type its name in the Watches section of the debugger. Why can't there just be a list of all of them with checkboxes next to them ?

The developer can then just check the box next to the one he wants to watch and that's it. Variables with identical names can probably be numbered in some way (for example a, b, x(1), x(2), c, etc.

I've seen some exceptions to this (NetBeans or BlueJ), but there are exceptions to everything, right ?

Maybe it's a stupid question, maybe not, but I've always wondered why this is so.


答:
As far as I'm concerned, the closer you keep documentation to the code, the more likely it is to be kept up to date and the more useful it is likely to be.

That's why I try to keep all documentation in the same repository as the code, even user manuals, and try to keep it in a plain text format that can be easily managed by a revision control system.

In-code documentation

It looks like you already have this one covered, but it is important to remember that actually using the documentation facilities in your chosen development environment (pydoc for python, javadoc in java or xml comments in C#) is the single most important documentation technique. They make it easy to write the documentation at the same time as writing the code.

If you rely on coming back and documenting things later, you may not get around to it, but if you do it as you are writing the code, then what needs to be documented will be fresh in your mind. C# even has the option to issue a compilation warning if the XML documentation is incomplete or inconsistent with the actual code.

Tests as documentation

Another important aspect is having good integration and unit tests.

Often documentation concentrates on what classes and methods do in isolation, skipping over how they are used together to solve your problem. Tests often put these into context by showing how they interact with each other.

Similarly, unit-tests often point out external dependencies explicitly through which things need to be Mocked out.

I also find that using Test-driven development I write software which is easier to use, because I'm using it right from the word go. With a good testing framework, making code easier to test and making it easy to use are often the same thing.

Higher level documentation

Finally there is what to do about system level, architectural, developer and possibly also end-user documentation. Many would advocate writing such documentation in a wiki or using Word or other word processor, but for me the best place for such documentation is also alongside the code, in a plain text format that is version control system friendly.

Just like with in-code documentation, if you store your higher level documentation in your code repository then you are more likely to keep it up to date. You also get the benefit that when you pull out version X.Y of the code, you also get version X.Y of the documentation. In addition, if you use a VCS friendly format, then it means that it is easy to branch, diff and merge, just like your code.

I quite like rst, as it is easy to produce both html pages and pdf documents from it, and is much friendlier than LaTeX, yet can still include LaTeX math expressions when you need them.

When writing highly mathematical code, I also find it useful to have a few wxmaxima documents in my project repository. Being plain text, these also branch, diff and merge nicely, but using a computer algebra system can help you consistency check your formulae as well as document them.

Title: Where should a programmer explain the extended logic behind the code?

Body:
I have developed a few quantitative libraries in C# where it is important to understand not only the classic information that goes with the XMLDoc comments (which contains basic information with the method signature) but also the mathematical formulas being use within the methods.

Hence I would like to be able to include extended documentation with the code, which could contain, for example Latex formulas, graphs, and so on.

Do you think such information should be included in the API documentation?

Or should it be included in a dev blog for examples?

Are there common tools that are usually used for this kind of purposes?


问:
I can't program because the code I am using uses old coding styles. Is this normal to programmers?
I have my first real job as programmer, but I can't solve any problems because of the coding style used. The code here:

Does not have comments

Does not have functions (50, 100, 200, 300 or more lines executed in sequence)

Uses a lot of if statements with a lot of paths

Has variables that make no sense (eg.: cf_cfop, CF_Natop, lnom, r_procod)

Uses an old language (Visual FoxPro 8 from 2002), but there are new releases from 2007.

I feel like I have gone back to 1970. Is it normal for a programmer familiar with OOP, clean-code, design patterns, etc. to have trouble with coding in this old-fashion way?

EDIT: All the answers are very good. For my (un)hope, appears that there are a lot of this kind of code base around the world. A point mentioned to all answers is refactor the code. Yeah, I really like to do it. In my personal project, I always do this, but... I can't refactor the code. Programmers are only allowed to change the files in the task that they are designed for.

Every change in old code must be keep commented in the code (even with Subversion as version control), plus meta information (date, programmer, task) related to that change (this became a mess, there is code with 3 used lines and 50 old lines commented). I'm thinking that is not only a code problem, but a management of software development problem.

答:
This coding style (if you even want to call it any kind of style) is bad coding style.

One can write short functions with descriptive variable names and sane flow control in most modern languages (Visual FoxPro is modern, yes).

The problems you are having are with a bad code base, nothing more, nothing less.

Such codebases exist and are many - the fact that you are having problems with them attest to how bad they can be (and that you have good training).

What you can try and do is improve on things where you can - rename variables, extract commonalities and divide large functions into smaller ones etc... Get a copy of Working Effectively with Legacy Code...

I am on a C# project with very bad structure, not miles off what you describe. Just combined 12 separate functions (obvious copy-paste) into one that takes a single parameter.


问:
How to recover from finite-state-machine breakdown?
My question may seems very scientific but I think it's a common problem and seasoned developers and programmers hopefully will have some advice to avoid the problem I mention in title. Btw., what I describe bellow is a real problem I am trying to proactively solve in my iOS project, I want to avoid it at all cost.

By finite state machine I mean this >
I have a UI with a few buttons, several session states relevant to that UI and what this UI represents, I have some data which values are partly displayed in the UI, I receive and handle some external triggers (represented by callbacks from sensors).
I made state diagrams to better map the relevant scenarios that are desirable and alowable in that UI and application.
As I slowly implement the code, the app starts to behave more and more like it should. However, I am not very confident that it is robust enough.
My doubts come from watching my own thinking and implementation process as it goes. I was confident that I had everything covered, but it was enough to make a few brute tests in the UI and I quickly realized that there are still gaps in the behavior ..I patched them.
However, as each component depends and behaves based on input from some other component, a certain input from user or some external source trigers a chain of events, state changes..etc.
I have several components and each behave like this
Trigger received on input -> trigger and its sender analyzed -> output something (a message, a state change) based on analysis

The problem is, this is not completely selfcontained, and my components (a database item, a session state, some button's state)...COULD be changed, influenced, deleted, or otherwise modified, outside the scope of the event-chain or desirable scenario. (phone crashes, battery is empty phone turn of suddenly)
This will introduce a nonvalid situation into the system, from which the system potentially COULD NOT BE ABLE to recover.
I see this (althought people do not realize this is the problem) in many of my competitors apps that are on apple store, customers write things like this>
"I added three documents, and after going there and there, i cannot open them, even if a see them." or "I recorded videos everyday, but after recording a too log video,  I cannot turn of captions on them.., and the button for captions doesn't work"..

These are just shortened examples, customers often describe it in more detail..from the descriptions and behavior described in them,  I assume that the particular app has a FSM breakdown.

So the ultimate question is how can I avoid this, and how to protect the system from blocking itself?

EDIT> I am talking in the context of one viewcontroller's view on the phone, I mean one part of the application. I Understand the MVC pattern, I have separate modules for distinct functionality..everything I describe is relevant to one canvas on the UI.

答:
I am sure you  already know this but just in case:

Make sure every node in the state diagram
has an outgoing arc for EVERY legal kind of input
(or divide the inputs into classes, with
one outbound arc for each class of input).

Every example I have seen
of a state machine uses only one outbound
arc for ANY erroneous input.

If there is no definite answer as to what an
input will do every time, it is either
an error condition, or there is another
input that is missing (that should
consistently result an arc for the inputs going to
a new node).

If a node doesn't have an arc for one
type of input, then that is an assumption
the input will never occur in real life
(this is a potential error condition
that would not be handled by the state machine).

Make sure the state machine can only take
or follow only ONE arc in response to the input
received (not more than one arc).

If there are different kinds of error scenarios,
or kinds of inputs that cannot be identified
at state machine design time, the error
scenarios and unknown inputs should arc
to a state with a completely
separate path separate from the "normal arcs".

I.E. if an error or unknown is received in
any "known" state, then the arcs followed
as a result of the error-handling/unknown input
should Not go back into any states
the machine would be in if it only received
known inputs.

Once you reach a terminal (end) state you
shouldn't be able to return to a non-terminal
only to the one starting (initial) state.

For one state machine there should not be
more than one starting
or initial state (based on the examples I've seen).

Based on what I have seen one state machine can
only represent the state of one problem or scenario.

There should never be multiple possible states at
one time in one state diagram.

If I see the potential for multiple concurrent
states this tells me I need to split the state diagram
up into 2 or more separate state machines
that have the potential each state to be
independently modified.

ContentLicense: CC BY-SA 4.0


问:
Which open source PHP project has the 'perfect' OOP design I can learn from?
I am a newbie to OOP, and I learn best by example.

You could say this question is similar to Which Scala open source projects should I study to learn best coding practices - but in PHP.

I have heard-tell that Symfony has the best 'architecture' (I will not pretend I know what that exactly means), as well as Doctrine ORM. Is it worth it to spend many months reading the source code of these projects, trying to deduce the patterns used and learning new tricks?

I have seen equal number of web pages dissing and liking Zend's codebase (will provide links if deemed necessary).

Do you know of any other project that would make any veteran OOP developer shed tears of joy?

Please let me add that practicality and scope of use is not a concern at all here - I just want to do:

Pick a project that has a codebase deemed awesome by devs way better and greater than me.

Write code that achieves what the project does.

Compare results and try to learn what I don't know.

Basically, an academic interest codebase. Any recommendations please?

答:
Well, personally I would say check out Symfony2.  It's pretty much the best end-to-end large project that I've seen yet.  That's not to say there aren't bad parts to it, but as a whole, it's pretty good.

Now, Zend is in the middle.  If you look at the public API, it's pretty good.  There are some WTF parts to it, but for the most part it's ok.  If you start digging into it more, you'll find a LOT more WTF code...

As far as what to avoid outright:

CodeIgniter - Fubar MVC model

Kohana - Lots of statics

Cake - PHP 4 object semantics

Drupal - Not OOP at all

Wordpress - Not OOP at all

As far as the rest, you'll find it's hit and miss.  There are good and bad parts to all designs.  Take a look at Lithium, it's got some really cool design concepts.  But it also has a lot of fubar redirection and hackery to get that to work.

And that's what to take to the bank.  There is no perfect design, don't try to find one.  Instead, look at a lot of them out there and decide for yourself.  Try each, try to break them.  Try to understand them just by reading them (which is a good test of sane design)...

Just my personal opinion...


问:
Terms for different types of development
I'm trying to figure out the right terminology for the different types of software development

Right now, the only development term I know is "web development", but I've also done a lot of Java and C# development for desktop applications. Obviously this isn't web development, but I'd like to be able to group these under a single term that is widely known and accepted within the industry.

Would the term for applications on the desktop be "desktop development"?

答:
The classifications I've always known are

Web Development

Desktop Development

Mobile Development

Embedded Systems Development

Database Development (Stored Procs, etc.)

Client-Server Development (Not used as frequently as it once was)


答:
That's not really "old fashioned" except in that (current) good design practices weren't always as popular. That's just bad code. Bad code slows anyone down. You eventually get used to it, but that's just because you get used to specific quirks in your specific system. Given a new project you might find whole new ways to write bad code. The good thing is you know how to identify these code smells already.

The biggest thing you can do is don't propagate the problem. Don't take these bad practices as a convention unless your team is. Keep new code clean in ways that don't force a refactor. If it's that bad and you have time, consider a major refactor...but in practice you rarely have that luxury.

Consider adding comments as you figure things out, and change little bits and pieces as practical. Unless you're coding solo you need to work this out with your team; if there's no conventions you should take some time to come up with them, and maybe commit to slowly improve the code base if you're regularly maintaining it anyway.

If you find a totally isolated function with bad variable names and you're fixing it anyway, you might as well make the variable names something useful, refactor the ifs. Don't make changes to common features unless you're going to refactor a large portion of it.

Title: I can't program because the code I am using uses old coding styles. Is this normal to programmers?

Body:
I have my first real job as programmer, but I can't solve any problems because of the coding style used. The code here:

Does not have comments

Does not have functions (50, 100, 200, 300 or more lines executed in sequence)

Uses a lot of if statements with a lot of paths

Has variables that make no sense (eg.: cf_cfop, CF_Natop, lnom, r_procod)

Uses an old language (Visual FoxPro 8 from 2002), but there are new releases from 2007.

I feel like I have gone back to 1970. Is it normal for a programmer familiar with OOP, clean-code, design patterns, etc. to have trouble with coding in this old-fashion way?

EDIT: All the answers are very good. For my (un)hope, appears that there are a lot of this kind of code base around the world. A point mentioned to all answers is refactor the code. Yeah, I really like to do it. In my personal project, I always do this, but... I can't refactor the code. Programmers are only allowed to change the files in the task that they are designed for.

Every change in old code must be keep commented in the code (even with Subversion as version control), plus meta information (date, programmer, task) related to that change (this became a mess, there is code with 3 used lines and 50 old lines commented). I'm thinking that is not only a code problem, but a management of software development problem.


问:
What advantages are conferred by using server-side page rendering?
I am developing a web app and I have currently written the entire website in html/js/css and on the backend I have servlets that host some RESTFUL services. All the presentation logic is done through getting json objects and modifying the view through javascript.

The application is essentially a search engine, but it will have user accounts with different roles.

I've been researching some frameworks such as Play and Spring. I'm fairly new to web development, so I was wondering what advantages using server side page rendering would provide?

Is it: Speed? Easier development and workflow? Access to existing libraries? More? All of the above?

答:
Mobile clients are usually power-, bandwidth-, and memory-constrained. It's probably better to render pages for them on server.

For desktop clients you may consider sending js + json to render the page on client, make it dynamically updatable, etc.


答:
Server-side HTML rendering:

Fastest browser rendering

Page caching is possible as a quick-and-dirty performance boost

For "standard" apps, many UI features are pre-built

Sometimes considered more stable because components are usually subject to compile-time validation

Leans on backend expertise

Sometimes faster to develop*

*When UI requirements fit the framework well.

Client-side HTML rendering:

Lower bandwidth usage

Slower initial page render.  May not even be noticeable in modern desktop browsers.  If you need to support IE6-7, or many mobile browsers (mobile webkit is not bad) you may encounter bottlenecks.

Building API-first means the client can just as easily be an proprietary app, thin client, another web service, etc.

Leans on JS expertise

Sometimes faster to develop**

**When the UI is largely custom, with more interesting interactions.  Also, I find coding in the browser with interpreted code noticeably speedier than waiting for compiles and server restarts.

You might also consider a hybrid model with a light backend implementation using a front-end/back-end templating system like mustache.

Title: What advantages are conferred by using server-side page rendering?

Body:
I am developing a web app and I have currently written the entire website in html/js/css and on the backend I have servlets that host some RESTFUL services. All the presentation logic is done through getting json objects and modifying the view through javascript.

The application is essentially a search engine, but it will have user accounts with different roles.

I've been researching some frameworks such as Play and Spring. I'm fairly new to web development, so I was wondering what advantages using server side page rendering would provide?

Is it: Speed? Easier development and workflow? Access to existing libraries? More? All of the above?


答:
It depends on what your requirements are. If you need a high performance, low latency solution that depends on a lot of small tasks, you may go with a structure similiar to what you describe. The most common solutions, in Java, PHP, and C# don't default to this though.

Most web application depend very heavily on databases - most of them so much so that pages could not render without at least one call. Obviously you do not want to expose your database publicly, for several reasons:

Security (as Oded mentions) - you definitely do not want to expose your network publicly! Ideally the only interface to your systems from the outside should be https to your server.

Ease of development - you really, really, really don't want to write SQL in Javascript, and the languages designed for web presentation don't work well with RDBs. They have no concept of state, for instance.

So, when you need a database, you use languages that do play nice with them like Java, C#, PHP, etc. The easiest way to generate a page turns out to be as follows: You use a templating language (most famously PHP, but JSP and ASP are two other very common languages) to construct the page. The language provides constructs that call out to other modules. In PHP this is commonly in the page or in another PHP file, using the MVC pattern. In JSP you use scriptlets or the JSP Expression Language. These other modules can to the heavy work of connecting to the DB, performing logic, and returning values to your view layer. The end result is a generated HTML page, rendered on the server and sent to the client.

When your database is on the same network as your page renderer, you get better performance as well. The client only has to do one request and receives a page - you may need to do 10-15 DB requests before you have all the information the user needs. A latency of milliseconds on your network would be seconds to minutes if the client had to do them all.

When systems grow larger, separation of concerns and core competencies become crucial. HTML is good for display. Javascript is good for dynamic content. SQL is great for querying a database, and other languages are good at business logic. Our job as developers is to use all the tools available to us to build a maintainable system. Ease of development is a huge part of a good system. In my mind, it's almost as important as performance and usability. Great systems evolve over time. Poor systems were written badly from the start and never were improved.


问:
Do any database "styles" use discrete files for their tables?
I've been talking to some people at work who believe some versions of a database store their data in discrete tables. That is to say you might open up a folder and see one file for each table in the database then several other supporting files. They do not have a lot of experience with databases but I have only been working with them for a little over a half year so I am not a canonical source of info either.

I've been touting the benefits of SQL Server over Access (and before this, Access over Excel. Great strides have been made :) ). But, other people were of the impression that the/one of the the benefit(s) of using SQL Server over Access was that all the data was not consolidated down into one file. Yet, SQL Server packs everything into a single .mdf file (plus the log file).

My question is, is there an RDBMS which holds it's data in multiple discrete files instead of one master file? And if the answer is yes, why do it one way over the other?

edit

Thank you everyone for you're answers. This has really helped clarify the whole situation.

答:
MySql does store data in a separate file per table AFAIK. I don't think there is a good reason about doing it one way or the other, alot of it has to depend on the implementation details of your storage I'd think. But I don't write database servers so I can't say for sure.

Also, sql server doesn't have a lock file. It has a transaction log file. Locks are for desktop dbs.


答:
Many databases keep their data in one file per table.  MySQL does, for example, for MyISAM tables.  Whether the data is all kept in one file or not isnt very relevant.  It just depends on the storage system being used.

Basically, its among the last things I'd care about when selecting a database server.  For desktop databases, single file data might be more convenient.

Title: Do any database "styles" use discrete files for their tables?

Body:
I've been talking to some people at work who believe some versions of a database store their data in discrete tables. That is to say you might open up a folder and see one file for each table in the database then several other supporting files. They do not have a lot of experience with databases but I have only been working with them for a little over a half year so I am not a canonical source of info either.

I've been touting the benefits of SQL Server over Access (and before this, Access over Excel. Great strides have been made :) ). But, other people were of the impression that the/one of the the benefit(s) of using SQL Server over Access was that all the data was not consolidated down into one file. Yet, SQL Server packs everything into a single .mdf file (plus the log file).

My question is, is there an RDBMS which holds it's data in multiple discrete files instead of one master file? And if the answer is yes, why do it one way over the other?

edit

Thank you everyone for you're answers. This has really helped clarify the whole situation.


问:
Justification for learning/implementing newer Microsoft technologies
I work at a large healthcare organization as a mid-level software developer. I have over 10 years experience in the IT industry using Microsoft technologies (ASP.NET & SQL Server).

When I go to conferences, code camps, .net user group meetings, I hear of all kinds of new tools and technologies: MVC, LINQ, Entity Framework, WCF Web Services, etc. I guess you could say I'm in my comfort zone using the same old stuff from asp.net 2.0. I use typed datasets for my data access layer. I use web forms and feature rich server controls with master pages. I know how to use plain old SQL and create queries in my typed datasets to get at data my applications need.

Throughout my career, I'm always sensitive to not become obsolete with my skill set. What I currently use works fine and my development time is fast. But I'm concerned that if I were to be laid off, I would be asked in interviews how many MVC apps I've written. Or how I am with LINQ or WCF web services.

I know that it doesn't matter how many conferences, books, or videos I watch on some new technology...I have to implement/use it or it simply won't sink in. Also, managers who interview don't care how much someone reads up on something, only real use and experience with a technology.

I have a new project to write. I've gone to my manager and have asked for additional time for the project for learning/implementing technology I may not be familiar with. Our organization encourages its employees to "learn and grow" and to continue are education. But I always get resistance when I ask for more time to ramp up on something new to implement. My manager is asking for concrete business reasons for implementing these new technologies. I don't have business reasons. My reasons are because I don't want to become obsolete. I could say it would make the project more maintainable in the future by other developers since at some point people could stop using these older technologies, but that' about all I can think of. Does Linq/Entity Framework/MCV apps perform better? So much so that the customers (users in departments I'm creating this app for) need? I doubt it.

I'm interested in you guy's thoughts on this. Do many of you have similar plights with trying to use newer upcoming technologies? I doubt I'm on the bleeding edge of technology, either. Are there "business reasons" that you would bring to light for using these technologies?

Thanks in advance! Sorry for the long wall of text.

答:
I think the main thing to do is figure out what the concrete benefits of adopting a newer technology are and present those as justification for doing so, rather than your own desire not to become obsolete.  You say that you don't have "business reasons", but surely you can find some with research...

Maybe moving to a newer framework/technology allows you to design apps that run with a smaller memory footprint, are more responsive, are faster to deploy, etc.  Those would all be concrete business reasons.  So, I guess I would suggest pulling back a little and investigating "why did people start using MVC, LINQ, Entity Framework, WCF Web Services, etc in the first place?"  Answer that question, and you'll probably find some business justification to offer.  Whether or not it's sufficient to drop the "go with what works" philosophy is another matter and may be a function of your salesmanship.


答:
As a developer, you have to push management to use newer technologies and justify it by demonstrating the benefits and value it will bring to the company (e.g. performance, features, ease of use, maintenance). Management is usually averse to change and won't justify changing anything unless it brings some added benefits over what is currently in use.

Using some new, "bleeding edge" technology is also good for the marketing team so that they can market the company as being on top of current technology trends and not stuck in the past using legacy technologies and platforms.

Title: Justification for learning/implementing newer Microsoft technologies

Body:
I work at a large healthcare organization as a mid-level software developer. I have over 10 years experience in the IT industry using Microsoft technologies (ASP.NET & SQL Server).

When I go to conferences, code camps, .net user group meetings, I hear of all kinds of new tools and technologies: MVC, LINQ, Entity Framework, WCF Web Services, etc. I guess you could say I'm in my comfort zone using the same old stuff from asp.net 2.0. I use typed datasets for my data access layer. I use web forms and feature rich server controls with master pages. I know how to use plain old SQL and create queries in my typed datasets to get at data my applications need.

Throughout my career, I'm always sensitive to not become obsolete with my skill set. What I currently use works fine and my development time is fast. But I'm concerned that if I were to be laid off, I would be asked in interviews how many MVC apps I've written. Or how I am with LINQ or WCF web services.

I know that it doesn't matter how many conferences, books, or videos I watch on some new technology...I have to implement/use it or it simply won't sink in. Also, managers who interview don't care how much someone reads up on something, only real use and experience with a technology.

I have a new project to write. I've gone to my manager and have asked for additional time for the project for learning/implementing technology I may not be familiar with. Our organization encourages its employees to "learn and grow" and to continue are education. But I always get resistance when I ask for more time to ramp up on something new to implement. My manager is asking for concrete business reasons for implementing these new technologies. I don't have business reasons. My reasons are because I don't want to become obsolete. I could say it would make the project more maintainable in the future by other developers since at some point people could stop using these older technologies, but that' about all I can think of. Does Linq/Entity Framework/MCV apps perform better? So much so that the customers (users in departments I'm creating this app for) need? I doubt it.

I'm interested in you guy's thoughts on this. Do many of you have similar plights with trying to use newer upcoming technologies? I doubt I'm on the bleeding edge of technology, either. Are there "business reasons" that you would bring to light for using these technologies?

Thanks in advance! Sorry for the long wall of text.


问:
Reflection: Is using reflection still "bad" or "slow"? What has changed with reflection since 2002?
I've noticed when dealing with Expressions or Expression Trees I'm using reflection a lot to set and get values in properties and what have you. It has occurred to me that the use of reflection seems to be getting more and more common. Things like DataAnotations for validation, Attribute heavy ORMs, etc. Have me wondering: What has changed since the days years and years ago when I used to be told to avoid reflection if at all possible?

So what, if anything has changed? Is it just the speed of the machines? Have there been changes to the framework to speed up reflection?

Or has nothing really changed? Is it still "bad" or "slow" to use reflection?

答:
Reflection is neither bad, nor slow.  It is simply a tool.  Like all tools, it is very valuable for certain scenarios, not so valuable for others.

If performance is really an issue, you can always use a library like FasterFlect.

Further Reading

If reflection is inefficient, when is it most appropriate?


答:
Reflection is still significantly slower than direct calls. Two things have changed:

Runtimes have optimized reflection mechanisms so that the difference has become smaller

CPUs have gotten faster so that small inefficiencies are easier to tolerate

Together, these two factors have brought the cost of reflection down to the point where you can routinely use it (where appropriate from a maintainability POV) and wait for the profiler to tell you whether it's actually a bottleneck (and be reasonably sure that most of the time it won't be).

Title: Reflection: Is using reflection still "bad" or "slow"? What has changed with reflection since 2002?

Body:
I've noticed when dealing with Expressions or Expression Trees I'm using reflection a lot to set and get values in properties and what have you. It has occurred to me that the use of reflection seems to be getting more and more common. Things like DataAnotations for validation, Attribute heavy ORMs, etc. Have me wondering: What has changed since the days years and years ago when I used to be told to avoid reflection if at all possible?

So what, if anything has changed? Is it just the speed of the machines? Have there been changes to the framework to speed up reflection?

Or has nothing really changed? Is it still "bad" or "slow" to use reflection?


答: One huge advantage of server-side rendering is accessibility -- javascript based apps are still a big issue for folks without sight. That and there is this blind guy called "googlebot" who you might want to cater to. He don't do javascript so well either.</p>


答:
You are going to need to do some smaller projects in your spare time if your company will not let you learn on theirs. The learning you do in your private time should give you the business case to make to your boss about the improvements in the newer technologies. If you are currently feeling too burnt out from your daily work to learn new stuff, you may need to take a few weeks' leave, rest for a few days, then do an intensive training session for yourself.

Say what you will about Microsoft, one thing you cant fault them on is making developer tools and training available at no cost. Install the latest Microsoft Web Platform installer on your PC, then fire it up and wait to see all the free development tools and platforms you can try out. Visit the MSDN, ASP.Net and Channel9 web sites and check out their tutorials.

I am still developing in ASP Classic if you can believe it, but with a few hours of persuasion have convinced my boss that .Net is the way to go, by making a business case for it. Next year we begin transitioning our legacy code.


答:
I have developed Microsoft Windows based software for more than ten years before I switched completely to free and open source software and gave up MS development. I am writing this from long personal experience.

Apart from other reasons due to which I switched to FOSS, the reason related to programming is that there is hardly ever any justification for learning/implementing proprietary technologies. The crux of the matter is that Microsoft is not committed to supporting each and every piece of technology it has ever distributed. All too often MS introduces deprecating changes to its APIs and frameworks. This renders much of the existing APIs as well as their knowledge obsolete. Indeed, they even do this with their end user software. For example, MS Office 2007/2010 is not similar to MS Office 2003, and more importantly, Windows 8 is a radical departure from existing platforms. In particular, there are bound to be all new APIs and frameworks for Windows 8, and you will not be able to support Windows 8 (in the future, if not now) without implementing those. This trend of constantly rendering existing technologies and knowledge obsolete and more importantly, unsupported, is one of the core business reasons for going on implementing any new technology that MS releases. If MS stops supporting the old technology tomorrow, where do you go with the legacy code? Where do you get updates for it?

Please also note that I am not asking you to drop MS development and switch to FOSS. I only wanted to help you here, having had a long experience in MS technology.


答:
server-side HTML generation:

easier to debug;

no issues with browser compatibility;

with classical full-page server side generation it's harder to cache HTML, even if it has large invariable parts; (solution is to fetch HTML fragments via AJAX calls);

not taking advantage of caching-proxies and CDNs for dynamic HTML;

client-side HTML generation:

harder to debug;

some issues with obsolete browsers;

no problems caching HTML-templates client-side;

taking advantage of caching-proxies and CDNs for HTML-templates and JS code;

much lower network usage;

Note, that client-side generation is the way it's done in case of successful mobile sites, as apparently it's way more efficient with modern browsers (WebKit based browsers have some 70-80% of mobile market).

LinkedIn has article about advantages of client-side approach using dust.js as an example: "Leaving JSPs in the dust: moving LinkedIn to dust.js client-side templates"


答:
For me, the way to keep my focus is to be ruthless about maintaining a clean work space, whatever that workspace might be. Anything that isn't part of my current project is noise in the hallowed signal-to-noise ratio. A vital part of maintaining focus is about keeping the signal-to-noise ratio high.

When I'm coding, this means closing programs that I haven't used recently, regularly pruning my browser tabs, and keeping my desktop clear of items that aren't immediately relevant to my current projects. I use the ten second delays to "make the rounds", so to speak--closing tabs, closing programs, deleting temporary files and archiving what needs to be archived, etc.

Getting in the habit of "making the rounds" helps prevent rabbit trails, too, because it forces me to continually evaluate--and be reminded of--any current tasks.

There's a small price to be paid when you have to re-open a tab that you've already opened 5 times today or re-launch a command prompt with elevated privileges for the 15th time, but leveraging accelerators like keyboard shortcuts can cut this to a very small price indeed.


答:
don't have comments - fix it as you learn it

don't have functions (50, 100, 200, 300 or more lines executed in sequence)

This probably dates from a previous iteration of the code. At this point, I'd beware of subtle differences between similar-seeming code blocks that have become "features". But regardless of how bad an idea this type of structure is, it is pretty simple to understand... so I'm not sure where you'd have trouble with it.

uses a lot of if statements with a lot of paths - I'm not actually certain what you mean here

has variables that make no sense (eg.: cf_cfop, CF_Natop, lnom, r_procod) -

I would emphasize caution with the 'renaming variables' bit. There's a fair chance you simply don't understand the lingo yet, and the variable names will make much more sense after you've been there for a while. Not to say that there can't be problematic variable names as well, but your examples look like there is a logic to them, if you knew what the common acronyms at your site are. This is obviously not as important if you're a team of 1.

uses a language I am unfamiliar with (Visual FoxPro 8 from 2002) - This is your issue, not the code's


问:
What is Script Binding, and How is it done?
I have heard such thing as Script Binding - binding Javascript or lua with API's from C++ or Objective-C.
I want to know more about it- however Google has strangely proven unuseful for this.

How is it done? - it OK if I get pointed to other sources, but, just how?
I never knew a Scripts jitter could interact with compiled libraries.

答: node.js appears to just spin up an instance of v8, parse a JavaScript file and extract a function object from it (in C++) then wrap some external C++ libraries in a v8 object and pass it into the function and call it. From there on out, it's bootstrapped with it's own bridge.</p>


问:
Why is Google blocking users from accessing their local file system in Chromium?
The question is based on this issue in Chromium. It is marked as Won't Fix.

Do you see any reason to block a local html file from accessing another local html file located in the same folder?

答:
I know this is an old question, but I didn't see this important fact mentioned anywhere:

Chrome allows you to add a folder on your file system as a local Web application.  Once you do that, files in that folder no longer need to be accessed through the file: protocol -- they become accessible through the chrome-extension:// protocol, e.g., chrome-extension://[app_id]/somefile.html.  When accessing your files this way, the restrictions on local file access do not apply.

True, you need to write a small, three-line manifest.json file [1] that specifies the name of your application, but if you want to use multiple local files as a local Web application, it makes some sense, security-wise, to require that you use Chrome's extension architecture to indicate clearly what folders on your hard drive should be accessed like Web applications.  That way, Chrome can assume that everything else on your hard drive is not a Web application, and lock down permissions on non-app HTML files that get loaded in the browser.  The addition of the manifest.json file adds only a few bytes to your folder, and it doesn't get in the way if you want to use your files in some other browser that does allow unfettered file access.


答:
I find it helps to track the actual time I spend not working

You can use any number of things for this. I know there are many free apps out there you can download to do this for you (can't think of any off the top of my head right now, but if someone gives me some I'll add them to this answer), or it's very easy to create your own. I usually use one I created which is a tiny window in the corner of my screen with buttons for Working/NotWorking, and I just click whichever one I'm on whenever I switch focus.

A chess clock also works

The very act of tracking your time makes you more aware of how much time you are wasting that you should be spending working, and I find it makes me more productive because I'll force myself to leave that super-interesting stackoverflow question, or blog article, and get back to work


问:
Which things instantly ring alarm bells when looking at code?
I attended a software craftsmanship event a couple of weeks ago and one of the comments made was "I'm sure we all recognize bad code when we see it" and everyone nodded sagely without further discussion.

This sort of thing always worries me as there's that truism that everyone thinks they're an above average driver. Although I think I can recognize bad code I'd love to learn more about what other people consider to be code smells as it's rarely discussed in detail on people's blogs and only in a handful of books. In particular I think it'd be interesting to hear about anything that's a code smell in one language but not another.

I'll start off with an easy one:

Code in source control that has a high proportion of commented out
  code - why is it there? was it meant
  to be deleted? is it a half finished
  piece of work? maybe it shouldn't have
  been commented out and was only done
  when someone was testing something
  out? Personally I find this sort of
  thing really annoying even if it's just the odd line here and there, but when you see large blocks interspersed with the rest of the code it's totally unacceptable. It's
  also usually an indication that the rest of
  the code is likely to be of dubious
  quality as well.

答:
Language agnostic:

TODO: not implemented

int function(...) { return -1; } (the same as "not implemented")

Throwing an exception for a non-exceptional reason.

Misuse or inconsistent use of 0, -1 or null as exceptional return values.

Assertions without a convincing comment saying why it should never fail.

Language specific (C++):

C++ Macros in lowercase.

Static or Global C++ variables.

Uninitialized or unused variables.

Any array new that is apparently not RAII-safe.

Any use of array or pointer that is apparently not bounds-safe. This includes printf.

Any use of the un-initialized portion of an array.

Microsoft C++ specific:

Any identifier names that collide with a macro already defined by any of the Microsoft SDK header files.

In general, any use of the Win32 API is a big source of alarm bells. Always have MSDN open, and look up the arguments/return value definitions whenever in doubt. (Edited)

C++/OOP specific:

Implementation (concrete class) inheritance where the parent class have both virtual and non-virtual methods, without a clear obvious conceptual distinction between what should/should not be virtual.

ContentLicense: CC BY-SA 2.5


答:
In Oracle, you could define "External Tables". These tables are just separate text files but can be accessed via SQL. In xBase family of databases, each database has its own file (.dbf) and each index has its own file (.ndx) (extensions vary among products).

The drawbacks of having several files representing your database are security and consistency of the database. The major bad thing about MS-Access specifically is that the database file stores not only data but also some code. If the database file is corrupted you get a problem not only accessing the data but also in accessing the coed.


答:
The best way to justify the use of newer technologies is when you can show that they improve developer productivity.  This means more work done at a lower cost.  That's the only thing that matters from a business perspective.

Some examples:

Tools that make it easier for the developer to work

Libraries that provide features which would otherwise have to be developed in house

More powerful languages that can result in code that is easier to read or fewer lines of code that need to be written/debugged


问:
Is it more advantageous to write a program to test your code (ie a client) or just use the main portion of your program?
For instance if I had a program with a bunch of methods.

```<code>        public class Dog{

            public boolean ishappy{..}

            public int weight{...}

        public static void main{
        Dog Max = new Dog
        Max.ishappy}}
</code>```

Is it best to use the main portion of the code to test, or write a completely separate program, which would be a client of the dog class, to test my code?

答:
Ideally, you would use a test framework. A test framework will act as a separate client, but will handle a lot of things for you automatically.

You generally want to minimize the amount of code (especially logic) involved in your test code, because then you increase the chance that your test has a bug. Test frameworks help with this by reducing a lot of the boiler plate code required to get tests off the ground.


答:
I always prefer to use a separate program to test. In .NET, there's the concept of test projects that provides a framework for unit tests, and in Perl, there are modules that give you the same sort of framework for testing. Just about any language will have something similar.

Keeping the test code separate gives you better distinction between the actual code and your tests. When you deploy your code to production, for example, what happens if you forget to remove a test? When you remove your tests, what happens when you want to rerun them? A separate test program/project will obviate many of these concerns.

Title: Is it more advantageous to write a program to test your code (ie a client) or just use the main portion of your program?

Body:
For instance if I had a program with a bunch of methods.

```<code>        public class Dog{

            public boolean ishappy{..}

            public int weight{...}

        public static void main{
        Dog Max = new Dog
        Max.ishappy}}
</code>```

Is it best to use the main portion of the code to test, or write a completely separate program, which would be a client of the dog class, to test my code?


答:
In anything other than a trivial homework application, robust testing is critical to getting anywhere close to a correct application.

Here's an article from a .NET perspective that describes a testing framework that assists in ensuring that your application behaves the way you expect.

Also look around for other answers here regarding tests.

How Do You Test Your Software?


答:
Welcome to the jungle !

Unfortunately, often start working in a company means start facing these kind of situations, unless you work for a structured and well organized company, this situations are quite usual ...

My advice is :

Start learning and get familiar with : programming language used(Clipper/dBase) and environment(Visual FoxPro)

Read and Analyse the code base and start commenting it

organizing/refactoring the code (addressing the problem of  too many lines executed in sequence)

Having problem facing a similar codebase it is normal, but can become a great challenge trying to improve the code quality and giving "your touch" to the program improving the codebase and maybe making it a better program ...


答:
To answer your question: Yes, people/companies everywhere utilize infrastructure which may be built upon crappy code. When integrating yourself into such situations, it can be very hard to deal with.

Last summer, I worked as an intern developing an application to be used by the QA team attached to a specific department. The QA team used a lot of standalone scripts (VBScript, Perl, Bash) to run tests on databases and such, and they wanted to bring them all together into one application. The problem with this, however, is those scripts were used elsewhere in the company (thus core functionality/variable names couldn't be changed), and the code was "added to" for almost 10 years; a lot of crap had built up.

Here's what you can do about it, though:

Ask for help: your fellow coworkers who have had to look though this code are probably familiar with its idiosyncrasies. What is obtuse and confusing to you is perfectly fine for them. So ask for help!

Refactor whenever possible: if you have to look at/maintain this code for an extended period of time, refactor it whenever you can. Even if you're running a find and replace on a variable name, every little bit helps. That company I interned for last summer had a similar problem of using crappy variable names. Every chance I could I ran their code through a fine-tooth comb, changing variable names, optimizing logic (grouping various functions together into 1, for example), etc. Do the same whenever you have the opportunity!

As is the case everywhere, as long as the external features of the code work properly, it won't matter how the internals work.


问:
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

答: A Hardware clock</p>

Body: A Hardware clock


问:
How are you using CFThread in ColdFusion Applications?
I'm presenting on Concurrency in ColdFusion at CFObjective this year, and I'd like to hear how you're using CFThread in your ColdFusion applications.

In addition, what problems have you had while using it, and how (if at all) have you solved them?

What do you dislike about CFThread?

Have you run into significant weaknesses with CFThread or other problems where it simply could not do what you wanted to do?

Finally, if there's anything you'd like to add related to concurrency in CF, not specifically related to CFThread, please do tell.

答:
CFthread has been a handy little tool :)

One thing I've used cfthread for is background image resizing.   If a user uploads a large image (let alone many users), it needs to be resized.  Threads work well.

Observations:

As for sticky areas, one area that's sticky / unclear for starting out with threading is how to best pass information in and out of a cfthread call.  One of the things that a cfthread generally needs is to be completely self contained -- so you have to pass in the information it needs when you make the cfthread call.

Knowing how to do joins (if required) vs, when you can pass in the information so the thread can spawn and complete entirely on it's own is helpful.

0.05 :)


问:
How do you maintain focus when a particular aspect of programming takes 10+ seconds to complete?
I have a very difficult time focusing on what I'm doing (programming-wise) when something (compilation, startup time, etc.) takes more than just a few seconds.  Anecdotally it seems that threshold is about 10 seconds (and I recall reading about study that said the same thing, though I can't find it now).  So what typically happens is I make a change and then run the program to test it.  That takes about 30 seconds, so I start reading something else, and before I know it 20 minutes have passed, and then it takes (if I'm lucky!) another 10+ minutes to deal with the context switch to getting back into programming.

It's not an exaggeration to say that some things that should take me minutes literally take hours to complete.

I'm very curious about what other programmers do to combat this tendency (or if I'm unique and they don't have this tendency?).  Suggestions of any type at all are welcome - anything from "sit on your hands after hitting the compile button", to mental tricks, to "if it takes 30 seconds to start up something to test a change, then something's wrong with your development process!"

答:
In your case, get up and walk around a little. If it's hard to get back in "the zone" it's probably because you're too far in. Doing stuff on the web is just another zone and one that's easy to lose track of time in. Give your brain the break it clearly wants and go for a walk, take a wiz, ideally in a restroom, or talk to a random co-worker. We do a lot of stuff behind the scenes on auto-pilot. Breaks are not bad for  coding, they are good, but the idea is to stop firing on all cylinders for a while and see what your back burners come up with while the more conscious part of your mind gives it a rest. Good devs aren't human calculators. Let the parts of your brain that do all the intuitive and pattern-matching stuff on autopilot do their thing for a while.

If this isn't just a coding problem, you might want to consider ADD.


问:
What's a good algorithm for a random, uneven distribution of a fixed amount of a resource?

Problem

I have X, a positive integer, of some resource, R.

There are N potential targets.

I want to distribute all of R to the N targets in some "interesting" way.

"Interesting" means:

Some targets may not get any R.

It should rarely be near even (with a majority of target getting near X/N of the resource).

There should be at least a small chance of one target getting all of R.

Bad solutions

The naive approach would be to pick a random target and give one R to it and repeat X times.  This would result in too even of an approach.

The next idea is to pick a random number between 1 and X and give it to a random target.  This results in too large of a number (at least X/2 on average) being given to one target.

Question

This algorithm will be used frequently and I want the distribution to be interesting and uneven so that the surprise doesn't wear off for users.

Is there a good algorithm for something in between these two approaches, that fits the definition of interesting above?

答: IMHO it needs to figure out what probability distribution you want (looks like normal distribution would fit your requirements).  You may let median to be R (choose it randomly each time) and you can also change variance each time.  If speed is not that important, python's random module may generate random numbers according to the normal distribution.  Otherwise, google for how to convert flat distribution to the normal distribution.</p>


答:
Not becoming obsolete sounds like a pretty good business reason for using new technology.  It flows both ways. You don't want your skill set to become outdated, but your boss should also be concerned that he might not be able to find employees willing or able to work on outdated technology. If the majority of developers and employers leave an old technology for a new one that might be reason enough for your company to do so too.

To specifically answer your question you should evaluate each one of those technologies individually to see if they meet your needs. I'll give you my take, but you really need to spend at least half a day to research and evaluate each one them as they apply to your specific business needs.

LINQ: This is something you can use, even without entity framework. LINQ is a technology used to work with collections of data, and you can use it in your applications even if you don't use it for loading that data from the database. Do yourself a favor and learn how to use lambda expressions and LINQ extension methods. It will save you time, make your life as a developer easier, and reduce the amount of code you need to write.

Entity Framework: This seems to be the future for data access in the Microsoft world.  Most of the new frameworks, technologies, and tools from Microsoft are designed to work with entity framework. It's not perfect, but it's a lot nicer than using datasets, especially if you use LINQ to entities.  One big business reason for using entity framework is that it reduces the amount of SQL code you need to write, as the framework will generate it for you. In my experience, most developers aren't very good at writing SQL anyway (and most companies don't have a dedicated DBA), so for most applications entity framework should make things faster and more efficient.  Entity framework will also let you work with POCOs which have less overhead and are easier to work with than datasets.

MVC: This one might be hard to justify, as most applications might not benefit much from it. Based on the latest job postings I've seen, MVC is still in the minority (although it is gaining ground fast). For a most business applications MVC might be overkill, and dragging a few controls onto an aspx page will suffice.  MVC has a learning curve to it, and to be productive and get the most out of it you really have to understand HTTP, HTML, CSS and JavaScript.  MVC works well when you need to have a really customized web application where performance is a big priority.  If that is not the case, and the employees don't have much experience with it, there probably isn't a strong business case for using it.

WCF Web Services: Do you have to provide data to remote client applications? WCF is probably the way to go. Are you just writing a web application that will run on the same server or local network as your database? Don't use WCF, you don't need it and it will only serve to complicate things with needless abstractions.

In short, use a new technology when it makes sense, and take the time to find out when that is. It takes a lot of time to learn new technologies, but it shouldn't take much time to evaluate them and learn if they will benefit your specific situation.  This is something the higher ups in your company should already be doing, but if they aren't then you need to do it and then take the time to educate them on what you have learned.

EDIT:
After reading your comments above I had some more thoughts. It might help if you are able to take an agile approach to developing this app and break it up into different components that can each be fully completed before moving on to the next one. Your manager may be more likely to approve of you taking the extra time for new technology if he's able to see that you're making steady progress along the way. Also, you don't have to choose between writing the entire app in MVC and Entity Framework or ASPX pages and datasets. It's possible to use both in the same app using a hybrid approach. You could start out using MVC and entity framework for a few of the components. If things are going well and your boss is happy then you could continue, but if he feels that it's taking too much time you could develop the rest of the app with ASPX pages and datasets.


问:
Why do you have to manually type variable names while debugging?
I've seen this in a lot of IDEs (even in the most popular and heavily used ones, like Visual Studio): if you want to watch a variable's value, you have to manually type its name in the Watches section of the debugger. Why can't there just be a list of all of them with checkboxes next to them ?

The developer can then just check the box next to the one he wants to watch and that's it. Variables with identical names can probably be numbered in some way (for example a, b, x(1), x(2), c, etc.

I've seen some exceptions to this (NetBeans or BlueJ), but there are exceptions to everything, right ?

Maybe it's a stupid question, maybe not, but I've always wondered why this is so.

答:
In Visual Studio you have always (been using VS since v4) been able to select a variable in the code window (eg: via ctrl-click or mouse scrub) then drag-n-drop it to the watch window.

There is also the auto window which only shows vars that are currently being accessed (and the eternally helpful "function returned value" feature ).

The Locals windows shows all variables in the current scope.

you can also mouse over a variable while debugging, right-click it and select "Add Watch".

you can also bind the Debug.AddWatch command to any shortcut of your choosing.

barring a "read-my-mind and guess which vars I want to look at" feature, I think it's actually pretty easy and well implemented. (said with humour not sarcasm)

Good Luck


答: The suggestions to get up and walk around etc. are good if your cycles are long (an hour or so).  But when cycle times get short, and I find myself popping back and forth between vim and make every few minutes, then I stay in the zone by staying in the pipeline:  While the build or test suite is running, I tend to go back and review the code, then start working on the next chunk that I'd be doing anyway if the build or tests do succeed.</p>


问:
How were some language communities (eg, Ruby and Python) able to prevent fragmentation while others (eg, Lisp or ML) were not?
The term "Lisp" (or "Lisp-like") is an umbrella for lots of different languages, such as Common Lisp, Scheme, and Arc. There is similar fragmentation in other language communities, like in ML.

However, Ruby and Python have both managed to avoid this fate, where innovation occurred more on the implementation (like PyPy or YARV) instead of making changes to the language itself.

Did the Ruby and Python communities do something special to prevent language fragmentation?

答:
Ruby and Python both have benevolent dictators at their helm.  They are languages deeply rooted in pragmatic concerns.  Those are  probably the most significant factors inhibiting fragmentation.   Lisp and ML, on the other hand, are more like "design by committee" languages, conceived in academia, for theoretical purposes.

Lisp was originally designed by John McCarthy as a practical mathematical notation for computer programs.  He never implemented it as an actual programming language; the first implementation was developed by Steve Russell, but he was not a benevolent dictator.  Over time, many different implementations of Lisp appeared; Common Lisp was an attempt to standardize them.

Lisp is more of a "family" of languages.  So is ML, which followed a similar evolutionary path to Lisp.


答:
While you should definitely learn some of the new MS technologies, my recent experience learning about things like WPF and WCF has made me a bit more cautious about learning the newest MS APIs.

Now, LINQ is a major boon to productivity that you should definitely be using; the nice thing is that you can introduce LINQ-to-objects piecemeal in all sorts of random situations, with or without the actual query syntax (I commonly call Where() without the from-select syntax, as it is often shorter.) The mathematical dual of LINQ, Reactive Extensions, is something you should be aware of, although I am still struggling to find a really good use case. Likewise, all features of C# 3/4/5 are useful so you should study them and watch for places where they will be useful, even as you continue using the "old" BCL stuff.

However, I'm going to take devil's advocate and suggest that the very newest big MS libraries, such as WCF and WPF are not necessarily worth learning at all.

The primary reason is that they are huge, and not especially well-designed (the former being a symptom of the latter). I briefly blogged recently about why WPF sucks. As for WCF, the whitepaper makes it sound like it will easily interoperate nicely with "Java EE server running on a non-Windows system" and "Partner applications running on a variety of platforms", but the truth is that WCF APIs are very specifically SOAP-oriented and have very limited support for non-SOAP protocols. MS could have easily designed a general system that allows pluggable protocols, and maybe the capability is hidden (undocumented) in there somewhere, but as far as I can tell they chose to design a much more limited system that can only do SOAP and limited HTTP (as long as your message body is a serialized .NET object, IIRC). I researched Entity Framework more briefly, but noticed some complaints that it was incapable of supporting some scenarios that the (much simpler) LINQ-to-SQL can handle out-of-the-box.

IMO the design of all of these libraries are fundamentally flawed because they use a lot of components that are tightly coupled to each other, a dependency graph of the classes in each framework would probably be huge and look like a jumbled mess of scribbly lines. And even if the design were good, we would not be able to tell because there aren't public architectural documents that delve into the lower-level details, and the MSDN docs for the most part aren't very good (they tend to get less and less helpful as you look at lower and lower-level classes.)

The sheer size of the libraries also seems like a flaw; I have learned over 20 years of programming that simplicity is a virtue, one that Microsoft has never valued.

But you might ask, "so what"? Well, with such big libraries you might never feel like you really understand them. That means that when you want to do something outside the use cases for which Microsoft specifically designed WCF/WPF/EF, you're not going to know how, and it is possible that no one outside Redmond will know how, either. And when something goes wrong, you will have a hard time figuring out what went wrong. And 15 years from now when Microsoft has moved on to their next next-generation API, no one is going to enjoy maintaining software built on a foundation that is so poorly-understood.

Also because of the largeness and complexity of these new APIs, the cross-platform alternative to .NET, Mono, has poor support or no support for them. You'll probably have little difficulty using your typed data tables on Linux or Mac, but Entity Framework? Forget about it. I wouldn't be surprised if Mono never supports it.

I have used LINQ-to-SQL in a new project and it's not bad. In some ways it could be better, but I think the developer experience is substantially better than ADO.NET. One significant limitation: L2S is easiest by far if you modify tables in "connected" mode, unlike the old ADO.NET which was specifically designed to work without an active database connection. Anyway, since LINQ-to-SQL is (according to Mono people) a quarter the size of Entity Framework, it's a shame that MS decided to quit working on it.


答:
I've used cfthread alot with batch processing - and more around memory management than anything else.

So if I have 80,000 records I need to process, I will often loop around, do the processing in a thread, and then join it back up at the end.

This doesn't give me any speed increase, but it does often mean I don't get memory overflows as the data processed in the thread is easily garbage collectable.

Oh, what I don't like about cfthread? on ACF, I'm limited by my Licence. That drives me nuts.

Title: How are you using CFThread in ColdFusion Applications?

Body:
I'm presenting on Concurrency in ColdFusion at CFObjective this year, and I'd like to hear how you're using CFThread in your ColdFusion applications.

In addition, what problems have you had while using it, and how (if at all) have you solved them?

What do you dislike about CFThread?

Have you run into significant weaknesses with CFThread or other problems where it simply could not do what you wanted to do?

Finally, if there's anything you'd like to add related to concurrency in CF, not specifically related to CFThread, please do tell.


答:
I don't think it's correct to say that languages like Python and Ruby aren't fragmented. Already we're starting to see some fragmentation effects. For instance, Python 3 isn't entirely backwards-compatible with Python 2, so both versions need to be maintained and lots of existing code works only with Python 2. There are some Python spinoffs, too, including PyPy.

Another factor is the age of the languages. The ones most subjected to fragmentation are the older languages and are thus subject to pressures of evolution and revision. Lisp was invented several decades ago, so there has been ample time to take some of its ideas and incorporate them into new languages. C is another example of a fragmented language. While C had only one really major revision to the language itself (K&R to ANSI), there have been numerous spinoffs including C++, Not Quite C, and all the others that share a C-like syntax.

Ruby itself is a "fragmentation" (if you will) of previous languages. Since it incorporates ideas from C, Smalltalk, and Perl (among others), it's currently the language doing the fragmenting. I don't see why we might not see further convolution of Ruby with other languages in the future.

Title: How were some language communities (eg, Ruby and Python) able to prevent fragmentation while others (eg, Lisp or ML) were not?

Body:
The term "Lisp" (or "Lisp-like") is an umbrella for lots of different languages, such as Common Lisp, Scheme, and Arc. There is similar fragmentation in other language communities, like in ML.

However, Ruby and Python have both managed to avoid this fate, where innovation occurred more on the implementation (like PyPy or YARV) instead of making changes to the language itself.

Did the Ruby and Python communities do something special to prevent language fragmentation?


答:
What I currently use works fine and my development time is fast

Unfortunately, Microsoft doesn't give a fig for this, what matters to them is to sell you more tools. That means creating new technologies, which means you have to buy more training too! Win-win, for them.

For you, it means a constant battle to learn new things, and once you've started to get good at them and your development productivity is as fast as it used to be.... there's something else to learn and you have to start all over again. There's a reason software is generally poor quality, its because its not treated like the 'professional' services like engineering or architecture, they keep the things that work. We throw them away and start from scratch all the time.

But, this poor state of the world doesn't help you. So my advice is to use a combination of "keeping up with technology" and "don't want to fall behind". Your boss should be concerned with recruitment, if you only did VB6 dev, then you'll find it quite hard to recruit new staff (well actually you'd probably find it really easy, all the guys who
liked VB6 will flock to you, but that's another matter).

I'd say that you need to check whether new technology x would help you do future development even faster - then it stops being a personal or simply wasteful task, and becomes a business-improvement task, companies are always going on about how R&D "innovation" helps them stay competitive.


问:
Is there a sequence to read through the Android developer site for a user new to Android?
To summarize: I can buy a book, people say "Just read the developer site", I like to be spoon-fed the early learning piece for a technology, what path through the developer site will give me that spoonfeeding I need (that is, examples tied directly to the section being discussed, a clear path, etc.).

I keep seeing that I don't need to buy an Android development book, that I should just read the Android developer site, because it has everything I need to know. I see it more as drinking from a fire hose.

But I'm one of those people who likes to be walked through the basics. I like to build up my knowledge, rather than being dropped into reference documentation. I also like to make sure I have see all/most of the topics covered. I'd hate to develop the wrong thing, because I don't know about Fragments, Content Providers, or whatever.

So, since it's a great resource, better than any book (we don't need no stinking books), how do I traverse the site to get the information provided in the same way as a book would lay it out?

答:
Well here's the steps that I took (granted I like to jump in over my head which from what I gather isn't exactly your way of doing things):

Google around

Keep getting directed here: http://developer.android.com/guide/topics/fundamentals.html

Get about half way through, then get ADD.  Back to google.  Before you do the same, have a gander at 'The AndroidManifest.xml, Activities and all of its subpages, and User Interface and all of its subpages

Find some tutorials: (google it.  Hackaday and ActiveFrequency had some decent ones, but there's some stupid two hyperlink rule here or something, so I can't link them)

Feel ready to start work on an app

Start programming

Get confused

Find answers on StackOverflow and other similar sites

When I get one part of the app working and move on to the next, check the appropriate section in  http://developer.android.com/guide/topics/fundamentals.html to try to find anything that could be relevant.

At some point, realize that I did everything wrong with my first app and move on to another.


问:
Be liberal in what you accept... or not?
[Disclaimer: this question is subjective, but I would prefer getting answers backed by facts and/or reflexions]

I think everyone knows about the Robustness Principle, usually summed up by Postel's Law:

Be conservative in what you send; be liberal in what you accept.

I would agree that for the design of a widespread communication protocol this may make sense (with the goal of allowing easy extension), however I have always thought that its application to HTML / CSS was a total failure, each browser implementing its own silent tweak detection / behavior, making it near impossible to obtain a consistent rendering across multiple browsers.

I do notice though that there the RFC of the TCP protocol deems "Silent Failure" acceptable unless otherwise specified... which is an interesting behavior, to say the least.

There are other examples of the application of this principle throughout the software trade that regularly pop up because they have bitten developpers, from the top off my head:

Javascript semi-colon insertion

C (silent) builtin conversions (which would not be so bad if it did not truncated...)

and there are tools to help implement "smart" behavior:

name matching phonetic algorithms (Double Metaphone)

string distances algorithms (Levenshtein distance)

However I find that this approach, while it may be helpful when dealing with non-technical users or to help users in the process of error recovery, has some drawbacks when applied to the design of library/classes interface:

it is somewhat subjective whether the algorithm guesses "right", and thus it may go against the Principle of Least Astonishment

it makes the implementation more difficult, thus more chances to introduce bugs (violation of YAGNI ?)

it makes the behavior more susceptible to change, as any modification of the "guess" routine may break old programs, nearly excluding refactoring possibilities... from the start!

And this is what led me to the following question:

When designing an interface (library, class, message), do you lean toward the robustness principle or not ?

I myself tend to be quite strict, using extensive input validation on my interfaces, and I was wondering if I was perhaps too strict.

答:
IMO, robustness is one side of a design trade-off not a "prefer" principle. As many have pointed out, nothing stinks like blowing four hours trying to figure out where your JS went wrong only to discover the real problem was only one browser did the proper thing with XHTML Strict. It let the page go to pieces when some portion of the served HTML was a complete disaster.

On the other hand, who wants to look up documentation for a method that takes 20 arguments and insists they be in the exact same order with empty or null value place holders for the ones you want to skip? The equally awful robust way to deal with that method would be to check every arg and try to guess which one was for what based on relative positions and types and then fail silently or try to "make do" with meaningless args.

Or you can bake flexibility into the process by passing an object literal/dictionary/key-value pair list and handle the existence of each arg as you get to it. For the very minor perf tradeoff, that's a cake and eat it too scenario.

Overloading args in intelligent and interface-consistent ways is a smart way to be robust about things. So is baking redundancy into a system where it's assumed packet delivery will regularly fail to be delivered in a massively complicated network owned and run by everybody in an emerging field of technology with a wide variety of potential means for transmission.

Tolerating abject failure, however, especially within a system you control, is never a good tradeoff. For instance, I had to take a breather to avoid throwing a hissy fit in another question about putting JS at the top or bottom of the page. Several people insisted that it was better to put JS at the top because then if the page failed to load completely, you would still potentially have some functionality. Half-working pages are worse than complete busts. At best, they result in more visitors to your site rightly assuming you're incompetent before you find out about it than if the busted up page is simply bounced to an error page upon failing it's own validation check followed by an automated e-mail to somebody who can do something about it. Would you feel comfortable handing your credit card info over to a site that was half-busted all the time?

Attempting to deliver 2010 functionality on a 1999 browser when you could just deliver a lower tech page is another example of a foolhardy design tradeoff. The opportunities blown and money I've seen wasted on developer time spent on bug-ridden workarounds just to get rounded corners on an element hovering above a !@#$ing gradient background for instance, have completely blown me away. And for what? To deliver higher tech pages that perform poorly to proven technophobes while limiting you choices on higher end browsers.

In order for it to be the right choice, the choice to handle input in a robust manner should always make life easier on both sides of the problem, in the short and the long term IMO.


问:
GPL vs plugin interfaces not designed with a specific application in mind
I am not seeking or in need of legal advice, but an interesting though experiment came to my mind.

Imagine the following situtation (I cannot really think about a concrete example and I am unsure if a real manifestation even exists): there is a free (libre) api A licensed under some permissive license or even LGPL. Non-free application B implements this api in order host plugins, but there are other free software doing the same thing. Moreover, there is plugin C acting as a plugin under api A. It links to library D, that is under GPL, so C is also under GPL. Plugins using A are loaded into hosts via a dlopen-like mechanism and use complex data structure for host-plugin communication. Neither B nor C distribute any files that may be required for A to function properly (like headers containing the structure definitions of A or dynamic libraries containing helper functions for A written by the authors of A), but such things may exist.

Now some user installs application B and plugin C on his machine, along with anything that may be required for api A to function properly. Then he proceeds and loads C into B and creates some intellectual property with B which is not a piece of software.

Did a GPL violation happend at some point, and if so, who violated GPL and why?

The authors of C violate D's license by making C possible to be used in non-free host B? This is a possibility because they can't give and exception of GPL (like one described in http://www.gnu.org/licenses/gpl-faq.html#GPLPluginsInNF or http://www.gnu.org/licenses/gpl-faq.html#LinkingOverControlledInterface) due to D's license terms.

The authors of B violate C's and D's license by making C possible to be loaded in B? This is a possibility because http://www.gnu.org/licenses/gpl-faq.html#NFUseGPLPlugins disallows the mechanisms A uses for communitation between the free and non-free modules.

The authors of A, because the api may be used (and in this case, was used) for communication between GPL'd and non-free software. This would be extremely absurd.

The user, because at the moment of loading B into C, he made a derived work of C. I think this is impossible, because he does not distribute it. But would the situation change is he decided to release a configuration file of B which makes B load C as a plugin?

Nobody, because A counts as a 'system library', and both B and C directly interact only with A, not eachother. In a sane world, this would happen...

A concrete example of A could be some kind of audio (think LADSPA) or image processing api. However, I could find no such interface (that is free software, generic and is also implemented by commercial tools). A real-world example could also be quite enlightening.

答: I believe this is a loophole that allows non-gpl code to use gpl code. The one example I know of the the vlc active x component. VLC is gpl. VLC activex component is GPL as well. Any windows app that can load activex components can load the vlc activex component without sharing any headers or code. I think it's your last bullet point that applies. </p>


答:
I have a bar attached to the doorpost

I can do only 5 pull-ups so it takes less than a minute. Or I make a cup of tea.


问:
I can't program because the code I am using uses old coding styles. Is this normal to programmers?
I have my first real job as programmer, but I can't solve any problems because of the coding style used. The code here:

Does not have comments

Does not have functions (50, 100, 200, 300 or more lines executed in sequence)

Uses a lot of if statements with a lot of paths

Has variables that make no sense (eg.: cf_cfop, CF_Natop, lnom, r_procod)

Uses an old language (Visual FoxPro 8 from 2002), but there are new releases from 2007.

I feel like I have gone back to 1970. Is it normal for a programmer familiar with OOP, clean-code, design patterns, etc. to have trouble with coding in this old-fashion way?

EDIT: All the answers are very good. For my (un)hope, appears that there are a lot of this kind of code base around the world. A point mentioned to all answers is refactor the code. Yeah, I really like to do it. In my personal project, I always do this, but... I can't refactor the code. Programmers are only allowed to change the files in the task that they are designed for.

Every change in old code must be keep commented in the code (even with Subversion as version control), plus meta information (date, programmer, task) related to that change (this became a mess, there is code with 3 used lines and 50 old lines commented). I'm thinking that is not only a code problem, but a management of software development problem.

答:
One of the things that sticks out is your edited comment

Every change in old code must be keep commented in the code, plus meta
  information (date, programmer, task) related to that change (this
  became a mess, there are code with 3 used lines and 50 old lines
  commented). I'm thinking that is not only a code problem, but a
  management of software development problem.

I also have a project where I inherited a legacy FoxPro code base with many of the issues that you describe.  One of the first things I introduced to the project was a good source code repository.  FoxPro can integrate with SourceSafe, but that product is painful to use.

I grabbed a copy of Paul McNett's scx tool http://paulmcnett.com/scX.php and integrated that into my development cycle.  It does a pretty good job of extracting the binary FoxPro code to a text format that can then be put into a source repository, like Subversion, Mercurial, or even git. (You might find the SubFox project at http://vfpx.codeplex.com useful.

These tools provide the History and allow the programmers to get on with the job of maintaining the code.  It definitely takes some time to learn to use these tools, but since they are all free, it doesn't really make sense not to invest some time into them. (even if you can't get the Job projects moving that way).


问:
Strategies for avoiding SQL in your Controllers... or how many methods should I have in my Models?
So a situation I run into reasonably often is one where my models start to either:

Grow into monsters with tons and tons of methods

OR

Allow you to pass pieces of SQL to them, so that they are flexible enough to not require a million different methods

For example, say we have a "widget" model. We start with some basic methods:

get($id)

insert($record)

update($id, $record)

delete($id)

getList()  // get a list of Widgets

That's all fine and dandy, but then we need some reporting:

listCreatedBetween($start_date, $end_date)

listPurchasedBetween($start_date, $end_date)

listOfPending()

And then the reporting starts to get complex:

listPendingCreatedBetween($start_date, $end_date)

listForCustomer($customer_id)

listPendingCreatedBetweenForCustomer($customer_id, $start_date, $end_date)

You can see where this is growing... eventually we have so many specific query requirements that I either need to implement tons and tons of methods, or some sort of "query" object that I can pass to a single ->query(query $query) method...

... or just bite the bullet, and start doing something like this:

list = MyModel->query(" start_date > X AND end_date < Y AND pending = 1 AND customer_id = Z ")

There's a certain appeal to just having one method like that instead of 50 million other more specific methods... but it feels "wrong" sometimes to stuff a pile of what's basically SQL into the controller.

Is there a "right" way to handle situations like this? Does it seem acceptable to be stuffing queries like that into a generic ->query() method?

Are there better strategies?

答:
There's no correct way to do this. Many people use ORMs to abstract away all the complexity. Some of the more advanced ORMs translate code expressions into complicated SQL statements. ORMs have their downsides as well, however for many applications the benefits outweigh the costs.

If you aren't working with a massive dataset, the simplest thing to do is to select the entire table into memory and filter in code.

```<code>//pseudocode
List<Person> people = Sql.GetList<Person>("select * from people");
List<Person> over21 = people.Where(x => x.Age >= 21);
</code>```

For internal reporting applications this approach is probably fine. If the dataset is really big, you'll start needing lots of custom methods as well as appropriate indexes on your table.

Body:
There's no correct way to do this. Many people use ORMs to abstract away all the complexity. Some of the more advanced ORMs translate code expressions into complicated SQL statements. ORMs have their downsides as well, however for many applications the benefits outweigh the costs.

If you aren't working with a massive dataset, the simplest thing to do is to select the entire table into memory and filter in code.

//pseudocode
List<Person> people = Sql.GetList<Person>("select * from people");
List<Person> over21 = people.Where(x => x.Age >= 21);

For internal reporting applications this approach is probably fine. If the dataset is really big, you'll start needing lots of custom methods as well as appropriate indexes on your table.