Posts for the 'Programming' Category (Feed for this category)
Ignorance is Bliss, apparently.
So, today on a random IRC Channel, the following definition of Django was given:
< freespace> jsp for python
The comparison seems like chalk and cheese. What I do know about JSP, is the fact that to do even little things would require a lot more code than the task was worth, where with Django on the other hand, it is simply a simple task. Create Models, views, and URLs, and you are done.
If you are wanting to know what Django really is (and what wouldn't you? It's fabulous!), have a look at: The Django Overview and Django FAQ
Meanwhile, Linux Australia, has announced that they are going to re-do their current site, and need to come up with something that better integrates, and provides a more modern, look.
Suggestions have already come up, for what should be used as a starting base. Drupal, Django and Ruby on Rails have all been mentioned, with embperl and slashcode being mentioned by people with more time than sense ;-).
Hopefully they go with something sensible (Django), and not end up with something clunky (Drupal).
This weeks better news...
Following one from last week's good news, it seems that this weeks is even better:
ADSL2+ plan puts heat on Telstra
The important thing about that is:
Perth ISP WestNet has signed on to resell PowerTel's ADSL2+ service to its 115,000 residential broadband subscribers.
This is great news, because it means I can get ADSL2+ when its launched, as iiNet already has a DSLAM in my local telephone exchange. And it also confuses the hell out of all those people who believed that WestNet were going to go with Optus' DSLAM/ADSL2+ network.
In other news, I did finish that Java assignment on time, only after it clocked in 1745 lines of code. Not bad for 3 days work.
Win32 API vs. Linux - Round One
Before we start today's fight, we shall introduce you to the contestants, and a bit of background on each of them.
In the Red Corner, we have code written to work well with the Win32 API. The Win32 API is known for being part of Windows, and being able to kill its opponents easily, with the sheer size and complexity of itself. In the Blue Corner, we have code written to work well on Linux. Linux code being known to be quite easy to deal with, and not having heaps of levels of abstraction when it isn't neccesary.
These two come together today, to see who can write the better program that can: * Open a file, specified on the command line, for exclusive read only access. * Report if there was a problem opening the file, with an appropriate error message. * Close the file.
We would like to thank today's sponsor for this event, namely the Systems Programming 2 class that I am currently undertaking at University, and is making me learn how to code with the Windows API.
So that is enough, talk, lets see how the fight goes.
Windows starts off first by allowing a bit more complexity to its CreateFile() routine, but this is unfortunately useless, and not able to withstand the sheer simplicity of Linux's open() call, which beats it hands down.
In an attempt to reclaim, the match, Windows tries to claim that it can give a more superior error message handling routine, for when that file open does not work. Unfortunately, while Windows was still trying to type the function name for the routine to get the error message, Linux had already finished writing code to get and display the error message, thanks to perror(). In fact, Linux was so efficient, it decided to go one step better, and customise the error message all together.
In the end, it came down to closing the handle/file descriptor, to see if Windows would get a foot in, in this round, and it seems that it was a tie. Both Windows and Linux successfully made closing the open file nice and easy.
However, it the clear winner this round is the Linux code. Score: 2.5 - 0.5 -- Linux code wins.
To see the code used in this contest, and to agree with me that Linux definately wins this round in terms of better code/less code for this task, see the code below.
Windows
include <windows.h>
include <stdio.h>
int main(int argc, char *argv[]) { HANDLE hFileToRead; LPTSTR pszErrorMessageBuf; SECURITY_ATTRIBUTES lpSecurityAtrribs;
lpSecurityAtrribs.nLength = sizeof(lpSecurityAtrribs); lpSecurityAtrribs.lpSecurityDescriptor = NULL; lpSecurityAtrribs.bInheritHandle = TRUE; if (argc < 2) { fprintf(stderr, "Syntax: %s <filename>", argv[0]); return -1; } hFileToRead = CreateFile( argv[1], GENERIC_READ, 0, lpSecurityAtrribs, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFileToRead == INVALID_HANDLE_VALUE) { FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, (LPTSTR)&pstrErrorMessageBuf, 0, NULL); fprintf(stderr, "Could not open file '%s': [%d] %s", argv[1], GetLastError(), pstrErrorMessageBuf); LocalFree(pstrErrorMessageBuf); return -1; } else printf("File successfully opened.\n"); if (!CloseHandle(hFileToRead)) fprintf(stderr, "Error closing file...\n"); return 0;}
Linux code
include <stdio.h>
include <sys/types.h>
include <sys/stat.h>
include <fcntl.h>
include <errno.h>
include <string.h>
include <unistd.h>
int main(int argc, char *argv[]) { int fd;
if (argc < 2) { fprintf(stderr, "Syntax: %s <filename>\n", argv[0]); return -1; } fd = open(argv[1], O_EXCL|O_RDONLY); if (fd == -1) { fprintf(stderr, "Could not open file '%s': [%d] %s\n", argv[1], errno, strerror(errno)); return -1; } else printf("File successfully opened.\n"); if (close(fd)) fprintf(stderr, "Error closing file...\n"); return 0;}
Some code
Oh, while I blog for a bit, I have put up on the site, some code I have done recently. Not all of it has been completed however, but usable somewhat.
First is mininova information query (mniq). It is written in python and atm only has a info command. It can be found at www.atomicirc.com/mniq
Secondly, is my submission I made for one of my Assignments at University, which I got full marks for. It's basically a slim line IRC sever and client, which is not much to look at. It can be found at www.atomicirc.com/dsap
Race to Linux
Aaron talks about Race to Linux having the prize as an Xbox, ironically something opposite of the goal they are trying to achieve. While my feelings on the point are neither here nor there (the Xbox is a decent piece of gaming equipment, as is the playstation), I do think the race is a great idea.
Simply put, it is trying to get coders, of ASP.Net web applications, to convert examples of current ASP.Net implmentations, or designs, into an open source language, such as PHP and Mono. So if you have some free time, might be an idea to check it out. It sounds fun, and looks fun, and you can get yourself a nice gaming machine.

16th November, 2006
0 Comments
Add Comment