i'll have chicken and chips if it's cheap else i'll have chicken
then-if-else, as nobody calls them
― koogs, Wednesday, 15 June 2022 14:12 (one year ago) link
eh, i don't think `a if cond else b` is significantly more/less readable than any other ternary syntax, e.g. `cond ? a : b`.
― š¯” š¯”˛š¯”¢š¯”Ø (caek), Wednesday, 15 June 2022 16:16 (one year ago) link
I dislike the original because I like the default condition first and having test as the default is uh, safer but not what I'd do
― mh, Wednesday, 15 June 2022 16:22 (one year ago) link
I think if/then/else syntax has absolutely trained developers of a certain age (e.g., me) to expect to see the condition first; that Python excerpt reads like someone said "my code would flow much better if it was arranged like German verbs or Spanish adjectives" and I'm getting irrationally angry about it (also I have never looked at or written Python code in my life).
― castanuts (DJP), Wednesday, 15 June 2022 16:33 (one year ago) link
the ?: is odd because of the use of only punctuation. and how do you nest them? it's probably ok if the bits are short, or indented correctly
thing = (v_one == v_two) ? same : different
with 'a if cond else b' there's more chance that the condition is further to the right than i like, and => easier to miss. i guess he moved the if onto the second line to make it clearer, but made it worse - it looks like another, badly indented, statement,
> developers of a certain age
it me
> having test as the default is uh, safer
i may've flipped the logic whilst anonymising it for posting
actually, i guess this would work
thing = safe_defaultif (rare condition) thing = special caseend
which looks a lot like the original but is in fact the opposite. maybe that's my issue with it
― koogs, Wednesday, 15 June 2022 17:00 (one year ago) link
this is baffling to me.
i don't think appeals to english word order make sense when talking about programming languages 1. this is not applescript 2. plenty of programmers are not native english speakers. 3. english word order is very flexible.
but to the extent they do: "x is y if condition, otherwise it's z" doesn't seem like non-english word order at all. it's idiomatic english.
if the argument is that this is unintuitive (hard to read?) for non-python programmers, i think that applies more to ternary operator syntax in every language that uses random punctuation like ? and :
if you really want a ternary one-liner with the condition first a la js, replace ? with "and" and : with "or", i.e. x = condition and y or z. this obviously sucks, but no more than random punctuation.
― š¯” š¯”˛š¯”¢š¯”Ø (caek), Wednesday, 15 June 2022 17:27 (one year ago) link
koogs i feel like your complaint is with ternary, not with the python syntax for ternary.
― š¯” š¯”˛š¯”¢š¯”Ø (caek), Wednesday, 15 June 2022 17:28 (one year ago) link
I think it's not english word order, it's just convention and the programming languages/syntax I'm used to using.I was looking at some python a coworker wrote and it was obviously written by someone used to C#. It's just idiomatic. I'd say over half of scanning over code and thinking you know what's going on is down to convention and not enforced language structure
that said,the ?: is odd because of the use of only punctuation. and how do you nest them?I got so used to parsing these in my brain that it'd disgusting. Mostly due to coworkers doingvar x = condition ? condition 2 ? a : b : c
I haven't done that or read through that in a few years so please clown me if I botched it
― mh, Wednesday, 15 June 2022 17:41 (one year ago) link
fwiw you are only truly a savage if you start doing one convention in a project that completely uses another (while others are still working on it) or if you just do your conditionals a bunch of different ways for no conceivable reason
― mh, Wednesday, 15 June 2022 17:42 (one year ago) link
it's more to do with putting the important information first.
let thing = "some value" if (whatever)
this is an assignment. oh, but it's conditional. i would've preferred to know that first. i basically want to read as little as possible of the line before i can decide whether it's important or not.
throw massive exception (argh!) if appropriate (oh...)
― koogs, Wednesday, 15 June 2022 17:49 (one year ago) link
var x = condition ? condition 2 ? a : b : c
yeah my reaction to this is mostly: if you think ternaries in python are bad, wait until you see how people use them in practice in js.
i get your point but fwiw you can't throw in a ternary.
― š¯” š¯”˛š¯”¢š¯”Ø (caek), Wednesday, 15 June 2022 18:18 (one year ago) link
code review today (please excuse clumsy anonymising)
... .withXXXXXXXXXXXXStartTime(OffsetDateTime.parse((somethingInfo.getXXXXXXXXXXXXStartTime() == null) ? XXXXXXXXXXXXX_START_TIME : DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(ZoneId.of("UTC")).format(Instant.EPOCH.plus(somethingInfo.getXXXXXXXXXXXXStartTime())))) ...
kids today with their 300 character-wide monitors
― koogs, Thursday, 16 June 2022 16:59 (one year ago) link
yeeeikes
― š¯” š¯”˛š¯”¢š¯”Ø (caek), Thursday, 16 June 2022 17:27 (one year ago) link
> if you think ternaries in python are bad, wait until you see how people use them in practice in js.
or java...
― koogs, Thursday, 16 June 2022 17:34 (one year ago) link
koogs, when did you start maintaining my old code from a decade ago
― mh, Thursday, 16 June 2022 18:24 (one year ago) link
actually, more like fifteen years ago. me old
― mh, Thursday, 16 June 2022 18:25 (one year ago) link
Is there a data science thread? Iā€™ve found myself managing some data scientist on a pretty cool project but I am completely out of my league. I work in geography (English major here!) and Iā€™ve been on the job for awhile so I can at least act as an SME but these kids are doing some insane stuff.
― Heez, Thursday, 16 June 2022 20:25 (one year ago) link
we should start a real one. weā€™ve just been bouncing between this one and caekā€™s corner iirc
― mh, Thursday, 16 June 2022 21:03 (one year ago) link
in my review i suggested moving the 300 character line of code into a separate method and calling that instead.
he duly copied the line verbatim into another method, so there's now a new method with a single 300 character line in it...
― koogs, Friday, 17 June 2022 10:36 (one year ago) link
Programmers gonna literal.
― Chewshabadoo, Friday, 17 June 2022 10:48 (one year ago) link
lmao
― castanuts (DJP), Friday, 17 June 2022 14:52 (one year ago) link
Classic!
― Jimmy Jimmy Loves Mary-Anne Mary-Anne (James Redd and the Blecchs), Friday, 17 June 2022 14:55 (one year ago) link
I don't think I've ever typed this out before but one thing I haven't forgotten over many years is someone once saying about someone else "he really is an automaton."
― Jimmy Jimmy Loves Mary-Anne Mary-Anne (James Redd and the Blecchs), Friday, 17 June 2022 14:56 (one year ago) link
regexp help. need at least 1 of A B and C, in order
9A9B9C9A9B9A9C9B9C9A9B9Care all ok (where 9 is any digit). blank is not
so far i have
/^(9A9B9C|9A9B|9A9C|9B9C|9A|9B|9C)$/
which reduces down to
/^(9A(9B9C|9B|9C|)|9B(9C|)|9C)$/
there's slightly more to it than this but this is the crux
― koogs, Monday, 20 June 2022 16:08 (one year ago) link
no reason it has to be one line, of course.
― koogs, Monday, 20 June 2022 16:30 (one year ago) link
since we got on Java 8 there's been like a competition to see who can make the most convoluted lambda expression possible, I hate it cuz these are so hard to debug
our transfer objects go like 6 layers deep. yeah a bunch of nested if loops looks like crap but you can at least step through it and easily make changes. we have a new developer on one of them now, I can only imagine how much he'd struggle if I did things the way everyone else was
― frogbs, Monday, 20 June 2022 17:46 (one year ago) link
Koogs, Iā€™m not great at regex but I find the editor at regexr.com quite useful- lots of user submitted patterns too that can be lifted and adapted
― she started dancing to that (Finefinemusic), Monday, 20 June 2022 18:31 (one year ago) link
i don't think we'll ever use more than one of A, B or C, so it'd just be 9b;ABCd; if i had my way.
(will that work?)
― koogs, Monday, 20 June 2022 20:24 (one year ago) link
no.
9[ABC]
― koogs, Monday, 20 June 2022 20:25 (one year ago) link
lol java 8, theyā€™re on 17 now bruv(8 is fine, I crack up that they finally did a version release strategy but itā€™s a major number so often)
― mh, Tuesday, 21 June 2022 01:30 (one year ago) link
last 3 components i worked on here were 2014 vintage and needed Java 8, wouldn't compile under (our default) Java 11. i didn't upgrade them.
Been downhill all the way with Java since they introduced lambdas.
― koogs, Tuesday, 21 June 2022 01:37 (one year ago) link
beginners mindset, youā€™re worse than a weird .net bro now
― mh, Tuesday, 21 June 2022 01:40 (one year ago) link
That sounds like a very difficult thing to do in regex, but fairly simple in regular code.
― o. nate, Tuesday, 21 June 2022 17:29 (one year ago) link
lol java 8, theyā€™re on 17 now bruv
yea we recently upgraded to 11, idk when we'll ever get to 17. i mean what's the point
― frogbs, Tuesday, 21 June 2022 17:47 (one year ago) link
I think I'd just do /^(9A)*(9B)*(9C)*$/ and check not empty/null separately tbh?
I'm assuming that checking for empty string is like one brief, readable line despite my suspicions about Java. I might not be understanding the requirements correctly though and my regexping is rusty.
(tbh I am rustier than ever at programming in general, which I was never good at, and I feel like my days at my current job are numbered because my brain seems to have died and we're implementing a new system I don't understand or care about understanding at all. Sort of feel I should completely give up on making a living doing anything tech-related but can't think of what else I might possibly do. I remember saying all this before, almost exactly half my lifetime ago at the start of my non-career, and probably on this thread several times since then...)
(Current job is in theory part scripting and part support, and the support part expands to fill 99.9% of the time. That's what support jobs are like, right? But also I let it do so, because I always put off any tasks which require1. concentration/flow/clear-headed thought/forward planning2. the perceptivity to think of all the possible disastrous problems and guard against them3. the calmness not to stress yrself to death thinking about what examples of 2 you've forgotten and how much of the database it might delete and how your coworkers will hate you and the boss will thunder down the hall going "WHICH IDIOT LET THIS HAPPEN", again)
― a passing spacecadet, Tuesday, 21 June 2022 18:31 (one year ago) link
This works from what I can tell, and the only suggestion I'd make is to not bother with capturing them if that's needed:
/^(?:9A)*(?:9B)*(?:9C)*$/
― Antifa Lockhart (Leee), Tuesday, 21 June 2022 18:43 (one year ago) link
it's ruby, but that doesn't matter.
i went with readability in the end, listed all the valid combinations in separate lines. you can golf these things but there's a point where concise becomes curt and that's everything i don't like.
but wouldn't /^(9A)*(9B)*(9C)*$/ allow 9A9A9A9A? i can only have at most one of each. replacing the *s (0 or more) with ?s (0 or 1) should do. then, yes, just need to catch "" separately
― koogs, Tuesday, 21 June 2022 20:46 (one year ago) link
as for fuckups, we have two components, A (currently on version 367) and B (currently on version 317) and i managed to deploy version 317 of component A to LIVE and didn't notice for an ENTIRE DAY. this is public facing stuff, 10s of thousands of users and not a single bug report or alert. so either nothing important has happened in those last 50 versions or all the built-in redundancy works.
(i've added checks so it won't happen again - it'll now look up the version itself)
― koogs, Tuesday, 21 June 2022 20:55 (one year ago) link
but wouldn't /^(9A)*(9B)*(9C)*$/ allow 9A9A9A9A? i can only have at most one of each.
Sorry, yes, it would - I misread "at least 1 of A, B and C" to mean that repeats were OK as long as A-B-C were still in order.
Probably something to be said with listing the valid combinations separately for readability, though. As long as it doesn't result in such a massive list nobody will ever read the whole thing...
― a passing spacecadet, Tuesday, 21 June 2022 21:20 (one year ago) link
maybe i'm missing something but isn't it just A.*B.*Chaven't done regex in ages
― adam t. (abanana), Friday, 24 June 2022 17:01 (one year ago) link
never mind
― adam t. (abanana), Friday, 24 June 2022 17:04 (one year ago) link
maybe i should do more regex? tried for a programming job for the first time in over a decade, flubbed a coding task where it required a "\w" but I put in a "*". fun but stressful.
― formerly abanana (dat), Wednesday, 24 August 2022 04:40 (one year ago) link
i love writing regexes--they're like a fun puzzle imo. regex101.com is a good tool for writing/debugging
― diamonddave85ļ»æ (diamonddave85), Wednesday, 24 August 2022 14:46 (one year ago) link
but \w / \W seems designed to confuse
― koogs, Wednesday, 24 August 2022 15:26 (one year ago) link
I enjoy writing regexes too, but I donā€™t think Iā€™ve ever written one without referring to a cheat sheet. They donā€™t seem like good material for interview questions because who can remember all those special characters.
― o. nate, Wednesday, 24 August 2022 18:41 (one year ago) link
I have spent my entire career avoding using regex as much as I possibly can, the most unreadable abominations that they are.
― Chewshabadoo, Wednesday, 24 August 2022 19:00 (one year ago) link
xp yeah it reminds me of the tests I got in college where you had to remember specific syntax which always felt dumb because in the real world you could just Google it. which I still do, often :)
in retrospect it was kind of funny how adamant they were about not sharing your code with your classmates, even calling it "plagiarism" over and over, when in reality like half of what I do is copy something and change it a bit
― frogbs, Wednesday, 24 August 2022 19:04 (one year ago) link
lol, I was careful to specify that I enjoy writing regexes. Reading them, not so much.
― o. nate, Wednesday, 24 August 2022 19:38 (one year ago) link
https://nedbatchelder.com/blog/201302/a_regular_crossword.html
https://nedbatchelder.com/iv/webp/pix/regular_crossword.png.webp
― koogs, Wednesday, 24 August 2022 19:43 (one year ago) link
you bugger
― the man with the chili in his eyes (ledge), Wednesday, 24 August 2022 19:58 (one year ago) link