Fork me on GitHub
#clojure-uk
<
2020-09-11
>
dharrigan05:09:43

Good Morning!

alexlynham10:09:20

i was just introduced to the idea that this is a code smell http://wiki.c2.com/?PrimitiveObsession

alexlynham10:09:26

and i was like looooooool

alexlynham10:09:35

using primitive data is good design

alexlynham10:09:41

not a code smell hahaha

alexlynham10:09:34

come back to me about primitive data once you've scaled a service that uses microservices or external parties... i don't think your ValueObject will serialise as easily as 1

mccraigmccraig10:09:45

primitive-data + language features to enforce type or schema of that primitive data is the killer combo

👍 3
alexlynham10:09:26

i feel like it's quite obvious

alexlynham10:09:38

but it's very hard to explain to some folks

alexlynham10:09:15

been using jsonschema on current project cos it's typescript and damn it makes me miss schema

alexlynham10:09:26

having to write schemas and my types out is booooring

mccraigmccraig11:09:17

this feels like a convincing argument: if only the types in typescript were themselves plain-old-datastructures, then you could use them to construct a parser for your JSON and your duplication problem would disappear

minimal12:09:17

or if the type system was more powerful you could derive the parsers and encoders from the types https://hackage.haskell.org/package/aeson-deriving#readme

mccraigmccraig12:09:25

in the end i presume a sufficiently expressive ability to despatch on type is equivalent to having the type-structures available as data, but perhaps safer ?

mccraigmccraig12:09:52

or, are there things which can't be expressed in one way that can be expressed in the other ? i can't recall anything about this... have you seen anything @U050CJW4Q ?

minimal12:09:59

I think by default it supports simple types and you can write custom convertors for others

alexlynham11:09:14

people look at you funny when you say stuff about getting things for free without having to parse the gen'd ASTs

mccraigmccraig11:09:16

it's the same as the old unix make-everything-a-filesystem argument - you get compounded benefits from having a uniform means of access

alexlynham11:09:15

right, which you only get with primitive data

mccraigmccraig11:09:53

there are lots of nice islands to visit in stockholm

alexlynham12:09:13

yeah noticeable that purescript is weaker than haskell in that regard (afaict anyway, from a novice perspective)

rickmoynihan13:09:26

@alex.lynham: I hear what you’re saying, but isn’t the advice behind that essentially saying, don’t use for example Int to mean EmployeeId, define a type or spec called EmployeeId, and use that instead, even if it’s just essentially an alias for Int? i.e. it’s better to lift primitives into domain language.

rickmoynihan13:09:40

e.g. in clojure.spec: (s/def ::employee-id integer?) is better than just using integer? everywhere where you mean employee-id.

alexlynham14:09:22

well when you see it in OO context it tends to mean encapsulate it in an object

alexlynham14:09:56

& even in your example it's just a ref innit, so it's quite different to something inaccessible

alexlynham14:09:18

back to the data/metadata thing with objects being like metadata that doesn't compose

alexlynham14:09:23

where e.g. types do compose

alexlynham14:09:11

because in OO land defining a type entails the baggage of instantiating objects and using objects

alexlynham14:09:35

i've got no quarrel with types sir

rickmoynihan14:09:24

:thumbsup: For them it certainly does mean encapsulating in an object; but I think that’s just because the c2 community and most of that wiki’s content were written circa 2000; by a bunch of smalltalkers, and folk adopting java… so most of it has an OO flavour. Weren’t they just using the tools and language available to them to try and express the more general idea of prefering domain representations to primitive ones?

rickmoynihan14:09:42

Nobody likes the drudgery of wrapping/unwrapping things that’s for sure… but sometimes needs must!

rickmoynihan14:09:39

100% agree that every class is an island though

alexlynham14:09:18

i guess the context is that i'm leading a project where we pass around largely domain-specific hashmap representations to avoid messing with classes/objects and we're the only team really being that functional primitive obsessed is a kinda criticism that's been levelled at me a few times as regards coding style and so yes while i think there's historical residue to the definition and indeed a charitable interpretation is 'map your domain well' the reality is i've found it something that OO people prize without understanding the trade off to

alexlynham14:09:36

because it parses as 'primitive data bad, objects good'

alexlynham14:09:28

example given in a friendly exchange earlier: > also toString(Money(7, ‘GBP’)) is different to toString(7) to which i retorted ['gbp', 7] (in js, obv in clj you could use :gbp or a namespaced version

alexlynham14:09:18

but the idea that instantiating a class for what is self evidently modellable as a tuple or variant while keeping within the bounds of primitive data is wild

alexlynham14:09:35

and imho dead wrong, but then i am an fp fundamentalist

alexlynham15:09:02

wrong tab craig

Conor15:09:44

"Deploy first. Think later. It's the natural order."

dominicm16:09:23

SQL is broken.

mccraigmccraig17:09:16

more than usual ?

dominicm17:09:01

No. Well, maybe.

dominicm17:09:51

I want to join to multiple things but retain the tree shape.

seancorfield17:09:38

Interesting comments about the c2 stuff. Back in the '90s and early '00s, OOP was still supposed to be the industry's "saviour" and Object Think and OOAD were the One True Way because the whole industry had aligned behind that after procedural and structured programming had failed to shine at scale (complexity scale).