Keep your methods small and focused
I got a fair bit of criticism for this putting be modular as my last tip in my blod entry 10 tips on writing reusable code, in truth I couldn't really think of any more tips and I wanted 10. I have been thinking about this recently and thought I would perhaps try and explain what I meant be your code being modular.
I view modular code as code that is like a black box, you know what you what you pass into the module and you know what comes out but you don't know or care how it does it. Similar really to 3rd party pieces of code or code that Sun writes, why bother wasting your time knowing how it works but focus on writing the code that uses it.Modular code has a public interface to a class or classes. I view modular code as being almost stand-alone pieces of code.
Modular code should have few connections to other modules so it should have weak coupling. The effect of coding a module means you are writing a self contained piece modular object is that it doesn't have links to any other modules and hence the weak coupling.
I know that what I am describing is probably just good coding practise by
One of the benefits of writing modular code is you will end up with a lots of modules which you will be able to use in lots of different projects and use different modules together.
By using different modules to create your software you will also be able to control the changes needed in the future by managing future change. Modules will naturally result in changes have a smaller effect on your code because you will hopefully be able to isolate the change to just one or two of your modules leaving the rest of the code unaffected by change.
Another good use of writing modular code is when the code is using an external resource like a configuration file, database or some other kind of input file. By accessing the resource from the one module you can then change the input type or the processing of the input without any of the other code being affected because the other code only interfaces with the one module.
Modular coding also uses encapsulation and information hiding built into my definition of modular code
Well I hope I have described what I meant by modular coding and I appreciate that I basically mean using all the good OO coding standards that we are told to use but I see that as a good thing. It also not new but I am just replying to the comments on my blog rightly criticising the vague use of the word modular.
Below are the current podcasts available, I liked the topics because they are useful everyday things.
This is one of the more challenging areas of programming. It doesn't really involve doing much extra work at the time but the correct design decision can make your life so much easier in the future. It reminds me of one of the more memorable saying's
"closed for change but open for extension"
I have been looking at Auto Starting Tomcat on Linux the final piece of my adventures with Tomcat and Linux. The other parts of my Linux Journey are
Idiots guide to Installing Java 5 and Linux
installing two versions of Tomcat and finding out what ports are being used
Increasing the memory allocation for Tomcat
Anyway so back to autostarting Tomcat on Linux. I have looked at various articles telling me how to do it and I have basically taken the best bits of a few them. Here are the more helpful ones
http://www.sitepoint.com/article/jsp-quick-start-guide-linux/3
http://www.option-c.com/xwiki/Jakarta_Tomcat#Auto_Startup
http://www.informit.com/articles/printerfriendly.asp?p=336708&rl=1
I read the articles above and then went my own way stealing a bit from each of them
My understanding of Linux is very poor as you can guess by reading this document. Basically to auto start tomcat you need to copy a file into a directory where Linux will look for it on startup. I believe Linux looks in the directory
/etc/rc.d/init
#!/bin/sh
#
# Startup script for Tomcat
#
case "$1" in
start)
echo -n "Starting Tomcat "
JAVA5_HOME="/usr/java/jdk1.5.0_07" ;
JAVA_HOME=/usr/java/j2sdk1.4.2_04;
JRE_HOME=/usr/java/jdk1.5.0_07;
CATALINA_HOME=/usr/local/tomcat;
export JAVA5_HOME && export JAVA_HOME && export JRE_HOME && /usr/local/tomcat/bin/startup.sh
;;
stop)
echo -n "Stopping Tomcat "
JAVA5_HOME="/usr/java/jdk1.5.0_07" ;
JAVA_HOME=/usr/java/j2sdk1.4.2_04;
JRE_HOME=/usr/java/jdk1.5.0_07;
CATALINA_HOME=/usr/local/tomcat;
export JAVA5_HOME && export JAVA_HOME && export JRE_HOME && /usr/local/tomcat/bin/shutdown.sh ;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
I'm not exactly sure I need to create the JAVA5_HOME, JAVA_HOME, JRE_HOME, CATALINA_HOME but I know the Catalina.sh file uses these parameters and that file is usually called on startup so I thought I would play it safe. The start and the stop code as you can see calls the startup.sh and the shutdown.sh and this is pointing to my tomcat installation directory. I have the JAVA5_HOME because I have OC4J installed which uses the JAVA_HOME directory so I had to create a different variable.
Once I have created this file and named it tomcat, I then need to create the file links and place them in the correct directories and below is the instructions for that which are run inside a Linux terminal.
# chmod +x /etc/init.d/tomcat
# ln -s /etc/init.d/tomcat /etc/rc0.d/K91tomcat
# ln -s /etc/init.d/tomcat /etc/rc1.d/K91tomcat
# ln -s /etc/init.d/tomcat /etc/rc2.d/S91tomcat
# ln -s /etc/init.d/tomcat /etc/rc3.d/S91tomcat
# ln -s /etc/init.d/tomcat /etc/rc4.d/S91tomcat
# ln -s /etc/init.d/tomcat /etc/rc5.d/S91tomcat
# ln -s /etc/init.d/tomcat /etc/rc6.d/K91tomcat
This creates the file links which will be run automatically by the Linux system on startup and shutdown. You should check the file links have been creating correctly by going into the directories specified above and looking for the relevant files and making sure the file doesn't say link broken. Hopefully when you restart the machine tomcat will automatically be up and running.