views:

1713

answers:

11

I'm looking for a book to learn to "engineer" programs better. I program in Java already. Looking at the source code of open-source projects usually is too complicated as I have never made a program with more than 20 small files in it. I'm not an advanced programmer, I learned with a book and do this mostly for personal projects.

My last program was a mess. I used Eclipse and put all my unrelated-files in the same package which didn't scale well.

Examples of good suggestions would be: books on how to organize files in a program, on how to architect/engineer a program, books on design patterns, books on using OOP properly, books on how to mix GUI and logic code. Bad suggestions would be "learn java in 21 days", or stuff about advanced features.

For example, I just saw "Interface Oriented Design" from the Pragmatic Programmers website and it seems to hit one part of what I need, but it probably won't explain how to organize files and such in a large program. Any ideas? Or perhaps ideas other than books on what I currently need? (besides participating in an open-source project, please)

+1  A: 

Refactoring by fowler.

Design Patterns.

those are the two critical ones.

Start with the refactoring book and learn the bad code smells, start to apply it throughout your source code.

Honestly there are a million books out there, but I think the most important concept is DRY (Don't repeat yourself). EVER.

This applies to your interfaces (don't pass redundant variables) and your code (Never have any piece of business logic in two different places).

As you ruthlessly refactor your code and remove redundancies, you will learn to program it better in the first place--then you can start trying to detect more subtle redundancies, things you might not have thought to factor in the first place, etc.

Bill K
+5  A: 

I would recommend Bruce Eckel's Thinking in Java. His approach is that you're already a developer and you want to learn how to use the language EFFECTIVELY.

For organizing your project, I'd look at the Pragmatic Programmer Series. There is a whole section in the version control book on organizing your project files.

+1 on Refactoring By Fowler and the Gang of Four Design Patterns. In addition I'd recommend reading Patterns of Enterprise Application Architecture (also by Fowler), followed by Domain Driven Design by Eric Evans. To tie it all together look at Domain Driven Design with Patterns (even though it's in C# it gives some great advice).

Mike Brown
+16  A: 

Effective Java, without a doubt.

SCdF
Make sure you get the second edition if you're using Java 5 or later
Don
+1  A: 

The two books that stay on my shelf always are both by Martin Fowler: Refactoring and Patterns of Enterprise Application Architecture.

I learned more about how to write Java reading Refactoring than any other book. PEAA will enlighten you to best practices. I highly recommend you read them both cover to cover.

Sixty4Bit
+1  A: 

Just a small piece of advice. You don't need a book to tell you how to organize your files, just create a root hierarchy, like com.fluff.princess and on top of it create a single package for each set of related functionality. For example, com.fluff.princess.gui will store the gui handling functions, com.fluff.princess.calculations will store the calculations part.

You can then repeat this further on each package, like com.fluff.princess.gui.menu will handle the menus, and com.fluff.princess.calculations.math will store the math calculations.

You can use a book for the rest of the doubts, for sure.

Vinko Vrsalovic
Thanks, that seems also helpful.
PRINCESS FLUFF
+3  A: 

Steve Mcconnel's Code Complete is invaluable in any language, java or otherwise. It is all about the art/science of constructing software that works.

The other book I might recommend is Head First Design Patterns. It is much more accessible than the gang of four book and includes tons of easy to understand examples in java.

edit: added links to books

Paul Wicks
+1  A: 

Forget refactoring for now. You aren't a maintenance programmer and you probably don't have the experience right now to put that in the right context. Stay away from patterns and practice books now, as well, for the same reasons: you need a body of experience to inform you when reading these things.

Bruce Eckel's website is your best resource right now. TiJ is what you should use, working through all examples without exception, until you get it. Move onto his beta-books "Thinking in Enterprise Java" and "Thinking in Java and Patterns" after you build something using your TiJ knowledge.

Above all else, don't look for shortcuts and don't cheat yourself. Learning is a process, and by process I mean that you need to move through it in time. Enjoying the process is one of the rarest abilities you can develop, but if you do, you can learn anything.

--#

Wow, forget refactoring because it's for maintenance only? Man do you have a LONG way to go. Plus, the refactoring book, chapter 3 is "Bad Code Smells". Every single one will improve your OO ability significantly even if you never "Refactor"
Bill K
+4  A: 

Definitely check out Robert C. Martin's Clean Code: A Handbook of Agile Software Craftsmanship. It's an excellent practical guide to writing code that is readable, malleable, and able to stand the test of time. Although 95% of the advice is applicable to other languages, the book is centered around Java.

Patrick McElhaney
+2  A: 

Another good book on "how to organize files in a program, how to architect/engineer a program, ... design patterns, [and] using OOP properly" is Agile Software Development: Principles, Patterns, and Practices. The examples are a mix of C++ and Java.

It covers a lot of ground, but most importantly catalogs eleven principles of object oriented design. For that reason, I consider it as important as the Gang of Four's Design Patterns.

Patrick McElhaney
+2  A: 

For effective software design principles, stay away from books about "pattern this" and "enterprise that". In fact, don't limit your scope to Java. Java is just one tool. Get good, solid books that will help you understand the craft of programming as a whole. I highly recommend:

The Structure and Interpretation of Computer Programs and Code Complete

See here for more recommendations from StackOverflow

Apocalisp
+5  A: 

tl;dr: Effective Java in general, Java Concurrency in Practice for important projects.

This is what I think you're asking: you would like more information on how to use Java effectively, efficiently and well but are not looking for the larger world of software engineering and architecture at this time.

Given that, I think you need to consider three books. While the third may be handy as you get started in Java, I think the first two will be useful to you for years:

  1. Effective Java (2nd edition) by Josh Bloch is an excellent list of "don't do this and here's why" points of information. I think of it as the flip side of Thinking in Java. For example: a common mistake made by C++ programmers new to Java is to think that you should use finalizers to simulate the destructors of C++ but that's not what they are. Quoting Item 6: Avoid finalizers, they "are unpredictable, often dangerous, and generally unnecessary."
    Note: if you ever read Meyers's Effective C++ books back in the day, this is the same sort of thing.

  2. Java Concurrency in Practice by Brian Goetz et al is the most important Java book that I have on my bookshelf. It is a critical reminder that Java is multi-threaded, all the time. If you ever want to write even the simplest useful program that has a user interface, accesses the disk / database and has any form of network traffic, multi-threading issues are going to be at the forefront of your brain. This book clearly lays out things you should never do, techniques that will often work and describes the pathological situations where there is no perfect answer, all in a very readable package.

  3. Thinking in Java (4th edition) by Bruce Eckel is a solid reference for syntax and usage. Admittedly, this information will become progressively more out of date over time but a reference like this is never a bad thing to have on hand.

Summary: Thinking in Java is good when you're new to Java, Effective Java is useful as you gain confidence and Java Concurrency in Practice is what you need when you are ready to see just how far Java can take you.

Bob Cross