Page 4 of 67 FirstFirst 1234567814 ... LastLast
Results 31 to 40 of 670

Thread: The LaserBoy Thread

  1. #31
    Join Date
    Mar 2012
    Location
    Akron, Ohio USA
    Posts
    2,197

    Default

    Um. No I don't explicitly handle out of memory. I do make sure that no frame has more than 64K vertices. That's WAY too many, but the limit is based on the unsigned short int "quantity" in the ILDA section header.

    I don't think I've ever run out of memory.

    I have even opened up multi-channel waves from ADATs that were easily more than 2GB.

    Virtual memory or the hard drive swap file takes care of that.

    The nice thing about an open source project is that you can look at the code yourself!

    What do you think? I know it needs work. It always does! Working on it now!

    I always took the meaning of unstructured programming to be code that relies mostly on the order in which it is encountered, possibly with jumps to offsets or locations; much like assembly language or even BASIC.

    C/C++ is structured. It does not rely on the order in which the compiler sees it to become the machine language (that is unstructured).

    In all of my years of C/C++ programming I have never used a goto statement.

    Just bailing out of where ever you are and popping to some outside error handling routine seems like a total violation of structured programming to me.

    C++ was developed to be able to write object oriented C. There is no exception handling in C. How long did C++ exist before it was added?

    I think it's just an easy way out for people who are too confused by other methodologies.

    I am trying to write code that can detect a problem in a file but still get whatever it can from the parts of the file that are OK, plus write an error report identifying the problem and even where to find it.

    James.
    Last edited by james; 12-12-2014 at 21:21.
    Creator of LaserBoy!
    LaserBoy is free and runs in Windows, MacOS and Linux (including Raspberry Pi!).
    Download LaserBoy!
    YouTube Tutorials
    Ask me about my LaserBoy Correction Amp Kit for sale!
    All software has a learning curve usually proportional to its capabilities and unique features. Pointing with a mouse is in no way easier than tapping a key.

  2. #32
    Join Date
    Dec 2010
    Location
    DC/VA metro area, USA
    Posts
    554

    Default

    Quote Originally Posted by james View Post
    I think it's just an easy way out for people who are too confused by other methodologies.
    When systems get large enough, and you begin to build sub-systems or libraries that will be part of larger systems which will be part of larger systems, you no longer own the design contract top-to-bottom, and you don't know exactly what the circumstances will be when a failure of some type occurs in the bowels of some sub-sub-sub-system. Exceptions are a way to structure handling of unforeseen problems, even though they are technically "unstructured code" by the CS definition. The "right" behavior in one instance may be exactly the "wrong" behavior in another, and it is up to the consumer of the sub-system to decide, not the sub-system itself. The sub-system's responsibility is to do its best to do its job, and if it can't, do its best to explain what happened to its consumers. Crashing or setting bit 26 of 32 in a return value are unfriendly ways of getting that done in that environment. It may work fine for some situations.

    I guess what I am saying is, just because you haven't encountered a situation where structured exception handling (SEH) would help you doesn't mean it's a bad practice, and labeling it as such may limit your perspective on potential solutions.

    And, just because you've never run out of memory in LB doesn't mean that gracefully handling out-of-memory situations isn't a good practice to be in, or that SEH isn't a good way to do it. I'm not saying you should make that a priority in LB, or that it would be the best use of anyone's time, it was just an example that goes to the usefulness of SEH.

  3. #33
    Join Date
    Mar 2012
    Location
    Akron, Ohio USA
    Posts
    2,197

    Default

    I get what you are saying. And I think you already understand that LB is a single threaded app that only reads and writes files. So it is not in, nor does it create an environment where "exceptional errors" might occur.

    It's a kind of circular reasoning, I think. We use exception handling because the modules we link to use exception handling.

    That is exactly what I don't like about Java. You have no choice.

    My analogy is being in a maze. You know there is a way out. You just have to figure it out. Or you can just fly out from where ever you are and place yourself at the exit.

    There are some software companies that use C++ for the bulk of their production and they explicitly prohibit the use of exception handling.

    http://google-styleguide.googlecode....tml#Exceptions

    First sentence of Pros:

    Exceptions allow higher levels of an application to decide how to handle "can't happen" failures in deeply nested functions, without the obscuring and error-prone bookkeeping of error codes.

    This statement says it all. There is a way. It's just sometimes very complex.

    BTW this is what I am working on right now.

    http://laserboy.org/forum/index.php?...sg2193#msg2193

    I'm working on error codes bubbling up from reading text from a file. I'm really glad I wrote that description! All that is hard to remember.

    James.
    Last edited by james; 12-13-2014 at 10:46.
    Creator of LaserBoy!
    LaserBoy is free and runs in Windows, MacOS and Linux (including Raspberry Pi!).
    Download LaserBoy!
    YouTube Tutorials
    Ask me about my LaserBoy Correction Amp Kit for sale!
    All software has a learning curve usually proportional to its capabilities and unique features. Pointing with a mouse is in no way easier than tapping a key.

  4. #34
    Join Date
    Dec 2010
    Location
    DC/VA metro area, USA
    Posts
    554

    Default

    Quote Originally Posted by james View Post
    There are some software companies that use C++ for the bulk of their production and they explicitly prohibit the use of exception handling.

    http://google-styleguide.googlecode....tml#Exceptions

    First sentence of Pros:

    Exceptions allow higher levels of an application to decide how to handle "can't happen" failures in deeply nested functions, without the obscuring and error-prone bookkeeping of error codes.
    People reading this thread should not assume from the above that Google is anti-exception. You really need to read the whole Decision section.

    On their face, the benefits of using exceptions outweigh the costs, especially in new projects. However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. Because most existing C++ code at Google is not prepared to deal with exceptions, it is comparatively difficult to adopt new code that generates exceptions.

    Given that Google's existing code is not exception-tolerant, the costs of using exceptions are somewhat greater than the costs in a new project. The conversion process would be slow and error-prone. We don't believe that the available alternatives to exceptions, such as error codes and assertions, introduce a significant burden.

    Our advice against using exceptions is not predicated on philosophical or moral grounds, but practical ones. Because we'd like to use our open-source projects at Google and it's difficult to do so if those projects use exceptions, we need to advise against exceptions in Google open-source projects as well. Things would probably be different if we had to do it all over again from scratch.

  5. #35
    Join Date
    Mar 2012
    Location
    Akron, Ohio USA
    Posts
    2,197

    Default

    I bet you know what a kludge is.

    If nothing else, the fact that they haven't been used implies they are not necessary.

    James.
    Creator of LaserBoy!
    LaserBoy is free and runs in Windows, MacOS and Linux (including Raspberry Pi!).
    Download LaserBoy!
    YouTube Tutorials
    Ask me about my LaserBoy Correction Amp Kit for sale!
    All software has a learning curve usually proportional to its capabilities and unique features. Pointing with a mouse is in no way easier than tapping a key.

  6. #36
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    2,292

    Default

    STL isn't necessary, either.

  7. #37
    Join Date
    Mar 2012
    Location
    Akron, Ohio USA
    Posts
    2,197

    Default

    STL doesn't redefine C++ program flow control. STL is made of pure C++.

    You're right. It isn't necessary. You could write all that stuff yourself without changing the rules of C++.
    Creator of LaserBoy!
    LaserBoy is free and runs in Windows, MacOS and Linux (including Raspberry Pi!).
    Download LaserBoy!
    YouTube Tutorials
    Ask me about my LaserBoy Correction Amp Kit for sale!
    All software has a learning curve usually proportional to its capabilities and unique features. Pointing with a mouse is in no way easier than tapping a key.

  8. #38
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    2,292

    Default

    Pulled this from a FAQ maintained by the guy who invented C++.


    Why use exceptions?
    What good can using exceptions do for me? The basic answer is: Using exceptions for error handling makes you code simpler, cleaner, and less likely to miss errors. But what's wrong with "good old errno and if-statements"? The basic answer is: Using those, your error handling and your normal code are closely intertwined. That way, your code gets messy and it becomes hard to ensure that you have dealt with all errors (think "spaghetti code" or a "rat's nest of tests").
    First of all there are things that just can't be done right without exceptions. Consider an error detected in a constructor; how do you report the error? You throw an exception. That's the basis of RAII (Resource Acquisition Is Initialization), which it the basis of some of the most effective modern C++ design techniques: A constructor's job is to establish the invariant for the class (create the environment in which the members function are to run) and that often requires the acquisition of resources, such as memory, locks, files, sockets, etc.

    Imagine that we did not have exceptions, how would you deal with an error detected in a constructor? Remember that constructors are often invoked initialize/construct objects in variables:
    vector<double> v(100000); // needs to allocate memory
    ofstream os("myfile"); // needs to open a file

    The vector or ofstream (output file stream) constructor could either set the variable into a "bad" state (as ifstream does by default) so that every subsequent operation fails. That's not ideal. For example, in the case of ofstream, your output simply disappears if you forget to check that the open operation succeeded. For most classes that results are worse. At least, we would have to write: vector<double> v(100000); // needs to allocate memory
    if (v.bad()) { /* handle error */ } // vector doesn't actually have a bad(); it relies on exceptions
    ofstream os("myfile"); // needs to open a file
    if (os.bad()) { /* handle error */ }

    That's an extra test per object (to write, to remember or forget). This gets really messy for classes composed of several objects, especially if those sub-objects depend on each other. For more information see The C++ Programming Language section 8.3, Chapter 14, and Appendix E or the (more academic) paper Exception safety: Concepts and techniques.
    So writing constructors can be tricky without exceptions, but what about plain old functions? We can either return an error code or set a non-local variable (e.g. errno). Setting a global variable doesn't work too well unless you test it immediately (or some other function might have re-set it). Don't even think of that technique if you might have multiple threads accessing the global variable. The trouble with return values are that choosing the error return value can require cleverness and can be impossible:
    double d = my_sqrt(-1); // return -1 in case of error
    if (d == -1) { /* handle error */ }
    int x = my_negate(INT_MIN); // Duh?

    There is no possible value for my_negate() to return: Every possible int is the correct answer for some int and there is no correct answer for the most negative number in the twos-complement representation. In such cases, we would need to return pairs of values (and as usual remember to test) See my Beginning programming book for more examples and explanations.

    Common objections to the use of exceptions:
    •but exceptions are expensive!: Not really. Modern C++ implementations reduce the overhead of using exceptions to a few percent (say, 3%) and that's compared to no error handling. Writing code with error-return codes and tests is not free either. As a rule of thumb, exception handling is extremely cheap when you don't throw an exception. It costs nothing on some implementations. All the cost is incurred when you throw an exception: that is, "normal code" is faster than code using error-return codes and tests. You incur cost only when you have an error.
    •but in JSF++ you yourself ban exceptions outright!: JSF++ is for hard-real time and safety-critical applications (flight control software). If a computation takes too long someone may die. For that reason, we have to guarantee response times, and we can't - with the current level of tool support - do that for exceptions. In that context, even free store allocation is banned! Actually, the JSF++ recommendations for error handling simulate the use of exceptions in anticipation of the day where we have the tools to do things right, i.e. using exceptions.
    •but throwing an exception from a constructor invoked by new causes a memory leak!: Nonsense! That's an old-wives' tale caused by a bug in one compiler - and that bug was immediately fixed over a decade ago.

  9. #39
    Join Date
    Mar 2012
    Location
    Akron, Ohio USA
    Posts
    2,197

    Default

    I just released a new version of LaserBoy!

    I can't even begin to list all of the stuff I fixed or went over.

    Please check it out and let me know if you can make it crash!

    http://laserboy.org/code/LaserBoy_2014_12_20.zip

    I would image there are still some things that need attention.

    I have not started on the "Spencer" SD card reader frame set effect yet.

    Perhaps we can discuss that here.

    James.
    Creator of LaserBoy!
    LaserBoy is free and runs in Windows, MacOS and Linux (including Raspberry Pi!).
    Download LaserBoy!
    YouTube Tutorials
    Ask me about my LaserBoy Correction Amp Kit for sale!
    All software has a learning curve usually proportional to its capabilities and unique features. Pointing with a mouse is in no way easier than tapping a key.

  10. #40
    Join Date
    Dec 2010
    Location
    DC/VA metro area, USA
    Posts
    554

    Default

    Got it! Chrome thinks it's malware because it's "not commonly downloaded." Phooey Chrome.

    I'll try to check it out over the holiday. We'll see how things work out.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •