Something like an SQL Paradox
I love philosophical problems translated into computer programs. And while reading SQL Cookbook, I thought I had come across another—a form of Russell’s Paradox.
Russell’s Paradox: a Review
You probably remember from logic class that Russell’s Paradox pointed out something very disturbing about naive set theory, namely that it is unclear whether or not the set of all sets not members of themselves are members of themselves. Or maybe you simply remember something about Barbers who shave only men who don’t shave themselves.
Oh, yeah!!! How does that go again?
Imagine a town, Russelltown, where there is a barber who- shaves all those men who don’t shave themselves, and
- doesn’t shave any man who does shave himself.
Does the Barber of Russelltown shave himself?
By 1, the Barber has to shave himself, but by 2, the Barber cannot shave himself.
So, it would seem that Russelltown has a barber who is not a man—an untenable solution. Where did we go wrong? Something must be wrong with our logic.
The general thought is that something is wrong with our axiomatic system.
SQL Groups as Sets
In SQL Cookbook, the author notes that a paradox arises for SQL groups.
What is a SQL group? A SQL group is a non-empty, distinct set. If you think about any SQL query that uses group by, this should be self evident. SQL groups can’t be empty otherwise it doesn’t really make much sense to call it a group—any nothing could be a group if empty groups are groups. SQL groups must be distinct otherwise we would say that our the database has not identified two sets of rows as similar.
The real problem arises for SQL groups when you consider the two facts about SQL groups in conjunction:- An SQL group can by definition not be empty. For instance, the aggregate function, COUNT returns a value >= 1. So, by definition, groups must have at least one member.
- SQL groups are syntactically promiscuous. To keep the SQL language flexible, NULL is a valid component of a SQL group by clause; however, NULLs are ignored by the group by function.
By 1, SQL groups cannot be empty, but by 2, SQL groups must be empty. Let’s take a closer look….
Consider the following table:
select * from femaleLogicians
Name
penelope maddy
ruth barcan marcus
susan haack
Consider that we insert several NULLs into the table like this…
insert into femaleLogicians values (NULL);
insert into femaleLogicians values (NULL);
insert into femaleLogicians values (NULL)
Given this table and the two facts above, what would you expect the following query to return?
select coalesce(name, 'NULL') as name,
count(name) from femaleLogicians
group by name;
The query would actually return something like this…
| name | count(name) |
|---|---|
| penelope maddy | 1 |
| ruth barcan marcus | 1 |
| susan haack | 1 |
| NULL | 0 |
This difficulty doesn’t arise by the definition of a SQL group alone; it arises by the definition of a SQL group and through the requirement that NULL values are valid SQL group components. Pretty cool, huh!! I’ll leave the work around solution as an exercise for the reader.
So, this SQL group “paradox” isn’t Russell’s paradox, but the similarity between a SQL group and a set makes one wonder whether it would be possible to create a group of all groups that do not contain themselves in SQL. I don’t believe syntatically something like that won’t work, but supposed your could rewrite the ISO SQL standard to accept such a syntax. Could you, with or without SQL, implement Russell’s paradox as a computer program? At very least, it appears that the problem can (like the problem of substitution into intensional contexts) be implemented using web pages in some way… maybe that will have to be fleshed out in another post.
A Ticklr File
I’ve been playing around with Google App Engine
to create something that resembles a Tickler File.
What’s a Tickler File?
“A tickler file is a collection of date-labeled file folder organized in a way that allows time-sensitive documents to be filed according to the future date on which each document needs action.”
Things you can do with a tickler file:- send yourself motivational quotes and photos
- remember birthdays, meetings, appointments
- actually send yourself an article at a time when you are likely to read it
- review your cliff notes the day before the big meeting
- divide course material up into consumable, accessible chunks
An interesting part of GAE has been the Task Queues which come in pretty handy when scheduling things.
TaskOptions taskOptions = TaskOptions.Builder.url("/emailDaylog")
.param("address", user.getEmail())
.param("content", daylog.getContent());
Queue queue = QueueFactory.getDefaultQueue();
queue.add(taskOptions.countdownMillis(DEFAULT_REMINDER_WAIT));
Digg-Style Pagination in Java
public ArrayList getPagingLinks(){
ArrayList pages = new ArrayList();
if (pageCount < (7 + (adjacents * 2))){
for(int i=1; i<=pageCount; i++){
pages.add(i);
}
} else if(currentPage < ((adjacents * 3) + 1)){
for(int i=1; i<=(4 + (adjacents * 2)); i++){
pages.add(i);
}
pages.add("e");
pages.add(pageCount);
} else if(((pageCount - (adjacents * 2)) > currentPage) && (currentPage > (adjacents * 2))){
pages.add(1);
pages.add("e");
for(int i=currentPage -adjacents; i<=currentPage +adjacents; i++){
pages.add(i);
}
pages.add("e");
pages.add(pageCount);
} else{
pages.add(1);
pages.add("e");
for(int i=pageCount - (adjacents *3); i<=pageCount; i++){
pages.add(i);
}
}
return pages;
}
Basically, it creates a list of links to pages determined by the displayCount. If the page number equals the current page or the page number is greater than the page count, then no link will be added, only the page number.
The Passionate Programmer: a review
Creating a Remarkable career in Software Development
by Chad Fowler

My favorite part of the book was the “Act on It!” sections that give you suggestions for things you can do now to act on the concepts introduced in the chapter. If you are looking for a springboard of ideas on how to enliven and improve your career as a software developer, this book gives you over 50 concrete actions to move in that direction.
I am so excited about using these suggestions in my life; I have already started with some of them. Of the 50 or so suggestions shared in the book, the following are the ones that really stood out to me.
- Figure out how the internals of the vm you program for work. Determine how external libraries are loaded or imported. Take time to learn the mechanics of how source code is compiled.
- Be the worst musician in your band. This means that you should surround yourself with developers who challenge you, who are better than you are…. so that you are continually challenged and feel the impetus to keep up and perform at your best.
- Practice
- I love this one… Questions you should ask yourself and your boss
- Was I worth it today?
- How could you make your development team more efficient?
- How could you creatively save your company money?
- Keep a development diary—what did you work on, why did you write it that way. I have started trying to do this and initally my ‘diary’ was more like a hit list of what i accomplished that day. What I have started doing differently is picking out some snippet that i wrote that day and pasting it into my diary post and then commenting on different lines.
- Try to do the boring stuff perfectly. I’ve tried this as well; it will add life back into your most tedious tasks.
- How to Fail
- raise the issue as soon as you know about it
- take the blame
- offer a solution
- ask for help
- One of my new goals after reading this book is to talk to all of the developers I work with face to face more often.
- Always have your “elevator speech” ready. What are you working on? Could you explain what you are working on to the CEO of your company?
I definitely recommend the book; it is inspiring and will silence even the whiniest of developers. While reading, you will want to take notes while you are reading or keep a to do list handy.
The Passionate Programmer: Creating a Remarkable Career in Software Development (Pragmatic Life)
Django: first impressions
A month or so ago I was anticipating a move into Django. I started on some of the Hello World tutorials on the django site, and I wanted to share the few observations from my very brief encounter with Python via Django.
- Double underscores?!! Whose idea was that? Does that end up being a pain when writing in Django? I remember that Ruby uses the double underscore too, but Rails doesn’t use this construct frequently from what I remember. Please someone write in and tell me I am mistaken about the frequency in use of double underscores in Django.
- The setup with sqlite was straight forward and simple—more simple than in Rails. It has been my impression, however, that this ease (or lack of ease) has more to do with the database installation on the operating system, than it does with actual integration with the framework. In other words, the problems that I have encountered with setting up database connections in other frameworks occur while trying to setup the data source itself.
- Is the settings.py file supposed to be like the web.xml in j2ee and the environment.rb in Rails? It seems that database information goes in this file, which is different than in j2ee and Rails where you have separate files to specify the database connections (e.g. context.xml and database.yml).
Overall, I would be interested in working more with Django.
506 tar xzvf Django-1.1.1.tar.gz 507 cd Django-1.1.1/ 508 sudo python setup.py install 509 python 510 ls -al 511 vi INSTALL 513 django-admin.py startproject Test 514 cd Test/ 515 ls -al 516 python manage.py runserver 517 python manage.py syncdb 518 python manage.py startapp polls 519 cd polls 520 python manage.py sql polls 521 cd .. 522 python manage.py sql polls 523 python manage.py syncdb
Code Reviewing
I wrote this a few months ago when I was doing a lot of code reviewing. There are a number of criticisms of the Code Review, and certainly, a number of review mechanisms that can and should be used in conjunction with some type of human review, such as static code analysis and performance analysis. In this post, I won’t be comparing or contrasting the Code Review to any of these.
Strategies, Questions to Ask and Things to look for
Some code review questions…- Is it relatively clear what the code does from reading it?
- Is the code in a reasonable location and named appropriately?
- Is this same functionality duplicated elsewhere?
- Are there any unnecessary calls, methods, variables?
- Do any of the url params have the potential to conflict?
- Has all text been pulled out into properties files?
- Would it be useful if this code could be disabled or enabled? If so, has the author provided a means for turning it off?
Tools
My experience with code reviewing tools is limited. The Jupiter eclipse plugin seemed to require too much work on the developers part—generating the request for review, checking in the .jupiter file and review files slowed development down. Monitoring svn check-ins seemed to work moderately well, although it required more work on the reviewer end.
When to do the code review
Ideally, code reviews shouldn’t uncover any larger architectural issues that need addressing. They should expose overlooking coding mistakes. So, ideally there should be no timing problem, that is, you shouldn’t find some large refactor that needs to be done before the code is released. Code should be reviewed after development is finished, but before the functionality is ready for qa.
Double Time
There are several different ways that code reviews can go: the code reviewer(s) can monitor check-ins, developers can request that code reviews be done on their code or the dev team can get together as a group and go over the code line by line etc etc. One thing that has worked for me is employing more than one of these methods. So, developers submit requests for review and I also monitor check-ins.
10 tools every web developer should know
I know, I know – this title sounds like link bait, but I realized the other day that many of the suggestions I make to my fellow developers on how to troubleshoot/debug “stuff” begins by recommending a tool. The underlying theme among all of these tools is that they help you verify, verify, verify!!
So here are some useful things to know how to do as web developer…
1. how to debug with firebug- Set breakpoints
- Edit html/css on the fly
- Turn off css classes
- View external calls that your browser makes on page load
Knowing how to debug with firebug will help you when you want to verify that some piece of javascript is being executed by the browser, when you need to know if a style is actually being applied to a class or that your browser is actually loading a fresh version of some file every page load.
2. how to use tamper data (or another packet sniffer like charles or wireshark/ethereal) :- install tamper data firefox extension or wireshark
- start tampering or capturing data *load webpage (optionally edit the request)
- stop the capture/tampering
- view calls your browser (ah, er, your computer) is making
Basically, if you are unsure that the request contains some information, you can verify that using tamper data or wireshark.
3. how to create cookies with web developer- install the web developer Firefox extension
- select “Cookies” from the Web Developer menu
- next select “Add Cookies”
- enter the name of the cookie, the value and what domain it applies to
Knowing how to set cookies and verify that a cookie exists and that it has some value and applies to some domain is, of course, essential when working with cookies.
4. how to test for multiple user agents- install the firefox extension
- import any needed user agents
- switch from your default user agent to needed user agent (iphone, IE6) and refresh the page
Sometimes development and test environments are publicly accessible, which can be a real problem for test from a mobile device without access to your companies intranet. And although testing for multiple browsers may best be done in the actual browsers themselves, problems can expose themselves here.
5. how to navigate your way around jQuery, prototype, yui, moo tools or some other javascript frameworks, including “third party” javascript apis (like video, twitter, url shortner apis)
- avoid “rolling your own” or “reinventing the wheel” by using existing methods provided by the framework
- use the right methods and objects for the version of framework you are using
It is important to know how to use documentation from some javascript framework to confirm that you are writing what you think you are writing.
6. how to write or use an automated functional testing suite, such as Selenium, Quick Test Pro or some home-made solution- easily set up functional tests to confirm that changes you’ve made aren’t breaking old functionality
The idea behind all of these tools is to capture some record of page quests and html/css/js on the page and match this up to some pre-recorded (potentially somewhat dynamic) set of html/css/js values.
7. how to configure your ide to help you spot javascript/css/html errors- whether it be a javascript plugin for your favorite IDE or the fact that your IDE provides syntax coloring for javascript, know how to make it easy on yourself to spot errors
The easiest thing you can do for yourself is verify that there aren’t errors in your code before you start testing it.
8. how to test your regexs- again just confirm that what you have written is working for the cases you can identify.
You won’t be able to test every possibility, but if you identify the cases that might occur you can test those out
9. how to put your “stuff” in version control easily- whether it is svn, git, clearcase, cvs or whatever, you’ve got to either know your version control client or know your command line commands very well
- confirm that your commits are successful by browsing them in some web interface provided by the vc service
If you aren’t seeing your changes in an environment, it is always good to check and see if those changes are really there.
10. how to troubleshoot client-side performance problems- determine what is slow and if the slowness is a result of page weight or because your javascript has some runtime inefficiencies.
- use yslow
- for a more in depth look at javascript performance, i suggest javascript rocks
Basically, the end result of these tools from a very high level perspective is to know where the performance problem is (or is not). For instance, if your page weight is small and there is little javascript “action” on your page, it might be plausible to think slowness isn’t “on the front end”, but is being cause by slowness on the server side.
Remembering what you've written
I have folks at work ask me details about code I’ve written and how it works. Almost always, I have to go back and at least look at what I’ve written before I can even say for sure that I wrote or worked on the code. Isn’t that sad?
This forgetfulness with regard to what I have written is annoying. And I’d like to brainstorm some ideas here about how someone with the same problem might move around it.
Wiki- fluid / roll your own
- fits high level and low level documentation
- wikis can be as difficult to navigate as the code if not maintained
- details on specific classes and methods
- auto generated; just document your code and wola!
- harder to get high level overview of what the pieces are and how they fit together
- the code speaks for itself
- if the code is well written, no one should be knocking at your door for an overview
- “document” as needed; no time spent for extra documentation that may never be used
- harder to get high level overview of what the pieces are and how they fit together
What other options have I missed here? What, in your experience, has been the best way to document what you have written?
Devchix Task List Android App
This post is to basically explain how the Devchix to do list android app that Nola and I have been working on works. Currently, we are working on Iteration 1 of our plan. Here’s how I understand what we have working so far: In our app, users can switch between 2 activities using the menu option, “Add Task”.
When our app is first opened the first activity that is rendered is the ViewTasks activity. We first start with some setup steps…. we inflate our layout, create our task database and open a connection to that database. We create a cursor that will just represent all tasks that we have put in our database and we call the startManagingCursor method, so that we do not have to do that ourselves.
We get a ListView from our ListActivity; this ListView will be our list of tasks. In our ViewTask activity, we have a subclass class called TaskAdapter, that will help us get data out of our cursor and into our list view. Lastly, we set our TaskAdapter as an adapter on the ListView we just created.
When the user clicks on the menu button, we will see the two menu options whose names we grabbed out of our strings.xml. And because we have implemented the onMenuItemSelected to detect which option the user selects, we the user selects the Add Task option, our second activity will be started where users can enter the name of the task and save the task to the tasks database.
If there are already Tasks in the task database, then TaskAdapter will inflate a new row from the records we get back from our query and then have the TaskWrapper place the contents of the cursor into a Task object. The task object represents has getters and setters for setting the various task fields, which may be overkill right now because we don’t have many fields but as our application grows and expands to do more complex things with task information this may make our code more modular.
Other than creating the table, I don’t believe the methods we have in the TasksDbAdapter class are currently being used. Depending on how we want to clean the code up, we may be able to refactor this class—either move the db creation into the ViewTask activity or move the other queries out into the TasksDbAdapter.
Here’s the link to the Devchix Task List Android App on Google Code.
Atlanta Linux Fest 2009
I attended the Atlanta Linux Fest last Saturday. I only got to stay for two talks, but what I saw was great!
From the Ubuntu Kernel talk given by Pete Graner of Canonical, I learned a couple of interesting things about Ubuntu…
Canonical has teams that work on things other than the ubuntu kernel, including integration for OEMs like Dell and HP, maintaining LaunchPad, and distributing install cds. They are able to maintain a 6 month release cycle for Ubuntu by deciding to only fix those bugs that are truly critical and focusing on the goals decided at the Ubuntu Developer Summit.
Ubuntu One allows you to back up any number of systems into the cloud.
The folks at Canonical have created a version of android that runs on Ubuntu Notebook Remix. It sounded like android uses some of its own version of libraries so a unique version of android had to be compiled to use those libs.
I also saw Kirrily Robert give her Standing Out in the Crowd talk. If you missed OSCon 2009 or the Atlanta Linux Fest, you can check out her talk here.

