Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming for and by yourself

Tags:

field

If you're writing something by yourself, whether to practice, solve a personal problem, or just for entertainment, is it ok, once in a while, to have a public field? Maybe?

like image 856
Stefan Avatar asked Jul 21 '09 05:07

Stefan


2 Answers

Let me give you an analogy.
I come from a part of the world where English is not the primary language. But it’s necessary for all things in life.
During one of those usual days during my pre-teen years I said something very funny in English. Then my Dad said, “Son, think in English. Then you’ll get fluent

I think it applies perfectly to this situation.

Think,try and question best practices in your playground. You will soon realize what’s best for what.Why are properties needed in the first place. Why should this be public? Why should I not call a virtual member from the constructor? Let me try using "new" modifier for a method call. What happens when I write 10 nested levels of if-then-else and try reading it again after 10 days. Why the heck should I use a factory pattern for a simple project. Et cetera.

And then you’ll realize without shooting at your foot, why design patterns are patterns...

like image 179
11 revs Avatar answered Sep 22 '22 11:09

11 revs


I think it's reasonable if you're consciously throwing the code away afterwards. In particular, if you're experimenting with something completely different, taking shortcuts makes sense. Just don't let it lead to habits which cross over into "real" code.

like image 42
Jon Skeet Avatar answered Sep 22 '22 11:09

Jon Skeet