Pages:
Author

Topic: Bitcoin source code is a giant mess (Read 10759 times)

hf
member
Activity: 98
Merit: 10
there will be no fucking vegetables
legendary
Activity: 1795
Merit: 1208
This is not OK.
newbie
Activity: 16
Merit: 0
June 13, 2013, 12: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
hero member
Activity: 490
Merit: 501
June 13, 2013, 12: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..
hero member
Activity: 727
Merit: 500
Minimum Effort/Maximum effect
June 13, 2013, 09:58:49 AM
#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.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
June 13, 2013, 08:05:27 AM
#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.
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 13, 2013, 08:03:15 AM
#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.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
June 13, 2013, 07:54:49 AM
#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
hero member
Activity: 630
Merit: 500
Bitgoblin
June 13, 2013, 06: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.
hero member
Activity: 630
Merit: 500
Bitgoblin
June 13, 2013, 06: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.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
June 13, 2013, 06:18:09 AM
#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;
            }
         }
      }
   }
hero member
Activity: 630
Merit: 500
Bitgoblin
June 13, 2013, 05: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.
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 13, 2013, 05: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;
hero member
Activity: 784
Merit: 1000
June 13, 2013, 05: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.
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 13, 2013, 03: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.
legendary
Activity: 1176
Merit: 1015
June 13, 2013, 02:57:54 AM
#81
I'm a novice at C++

Why use goto instead of a throw for error handling?
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
June 12, 2013, 09:49:41 PM
#80
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).
hero member
Activity: 490
Merit: 501
June 12, 2013, 06:56:10 PM
#79
Ok, this is getting nuts. there is nothing inheritantly wrong wrong with goto. the problem is that not everyone uses them responsibly. there once was a time in history when poor use of goto created what was called "spaghetti code" where people used goto's to jump into the middle of functions and such all over the place. this made the code hard to read and costly to return. This caused the stigma on goto. Structured Programming using accepted constructs becae the norm.

For any company paying to have code developed, Maintainability became the mandate. Arguing about goto accomplishes nothing. if you are coding for free, do what ya want, go ahead, develop bad habits. Somebody will make you confrom sooner or later.  the US Gov. spent hugh sums getting ADA developed and used to encourage a common structured, readable language. Today, ADA isn't so popular, i suspect because the rebels couldn't do what ever they wanted.

The thing to do if you are coding for public consumption is to write and document your code as if the next person isn't as smart as you and what is clear to you may not be clear to them. Do this and you'll be a successful Professional Programmer/Software Engineer.
sr. member
Activity: 399
Merit: 250
June 12, 2013, 06:36:26 PM
#78
+1 CIYAM. To add to your good and explanative post, we could add that the main *good* usage of goto in C is for error handling, or to rephrase : to compensate for the lack of ... exceptions. Exception handling being provided by C++, there's no good reason to use gotos in C++ anymore.
gotoes are directly dangerous in C++.

And a Jump table is what?
Pages:
Jump to: