30

I come from PHP and have been using jQuery as a crutch for years. I've dabbled in Node and obviously writing some vanilla JS is unavoidable, but now I'm starting to use ES6 with Babel and VueJS and the more I dig in, the more I hate javascript. Everything is an object (null, array), there seems to be a few gotchas with math (including the one pictured), nothing is strongly typed but types are very important (for instance, you can't loop an object and an array using the same code), and there are a lot of inconsistencies/functions missing. ucwords for instance. Why doesn't that exist? typeof only returns object, but Array.isArray and Object.isObject work fine. I'm going to give typescript a go soon and cross my fingers.

Comments
  • 3
    I know exactly what you mean. JS allows us to build great things, don't get me wrong, but it's a fucking mess
  • 6
    How you can call js a mess when you come from php is beyond me 🙃
  • 3
    That said, it really looks like you're trying to write some php in js instead of actually learning the language. While there's some merit in using what you already know, it's also the best way to misuse a language and get frustrated.
  • 4
  • 2
    PHP is a fucking mess, but I like that mess.
  • 2
    PHP has come a long way and despite the little problems that autocomplete mostly solves (like parameter ordering), it's a solid backend language for the web. PHP 7 is a whole new animal and people who diss PHP are ridiculous. Get off your high horse and recognize that each language has it's pros and cons. Stop bitching about the state of PHP in 1995 and try it today...everything evolves, except your opinion apparently...
  • 0
    @Commodore I'm not an idiot, don't treat me like one. The reasons I'm frustrated are perfectly legitimate.

    For instance, JSON encoding an associative array in PHP and decoding in JS will give you an object, but if that associative array is empty, you end up with an array in JS.

    Two options I've found that work best:

    1) Convert the array to a new StdObject() in PHP before encoding
    2) Run a conversion of expected objects in JS

    I went with #1, but hate the extra code.

    I like that everything is an object in theory, but I don't like that typeof returns object instead of a more specific type or an object with the generic and specific types.

    I don't know how anyone could argue that a consistent syntax for looping arrays and objects would be a bad thing....

    ucwords may not be used a ton, but it's a basic function that should exist like .toLower() does...

    I really don't understand how you can deduce that I'm misusing the language by my comments....You're just being a dick.
  • 0
    @Commodore

    Man...I'm seriously irritated by people like you who say shit like that.

    PHP and JS are obviously not the same language and were built for different use-cases, but there is overlap and there are conventions in programming that are language agnostic.

    I'm mad that it isn't strongly typed, someone created Typescript to solve that, and you are cool with their implementation, but tell me I'm misusing it...what the fuck?
  • 0
    I think my #1 problem with vanilla JS is how verbose it is. There just aren't enough helper functions like there are in jQuery (or just about any library).

    Checking element visibility, replacing an element, etc. All too verbose.

    Between this and browser compatibility, it's obvious why I stuck with jQuery all these years.

    I really never had to write a whole lot of JS. Event handlers and AJAX calls mostly.

    I will say, of all JS I've worked with, I'm really enjoying Vue (for the most part). Primarily due to the data binding and watchers.
  • 1
    "yOu'Re UsInG iT wRoNg"

    JS fanboys say you should create everything as an SPA because "that's the future" but then when you start migrating logic to the front-end, suddenly your understanding of classes, interfaces, types, etc is irrelevant...
  • 0
    @Stebner55 first off my first comment was a troll, because, well, php.

    I didn't say you were misusing js, I said it felt like it. What put me on that train of thought was your comment on everything being an object and the impossibility to loop over an array like you would over an object. Because yes, not every object is an iterrable and that's the case in many languages if not most of them.

    As for ucfirst, yes it doesn't exist in js because it should be handled in css. Otherwise you would be, you know, misusing the language.

    Last but not least, it's not like JSON stands for javascript objet notation, so yeah sure blame js for not being able to reliably decode the mess php puked.
  • 0
    @Stebner55 also, insecure much? Jeez...
  • 0
    @Commodore

    So you're the ucwords authority then? It's not acceptable to fix proper names that were just input by the user before displaying them and sending them to the backend to be stored in a database?
  • 0
    @Commodore

    All I'm asking for is a single, consistent method of iteration. Your comment on passing an invalid object is irrelevant. You can pass bad data to any function and get an error....
  • 0
    @Commodore

    You're right about the JSON issue. It's not javascript's fault that JSON doesn't include types. The reason I never ran into it before is because it didn't matter. jQuery has a consistent API for looping.
  • 0
    Also, why doesn't this exist natively in the language?

    function isIterable (value) {
    return Symbol.iterator in Object(value);
    }

    Since everything is an object, it would be cool if you could just say
    If( obj.isIterable() ){
    }
  • 0
    @Stebner55 yes it could be, but that's just the thing, you're wasting time, and by the looks of it, a bit of sanity, by focusing on why js doesn't behave the way you want it.
    Learn why the language has been created, which problem it has been intended to solve, and build from there.

    Lastly, capitalization is formatting, you said it yourself, ergo style. Therefore Cascading Style Sheet. No need be an authority, which I'm certainly not.
  • -1
    @Commodore

    Ok, if that's the case then remove all functions related to formatting. .toLower() needs to be destroyed because Commodore knows best!...
  • 0
    @Commodore

    It's not that JS doesn't behave the way I want. That's a strawman. It is extremely flexible and does everything I could ever want...what it doesn't do is make everything easy. You act like vanilla JS has it all figured out and there's no need to question it or improve it. If that's the case, then why do almost all JS developers rely on a library or framework to provide them with exactly what I'm asking for?

    You're just arguing to argue...
  • 0
    @Plasticnova

    it's a mess but it's OUR mess.
Add Comment