As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
so I have been through all the courses on programming, algorithms, etc. and did a lot of coding and some small projects.
Now, I may start working on a real project, real java SE program with gui and everything, not big, but much more complicated than average school project. My experience says that when I'm having more classes in my project (say 10), it kind of gets difficult to decide from where this constructor should be called, if I should pass this parameter here or create it later and how the whole thing should work together.
can you recommend me some resources on this? Should I go the way of studying the design patterns or how do I get to design apps that have nice architecture?
what is the procedure when developing an app with lots of classes and gui and so on?
thanks a lot
Design patterns usually help in making an application more maintainable and also more flexible. Although which design patterns to use relies essentially on what type of problem you have.
I did go through this book, which provided me with a quick and easy way to grasp what design patterns are and how they work.
Since you are dealing with GUI related applications, my only recommendation would be to try and make your GUI and Logic seperate. This should reduce clutter and should make your code more understandable since each class deals with items related to its layer (GIU or Logic).
Breaking things down also makes your application more flexible and reusable. Cohesion vs Coupling should also be another thing which you should keep in mind.
For design patterns : Head First Design Patterns & Design Patterns: Elements-Reusable-Object-Oriented
For Effective Programming Guidelines : Recommended reading Joshua Bloch's Effective Java
I personally like to thing in a TDD approach and love to read this blog Writing Testable Code by Misko Hevery.
It explains how should we focus on making code loosely coupled and testable.
And lastly keep exploring open source libraries and projects they will keep you up to date with latest trends and coding styles.
Head first Design Patterns or even the original Design patterns book from the Gang of Four (if you are the kind of person who likes more direct theory) for application design and I think it may be useful for you to have some knowledge of enterprise design patterns (Enterprise Integration Patterns from Hohpe and Wolf) will help you to understand how to implement flexible communication even in small SE projects. (Even these systems needs sometimes some kind of interprocess communication).
Additionally, the answers of Narendra and npinti are very good advices as well.
Have fun!
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
As the title states; the way one groups classes in PHP compared to for example Java, is it supposed to be different? I am currently reading O'Reilly's book OOA&D and in the chapters I've learned to use one class for each specific task and not one class for a grouped thing. Recently, I looked upon some code for a calendar, and the class was thousands of lines and had everything inside it that was to be used. However, this feels to me like it's violating the point of having many objects doing one task, but seeing as PHP is web development, is it supposed to be different? E.g. monster-classes.
Answer: use good design principles, even in PHP.
In addition to not creating Monster classes (also known as God-classes or objects) the following patterns are worth mentioning specifically:
Object naming:
Class names should be nouns because they are objects.
Method names should be verbs, because they are actions.
Cohesion. The short-version is basically: methods do one thing and do it well.
Property Visibility: Variables should private unless you've got a dang good reason not to, and in such case, use protected. Almost always you should avoid public.
Use interfaces and abstractions. Almost no one uses interfaces in PHP, but they should. It means that I can write my own implementation details but still hook in with some service that uses the class.
A somewhat outdated article on PHP design patterns that's still worth reading but is hard on the eyes.
Short-version:
If you are ever relying on an array to hold a particular structure it should probably be in a class.
An example from my life: ActiveRecord
What if I want to build a website that does not need any particular Active Record implemenation? At the moment, I'm quite stuck once I choose an implementation because they are all so unique. If they actually implemented an ActiveRecordInterface, I would be able to swap out my actual ActiveRecordEngine if I wanted to change.
I've learned object-oriented programming over 15 years ago and have been using it with C++, Java, Pascal. The PHP at that time was much less powerful than it is now. It took PHP about 10 years to implement Objects properly. They finally work fast, references are passed properly.
Unfortunately, many developers who started with PHP haven't got a grasp on a proper object-oriented design of software. The class is often used like a "library" and everyone speaks about de-coupling and having everything independent, so in many cases classes won't have parent.
There are no solid foundation what everyone could agree on and use. When you turn to the frameworks, some are better and other are worst in terms of the proper OOP. For instance, the proper Code Igniter framework is fast, secure, simple to use, but has very bad OOP design. The main reason is compatibility with PHP4.
For a better-structured frameworks, simply look at the source code of some of their components:
Tabs in Yii: http://code.google.com/p/yii/source/browse/tags/1.1.8/framework/web/widgets/CTabView.php
Tabs in Agile Toolkit:
https://github.com/atk4/atk4/blob/master/lib/View/Tabs/jUItabs.php
Tabs in CakePHP:
http://bakery.cakephp.org/%20articles/view/4caea0e3-ac74-409b-8693-435282f0cb67
My conclusion is that the language in itself is OK, but a lot of badly written code is out there.
It is not supposed to be so. Monser-classes are always "bad" because it is hard to fix bugs / implement new features or maintain your code.
Just because people have written the code and made the source available doesn't mean that it's always going to be good code.
The principles you're used to (small classes that do their one thing well) is a good one. But not every developer follows those principles.
In the PHP world, a lot of people have worked their way up through it from the early days, when everything was in a single procedural monolithic block of code -- and I've seen some horrendous examples of that still in everyday use. Converting one's mindset from that to an OOP structure at all can be a big leap for some people, and even for people who haven't come from that background, a lot of the code examples they would be learning from are, so it's not a surprise to see monster classes.
The short answer is to write code the way you're comfortable with and the way you've been taught. It sounds like you've got better coding practices ingrained into you than most PHP developers out there, so don't feel you have to change just because other people are doing things differently.
Don't know if this answers your question but my experience is that it's quite common for PHP scripts and plugins like the calendar you mention to be constructed in the monster-class kind of way because of PHP's poor support of namespaces and encapsulation. The same goes for Javascript which also tends to have superbig classes in some cases (jQuery for example).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I want to learn features of java.util.concurrent libraries (so everything older, or non-java specific is no option for me).
I know basics and theory about concurrency and multithreading, I am not looking for theory.
I am now reading Java Concurrency in Practice. To be honest, I am quite disapointed of examples in this book. They're too short and simple and "dummy" for me. I am looking for some nice Java 5+ concurrency examples and exercies explained.
Is there something like that? I am quite afraid that If I don't use what I learned in JCIP very soon, I am going to forget it pretty much :/
Why not just search on GitHub (here is an example) ?
I have no affiliation, btw. But you can find projects that use "java concurrency" in the description or refer to the library in the code.
Another option is to think of your favourite Java frameworks. e.g. Tomcat or Quartz (though I don't know if they use Java 5 concurrency per se). Such frameworks would be excellent examples because it is real-world stuff.
definitely learn by making an application. for example, you could make your own real time online stock trading system or even an auction system. stuff like that that will thoroughly test your concepts. or you could participate in open source projects which focus on these types of applications..
I don't agree with your opinion of Java Concurrency in Practice, nevertheless, you might also want to look at "The Art of Multiprocessor Programming" by M. Herlihy and N. Shavait.
I recommend both books to understand more about the underlying principles of concurrency; rather than just skim read some code snippets.
Considering we are talking about "Shared state concurrency"
Look at the implementation of these two frameworks:
LMAX Disruptor :
They have very nicely used the concept of cache lines and ring buffers to achieve an extreme level of concurrency. Of course they are relying on atomic classes in concurrent utils plus their own ring buffer based concepts.
Google Guava Concurrent package:
They have decorated the Futures and Executor interfaces to offer real world concurrent event driven primitives. Underlying their framework is a good understanding of java concurrency classes and design patterns.
Shared state concurrency is not the only flavor, you may also like to check what Actor based frameworks e.g. AKKA are doing. This kind of concurrent programming is called message passing concurrency.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I like reading open-source code to see how particular problems have been solved, or simply to study how to create nice and clean code.
I was wondering if there actually was any good book out there that goes through excerpts of different (preferably in Java) open-source projects to show how patterns have been used and implemented, some nifty tricks, etc.?
Update: I took design patterns as an example, but it’s not really what I am after. I read a lot of open-source code, and I often find interesting ways of doing things which I didn’t think of before – my question is whether there is a book that shows some “cool” open-source code, a bit like how Clean Code uses FitNesse code to illustrate refactoring and other points.
Well, you can read just book about open source project, and authors can show what and how. E.g. I read Pro Spring 2.5 and there is even chapter called "Spring Patterns" with explanation of why and how they call files, directories, design patterns they use and invite you to use etc. Probably take a look at the books about open source projects you investigate.
UPDATE (just that paragraph insert to extend answer:) : as I told previously, you can look through the books about open source projects and find there information how this project is developed, architectural issues etc. Once I looked for real good example of "Open/Closed Principle" using, theory is nice but I would not say that it is so clear how to use it. The only book which helped me was Expert Spring MVC and Web Flow (I already pointed you to google books with that chapter I read). I didn't read the whole book, but I am sure it contains a lot of such things (what and how was used to make Spring done). From book Clean Code: A Handbook of Agile Software Craftsmanship I remember that there is a chapter, when they take a code from one open source project and make it better (unfortunately open source does not mean that it is good enough); that book also contain reference to how some other projects where written (e.g. jUnit). I don't know any book, which is completely dedicated to any project, there are just books where is "theory", and books about project which can have some explanation of what is inside. I would recommend books from APress (Pro and Expert series, afaik "beginning" books does not contain such explanation), and Packt Publishing - their main topic is open source.
UPDATE 2 (just can't stop :) Just remembered new series of books from OReilly "Beautiful ...." - I never read it, but I looked through. It actually consists of different stories behind development, real stories from life. I see there is also Beautiful Code: Leading Programmers Explain How They Think - I should contain what you need. Other "beautiful" books can be worth of your time too.
About patterns in general there are a lot of good books, and it depends on what exactly are you looking for. E.g. Head First Design Patterns is quite good to explain common patterns in fun way. If you need more, you can take a look at Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions to see how different applications, systems etc. can be integrated (and how open source projects do it too). Etc. Just specify what patterns or tricks do you want to read about, community will make its suggestion ;)
Some web links out of my bookmarks:
Anti Patterns Catalog - know what you are not going to do!
Design Patterns and Martin Fowler's Catalog - that's shortly about what is good to use and know about
SOA patterns - community site for SOA patterns (integration etc.)
And few more books to take a look at:
Head First Object-Oriented Analysis and Design
Agile Software Development, Principles, Patterns, and Practices
Code Complete - this book is just a bible of how to write code...
people, who develop open source definitely know what are those books about ;)
Hope that helps
UPDATE (25-05-2011) Just found one book, which I definitely going to buy, and I think it perfectly fits your question:
The Architecture of Open Source Applications
Architects look at thousands of buildings during their training, and study critiques of those buildings written by masters. In contrast, most software developers only ever get to know a handful of large programs well — usually programs they wrote themselves — and never study the great programs of history. As a result, they repeat one another’s mistakes rather than building on one another’s successes. This book’s goal is to change that. In it, the authors of twenty-five open source applications explain how their software is structured, and why. What are each program's major components? How do they interact? And what did their builders learn during their development? In answering these questions, the contributors to this book provide unique insights into how they think. Electronic versions of The Architecture of Open Source Applications for e-readers will be available for download soon.
Good question. But I doubt if there is a book based on a real project.
But to answer your "nice and clean" part, Josh Bloch's Effective Java is the right book.
I'm not sure if there's any Java examples (I own the books, but didn't bring them to school), but if you are looking for general advice on how to read code and assess its quality, you might be interested in Code Reading and Code Quality by Spinellis. Based on your question, I would suspect that Code Reading is more along the lines of what you want - it looks at how you can read unfamiliar code effectively before editing it, comprehending complex code, and so on.
Not a book, but might be helpful.
http://www.java2s.com/Code/Java/Design-Pattern/CatalogDesign-Pattern.htm
Best Java book out there is absolutely Head First Java, I have never seen/read a book as funny as this + it explains difficult things in the simplest and funniest form. But this book is a bit old, but I think it's okay if you're learning the basics of Java
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I've seen internationalization implemented in a classic ASP shopping cart as a most-massive monolithic dictionary of (int,String) key-value pairs, where the calling code passed the dictionary an integer representing which string was to be returned (binary-ORed with the desired language id) and the value for each unique int was the "internationalized" string.
This seems like a very, very, very horrible way to implement i18n.
I'm in the "pre-design" (if there is such a thing) phase for a Java-based Swing application that I would want to be internationalized. Not that I speak anything other than English (ha!) but it would be nice to expand into other languages in the future without having to refactor 20,000 strings.
So, this begs the question: what are the best practices surrounding Java-based i18n (and L10n for that matter)? What sort of classes & structures are used? Obviously, if this winds up as one big com.myproject.i18n package with an "Internationalizer" class as the common gateway for the rest of my code, I would want this to be a singleton class, yes?
Just a request for some food-for-thought here, any nudges in the right direction are greatly appreciated :-)
The idea is to work around properties files. They are easy to work with and you can extend this system easily.
You can find a nice answer here.
Netbeans have also a great sample tutorial.
After you get your languages right, you will need software to switch locales, localize dates and amounts etc. Kai Toedter' tools are very reliable. You can add these beans to your IDE and drag and drop them to your JPanels.
You can create your property file and insert them into iL10Nz.
In order to evoid context issues, it is good to have a scrrenshot for each strings that you are progressively creating. This will pay off with the languages you will translate into
Check http://www.myl10n.net
You can take a look at Gettext Commons. It's i18n in gettext-way for Java. It has Maven plugin for generating, updating and compiling PO files. Personally after some time of use found it's easier to go with standard ResourceBundles.
i using netbeans for developing GUI application based on Swing Application Framework [SAF]
and you can get powerful tools for internationalizing Project on Netbeans IDE.
look at this article : Internationalizing a GUI Form
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
So I apologize if I'm posting this in the wrong place but I thought asking the coding crowd would be best.
So I'm building a website with 3 developers. One dev is on front-end, one on PHP back-end and one on the database design. The core application of the website is actually much more complicated than i/we (the devs here) originally imagined it would be. The hardest part is in the database design and the design and development of the CMS to manage the database. Working closely with one dev, we have created the final version of the database. This is good news. Meanwhile, the rest of the site is being built with Zend with the other 2 developers.
Essentially what has happened is that the database designer that I have been working with has all the knowledge in his head because he worked with me consistently to design the DB by learning about the technicalities of the domain, industry terminology, the system requirements and so forth. He has also designed the CMS to manage the products that we will insert as per his data structure. Logically, he should really be the one then to code the core application because he knows deeply what he designed. However our system is in PHP and he's a Java dev. So I'm pondering what do to. He has agreed that he could learn PHP in about 2-3 weeks he estimated but admits that at the start, coding would be quite slow while he falls over a few times.
The lead developer on the other hand knows little about the requirements of the core app, the design of the database, the products and the business domain and would therefore take a long time to go through the same process of transferring all this knowledge until he's intimately familiar with everything. So its really a question of time. Would it be faster for a 6 year Java dev to learn PHP and build the core app or would it be faster for the 6 year PHP dev to pick up the knowledge from myself and the database dev?
Is it a close call? Is there a clear winner?
Any advice/suggestions?
Thanks
In essence I think that having experience of design and a good knowledge of how systems work is the most important thing.
Individual languages can be learned (and yes, there is a learning curve, while the syntax is absorbed, then the idioms, etc) and whilst having someone who knows a language when they start makes them a little quicker off the mark, I would choose someone with good design skills over someone with weaker design, but more knowledge of the language.
Language skills can be learned much more quickly than design principles.
In your situation, you have a problem. Two good people with different skillsets. Surely the ideal solution (if it's financially viable) is to have them work as team. Then both will learn much more quickly from the other where they are weak - and they'll be able to discuss design issues and rational. You should end up with a vastly superior product, and two developers whith enhanced skillsets and expanded experience. A win-win, if they can work well togther.
I agree with #Ragster - get the database guy and the UI guy to work together. There's even a buzzword for this - it is called pair programming.
But I'd add one thing. It sounds like a significant part of the problem is that the database guy has all of the knowledge in his head ... and there is nothing written down. This is not good. What happens if the database guy is run over by a green bus?
Maybe you need to make the database guy's number one priority to document the database design in a form that the UI guy can assimilate.
I would vote for using the experienced PHP dev rather than one new to PHP. Any experienced PHP dev should be able to take a brief from you and your colleague on what is needed and utilise the db design work already done.
A dev new to PHP will not produce code that is as well written as an experienced dev and that could cause you problems in the future.
The other solution would be to use Java for this application even if some of your other apps are PHP based. The two can live pretty well side by side.
I'd vote for the PHP-dev, working alongside the database/java dev.
That way, the database/java dev begins to get exposure to PHP, which will help his learning curve; while the PHP-dev will pick up the database structure and the all-important business rationale/details from the database/java dev.
You shouldn't create a dependency on any one person if you can help it, but distribute the application knowledge across your team. This way, you'll end up with a stronger team overall.
You should also ensure that the knowledge isn't maintained purely in anybodys head, but is documented. Always consider the dangers of a number 17 bus when all the knowledge is in somebody's head.
The nature of your question implies that you expect your programmers to develop in single-user mode throughout. I have honestly never met a situation where that was less appropriate than for you right now. Allow/instruct the obvious candidates to use pair programming, and the problem will simply dissolve into thin air. You will get better understanding within the team, faster results, better code, more unified solutions all around...
I am not being flippant here. If you have any historical or even ideological aversions to pair programming, please please please try to just get over them. It just is that much more efficient.