Naming variables and arguments

I rewatched recently a C++ conference video:

CppCon 2018: Kate Gregory “What Do We Mean When We Say Nothing At All?”

Then I did some research and posted a comment which YouTube decided to remove because it detected “Spam, deceptive practices, & scams policies” violation.It didn’t provide any detail, or a way to check what the comment was or appeal the removal. Nice! I was only able to find out which comment it was by looking at my Your YouTube Comments history and see which comment was NOT there (you have to rely on your memory, because there is no mark that a comment was deleted, or when, on which video…). I will try to reproduce it from memory here (because I cannot find it anywhere), I’ll let the reader decide it it was spam, scam or not:


It’ not enough to name your arguments, the names have to be meaningful.
In 2023 we still have this:

  • const char * strstr ( const char * str1, const char * str2 );
    thanks cplusplus.com ! WTF is str1 and str2? And this is the 1st result on Google (I mean duckduckgo.com)
  • char *strstr(const char *haystack, const char *needle) tutorialspoint.com has it right
  • char *strstr(const char *str,const char *strSearch); so does learn.microsoft.com
  • char *strstr (const char *s1, const char *s2); geeksforgeeks.org can F*** right off
  • char *strstr( const char *str, const char *substr ); cppreference.com does it well
  • char *strstr(const char *string1, const char *string2); IBM can also go to hell
  • char *strstr(const char *s1, const char *s2); so do pubs.opengroup.org

Yay, at least they all name the arguments. Are we happy now?
Well, actually not all, this is what newlib has to say about this:

  • char *_EXFUN(strstr,(const char *, const char *)); 1 or
  • char *strstr (const char *, const char *); 2

Good luck to my fellow embedded developers!

How are junior programmers supposed to name arguments right when this is what they learn from the big guys?

And contrary to what cplusplus.com says, strstr returns a NON const pointer from 2 const pointer. Congratulation!

We are all doomed!

[1] github.com/eblot/newlib/blob/master/newlib/libc/include/string.h
github.com/32bitmicro/newlib-nano-1.0/blob/master/newlib/libc/include/string.h
[2] sourceware.org


… and I understand why YouTYube might detect the “excessive” domain name usage and a couple of links as spam, but FUCK them too for removing my educational comment without providing: 1/ any means to see the comment they have an issue with; 2/ recover a copy; 3/ appeal to restore it… Meanwhile leaving trash comment up and letting actual scams trough!

Computer Color is Broken

Well, yeah, writing good code not only requires the programmer to know how to write code or learning a programming language, but requires the understanding of physical, psychological and other processes involved interfacing the code. (For manipulating pixels understanding the creation, reception, transformation processes involved, and not just knowing math, how to average numbers. And for GUI development understanding humans…)

This raises the question if we (will) need coders, programmers at all, or only professionals who know their field and tell the computers how to write the code.

The Hidden Secrets Inside Internet The Deep Web – Documentary 2015

Ezt találtam ma. Ajánlom mindenkinek aki nem akarja a homokba dugni a fejét…


(Csak másfél óra ebből a film)

Ahogyan röviden össze tudnám foglalni:
A story about Silk Road, cryptography and drugs…
and also another story about the death of privacy, government overreach, corporate interest, game of law and death of justice. 🙁

És hogy hogy mennyire rossz úton járnak a war on drugs hadjáraton, vagy hogy az mennyire nem az állampolgárok megóvását és a közbiztonságot szolgálja.
https://youtu.be/gOHb5Jua-mE?t=1h5m9s

Why Pascal is better than C

Or to be more specific, why is C bad.

I learnt Pascal before C, and Delphi before C++. So this might be just that. Meaning that my brain is damaged by Pascal 🙂

I’m also Hungarian and the sentence and phrase construction order is different than in English. And because you express your thoughts in language, it pretty much means that we learn to think in different order than humanoids brought up learning English. The order in Hungarian is from big to small. In addresses (country, city, street, number), time (year, month, day, hour, minute, seconds…), names (family name, given name), even in articles (what we want to discuss, and then the details), someone’s stuff rather then stuff of someone.
So this might also contribute to my insanity. What seems to me logical order, might be different for others.

So, Why is C driving me crazy?

There is a lot of reason for it, but for now just look at a simple example.
Lets move some memory around.

When I thing about moving, I think of “Let’s move this to somewhere”. (this, to)
And I would think when a messenger gets a delivery task to carry something, form somewhere, to somewhere that would be the order (form , to).
If I know “where from” then I can already start going that way to pick it up. That is how taxis work, they first only know where to pick up someone. That is also how the IP header is structured (Source IP Address, Destination IP Address).
It feels natural: from somewhere, to somewhere.

So when I want to move some bytes in the memory I would specify from where, to where, and how much.

And that is how Move in Pascal does it:
procedure Move ( const SourcePointer; var DestinationPointer; CopyCount : Integer ) ;

On the other hand memmove in C uses the opposite order.
void * memmove ( void * destination, const void * source, size_t num );
This just doesn’t feel right.

(Both can handle overlapping source, destination buffers, that’s why they are move and not copy.)

When you write in command line you also use source destination order (copy, cp, move, mv) [1]
PHP uses from, to order too. [2]
C#, .NET also uses source, destination order. [3]

You can find the same reversal in source and destination operand ordering in AT&T and Intel assembly formats.
Intel has dest = source order, while AT&T the opposite.
(It’s strange, I’m compelled to end my lines with a semicolon;)

Example: [4]

Intex Syntax AT&T Syntax
mov eax,[ebx]
mov eax,[ebx+3]
add eax, 4
movl (%ebx),%eax
movl 3(%ebx),%eax
addl $4, %eax

I like Intel’s syntax more. Because it resembles the assignment operator order:
eax = *ebx;
eax = *(ebx+3);
eax += 4;

And I know that it is the opposite order (dest, source) of Move, but I’m crazy like that…
But mov actually means: make this equal to that, (there is no actual moving from).

I think the order should always be this, that and here, there.
So if I call a function Move, than it should move from here to there.
But if I call a function MoveTo, then it might move to here from there.
(We could clarify by naming it MoveFrom or MoveFromTo (which sound awful), but the from, to order just seems natural to me.)

Next time I might write something about constructors. Till then you can also read my rant about arrays, and why are they suck in C, and rock in Pascal… 😉

GUI Design

Egyre több a jól tervezett grafikus felület, köszönhetően a sok éves tapasztalatnak, szakembereknek, tanulmányoknak. De sajnos nem mindeki olvassa ezeket, és sajnos egyre több a roszul (vagy egyáltalán nem) tervezett felhasználói interface is.

A dialógus dobozokat pl jó lenne elkerülni.

Death to the Dialog Box
Teaching Users to Read
The “Just In Time” Theory of User Behavior

Érdemes ezeket elolvasni mindenkinek aki GUIt programozik…

Van még ezeken kívül nagyon sok felhasználói felület pszihológiával és tervezéssel kapcsolatos anyag.
Az egyik kedvenc szabályom:
Jakob’s Law of the Web User Experience – “users spend most of their time on other sites”

Python

I wanted to look into some Python development, because it seemed a cool (productive) language.
I have seen some python code before, but have not coded much (if any).

So yesterday I installed an IDE for it, and today wrote a (simple) calculator. This included installing the environment (and watching StarCraft 2 DreamHack Open : ) .
Here is the code,
and a readme for it.

Opera Memory leak Update

So I decided to get the bottom of it, and disabled javascript on all but a few pages. The memory leak disappeared and Opera 12 consumes less than 300 MB RAM (with 32 open tabs).
opera 12 without memory leak
While Chrome consumes more than 1.3 GB RAM with 10 tabs, and IE around 800 MB with 2 tabs (while flash playing video)…
Opera is still my favorite browser, but it’s unfortunately dying off…

DEFCON 20: Black Ops


Timing attacks, clocks, RNG, entropy starvation…
theory vs. development, counter measures against hackers
“Code needs to work!” “This is why PHP is good” escaping = blacklist = does not work most of the time
hard to grep for missing escape 🙁
give data context/meta-data (code/command, data/user input)