• Post Reply Bookmark Topic Watch Topic
  • New Topic

Advice given by text books and websites  RSS feed

 
Greenhorn
Posts: 1
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question isn’t exactly related to Java, but OOP in general.

For me personally, I have this idea that the official documentation and text books are the official source of information regardless of what I read online. These are set in stone and should be adhered too. I also find I’m spending hours searching online only to realize what I’m looking for is in a text book I have lying around.

However, lately I’m unsure of what to do. Let me explain.

I’ll have a question about OOP and use Java to demonstrate my problem, I always consult the Java documentation and Effective Java before asking or searching online. When I find the answer in the text book, I usually ask online either on SO or other forums to make sure I understand what is being said in the textbooks and documentation. The problem is I’ll come across answers that completely contradict what is being said in the textbook or documentation and I get lost and frustrated.

For example, the debate about getters and setters.

Effective Java demonstrates how to use getters and setters and says to use them instead of public variables. Great! Fully agree. Problem is, a simple Google search will turn up results that say otherwise, what makes it worse, you’ll never find a direct answer to what you should do instead.

Sometimes you’ll find textbooks that contradict other textbooks! Both authors are well respected, it’s just that they differ in opinion about OOP principals. 

My question is this, how should you take advice you get from official documentation, textbooks, and forums? What source of information is more reliable than others? What takes precedence over the other?
 
author & internet detective
Marshal
Posts: 37708
578
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarah,
Welcome to CodeRanch! Have a cow for the excellent first question. Or meta question .

The official documentation is almost always right. (Yeah, I know, "almost".) So if you find something that conflicts, the docs are way more likely to be right.

Books are the second level of correctness. At least when from a reputable publisher and have decent reviews online. (self published books vary extensively in terms of quality.) Also, look to see if the book you are using has an errata list online. No book is going to perfect. But books with an errata link show they will disclose mistakes so you don't have to sit around puzzled. I even wrote a blog post - why posting errata matters..

Next comes forums. CodeRanch and Stack Overflow have multiple people looking at an answer so something incorrect is likely to be questioned.

Finally comes random tutorials. Anyone can post something online so it could easily be wrong.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37708
578
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you aren't sure if something you read online (or in a book), feel free to post here. We welcome discussions so you'd learn about the pros/cons if it is controversial or why the site is wrong if it is.

For example, in the getter/setter thing, you should definitely avoid public instance variables. This provides good encapsulation and makes the code easier to modify later.
 
Marshal
Posts: 56895
174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Jeanne. I think the standard of books from reputable publishers, at least about computing, is good, and it seems to be getting better over the years.
As for the getters and setters question, you have two problems here. One is that non‑private variables are definitely a bad idea. The other is that it is possible to provide too much access to private variables via getXXX and setXXX methods. But you have people here who know about such questions. To sweeten things a little, do a search for honey. You will get three hits in the last few weeks: 1 2 3 (maybe less useful). Have a quick look at them and see whether they help explain why getXXX mehthods and, more so, setXXX methods can constrain the implementation details of your classes.

And welcome to the Ranch again. Congratulations on being given a cow so soon.
 
Sheriff
Posts: 11598
187
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think just as, if not more, important when you're learning is to understand not just what to do but why you do things in certain ways. Your understanding of why people recommend doing things in certain ways can be broadened by also studying the consequences of not following their advice. In other words, look for counter-examples that show you what happens if you don't do the right thing.

Language documentation focuses mainly on syntax and technical details related to the language itself. Good programming goes far beyond those mechanics. So, for me, after you've studied the "official documentation" and become comfortable enough with language syntax and constructs, you really should strive to dig deeper into the principles of programming itself and start developing your own sense of what's "right" and "wrong" by studying and understanding books like Bloch's Effective Java Programming, which I think does a lot better at explaining the why of good practices. Another book that gives a lot of insights about the motivations for doing things in certain ways is Martin Fowler's Refactoring.

Lastly, while reading good books is important, nothing beats actual practice. Programming is like swimming: You can only learn so much by watching other people do it. To really learn how to swim, however, you have to get in the water and do it yourself. So, practice, practice, practice. But practice mindfully and thoughtfully.
 
Greenhorn
Posts: 3
Eclipse IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very interesting as I am a total Java noob myself.  After watching countless Video courses there are some where the teaching is just plain wrong. I refer to the Java Documentation by Oracle to either confirm my suspicions or show me how I am wrong and the presenter is absolutely correct.

Just don't give up in your frustration.  Keep on coding, "getting wet" as someone put it.

Look at the answers, try the code yourself and balance it out against; 1) Does it work; 2) if not why?, 3) What does the official documentation say.

Also, in my professional career, I have reached out to authors of books for clarification and they are usually willing to respond with an explanation.

Lastly, while Google is your friend, be careful.

Cheers,
Steve
 
Sheriff
Posts: 22967
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two observations:

First, when you find things on the web, Sturgeon's Law applies: 90 percent of everything is crap.

And second, beginners seem to want absolute rules. Sometimes they exist and sometimes the answer is "It depends". Should you use setters and getters? Well, it depends. Only use them if you need them. How do you know if you need them? Well, your design will tell you. Unfortunately most courses seem to teach programming first and design second, leaving the poor beginner adrift.
 
Junilu Lacar
Sheriff
Posts: 11598
187
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul keeps coming up with very nicely encapsulated nuggets of truth. The observation that beginners look for absolute rules lines up with what I've seen as well and what authors like Andy Hunt write regarding learning and context. Beginners, having no experience by definition, have nothing to draw upon to put problems and decisions in context. Context is where you find the answers to "It depends on what?" The way to having context is through diligent and careful study and experience gained from practice. And don't forget mistakes, or as Yoda said in the latest installment, "...yes, failure most of all. The greatest teacher, failure is."
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a complete newb and find Simple Compliable Examples (SCE) to be of more value to my learning experience than code snipets. When reviewing a code examples, remember the author is using the code to demonstrate a particular feature or problem, and is likely using the least amount of code possible. Very likely not the way you would choose to code in a real application.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!