
Archive for the ‘Uncategorized’ Category
Code Q&A
Tuesday, March 25th, 2008My PSP Games Collection
Wednesday, March 12th, 2008Last Christmas I decided to acquire a PSP Slim. I’ve never been a huge fan of gaming consoles, though I own a Nintendo Wii. However, despite occasional playing especially during on-house parties, I’ve never used my Wii that much. The fact that it doesn’t double as a DVD Player (nor DivX) increased my negligence over that device.
It’s no wonder that my family and friends gave me a suspicious looking after buying the PSP. However, nearly 3 months have passed and this is the single best gaming device I’ve ever had:
- It has a gorgeous screen;
- It has WiFi connection, browser, etc;
- The sound is ok with the in-built speakers, but it blows your mind with a set of headphones;
- It has an increasingly amount of games being actively developed;
- It has a good amount of battery duration;
- It is portable
And if I’m in the mood, I can even connect it to my 42″LCD set using the component cables.
I could go on and on with this list (catching up with the Heroes series in the PSP screen is amazing). Still, the goal of my post was to make a selection of the games I carry around with my PSP:
- God of War: Chains of Olympus: Amazing graphics and excellent playability. Very fast-paced.
- Fading Shadows: Nice concept, good graphics, few options, limited camera freedom.
- Chessmaster: Bad graphics for the PSP, but hey, it’s a chess game. Cool mini-games.
- Patapon: Probably the best game ever for this system. Excellent concept and graphics. Twist of mind in playability. Pity it is so small.
- Exit: Nice concept but awkward and unresponsive user-interface that completely blows the immersion.
- Practical IQ: Those who like hard puzzles will love this one. Puzzle feeding via WiFi. Graphics sucks, though.
- Lumines: This one is for the PSP as Tetris was for the original Gameboy, XXI century style.
- Lemmings: For the nostalgia. Improved graphics and sounds from the original. Interesting enough, the interface was so well designed that I don’t feel the need of a mouse.
- Dungeons and Dragons Tactics: DnD 3.5 very badly done. Awkward interface, slow-paced game. We are in desperate need of a native port of Neverwinter Nights for the PSP, or at leas, Baldur’s Gate II.
- Worms Warfare: For multiplayer fun
- Wipeout Pulse: This was my preferred game in the PSOne, and it still has that unique feeling of speed, listening to good old techno music.
- Pro Evolution Soccer 2008: I’m a PES fan, but I feel little has changed in terms of gaming since version 6
- UAE: The Commodore Amiga Emulator, of course
What about you? What is your PSP games collection?
Thought of the Day
Wednesday, March 5th, 2008![]()
“We are star stuff which has taken its destiny into its own hands.”
- Carl Sagan in Cosmos
Green River: Soon in 24bit
Saturday, March 1st, 2008Thesis
Friday, February 22nd, 2008My thesis proposal has been approved by the scientific comitee yesterday, and it will be on:
“Adaptive Object-Modelling: Patterns, Tools and Applications”
Also, the first semester is gone. Here comes the second semester and my pre-thesis evaluation in July
Turing 2008 Award
Tuesday, February 5th, 2008Goes to Edmund M. Clarke, Allen Emerson, and Joseph Sifakis:
“Model Checking is a type of “formal verification” that analyzes the logic underlying a design, much as a mathematician uses a proof to determine that a theorem is correct. Far from hit or miss, Model Checking considers every possible state of a hardware or software design and determines if it is consistent with the designer’s specifications. Clarke and Emerson originated the idea of Model Checking at Harvard in 1981. They developed a theoretical technique for determining whether an abstract model of a hardware or software design satisfies a formal specification, given as a formula in Temporal Logic, a notation for describing possible sequences of events. Moreover, when the system fails the specification, it could identify a counterexample to show the source of the problem. Numerous model checking systems have been implemented, such as Spin at Bell Labs.”
For those interested in Model Checking and Formal Specification, you can take a peek at lectures from my PhD, specifically the courses Program Semantics, Verification and Construction and Model-Driven Software Engineering.
xkcd #329
Thursday, January 31st, 2008
Quando ainda tinha algo semelhante a uma vida…
Thursday, January 24th, 2008… ia divagando um pouco. Agora não consigo escrever nada sem me perguntar: “Mas o que é que isto adiciona ao estado da arte???”
“Será sábio aquele que, como Socrates,
sabe que a sua sabedoria é pouca?”Que enigma esse o da filosofia!
Que peculiar modo de vida,
Que caprichosa religião!
Dedicar a vida ao sofrimento,
Por tanto amar a verdade e o conhecimento.Serão a esses seres permitidos tais devaneios,
Que subtilmente separam o fantástico da loucura?
Ou estarão eles condenados à eterna caminhada,
Pela ténue linha entre a verdade e a ilusão?Serão apenas os seus destinos uma vã busca,
Do equilibrio sobre os penhascos da realidade?
Ou o nobre fardo de manter a chama acesa,
Para guiar sociedades e gerações.Oh conhecimento, a que me obrigas,
Para no fim, não passares de um reflexo,
E assim levares tais seres a procurar
Para sempre o outro lado do espelho.
100 Amiga Games in 10 Minutes
Thursday, January 24th, 2008C# Odds, Part IV: Give me usefull Boolean Operators
Tuesday, January 8th, 2008How many times have you written an ‘if’ statement like this:
if ((a && b) || !a) ...
You can think of condition ‘a’ behaving like a switch. Its like saying, if the switch is on, please take into account condition ‘b’ in order to do something; if it is off, then simply do it*. Now rewrite ‘a’ and ‘b’ as larger, real-word, classes’ fields/properties, mix more logic evaluation, and voila: an unreadable long expression.
Funny thing is, there *exists* a boolean operator that evaluates the very same way: it is called “implication”. Unfortunately, C# doesn’t have a keyword for it (same with Java, Python…). If it had, the code could be written as simple as:
if (a -> b) ...
Far more readable to me. Maybe they didn’t wanted to use the -> symbol because of the C++ syntax heritage? Who knows…
* Real-world example? Easy. You want to override the display of a dialog-box: if the switch is on, the application always asks for user confirmation; if it is off, it simply executes whatever it needs to.
Update: Hugo Ferreira (same name as mine), as pointed out that you can simplify ((a && b) || !a) to (!a || b); thank you.
C# Odds, Part III: Beware of anonymous delegates
Sunday, December 30th, 2007Consider the following code:
public class TestEvent {
public event EventHandler FireUp;
public void InvokeFireUp() {
if (FireUp != null) FireUp(this, EventArgs.Empty);
}
}
class Program {
static void Main(string[] args) {
List<TestEvent> fires = new List<TestEvent>();
for (int i = 0; i < 10; i++) {
TestEvent t = new TestEvent();
t.FireUp += delegate { Console.WriteLine(i); };
fires.Add(t);
}
foreach (TestEvent t in fires) t.InvokeFireUp();
Console.ReadLine();
}
}
If you are expecting it to print the numbers from 1 to 10 then you’re wrong
The thing is, external variables used in anonymous delegates are passed by reference (even value types like int). In the loop, the variable i is not recreated but increased by one. In the end, i will contain the last value and every event fired will simply write down the value 10. To work as intended, you should write the loop as follows:
for (int i = 0; i < 10; i++) {
int j = i;
TestEvent t = new TestEvent();
t.FireUp += delegate { Console.WriteLine(j); };
fires.Add(t);
}
Because j is defined “inside” the loop, it will always be a new variable (and hence a new reference in memory).
C# Odds, Part II: More about Access Modifiers
Saturday, December 29th, 2007In my previous post I argued about the behavior of the protected keyword in C# being counter-intuitive. Some people commented on my post (to whom I thank for the participation), with several kind of reactions: there were suggestions to just change the field to public, to make a getter/setter method (property in C#), to go back to university and stay awake in OOP classes (*sigh*), and to use a real language instead of a Microsoft one (eheh). I’ll try to answer to all of those comments here, because I believe that understanding the languages we work with is important to develop correct and sophisticated programs using the Object Oriented paradigm (and not just write C with Classes).
To clarify further the issue, let’s just call stuff by their name: the concept we are discussion is called Access Modifiers. Access Modifiers are also used in C++, Java, Smalltalk and several other OO (arguably more or less) languages. Access Modifiers exist to aid the process of Information Hiding which is part of the Encapsulation strategy used in OO (or separation of concerns). Some argue that Encapsulation and Data Hiding are the same. Personally (and several other people including some from the Python and Java community) I tend to disagree. But the important concepts to stick around can be summed up by the following quote from wikipedia:
“In computer science, the principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. The protection involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change). In modern programming languages, the principle of information hiding manifests itself in a number of ways, including encapsulation (given the separation of concerns) and polymorphism.”
You may follow the links for further information, but the main reasoning I’m trying to follow here is that using public everywhere around is bad (I’ve seen this countless times). It can appear to be harmless in simple/academic applications, but when designing a full blown framework that will be used by other people, don’t ever underestimate the capacity of users to screw up things (including yourself after you decide to reuse a component you’ve done 1 month ago and don’t remember that, while that field is public, YOU SHOULDN’T TOUCH IT!!).
That said, lets look at the definition given by Microsoft to their Access Modifiers:
- public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
- private: The type or member can only be accessed by code in the same class or struct.
- protected: The type or member can only be accessed by code in the same class or struct, or in a derived class.
- internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
Still with me? Great. Everyone knows public well enough. Internal is simple to understand too. But if you think private and protected follow the same rational, guess what: you’re wrong. Compare the following code with the one in the last post:
class A {
private int protectedField;
public void doStuff(A a) {
a.protectedField = 3;
}
}
class Program {
static void Main(string[] args) {
A a = new A();
A aa = new A();
aa.doStuff(a);
}
}
It compiles, as it should! Though members doStuff and protectedField are of different instances, they are defined in the same class. Look at the definition of private: “The type or member can only be accessed by code in the same class or struct”. Are you following me? Private basically says: “I don’t care who tries to access this member, as long as it is within the context of the same *class*.”
Now let’s remember the code using protected:
class A {
protected int protectedField;
}
class B: A {
public void doStuff(A a) {
a.protectedField = 3;
}
}
It fails to compile, though the definition of protected says: “The type or member can only be accessed by code in the same class or struct, or in a derived class.” Can you spot the differences? The text is the same except that it adds “or in a derived class”. Well, B derives from A. So what is the problem? The problem, it seems, has nothing to do with instances being different. The exact error code the compile gives is: “Cannot access protected member ‘A.protectedField’ via a qualifier of type ‘A’; the qualifier must be of type ‘B’ (or derived from it)”. So in order for the member doStuff to have access to the protected field, a should be typed as B, despite the fact that protectedField is defined in A.
I would personally like to know the person who thinks this is intuitive (and sorry, but I will not even discuss why not just simply cast A to B).
To finalize, I just want to point out that these posts are called C# for a reason: this behavior does not emerge in Java
For example, the following code compiles and runs perfectly in JRE6:
public class A {
protected int protectedField;
}
public class B extends A {
public void doStuff(A a) {
a.protectedField = 3;
}
}
C# Odds, Part I: “Protected” Keyword
Friday, December 28th, 2007What is wrong with this code?
public class A {
protected int campoProtegido;
}
public class C: A {
public void doStuff(A a) {
a.campoProtegido = 3;
}
}
Actually, it won’t compile. It seems that the protected keyword only works at the instance context. So, although class C is a subtype of A, because it is a different instance than the instance of A we are trying to access, it fails at compile time in line 7. So much for encapsulation…
Any ideas besides turning the field campoProtegido public?
Please allow me to express my frustration…
Friday, November 16th, 2007… with captchas. They are becoming increasingly difficult. So diffcult, that I start to believe that very soon, only computers would actually be able to decipher a captcha. I, for instance, must be reaching my limit of pattern-matching abilities, since I’ve just been banned from a forum for failing 3 times in a row.
Happy birthday G0dLik3
Monday, June 4th, 2007My brother, main leader of Underworld Preachers, computer’s technologies student and overall good friend, has turned 0b10011 today. Happy birthday
Windows Inter-process Synchronization in Python
Tuesday, December 5th, 2006Suppose you have two processes that need to sync information between them. If you were using Linux, a SIGHUP signal would do the trick. But Windows don’t have signals…
Fear no more… We have Named Events to the rescue… I’ve found the need to use these for inter-process synchronization when I was confronted with the problem of having an external application reacting to database triggers. Of course, the RDBMS we are talking about is PostgreSQL, and the external application is made in Python.
Anyway, the trick consists of setting a well-known named Event in the external application (server), and then Pulsing this event inside a ‘plpython’ function in postgreSQL. So, the server would be something like:
import win32event
event = win32event.CreateEvent(None, 0, 0, ‘Global\EventXPTO’)
win32event.WaitForSingleObject(event, win32event.INFINITE)
print ‘Received event…’
But there’s a catch… If PostgreSQL is not running as the same user as the script, it will give an ‘Access is Denied’ error when trying to open the Event. Thus, we need to change the PySECURITY_ATTRIBUTES (first parameter of CreateEvent) from None to something that allows the world to access it. Here’s how:
import pywintypes
import ntsecuritycondef createEventSecurityObject():
sa = pywintypes.SECURITY_ATTRIBUTES()
sidEveryone = pywintypes.SID()
sidEveryone.Initialize(ntsecuritycon.SECURITY_WORLD_SID_AUTHORITY,1)
sidEveryone.SetSubAuthority(0, ntsecuritycon.SECURITY_WORLD_RID)
sidCreator = pywintypes.SID()
sidCreator.Initialize(ntsecuritycon.SECURITY_CREATOR_SID_AUTHORITY,1)
sidCreator.SetSubAuthority(0, ntsecuritycon.SECURITY_CREATOR_OWNER_RID)acl = pywintypes.ACL()
acl.AddAccessAllowedAce(win32event.EVENT_MODIFY_STATE, sidEveryone)
acl.AddAccessAllowedAce(ntsecuritycon.FILE_ALL_ACCESS, sidCreator)sa.SetSecurityDescriptorDacl(1, acl, 0)
return sa
Of course, change the event setup to:
event = win32event.CreateEvent(createEventSecurityObject(), 0, 0, ‘Global\EventXPTO’)
And the client:
import win32event
event = win32event.OpenEvent(win32event.EVENT_ALL_ACCESS, 0, ‘EventXPTO’)
win32event.PulseEvent(event)
You can certainly figure the rest on your own
It would be advisable though to read this MSDN article if you want to know more about inter-process synchronization in Windows.
P.S. Don’t forget to check win32api.GetLastError() when creating or opening events.
Java will take on the world
Thursday, November 30th, 2006Green Refugee, The Beginning
Monday, October 9th, 2006So me and my girlfriend got tired of her old Aquarium, and started to build a new one, based on the equipment we already had. Here’s the result…
24 September 2006:
30 September 2006:
8 October 2006:
Flora
Fauna
- 2 Corydoras Aenus
- 1 Crossocheilus Siamensis, SAE
- 20+ Neocaridina Denticulata Sinensis, Red-Cherry Shrimp
- 13 Paracheirodon Inessi, Tetra Neon
Setup and Equipment
- Aquarium 50×25x25 (31l)
- Eheim Powerball Filter
- 36W Philips Dulux-L 6500K w/ Electronic Ballast
- 50W Heater
- CO2 Bio-Injection






