Bitcoin Forum
May 03, 2024, 08:57:39 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 3 4 [5]  All
  Print  
Author Topic: Bitcoin source code is a giant mess  (Read 10714 times)
drawingthesun
Legendary
*
Offline Offline

Activity: 1176
Merit: 1015


View Profile
June 13, 2013, 07:57:54 AM
 #81

I'm a novice at C++

Why use goto instead of a throw for error handling?
1714726659
Hero Member
*
Offline Offline

Posts: 1714726659

View Profile Personal Message (Offline)

Ignore
1714726659
Reply with quote  #2

1714726659
Report to moderator
1714726659
Hero Member
*
Offline Offline

Posts: 1714726659

View Profile Personal Message (Offline)

Ignore
1714726659
Reply with quote  #2

1714726659
Report to moderator
"Bitcoin: mining our own business since 2009" -- Pieter Wuille
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
June 13, 2013, 08:18:00 AM
 #82

I'm a novice at C++

Why use goto instead of a throw for error handling?
to take *advantage* of undefined behavior.

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
oakpacific
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1000


View Profile
June 13, 2013, 10:05:12 AM
 #83

And a Jump table is what?

It is not part of the C++ language (so not relevant to this discussion).

Understand that the main evil in coding goto is the possibility of it leading to undefined behavior which does not have to be reported by the compiler (same as something like a[ i ] = i++; which compilers are not likely to give you any warning about).


I don't think this problem is specific to C++ complier.

https://tlsnotary.org/ Fraud proofing decentralized fiat-Bitcoin trading.
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
June 13, 2013, 10:28:35 AM
 #84

And a Jump table is what?

It is not part of the C++ language (so not relevant to this discussion).

Understand that the main evil in coding goto is the possibility of it leading to undefined behavior which does not have to be reported by the compiler (same as something like a[ i ] = i++; which compilers are not likely to give you any warning about).


I don't think this problem is specific to C++ complier.
to explain the problem with pseudo c++ code(pseudo code with c syntax, gotos and exceptions. as i can't code C++, but hate it on principal):
Code:
try {
  goto out;
} catch exception {
 print("am im getting printed or not?");
} finally {
 print("okay, does i get printed too then?")
}
out:
throw exception;

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
Lohoris
Hero Member
*****
Offline Offline

Activity: 630
Merit: 500


Bitgoblin


View Profile
June 13, 2013, 10:43:09 AM
 #85

to explain the problem with pseudo c++ code(pseudo code with c syntax, gotos and exceptions. as i can't code C++, but hate it on principal):
Code:
try {
  goto out;
} catch exception {
 print("am im getting printed or not?");
} finally {
 print("okay, does i get printed too then?")
}
out:
throw exception;

This is a case of bad goto use.

As long as you don't jump outside of trys, or inside loops, that's fine.

I.e. it is mostly used to jump out of nested loops.
And yes, there are plenty of situations were nested loops make sense. And doing that with an exception is violating the KISS principle.

1LohorisJie8bGGG7X4dCS9MAVsTEbzrhu
DefaultTrust is very BAD.
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1075


Ian Knowles - CIYAM Lead Developer


View Profile WWW
June 13, 2013, 11:18:09 AM
Last edit: June 13, 2013, 11:32:23 AM by CIYAM Open
 #86

This is a case of bad goto use.

Really - understand that there is "no good goto use" in C++ (see below).

As long as you don't jump outside of trys, or inside loops, that's fine.

I.e. it is mostly used to jump out of nested loops.
And yes, there are plenty of situations were nested loops make sense. And doing that with an exception is violating the KISS principle.

By placing a goto *anywhere* in code you have placed the coding equivalent of a *landmine*.

Why? Because if anyone in the future working on a large loop with a goto hiding in it uses some normally perfectly acceptable OO or exception handling code then *boom* you end up with undefined behavior even though you didn't even *write* the stupid goto.

So if you think it is a good idea to hide gotos in large loops then I'd suggest you might want to put a comment on every 3rd line or so like this:

// Warning, warning! Danger Will Robertson! This loop contains a *goto* landmine. You are best to only write C code in here.

In no C++ project that I have worked on was *goto* ever used (or would have been accepted) and even in a very large C project I worked on it was used very sparingly.

The only people I've found to still write "goto" are C programmers who never managed to accept the idea of exception handling.

BTW - for your nested loop situation use this approach:

Code:
   bool done = false;
   bool some_cond = false;
   for( size_t i = 0; i < 10 && !done; i++ )
   {
      for( size_t j = 0; j < 10 && !done; j++ )
      {
         for( size_t k = 0; k < 10 && !done; k++ )
         {
            if( some_cond )
            {
               done = true;
               break;
            }
         }
      }
   }

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Lohoris
Hero Member
*****
Offline Offline

Activity: 630
Merit: 500


Bitgoblin


View Profile
June 13, 2013, 11:57:12 AM
 #87


Code:
   bool done = false;
   bool some_cond = false;
   for( size_t i = 0; i < 10 && !done; i++ )
   {
      for( size_t j = 0; j < 10 && !done; j++ )
      {
         for( size_t k = 0; k < 10 && !done; k++ )
         {
            if( some_cond )
            {
               done = true;
               break;
            }
         }
      }
   }


This is horrible and *MUCH* less clear than a simple goto.

Code:
   bool some_cond = false;
   for( size_t i = 0; i < 10; i++ )
   {
      for( size_t j = 0; j < 10; j++ )
      {
         for( size_t k = 0; k < 10; k++ )
         {
            if( some_cond )
            {
               goto end;
            }
         }
      }
   }
   end:

If code is less readable, you're wrong.
It's as simple as that.

1LohorisJie8bGGG7X4dCS9MAVsTEbzrhu
DefaultTrust is very BAD.
Lohoris
Hero Member
*****
Offline Offline

Activity: 630
Merit: 500


Bitgoblin


View Profile
June 13, 2013, 11:58:33 AM
 #88

If code is less readable, you're wrong.
It's as simple as that.
i.e. for the very same reason you oppose goto, goto is good in some situations.

1LohorisJie8bGGG7X4dCS9MAVsTEbzrhu
DefaultTrust is very BAD.
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1075


Ian Knowles - CIYAM Lead Developer


View Profile WWW
June 13, 2013, 12:54:49 PM
 #89

If code is less readable, you're wrong.
It's as simple as that.

i.e. for the very same reason you oppose goto, goto is good in some situations.

I'm sorry but you're wrong and being a child at the same time - read my initial post about undefined behaviour and *landmines* then you can join in with the adults.

Sheesh!

I think any useful discussion has left this topic already so I will probably unwatch about now. Smiley

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
June 13, 2013, 01:03:15 PM
 #90

If code is less readable, you're wrong.
It's as simple as that.
i.e. for the very same reason you oppose goto, goto is good in some situations.
yes, but not in C++, because C++ sucks.

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1075


Ian Knowles - CIYAM Lead Developer


View Profile WWW
June 13, 2013, 01:05:27 PM
 #91

because C++ sucks.

and with that I'm out of here - enjoy the trolling guys - hopefully at least a point or two managed to get through.

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
jdbtracker
Hero Member
*****
Offline Offline

Activity: 727
Merit: 500


Minimum Effort/Maximum effect


View Profile
June 13, 2013, 02:58:49 PM
 #92

well, this thread has degenerated, so I'll throw a couple wrenches of my own.
I've read the comments and looked at the information that I can find... I think Satoshi was a programmer, just that they were a C programmer trying to write in C++ code.
If we approach the source code from the perspective of a C programmer it could start making sense.

If you think my efforts are worth something; I'll keep on keeping on.
I don't believe in IQ, only in Determination.
Trongersoll
Hero Member
*****
Offline Offline

Activity: 490
Merit: 501



View Profile
June 13, 2013, 05:08:45 PM
 #93

well, this thread has degenerated, so I'll throw a couple wrenches of my own.
I've read the comments and looked at the information that I can find... I think Satoshi was a programmer, just that they were a C programmer trying to write in C++ code.
If we approach the source code from the perspective of a C programmer it could start making sense.

More likely he was a Mathematician or EE who knew how to program. Comp. Sci. types tend to understand the need for a disciplined approach to programming..
hacker
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile
June 13, 2013, 05:46:11 PM
 #94

$ grep -R goto ~/linux-3.10-rc5/* | wc -l
  108095

Also Dijkstra was wrong: -

http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf

If you want to argue with Knuth, you're a braver soul than me.

And for entertainment value: -

http://harmful.cat-v.org/software/c++/linus
P_Shep
Legendary
*
Offline Offline

Activity: 1795
Merit: 1198


This is not OK.


View Profile
June 13, 2013, 06:07:50 PM
 #95

LoL Cheesy

http://harmful.cat-v.org/software/c++/I_did_it_for_you_all
P_Shep
Legendary
*
Offline Offline

Activity: 1795
Merit: 1198


This is not OK.


View Profile
June 13, 2013, 06:14:08 PM
 #96


Ahhhhh... not true!

http://www.snopes.com/computer/program/stroustrup.asp
hf
Member
**
Offline Offline

Activity: 98
Merit: 10


there will be no fucking vegetables


View Profile
June 13, 2013, 06:15:01 PM
 #97

And also, for fun : https://en.wikipedia.org/wiki/Considered_harmful
Pages: « 1 2 3 4 [5]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!