Archive for the ‘Interesting Stuff’ Category

Good old-skool h4×0r!

Monday, September 29th, 2008

As seen on slashdot, this story made me smile in pure, raw nostalgia:

The manual for Mental Blocks claims that, for both C64 and IBM, you put the diskette in label-side up.  I thought that had to be a typo, since every single mixed C64/IBM or Apple/IBM diskette I have ever seen is a “flippy” disk where one side is IBM and the other side is C64 or Apple — until I looked at the FAT12 for the disk and saw that tons of sectors in an interleaved pattern were marked as BAD — very strange usage.

Absolutely… beautiful!

All this thing about LHC…

Thursday, September 11th, 2008

… made me remind something Carl Sagan said, and which I’ve previously posted:

“We are star stuff which has taken its destiny into its own hands.”

- Carl Sagan in Cosmos

.NET Memory Leak and no solution from Microsoft…

Sunday, September 7th, 2008

You think that living in a managed world eliminates your worries with memory leaks? You think that as long as you don’t touch unmanaged resources you’re safe? Well, think again…

I’ve recently been struggling with .net because of Panels not being destroyed. Since I dynamically create these panels, which hook upon several events in the system, the application started to crawl down after a while due to some thousands/millions of events being fired to panels that should no longer exist. When we started testing the code line-by-line, what we’ve found amazed us: a particular Panel couldn’t be destroyed due to having AllowDrop set to True. WTF?

But there it was: set it to false, and the garbage collector happily destroys the object. Set it to true, and Dispose() is never called, the Panel lives, and the application stalls.

We thought: a bug in .NET? Does this happens in 3.x as well? Yes, it does. But, how is it possible? No one ever found it? After all, Drag’N'Drop is a common feature. Well, apparently, one guy did. But, either I’m misunderstanding the solution, or there is no solution at all.

Help?

Cocoa Programming

Monday, August 25th, 2008

I’m currently reading Cocoa Programming for Mac OS X. I’m becoming astonished by the underlying technology in Cocoa. There are some drawbacks, it’s true: for instance, Objective-C is much less intuitive than Java or C#, the whole .h files seem pretty much deprecated nowadays, and there’s definitely a learning curve there. But having a book like this can help a lot in the process.

I’ve just finished chapter 11 from 35 in total. I must say that by now, CoreData amazed me by allowing to create an application to display, manage and persist (with an Undo/Redo mechanism and all) a simple Information System to catalog Books (along-side with an Image, rating, etc…) without a single line of code. What amazes me most, is that there’s barely code-generation going under the hood: it’s the whole pervasive MVC architecture in Cocoa that allows you to bind hotspots everywhere.

I strongly advise every programmer who can to read this book and do the exercises up to the eleventh chapter. If after this point you aren’t convinced, you can flame me at will :)

My whole dilemma now is: I’m a developer for Windows (it sucks, but that’s what the company I work for do). I can see the potential in this framework, business-wise, but I can’t seem to find a way to bring this into the Windows world. Any ideas out there?

And another macro…

Tuesday, August 19th, 2008

I know, I must change the theme… I’ll try to capture some insects today in the village.

P = NP \/ P != NP -> True

Thursday, August 14th, 2008

I recently started to read a book from Keith Devlin about the Millenium Problems of Mathematics. One particular problem which every Computer Scientist have heard about is the P = NP. I say heard, not understood. Most of the people I’ve met, including me, know that this problem is directly related to the complexity of a particular algorithm. Most also know that it states that any known solution of a particular problem performs in superpolynomial time. And that’s all they need to know…

What most don’t know is the exquisite meaning of NP. An NP class problem is one such that a non-deterministic computer can solve it in polynomial time. Got it? Let me express it in other words: A problem which is NP can be efficiently solved by just getting luck in every choice you have to make. For example, in the traveling salesman problem, one can in fact solve it in linear time by correctly guessing the next city. The problem is guessing it right!

Some people have also heard about NP-complete (NPC) problems. What is the difference between a NP and an NPC problem? To put it simple, an NPC problem is an NP problem that has been shown to exhibit the characteristic of being able to be “translated” into any other NPC problem. This means that a polynomial solution found to a particular NPC problem can be easily applied to every other one. It’s like a dictionary of problems; find the solution of a puzzle, and you’ve found the generic solution of that class of puzzles!

And this is where everyone stands… No one have been able to prove that there exists NP problems that can or cannot be solved in polynomial time, since no one ever found a P solution to an NP problem. Of course P = NP could be proved or disproved without actually founding a particular solution: this would mean that every NP problem have an efficient solution, though it hasn’t been found yet.

Keith describes this enigma in such an enthusiastic way that lead me to read the formal problem statement. I must say that even my recently acquired knowledge on formal language semantics is not enough to read it easily. But I couldn’t resist inciting my colleagues and readers to have a glance at it… Enjoy!

P.S.: My apologies to my purist friends from any inaccuracy I’ve made for the sake of simplicity. You are free to flame me in the comments section ;-)

Some macros: 450D and a standard 18-55mm

Tuesday, August 12th, 2008

Logic gates with Dominos!

Monday, July 21st, 2008

Big Ball of Mud: On Software Architecture

Saturday, June 28th, 2008

There has been a paper that was kept out of my radar for a surprisingly amount of time: “Big Ball of Mud”, by Brian Foote and Joseph Yoder. Just reading the introduction makes any software architect fight the urge to get out screaming to their bosses and colleagues: “See?? This is exactly what I’ve been saying!!”

The paper is an excellent summary of the dynamics of software development and evolution. I can’t resist to quote some passages from the introductory chapters to see if I can persuade someone to read it:

A BIG BALL OF MUD is haphazardly structured, sprawling, sloppy, duct-tape and bailing wire, spaghetti code jungle. We’ve all seen them. These systems show unmistakable signs of unregulated growth, and repeated, expedient repair. Information is shared promiscuously among distant elements of the system, often to the point where nearly all the important information becomes global or duplicated. The overall structure of the system may never have been well defined. If it was, it may have eroded beyond recognition. 

Now… Who doesn’t recognize these symptoms? The authors go on:

Why does a system become a BIG BALL OF MUD? Sometimes, big, ugly systems emerge from THROWAWAY CODE. THROWAWAY CODE is quick-and-dirty code that was intended to be used only once and then discarded. However, such code often takes on a life of its own, despite casual structure and poor or non-existent documentation. It works, so why fix it? When a related problem arises, the quickest way to address it might be to expediently modify this working code, rather than design a proper, general program from the ground up. Over time, a simple throwaway program begets a BIG BALL OF MUD. 

This paragraph reminds me of people who claim the XP, but they don’t refactor. eXtreme Programming is not just about, well, programming. The architecture, design and model phases are just as important as getting things done. Still, most agile practitioners disregard those “extras” and believe that code that works is good enough. Actually, it’s not just the programmers; authors, few pages away, state:
The time and money to chase perfection are seldom available, nor should they be. To survive, we must do what it takes to get our software working and out the door on time. Indeed, if a team completes a project with time to spare, today’s managers are likely to take that as a sign to provide less time and money or fewer people the next time around. 
Indeed:

Programmers with the ability to discern and design quality architectures are reputed to command a premium. These expenses must be weighed against those of allowing an expensive system to slip into premature decline and obsolescence. If you think good architecture is expensive, try bad architecture. 

And I could continue to quote the article for dozens of pages… This was written in 2000. Eight years later, where are we? I believe we are roughly at the same. People still come out from University clueless about architecture and design, despite they have courses intended for that. But, somehow, it’s still relegated as a second-class knowledge. Why?

Not wanting to start on a largely (perhaps irrelevant) rumination about the “why’s” and “how’s” (read the article for that), I would like to close this simple post with another quote:

Another is the Extreme Programming practice of pair programming [Beck 2000]. A pure pair programming approach requires that every line of code written be added to the system with two programmers present. One types, or “drives”, while the other “rides shotgun” and looks on. In contrast to traditional solitary software production practices, pair programming subjects code to immediate scrutiny, and provides a means by which knowledge about the system is rapidly disseminated. Indeed, reviews and pair programming provide programmers with something their work would not otherwise have: an audience. Sunlight, it is said is a powerful disinfectant. Pair-practices add an element of performance to programming. An immediate audience of one’s peers provides immediate incentives to programmers to keep their code clear and comprehensible, as well as functional.

In other words: if you have to write your code alone, do it so you can be proud of it. Do it as if you’re going to show the world what you’ve done…

First annoyance in Leopard

Saturday, April 5th, 2008

Since the very first usage, I’ve found safari very slow when starting a page display, but I blamed the rendering engine for that. However, slightly after installing Little Snitch, I’ve incidentally realized that something wrong was happening with the DNS: it was taking too long to answer. By digging some pages on the internet, one can conclude that by adding the OpenDNS server addresses to the DNS section on Network preferences, the problem is fixed.For more information, check this forum.

Singleton using Generics

Friday, March 28th, 2008

Here goes a tip from my colleague José Vilaça for “elegantly” creating Singletons using Generics in C#2.0+ :

public sealed class Singleton<T> where T: class, new() {
 private static T _instance;
 private Singleton() { }
 public static T Instance {
  get {
   if (null == _instance)
    System.Threading.Interlocked.CompareExchange(ref _instance, new T(), null);
   return _instance;
  }
 }
}

Here’s an example:

Console.Writeline(Singleton<object>.Instance == Singleton<object>.Instance);

Of course, T must be a class with a public constructor without any arguments.