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
Luigi Thirty
Apr 30, 2006

Emergency confection port.

Plorkyeran posted:

you're passing an array of points to something wanting a pointer to an array of points

oh i am literally retarded thanks

Adbot
ADBOT LOVES YOU

ErIog
Jul 11, 2001

:nsacloud:

Luigi Thirty posted:

working on my C++ dos toy thing. i have some routines set up to draw lines... I'm trying to feed an array of points into a general polygon drawing routine but pointers are driving me nuts as usual

code:
Point polygonPoints[] = {Point(50, 50), Point(80, 50), 
    Point(110, 50)};
Point *ptrPolygonPoints = polygonPoints;
draw_polygon(layer_background, ptrPolygonPoints, 3, 0x02);

void draw_polygon(char *framebuffer, Point *points[],
    int num_points, int color);
what dumb thing am i doing wrong here (besides writing a program targeting protected mode DOS using Watcom C++)

It's nice to see someone else get bitten by the array syntax leading to implicit pointers. It makes sense when you know what it's doing, but if you don't know then it just seems like the compiler is trolling you.

As you can see by the necessity of needing to pass the number of elements separately, C doesn't really have a fully-featured implementation of what you're probably used to thinking of as an array. Arrays in C are just pointers to 0-th element. So as far as C is concerned, a pointer to anything could be a pointer to a single item or it could be a pointer to an array of those type of items.

Bracket array notation is just syntactic sugar for doing the pointer arithmetic. It does so implicitly, though. So when you say points[1], it's doing the pointer math to find the address, and then dereferencing the resulting pointer for you. This is why when you want to pass the actual address of a specific index you have to say &points[index].

So your Point* points[] in your function declaration is saying you want a pointer to the 0-th element of an array of Point type. That's why the compiler is saying your function is requesting a Point**(pointer to a pointer). The pointer part is implicitly being done for you already when you said "points[]" because you used the brackets. So if you drop the brackets or drop the star then it should work fine.

You can do neat(or dangerous) stuff with it sometimes like if you wanted to chop off the first 3 chars of a null-terminated ASCII string before printing it you can just say printf("%s", &string[3]) without actually needing to munge the string. Since printf takes a pointer the same way anything that's expecting an array does, it doesn't care that the address of the 3rd element isn't actually the 0-th element.

efb, but hopefully my explanation is helpful for avoiding future problems.

ErIog fucked around with this message at 01:41 on May 24, 2016

GameCube
Nov 21, 2006

kalstrams posted:

yea i cant find anything better both in price and length so getting this, as i doubt id read 400 page tdd book about python

hope its good, i just linked it cuz the guy was a guest on another python podcast and seemed smart :shobon:

GameCube
Nov 21, 2006

hmm judging by the table of contents it's more about how to use specific python testing frameworks than about, like, the concepts of unit testing. my "Critical Hit" is more of an "Epic Fail"! lol!

Luigi Thirty
Apr 30, 2006

Emergency confection port.



yay i'm smart again and i can draw shapes on a VGA framebuffer

quiggy
Aug 7, 2010

[in Russian] Oof.


Luigi Thirty posted:



yay i'm smart again and i can draw shapes on a VGA framebuffer

that's pretty rad. you following a guide or using some special library or what?

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Notorious QIG posted:

that's pretty rad. you following a guide or using some special library or what?

nope i'm working it out as i go

i downloaded the font from some asset library and looked at some other source code to work out how to get a 240Hz timer going but other than that it's just google and old documentation

Brain Candy
May 18, 2006

GameCube posted:

whats up you idiots. how do i write good unit tests and make it easy for people to write their own loving unit tests instead of making me do it. what's a good book, or maybe blog. help me out here. come on.

don't

before you do traditional unit tests you should try

* exhausitive testing

pick a property like 'all apples are green' and examine all the apples. try all the things. 65000 items? test them all. four million things? test them all. computers are fast, edge cases are hard, don't think if you can avoid it

* property-based testing - a.k.a. quickcheck after a haskell library

sometimes you are dealing with 8 billion things. or 8 billion things cubed so testesting them all isn't going to happen. instead you throw random input at your functions

both of these operate under the assumption that you are bad at figuring out where your code will break. this is probably true! otherwise you would have already fixed it

you can get part of this effect by having a more senior person write the unit tests, but this is boring for the senior and maddening for the junior and i don't recommend it

this only works with things that can be cobbled into effectly pure functions; you don't want to be testing how often the stars align. traditional unit testing has similar problems, but usually also comes with frameworks with well-defined setup and tear downs to manage state. sometimes this means every test gets its own process! expect weirdness in load ordering and resource allocation

there is a place for traditional unit tests, in that you can take the tests that you'd traditionally put into mains and put them into unit tests instead. this is also known as smoke testing. it's fine to check these tests in since it lets everyone know that the code actually does something and also provides a working example

if you find that you are writting the same tests over and over, figure out how to write less code! most of the time this means abstracting the thing you are doing and testing that

if you hear 'code coverage', you know that somebody wants to chase a bonus/dopamine by making numbers go up. code coverage is the delusion that percentage of lines that are executed during your test has any predictive power. instead, you should think of how much of the state space is tested; how many of the configurations of all of the possible arguments and all relevant accessible states are run through your tests. it only takes two 32-bit integer argument for this count to be larger this number of grains of sand on the earth, where a traditional unit test probably goes through five of them.

this combinatorial explosion should convince you that before you start to test iyou should reduce the state space as much as you can. you do this by making pure functions with no side effects, by reducing access to global state, in general by prefering simple things to easy things

testing is a thing that you do with other people if you work with other people. if you start testing, your good tests can silently become bad because the code under test became more complex. you need to yell at people when they make things more complicated

tests happen automatically or they will never be run. failing tests break the build and breaking the build needs to addressed right away.

one way to test your tests automatically is to do mutation testing. this is where you automatically mutate the code under test and see how well your tests deal with the world going insane. here failing tests are good tests, since that means your tests match the assumptions in your code

but even then testing your assumptions is not the same thing as testing for errors. use testing as a tool to check if you are wrong, not to assure you that you are are right

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


i was under the impression that property-based testing was a form of unit testing, but i guess not (i'm still getting used to TDD)

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?
code:

public int isOdd(int num){
     while(num%2!=0) return 0;
     return 1;}

this person desperately needs to be introduced to the "right margin river-of-punctuation" idea

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?

Luigi Thirty posted:

nope i'm working it out as i go

i downloaded the font from some asset library and looked at some other source code to work out how to get a 240Hz timer going but other than that it's just google and old documentation

have you seen the Graphics Programming Black Book? it'll be right up your alley and it's all free.

Bloody
Mar 3, 2013

what is property based testing

JawnV6
Jul 4, 2004

So hot ...

Brain Candy posted:

sometimes you are dealing with 8 billion things. or 8 billion things cubed so testesting them all isn't going to happen. instead you throw random input at your functions

both of these operate under the assumption that you are bad at figuring out where your code will break. this is probably true! otherwise you would have already fixed it
is "directed random testing" used outside ASICs? the idea is to take test content and randomize chunks of it, picking and choosing where to add randomness. you're still picking a part of an intractable state space and searching "close by," but it's better than running the same precise test case

also i know everyone's on pins and needles about my job hunt: first on-site interview is this wednesday

Brain Candy
May 18, 2006

Bloody posted:

what is property based testing

testing by logical properties

"all humans have two legs" is a property
"humans don't have more than two legs" is a property

you could test either by examining all people. this is exhaustive testing. you are almost certain when you are done

you could test either by examining a thousand people. this is property based testing. you are asymptotically sure

traditional unit testing is where you test the same five people over and over again

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?

JawnV6 posted:

also i know everyone's on pins and needles about my job hunt: first on-site interview is this wednesday

congrats!

Brain Candy
May 18, 2006

JawnV6 posted:

is "directed random testing" used outside ASICs? the idea is to take test content and randomize chunks of it, picking and choosing where to add randomness. you're still picking a part of an intractable state space and searching "close by," but it's better than running the same precise test case

also i know everyone's on pins and needles about my job hunt: first on-site interview is this wednesday

modern mutation testing to test your tests does this by homing in on any branches it can identify:

code:
//Ah hah! Better throw a case where i > 3 and i = 3 in there!
if (i < 3) {
  //... 
}

quiggy
Aug 7, 2010

[in Russian] Oof.


Luigi Thirty posted:

nope i'm working it out as i go

i downloaded the font from some asset library and looked at some other source code to work out how to get a 240Hz timer going but other than that it's just google and old documentation

neat :)

Bloody
Mar 3, 2013

JawnV6 posted:

is "directed random testing" used outside ASICs? the idea is to take test content and randomize chunks of it, picking and choosing where to add randomness. you're still picking a part of an intractable state space and searching "close by," but it's better than running the same precise test case

also i know everyone's on pins and needles about my job hunt: first on-site interview is this wednesday

there is some insanely cool testing tools in that direction like American fuzzy lop (the fuzzer not the bun)

Progressive JPEG
Feb 19, 2003

LeftistMuslimObama posted:

i'm not advocating writing a 40-line chain of if-then-else-else-else or whatever, but this guy is pathological to the point that he will not write the word "if", even when the thing he's doing is literally
code:
if (condition) return <value>;
[else] return <other value>
he'll instead do
code:
while(condition){
return value;}
return <other value>:
he will still do that as a while loop, or a crazy one-case switch statement with a default case as the else, etc. in code that will very clearly never be revised in a way that would require extensibility of the conditional. it's crazy.

troll him by making a script that replaces his boilerplate garbage with if statements

Progressive JPEG
Feb 19, 2003

Bloody posted:

interacting with a piece of hardware to update the state of some hardware connected to that hardware then reading back the state of that hardware to see if it matches what was set

there are A Lot of possible failure points in this path and a lot of room for heisenbugs

yeah at 93% it sounds like a race

quiggy
Aug 7, 2010

[in Russian] Oof.


Progressive JPEG posted:

troll him by making a script that replaces his boilerplate garbage with if statements

#define while if

:downs:

ErIog
Jul 11, 2001

:nsacloud:

Progressive JPEG posted:

troll him by making a script that replaces his boilerplate garbage with if statements

I'm not like a Good Programmer, but isn't the compiler already doing that?

It seems like unless he's trying to deliberately obfuscate what he's doing then shouldn't his compiled code end up looking nearly the same as if he had just used an if statement?

ErIog fucked around with this message at 04:01 on May 24, 2016

Bloody
Mar 3, 2013

Progressive JPEG posted:

yeah at 93% it sounds like a race

i was about to start enumerating possible origins of a ~7% failure rate bug in our system and literally the first piece of math i did involving the backpressure mechanism in a parallel-to-serial block gave a 1-in-18 5.6% error rate which is probably within the error margin of my tests and i bet i know at least where to start ripping poo poo apart. boy i love digital design

Bloody
Mar 3, 2013

bespoke artisanal serial protocols are absolutely miserable btw

JawnV6
Jul 4, 2004

So hot ...

eschaton posted:

congrats!
tyvm!

Progressive JPEG posted:

yeah at 93% it sounds like a race
nah, for a pure digital failure it's likely a race but especially with a serial protocol i'd check if either side detected a bit error and oh my, window open for a while

Progressive JPEG
Feb 19, 2003

JawnV6 posted:

nah, for a pure digital failure it's likely a race but especially with a serial protocol i'd check if either side detected a bit error and oh my, window open for a while

oh yeah i havent done much hardware stuff outside of firstjob

ps grats :)

Luigi Thirty
Apr 30, 2006

Emergency confection port.

eschaton posted:

have you seen the Graphics Programming Black Book? it'll be right up your alley and it's all free.

neato

there's just something cool about working out the best way to shovel pixels around in a 64kb frame buffer or optimize a string search that you don't get writing dumb Java business software at work

or in my case spend an hour banging my head against Watcom trying to figure out how to turn a string of |-delimited integers I'm reading from a file into my Point objects

Luigi Thirty fucked around with this message at 04:51 on May 24, 2016

Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Luigi Thirty posted:

nope i'm working it out as i go

i downloaded the font from some asset library and looked at some other source code to work out how to get a 240Hz timer going but other than that it's just google and old documentation

PC Game Programmer's Encyclopedia

It's what I used when I had a DOS/Windows 3.1 machine and wanted to make games.

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?

Progressive JPEG posted:

gaslight him by making a commit hook that replaces his boilerplate garbage with if statements

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?

Notorious QIG posted:

#define while if

:downs:

a friend had this in his .signature for a long time:

#define struct union /* space saver */

cinci zoo sniper
Mar 15, 2013




GameCube posted:

hope its good, i just linked it cuz the guy was a guest on another python podcast and seemed smart :shobon:
It's concise and written in Simple English, and primarily talks about practical matters, so works for me

Progressive JPEG
Feb 19, 2003

cinci zoo sniper
Mar 15, 2013




GameCube posted:

hmm judging by the table of contents it's more about how to use specific python testing frameworks than about, like, the concepts of unit testing. my "Critical Hit" is more of an "Epic Fail"! lol!

nah, the concepts beyond "test every X" are needless circlejerkery for me

suffix
Jul 27, 2013

Wheeee!
unit testing as a field seems to be chock full of pointless dogma

"avoid (thing that works perfectly well) at all costs! you should rewrite all your legacy code to follow the POOP principle where you contort all your code to avoid fnorbed methods"

cinci zoo sniper
Mar 15, 2013




suffix posted:

unit testing as a field seems to be chock full of pointless dogma

"avoid (thing that works perfectly well) at all costs! you should rewrite all your legacy code to follow the POOP principle where you contort all your code to avoid fnorbed methods"
isnt that everywhere though?

what, you app startup doesnt use neo-randian functionally imperative narrative driven agile testless development?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
so what is the reasoning behind "never write if" in code?

i understand trying to minimize the number of branches, so the code is easier to reason about, but never writing ifs ever? or never writing ifs speficifally, but switches and ?: being ok?

i did do a coding excercise like that once, and it was pretty fun as a challenge

cinci zoo sniper
Mar 15, 2013




Wheany posted:

so what is the reasoning behind "never write if" in code?

i understand trying to minimize the number of branches, so the code is easier to reason about, but never writing ifs ever? or never writing ifs speficifally, but switches and ?: being ok?

i did do a coding excercise like that once, and it was pretty fun as a challenge
https://www.se.rit.edu/~tabeec/RIT_441/Resources_files/How%20To%20Write%20Unmaintainable%20Code.pdf

Progressive JPEG
Feb 19, 2003

ive been using avro as a serialization format for some one-way record streaming stuff and its worked out p well. avro's nice for streaming because the spec defines a framing format so you dont have to invent your own every time. seriously why didnt protobuf at least define some kind of convention for like a size header to use when dealing with a list of multiple adjacent records, it could've just been '8 bits of magic followed by 24 bits of size' and itd have been plenty; lol at anyone with a 16mb proto message. also the avro schema can either be provided up-front with the data or in a separate channel, making the data fully self-describing, while the records themselves have little overhead since any decoding fully depends on the contents of the provided schema

avro specifies its own socket protocol too, but afaict the only existing implementation of that, even among all the first party libs, only exists in the java lib, which sorta makes sense given the hadoop lineage. but im intending to support 4-5 or so different langs (which all do have good 1st-party or 3rd-party serialization implementations) and i dont want to require more diying than necessary for users of the interface

so for the streaming over a socket part i ended up just going with 'send the data as avro object file format over a tcp session, and if the receiver doesn't like something it closes the socket, at which point the sender should get its poo poo together and attempt to reconnect/resume where it left off'. unlike the socket protocol this file format is pretty widely supported, and easy to diy given a serialization lib if it isnt. this 'protocol' isnt super robust in non-hiccup cases (eg say the receiver/sender are completely incompatible somehow, or say the sender is configured with the wrong port entirely and should stop sending to the wrong endpoint) but this is just for sending over localhost anyway so close enough. also the cool part of using a plain standard format over plain tcp is that it means i can test things by just using nc to send/recv data directly, and the files themselves have a bunch of tools thatll operate against them directly too

anyway if you got a bunch of structured data to move around and/or store in a consistently standardized format then avro might be right for you

JawnV6
Jul 4, 2004

So hot ...

Wheany posted:

i understand trying to minimize the number of branches, so the code is easier to reason about, but never writing ifs ever? or never writing ifs speficifally, but switches and ?: being ok?
wouldn't ternary map to cmov for available widths?

e: like 20 minutes of messing around and gcc optimizes ternaries comparing structs as well as simple values into cmov, although it does have to copy the struct members around after figuring out the pointer to it https://godbolt.org/g/uQtFTN arm w/ gcc is branching w/ an ite, not sure if that's cheaper than a real branch

Adbot
ADBOT LOVES YOU

cinci zoo sniper
Mar 15, 2013




whoa i was sitting on some poo poo rear end old anaconda apparently, its all cloud and poo poo in this version i just set up

  • Locked thread