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
redleader
Aug 18, 2005

Engage according to operational parameters
tax stuff sounds like it should be one of those very unit-testable things - given these conditions, this value should come out. properly done, it should be a pure function. done wrong, it's both rigidly inflexible and impossible to understand

guess how well the system i work on handles taxes?

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters
i should really put together a blog or something on "dealing with money stuff without wanting to kill yourself"

pangstrom
Jan 25, 2003

Wedge Regret

Finster Dexter posted:

Sorry for double post, but I'm finishing up this talk on Rust.

https://www.youtube.com/watch?v=LjFM8vw3pbU

It's Bryan Cantrill, a joyent guy, and he kinda rambles all over the place but he used Rust for a few weeks and thinks it's cool.

Rust content starts at: 1:00:30

His discussion of the fight over npm shrinkwrap is kinda funny (at 1:11-ish)
Whoa. If that guy ever asked me if I had kissed a girl I would kill myself.

edit: unless kissing a girl means something about error handling to him

pangstrom fucked around with this message at 02:17 on Aug 14, 2018

Ellie Crabcakes
Jan 31, 2008

Stop emailing my boyfriend Gay Crungus

redleader posted:

guess how well the system i work on handles taxes?
The best solution might just be "let someone else do it" especially if it's telecom, where the taxation gets insanely specific.

cheque_some
Dec 6, 2006
The Wizard of Menlo Park
Thanks for all the outpouring of advice.

who would have thought funny computer forum would be so helpful

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





NihilCredo posted:

here's a real life scenario: products have VAT rates. those VAT rates can occasionally change over time, meaning both that a product can be moved to a different VAT rate, or that a VAT rate can be increased or decreased by a percentage point or two (let's keep it simple and say it's one VAT rate per product (it's not)).

is there a unit testing book that will teach me how to structure an invoicing system in such a way that I can test that it won't apply the wrong VAT rate when an invoice is created, edited, modified, or duplicated, even if the VAT rate for a product changes at some point?

"Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?"

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

cheque_some posted:

Thanks for all the outpouring of advice.

who would have thought funny computer forum would be so helpful

Nobody in yospos is funny so they have to be good at something

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


jit bull transpile posted:

Nobody in yospos is funny so they have to be good at something

that's not fair, we're all terrible at programming

Ellie Crabcakes
Jan 31, 2008

Stop emailing my boyfriend Gay Crungus

I have it on good authority that I am funny looking, Jit.

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

toiletbrush posted:

It's interesting how you can break down each instruction 'family' like MOV and figure out what registers it's dealing with just from looking at the opcode

"opcodes let you know what the instruction does"...is that what you're saying here? big if true

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Lutha Mahtin posted:

"opcodes let you know what the instruction does"...is that what you're saying here? big if true

This is why it's important to learn assembly kids. Turns out, computers are in fact not magic

invlwhen
Jul 28, 2012

please do your best

the talent deficit posted:

"Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?"

reminder that this was an mp skeptical of babbage's machine being a farce rather than an mp who had no idea about which what they were looking

redleader
Aug 18, 2005

Engage according to operational parameters

jit bull transpile posted:

Nobody in yospos is funny so they have to be good at something

conclusion does not follow from premise imo

my new dog
May 7, 2007

by Nyc_Tattoo
whats the point of tests
if nothing works anyway
somehow i get paid

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

my new dog posted:

whats the point of tests
if nothing works anyway
somehow i get paid

I need a shirt of this

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

pangstrom posted:

Whoa. If that guy ever asked me if I had kissed a girl I would kill myself.

edit: unless kissing a girl means something about error handling to him

what

Stringent
Dec 22, 2004

The internet is the universal sewer.

eschaton posted:

try doing this

get yourself off vi

quoting from way back, but learning vi is pretty much the equivalent to picking up smoking.
i've tried quitting vi off and on for like 15 years and i always keep coming back.

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
that's a good analogy

NihilCredo
Jun 6, 2011

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

MononcQc posted:

Can you define what you mean by "wrong rate", like basically the VAT should be denormalized and stored at the time of the invoice rather than mutating with the current rate the entire way through?

Mostly. When you create an invoice, but haven't yet published it (= sent it to the client or other third parties), then every time you open it the VAT rates should update to the current values. Once you publish it, VAT rates are locked at the date of publication, so if you open it (you can still make some changes after publication, like adding notes) it shouldn't update the VAT rates anymore. But, if you make a duplicate of the invoice, it should act like a newly-created one, with up-to-date rates. Oh, and if you make a credit note from the invoice, the credit note has the current date but it must keep the old VAT rates.

One can see that every sentence in the above paragraph can be expressed quite straightforwardly as a test or two, but if I've never tested anything more complicated than string parsers so far, I'm likely to make those tests brittle or vacuous or just way more work to write and maintain than they need to be.

MononcQc posted:

<stuff>
Anyway that would be the simple way to go without caring too much about whether it's clean or not.

Yes, I'd really love to see or read someone take this outline you've written and go through all the nitty-gritty details and complications that arise. How should the test invoices look like? Should it just use the current date, or fuzz values, or explicitly test 'dangerous' dates around New Year's (when invoice numbering resets)? Would it be a good idea to write a list of test invoices covering every corner case you can think of, and then share them between all tests? Customers can be set to 'VAT exempt', how do I set up the tests so they run for both exempt and non-exempt customers (and I don't want to read another loving "oh, you're testing the behavior of *two* classes, well technically it's an *integration* test now, sorry, this book is only for unit tests" evasion).

quote:

But yeah, having mostly finished writing a testing book, a big problem is that interesting tests require interesting codebases to demonstrate stuff, and having to introduce an interesting system just to test it after the fact is a hell of a lot of work (both for reader and author), and it's hard to make it interesting to the reader. You've got to dump a bunch of code going "this is not actually relevant to the lesson in this chapter but you have to go through it anyway, sorry!"

See, this is exactly what I think a book should be *for*: a well structured tutorial that can afford to take the time to properly set up the stuff it's trying to teach. If it's complicated stuff and it takes a hundred pages to do it justice, then it takes a hundred pages, and critically, *only* a book can do that. I won't find it anywhere else, short of hiring an experienced engineer to do pair programming.

If I wanted a bunch of rapid tutorials with simple examples that are more preoccupied with being interesting than useful, then I'd look for a series of articles on a blog, not a book.

NihilCredo fucked around with this message at 08:44 on Aug 14, 2018

Soricidus
Oct 20, 2010
freedom-hating statist shill

Stringent posted:

quoting from way back, but learning vi is pretty much the equivalent to picking up smoking.
i've tried quitting vi off and on for like 15 years and i always keep coming back.

it’s useful if you ever ssh into a barebones linux, or if you sudoedit without remembering to set EDITOR and can’t be bothered to change programs

here is a complete cheat sheet of vi commands worth learning:

  • i - make it behave like a normal program so you can type things
  • esc :wq - save and quit

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

NihilCredo posted:

I'd really love to see or read someone take this outline you've written and go through all the nitty-gritty details and complications that arise. How should the test invoices look like? Should it just use the current date, or fuzz values, or explicitly test 'dangerous' dates around New Year's (when invoice numbering resets)? Would it be a good idea to write a list of test invoices covering every corner case you can think of, and then share them between all tests? Customers can be set to 'VAT exempt', how do I set up the tests so they run for both exempt and non-exempt customers (and I don't want to read another loving "oh, you're testing the behavior of *two* classes, well technically it's an *integration* test now, sorry, this book is only for unit tests" evasion).

If there's a stub implementation or just more formal/step-by-step description of this domain available somewhere you can share, I would love to take a crack at this to be honest. I'm terrible obv but this is fascinating to me and I'm trying to become more test-focused in both implementation and execution. Plus this thread is inspiring me to try and do some more 'homework'.

Like, in general the question sounds like one of a series of different transformations and mutations that ideally would be isolated and therefore easy to test but there's some juicy cascading effects going on. My naive instinct would be to use a bunch of consecutive service functions and maybe use some nesting test setups (a la jasmine in the JS world) to make the combinatoric situation not explode.

gonadic io
Feb 16, 2011

>>=

Soricidus posted:

it’s useful if you ever ssh into a barebones linux, or if you sudoedit without remembering to set EDITOR and can’t be bothered to change programs

here is a complete cheat sheet of vi commands worth learning:

  • i - make it behave like a normal program so you can type things
  • esc :wq - save and quit

after a few years i have upgraded my repertoire to include dd which deletes the whole line and saves me holding down backspace for 10 mins at a time

Sapozhnik
Jan 2, 2005

Nap Ghost
You must absolutely make your unit tests deterministic. So yeah hard code some plausible minimal test cases into your code. In situations where randomness is required your classes under test must take an RNG as a constructor param and you should supply an RNG that was initialized with a hard coded seed.

Definitely have test cases for edge cases like new year.

Seems like vat rates are a time series that requires a snapshot capability, so yeah build that whole time series service as a separate unit with its own separate unit tests. All else being equal you want your vat calculator (or anything else really) to have the data pushed to it instead of making it pull things.

Vat exemption, well, no universal answer for that. Maybe you want your calculator to take a TaxRegime interface and have a method on that interface that takes the invoice date and whatever other properties the tax man cares about. Then have a PrivateCustomerTaxRegime and a VatExemptRegime where the latter returns a zero tax rate for everything and have an upper layer locate a suitable tax regime given a Customer object. Then test that upper layer separately. Sounds like you have an Invoice object with an effective date, a list of line items, and your tax calc function takes an Invoice and a TaxRegime. Elsewhere you have some other function that locates a TaxRegime given a Customer which you can test separately, and some other thing above all that to execute all the steps of the process. Or maybe that is a poo poo design idk. I don't know what the entire requirements doc looks like.

So, push not pull where possible, think very hard about what your business logic should be a function of and cut the task into pieces accordingly, and let your testing plan inform your system design instead of the other way around.

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER


lol if you have to deal with time zones and/or any naive time really

get a library dude

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Sapozhnik posted:

let your testing plan inform your system design instead of the other way around.

This is really such a good point. The amount of headaches this saves is amazing.

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER


today in terrible programming: my boss said to me: "hey boiled can we remove the square brackets from the json output? yeah the ones demarking arrays, our scandi customers are having trouble parsing them"

:suicide:

CPColin
Sep 9, 2003

Big ol' smile.

Sapozhnik posted:

So, push not pull where possible...

I have to remind myself this all the time. I'll start fretting about how a function needs to call all these other functions to get the data it needs, then, after far too long, realize I should be passing in that data instead. Along the same lines, I'll stare at a blank screen for a while before realizing that I can just start with the most obvious piece and build from there.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Sapozhnik posted:

You must absolutely make your unit tests deterministic. So yeah hard code some plausible minimal test cases into your code. In situations where randomness is required your classes under test must take an RNG as a constructor param and you should supply an RNG that was initialized with a hard coded seed.

also to compound on this, if anything is time-based (now(), etc), make sure whatever functions you write let you pass in the current time, so you can test it. basically:

code:
interface Yospos {
  long calculateValueForToday(ZonedDateTime now);
  default long calculateValueForToday() {
    return calculateValueForToday(ZonedDateTime.now());
  }
}

Sapozhnik
Jan 2, 2005

Nap Ghost
Well in that specific case it may be better to pass a Clock, but of course it depends on the exact task at hand

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Sapozhnik posted:

Well in that specific case it may be better to pass a Clock, but of course it depends on the exact task at hand

well yeah, i was trying to simplify it.

MononcQc
May 29, 2007

This is where purity lessons from Haskell are interesting to borrow from. If code handles time, as much as possible make that pure. Whatever date or value to use, someone hands it to you.

If you have a file from which you read content, read the contents externally and only pass in the bytes/string/stream to whatever consumes it.

This makes it really easy to then test these components by passing them all the edge cases without needing to control the environment strictly, though you'll need some kind of higher-level view that deals and copes with all the side-effect injection.

It's not always realistic and working in all places, but there's often an interesting way to go about these things if you want to ease testing and analysis.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
best thing is that if you are writing with testing in mind, not only is it easier to test your code, it really enforces thinking about some design decisions that will improve your code in general.

you can also go overboard though: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

I'm the
LoopContextStateManipulation.java
LoopContextStateRetrieval.java
LoopPayloadExecution.java

LoopCondition.java
LoopContext.java
LoopFinalizer.java
LoopInitializer.java
LoopRunner.java
LoopStep.java

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
wow gitlab is just way better than bitbucket

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

MALE SHOEGAZE posted:

wow gitlab is just way better than bitbucket

I disagree. Gitlab's UI is consistently hard to read. It definitely has more features than bitbucket, but the bitbucket UI doesn't give me eyestrain trying to find the button or link that I need to do a thing. I dunno, part of my bias could be the fact that the bulk of my gitlab experience has been from the on prem gitlab our Russian contractors are using. Everything is English, but drat it's hard to look at compared to bitbucket or github.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
we use phabricator at work and i'll never go back

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost

CRIP EATIN BREAD posted:

we use phabricator at work and i'll never go back

phab is good as hell but they note right there on their front page that they use php so "even babies and dogs can contribute (with supervision)"

Stringent
Dec 22, 2004

The internet is the universal sewer.

gonadic io posted:

after a few years i have upgraded my repertoire to include dd which deletes the whole line and saves me holding down backspace for 10 mins at a time

watch it, that's how it gets you.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

bob dobbs is dead posted:

phab is good as hell but they note right there on their front page that they use php so "even babies and dogs can contribute (with supervision)"

for awhile on their site navigation bar there was a link just titled "pokemon" that just listed off different types of pokemon.

its a good piece of software.

tef
May 30, 2004

-> some l-system crap ->
learn ed and become better at vi

Adbot
ADBOT LOVES YOU

Soricidus
Oct 20, 2010
freedom-hating statist shill

Finster Dexter posted:

I dunno, part of my bias could be the fact that the bulk of my gitlab experience has been from the on prem gitlab our Russian contractors are using.

i didn't realise you wrote software for voting machines

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