答:
Rewriting from scratch just so you can have automated tests is silly - you have a codebase that (mostly) works, and you probably can test it (just not automatically). A rewrite, even with all the tests in the world, introduces extra risk, and it always takes longer than expected. So don't do that.

Writing tests to achieve 100% coverage in one go is also silly, because it means you are halting on-going development to implement something which doesn't add any value yet. In most situations, this is unacceptable. Further, writing tests for code that already works and doesn't need changing has little benefit other than verifying that it does indeed work (but if it's running in production, you better be pretty sure about that already).

The best way to go, IMO, is to add tests as you go. That is, for every change you make, apply the following steps:

See whether existing tests sufficiently describe the current functionality.

If necessary, add tests to capture the current functionality of that particular part / module / class / function / ... Verify that they pass.

Refactor existing code if necessary.

Modify the tests to reflect the intended new behavior.

Modify the code to make the tests pass.

Refactor.

Steps 4 through 6 are just basic TDD; the only addition is that you retroactively add tests as needed before you start the actual TDD cycle.

If you follow this procedure, and the tests you add in step 2 are sufficient, the codebase will gradually move towards full test coverage.

Of course, if you are going to rewrite anyway, for different reasons, then going TDD right from the start is probably a good idea.

Title: Introduce unit testing when codebase is already available

Body:
Possible Duplicate:

  Best practices for retrofitting legacy code with automated tests

I've been working on a project in Flex for three years now without unit testing. The simple reason for that is the fact that I just didn't realize the importance of unit testing when being at the beginning of studies at university. Now my attitude towards testing changed completely and therefore I want to introduce it to the existing project (about 20000LOC).

In order to do it, there are two approaches to choose from:

1) Discard the existing codebase and start from scratch with TDD

2) Write the tests and try to make them pass by changing the existing code

Well, I would appreciate not having to write everything from scratch but I think by doing this, the design would be much better.

What would be your approach?


问:
Best practice to propagate preferences of application
What is your approach with propagation to all classes/windows of preferences/settings of your application?

Do you share the preference_manager class to all classes/windows who need it or you make variables in each classes/windows and update them manually each time setting are changed?

Currently I have a PreferencesInterface class that hold all preferences and is responsible to default all values with a dedicated method called on create and when needed, all values are public, so non getters/setters, also it have virtual SavePreferences/LoadPreferences methods.

Then I have PreferencesManager that extends from PreferencesInterface and is responsible for actually implementation of SavePreferences/LoadPreferences. I've made this basically for cross-platform so that every platform can have a different implementation of actual storage (registry, ini, plist, xml, whatever).

答:
Out of the options you give, I'd definitely side with the first.

Having a single class or object that is responsible for holding information about the users preferences, which is then queried by interested parties, is much more maintainable than having ever class that could be interested duplicating the storage of these settings and having to compile an ever-growing list of parties that need to be updated whenever something changes.

ContentLicense: CC BY-SA 3.0


答: It would be good having a Preferences class and a PreferenceManager class that extends/uses Preferences where the former will have getter methods for all preferences and the latter will add setters for the same. The former can be shared with all parts of the app that need access to preferences. The latter will be used only by the context(s) that can modify/has write access to the preferences.

Title: Best practice to propagate preferences of application

Body:
What is your approach with propagation to all classes/windows of preferences/settings of your application?

Do you share the preference_manager class to all classes/windows who need it or you make variables in each classes/windows and update them manually each time setting are changed?

Currently I have a PreferencesInterface class that hold all preferences and is responsible to default all values with a dedicated method called on create and when needed, all values are public, so non getters/setters, also it have virtual SavePreferences/LoadPreferences methods.

Then I have PreferencesManager that extends from PreferencesInterface and is responsible for actually implementation of SavePreferences/LoadPreferences. I've made this basically for cross-platform so that every platform can have a different implementation of actual storage (registry, ini, plist, xml, whatever).


问:
Introduce unit testing when codebase is already available

Possible Duplicate:

  Best practices for retrofitting legacy code with automated tests

I've been working on a project in Flex for three years now without unit testing. The simple reason for that is the fact that I just didn't realize the importance of unit testing when being at the beginning of studies at university. Now my attitude towards testing changed completely and therefore I want to introduce it to the existing project (about 20000LOC).

In order to do it, there are two approaches to choose from:

1) Discard the existing codebase and start from scratch with TDD

2) Write the tests and try to make them pass by changing the existing code

Well, I would appreciate not having to write everything from scratch but I think by doing this, the design would be much better.

What would be your approach?

答:
Legacy code is working code, it has been tested in the wild. The worst thing you can do it throw it away and replace it with new code. Even with the best new code (with TTD ect) will have occasional bugs.

What I would recommend it every time you hit a bug you create a unit test around that functionality. Its not much extra work when your fixing things anyway and will mean the more buggy areas will get unit tests first.


问:
Create association between informations
I deployed a project some days ago that allow to extract some medical articles using the results of a questionnaire completed by a user. For instance, if I reply on questionnaire I'm affected by Diabetes type 2 and I'm a smoker, my algorithm extracts all articles related to diabetes bubbling up all articles contains information about Diabetes type 2 and smoking. Basically we created a list of topic and, for every topic we define a kind of "guideline" that allows to extract and order informations for a user.

I'm quite sure there are some better way to put on relationship two content but I was not able to find them on network. Could you suggest my a model, algorithm or paper to better understand this kind of problem and that helps me to find a faster, and more accurate way to extract information for an user?

答:
This is a perfect application for a full-text indexer such as Lucene.

Let's say your questionnaire asks about three things:  smoking, diabetes and obesity.  Once the text of the articles is indexed, you can use the answers you get to form queries that will return the most relevant articles first.

So, for example, the query for an overweight, non-diabetic smoker might be:

obesity smoking

+obesity +smoking to return only articles that explicitly mention both

+obesity +smoking -diabetes to make sure selected articles mention both and do not mention diabetes

Your results can be further enhanced by using a query expander like WordNet that can add synonyms to the query (e.g. expanding diabetes to include related words like neuropathy, retinopathy and insulin) and make articles containing those words more relevant.

I've built several systems that put full-text indexers to unusual use and have found that they provide a lot of query flexibility with a minimum of development and give very good results.

Title: Create association between informations


问:
Is having functionality in DB a road block to scalability?
I may not be able to give the right title to the question. But here it is,

We are developing financial portal for wealth management. We are expecting over 10000 clients to use the application. The portal calculates various performance analytics based on the the technical analysis of the stock market.

We developed lot of the functionality through Stored procedures, user defined functions, triggers etc. through Database. We thought we can gain huge performance boost doing stuff directly in database than through C# code. And we actually did get a huge performance boost.

When I tried to brag about the achievement to our CTO, he counter questioned my decision of having functionality implemented in database rather than code. According to him such applications suffer scalability problems. In his words "These days things are kept in memory/cache. Clustered data is hard to manage over time. Facebook, Google have nothing in database. It is the era of thin servers and thick clients. DB is used only to store plain data and functionality should be completely decoupled from the database."

Can you guys please give me some suggestions as to whether what he says is right. How to go about architect such an application?

答:
And we actually did get a huge performance boost.

I think you need to set a performance benchmark and start building your prototype first. Keeping all logic in DB is an old school (imho, i don't have anything against it) of dealing with client-server architecture. Although, it has its advantages, there are number of drawback that needs to be considered.

Usual approach for this type of salable applications is done through SOA. Because in long run, this is the easiest way to add new client applications to your project.

You have also mentioned triggers. The trigger usage might turn to be a big gotchas later in the application's support life-cycle, i would be double careful with it, and even try to skip its usage.


答:
The only drawback of propagation of PreferencesManager that i see is that you can't really know that on a certain point that class is still exist (that the pointer in not simply pointing to a dirt memory), but the huge advantage is that settings are applied to all your application on-the-fly.

The other approach is more secure because you are really sure that variables are anytime accessible, but it's more triky to propagate changes.

I really don't know what's better...


问:
What is the relevance of resumes in the age of GitHub, Stack Exchange, Coursera, Udacity, blogs, etc.?
My resume is no longer relevant. It can no longer contain an adequate description of my technical abilities. One can get a much better sense of what I am capable of by looking at my GitHub repositories, my Stack Exchange profiles, and the various courses that I am taking at Udacity and Coursera. The problem is that I have no idea how to tell employers that those are the places to look if they want an accurate description of what I can do.

Every time a recruiter contacts me I gently nudge them towards all the resources I just mentioned and I also provide a link to a publicly visible Google doc that contains my resume along with links to all those resources. Yet, they keep coming back asking for a more descriptive resume.

How can I make it even more blatantly obvious that if somebody wants to hire me then they can save themselves a whole bunch of trouble by just clicking on a few links and browsing around?

答: Create a careers resume. I find it the best way of demonstrating professional experience, education, major achievements, online presence, github repositories, etc. on a single webpage. Plus it is easy to keep it up to date and refer recruiters using a simple URL.</p>


答:
In short, I would agree with your CTO.  You've probably gained some performance at the expense of scalability (if those terms are confusing, I'll clarify below).  My two biggest worries would be maintainability and lack of options to scale horizontally (assuming you are going to need that).

Proximity to data:  Let's take a step back.  There are some good reasons for pushing code into a DB.  I would argue that the biggest one would be proximity to the data - for example, if you are expecting a calculation to return a handful of values, but these are aggregations of millions of records, sending the millions of records (on-demand) over the network to be aggregated elsewhere is hugely wasteful, and could kill easily your system.  Having said this, you could achieve this proximity of data in other ways, essentially using caches or analysis DBs where some of the aggregation is done upfront.

Performance of code in the DB: Secondary performance effects, such as "caching of execution plans" are more difficult to argue.  Sometimes, cached execution plans can be a very negative thing, if the wrong execution plan was cached.  Depending on your RDBMS, you may get the most out of these, but you won't get much over parametrised SQL, in most cases (those plans typically get cached, too).  I would also argue that most compiled or JIT'ed languages typically perform better than their SQL equivalents (such as T-SQL or PL/SQL) for basic operations and non-relational programming (string manipulation, loops, etc), so you wouldn't be losing anything there, if you used something like Java or C# to do the number crunching.  Fine-grained optimisation is also pretty difficult - on the DB, you're often stuck with a generic B-tree (index) as your only data structure.  To be fair, a full analysis, including things like having longer-running transactions, lock escalation, etc, could fill books.

Maintainability: SQL is a wonderful language for what it was designed to do.  I'm not sure it's a great fit for application logic.  Most of the tooling and practices that make our lives bearable (TDD, refactoring, etc) are difficult to apply to database programming.

Performance versus scalability: To clarify these terms, I mean this: performance is how quick you'd expect a single request to go through your system (and back to the user), for the moment assuming low load.  This will often be limited by things like the number of physical layers it goes through, how well optimised those layers are, etc.  Scalability is how performance changes with increasing number of users / load.  You may have medium / low performance (say, 5 seconds+ for a request), but awesome scalability (able to support millions of users).  In your case, you will probably experience good performance, but your scalability will be bounded by how big a server your can physically build.  At some point, you will hit that limit, and be forced to turn to things like sharding, which may not be feasible depending on the nature of the application.

Premature Optimisation:  Ultimately, I think you've made the mistake of optimising prematurely.  As others have pointed out, you don't really have measurements showing how the other approaches would work.  Well, we can't always build full-scale prototypes to prove or disprove a theory...  But in general, I'd always be hesitant to chose an approach which trades maintainability (probably the most important quality of an application) for performance.

EDIT:  On a positive note, vertical scaling can stretch quite far in some cases.  As far as I know, SO ran on a single server for quite some time.  I'm not sure how it matches up to your 10 000 users (I guess it would depend on the nature of what they are doing in your system), but it gives you an idea of what can be done (actually, there are far more impressive examples, this just happens to be a popular one people can easily understand).

EDIT 2:  To clarify and comment on a few things raised elsewhere:

Re: Atomic consistency - ACID consistency may well be a requirement of the system.  The above doesn't really argue against that, and you should realise that ACID consistency doesn't require you to run all your business logic inside the DB.  By moving code which does not need to be there into the DB, you're constraining it to run in the physical environment of the rest of the DB - it's competing for the same hardware resources as the actual data management portion of your DB.  As for scaling only the code out to other DB servers (but not the actual data) - sure, this may be possible, but what exactly are you gaining here, apart from additional licensing costs in most cases?  Keep things that don't need to be on the DB, off the DB.

Re: SQL / C# performance - since this seems to be a topic of interest, let's add a bit to the discussion.  You can certainly run native / Java / C# code inside DBs, but as far as I know, that's not what was being discussed here - we're comparing implementing typical application code in something like T-SQL versus something like C#.  There a number of problems which have been difficult to solve with relational code in the past - e.g. consider the "maximum concurrent logins" problem, where you have records indicating a login or logout, and the time, and you need to work out what the maximum number of users logged in at any one time was.  The simplest possible solution is to iterate through the records and keep incrementing / decrementing a counter as you encounter logins / logouts, and keeping track of the maximum of this value.  It turns out that unless your DB supports a certain sliding window aggregation (which SQL 2008 didn't, 2012 may, I don't know), the best you can do is a CURSOR (the purely relational solutions are all on different orders of complexity, and attempting to solve it using a while loop results in worse performance).  In this case, yes, the C# solution is actually faster than what you can achieve in T-SQL, period.  That may seem far-fetched, but this problem can easily manifest itself in financial systems, if you are working with rows representing relative changes, and need to calculate windowed aggregations on those.  Stored proc invocations also tend to be more expensive - invoke a trivial SP a million times and see how that compares to calling a C# function.  I hinted at a few other examples above - I haven't yet encountered anyone implement a proper hash table in T-SQL (one which actually gives some benefits), while it is pretty easy to do in C#.  Again, there are things that DBs are awesome at, and things that they're not so awesome at.  Just like I wouldn't want to be doing JOINs, SUMs and GROUP BYs in C#, I don't want to be writing anything particularly CPU intensive in T-SQL.

Title: Is having functionality in DB a road block to scalability?

Body:
I may not be able to give the right title to the question. But here it is,

We are developing financial portal for wealth management. We are expecting over 10000 clients to use the application. The portal calculates various performance analytics based on the the technical analysis of the stock market.

We developed lot of the functionality through Stored procedures, user defined functions, triggers etc. through Database. We thought we can gain huge performance boost doing stuff directly in database than through C# code. And we actually did get a huge performance boost.

When I tried to brag about the achievement to our CTO, he counter questioned my decision of having functionality implemented in database rather than code. According to him such applications suffer scalability problems. In his words "These days things are kept in memory/cache. Clustered data is hard to manage over time. Facebook, Google have nothing in database. It is the era of thin servers and thick clients. DB is used only to store plain data and functionality should be completely decoupled from the database."

Can you guys please give me some suggestions as to whether what he says is right. How to go about architect such an application?


问:
C# database communication technique
A few days ago, I read an answer stating that writing queries within your c# code are long gone.

I'm not sure what the specific person meant with the comment but, it got me thinking. At the company where i work, we maintain an assembly containing all the queries to the database (let's call it Queries). This assembly is reference by a QueryService (Retrieve the correct queries) assembly which in turn is referenced by a UnitOfWork assembly (The database connector classes, we have different connector classes for SQL, MySQL etc.). We use these three assemblies to perform operations on our database and all queries/commands are written by C# code.

Is there a better way to communicate with the database and is there a better way to communicate with different database types?

答:
I'd hazard a guess that the quote is talking about the rise of ORMs for database access.

An ORM will do all the communication to the database and translate between the database and your objects.

Most ORMs will also abstract away the differences between different databases, so you should be able to use the same code.

Examples of ORMs for .NET are nHibernate and Entity Framework (though there are many).

Title: C# database communication technique


问:
How can I figure out if programming is right for me?
I have an IT background and was pretty confident until an opportunity came up at work to go into programming(C#). I have never programmed before this, and the software I am programming for is a program I have never used before (a 3D modeling software).

It has been 6 months since then and I feel like giving up. I didn't get much training... about 3 weeks of training spread out over the last 6 months.

I think I would be good at programming but this experience is making me rethink my decision. I'm not sure if it's just me, or if this frustration is normal.

How can I figure out if programming is right for me?

答:
Is it me or am I right to be frustrated?

The question that you really need to ask yourself are:

a) Is do you enjoy programming? b) Do you feel the happiest person in the world once your application is working? - If your answer is YES, stop worrying, just keep learning and improving your skills in programming.

Generally speaking, 3D modeling - is totally different area in programming world like a game programming. That may scare you or not drive your interest. Don't get scared, just keep up your motivation by learning things that you don't know. Set your short-term and long-term goals on what you need to catch-up and learn.

Edit: The "3D modeling software" is not a main stream programming area. Thus, you might find yourself in learning very specific knowledge/techniques that are not applied in other areas (CRM, accounting, health care, etc..) If you find "3D modeling" NOT interesting, just look for different business area of programming that drives your interest.


答:
Important thing in .NET to mention is the LinQ - a feature in C# programming language. It is very powerful querying tool on collections that support generic IEnumerable<T> interface.

For example, LINQ to SQL (also called Linq2Sql) and LINQ to Entities are both very powerful and getting familiar with it saves tons of time.

This is really handy tool to be used, in times when you are building a quick data-driven application.

Edit: To support different databases you may need to look ORM solutions that have that capability. To my knowledge nHibernate and lately Entity Framework have this capability.

Title: C# database communication technique

Body:
A few days ago, I read an answer stating that writing queries within your c# code are long gone.

I'm not sure what the specific person meant with the comment but, it got me thinking. At the company where i work, we maintain an assembly containing all the queries to the database (let's call it Queries). This assembly is reference by a QueryService (Retrieve the correct queries) assembly which in turn is referenced by a UnitOfWork assembly (The database connector classes, we have different connector classes for SQL, MySQL etc.). We use these three assemblies to perform operations on our database and all queries/commands are written by C# code.

Is there a better way to communicate with the database and is there a better way to communicate with different database types?


答:
My advice to you is to spend some time on your own with C# and programming in general.

Make a small game. Make a simple tool to organize your photos. Make anything really.

If you spend your own individual time, you may find you enjoy programming. If not, programming is not the career for you. Either way, keep working at it.

A resource that may be of use for learning some concepts:

http://msdn.microsoft.com/en-us/library/618ayhy6.aspx (C# Reference)

Body:
I have an IT background and was pretty confident until an opportunity came up at work to go into programming(C#). I have never programmed before this, and the software I am programming for is a program I have never used before (a 3D modeling software).

It has been 6 months since then and I feel like giving up. I didn't get much training... about 3 weeks of training spread out over the last 6 months.

I think I would be good at programming but this experience is making me rethink my decision. I'm not sure if it's just me, or if this frustration is normal.

How can I figure out if programming is right for me?


答:
There's a few things to note about getting into programming.

First off, you will never know everything about programming. You'll probably never even come close to knowing a fraction of everything. And if you ever get to thinking you know something, something new will come out and what you know will be obsolete.

So, you need to be OK with constantly learning new things, and teaching yourself what needs to be done. If you're not OK with spending a lot of time doing a lot of learning, doing research, and figuring things out through "educated trial and error", don't get into Programming.

Second, its the logic that matters, not the syntax. Just learning a language, framework, or technology does not necessarily make a good programmer. You really need to have the sort of mind that is capable of understanding the logic behind the code - how the pieces fit together, what kind of logic is getting used, and how the computer will interpret your code.

It sounds like you're working with a single piece of software and language, but keep in mind there are many more languages and technologies out there. Don't judge them all by your experience with one of them. If the syntax is frustrating you, then keep in mind there are always other options. But if you're having problems grasping the logic behind the code, then perhaps programming may not be for you.

And last of all, don't pick a job you hate. Sure programming can be frustrating, but it can also be very rewarding. If you can handle the times when you want to bang your head against the wall over some bit of code, or delete everything off your computer in frustration, and still enjoy the coding, you're good :)

Title: How can I figure out if programming is right for me?


答:
You may not have chosen the best path to learn programming :)

Seriously, 3D modelling is a very complex domain even for an experienced programmer, so having that as your first project is going to be hard.  I would suggest getting some good books and working on simple projects on your own.  If you enjoy working on those, then keep plugging away and you will get there.  If you don't enjoy that, then it might be time time to cut your losses.

I'm not going to start any arguments about the best programming books, but I think you will find numerous questions on SE about programming references.

FWIW, I have been programming in MS Windows since 2.x, and if I jumped into an existing 3D modelling project, I think I would be frustrated for a while too :)


答:
Is there a better way to communicate with the database and is there a better way to communicate with different database types?

To this particular question, I would say: no.  Relational databases still typically "talk" SQL as their primary language.  How you construct those SQL queries, however, does seem to be outdated.

To offer an alternative to the ORM answers (which are correct - ORMs are very popular, and often great for this), consider SQL Builders.  Essentially, these are classes which allow you to construct SQL queries in a way which is less open to mistakes, and are more natural.  Manual string concatenation is difficult to read, error prone, and often the source of security holes.

Edit:  Since you specifically mentioned C#, try Massive or (the somewhat limited) CommandBuilder.

Title: C# database communication technique


问:
ASP.NET MVC Controller separation best practices
I am very new in ASP.NET MVC and Web stuff. I want to know how I should separate my page logic into different controllers. Like for example should I use Home\BuyProduct or Product\Buy. When there is a sign to move logic to the new separate controller? Should it be one Controller per page? What is the basic rules?

答:
It sounds to me like you are still looking at it in terms of web forms. You have to change your thinking a little. Don't think of it as "controllers per page". There are no "pages", there are views. Controllers direct traffic. They take in input from the user and decide which view should bre presented. The models are your business logic...

How you set it up is a function of the site you are creating and a matter of personal preference. But, the most important thing is that you need to redirect your mind from web forms.


问:
Programming vs Planning
Recently, I have been tasked with more high-level planning assignments due to the lead developer of my team leaving. I hate long-term planning.  My brain just doesn't naturally seem wired for it, and I am not interested enough in it to spend the time to learn it (it is hard enough to keep up with the programming side of the picture).

Can one still be a good programmer without being a high-level planner, too?

As a senior programmer, is one expected to be good at planning out the entire product and picking a date of completion?

答:
Yes and No are your answers.

On the one hand, you're being nudged towards project management.  IMO, all good programmers have some degree of project management capability, but they are different skill sets.  The ability to plan for the long term improves your ability to communicate with the actual project management.  So "no" you can't be a good programmer without the ability to plan long term.

That having been said, project management is a different skill set that appeals to aspects that are related but different than programming.  So here's where the "yes" comes into play.  You don't have to be a project manager to be a great programmer.

For your specific situation, try to become more objective about what the company needs as well as what you enjoy doing.  There a bit too much ego reflected in your question and that's biasing your ability to look at this situation.  If you can find ways to contribute more to your employer while still doing the things you enjoy, then you should consider them and talk the matter over with your boss.

Title: Programming vs Planning


问:
How Facebook's Ad Bid System Works
When you are creating an ad on Facebook, you are provided with a "suggested bid" range (e.g., $0.90 - $2.15 USD). According to this page:

The suggested bid range is there to help you pick a maximum bid so your ad will be successful. It’s based on how many other advertisers are competing to show their ad to the same audience as you are.

I'm interested in understanding what's actually going on (technically) under the hood here.

Say a user logs into Facebook. On the server-side, it the HTTP request that the user's browser sent (as part of the login) is handled, and the server needs to figure out which ad to display back to the user.

I assume this is where the "bidding" system comes into play? Say that, based on this user's demographics, and based on the audience targeting that several competing advertisers designed their campaign with, let's pretend that Facebook sees a pool of 20 different ads it could return.

How does this bidding system help Facebook determine which of the 20 ads it returns to the client-side? I'm guessing that advertisers who "bid more" get prioritized over those who "bid less". But when does this bidding take place? How often does an advertiser need to re-bid? How long is a bid binding for?

Once I understand these usage-related concepts behind ads, it will probably be obvious between which of the following "selection strategies" the backend is using:

Round robin

Prioritized round robin

Randomized (doubtful)

History-based

MVP-based

Thanks to anyone who can help point me in the right direction and explain what these suggested bid systems are and how they work.

答:
This link doesn't directly answer your question, but it may point you in the right direction for additional search terms.  Facebook FBX

With re-selling, they'll have to move to a prioritized round-robin type approach filtered by indicators mined from cookies.  Otherwise I think they'll have a difficult time getting continued sales into the reseller market.

Title: How Facebook's Ad Bid System Works


答:
Is it possible to be a good programmer and not a high level planner?

Short Answer: Yes it is possible.

However, more you get experience with the type of projects that you are involved, the better planning ideas you will have. Ideally, as a programmer we have some approach how to solve the problem or we look for one. Thus, if we know the approach then we may start think about the planning :)

Another possible route is that a programmer who becomes a good planner is also eventually heads toward Project Management. Thus, if you have interest in management of projects you may put some extra effort toward that direction.

Title: Programming vs Planning

Body:
Recently, I have been tasked with more high-level planning assignments due to the lead developer of my team leaving. I hate long-term planning.  My brain just doesn't naturally seem wired for it, and I am not interested enough in it to spend the time to learn it (it is hard enough to keep up with the programming side of the picture).

Can one still be a good programmer without being a high-level planner, too?

As a senior programmer, is one expected to be good at planning out the entire product and picking a date of completion?


答:
As a fairly novice software developer myself(2 years of part-time work), what keeps me going is the long-term perspective.

Every new project I start, i have a better grasp on how to handle it smoothly. Each new language becomes less difficult. My solutions start feeling more complete.

Here's my list of what you should have to continue as a programmer:

You should like, and be able, to learn on your own. (i.e. work with books, forums, documentations, ...)

You should like to keep your thoughts organised - programming is a way of bringing thinking processes to paper(to computer).

You should have a sufficient resilience, when constantly dealing with a seemingly endless list of minute problems, that first need to be identified before they can be solved.

Other than that, I think there are many reasons to like programming, and the more you do it, the more you'll experience the joy of working in such a creative and non-repetitive field.

Edit: If you are having trouble with something, try to pin point exactly what the problem is, and then take it to one of the Stack-Exchange sites, if your question hasn't already been answered, you're bound to get a good reply. In the long run, it'll also be good for you to read some structured books about programming paradigms, software engineering, and algorithms. Most import though, keep writing code - and like most answers here suggest, find some time to work on programs unrelated to what you are already doing, even if it means you make up your own projects to work at from home.


答: Yes it is possible. However, if you want to be a good software engineer or software architect that is where your high level planning comes into play. To me, the main difference between a programmer and an engineer has been the ability to see the big picture.</p>

Title: Programming vs Planning


答:
ORMs only work with simple database structures. For the most part I guess this is OK. If like me you need to get more out of your database than just select/update etc then I have found ORMs are not a good fit and will make your code longer, less clear, more difficult to manage...

Also SQL scripts and sprocs are essentially database language and we should not be scared to mix languages when they are the best fit for the job at hand

Title: C# database communication technique


答:
Is it possible to be a good programmer and not a high level planner?

For a while, yes. Is it possible to do this for long? No.

With many employers nowadays it is standard operating procedure to give cost of living industry-competitive raises. If you don't improve yourself, don't try to tackle bigger and harder problems, those industry-competitive raises will price you out of the market in five or ten years. Keep this up and your employer will eventually start to look for a reason to get rid of you, and your employability elsewhere will be drastically diminished as well.

Title: Programming vs Planning


答:
Where was your background if you never programmed before this?  Most IT roles would have some opportunity to program something, if only a macro or script to automate some little piece of the puzzle.

You have a right to your emotions.  However, the better question is what are you doing about this frustration?  Are you figuring things out and moving forward?  What kind of feedback are you getting about the work you are doing?  If you are getting feedback that it is great then you may have unrealistic expectations of yourself.  On the other hand, if you are getting little to no feedback then I could understand having some fears.


答:
Sure, you can be a good programmer, from a programmer's point of view.  From management's point of view is a whole other question.  In my experience, being involved in the planning process is the best way to 1) get more interesting programming assignments and 2) get to do them the way you want.

In other words, once it gets down to short term planning, a lot of options are off the table.  If your preferred solution would take six weeks but they only budgeted two, you're stuck with what they decided.  If you have concerns about something they already discussed in long term planning, they're not going to want to rehash it.

If you're happy with that state of affairs, more power to you.  Most people grow less satisfied with that the more experience they get.

The dirty little secret is no one is very good at long term planning and estimation.  Better planners are the ones who are aware of their limitations, so believe it or not, you are ahead of the curve.  Get some training on accounting for uncertainty in estimation.  Look at techniques like evidence based scheduling or scrum, which rely on historical data to show how accurate your estimates are.  You will be happier in the long term if you have a larger say in your work.

Title: Programming vs Planning


答:
You've basically had no training and have been thrown on to a difficult project. Typically, people spend at least three years learning stuff before they even begin non-trivial projects. There's no embarassment, nor does it mean that programming isn't for you, if you're finding it too hard.

Even I struggled in my fourth week of programming :P


答:
I remember starting off with assembler on a Commodore VIC20.  At first, I just followed the instructions for hacks which were published in gaming magazines to give me infinite lives on Jet Set Willy or whatever is was I was trying to cheat at.  I had a curiosity and a yearning that led me to wanting to create my own hacks and understand how and why they worked.  This is turn led to me writing my first programs.

The point is that I was totally confused for quite a long time (not as long as 6 months but I agree that's probably a function of starting with 3D modelling) but then, the penny suddenly dropped.  I began to understand how the code I wrote translated into CPU instructions and memory references and soon, I could write quite competent assembler.  Of course, you are working 20 levels above the CPU now but, I am sure that if you have the aptitude, that light bulb moment will happen.

I guess I'm reiterating the points made re curiosity, learning and getting fizzed when you create something that is truly synergistic.

If can can give one piece of advice it's "persevere and learn the basics of object oriented programming".  Good luck.


问:
.NET developer needs FoxPro advice
We have a prospect with FoxPro 2.6 (whatever it means) system.

Our product integrates with other systems by the means of triggers (usually). We would place couple of triggers on X system and then just pull collected data for our use. This way there is no need to customize customers product and it works great(almost real time - we poll for changes every 30 seconds).

Question:

Can I put triggers on FoxPro 2.6?

Can access FoxPro from .NET?

Any catches/caveats?

答:
Can access FoxPro from .NET?

Yes, you can use the FoxPro OLE DB Driver provided by Microsoft, to connect to FoxPro through .NET. It may be done in C# the following way:

```<code>OleDbConnection oleDbConnection1 = new   OleDbConnection("Provider=VFPOLEDB.1;"+
   "Data Source=C:\\myVFPDatabase.DBC;");
oleDbConnection1.Open();
OleDbConnection oleDbConnection1 = new OleDbConnection();
oleDbConnection1.ConnectionString = "Provider=VFPOLEDB.1;" +
      "Data Source=C:\\myVFPDatabase.DBC;";
oleDbConnection1.Open();
</code>```

According to Microsoft, this works with at least Visual FoxPro 7. FoxPro 2.6 does not support DBC files, and as such you would have to access it the DBF way (according to programmer2programmer at least), such as :

```<code>"Provider=vfpoledb.1;Data Source=C:\MyDataDirectory\;Collating Sequence=general;"
</code>```

Note that the first link also mentions how to configure and test the connection in Visual Studio (if you are using it of course). As for your second question,

Can I put triggers on FoxPro 2.6?

Unfortunately, No, you can't create triggers in FoxPro 2.6 (thanks to user @Morons and the Internet)

Title: .NET developer needs FoxPro advice

Body:
Can access FoxPro from .NET?

Yes, you can use the FoxPro OLE DB Driver provided by Microsoft, to connect to FoxPro through .NET. It may be done in C# the following way:

OleDbConnection oleDbConnection1 = new   OleDbConnection("Provider=VFPOLEDB.1;"+
   "Data Source=C:\\myVFPDatabase.DBC;");
oleDbConnection1.Open();
OleDbConnection oleDbConnection1 = new OleDbConnection();
oleDbConnection1.ConnectionString = "Provider=VFPOLEDB.1;" +
      "Data Source=C:\\myVFPDatabase.DBC;";
oleDbConnection1.Open();

According to Microsoft, this works with at least Visual FoxPro 7. FoxPro 2.6 does not support DBC files, and as such you would have to access it the DBF way (according to programmer2programmer at least), such as :

"Provider=vfpoledb.1;Data Source=C:\MyDataDirectory\;Collating Sequence=general;"

Note that the first link also mentions how to configure and test the connection in Visual Studio (if you are using it of course). As for your second question,

Can I put triggers on FoxPro 2.6?

Unfortunately, No, you can't create triggers in FoxPro 2.6 (thanks to user @Morons and the Internet)


答:
There's a million ways to set up anything, but I will tell you that being new to MVC myself (but liking it so far), I typically do set up one Controller action "per page". I'm sure you can abstract this differently as you master MVC, but for my first app, there's a correlation between a single action in a controller and a single "page".

Regarding the structure around home||product||buy etc, I'm setting mine up like

Home Controller:

"http://root/" => home page

Products Controller:

"http://root/products" => listing of all products, or product categories.

"http://root/products/detail" => 404 error.

"http://root/products/detail/50" => details of a single product with ID 50.

"http://root/products/detail/50/add" => add that product to the cart

Cart Controller:

"http://root/shoppingcart" => show cart details for current user.

"http://root/shoppingcart/checkout" => show checkout details.

I'm trying to follow the "Fat ViewModel, Skinny Controller" pattern, so my controller actions are just a couple lines long each. They just initialize Fat ViewModels and execute 1-2 methods on each model depending on what needs to be done. The models contain the bulk of the code.

And widgets that need to get re-used are made into their own ViewModel and the parent ViewModel has a child member of that reusable ViewModel class. The reusable ViewModel gets a view created for it and put into the "Shared/EditorTemplates" folder. This view is called from the "EditorFor" helper thats put in the main ViewModel's view.

Title: ASP.NET MVC Controller separation best practices

Body: I am very new in ASP.NET MVC and Web stuff. I want to know how I should separate my page logic into different controllers. Like for example should I use Home\BuyProduct or Product\Buy. When there is a sign to move logic to the new separate controller? Should it be one Controller per page? What is the basic rules?


问:
Usage of repository between EF model and code consumer
I have binary data in my database that I'll have to convert to bitmap at some point. I was thinking whether or not it's appropriate to use a repository and do it there. My consumer, which is a presentation layer, will use this repository. For example:

// This is a class I created for modeling the item as is.
public class RealItem
{
    public string Name { get; set; }
    public Bitmap Image { get; set; }
}

public abstract class BaseRepository
{
    //using Unity (http://unity.codeplex.com) to inject the dependancy of entity context.
    [Dependency]
    public Context { get; set; }
}

public calss ItemRepository : BaseRepository
{
    public List<Items> Select()
    {
        IEnumerable<Items> items = from item in Context.Items select item;
        List<RealItem> lst = new List<RealItem>();
        foreach(itm in items)
        {
            MemoryStream stream = new MemoryStream(itm.Image);
            Bitmap image = (Bitmap)Image.FromStream(stream);
            RealItem ritem = new RealItem{ Name=item.Name, Image=image };
            lst.Add(ritem);
        }

        return lst;
    }
}
```

<p>Is this a correct way to use the repository pattern? I'm learning this pattern and I've seen a lot of examples online that are using a repository but when I looked at their source code... for example:</p>

<pre class="lang-cs prettyprint-override"><code>public IQueryable<object> Select
{
    return from q in base.Context select q;
}
</code>```

as you can see no behavior is added to the system by their approach, so I was confused that maybe repository is something else and I got it all wrong. At the end there should be extra benifits of using them right?

答:
That is exactly the value add that a Repository can give above and beyond the standard crud operations. However, I would take advantage of deferred operations. Instead of List, return IEnumerable (or even IQueryable which will allow the consumer to filter it even more) and instead of foreaching return the realitem from the selector like so

```<code>public IQueryable<RealItem> Select()
{
   return Context.Items.Select(item=>
   {
      Bitmap image;
      using(MemoryStream stream = new MemoryStream(item.Image))
      {
         image = (Bitmap)Image.FromStream(stream);
      }
      return new RealItem{Name=item.Name, Image=image};

   });
}
</code>```

The other option is like someone else mentioned, provide a second property on RealItem that does the conversion from bytearray to bitmap for you.

Body:
That is exactly the value add that a Repository can give above and beyond the standard crud operations. However, I would take advantage of deferred operations. Instead of List, return IEnumerable (or even IQueryable which will allow the consumer to filter it even more) and instead of foreaching return the realitem from the selector like so

public IQueryable<RealItem> Select()
{
   return Context.Items.Select(item=>
   {
      Bitmap image;
      using(MemoryStream stream = new MemoryStream(item.Image))
      {
         image = (Bitmap)Image.FromStream(stream);
      }
      return new RealItem{Name=item.Name, Image=image};

   });
}

The other option is like someone else mentioned, provide a second property on RealItem that does the conversion from bytearray to bitmap for you.


答:
My friend was a frequent flyer for many years, but he always wanted to be an airline pilot. One day he took an opportunity to fly Boeing 747. After about six months he felt like giving up: he thought he would be good at flying airplanes, but this experience of the last six months made him rethink his decision.

Of course I'm kidding: I do not have such a friend. And that's for a good reason: any airline would be crazy to let someone take the controls of a 747 before he spends a few years flying a Cessna, followed by a few years flying multi-engine planes, followed by a few years of flying jets, followed by a few months of extensive training on the 747.

The point of my made-up story is that even the simplest 3D modeling package would be software developer's equivalent of flying a 747. Many programmers would be intimidated by it, even after a decade or two in the industry. It is not surprising that you feel frustrated: you took on a wrong task for your current skill level!

What should you do? First, I would quit the 3D modeling shop, take an online or a real course in programming, and get yourself a pet project that you can work on in your spare time. After you're done with the course, try getting an entry-level position in a shop that produces business applications, mobile apps, or sophisticated web sites. Learn as much as you can at work, and practice at home to improve your skills even further. In a few years you will be able to come back to your 3D modeling company, and work there without a slightest bit of frustration.


问:
Is throwing an exception from a property bad form?
I've always been of the mindset that properties (ie, their set/get operations) should be fast/immediate and failure-free. You should never have to try/catch around getting or setting a property.

But I'm looking at some ways to apply role-based security on the properties of some objects. For instance an Employee.Salary property. Some of the solutions I've run across that others have tried (one in particular is the AOP example here) involve throwing an exception if the accessor doesn't have the right permissions - but this goes against a personal rule that I've had for a long time now.

So I ask: am I wrong? Have things changed? Has it been accepted that properties should be able to throw exceptions?

答:
I consider it to mostly be bad form but even Microsoft recommends using exceptions sometimes.
A good example is the abstract property Stream.Length. As guidelines go I would be more concerned with avoiding side effects on getters and limiting side effects on setters.</p>

ContentLicense: CC BY-SA 2.5


答:
Detailed long-term project plans are notorious for usually being wildly inaccurate. The functionality of the system will inevitably change before launch, and people usually spend a long time working out the specifics that go into the specification only to have stake-holders give it a cursory glance at best.

You should read more on Agile planning, you might find it fits in more with your mindset. Many Agile methodologies try to find ways to move away from detailed, long-term planning.

Agile methodologies try to minimise detailed technical specifications and documentation in favour of self-documenting code and isolated, atomic user stories and ultimately working software. In an efficient Agile team, there will be a minimum amount of time spent on planning.

Read the Agile Manifesto and look into Scrum. Use Iterative Development and Dynamic systems development method to guide the project.

The main downside with Agile approaches is that you have to admit openly that you don't know the exact scope of your project, and getting management buy-in to this idea can be extremely difficult, and usually takes a while. See this question and answer and this post for some tips on that.

However it is certainly true that as you get to be a more senior programmer you will probably do less coding, but I think that in an Agile team instead of meaning that you write more technical specifications, it would mean you spend more time managing and tutoring the members of your team and making architectural decisions about code.

Title: Programming vs Planning


问:
Are dynamic languages at disadvantage for agile development?
From what I've read agile development often involves refactoring or reverse engineering code into diagrams. Of course there is much more than that, but if we consider the practices that rely on these two methods, are dynamically typed languages at disadvantage?

It seem staticly-typed languages would make refactoring and reverse engineering much easier.

Is Refactoring or (automated) reverse engineering hard if not impossible in dynamically typed languages?
What does real world projects tell about usage of dynamically typed languages for agile methodology?

答:
Lest we forget, the "Agile" way of working which became known as Extreme Programming (XP) was created on a Smalltalk project (and Smalltalk certainly counts as a "dynamic" language).

Here's a case study of industrial use of a refactoring tool provided with a dynamically typed language:

A very large Smalltalk application was developed at Cargill to support
the operation of grain elevators and the associated commodity trading
activities. The Smalltalk client application has 385 windows and over
5,000 classes. About 2,000 classes in this application interacted with
an early (circa 1993) data access framework. The framework dynamically
performed a mapping of object attributes to data table columns.

Analysis showed that although dynamic look up consumed 40% of the
client execution time, it was unnecessary.

A new data layer interface
was developed that required the business class to provide the object
attribute to column mapping in an explicitly coded method. Testing
showed that this interface was orders of magnitude faster. The issue
was how to change the 2,100 business class users of the data layer.

A
large application under development cannot freeze code while a
transformation of an interface is constructed and tested. We had to
construct and test the transformations in a parallel branch of the
code repository from the main development stream. When the
transformation was fully tested, then it was applied to the main code
stream in a single operation.

Less than 35 bugs were found in the
17,100 changes. All of the bugs were quickly resolved in a three-week
period.

If the changes were done manually we estimate that it would
have taken 8,500 hours, compared with 235 hours to develop the
transformation rules.

The task was completed in 3% of the expected
time by using Rewrite Rules. This is an improvement by a factor of 36.

from “Transformation of an application data layer” Will Loew-Blosser OOPSLA 2002

Also -- "Tools for making impossible changes - experiences with a tool for transforming large Smalltalk programs"

ContentLicense: CC BY-SA 4.0


问:
Common header file for C++ and JavaScipt
I have an app that runs a C++ server backend and Javascript on the client.  I would like to define certain strings once only, for both pieces of code.  For example, I might have a CSS class "row-hover" - I want to define this class name in one place only in case I change it later.

Is there an easy way to include, or read, some sort of common definitions file into both C++ and JavaScript?  Ideally as a compile / preprocessing step but any neat approach good.

答:
I had proposed a quite similar approach here: https://stackoverflow.com/questions/4248831/shared-config-file-between-php-and-c/4248881#4248881 for a similar issue.

I would suggest to write a small script that generates code for C++ and  JavaScript, with the configuration you want to have common. You can also use two templates in a template library, that you will run as part of your build process that will generate the appropriate files for each language.

Using a freemarker-like syntax (although I do not suggest including another language!), there could be something like this for JavaScript:

```<code>commonStuff = { config1: ${value1},
config2: ${value2}
}
</code>```

and another template for the C++ implementation.

As suggested in the comments below, one good candidate for that, is to use sed, so that you would not have to introduce another language since your project has two already.

Body:
I had proposed a quite similar approach here: https://stackoverflow.com/questions/4248831/shared-config-file-between-php-and-c/4248881#4248881 for a similar issue.

I would suggest to write a small script that generates code for C++ and  JavaScript, with the configuration you want to have common. You can also use two templates in a template library, that you will run as part of your build process that will generate the appropriate files for each language.

Using a freemarker-like syntax (although I do not suggest including another language!), there could be something like this for JavaScript:

commonStuff = { config1: ${value1},
config2: ${value2}
}

and another template for the C++ implementation.

As suggested in the comments below, one good candidate for that, is to use sed, so that you would not have to introduce another language since your project has two already.


答:
What you're describing is what is commonly done with languages like JSP and PHP, injecting names defined on the server.  If you cannot use these languages, then I don't think it is worth the difficulty you're attempting simply to avoid having to change class names in more than one spot.  Granted, that is generally a best practice, but if it makes your code unnecessarily unreadable, you should avoid it like the plague.

C# is similar enough to C++ that the transition should be smooth, and C# has Asp support which allows you to define constants and drop them directly in the page.

However assuming that you don't want to switch language, my advice is to do the next best thing:  Have a C++ header and a css file which declare the same names.  If you need to change the names, you need only change in these two places, and you've lost little extra time in doing so.  Don't lose sight that simplicity is your objective, not avoiding duplication of code, and in this case, I can't possibly think that what you're attempting is the simplest solution.

Title: Common header file for C++ and JavaScipt

Body:
I have an app that runs a C++ server backend and Javascript on the client.  I would like to define certain strings once only, for both pieces of code.  For example, I might have a CSS class "row-hover" - I want to define this class name in one place only in case I change it later.

Is there an easy way to include, or read, some sort of common definitions file into both C++ and JavaScript?  Ideally as a compile / preprocessing step but any neat approach good.


问:
My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

答:
For accountability I wouldn't want a person to blame field,  I would want a Person who knows the code field or a person who can fix field, so that I would know where to send the support ticket.

This would speed up the process fixing the bug itself and give accountability, kind of like killing two birds with one stone. I would personally bring this up to him and let him decide if this would help to increase morale and accountability without making anyone feel like they failed.  Extreme testing doesn't catch all bugs, otherwise there wouldn't be bug reporting.


答:
Generate the javascript based on the definitions in the C++ file. If you already have a template system in place for the HTML, you can probably reuse that to interpolate C++ values into the javascript.

If server load or performance is an issue, consider caching the javascript (both on the server and on the client), or precompiling it altogether (it's a small step from a C++ program that serves dynamic javascript on-the-fly to one that saves it in a file instead).


问:
How does svn handle concurrent file updation
I understand that it is capable of managing concurrent users on same file, but how does it do that?

I am working on a file that another user is using concurrently and he committed couple of times before me, now my files don't have the changes he made. Every time I end up in such a situation I gets a conflict and I am stuck.

So is there something else I should do instead of just committing and causing conflict?

Is it safe to do a update first and then commit ? Will I lose my local changes in this case?

答:
You can (and should) update first before committing any changes. You will not lose any local changes when updating. If there are any conflicts, you will be informed and can deal with them by carefully merging your local changes with those in the repository.

For more information about TortoiseSVN, read the online documentation here.


问:
Ideal programming language learning sequence?
What do you think? What is the ideal programming language learning sequence which will cover most of the heavily used languages and paradigms today as well as help to grasp common programming basics, ideas and practices?
You can even suggest learning sequence for paradigms rather than languages.

N.B. : This is port of the question I asked in stackoverflow and was closed for being subjective and argumentative.

答:
Assembly Language, C, SQL, C#

I know, boring and old-skool. And the entire question ignores the really hard part of programming, which is problem-solving, domain modeling, and algorithm construction. But here's why:

you can't fake your way through assembly language; you either get it or you don't. the compiler won't save you, there's no framework or library overhead, and you can't hide from the machine architecture; it is pure programming (at the beginner add-two-numbers level)

after you've written a few assembly-language programs of more than a few hundred lines, pointers and memory management are no longer mysterious, and you should have started to notice patterns in the code (if, switch, array, loops, etc.). C brings those patterns out into the sunlight and lets them shine. The standard library is useful without being immense, but don't bother with macros/templates/etc. at this stage.

now jump into databases with SQL. Don't go overboard with stored procedures, just get the basics of tables and queries.

after you've written a few C programs of more than a few hundred lines, pointers, structures, and memory management are second nature, and procedural constructs are old friends. You will begin to notice higher-order patterns: these functions always go with this data structure, this part of the code is just like that part of the code except for methods X, Y, and Z, and so on. Add to this your grasp of relational data and now you're ready for an object-oriented language. With a massive framework and generally obtuse documentation. Welcome to the real world! Explore GUIs, write desktop apps, write web sites, write web services, write whatever you like. Go get a job if you're so inclined.

Are you now a programming Jedi? A code ninja? No, now you're merely competent. But you have a solid foundation to stand on to explore the shiny new fun stuff.


问:
Triggering Data Changes in N-Tier
I've been studying n-tier architectures as of late, particularly in VB.NET with Entity Framework and/or LINQ to SQL. I understand the basic concepts, but have been wondering about best practices in regard to triggering CRUD-type operations from user input/action. So, the arcitecture looks something like the following:

[presentation layer] -> [business layer] -> [data layer] -> (database)

Getting information from the database into the presentation layer is simple and abstracted. It's just a matter of instantiating a new object from the business layer, which in turn uses the data layer to get at the correct information. However, saving (updating and inserting), and deleting seem to require particular APIs on the relevant business objects. I have to assume this is standard practice, unless a business object will save itself on various operations (which seems inefficient), or on disposal (which seems like it just wouldn't work, or may be unwieldy and unreliable).

Should my "savable" business objects all implement a particular "ISavable" or "IDatabaseObject" interface? Is this a recognized (anti-)pattern? Are there other, better patterns I should be using that I'm just unaware of?

The TLDR question, I suppose, is How does the presentation layer trigger database changes?

答:
How does the presentation layer trigger database changes?

Well, presentation layer should not directly trigger changes in database layer. It should initiate call to the service layer, where your business logic should verify the request. Upon successful verification it should perform DB operation on entities/tables that it needs.

You may also look at this very useful pattern - Repository Pattern that may associate a behavior with the related data.

Title: Triggering Data Changes in N-Tier


问:
Schema.org vs microformats
They both serve the same purpose: Providing a vocabulary for semantic markup. Schema is recognized and standardized… but the microformats standard is by an open community process.

Schema exploits microdata in documentation, while microformats go on classes. (Of note: microdata means that an element must be of a single itemtype, while microformats allow several classes to apply to the same element. I can markup xFolk+hAtom with classes, but not with microdata.)

Is this a black-and-white situation? Google says I can't use both "because it may confuse the parser".

What's the consensus on these?

答:
There is no consensus on these.

Both can be used for Google, though Schema.org is the newer of the two and appears to be more comprehensive in my opinion.

It boils down to your needs for markup - use what is easier and more suitable to what you are doing.

Title: Schema.org vs microformats


答:
Your frustration is completely normal; it's likely that 3 weeks of training is deeply insufficient. You cannot know if programming is right for you by being thrown head-first into a difficult programming project with your paycheck on the line.

If you truly want to know if programming is "right for you", then learn a new programming language during your spare time, and do some hobby programming projects. If you enjoy this experience (the programming experience without deadlines and work pressures looming over your head) then programming is right for you.

Now... whether that particular programming job is right for you... I'd personally lean towards a no. Talk to your manager about your frustration, and consider getting a job that is either better suited to your current skillset, or that promises a better training program. I cannot know the details of your particular situation, but it seems to me that it was a disservice to both you and the company to hire you to that position without providing adequate training time; if they weren't planning on providing better training then they shouldn't have hired you. Still, the school of hard knocks is as good a school as any; again, the best course of action here is to talk with your manager and see how he or she assesses your current performance and responds to your frustration.


问:
Learning Java with a simple project
As i remember the time when i was learning PHP, it was suggested to build a simple blog or a forum after reading the language fundamentals. I was told/read that this would cover everything that I would need to learn about PHP from a beginners book.
This advice was out there in a number of places, and after following and working with PHP it seems quite good advice. </p>

<p>Now, i am learning Java and reading the book "Thinking in Java" by Bruce Eckel. I wonder if there is any such set of similar, small projects that I could take up, that would cover all the essentials and most of what is covered in the book. </p>

答:
Find a class syllabus for something like Data Structures in Java from a local community college.

Do the projects from the class like building a class grades tracking system or a simple ATM machine.

Title: Learning Java with a simple project


问:
What are the pros and cons for having a dedicated T-SQL developer on your team?
Our T-SQL developer just gave his two weeks notice. We have been asked if our team of four developers would like an additional developer.

We are offered to do our own T-SQL / Entitiy Framework development or we could get another dedicated T-SQL developer.

What are the pros and cons with having a dedicated T-SQL developer on the team?

Which would you prefer and why?

答:
Pros:

One less team member (less communication overhead)

Devs get do database work (yay! devs get to learn more)

Cons:

One less team member (not as many people to do the work)

Devs get do database work (even if they don't know it)

No dedicated resource to take care of the database infrastructure

No one who understands the workings of the database well

No one to take care of backups, maintenance and the other "boring" parts of the job

No one to warn devs of applications that will cripple the database

No one to warn devs of badly written SQL (that works now but will kill performance later)

I think you can figure out where I am going with this.

You need a DBA. These are people who take care that databases are running, running well and to requirements. People who will educate and teach the developers as to best practices and what to avoid.

If you don't get a dedicated DBA, one (or all) of you will have to take up the slack, working on things that are not directly development related.

Though my points are about DBAs (as that's what the title of the question was originally), except for the backups and maintenance points, the rest are valid for a T-SQL developer.

The assumption is that a T-SQL developer is a professional that understands how that database works and best practices etc...

If you use EF and don't have someone who understands how a database works, you can be in problems. If your team is proficient (understands indexing for example and when to apply them appropriately, understands how to optimize a query etc...) then you probably don't need a dedicated T-SQL developer.


答:
3D graphics programming is a niche that even most well established software developers would rather not get into. I do a lot of work with OpenGL and know this first-hand. Hopefully, all your work involves working with scenegraphs on a higher level, but if you are deep down in the guts of it like myself. For a new programmer, that's like a baby running...in a 100m sprint....with the likes of Usain Bolt...with the added pressure of people actually having realistic expectations that the baby will win the race.

However, miracles do happen, and all hope is not lost.

I trust you are doing this already, but not only do you have to do tutorials on programming (this is by far the smallest challenge), you need to read things about 3D fundamentals and coordinate systems. Understand the math involved in drawing polygons, translation, rotation (God help you if Quarternion), matrices, etc.

But seriously, are you sure you want to go ahead with this? What's more important to you? this job or a full set of hair?


答:
Which would you prefer and why?

It depends on my team skillset and the application. If the team has some SQL background, then they can make do. If the application doesn't have enough SQL work to keep 1 guy busy, then I maybe don't want a dedicated guy. If the SQL work is basic CRUD stuff, then I don't need a specialist for that.

And the opposites are true. If the team is SQL ignorant, or the app is SQL heavy, or the SQL is complex then maybe a specialist is the right way to go.

It's just like any other skillset on the team.

Title: What are the pros and cons for having a dedicated T-SQL developer on your team?

Body:
Our T-SQL developer just gave his two weeks notice. We have been asked if our team of four developers would like an additional developer.

We are offered to do our own T-SQL / Entitiy Framework development or we could get another dedicated T-SQL developer.

What are the pros and cons with having a dedicated T-SQL developer on the team?

Which would you prefer and why?


答:
If you have at least one person on your team already who can:

Use a database profiler to get accurate useful metrics

Analyze an execution plan and know how to affect said execution plan

Correctly name the tradeoffs between having indexes/not and the effects of adding/removing columns from said index.

Define a clustered index

Dictate from memory what normalized and denormalized structures are and what the levels of normalization are for.

You might already have another t-sql developer who can keep the team at least in line. My list isn't comprehensive but if those things are there he can probably keep you guys out of trouble.

If you don't have someone on your team who can do those things and your team does have their hands in the database, you need someone who can do those things. Unless you're completely unconcerned with the quality of the database (a valid stance if the system is tiny enough, read: under 15 tables perhaps.)


答:
What sort of application are you working on? Since you've had a database/T-SQL developer on your team previously, I assume that it's reasonably database-centric, but the answer to how the database is actually used by your application has an impact on whether a separate database developer is needed or helpful.

My initial reaction was "you want a T-SQL developer with database development experience on your team", but if the database is little more than a data store (little or no logic in the database layer), then perhaps you could make do without. Same if the database design is simple (meaning that to extract something useful you don't need umpteen million joins across dozens of tables), or if performance and scalability aren't great concerns in your case.

An obvious drawback of a separate database developer is the short-term cost of another developer who won't be contributing directly to the user-visible portions of the software.

Assuming that the application you are working on is reasonably database-centric, once the initial ramp-up period is taken care of, having a developer who can focus on the database aspects of the application can help quite a bit. You get someone who knows the ins and outs of set-based programming, can focus on what amount of data normalization in storage is useful in your particular case, and can hopefully help come up with or further the design of the database to provide good performance now and in the future.

Having an application developer also do database development doesn't necessarily have to be a bad thing, but there is an obvious risk that the developer in question will focus more on the needs on the application side than on what makes a good, scalable database design and then figure out how to expose that to the application layer in a way that provides the application with the data that it needs. This can lead to short-term results and long-term pain when the underlying design turns out to not be scalable. Of course it doesn't have to happen that way, but it's a risk well worth being aware of.

As for communications overhead (and particularly that causing delays), it doesn't have to happen that way. If the other developers on the team know a bit of T-SQL (it's not that hard picking up the basics like how to do selects, updates, joins, etc.), then they can certainly do prototyping in the database layer just to get the data that they need. Before the code goes to production (whatever that means in your environment), the database developer can either sign off on it saying that it's a good enough design, or take the input parameters, desired result and output result set design, and figure out a better way to perform the actual queries.


答: I think that having a dedicated t-sql person on a team that does EF is a luxury, unless her or him also helps out with the .NET side of the project. Most developers in micro-sized teams, such as yours, should be familiar with enough SQL design and tuning principles to bring your project to acceptable levels of performance. The problems that your four developers cannot address should be solvable through Stack Overflow and short-term consultants.</p>


答:
Short Answer: It will depend on the scope of the project and developers skill set.

For example: a Database First approach with EF may need a good T-SQL developer. Because a solid DB design with, indexes, stored procedures and functions might be very useful for targeted performance boost areas within application.

For a code first approach without any usage of complex stored procedures you may probably have NO need for a T-SQL developer.

In addition, if you have in your team a developer who has solid knowledge in DB design, index, query profiling, analysis of execution plan... then you have a right guy in a team to take care of all DB development that you may expect to have.


答:
Thinking that each OO (and really, Turing complete) language needs to be "learned" separately is a bad approach. Trust me, I've started like that as well, and then I rethought the whole approach. The idea here is to familiarize yourself with the basic notions common to all programming languages, like how variables works, how references and pointers work, what's up with functions/methods, and then with data structures, classes and objects.

Then look into basic good coding practices: OO principles (at least the major ones), various kinds of automated tests for your code, etc.

Use the language you're already most familiar with to explore all these. Once you have a good grasp of these basic concepts, familiarizing yourself with a new language will be a breeze.

Yes, of course, each language has it's specifics, like they might treat functions or objects of variables slightly different between themselves, but they have a lot more in common than they have discrepancies.

And don't fall into the trap of thinking that learning a certain language mostly comes down to knowing by heart the APIs of the major 3rd party libraries and frameworks created for than language. Especially frameworks. This is something that Java and JavaScript suffer from. It's not their fault, it's how some people think to best approach them. This is another pitfall I fell into at some point. I used to be more worried about what new tricks the latest Spring Framework version can do rather than thinking about how to improve my general coding. This is less of a problem for languages such as C and CPP.

Continuing on the last idea, Bruce Eckel's Thinking in XXX books are excellent. Finish the one about Java and try to code as many examples from it as possible yourself. Then try Thinking in C/CPP, followed by some books on unit and functional testing. Then go on to stuff about data structures and algorithms, this one's one of my favorites on the subject: http://www.amazon.fr/Data-Structures-Algorithms-Michael-Goodrich/dp/0470398809/ref=sr_1_1?ie=UTF8&qid=1348865961&sr=8-1

Title: Learning Java with a simple project

Body:
As i remember the time when i was learning PHP, it was suggested to build a simple blog or a forum after reading the language fundamentals. I was told/read that this would cover everything that I would need to learn about PHP from a beginners book.
This advice was out there in a number of places, and after following and working with PHP it seems quite good advice. </p>

<p>Now, i am learning Java and reading the book "Thinking in Java" by Bruce Eckel. I wonder if there is any such set of similar, small projects that I could take up, that would cover all the essentials and most of what is covered in the book. </p>


答:
Short Answer: Learn the language while building your practical Android application.

That is right, it is better jump straight to the blog that is a cool jump-start : Learn Java for Android Development: Introduction to Java.

However, having a good understanding of data structures and algorithms in Java is also an important corner-stone which i definitely recommend to learn. A good recommended book for that is - Data Structures and Algorithms Using Java.

Title: Learning Java with a simple project


问:
From where is a DES key generated?
GOing over a lecture on DES

I got most of it except WHERE DOES DES KEY COME FROM?

Does an authority give you the key or what?

Simple language please

答:
The simple answer is that the key is and must be picked at random. You grab a bunch of bits from wherever, and hope that they are random enough to resist attacks on the key generation algorithm. (It's worth noting that many real-world attacks on cryptographic software have focused on the particulars of the key generation, rather than the cryptographic algorithm itself.) There is no central authority involved; in fact, having such a central authority would largely defeat the whole purpose of encryption (which is to transform a large secret - the plaintext - into a small secret - the encryption, or more accurately the decryption, key).

DES is a symmetric encryption algorithm, which means that to decrypt the data you must have the same key that was used to encrypt it. That leads to key distribution problems, but it's much easier to securely distribute and store a small key than a large plaintext, and keys can be distributed ahead of time provided that you can store them securely.

Asymmetric, or public/private key, algorithms solve the key distribution problem by using different keys for encryption and decryption - the mathematics that makes that possible is rather involved and varies between algorithms, but the general approach is that the encryption and decryption keys have nontrivial mathematical relationships - but have other issues of their own. Security is always a trade-off between different considerations. The most well-known such algorithm is probably RSA.

The only provably secure encryption algorithm is a properly used OTP (one-time pad), but that requires a properly random key the length of the message to be encrypted and the key must never be re-used, so is not very useful in practice for anything beyond short messages between parties who already have some sort of secure communications channel that just isn't "good enough" for sending the messages involved. For example, a trusted courier might be used to distribute key material; the courier is slow, whereas the OTP-encrypted message can be transmitted over a satellite link or Internet e-mail with no risk of being understood if it is intercepted, as long as the key can be trusted to be secure.

Specific usage scenarios might involve a central key distribution facility of some kind even for symmetric-key encryption algorithms, but I really think that those are truly the exception in that case.

Also, like @delnan touched at, what other encryption algorithms are you familiar with? It's worth keeping in mind that DES is trivially easy to break these days, even with consumer-class hardware and a naïve brute-force attack on the key.

Title: From where is a DES key generated?


答:
The cryptographic key is just a series of bits.

At the simplest level, the key is generated from a hashed version of a password.  The key (ie the specific series of bits) must be re-creatable otherwise you will not be able to decrypt the encrypted object.

Technically, you could just use the password without hashing for the key, but it makes me shudder to think of doing it that way.  NOT secure.

DES has some funkiness with its key length being either 56 bits or 48 bits.  I don't know of any other ciphers with a similar key length characteristic, so I would ignore that aspect.  The 48 bit key is not just a subset of a 56 bit key, they're different.

DES has nothing to do with public / private key pairs.  DES is a symmetric encryption algorithm, whereas public / private keys indicates an asymmetric algorithm.

Title: From where is a DES key generated?

Body:
GOing over a lecture on DES

I got most of it except WHERE DOES DES KEY COME FROM?

Does an authority give you the key or what?

Simple language please


问:
Reasons for Pair Programming
I've worked in a few shops where management has passed the idea of pair programming either to me or another manager/developer, and I can't get behind it at all.  From a developer stand-point I can't find a reason why moving to this coding style would be beneficial, nor as a manager of a small team have I seen any benefit.

I understand that it helps on basic syntax errors and can be helpful if you need to hash something out, but managers that are out of the programming loop seem to keep seeing it as a way of keeping their designers from going to Facebook or Reddit than as a design tool.

As someone close to the development floor that apparently can't quite understand from a book tossed my way or a wiki page on the subject... from a high level management position, what are the benefits of Pair Programming when dealing with Scrum or Agile environments?

答:
Partly, it depends on how you are doing pair programming. In some instances, the driver of the pair is writing code, while the second member of the pair is observing and discussing the design and implementation details of the system. Another instance of pair programming involves both people writing code simultaneously - one person is writing the implemented functionality and the other is actively developing and writing test code at the unit and integration level, again discussing the design and implementation details of the system.

Regardless of the type of pair programming, it effectively serves as a continuous code review. You have two people's eyes on the code, watching for errors before they escape into a later system/acceptance testing environment or the field. You also have two people who understand a particular part of the system very well, to serve as a redundancy to minimize your bus factor. Both catching defects early and spreading system knowledge around the team reduces the cost of building a system.

The spreading of knowledge isn't just limited to the technical knowledge of the team, either. Depending on who the pair is, it can allow for information to flow between a more senior member of the company to a new member about other things that transcend the project - coding style, company culture, expectations, and so on. It can also allow someone who is more familiar with a technology or tool to share their knowledge in that technology or tool in a real-world applied setting.

As you mentioned, it also does help keep developers focused and in flow. In addition to flow, many individuals are less likely to interrupt multiple people working on something than a single individual working on something. If you walk by someone's desk and they are working alone, but you need to talk to them, you might knock and talk to them. This is less likely if you see two or more people collaboratively working or having a discussion - you won't interrupt them. Interruptions cost time, and spending more time means higher costs. It's in the best interests of the business to maximize productivity of the employees.

However, there are some challenges that must be overcome to make pair programming viable. Consider things like personality clashes or choosing the pairs to properly distribute the knowledge. There's also consideration of exactly when to rotate pairs. Pair programming done haphazardly probably won't be effective as one that's planned out. Depending on the makeup of your team, it might not be effective to pair people at all.

Title: Reasons for Pair Programming


答:
There are a few benefits for pair programming:

The two programmers are able to collaborate on the design together, potentially producing better architecture/code - two pairs of eyes can spot mistakes

Institution knowledge is preserved better - if one programmer leaves or is unavailable, the other should be able to continue the work without much loss of productivity

It's one way to quickly train new developers - pair them up with an experienced member of the development team and they'll be able to experience the code base from the perspective of a veteran of the team

Better discipline - the paired programmers are likely be productive over a longer period of time, since one or the other can take over for bursts of activity. Potentially tedious tasks, like unit testing, might be skipped less frequently than for solo developers.

Wikipedia also has a nice summary of the costs and benefits in the wiki entry.

Title: Reasons for Pair Programming

Body:
I've worked in a few shops where management has passed the idea of pair programming either to me or another manager/developer, and I can't get behind it at all.  From a developer stand-point I can't find a reason why moving to this coding style would be beneficial, nor as a manager of a small team have I seen any benefit.

I understand that it helps on basic syntax errors and can be helpful if you need to hash something out, but managers that are out of the programming loop seem to keep seeing it as a way of keeping their designers from going to Facebook or Reddit than as a design tool.

As someone close to the development floor that apparently can't quite understand from a book tossed my way or a wiki page on the subject... from a high level management position, what are the benefits of Pair Programming when dealing with Scrum or Agile environments?


问:
Besides macros, are there any other metaprogramming techniques?

Possible Duplicate:

  Programming languages with a Lisp-like syntax extension mechanism

I'm making a programming language, and, having spent some time in Lisp/Scheme, I feel that my language should be malleable.  Should I use macros, or is there something else I might/should use?  Is malleable syntax even a good idea?  Is it perhaps too powerful a concept?

In doing some research, I found fexprs.  I don't really understand what these are.  Help with that in an answer too please.

Is it possible to have a language with macros/something-of-a-similar-nature without having s-expressions?

答:
As I don't know exactly what you mean by malleable, for the purpose of this question I will take it to mean a language that can be extended.

While I do understand the concept of LISP macros, and how it extends the language, the language that I most associate with this ability is PROLOG.

PROLOG has the ability to define new clauses and add them to its knowledge base by using the assert command. Clauses can also be removed by the retract command.

Stepping further away from the PROLOG where the concept is built into the language and into languages where the dynamic runtime code can be modified with Meta programming or reflection, then we find languages such as Java and C#.

In my view if you are designing a new language and what to give it malleability, then start with the way PROLOG does it naturally in the language and build from there. Languages that use other means to achieve malleability in my view are treating it like an afterthought and it shows.

As an example, take a look at Mercury. This is functional/logic language that is malleable and yet is more than just PROLOG.


问:
is Java free for mobile development?
Q1. I would like to know if it's free for a developer (I mean, if I have to pay no royalties to Sun/Oracle) to develop (Android) mobile apps in Java?

After reading this snippet about use of Java field, I'm getting the impression that Java is not free for mobile development, is that right?

.."General Purpose Desktop Computers and Servers" means computers, including desktop and laptop computers, or servers, used for general computing functions under end user control (such as but not specifically limited to email, general purpose Internet browsing, and office suite productivity tools). The use of Software in systems and solutions that provide dedicated functionality (other than as mentioned above) or designed for use in embedded or function-specific software applications, for example but not limited to: Software embedded in or bundled with industrial control systems, wireless mobile telephones, wireless handheld devices, netbooks, kiosks, TV/STB, Blu-ray Disc devices, telematics and network control switching equipment, printers and storage management systems, and other related systems are excluded from this definition and not licensed under this Agreement...

and from http://www.excelsiorjet.com/embedded/

Notice : The Java SE Embedded technology license currently prohibits the use of Java SE in cell phones.

Q2. how come these plethora of Android Java developers aren't paying Sun/Oracle a dime?

答:
Your reading of the Java license snippet you quote is wrong not only in that it doesn't apply to Android (as explained in another answer).

As an application developer, you don't have to pay Sun/Oracle anything when developing applications for whatever device that has Java installed (here, I am talking about "official" Java, not Android). The license snippet you quoted covers / protects another thing, namely installation of Java runtime at this device.

You probably already noticed how you freely install Java runtime (JDK / JRE) to desktop computers, notebooks, servers, did you? That's legal and official and that is compliant with the license you quoted.

But, if you would want to do the same to any other device, this would not be free - you'd have to pay / negotiate with Oracle for permission to do this.

In that sense, it would be easier to think about mobile Java development like you think about development for Windows. Microsoft won't charge you for developing applications for Windows. But you are not allowed to freely install Windows OS.

Similarly, Oracle won't charge you for developing mobile applications. But you are not allowed to freely install Java runtime at mobile.

Title: is Java free for mobile development?


问:
How to handle this unfortunately non hypothetical situation with end-users?
I work in a medium sized company but with a very small IT force.

Last year (2011), I wrote an application that is very popular with a large group of end-users.  We hit a deadline at the end of last year and some functionality (I will call funcA from now on) was not added into the application that was wanted at the very end.  So, this application has been running in live/production since the end of 2011, I might add without issue.

Yesterday, a whole group of end-users started complaining that funcA that was never in the application is no longer working.  Our priority at this company is that if an application is broken it must be fixed first prior to prioritized projects.

I have compared code and queries and there is no difference since 2011, which is proofA.  I then was able to get one of the end-users to admit that it never worked proofB, but since then that end-user has went back and said that it was working previously... I believe the horde of end-users has assimilated her.  I have also reviewed my notes for this project which has requirements and daily updates regarding the project which specifically states, "funcA not achieved due to time constraints", proofC.

I have spoken with many of them and I can see where they could be confused as they are very far from a programming background, but I also know they are intelligent enough to act in a group in order to bypass project prioritization orders in order to get functionality that they want to make their job easier.

The worst part is is that now group think is setting in and my boss and the head of IT is actually starting to believe them, even though there is no code or query changes.  As far as reviewing the state of the logic it is very cut and dry to the point of if 1 = 1, funcA will not work.

So, this is the end of the description of my scenario, but I am trying not to get severally dinged on my performance metrics due to this which would essentially have me moved to fixing a production problem that doesn't exist that will probably take over 1 month.

答:
Disputes about easily-observable facts are actually quite easy to resolve: just observe the facts.  If I say "there's a tree with purple wood outside my house," anyone able to come to my house can verify the truth or falsehood of my statement for themselves.

If they're complaining that FuncA used to be in the product and used to work in an earlier version and now it's not working, and you don't think it was ever in the product, ask them to prove it.  (Or, in more gentle words, say something like "we're having trouble reproducing the problem. Could you help us out here?")

Give them a copy of the earlier version if they don't still have one, and get them in a LiveMeeting, and have them show you how they used to use FuncA.  If they can't do it, then (hopefully) they're realize that it wasn't in there afterall and get off your case about it, or at least try a different tactic to get it implemented.  (And make sure to get someone from management or PM in on the LiveMeeting.)