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.
 
  • Locked thread
Bloody
Mar 3, 2013

Di is boring let's talk about cvs

Adbot
ADBOT LOVES YOU

FamDav
Mar 29, 2008

MononcQc posted:

The quickcheck library wouldn't be much help unless you can figure out a property of your IO system you want to see, or find an alternative function (a model) to compare your implementation to.

Otherwise you'll be generating random-but-guided data and test cases, but you have no guarantee that your tests are relevant in any way.

yeah, the few things you want to do to be able to test IO are:

* move all of your pure code in IO functions to pure functions. hey now you can test all of that with quickcheck or whatever

* you can create a wrapper class Monad m => AppIO m that declares all the IO functions you use in your program and declares its own instance of monad. then you can create an instance for IO which is the one used normally, and an instance for something like AppIO (State MockData) that you can use in testing

but really, moving your pure code out of pure functions and making those as small as possible is what you want to do.

hobbesmaster
Jan 28, 2008

Bloody posted:

Di is boring let's talk about cvs

walgreens suits my needs op

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

FamDav posted:

yeah, the few things you want to do to be able to test IO are:

* move all of your pure code in IO functions to pure functions. hey now you can test all of that with quickcheck or whatever

* you can create a wrapper class Monad m => AppIO m that declares all the IO functions you use in your program and declares its own instance of monad. then you can create an instance for IO which is the one used normally, and an instance for something like AppIO (State MockData) that you can use in testing

but really, moving your pure code out of pure functions and making those as small as possible is what you want to do.

elm is really easy for this kind of stuff. you just write literally everything as pure functions and then thread a signal through it right at the end to make it actually do stuff. that's basically what you should be doing in haskell with io anyway, but haskell makes it a lot easier to spend a lot of unnecessary time living in the io monad

MononcQc
May 29, 2007

FamDav posted:

yeah, the few things you want to do to be able to test IO are:

* move all of your pure code in IO functions to pure functions. hey now you can test all of that with quickcheck or whatever

* you can create a wrapper class Monad m => AppIO m that declares all the IO functions you use in your program and declares its own instance of monad. then you can create an instance for IO which is the one used normally, and an instance for something like AppIO (State MockData) that you can use in testing

but really, moving your pure code out of pure functions and making those as small as possible is what you want to do.

If I'm in Erlang I can use meck to mock the IO functions and leave their implementation in place, and then get a trace of all their arguments and return values, and/or overload their implementations. I can then use that stuff in any test framework I want, including Quickchck v:shobon:v

It's particularly useful when I want to test that something gets properly logged, because I just get a trace of the logging module and can analyze everything post-facto in a functional manner.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

fart simpson posted:

elm is really easy for this kind of stuff. you just write literally everything as pure functions and then thread a signal through it right at the end to make it actually do stuff. that's basically what you should be doing in haskell with io anyway, but haskell makes it a lot easier to spend a lot of unnecessary time living in the io monad

Maybe it's finally time for me to get serious about haskell

FamDav
Mar 29, 2008

MononcQc posted:

If I'm in Erlang I can use meck to mock the IO functions and leave their implementation in place, and then get a trace of all their arguments and return values, and/or overload their implementations. I can then use that stuff in any test framework I want, including Quickchck v:shobon:v

It's particularly useful when I want to test that something gets properly logged, because I just get a trace of the logging module and can analyze everything post-facto in a functional manner.

that just doesnt feel necessary in a language where the stuff actually dependent on IO are going to sit at main or maybe a function below that. For any case where you have to thread IO deeper into your stack (and a lot of times you don't) you're likely working with something that is (or should be) a monad transformer that wraps IO and can be substituted out for a state instance or something.

FamDav
Mar 29, 2008
though no lie writing the kind of code to make a MyServiceT that does the correct thing can be cumbersome

MononcQc
May 29, 2007

FamDav posted:

that just doesnt feel necessary in a language where the stuff actually dependent on IO are going to sit at main or maybe a function below that. For any case where you have to thread IO deeper into your stack (and a lot of times you don't) you're likely working with something that is (or should be) a monad transformer that wraps IO and can be substituted out for a state instance or something.

Logging or gathering metrics in running code that operates with sockets tends to be nice to be able to weave as deep as you need it to be if you want the values to be accurate. I'm still not sure how easy it would be to take some production code we have that parses, transforms and pipes data across many sockets and goes "yes that were how many bytes were shuttled from A to B and from B to A and here's how long each step took" especially without wanting to accumulate any of that data in memory longer than required in the first place.

Instead I access global time wherever, put logs in a mergeable data structure and can then build everything where I need to report it without altering code structure or duplicating it because someone wants to know where time is spent on specific requests and responses.

I'm guessing these cases just can't happen in Haskell so you have to solve that problem beforehand (or give up on these metrics altogether) though.

I like being able to go meck:new(io, [passthrough, unstick]), run_my_test(), meck:history(io) and then I have a data structure that traces every call made lower in the stack and not have to do anything different.

suffix
Jul 27, 2013

Wheeee!

thanks, these are all good points

tef posted:

on the other hand if you're just using it for unit testing there is probably some classloader hack that will fix this for you.

in java i can use powermock to swap in a mock implementation, and in python unittest.mock can monkey patch things out for each test
i was thinking there might be some general way to do it across oo languages that i was missing, but i'm starting to think that you need language support to do it well


MononcQc posted:

If I'm in Erlang I can use meck to mock the IO functions and leave their implementation in place, and then get a trace of all their arguments and return values, and/or overload their implementations. I can then use that stuff in any test framework I want, including Quickchck v:shobon:v

It's particularly useful when I want to test that something gets properly logged, because I just get a trace of the logging module and can analyze everything post-facto in a functional manner.

cool. this lets you swap out any module for your tests?

MononcQc
May 29, 2007

suffix posted:

cool. this lets you swap out any module for your tests?

Yes, at runtime. You can override anywhere between no functions to all of them functions there by arbitrary code and even define sequences for whatever mocks you'd make that would depend on hidden process state. You can decide to let missing overrides pass through to existing code or to force a crash if you want.

It's a pretty nifty tool that beats monkeypatching and some lovely container mechanism any day of the week.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
who knows about fb app poo poo? i'm trying to fix some bug in one of our apps but i dont know anything about this and i dont really want to. we have 6 links and all of them send a request back to our local box which i can see. the 7th is throwing an internal server error but it's never even sending a request back to my server.

these links all point to apps.facebook.com/app_namespace/:route, which are configured in the fb app settings to point back to my server. i dont understand why all the other routes have no issue reaching me but this one is throwing an error, unless there's some setup thing on facebook that i'm missing

comedyblissoption
Mar 15, 2006

suffix posted:

i have a terrible programmer question: how do you do dependency injection right?

i get the concept and how it makes unit testing easier, but on the projects i've worked on it always ends up with at least one of two problems:
- all your code ends up unnecessarily tied to a specific injection container
- your outermost layer ends up being a gigantic mess of instantiating and connecting every object in the program, maybe in xml for good measure

like 90% of the time we don't have any alternative implementations and only want to switch it out for our unit tests,
so it doesn't feel right to just pass it up until your main code has to care about a helper class to a helper class to a helper class,
but that's the logical conclusion from the introductory texts i've read
Use a convention-based Dependency Injection framework.

The entire reason for a DI framework is to create the object graph for you without you having to do it all by hand with a giant series of new Foo(new Bar, new Baz(...)). If you have to set something up whenever you add a new dependency in your object graph, your DI framework sucks.

As an example, imagine your class needs an IFoo instance in its constructor. Somewhere in your assembly is a Foo implementing IFoo. Your DI framework should be able to automatically detect this and instantiate Foo and pass it into the IFoo. The DI framework should be able to recursively do this for all of the dependencies of Foo. You should be able to configure if Foo will be a singleton throughout the assembly and the DI framework should handle that.

Be careful if you use the new operator in an object's constructor and you're not constructing a simple value object. The entire point of DI is to make it so you aren't calling new in an object constructor.

Following DI principles is a boiler-platish patch on java-like OOP encouraging bad practices for modularity and composition of programs.

comedyblissoption
Mar 15, 2006

Also run away from poo poo that requires you to program things in XML.

FamDav
Mar 29, 2008

comedyblissoption posted:

Following DI principles is a boiler-platish patch on java-like OOP encouraging bad practices for modularity and composition of programs.

if java were amenable to partial application you really wouldnt need nearly as much of the plumbing that goes into, say, spring.

that being said, spring gives you the ability to do configuration at runtime p easily, whether thats at startup or even per request.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

MALE SHOEGAZE posted:

who knows about fb app poo poo? i'm trying to fix some bug in one of our apps but i dont know anything about this and i dont really want to. we have 6 links and all of them send a request back to our local box which i can see. the 7th is throwing an internal server error but it's never even sending a request back to my server.

these links all point to apps.facebook.com/app_namespace/:route, which are configured in the fb app settings to point back to my server. i dont understand why all the other routes have no issue reaching me but this one is throwing an error, unless there's some setup thing on facebook that i'm missing

okay i just changed the link to apps.facebook.com/app_namespace/settings to apps.facebook.com/app_namespace/buttslol and it works fine wtf

comedyblissoption
Mar 15, 2006

FamDav posted:

if java were amenable to partial application you really wouldnt need nearly as much of the plumbing that goes into, say, spring.

that being said, spring gives you the ability to do configuration at runtime p easily, whether thats at startup or even per request.
Yeah, it's basically a language flaw that proper composition requires newing up a giant object graph at the top level which requires a reflection-based framework not to be tedious.

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

Bloody posted:

Di is boring let's talk about cvs

cvs was pretty bad

Stringent
Dec 22, 2004


image text goes here
i wonder if there's some other forum where some dude 10 years older than rotor is vociferously defending cvs

Plastic Snake
Mar 2, 2005
For Halloween or scaring people.
good new thread title

theadder
Dec 30, 2011


can i ask rly stupid programming qs in here

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

Stringent posted:

i wonder if there's some other forum where some dude 10 years older than rotor is vociferously defending cvs

nope, i checked

cinci zoo sniper
Mar 15, 2013




theadder posted:

can i ask rly stupid programming qs in here
yes, itt is hideout

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

theadder posted:

can i ask rly stupid programming qs in here

nobody will judge you here, friend

Soricidus
Oct 21, 2010
freedom-hating statist shill

rotor posted:

nobody will judge you here, friend

unless you defend git

wolffenstein
Aug 2, 2002
 
Pork Pro
what up thread its been a long while since i last posted in here. last time i shitposted about webdna, a lovely relic of a language no one's heard of. well after quitting that job without lining up another one first, i had a severe existential crisis and pretty close to committing suicide. a cross country move and several lovely months later, i am gainfully employed at a php dev shop. also i take sad brain medication and see a counselor so i don't repeat what i did. yet i still seem easily susceptible to giving a drat about doing my job right.

so this dev shop was like three people for the longest time, then in the past year they hired on like crazy to try and keep up with the work coming in. well considering my last job was just my boss and i with no prospect for growth, this is already a step up. they use svn, which is better than no vcs so yay another step up.

and that's about it. every client's svn repo is the latest development snapshot with no branches or indication what production is running. development is done on a remote web server that may also be hosting the test environment and/or the production environment. debugging consists of var_dump, print_r, and die calls, and checking logs is next to useless because they turned off all error logging in php.ini. updating files on servers consists of ssh, using svn up only on the specific files you changed, and alter table queries from the mysql cli.

to save my sanity and resolve some long standing bugs i made a vagrant vm, cloned the svn repo into git, and made an orphan branch with rsync'd production code. i got an actual debugger installed and resolved a few issues within hours of setup.

my team thinks this is black voodoo magic and would take too much time to setup and train, so their solution is to make separate remote servers for every dev and just be sure to check svn before you work on a file.

i guess i should jump ship but given my troublesome employment history, i think its best to stick it out for at least a year before moving. or finding a less sad brains-inducing career. i just wanna be like tef. thanks for reading.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Stringent posted:

i wonder if there's some other forum where some dude 10 years older than rotor is vociferously defending cvs

I'm actually on that list (not forum) and it has not just CVS but RCS/SCCS adherents and ClearCase (or was it PVCS?) advocates

people who consider locking everyone else out of a file while it's being edited by one person a serious advantage

who think sharing should code be done via a shared filesystem - and possibly sharing build intermediates too

cinci zoo sniper
Mar 15, 2013




while your team are savages, dont jump ship before you see the coast, unless they want to eat you
godspeed, coder :unsmith:

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

wolffenstein posted:

i guess i should jump ship but given my troublesome employment history, i think its best to stick it out for at least a year before moving. or finding a less sad brains-inducing career. i just wanna be like tef. thanks for reading.

using a VM to do your black voodoo magic debugging sounds like a step on the way to being like tef, especially in that small pond, sticking it out for a year could see you leading or managing things

theadder
Dec 30, 2011


rotor posted:

nobody will judge you here, friend

thank u 4 ur kind words



ive no programming experience at all & this is the problem im looking at

im trying to do the experiment bit but but im unsure what the answer would look like

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

theadder posted:

thank u 4 ur kind words



ive no programming experience at all & this is the problem im looking at

im trying to do the experiment bit but but im unsure what the answer would look like

Imo tef or someone who has thought a lot about teaching programming should answer this one

Is that swift or lua maybe?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
the code currently keeps track of the largest number it's seen so far in the aptly-named "largest" variable.

the experiment is asking you to add another variable (say, largestKind) that keeps track of what kind the largest number seen so far happens to be.

PokeJoe
Aug 24, 2004

hail cgatan


theadder posted:

thank u 4 ur kind words



ive no programming experience at all & this is the problem im looking at

im trying to do the experiment bit but but im unsure what the answer would look like

i don't know anything about programming either but is that set of numbers an array of arrays? you can keep track of the position in that first array when a number is found in the others to see what "kind" of number it is.

theadder
Dec 30, 2011


MALE SHOEGAZE posted:

Imo tef or someone who has thought a lot about teaching programming should answer this one

Is that swift or lua maybe?

its swift ya

Jabor posted:

the experiment is asking you to add another variable (say, largestKind) that keeps track of what kind the largest number seen so far happens to be.

i should have said more but im used to v short posts

its not the concepts but smth about the syntax that im having trouble with

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

theadder posted:

thank u 4 ur kind words



ive no programming experience at all & this is the problem im looking at

im trying to do the experiment bit but but im unsure what the answer would look like

something like this I guess

code:
var largest = 0
var tracked_kind = ""
for (kind, numbers) in interestingNumbers {
    for number in numbers {
        if number > largest {
            largest = number
            tracked_kind = kind
        }
}
now what if your interestingNumbers contain only negative numbers? :iamafag:

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
you should post something that you've tried but isn't working - it's way more instructive to point out where your existing approach went wrong than it is to just give a solution (or a process to derive a solution) from nothing.

cinci zoo sniper
Mar 15, 2013




take absolute values, butt?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

kalstrams posted:

take absolute values, butt?

but -1 is larger than -9!

cinci zoo sniper
Mar 15, 2013




err, i brainfarted

wouldn't it work as is then? (note, i have no idea about swift)

Adbot
ADBOT LOVES YOU

jesus WEP
Oct 17, 2004


kalstrams posted:

err, i brainfarted

wouldn't it work as is then? (note, i have no idea about swift)
no because the variable is initialised as 0 so it would return 0

  • Locked thread