Posts

Showing posts from 2013

Comments: A deodorant to mask code smells

Image
Don't get me wrong. Comments are useful and not all of them have the olfactory purpose of the famous analogy I'm using in this article's title. So, what's so wrong about comments that programmers are willing to even dress a shirt about this odorous matter? Let's say we have this fragrant method:




 nastyMethod() {
  // connect to database
  ... Code to connect to the database ...

  // create default configuration
  ... Code to create the default configuration ...

  // load configuration
  ... Code to load the configuration ...

  ... and more, and more, and even more of this...
}

The problem here is that the comments are saying what the code is doing. Comments should say WHY the code is doing something, not WHAT the code is doing. Moreover, this typically leads to the Long Method anti-pattern putting in risk two basic OO design principles: Interface Segregation Principle and Single Responsibility Principle to say the less.

Make your code self explanatory:

 betterMethod() {

  co…

Book Give-away: Hold a chance to win free copy of the book "Vaadin 7 UI Design By Example", just by commenting!

Image
And the winners are:
Iskael Diaz MarquezCamilo Gonzalez Packt Publishing has two copies of Vaadin 7 UI Design By Example to be given away to two lucky winners.

How you can win:
To win your copy of this book, all you need to do is come up with a comment below highlighting the reason why you would like to win this book.

Please note: Winners residing only in the USA and Europe would get a chance to win print copies. Others would be provided with eBook copies only.

Duration of the contest & selection of winners: The contest is valid up until October 5th7th 12th, and is open to everyone. Winners will be selected on the basis of their comment posted.  About the book:
This is what Packt Publishing says about the book:Vaadin 7 UI Design By Examplewritten by Alejandro Duarte, is an engaging guide that teaches the user how to develop web applications in minutes. This book shows the user how to use Eclipse, Netbeans, and Maven to create Vaadin projects. It then demonstrates how to use labels, text…

Lightning fast commenting (in and out)

Image
I have used this two or three times in my life but it's one of those simple (and useful?) hard to forget tricks. It could be useful during tough debuging times. If you have several lines of code and you want to comment them out, you can use standard multi-line comments (this is for C++, Java, and others):     /*
    Component contentArea = getContentArea();
    layout.addComponent(contentArea);
    layout.setExpandRatio(contentArea, 1);
    //*/ But you can also comment out the first and last lines using single-line comments:     //*
    Component contentArea = getContentArea();
    layout.addComponent(contentArea);
    layout.setExpandRatio(contentArea, 1);
    //*/ Now you can comment in and out your code just by removing or typing the first "/":
CAUTION: Avoid usage in programmers with chronic lava flow disease, including junior and senior developers.

Empty lines and semantics in source code

I remember a couple of years ago, while working with some developers, one of them seemed to be irritated by seeing empty lines in source code. I think he was missing an important dimension of software: Readability. Grab a book nearest to you. Go ahead and do it. Grab any book close to you. Open it on any page. Are there any blank spaces between lines? If you didn't take a book for kids, empty lines will emerge like crack in the 80's making paragraphs easier on the eyes (instead of making them red). Speaking of the devil…

I feel better now*. Just as empty lines break ideas up in text books, empty lines in source code offer a new dimension for structuring code. It’s like something that the developer wants to say about the code. Almost like nonverbal communication. I’m exaggerating, but really, use empty lines to separate related lines of code when "extract method" gets to the limit.

Perfectly refactored code will have only one line per method, which is absolutely a boo…

Enterprise App now available with Maven

Image
Finally! I've managed to write a Maven POM for Enterprise App. Just add this into your pom.xml file:

<dependency>
    <groupId>org.vaadin.addons</groupId>
    <artifactId>enterprise-app</artifactId>
    <version>0.4.0</version>
</dependency>

You might need to add the official Maven repository for Vaadin addons as well:

<repository>
    <id>vaadin-addons</id>
    <url>http://maven.vaadin.com/vaadin-addons</url>
</repository>

Better late than never ;)

A strategy to manage large SQL tables

Some months ago, I got involved in a project where I needed to generate quite big reports (more than 1 million rows) extracted mainly from an SQL table growing at a very fast pace. This table played a central role in the everyday usage of the system.

In order to avoid losing performance, we scheduled a database backup and a process to empty that large troublesome table every 3 months. But the problem with the reports remained the same. At some point we ended up with a table with more than 3 million rows and sometimes we had to generate reports with more than 1 million rows. Even if the report was small, querying this table was taking way too much time (some times more than 10 minutes).

Here is what we did. First we decided to design kind of an ETL process using only SQL (somebody will argue that this is not ETL, but I think it is). How? We developed a module to execute SQL scripts defined at run-time every day at 3:00 am.

These scripts were basically "insert into table" stat…

Pagination: An old web 1.0 solution

Image
A few days ago, an Enterprise App user asked me if lazy loading is better (particularly in a buisiness application) than pagination. My answer: Totally! Pagination is an old, so called, web 1.0 solution. At that time, no AJAX was possible at all.

It's not very usable to have a lot of 1, 2, 3, 4, 5, 6, ..., 100 links. Lazy loading รก la Vaadin is not only easier to use but to understand for the end user. If a user sees a scroll bar, they will understand that scrolling that thing will cause the rows to, well... scroll. No need for further explanations about it (is there any explanation to make?). Chances are that pagination will cause some novice users to get lost, at least the first time they use the software.

Sometimes scrolling through the entire data set is certainly necessary and pagination could make that task a pain in the neck. I think pagination is OK if we have, let's say, seven pages at most (tanks Miller). If the number of pages is uncertain at design or development …

Hello GitHub

I have been a ProjectLocker and Assembla user for years. They both offer excellent tools for software projects management. However, now I'm moving to GitHub, 'cause you know, I'm becoming kind of an open-source activist (don't take that too serious, it doesn't mean that I'm pretending to be the next Stallman or anything). GitHub seems to be better suited for social open source projects.

I have written my share of code, so it's time to give something back to the World (also, I'm publishing all that code to raise my developer career but it doesn't sound like the thoughts of an open-source activist). Check it out, tons of code for you: QBasic, C, C++, PHP, and Java (mostly Java), and some projects using well known Java technologies such as Spring Framework, Hibernate, JPA/TopLink, Struts 2, SiteMesh, DisplayTag, Vaadin, and Enterprise App).

Enterprise App users! now you can follow the add-on development here. I will migrate all issues and tasks to GitH…

My brand new web site

Image
As some of you already know, I will be making a big noise about Enterprise App and InfoDoc Pro next month. Big noise without a new website is not worthwhile. So I acquired a hosting service (no free advertising for them right now), a new domain (alejandrodu.com), and a bunch of new ideas to make Enterprise App and InfoDoc Pro shine like a golden Java coffee cup (or at least like the yellow one in the picture).

So far, Enterprise App has more than 600 downloads at Vaadin Directory and I'm aware of more than 15 projects using it worldwide. I would like to thank all license buyers for supporting this web site as well as the add-on itself.

InfoDoc Pro is currently near a stable release version. Thanks to Thota Software Solutions, Aio Technology S.A.S. and Colombitrade S.A.S. for all the feedback and financial support for the project.

Originally posted on January 15, 2013 at http://www.alejandrodu.com/blog/my-brand-new-web-site.