Wir sind die Technology Scouts. Wir finden neue Lösungen für alte und neue Herausforderungen.

Gute und schlechte Programmierer

Charles H. Moore in einem Interview zu einem neuen Buch von O'Reilly:

Ein guter Programmierer schreibt schnell guten Code. Guter Code ist korrekt, kompakt und lesbar. "Schnell" bedeutet Stunden oder Tage.
Ein schlechter Programmierer wird über das Problem sprechen wollen, Zeit mit Planung statt mit Schreiben verschwenden und auf dem Schreiben und Debuggen von Code seine Karriere aufbauen.

Würde ich vielleicht nicht ganz so unterschreiben wollen, aber es ist ein Denkanstoß ...

New Geek magazine from Pragmatic Programmers

Publisher Pragmatic Programmers has launched sort of an agile published magazine called PragPub distributed for free in pdf, epub and mobi format. Consequentially the first issue is called first iteration. Editor of the magazine is Michael Swaine, former editor-in-chief at Dr. Dobb’s Journal.
The magazine features high quality articles expressly for the magazine. Attached to each article is list of directly linked useful links. The main articles are:


  • The Layoffs Are Coming!
    How to Keep Your Tech Job by Andy Lester

  • Why Clojure?
    Rich Hickey interviewd by Michael Swaine

  • When Things Go Wrong
    Clojure’s Exceptional Handling of Exceptions by Stuart Halloway

  • Pragmatic Publishing
    Dave Thomas (one of the owners of Pragmatic Programmer) interviewd by Michael Swaine


The set is completed by Welcome to Prag Pub (intro to the magazine), Up Front (Editorial), Choice Bits (tweets, posts and chatter on every topic in the world), How Do We…? (have a look behind the curtain how PragProg does business), Swaine’s World (in which Michael Swaine loses his job and offers you career advice), The Quiz (geeky quiz about lesser known programming languages), Shady Illuminations (column by John Shade on Microsofts Bing) and Calendar (geeky events).
Its well written, informative, high quality and just fun reading. And by the way Michael Swaine is one of my early computer science heroes from his time with Dr. Dobb’s Journal.

Mysql Profiler

Nearly unnoticed from most people, there's now a profiler built into every mysql database beginning with release 5.0.37. It profiles the steps of the SQL engine and can help to solve performance issues. Usage is very simple:

set profiling=1;

After that statement MySQL will start to maintain profiling information in a table in the information_schema schema, called information_schema.profiling. For the examples I will use a table called testo1:
CREATE TABLE testo1 (
id int(11) NOT NULL auto_increment,
name1 varchar(20) NOT NULL,
PRIMARY KEY (id));

and a view called v1:
create view v1 as select * from testo1

Now lets try some select statements:
select * from testo1;
select * from v1;

And see what we get:
mysql> show profiles;
+----------+------------+----------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------+
| 1 | 0.00964100 | select * from testo1 |
| 2 | 0.00099800 | select * from v1 |
+----------+------------+----------------------+
2 rows in set (0,00 sec)

Thats OK, but we want a closer look into each query:
mysql> show profile for query 1;
+--------------------+------------+
| Status | Duration |
+--------------------+------------+
| (initialization) | 0.00003200 |
| Opening tables | 0.00001000 |
| System lock | 0.00001300 |
| Table lock | 0.00000800 |
| init | 0.00001400 |
| optimizing | 0.00000400 |
| statistics | 0.00001300 |
| preparing | 0.00000800 |
| executing | 0.00000400 |
| Sending data | 0.00069000 |
| end | 0.00000700 |
| query end | 0.00876200 |
| freeing items | 0.00006500 |
| closing tables | 0.00000700 |
| logging slow query | 0.00000400 |
+--------------------+------------+
15 rows in set (0,00 sec)

And for the second query:
mysql> show profile for query 2;
+----------------------+------------+
| Status | Duration |
+----------------------+------------+
| (initialization) | 0.00004500 |
| Opening tables | 0.00016400 |
| System lock | 0.00000800 |
| Table lock | 0.00001100 |
| init | 0.00000800 |
| checking permissions | 0.00002000 |
| optimizing | 0.00000700 |
| statistics | 0.00001400 |
| preparing | 0.00001200 |
| executing | 0.00000500 |
| Sending data | 0.00009000 |
| end | 0.00000600 |
| query end | 0.00058000 |
| freeing items | 0.00001700 |
| closing tables | 0.00000600 |
| logging slow query | 0.00000500 |
+----------------------+------------+
16 rows in set (0,00 sec)

If we once again select from the table testo1 with:
select * from testo1;

we get the following profiles:
mysql> show profiles;
+----------+------------+----------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------+
| 1 | 0.00964100 | select * from testo1 |
| 2 | 0.00099800 | select * from v1 |
| 3 | 0.00071200 | select * from testo1 |
+----------+------------+----------------------+
3 rows in set (0,00 sec)

The first select needed 9.6msec, the second one only 0.7 because of the query cache. We used two identical statements so the query cache could be used.
This should be enough to wet your appetite. If you would like have a closer look:
MySQL dev center article on profiling
MySQL manual entry for "show profiles"

Renumber an ordered list in a MySQL table

Did you ever have a table containing evenly numbered entries and had to delete an entry in the middle? How to renumber the remaining entries? Here's a trick for MySQL using a user variable to recount the index:


set @num=0;
update TABLE set IDX=@num:=@num+1 where FILTERCOL='only these' order by IDX;

This statement renumbers all entries in table TABLE which fulfill the filter condition FILTERCOL='only these' by using a user variable @num which is auto-incremented after assigning to the IDX field. The solution is fast, elegent ... and not portable wink

Beautiful data

The amount of data on any given topic is rising nearly exponentially. Online media and social sites give an incomparable statistical and empirical insight into the inner workings of groups of human beings.
So there's a need to visualize large amounts of data, complex relationships and correlations and to do that often and nearly en passant.
There's a really interesting article in Smashing Magazine, a graphics designer online publication showing new methods, forms and algorithms to show mndmaps, news, data, connections and web sites. Plus it contains a large appendix with links and references to further delve into the thematics. I was really impressed.
All those beautiful data visualization techniques made me think about the importance of usability issues in visualization: complex data sets or relations are no longer the domain of some highly specialized experts but will enter the real life of a larger group of possibly technically adept but not specialized people. Every decent personal computer has the cpu power and graphical ability to create sophisticated graphs and let its user interact with it in real time.
There only needs to be a set of tools enabling easy creation and usage of such graphs and more important, there need to be new ways to show the more complex findings in such data in an eye pleasing way. The more beautiful and self explaining visualizations are, the more useful they are for viewers/users.
I'm very interested, what the future will show concerning tools and visual representations of data. Please let me know what you think and if you know of any other new ways to display data.