Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Soricidus
Oct 21, 2010
freedom-hating statist shill

NihilCredo posted:

i'm curious, if you're writing in a statically typed language and the class api isn't an absolute spaghetti ball of implicit assumptions, how painful did you find the refactoring effort?

i've never bothered with single-impl interfaces and i've had to add alternative implementations several times. my process looked like this:

- write the interface IFoo (if I was using a good IDE I'd just go right click -> extract interface and clean it up a bit)
- temporarily rename the interface to something else
- temporarily rename the class to IFoo via the IDE (affecting all usages)
- manually change the class name back to Foo and the interface back to IFoo

now every point in the codebase that was using a Foo is using an IFoo instead.

you just made a massive incompatible change to your api. any other code that consumes yours now needs changing too - hope you dont write libraries! hell even if your project is self contained, anyone whos working on a different branch is going to hate you when they try to merge.

whereas if you just define the interfaces up front you can add another implementation without even breaking binary compatibility, let alone source compatibility. its good.

Adbot
ADBOT LOVES YOU

Chalks
Sep 30, 2009

it's a solution to a specific problem, if you're having that problem then they're great but if not then they're not.

CPColin
Sep 9, 2003

Big ol' smile.
I had a coworker at Experts Exchange who wanted every class to implement a new interface called EEObject, which was to be empty, because they couldn't think of anything to put in it yet, but "just in case" we ever wanted to add anything that literally every class should have in common. I got the feeling my boss had my coworker come over and talk to me because Boss thought it was unnecessary, but couldn't find the words to explain why.

So I said, "That sounds unnecessary." and they dropped it. You Aren't Gonna Need It is such a fun thing when it turns out to be right.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Soricidus posted:

you just made a massive incompatible change to your api. any other code that consumes yours now needs changing too - hope you dont write libraries! hell even if your project is self contained, anyone whos working on a different branch is going to hate you when they try to merge.

whereas if you just define the interfaces up front you can add another implementation without even breaking binary compatibility, let alone source compatibility. its good.

most people are not writing libraries which will be consumed by other people. if a rename as simple as changing Foo to IFoo makes people hate you then how do you managed to ever change anything? is your codebase just an append-only nightmare?

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender
I work on a product that is implemented in C++. We rarely define new C++ (non-rpc) interfaces. I've kinda groomed our test strategy for "unit tests" to be like:
* Wherever possible, use real implementations.
* When required, use fakes/mocks (generally for the remote services we depends on)
* Rarely mock anything else.

It's going pretty OK for us! Hope this helps

Chalks
Sep 30, 2009

CPColin posted:

I had a coworker at Experts Exchange who wanted every class to implement a new interface called EEObject, which was to be empty, because they couldn't think of anything to put in it yet, but "just in case" we ever wanted to add anything that literally every class should have in common. I got the feeling my boss had my coworker come over and talk to me because Boss thought it was unnecessary, but couldn't find the words to explain why.

So I said, "That sounds unnecessary." and they dropped it. You Aren't Gonna Need It is such a fun thing when it turns out to be right.

increasing the complexity of your code "just in case" is the worst - even when it occasionally turns out to be useful and saves you some time, you already wasted far more time than you saved scattering 1000 other "just in case" complications throughout the rest of the code.

the best code is the code you decided not to write

MrQueasy
Nov 15, 2005

Probiot-ICK

Chalks posted:

increasing the complexity of your code "just in case" is the worst - even when it occasionally turns out to be useful and saves you some time, you already wasted far more time than you saved scattering 1000 other "just in case" complications throughout the rest of the code.

the best code is the code you decided not to write

This is the most secure and bug-free code I've ever seen. https://github.com/kelseyhightower/nocode

raminasi
Jan 25, 2005

a last drink with no ice

Jabor posted:

if you get it right the first time

the sign was just tapped like a page ago

12 rats tied together
Sep 7, 2006

yagni shouldn't even be classified as "extreme programming". nothing is ever correct period, never mind "the first time"

Bloody
Mar 3, 2013

raminasi posted:

i am getting the sense that this is just one of the few concrete c#/java distinctions in the space; something like mockito wouldn't be possible in c# without getting weird, because in c# you can't just stub part of an object for free. (and fwiw i don't understand why mocking a whole object is more of a smell than stubbing individual methods on it - in the ideal well-factored case, wouldn't the second option not be sensible anyway because the methods are all designed to work together?)

my friend are you familiar with proxying https://www.castleproject.org/projects/dynamicproxy/

raminasi
Jan 25, 2005

a last drink with no ice

you are making my point for me posted:

You can use DynamicProxy to generate lightweight proxies on the fly for one or more interfaces or even concrete classes (but only virtual methods will be intercepted).

distortion park
Apr 25, 2011


There is a Microsoft Fakes thing which I think can mock just about everything, but it's more work to debug and more confusing than just using basic language features. Interfaces are simple and work with all your tools.

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


finishing the week with the following comment in some code:

code:

\\I have a hangover and don't have the mental energy to make this better

happy Friday :toot:

fourwood
Sep 9, 2001

Damn I'll bring them to their knees.

Powerful Two-Hander posted:

finishing the week with the following comment in some code:

code:
\\I have a hangover and don't have the mental energy to make this better
happy Friday :toot:
the coding horror is the use of backslashes instead of forward slashes for comments

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


fourwood posted:

the coding horror is the use of backslashes instead of forward slashes for comments

loving too hungover to even write a comment properly :negative:

necrotic
Aug 2, 2005
I owe my brother big time for this!
its great, it will fail to run so you cant miss it when you return

CPColin
Sep 9, 2003

Big ol' smile.
I've definitely left syntax errors for myself so I know where to pick back up on Monday. Good strategy.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


sounds like a problem for monday me

fourwood
Sep 9, 2001

Damn I'll bring them to their knees.

CPColin posted:

I've definitely left syntax errors for myself so I know where to pick back up on Monday. Good strategy.
yeah ive totally done this before

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


necrotic posted:

its great, it will fail to run so you cant miss it when you return

tbf that was phone posting not copy and paste, the real comment is correctly formatted

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Soricidus posted:

separate interfaces are good and idk why people are obsessing over the testing thing. i use them all the time and rarely for mocking. theyre a useful organisational tool, they make your public api explicit instead of relying on convention or coarse-grained visibility modifiers, they let you inherit structure without having to inherit implementation. its good stuff and a useful tool to make my life easier.

and if I had a dollar for every time Ive realised down the line that I need a second implementation of something, and been able to just add it instead of having to choose between subclassing or painful refactoring, Id be able to buy a coffee. maybe two coffees.

annotating your methods with public/private is too "coarse-grained" so instead you copy and paste the whole interface?

"public" is not explicit?

grats on making GBS threads up your codebase for $5 though

MrMoo
Sep 14, 2000

Whats todays fastest method for replicating files across a MAN? Multicast only works to a certain speed and needs recovery back channels. BitTorrent sounds better than it is supposed to, I recall Blizzard using it and some here saying they moved to something else? Up to around 2GB, mainly video.

https://tech.ebayinc.com/engineering/bittorrent-for-package-distribution-in-the-enterprise/

I see Canonical has moved from the gimpy Jigdo thing that no one knew anything about to the more standard zsync system as referenced by Ebay above.

CTO job is starting soon, and :lol: Who wants some Django, Postgres, Flask, and oodles of JS?

I have a LG set top box, it looks like it cannot support HTTP streaming at anything from 40mbps and 10-bit colour h265 to 3mbps h264. Literally stutters on all versions of the wonderful jellyfish video, which apparently is a thing.

https://jell.yfish.us/

MrMoo fucked around with this message at 06:13 on Jun 12, 2021

men with puns
Feb 8, 2010
Young Orc

duz posted:

sounds like a problem for monday me

fuckin :same:

CPColin
Sep 9, 2003

Big ol' smile.
Monday me, specifically after I get "settled in", so Monday afternoon me

men with puns
Feb 8, 2010
Young Orc

fart simpson posted:

*clears throat* in haskell you can implement type classes (basically interfaces) for types you didnt write and also wrap existing types in newtypes and give the newtypes a different implementation of the same type class, and the compiler strips all of that away so that at runtime the type and newtype are identical but with different functions called on them

i havent thought about haskell in a while so i went back to look at it again and i still dont understand why people use it in any practical context.
i took a class long ago from a person who was absolutely smitten with haskell but during their hours of talking about "syntactic sugar", etc, they completely, totally failed to convey why we as potential users might want to consider it as an option over other languages that have better library support, simpler syntax, more resume value, or other conveniences.

and now that i look into it again, the main pro-haskell arguments seem to mostly boil down to "smart people like how sophisticated haskell is".
most of the other quoted benefits seem to just go out the window as soon as you have to do any i/o. need to do a database query? need to interact with something over a network socket? need to activate a physical device or get user input? your lazy evaluation is done. your functions are no longer pure, because they have side effects. you no longer get free parallelism. you have to handle raw signals, bytes or strings and convert them to whatever types your program likes to think about. can your program even do anything interesting without crossing those boundaries? and if not, why even use haskell? most programming work is just endlessly refactoring ancient garbage due to arbitrary business decisions, and i dont see how haskell makes that easier. even in optimal circumstances, haskell's lazy evaluation is bad with memory usage so it seems like a poor choice for performance.

if i wanted to build a really elegant calculator or something, sure, i can see haskell as a good choice, but in the world where programs are made by the lowest bidder and have to talk to other people's programs, who dont even follow their own specifications, and where you spend most of your time writing regretful compromises, well, being as abstract as haskell likes to be just seems like doing extra work to create more problems for yourself.

not meaning to call you out or whatever, its cool to use what makes you happy and i'm not asking you to defend it or anything. it just feels like there's something else there that i'm not getting and it bugs me.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
lmao that's great

did you get it from reddit or something

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


Powerful Two-Hander posted:

finishing the week with the following comment in some code:

code:

\\I have a hangover and don't have the mental energy to make this better

happy Friday :toot:

Saturday morning and the not hungover brain kicks in...

the problem i was failing to solve neatly was to take a list of object ids where the objects may contain a reference to another object id as parent-child relationship, and process it so that the parent objects were all handled before the children. this would be easier if the objects had their parent id as a property but they don't. or more accurately they do but you have to parse it out of an xml string which means you've got to load the whole thing first.

so what was my brilliant fix? Iterate over the objects, check each has a parent I'd after loading it and if it does, stuff that id into another list of children, then once the parents are processed, process the children. In between, create a dictionary of created parents to link a parent id to the created object reference. sort of works, fails in a case where a child is also a parent but good enough, commit it with a comment and go lie down.


today I realise that because the parent and child ids are all keys from the same sql table in their ultimate source syatem (which I maintain), I could have just sorted the ids and it would guarantee that each parent is processed before any possible children :negative:

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Powerful Two-Hander posted:

today I realise that because the parent and child ids are all keys from the same sql table in their ultimate source syatem (which I maintain), I could have just sorted the ids and it would guarantee that each parent is processed before any possible children :negative:

this is totally fine but please don't leave the id layout assumption implicit. keep a hash set of the processed IDs and when you process a child, check that the parent has been already processed before continuing

Brain Candy
May 18, 2006

men with puns posted:

what is I/O monad or literally anything in the lang people love to use to write parsers

source your quotes

mystes
May 31, 2006

Even if you think the io monad is impractical (although you can really just do your whole program in the io monad and then it's just like an imperative language), it's one of the most successful attempts to make a language where functions have to somehow be marked based on whether they're pure or not, which is an extremely good idea.

Effect systems are getting more popular though, so I wouldn't be surprised if in 10 years whatever the next rust is will have a limited, hardcoded effect systems with just "pure" "partial" and "io" as effects or something like that.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

men with puns posted:

i havent thought about haskell in a while so i went back to look at it again and i still dont understand why people use it in any practical context.
i took a class long ago from a person who was absolutely smitten with haskell but during their hours of talking about "syntactic sugar", etc, they completely, totally failed to convey why we as potential users might want to consider it as an option over other languages that have better library support, simpler syntax, more resume value, or other conveniences.

and now that i look into it again, the main pro-haskell arguments seem to mostly boil down to "smart people like how sophisticated haskell is".
most of the other quoted benefits seem to just go out the window as soon as you have to do any i/o. need to do a database query? need to interact with something over a network socket? need to activate a physical device or get user input? your lazy evaluation is done. your functions are no longer pure, because they have side effects. you no longer get free parallelism. you have to handle raw signals, bytes or strings and convert them to whatever types your program likes to think about. can your program even do anything interesting without crossing those boundaries? and if not, why even use haskell? most programming work is just endlessly refactoring ancient garbage due to arbitrary business decisions, and i dont see how haskell makes that easier. even in optimal circumstances, haskell's lazy evaluation is bad with memory usage so it seems like a poor choice for performance.

if i wanted to build a really elegant calculator or something, sure, i can see haskell as a good choice, but in the world where programs are made by the lowest bidder and have to talk to other people's programs, who dont even follow their own specifications, and where you spend most of your time writing regretful compromises, well, being as abstract as haskell likes to be just seems like doing extra work to create more problems for yourself.

not meaning to call you out or whatever, its cool to use what makes you happy and i'm not asking you to defend it or anything. it just feels like there's something else there that i'm not getting and it bugs me.

idk i just like it and programming in haskell fits my mental model of how things should work better than other languages do. hth

Bloody
Mar 3, 2013

haskell is cool op

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

in micro examples it looks complicated i guess but when actually putting different things together i find all that extra haskell stuff makes it much easier to figure out whats going on and how it all fits together, and easier to come back a year later and edit things without having everything break. i dont like haskell because i think im smart, if anything its the opposite. i like it because im not smart enough to use c# or something like that

CPColin
Sep 9, 2003

Big ol' smile.

NihilCredo posted:

this is totally fine but please don't leave the id layout assumption implicit. keep a hash set of the processed IDs and when you process a child, check that the parent has been already processed before continuing

Everybody is proud of sorting sequentially submitted data by ID until, bam, some idiot does a migration somewhere and suddenly everything needs new indexes with Submit_Date in them. (And, since you've been storing everything in local time, with no time zone, this whole time, suddenly your users start filing a bug every year that stuff is appearing out of order between 1AM and 2AM in November.)

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED
haskell is nice because of its type system. other statically typed languages like python get you part of the way there, but the amount of constraints and verification you can encode in haskell's type system really does make it fun to use

psiox
Oct 15, 2001

Babylon 5 Street Team

Powerful Two-Hander posted:

Saturday morning and the not hungover brain kicks in...

the problem i was failing to solve neatly was to take a list of object ids where the objects may contain a reference to another object id as parent-child relationship, and process it so that the parent objects were all handled before the children. this would be easier if the objects had their parent id as a property but they don't. or more accurately they do but you have to parse it out of an xml string which means you've got to load the whole thing first.

so what was my brilliant fix? Iterate over the objects, check each has a parent I'd after loading it and if it does, stuff that id into another list of children, then once the parents are processed, process the children. In between, create a dictionary of created parents to link a parent id to the created object reference. sort of works, fails in a case where a child is also a parent but good enough, commit it with a comment and go lie down.


today I realise that because the parent and child ids are all keys from the same sql table in their ultimate source syatem (which I maintain), I could have just sorted the ids and it would guarantee that each parent is processed before any possible children :negative:

i would simply assemble a DAG and do a breadth-first search over it

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


psiox posted:

i would simply assemble a DAG and do a breadth-first search over it

well, actually this whole thing is to create a DAG. it's my (probably) pointless "spare time" work project that I do when I'm bored with real work (arguing about estimates). each node type implements and interface (stop it) so has a method that looks for all related nodes in the source and adds them to the DAG or returns them if they already exist (using a lookup to a dictionary of node and type keys), then adds the edges linking them and any grouping structure around them. It's all then thrown at cola.js to draw it.

so i actually probably could do that and while loop it

men with puns
Feb 8, 2010
Young Orc

fart simpson posted:

idk i just like it and programming in haskell fits my mental model of how things should work better than other languages do. hth

that's cool. maybe some day it'll click for me

MrQueasy
Nov 15, 2005

Probiot-ICK

men with puns posted:

that's cool. maybe some day it'll click for me

The problem is, once you understand monads, you become incapable of explaining them properly.

Haskell as a language is kindof like that, but on a larger scale.

Adbot
ADBOT LOVES YOU

toiletbrush
May 17, 2010
every programming language should aspire to be haskell, because every concept you steal from it will make you better, but never, ever actually *become* haskell

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply