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
Share Bear
Apr 27, 2004


cursed terminology

Adbot
ADBOT LOVES YOU

Powerful Two-Hander
Mar 10, 2004

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


Share Bear posted:

cursed terminology

call it static, call it vendoring, who cares? Just dehumanise and face package managers and walk backwards into Shaggar's embrace

Powerful Two-Hander
Mar 10, 2004

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


Look deep down inside yourself and ask "do I give a gently caress?" No? then do whatever is easiest for you at the time and be at peace.

Future you can get angry and post back in this thread at any time.

NihilCredo
Jun 6, 2011

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

Sapozhnik posted:

this seems like a great idea right up until the first moment when you need to make an arbitrarily sortable and searchable table in your application

SELECT * FROM shart
WHERE
COALESCE(what = :what, TRUE) AND
COALESCE(the = :the, TRUE) AND
COALESCE(gently caress = :gently caress, TRUE) AND
COALESCE(did = :did, TRUE) AND
COALESCE(did >= :didGte, TRUE) AND
COALESCE(did < :did_lt, TRUE) AND
COALESCE(you = :you, TRUE) AND
COALESCE(just = :just, TRUE) AND
...

i use that pattern and unironically donīt see any problem with it tbh

other perhaps than that the condition should be written as "(:what is null or :what = what)" to make it easier for the engine to short-circuit missing parameters, but i expect that modern dbs can figure it out either way

Deffon
Mar 28, 2010

NihilCredo posted:

i use that pattern and unironically donīt see any problem with it tbh

other perhaps than that the condition should be written as "(:what is null or :what = what)" to make it easier for the engine to short-circuit missing parameters, but i expect that modern dbs can figure it out either way

Query planners choose and reuse an execution plan based on the prepared statement alone, not the particular invocation. Even if you have an index on one of the columns, and happen to only use that column for a query, it will probably choose a full table scan.

Powerful Two-Hander
Mar 10, 2004

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


imo this is unironically the time to build the SQL statement in the caller to avoid having a proc with 20 parameters that will almost certainly create a hosed up plan

Shaggar
Apr 26, 2006
assuming your tables are properly indexed, a proc with optional parameters is basically the example of when to use OPTION(RECOMPILE)

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
fyi for those using databases other than mssql, which for this thread i assume is most of you: normally with stored procedures, the query planner caches the plan from the first call and reuses it for subsequent calls. if you don't want this, for reasons such as those posted above, you can always use dynamic sql in the proc. or if you're using mssql, you can write option(recompile), which is a stupid name because recompilation is not the important step, it's re-planning, but when was microsoft ever known for giving anything a good name?

Corla Plankun
May 8, 2007

improve the lives of everyone
im a page late but just wanted to say that tinkerpop gremlin is the funnest name for a technology i;ve encountered irl but thats literally the only thing i remember about using it so idk if it is any good for anything

Shaggar
Apr 26, 2006

DELETE CASCADE posted:

fyi for those using databases other than mssql, which for this thread i assume is most of you: normally with stored procedures, the query planner caches the plan from the first call and reuses it for subsequent calls. if you don't want this, for reasons such as those posted above, you can always use dynamic sql in the proc. or if you're using mssql, you can write option(recompile), which is a stupid name because recompilation is not the important step, it's re-planning, but when was microsoft ever known for giving anything a good name?

its recompiling the proc/plan

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
didn't mysql use to not cache prepared statement plans and just recompile every single time? hell, maybe it still does. i'm sad i haven't done any db stuff in like 10 years, but the silver lining is that it's also guaranteed i'd never have to touch mysql during that time so maybe it's not so bad

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
the crown of shittiest dbms used for depressingly serious data has been definitively passed on from mysql, mind you

sb hermit
Dec 13, 2016





NihilCredo posted:

i use that pattern and unironically donīt see any problem with it tbh

other perhaps than that the condition should be written as "(:what is null or :what = what)" to make it easier for the engine to short-circuit missing parameters, but i expect that modern dbs can figure it out either way


what is null
baby don't hurt me
don't hurt me
no more

sb hermit
Dec 13, 2016





DELETE CASCADE posted:

fyi for those using databases other than mssql, which for this thread i assume is most of you: normally with stored procedures, the query planner caches the plan from the first call and reuses it for subsequent calls. if you don't want this, for reasons such as those posted above, you can always use dynamic sql in the proc. or if you're using mssql, you can write option(recompile), which is a stupid name because recompilation is not the important step, it's re-planning, but when was microsoft ever known for giving anything a good name?

buddy, this is the lovely programming thread.

naming things is hard.

DELETE CASCADE
Oct 25, 2017

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

sb hermit
Dec 13, 2016





DELETE CASCADE posted:

yeah i'm bad at it too

:same:

:smith:

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
naming things is so hard that 'naming things' is not even a good name for the act. so 'naming things is hard' is a fully recursive statement in and of itself

see h wayne's thingy about it

https://buttondown.email/hillelwayne/archive/naming-things-is-a-poor-name-for-naming-things/

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
every time i want to call it the thing-doer i briefly think to myself, "hmm, perhaps marketing is not complete bullshit after all?", but then the moment passes and i remember how useless they are at naming things too

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
they renamed 'rapeseed oil' 'canola oil'. that was a worthwhile act

matti
Mar 31, 2019

im pretty good at naming things

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER

bob dobbs is dead posted:

they renamed 'rapeseed oil' 'canola oil'. that was a worthwhile act

it's just another example of americans being proud for being italians and ashamed of being german

sb hermit
Dec 13, 2016





I always saw hot dogs as german cuisine's influence on america

and now hot dogs are considered as much of a part of americana as baseball and apple pie

https://www.cnn.com/travel/article/hot-dog-classic-american-summer-food/index.html

distortion park
Apr 25, 2011


using node.js is just a constant stream of disappointment. so many libraries and frameworks look ok but are just missing important bits of functionality or have hosed up models

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

distortion park posted:

using node.js is just a constant stream of disappointment. so many libraries and frameworks look ok but are just missing important bits of functionality or have hosed up models
to be fair, it's not as if you weren't warned by threads such as this one

redleader
Aug 18, 2005

Engage according to operational parameters

Plank Walker posted:

maybe, I think string literal unions are what I want/need. the use case is I generally want them to be serialized as strings to they can be passed to some backend APIs where the input is a string, but not any old string, just one option out of a handful, or vice versa with an API that returns a string value from a known set of strings

we use something like
code:

const ButtStatus = {
    Shidding = 'shiddin',
    Farding = 'fardin'
} as const; // as const is important here

type Butt = {
    status: typeof ButtStatus[keyof typeof ButtStatus]
};

// then you can do
const a: Butt = {
    status: 'shiddin'
};

// and
const b: Butt = {
    status: ButtStatus.Fardin
};

the typeof Thing[keyof typeof Thing] is annoying so we have a utility type type ValueOf<T> = T[keyof T] and use it like ValueOf<typeof ButtStatus>

is it better than ts enums or string literal union types? nah. is it basically the same as an enum but a bit more awkward to define? a little, yes

i get the feeling the ts lang team regret creating enums because there isn't (yet?) have a corresponding js equivalent. and the docs have some warnings about using enums with modules that i'm not js-brained enough to understand so i avoid them


MrQueasy posted:

Enums work well for that too if you want to hang more information than just a value (like schema defs, etc) off the string.

yo, what do you mean by this?

NihilCredo
Jun 6, 2011

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

Deffon posted:

Query planners choose and reuse an execution plan based on the prepared statement alone, not the particular invocation. Even if you have an index on one of the columns, and happen to only use that column for a query, it will probably choose a full table scan.

imo either all the columns are indexed, or none are

if for some reason only some of the columns are indexed, i would have two search functions, a regular 'search' for indexed columns only and a 'slow_search' for any column

application developers shouldn't be expected to have to look at indexes to figure out which functions to call, so if the perf characteristics are drastically different based on parameters i would make it clear in the api



also for postgres, the equivalent of option(recompile) is `set plan_cache_mode = force_custom_plan`. there's a ton of other options you can set as well: https://www.postgresql.org/docs/14/runtime-config-query.html

NihilCredo
Jun 6, 2011

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

DELETE CASCADE posted:

every time i want to call it the thing-doer i briefly think to myself, "hmm, perhaps marketing is not complete bullshit after all?", but then the moment passes and i remember how useless they are at naming things too

i've used more synonyms for "worker" in code than a mid-20th century leftist party schism

Captain Foo
May 11, 2004

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

NihilCredo posted:

i've used more synonyms for "worker" in code than a mid-20th century leftist party schism

lol

mystes
May 31, 2006

Web comrades and comrade threads

Sapozhnik
Jan 2, 2005

Nap Ghost
class Traitor extends Worker implements Supervisor

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

rm warsaw.pak

Corla Plankun
May 8, 2007

improve the lives of everyone

matti posted:

im pretty good at naming things

imo naming things isn't hard at all if you spend like 20 minutes thinking about stakeholders but in my experience most developers consider this act to be below them

CPColin
Sep 9, 2003

Big ol' smile.
All the developers snicker as the boss laments, "I don't get it. I've been eating all this celery but our Concurrent User Metric hasn't increased at all!"

MrQueasy
Nov 15, 2005

Probiot-ICK

redleader posted:

yo, what do you mean by this?

Whoops, I misremembered how un-powerful Typescript's enums are compared to Java/Python.

I forgot that typescript doesn't let you create things like

code:
# NOT A THING IN TYPESCRIPT
const x : SomeEnum = userInput.getSomeEnum();
x.doSomethingFancy(); // no if-statement inside... 

// YOU HAVE TO DO THIS INSTEAD:
doSomethingFancy(x); // contains an if statement
I love using types to get rid of IF statements...

Sapozhnik
Jan 2, 2005

Nap Ghost
right but instead of using actual enums you'd want to use discriminated unions instead.

type SomeEnum = ("shid" | "fard") & { doSomethingFancy() };

is a valid type in typescript

Powerful Two-Hander
Mar 10, 2004

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


"hey we think that this queue needs to have our new hosts added to an allow list so we can publish, can you tell us how we do that?"

"well it depends, did you add the hosts to the allow list first?"

don't gently caress with me middleware :mad:

MrQueasy
Nov 15, 2005

Probiot-ICK

Sapozhnik posted:

right but instead of using actual enums you'd want to use discriminated unions instead.

type SomeEnum = ("shid" | "fard") & { doSomethingFancy() };

is a valid type in typescript

Yes, but how do you use it? (This is the type of awful cleverness I love)

Sapozhnik
Jan 2, 2005

Nap Ghost
use it to do what? you're the one who produced the original example

MrQueasy
Nov 15, 2005

Probiot-ICK
I mean... in java I can do something like...

code:
enum SomeEnum {
	shid("liquid", () -> print("your mother")),
        fard("gas", () -> writeToFile("gambled and won"));

	String state;
	Supplier<Void> something;

        SomeEnum(String state, Supplier<Void> something) {
                this.state = state;
		this.something = something;
        }
     
       public void doSomething() {
           this.something.apply();
       }

       public String getState() {
           return this.state;
       }
  }
  
To be able to write code that does:
code:
public void example(SomeEnum se) {
    se.doSomething();
    saveToDatabase(se.getState());
}
instead of
code:
public void example(SomeEnum se) {
    if (se == shid) {
        print("your mother");
	saveToDatabase("liquid");
    } else if (se == fard) {
       writeToFile("gambled and won")
       saveToDatabase("gas");
    }   
}

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost
type SomeEnum = ("shid" | "fard") & { something(): string };

function one(): SomeEnum {
const x = "shid";
x.something = () => "asdf";
return x;
}

function two(): SomeEnum {
const x = "fard";
x.something = () => "fdsa";
return x;
}

why you'd want to do this is a whole other question but javascript is terrible, strings are objects, and you can add properties and indeed delete properties on any individual object you please.

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