Page 1 of 4
Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 5:16 am
by TudorOS1
I paused my OS development indefinatly while I worked on mods to Minecraft in Java.
When I resumed I was looking in the source files, and I found this in my scheduler:
Code: Select all
//Why did the chicken cross the road?
//He didn't, his thread got pre-empted
I have left odd "humerous" things in my source files quite a lot, mostly for fun (programming can get boring), for instance, also in my scheduler, I found this:
Code: Select all
//This code came from the time components but shhhhh
DOUBLE_DWORD temp = count;
So I do have one question, what funny comments have you put in your OS?
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 6:42 am
by bluemoon
I got comment not on my kernel but some production code looks like this due to policy:
Code: Select all
//! Hey, this function make fruit punch, what else you'd expect?
//! \param apple_juice amount of apple juice
//! \param apple_juice amount of orange juice
void make_fruit_punch(int apple_juice, int orange_juice) {
...
}
Seriously, it ain't funny, adding redundant comment to simple function is a waste of screen estate.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 6:53 am
by AJ
Hi,
Looks to me like that has been done for parsing by a documentation generator such as Doxygen. In which case, I guess it makes sense to have the entire interface documented, even simple functions.
Cheers,
Adam
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 7:33 am
by Kevin
And had you documented what happens when apple_juice or orange_juice (or even both) are negative, your comment might actually have ended up useful.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 9:46 am
by Antti
TudorOS1 wrote:what funny comments have you put in your OS?
I do not have funny comments in any code I write (or even colloquial writing style there). Yes, I am boring and that is my style. I like to do it as professional as I can (whether it is a "hobby" or "professional" project). I like it when the code comments are written like the soulless computer itself would write them. I do not want to express my current mood of the day there. Of course, what I have done so far has not been very professional when it comes to the actual code. However, you do not find any funny comments that would make it even worse.
Of course, I am not against people making funny comments. That is their style.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 10:19 am
by AJ
Hi,
I only tend to make any comments that may be considered funny when I've narrowed down a bug to a particular piece of code, but haven't yet worked out exactly why that bug is happening.
Other than that, it's pretty much all stuff that will be read by Doxygen or basic annotations explaining any "magic" (actual magic numbers or constants are properly declated as consts, but if I have "wait(200);", I may document that this piece of hardware requires a 200msec delay just because the datasheet says so).
Cheers,
Adam
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 10:24 am
by Jezze
Id say if your code needs comments you probably wrote bad code. That is unless the code has weird consequences that are hidden or not very obvious to the reader in which case a funny comment is a must to relieve tension.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 11:16 am
by bluemoon
Jezze wrote:Id say if your code needs comments you probably wrote bad code. That is unless the code has weird consequences that are hidden or not very obvious to the reader in which case a funny comment is a must to relieve tension.
While for simple code, the purpose of comments is to "compile with the whole theme", however, I think for serious project, most of the code require comment. The basic comment describe the interface (input/output parameters, any side effects), it's also good to document any assumption or fail cases, or why this piece of shi* is coded[e.g. due to customer request
] etc.
Without proper comment it's difficult for anyone, including a future instant of yourself, to maintain code more complex than a hello world.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 1:26 pm
by Combuster
The first rule of comments is that they are not the solution for poorly written code. Well written code doesn't need that much comments - just simple autocompletion and knowing the general theme does much more than having to look up (java)doc for everything you might use.
That said, funny comments don't typically end up in my code. The typical emotional comment typically takes the following format:
Code: Select all
// Do X because Y is stupid and does Z.
I'm also a personal fan of writing out the proofs for mathematical equations in comments directly above the implementation. Depending on the case in question, this not uncommonly results in code decorated with ascii art. Typically when it comes to that, half my colleagues wouldn't begin understanding it anyway - comments or not.
The closest thing to a funny remark is the occasional "Here be dragons" warning in my driver code.
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 2:48 pm
by Griwes
Not in the kernel, but in the same project's dumb imitation of Boost.Spirit from before splitting a single file with lots of template magic into smaller ones:
Code: Select all
/**
* Watch out, crazy template code ahead. All hope abandon ye who enter here.
*
* Lexer is full of run-time, er, somethings, this one is full of compile time
* ones. And run-time too. I *did* write `all hope abandon`, didn't I?
*/
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 24, 2013 3:02 pm
by Kazinsal
At the beginning of a function in a driver for some VirtualBox specific crap:
Code: Select all
// Dragons aren't scary enough. Here be snakes.
And when that function starts getting weird:
Code: Select all
// Programmer Indiana Jones is screaming like a little girl.
// I warned you, didn't I?
Re: Funny comments in your OS's Source code?
Posted: Thu Jul 25, 2013 12:59 am
by Velko
Being a Futurama fan, i couldn't resist.
Code: Select all
/* We're Owl Exterminators! */
avl_tree::~avl_tree()
{
clear();
}
Re: Funny comments in your OS's Source code?
Posted: Thu Jul 25, 2013 6:01 am
by bemk
This is the closest I got.
The statement about infinite loop, I think was from before I had the endProg call in there (which is just an assembly fuction halting the cpu). Cas van Raan is a classmate of mine, and he's a little foul mouthed at times. He asked me to put it in, so I did.
It only shows when you enable the "cas" flag before compiling, and you manage to panic the kernel (which I happen to do, from time to time).
Code: Select all
// Claim to have panicked, show the message and enter an infinite loop.
void panicDebug(char * msg, char* file, int line)
{
#ifdef CAS
// Little easter egg, a request from Cas van Raan
printf("****'s fucked up at line %i in file %s\n%s\nTry again!", line, file, msg);
#else
printf("Andromeda panic in %s at line %i\n%s\n", file, line, msg);
#endif
endProg(); // Halt and catch fire!
}
Re: Funny comments in your OS's Source code?
Posted: Thu Jul 25, 2013 9:03 pm
by bluemoon
Just found a funny comment (and behavior) on my boot loader code, it happens when it failed to parse the kernel executable.
Code: Select all
.phdr_fail:
mov edi, 0xB8000
mov rax, 0x1F211F211F211F21 ; Holy, Full screen of !!!!!
mov ecx, 80*25/4
rep stosq
hlt
Re: Funny comments in your OS's Source code?
Posted: Wed Jul 31, 2013 5:54 am
by qw
When I was programming in Basic I commented blocks that contained a lot of goto's, with "start of spaghetti code" and "end of spaghetti code". It also was my guarantee that no goto would jump into or out of that block.