Live data from Hacker News

For modern development Javascript indeed is a shit language

live.julik.nl

231–240 of 243 posts

Re: For modern development Javascript indeed is a shit language

#231
post #222

Earlier quoted context omitted.

> Clearly possible to fix code that's in branches/working trees that you don't even have access to?? This is a non-issue - if you're using unstable libraries then that's your own problem and breakages are to be expected. This is not the fault of JS. > When you change function signatures, code that calls those functions is broken. In static languages the breakage is a compile-time error. In dynamic languages the break…

It seems you are misunderstanding me. I am not talking about library APIs here. I am talking about internal function signatures inside a single product developed by multiple codevelopers. All your replies about external APIs changing are irrelevant. A codeveloper touching functions that call your functions or defining functions called by you will integrate with your work with an innocuous "git pull" and force you to…

> All your replies about external APIs changing are irrelevant. A codeveloper touching functions that call your functions or defining functions called by you will integrate with your work with an innocuous "git pull" and force you to review everything just to rule out what JS could have easily detected.

Everything that you didn't write yourself is an external API for all intents and purposes - you're using somebody else's code, regardless of whether that person 'owns' the code or not. The fact remains that if you're relying on a function and somebody changes it without considering the consequences, then that's a process issue, not a JS one. In the same way, if you're writing code which others may depend on, then you need to consider the potential consequences of your changes.

> Again, I'm not talking about "dependencies" or libraries here at all.

The point is that you should be talking about dependencies and libraries. The situation you're describing is one in which code is not properly modularised and organised - where any developer can change any function and thereby fuck up the rest of the project. If your code was organised properly, these problems would disappear.

> The push was completely benign. The integration of that push with your current work will be broken in cryptic ways. Not necessarily ones that show up in the testing suites.

You keep using the word 'will'. I'm telling you with hand on heart that this problem does not happen if you sort out your development team and project structure.

> Every single function signature can break things, not just exposed APIs.

Yes, it can break things, but it shouldn't.

> Two developers might work on the same piece of code. There's not necessarily any obvious point to notify here and still breakage may arise.

If two developers can't work on the same area of code without stepping all over each other, then you need to look at how you're structuring your code.

> 1) Developer A adds a new function FOO that calls internal function BAR in his unpushed working tree. > 2) Developer B changes the signature of internal function BAR, and pushes this change to "master". > 3) Developer A pulls from master, his code is now broken, but JS doesn't even warn him when he executes it. Instead, wrong results (or accidentally correct results for any given test case) arise. > 4) The test suites don't catch the error. Developer A unwittingly pushes the broken code to master.

Why is developer B changing the signature of function BAR willy nilly? Code isn't written in isolation and your changes have an effect on other developers. If you have a function which is being used by other people - then you have a public API. You don't break an API randomly.

Re: For modern development Javascript indeed is a shit language

#232
post #195

Earlier quoted context omitted.

So how should [1, "a", 2, 3] be sorted by default?

Both Python and Erlang would return [1,2,3,"a"], Ruby and Clojure won't allow the comparison. Either of these approaches makes more sense than JavaScript's.

Javascript returns [1,2,3,a]. What's the problem.

Re: For modern development Javascript indeed is a shit language

#233
post #208
post #150

Earlier quoted context omitted.

> Because you don't have to write a lot of boilerplate to tell the language things that it should be able to figure out for itself. This is exactly my point; compiler can't figure out what kind of data I want, at least not in general. A good example is jQuery $.data() which tries to guess what kind of data you have in your HTML tag attribute. Guess what happens if you have a MongoDB ObjectId (as string), for instance…

Guess what happens if you have a MongoDB ObjectId (as string) But that's a matter of semantics, not static typing. You're going to have to do type conversion on the string regardless, because "MongoDB Objectid" isn't a native type for the compiler. But with static typing, you need to tell the compiler the type of the variable in addition to telling it how to do the type conversion: for example, in C++, you might have…

Actually in C++11 you can just say:

    auto id = mongo::OID("1234...");
This gives you much (not all) of the brevity and flexibility of dynamic typing, while maintaining the power and safety of static typing.

Re: For modern development Javascript indeed is a shit language

#234
post #222

Earlier quoted context omitted.

It seems you are misunderstanding me. I am not talking about library APIs here. I am talking about internal function signatures inside a single product developed by multiple codevelopers. All your replies about external APIs changing are irrelevant. A codeveloper touching functions that call your functions or defining functions called by you will integrate with your work with an innocuous "git pull" and force you to…

> All your replies about external APIs changing are irrelevant. A codeveloper touching functions that call your functions or defining functions called by you will integrate with your work with an innocuous "git pull" and force you to review everything just to rule out what JS could have easily detected. Everything that you didn't write yourself is an external API for all intents and purposes - you're using somebody e…

So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit.

Your question about why a developer would need to change an internal function's signature is ridiculous. Maintaining code involves changing function signatures all the time. If another developer is working within the same API boundary, he's screwed.

This isn't a necessary fact of life. Even most sane dynamic language will error out when such incompatibility arises, instead of blaming the developer for using a process incompatible with the js way.

Not to mention the other argument, that with all the discipline in the world, humans will still make mistakes. Instead of translating to errors, they translate to bugs.

The gain? not having to use an asterisk when you want varargs. That's just stupid.

Re: For modern development Javascript indeed is a shit language

#235

Earlier quoted context omitted.

Yes really. It's an OO language based on Self's prototypical OO model rather than a class based OO model. Prototypical OO is still OO, unless you're claiming Self isn't OO, but the Smalltalker's who invented Self would very much disagree. Prototypes are objects, no closures or classes required.

Ah, I stand corrected, thanks. Makes sense; I think I had something about private vars in JavaScript and closures running through my head and confused it with 'JavaScript does OO with closures' :)

No problem.

People who don't like or get prototypes have certainly reimplemented classes with closures, but classes are not a requirement to be OO, objects are; classes are just one way to do it, prototypes are another. Objects don't require classes, though many a JavaScript programmer thinks so.

Re: For modern development Javascript indeed is a shit language

#236
post #234

Earlier quoted context omitted.

> All your replies about external APIs changing are irrelevant. A codeveloper touching functions that call your functions or defining functions called by you will integrate with your work with an innocuous "git pull" and force you to review everything just to rule out what JS could have easily detected. Everything that you didn't write yourself is an external API for all intents and purposes - you're using somebody e…

So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit. Your question about why a developer would need to change an internal function's signature is ridiculous. Maintaining code involves changing function signatures all the time. If another developer is wor…

> So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit.

No, but when somebody I'm working with makes a potentially breaking change to a shared codebase, they either ensure that they also fix the now broken code, or they flag it up to the people whose responsibility that is. Aside from that - most people simply avoid making a breaking change - or if it absolutely must be made, then a process is followed.

> Your question about why a developer would need to change an internal function's signature is ridiculous

I wasn't asking why the developer was changing a function signature - rather why they're so eager to change a function signature without following up and either fixing the things they break, or flagging those things up to the people who require it.

> This isn't a necessary fact of life. Even most sane dynamic language will error out when such incompatibility arises, instead of blaming the developer for using a process incompatible with the js way.

There's no such thing as a random error. If there's an error, somebody made a mistake. Some mistakes are stupid, others are subtle. Changing a method signature and then not doing something about the callers is a stupid mistake.

> Not to mention the other argument, that with all the discipline in the world, humans will still make mistakes. Instead of translating to errors, they translate to bugs.

Of course humans will make errors - but your job is to minimise the frequency and severity of those errors. There's no excuse for sloppiness - you either keep on top of shit, or you don't. Call it whatever you like, but a shitty broken codebase is only the fault of the developers, not the language.

Re: For modern development Javascript indeed is a shit language

#237

Earlier quoted context omitted.

Both Python and Erlang would return [1,2,3,"a"], Ruby and Clojure won't allow the comparison. Either of these approaches makes more sense than JavaScript's.

Javascript returns [1,2,3,a]. What's the problem.

    > [1,2,"10",3].sort()
    [ 1, '10', 2, 3 ]
That's the problem.

Re: For modern development Javascript indeed is a shit language

#238
post #234

Earlier quoted context omitted.

So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit. Your question about why a developer would need to change an internal function's signature is ridiculous. Maintaining code involves changing function signatures all the time. If another developer is wor…

> So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit. No, but when somebody I'm working with makes a potentially breaking change to a shared codebase, they either ensure that they also fix the now broken code, or they flag it up to the people whose resp…

> Aside from that - most people simply avoid making a breaking change - or if it absolutely must be made, then a process is followed.

Changing internal functions is not considered a "breaking change" by anyone I know. You're allowed to refactor code internally, which definitely includes changing the structure of the internal functions.

Other coders who are also working inside the same module/API boundary will have their edits broken by this change. The original developer cannot fix their code because it's not checked in yet.

> rather why they're so eager to change a function signature without following up and either fixing the things they break, or flagging those things up to the people who require it.

I already explained why they can't follow up - because the code that needs the follow up is in their codevelopers' working trees. Flagging here would be silly. Almost every single commit would be "flagged for fixing breakage", since every single commit can refactor/change internal function signatures.

> If there's an error, somebody made a mistake. Some mistakes are stupid, others are subtle. Changing a method signature and then not doing something about the callers is a stupid mistake.

Yes, and we are all human so sometimes, despite heroic efforts, we will all make stupid mistakes as well as subtle mistakes.

Now, once we made the mistake, do we want our tool to insidiously hide this mistake from us, making it as expensive as possible to punish us for our mistake? Or do we want a tool that tells me ASAP "Hey dude, you made a stupid mistake over there"?

> but your job is to minimise the frequency and severity of those errors.

And to do this job, I have tools like languages that help me find those mistakes quickly.

> There's no excuse for sloppiness

Making mistakes isn't "sloppiness", it's human.

> Call it whatever you like, but a shitty broken codebase is only the fault of the developers, not the language

If one language makes writing a non-shitty codebase harder than a different language, it is also the fault of that language.

Re: For modern development Javascript indeed is a shit language

#239
post #238

Earlier quoted context omitted.

> So basically you need to use strict ownership at API boundaries as that is the only way to avoid this. This isn't always optimal. It sounds like you're sacrificing quite a few goats at the js altar for no real benefit. No, but when somebody I'm working with makes a potentially breaking change to a shared codebase, they either ensure that they also fix the now broken code, or they flag it up to the people whose resp…

> Aside from that - most people simply avoid making a breaking change - or if it absolutely must be made, then a process is followed. Changing internal functions is not considered a "breaking change" by anyone I know. You're allowed to refactor code internally, which definitely includes changing the structure of the internal functions. Other coders who are also working inside the same module/API boundary will have th…

> Changing internal functions is not considered a "breaking change" by anyone I know.

If changing internal functions results in breakages, then I don't know what else you'd call it except a breaking change.

> You're allowed to refactor code internally, which definitely includes changing the structure of the internal functions.

If the person changing the function doesn't then go and update all of the callers, then that person isn't doing their job properly. It's not refactoring if you just randomly decide to modify a single function's signature and then don't follow up and fix the rest of the code.

> Other coders who are also working inside the same module/API boundary will have their edits broken by this change. The original developer cannot fix their code because it's not checked in yet.

Not if you're making small commits, often. Changing a function signature necessitates the modification of all callers to that function. This would be a large commit which includes all of necessary changes to ensure that the software remains in a stable state.

> I already explained why they can't follow up - because the code that needs the follow up is in their codevelopers' working trees. Flagging here would be silly. Almost every single commit would be "flagged for fixing breakage", since every single commit can refactor/change internal function signatures.

This is still just a process problem - if you committed and merged more often, these issues wouldn't arise. The reason you're having these issues is because you're allowing your working trees to become too out of sync. If everybody is working on the same module, then those developers should be trying to retain lock-step. Even if developer A (the breaker) doesn't have access to the code of developer B and therefore can't update his function calls - committing smaller changesets and merging more often, where the overhead in assessing changes is tiny, will wipe out 99% of these issues. If you can't see the forest for the trees, then issues are going to slip through.

> Yes, and we are all human so sometimes, despite heroic efforts, we will all make stupid mistakes as well as subtle mistakes. Now, once we made the mistake, do we want our tool to insidiously hide this mistake from us, making it as expensive as possible to punish us for our mistake? Or do we want a tool that tells me ASAP "Hey dude, you made a stupid mistake over there"?

Except in JS, the code itself isn't a mistake. It's your problem - JS has nothing to do with ensuring that you keep your codebase bug-free.

> And to do this job, I have tools like languages that help me find those mistakes quickly.

Then use them, and stop complaining about something that you don't even use.

> Making mistakes isn't "sloppiness", it's human.

Making the same mistake repeatedly and then blaming your tools is sloppiness however you dress it up.

> If one language makes writing a non-shitty codebase harder than a different language, it is also the fault of that language.

It's not harder, it's just different. If you learn the language and its subtleties, then you won't have these problems.

Re: For modern development Javascript indeed is a shit language

#240
post #94
post #11

Sadly I agree, you can just start with this: > [1,10,5,-15,-2,4].sort(); [-15,-2,1,10,4,5] And yes saying "oh but it is because it has weak types" doesn't excuse it, it is broken and that's that. Naming the brokeness with a label or showing why historically it is there, doesn't fix it. On the other hand they do have nice closure support, I do like some of that. But in large, the language makes me angry every time I h…

The sort function is fine when used as intended (for alphabetic sorting). If you want numeric sorting you use sort(function(a,b){return a-b}). [1,10,5,-15,-2,4].sort(function(a,b){return a-b}); [-15, -2, 1, 4, 5, 10]

Ok but if I wanted to use alphabetic sorting I would have used ["1","10","5","-15"] no? Wouldn't that make more sense.
Post reply on HN