|
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.
|
# ? Jul 21, 2018 20:44 |
|
|
# ? Jun 8, 2024 06:10 |
|
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?
|
# ? Jul 21, 2018 20:45 |
|
TooMuchAbstraction posted:You've never needed to switch which of two loops is the outer and which is the inner?
|
# ? Jul 21, 2018 20:52 |
|
I just spell out index :^)
|
# ? Jul 21, 2018 20:55 |
|
index, jndex, kndex
|
# ? Jul 21, 2018 20:57 |
|
It's "K*nex"
|
# ? Jul 21, 2018 21:18 |
|
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.
|
# ? Jul 21, 2018 21:24 |
|
Captain Cappy posted:I just spell out index :^) You'll never win at code golf with an attitude like that.
|
# ? Jul 21, 2018 22:59 |
|
Well, whatever you do, don't use i, j or k for things other than loop variables.
|
# ? Jul 21, 2018 23:26 |
|
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.
|
# ? Jul 21, 2018 23:30 |
|
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.
|
# ? Jul 21, 2018 23:53 |
|
you guys would hate image processing. i find this perfectly readable.C++ code:
|
# ? Jul 22, 2018 01:02 |
|
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.
|
# ? Jul 22, 2018 01:37 |
|
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 |
# ? Jul 22, 2018 01:39 |
|
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.
|
# ? Jul 22, 2018 01:51 |
|
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
|
# ? Jul 22, 2018 09:34 |
|
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.
|
# ? Jul 22, 2018 10:25 |
|
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.
|
# ? Jul 22, 2018 10:46 |
|
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... That's definitely a lot to take in but replacing the unicode wouldn't make it any easier.
|
# ? Jul 22, 2018 10:50 |
|
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)
|
# ? Jul 22, 2018 11:02 |
|
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.
|
# ? Jul 22, 2018 11:45 |
|
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?
|
# ? Jul 22, 2018 12:33 |
|
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 |
# ? Jul 22, 2018 14:01 |
|
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. Why do you use this heavily parenthetical writing style?
|
# ? Jul 22, 2018 14:03 |
|
return0 posted:Why do you use this heavily parenthetical writing style? They code in LISP
|
# ? Jul 22, 2018 14:07 |
|
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.
|
# ? Jul 22, 2018 15:05 |
|
return0 posted:Why do you use this (heavily parenthetical) writing style?
|
# ? Jul 22, 2018 16:09 |
|
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?
|
# ? Jul 22, 2018 19:20 |
|
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. 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.
|
# ? Jul 22, 2018 19:39 |
|
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.
|
# ? Jul 22, 2018 20:59 |
|
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.
|
# ? Jul 22, 2018 21:47 |
|
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.
|
# ? Jul 23, 2018 03:28 |
|
Whenever developers speak to me about their insane naming conventions I'm reminded that heiroglyphyics needed several dedicated interpreters too
|
# ? Jul 23, 2018 05:10 |
|
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.
|
# ? Jul 23, 2018 05:13 |
|
Suspicious Dish posted:you guys would hate image processing. i find this perfectly readable. There are tools for generating stuff like that.
|
# ? Jul 23, 2018 05:42 |
|
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.
|
# ? Jul 23, 2018 06:28 |
|
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!
|
# ? Jul 24, 2018 02:13 |
|
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! 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.
|
# ? Jul 24, 2018 03:00 |
|
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?
|
# ? Jul 24, 2018 04:52 |
|
|
# ? Jun 8, 2024 06:10 |
|
https://twitter.com/slowbeef/status/1021550648796631040
|
# ? Jul 24, 2018 17:38 |