A Software Engineer's Daily Musings

I write this blog to share the solutions and problems I have found with fellow software engineers. I also do it to remind myself of what I've already figured out ;)

Friday, April 10, 2009

What is Software Engineering?

This question has consumed me lately. People everywhere are calling themselves software engineers or the even more popular "software architect", but what does that mean. It's easy to give a flippant response such as:

Software engineering is the application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software, and the study of these approaches; that is, the application of engineering to software.

This comes straight from the SWEBOK, but that thing was written almost five years ago, which is of course decades in software time.

The application of engineering to software. Okay, I know what software is. Engineering? That's another nut to crack. Software engineering is nowhere near mature as civil, mechanical, or electrical engineering. We don't have the "CRC Handbook to Software Engineering". Grady Booch is starting one on Software Architecture, but that's not our topic here. Mary Shaw, from CMU, published a great article on the maturation process of engineering disciplines and where software engineering is in that process entitled, "Prospects for an engineering discipline of Software".

I think the biggest disconnect is between industry and academia. Practitioners on a daily basis don't care about this question, we just code up a solution using best practices. Professors on the other hand spend all day theorizing about new ways to do software engineering, but don't face the same pressures as practitioners to actually make their stuff work. Steve McConnell, in his legendary book "Code Complete", was able to bridge the gap and bring academia's ideas to practitioners. We need more like him. The Gang of Four were able to write the closest thing we have to a "CRC Handbook" with their design patterns book.

Maybe software engineering is not the best term. Software developer and architect are getting a whole lot more airtime lately. For me, "Developer" brings up connotations of a real estate developer just putting up strip malls. I'm betting that software engineering will stand the test of time and come out as the dominant term (I'm getting my MS in it after all). In the meantime, I think it is fruitful for us all to think about what that actually means, even if only for five minutes. And then get back to coding before we all get fired! :)

Wednesday, February 13, 2008

Flex vs. GWT

I recently had the chance to create a prototype of a Rich Internet Application (RIA) similar to geni.com. Having done mostly pre-Web 2.0 development up until this point, I went to research what would be the best technology or tool for the job. I honed my sights on the Google Web Toolkit (GWT) and Adobe's Flex.

I first started with the GWT. I was very impressed by what Google had done, as I usually am. In short, the technology allows you to write AJAX sites in Java. Google provides a "compiler" that takes your Java and outputs it to the right AJAX (mostly JavaScript) technologies for different browsers. Google has provided a bare minimum of components such as a textbox, drop-down box, etc. They rely on third-parties to create more elaborate components to use in your sites.

The GWT falls right into Google's theme of simple, usable, terse GUI's (e.g. G-Mail). This works well for some applications. Plus, you are able to leverage past Java skills in writing your new sites. Letting Google take care of the browser compatibility problems with AJAX is a definite advantage. The Java aspect also aids in code maintenance, which is an area where I feel most AJAX frameworks still have a lot of maturing to do.

My prototype was a family tree application and called for vector graphics, so the GWT did not work well for this; because at the end of the day you are still constrained to the HTML tags provided to you. Adobe Flex however is not constrained by HTML and picks up where Java applets left off. Back in 1995/6, Java applets were suppose to be the next best thing, but for a variety of reasons (e.g. the Browser Wars), they never gained a foothold. Enter Flex and the Adobe Flash Player, which is installed on aprroximately 95% of all browsers (according to Adobe's statistics). The Flash Player becomes the Java Virtual Machine that applets used to have. You can now write applications that run entirely on the browser or are just a thicker client.

Adobe's first attempt at an IDE for Flex was an abject failure. Smartly, they took the popular Eclipse platform and provided plug-ins for it to be the new Flex IDE. Flex uses MXML to be their markup language and also provides some out-of-the-box components. The real power of Flex, however, is unleashed when you start to use ActionScript 3.0. This is what MXML is really made of, and it allows you to create all kinds of new components based on 2-D graphics. ActionScript 3.0 is based on the ECMAScript standard (JavaScript's standard), so it is relatively easy to learn and a very powerful scripting language with strong typing and object-oriented features. While, I did not get to use their back-end capabilities for my prototype, I was impressed how Flex could integrate with both Java EE and .Net sites.

As a footnote, Microsoft has tried to duplicate Adobe's Flex framework with Silverlight, but their main problem is browser penetration (which is very low right now). It is never easy to predict the future in Web technologies, but I believe the Abode Flex framework will begin to used more and more for desktop-like applications running over the Internet. It is the best option available right now and their 3.0 version will be released soon. And if you're from the "Show-Me" state, travel over to the Flex showcase to see their technology in action.

Thursday, June 28, 2007

Example of javax.swing.Timer

*
* MainFrame.java
*
* Created on June 27, 2007, 9:15 AM
*/

package main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;

/**
*
* @author Woody
*/
public class MainFrame extends javax.swing.JFrame implements ActionListener {

static Thread thread1;
static Logger log = Logger.getLogger("MainFrame");
static StringBuffer log2 = new StringBuffer();
static Timer t;

/** Creates new form MainFrame */
public MainFrame() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
private void initComponents() {

}//


private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

thread1.interrupt();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
thread1 = new Thread1();
t = new Timer(100, this);
t.setDelay(100);
t.start();
thread1.start();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

new MainFrame().setVisible(true);
}
});

}

public javax.swing.JButton getJButton1() {
return jButton1;
}

public void setJButton1(javax.swing.JButton jButton1) {
this.jButton1 = jButton1;
}

public javax.swing.JButton getJButton2() {
return jButton2;
}

public void setJButton2(javax.swing.JButton jButton2) {
this.jButton2 = jButton2;
}

public javax.swing.JButton getJButton3() {
return jButton3;
}

public void setJButton3(javax.swing.JButton jButton3) {
this.jButton3 = jButton3;
}

public javax.swing.JScrollPane getJScrollPane1() {
return jScrollPane1;
}

public void setJScrollPane1(javax.swing.JScrollPane jScrollPane1) {
this.jScrollPane1 = jScrollPane1;
}

public javax.swing.JTextArea getJTextArea1() {
return jTextArea1;
}

public void setJTextArea1(javax.swing.JTextArea jTextArea1) {
this.jTextArea1 = jTextArea1;
}

public void actionPerformed(ActionEvent actionEvent) {
jTextArea1.setText(log2.toString());
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

}

Friday, June 22, 2007

Using javax.persistence and SQL Server stored procedures

EntityManagerFactory emf = Util.getEMFFactoryCoreRDSce();
EntityManager em = emf.createEntityManager();
Query q = em.createNativeQuery("EXECUTE dbo.getNationalCEDCount");
Vector i = (Vector) q.getSingleResult();

Sunday, June 17, 2007

Producer Consumer Example using Java.Util.Concurrent and a CompletionService

Blogger screws up indentations, so sorry the source looks ugly. The code does work however.

Main Class

package test;

import java.util.concurrent.*;

public class Main {

public static CompletionService cs;
private final static int poolSize = 4;
public static volatile int counter = 1;
/**
* @param args
*/
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(poolSize);
cs = new ExecutorCompletionService(pool);
(new Producer()).run();
(new Consumer()).run();
}

}

Producer Class
package test;

public class Producer extends Thread {

@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("Submitting Task " + i);
Main.cs.submit(new Task1(i));
}
}

}

Consumer Class

package test;

import java.util.concurrent.ExecutionException;

public class Consumer extends Thread {

@Override
public void run() {
int i = 0;
while(true) {
try {
Integer j = Main.cs.take().get();
i++;
System.out.println("Took out task " + i + " with result:" + j);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

Task Class

package test;

import java.util.concurrent.Callable;

public class Task1 implements Callable {

int id;

Task1 (int i){
id = i;
}

public Object call() throws Exception {
Thread.sleep(1000*Main.counter);
Main.counter++;
System.out.println("In Task1 and just iterated counter to:" + Main.counter);
return Main.counter;
}

}


Tuesday, November 28, 2006

The debate on Stored Procedures

An recent article I read discussed the issue of using stored procedures versus straight T-SQL statements. The author threw out some pros and cons but basically asked readers to give their thoughts. So here are mine:

I was brought up in the world of programming to always use stored procedures when accessing a database from a client program. The advantages were clear I was told:
  1. The stored procedure was pre-compiled and therefore would run more quickly.
  2. The store procedure provided better security through the use of the keyword GRANT.
  3. The stored procedure protected against SQL injection attacks.
  4. The stored procedure easily allowed me to pass parameters to my T-SQL.
I'm sure there are other advantages but those are all I remember at the present moment. Now, about three years later I am starting to question the "Stored Procedure Law". One of the biggest reasons is something I was little aware of in my earlier programming career called "Configuration Management". You have to get your stored procedures promoted from the development environment to production to insure that your code will work when it calls them. However, if you just write sure simple T-SQL in your code, you do not have to worry about this issue. This can be a huge advantage when the PM comes to you and says "Why is this not working?!!?".

Plus, let me give countering views to the four points I listed above in favor of stored procedures:
  1. I am not so sure actually that the store procedure is precompiled. Possibly someone can point me to a link that clears this this issue up for me. I have heard arguments both for and against when it comes to SQL Server. Regardless, when you are running a simple select statement the time that it would save is inconsequential to the performance of your overall application. Hence, this is a moot point.
  2. This is not true when .Net security is used correctly, especially when the right user permissions for the process running the application is in concert with Windows Integrated Authentication. Also SQL Server 2005 adds extended functionality to schemas, which can restrict the connecting client application to only access certain tables and perform certain functions.
  3. This point seems deceivingly true. But when looked at more thoroughly, if a hacker is able to exploit a poorly written T-SQL statement in your code they will be able to equally do so even if it is contained in a stored procedure. The answer here is to validate all user input and to carefully write all T-SQL statements.
  4. This point is true at first but again becomes moot when you learn how to pass parameters to a T-SQL statement in your code.
Well, that is my present opinion on the matter, but I am sure that it will change as time passes. Thanks for reading (my audience of one ;).

Eclipse

Today I did some programming in Java with the Eclipse IDE. I've been using Eclipse for about two months now, and I am really impressed. Having come from the Microsoft world and using Visual Studio .Net, I must say that my expectations were rather high. The learning curve for eclipse was rather steep, but I would expect that of any world-class IDE. I know that many C# developers out there are probably incredulous of what I'm saying, but I challenge them to give it a wholehearted try.

I used the book "Eclipse Distilled" to learn how to use eclipse, and I highly recommend it. The book was neither too short nor too long. It used a demonstration project as a learning guide, which helped immensely. Also after reading the introductory chapters you could choose from which chapters you would like to read a la carte.

Eclipse has all of the features that Visual Studio .Net has and then some. Plus, the developers are constantly adding new ones as their need becomes apparent. Visual Studio .Net has long release cycles (usually one to two years) that are at the sole discretion of Microsoft. Eclipse is also a platform, in that plug-ins can be developed for just about anything. Plus, you can use Eclipse as the foundation for your own application, much like a browser such as Firefox provides a GUI foundation for client/server applications. After going back to Visual Studio.net, I found myself saying many times: "Why doesn't Visual Studio have that? Why doesn't Visual Studio have this like Eclipse did?"

Finally, Eclipse also help me to see how customizable IDE's really are. I know it's rather simple, but being able to map Ctrl-L to do the same thing in two different IDE's helps my productivity immensely. Before eclipse, I usually just took Microsoft's defaults to be the one and only way. After Eclipse, I customize my shortcuts, perspectives, toolbars, etc. I feel I have been freed from one of Microsoft's shackles.