GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Embed Notice

HTML Code

Corresponding Notice

  1. Embed this notice
    pistolero (p@fsebugoutzone.org)'s status on Sunday, 31-May-2026 02:28:28 JSTpistoleropistolero
    in reply to
    • Haelwenn /элвэн/ :triskell:
    • Phantasm
    • Junes
    • DulceKennedy
    • SilverDeth
    • Slim Jim
    • CMD
    @phnt @ElDeadKennedy @Junes @SilverDeth @ceo_of_monoeye_dating @j @lanodan

    > I think that's a fair replacement for early return.

    I mean, I think it's a mess. Especially in a lived-in codebase, you get buckets of this stuff and it's a pain to trace execution.

    > a descriptive function name

    Well, you can name an accumulator "a" or "acc" or "i" or "n" and it's a name that stays out of your way, but you can't do this at the module level. You're taking something that would have, as its only scope, the ten-line function it lives in, and then you're putting it into the module's scope: this means you've got to name it a little more carefully because it's now part of a module instead of a local variable. It's not always obvious where it's called from, especially in a big module, and this gets in the way of debugging. Having to come up with a module-scope name for an intermediate calculation gets in the way of sketching, so people don't do it, and sometimes it's not even possible: this is an intermediate value with no meaning outside the very narrow scope, and what *is* it? Sometimes it's nothing. It's half an equation.

    Look at the quadratic formula, right, you've got a +/- and to avoid calling sqrt twice, people store the intermediate value and then return a tuple (however tuples are done it the language you're using) with (-b-val, -b+val). What's a good name for that value? Or you calculate stddev and you've got to have an accumulator for the sum of the squares of the differences of the individual elements and the average, and if you don't have a `reduce` builtin, you put it into a variable and you general call it something short enough to be legible, `ssd` for `sum of squares of differences` or something, fine for local scope. Say you're doing it in awk:

    :mycomputer: total=0; for(i in a) total += a[i]; avg = total/length(a)
    :mycomputer: ssd=0; for(i in a) ssd += (a[i]-avg)*(a[i]-avg)
    :mycomputer: stddev = sqrt(ssd/length(a))

    I mean, some stuff just doesn't have a good name, but if it's module scope, you don't have the option of giving it a *bad* name.

    (You write enough Forth and you see what people mean about not having to name *anything* that you don't want to name.)

    > It tends to remove the 20+ line if/switch statements you get in something like C when you need to do this

    That is the point of the early return: you shouldn't nest like that in any language, C included.

    > It is terrible design to process multiple types of something in a single function.

    The World Wide Web does not give you a lot of options: you get to process multiple types of something in a single function. (Worst part about Go is that it wants JSON to be a static data structure and JSON is not a static data structure.)

    Pleroma has to do a lot of this due to the having to handle "is this an array or not" or "did the DB return a valid UTF-8 string or just a bucket of line noise because the web is dirty or maybe it's nil, plus if it's a string like we're hoping, what does it look like and which way should we handle it?" (You will often have a bad time if you see `conn |>` in the function and you will almost always see that and it's the context trash bucket, it's like inside-out manual AOP, and AOP is already bad enough. "I've never looked in this module", I think. "`conn |>` could be here. `conn |>` could be anywhere." Illicit stimulants coursed through my veins as some square wave remix of something that used to be music reverberated through the cheap-ass Logitech subwoofer. "With a TCP socket, you can send data anywhere you want," I say to myself, out loud.)

    > You would name that function the same in other languages

    I wouldn't name *anything* that in *any* language. If you have an entire sentence with conditionals as your function name, then you don't have a function and I don't know what you *do* have but I don't want to touch it. You see names like that in Rails or in Java. (Most of the code in the world is bad so you have to cope, and if you're in a codebase that looks like that, you wanna fit the style so that you don't clash at the interface level, but you don't want to forget that it's bad.)

    > If it really needs to exist, multiple functions guarded with a when are slightly better at least in my mind.

    A `when` is like a really long chain of `&&`s. You don't want to if you can avoid it, and you definitely don't want to put any side-effects in there, but people do that.

    > It's a different code style basically. Same endless arguments about different code styles being better than others apply here as well.

    It's a different set of tradeoffs. You don't get a language with no warts; coding style dictates which warts you'll put up with. I really like using awk but there are some infelicities; same with anything, but awk is nice to use when what you have fits awk's way of doing things.

    > Just that you can also do this, nothing more:

    Yeah, I get that part, that's why I was confused about why you were saying it.
    In conversationabout 5 months ago from fsebugoutzone.orgpermalink
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.