Programming Pitfalls
Below you will find answers to some annoying troubles I've had in my adventures in programming. It's amazing after so many years that there are so many undocumented features or little support for common features. But, hopefully my hours of frustration over what should be trivial things will serve you well. I'll probably add other helpful tips that others I've encountered have encountered as well.
Java RMI
Just don't...(I'll have to update this section again when I remember more...)
Setup
- There's a very long procedure, make sure you follow it to the letter (I may post it here later)
- Ensure the permissions are set correctly for your public_html directory
- You need to run a rmiregistry on each machine (at least that's what I remember...)
Usage
- Stick to straight Java Classes for parameters and return values
- Otherwise, setting up stubs will be a nightmare...
Java Sockets
Ensure that when setting up Input and Output streams that their order is opposing on the client and server otherwise both will hang. It didn't seemed to be documented anywhere and was a big headache.
Externalization
Externalization is a useful tool to save space in a network object. Normaly when you serialize a message in Java it saves everything (variable names, method names, etc...). This wastes a lot of space if you know the structure of your object.
However, externalization needs to have a blank empty constructor myclass() { } in order to function properly.
Java Spread
Setup
- It seems to help to have a daemon running on each machine.
- The config file needs to be tab delineated.
- It's also easier if all the machines are on the same subnet.
Usage
- The SpreadGroup object can only join one group, it may not always leave the group.
- When replying by adding the sender group, it will respond to all clients in the same network group (if you're on a local subnet, that means all clients!)
Java Swing
The eclipse form designer is very helpful, but doesn't seem to work so well on McGill lab machines.
Images
- Are very annoying.
- Using a class loader can help make things relative to the current path, but make sure to know where your class files are (especially in eclipse!)
- Remeber that case matters in *nix
List Boxes
- Make sure to use a ListModel if you want to add to the list, the DefaultComboBox Model works well
- When retrieving the item, you need to use the JList's getSelectedIndex not the ListModel's.
Java
Classes
- instanceof is evaluated at compile time, for dynamic class checking use class.isInstance(obj)
- Dynamic Class Instantiation:
Class c = Class.forName("ClassNameString"));
Constructor cons = c.getConstructor(param1.getClass());
ActualClass obj = (ActualClass)cons.newInstance(param1);
Minueto
Compiling
- Strange Unsatisfied link error for AWT: ensure that you're using the jogl libraries included with Minueto
Python
Strings
- the .center method is useful for console based applications
- don't forget you can use .endswith to check file extensions easily
Lists
- You can use .remove(element) to remove a specific element in your array without knowing it's index
- You can use .index(element) to get the index of a specific element in an array
- The random stdlib contains a randomize array function: shuffle(array) (in place)
Win32 Console Lib
- The ButtonPress event is just "Button" with the .state variable set to True, it's false if it's the Release event
Eclipse SVN
General Issues
- Make sure in your Eclipse settings (Window->Preferences) to select SVNKit (Pure Java) under the Team->SVN settings branch.
- Wireless connections can sometimes be too unstable for the precision of large SVN data. If you're having a lot of trouble, try a wired connection.
Malformed Data Exception
- Make sure to update to the latest version of subclipse: http://subclipse.tigris.org/update_1.0.x
- If using Eclipse v3.2 use this link: http://subclipse.tigris.org/update_1.2.x
Folder " doesn't exist
- You might have a bad network connection, try another wireless access point or wired connection
- If your repository is empty, don't click to browse deeper into the repository
Google Gadgets
Required Properties Must be set
- Don't set hidden property fields to be required
Inline Gadget can't be rendered in iFrame
- This can happen if you're trying to preview a complex gadget
- It can also happen if Google fails to retrieve your gadget from its URL