balsoft

joined 5 months ago
[–] [email protected] 2 points 1 day ago (1 children)

Typically this is true, but it’s certainly possible to get comparable performance with functional style

It's possible, but you have to specifically write code that's fast, rather than idiomatic or ergonomic, and you have to know what you're doing. At that point, you may have been better off writing it in something else. I feel like OCaml is good at this because it allows you to write abstractions and main control flow in a functional way and hot paths in an imperative way without switching language, but so is Rust.

Carp, which I linked above, basically uses the same approach to memory management as Rust. It doesn’t rely on GC.

I'll take a look, thanks!

I also find that for most cases it really doesn’t matter all that much unless you’re in a specific domain like writing drivers, making a game engine, etc. Computers are plenty fast nowadays, and ergonomics tend to be more important than raw performance.

I mostly agree with you, e.g. Haskell and Clojure, despite being "slow", are plenty fast for what they're used for. On the other hand, I'm very much annoyed when "user-facing" software takes way too long to load or do simple tasks. Java in particular is pretty bad at this: JOSM (Java OpenStreetMap editor) takes longer to load than my entire desktop startup, including a window manager and browser. Unfortunately it's also the best editor around, so I pretty much have to use it to edit OSM, but it still annoys me to no end. Unnecessary computations, IO inefficiencies and layers of wrapping also affect the power consumption quite noticeably.

[–] [email protected] 2 points 1 day ago* (last edited 1 day ago) (3 children)

Modern C compilers are a fascinating blend of functional and imperative, that's true; and I didn't say that C is "close to how the modern architectures work". However, mainstream modern architectures are almost always engineered with C in mind primarily, and this is also acknowledged in the article you've linked. Rust, having a lot of similarities to C in terms of its underlying memory model, calling conventions, and control flow primitives, can often benefit from those hardware patterns and optimizations in a way that's more difficult to replicate with a functional language (especially so given most of them are GC-d due to their memory model). The closest I've seen in terms of easy-to-write-quick-code is OCaml, but even there the fast paths are often written in a very much imperative style. Idris2 also seems promising if they manage to get a GC-less mode working. Maybe also Roc, but I've not taken a look at it yet.

Note that I write all of this as someone spending a lot of their work time programming in a functional language (Haskell), with Rust being mostly for hobby stuff. It just always surprises me how much easier it is to write fast code in Rust, and yet also how much of my Haskell intuition was applicable when I was learning it.

[–] [email protected] 2 points 1 day ago (5 children)

I agree that they fit different niches! My point was that with modern CPU architectures, imperative languages make it much easier to write fast&efficient code just because the hardware was pretty much engineered with C in mind. IMHO Rust offers the best of both worlds when it comes to systems/low-level dev.

[–] [email protected] 4 points 2 days ago (7 children)

TBH Rust is pretty nice, it borrows (pun intended) a lot of ideas from the functional world (algebraic data types, traits, closures, affine types to an extent, composition over inheritance, and the general vibe of type-driven development), but it's much easier to write fast, efficient code, integrate with decades of libraries in imperative languages, and the ecosystem somehow feels mature already.

[–] [email protected] 35 points 2 weeks ago* (last edited 2 weeks ago) (8 children)

So, here's my attempt

The first portion (^.?$) matches all lines of 0 or 1 characters.

The second portion (^(..+?)\1+$) is more complicated:

  1. (..+?) is a capture group that matches the first character in any line, followed by a smallest possible non-zero number of characters such that (2) still matches (note that the minimum length of this match is 2)
  2. \1+ matches as many as possible (and more than 0) repeats of the (1) group

I think what this does is match any line consisting of a single character with the length

  • divisible by some number (due to the more than 0 condition in (2), so that there have to be repeats in the string), that's not
    • 1 (due to the note in (1), so that the repeating portion has to be at least 2 characters long), or
    • the length itself (due to the more than 0 condition in the (2), so that there is at least one repetition)

Therefore, combined with the first portion, it matches all lines of the same character whose lengths are composite (non-prime) numbers? (it will also match any line of length 1, and all lines consisting of the same string repeated more than one time)

[–] [email protected] 2 points 1 month ago* (last edited 1 month ago) (1 children)

My understanding is that the Congress of Soviets was replaced with the Supreme Soviet, the democratic structure was changed but the Soviets remained, just shifted in form, and could still be used democratically, just not in all cases.

I believe this is true, but I would argue that the fundamental change was that non-Party candidates were almost never allowed to run. As I noted, this is not due to a constitutional change but rather a change in electoral tradition. Anecdotally, as a result of this, all three my grandparents didn't feel represented by their deputies/delegates, and welcomed that part of the Perestroyka changes, when the rules were relaxed and more alternative candidates appeared.

A good analogy is that most local governments in the US run uncontested.

I believe this to also be a non-ideal situation (especially given the two-party system where neither represents the working class). However, aren't there at least party primaries, so that one can choose which candidate from the dominant party "runs" for the uncontested election? Whereas in USSR the candidates were chosen by the Party and not the electorate directly. (my understanding of the US electoral system is lacking, so I may be wrong here).

That’s why I stressed reading Blackshirts and Reds, which dispels the mythology and takes a critical, nuances look at the USSR.

Thanks for the recommendation! I've started to read it a while ago, and mostly agreed with the contents. I'll have to pick it up again.

[–] [email protected] 2 points 1 month ago* (last edited 1 month ago) (3 children)

Soviets were de-facto abolished after 1936 (not due to the constitution itself, rather "by tradition"). While there technically were elections, in almost all cases there was only one candidate. The three of my grandparents that I grew up with (all proudly working-class - teacher, engineer and doctor, born in 1930s), never participated in elections with more than one candidate until Perestroyka (at which point the communist project was on its deathbed).

Note that I'm not even anti-USSR, it's still markedly better than the bullshit capitalist systems. There actually was plenty of workspace democracy, and some local democracy, but I don't think we should glorify it as some bastion of democracy. There still unfortunately was a kind of ruling class - the Party and MGB/KGB (but I should note that it was much easier for a working-class person to join their ranks than it is in capitalist "democracies"). Rather, learn from what it got right, and fix what it got wrong.

[–] [email protected] 1 points 2 months ago

Yes, that can happen sometimes, but I find that there are plenty of cheap options with unlocked bootloaders if you look for them.

[–] [email protected] 1 points 2 months ago (2 children)

Nah, cheap phones often have their bootloader unlocked/unlockable. Really happy with my POCO M5 running modified AOSP. Also, unlike every expensive phone nowadays, it has 3.5mm jack, SD card slot, and exceptional battery life for hiking/trekking (it survives 5-6 days as just a camera+map phone with all power saving on, in comparison people with flagships typically only last 2-3 days with the same usage and power-saving techniques).

[–] [email protected] 3 points 2 months ago* (last edited 2 months ago)

You can almost always replace the battery, even when the manufacturer doesn't want you to. As for flashlights, they typically come with easily user-replaceable ones, often even sold separately. Worst-case, you can get a AA or AAA flashlight and use rechargeable AA/AAAs.

[–] [email protected] 2 points 2 months ago

I've paid quite a lot for my second headlamp for hiking, but I am really happy with the purchase as it's very light (35 g) compared to my first cheapo one (~120 g), while being the same 200 lm max. It doesn't sound like much, but it's enough for me to not even notice it, while the heavy one was getting annoying after a while.

[–] [email protected] 1 points 2 months ago

I'd say it depends. For safety-critical stuff maybe, but for a headlamp or something I prefer rechargeable as I can easily recharge it from a power bank or a portable solar panel if needed. If you run out of a disposable battery for whatever reason, you're screwed.

view more: next ›