- 0 Posts
- 15 Comments
It’s a container with certain behaviors and guarantees making them easy and reliable to manipulate and compose. A practical example is a generic List, that behaves like:
List[1, 2, 3], i.e. (“new”, “unit”, “wrap”) to create, containing obj(s)map(func)to transform objs inside, List[A] -> List[B]first(), i.e. (“unwrap”, “value”) to get back the objflat_map(func), i.e. (“bind”) to un-nest one level whenfunc(a)itself produces another List, e.g.[3, 4].flat_map(get_divisors) == flatten_once([[1, 3], [1, 2, 4]]) == [1, 3, 1, 2, 4]
Consider the code to do these things using
forloops – the “business logic”func()would be embedded and interlaced with flow control.The same is true of Maybe, a monad to represent something or nothing, i.e. a “list” of at most one, i.e. a way to avoid “null”.
Consider how quickly things get messy when there are multiple functions and multiple edge cases like empty lists or "null"s to deal with. In those cases, monads like List and Maybe really help clean things up.
IMO the composability really can’t be understated. “Composing” ten
forloops via interlacing andifchecks and nesting sounds like a nightmare, whereas a few LazyList and Maybe monads will be much cleaner.Also, the distinction monads make with what’s “inside” and what’s “outside” make it useful to represent and compartmentalize scope and lifetimes, which makes it useful for monads like IO and Async.
In my experience, LLMs aren’t really that good at summarizing
It’s more like they can “rewrite more concisely” which is a bit different
Also have the option of selectively/strictly enforcing in CI, to get an experience & protections similar to “compile-time type checking”
it lacks clear and enforced type restrictions which help with clear code contracts
Not anymore! Gradual typing is supported by the core language and pyright is a fantastic incremental type checker that you can use both in your editor and in CI.
Kache@lemm.eeto
Programmer Humor@programming.dev•++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>>++++++++++++.-----------.+++++++++.-----.++++++++++.
1·2 years agoWhat’s hard about vanilla Ruby?
Kache@lemm.eeto
Programmer Humor@lemmy.ml•TIFU by not using objects in my object-oriented programming coursework
11·2 years agoBad abstraction is worse than no abstraction
If the code is going to poorly organized, I’d prefer it to just be one single gigantic standalone script than some wrong and misleading arrangement of objects or functions that adds more complexity than they solve
Kache@lemm.eeto
Programmer Humor@programming.dev•TIFU by not using objects in my object-oriented programming coursework
3·2 years agoinheritance to avoid code duplication
What no, inheritance is not for code sharing
Sound bite aside, inheritance is a higher level concept. That it “shares code” is one of several effects.
The simple, plain, decoupled way to share code is the humble function call, i.e. static method in certain langs.
Kache@lemm.eeto
Programmer Humor@programming.dev•TIFU by not using objects in my object-oriented programming coursework
23·2 years agoIf you used good objects, you’ll only have to make the change in one place
IMO that’s generally a retroactive statement because in practice have to be lucky for that to be true. An abstraction along one dimension – even a good one, will limit flexibility in some other dimension.
Occasionally, everything comes into alignment and an opportunity appears to reliably-ish predict the correct abstraction the future will need.
Most every other time, you’re better off avoiding the possibility of the really costly bad abstraction by resisting the urge to abstract preemptively.
Kache@lemm.eeto
Programmer Humor@programming.dev•Modern self-inflicted problems require modern solutions
1·2 years agoYou can reference envs from the host in docker compose, so code it in instead of manually passing tribal knowledge in: https://stackoverflow.com/a/73826410
Kache@lemm.eeto
Programmer Humor@programming.dev•Modern self-inflicted problems require modern solutions
1·2 years agoSimpler to keep everything in one compose file if you can, under a
testservice that doesn’t build unless explicitly namedUn-weird that env var and use the normal, boring feature of defining
environmentunder yourtestservice
Kache@lemm.eeto
Programmer Humor@programming.dev•Modern self-inflicted problems require modern solutions
2·2 years agoI’ve often been able to
alias drun='docker compose run --rm --build'and simplify down to:drun testShould be able to encode all those wayward args into
docker-compose.ymlorDockerfileand only use vanilla docker commands – that’s the whole point of containerization
I find it’s possible to operate Python as a statically typed language if you wanted, though it takes some setup with external tooling. It wasn’t hard, but had to set up pyright, editor integration, configuration to type check strictly and along with tests, and CI.
I even find the type system to be far more powerful than how I remembered Java’s to be (though I’m not familiar with the newest Java versions).
That’s only because the former already implies much of the latter, so they don’t need to repeat it
But IMO that’s one reason weird UX/design is not uncommon and can persist in dev ecosystems. The intended users are more proficient than average and most are able to work around most issues.