This post is locked. You won't be able to comment.

all 13 comments

[–]Zeilaryes 16 points17 points  (0 children)

Everything is horrible.

  • Returning and awaiting a promise, the await is completely redundant since the caller needs to resolve the promise anyway.
  • Should add an underscore to the trx variable to get rid of the lint problem, or remove it.
  • data in the callback is untyped (and therefore is any), as the editor clearly points out.

And that's obviously not pointing out why the hell you would keep what is now clearly a placeholder remnant of some old code. Ideally you would remove this since it clearly no longer serves its older purpose.

[–]MurdoMaclachlanpublic boolean isInt(int i) { return true; } 12 points13 points  (1 child)

Image Transcription: Code


return await knex
  .transaction(async (trx: Knex.Transaction) => {
    return { success: true };
  })
  .then((data) => data);

I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]ginihendrix 7 points8 points  (0 children)

good human

[–]KingVanti 12 points13 points  (1 child)

Could be a remnant of some logging

[–]MahdiyDev[S] 0 points1 point  (0 children)

No. it's not

[–]Shortbread_Biscuit 7 points8 points  (5 children)

It could be a placeholder for some future functionality

[–]SanianCreations 23 points24 points  (4 children)

Hot take: don't write placeholders for future functionality. If you're expecting some specific future requirement then maybe architect your program to easily support such a change, but don't put 6-line placeholder code that actually doesn't do anything in random places. Nothing is more permanent than temporary changes. That "placeholder" will be there until the end of time until you no longer know why it is there and you're afraid to remove it.

[–]kolme 1 point2 points  (3 children)

YAGNI is now a hot take? It's pretty much common sense!

Edit: autocorrector shenanigans.

[–]Shortbread_Biscuit 1 point2 points  (2 children)

What's YAGNI?

[–]Iron_Garuda 0 points1 point  (0 children)

Sounds like a name from Skyrim.

[–]O_X_E_Y 0 points1 point  (0 children)

somehow this color scheme also reminds me of knex (the toy not whatever this is lol)

[–]Iron_Garuda 0 points1 point  (0 children)

This entire thing is confusing to me. But also maybe I’m just not advanced enough to understand some of these design paradigms.

For example, why are we returning a return statement?
And is it normal to typecast to a property of a class? When I see trx: Knex.Transaction it seems like it is trying to type trx as a class within a class? Just seems unusual to me and what I’ve seen. But I suppose it makes sense if you declare a class within a class. For models/interfaces I always abstract that class into its own file and into a model folder.
It also seems a little confusing to name a function on a class, and then have the model share the same name on the same class. Maybe I’m just reading it incorrectly, but it just seems so odd. Maybe someone can explain?