Friday 29 March 2013

According to Wikipedia[1]:
“A paradox is an argument that produces an inconsistency, typically within logic or common sense.”
Every once in a while, it helps to do something that is totally unrelated to the field of Software Design. In my case I like to make the occasional wooden thing. In this case, I decided to build a wooden paradox.

Just to elaborate, I wished to make a wooden version of Curry's Paradox[2]. If you wish to know how the trick works, youtube[3] has some very good explanations.

This little project is one of the easiest I've made. (Quickest too)

Ingredients

• some wood, 1 cm thickness, made of glued-together-layers of wood
• different colour paints
• varnish
• magnets

Utensils:
• a fretsaw (I used an iron saw, because I'm short a fretsaw)
• glue
• sandpaper
• tapemeasure (essential)
• pencil
• paper (I used cm2 paper)
• scissors
• eraser
• brushes

The Making Of

Cut the shapes out of paper.

Mark the shapes on the wood.

Saw the shapes using the fretsaw.
Use sandpaper on the pieces.

Paint them.

Varnish them.

After drying, apply glue to the magnets and glue them to the shapes.

Done.

It's not rocket science!

Notes

I managed to make something appropriate using an iron saw instead of a fretsaw, and I do not recommend it. It's a pain to create 90 degrees corners.

Next time need to sandpaper more, as the edges were quite rough.

References

[2] Missing square puzzle
http://en.wikipedia.org/wiki/Missing_square_puzzle
[3] Curry's Paradox and the Notion of Area: Part I (Tanton)
http://youtu.be/eFw0878Ig-A

Introduction

I find it fascinating the way Java is being developed, and accrues different new features from other "newer" programming languages.

One of the things that struck me forcefully recently, is the progression of our beloved for Statement. So forcefully, that I had to make a blog about it.

Output of the programs listed below is always:
James Gosling is 57 years old.
Charles Babbage is 221 years old.
Alan Turing is 100 years old.
Donald Knuth is 75 years old.
Edsger Dijkstra is 82 years old.
Anyone interested in the Person.java class used, can find it here.

Version 1

This is the way we did it back in the old days. A counter for 0 until we reached the size of the list we wanted to iterate over. And every time we had to cast what we got out of the list, as the list contained Objects.

Version 2

Finally! A Collections framework! With default naming, so we could always more or less assume what the exact Contract was that the Collection adhered to, once we knew the name of the Collection used.

Version 2.5

Yay! No more casting, no more 'counters' and we can add a variable number of arguments to some of our collection framework methods.

Version 7

Small change, due to project Coin. We have a simpler notation for Generics.

Version 8

Lambdas, here we come!

Conclusion

The for-loop, while still a very important tool in the arsenal of the Developer, seems to have been relegated to the internals of the Frameworks. I would not be surprised if the for-loop will become used less and less.

Small note

Whilst trying to get Lambda functions to work, I made the mistake to download the OpenJDK snapshot from Oracle that does not actually contain Lambda syntax yet. Try [1].

References

The for Statement
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
Maurice Naftalin's Lambda FAQ
http://www.lambdafaq.org/
JDK 8 Features
http://openjdk.java.net/projects/jdk8/features
Java 8: The First Taste of Lambdas
http://zeroturnaround.com/labs/java-8-the-first-taste-of-lambdas/
[1] Java™ Platform, Standard Edition 8 Early Access with Lambda Support
http://jdk8.java.net/lambda/
Java Version History
http://tech-my-talk.blogspot.in/2013/03/java-version-history.html

Wednesday 13 March 2013

Databases

So, after several of years in the business, I've had the pleasure to learn a new database server in each and every new job. I consider it a happy coincidence.

Here's a list:
1999 - 2009 : Sybase ASE
2009 - 2010 : Microsoft SQL Server
2011 - now : Oracle Database Server
2013 - now : recently followed the course to learn the workings of the Postgres Pro Advanced Database Server of EnterpriseDB, which is based on PostgreSQL

And, of course, I've dabbled at home with MySQL, but then, who hasn't?

So, in total:
• Sybase ASE
• Microsoft SQL Server
• Oracle Database Server
• PostgreSQL
• MySQL

I should be expanding this list with some NoSQL databases, but currently no projects that fit the bill on hand.

Friday 8 March 2013

Recently I got into a tiff over the lack of CHECK CONSTRAINTS in MySql. The MySQL manual[1] says:
“The CHECK clause is parsed but ignored by all storage engines.”
They say it's best to use a Trigger to work around the problem. Luckily, I have the opportunity for my work to attend a course in Postgres Plus Advanced Server Database Administration.

Included in the course was a certification track. So, since the fourth of March 2013, I can now officially call myself an "EnterpriseDB Certified Postgres Plus 9.0 Associate". Yay!!!

I've made some notes during the course, and this here are some excerpts from them I feel were important enough to share.

Introduction

EnterpriseDB [3] provides a version of PostgreSQL, called Postgres Plus Advanced Server[2], that is very similar to Oracle Database Server in a lot of ways.

In fact, the PostgreSQL Server will attempt to contact your profile info via the internet upon startup, but if there is no internet connection it starts up regardless.

Support for

Postgres Plus 9.0 has support for the following features:
SQL
PostgreSQL supports most of the major features of de SQL:2011 standard (ISO/IEC 9075:2011 "Database Language SQL").[5]
schemas
there is a schema search path per database/per user, by default set to ['\$user',public], that indicates in what preference schemas are checked when a tablename is not prefixed with the schema
savepoints
make it possible within a transaction to "save" part of the transaction, so the entire transaction need not be rollbacked upon failure, but can be rollbacked to the savepoint.
log first, *then* the database
vertical table partitioning
divides different columns of one table across tables. Oracle syntax works, but can allow many more partitions
horizontal table partitioning
also called database sharding. Different rows of a table are stored in different tables. It's kind of a view of a couple of tables unioned together.
tablespaces
tables on different devices for concurrent io.
caching
caching of everything in memory
materialized views
a view that is actually stored as a table, which provides the advantage of having indexes and being quicker, and the disadvantage of being possibly out of date
synonyms
created aliases for database objects (tables, procedures, etc)
hierarchical queries
returns a resultset which is a flattened tree, based on a parent-child relationship defined in a CONNECT BY. It is possible to create queries that work on the node-level by using LEVEL (for example for indentation). ORDER SIBLINGS makes it possible to order all siblings under a common parent as you'd like.
database links provide links in the current database to tables in other (remote) databases that otherwise could not be queried.
optimizer hints
hints provided to update/insert/delete/select statements for influencing which query plan the optimizer will choose. The APPEND keyword for this is interesting. It forces an insert to be appended at the end of the table, not at the location of a (couple of) vacuumed record(s). This is handy for efficient bulkloading of data.
MSRs
send multiple requests of the database all at once, instead of each request individually. Minimizes network round trips.
functions
lets you embed functions that perform actions within a regular SELECT query. A common use is with "SELECT pg_reload_conf();" which reloads the configuration.
inheritance
define tables as inherited from other tables

Glossary

DBMS
DataBase Management System
fsm
free space map
hba
Host Based Access
MSR
Multi-Statement Request
MVCC
Multi Version Concurrency Control
OLAP
Online analytical processing
OLTP
Online transaction processing
QUEL [4]
old standard query language existing alongside SQL
RDBMS
Relational DBMS
STONITH
"Shoot The Other Node In The Head", just to make sure that the master, which went down, stays down after the slave takes over.
tid
tuple id, identification of a row in the table (a row in a table is called a tuple in Postgres)
vm
visibility map
WAL
xlog
transaction log

References

[1] MySQL manual 5.6 - CREATE TABLE
http://dev.mysql.com/doc/refman/5.6/en/create-table.html
[2] PostgreSQL
http://www.postgresql.org/
[3] EnterpriseDB/
http://www.enterprisedb.com/
[4] QUEL
http://en.wikipedia.org/wiki/QUEL_query_languages
[5] Appendix D. SQL Conformance
http://www.postgresql.org/docs/9.2/static/features.html