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
NiceAaron
Oct 19, 2003

Devote your hearts to the cause~

I use ii instead of i, not because of find-and-replace, but because single-letter variable names are obnoxious to read. I also use "catch (Exception ex)" instead of "catch (Exception e)" for the same reason.

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

raminasi posted:

I cannot think of a time I have ever needed to rename a loop index variable.

You've never needed to switch which of two loops is the outer and which is the inner?

Volte
Oct 4, 2004

woosh woosh

TooMuchAbstraction posted:

You've never needed to switch which of two loops is the outer and which is the inner?
That's not renaming the variables since the usages don't switch. You can do that just by swapping the two lines.

Captain Cappy
Aug 7, 2008

I just spell out index :^)

CPColin
Sep 9, 2003

Big ol' smile.
index, jndex, kndex

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

It's "K*nex"

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

Volte posted:

That's not renaming the variables since the usages don't switch. You can do that just by swapping the two lines.

...right, sorry, don't know what I was thinking. :doh:

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Captain Cappy posted:

I just spell out index :^)

You'll never win at code golf with an attitude like that.

Doom Mathematic
Sep 2, 2008
Well, whatever you do, don't use i, j or k for things other than loop variables.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

raminasi posted:

I cannot think of a time I have ever needed to rename a loop index variable.

Wrapping an existing loop in a new loop, shifting "i" to the outer loop variable and the existing loop to j.

Still not a usecase it ever would have occurred to me to optimize for. Even if you don't know about word boundary matches in regexes and aren't clever enough to figure out a regex that matches your index variable and not other things, if your loop body is so large that just plain updating it by hand is an issue then your code is bad to begin with.

itskage
Aug 26, 2003


NiceAaron posted:

I use ii instead of i, not because of find-and-replace, but because single-letter variable names are obnoxious to read. I also use "catch (Exception ex)" instead of "catch (Exception e)" for the same reason.

I use catch (\Throwable $e) because I'm in hell.

Hell.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
you guys would hate image processing. i find this perfectly readable.

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;
                    }
                }
            }
        }
    }

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
That's the kind of thing where I'd be looking to build some kind of general-purpose "apply this function to these pixels according to these step/stride parameters" tool, mostly because I'd be worried otherwise that one of my dozen minor variations on a theme would have a subtle typo that would keep it from working properly.

xtal
Jan 9, 2011

by Fluffdaddy
I'm a big fan of x, y, z for values, xs, ys and zs for collections, f, g and h for functions, and a, b, and c for types.

xtal fucked around with this message at 16:03 on Jul 22, 2018

Xerophyte
Mar 17, 2008

This space intentionally left blank

TooMuchAbstraction posted:

That's the kind of thing where I'd be looking to build some kind of general-purpose "apply this function to these pixels according to these step/stride parameters" tool, mostly because I'd be worried otherwise that one of my dozen minor variations on a theme would have a subtle typo that would keep it from working properly.

Image processing DSLs where you "just" apply kernels to arrays are definitely A Thing, but they do not always make life easier. Debugging is nontrivial.

I think following some existing terse nomenclature can make sense when you're literally just implementing a known piece of math. The temporary partial computation values in something like a probability distribution sampler aren't necessarily meaningful, they're just there to keep the formula readable. About the most meaningful name you could give them is float temp. If the paper you're implementing calls some local helper variable χ, just go with float chi when implementing and refer back to the original paper in a comment. Then at least future code maintainers can compare your code to the original definition and hopefully see where you screwed up.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Xerophyte posted:

If the paper you're implementing calls some local helper variable χ, just go with float χ when implementing and refer back to the original paper in a comment.

We have Unicode now, grandpa

Xerophyte
Mar 17, 2008

This space intentionally left blank

Soricidus posted:

We have Unicode now, grandpa

I believe this is where I try to find the most majestic string of densely unreadable unicode in the Agda standard library to show the slippery slope, hang on...


Maybe?

The real problem with using unicode in code is that most IDEs have crap support for coding in unicode. Agda has a bespoke emacs environment that lets the happy little category theorists enter happy little latex codes for whatever obscure turnstile they desire. It's the sort of thing only a mother could love.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
All this stuff people are mentioning about having to use regex replace operations to rename variables is scary. Like someone else said, use the variable rename functionality in your IDE. If you aren't using an IDE or your IDE doesn't have that feature, then this is a problem you ought to fix.

The primary concern when naming variables (or anything else) is that the purpose of the variable should be clear to the person who is going to need to understand and maintain the code. Explanatory variable names composed of words are one fairly reliable way to do this. But the reason why e.g. "i, j, k as loop variables" is widely accepted is that it meets that "purpose of the variable should be clear" test, because everybody who has done any programming is familiar with that convention (or should be - they are bound to meet other code that uses it).

Similarly, if you are implementing a mathematical formula where the single-letter names of the variables are a matter of established and well-known convention, there is nothing wrong with naming the variables accordingly in the function: a person who needs to understand and maintain the code will be familiar with the formula, or capable of making themselves familiar with it on demand. If that isn't the case then they have no business working on that code. If the code implements something described in a specific paper (say) and makes explicit reference to that paper and its contents, then using the same variable names from the paper is also defensible even if they are idiosyncratic to the paper.

What isn't acceptable is to dream up single-letter variable names that are initially opaque to even a person with subject-matter expertise and can only be deciphered by someone studying the code to work out what the variable does.

Dylan16807
May 12, 2010

Xerophyte posted:

I believe this is where I try to find the most majestic string of densely unreadable unicode in the Agda standard library to show the slippery slope, hang on...


Maybe?

The real problem with using unicode in code is that most IDEs have crap support for coding in unicode. Agda has a bespoke emacs environment that lets the happy little category theorists enter happy little latex codes for whatever obscure turnstile they desire. It's the sort of thing only a mother could love.

That's definitely a lot to take in but replacing the unicode wouldn't make it any easier.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Dylan16807 posted:

That's definitely a lot to take in but replacing the unicode wouldn't make it any easier.

That code is definitely unreadable to me but I think that probably has more to do with not being familiar with Agda syntax in particular or functional language syntax in general.

Having said that, I think a lot of people (not necessarily all) read code in an "inner monologue" fashion and it is an impediment to reading code this way if there is no obvious (to the reader) way to pronounce something encountered in the code, for example if the name of an operator or symbol isn't known to the reader. I think whether the usage of a particular unicode character as a name is acceptable or not is dependent on whether the usage is standard or not, which is consistent with what I said in my previous boring post.

(It is also entirely reasonable to ban the use of non-ascii characters, or to mandate their use where convention would require it, based on the established convention for the language)

Xerophyte
Mar 17, 2008

This space intentionally left blank

Hammerite posted:

That code is definitely unreadable to me but I think that probably has more to do with not being familiar with Agda syntax in particular or functional language syntax in general.

Not sure that just knowing functional programming would help in the particular case of Agda. I did very little Agda touching in college but the short version is that the language is intended to be a programmable, generic and extensible proof assistant. An Agda program isn't usually meant to compute something in the "traditional" sense, the program is usually just stating a theorem which is then validated by typechecking.

That particular snippet is a proof of ... some fold property on reflexive and transitive relations that's beyond my vaguely remembered formal methods knowledge. You'll note that it even ends in a '∎' QED tombstone, which I think is implemented as an always valid postfix unary operator and just used to make the proofs implemented in Agda look proofier. Agda's standard library doesn't just give you some datatypes, it gives you the generic higher order proof functions you then need to construct specific proofs on other types dependent on the built in types, and the dependent types would then represent the properties of some real theorem in topology or whatever that you want verified.

You could of course also do real coding in Agda -- it has arbitrary foreign function import from Haskell -- and then be extremely sure of the formal correctness of your code if you bothered to define sufficiently rich types for all your data. That's not really the point, though. It's a language where integers are generally implemented as linked lists of void types. It's a good example language for a lot of weird things simply because it looks and behaves like any other functional language, if one with very complex type annotations, but the code is usually doing something completely different than what most programmers would even think of as a program.

Carbon dioxide
Oct 9, 2012

Xerophyte posted:

You could of course also do real coding in Agda

Internet says Agda is not in fact turing complete. I am not sure what that means in this particular context, it's the first time I see this language. Perhaps Haskell compatibility does make it Turing complete?

Linear Zoetrope
Nov 28, 2011

A hero must cook

Carbon dioxide posted:

Internet says Agda is not in fact turing complete. I am not sure what that means in this particular context, it's the first time I see this language. Perhaps Haskell compatibility does make it Turing complete?

Most languages that have a primary or large purpose as theorem provers and can prove things about themselves (Agda, Coq) aren't Turing Complete because being able to guarantee things like termination and halting are important. Strictly speaking, a lot of them can escape it. Coq can run OCaml(? some ML) code painlessly for instance which is Turing Complete, but if you want to use it in proofs you need to make manual guarantees to the theorem prover and manually restrict yourself to a provable subset of whatever Turing Complete language you're linking in.

You can usually generally still do a lot in them, and they have very advanced type systems, but they're more very domain specific theorem provers than they are general purpose programming languages. You probably don't want to try to write a web server or whatever in Agda unless it's a personal challenge.

E: Generally the limits are on things like recursive types/functions or other constructs that can diverge in some way. Basically, the compiler needs to be able to prove every type definition and function can be run with every conceivable argument within finite time. It can't prove every construction it should allow will work since if it could, you could solve the halting problem. Thus, the restriction becomes "whatever the halting checker can prove halts" which is what limits it to being non-Turing Complete. This means occasionally you need to do weird things to appease the compiler. If you've used Rust, this is going to sound familiar since the borrow checker is a very similar concept, where Haskell/ML/whatever takes the place of "unsafe".

Linear Zoetrope fucked around with this message at 14:17 on Jul 22, 2018

return0
Apr 11, 2007

Hammerite posted:

That code is definitely unreadable to me but I think that probably has more to do with not being familiar with Agda syntax in particular or functional language syntax in general.

Having said that, I think a lot of people (not necessarily all) read code in an "inner monologue" fashion and it is an impediment to reading code this way if there is no obvious (to the reader) way to pronounce something encountered in the code, for example if the name of an operator or symbol isn't known to the reader. I think whether the usage of a particular unicode character as a name is acceptable or not is dependent on whether the usage is standard or not, which is consistent with what I said in my previous boring post.

(It is also entirely reasonable to ban the use of non-ascii characters, or to mandate their use where convention would require it, based on the established convention for the language)

Why do you use this heavily parenthetical writing style?

iospace
Jan 19, 2038


return0 posted:

Why do you use this heavily parenthetical writing style?

They code in LISP

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Hammerite posted:

All this stuff people are mentioning about having to use regex replace operations to rename variables is scary. Like someone else said, use the variable rename functionality in your IDE. If you aren't using an IDE or your IDE doesn't have that feature, then this is a problem you ought to fix.

if you're going to use single character variable names, just use vim with no plugins. the best part is if you're a real programmer(tm), you don't actually have to run the code you're writing to know it'll work, so the ide is just going to slow you down by limiting your typing speed.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

return0 posted:

Why do you use this (heavily parenthetical) writing style?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

return0 posted:

Why do you use this heavily parenthetical writing style?

I don't know. I have noticed it in my own writing in the past. Perhaps I am not very good at writing well-organised prose, and/or I am too ready to add asides that aren't really necessary. In general I tend to err on the side of verbosity, but I'm happy with that since I would rather be verbose and be understood than be terse and be misunderstood. Why do you ask?

Xerophyte
Mar 17, 2008

This space intentionally left blank

Linear Zoetrope posted:

Most languages that have a primary or large purpose as theorem provers and can prove things about themselves (Agda, Coq) aren't Turing Complete because being able to guarantee things like termination and halting are important. Strictly speaking, a lot of them can escape it. Coq can run OCaml(? some ML) code painlessly for instance which is Turing Complete, but if you want to use it in proofs you need to make manual guarantees to the theorem prover and manually restrict yourself to a provable subset of whatever Turing Complete language you're linking in.

You can usually generally still do a lot in them, and they have very advanced type systems, but they're more very domain specific theorem provers than they are general purpose programming languages. You probably don't want to try to write a web server or whatever in Agda unless it's a personal challenge.

E: Generally the limits are on things like recursive types/functions or other constructs that can diverge in some way. Basically, the compiler needs to be able to prove every type definition and function can be run with every conceivable argument within finite time. It can't prove every construction it should allow will work since if it could, you could solve the halting problem. Thus, the restriction becomes "whatever the halting checker can prove halts" which is what limits it to being non-Turing Complete. This means occasionally you need to do weird things to appease the compiler. If you've used Rust, this is going to sound familiar since the borrow checker is a very similar concept, where Haskell/ML/whatever takes the place of "unsafe".

Yeah, pretty much. Agda is similar to Coq and the other ML-based suspects in that domain; two of the major contributors to the language are named Coquand. It uses a termination checker based on the very unfortunately named foetus termination checker.

Naar
Aug 19, 2003

The Time of the Eye is now
Fun Shoe
There's also Idris, which is like if Agda and Haskell had a baby (who loved proving things). It also has a big focus on total functions.

return0
Apr 11, 2007

Hammerite posted:

I don't know. I have noticed it in my own writing in the past. Perhaps I am not very good at writing well-organised prose, and/or I am too ready to add asides that aren't really necessary. In general I tend to err on the side of verbosity, but I'm happy with that since I would rather be verbose and be understood than be terse and be misunderstood. Why do you ask?

I ask for a couple of reasons:

1. I used to do it in work emails often. A buddy of mine told me to stop as it came over as being tentative and unsure, despite this not being the case. I now try to force myself to write more tersely. I’m interested in if you’ve had the same feedback or experience?

2. When phone lurking, I zoom on the posts and don’t see the username or avatars. I don’t often recognise posters by their writing style in CoC. I did however recognise your post due to the parentheses, which piqued my curiosity.

Presto
Nov 22, 2002

Keep calm and Harry on.

raminasi posted:

I cannot think of a time I have ever needed to rename a loop index variable.

I can. Many years ago I worked with some code that used 'loop_counter_variable' in a for loop. In some other places someone realized that was really long and switched to 'lcv' instead.

Coffee Mugshot
Jun 26, 2010

by Lowtax
Whenever developers speak to me about their insane naming conventions I'm reminded that heiroglyphyics needed several dedicated interpreters too

fishmech
Jul 16, 2006

by VideoGames
Salad Prong

Coffee Mugshot posted:

Whenever developers speak to me about their insane naming conventions I'm reminded that heiroglyphyics needed several dedicated interpreters too

Hopefully the code won't still be in use for 5000 years though.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Suspicious Dish posted:

you guys would hate image processing. i find this perfectly readable.

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;
                    }
                }
            }
        }
    }

There are tools for generating stuff like that.

Taffer
Oct 15, 2010


fishmech posted:

Hopefully the code won't still be in use for 5000 years though.

Unfortunately, it doesn't take 5000 years for the understanding of bad code to be lost, it only takes about 6 hours.

Absurd Alhazred
Mar 27, 2010

by Athanatos
You thought timezones were bad? Worried that the Gregorian calendar is a bit too arbitrary? I give you: the Japanese Imperial era-based calendar!

Main highlight: you won't know what the dates after April 30, 2019 are called because the era name will only be divulged post abdication!

fishmech
Jul 16, 2006

by VideoGames
Salad Prong

Absurd Alhazred posted:

You thought timezones were bad? Worried that the Gregorian calendar is a bit too arbitrary? I give you: the Japanese Imperial era-based calendar!

Main highlight: you won't know what the dates after April 30, 2019 are called because the era name will only be divulged post abdication!

I was going to ask how computers handled the move between the Showa and Heisei periods in the first place. But then I realized that given that was in 1989 a bunch of stuff probably didn't track it, given it was a time when tons of equipment didn't bother to support the language. And a bunch of the stuff that did track it is systems no longer in use including the many computer systems that were only popular in the Japanese domestic market, to be replaced by standard Windows and Mac and Linux systems.

Still there must be old corporate systems around still counting today as part of year Showa 93 or something because they couldn't figure out a way to move over back then - I bet some of that stuff is going to do interesting things when it rolls up to a year 100.

1337JiveTurkey
Feb 17, 2005

Java supports the Japanese calendar system but only as far back as Meiji 6, which happens to be when Japan switched to the Gregorian calendar. I guess that's useful for someone?

Adbot
ADBOT LOVES YOU

Carbon dioxide
Oct 9, 2012

https://twitter.com/slowbeef/status/1021550648796631040

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