Nicolás Brailovsky


A modern blog

Archive for the ‘Grumpy’ Category

Dealing with Office on Linux

author Posted by: nico on date May 18th, 2010 | filed Filed under: Funny, Grumpy

Seen @ bash.org:

< adamkuj> are there any good open source tools for working with Access DB’s (mdb files)?
<@Dopey> rm
Comment: #evilgeeks

True, so true… It’s been said a thousand times, but I kinda like ranting… like it or not Office files are a majority out there. If you work with Linux, using it in a real enterprise environment, sooner or later you’ll run into someone using a propietary Office format. You’ll also run into someone who doesn’t know that you need OOO to open those weird odf files. You may need to produce an adecuately formated document sometime, and LaTeX may not be an option.

Deal with it. Install a VM, or Wine, and a copy of MS Office. Resistance is futile.

Random WTFs

author Posted by: nico on date May 10th, 2010 | filed Filed under: Grumpy, WTF

Random WTF 1

Note: Use dapper instead of edgy to use Ubuntu Dapper

Thank you captian obvious.

Random WTF 2

I’ve been working with a big-co supplied ACS server, but it’s IE only. WTF!? Aren’t ACS all XMLy so they can work everywhere? I hate you all.

Ubuntu: Sound still FUBAR’d

author Posted by: nico on date May 4th, 2010 | filed Filed under: Grumpy, Linux, WTF
Remember my problems with dual screen support in Ubuntu? Well, I still love bashing Ubuntu, and the sound system in Linux is certainly a topic to rant a lot. Making the sound work fine in Ubuntu is an odyssey in pain and frustration, unless it works fine out of the box. And even if it does, it may still have it’s kirks. Lots of them.

In my case the sound starts in mute. I know it’s a problem with pulse (which is a WTF in itself) and alsa, I don’t really care what’s the problem though, I just want to play my mp3s collection without having to carefully turn the knobs up to eleven in alsamixer.

After trying a lot of the “solutions” found on the internets I’ve decided the best thing to do, short of switching back to windows me, is adding the following to my “fix_ubuntu_fuckups.sh” start script, which already contains my dual-screen pseudofix:

  1. amixer -c0 — sset Master playback -0dB unmute
  2. amixer -c0 — sset Headphone playback 0dB unmute
  3. amixer -c0 — sset Front playback 0dB unmute
  4. amixer -c0 — sset PCM playback -16dB unmute

This sets alsamixer to normal volume levels. As for the real fix, I’ll wait till the next Ubuntu version. I wonder which sound subsystem will they chose next time.

I hearth Berkeley

author Posted by: nico on date Apr 10th, 2010 | filed Filed under: C++, Grumpy
  1. error: cannot convert ‘Db**’ to ‘DB**’ for argument ‘1’ to ‘int db_create(DB**, DB_ENV*, u_int32_t)

Thank you very much, Oracle Berkeley, for having a type named Db and another one named DB, and for never using namespaces. It makes my work a much more interesting challenge (*).

(*) Yeah, I know, Db is for the C++ wrapper and DB is for the plain C API (**). So what, I hate you all anyway.
(**) I’m working on a project with Berekley DB and it has enough WTF moments for a complete blog… I may post some of them, as a catharsis method. (***)
(***) Or because it has some interesting stuff too… who knows. Recursive note FTW (**). I think I have already done that, haven’t I?

Operator sizeof (AKA Reading Berkeley’s FM, take II)

author Posted by: nico on date Mar 29th, 2010 | filed Filed under: C++, Grumpy, Programming, WTF

Last time I told you about an evil snipet I found on Oracle Berkeley DB’s manual:

  1.  skey->size = sizeof((struct student_record *)pdata->data)->last_name;
And we concluded it’s trying to… well, dereference a number. And yet it compiles. What the hell is going on there?

The answer here is in the subtleties of the sizeof operator. That’s right, operator, not function. Plus is an operator. Less is an operator. * is a (unary) operator. sizeof is a unary operator too. The relevance of this is that operators can behave in more bizzare ways than functions do. In this case there’s a difference between this two lines:

  1.  MyClass x;
  2.   int a = sizeof(MyClass);
  3.   int b = sizeof(x);

A very subtle difference. Can you spot it? a and b will have the exact same value, rest assured. The difference is in the operator itself: sizeof MUST have parenthesis when applied to a type name, yet parenthesis are optional when applied to an instance of a datatype, so this code is legal:

  1.  MyClass x;
  2.   int a = sizeof(MyClass);
  3.   int b = sizeof x;

Oh, wait, the fun doesn’t stop there: sizeof also has bizarre precedence order, meaning it won’t get applied as you expect it. So, this is valid too:

  1.  struct MyClass { int y; } x;
  2.   int b = sizeof x->y;

Can you see where we are going? Knowing that sizeof will be applied last lets you write something like this too:

  1.  void *ptr = …
  2.   int b = sizeof((X*)ptr)->y;

Which means nothing else than “store in b the size of member y in struct X. It should be easy to see why BDB’s example does compile, and why did I spend half an hour trying to understand the reason it compiled fine.

By using some more casts and a clever arangement of parenthesis you can come up with a great job security device.

Reading Berkeley’s FM

author Posted by: nico on date Mar 26th, 2010 | filed Filed under: C++, Grumpy, Programming, WTF

I got this from Oracle Berkely DB’s FM:

  1.  skey->size = sizeof((struct student_record *)pdata->data)->last_name;

Take a good look at that pice of code:

  1.  a_number = sizeof((T*)pdata->data)->last_name;

Again:

  1.  a_number = sizeof(Whatever)->field;

Wait a minute. typeof(sizeof(x)) == const unsigned int. Right? So, again:

  1.  a_number = 42->field;

There’s no way that first line can compile. Go and check it (in the example, not the last line please). I’ll wait. Done? Yeap, I was surprised to, it does indeed compile. Mi first reaction towards this discovery went something like this:

What is going on there? It took me a while to figure out how evil Berkely ‘s manual can be. The answer next time.

I hate Berkeley

author Posted by: nico on date Mar 25th, 2010 | filed Filed under: Grumpy, Programming

Polymorphism taken to 11:

SQL Term Oracle Berkeley DB Equivalent
Database Environment
Table Database
Tuple/row Key/data pair
Secondary index Secondary database

WTF ORACLE, WTF.

Cofeeeeeee

author Posted by: nico on date Mar 18th, 2010 | filed Filed under: C++, Grumpy
  1.  
  2. int main() {
  3. otl_connect db;
  4. otl_connect::otl_initialize();
  5. db.rlogon("whatever");
  6.  
  7. int cuarentaydos;
  8. const char *sql = "select 42 drom dual";
  9. otl_stream stmt(1, sql, db);
  10.  
  11. if (!stmt.eof()) stmt >> cuarentaydos;
  12. std::cout << "En la base 42 == " << cuarentaydos << "\n";
  13.  
  14. db.logoff();
  15. }
  16.  

I spent half an hour looking for the error. How come drom is not a standard sql keyword? Damn!

Methods and instance variables: should there be a difference?

author Posted by: nico on date Oct 19th, 2009 | filed Filed under: Grumpy, Programming
Many times I find myself forgetting the parenthesis for a method with no arguments and a nasty compiler error. This reminds me of my Rubyst times. There’s no difference between methods and instance variables in Ruby, so this:

class Foo
@bar
end

foo.bar = 1

variables

Could be changed to

class Foo
@bar
def bar=(val) @bar = val end
end

foo.bar = 1

and the dependant objects using the property would use the new behaviour without ever needing a change in the way bar is accessed.

In languages like C++ the parentheses are mandatory so you can have a clear difference between instance variables and methods, and between a method call and a function pointer (which should be referenced as &Foo::bar and not Foo::bar anyway).

All of this always leads to the same conclusion: closing parenthesis should not be needed!

What I like about Linux and C++

author Posted by: nico on date Oct 12th, 2009 | filed Filed under: Grumpy, Programming

Some time ago I worked in a team with a guy who liked programming in Java. Really like it, to the point where the weaknesess of the language were all in his blindspot. I did the only sensible thing a guy like me can do, sent him a mail stating that the lack of closures in Java would doom the language as soon as C++0X comes out.

That is not really my opinion but it sure served my pourpose. Trolling. Obviously I recieved a three page email back, explaining why adopting closures as part of the Java specification was irrelevant due the use of inner classes (?) or something like that, I don’t remember now. MountainTroll

I must admit this was not my first time trolling around a language zealot (and it IS fun, let me say it) may this post serve as a public apollogy for those who have suffered it.

What was that long introduction for? There are lots of religious wars amongst programmers. Vim vs emacs, Windows vs Linux, tabs vs spaces. We all know (Vim, Linux, tabs) what are the best options, but fighting is still fun and with due respect for each other quite healthy.

CW Turbo Tank

It’s difficult to distinguish when “religious fantatism” for a tecnology overcomes pragmatism, making a task much more difficult than it should, instead of simplifing it, because of the use of a specific tool. Take for example watching a movie in console mode. Kudos to whoever can do it, I have better things to do in my spare time.

How does all this relate to Linux, C++ and programming in my twisted mind? What I’ve noticed about (most) people using C++ and GNU/Linux as a working platform is that we are always complaining. No, I don’t mean we’re grumpy old dinosaurs (altought you can certainly find a fair share of those too) but you tend to meet people who are much more aware of the limitations they platform of choice has.

678grumpy-posters In my years as a programmer I’ve worked with PHP, Java, .NET, Ruby, Linux, Windows, etc. From all these platforms I could say I found people truly offended when told their platform sucks. Most, if not all, C+++Linux (lol, ain’t I smart?) programmers I’ve found so far have one thing in common: they (we) all know both Linux AND C++ suck. They suck hard, C++ syntax is messy, Linux has configuration and portability problems, pointers will screw you at any chance. But we know this.

Far more important than actually choosing the perfect OS, the perfect language, the perfect whatever, choose what better fits your skills and your team, then know your limitations by hearth. It’ll save you lots of trouble.

PS: I like the new category, “Grumpy”. Here I’ll post all kind of rants and subjective opinions I feel like posting.