Hacker News new | past | comments | ask | show | jobs | submit login

Well i'v never understood the problems with JavaScript but maybe it's because i haven't done things how other languages do it. But js is very "open" and bound free. Especially with functions and objects. They make sense to someone who is new to OOP. maybe its not follow how things are usually done in other languages but that does not mean its necessarily a bad thing. If you think something doesn't make sense that does not mean its wrong. i am learning c and i have to say typed variables must be faster but they are difficult to gasp at first. In fact its a nightmare to make variables of a certain type, it limits my thought process when i have to think what the variable's type is after every line of code. Strings look like a huge deal. The fact that i have to predetermine the length of a string is laughable. Its my string and it can be as long as i want it to be anywhere in my code. (yes i now sound immature but this is my experience until now, call it a rant if you may) Alot of things need to be known before we can write a meaningful program. Thats not the case with js or even with php to some extent.



These difficulties in C are not "craziness", they are for very good reasons.

Unbounded strings have much more complex and potentially less optimal semantics than bounded strings, need to be allocated in different ways, etc. C makes tight resource control possible, and to do that it sacrifices a lot of ease. You have to think about resources when programming. In many scenarios, this is a good thing.


>C makes tight resource control possible, and to do that it sacrifices a lot of ease.

I'm not a C programmer (yet), but I would say that depends on what you define as "easy" or "simple". What I am is an Arch Linux user, and I embrace KISS - Keep It Simple, Stupid. Arch understands "simple" as "technically elegant and uncomplicated", but that doesn't mean it's easy to understand or foolproof to use - for the inexperienced user, that is. C is an incredibly powerful tool exactly because it is this kind of simple.

What I also am is someone who learned programming with Python, and I initially couldn't understand the appeal of C-oid languages either. But I've since realized it's all about using the right tool for the job. A programmer is a mechanic, and a mechanic that only knows how to use a hammer is a pretty useless mechanic (in general, of course. If all you deal with are nails then it's not an impediment to your abilities).


There's of course the view that a programmer is a mathematician :-)

But I agree we need various tools to cover the necessary ground.


Yes, i agree. I was not offending C, i was just defending JS buy using C as an example. I have said this below but will say again. C is as much crazy to me as is JS to some other people. this does not make C evil.


> it limits my thought process when i have to think what the variable's type is after every line of code

Why do you feel the need to think about the variable's type on every line though? Since they're typed, you should pretty much know exactly what they are, instead of trying to figure it out. Since they're not dynamic, they're never changing.


let me give an example. there is no easy or straight forward way to make a string's length variable. i cannot for example do something like 'int string1[n]' where n is something i got through scanf. also there are different functions to get user's input for intigers and strings. Why would anyone have so many different things like scanf, getch, getche, gets, etc. why not make one simple function and take other things as an argument?

So i need to stop and think how can i input a variable from user, which function should i use. I was just defending js. I don't oppose C, i am just saying its about perspective. C is as much crazy to me as is JS to some other people. this does not make C evil.


One simple example: when you read a telephone number, you care very much whether it's a string or an integer. The reasons are:

- 004412......... and 4412..... are completely different things. You care also about how you annotate base of integers, because anything starting with "0" might be an 8-base integer.

- Even if we assumed local numbers don't start with 0, there are some places where such number doesn't fit into an integer. 32b int is only 10 digits in dec base.

So yes - whether it's C or JS you should very much care what the actual type is. This isn't very theoretic either. Some time ago, twitter started using id which were larger than 32b fields. Even though people should've been treating those ids simply as opaque strings, some used integers, leading to twitter client update panic.


well yes but i was talking about how it's stored in memory. Like in js all the numeric operations can be performed on strings that are just numbers. Think of it as an intelligent string that behaves according to it's contents. if it's contains an integer, it behaves like one. since there are finite number of types a variable can have, it shouldn't be a huge deal to automate this. But since this has not already been done, i am obviously missing something here.


No, it doesn't. If it's a string, it's a string: "1" + "1" -> "11". I know what you mean (it would if the first op wasn't a string), but see how this got confusing even in your short message. I'm still not sure why would you want to automate all types into a magic one that does what you want... unless you split all operators into N distinct ones giving you different results. But then you get the same result really - ops determine your results.

Again using phones example:

country + area + ending

is different depending on what the actual types are. This is simply an issue we cannot ignore. In this case I'm expecting the concatenation and the result cannot depend on "contents of the string".


I wouldn't really consider C that much of a statically typed language, with all the pointers and casting and low level stuff. Have a look at Haskell/ML/Ocaml if you really want to see a type system that will blow your mind :)


You can say that this is more of a first world developer problem but i am still an ammature (as you might have guessed) and i have started to kind of dislike typed languages. i like my space and freedom to put text or integer or float or blob or raw binary data in a variable. because mostly it all ends to string, everything can be a string, numbers, floats, characters all of them. so why not make devs life easy by making everything a string?


Because in strongly typed languages the compiler is able to hunt down the most of the bugs for you in milliseconds. That's why haskell programmers suggest that if a haskell program compiles gracefully, you can assume is mostly correct and bug free.


Because someone is paying for the code you write to do predictable things that they want.


"The fact that i have to predetermine the length of a string is laughable... Thats not the case with js or even with php to some extent."

It's not laughable. Most implementations of JS and PHP are probably written in C or C++. While using dynamically allocated strings in higher level languages like these are indeed easier than null terminated strings in C, at some point someone somewhere had to write code at a lower level to support this.


> at some point someone somewhere had to write code at a lower level to support this

Yes that is something i totally agree with. In fact that's why i only supported js and not hate c. Because somewhere it has to be done and c is efficient in dealing with memory allocations whereas js deals with front-end mechanics. But to say that js is 'crazy' is something beyond me. every language has its ways and it depends on what 'level' (high, low, machine) that language works in computer hierarchy.

Comparing high level language like js to lower level language (like c++, java, etc) on their syntax or how it deals with objects/arrays makes no sense.


Well, given that javascript was designed in somehow less time and with less resources than superior languages it has obviously some inconsistences and everybody agrees on that. On the other side if you know the language really well you can avoid the most of the problem it has. I like your point of 'keep it real' but you need to accept that the language is far from 100% correct.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: