Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Soricidus
Oct 21, 2010
freedom-hating statist shill
All my variable names are greek letters.

Adbot
ADBOT LOVES YOU

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
I just use "i" with subtly different diacritics.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



I just write my code pre-minified so I don't need another compile stage.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


In languages which support utf8 source, save extra space by using whitespace characters, especially zero-width varieties.

VikingofRock
Aug 24, 2008




Soricidus posted:

All my variable names are greek letters.

I'm always a little tempted to do this when there is a well-established greek letter for something in my physics code. So far I've resisted the temptation, but it would be kind of fun to write (r, θ, φ) instead of (r, theta, phi) or (radial_distance, polar_angle, azimuthal_angle).

Soricidus
Oct 21, 2010
freedom-hating statist shill

VikingofRock posted:

I'm always a little tempted to do this when there is a well-established greek letter for something in my physics code. So far I've resisted the temptation, but it would be kind of fun to write (r, θ, φ) instead of (r, theta, phi) or (radial_distance, polar_angle, azimuthal_angle).

I seriously am using θ to represent an angle in some visualisation code. Why not?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Soricidus posted:

I seriously am using θ to represent an angle in some visualisation code. Why not?

Because it's difficult for humans to type if they need to edit the code at some point. You might as well use a poo emoji.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Just use emoji for your variable names. Use the handy popup palette to store your recently used members.

xzzy
Mar 5, 2009

I still find it easier to google a unicode/emoji then ctrl-c it to paste in whatever I'm typing.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

VikingofRock posted:

I'm always a little tempted to do this when there is a well-established greek letter for something in my physics code. So far I've resisted the temptation, but it would be kind of fun to write (r, θ, φ) instead of (r, theta, phi) or (radial_distance, polar_angle, azimuthal_angle).

I do this when writing Mathematica code.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Never write image processing code. It always looks like this:

C++ code:
    /* do y samples first */
    int bs = 32;
    for (y = 0; y < h; y += bs) {
        for (x = 0; x < w; x += bs) {
            for (dy = 0; dy < bs; dy++) {
                for (dx = 0; dx < bs; dx += 8) {
                    unsigned char lp[8];
                    read8(lp);
                    for (si = 0; si < 8; si++) {
                        int px = rgbat(y+dy, x+dx+si);
                        int y = clamp((lp[si]-12) * 1.16);
                        rgb[px+0] = y;
                        rgb[px+1] = y;
                        rgb[px+2] = y;
                        rgb[px+3] = 255;
                    }
                }
            }
        }
    }

    /* now add in uv samples */
    for (y = 0; y < h; y += 64) {
        for (x = 0; x < w; x += 32) {
            int dx, dy, si;

            for (dy = 0; dy < 64; dy += 2) {
                for (dx = 0; dx < 32; dx += 8) {
                    unsigned char lp[8];
                    read8(lp);

                    for (si = 0; si < 8;) {
                        int u = ((lp[si++]-128) * 1.1);
                        int v = ((lp[si++]-128) * 1.1);

                        int dr = 1.370705f*v;
                        int dg = -0.698001f*v - 0.337633f*u;
                        int db = 1.732446f*u;

#define setpx                                                   \
                        rgb[px+0] = clamp(rgb[px+0] + dr);      \
                        rgb[px+1] = clamp(rgb[px+1] + dg);      \
                        rgb[px+2] = clamp(rgb[px+2] + db);

                        int px;
                        px = rgbat(y+dy, x+dx+si);
                        setpx;
                        px = rgbat(y+dy+1, x+dx+si);
                        setpx;
                        px = rgbat(y+dy, x+dx+si+1);
                        setpx;
                        px = rgbat(y+dy+1, x+dx+si+1);
                        setpx;
                    }
                }
            }
        }
    }

HFX
Nov 29, 2004

Suspicious Dish posted:

Never write image processing code. It always looks like this:

C++ code:
    /* do y samples first */
    int bs = 32;
    for (y = 0; y < h; y += bs) {
        for (x = 0; x < w; x += bs) {
            for (dy = 0; dy < bs; dy++) {
                for (dx = 0; dx < bs; dx += 8) {
                    unsigned char lp[8];
                    read8(lp);
                    for (si = 0; si < 8; si++) {
                        int px = rgbat(y+dy, x+dx+si);
                        int y = clamp((lp[si]-12) * 1.16);
                        rgb[px+0] = y;
                        rgb[px+1] = y;
                        rgb[px+2] = y;
                        rgb[px+3] = 255;
                    }
                }
            }
        }
    }

    /* now add in uv samples */
    for (y = 0; y < h; y += 64) {
        for (x = 0; x < w; x += 32) {
            int dx, dy, si;

            for (dy = 0; dy < 64; dy += 2) {
                for (dx = 0; dx < 32; dx += 8) {
                    unsigned char lp[8];
                    read8(lp);

                    for (si = 0; si < 8;) {
                        int u = ((lp[si++]-128) * 1.1);
                        int v = ((lp[si++]-128) * 1.1);

                        int dr = 1.370705f*v;
                        int dg = -0.698001f*v - 0.337633f*u;
                        int db = 1.732446f*u;

#define setpx                                                   \
                        rgb[px+0] = clamp(rgb[px+0] + dr);      \
                        rgb[px+1] = clamp(rgb[px+1] + dg);      \
                        rgb[px+2] = clamp(rgb[px+2] + db);

                        int px;
                        px = rgbat(y+dy, x+dx+si);
                        setpx;
                        px = rgbat(y+dy+1, x+dx+si);
                        setpx;
                        px = rgbat(y+dy, x+dx+si+1);
                        setpx;
                        px = rgbat(y+dy+1, x+dx+si+1);
                        setpx;
                    }
                }
            }
        }
    }

Eh, considering what you are doing, multiple for loops are likely unless you vectorize into a single long array.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That code is mostly readable and understandable, which makes it distinctly above average as far as image-processing code goes. I guess it'd be less clear for people who don't know what operation it's performing based solely on the coefficients used?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I wrote that code, and I always get strange looks when I show it to people. If you do image processing long enough it mostly just becomes natural, I think.

I would change "dx" to "bx" probably these days since "dx" usually means "delta x".

I'm not sure why I chose 1.16 for luma and 1.1 for chroma -- that's the only part I'm not sure about. I think it was trial and error.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Sounds like you could have barrels of fun exploring Array Languages, banishing the need for those loops and most of the unrolled component-wise operations to boot. :science:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
APL reminds me of someone saying "you know that weird syntax you see in math papers where everything is ambiguous and uses one-letter variable names? What if that was executable"

https://twitter.com/unconed/status/678412252752519168

vOv
Feb 8, 2014

I'm sure the person who decided to post a screenshot of their text editor instead of using a pastebin or something cares very deeply about making things readable.

e: Less shitpostingly I don't understand how this person manages to speak English considering that it, just like math, makes a terrible programming language as well.

vOv fucked around with this message at 08:30 on Feb 25, 2016

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

carry on then posted:

Just use emoji for your variable names. Use the handy popup palette to store your recently used members.



I haven't used emojis as variable names, but I did write some unit tests like this one the other day:



I ❤️ UTF-16

ErIog
Jul 11, 2001

:nsacloud:
The math world realized long ago that it has to contend with something the English-speaking programming world has convinced itself it doesn't need to deal with, and that's cooperation among people speaking different languages.

The one benefit to the way math information is conveyed is that it's, to a certain extent, language-agnostic. So it's possible to translate the text of a whitepaper while retaining the same formulas. It's a pretty good separation of application and documentation.

English-speaking programmers like to pretend that most computer programming languages are language-agnostic, but that's really not the case. Due to the fact that terse/meaningless variable names are frowned upon, source code is effectively tied to English(keywords, etc.) plus whatever language the comments/variable names are written in.

So all the language keywords are English, variable names must be written using the English alphabet, foreign language documentation for programming languages, if it's even available, is often machine-translated, and then when a non-English-speaking person bothers to overcome these hurdles to write some code all the English-speaking programmers sit around bitching about code quality from non-English-speaking countries.

So, um, maybe programmers/engineers shouldn't pretend to know what the gently caress they're talking about it when it comes to communication. Code quality, the world over, would probably be much better if English-speaking programmers would accept the fact that it's not a big deal if some dude in China wants to use hanzi for variable names if that dude in China doesn't care about working on that project with people who don't speak Chinese. English-speaking programmers certainly don't seem to have any concern about people who don't speak English being able to read their code.

Everyone should watch this Rami Ismail talk:
http://www.gdcvault.com/play/1022362/We-Suck-at-Inclusivity-How

ErIog fucked around with this message at 09:41 on Feb 25, 2016

qntm
Jun 17, 2009
There's also the fact that mathematics predates text editors and Google by several millennia, it evolved to be handwritten, and it isn't a programming language.

qntm
Jun 17, 2009
Hey, have you heard about this thing called "sheet music"?

feedmegin
Jul 30, 2008

leper khan posted:

Because it's difficult for humans to type if they need to edit the code at some point. You might as well use a poo emoji.

Unless the human in question is Greek, of course. People do still speak/type in the language!

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Soricidus posted:

I seriously am using θ to represent an angle in some visualisation code. Why not?

def Σ(x: List[Int]): Int = (0 /: x) (_ + _)

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
The "programmers who think the hard part of math is the notation" meme annoys me.


APL has its own dialect of symbols that I don't think characterizes math notation in general. Like ○ for pi and ⍟ for log. It's cute and fun but I seriously never seen any serious math paper making up arbitrary notation for relatively well known stuff just for the sake of brevity.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

feedmegin posted:

Unless the human in question is Greek, of course. People do still speak/type in the language!

And if they're doing it on their time or working on a project where Greek is the lingua Franca, then great.

I would never pass code through review that used non-standard characters. Standard here meaning within the language and reasonably expected natural keybindings for everyone on the project.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Doc Hawkins posted:

In languages which support utf8 source, save extra space by using whitespace characters, especially zero-width varieties.

Do you know of any languages where that works? All the languages I know of which support non-ASCII names (whether the source is encoded as UTF8 or something else) prohibit whitespace in those names.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
A contractor with over a decade of experience with C# working for a very large bank comes in and sees this code:

code:
public bool GoofyCheck()
{
	var success = true;
	try
	{
		var value = Decimal.Parse(stringField);
	}
	catch
	{
		success = false;
	}
	
	return success;
}
Ok I mean...I guess that's weird code and technically uses *Exceptions* as a logic gate? Ok? That's kind of a horror.

Commit log: "Fixed Exception"

code:
public bool GoofyCheck()
{
	decimal result;
	var isValid = TryParse<Decimal>(stringField.Trim(), out result);
	return isValid;
}
Oh ok TryP...wait a second. TryParse<T>?

code:
#region TryParse
public bool TryParse<T>(string input, out T result)
{
	result = default(T);
	bool isValid = false;
	if (!String.IsNullOrEmpty(input))
	{
		TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
		if (converter != null)
		{
			isValid = converter.isValid(input);
			result = (T)converter.ConvertFromString(input);
		}
		else
			return isValid;
	}
	return isValid;
}
#endregion TryParse
:psyduck:

region for a single small method? check.
public access to a class's internal helper method? check.
attempting to 'fix' exceptions by re-implementing fundamental .NET functionality? check.

Code Review gave us the opportunity to educate this developer about the availability of Decimal.TryParse()

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
APL notation was specifically designed to try to unify the disparate notation used in mathematics for working with vectors, matrices and logic. While complaining about the overloaded behavior of some operators is valid, its syntax and semantics follow simple, consistent rules. Some of APL's notation even "stuck" and made its way into mainstream mathematics, like the symbols it used for "floor" and "ceiling". I don't think it's fair to characterize it as arbitrary or intentionally obtuse simply because mainstream languages went in a different direction.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Subjunctive posted:

Do you know of any languages where that works? All the languages I know of which support non-ASCII names (whether the source is encoded as UTF8 or something else) prohibit whitespace in those names.

In Ruby only plain-old spaces are treated as semantic whitespace, which makes sense to me from a language design perspective, but one result is that identifiers can contain every other whitespace character.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Doc Hawkins posted:

In Ruby only plain-old spaces are treated as semantic whitespace, which makes sense to me from a language design perspective, but one result is that identifiers can contain every other whitespace character.

Wow that is terrible design. Newlines aren't semantic whitespace? Tab characters? That's trippy poo poo.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Internet Janitor posted:

APL notation was specifically designed to try to unify the disparate notation used in mathematics for working with vectors, matrices and logic. While complaining about the overloaded behavior of some operators is valid, its syntax and semantics follow simple, consistent rules. Some of APL's notation even "stuck" and made its way into mainstream mathematics, like the symbols it used for "floor" and "ceiling". I don't think it's fair to characterize it as arbitrary or intentionally obtuse simply because mainstream languages went in a different direction.

Wow I didn't know about floor/ceiling, that's cool.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

ErIog posted:

The math world realized long ago that it has to contend with something the English-speaking programming world has convinced itself it doesn't need to deal with, and that's cooperation among people speaking different languages.

The one benefit to the way math information is conveyed is that it's, to a certain extent, language-agnostic. So it's possible to translate the text of a whitepaper while retaining the same formulas. It's a pretty good separation of application and documentation.

English-speaking programmers like to pretend that most computer programming languages are language-agnostic, but that's really not the case. Due to the fact that terse/meaningless variable names are frowned upon, source code is effectively tied to English(keywords, etc.) plus whatever language the comments/variable names are written in.

So all the language keywords are English, variable names must be written using the English alphabet, foreign language documentation for programming languages, if it's even available, is often machine-translated, and then when a non-English-speaking person bothers to overcome these hurdles to write some code all the English-speaking programmers sit around bitching about code quality from non-English-speaking countries.

So, um, maybe programmers/engineers shouldn't pretend to know what the gently caress they're talking about it when it comes to communication. Code quality, the world over, would probably be much better if English-speaking programmers would accept the fact that it's not a big deal if some dude in China wants to use hanzi for variable names if that dude in China doesn't care about working on that project with people who don't speak Chinese. English-speaking programmers certainly don't seem to have any concern about people who don't speak English being able to read their code.

Everyone should watch this Rami Ismail talk:
http://www.gdcvault.com/play/1022362/We-Suck-at-Inclusivity-How

Programmers are bigoted human garbage, news at 11.

FamDav
Mar 29, 2008
That's a p romantic view of mathematics but don't worry it's actually full of bigotry and is hecka anglocentric (and before that it was France and Germany, sometimes Russia but they mostly had their work stolen or ignored).

ExcessBLarg!
Sep 1, 2001

Subjunctive posted:

Newlines aren't semantic whitespace? Tab characters? That's trippy poo poo.
Doc is wrong, both newlines and tabs are. I don't know about \v and \f.

Generally I believe that Ruby's lexer only treats ASCII-range characters specially, so all high-bit characters in 8-bit encodings are lumped together. Until Ruby 1.9 I believe Ruby only allowed ASCII characters to be used as identifiers, but now allows other, e.g., Unicode characters to be used (and quite possibly lumps them all together as "valid identifier characters").

Part of the reason for this is that Ruby has long tried to be encoding agnostic, and historically users have used EUC-JP or Shift-JIS just as much as UTF-8. One of the (perhaps scary) things about Ruby is that identifiers that start with capital letters (that is, [A-Z] in ASCII) are considered constants, and as a consequence, all class and module identifiers must start with a capital. Folks complain that non-ASCII Unicode capitals don't count for this purpose, but the reason is that capitalization and its rules (outside [A-Z]) is language/locale dependent, and they didn't want to go down that path.

Soricidus
Oct 21, 2010
freedom-hating statist shill

ExcessBLarg! posted:

Doc is wrong, both newlines and tabs are. I don't know about \v and \f.

Generally I believe that Ruby's lexer only treats ASCII-range characters specially, so all high-bit characters in 8-bit encodings are lumped together. Until Ruby 1.9 I believe Ruby only allowed ASCII characters to be used as identifiers, but now allows other, e.g., Unicode characters to be used (and quite possibly lumps them all together as "valid identifier characters").

Part of the reason for this is that Ruby has long tried to be encoding agnostic, and historically users have used EUC-JP or Shift-JIS just as much as UTF-8. One of the (perhaps scary) things about Ruby is that identifiers that start with capital letters (that is, [A-Z] in ASCII) are considered constants, and as a consequence, all class and module identifiers must start with a capital. Folks complain that non-ASCII Unicode capitals don't count for this purpose, but the reason is that capitalization and its rules (outside [A-Z]) is language/locale dependent, and they didn't want to go down that path.

yeah, you can see how they got to where they were by following a series of decisions that were individually justifiable given their goals for the language. but it doesn't really make sense to stay where they've got to. i don't think anyone sane would really complain about a breaking change that started forbidding loving whitespace in identifiers.

gonadic io
Feb 16, 2011

>>=

carry on then posted:

Humans are bigoted human garbage, news at 11.

ExcessBLarg!
Sep 1, 2001

Soricidus posted:

i don't think anyone sane would really complain about a breaking change that started forbidding loving whitespace in identifiers.
Perhaps not, but at the same time no source code should contain a THREE-PER-EM SPACE except in a string or maybe a comment. I'm OK with that behavior being effectively undefined, and if Ruby allows them to be used in identifiers simply because it's a high-bit character like any other, I'm not completely opposed to that. The alternative is to keep up with Unicode revisions and having to regularly make the decision of whether a MONGOLIAN VOWEL SEPARATOR counts as whitespace for coding purposes or not, and accepting that it probably was a valid identifier character in previous versions because it hadn't actually been defined in the standard yet.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Unicode defines the set of whitespace in each revision, no? Upgrade your libicu and you're done.

ExcessBLarg!
Sep 1, 2001
Well Ruby doesn't use libicu. They probably have reasons for not wanting to use it either. It's also kind of weird, to me, that the way an interpreter parses code is dependent on the version of a dependent library that I have installed. I think it's a defensible approach, but I also don't think what Ruby does is particularly silly either.

Adbot
ADBOT LOVES YOU

CPColin
Sep 9, 2003

Big ol' smile.
I discovered today that Java allows ဪ in identifier names, but not 💩. I guess the first one counts as a letter, but the pile of poo is just a pile of poo.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply