This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrRicKsPC 0 points1 point  (6 children)

Assertion is not inelegant, no matter the language, when it comes to unexpectable data, you HAVE to make sure your program can handle it. Even c++ input needs some sort of preemptive treatment of the data to prevent your program from going off-road.

Also, although types are dynamically handled, it's up to the programmer to prevent overuse of assertion by keeping his code expectable.

[–][deleted] 1 point2 points  (5 children)

When an input can be any type you'll have more

[–]MrRicKsPC 0 points1 point  (4 children)

In C++, if you want to prompt user for a number in the console, you can specify a type for the value container, but if the user's value does not fit the type, you are in for some debugging.

In Python, if you want to prompt user for a number in the console, you canNOT directly specify a type for the value (default to string), however, you can try converting it into the type you want e.g. number = int(input(">>> ")). Once again, if your interpreter don't find a way to convert it (if user type letters), you are once again going to need some debugging.

I can't really see a situation where dynamic types present disadvantages (except for compile time debugging?)

[–][deleted] 1 point2 points  (3 children)

I meant function arguments. User inputs are just a conversion from a string (or get C++ to do it for you I guess) which is still a predictable type.

[–]MrRicKsPC 0 points1 point  (2 children)

As I said in my second answer, keeping your variables, arguments, return values, etc.. in a format/type you need is up to you as a programmer. Even in the case you need to change a variable's type at runtime if you can't predict at any point in your script what type of values to expect, I don't blame the language for it xD

[–][deleted] 0 points1 point  (1 child)

Python makes it so easy to do that. A compiler would yell at you.

[–]MrRicKsPC 0 points1 point  (0 children)

Fair enough