问:
What to do when the programming activity becomes a problem?
I once saw a program (can't remember which) where it talked about people "experiencing flow" when they are doing something they are passionate about. When "in flow", they tend to lose track of time and surrounding, concentrating only on their activity at hand.

This happens a lot for me when I program; most particularly when I face a problem. I refuse to give up until it's solved. This usually leads to hours just rushing by and I forget to eat lunch, dinner gets pushed into far into the evening, and when I finally look at the clock, it's way into the wee-hours of the night and I will only get a few hours of sleep before having to rise early in the morning. (This is not to say that I'm in flow only when facing a problem - but I find it particularly hard to stop programming and step back when there's something I can't solve immediately.)

I love programming, but I hate it when it disrupts my normal routines (most importantly eating and sleeping patterns). And sitting still for so many hours, staring a screen, is not healthy.

Please, any ideas on how I can get my rampant programming activity under control?

答:
Train yourself to end at a specific time, and stick to it. Eg If you need to leave at 5pm, have an alarm that goes off at 4, 4:30, 4:45, and 4:55 warning you to just put it down and continue the next day.

The hard part of course is training yourself to do this. This mainly requires self discipline, but can also be helped by splitting up your work into units. The advantage of units is that you can complete a task quicker and get that satisfaction of completion earlier, which might give you enough sense to listen to that alarm going off. It will be tough, but its something that you've got to do.

ContentLicense: CC BY-SA 2.5


问:
Does defining the stopping point of a genetic algorithm defeat the purpose of the algorithm?
Wikipedia defines the termination point of a GA to this:

Commonly, the algorithm terminates when either a maximum number of
  generations has been produced, or a satisfactory fitness level has
  been reached for the population. If the algorithm has terminated due
  to a maximum number of generations, a satisfactory solution may or may
  not have been reached.

Now, if it terminates when a satisfactory fitness level has been reached, and you are the one defining that fitness level, why wouldn't you just be able to create the "perfect" genome from the beginning yourself, since you already know the characteristics of this perfect genome?

I guess I'm just a little confused here. I thought the purpose of a GA was to constantly evolve and show us possibly an even better solution than what we thought of, and our fitness function was just something that helped it along the way, not something we put on the pedestal as the termination "perfect" state. Doesn't that destroy the point?

答:
The fitness function evaluates the output of your algorithm.  It's quite possible to recognize an ideal output when you see it, but not know the steps to produce that output from any given input.  That's where genetic algorithms are most useful.

For example, one common fun application of GA is in producing an animation that can move a virtual creature in an efficient way.  It's easy to tell if the creature is moving at a certain speed in a relatively straight line.  That's your fitness function.  It's much more difficult to tell the exact sequence of "muscle" movements to get it to do so.

ContentLicense: CC BY-SA 3.0


答:
The entire point of the GA is to give you the solution to the problem that has that fitness level. This solution would be very hard to find using other more conventional search algorithms, which is usually why you're using a GA in the first place.

Or instead of a fitness value limit, you could decide how many generations you want to run (the more generations you run, the higher chance you have of finding ever higher fitness values). For example, in the traveling salesman problem, getting a path that has the lowest cost between the cities you need to traverse.

Whether your stopping condition is a certain fitness level that is acceptable or a certain time constraint (running the GA for a maximum time period or a limited number of generations for time-critical applications such as pathfinding or AI applications) is determined usually by your problem domain.

Title: Does defining the stopping point of a genetic algorithm defeat the purpose of the algorithm?

Body:
Wikipedia defines the termination point of a GA to this:

Commonly, the algorithm terminates when either a maximum number of
  generations has been produced, or a satisfactory fitness level has
  been reached for the population. If the algorithm has terminated due
  to a maximum number of generations, a satisfactory solution may or may
  not have been reached.

Now, if it terminates when a satisfactory fitness level has been reached, and you are the one defining that fitness level, why wouldn't you just be able to create the "perfect" genome from the beginning yourself, since you already know the characteristics of this perfect genome?

I guess I'm just a little confused here. I thought the purpose of a GA was to constantly evolve and show us possibly an even better solution than what we thought of, and our fitness function was just something that helped it along the way, not something we put on the pedestal as the termination "perfect" state. Doesn't that destroy the point?


问:
Importance of hobby projects
I want to know, how important is it to program in your spare time? Is it necessary to work your 9-5 as a programmer and then get home and work on your hobby to become a better programmer?

This said, I know you only get better at programming by, well, programming.

Do prospective employers take hobby programming into account in an interview or do they ask this just out of curiosity?

I feel guilty for not having a hobby project, but everything I can think of doing has already been done. So I am kind of in two minds about this, start something that has already been done or leave it until I come up with something original?

答: The programmers I meet who have a hard time keeping up to date with new technologies are the guys who treat it as a job. Their counterparts - the ones who do keep up with the new stuff are the ones who make things at home.

Title: Importance of hobby projects


问:
MonoTouch/MonoDroid + C# = trustable?

Possible Duplicates:

  MonoTouch vs Objective-C for iPhone/iPod/iPad development

  As a C# developer, would you learn Java to develop for Android or use MonoDroid instead?

I'm very curious about the tools named MonoTouch and MonoDroid to create applications for Android, iPhone and iPod by using c# code.

Question:

Are these tools good enough to create applications that will be used in different environments?

Can these tools replace the orgininal way of creating application? If you create an application for Android, you often use Java to create it.

How different is it to create a application with Mono for Android compare to creating an application for Windows Mobile Phone?

答:
Are these tools good enough to create applications that will be used
  in different environments?

Not different environments. Monodroid costs 400 USD just for android apps. Monotouch 400 USD just for iOS apps. (And in the case of iOS you also need to buy an iOS developer license (another 100 USD per year). So both are very environment specific.

Can these tools replace the orgininal way of creating application? How different is it to create a application with Mono for Android compare to creating an application for Windows Mobile Phone?

No. They are primarily bindings. So, for example, in the case of monotouch you'll get iOS bindings for say Core API's. Instead of use NSString you'll use "c#" string. And so on.

So, they are not the same as creating directly a windows phone app (different platform and different API) what miguel and its team does is create a shareable .NET base between all of them, so you can reutilize your existing code.

It's trustable?

Well, I think it is. Mono isn't recent, nor mono touch or droid. Plus, they're now not a Novell division but an entire company (Xamarin). So I don't see why not can be trustable. We have use its tools since a few years and are great.

BUT

I'll advice you that if you want to start fresh with a platform, just use its API's directly. If you're doing android development, use Java and Android's SDK. both for iOS. Why? Well, isn't the same thing. When you're working with bindings you are relegated until those bindings are fully implemented. For example, if new iOS 5 SDK exposes 4000 new APIS (as frequently happens) you need to wait until there respective bindings are implemented (by Xamarin team). I see that as inventing and reinventing.

¿Why does this tools exists?

I think that basically for legacy support. At least that's the reason we (as a company) uses them. We have clients with large code bases that we can't implement again (.NET code base), so with monotouch we can port pretty much of it.

Sure, they're great for other things but thats my opinion.

Title: MonoTouch/MonoDroid + C# = trustable?


答:
It is trustable now that Xamarin acquired the rights for all of Mono and MonoTouch, before that users (developers) were in a pretty bad position, but now it's all clear

These tools are much better than the native alternatives (Objective-C and Java), yes, they can absolutely replace the original way of creating the application, not only that, they do a much better job than the original language, plus you get to use a single language to write apps for all platforms

It is very different to create an app for Android vs WP7 or iPhone, they are very different platforms, the only code you can share is the logic, so make sure to keep that well separate from the presentation layer, which you'll have to write for each different platform that you want to support

Title: MonoTouch/MonoDroid + C# = trustable?

Body:
Possible Duplicates:

  MonoTouch vs Objective-C for iPhone/iPod/iPad development

  As a C# developer, would you learn Java to develop for Android or use MonoDroid instead?

I'm very curious about the tools named MonoTouch and MonoDroid to create applications for Android, iPhone and iPod by using c# code.

Question:

Are these tools good enough to create applications that will be used in different environments?

Can these tools replace the orgininal way of creating application? If you create an application for Android, you often use Java to create it.

How different is it to create a application with Mono for Android compare to creating an application for Windows Mobile Phone?


问:
PHP Open Source Tools for Agile Development
Hello Everyone,

There are so many Questions on Stackoverflow about Agile tools, but I haven't seen a tool which can be installed on a PHP Server.

I'm just looking for an Open Source Scrum Tool or just an Open Source Scrum Dashboard for my Team, which can be installed on my webspace(php).

Thank you for Help!

答: Not sure if you can store it on your web space, but if you have your own server CollabNet is giving away a free 5 user license of ScrumWorks Pro!.</p>

OwnerDisplayName: trouble


答: They are trustable, but you have to keep in mind that they are not cross-compilable. You can't just write a monoTouch app and compile it for Android. You could reuse code (if it's written in a loosely-coupled manner), but that's a bit different.</p>

Title: MonoTouch/MonoDroid + C# = trustable?


问:
Should a poll framework be closed sourced
I was having a chat with a coworker who is working on a polling app and framework. He was asking technical questions and I suggested he open source the application to get more quality opinions from developers who are interested in this problem and are willing to give it heavy though.

He has a different point of view which I think is still valid so I want to open this question for discussion here. He says he believes something like a polling framework should not be open sourced because it will reduce its security and validity as people reveal loopholes through which they can cheat. Can't say I completely disagree. I see a somewhat valid point there, but I always believed that solutions by a group of people are almost always better than a solution thought by a single person asking a small number of coworkers, no matter how smart that person is. Again I'm willing to accept that maybe some types of applications are different.

Does anyone have an argument in his favor? I'd really like to present your responses to him.

答:
Have a read through Will Open Sourcing Stack Overflow Destroy Our Business Model? - while Stack Overflow isn't the same as your poll framework it should give you more insight into many other people's views.

Couple of thoughts that occured to me that I don't know the answer to myself...

Just because someone submits code to the project, it might not be good enough/accepted/used. Open-source doesn't automatically make the code better.

Similarly, I don't know what the average take-up is for developers helping out with the code. There may not be hordes of developers contributing to the source? (although you only need 1 or 2 to make a substantial difference).

I guess there is also nothing stopping you from open-sourcing the framework, but you run a customised version for your business that has other features/security built in.

Can your business remain anonymous/not advertise that it is behind the framework? And where the framework is installed/live - disguise that it is a particular framework? (Consider wordpress and how one of the security recommendations is to hide the meta tag that says "Wordpress version 2.3").

You also need to talk to your boss/legal department because your employment contract might say something to the effect that the intellectual property of anything that you create at work is owned by your employer, and open-sourcing some code that originated in the company could land you in hot water.


问:
Is micro-optimisation important when coding?
I recently asked a question on Stack Overflow to find out why isset() was faster than strlen() in PHP. This raised questions around the importance of readable code and whether performance improvements of micro-seconds in code were worth even considering.

My father is a retired programmer, and I showed him the responses. He was absolutely certain that if a coder does not consider performance in their code even at the micro level, they are not good programmers.

I'm not so sure - perhaps the increase in computing power means we no longer have to consider these kind of micro-performance improvements? Perhaps this kind of considering is up to the people who write the actual language code? (of PHP in the above case).

The environmental factors could be important - the Internet consumes 10% of the world's energy. I wonder how wasteful a few micro-seconds of code is when replicated trillions of times on millions of websites?

I'd like to know answers preferably based on facts about programming.

Is micro-optimisation important when coding?

My personal summary of 25 answers, thanks to all.

Sometimes we need to really worry about micro-optimisations, but only in very rare circumstances. Reliability and readability are far more important in the majority of cases. However, considering micro-optimisation from time to time doesn't hurt. A basic understanding can help us not to make obvious bad choices when coding such as

```<code>if (expensiveFunction() || counter < X)
</code>```

Should be

```<code>if (counter < X || expensiveFunction())
</code>```

(Example from @zidarsk8) This could be an inexpensive function and therefore changing the code would be micro-optimisation. But, with a basic understanding, you would not have to, because you would write it correctly in the first place.

答:
It is not important to micro optimize while writing the code. Optimization should be done with the help of a profiler, optimizing the code where it matters.

HOWEVER, a programmer should try to avoid doing obviously stupid things while writing the code.

For example, don't do repeated expensive operations inside a loop. Store the value in a variable outside the loop and use that. Don't do things like string comparisons or regex over and over again in an often called function, when you can go up a level, do the comparison and make it into an integer or a function reference or a derived class.

These things are easy for an experienced programmer to remember and almost always improve the code quality.


问:
How to flag a class as under development in Java
I'm working on a internship project, but I have to leave before I can finish up everything.

I have 1 class that is not stable enough for production use. I want to mark/flag this class so that other people will not accidentally use it in production. I have already put the notice in Javadoc, but that doesn't seem enough. Some compiler error or warning would be better.

The code is organized like this:

```<code>[Package] | company.foo.bar.myproject
          |-- Class1.java
          |-- Class2.java
          |-- Class3.java <--(not stable)
</code>```

If there was a single factory class that calls those classes in public methods, I could have set the method to class3 as private. However the API is NOT exposed that way. Users will directly use those class, e.g. new Class1();, but I can't make a top-level class private. What's the best practice to deal with this situation?

答:
I do not know such compiler warning.

In your situation I would probably use the @Deprecated annotation. It will cross out method calls so it will be obvious to the others that something is up. When they look at whats up, they will see your comments about 'not production ready' and go AHA.


答: I've been looking into Scrum/Agile recently too. www.planbox.com is an excellent online Agile project management tool. It isn't installable on your own server as far as I know but its definitely worth a mention here. Contact them and they'll show you around the app in a Webinar</p>

Title: PHP Open Source Tools for Agile Development

Body:
Hello Everyone,

There are so many Questions on Stackoverflow about Agile tools, but I haven't seen a tool which can be installed on a PHP Server.

I'm just looking for an Open Source Scrum Tool or just an Open Source Scrum Dashboard for my Team, which can be installed on my webspace(php).

Thank you for Help!


答:
Could you move all the incomplete classes into a subpackage named something obvious like "NOTCOMPLETE"? It's a bit of a hack but might be visible enough.

(If they are not all in the same package, you could recreate the package structure under there.)

Title: How to flag a class as under development in Java

Body:
I'm working on a internship project, but I have to leave before I can finish up everything.

I have 1 class that is not stable enough for production use. I want to mark/flag this class so that other people will not accidentally use it in production. I have already put the notice in Javadoc, but that doesn't seem enough. Some compiler error or warning would be better.

The code is organized like this:

```<code>[Package] | company.foo.bar.myproject
          |-- Class1.java
          |-- Class2.java
          |-- Class3.java <--(not stable)
</code>```

If there was a single factory class that calls those classes in public methods, I could have set the method to class3 as private. However the API is NOT exposed that way. Users will directly use those class, e.g. new Class1();, but I can't make a top-level class private. What's the best practice to deal with this situation?


问:
What is a good code practice of when to make a function/method for small repetitive code segments?
Many times throughout writing larger programs I have questioned after how many copy and pastes does it make sense to put the code into a function or method and what is a good rule of thumb?
I have been using a rule of thumb of four lines or greater and appearing more then twice, then I make a simple function / method containing that code.
Can you think of a better practice or offer any pointers?
This is more of a general design pattern question rather then a language specific question.</p>

答: A search for "refactoring" will lead you to many resources for industry "best practices" for this very common process.  The somewhat famous article, Once and Only Once is a great historical reference explaining what some view as "best practices" for the concerns raised by your question.  Also, the even more general concept is known as Don't Repeat Yourself (DRY).  For a really in-depth set of answers to your question, read Martin Fowler's great classic, Refactoring: Improving the Design of Existing Code, which covers some of the best known advice for refactoring, which is what you are intuitively trying to accomplish!

OwnerDisplayName: Nirma


答:
I don't think there is a standard way of marking code as WIP, Incomplete, or something like that.

You could create a new exception named ClassUnstableException and then raise it in the Class3 constructor with a message that explains how they shouldn't use it. This is bad though, because it only warns them at run time.

You could also try making the class incompilable in some way, and then add a note to the section of code that trips the compiler so that if someone goes to fix the code they will hopefully see an explanation of why they shouldn't use that class. This may not work if they use some semi-automated "fix this problem" tool that some IDEs have. This is also bad because it could break builds.

You could create an annotation named WIP (since the closest I can think of is Deprecated but it doesn't really mean the same thing) and use it to annotate the class. This would probably be a bit more work, and what would support the annotation?

Finally, you could just put it in the comments, but that will only work if people actually read them.

EDIT:

This may be relevant: How to intentionally cause a custom java compiler warning message?


答: Why not just check all the unstable classes into a different branch on your version control system?</p>


答:
If you have properly commented the class you could mark the bits of incomplete functionality as "deprecated" and or comment out the guts of the method and put a throw new UnsupportedOperationException();.

See Is there anything like .NET's NotImplementedException in Java? for details.


问:
Do programmers need to know about graphic designing?
I want to know your opinion. Do programmers (like me) need to know about design? For example drawing, web design, image manipulation etc.

```<code>Edited
</code>```

Actually, I like web, enterprise and mobile programming.

Thanks :D

答: What do programmers like you do? If you work on the guts of an accounting system, probably no. If you're a one-man shop writing mobile applications, it'd definitely help.</p>


答:
Yes and no.  It depends what you are doing.  If all you do is poke data around, then probably no, but if you are developing commercial web sites, web or desktop applications then it helps considerably.

However, a basic knowledge is useful to help you with solving user-centric problems and building abstractions of processes in your mind.

Title: Do programmers need to know about graphic designing?

Body:
I want to know your opinion. Do programmers (like me) need to know about design? For example drawing, web design, image manipulation etc.

```<code>Edited
</code>```

Actually, I like web, enterprise and mobile programming.

Thanks :D


问:
Any alternative main stream programming methodologies to OOP using C#?
As far as programming languages go, I love C#, and for that matter all the good that comes from the .net framework (LINQ, etc).

My main concern is I seem to be churning out too much code, and using OOP, I have a concern my code isn't always that easy to manage.

I want to continue using C# and .Net, but are there any other approaches to applying the language to get overall less code, and easier to manage compared to text book OOP?

Thanks in advance!

答:
Before straying too far into differing methodologies, make sure to take advantage of refactoring to simplify and consolidate your code.  Here is Fowler's catalog, the "alpha List of refactorings," each of which can help you improve and manage your C# code.

By learning to effectively design for reuse and by optimizing your application of interfaces, abstract classes, class hierarchies, dependency injection, and similar tools that exist within the standard object-orientated methodology, you may find yourself well on your way to achieving your desired results.

Beyond that, @Chris Smith has already pointed you to the fact that newer versions of C# (3.5 and 4.0) have added  several functional programming capabilities that may help you make your code rock!

If you find you like functional programming, give Microsoft's new F# language a try!  It's actually more like "object-functional," a mixture of the two methodologies.  You may also want to know that you can mix F# and C# in the same .NET Solution.

I also concur with the other commentators that AOP certainly has its uses!


答: I'll put it this way - micro-optimisation is a process of optimising something that is not a bottleneck at all. For example, if your program calls two functions A and B, and A takes 100 milliseconds to complete and B takes 2 microseconds, and you keep optimising function B. That is not only not important, that is absolutely wrong. But optimising function B is called optimisation and not micro-optimisation. Importance of optimisation depends. Say you have nothing else to do and your program is bug-free, then yes, it is important. But generally you have priorities. Let's say you need to add/write function C. If you think that writing function C will make you more money than making your program faster without that functionality, then go for optimisation. Otherwise pursue functionality. Also, experienced programmers focused on performance don't spend much time optimising, they just write fast programs. Of at least they know what tools to use and what to do not to spend years doing meaningless (read micro) optimisations.</p>

Body:
I recently asked a question on Stack Overflow to find out why isset() was faster than strlen() in PHP. This raised questions around the importance of readable code and whether performance improvements of micro-seconds in code were worth even considering.

My father is a retired programmer, and I showed him the responses. He was absolutely certain that if a coder does not consider performance in their code even at the micro level, they are not good programmers.

I'm not so sure - perhaps the increase in computing power means we no longer have to consider these kind of micro-performance improvements? Perhaps this kind of considering is up to the people who write the actual language code? (of PHP in the above case).

The environmental factors could be important - the Internet consumes 10% of the world's energy. I wonder how wasteful a few micro-seconds of code is when replicated trillions of times on millions of websites?

I'd like to know answers preferably based on facts about programming.

Is micro-optimisation important when coding?

My personal summary of 25 answers, thanks to all.

Sometimes we need to really worry about micro-optimisations, but only in very rare circumstances. Reliability and readability are far more important in the majority of cases. However, considering micro-optimisation from time to time doesn't hurt. A basic understanding can help us not to make obvious bad choices when coding such as

```<code>if (expensiveFunction() || counter < X)
</code>```

Should be

```<code>if (counter < X || expensiveFunction())
</code>```

(Example from @zidarsk8) This could be an inexpensive function and therefore changing the code would be micro-optimisation. But, with a basic understanding, you would not have to, because you would write it correctly in the first place.


问:
Business Objects - Containers or functional?
This is a question I asked a while back on SO, but it may get discussed better here...

Where I work, we've gone back and forth on this subject a number of times and are looking for a sanity check. Here's the question: Should Business Objects be data containers (more like DTOs) or should they also contain logic that can perform some functionality on that object.

Example - Take a customer object, it probably contains some common properties (Name, Id, etc), should that customer object also include functions (Save, Calc, etc.)?

One line of reasoning says separate the object from the functionality (single responsibility principal) and put the functionality in a Business Logic layer or object.

The other line of reasoning says, no, if I have a customer object I just want to call Customer.Save and be done with it. Why do I need to know about another class to save a customer if I'm consuming the object?

Our last two projects have had the objects separated from the functionality, but the debate has been raised again on a new project.

Which makes more sense and why??

答:
If you consider that a Customer is a part of the domain model, then it makes sense (especially within the context of DDD but not limited to it) to have have both properties and operations for that object.

With that said, however, I think that the example you've used is a poor one, and is a cause of the argument. If you're talking about persistence, then Customers generally don't 'save' themselves; whatever you're using for persistence will. It makes sense that any kind of persistence should belong to the persistence layer/partition. This is generally the thinking behind the repository pattern.** A method like Customer.UpgradeWarranty() or Customer.PromoteToPreferred() makes the argument clearer.

This also doesn't remove the possibility for having DTOs. Consider the situation where you're going to pass customer information to a remote service for instance. It may not make sense for a customer to create a DTO of itself for transport, that's an architectural concern, but a case could be made for it in the persistence or network layer/partition/code/what-have-you. In that case, such an objectcould have methods that look like this

```<code>public static CustomerDTO GetDTO(Customer c) { /* ... */ }

public static Customer GetCustomer(CustomerDTO cdto) { /* ... */ }
</code>```

So, in summary, it makes perfect sense to have operations on a domain object that are congruent with logical operations in the domain.

Google for 'Persistence Ignorance' for a number of good discussions on the matter (this SO question, and its accepted answer is a good place to start).

** This gets a bit muddied with certain OR/M software where you are forced to inherit from a persistent base that has a 'Save' method.

Body:
If you consider that a Customer is a part of the domain model, then it makes sense (especially within the context of DDD but not limited to it) to have have both properties and operations for that object.

With that said, however, I think that the example you've used is a poor one, and is a cause of the argument. If you're talking about persistence, then Customers generally don't 'save' themselves; whatever you're using for persistence will. It makes sense that any kind of persistence should belong to the persistence layer/partition. This is generally the thinking behind the repository pattern.** A method like Customer.UpgradeWarranty() or Customer.PromoteToPreferred() makes the argument clearer.

This also doesn't remove the possibility for having DTOs. Consider the situation where you're going to pass customer information to a remote service for instance. It may not make sense for a customer to create a DTO of itself for transport, that's an architectural concern, but a case could be made for it in the persistence or network layer/partition/code/what-have-you. In that case, such an objectcould have methods that look like this

public static CustomerDTO GetDTO(Customer c) { /* ... */ }

public static Customer GetCustomer(CustomerDTO cdto) { /* ... */ }

So, in summary, it makes perfect sense to have operations on a domain object that are congruent with logical operations in the domain.

Google for 'Persistence Ignorance' for a number of good discussions on the matter (this SO question, and its accepted answer is a good place to start).

** This gets a bit muddied with certain OR/M software where you are forced to inherit from a persistent base that has a 'Save' method.


答:
In short - they need to know enough about design principles to not produce crap.

Jeff had a good article on the subject.


答:
OOPS may have caused more code but If your application is large, the reduced complexity OOPS brings in would have resulted in maintainable,manageable code and clarity. If this is not the case and you feel it as a burden I am sure you might have used improperly. check if your classes are representing the domain objects properly and the communication among them is close to how it happens in the real world system that you try to simulate in program.

In C#, too much code is not a realistic reason to move away from OOPS IMHO. A paradigm shift should have a much more valid reason, in reality.

one can do 'structured programming' in C#..but I guess it will be a waste of time and effort.And most of the mainstream alternatives make use of OOPS too.

Title: Any alternative main stream programming methodologies to OOP using C#?

Body:
As far as programming languages go, I love C#, and for that matter all the good that comes from the .net framework (LINQ, etc).

My main concern is I seem to be churning out too much code, and using OOP, I have a concern my code isn't always that easy to manage.

I want to continue using C# and .Net, but are there any other approaches to applying the language to get overall less code, and easier to manage compared to text book OOP?

Thanks in advance!


问:
one programmer, many languages -- the name dilemma
When you work across multiple programming languages, there is a problem you encounter...

A valid name (identifier) in one language is invalid in another. For example...

var new function this are a keywords in JavaScript, but you can use them freely in Python. Similarly list dict def can be used in JavaScript without problems.

This is a very common and something programmers generally quickly become acquainted with when they program in multiple languages.

However, when you're working in collaboration, you have to lay out some rules/guidelines for your team members to ensure consistency and uniformity in the code. With teams, this issue becomes more important than simply remembering what's valid and what's not while you program.

So, my question is, what strategies you adopt...

simply take a union of all the reserved words present in all the languages you use, hand out a list to everybody and abstain their use?

accept the diversity and take extra pains when "context switching"

adopt an intermediate ground where one language can use the other's, but not vice-versa

(Note: i am only talking about Python and JavaScript in this question ... but please answer the question more broadly)

-- UPDATE --

Thanks for all the answers. So the general consensus i see emerging is to let programmers use any name regardless of what they do other languages -- as long as names are descriptive, it doesn't hurt.

答: Switching from, say, javascript to python already is a context switch. I don't think it is bad if variable names shift, especially if the changes in name is idiomatic with the language. One could even argue harder context switches can help in this case as it helps reinforce "dude, you are writing javascript not python now."</p>


答:
In my experience, the fix for this is to have broad naming conventions that apply to all languages.  Whether it be JavaScript, C#, or some other funky language, the way variables and classes are named can become a standard within a code base which is how I'd generally see resolving this issue.  The conventions can be agreed by consensus of everyone, simply a majority wanting a guideline, management saying, "This is how we do it," or a few other possibilities I'd imagine.

I rarely see the identifier problem you describe because most of the time my class or variable name is descriptive enough to not conflict so easily.  At the same time, if one is working with others than having clarity on how does the team want to handle this is the important point.

Title: one programmer, many languages -- the name dilemma

Body:
When you work across multiple programming languages, there is a problem you encounter...

A valid name (identifier) in one language is invalid in another. For example...

var new function this are a keywords in JavaScript, but you can use them freely in Python. Similarly list dict def can be used in JavaScript without problems.

This is a very common and something programmers generally quickly become acquainted with when they program in multiple languages.

However, when you're working in collaboration, you have to lay out some rules/guidelines for your team members to ensure consistency and uniformity in the code. With teams, this issue becomes more important than simply remembering what's valid and what's not while you program.

So, my question is, what strategies you adopt...

simply take a union of all the reserved words present in all the languages you use, hand out a list to everybody and abstain their use?

accept the diversity and take extra pains when "context switching"

adopt an intermediate ground where one language can use the other's, but not vice-versa

(Note: i am only talking about Python and JavaScript in this question ... but please answer the question more broadly)

-- UPDATE --

Thanks for all the answers. So the general consensus i see emerging is to let programmers use any name regardless of what they do other languages -- as long as names are descriptive, it doesn't hurt.


问:
Keys as attributes for ajax calls
I have been told its kind of a bad idea to use a key as an attribute of an xml tag. I find the very handy for ajax as i can just stick the key i need in what ever element is being clicked,changed, or whatever. I can see how this is a security risk but have only used the tactic in internal apps.

On external application/sites what would be a better way to handle this. I would assume just embedding another unique field that isn't numeric.

Basic example...
I have a button than when pressed would update the price of an item in the database.

Then using JS on button press i would take the id and pass it back to the controller to update the item.

答:
I don't see a problem with that per se.

The controller should validate the request anyway, if a user doesn't have access to something it should be stopped there.

For example,

```<code>page.php?action=updateAddress&id=7
</code>```

Obviously you want to make sure the request is coming from someone who is allowed to modify ID 7 once you receive it, also a user who can edit the record ID 7 might not have access to edit the record ID 8.

You almost certainly don't want to start litering standard HTML with a bunch of keys like

```<code><form ...>
  <input type="text" id="addressL1" name="addressL1" value="123 xyz blvd" addressValue="123 xyz blvd" addressID="6">
</form>
</code>```

If you need them in a form, pass them as hidden fields with their own IDs.

"Be conservative in what you send; be liberal in what you accept."
https://secure.wikimedia.org/wikipedia/en/wiki/Robustness_principle

Title: Keys as attributes for ajax calls

Body:
I don't see a problem with that per se.

The controller should validate the request anyway, if a user doesn't have access to something it should be stopped there.

For example,

page.php?action=updateAddress&id=7

Obviously you want to make sure the request is coming from someone who is allowed to modify ID 7 once you receive it, also a user who can edit the record ID 7 might not have access to edit the record ID 8.

You almost certainly don't want to start litering standard HTML with a bunch of keys like

<form ...>
  <input type="text" id="addressL1" name="addressL1" value="123 xyz blvd" addressValue="123 xyz blvd" addressID="6">
</form>

If you need them in a form, pass them as hidden fields with their own IDs.

"Be conservative in what you send; be liberal in what you accept."
https://secure.wikimedia.org/wikipedia/en/wiki/Robustness_principle


答: Most reserved words (in any language) are pretty general. I prefer variable/function names that are more descriptive and that means I almost never encounter this problem. I should admit to having been infected by Charles Simonyi with his original naming scheme -- this was at Xerox in the late 70's, before it was even called Hungarian Notation -- and that also tends to mean that the names are something than no sane human would ever use as reserved words.</p>


答: I think that if you're using descriptive variable naming the problem you describe should be minimal.  With that said, if it is minimal, then accepting the context shifting caused by variable naming between languages also becomes minimal.</p>


答:
Having programmed in quite a few languages over the 30+ years of my experience, I would say that trying to find naming standards that will work in any language is probably a pie in the sky idea.

Early on in my experience, I tried to use #define macros in C to create things that would make my C code look like the Pascal code that I was using before that. I was so used to programming in Pascal that I figured if I could just make C work like Pascal it would make me more productive. I soon discovered that I was wrong.

What made me more productive was to learn C and to not try to leverage Pascal syntax into another language just because it made me more comfortable.

I think you will be potentially constraining your programmers by prevent them from doing something in one language, just because it is wrong to do it in another language you are using.

If you limit your naming conventions to things that make sense to explain the variable use, then you will probably create good code, in whatever language.


答:
I don't know that there is really a good way to do this in the code. Take a step back:

Create two copies of the whole project, one with the class, and one without. Mark the version without the class as a stable codebase, ready for production release, and the version with the class as development for a future release. Document what needs to happen before this class can be considered production-quality.

Ideally, you should do this using branches in your source control solution of choice. You might have to cheat a bit though, since it sounds like you haven't been using such a branching strategy. Carefully remove the new class, check in a version without it, and do some regression testing. When you're satisfied it's stable, you can tag that revision, create a development branch from the tag, and then add the class back in the development branch.


问:
Using continuous build results as part of performance review metrics?
My boss is planning to use the metrics from our continuous build (builds and runs tests on every commit) as part of our performance reviews (in our 'quality' metric). This seems like a REALLY bad idea to me, but I'd like to know if anyone has studied this or seen this tried before.

My thought is that it's going to have our developers not put in as many tests as they otherwise would, for fear that the tests are going to fail. I feel that he's turning a valuable developer tool into a stick to beat the developers with.

The obvious counter argument is that it will promote people being more careful before they commit, and therefore leading to higher quality.

Am I off base here? Please leave aside the question of whether we should be doing performance reviews at all or not - that's been answered elsewhere.

答: Gaming the system here is quite likely, in my opinion, and your boss has to find ways to prevent that from being the reality.  The other case you didn't mention is where developers commit tons of times so that there is this flood of check-ins where the number of modifications is relatively low as if there is some part of the review where the count of builds is used this is where this becomes a new tool that could be misused rather easily.  I'm thinking of check-ins where something is renamed or white space is changed is a check-in and counts as some form of productivity would be the pedantic view.</p>


问:
Legal proof of when a feature been implemented
For various reasons I need to supply "proof" my company's lawyer that I implemented a feature by a certain date. I have used source control since the late 90s and even the oldest databases are still working. I also have the all the old setups. Our release notes are not always as clear as they could be and most of them are not dated but organized by revision number.

I figure rather than guessing I as other software developer if they know what is typically provided in this situation given what I have. I am particularly confused when a feature is spread among several source files. One feature we need to document is not just dependent on an algorithm but the UI as well and there a half-dozen files that were modified to this.

Update
By Completed, the feature was tested and released to the customer and it worked. And listed in the release notes. Also I already handed the lawyer the release dates, and the release notes (when they existed). However that was not sufficient. I need to show how I got dates. I got them out of my source control databases (Sourceforge, Subversion, Mercurical) so how to I  put data that in my source control in a form that a non-technical layman can understand.

Note: If you wondering why we have multiple database it is because the software in question been in continuous development since the late eighties.

答: This question isnt particularly clear.  But if you want 'proof' that a feature worked, you probably need the customer to sign off that said feature was delivered and functioned correctly.  Otherwise the functionality cant really be said to have been delivered and that it worked.


答: Just stick to lower-case-leading CamelCase. It works everywhere. This is called looking for the lowest common denominator between incompatible systems, and you will find yourself doing this often!</p>


问:
Why (not) segmentation?
I am studying operating systems and the x86 architecture, and while I was reading about segmentation and paging I naturally was curious how modern OSes handle memory management. From what I found Linux and most other operating systems essentially shun segmentation in favor of paging. A few of the reasons for this that I found were simplicity and portability.

What practical uses are there for segmentation (x86 or otherwise) and will we ever see robust operating systems using it or will they continue to favor a paging based system.

Now I know this is a loaded question but I am curious how segmentation would be handled with newly developed operating systems. Does it make so much sense to favor paging that no one will consider a more 'segmented' approach? If so, why?

And when I say 'shun' segmentation I am implying that Linux only uses it as far as it has to. Only 4 segments for user and kernel code/data segments. While reading the Intel documentation I just got the feeling that segmentation was designed with more robust solutions in mind. Then again I was told on many occasions how over complicated the x86 can be.

I found this interesting anecdote after being linked to Linux Torvald's original 'announcement' for Linux. He said this a few posts later:

Simply, I'd say that porting is impossible.  It's mostly in C, but most
  people wouldn't call what I write C.  It uses every conceivable feature
  of the 386 I could find, as it was also a project to teach me about the
  386.  As already mentioned, it uses a MMU, for both paging (not to disk
  yet) and segmentation. It's the segmentation that makes it REALLY 386
  dependent (every task has a 64Mb segment for code & data - max 64 tasks
  in 4Gb. Anybody who needs more than 64Mb/task - tough cookies).

I guess my own experimentation with x86 led me to ask this question. Linus didn't have StackOverflow, so he just implemented it to try it out.

答:
The short answer is that segmentation is a hack, used to make a processor with a limited ability to address memory exceed those limits.

In the case of the 8086, there were 20 address lines on the chip, meaning that it could physically access 1Mb of memory. However, the internal architecture was based around 16 bit addressing, probably due to the desire to retain consistency with the 8080. So the instruction set included segment registers that would be combined with the 16-bit indexes to allow addressing of the full 1Mb of memory. The 80286 extended this model with a true MMU, to support segment-based protection and addressing of more memory (iirc, 16Mb).

In the case of the PDP-11, later models of the processor provided a segmentation into Instruction and Data spaces, again to support the limitations of a 16-bit address space.

The problem with segmentation is simple: your program must explicitly work around the limitations of the architecture. In the case of the 8086, this meant that the largest contiguous block of memory that you could access was 64k. if you needed to access more than that, you would have to change your segment registers. Which meant, for a C programmer, that you had to tell the C compiler what sort of pointers it should generate.

It was a lot easier to program the MC68k, which had a 32-bit internal architecture and a 24-bit physical address space.

OwnerDisplayName: Mr. Shickadance

Title: Why (not) segmentation?

OwnerDisplayName: parsifal


答:
Segmentation was a hack / workaround to allow up to 1MB of memory to be addressed by a 16 bit processor - normally only 64K of memory would have been accessible.

When 32 bit processors came along you could address up to 4GB of memory with a flat memory model and there was no longer any need for segmentation - The segment registers were re-purposed as selectors for the GDT / paging in protected mode (although you can have protected mode 16-bit).

Also a flat memory mode is far more convenient for compilers - you can write 16-bit segmented programs in C, but its a tad cumbersome.  A flat memory model makes everything simpler.

Title: Why (not) segmentation?

Body:
I am studying operating systems and the x86 architecture, and while I was reading about segmentation and paging I naturally was curious how modern OSes handle memory management. From what I found Linux and most other operating systems essentially shun segmentation in favor of paging. A few of the reasons for this that I found were simplicity and portability.

What practical uses are there for segmentation (x86 or otherwise) and will we ever see robust operating systems using it or will they continue to favor a paging based system.

Now I know this is a loaded question but I am curious how segmentation would be handled with newly developed operating systems. Does it make so much sense to favor paging that no one will consider a more 'segmented' approach? If so, why?

And when I say 'shun' segmentation I am implying that Linux only uses it as far as it has to. Only 4 segments for user and kernel code/data segments. While reading the Intel documentation I just got the feeling that segmentation was designed with more robust solutions in mind. Then again I was told on many occasions how over complicated the x86 can be.

I found this interesting anecdote after being linked to Linux Torvald's original 'announcement' for Linux. He said this a few posts later:

Simply, I'd say that porting is impossible.  It's mostly in C, but most
  people wouldn't call what I write C.  It uses every conceivable feature
  of the 386 I could find, as it was also a project to teach me about the
  386.  As already mentioned, it uses a MMU, for both paging (not to disk
  yet) and segmentation. It's the segmentation that makes it REALLY 386
  dependent (every task has a 64Mb segment for code & data - max 64 tasks
  in 4Gb. Anybody who needs more than 64Mb/task - tough cookies).

I guess my own experimentation with x86 led me to ask this question. Linus didn't have StackOverflow, so he just implemented it to try it out.

OwnerDisplayName: Kragen


问:
Develop fast and buggy, then correct errors or be slow, careful for each line of code?

Possible Duplicates:

  Frankly, do you prefer Cowboy coding?

  Prototyping vs. Clean Code at the early stages

  Good design: How much hackyness is acceptable?

  Does craftsmanship pay off?

Which is better:

Coding fast, not caring about possible errors and limits, maybe forgetting to check the input, NULL returns etc, just to complete the task or to get to the milestone, and then correct all possible errors.

Coding slow, checking every line you write many times, writing tests, and checking every possible input to make a code as bug free as you can but taking weeks to write a working program.

Actually I'm using the 2nd way but it's frustrating to work, work, work and see only small improvements every day...

答:
The only way to go fast is to go well.

I saw "Uncle" Bob Martin speak on this at a conference once. Luckily, a quote of it is on line.

There's no such thing as quick and dirty in software. Dirty means slow. Dirty means death.

Bad code slows everyone down. You've felt it. I've felt it. We've all been slowed down by bad code. We've all been slowed down by the bad code we wrote a month ago, two weeks ago, even yesterday. There is one sure thing in software. If you write bad code, you are going to go slow. If the code is bad enough, you may just grind to a halt.

The only way to go fast is to go well.


问:
Measures of Javascript engine performances over time?
Since the beginning of the Javascript race -- which I would situate around Google Chrome launch in 2008 -- the improvement in the Javascript engine performances have been impressive.

The web is crowded with comparisons such as "Firefox V3.42.7 vs. Safari 3.0-prealpha2", and the winner of those comparisons changes every few months and differs on each benchmark.

But the big picture, independently of who got their new version out last, is that the average speed of current up-to-date browsers has improved a lot over the last years. Yet this long-term improvement is difficult to quantify:

people usually compare the last version of each browser, and not different versions of one browser

announced performance improvements do not generally pile up: when someone announce V3 twice as fast as V2, and later V4 twice as fast as V3, this does not mean that V3 is fourth times as fast as V1, because they usually mean "in a favorable case", and the favorable case in the V3-4 transition are not necessarily the same as in the V2-3 transition

benchmarks themselves evolve over time; what is referred as "the Sunspider test" today is not the same as in 2008, so we cannot compare raw scores over time.

Does anyone know of a valuable measurement of javascript engines performance improvement over the last few years?

答:
The first thing that comes to mid when you ask this question is Are We Fast Yet. (Link is to the "old" page, because the current page is straight lines.

(Historical note, the original page just said "No.")


答:
I think your question creates something of a false dichotomy.  In reality, the decision is not binary ("do I code slowly and carefully, or quickly and recklessly?"), but is rather on a spectrum.  The two options you presented are at either extreme.

Exactly where on the spectrum you want to be depends a lot on the particular product you're working on and what your customers expect from you.  You need to examine the constraints you're working with and then make an intelligent decision about what kind of process you want to use.

For instance, if you're in a position where it's very expensive to correct mistakes, or where failures are potentially catastrophic, you want to be closer to option #2.  Embedded software, missile guidance code and medical tools are good examples.  When fixing a bug would mean recalling millions of dollars worth of hardware, or when your mistake might result in people dying, you need to make sure that you get it right the first time.

The other end of the spectrum is when the business environment demands rapid code changes, but it's easy to fix mistakes and the penalties for failure are low.  Web applications often fit this description.  Your users are clamoring for new features and business logic changes, and they want them implemented yesterday.  If a small mistake in the code is made, it takes fifteen minutes to edit the offending script, get the change code reviewed, and hotfix it.  In this case, as long as you manage user expectations properly, they'll learn to ignore the occasional bug as long as you're responsive to their needs and maintain a quick turnaround time.  Of course, even when taking this approach, you should still have safeguards in place to prevent against catastrophic failures: keep backups, do code reviews, and make sure you've got a good hotfix/revert process.

I think the reality of software development is that most projects lie somewhere between these two extremes.  You usually want to be diligent about preventing bugs, but you may not want a year-long release cycle due to a burdensome QA process.

Aside from the environmental factors I mentioned earlier, I think the best way to figure out exactly where you should be is to evaluate feedback from users.  If they're frustrated by long wait times for new features, you may want to trim the QA process a bit in order to be more responsive.  Just make sure that you're extra quick about fixing any bugs you may introduce.  On the other hand, if they're demanding absolute reliability, then make sure you've got enough safeguards in place to meet that demand as best you can.

Title: Develop fast and buggy, then correct errors or be slow, careful for each line of code?

Body:
Possible Duplicates:

  Frankly, do you prefer Cowboy coding?

  Prototyping vs. Clean Code at the early stages

  Good design: How much hackyness is acceptable?

  Does craftsmanship pay off?

Which is better:

Coding fast, not caring about possible errors and limits, maybe forgetting to check the input, NULL returns etc, just to complete the task or to get to the milestone, and then correct all possible errors.

Coding slow, checking every line you write many times, writing tests, and checking every possible input to make a code as bug free as you can but taking weeks to write a working program.

Actually I'm using the 2nd way but it's frustrating to work, work, work and see only small improvements every day...


问:
Model Design: Which layers should access resources?
I am implementing a model design where DB tables are 'resources', and a model can use many 'resources'.  When I return a row from a table, it is represented by an 'item'.  (This came from a book by Keith Pope, but I've seen it in several other places too).

So, my question is, who should be able to access the resources?  In particular:

From time to time I'm tempted to let controllers access the resource directly, rather than through the model, for very simple tasks like finding a record.  Is this OK?

Many of my resources are accessed by more than one model.  For example, the 'country' table is accessed by the Organisation Model, and the User model.  Presumably this is OK?

Any pointers appreciated, as always!

答: Your "resources" should be abstracted into a repository class.  Your controllers can access the "resources" through the repository.  This gives you the ability to change the underlying "resources" model, without breaking the application.  It also gives you a place to put in some security, as needed.</p>

OwnerDisplayName: Kim


答: You shouldn't be naming things "list", "new", "var", "this" in the first place, as they aren't descriptive enough in any language.</p>


答:
You work off a contract that states that the feature is completed when the client signs off on the acceptance tests for the feature.  When the client signs off, it constitutes legal acceptance that the feature is completed.

If there is a problem with time frames, or the client is dragging his feet on signing off the features, there should be something in the contract that specifically allows you to sign off the feature yourself by demonstrating that the feature works in accordance with the stated feature requirements.

It goes without saying that the requirements need to be clear and unambiguous.

Title: Legal proof of when a feature been implemented

Body:
For various reasons I need to supply "proof" my company's lawyer that I implemented a feature by a certain date. I have used source control since the late 90s and even the oldest databases are still working. I also have the all the old setups. Our release notes are not always as clear as they could be and most of them are not dated but organized by revision number.

I figure rather than guessing I as other software developer if they know what is typically provided in this situation given what I have. I am particularly confused when a feature is spread among several source files. One feature we need to document is not just dependent on an algorithm but the UI as well and there a half-dozen files that were modified to this.

Update
By Completed, the feature was tested and released to the customer and it worked. And listed in the release notes. Also I already handed the lawyer the release dates, and the release notes (when they existed). However that was not sufficient. I need to show how I got dates. I got them out of my source control databases (Sourceforge, Subversion, Mercurical) so how to I  put data that in my source control in a form that a non-technical layman can understand.

Note: If you wondering why we have multiple database it is because the software in question been in continuous development since the late eighties.


问:
Should I plan ahead, or figure out programs as I'm writing them?
I was thinking today about Paul Graham's book "Hackers and Painters." More specifically, these two paragraphs:

"I was taught in college that one ought to figure out a program
  completely on paper before even going near a computer. I found that I
  did not program this way. I found that I liked to program sitting in
  front of a computer, not a piece of paper. Worse still, instead of
  patiently writing out a complete program and assuring myself it was
  correct, I tended to just spew out code that was hopelessly broken,
  and gradually beat it into shape. Debugging was a kind of final pass
  where you caught typos and oversights... [It] seemed like programming
  consisted of debugging.

... As far as I can tell, the way they taught me to program in college
  was all wrong. You should figure out programs as you're writing them,
  just as writers and painters and architects do."

That's how it's taught in my college and I'm pretty sure most other colleges as well. You figure out what your program will do, and then you figure out how to do it, then you type and debug. Sometimes you make a basic version and add functionality, but the idea is that you think through and then type.

This sort of reminds of that chapter in Feynman's book called "He Solves Radios By Thinking!" where he paced around thinking of how the radio could be broken, and then fixes it. To me, that's what programming is about - thinking and then finding a solution.

Is this the prevalent approach to coding? If so, why don't more people just hack away and put a program together without having a preconceived idea of what it's going to look like?

What are the advantages and disadvantages of think & type vs. spew & beat?

答:
Well, who am I to dispute what pg says, but... I think the best approach probably varies by individual, and that - to the extent that there might be an objective truth to this point - the truth probably lies in the middle somewhere. At the very least, I think making a dichotomy between "no planning ahead at all" and "figure everything out in advance" is a false dichotomy. It's a continuum, in my experience.

I personally lean more towards the exploratory programming style, and the "figure it out as I go," but at the same time, two of my favorite programming tools are an artists sketchpad and a set of colored pencils. There's definitely a time and place to sit down and sketch out high level relationships and visualize things to help yourself understand how things will fit together. Well, there is for me.

Again, I think this depends a lot on the individual... and also on the problem domain and the inherent complexity of the program. That is, a simple command-line calculator program (think, "poor man's bc") would probably require less up-front planning than an ERP system for a 30,000 employee company.


答:
Performance reviews are fine but how about useful metrics like:

Percentage of Unit Test coverage on features

Ability to meet deadlines

Clear and concise documentation

Follow proper coding conventions

Communicates well with others

Ability to turn requirements and user stories into tasks

These are all good ways to measure performance but the problems that management seem to have with these are that they actually require... ummm.. well ya know... ACTUAL WORK on their part.

Unfortunately most management has the attitude, "To hell with that, I want to judge my employees on metrics that don't actually require me to keep up with what they are doing."

Title: Using continuous build results as part of performance review metrics?

Body:
My boss is planning to use the metrics from our continuous build (builds and runs tests on every commit) as part of our performance reviews (in our 'quality' metric). This seems like a REALLY bad idea to me, but I'd like to know if anyone has studied this or seen this tried before.

My thought is that it's going to have our developers not put in as many tests as they otherwise would, for fear that the tests are going to fail. I feel that he's turning a valuable developer tool into a stick to beat the developers with.

The obvious counter argument is that it will promote people being more careful before they commit, and therefore leading to higher quality.

Am I off base here? Please leave aside the question of whether we should be doing performance reviews at all or not - that's been answered elsewhere.


问:
Should I create a new database for a public website when the data already exists?
I am looking for advice on how to create my data schema for a public web site.

Currently, we have an Intranet website where our agents create the data needed for reservations. The data includes tables like Establishments, products, prices per periods, and a typical Users table.

This intranet is already in production.

I've been tasked to create a public web site, where anonymous Joe and Jane will be able to book a reservation without calling one of our agent. The site will offer registration and will display the data available from the Intranet, albeit as read-only.

The public site itself will have some data of its own.

I am a bit reluctant to combine the data from the public site into the same database than our intranet, but most of the information that will be displayed on the public site will come from the pre-entered data from the intranet.

Are there any best practices concerning the separation and sharing of information between a public and a private website?

答:
Write web services to expose the necessary data and other actions, as needed by your site, and deploy the services so that they have access to the database, but can only be accessed by your specific web site (only allow a certain IP to perform actions, etc.).

This gives you access to your data, removes the necessity of creating another schema, syncing data between the two, and eliminates some of the hazards of wiring up your agent's database directly to your web application.

There may be other solutions, but this worked well for my company.


问:
How can I show aptitude to prospective employers when my all my work is on internal projects?
I've been in my current position for a long time (10 years) and in that time, I feel like I've performed well as a designer, system architect, and programmer.  However, all that work has been on internal projects that aren't accessible from the outside world.

I see a lot of advice like this that suggests 'If you can literally point to something and say "I wrote this" it's very impressive'.  What about if you can 'literally point to' nothing at all, because while you're a passionate programmer who (as the classic Joel-ism puts it) "is smart and gets things done", all those things are invisible?

Do I need to start frantically committing to open-source projects?  Start a "real world" (not corporate-internal) blog?  Frankly, I spent most of my 10 years happy here, and only recently have considered leaving for greener pastures.  Am I going to be sunk before I start looking because of my focus on work my current employer, at the expense of my "public presence"?

答:
This is very common -- there are a lot of contracting companies out there with a lot of staff writing code under non-disclosure or confidentiality agreements that will never be set free.

A lot of them don't have side projects or open source work, but still manage to change jobs with no problem. So you need to can talk about the types of work and projects you have done without breaking the NDA.

Of course, if you did join or start an open source project (or two), that's a great way to actually show something off.


问:
Do I have the wrong idea about software engineering?
I have a question which has been raised by my latest job (rather intern).

Just to put things into context - I'm 21 and I've finished my 2nd year of university before that I've had around 2 years of experience doing sys admin/QA jobs and basically I can say that I've seen how different IT sectors operated. Flash forward to present times and here's me landing an interning job at one of the premier research institution in the UK.

What I have to do is create some internal tools using a mix of technologies - mainly AWS/Java/Bash - you get the picture. Everything is OK, I'm doing my job BUT I'm not happy. Why is that - because I'm expected to work in an ad-hoc matter. That is create things quickly, without spending time on designing. My manager explicitly said that it was expected to "rush" through problems as they arise and we essentially. As a consequence it turned out that  things had to be re-done and re-engineer and they are still not perfect. As far as testing is concerned - keep it to a minimum, as long as it looks working then it is OK.

Am I at fault to disagree with this way of conducting work? Is it wrong to want to think over the system as a whole, then focus on different components and see how they might inter-operate, to zero in on different "key points" which might turn out to be problematic in the future? Is it a crime to want to do a good job and not a "quick job"? Is it a mistake or wrong attitude to want to research the data structures applicable to a problem so that you can choose the best depending on a particular problem set? To the best of my understanding the "Engineering" bit in "Software Engineering" has got to do exactly with this - research your problem domain and come up with a informed solution then refine as necessary?

I've been to an interview at an Arm's office in the UK and they showed me their SCRUM room and it looked they had pretty good idea as to how to manage their project - they had a backlog, they had metrics as to how long each issue might take to resolve - the usual things for SCRUM - completely different than the way things are run "here"

Have I built a wrong idea about the software industry in general? I'd like to hear your input on that. I mean I "entered" software development purely because I want to create things - plain and simple, but I want to create quality things. I want to see my software used in various scenarios, I want to see it bullet proof - isn't that the driving force for all software engineers? I think everyone can be a programmer/coder by just learning the syntax but for me where the real fun begins is when you actually have to come up with a design which is doable in real world.

I used to do my university assignments by just looking at them and directly start coding and could easily get marks above 75% and never really appreciated the "software development lifecycle" module. But now when I saw in the real world how bad it is to work without any formal process and the frustration that is inherent in situation where you don't know if the requirements are going to change tomorrow (oh, did I say that we don't have clearly defined requirement analysis?)

I really like to believe I just landed a position where some people just needed a code monkey to do their dirty work and this is not the case how the software world operates at large.

答:
I think you've noticed very early in your career that doing things quickly, without a proper design or proper testing, tends to come back to bite you. You obviously don't like this and you have good reason not to. It's ridiculous to be expected to "rush through problems", especially if you have to revisit them later when the initial solutions are incorrect or incomplete. You can only provide solutions to problems if you understand them completely, and that takes time and careful planning.

My suggestion to you is to let your superiors know that this bothers you and to suggest to them a better approach to doing your work. If they do not agree and want you to continue to "rush" through your work, I would start looking for work elsewhere. There is no sense in doing things in a manner that is not up to your own standards, let alone a standard of software development quality the industry expects.


问:
Is there a standard for when you include libraries or not?
I often come across a class which has a single reference to another library and was wondering if its better to include the library or to reference the object by it's full name. Is one better then the other? Is one more of a standard then another?

For example using System.Windows.Messagebox:

Option A:

```<code>using System.Windows;

public class MyClass
{
    SomeMethod()
    {
        MessageBox.Show("Something");
    }
}
</code>```

Option B:

```<code>public class MyClass
{
    SomeMethod()
    {
        System.Windows.MessageBox.Show("Something");
    }
}
</code>```

If B, how many references do you need before you decide to add the entire library?

答: I would prefer 'Option A'. It clearly states, that this file indeed uses that library. And anybody new to the code won't be searching for signs of external references through the whole file. Don't know about such standards though, just reasoning.</p>


答:
You don't have the wrong idea about what software engineering is. However, you're missing a very important aspect of it: this is a service industry. Some of us get to work on a product for years, and go through design and then many iterations before it's in v1. Others have to produce something in 3 hours. It depends on who you're servicing and what the purpose is.

If you can produce an application in 3 hours (or days) that does what it's meant to do, why spend more time on it up to design up front? You're just wasting money. Wasting money is general no a Good Idea™.

Title: Do I have the wrong idea about software engineering?

Body:
I have a question which has been raised by my latest job (rather intern).

Just to put things into context - I'm 21 and I've finished my 2nd year of university before that I've had around 2 years of experience doing sys admin/QA jobs and basically I can say that I've seen how different IT sectors operated. Flash forward to present times and here's me landing an interning job at one of the premier research institution in the UK.

What I have to do is create some internal tools using a mix of technologies - mainly AWS/Java/Bash - you get the picture. Everything is OK, I'm doing my job BUT I'm not happy. Why is that - because I'm expected to work in an ad-hoc matter. That is create things quickly, without spending time on designing. My manager explicitly said that it was expected to "rush" through problems as they arise and we essentially. As a consequence it turned out that  things had to be re-done and re-engineer and they are still not perfect. As far as testing is concerned - keep it to a minimum, as long as it looks working then it is OK.

Am I at fault to disagree with this way of conducting work? Is it wrong to want to think over the system as a whole, then focus on different components and see how they might inter-operate, to zero in on different "key points" which might turn out to be problematic in the future? Is it a crime to want to do a good job and not a "quick job"? Is it a mistake or wrong attitude to want to research the data structures applicable to a problem so that you can choose the best depending on a particular problem set? To the best of my understanding the "Engineering" bit in "Software Engineering" has got to do exactly with this - research your problem domain and come up with a informed solution then refine as necessary?

I've been to an interview at an Arm's office in the UK and they showed me their SCRUM room and it looked they had pretty good idea as to how to manage their project - they had a backlog, they had metrics as to how long each issue might take to resolve - the usual things for SCRUM - completely different than the way things are run "here"

Have I built a wrong idea about the software industry in general? I'd like to hear your input on that. I mean I "entered" software development purely because I want to create things - plain and simple, but I want to create quality things. I want to see my software used in various scenarios, I want to see it bullet proof - isn't that the driving force for all software engineers? I think everyone can be a programmer/coder by just learning the syntax but for me where the real fun begins is when you actually have to come up with a design which is doable in real world.

I used to do my university assignments by just looking at them and directly start coding and could easily get marks above 75% and never really appreciated the "software development lifecycle" module. But now when I saw in the real world how bad it is to work without any formal process and the frustration that is inherent in situation where you don't know if the requirements are going to change tomorrow (oh, did I say that we don't have clearly defined requirement analysis?)

I really like to believe I just landed a position where some people just needed a code monkey to do their dirty work and this is not the case how the software world operates at large.


答: Since its your code thats manipulating the databases, the safety of accessing the internal database from a public facing site really isnt an issue.  You just need to make sure you follow safe coding standards to prevent things like sql injection.  You can also use in the public facing app, as an extra precaution, a database user name with proper GRANT privileges such that it only has rights to modify certain tables - your sessions table, for example - but not the rights to modify other data.</p>

Title: Should I create a new database for a public website when the data already exists?

Body:
I am looking for advice on how to create my data schema for a public web site.

Currently, we have an Intranet website where our agents create the data needed for reservations. The data includes tables like Establishments, products, prices per periods, and a typical Users table.

This intranet is already in production.

I've been tasked to create a public web site, where anonymous Joe and Jane will be able to book a reservation without calling one of our agent. The site will offer registration and will display the data available from the Intranet, albeit as read-only.

The public site itself will have some data of its own.

I am a bit reluctant to combine the data from the public site into the same database than our intranet, but most of the information that will be displayed on the public site will come from the pre-entered data from the intranet.

Are there any best practices concerning the separation and sharing of information between a public and a private website?


答:
I'd agree that the way your current work operates is suboptimal, yes.  However, if you want to say that it doesn't work at all, I'd disagree with you there as there are various results and the institution is still around.

My main question back to you is to what extent are you dealing with fires that require immediate solutions done quickly similar to giving a medical patient first aid versus requests that could be set up as projects and handled on a much different scale similar to the medical patient having to schedule tests and various procedures that aren't necessary to do immediately but in the near term.

Taking the time to do a job well depends a bit on the maturity of the organization along with how important is it for something to be done well versus a claim of being done.

The question on researching the data structures is how long are wanting to do this.  If you want to take a decade to research a data structure that is quite different from wanting a couple of hours.  While I can appreciate the desire to get the best answer, there is something to be said for diminishing returns after spending some time on a problem,e.g. could you spend hours finding a solution to FizzBuzz as you could try to solve it in various languages on various hardware to optimize just how fast could it run.

While it can be important to research it is also important to deliver something.  If you don't deliver something, how good are you really?  Duct Tape Programmer would be more of an example on the getting things done side here.

Scrum is a specific methodology that you possibly could try to adopt at your current workplace.  Don't think Scrum is a silver bullet though.  Under What Circumstances Can Projects Under Scrum And Agile Fail? would be a blog post on that subject that may be of interest.

My guess is that you aren't seeing how informal your current place's processes are and thinking the grass is immensely greener on the other side where there is a formal methodology.  While it may be better there, some people may prefer what you have now with the massive freedom of being a cowboy.


答:
I think your situation is still on the Real World scale towards less emphasis on the quality side. Your preference is on the other end of the real world. Specs change, get over it. Things need to get done.

Consider ways to identify these types of companies when you apply for your next job. Few places have a business model where they can afford to have developers analyze their designs forever (Even professors have to teach.). Clients rarely pay if your work doesn't leave the dry erase board. Hate to see you drive yourself crazy so early in your career.


问:
What is a good Planned Release/Freeze/Beta Methodology?
I've been working on a nightmare of a project for some months now. The product is a small Ruby on Rails app/website for internal use by a small group of people. I'm coming up to the finish line and I'd like the actual beta release to go smoothly. I still have a number of small bugs that affect functionality in a minor way and do not break the build.

This is my first job and first time taking a product to launch. I'm curious what people's methodologies are for a smooth transition to bring your application from a development environment to a live production environment.

答:
Your qUESTion is interesting,as it demands the methodology for the product or website launch.
But I tell you,In reality,no body follows a fixed bookish methodologies Instead they go for some Quick Checklist type method,which includes what to take care of from product building to product launching. And this check list changes year by year based on present market environment.  So I have one such resource,which I followed once ,and got Good response also.

So,Checkout this page,which has that checklist before launching publicly:

10-simple-tips-for-launching-a-website

And I had also come across one article which describes the feel before any launch,have a read of it,if your time permits at: 7 Lessons I Learned from My First Very Small launch

And if wish to read more about it,then throw a keyword in google like:'Website launch flowchart',then see google may treat you nicely.


问:
How to effectively manage source control for project with both open and closed source?
I'm currently working on a project that has both an open-source "community edition" and a set of closed-source features for paying clients. One of the pain-points right now is figuring out how to handle keeping the shared source in sync between projects.

We use Mercurial for source control, and the open-source piece is pushed to both CodePlex and Kiln, while the closed-source piece is pushed only to Kiln. We're presently keeping them in separate repositories with project references into the open-source repository where applicable.

Is this really the best way to handle this kind of situation, or if there's something I'm missing (like using a subrepository within the closed-source repository to contain the open-source portion) that might be easier and cleaner to work with?

答:
From what I can tell, you are essentially working on two "projects": one open source, the other closed source. I don't see there being a problem if these two "projects" are kept separated (i.e. kept in separate repositories).

How you manage both of these "projects" depends a lot on how they are individually designed and how well one can integrate with the other. For example, if one of the "projects" is a closed-source library, the other open source "project" can integrate and use this library without having access to the source. I have a feeling you are doing this already. You can manage this separation by having separate teams responsible for each "project" and coordinating between themselves when necessary.


问:
How would you design a programming language?
If you were to design a programming language, how would you do it? What features would you put in? What would you leave out? Statically or dynamically typed? Strongly or weakly typed? Compiled or interpreted? Justify your answers.</p>

答:
Compiler hints

I'm talkin out of me bum since I don't know that much about language design, but I think the feature I'm talking about is called hints in other languages. Compiler hints, maybe?

I don't know if I read this in a Perl6 draft or was just high at the time, but I imagine a language where everything by default is loosy goosy and automagical. But if you wanted to really crank out performance and say, hey, this value is always an integer or it's never null, or this can be parallel, or this is stateless, things like that... That the compiler could automatically go to town on these specifically marked areas.

E: I'd appreciate comments clarifying what I'm asking for or citing examples where this already exists.


问:
Project Proposal templates/requirements
When drafting a project proposal, do you use any standard template?

What features/information should be included? What is nice to have included? What sort of boiler plate information should I shove in?

Do you find any design pattern or concept particularly helpful?

答:
When it comes to templates, I find the ReadySET templates to be pretty solid. These templates cover the major lifecycle points - project planning, requirements, design, implementation, testing, deployment/installation, support, and project finalization.

Something to keep in mind, though, is that templates should be modified to fit the project and processes. Very rarely can you just pull down a template from a book or the Internet and use it. I find templates most useful in determining what information I should have somewhere at each phase, and let the project determine how and where the information is captured.

Title: Project Proposal templates/requirements


答: The real benefit of your subrepository idea is that it ties revision dependencies together between the two projects.  In other words, if a new closed source feature depends on an open source version, when someone gets one they automatically get the other.  If you back out to an earlier closed source revision in order to do a hotfix, you automatically get the open source revision you originally built it with.  There are other ways, like configure or build scripts, to manage those kinds of dependencies, but they are more difficult to maintain.</p>

Title: How to effectively manage source control for project with both open and closed source?

Body:
I'm currently working on a project that has both an open-source "community edition" and a set of closed-source features for paying clients. One of the pain-points right now is figuring out how to handle keeping the shared source in sync between projects.

We use Mercurial for source control, and the open-source piece is pushed to both CodePlex and Kiln, while the closed-source piece is pushed only to Kiln. We're presently keeping them in separate repositories with project references into the open-source repository where applicable.

Is this really the best way to handle this kind of situation, or if there's something I'm missing (like using a subrepository within the closed-source repository to contain the open-source portion) that might be easier and cleaner to work with?


答:
Making software re-usable and bullet proof is not the driving force of software engineering.  Engineering is about solving real world problems optimally within real world constraints.  Most engineers would prefer to work on a Ferrari - but a station wagon needs just as much engineering, and the reason a station wagon doesn't perform as well (in some ways) is due to more difficult design constraints, not due to worse engineering.

When you say you want to do a "good job" rather than a "quick job", most engineers do, but sometimes part of what defines good is how quick it is to completion.  So it's not right to think of "good" and "quick" as opposing choices.  Or to think you are doing a bad job, or are just a "code monkey", for doing the best possible job in the time available.

Of course, it's quite possible that the process isn't optimal, and would do better with a little more design up front.  The acid test would be, is the current way of doing things creating more problems than it solves for the users, or is it just bugging the developers who have to work that way?  If it's actually causing problems for the users, part of your job is to try to demonstrate that this is the case, and try to win people over to a slightly more controlled process.


答:
Plan initial features/UI -> Code top x features -> Test and signoff -> dogfood/demo

Plan next iteration -> Code next x features-> Test and signoff -> demo/dogfood/Alpha

Plan next iteration -> Code next x features-> Test and signoff -> demo/dogfood/Beta --> ship

Changes/Feedback from a previous iteration can be taken into account. And depending on the cycle length you can be agile (weekly/monthly sprints) or iterative (multi-month cycles)

One of the important part is to get some kind of demo/dogfood/trial after every iteration since this gets feedback from the real users.

Title: What is a good Planned Release/Freeze/Beta Methodology?

Body:
I've been working on a nightmare of a project for some months now. The product is a small Ruby on Rails app/website for internal use by a small group of people. I'm coming up to the finish line and I'd like the actual beta release to go smoothly. I still have a number of small bugs that affect functionality in a minor way and do not break the build.

This is my first job and first time taking a product to launch. I'm curious what people's methodologies are for a smooth transition to bring your application from a development environment to a live production environment.


答:
With segmentation it would be, for example, possible to put each dynamically allocated object (malloc) in its own memory segment. Hardware would check segment limits automatically, and the whole class of security bugs (buffer overruns) would be eliminated.

Also, since all segment offsets start at zero, all compiled code would automatically be position independent. Calling into another DLL would boil down to a far call with constant offset (depending on the called function). This would greatly simplify linkers and loaders.

With 4 protection rings, it is possible to devise more fine-grained access control (with paging you have only 2 protection levels: user and supervisor) and more robust OS kernels.  For example, only ring 0 has full access to the hardware. By separating the core OS kernel and device drivers into rings 0 and 1, you could make a more robust and very fast microkernel OS where most of the relevant access checks would be done by HW. (Device drivers could get access to hardware through I/O access bitmap in the TSS.)

However.. x86 is a bit limited. It has only 4 "free" data segment registers; reloading them is rather expensive, and it is possible to simultaneously access only 8192 segments. (Assuming you want to maximize the number of accessible objects, so the GDT holds only system descriptors and LDT descriptors.)

Now, with 64-bit mode segmentation is described as "legacy" and hardware limit checks are done only in limited circumstances. IMHO, a BIG mistake. Actually I don't blame Intel, I mostly blame developers, the majority of which thought that segmentation was "too complicated" and longed for flat address space. I also blame the OS writers who lacked the imagination to put segmentation to good use. (AFAIK, OS/2 was the only operating system which made full use of segmentation features.)

Title: Why (not) segmentation?


答:
Actually, this bothers me. You're in a profession where you develop tools for research scientists, correct. However, you're told to make these programs quick and have them appear to work minimally. Surprise surprise. This is simply the researcher's typical approach to programming with the buck passed off to an actual programmer.

The main concern here being that lack of testing in particular can be ethically dubious if the tools have an important purpose. If one isn't sure the software has defects because one is restricted to minimal testing time, this means NO ONE is held liable to the working condition of the software, and Atlas shrugs.

Let's stop and think about this for a second though. What kind of tools are you developing? If you're developing software that models data, there's a big ethical dilemma here. In some situations, scientific research leads to decisions that affect a lot of people on a big scale.

Suppose for an instant, the controversial topic of man-made climate change. Let's say they placed the same standards on the modeling software that they use to come to the conclusions they have today. The topic has a big impact on how we approach correctly managing the environment, and international policy.

Is it not ethical to ensure that the modeling software doesn't have major problems with its predictions?

The whole problem isn't that greenhouse gases warm the earth. The problem is whether the net result of the feedback effects is an accelerating gain in temperature, which after breaking a threshold would no longer be reversible.

If said gain was occurring, the evidence of a net result would be marginal, probably within the err range.

So, slight miscalculations, even methodology involving data storage and retrieval on the back end, could result in either ignoring a serious environmental problem on one end of failure, or international policy that affects a lot of people (destroys jobs, destroys pensions, etc.) on the other.

So, yes, you are right. I don't care what the pace of research is... If researchers want to rely on software tools to manage data and perform calculations for them, they need to learn to wait on software done right. Otherwise this software becomes a vulnerability point in their theories that they aren't held accountable to, resulting in ethic misconduct.


答:
My rule of thumb is that if I use a library a lot in a particular class file then I'll include it (it looks neater and saves typing). But if there's just a single reference to a rarely used class in my code then I may well reference it using the fully qualified name (that way it's obvious which namespace it is in).

Don't forget in Visual Studio you can collapse namespace definitions and also easily remove unused using statements, if you find you have a lot.

Title: Is there a standard for when you include libraries or not?

Body:
I often come across a class which has a single reference to another library and was wondering if its better to include the library or to reference the object by it's full name. Is one better then the other? Is one more of a standard then another?

For example using System.Windows.Messagebox:

Option A:

```<code>using System.Windows;

public class MyClass
{
    SomeMethod()
    {
        MessageBox.Show("Something");
    }
}
</code>```

Option B:

```<code>public class MyClass
{
    SomeMethod()
    {
        System.Windows.MessageBox.Show("Something");
    }
}
</code>```

If B, how many references do you need before you decide to add the entire library?


答: You could always check out, build and test old versions of the browsers since some of them are open source. I bet you could find older binary versions of those who aren't. </p>

Title: Measures of Javascript engine performances over time?

Body:
Since the beginning of the Javascript race -- which I would situate around Google Chrome launch in 2008 -- the improvement in the Javascript engine performances have been impressive.

The web is crowded with comparisons such as "Firefox V3.42.7 vs. Safari 3.0-prealpha2", and the winner of those comparisons changes every few months and differs on each benchmark.

But the big picture, independently of who got their new version out last, is that the average speed of current up-to-date browsers has improved a lot over the last years. Yet this long-term improvement is difficult to quantify:

people usually compare the last version of each browser, and not different versions of one browser

announced performance improvements do not generally pile up: when someone announce V3 twice as fast as V2, and later V4 twice as fast as V3, this does not mean that V3 is fourth times as fast as V1, because they usually mean "in a favorable case", and the favorable case in the V3-4 transition are not necessarily the same as in the V2-3 transition

benchmarks themselves evolve over time; what is referred as "the Sunspider test" today is not the same as in 2008, so we cannot compare raw scores over time.

Does anyone know of a valuable measurement of javascript engines performance improvement over the last few years?