LA.NET [EN]

TriviaArchive

Jun 03

At least, my answers, that is…

A few days ago, I’ve published a quiz I’ve found on Dan Garcia’s class. The question was:

which snippets prints always 5?

1,,)
main() {
   int *a-ptr; *a-ptr = 5; printf(“%d”, *a-ptr);
}

2)

main() {
  int *p, a = 5;
  p = &a; …
  /* code; a & p NEVER on LHS of = */
  printf(“%d”, a);
}

3)

main() {
int *ptr;
ptr = (int *) malloc (sizeof(int));
*ptr = 5;
printf(“%d”, *ptr);
}

I guess we’ve got a language problem here 🙂 the *always* part is really important and I’d say is the key to getting things right.

Option 1 is completely wrong: even if the name of the pointer variable was correct, that still wouldn’t work because the pointer doesn’t point to a valid memory position.

Option 2 could work…but what would happen if you had something like this instead of the comments:

int* q = &a;
*q = 20;

I guess that we can dismiss this option as *always* printing 5, right?

Finally, option 3…it seems almost right, doesn’t it? In my opinion, it isn’t. why? Simply because it assumes that malloc won’t fail and that is not correct (btw, even though it wasn’t guaranteed of always printing 5, the code for option 3 is also incorrect: it’s missing a null check after the malloc call).

So, my answer is: none of them will always print 5!

This is not the answer Dan accepted. He says (and maybe he has a point) that he can’t think of any system which doesn’t have space for allocating an int. That’s why he considers option 3 to be the correct one. It might be a good argument, but I’m still saying that *always* is important here and that the most correct answer is none. Opinions?

Jun 03

Is this true?

Posted in Trivia       Comments Off on Is this true?

Saw it on Sava’s blog. If it’s true, it’s going to be amazing!

Jun 01

Fair play is a b*tch

Posted in Trivia       Comments Off on Fair play is a b*tch

[Not technical, so you probably want to skip it unless you’re Portuguese or want to see how bad things are around here]

In Portugal, there was a football (soccer, if you’re in US) coach which said something like “fair play is a bitch”. I guess he was right…in fact, I tend to go a little further and say that in Portugal there’s really not much space for character…

This weekend I’ve decided to go and see an under 16 football match between Maritimo and Nacional (two local rivals). Well, the game wasn’t great but what I couldn’t believe is the character of most of those kids!  During the game, most of them kept provoking the  opponents (no sure why, but many Nacional players insisted in this strategy – and they didn’t need it because they were the better team) by kicking the opponents when the referee wasn’t looking or trying to elbow and justify it with ball protection…

The referee…what a f*cking disgrace! I guess that if he wasn’t there, things couldn’t really be worst…really bad, without any kind of consistency regarding fouls. As if that wasn’t bad enough, he simply didn’t exist in the disciplinary level and allowed one of the worst tackles I’ve seen go with a simple fault and no card! That tackle caused a serious injury in a kid – that careless entry broke his leg right there on the field! The worst thing of all is that is was done on *purpose* without any sanctions from the ref of from his coach (I can ensure you that if I was the coach of that team he would go directly to locker room and I’m not sure if he would ever play in my team again!)

What shocked me the most what that the crowd – mainly consisted of parents – kept asking their children to be more tough on the next dispute, instead of explaining that it was just a football match. I’m not saying that one shouldn’t put “everything” in the game; however,there’s a difference between giving 110% and being violent,which is what the game ended up being about…

I’m not sure why I’m still surprised with this kind of behavior. Probably that’s because I do try to forget that I live in a country where:

  • everyone puts a car on a handicap place;
  • if you remove the handicap place and put a barrier for no parking, people will just park in the middle of the street, by the barrier (even when there are parking spots at 50 meters!);
  • you cannot improve your life quality if you don’t know someone important. Just take a look at the new evaluation system introduced by the government where only the best will get promoted (btw, the best should be seen as a synonym of being someone’s family or having some important friends). This is such an interesting topic that I’ll have to return to it in the future 😉
  • the national sport is not football (as everyone might tell you),  but cheating the IRS;
  • there is simply no corruption. Ok, there is corruption, but nobody gets arrested for it (interestingly, most politicians get rich without any explanation);
  • kids don’t learn in the school and things get worst every year (now everyone has to stay at school for 12 years and the worst is that they end those 12 years without knowing anything!);
  • need I say more?

I guess that I thought that things wouldn’t be so bad with kids, but now I understand that there probably is no going place for us…after all, those kids are a mirror of the education of their parents…and I’ve already described most of their parents, didn’t I?

Jun 01

Are you using bing?

Posted in Trivia       Comments Off on Are you using bing?

I’ve tried it and didn’t dislike it (which is something new when I think about previous MS tries on the search engine world)…

May 28

Downloading .NET reflector

Posted in Trivia       Comments Off on Downloading .NET reflector

Not sure on how I should classify this, but I’d say that getting this error in 2009 from a page served by a company like redgate is incredible! Today I needed to download reflector, so I went to redgate’s site and chose the download option. When you do that, you’ll be redirected to a page that asks for name and email. Since I was in a hurry, I’ve just hit several keys in the keyboard and ended up introducing this:

error1

Notice the < on the email…then, clicking the download free copy produced the following result:

error2

fantastic, right?

May 27

C question from Dan Garcia

Posted in Trivia       Comments Off on C question from Dan Garcia

Currently, I’m following Dan Garcia’s CS61C course (which is freely available online). On lesson 6, there’s an interesting puzzle (which, btw, I got it wrong – I’ll tell you why on the next post). The question is: which snippets prints always 5?

1,,)
main() {
   int *a-ptr; *a-ptr = 5; printf(“%d”, *a-ptr);
}

2)

main() {
  int *p, a = 5;
  p = &a; …
  /* code; a & p NEVER on LHS of = */
  printf(“%d”, a);
}

3)

main() {
int *ptr;
ptr = (int *) malloc (sizeof(int));
*ptr = 5;
printf(“%d”, *ptr);
}

Option 2 says that there’s code between p = &a; and the printf line, but a and p are never on the left hand sign of an equals operation. With this data, which option (if any) do you think will always print 5?

May 26

Sheer mind power!

Posted in Trivia       Comments Off on Sheer mind power!

This is not a technical post, so if you’re not interested, just skip it!

Here’s the deal: a few days back, my good friend Filipe (aka, “super-loide” – long story, ok? but he knows why he’s called that:),,) started laughing when I said that I would reach the 10km mark on my treadmill. His words: “You won’t make it”. I didn’t say nothing at the time, but I knew I’d make it. Generally, I run 2 to 3 times a week, for about 25 minutes (at a max of 4 kms a run).

I’ve already run 6 kms in the past and it was a painful experience (especially because I don’t enjoy running). I knew that achieving the 10km mark meant that I had to run at least an hour, at 10Km/h. This wasn’t going to be easy…

However, I do believe in the power of the mind (I’d say that’s why I believe in the “Yes, We can” slogan too). And today, while I’m on a terrible cold, I’ve decided to reach that mark! It’s crazy, right? I know, but, after all, if I can do it today, I’ll be able to do it any day! And here’s the proof:

IMG_2630

And here am I, after running 62 minutes (almost dead, but really happy for achieving the mark):

IMG_2633

Btw, you can see one of my secrets for achieving my objective: Nightwish’s End of an Era DVD! The other was my wife, which helped me made the last 500 meters 🙂

So now you have it “super-loide” :). If I can do it, you can too! It’s all in the mind…

May 19

Wonderful news!

Posted in Trivia       Comments Off on Wonderful news!

Currently, I’ve got three wonderful cats. Luna, a cat that I’ve found in the street when she was two months old, got really sick in the last months…in fact, the vet had told us to get ready because her liver problems wouldn’t let her live much longer. All her blood tests returned some pretty bad figures…so bad, that the vet told us to forget her food diet and let her eat whatever she wanted.

And so we did…until that yesterday she stopped eating…we really thought the worst when we took her back to the vet again…however, it seems like she was, in fact, much much better (even though she wasn’t eating). After running some more tests, we got confirmation: she is, in fact, much better and she’ll probably get her appetite back in a few hours. As you can probably guess,this news has made me a really happy man! And I think that it’s time to get away from the PC and enjoy some time with my pets :,)

May 06

Incompetent people really have no clue

Posted in Trivia       Comments Off on Incompetent people really have no clue

I guess that we’ve all heard this in the past, but it seems like now there are studies that show that this is really true (thanks go to my friend JPC for sending me the link).

Most of us will react to this news like Dr. David Dunning and we’ll be be really worried and fear being one of them. If after reading the essay you don’t feel like that, I guess that it’s fair to say that you’re probably one of them :,,)

Apr 29

Opera’s 15th anniversary

Posted in Trivia       Comments Off on Opera’s 15th anniversary

468x60opera15

Hurray!

Apr 29

Windows 7 on multiple cores

Posted in Trivia       Comments Off on Windows 7 on multiple cores

I’ve just found this on Daniel Moth’s blog. I’m speechless…

Apr 23

Ok, so today I was watching a TV Portuguese program on animals and, as you might guess, bullfighting was one of the discussed topics. For starters, you should know that I’m against it. I’m not sure why some think that we have the right to create animals and them make them suffer for our pleasure (I guess that if we have that right, then we should go back to ancient Rome and throw those into the pits with lions. how about that?).

I’m not going into a discussion about its cultural aspects (don’t we need to evolve?)…I do accept that you say that you like it and that it’s your argument for watching it. Just don’t try to convince me that they don’t hurt while they’re in the arena like one guy did in the program I was watching…I mean, can anyone really believe that the bull doesn’t hurt and enjoys being stabbed? (please don’t anwer…this was rhetorical…)

oh well, I guess that it’s one of those topics where you won’t be able to reach a consensus, right? so back to coding again…

Apr 21

Today I took 10 minutes of my time and I’ve decided to use them in browsing through Stackoverflow. It completely blew me away…They have done a fantastic job in building a great software developer community which is open to anyone. This is going to be a great place to visit regularly. From now on I’ll surely dedicate 10 minutes each day to browse through the discussions (I’m sure I’ll learn something and, who knows…I’ll probably might even answer one or two questions)

Apr 20

Fog Creek guided tour

Posted in Trivia       Comments Off on Fog Creek guided tour

I guess that by now everyone has heard about Joel Spolsky and his company (Fog Creek), right? Ok, if you’ve got a minute, then watch this guided tour around their offices…the only thing I can say is that they do have excellent work conditions and that I’d love to work in a place like that one day!

Apr 19

2009 Lang.NET Symposium

Posted in Trivia       Comments Off on 2009 Lang.NET Symposium

Videos available.

Apr 14

Well, I’m thinking that the MVC platform hasn’t really much more for me to blog about, so I’m thinking about new themes which might also interest you. Here are my ideas for future posts:

  • I’m thinking on starting a basics series. The idea is to talk about concepts which I consider that every developer should know (ex.: patterns, OO programming concepts, etc). The cool thing about this is that I can use it to refresh my ideas too and it will probably help those which are starting programming;
  • I’m thinking into taking a deep dive on MEF and see if it might help me build easily customized/extendable apps. Not sure if this is the way to go, but…
  • Silverlight: at the beginning, I was a fairly active member on the Silverlight forums (at the time, it was still called WPF/e). However, I haven’t really done anything with it (professionally, that is) and haven’t really looked at it for years. I’m not sure if this is for me (ok, I’m not really a designer!), but I’m really curious about it;
  • C++: yes,I know…I’m insane,right? The truth is that I never mastered C++, even though I’ve written C++ code in the past (my first professional gig was developing C++ ATL COM components). If I go back there, I’m thinking about sharing my experiences with you (and I’m not doing this out of kindness…no, I’m hoping that someone will help me and put me back on track when I’m lost);
  • Multithreading: yes, this is something that I will surely pick up in the next days. I’ve already started reading another book in multithreading and you can count on seeing some thoughts about it here.

Ok, this are some extremely ambitious objectives and I’m not sure if work will let me fulfill all of them…anyways, you can bet that I’ll try hard…And what do you think about this plan?

Apr 03

Update: after all, it seems like this was also supported in vista…interesting :,,)

I’ve been so busy that I’ve neglected my windows 7 series…oh well….what can I say? 🙂

Back to the important stuff…one of the things I really love in windows 7 is that it lets me put one monitor in top of the other, like you can see next.

config

I do love this because this arrangement is really good for when I’m using my netbook and have it connected to an external monitor on a small desk and move the mouse in a natural way (with this configuration, going to to top monitor is accomplished by moving the mouse up, not to the side!). Just take a look at my current configuration:

IMAG0114

Isn’t this nice?

Apr 03

Did you know?

Posted in Trivia       Comments Off on Did you know?

I’ve just noticed this excellent presentation on the progression of information technology.

Mar 30

Just take a look.

Mar 20

Mix sessions online

Posted in Trivia       Comments Off on Mix sessions online

Just a quick note for those that stayed home: there are several MIX 09 sessions are already available. Go get them!

Mar 20

MIX almost over

Posted in Trivia       Comments Off on MIX almost over

And I still haven’t finished watching the 1st keynote…oh well, that’s what happens when you have lots of things to do…as you all know, MVC is out (which is great!) and I do intend to continue my posts on  it as soon as I can get my hands on a futures assembly which works with the RTM version…btw, can anyone access the codeplex site?

Mar 16

Technical debt

Posted in Trivia       Comments Off on Technical debt

Technical debt is a cool metaphor introduced by Ward Cunningham. Martin Fowler has a nice post on it here too. In my current job, I see this happening almost every day. The worst thing is that it really seems like there’s nothing that can  be done to correct things. 

It always starts with a tight timeline…here’s a typical scenario: “hey, lets forget the tests for this part…we must have everything ready by the end of the week and tests are just reducing our productivity”…I think we all know this is wrong…at least, that is my opinion…yes, tests will decrease your immediate productivity (remember, you’re writing more code and I’m positive that at least half of it will be in testing – at least, if you want to have good code coverage), but they will improve your long time productivity (especially if you’re looking at it from a team perspective and you’re thinking about the future. btw, Scott Bellware has written about it in the past. If you have the time, go read some of this posts….).

Like Ward and Fowler say, sometimes it’s ok to incur into some “technical debt” to get things out of the door, but I do also think that it’s important not to let it get out of control. This is important,so I’m repeating it here: don’t let it go out of control! Never! Unfortunately,this is almost impossible (at least, this is what I’ve been seeing in all the projects I’ve been working in the last years). After you lose control, it will be extremely difficult to recover. Let me give you an example…in this last week I’ve been rewriting  and refactoring an app which doesn’t have any kind of tests…as you might expect, this is really close to a nightmare! And not good to morale either! Progress is really slow and I seem to be cursing the guy that wrote the app from 30 to 30 mins (when everything goes well…the interval decreases when you find WTF snippets!)

Now, instead of adding more value to that app, I’m just cleaning it up…not really productive, but, in my opinion, this is really necessary so that we can get things under control again. Of course, this would be unnecessary if the original developer had thought about the future and hadn’t incurred in such a high technical debt!

Mar 12

Multithreading is one of the topics I’ll have to start looking at with more attention and I’m thinking of adding posts about it in the future. Today I’ve read an interesting article on how to debug multithreaded applications on the site Packt. The author has also written a book on that topic (which I’ve already received). Yes, I’ll be publishing a review about it when I finish reading it.

Mar 12

Congrats!

Mar 09

Beware: this is a rant! CGD returns withdrawn money to its clients

Posted in Trivia       Comments Off on Beware: this is a rant! CGD returns withdrawn money to its clients

You know what: Portugal is really becoming  a 3rd world country…Just take a look at this.  It’s only another sad episode that happened here. I’ll translate since it’s in Portuguese. It says something like this: CDG (Caixa Geral Depositos) returns money that it had withdrawn from the  client’s accounts without any warning. What happened? Ok, I’ll explain. A few years ago the government decided to help those that earned less to buy a house. In practice, what this means is that the state would help you pay your monthly mortgage if your income didn’t reach a certain threshold. Until 2007, you’d have to deliver the previous year’s IRS declaration to the bank so that they could perform the calculations and see if you’re still eligible for that help.

From 2007 onwards, credit institutions started communicating directly with finances. So, everyone stopped delivering the IRS declarations to the bank. My mother was one of people who got this kind of credit approved ten years ago. Last week, she received a letter from the bank saying that there had been some problems with its system and that some people might be paying more that they should and others were paying less. The letter mentioned that this problem had been solved and that they would automatically update everything. Now, they’ve also said that they were available for negotiating with the clients in order to minimize the impact that this might have. The most curious thing about this letter is  that it was a template letter, ie, the bank sent that letter to everyone instead of  creating custom letters for each client informing them of their own status.

Guess what? On the next day the money was gone from my mother’s account. They simply withdrawn the money without saying anything. My mother didn’t even knew she was owning money and she didn’t even had time to go to the bank and ask about it before the money was withdrawn (as I said, the letter from the bank didn’t give this info – they just said that some paid more and that others paid less, remember? And she received it on one day and the money was gone by the end of that day… )

The best part was the explanation given by the bank (in my presence). In response to ”where’s the money”,they simply said that they had to withdraw it because my mother was owing that money to the finances. Now,this is really an interesting answer because 1.) when you’re owing money, they (finances) need a court order to get access to your stuff and 2.) she didn’t sign anything giving permission to the bank to go and take money from her account.

It was obvious that this was not a valid operation, but even so the bank clerk decided to keep justifying it with the same answer. And he even said that if I wanted more info I should go and ask the finances about it.Arguing with him was a waste of my precious time, so I did take my case to the consumer’s protection organism and yes, they’ve confirmed me that this is not  legal. And the best thing of all is that at night SIC (Portuguese TV station) showed a report where many were complaining about that problem. Interestingly, the money was back in the client’s accounts on the next morning (at 3:30 AM of a Saturday, and that is what the news I’ve linked to says). Now, I’m only putting this here because I’d like to comment Mr. Paulo Sousa’s remarks regarding this incident. He says something like this:

"o processo foi ao longo de meses fruto de numerosos contactos entre a nossa rede de agência e os nossos clientes, acrescentando que, ele próprio enviou, no passado dia 20 de Fevereiro, uma carta aos clientes que estavam abrangidos pela situação a informar o que iria suceder e a sugerir um contacto imediato com a rede"

In English, it says something like:

“the process was the result of several contacts on these months between our agencies and our clients, and that he had sent several letters to the clients informing them about what was happening and suggesting a quick contact with the agencies”

I’m sorry, but this is  a lie. My mother wasn’t contacted by anyone on the local agency. the only contacts that occurred were all after the unauthorized money withdraw and they only happened because we went there and asked for our money. As I’ve said, the only thing the bank said was that this withdraw wasn’t really its fault (which is a lie) and that they couldn’t do anything about it. I’m still not sure on how they can keep saying that it wasn’t their fault when it clearly was. And if the withdraw operation is valid, why did they returned the money quickly to their customers?

It would be  unbelievable if they could get away with this behaviour (which they didn’t, thanks to the DECO)…btw, this is a government bank…unbelievable…and that’s all…end of rant…

Mar 07

In these last days I’ve been extremely busy working in my next book (which is going to be on LINQ) converting all the code from C# to VB.NET and adding some word docs  for VB.NET programmers. Comparing both languages leads me to thinking that they’re getting closer and closer with each release. In the current version, I think that it’s fair to say that C# has more features than VB.NET (for instance, C# supports anonymous methods and its Lambda support is superior), but there is also some cool stuff which C# doesn’t support (ex.: XML literals).

However, I’ve noticed that several things which aren’t still available on VB.NET have already been announced for VB.NET 10 (for instance, it seems like VB 10 will support automatic properties). In practice, this means that with the next release, the differences between the two languages will really be minimum. Is it possible that, in  a near future, both languages will end up working over the same abstract syntax model? In others words, will C# and VB.NET end up being two concrete syntax models that are mapped into a common abstract syntax model? Probably not, but that would be interesting…

Mar 07

The Manifesto for Software Craftsmanship

Posted in Trivia       Comments Off on The Manifesto for Software Craftsmanship

Here it is.

Feb 27

One of the things I do like to do is reply all my mail in plain text. So, like any normal person, I went straight to the options and searched for something about mail replying. And yes, there are a couple of options there. Just to  be sure, I’ve set them all to plain text. Despite that, whenever I hit the reply button, I’d always get rich text if the original message was in plain text.

After some searching, it seems like the only way to get this automatically for all mails is by reading all messages in plain text or by creating a macro. So, I went with plain text. Now, I’d really love to know why can’t I have something that lets me read my messages in the original and *always* reply in plain text…

Feb 24

Paul do Mar mini-vacations

Posted in Trivia       Comments Off on Paul do Mar mini-vacations

I’ve just returned from a mini-vacations at Hotel Paul do Mar. Even though the services could be a little better, it was a really nice place to say and relax (as you can see from these photos). Now I’m relaxed and ready for more work (which involves ending the LINQ book which is going to be released by the publisher on March).