Processing is an open source programming language that has been around since 2001, and has steadily become a comprehensive alternative to proprietary software for the creation of images, motion graphics and teaching aid to students. This Java based language and environment allows you to quickly and easily create mesmerizing graphics in 2D and 3D that will quickly have you wondering what else you can do.
For a sneak peak at what you can do with Processing simply visit the examples on their official website. For myself I have a couple little projects in mind that i hope I find the time to work on soon. The first being the creation of a script to generate a simple 3D medieval castle out of bricks that the user would be able to rotate and examine via some basic mouse/keyboard interactions. The second being a little app to visualize my Google Analytics data over time for different variables. What fun this will be, now where o where will I find the time to play with this . . .
Resources
Data Visualization, Processing, Protoyping, Ruby-Processing
Over the lifespan of a software’s code source you will inevitably have to rename functions and properties of classes and maybe even remove them all together. This is not a major issue on simple projects but when your project is used by multiple applications then you may find that you need to keep these deprecated functions until other projects update their code to the new values. The Javadoc deprecated tag is how you mark a function or property as no longer in use and link to the new property or function to use.
The Deprecated Tag
The deprecated tag marks the current property or function as no longer in use. To use the tag simply add it into your Javadoc comments on its own line proceeded by the @ symbol.
/**
* VIEW - ACTION TYPE
* @deprecated
*/
public static final String VIEW = "View";
The Link Tag
When you mark a property or function as deprecated it is always a good idea to link to the new property or function by use of the link tag. You can link to a property/value in the current class or to a property/value in another class.
Link in the current class
/**
* VIEW - ACTION TYPE
* @deprecated replaced by {@link #ACTION_VIEW}
*/
public static final String VIEW = "view";
Link in another class
/**
* filters valid records
* @deprecated replaced by {@link com.test.TestClass#filter()}
*/
Resources
@deprecated, @link, Java, Javadoc
When working in applications that utilize a lot of variables I often come across interfaces containing nothing but constants. Instead of creating a class containing the constants the developers choose to define them in an interface that can be implemented by a class so that constants don’t need to be qualified to a class in the code. This is so widespread that it has been termed the Constant Interface Antipattern. To ease users into correctly defining and using interfaces Java introduced Static Import in version 1.5.
To help illustrate why people choose to use interfaces to define constants lets have a look at an example. Lets assume we have defined our constants in the following interface MyConstants.
public interface MyConstants {
public static final String PASS= "pass";
public static final String FAIL = "fail";
}
To use the constants one would have their class implement the interface:
public class BadConstants implements MyConstants {
private void outputResults() {
System.out.println("FAIL Constant is " + FAIL);
System.out.println("PASS Constant is " + PASS);
}
}
As can be seen in the example the reason people prefer to use this method is that they do not have to qualify the constant by instead using:
System.out.println("FAIL Constant is " + MyConstants.FAIL);
To make it easier for coders to write good code Java introduced the Static Import feature in 1.5. What this does is allow us developers to import static properties into the current class’s namespace effectively allowing you to not qualify the constants. This is down by use of the import static statement where you can import a single constant or all constants of a class.
import static com.example.MyConstants.PASS;
import static com.example.MyConstants.*;
To put it simply don’t define constants in an interface, instead create them properly in their own classes and if you really don’t want to qualify them then utilize static import to import the constants into your class.
References
Antipattern, Constants, import static, Interface, Java
For some reason I have the utmost trouble remembering how to do a single line or inline if else statement. This article is mainly for myself so hopefully I will remember the next time I want to do an inline if else statement.
The usual format for performing an if else statement is:
if( $val1 > $val2 ) {
// code executed if true
} else {
// code executed if false
}
If you are trying to set a variable to a value depending on a condition then it is often the case that an inline if else statement will be sufficient and easier to read. This is done by the use of ?. The full format is (condition) ? (true output) : (false output) or as an example:
$val = ($var1 > $var2) ? $var1 : $var2;
Code Snippets, How To, if, IF ELSE, Java, Tips & Tricks
How many times have you found yourself defining multiple find or search methods for obtaining data in your Web Applications. For example for a Users table you may have a findByName, findById, FindByEmail, and etc. Utilizing the iBATIS framework and SQL Maps we can have all these sql statements condensed into a single dynamic select statement.
To illustrate how this would be completed lets define our User table as the following:
| USERS |
| ID |
| USER_NAME |
| FIRST_NAME |
| LAST_NAME |
| PHONE_NUM |
| EMAIL_ADDR |
Traditionally to create the above find methods you would create a sql statement for each query. Using iBATIS’s Dynamic SQl we are able to add them all into one statement by use of the dynamic element. To help illustrate lets start with a basic select SQL Map.
<select id="User.find" parameterClass="com.mdbitz.model.User" resultMap="userMap">
SELECT *
FROM USERS
WHERE
FIRST_NAME LIKE #firstName:VARCHAR#
AND LAST_NAME LIKE #lastName:VARCHAR#
</select>
Using this simple map as a base we could extends it by adding a dynamic clause that only adds the where clauses if a property is set in the parameter object. To do this we would use the isNotNull element that outputs its content only if a property is not null. An updated dynamic map would look like:
<select id="User.find" parameterClass="com.mdbitz.model.User" resultMap="userMap">
SELECT *
FROM USERS
<dynamic prepend="WHERE">
<isNotNull property="firstName" prepend="AND">
FIRST_NAME LIKE #firstName:VARCHAR#
</isNotNull>
<isNotNull property="lastName" prepend="AND">
LAST_NAME LIKE #lastName:VARCHAR#
</isNotNull>
</dynamic>
</select>
Using these dynamic statements you could extend this to do any type of find by that you need. You could query by name, phone number, email, id, or any combination of them. In addition to the property you could also use isNull, isEmpty, isNotEmpty, isGreaterThan, IsGreaterEqual, and etc. Instead of dozens of SQL Map statements for each desired search or query. Dynamic SQL allows you to condense your sql query into simpler more robust statements.
Resources
DAO, Dynamic SQL, iBATIS, Java, SQL, SQL Maps