I straight up never got a nice answer from StackOverflow on this. Say you have 5 classes, each requiring access to the data members/functions of the others. What's a nice way to solve this problem? I've thought of only two nice shit methods:
Pass pointers/shared-pointers etc to each class, but not through the constructor but a setter function
Pass lambdas or std::function everywhere. Yuck! Still doesn't put each object in a valid state in the constructor.
The. real question is whether this problem needs to be modelled using classes in the first place. The alternative is to just have a set of composable functions that take a piece of data and return a modified version that can be passed to a different function.
There's plenty of real world code written in functional languages. Also, this idea that FP is somehow more complex is complete nonsense. Lisp family are some of the easiest languages to learn.
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.
Sure yeah, I've done lots of UI programming with Clojure. It works great. I've also made small games. Why do you think it would be more difficult than with imperative style?
I'm just a hobbyist but...are you guys using exceptions like they're conditional statements?? I thought those were for only when shit is seriously wrong and execution can't continue in the current state. Like if some resource was in a bad state or some input was malformed.
Or maybe I haven't worked on anything complex enough, I dunno.
As a rule, exceptions should indeed be used for behaviors that are outside normal execution flow. For example, you might throw an exception if a file you're trying to access doesn't exist, or a network call fails, etc.
You don't want to use exceptions in normal control flow, because they're extremely slow. Every time you throw an exception, it has to collect a stacktrace, which is hundreds, if not thousands, of calculations, compared to a handful of calculations for returning a boolean or an enum variant.
I suppose it depends on the language? For the most part I think you're right. Exceptions are only used (if at all) in situations where a program diverges unexpectedly from its normal flow. But take a language like Python. They're just everywhere. Even your plain old for loop ends on an exception, and that's just business as usual.