Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Zoomic on May 30, 2023, 09:54:54 PM



Title: why was Bitcoin written in C++?
Post by: Zoomic on May 30, 2023, 09:54:54 PM
I have tried to figure out why Satoshi decided to go with C++ in writing bitcoin codes. I have some of these assumptions below, I decided to share to learn more;

  • Could it be that C++ is the most popular language then?
  • Could it be that it is the language Satoshi was more conversant with. As a developer,  I try to use the language I know too well, even if it might be inefficient
  • Is there any security advantages of using C++? I mean python also supports open source and Js enhances scalability.  Why the special interest in C++
  • Right now C++ is largely regarded as the best language for crypto coding. Is this accolade given C++ because Satoshi used it and developed the king of cryptocurrency.  Assuming Satoshi used another language,  is there any possibility that the language would be more adopted for crypto coding
  • Finally,  is there any possibility that since 1985 C++ is developed, there will be a time it will become an obsolete language and bitcoin codes will require that it should be re-written in another language?


Title: Re: why was Bitcoin written in C++?
Post by: BitMaxz on May 30, 2023, 10:35:21 PM
Satoshi Nakamoto never explains why he chose to use C++ language more than others even on his whitepaper he didn't mention it but you can build blockchain in any language.

However, I think he chose C++ due to the speed and efficiency compared to other languages like Python and it was known that can handle big data.


Title: Re: why was Bitcoin written in C++?
Post by: sheenshane on May 30, 2023, 10:46:04 PM
I think he chose C++ due to the speed and efficiency compared to other languages like Python and it was known that can handle big data.
The first thing that comes to my mind is what you've said above because C++ is known for its performance and efficiency when it comes to speed.  Another reason for choosing C++ could be because it was wide availability and a mature ecosystem, C++ has been around for several decades and has a vast community of developers supporting it.

And the last one could be, C++ allowed the Bitcoin developers to have direct access to the systems, enabling them to write code that interacts efficiently with the system resources.  Whatever the reason is, as long as it operates in a decentralized way and C++ was suitable for it.


Title: Re: why was Bitcoin written in C++?
Post by: Yamane_Keto on May 31, 2023, 07:16:01 AM
I have tried to figure out why Satoshi decided to go with C++ in writing bitcoin codes. I have some of these assumptions below, I decided to share to learn more;
You have to distinguish between Bitcoin, which is a protocol, and the software that runs full nodes, which is Bitcoin Core in our case.
Your question is What made satoshi written Bitcoin core using C++ as the main programming language.

One of the most important advantages of C++ language is that it gives great control over memory usage, the program can be written will be very consistently without the need to rewrite the code from scratch in case you want to write for a different programming language.

You will find more reasons on the internet, but Satoshi had to choose a programming language and this language was C++ because it is the best and he (she or they) may have other reasons, God only knows.


Title: Re: why was Bitcoin written in C++?
Post by: goatpig on May 31, 2023, 07:36:51 AM
AFAIK he was in touch with Wei Dai via various cypherpunk forums. Bitcoin used CryptoPP, Wei Dai' C++ crypto library. I assume that had some weight in the balance.


Title: Re: why was Bitcoin written in C++?
Post by: witcher_sense on May 31, 2023, 07:55:26 AM
Could it be that C++ is the most popular language then?
According to the data from https://www.tiobe.com/tiobe-index/, Java, C, and C++ were one of the most popular programming languages in 2008.

Quote
Could it be that it is the language Satoshi was more conversant with. As a developer,  I try to use the language I know too well, even if it might be inefficient
Developers usually write in the languages they are most proficient in, but you can solve the problem with any programming language you like and later reimplement it in another to make the solution more efficient and suitable for particular use cases.

Quote
Is there any security advantages of using C++? I mean python also supports open source and Js enhances scalability.  Why the special interest in C++
As far as I know, C++ has no serious vulnerabilities, and it is supported by a large community of developers and regular contributors. If you want to build a secure system, then C++ is quite suitable for achieving your goal.

Quote
Finally,  is there any possibility that since 1985 C++ is developed, there will be a time it will become an obsolete language and bitcoin codes will require that it should be re-written in another language?
Bitcoin already has dozen of implementations in different languages, so it is not necessary to rely on C++ as a popular choice among developers.


Title: Re: why was Bitcoin written in C++?
Post by: hZti on May 31, 2023, 09:06:04 AM


You will find more reasons on the internet, but Satoshi had to choose a programming language and this language was C++ because it is the best and he (she or they) may have other reasons, God only knows.

It is also believed that satoshi was already of a high age when he created bitcoin, maybe he was already retired or close to his retirement. For this reason he probably was not so fluent in more modern coding languages and also bitcoin works perfectly in C++, so why bother to write it in another langue. You have to remember that at first bitcoin was slimly a project that was managed of a handful of people and nobody would have thought that the adoption would be this huge.

What speaks for this thesis is also that satoshi left bitcoin not long after it was published, since he probably simply retired. That is something a young person would probably not do, but who knows. Satoshi could still be here under another name and nobody would know.


Title: Re: why was Bitcoin written in C++?
Post by: Synchronice on May 31, 2023, 10:17:37 AM
I would describe bitcoin idea in four words: A currency, blockchain, node and miner.
Satoshi needed to create something that was super secure, resource efficient and fast. You have to keep in mind the equipment that was available back then, there weren't so powerful PCs 15 years ago. Bitcoin's block size was limited to 1MB, mining uses Proof Of Work consensus, blocks should be validated quickly. I don't have a background in programming, I just started learning of javascript recently, so, there may be other reasons why he chose C++ but from all of these, I would say that he chose C++ over others because of its excellent performance, efficiency and support back then.


Title: Re: why was Bitcoin written in C++?
Post by: ABCbits on May 31, 2023, 10:50:19 AM
    • Finally,  is there any possibility that since 1985 C++ is developed, there will be a time it will become an obsolete language and bitcoin codes will require that it should be re-written in another language?

    As long as C++ remain popular and actively receive new update/standard, it won't become obselete. For reference, C++20 standard already released while C++23 standard still in progress.



    Could it be that C++ is the most popular language then?
    According to the data from https://www.tiobe.com/tiobe-index/, Java, C, and C++ were one of the most popular programming languages in 2008.

    TIOBE use very poor data source though, since it seems they rely on total search result with specific keyword on few different search engine.

    The TIOBE Programming Community index is an indicator of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings. It is important to note that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.


    Title: Re: why was Bitcoin written in C++?
    Post by: Yamane_Keto on May 31, 2023, 12:43:36 PM

    It is also believed that satoshi was already of a high age when he created bitcoin, maybe he was already retired or close to his retirement. For this reason he probably was not so fluent in more modern coding languages and also bitcoin works perfectly in C++, so why bother to write it in another langue. You have to remember that at first bitcoin was slimly a project that was managed of a handful of people and nobody would have thought that the adoption would be this huge.

    All the ideas related to Bitcoin were already present, and even the idea of ​​Bitcoin has a historical basis before 2008, but Satoshi was the only one who developed it for a valuable model, and Satoshi was not an exceptionally experienced software developer, and this is evidenced by the presence of a lot of bugs in the versions that he developed .

    Age is not a measure. For example, a 15-year-old teenager was able to hack a *wallet* claiming to be an unhackable crypto wallet.
    https://techcrunch.com/2018/08/14/unhackable-bitfi-crypto-wallet-has-been-hacked/
    https://www.talkimg.com/images/2023/05/31/wHIw5.png
    Source researchgate/Elise Alfieri (https://www.researchgate.net/figure/Chronological-timeline-This-figure-illustrates-the-chronological-timeline-of-the_fig1_349310768)


    Title: Re: why was Bitcoin written in C++?
    Post by: darkv0rt3x on May 31, 2023, 02:30:44 PM
    I also think that C++ was chosen mostly because of 2 reasons. Who wrote either the protocol and the software Bitcoin core where comfortable with the programming language and also because C++ allows a very more "user-friendly" memory management than for instance, languages of lower level such as pure C. Also, trying to build applications which requires graphics like windows and boxes, buttons and so on, in pure C, requires the usage of external libraries such has SDL, and despite the fact tha tI don't know much about it, I know it is very easy to get quite complex and probably less efficient and slower than using C++ or other OOP languages.


    Title: Re: why was Bitcoin written in C++?
    Post by: gmaxwell on May 31, 2023, 02:45:06 PM
    All the ideas related to Bitcoin were already present, and even the idea of ​​Bitcoin has a historical basis before 2008
    Sorry, but in the interest of slowing the spread of misinformation this is just plainly false.  The idea of using a distributed anonymous cryptographic lottery to form a consensus is the revolutinary idea in Bitcoin and it had no historical precedent.  People were working on the problem since at least 2001 (https://lists.ibiblio.org/pipermail/bluesky/2001-March.txt) (search spent-twice) and not finding the answer-- even though they were well aware of the predecessor technologies:  The linked discussion included Hal Finney (eventual creator of RPOW), Adam Back (inventor of hashcash), and Peter Todd (eventual Bitcoin developer).

    Quote
    and Satoshi was not an exceptionally experienced software developer, and this is evidenced by the presence of a lot of bugs in the versions that he developed .
    Sorry but that is also a fairly clear falsehood, one spread by inept and inexperienced developers to make themselves sound smarter.  Bitcoin was written in a modern style, almost entirely free of manual memory management.  Normally in industrial software you expect a defect rate of worse than 1 bug per thousand lines of code and bitcoin had a much higher proportion of tricky parts so I would expect a higher defect rate than typical.  Yet the original bitcoin software had an extremely low defect rate-- a few bugs in script mostly.  More than a few of the 'early' bugs found in 2011-2013 were introduced *later* after the initial release, the qualify of Bitcoin fell when public development began but then improved.  The defect rate in the original Bitcoin was significantly better than later developed altcoins which had the benefit of Bitcoin as an example and in some cases extremely experienced developers.  Comments by reviewers back in 2011 were mostly along the lines of "issues you expect to be there just aren't there".  The low defect rate is particularly surprising for a one-person project and has even been a reason some people have wondered if Satoshi didn't have more help than he made publicly known.

    Some of these comments are because the original software lacked the modularity that would make sense for the later feature set, but those later features weren't imagined at the start so designing for them would have been an error and would have increased the defect rate.  It's easy to be critical in hindsight *after* you know the features that would later be developed.  But given the amount of *churn* in Bitcoin core, if choice of the correct abstractions and modules is a metric to judge experience we could say it supports an argument that Satoshi was more experience than the entire Core project is today (lol, but I don't think choice of abstractions is a very good metric).

    It's possible that Satoshi was inexperienced but was a natural at it and worked very hard to get it right, but we absolutely can't say that there was poor software quality which implied inexperience.  I can't think of a single concrete "inexperienced developers do this" error that anyone has cited (other than the lament that it was not very modular).  Even the script bugs, they mostly arose through bad and surprising abstractions in library code-- not because of erroneous code that Satoshi wrote, maybe you could argue that failure to anticipate the library code being junk was a mark of inexperience but by that standard almost no one ever becomes experienced.


    For this reason he probably was not so fluent in more modern coding languages and also bitcoin works perfectly in C++, so why bother to write it in another langue.
    What more modern language would he have used?  The likely candidates that existed at the time have extremely poor performance (particularly memory usage overheads but also runtime), given that Bitcoin has many times been at the breaking point keeping up with the traffic and there are no alternative implementations with acceptable performance written in those more modern languages even today, I think that would have been unwise indeed.




    Title: Re: why was Bitcoin written in C++?
    Post by: Kryptowerk on May 31, 2023, 10:35:31 PM

    Quote
    and Satoshi was not an exceptionally experienced software developer, and this is evidenced by the presence of a lot of bugs in the versions that he developed .
    Sorry but that is also a fairly clear falsehood, one spread by inept and inexperienced developers to make themselves sound smarter.  Bitcoin was written in a modern style, almost entirely free of manual memory management.  Normally in industrial software you expect a defect rate of worse than 1 bug per thousand lines of code and bitcoin had a much higher proportion of tricky parts so I would expect a higher defect rate than typical.  Yet the original bitcoin software had an extremely low defect rate [...]

    Thanks for these very informative and intersting lines on Satoshis coding skills. I vaguely remember reading a similar comment years ago, but with less substance and also less infotainment factor.
    You mentioned the low error-to-codel-ratio could be an indication for a team working behind the pseudonym of Satoshi - how likely do you personally rate this hypothesis to be true and are there other indicators pointing in that direction?


    Title: Re: why was Bitcoin written in C++?
    Post by: NotATether on June 01, 2023, 06:48:12 AM
    Right now C++ is largely regarded as the best language for crypto coding. Is this accolade given C++ because Satoshi used it and developed the king of cryptocurrency.  Assuming Satoshi used another language,  is there any possibility that the language would be more adopted for crypto coding

    The only reason why it is believed that C++ is the most popular language for developing crypto projects is that thousands of projects are just forks of Bitcoin and Monero which all use C++.

    These don't have smart contracts so they can't just write a token for it like Ethereum (which is written in Golang) and derivatives, they have to clone the entire physical codebase.

    Also many of the more "modern" languages did not exist back in 2008 when Satoshi started coding this thing. There was really only C/C++, Java, Python, ... you get the idea. Be thankful that he didn't write it in Delphi or Pascal :)


    Title: Re: why was Bitcoin written in C++?
    Post by: BlackHatCoiner on June 01, 2023, 08:13:53 PM
    I tend to believe it's because C/C++ has probably the best readability : efficiency tradeoffs, at least comparably to the high level languages of that time. C is pretty much the father of programming languages; just think that the entire linux kernel is written in C. And, while efficiency isn't prioritized in many software, I think Bitcoin needs to run efficiently. Otherwise, someone else will write a more efficient alternative.


    Title: Re: why was Bitcoin written in C++?
    Post by: Zoomic on June 01, 2023, 11:27:37 PM
    Right now C++ is largely regarded as the best language for crypto coding. Is this accolade given C++ because Satoshi used it and developed the king of cryptocurrency.  Assuming Satoshi used another language,  is there any possibility that the language would be more adopted for crypto coding

    The only reason why it is believed that C++ is the most popular language for developing crypto projects is that thousands of projects are just forks of Bitcoin and Monero which all use C++.
    This makes alot of sense to me. Since the codes system is open source, it was accessible to many who cloned it and mare make lily changes to create their own coin. This should be the genesis of C++ as the most popular language for crypto projects development.

    • Finally,  is there any possibility that since 1985 C++ is developed, there will be a time it will become an obsolete language and bitcoin codes will require that it should be re-written in another language?

    As long as C++ remain popular and actively receive new update/standard, it won't become obselete. For reference, C++20 standard already released while C++23 standard still in progress.

    Great to remind me of this. I think I wasn't thinking then....
    https://www.talkimg.com/images/2023/06/02/wm9vb.gif


    Title: Re: why was Bitcoin written in C++?
    Post by: SamReomo on June 02, 2023, 05:56:34 AM
    I have tried to figure out why Satoshi decided to go with C++ in writing bitcoin codes. I have some of these assumptions below, I decided to share to learn more;

    • Could it be that C++ is the most popular language then?
    • Could it be that it is the language Satoshi was more conversant with. As a developer,  I try to use the language I know too well, even if it might be inefficient
    • Is there any security advantages of using C++? I mean python also supports open source and Js enhances scalability.  Why the special interest in C++
    • Right now C++ is largely regarded as the best language for crypto coding. Is this accolade given C++ because Satoshi used it and developed the king of cryptocurrency.  Assuming Satoshi used another language,  is there any possibility that the language would be more adopted for crypto coding
    • Finally,  is there any possibility that since 1985 C++ is developed, there will be a time it will become an obsolete language and bitcoin codes will require that it should be re-written in another language?

    I agree with the answers of the reputed members of the forum but in my mind the answer is a little different. I think Satoshi chose to write Bitcoin in C++ programming language because he was good at that language and his main programming language at that time might be C++ because of the wide acceptability. He might have also tried the thing using other codes and failed to get it into the state that C++ helped him to get. I might be wrong but that's what I think of right now.

    Everyone knows that C++ was and is one of the most famous programming languages out there and many of the top software creators have mastered the language and have built applications specifically in that language.  Some of those well known applications that have been built using C++ code are Adobe Photoshop, Google chrome, Git, Dropbox, and many others. The most of the AAA titles use that language for creating those high graphics games. Even the operating systems are mainly codded with C++ programming language.

    In 2008 the best language for programmers was C++ and there were many guides, and tutorials available for that language. Other languages weren't as efficient and as useful for creating high quality software piece in those times, the best programmers of the era chose C++ for their projects and most of those applications are still based on the same code with fixed bugs and added features.

    So, if we keep all those things in our mind than it was a good decision to chose C++ over other programming languages to create a safe and useful digital currency for the world. Even if we leave the coding language behind, it's still a inspiring thing to notice that someone like Satoshi gave us a gift in the form of Bitcoin and he was so sincere that he left it in the hands of the community. If fame was his intention then he would never disappear from the scene, and trust me he would be among the richest and most famous people of the world if he didn't chose to disappear.


    Title: Re: why was Bitcoin written in C++?
    Post by: ABCbits on June 02, 2023, 09:15:17 AM
    C is pretty much the father of programming languages; just think that the entire linux kernel is written in C.

    Not entire linux kernel though, very small amount of linux kernel are also written with Assembly, C++ and Rust.

    Everyone knows that C++ was and is one of the most famous programming languages out there and many of the top software creators have mastered the language and have built applications specifically in that language.  Some of those well known applications that have been built using C++ code are Adobe Photoshop, Google chrome, Git, Dropbox, and many others. The most of the AAA titles use that language for creating those high graphics games. Even the operating systems are mainly codded with C++ programming language.

    In 2008 the best language for programmers was C++ and there were many guides, and tutorials available for that language. Other languages weren't as efficient and as useful for creating high quality software piece in those times, the best programmers of the era chose C++ for their projects and most of those applications are still based on the same code with fixed bugs and added features.

    While C++ indeed is great programming language, i can't help but think your statement is just very biased towards C++.
    1. C++ is far from most famous programming language based on https://survey.stackoverflow.co/2022/ (https://survey.stackoverflow.co/2022/).
    2. Linux is almost entirely written with C, while Windows and Mac also use C. See https://stackoverflow.com/a/580300 (https://stackoverflow.com/a/580300).
    3. There's no such thing such as best programming language.


    Title: Re: why was Bitcoin written in C++?
    Post by: DaveF on June 02, 2023, 10:35:23 AM
    I am going to have to go with the theory of what most things are written in a particular language. It's white the person knows.

    Many times, we have done things for web-based apps in PHP that we know can be done more efficiently using a different language. But, and this is a huge BUT everybody in the office knows PHP everybody in the office can deal with any issues if they come up. So PHP it is. Satoshi could have done it differently, but if C++ was what was known then that is what was used.

    -Dave


    Title: Re: why was Bitcoin written in C++?
    Post by: Kryptowerk on June 02, 2023, 11:57:04 PM
    I am going to have to go with the theory of what most things are written in a particular language. It's white the person knows.

    Many times, we have done things for web-based apps in PHP that we know can be done more efficiently using a different language. But, and this is a huge BUT everybody in the office knows PHP everybody in the office can deal with any issues if they come up. So PHP it is. Satoshi could have done it differently, but if C++ was what was known then that is what was used.

    -Dave
    Agreed, anyone that's not a mulit-language genius will stick to what they know best.
    However the question should also be, why did Satoshi and future Bitcoin devs know c++ so well? One reason is probably the time-period they learned computer-science related stuff - until the early 2000s c++ was still very popular, before the uprising of Javascript and other web-focused languages.
    Another very important aspect as to why c++ is probably one of the best fits for Bitcoin Core is it's closeness to Assembly. C and C++ allow low-level memory management and offer one of best performances compared to a ton of newer languages.
    These are just my amateur guesses though. :)


    Title: Re: why was Bitcoin written in C++?
    Post by: Zoomic on June 04, 2023, 03:52:35 PM
    But, and this is a huge BUT everybody in the office knows PHP everybody in the office can deal with any issues if they come up.
    As I mentioned above, this is a bit of issue when you are working as a team. In my team, we have few new guys who are coming from the Vue library background but majority of us have been working with Angular. But then, we have to readjust to Vue because the framework is easy to learn.
    The consequence was delay in task management as we depended on documentation for few days.
    Choice of language is sometimes a problem when you are not a solo programmer. I read somewhere that people were helping Satoshi to write codes as he didn't do it all alone.


    Title: Re: why was Bitcoin written in C++?
    Post by: so98nn on June 05, 2023, 05:52:23 PM
    I am not sure if this has any relevancy but I know one company named as 63 moons. It’s a multinational conglomerate and operates in various financial domains as well. Most recently they have started their own crypto currency exchange and they also have pre existing stock market exchanger.

    The programming and full stack development has been done in C++ language itself. Most of the developers they are choosing has extensive knowledge of C programming. When asked to friend working at their firm named “Ticker Enterprise” they said it is both simple and hard language but it is most common in the field of information technology. This could mean that it’s just that it is most basic language, it is the language where everything starts really. That could be the reason for the same.


    Title: Re: why was Bitcoin written in C++?
    Post by: Jerayer on June 08, 2023, 03:54:32 AM
    Modern CPUs have many cores. Some parts of blockchain applications parallelize perfectly (like checking digital signatures) while some parts don't parallelize at all (like executing transactions in order). Modern C++ has a very good mix of effective inter-thread communication and optimization of single-thread performance.

    C++ doesn't have a run time that stops the world or manages memory, giving your application consistent control over this behavior. Move semantics allow you to get objects that behave like values (i=j; a+=1; does not change j) but perform like references (deep copies are avoided except where needed).