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
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.


HappyHippo posted:

effortpost but whatever. if "readability" means anything it should be related to the mental burden the code requires to understand it. one aspect of that is "do i need to understand all the details to understand the big picture?" if i do, the readability is poor because i can only keep so much info in my head at once. much better if you can understand the big picture before you read the details

so if we're going to initialize a variable with one of two values based on a condition
code:
var x = someCondition ? thing : other_thing;
code:
var x;
if (someCondition) {
    x = thing;
} else { 
    x = other_thing;
}
i find the first more readable because i know the big picture at this point:
code:
var x = someCondition ? ...
whereas with the second i need to read all the clauses of the if/else to know that they're assigning to x and that's all they do. it's not a big burden either way but my general preference is to use the least powerful construct to accomplish a task. if/else is generally more powerful than ?: so my preference is for ?: here

this is also why i prefer things like map/filter/etc. over for loops when they're available. they're less powerful than for loops so you can understand the intent before you read the details rather than after. i think a diversity of programming constructs is better because it allows you to communicate intent, which is why i don't understand when people try to reduce that diversity in an attempt to make the code "simpler." technically we don't need for loops if we have while loops but using a for loop indicates something to the reader (actually we don't need anything other than gotos but everyone understands why that's a bad idea).

I actually find the first easier to read than the second

then again I also really don't like filter at al, at least unless it's genuine filtering rather than some chained transform monstrosity

I don't mind lambdas and for_each though

Private Speech fucked around with this message at 20:49 on Dec 2, 2021

Adbot
ADBOT LOVES YOU

Just a Moron
Nov 11, 2021

I don't know why anyone would use Javascript when Typescript is right there. It seems like half the problems with JS is from the extraordinary weak typing.

Presto
Nov 22, 2002

Keep calm and Harry on.
As soon as I see map or filter I assume someone is being too clever for their own good.

Powerful Two-Hander
Mar 10, 2004

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


nested ternary and comments is gross imho because if you multiline it you're putting comments inside the brackets and then ending with some horrid ))) at the end. just use if statements with indentation, there's no prize for brevity.

That said:

Shaggar posted:

there used to be a handful of places where terneries were ok, but they've been supplanted by better syntax.

i.e.

var fart = butt.HasValue ? butt.Value : "ffffffffff";

can now be written as

var fart = butt??"ffffffffff";

I love ?? When I remember it exists but every time I use it I think "someone's gonna hate me for this"

Powerful Two-Hander fucked around with this message at 22:16 on Dec 2, 2021

Powerful Two-Hander
Mar 10, 2004

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


today's adventure was that I accidentally broke all the loggers by loving up setting a lifecycle policy on the elastic indexes, or more accurately setting that correctly but in the process applying an index template with the ootb "logs" definition which it turns out completely fucks Serilog if you're not using neweer versions. Stated reason: "oh that field changed from _butts to _balls in later versions of elastic", god the docs for this suck.

turns out nobody looks at any logs apart from me though because nobody noticed none had been written for 24 hours!

Carthag Tuek
Oct 15, 2005

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



i have three tickets for tomorrow thats justs deleting poo poo :yeshaha:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

HappyHippo posted:

whereas with the second i need to read all the clauses of the if/else to know that they're assigning to x and that's all they do.

idk if it's disallowed to return/break/continue from a ternary or if it just doesn't happen much, but yeah I like that aspect

The Wisest Moron posted:

I don't know why anyone would use Javascript when Typescript is right there. It seems like half the problems with JS is from the extraordinary weak typing.

lack of a compile step or dependencies can be nice

but I agree as soon as you add either

hbag
Feb 13, 2021

oh god i forgot advent of code was a thing

cinci zoo sniper
Mar 15, 2013




hbag posted:

oh god i forgot advent of code was a thing

you have plenty of time to get in on the action

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Powerful Two-Hander posted:

nested ternary and comments is gross imho because if you multiline it you're putting comments inside the brackets and then ending with some horrid ))) at the end. just use if statements with indentation, there's no prize for brevity.

what? to be clear

code:
var x = cond1 ? first_thing :  //it's the first thing
        cond2 ? second_thing : //it's the second thing
                other_thing;   //it's the other thing
no brackets needed, unless you're using php, because they got this wrong

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

cinci zoo sniper posted:

you have plenty of time to get in on the action

also there is absolutely no chance you will be on the leaderboard, so there is no pressure.

on the first two days the 100 people on the leaderboard completed both of the daily tasks in under 3 minutes after they were published. it took me longer than that to get the input file opened.

CPColin
Sep 9, 2003

Big ol' smile.

Presto posted:

As soon as I see map or filter I assume someone is being too clever for their own good.

ok graybeard

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Presto posted:

As soon as I see map or filter I assume someone is being too clever for their own good.

map is just "convert a collection of things to a collection of other things" and filter is just... filtering?

like
Java code:
Orders.stream()
	.map(Order::getOrderNumber)
	.filter(Strings::isNotBlank)
//whatever, collect to a list, iterate with forEach

Truman Peyote
Oct 11, 2006



ternaries are often good for setting struct fields. can't think of a time when i'd prefer nesting them to if/else, though.

Powerful Two-Hander
Mar 10, 2004

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


HappyHippo posted:

what? to be clear

code:
var x = cond1 ? first_thing :  //it's the first thing
        cond2 ? second_thing : //it's the second thing
                other_thing;   //it's the other thing
no brackets needed, unless you're using php, because they got this wrong

I guess I was thinking of javascript, specifically those examples earlier? Idk. I guess I use nested statement s like that so rarely I have just gone to if statements when it's more than one case.

MrQueasy
Nov 15, 2005

Probiot-ICK

Powerful Two-Hander posted:

I guess I was thinking of javascript, specifically those examples earlier? Idk. I guess I use nested statement s like that so rarely I have just gone to if statements when it's more than one case.

and it's not like most ides won't flip one to the other seamlessly.

Arcsech
Aug 5, 2008

Presto posted:

As soon as I see map or filter I assume someone is being too clever for their own good.

lol that’s certainly a take

“these functions that are semantically clearer than looping are bad, only eggheads use them”

Share Bear
Apr 27, 2004

Arcsech posted:

“these functions that are semantically clearer than looping are bad, only eggheads use them”

this but unironically

jk i use collection comprehensions all the time theyre the best

Doom Mathematic
Sep 2, 2008
If your nested ternaries are complex and inscrutable enough to require comments on multiple lines (versus perhaps one explanatory comment immediately above) then you're golfing and probably a chain of if/elses would be better.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Powerful Two-Hander posted:

I guess I was thinking of javascript, specifically those examples earlier? Idk. I guess I use nested statement s like that so rarely I have just gone to if statements when it's more than one case.

js gets the precedence right. php is the only mainstream language that gets it wrong.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
sql case when is the "better" way of implementing nested ternary expressions

Powerful Two-Hander
Mar 10, 2004

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


ugh here's a horror I saw today: using a CASE statement in a subquery that then either returned an integer or 'No', and then left joined on the value matching to another int and the value not equalling the string 'No'.

SQL type cooercion :barf:

toiletbrush
May 17, 2010

Jabor posted:

sql case when is the "better" way of implementing nested ternary expressions
doesn't case-when not require an else though? forcing you to handle each case is what's great about ternaries

Powerful Two-Hander
Mar 10, 2004

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


toiletbrush posted:

doesn't case-when not require an else though? forcing you to handle each case is what's great about ternaries

No you've got to have an else as a fall through in your cases otherwise you'll get an error. In mssql anyway. Edit; nope I'm wrong, a case without an else returns null if nothing matches. Tbf we run some godawful compatibility mode so maybe that was changed? Now I'm gonna have to read technet.

Ignore me I realised I was thinking of something completely different. Leaving this here though:

so of course your have your else return '???' (I have literally seen this)

Powerful Two-Hander fucked around with this message at 00:48 on Dec 3, 2021

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If your expression doesn't produce a value then your output row will have a null in it. Same as if you do an outer join and there's nothing to match against.

If you implemented that syntax in an imperative programming language then you'd probably require the else case, yeah.

cinci zoo sniper
Mar 15, 2013




ansi sql case statements have else as optional clause

cinci zoo sniper
Mar 15, 2013




https://aws.amazon.com/about-aws/whats-new/2021/12/aws-sdk-rust-developer-preview/

developer preview for aws rust ask

Bored Online
May 25, 2009

We don't need Rome telling us what to do.
they have kotlin and swift now too

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
esac

Ocean of Milk
Jun 25, 2018

oh yeah
The Binding of esac

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Arcsech posted:

“these functions that are semantically clearer than looping are bad, only eggheads use them”

this is what i was trying to say, but the words escaped me

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik
map/filter/fold/etc whip rear end.

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER

Share Bear posted:

this but unironically

jk i use collection comprehensions all the time theyre the best

:yossame: except for every time I have to use them in Python and remember that filter of an array doesn't output an array but a single use iterator and I don't like it

NihilCredo
Jun 6, 2011

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

Jabor posted:

If your expression doesn't produce a value then your output row will have a null in it. Same as if you do an outer join and there's nothing to match against.

sql is a bit of a tragedy because the "runtimes" are so freaking good but it's impossible to fix the relatively minor design flaws in its frontend

type coercion, pervasive nulls, no null vs undefined distinction, clunky and limited "variables" (ctes and temp tables)... any other language with such wide adoption would have since sprouted a runtime-compatible with those frontend flaws fixed. java -> kotlin, js -> ts, erlang -> elixir etc.

every few years somebody tries to make sql 2.0 that compiles to sql and it never catches on because compiling to a language that is almost fully declarative and only barely standardized is leaky as hell, and also its flaws aren't so bad for 95% of its use cases (basically any program under 200 lines or so)

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

Presto posted:

As soon as I see map or filter I assume someone is being too clever for their own good.
golang user spotted

Powerful Two-Hander
Mar 10, 2004

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


NihilCredo posted:


every few years somebody tries to make sql 2.0 that compiles to sql and it never catches on because compiling to a language that is almost fully declarative and only barely standardized is leaky as hell, and also its flaws aren't so bad for 95% of its use cases (basically any program under 200 lines or so)

who remembers linq2sql/entity framework? what a loving disaster that was

Powerful Two-Hander
Mar 10, 2004

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


https://twitter.com/fesshole/status/1466699991746244610?t=kySgGOUKvPP4DZG15LKcng&s=19


I swear that wasn't me ( i actually wrote some unit tests two weeks ago)

cinci zoo sniper
Mar 15, 2013




Powerful Two-Hander posted:

https://twitter.com/fesshole/status/1466699991746244610?t=kySgGOUKvPP4DZG15LKcng&s=19


I swear that wasn't me ( i actually wrote some unit tests two weeks ago)

this piece of poo poo im working on is like 10 times more difficult to test than to actually implement, im probably not going to bother even (because ive got a month left here lmao). it’s the perfect storm of a third party process marshalling my code, which in turn is balls deep in abstraction layers of our orchestration framework, and every operation is like “read 100 terabytes from A and copy it into B”

cinci zoo sniper fucked around with this message at 12:01 on Dec 3, 2021

Carthag Tuek
Oct 15, 2005

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



I'm trying to run a phpunit test but it won't loving pick up my env vars :argh:

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015
Apparently I get to maintain a bunch of Go code, because the teams using our library from Go cannot be trusted to do the sane thing and write common utility functions once, so there are now 4 subtly different versions of conceptually same code between different go projects.

What is a good Go tutorial?

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