Author

Topic: Bitcoin source code is a giant mess (Read 10793 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: 1089
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: 1089
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: 1089
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: 1089
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?
sr. member
Activity: 248
Merit: 252
1. Collect underpants 2. ? 3. Profit
hero member
Activity: 490
Merit: 501
June 12, 2013, 01:55:56 PM
#76
Isn't this open source? anybody can rewrite the code in any language that they want.

It definitely *is* open source but not just *anybody* can rewrite the code - to do that you would need to understand not just the C++ language (which I don't think anyone here is arguing is easy itself) but also boost (a big library which I actually don't use) as well as the other libraries that are being used in the project.

Even the devs themselves missed the subtleties of BerkleyDB that led to the temporary "hard-fork".

In short - no-one is going to come up with a 100% compatible Bitcoin equivalent in another language without a *lot* of work (a point that has been argued in various other threads - the problem was that Satoshi wrote the spec *after* he wrote the code).


so, anyone with the time, the knowledge, and the desire can rewrite it in any language.  as for it being used. I don't see that being an issue. It doesn't mean that it can't be done.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 12, 2013, 01:17:48 PM
#75
Isn't this open source? anybody can rewrite the code in any language that they want.

It definitely *is* open source but not just *anybody* can rewrite the code - to do that you would need to understand not just the C++ language (which I don't think anyone here is arguing is easy itself) but also boost (a big library which I actually don't use) as well as the other libraries that are being used in the project.

Even the devs themselves missed the subtleties of BerkleyDB that led to the temporary "hard-fork".

In short - no-one is going to come up with a 100% compatible Bitcoin equivalent in another language without a *lot* of work (a point that has been argued in various other threads - the problem was that Satoshi wrote the spec *after* he wrote the code).
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 12, 2013, 01:17:27 PM
#74
Isn't this open source? anybody can rewrite the code in any language that they want.
... but the satoshi client is still official community approved and most well tested client, so nobody gonna use it unless rewrite is very good, or suits there specific needs.
hero member
Activity: 490
Merit: 501
June 12, 2013, 01:01:24 PM
#73
Isn't this open source? anybody can rewrite the code in any language that they want.
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 12, 2013, 01:01:10 PM
#72
+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++.
hf
member
Activity: 98
Merit: 10
there will be no fucking vegetables
June 12, 2013, 12:36:10 PM
#71
+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.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 12, 2013, 11:50:22 AM
#70
I think goto's are fine, they are just unfashionable

but fast and handy.

In C they can indeed make sense - but in C++ they present problems that the language itself does *not* provide guarantees for (in regards to safe exception handling).

So in C++ "goto" really is a "no no" (for error handling as the "goto" in this topic was originally referring to you should just use a "throw").

The *only* reason that *goto* was not *dropped* as a keyword from C++ was to keep backwards compatibility as much as possible with C.

So "fast and handy" they maybe - but in C++ they are 100% *wrong* (as any exception handling would get *screwed* by the *goto* as the language does not cater for this situation).

It goes the same for "setjmp" and "longjmp" (guess most don't remember those) - they can also *not* be used safely in C++ apps.
legendary
Activity: 2674
Merit: 1029
June 12, 2013, 11:39:22 AM
#69
heretical as it is

I think goto's are fine, they are just unfashionable

but fast and handy.

legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 12, 2013, 11:21:59 AM
#68
In case of bitcoin quality and performance is high because of high effort of highly capable people committed to it. It however does not have the right patterns and is not well readable.

So then I think that *fundamentally* what we are really looking at identifying is which are the *wrong* patterns and how they should be reworked and also how any *unreadable* code should be changed to make it more readable.

This would be a much more productive direction than just having a "language war" (which never gets anywhere that I've seen in following such things since using Usenet back in the early 90's).

(I also don't think that Bitcoin should be *exclusively* C++ as I do support the idea of eventually there being a Bitcoin protocol RFC type document that *could* be implemented in any decent language).
hero member
Activity: 836
Merit: 1030
bits of proof
June 12, 2013, 11:13:58 AM
#67
Whilst I am an advocate of C++ (and don't see any reason to change the language at all) I think in any case the importance is the choice of algorithms and design patterns not the language itself.

Any language that provides the correct semantics with reasonable enough performance and is readable should be acceptable.
+1

I do not hate C++.

I think that there are languages that better support good design patterns, readability, code quality and have a performance that is acceptable. That does not mean there would not be any C++ code that has the right patterns, readability and quality.

In case of bitcoin quality and performance is high because of high effort of highly capable people committed to it. It however does not have the right patterns and is not well readable.

hero member
Activity: 727
Merit: 500
Minimum Effort/Maximum effect
June 12, 2013, 11:04:06 AM
#66
I'm just asking, I wanted to try to learn a new language and build a Bitcoin clone with extra features that the language can provide, just extra features or flexibility.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 12, 2013, 10:56:07 AM
#65
Whilst I am an advocate of C++ (and don't see any reason to change the language at all) I think in any case the importance is the choice of algorithms and design patterns not the language itself.

Any language that provides the correct semantics with reasonable enough performance and is readable should be acceptable.

BTW - all the C++ haters should have a list of bugs that *crash* the bitcoin-qt client (and lose people BTC) - could we have a list please just so we have an idea of how *broken* it actually is?

(and if it is not broken then why are people arguing it *needs* to rewritten in another language?)
hero member
Activity: 630
Merit: 500
Bitgoblin
June 12, 2013, 10:33:20 AM
#64
Java was already a step forward.
SBROFL.

Java is a terrible step backward, it's a total mess, manages to overcomplicates everything both over modern+higher level languages, AND over C/C++ themselves.
hero member
Activity: 836
Merit: 1030
bits of proof
June 12, 2013, 10:05:45 AM
#63
Java was already a step forward.

The next time I would consider Scala as it runs on JVM is OOP and is functional.
hf
member
Activity: 98
Merit: 10
there will be no fucking vegetables
June 12, 2013, 10:05:08 AM
#62
Go.
hero member
Activity: 727
Merit: 500
Minimum Effort/Maximum effect
June 12, 2013, 09:52:57 AM
#61
So what would be the ideal programming language to build Bitcoins succesor?
hero member
Activity: 630
Merit: 500
Bitgoblin
June 12, 2013, 09:38:15 AM
#60
and of course functional programming is the way forward, not OOP.
so, you like functional programming, hence functional programming is the way to go, and everyone else is doing it wrong.

well thought... Roll Eyes
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 11, 2013, 08:56:09 PM
#59
C++ sucks.

People who repeatedly type C++ sucks *suck*. Smiley
sr. member
Activity: 406
Merit: 250
LTC
June 11, 2013, 06:40:01 PM
#58
Guys, how many extra hashes you will get programming oo? None notices the irony of things? Indeed, BTC was designed for PC, but "surprise", FPGAs and ASIC too control over it, hashes are today produced with very low level hardware, quite the oposite of "OO"..
lolwut.

we're not talking about miners here.
Stupid me, didn't notice this is poetry thread, just looked over OP and saw some BTC related code.. Cheesy

Dude, no patronizing intention, but you always are under scrutinize of miners here., They move the thing around.. Smiley
legendary
Activity: 2058
Merit: 1462
June 11, 2013, 05:33:43 PM
#57
Guys, how many extra hashes you will get programming oo? None notices the irony of things? Indeed, BTC was designed for PC, but "surprise", FPGAs and ASIC too control over it, hashes are today produced with very low level hardware, quite the oposite of "OO"..
lolwut.

we're not talking about miners here.
sr. member
Activity: 406
Merit: 250
LTC
June 11, 2013, 05:23:18 PM
#56
Guys, how many extra hashes you will get programming oo? None notices the irony of things? Indeed, BTC was designed for PC, but "surprise", FPGAs and ASIC too control over it, hashes are today produced with very low level hardware, quite the oposite of "OO"..
legendary
Activity: 2058
Merit: 1462
June 11, 2013, 03:12:51 PM
#55
no, C++ generally sucks.

I can code OO, but it sucks big time when you don't have a interpreter or duck typing. (python ftw!)

and of course functional programming is the way forward, not OOP.
you want duck typing? cast everything to void*  Tongue
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 11, 2013, 02:52:17 PM
#54
A lot of the more recent changes to C++ have been to make things *easier* (such as the new use of "auto") as well as to improve its *functional programming* limitations and other general improvements (such as no longer requiring a space between two '>' characters in order to avoid being confused with the '>>' operator).

The major *problem* it has was that unlike more modern languages it wasn't designed to do some of the things that it was later found to be able to do (some admittedly much worse than can be done in other languages) and so has had to *evolve* (and this evolution has been slow).

That evolution is still ongoing but I certainly understand that it is not appealing to many - if "beauty" is in the eye of the beholder then I can appreciate that C++ is the kind of language you would have had to have had quite a few beers before thinking of it as anything more than comely. Smiley

You assume evolution makes 'good' choices. Your assumption is wrong.

C++ sucks.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 11, 2013, 04:26:29 AM
#53
A lot of the more recent changes to C++ have been to make things *easier* (such as the new use of "auto") as well as to improve its *functional programming* limitations and other general improvements (such as no longer requiring a space between two '>' characters in order to avoid being confused with the '>>' operator).

The major *problem* it has was that unlike more modern languages it wasn't designed to do some of the things that it was later found to be able to do (some admittedly much worse than can be done in other languages) and so has had to *evolve* (and this evolution has been slow).

That evolution is still ongoing but I certainly understand that it is not appealing to many - if "beauty" is in the eye of the beholder then I can appreciate that C++ is the kind of language you would have had to have had quite a few beers before thinking of it as anything more than comely. Smiley
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 11, 2013, 04:16:08 AM
#52
I will simply say that I did manage to build CIYAM which is a web application generating platform using C++ and using *no other framework* nor back-end scripting language.
Okay, you managed to use C++ to make a application. Good for you.

So even if it does suck - it has enough going right with it to be able to do that much at least. Smiley
Did you know that brainfuck can print the mandlebrot factal in ascii art?

Just because you *can* code in it, does not make it good.

Languages are tools and as such are really only as bad as the hands of those who lack the skill to use them correctly (yes - most people do not have the patience to learn a language as difficult as C++ and I would probably not advise anyone to do so if they don't want to spend many years learning).
Languages does not need to be complicated to be efficient, C++ is way to complicated(and yet i understand it!). Bjarne Stroustrup did it wrong, by taking a good and uncomplicated language(C), and fucked it up(C++). if he had designed it from the bottom, it would have been much better. C and classes does not mix well. but you can still do OOP in C, the whole linux vfs is OO C code.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 11, 2013, 03:57:32 AM
#51
I will simply say that I did manage to build CIYAM which is a web application generating platform using C++ and using *no other framework* nor back-end scripting language.

So even if it does suck - it has enough going right with it to be able to do that much at least. Smiley

Languages are tools and as such are really only as bad as the hands of those who lack the skill to use them correctly (yes - most people do not have the patience to learn a language as difficult as C++ and I would probably not advise anyone to do so if they don't want to spend many years learning).
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 11, 2013, 03:32:02 AM
#50
Of course you are aware that C++ *does* functional programming,

nope, it does not. can C++ generate complex functions at runtime, with only a little programming(compiling code/assembly/implementing brainfuck and then use it is cheating).

you cannot easily compose one function from another 2 functions in C++.

along with procedural, object oriented, generic

Well thats one is true, but which language doesn't?

Quote
and let's not forget template meta programming (and actually the *last* one of these is the big *way forward* which basically *no other* language can do).
nope that sucks too, because C++ generally sucks. Haskell does some of the same at compile time, because of its lazy evaluation and referential transparency. C++ sucks big time at this.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 10, 2013, 10:56:45 PM
#49
and of course functional programming is the way forward, not OOP.

Of course you are aware that C++ *does* functional programming, along with procedural, object oriented, generic and let's not forget template meta programming (and actually the *last* one of these is the big *way forward* which basically *no other* language can do).
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 10, 2013, 12:55:51 PM
#48
a) C++ generally sucks.
c) C++ generally sucks.
anti c++ circlejerk thread?
C++ generally sucks if you never had the time or intelligence to learn OOP.
no, C++ generally sucks.

I can code OO, but it sucks big time when you don't have a interpreter or duck typing. (python ftw!)

and of course functional programming is the way forward, not OOP.
sr. member
Activity: 280
Merit: 257
bluemeanie
June 10, 2013, 09:49:31 AM
#47
a) C++ generally sucks.
c) C++ generally sucks.
anti c++ circlejerk thread?

C++ generally sucks if you never had the time or intelligence to learn OOP.
sr. member
Activity: 280
Merit: 257
bluemeanie
June 10, 2013, 09:48:36 AM
#46
Presented without comment:



link (github.com)


LOL.  Global Variables: the wave of the future.
hero member
Activity: 490
Merit: 501
June 09, 2013, 06:11:31 PM
#45
Just rewrite the whole thing in ADA. End of problem.  Cheesy
sr. member
Activity: 406
Merit: 250
LTC
June 09, 2013, 05:26:06 PM
#44
Presented without comment:



link (github.com)

RELEASE TEH DIJKSTRA!.. Smiley
Actually I ate enough Dijkstra during uni to hate "goto" forever even if I started writing BASIC when I was 10 years old..
legendary
Activity: 2058
Merit: 1462
June 09, 2013, 05:18:29 PM
#43
a) C++ generally sucks.
c) C++ generally sucks.
anti c++ circlejerk thread?
legendary
Activity: 1050
Merit: 1000
You are WRONG!
June 09, 2013, 02:16:10 PM
#42
a) C++ generally sucks.
b) goto err, the best way to handle errors in C, they are better than nested if/else and breaks.
c) C++ generally sucks.
sr. member
Activity: 306
Merit: 257
June 09, 2013, 02:09:15 PM
#41
Interesting that people still use COBOL, FORTRAN and C++. Rather than try to fix that C++ code, would be easier to switch completely to some modern language, and have a small library of functions coded in C/ASM where efficiency is critical.
hero member
Activity: 714
Merit: 500
Martijn Meijering
June 09, 2013, 01:48:05 PM
#40
Not again, he already has his own thread.
full member
Activity: 200
Merit: 104
Software design and user experience.
June 09, 2013, 01:47:19 PM
#39
Worst problem of BTC is not the code but the basic "cash/change" logic ignoring all fundamentals of GAAP.
Ripple -though in this respect much better structured- cannot be trusted due to many other reasons.

Can you expand on cash/change problem? What's wrong with it?
LvM
full member
Activity: 126
Merit: 100
June 09, 2013, 12:45:38 PM
#38
Worst problem of BTC is not the code but the basic "cash/change" logic ignoring all fundamentals of GAAP.
Ripple -though in this respect much better structured- cannot be trusted due to many other reasons.
hero member
Activity: 714
Merit: 500
Martijn Meijering
June 05, 2013, 01:37:59 AM
#37
Switching to another codebase is certainly one possibility,  but refactoring the existing code is also a realistic option. Starting with a good test harness around bitcoind would be a good start for both options. And the existence of an API makes this a lot easier.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 10:24:20 PM
#36
Linux kernel use goto quite extensively

Am pretty sure that it is C not C++ (and yes they are two very different languages).
legendary
Activity: 2128
Merit: 1074
June 04, 2013, 08:45:44 PM
#35
We're far beyond that point. The code needs very thorough restructuring. That can be done incrementally, even while others are adding functionality, but I think it is going to be very hard to get a consensus on the needed changes.
The consesus about the needed changes could conceivably be that the official Bitcoin client switches from the "Satoshi legacy C++" to one of the newer candidate codebases, e.g. the Java code from Hungary.

For me it is good to read more and more comments about the need to stop treating Satoshi (and his legacy code base and protocol) as an inviolate revelation and more as an ingenious sketch of the future.

Time for me to repost my favourite picture of an amber:
It is an ambodiment of both the mess and the beauty.
hero member
Activity: 714
Merit: 500
Martijn Meijering
June 04, 2013, 06:00:08 PM
#34
We're far beyond that point. The code needs very thorough restructuring. That can be done incrementally, even while others are adding functionality, but I think it is going to be very hard to get a consensus on the needed changes.
hero member
Activity: 767
Merit: 500
June 04, 2013, 05:57:49 PM
#33
I would suggest that if you see problems with the bitcoin codebase, you submit a patch (and appropriate tests for your patch) via the bitcoin github, and make the codebase better!  The code is open source!

Will
hero member
Activity: 714
Merit: 500
Martijn Meijering
June 04, 2013, 12:05:45 PM
#32
Let's not turn this into a C++ coding standards discussion.
legendary
Activity: 1260
Merit: 1008
June 04, 2013, 11:57:27 AM
#31
Presented without comment:



link (github.com)


Linux kernel use goto quite extensively
legendary
Activity: 2058
Merit: 1416
aka tonikt
June 04, 2013, 11:43:39 AM
#30
2. Excessive use of C++ subclasses and operators makes it hard to read code. You see a << b, but it actually goes to a very specific place which is not entirely obvious where.

Streaming operators << and >> have always been the standard way of doing I/O in C++ so are you saying these operators are being used for something *other than streaming*?


I have nothing against using << as a streaming operator. The problem is that it's much harder to search for any operators in use (be it "<<" or "+"). Especially when you pointer-dereference operator overload. Or implicit copy constructors. Yes, code may look elegant for a mathematician, but inside an app where you have tons of multi-word symbols, operator density or implicitness is painful.

When you have "[a add:b]" instead of "a + b" it's much clearer what is going on and you can quickly find all occurrences of -add: method call.
+1
I also hate these symbols, because of the same reason.
You just cannot find a function that implements it. And worse; it can either be in a header, or in a cpp file... and it can be overridden/inherited, so: good luck looking for it!
full member
Activity: 200
Merit: 104
Software design and user experience.
June 04, 2013, 11:42:08 AM
#29
2. Excessive use of C++ subclasses and operators makes it hard to read code. You see a << b, but it actually goes to a very specific place which is not entirely obvious where.

Streaming operators << and >> have always been the standard way of doing I/O in C++ so are you saying these operators are being used for something *other than streaming*?


I have nothing against using << as a streaming operator. The problem is that it's much harder to search for any operators in use (be it "<<" or "+"). Especially when you pointer-dereference operator overload. Or implicit copy constructors. Yes, code may look elegant for a mathematician, but inside an app where you have tons of multi-word symbols, operator density or implicitness is painful.

When you have "[a add:b]" instead of "a + b" it's much clearer what is going on and you can quickly find all occurrences of -add: method call.

legendary
Activity: 1064
Merit: 1001
June 04, 2013, 11:06:11 AM
#28
Donald Knuth and Linus Torvalds both agree with this sentiment.  Smiley Just like any other tool, you have to know when to use it, and when not to use it.

Bitcoin source is by no means even remotely close to being a model of C++ exposition. Expedience always takes priority over tidiness.
legendary
Activity: 1526
Merit: 1136
June 04, 2013, 10:47:53 AM
#27
If you're working on a native Mac wallet, you might want to contact Colin Tulloch. He's also exploring this. I've been trying to convince him to use bitcoinj compiled down to native code with GCJ/CNI. I prototyped this last year and got an Objective-C++ app that could load bitcoinj wallets up and running, the end result was a native .app without any Java dependencies. Unfortunately for various reasons I stopped rebasing that branch and the support wasn't fully documented or integrated into bitcoinj. But writing a real SPV wallet app is a lot of work, so reusing the work we've done in the Java world makes a ton of sense. From the code perspective it looks like writing C++ except you don't need to delete objects and the API uses jstrings instead of std::string or NSString.
legendary
Activity: 1596
Merit: 1100
June 04, 2013, 10:47:42 AM
#26
The fact that goto has been used badly doesn't make it a bad instrument: it's a great instrument if you know exactly when to use or not use it.

Donald Knuth and Linus Torvalds both agree with this sentiment.  Smiley

Just like any other tool, you have to know when to use it, and when not to use it.

legendary
Activity: 1064
Merit: 1001
June 04, 2013, 10:46:40 AM
#25
it ties into the topic, What are the problems that the code creates? What problems will it cause?

Hard to read, harder to change without breaking something.
hero member
Activity: 727
Merit: 500
Minimum Effort/Maximum effect
June 04, 2013, 10:45:16 AM
#24
it ties into the topic,

What are the problems that the code creates? What problems will it cause?
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 10:34:56 AM
#23
...

Completely off-topic. This post is only about the form of the code and not its content (which is equally important, but not the subject of this thread).
hero member
Activity: 727
Merit: 500
Minimum Effort/Maximum effect
June 04, 2013, 10:24:01 AM
#22
I don't know how to program C++, but I can tell from what I do know that the Bitcoin system feels intentionally limited.

the block chain limit of 1mb... creates fee scarcity fluctuations; The limit will be hit sooner and economic effects from the fees will be visible once we get close to it.

the size of the coin limit of 21 million, if it had been 210 million with 500 coin initial block release, the price would more easily be able to handle large fluctuations a far smoother accent to it's final value.Having the limit that small to me feels like it was done intentionally for experimental observations, more scarcity econonomics.

also the number of zeros past the period also feels like a mistake with large disparities in value between two currencies it becomes very difficult to transfer financial information when large chunks of an economy are absorbed, Think along the lines of 100 trillion yen cap value to bitcoin with someone trying to exchange a small amount to a country like zimbabwe with a 1million/1USD value... there are not enough digits to transfer the value accurately in that situation, you'd be limited to doing 100 thousand zimbabwe dollar transaction... what if you can buy a cup of coffee in zimbabwe with 100 Z dollars? you wouldn't be able to do the micro-transaction.

10 minute confirms? when transactions can go around the globe in under a second. with a 1mb limit every 1 minute it could more effectively use the network overall power and increase security on a timed basis.

It would not surprise me that the code was written intentionally for big problems to occur much sooner, for expermentation... Bitcoin really is an experiment, the limits it has are made to cause instability intentionally or to observe data fluctuations more easily. The code itself could be flawed and vague on purpose.

So what is everyone doing to improve these possibly intentional limitations?

legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 10:11:14 AM
#21
Close enough to have a working goto... Smiley

Hmm... am not really sure about that (and no C++ guru would ever recommend using it) - the problem is that the compiler needs to handle all the object dtors correctly (the reason why it is *not easier for the compiler*).

I am not sure that g++ (or other major compilers) give such a guarantee.

It's a bit like using *void* pointers (another common C idiom that is *bad* in C++).
legendary
Activity: 2058
Merit: 1416
aka tonikt
June 04, 2013, 10:08:16 AM
#20
Really?  Well, then I was wrong all my life, believing that C++ was backward compatible with C... Smiley

You are wrong - C++ is *not* backwards compatible with C only as *close as possible*.
Close enough to have a working goto... Smiley
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 09:39:22 AM
#19
Really?  Well, then I was wrong all my life, believing that C++ was backward compatible with C... Smiley

You are wrong - C++ is *not* backwards compatible with C only as *close as possible*.
hero member
Activity: 630
Merit: 500
Bitgoblin
June 04, 2013, 09:36:50 AM
#18
The fact that goto has been used badly doesn't make it a bad instrument: it's a great instrument if you know exactly when to use or not use it.

Opposing it just because someone isn't trained or smart enough to use it properly is a dumbing down which does much much much more harm than good.
legendary
Activity: 2058
Merit: 1416
aka tonikt
June 04, 2013, 09:35:17 AM
#17
Coding in C and never using goto, is like driving a car and never using its last gear. Safe for poor drivers... Wink

Bitcoin is written in C++ (which is not even close to C as any C++ programmer knows).
Really?  Well, then I was wrong all my life, believing that C++ was backward compatible with C... Smiley
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 09:33:45 AM
#16
Coding in C and never using goto, is like driving a car and never using its last gear. Safe for poor drivers... Wink

Bitcoin is written in C++ (which is not even close to C as any C++ programmer knows).
legendary
Activity: 2058
Merit: 1416
aka tonikt
June 04, 2013, 09:28:10 AM
#15
Coding in C and never using goto, is like driving a car and never using its last gear. Safe for poor drivers... Wink
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 09:15:31 AM
#14
2. Excessive use of C++ subclasses and operators makes it hard to read code. You see a << b, but it actually goes to a very specific place which is not entirely obvious where.

Streaming operators << and >> have always been the standard way of doing I/O in C++ so are you saying these operators are being used for something *other than streaming*?
full member
Activity: 200
Merit: 104
Software design and user experience.
June 04, 2013, 09:12:19 AM
#13
"goto err" is not a big deal in my view.

Bitcoin-QT is a mess for entirely different reasons.

1. Endianness is not well documented. libbitcoin flips some bytes where BitcoinQT does not, but also does not document why they are doing that.

2. Excessive use of C++ subclasses and operators makes it hard to read code. You see a << b, but it actually goes to a very specific place which is not entirely obvious where.

3. Some utility class names look like variable names.

4. Some funny design patterns are not documented even with a single line of text. E.g. CBigNum is smartly done (BN_CTX and BIGNUM are wrapped in classes differently), but you have to be really proficient in C++ or spend half a day deciphering the code to understand why it is done that way. For someone coming from C/Objective-C it's not easy.

I'm working on Mac wallet app and reimplement many things that BitcoinQT does in C and ObjC and learn how that whole thing works. It is smart, but it's messy.
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 08:52:20 AM
#12
You're a OpenCoin employee / currently hired by OpenCoin?

No
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 08:48:38 AM
#11
It's doable but it needs to be a design criteria from the beginning.

Indeed - I did it with an Object Database I created (the error string buffers are pre-allocated before the ODB instance is even created) - it is a little tricky though as you end up using "non-standard" exceptions (although you can make it enough like a std::exception to be useful).
hero member
Activity: 518
Merit: 500
June 04, 2013, 08:48:25 AM
#10
You're a OpenCoin employee / currently hired by OpenCoin?
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 08:47:04 AM
#9
...I doubt there is much code out there at all that can really handle out of memory conditions well (for a start you can't throw a std::runtime_error as that needs a std::string to be allocated).

It's doable but it needs to be a design criteria from the beginning.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 08:46:09 AM
#8
I seriously doubt that Bitcoin is written robustly throughout to handle out of memory conditions.

Actually I doubt there is much C++ code out there at all (apart from perhaps OS level code) that can really handle out of memory conditions well (for a start you can't throw a std::runtime_error as that needs a std::string to be allocated).
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 08:44:28 AM
#7
Well in my code you would have seen something like this:
Code:
   if (!pkey || !group || !pub_key || !priv_key) 
      throw runtime_error( "no keys or group found" );

Yeah I agree, I don't see how it is useful to return an error in this case. You want the program to halt. I seriously doubt that Bitcoin is written robustly throughout to handle out of memory conditions.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 08:43:10 AM
#6
Yup - just checked the source link - error handling.

Well in my code you would have seen something like this:

Code:
   if (!pkey || !group || !pub_key || !priv_key) 
      throw runtime_error( "no keys or group found" );

BTW - I hate the term RAII (although it stuck) - I argued years ago on comp.lang.c++.moderated to call the idiom "scoped objects". Smiley
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 08:42:22 AM
#5
Can we have some context on how it was used?

Yep I updated the original post to include a link.

...These situations include: multi-level breaks, resource allocation/deallocation, error handling in C language, computed goto in Perl language.

In this case its error handling in the C language (although Bitcoin is written in C++).

Everybody is afraid of breaking it since it appears to work, and that is reasonable to an extent, but on the other hand this code base is utterly unsuitable for serious work.

Yep. A year ago I came in here and I wanted to work on Bitcoin. Clean it up a bit, reduce external dependencies, etc... but I was pooh-poohed. Now I'm doing the same work in Ripple, and it is welcomed. For Bitcoin code to improve first the people working on it need to acknowledge that there's a growing problem and then commit to addressing it. Even if it is just a little bit at a time, or for example making sure that new code is clean (adding RAII utilities where needed, for example), it can help to reverse the spaghettification.
legendary
Activity: 2058
Merit: 1462
June 04, 2013, 08:38:10 AM
#4
Can we have some context on how it was used?

Also:
Quote
While overall usage of gotos has been declining, there are still situations in some languages where a goto provides the shortest and most straightforward way to express program's logic (while it's possible to express the same logic without gotos, the equivalent code will be longer and often more difficult to understand).

These situations include: multi-level breaks, resource allocation/deallocation, error handling in C language, computed goto in Perl language.[15][16]
hero member
Activity: 714
Merit: 500
Martijn Meijering
June 04, 2013, 08:36:00 AM
#3
Gavin has said that the genius doesn't lie in the code base, but in the algorithms and that the code is crap. I agree with that assessment. There's a somewhat refactored version available that can also be used for alt coins, but I don't have a link handy right now. I've been thinking about refactoring the code myself. Everybody is afraid of breaking it since it appears to work, and that is reasonable to an extent, but on the other hand this code base is utterly unsuitable for serious work.
legendary
Activity: 1890
Merit: 1089
Ian Knowles - CIYAM Lead Developer
June 04, 2013, 08:33:09 AM
#2
I think this would very much depend upon the specific context - although I haven't coded a "goto" myself since the 1980's I did work on some C code with huge *case* statements in the 90's where it can actually make some sense (in general it is not a good idea with C++ due to the problems of exception handling).

Typically the only reason to use such a construct would be to "skip" to the *end* of a large block of code (and of course you could always use *break* inside a loop to do the same thing).

In no way is a *goto* more "efficient for the compiler" though (nor is it very good for human eyes as no-one would *expect* to even *see* a goto these days) so in regards to your quote I'd have to agree it doesn't inspire a lot of confidence.
legendary
Activity: 1064
Merit: 1001
June 04, 2013, 08:30:20 AM
#1
Presented without comment:



link (github.com)
Jump to: