Earlier quoted context omitted.
99% of such bugs can be avoided in a weakly typed language by simply having the string concatenation operator different from the "+" operator (PHP has the "." operator for this, VisualBasic has "&" ...Haskell has "++" ) ...yet Javascript, Python and Ruby seem to stubbornly avoid this simple way of achieving some sort of sanity (and yeas on this one PHP is above Python and Javascript!). Also, having " " also work for…
EDIT: My bad, I retract all reference to Python, its dynamic strong typing really prevents these kings of problems. The behaviors I was thinking on happen in Javascript (and sometimes in Ruby as I recollect).
Rust for C++ programmers – part 3: primitive types and operators
41–50 of 68 posts
Re: Rust for C++ programmers – part 3: primitive types and operators
#42Earlier quoted context omitted.
99% of such bugs can be avoided in a weakly typed language by simply having the string concatenation operator different from the "+" operator (PHP has the "." operator for this, VisualBasic has "&" ...Haskell has "++" ) ...yet Javascript, Python and Ruby seem to stubbornly avoid this simple way of achieving some sort of sanity (and yeas on this one PHP is above Python and Javascript!). Also, having " " also work for…
No. PHP's `+` operator always tries to convert to the number, and uses 0 (!!!) when it is not possible. (e.g. what is `"hello" + "world"`?) Having different operators hardly matters; operators should cause a visible and clear error if they were given unexpected operands. Python is better in that regard since it does not allow `str + int` and so on.
Re: Rust for C++ programmers – part 3: primitive types and operators
#43Earlier quoted context omitted.
Have you used Python a lot? That's not how it works. Python is not weakly typed and "string" + 5 throws an exception.
Yes (though it treats 1 as True and 0 as False, which it really ought to avoid).
if some_bool == 1
or if isinstance(some_bool, int)
written before the bool type was added (which only happened 2.3)Re: Rust for C++ programmers – part 3: primitive types and operators
#44Earlier quoted context omitted.
A colleague recently went through that as well, a (JS) graphing package would sometimes display bar charts with an incorrect scale (it would pick the wrong maximum value, so part of the bars would be cut off). Turns out the package expected numbers, but sometimes a bug meant the data source would give arrays (of a single number each), the package's own max (using <) would perform a lexical comparison (comparison woul…
Add me to the list. The other day I was debugging some simple Python code that worked something like return 10000 if x > 10000 else x and it wasn't working because x was a string. Instead of raising an exception, though, Python decided that all strings are "greater than" all integers, and code was essentially equivalent to return x
Yep. That's one of the things they changed/fixed in Python 3, comparisons are not defined across and between any and all types:
>>> "foo" > 3
Traceback (most recent call last):
File "", line 1, in
TypeError: unorderable types: str() > int()Re: Rust for C++ programmers – part 3: primitive types and operators
#45Earlier quoted context omitted.
Thats the rework that I'm working on! I'm debating between making a context trait and having the static function signature include a context instead of a request and the everything request related would be included/appended in the context, or having the user implement "controller" trait on their struct that has a method I will call after settling the routes (something like https://github.com/jroweboy/oxidize/blob/inc…
Personally, I'd be inclined to have the context separate from the request, since they're really two different things. Also, you could introduce a FromRequest trait (trivially implemented by Request, returning self) to allow the user to build structures directly from a request (and its converse ToResponse), giving your function a signature of: fn (context: Context, req: FromRequest) -> ToResponse trait FromRequest { f…
Re: Rust for C++ programmers – part 3: primitive types and operators
#46Earlier quoted context omitted.
All array indexing is bounds checked, so those kind of errors are prevented. We're still working on the story around overflow checking
This prevents buffer overflow errors, but not crashes.
Re: Rust for C++ programmers – part 3: primitive types and operators
#47Earlier quoted context omitted.
Yes, I can catch SIGSEGV. And I can catch Java NullPointerExceptions and ArrayIndexOutOfBoundsExceptions. So Java prevents all crashes, lol.
Yes, Java applications are rarely killed by the OS/memory manager for trying to access memory they don't have control over.
Re: Rust for C++ programmers – part 3: primitive types and operators
#48Re: Rust for C++ programmers – part 3: primitive types and operators
#49Earlier quoted context omitted.
That's a strange definition of "crash" you have there. I should go tell my customers next time that their programs definitely didn't crash.
Java raises an exception. If you handle it in code, the app does not crash. The crash is a consequence of failure to handle and recover from the exception. Granted, it is very rare that you can/should recover from nullpointer or OOB exceptions anyway. What you can do though is try to clean up things, show a polite message and shut down the application in a semi-controlled way. "Preventing crashes" isn't the best desc…
Re: Rust for C++ programmers – part 3: primitive types and operators
#50I understand that there is probably a performance motivation for having int/uint having machine-dependent sizes. However, it seems to me that having different sizes on different platforms is a potential security hazard if the programmer doesn't think of this. It also gives rise to porting bugs. Isn't the idea of rust to make a securer language than C++? I would have thought mandating 32 or 64 bit for int/uint would m…