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
Powerful Two-Hander
Mar 10, 2004

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


Luigi Thirty posted:

folks, I bring you this thing that appeared on my twitter timeline

visual mumps for the Apple IIgs

https://twitter.com/AndiarSoftware/status/1103283584113262597

huh I thought vaccines protected against mumps yet here we are in yospos talking about mu.... Oh wait no I see now.

Adbot
ADBOT LOVES YOU

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:

folks, I bring you this thing that appeared on my twitter timeline

visual mumps for the Apple IIgs

https://twitter.com/AndiarSoftware/status/1103283584113262597

cursed IDE

pls share your Atari TT stories with us

Luigi Thirty
Apr 30, 2006

Emergency confection port.

eschaton posted:

cursed IDE

pls share your Atari TT stories with us

I'm writing a mastodon client in C++ targeting m68k-atari-mint atm

it's only 206kb so far!

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Currently: it can make calls to the accounts API, parse the result, and display a couple strings lol

https://twitter.com/LuigiThirty/status/1103539212312293379

Corla Plankun
May 8, 2007

improve the lives of everyone

Luigi Thirty posted:

Currently: it can make calls to the accounts API, parse the result, and display a couple strings lol

https://twitter.com/LuigiThirty/status/1103539212312293379

:krad:

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



how do i get at a method/function's arguments in a way where i can fall back from **kwargs to *args? i have this decorator:

code:
def blahblah(key: str):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            self = args[0] ## works fine, points to instance of Something
            fileid = kwargs.get('fileid', args[1]) ## IndexError: tuple index out of range
            # here i wanna do some things with key + self + fileid before going to the wrapped method
            return func(*args, **kwargs)
        return wrapper
    return decorator


class Something(object):
    @blahblah('doy')
    def a(fileid, foo, bar):
        pass

    @blahblah('hubba')
    def b(fileid, zoom, pow):
        pass

s = Something()
s.a(fileid='blah', foo=1, bar=2)
s.b(fileid='blah', zoom=3, pow=4)
s.a('blah', 5, 6)
s.b('blah', 7, 8)
i want the a/b methods to be callable with both fileid as a named or an unnamed argument, but args[1] above fails even though it should only be called if 'fileid' not in kwargs...?

Carthag Tuek fucked around with this message at 13:59 on Mar 8, 2019

Volte
Oct 4, 2004

woosh woosh
args[1] has to be evaluated in order to even call kwargs.get with it as an argument - it's not short circuited.
code:
fileid = kwargs.get('fileid')
if fileid is None:
  fileid = args[1]

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



ahh thanks, that makes sense :)

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



it works! wrote up a little helper for it :cool:

code:
def get_arg(args, kwargs, name, index):
    val = kwargs.get(name, None)
    if val is None:
        val = args[index]
    return val

fileid = get_arg(args, kwargs, 'fileid', 1)

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



this is probably more robust re possible "None" arguments

code:
def get_arg(args, kwargs, name, index):
    if name in kwargs:
        return kwargs[name]
    else:
        return args[index]

FlapYoJacks
Feb 12, 2009

Krankenstyle posted:

this is probably more robust re possible "None" arguments

code:
def get_arg(args, kwargs, name, index):
    if name in kwargs:
        return kwargs[name]
    else:
        return args[index]

You don't need that else though?

Edit:

code:
def get_arg(args, kwargs, name, index):
    if name in kwargs:
        return kwargs[name]
    return args[index]
Works just fine. :colbert:

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



right :doh:

also i considered going

code:
return kwargs[name] if name in kwargs else args[index]
but im not a huge fan of pythons dumbass lack of ternary operator, i mean this is just ugly

Carthag Tuek fucked around with this message at 16:59 on Mar 8, 2019

kalel
Jun 19, 2012

ratbert90 posted:

You don't need that else though?

:jerkbag:

FlapYoJacks
Feb 12, 2009

Krankenstyle posted:

right :doh:

also i considered going

code:
return kwargs[name] if name in kwargs else args[index]
but im not a huge fan of pythons dumbass lack of ternary operator, i mean this is just ugly

* Rushes in with heavy breathing * HAVE YOU SEEN PYTHONS LIST COMPREHENSION?!?!?!


It's unnecessary and stupid. :colbert:

kalel
Jun 19, 2012

semicolons are unnecessary in javascript but I still use them like a good boy scout :angel:

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



lol at all the code golf-y alternatives here:
https://en.wikipedia.org/wiki/%3F:#Python

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



ratbert90 posted:

* Rushes in with heavy breathing * HAVE YOU SEEN PYTHONS LIST COMPREHENSION?!?!?!

one of them is actually a tuple with an index (because true/false evaluate to 1/0): (args[index], kwargs[name])[name in kwargs] :barf:

cinci zoo sniper
Mar 15, 2013




Krankenstyle posted:

this is probably more robust re possible "None" arguments

code:
def get_arg(args, kwargs, name, index):
    if name in kwargs:
        return kwargs[name]
    else:
        return args[index]

what you want is

code:
def get_arg(args, kwargs, name, index):
    if kwargs:
        return kwargs.get(name) if kwargs.get(name) is not None else args[index]
    return args[index]
"if name in kwargs" will throw attributerror if kwargs is none

cinci zoo sniper fucked around with this message at 17:13 on Mar 8, 2019

cinci zoo sniper
Mar 15, 2013




3 notes:

this is going to get ugly if it is permissible for a kwarg value to be None
if you have imbalanced input data (e.g. majority of kwargs is like this or like that) then its better to rewrite this via try/except
if you can guaranteed that all kwargs values will be truthy then you can reduce "is not None" to basic truthiness check

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

SciFiDownBeat posted:

semicolons are unnecessary in javascript but I still use them like a good boy scout :angel:

iirc there are some really weird gotchas if you don't use semicolons so it's not a bad habit really

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



cinci zoo sniper posted:

what you want is

code:
def get_arg(args, kwargs, name, index):
    if kwargs:
        return kwargs.get(name) if kwargs.get(name) is not None else args[index]
    return args[index]
"if name in kwargs" will throw attributerror if kwargs is none

wouldnt this work just as well then?

code:
def get_arg(args, kwargs, name, index):
    if kwargs and name in kwargs:
        return kwargs[name]
    return args[index]

Aramoro
Jun 1, 2012




Symbolic Butt posted:

iirc there are some really weird gotchas

fixed for all of JavaScript.

cinci zoo sniper
Mar 15, 2013




Krankenstyle posted:

wouldnt this work just as well then?

code:
def get_arg(args, kwargs, name, index):
    if kwargs and name in kwargs:
        return kwargs[name]
    return args[index]

yea, this would. {'foo': None} would get you a None, if that matters. it's what i originally wrote replying to you, but then i brain sharted somewhere, this was a hellweek at $job and i was completely fried by like tuesday afternoon

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



ya I'm fine with a None showing up if that was indeed what th method was called with

cinci zoo sniper
Mar 15, 2013




Krankenstyle posted:

ya I'm fine with a None showing up if that was indeed what th method was called with

you're all set then, kwargs conditional should not have any meaningful failure modes remaining. args[index] can go sideways - i'd at least do some index check in a "better safe than sorry" fashion

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



good call tho I doubt it'll happen. better safe as you say

cinci zoo sniper
Mar 15, 2013




Krankenstyle posted:

good call tho I doubt it'll happen. better safe as you say

if you doubt it will happen, wrap what you have into a try/except IndexError block.

cinci zoo sniper
Mar 15, 2013




as everyone who has followed my database posts itt might imagine, im really into "defensive coding" by now :v:

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



cinci zoo sniper posted:

if you doubt it will happen, wrap what you have into a try/except IndexError block.

on second thought, i want my app to blow up if the argument is missing cause theres no reasonable way to go forward without a fileid anyway

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

yes, but when you don’t have a compiler telling you “hey dipshit you haven’t returned anything from all code paths” then I like to code in a way that I’m less likely to forget to return something

SciFiDownBeat posted:

semicolons are unnecessary in javascript but I still use them like a good boy scout :angel:

this is way more confusing than the other thing and is not a good comparison

fritz
Jul 26, 2003

ratbert90 posted:

It's unnecessary and stupid. :colbert:

so are my posts but that's enver stopped me

kalel
Jun 19, 2012

pokeyman posted:

yes, but when you don’t have a compiler telling you “hey dipshit you haven’t returned anything from all code paths” then I like to code in a way that I’m less likely to forget to return something

I agree in practice but it's a two line utility function for pete's sake

Captain Foo
May 11, 2004

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

SciFiDownBeat posted:

I agree in practice but it's a two line utility function for pete's sake

whatever you're coding is now doomed to be mission critical line of business code

Sapozhnik
Jan 2, 2005

Nap Ghost

Captain Foo posted:

whatever you're coding is now doomed to be mission critical line of business code

College stoner me: "Like, the universe isn't straight-up malevolent, it's just totally indifferent to us man"
Working programmer me: "I dunno, maybe there's a case to be made that it actually is malevolent"

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
ctps: writing unit tests for the first time in my life and I'm exhausted. this is taking me an ungodly amount of time, but I'm anxious about hitting all the corner cases. anyone has examples handy of "good" unit tests for some simple real world library? I suspect I'm maybe overdoing it a little

Luigi Thirty
Apr 30, 2006

Emergency confection port.

me, 3 hours ago: this C GEM library sucks, I want object oriented controls

me, 5 minutes ago: I think I’ve accidentally invented WinApi common controls but for the Atari ST

4lokos basilisk
Jul 17, 2008


hackbunny posted:

ctps: writing unit tests for the first time in my life and I'm exhausted. this is taking me an ungodly amount of time, but I'm anxious about hitting all the corner cases. anyone has examples handy of "good" unit tests for some simple real world library? I suspect I'm maybe overdoing it a little

not sure if it is possible to hit all corner cases or even most of them before you need unit tests on the unit tests

seems to be a thing where practice will help you figure out the balance

personally I try hitting only the corner cases that I think might be occurring actually or the cases that could be difficult to detect and debug later on

gonadic io
Feb 16, 2011

>>=

hackbunny posted:

ctps: writing unit tests for the first time in my life and I'm exhausted. this is taking me an ungodly amount of time, but I'm anxious about hitting all the corner cases. anyone has examples handy of "good" unit tests for some simple real world library? I suspect I'm maybe overdoing it a little

check ur coverage

(no really, it points out when you miss branches)

4lokos basilisk
Jul 17, 2008


also I think unit tests are meant to force you write the software in easily testable layers so you can replace the layers later on if you need to without messing with tests

ie like when you replace your thing which handles db interaction then you can focus on only that and know that whatever you do in the code as long as tests succeed you should be good

Adbot
ADBOT LOVES YOU

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


i've been wondering if unit testing in embedded/kernel/IoT space can be useful, there's an itch to try but when you don't even compile in all of the standard library into the firmware to save space it's fairly hard to design tests which would actually be meaningful and still run on the device

and most of the bugs come from a complex interplay of PCBs/firmware/components/third-party software anyway

obviously hardware testing/black box testing is important, but that's another kettle of fish entirely

e: there's the design verification route of running in a simulator maybe, but I don't know if that wouldn't bring in even more issues than it would solve

Private Speech fucked around with this message at 02:19 on Mar 9, 2019

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