Earlier quoted context omitted.
All of the C/C++ experts I know, as well as people who have interviewed me coming from primarily that background, have always been among the most adamant to stress that an application crashing unexpectedly should never happen and is always the wrong outcome. I imagine they would say that your statement about crashing vs. e.g. launching the missiles is a false dilemma. You don't crash and you don't incorrectly launch…
I've been writing software in C and C++ for a long time. Crashing is never a good user experience, so avoid it. If something unexpected happens, catch and report the error, then carry on, if possible, or gracefully exit otherwise.
A bite of Python
161–168 of 168 posts
Re: A bite of Python
#162Earlier quoted context omitted.
I find that with Python that's almost always caused by not quite understanding the underlying rules. Once understood, they're very consistent. For example: does Python pass function arguments by value or by reference? Neither! It passes them by object reference - not by variable reference like C/C++. Check out: >>> def foo(a): ... a = 2 ... >>> value = 1 >>> value 1 >>> foo(value) >>> value 1 and: >>> def mutate(dct)…
haha, your explanation is exactly the mutable vs immutable thing. dicts are mutable, so, it doesn't create a new object to make an assignment numbers are immutable, so, it does.
Python is always pass-by-object-reference, and assignment is always a pointer operation. It's not special-cased like you're describing.
Re: A bite of Python
#163I would never accuse Python of "language clarity and friendliness". Far from it. For someone who came up through C, Java, Perl, and Ruby, but who's wrangled with Python, Javascript, Go, and even Haskell in recent years, I still find Python mysterious, self-contradictory, and filled with implicit rules and assumptions that are entirely un-intuitive to me far more than other languages. And yet, people seem to like it.…
In my experience and implied by the rising popularity of python, you would be among the minority. Personally, I find python to be the most clear of any language I've worked with, most resembling natural language in the way I typically speak. Do you have some examples of how you find it self-contradictory? Here's an example of its expressiveness a colleague and mine I discussing the other day: Python: [os.remove(i.loc…
I think your Java example only looks gross because it's using ugly APIs, and isn't indented well, but otherwise, apart from contrived examples, pipelining is superior.
I find Python's lack of pipeline capability, whilst every other modern language supports it, very frustrating. JavaScript, Scala, Swift, Rust, Ruby, Elixir, C#, F#, Java, Kotlin Meanwhile, Python has borked, 1-line, lambdas that compose awkwardly with map/filter (if you do a map over the result of a filter, they'll be written in reverse order), and refuses to implement useful methods on lists, that would allow pipelining. It's like it can't decide to pick the OO solution to the problem (and add the methods to lists) or to go the FP route (and fix its lambdas), so has done neither.
So we're stuck hoping our problem at hand fits neatly into a list comprehension, which still won't be composable when we come back to it and realise we want to add another operation.
I like Python very much, but this is one of it's weakest areas in my opinion, so I'm surprised you bring it up as a strength.
Re: A bite of Python
#164Earlier quoted context omitted.
That is certainly one approach, and the article agrees. > The root cause of this weakness is that the assert mechanism is designed purely for testing purposes, as is done in C++. However, C and C++ are perhaps unique in how much undefined behavior is possible and in how simple it is to create. Inserting into a vector while iterating through it, for instance. Or an uninitialized pointer. That's why many C++ experts be…
I think it depends on the job the program is being used for. If the program is used in a setting where occasional crash has no severe consequences, say search engine backend, it may be useful for the company to actually run in production a program that is allowed to crash whenever severe error condition occurs. In scenarios where lives or lots of money hinge on program being alive and functioning, such as plane autop…
Re: A bite of Python
#165Earlier quoted context omitted.
All of the C/C++ experts I know, as well as people who have interviewed me coming from primarily that background, have always been among the most adamant to stress that an application crashing unexpectedly should never happen and is always the wrong outcome. I imagine they would say that your statement about crashing vs. e.g. launching the missiles is a false dilemma. You don't crash and you don't incorrectly launch…
In my experience, "You don't crash" means you catch the exception and exit gracefully, reporting a fatal error has occurred. Users don't distinguish between a crash and a fatal error. Higher level languages are better at reporting uncaught runtime errors than C/C++ is, because they'll automatically do things like print useful stack traces and then exit gracefully even if you don't catch an exception. The interpreter…
Also, if you don't catch an exception in C++, most systems will give you a full core, which includes a stack trace for all running threads. Catching an exception and 'exiting cleanly' actually loses that information.
Re: A bite of Python
#166Earlier quoted context omitted.
I've been writing software in C and C++ for a long time. Crashing is never a good user experience, so avoid it. If something unexpected happens, catch and report the error, then carry on, if possible, or gracefully exit otherwise.
As someone who works in support, customers (at least the ones I support) REALLY need a clear and obvious crash to understand something's wrong. That really forces them to "do something differently" and/or look for help. You're correct in that it's not a good user experience. Neither is chaos.
Exactly. "Undefined behavior" includes showing private data to the wrong user and booking ten times more orders than the user originally indicated. I'll take crashing over that.
Re: A bite of Python
#167Re: A bite of Python
#168Earlier quoted context omitted.
haha, your explanation is exactly the mutable vs immutable thing. dicts are mutable, so, it doesn't create a new object to make an assignment numbers are immutable, so, it does.
Except that's 100% wrong here. There's not even a facility for marking an object as immutable in Python, so that wouldn't support user-defined classes at all. Python is always pass-by-object-reference, and assignment is always a pointer operation. It's not special-cased like you're describing.
>>> v=2
>>> id(v)
4148001784
>>> id(2)
4148001784
>>> def m(a):
... a=3
...
>>> m(v)
>>> id(3)
4148001800
>>> id(v)
4148001784
>>> v
2
>>> l=[]
>>> id(l)
4140973392
>>> def m2(lst):
... lst.append(1)
...
>>> m2(l)
>>> l
[1]
>>> id(l)
4140973392