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
repiv
Aug 13, 2009

:sickos:

https://twitter.com/d_feldman/status/1740106959704195185

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Write Four Billion Conditions

Volmarias fucked around with this message at 07:27 on Dec 28, 2023

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

Volmarias posted:

Write Four Billion Conditions

Reach heaven through bad code

shame on an IGA
Apr 8, 2005

do it for 64-bit and you will complete all the names of God

Polio Vax Scene
Apr 5, 2009



how long is the 4 billion if condition code if printed on 8.5x11, 12 point courier?

ExcessBLarg!
Sep 1, 2001

Volmarias posted:

Write Four Billion Conditions
Again, this could be written perfectly performantly using switch/case and a 32 GB jump table.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
sooo aaaanyway

OddObserver
Apr 3, 2009
This thing seems like a fun thing to throw at optimizers. (Not to be confused with a wise choice of a benchmark).

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Please, your jump table only needs to fill one physical memory frame, and simply redundantly remapped across your entire virtual address space

2Fast2Nutricious
Oct 4, 2020

Dijkstracula posted:

Please, your jump table only needs to fill one physical memory frame, and simply redundantly remapped across your entire virtual address space

quote:

For added performance (it is very important), I decided to map the file into the address space instead of reading all of it. By doing this, we can just pretend that the entire file is already in memory and let the poor OS deal with fitting a 40 GB blob into virtual memory.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I don't think I'm complaining too much about my ORM having an 'engine' component written in rust that is 2.5GB in size and requires me to build it myself. My host where I'm trying to put it is running FreeBSD13 for which the ORM doesn't have pre-compiled binaries. I'm currently moving 2.5GB of who knows what onto the host so that I can pray that I can build it.

The ORM is Prisma by the way.

abraham linksys
Sep 6, 2010

:darksouls:
the development history of prisma is so insane that i am unsurprised that that's what they're shipping, what a loving company/project

it makes slightly more sense as an architecture if you know that prisma at one point had aspirations of supporting other languages, but afaik they only ever got as far as a half complete go library that appears to have been completely deleted from their website, and the lead developer on the project at prisma was given ownership of the project after exiting the company which is very funny

abraham linksys
Sep 6, 2010

:darksouls:
personally i would not use the ORM created by a company that originally raised money to be a GraphQL-based backend-as-a-service, then pivoted to being a GraphQL query engine as a serice for existing databases, then pivoted to being an ORM for all databases and languages, and now appears to have burned $40 million dollars in venture capital on building a TypeScript ORM

anyone remember "gatsby"? love that they got a bunch of people into their open source project, then when everyone started having more mature sites and their build times started creeping up, they introduced a paid gatsby cloud project that was the only officially supported way to do incremental builds, and then they got bought by netifly and now the entire project is very dead :allears:

The Fool
Oct 16, 2003


abraham linksys posted:

they got bought

sounds like a success story to me

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Ok well I spent all day today trying to get a javascript npm module to run on node. I'll wake up with a brilliant idea I can try, I'll try it as a curiosity. Then I'll spend all day tomorrow replacing the ORM in the project.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


https://twitter.com/IroncladDev/status/1752349724105945181

OddObserver
Apr 3, 2009
readUTFWhat?

Remulak
Jun 8, 2001
I can't count to four.
Yams Fan
I C++ footgunned myself the other day with frigging clamp(). Was in older code and std::clamp() wasn’t there, so I did a template in what was essentially ‘randomUtils.cpp’. Had to touch a lot of older code, so I of course re-factored ton of stuff into clamp().

Oops, turns out that unsigned is a thing, especially if people turn a dial Really Fast and of course when a hosed-up unsigned goes negative things get really interesting.

That build never left the building, I’m only posting this here because I know I have one point I posted here my diatribe about using signed versus unsigned for expected values and how that implicit communication is a good thing. Mea culpa.

Raymond T. Racing
Jun 11, 2019

abraham linksys posted:

personally i would not use the ORM created by a company that originally raised money to be a GraphQL-based backend-as-a-service, then pivoted to being a GraphQL query engine as a serice for existing databases, then pivoted to being an ORM for all databases and languages, and now appears to have burned $40 million dollars in venture capital on building a TypeScript ORM

anyone remember "gatsby"? love that they got a bunch of people into their open source project, then when everyone started having more mature sites and their build times started creeping up, they introduced a paid gatsby cloud project that was the only officially supported way to do incremental builds, and then they got bought by netifly and now the entire project is very dead :allears:

GatsbyJS looks safe still, but dang didn’t know that

I’m an Astro shill these days

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

abraham linksys posted:

personally i would not use the ORM created by a company that originally raised money to be a GraphQL-based backend-as-a-service, then pivoted to being a GraphQL query engine as a serice for existing databases, then pivoted to being an ORM for all databases and languages, and now appears to have burned $40 million dollars in venture capital on building a TypeScript ORM

anyone remember "gatsby"? love that they got a bunch of people into their open source project, then when everyone started having more mature sites and their build times started creeping up, they introduced a paid gatsby cloud project that was the only officially supported way to do incremental builds, and then they got bought by netifly and now the entire project is very dead :allears:

I remember when a client wanted me to build them a gatsbe project and I did and then they had a bloated application that was way more complicated than what they needed.

DELETE CASCADE
Oct 25, 2017

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

ok so as you can see here on line 33, we declare the variable i to be an integer, and initialize it with the value 0

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug
So, one of the juniors on my team came up with something I said (in a code review) was "beautiful and terrible".

Minor vagueness in backstory: so we have a service (written in Python) that operates on a list of objects; the objects are in a strict hierarchy and the names are expressed as ParentObj/ChildObj/ChildOfChildObj, etc etc. We identified a bug in some code where there was an inheritance of an attribute from parent to child that this program was trying to change; so changing the parent and then trying to change the child would result in an error, since you were trying to add something to a set that already existed, essentially.

Example:
code:
# Denotes an object with a parent
# Blue/Apple/One 
  Blue/Banana/One
# Blue/Apple/Two
  Blue/Apple
# Red/Banana/One
  Red
# Red/Banana
Of that list, we only need to modify three, as those are the ones without parents. This sounds like an interview question: it's a reasonably straightforward logical application of low level algorithms. There's a ton of ways to solve it, and my junior was really struggling, so I walked them through a few options, mostly involving utilizing str.split('/') and then doing simple list interpretation. I assumed this wouldn't be a big problem and didn't want to get too directive about it, so I left it open ended.

The PR I received contained the phrase "I have used PurePath in my implementation, confirmation of logic in ticket". I kind of blew past that at first, and then had to go back and read it again.

"Wait...PurePath? Did I read that right?" I then opened the PR and confirmed that yes, I had read that right.

The way they solve this was to interpret each object name as a Unix-style file path using Python's stdlib Pathlib module, and then utilize directory crawling patterns to achieve the answer. I was immediately horrified, followed almost directly afterward by 'wait...hold on. Does this...work?' and I looked into it.

So a minor note aside that PurePosixPath was a better option to ensure that the OS didn't freak out, I came to the conclusion that this...definitely worked. Now, the rest of their implementation was pretty weird, involving some significant logic issues, but here's the final implementation, give or take:

Python code:
def find_parents(obj_list: List[Object]) -> List[Object]
    path_parents = [PurePosixPath(obj.name) for obj in obj_list]
    return [str(obj) for obj in path_parents if any(y in obj.parents for y in path_parents)]
These objects maintain very similar naming requirements to PosixPaths, and in fact are more strict - strictly alphabetical, no weird runes or emojis/etc, no spaces or punctuation at all. As far as we can tell, valid object names are a subset of all valid file path names, so this...works. The code is quite readable, and the underlying implementation can be generally assumed to be well tested as part of the standard library. Aside from refactoring a weird recursive lookup they had implemented, my only other comment was that they absolutely had to leave a clear comment about how we're not actually handling file paths.

Now, could we have written something else? Sure, and it probably would have been just as readable, but I was kind of awestruck at this hacky thing, and it was reasonably constrained so...I approved it.

more falafel please
Feb 26, 2005

forums poster

In college I interviewed for an internship at Microsoft (they'd bring a bunch of recruiters and engineers on campus once a year and interview basically every 3rd/4th year CS student) and I was definitely in my smarmy-Unix-kid phase, which intersected heavily with my any-program-worth-writing-can-be-a-Perl-oneliner phase

My interview was being done by a recruiter, not an engineer, but they still asked technical questions. One was "write a function to reverse the order of words in a string". I had done plenty of that type of exercise in school, and I was well-versed in C and to a lesser extent C++, so I could have done a straightforward recursive or iterative algorithm, but the interviewer said I could use whatever language I wanted, and I wanted to show everyone just how fuckin' clever I was so I just wrote "join reverse split;" on the whiteboard and then refused to elaborate.

I didn't get the internship.

Soricidus
Oct 21, 2010
freedom-hating statist shill

more falafel please posted:

In college I interviewed for an internship at Microsoft (they'd bring a bunch of recruiters and engineers on campus once a year and interview basically every 3rd/4th year CS student) and I was definitely in my smarmy-Unix-kid phase, which intersected heavily with my any-program-worth-writing-can-be-a-Perl-oneliner phase

My interview was being done by a recruiter, not an engineer, but they still asked technical questions. One was "write a function to reverse the order of words in a string". I had done plenty of that type of exercise in school, and I was well-versed in C and to a lesser extent C++, so I could have done a straightforward recursive or iterative algorithm, but the interviewer said I could use whatever language I wanted, and I wanted to show everyone just how fuckin' clever I was so I just wrote "join reverse split;" on the whiteboard and then refused to elaborate.

I didn't get the internship.

Well obviously not, you forgot the separator argument for join

more falafel please
Feb 26, 2005

forums poster

Soricidus posted:

Well obviously not, you forgot the separator argument for join

goddamnit larry how does it not default to $_ (probably because it's in list context and all the args get collapsed, once again goddamnit larry)

Soricidus
Oct 21, 2010
freedom-hating statist shill

more falafel please posted:

goddamnit larry how does it not default to $_ (probably because it's in list context and all the args get collapsed, once again goddamnit larry)

I think technically your code uses the result of “reverse split” in scalar context (i.e. the number of words), to join an empty list. So the result is always an empty string.

Perl is fun!

Falcon2001
Oct 10, 2004

Eat your hamburgers, Apollo.
Pillbug

more falafel please posted:

In college I interviewed for an internship at Microsoft (they'd bring a bunch of recruiters and engineers on campus once a year and interview basically every 3rd/4th year CS student) and I was definitely in my smarmy-Unix-kid phase, which intersected heavily with my any-program-worth-writing-can-be-a-Perl-oneliner phase

My interview was being done by a recruiter, not an engineer, but they still asked technical questions. One was "write a function to reverse the order of words in a string". I had done plenty of that type of exercise in school, and I was well-versed in C and to a lesser extent C++, so I could have done a straightforward recursive or iterative algorithm, but the interviewer said I could use whatever language I wanted, and I wanted to show everyone just how fuckin' clever I was so I just wrote "join reverse split;" on the whiteboard and then refused to elaborate.

I didn't get the internship.

Don't worry, some people never grow out of that phase.

Xarn
Jun 26, 2015
That Python paths solution is funny, but hopefully the inputs stay small.

Beef
Jul 26, 2004

Falcon2001 posted:

So, one of the juniors on my team came up with something I said (in a code review) was "beautiful and terrible".

Minor vagueness in backstory: so we have a service (written in Python) that operates on a list of objects; the objects are in a strict hierarchy and the names are expressed as ParentObj/ChildObj/ChildOfChildObj, etc etc. We identified a bug in some code where there was an inheritance of an attribute from parent to child that this program was trying to change; so changing the parent and then trying to change the child would result in an error, since you were trying to add something to a set that already existed, essentially.

Example:
code:
# Denotes an object with a parent
# Blue/Apple/One 
  Blue/Banana/One
# Blue/Apple/Two
  Blue/Apple
# Red/Banana/One
  Red
# Red/Banana
Of that list, we only need to modify three, as those are the ones without parents. This sounds like an interview question: it's a reasonably straightforward logical application of low level algorithms. There's a ton of ways to solve it, and my junior was really struggling, so I walked them through a few options, mostly involving utilizing str.split('/') and then doing simple list interpretation. I assumed this wouldn't be a big problem and didn't want to get too directive about it, so I left it open ended.

The PR I received contained the phrase "I have used PurePath in my implementation, confirmation of logic in ticket". I kind of blew past that at first, and then had to go back and read it again.

"Wait...PurePath? Did I read that right?" I then opened the PR and confirmed that yes, I had read that right.

The way they solve this was to interpret each object name as a Unix-style file path using Python's stdlib Pathlib module, and then utilize directory crawling patterns to achieve the answer. I was immediately horrified, followed almost directly afterward by 'wait...hold on. Does this...work?' and I looked into it.

So a minor note aside that PurePosixPath was a better option to ensure that the OS didn't freak out, I came to the conclusion that this...definitely worked. Now, the rest of their implementation was pretty weird, involving some significant logic issues, but here's the final implementation, give or take:

Python code:
def find_parents(obj_list: List[Object]) -> List[Object]
    path_parents = [PurePosixPath(obj.name) for obj in obj_list]
    return [str(obj) for obj in path_parents if any(y in obj.parents for y in path_parents)]
These objects maintain very similar naming requirements to PosixPaths, and in fact are more strict - strictly alphabetical, no weird runes or emojis/etc, no spaces or punctuation at all. As far as we can tell, valid object names are a subset of all valid file path names, so this...works. The code is quite readable, and the underlying implementation can be generally assumed to be well tested as part of the standard library. Aside from refactoring a weird recursive lookup they had implemented, my only other comment was that they absolutely had to leave a clear comment about how we're not actually handling file paths.

Now, could we have written something else? Sure, and it probably would have been just as readable, but I was kind of awestruck at this hacky thing, and it was reasonably constrained so...I approved it.

The bad small here is that the junior still does not understand recursion.

tyrelhill
Jul 30, 2006

DELETE CASCADE posted:

ok so as you can see here on line 33, we declare the variable i to be an integer, and initialize it with the value 0

or an hour long "chat gpt explain this" voice to text

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Falcon2001 posted:

...
Now, could we have written something else? Sure, and it probably would have been just as readable, but I was kind of awestruck at this hacky thing, and it was reasonably constrained so...I approved it.

I don't think I would describe it as "hacky". You've designed a system where the "paths" are paths in an abstract filesystem, so it's amenable to interrogation with tools intended for filesystems. Is it "hacky" when URIs are constructed using abstract paths like http://example.com/foo/get/12345

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yeah. I mean, given your constraints of canonical Unix-style strict-alpha paths, the simpler and much more efficient solution is just to sort them and then make a single pass dropping elements that have the last undropped element as a path-prefix (which is just string-prefix except the first character after the prefix also has to be a slash). But using an abstract path library for abstract paths is totally fine.

NtotheTC
Dec 31, 2007


I would have used urllib

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
The Soviets used a pencil

QuarkJets
Sep 8, 2008

Falcon2001 posted:

So, one of the juniors on my team came up with something I said (in a code review) was "beautiful and terrible".

Minor vagueness in backstory: so we have a service (written in Python) that operates on a list of objects; the objects are in a strict hierarchy and the names are expressed as ParentObj/ChildObj/ChildOfChildObj, etc etc. We identified a bug in some code where there was an inheritance of an attribute from parent to child that this program was trying to change; so changing the parent and then trying to change the child would result in an error, since you were trying to add something to a set that already existed, essentially.

Example:
code:
# Denotes an object with a parent
# Blue/Apple/One 
  Blue/Banana/One
# Blue/Apple/Two
  Blue/Apple
# Red/Banana/One
  Red
# Red/Banana
Of that list, we only need to modify three, as those are the ones without parents. This sounds like an interview question: it's a reasonably straightforward logical application of low level algorithms. There's a ton of ways to solve it, and my junior was really struggling, so I walked them through a few options, mostly involving utilizing str.split('/') and then doing simple list interpretation. I assumed this wouldn't be a big problem and didn't want to get too directive about it, so I left it open ended.

The PR I received contained the phrase "I have used PurePath in my implementation, confirmation of logic in ticket". I kind of blew past that at first, and then had to go back and read it again.

"Wait...PurePath? Did I read that right?" I then opened the PR and confirmed that yes, I had read that right.

The way they solve this was to interpret each object name as a Unix-style file path using Python's stdlib Pathlib module, and then utilize directory crawling patterns to achieve the answer. I was immediately horrified, followed almost directly afterward by 'wait...hold on. Does this...work?' and I looked into it.

So a minor note aside that PurePosixPath was a better option to ensure that the OS didn't freak out, I came to the conclusion that this...definitely worked. Now, the rest of their implementation was pretty weird, involving some significant logic issues, but here's the final implementation, give or take:

Python code:
def find_parents(obj_list: List[Object]) -> List[Object]
    path_parents = [PurePosixPath(obj.name) for obj in obj_list]
    return [str(obj) for obj in path_parents if any(y in obj.parents for y in path_parents)]
These objects maintain very similar naming requirements to PosixPaths, and in fact are more strict - strictly alphabetical, no weird runes or emojis/etc, no spaces or punctuation at all. As far as we can tell, valid object names are a subset of all valid file path names, so this...works. The code is quite readable, and the underlying implementation can be generally assumed to be well tested as part of the standard library. Aside from refactoring a weird recursive lookup they had implemented, my only other comment was that they absolutely had to leave a clear comment about how we're not actually handling file paths.

Now, could we have written something else? Sure, and it probably would have been just as readable, but I was kind of awestruck at this hacky thing, and it was reasonably constrained so...I approved it.

Given the choice between easy to read and comprehend vs clever I prefer the former, but if it's well-tested then clever is fine

JawnV6
Jul 4, 2004

So hot ...

QuarkJets posted:

Given the choice between easy to read and comprehend vs clever I prefer the former, but if it's well-tested then clever is fine

Back at my first job they'd literally have sections of code where the two were side by side. "Here's the legible version if you're trying to interact with this section, here's the gross bit-by-bit breakdown to actually make it fast enough."

Carbon dioxide
Oct 9, 2012

.

Only registered members can see post attachments!

OddObserver
Apr 3, 2009
Is someone playing with BiDi overrides somehow?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
It's like how a[2] is the same as 2[a].

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I'll bite, my knowledge of C/C++ esoteria is apparently insufficient. Is this actually something, or did you ask an AI to generate a picture of hello world?

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