So I've been forced to work on a project for some time using JavaScript

Many parts of it must function synchronously and js has a lot of libs and otherwise that will spawn threads in threads

I'm horrified by the amateurish appearance of my code

Await this await that
Everything enclosed in something else and what is worse is the base node modules I'm using are ALL asynchronous! Were talking methods that one consistently has to wait on finishing like db reads !

Why is js so dumb ?

  • 2
    I don’t understand your problem. “Many parts of it must function synchronously” who added that requirement?
    Also JS is single-threaded.
    If it’s just a script that you’re running from the shell node after version 18 I think supports awaiting within the global scope. If not create a “main” async function and kick it off the process won’t exit until that function is done.
  • 4
    Also DB reads are like a perfect example of being async. Why would you wanna block the event loop for an IO operation?
  • 4
    "i am horrified at the amateurish appearance of my code"

    nah, buddy, that's not you, that's JS.

    in JS, you code can either be a psychotic incomprehensible mess, or horribly amateurish (looking) . JS doesn't support any other options.
  • 1
    "js is single-threaded"
    but also heavily concurrent. he meant logic flow threads, meaning whether they're done by actual multithreading or single-threaded concurrence is irrelevant, i'd guess
  • 2
    @Midnight-shcode oh I wish I could show you our codebase… it’s a private repo 😢

    People don’t know how to write proper code and blame the language.
  • 2
    "people don't know how to..."

    i agree. but also, if it's JS, they're correct.
    watch some talks about language design. designing language in a way that enables, motivates, or even enforces good code writing styles is one of the main topics, and for a good reason.

    JS fails all of the points i ever heard and had explained o n that front.

    you can write shit code in any language.
    however, in a shit language, it's the default way of writing code, and anything else requires extra effort. in a good language, writing shit code required extra effort/incompetency.
  • 1
    usually, it's the annoying limitations of the language which enforce/facilitate better code.

    such as strong typing.

    peope get annoyed because they are being banned from taking shit lazy shortcuts
  • 0
    Well that’s why typescript was introduced. I thought it was assumed.

    Vanilla JS automatically gives you spaghetti code.

    TS + JS = the type enforcement of Java/C# etc + the flexibility of python
  • 0
    @TwentyMinuteMan you mean wrap the main code in an anonymous adync function to do an await I should be able to do in the main scope or any function at all without extra decorators and keywords ? Wow why wasn't I embarrassed already to have to do that!
  • 0
  • 2
    @TwentyMinuteMan it's because js as a language sucks donkey balls !
  • 1
    @TwentyMinuteMan typescript a compiler that back ends workarounds to shitty js lol
  • 4
    Well there are two types of language in this world:
    1) The ones nobody talks about
    2) The ones everybody complains about
  • 0
    @TwentyMinuteMan why not just make a.default await context that could be set per method of scope ? You know and why do functions have to be be marked async to contain an await which tells an async function to be synchronous ?/doesn't make sense you're basically doing a thread await or thread join ! More like a thread join by really.
  • 1
    @TheWrongGod elaborate on the context business.

    Because sometimes you don’t care about the async function running synchronously sometimes you do. Would you like to rewrite the same function twice? Once async once sync?

    Async functions and threads are different things. Even in C++ or wherever you learnt that terminology there’s a separate concept for asynchronous functions vs threads.
  • 0
    @TwentyMinuteMan I think you shouldn't have to make everything async that calls await

    That's the meat of it
    Its redundant

    And many of the things that are async like sqlite make no sense to me
  • 0
    @TwentyMinuteMan unless you had a processing thread that had a shared collection why would you make database and file system and io calls default to async ? And why would blocking till a call resolved require a function to he async. Usually you time out blocks so there is no thread lock

    I just don't like the extra typing or the uncertain return types etc
  • 0
    @TheWrongGod say that to phyton, please.

    Mfs make me await shit i don't want to await.
  • 0
    @TheWrongGod ok, here is a perfect sync file system example:

    There is incoming data and it's estimated to be around 3GB.

    Because of redundancy issues with not using same hard drive models, you can write 4MB to the buffers and wait a second for the next fragment.

    Your fs have a hard set 30 second timeout, just in case an operation doesn't progress.

    Now, tell me, how do I read another file while also writing the incoming data to the disk?
  • 0
    > Many things that are async like sqlite doesn't make sense go me

    Have you heard about network latency?

    A good app/component/micro-service should do it's best to respond as soon as it can, so if you don't have it on a cache you will make a request and send it.

    Now, what if a request came, asking for uncached data, and then another one asking for cached data.

    What do you do then? Your request can be made to a file and to a server. It can be the simplest thing in the world or it can query and filter 10k rows, across tables.

    If you don't cache and async things, you will easily reach a lock, troubleshoot what is wrong, and see you spend 99% of the time at waiting for network.
  • 0
    @melezorus34 ahhh but you can exp licitly types vars in python
  • 0
    @melezorus34 well see that's two threads doing different things

    Which is my point
    It's synchronous operations being carried out in two threads that communicate

    Js seems to make everything a worker thread that requires extra markup to wait on things or else terrible spaghetti code

    It's syntax sucks
  • 0

    > have to be marked async (...) which makes the async function syncronous

    That's the point of async. It let's other things to be made.

    > It's the meat of it, it should be redundant

    Ok, don't await any async function, make all async functions use a context variable which the function can fill.

    The main function will eventually need something from the async functions. How will you know it's done? Let's say you can figure it out, here's another question then:

    What will you do when you need data but it's not ready? Loop nop until it's ready? Well, it will never have time to execute, so it will never be ready.

    Even in c++, where you can sleep within the function context, you still won't give the async function any time to execute it's magic.
    Hence why we async-wait it.
  • 0
    @melezorus34 yes but yet again youre describing something that is more fire and forget like a queue where one operation doesnt wait on data from another

    And for the record sqlite doesn't use the network
  • 0
    @melezorus34 this would be easier to debate in a chat

    From my stand point traditional collections locking thread waits with timeouts etc when they have their uses are better

    But everything and it's mother shouldn't require special handling if I want program flow yo be first one statement then the next then the next
Add Comment