Блог пользователя oversolver

Автор oversolver, 7 месяцев назад, По-английски

Inspired by One-letter variables

My template for coding full of double-letter defines and functions. Each new addition requires a lot of thought about how to call it.

aa - never use
bb - define begin end (most likely yours "all")
cc - can use for count of c???
dd - dp for down, beside with du, dr and dl
ee - define for single parameter lambda
ff - define for recursive lambda
gg - using for naming function when I spend more then 5 seconds to think about proper name
hh - never
ii - define for create and cin ints (input ints lol) (btw I see it is japanese meta, but I am sure I have started using it first)
jj - same but for arbitrary type
kk - never
ll - using ll = you know
mm - never
nn - never
oo - never but in good old times of icpc my teammate used it for defining infinity
pp - binsearch in template (comes from partition_point)
qq - never but looks like I must use it for something
rr - define for debug printing (comes from cerr)
ss - the only usage: stringstream ss;
tt - counter in program for count some operations (do not believe exec time)
uu - using/used and up, beside with ul, ur and ud
vv - I wanted once to add to template function for create multi-vector and call it vv but failed with design
ww - cant even imagine....
xx - geom??? better x2
yy - in template function to convert bool to yes/no
zz - same as xx

How often you using double-letter naming?

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Well, I can just say I hardly use variable names consisting of more than 2 chars! However, I use "1 letter + 1 digit" more often. Below is an example (guess what it does):

#define y1 Y1 // you know why
bool ok(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
	if ((x2 - x1) * (y4 - y3) == (x4 - x3) * (y2 - y1))
	{
		if ((x2 - x1) * (y3 - y1) != (x3 - x1) * (y2 - y1)) return true;
		if (x1 == x2 && max(y1, y2) <= min(y3, y4)) return true;
		if (x1 == x2 && max(y3, y4) <= min(y1, y2)) return true;
		if (x1 != x2 && max(x1, x2) <= min(x3, x4)) return true;
		if (x1 != x2 && max(x3, x4) <= min(x1, x2)) return true;
		return false;
	}
	int a1 = (x3 - x1) * (y4 - y3) - (y3 - y1) * (x4 - x3);
	int a2 = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
	int b1 = (x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1);
	int b2 = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
	if (a1 * a2 < 0 || abs(a1) > abs(a2)) return true;
	if (b1 * b2 < 0 || abs(b1) > abs(b2)) return true;
	if (a1 == a2 * 0 && b1 == b2 * 0) return true;
	if (a1 == a2 * 1 && b1 == b2 * 0) return true;
	if (a1 == a2 * 0 && b1 == b2 * 1) return true;
	if (a1 == a2 * 1 && b1 == b2 * 1) return true;
	return false;
}

I have to say such variable names give this code..."neatness"?

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I can proudly say that I have never used any of these abominations, except ss for stringstream and an array of strings.

  • »
    »
    7 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    I always use ss for stringstream and iss for istringstream. It seems I’d always like to split a name into two (or more) words and then put these words' first letters together to be a name for my variables, functions, etc.

    Like gd for generate_docs and gg for get_goals (Maybe? I think if someone sees my code that has gg, they would think it's referred to good_game).

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

I use aa when I'm stressed out while getting wa2 on an implementation heavy problem in a contest and screaming for it to be over

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Sometimes I use ii and jj as iterator names after i and j depending on the logic flow of the problem