Monday, March 5, 2012

Principles of Programming

Principles of Programming

1. Model everything in the user domain and the programming domain as an object. It provides a useful paradigm for program organization, remembering what each part does, and conceptual chunking.
2. Always use constants and enumerations.
3. Create unit tests to guide development.
4. Create print method for each class.
5. Create standard exception handling method.
a. Easy at highest level to capture all exceptions.
b. Exceptions themselves should contain information on how to handle themselves.
c. Handlers can decide how to handle exception, i.e. output to stdout, logfile, abort, or html error message.
6. Document (almost) every class and method – except for functions whose description can be determined by convention, i.e. getter/setter.
7. Document even functions that seem redundant with their name, just to show that they actually do what their name implies.
8. Learn how to use the source level debugger and the IDE and other programming tools.
9. Keep a log of what you are doing – hardcopy, in a notebook.
10. Make system with minimal features for each stage of development.
11. Make system extendible for future stages of development.
12. Write install document as you do development, so that you remember to write down what is needed to get going in the environment. Later when you are expert you may make too many assumptions.
13. No global variables for the program. Some may be used for testing or runtime environment, to save typing.
14. If you need global variables, you really need an “application” class. Imagine that you have 2 instances of the application running in another module – will it work?
15. Let the app class know about everything (i.e. root of a tree of information that encompasses the program) and let everything know about the app tree (directly or indirectly, through it’s parents/ancestors).
16. (to be continued)

Friday, July 22, 2011

Why Process?

I'm beginning to understand why software companies have process. It isn't because you have bad programmers on your team. Usually you have a few great ones, a lot of good ones, some average ones, and the occassional bad one. But any one of them can mess up the system on any given day, and it isn't necessarily the bad programmers who are the worst offenders -- sometimes it's the great ones.

Friday, April 22, 2011

Netbeans API

Netbeans API
- tutorial - learning trail
- tried first example, didn't run until added more libraries
- do not see the System.out.println result

Tuesday, April 19, 2011

SVN Import

svnadmin create /usr/local/svn/newrepos
$ svn import mytree file:///usr/local/svn/newrepos/some/project \
-m "Initial import"
Adding mytree/foo.c
Adding mytree/bar.c
Adding mytree/subdir
Adding mytree/subdir/quux.h

Committed revision 1.


So much better than the headache of figuring out CVS Root syntax

Monday, April 18, 2011

Hibernate Notes

Hibernate Notes
1. Develop a system that displays, allows add, delete, and modifications
New Project
2. Web Application,
3. select Hibernate and Java Faces frameworks,
4. choose correct database
hibernate configuration
1. open hibernate.cfg.xml
2. add,
a. driver_class,
b. url, jdbc:mysql://localhost:3306/databaseName
c. username,
d. password if not there
3. Optional Properties
a. Configuration properties
i. Show_sql – true
4. Miscellaneous properties
a. Current_session_context_class – thread
Create filviewer package in Soruce Packages
i. Use File->Hibernate->New HIbernateUtil (or somewhere in there)
ii. Put in Source Packages in package filmviewer
Reverse Engineering
i. Go to default package
ii. Open up New file->Hibernate->Hibernate reverse engineering wizard
iii. Use src/java
iv. Add tables from database
Mapping POJO’s
i. Use File->Hibernate->Hibernate Mapping Files and POJO’s from Database
ii. Use
a. JDK5.1 language,
b. hibernate.cfg.xml ,
c. hibernate.reveng.xml,
d. domain Code,
e. Hibernate XML Mappings
Session Bean
i. Use File->JavaServer Faces->JSF Managed Bean
ii. Use either Request Scoped or Session Scoped as appropriate.
iii. Edit:
a. Import Org.hibernate.Session, Query, Transaction, java.util.*
b. Cache HibernateUtil.getSessionFactory().getCurrentSession() in an instance variable
c. Helper Methods
private Session getSession() {
return HibernateUtil.getSessionFactory().getCurrentSession();

private Transaction beginTransaction() {
return HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();

private Transaction getTransaction() {
return HibernateUtil.getSessionFactory().getCurrentSession().getTransaction();
public List view() {
try {
Query query getSession().createQuery("from Film");
List< POJO > result = (List< POJO >) query.list();
return result;
} catch (Exception e) {
return null;
public void add(String title, String description) {
try {
POJO film = new POJO ();
} catch (Exception e) {
public void delete(int id) {
try {
Film film = (Film)getSession().get(Film.class, id);
} catch (Exception e) {

public void update(int id, String title, String description) {
try {
Film film = (Film)m_session.get(Film.class, id);
} catch (Exception e) {

Running Methods/Accessing View
a. Edit Web Pages/index.xhtml
b. Add xmlns:f=

1. Helpful to run server from console using glassfish\bin\startserv so you can see stacktraces in terminal window.
Example of how to create a table with autoincremented primary key
title VARCHAR(255) ,
description VARCHAR(1000)

What to plan before starting development on a project?

[someone asked this on - my response]

Most important thing to do: review the specs, interact with customer to get more refined specs.

The requirements are undoubtedly incomplete, vague, or incorrect. The biggest waste of time is doing the wrong thing. Customers are not professional software engineeers, and cannot be expected to be good at developing a good set of requirements.

So, you should review the specs, interview the customer and find out if this is what he/she really needs and wants, and can afford, etc.

Develop test/use cases and review with customer. If a requirement isn't testable, throw it out.

Develop the design and make sure if all the pieces function correctly that it would in theory do what you need.

Develop an architecture prototype that tests all of the technology to be used in every layer but ignore functionality. You are testing the architecture, not the functional specification. Having the wrong architecture will mean you have to rewrite everything, so getting the right architecture is important. Make sure it can meet your requiremenets for speed, efficiency, security, etc.

Tuesday, April 12, 2011

How to delete a windows service

1. Run Regedit or Regedt32

2. Find the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"

3. Look for the service there and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).