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

MALE SHOEGAZE posted:

^^ once twice refactor is such a good rule of thumb.


i don't have good resources, unfortunately, but maybe this will help you figure out what to look for:

professional code, in the domain we're discussing, is all about writing code that can be easily evolved, maintained, and tested. additionally, it's about learning how make changes that are easily evolved, maintainable, and testable to a legacy application that is none of the above.

it's really hard to learn how to do this stuff without actually doing it, mostly because it's loving tedious and no one wants to write a tutorial that involves digging through a 400k LoC legacy enterprise app to figure out where you can safely graft in some feature.

personally, i've found the functional approach incredibly useful to me throughout my career. i dabbled in haskell very early in my programming development, and while i remember little to nothing about haskell, a few of the functional concepts stuck with me and i think they helped me a lot, even when i was working on a terrible rails app. there are very few places where you can't escape from some stateful context into a pure function.

but you also probably need to learn standard OOP and MVC.

this is a good post. learning new languages is good (even if they’re not widely used for real work), learning industry standard methodologies is good (even if yospos rightly sneers at them)

basically imo if you’re learning something then you’re doing it right. learn Haskell, learn x86 asm, learn spring or asp mvc, it will all help your brain develop in useful ways. the genuinely terrible programmers are the ones who learn to do exactly one thing and then try to rely on that their whole career.

Adbot
ADBOT LOVES YOU

floatman
Mar 17, 2009
You could also join a lovely company and work on their legacy app, giving you a treasure trove of study material on how NOT to write and structure software, with the benefit of this aforementioned trove growing everyday

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
going through the Design Patterns book as a p-langer is very masochistic imo, I'd save that for later, preferably after you at least dabbled into java a bit.

Sapozhnik
Jan 2, 2005

Nap Ghost

cheque_some posted:

What would you recommend for someone who is a self-taught terrible devopsing p-langing programmer but want to become a non-terrible programmer


at the point where I can make a CRUD (more like cruddy) program, that does what I want it to, but how do I get to the point where it's something professional grade. like how do you learn how to architect programs and when to use a lookup table instead of just a bunch of if-statements, and architect using different controllers instead of all just in one main, and optimized code, and all that other stuff. It seems like there's tons of 'learn to program' sites like codeacademy and all that, but they never go beyond loops and if statements and arrays.

Are there any books or sites that teach you how to go from beginning to intermediate level?

make a bunch of mistakes then think about and research ways to fix them. and do the actual fixing part as well ofc

gonadic io
Feb 16, 2011

>>=
ctps: adding a field to device telemetry here requires 7 different pull requests and deployments. Each service/pipeline has a different enrichment process and so it's own data schema (and half of them use different data transport technologies).

It's taken me a week to add a "butts": true to messages.

What's a not poo poo way of doing this? Everyone at work is adamant that each of the stages is unavoidable complexity and totally needs to exist

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

MALE SHOEGAZE posted:

personally, i've found the functional approach incredibly useful to me throughout my career. i dabbled in haskell very early in my programming development, and while i remember little to nothing about haskell, a few of the functional concepts stuck with me and i think they helped me a lot, even when i was working on a terrible rails app. there are very few places where you can't escape from some stateful context into a pure function.

but you also probably need to learn standard OOP and MVC.

this, a hundred times this.

you don't need to be purely functional, but if you have stuff with side effects that populates values which are SOMETIMES needed, I will loving berate a coworker about this kind of thing to no end.

This stuff drives me mad:

code:
// this throws an exception! why?
Foo x = getFoo();
Result result = calculateValues(x);

// well you forgot to populate the missing fields first!
Foo x = getFoo();
enrichFoo(x);
Result result = calculateValues(x);
is it really so hard to do:

code:
Foo x = getFoo();
EnrichedFoo y = enrichFoo(x);
Result result = calculateValues(y);
even worse is things like:

code:
Foo x = fooService.getById(1);
Foo y = fooService.getByName("abc");
where both methods return the same type (and same represented value) but one of them has certain fields populated and the other one doesn't, with no indication at all what the difference is.

Xarn
Jun 26, 2015
:murder:

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
a couple of online courses that made a huge impression on me:

CS212 Design of Computer Programs by Peter Norvig is probably my favorite course ever. it's kind of a unique course on algorithms/data structures but a lot more pragmatic.

he also introduces a lot of design patterns in a sneaky way, if you plan to really get into that it'll definitely help to already have the general intuition that Norvig gives you here.

if that's a heavy course to you maybe give it a pause and try CS101 Intro to Computer Science, it's a way more basic course but it touches on a lot of intermediate topics that you may not be familiar with.


Programming Languages by Dan Grossman is a great intro to PLT. It's about learning 3 languages and their key ideas (SML, Racket and Ruby). it forces you to think about a lot of stuff you never really think about in introductory p-lang courses (typing, mutability, scoping, dispatch etc)

compared to CS212 this is hella formal and academic so it may or may not be your cup of tea. Starting with SML may be a huge shock but is totally worth it. I really like this course better than just learning just one fp language in isolation because it puts other paradigms side by side to give you a better perspective.

Symbolic Butt fucked around with this message at 16:52 on Aug 18, 2018

redleader
Aug 18, 2005

Engage according to operational parameters

floatman posted:

You could also join a lovely company and work on their legacy app, giving you a treasure trove of study material on how NOT to write and structure software, with the benefit of this aforementioned trove growing everyday

yes, you will learn a lot. but you will need a good work environment + coworkers to stop you from wanting to take a long walk off a short pier, and if you do it too long your brain ends up broken

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
now someone should post about SICP and the smart dog book and we're cool

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
oh another like, super duper important thing: learning to write unit testable code. this is maybe the most important skill to have for your average CRUD app developer. it's a huge topic that i certainly cannot do justice but the takeaway is: write code in a way that makes it easy to unit test. now you have tests, and also it turns out that most methods for writing unit testable code are also good practices in general.

i'm not sure of a good resource for unit testing though as i've picked all of this up on the job. perhaps someone else has a good rec.

also before i start a derail i'm not saying unit testing is the only kind of testing you should do but it's the best place to start learning how to test.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
also this is a good thread for asking questions. feel free to come by and ask as many questions as you want. this thread and others on SA have been invaluable to me and have helped me develop from a terrible programmer who didn't even know what questions to ask to an okay programmer making money. also i've developed a real passion for programming, it's great most of the time.

DONT THREAD ON ME fucked around with this message at 12:36 on Aug 13, 2018

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
i miss writing code and am srsly thinking about going back to being an ic even though management has sweet rear end perks

my new dog
May 7, 2007

by Nyc_Tattoo

MALE SHOEGAZE posted:

good news: we’re here to help with both problems

ah gently caress

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

what's a unit test

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 14 hours!

Captain Foo posted:

what's a unit test

A miserable pile of false passes.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Ah, functional programming. The veganism of computers.

raminasi
Jan 25, 2005

a last drink with no ice

MALE SHOEGAZE posted:

oh another like, super duper important thing: learning to write unit testable code. this is maybe the most important skill to have for your average CRUD app developer. it's a huge topic that i certainly cannot do justice but the takeaway is: write code in a way that makes it easy to unit test. now you have tests, and also it turns out that most methods for writing unit testable code are also good practices in general.

i'm not sure of a good resource for unit testing though as i've picked all of this up on the job. perhaps someone else has a good rec.

also before i start a derail i'm not saying unit testing is the only kind of testing you should do but it's the best place to start learning how to test.

The Art Of Unit Testing is really, really good

JawnV6
Jul 4, 2004

So hot ...

Phobeste posted:

it's just loving tedious and easy to screw up and still has a similarly abstracted machine model as c. you don't think about cache in x86 assembler, usually. you're still dealing with virtual memory. the only difference is it it's now a massive pain to do any flow control and it's a massive pain to deal with types above machine word size. hooray

contrariwise, when i have to think about caches it's time for asm

Soricidus
Oct 21, 2010
freedom-hating statist shill
one good reason to learn asm imo is that it forces you to think about how your code is structured, because careless or poorly documented code becomes unmaintainable after a few dozen lines of code at most, whereas in a higher level language you can get away with hundreds or even thousands of lines of bad code and still be able to work with it

you almost certainly shouldn’t be using asm for anything real (unless you’re working in some very specific domains), but it’s a nice didactic tool

Bloody
Mar 3, 2013

gonadic io posted:

ctps: adding a field to device telemetry here requires 7 different pull requests and deployments. Each service/pipeline has a different enrichment process and so it's own data schema (and half of them use different data transport technologies).

It's taken me a week to add a "butts": true to messages.

What's a not poo poo way of doing this? Everyone at work is adamant that each of the stages is unavoidable complexity and totally needs to exist

I can do it in one except it silently breaks a subset of the consumers and there's no way to know in advance which consumers are liable to break

NihilCredo
Jun 6, 2011

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

raminasi posted:

The Art Of Unit Testing is really, really good

i skimmed it. it's probably a decent introduction if you've never heard of unit testing at all. but otherwise, it's yet another loving unit testing book that tells me in excruciating detail how to test string parsers and arithmetic operations. yawn.

assert.equals(two.plus(two), 4)? thanks dude, would never have figured out how to write that. wait, why are you talking to me about mocks and stubs and testing stubs against mocks now*? what do i need those things for?

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?

(btw, at one point TAoUT literally shows a test that defines a mock, tells the mock what a certain method should return, then asserts that the method returns that value. no non-mock code appears in the test at all.)

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

NihilCredo posted:

(btw, at one point TAoUT literally shows a test that defines a mock, tells the mock what a certain method should return, then asserts that the method returns that value. no non-mock code appears in the test at all.)

Sounds great! I want my codebase to have 110% coverage!

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost

NihilCredo posted:

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?


i read 7 unit testing books so far and haven't found one that does that. seconding the request

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

bob dobbs is dead posted:

i read 7 unit testing books so far and haven't found one that does that. seconding the request

it was already linked in this thread

CPColin
Sep 9, 2003

Big ol' smile.
The emulator101 bug has bitten me too, but I'm doing it in Ceylon and adding tests because I'm a weirdo.

I started with an Opcode enum that I was piling everything into—byte value, size, mnemonic, parameter mnemonic—before I realized that was stupid and put only what both the disassembler and the emulator needed to know in there: byte value and size.

I made that realization when I was about to stuff the code that does the emulation into the enum, which was way too late to figure that out.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

CPColin posted:

The emulator101 bug has bitten me too, but I'm doing it in Ceylon and adding tests because I'm a weirdo.

I started with an Opcode enum that I was piling everything into—byte value, size, mnemonic, parameter mnemonic—before I realized that was stupid and put only what both the disassembler and the emulator needed to know in there: byte value and size.

I made that realization when I was about to stuff the code that does the emulation into the enum, which was way too late to figure that out.

haha i did almost exactly the same thing.

now i'm actually implementing the instructions and i just refactored my runloop. now my jmp test is broken and i'm not sure why. i'm definitely advancing the pc when i shouldn't, or i'm not advancing it. one or the other.

e: ugh it was because i apparently deleted the part of jmp where i set the pc to the offset.

DONT THREAD ON ME fucked around with this message at 22:50 on Aug 13, 2018

toiletbrush
May 17, 2010
Same here, but Swift.

I started with the disassembler but was frustrated by all the repetition and went through three or four different ways of breaking down the instruction set until I finally ended up with one I liked, and started writing the execution part along side to make sure it would actually work.

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, so rather than coding MOV 63 times you just have one bit of code that knows how to decode the registers. Now instead of a switch statement I've just got a cached lookup into a much smaller set of structs that each know how to disassemble or emulate a family of instruction, which nicely handles instructions with varying timing too.

The only bit that is a bit poo poo is the bit that holds the current 'in flight' instruction across ticks so it doesn't change cpu state until the right number of ticks have elapsed. I don't even know if that's how it should do it?

CPColin
Sep 9, 2003

Big ol' smile.

MALE SHOEGAZE posted:

haha i did almost exactly the same thing.

now i'm actually implementing the instructions and i just refactored my runloop. now my jmp test is broken and i'm not sure why. i'm definitely advancing the pc when i shouldn't, or i'm not advancing it. one or the other.

e: ugh it was because i apparently deleted the part of jmp where i set the pc to the offset.

I couldn't figure out why the emulator wasn't getting anywhere until I realized that when you RET from a CALL, you're supposed to end up with the program counter pointing at the instruction after the CALL, not back at the CALL again. Whee!

toiletbrush posted:

The only bit that is a bit poo poo is the bit that holds the current 'in flight' instruction across ticks so it doesn't change cpu state until the right number of ticks have elapsed. I don't even know if that's how it should do it?

I haven't even tried to deal with that part yet, but I made my State class immutable and my emulate() function return the new state along with the number of cycles the instruction will/would take. I figure I'll delay applying the new state until the right number of cycles have passed, or something. I haven't really sorted through how I'll deal with emulating the processor speed and the interrupts yet.

Powerful Two-Hander
Mar 10, 2004

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


Captain Foo posted:

what's a unit test

if you find out can you let our devs know tia

edit: also me because as per the above i pretty much learned what i know by going through then eventually refactoring our code base which has......zero tests.

Powerful Two-Hander fucked around with this message at 23:38 on Aug 13, 2018

Hunter2 Thompson
Feb 3, 2005

Ramrod XTreme
echoing that, i never learned really learned how to do testing beyond test as you go incremental development, certainly nothing part of a build process

the last job i had paid somebody else to write/regularly run test suites against the running embedded system so we had some kind of testing, but i wasn't very involved

Soricidus
Oct 21, 2010
freedom-hating statist shill

Captain Foo posted:

what's a unit test

code:
@Test
public void unit()
{
    assertEquals(1, this.length);
}

floatman
Mar 17, 2009
I'm amazed at the other pl thread that actually has the embarrassment of riches to actually argue about what type of unit tests is good, while here I am struggling for scraps with this pos test suite that takes 9 hours to run, but don't worry guys we got, "ideas to fix them!"

I literally just saw a test that performed a bunch of loving asserts, then the last line of the test was markTestSkipped(). When I comment out the last line it's actually a passing test. What the gently caress was that Dev on when it was marked as skipped I want some of that too to ease my pain

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

floatman posted:

I'm amazed at the other pl thread that actually has the embarrassment of riches to actually argue about what type of unit tests is good, while here I am struggling for scraps with this pos test suite that takes 9 hours to run, but don't worry guys we got, "ideas to fix them!"

I literally just saw a test that performed a bunch of loving asserts, then the last line of the test was markTestSkipped(). When I comment out the last line it's actually a passing test. What the gently caress was that Dev on when it was marked as skipped I want some of that too to ease my pain

it could be (or was) a flappy test. Did you run it again? Flappy tests (tests that alternatively succeed and fail) can be really hard to debug if your test fixtures were engineered badly.

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.
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)

qntm
Jun 17, 2009

Finster Dexter posted:

it could be (or was) a flappy test. Did you run it again? Flappy tests (tests that alternatively succeed and fail) can be really hard to debug if your test fixtures were engineered badly.

Did I ever mention the time I discovered that our integration tests were intentionally using alternating auth methods depending on whether the day of the month was odd or even

MononcQc
May 29, 2007

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?

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?

qntm
Jun 17, 2009
correctly computing and adjusting VAT rate information sounds more like a domain knowledge/architecture question...?

MononcQc
May 29, 2007

I mean there's many ways you can test them, but it comes closer to "integration" since if the VAT is 'take current snapshot then mutate but the invoice is unchanged' arguably may depend on a component having to control current VAT (or a per-date historic table), and one handling the invoices themselves. So to check the interaction (or lack thereof) between both components, I'd imagine this stuff would not initially fit well under unit tests.

But if you wanted to unit test it, you gotta isolate everything to ignore the filesystem, network, and other components, you could use a mock; first call has a reported current VAT at say 10%, second call 11%, 12%, and so on. Make sure that the value you have on the invoice is at a given % value; call the mock to read/change the value so it should be higher. Check on the invoice again and ensure the invoice was unchanged. That shows the isolation between current rate and rate-at-invoice-time. Anyway that would be the simple way to go without caring too much about whether it's clean or not.

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!"

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...

toiletbrush posted:

The only bit that is a bit poo poo is the bit that holds the current 'in flight' instruction across ticks so it doesn't change cpu state until the right number of ticks have elapsed. I don't even know if that's how it should do it?

the way y'all are describing pipelining is really strange, can't wrap my head around it

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