exceptions in C++ vs exceptions in other languages [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
the idea I have about using exceptions and try {} catch {} blocks is that those are used for error handling.
I was reading Bjarne's Strostrup FAQ page section about exceptions and I came across this
There are other uses of exceptions - popular in other languages - but
not idiomatic in C++ and deliberately not supported well by C++
implementations (those implementations are optimized based on the
assumption that exceptions are used for error handling).
What are other usages for exceptions in other languages (C# or java for example)?

In Python, in the spirit of "ask for forgiveness, not permission", exceptions are frequently used as part as the normal control flow of the application. For instance, when looking up an element in a dictionary (think std::unordered_map in C++):
try:
my_value = my_dict["the answer to life, the universe and everything"]
except KeyError:
my_value = 42
In C++, this is not considered an "erroneous" situation; exceptions should only be used in interaction with "unpredictable" things like hardware devices and (to some degree) the operating system.

One other use is InterrutedException in java. It allows waiting on monitors or sleeping threads step out of wait or sleep.

Related

Is Unreal Engine 4 C++ managed or unmanaged? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Unreal Engine 4 controls some runtime aspects of the application, such as having its own Garbage Collector and a unique metadata ("reflection") system.
The question is: is it correct to say UE4 makes the C++ code "managed" in the context of "managed" and "unmanaged" languages (as in C# is a managed language and C++ is an unmanaged language)?
If by "managed" you mean "managed memory" meaning "garbage collected" then C++ allows you to opt-in to that if you so wish, but by default it does not offer such a thing.
C#, like Java and many others, forces garbage collection on you, there is no way around it.
In C++ you can use things like std::shared_ptr to wrap around any objects you want to be garbage collected.
Remember that in C++ there's many ways to allocate and initialize. In situations where performance must be optimized at the expense of complexity it's not uncommon to write a custom allocator that can cut a lot of corners so long as it's used a very specific way.
So in other words C++ is "managed" if you want and how you want it to be managed. Management in C++ is a process you're an active participant in.
C++ is not a managed langue. There is C++/CLI in visual studio that's managed, but it's not really C++. Things like garbage collection can be implemented in C++ code with some work and is useful for some applications (I've had to do that). Even reflection is possible with a lot more work but it's not natively supported. Reflection does not really mean calling the compiler in your code. You can even do that in C.

Is there a C++ dialect without "standard bugs"? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Today I was listening to a number of talks about dark sides of C++. One them was held by a man who was participating in the creation of the new C++ standard (Nikolai Jossutis). I'm fascinated by the many things in language, which make it easier to misuse. And for me personally it seems that C++ is actually fine if there wasn't backward comparability, which didn't allow to fix "bugs in the standard".
Hypotethically let's say I want an language dialect of C++ that is not backward compatible with the standard C++. It removes components considered dangerous, it doesn't compile something which is almost always results in UB.
I don't want to give any concrete examples, but I'm fine with everyhing which will make code safer. I already treat warnings as errors in the strictiest provided by the compiler way and use static analysis, along with ASan, etc..
UPD: I'm speaking about something very similar to C++ and it's characteristics. If I think about Java, it isn't suitable for me, because of VM. I'm asking about dialect of C++, not very different language, like Java or Rust. Rust is fine, because it compiles to native code, but I'm asking about dialect, not new language.
you could try D https://dlang.org/...
Or have a look at the Misra C++ rules https://www.perforce.com/resources/qac/misra-c-cpp, there are also code checkers available

How Erlang is better than other language in doing concurrency? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I don't understand why erlang itself is great with concurrency
Is there anyway other language such as C# could be as great as erlang if we do some trick?
Or it is the very specific language feature of erlang that most language don't have?
Could we write C to be like erlang?
One Major property of Erlang is that it was built from the ground up to be a concurrent language. Erlang supports hundreds of thousands of lightweight processes in a single virtual machine. Because Erlang's processes are completely independent of OS processes they are very lightweight, with low overhead per-process. Thus when using Erlang for concurrent oriented programming you get alot of advantages out of the box.
Fast process creation/destruction
Ability to support millions of concurrent processes with largely unchanged characteristics.
Fast asynchronous message passing.
Copying message-passing semantics (share-nothing concurrency).
Process monitoring.
Selective message reception.
This Erlang style concurrency is not impossible to do in C, but it would be hard to do it. Read this blog for more information on Erlang style concurrency

Exception vs Non exception handling in c style languages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
This question was brought to me because I was watching this talk
A large part of the second half of the talk is spent kinda going back and fourth about exception vs non exception handling in c++.
I am working mainly with c but I would like to get some experienced programmers help understanding this.
I haven't written any code that really did anything with exceptions, I have done java code and that basically forces you to add try/ catch blocks etc.
When he says exception handling vs non exception handling does that mean the way java almost forces you to add those blocks around any unsafe code while in c basically if you don't remember to do it your app will just crash?
You have to take into consideration that exceptions are usually constructs of Object Oriented programming - That's why Java, C#, C++, etc. often talk about exceptions and try/catch blocks.
In C, this isn't the case. Usually errors need to be caught by the programmer by ways of return values (The C standard uses the errno to keep track of any errors values returned by certain functions).
If something goes really wrong, C will either crash or have an unexpected behaviour - This is where exceptions come in. They are fancier constructs to determine where, how, and why something went wrong.
There is no way of making exceptions in C, but something similar could be done with POSIX signals - though not recommended unless you really know what you are doing. Preferably, use return values to determine when someone goes wrong/right.

Is managed code slower than unmanaged code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Its just a question out of my curiosity. Though generally considering the Framework and the steps involved in Execution, i'd say yes. Still i would also like to consider the factors like Memory/Disc access and networking which limit the performance of unmanaged code.
Quoting Herb Sutter
"First, JIT compilation isn’t the main issue. The root cause is much more fundamental: Managed languages made deliberate design tradeoffs to optimize for programmer productivity even when that was fundamentally in tension with, and at the expense of, performance efficiency."
There’s always an inescapable and fundamental difference between “prevention” and “cure” — when it comes to performance optimization, C++ always chooses “prevention,” and managed languages choose “cure” with the above-mentioned heroic efforts and many more. But the old ounce/pound saying is inescapable; you can’t beat prevention (in part because you can always add the cure after first doing the prevention, but not the reverse), and if you care about performance and control primarily then you should use a language that is designed to prioritize that up front, that’s all.
You can refer this article for more clarity
http://www.i-programmer.info/professional-programmer/i-programmer/4026-the-war-at-microsoft-managed-v-unmanaged.html