Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ekiro on March 06, 2024, 06:17:38 AM



Title: why was bitcoin written in C++ instead of pure C?
Post by: ekiro on March 06, 2024, 06:17:38 AM
why


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Mia Chloe on March 06, 2024, 06:29:44 AM
C++ is a more complex language more like an advanced c sharp. Plus it has some extra attributes and is kind of more reliable than C sharp.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: pooya87 on March 06, 2024, 07:00:15 AM
In a big application such as a Full Node with a lot of different parts, you don't need to write everything in such a high level language such as C (or even C++ for that matter if you ask me). Usage of C (and in some cases using assembly like in libsec256k1 used for cryptography) is most useful when you want as much efficiency as you can get.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Ruttoshi on March 06, 2024, 07:22:53 AM
Satoshi basic idea was to create a blockchain network that will make financial interactions easy, and make the process very fast. C++ is the best coding language for such

C++ algorithms can perform at the best level by maximizing resource use and giving the developer control over the CPU and memory use. This algorithm also allows the blockchain to accept or reject blocks, thus eradicating any forks in the blockchain. Using C++, therefore, helps the platform interact with different endpoints at fast rates.

C++ is the extension of C, and C is a low level programming. C++ has some extra features/libraries one can rely on. C++ is good with complex software.

https://cryptoadventure.com/why-satoshi-nakamoto-chose-c-to-program-bitcoin/



Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Mia Chloe on March 06, 2024, 07:48:23 AM
Satoshi basic idea was to create a blockchain network that will make financial interactions easy, and make the process very fast. C++ is the best coding language for such

C++ algorithms can perform at the best level by maximizing resource use and giving the developer control over the CPU and memory use. This algorithm also allows the blockchain to accept or reject blocks, thus eradicating any forks in the blockchain. Using C++, therefore, helps the platform interact with different endpoints at fast rates. 

https://cryptoadventure.com/why-satoshi-nakamoto-chose-c-to-program-bitcoin/


Aside from all these you mentioned, Satoshi pick C++ not only because it was the best but it was also the most efficient one for the job at that time.  C++ was picked because many developers at that time knew how to program with it and there were not much alternatives like SOLIDITY and move had not even been invented at that time. Others like Go and rust at that time were not too common.

The block chain is a whole lot of complex cryptographic data so  using C sharp as a base code will bring a lot of bugs because of its inefficiency to carry such heavy program. Plus C sharp doesn't contain certain complex attributes like C++


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Flavatron on March 06, 2024, 10:11:58 AM
I think the OP asked about C, and C++ ... not c# which is totally different. For the most part, the performance of C and C++ are almost identical in most cases if you were not to use the Object Orientated features(like  inheritance, classes, templates, and some others). C# is a high level level language and not really comparable with either of the above, it's level of abstraction is probably on par with Python.

As others have said too, RUST( which in most cases is set to replace c++ by todays estimation, at least it's the plan for some, like the US Biden admin) wasn't even released in 2007. C++ was basically the defacto language for high performance applications.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: BlackHatCoiner on March 06, 2024, 01:28:10 PM
Because Bitcoin is complex, and complex projects are better to be programmed in object oriented programming. It also comes with rich libraries like STL, which reduce the overall chance for making a mistake, and it improves performance.

C is (usually) faster than C++, but I wouldn't want Bitcoin's source code to be a monster like the Linux kernel, even if it was slightly faster (which isn't necessarily to be the case).


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: promise444c5 on March 06, 2024, 02:20:23 PM
I think the OP asked about C, and C++ ... not c# which is totally different. For the most part, the performance of C and C++ are almost identical in most cases if you were not to use the Object Orientated features(like  inheritance, classes, templates, and some others). C# is a high level level language and not really comparable with either of the above, it's level of abstraction is probably on par with Python.

As others have said too, RUST( which in most cases is set to replace c++ by todays estimation, at least it's the plan for some, like the US Biden admin) wasn't even released in 2007. C++ was basically the defacto language for high performance applications.
Yeah C# is more of object oriented  and it has some frameworks which are dedicated to almost every  aspect of development.
I've  tried python a little and I can't  compare it's level of OOP to that of C# although they kind of have some related calls but different implementation.

C++ and C# C are more  popular with Embedded  system, C++ provides much more scalability than C (which means it will be easy to read than C) but in term of performance  C performs morre faster



Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: pooya87 on March 06, 2024, 04:04:14 PM
Since C# was brought up let me add that C# depends on dotnet framework (today that's just called dotnet) by 2007/2008 there were only dotnet framework 3.5 and it was closed source. Microsoft only started releasing the source code on January 2008 which meant when Satoshi was coding Bitcoin it was neither mature nor reviewed enough to be used for something as critical as Bitcoin which relied on security.

Today that's different since dotnet is now open source and very mature which can compete with C++ even in speed and efficiency.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: apogio on March 06, 2024, 04:48:26 PM
why

Everything I wanted to add has already been mentioned. C++ is a smart choice in my opinion. Low level language with high compatibility and ease of writting. C can be a pain in the ...
Let me ask the obvious question.
Why do you think it should be written in C? What would be the benefits. I can't see any benefits apart from speed but C++ is also a very fast language.




Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: DaveF on March 06, 2024, 05:25:46 PM
Just putting it out there....it's what Satoshi knew and was comfortable with.

This question has also been asked many times though the years:

https://www.quora.com/Why-is-bitcoin-written-in-C
https://bitcoin.stackexchange.com/questions/48414/why-is-bitcoin-written-in-c
and so on.

In the end it really does not matter, since if the current devs wanted to switch they could.
But none of them seem to want to.

-Dave


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: odolvlobo on March 07, 2024, 01:22:43 AM
Quote
why was bitcoin written in C++ instead of pure C?

I don't think satoshi has ever explained why he chose C++. Anyone can tell you why they would use C++ or C, but only satoshi can answer your question.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: NotATether on March 07, 2024, 07:59:24 AM
I think the OP asked about C, and C++ ... not c# which is totally different. For the most part, the performance of C and C++ are almost identical in most cases if you were not to use the Object Orientated features(like  inheritance, classes, templates, and some others). C# is a high level level language and not really comparable with either of the above, it's level of abstraction is probably on par with Python.

Seriously though, try implementing a linked list or hash table in C. And then again for your second and third project. Then you will see why everyone uses STD for this kind of stuff.

There is only so much you can implement without using classes, if you don't want to fill up your program with messy structures and pointers like in the Linux kernel. It makes for an unmaintainable mess.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Flavatron on March 07, 2024, 09:47:35 AM
I think the OP asked about C, and C++ ... not c# which is totally different. For the most part, the performance of C and C++ are almost identical in most cases if you were not to use the Object Orientated features(like  inheritance, classes, templates, and some others). C# is a high level level language and not really comparable with either of the above, it's level of abstraction is probably on par with Python.

Seriously though, try implementing a linked list or hash table in C. And then again for your second and third project. Then you will see why everyone uses STD for this kind of stuff.

There is only so much you can implement without using classes, if you don't want to fill up your program with messy structures and pointers like in the Linux kernel. It makes for an unmaintainable mess.



100%. I probably wasn't very clear in my answer, but what I was meaning is C and C++ are very much related( so much so that if certain OO features are not used, the performance is exactly the same). However you are most certainly right, and actually writing something(complex) without using OO = pain! :)


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: Flavatron on March 07, 2024, 09:52:26 AM
Because Bitcoin is complex, and complex projects are better to be programmed in object oriented programming. It also comes with rich libraries like STL, which reduce the overall chance for making a mistake, and it improves performance.

C is (usually) faster than C++, but I wouldn't want Bitcoin's source code to be a monster like the Linux kernel, even if it was slightly faster (which isn't necessarily to be the case).

True. There has been some momentum around moving the kernel over to Rust, in time.

https://www.zdnet.com/article/rust-in-linux-where-we-are-and-where-were-going-next/


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: ekiro on March 07, 2024, 08:35:50 PM
I think the OP asked about C, and C++ ... not c# which is totally different. For the most part, the performance of C and C++ are almost identical in most cases if you were not to use the Object Orientated features(like  inheritance, classes, templates, and some others). C# is a high level level language and not really comparable with either of the above, it's level of abstraction is probably on par with Python.

Seriously though, try implementing a linked list or hash table in C. And then again for your second and third project. Then you will see why everyone uses STD for this kind of stuff.

There is only so much you can implement without using classes, if you don't want to fill up your program with messy structures and pointers like in the Linux kernel. It makes for an unmaintainable mess.


makes sense. thank god he didn't use java...


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: promise444c5 on March 08, 2024, 07:11:37 AM

 However you are most certainly right, and actually writing something(complex) without using OO = pain! :)


Lol  ;D this explains  why php has the frame work Laravel it more of OO features but some comes with OO =pain(may be not complex)


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: apogio on March 08, 2024, 07:55:23 AM
Seriously though, try implementing a linked list or hash table in C. And then again for your second and third project. Then you will see why everyone uses STD for this kind of stuff.

There is only so much you can implement without using classes, if you don't want to fill up your program with messy structures and pointers like in the Linux kernel. It makes for an unmaintainable mess.

makes sense. thank god he didn't use java...

Java is a more advanced C++. It's great for general purpose applications and of course it's easy to use and maintain. Most of the libraries you need are available in Java, so actually customization is minimal, most of the time.
On the other hand, NotATether is right about C. In C you can literally do anything you want, because you have direct access to the RAM (memory), using pointers and memory allocation functions (malloc, calloc etc). However, this "freedom" most of the time comes with an "unmaintainabe mess" (this phrase was perfectly used here).


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: ABCbits on March 08, 2024, 10:40:54 AM
Because Bitcoin is complex, and complex projects are better to be programmed in object oriented programming. It also comes with rich libraries like STL, which reduce the overall chance for making a mistake, and it improves performance.

C is (usually) faster than C++, but I wouldn't want Bitcoin's source code to be a monster like the Linux kernel, even if it was slightly faster (which isn't necessarily to be the case).
True. There has been some momentum around moving the kernel over to Rust, in time.

https://www.zdnet.com/article/rust-in-linux-where-we-are-and-where-were-going-next/

But so far, Rust (along with other language) remain to have small popularity[1]. In addition, previously Linux kernel already switch from C89 to C11[2].

--snip--
Java is a more advanced C++. It's great for general purpose applications and of course it's easy to use and maintain. Most of the libraries you need are available in Java, so actually customization is minimal, most of the time.
--snip--

Does your statement apply to Java in general or just newer Java version? I often hear Java 8.0 or older is hated due to various reasons.

[1] https://openhub.net/p/linux/analyses/latest/languages_summary (https://openhub.net/p/linux/analyses/latest/languages_summary)
[2] https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/ (https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/)


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: apogio on March 08, 2024, 02:02:01 PM
Does your statement apply to Java in general or just newer Java version? I often hear Java 8.0 or older is hated due to various reasons.

[1] https://openhub.net/p/linux/analyses/latest/languages_summary (https://openhub.net/p/linux/analyses/latest/languages_summary)
[2] https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/ (https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/)

I have been a Java software engineer since 2017. When I first started we used Java 6. Now we mainly use Java 11.

Certainly Java has evolved. Before Java 8 it was a bit frustrating and not feature rich.

Java 8 was a huge development in my opinion. Then Java 11 is also a big step up.

Nowadays, Java 19 has some significant new features.

What I love about Java is the platform independence and the fact that it is maintained very well. People keep using it and keep supporting its development.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: promise444c5 on March 08, 2024, 09:11:18 PM
Does your statement apply to Java in general or just newer Java version? I often hear Java 8.0 or older is hated due to various reasons.

[1] https://openhub.net/p/linux/analyses/latest/languages_summary (https://openhub.net/p/linux/analyses/latest/languages_summary)
[2] https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/ (https://www.zdnet.com/article/linus-torvalds-prepares-to-move-the-linux-kernel-to-modern-c/)

I have been a Java software engineer since 2017. When I first started we used Java 6. Now we mainly use Java 11.

Certainly Java has evolved. Before Java 8 it was a bit frustrating and not feature rich.

Java 8 was a huge development in my opinion. Then Java 11 is also a big step up.

Nowadays, Java 19 has some significant new features.

What I love about Java is the platform independence and the fact that it is maintained very well. People keep using it and keep supporting its development.
Never used java maybe because while I was starting my learning the horror I heard about it made me ran away from it :D(poor me!) but I could say 70% out of known people  migrated  due to its implementation just like a mini C language


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: apogio on March 08, 2024, 09:24:03 PM
Never used java maybe because while I was starting my learning the horror I heard about it made me ran away from it :D(poor me!) but I could say 70% out of known people  migrated  due to its implementation just like a mini C language

What do you mean "migrated"? And more importantly what do you mean "mini C"?

Migration from C to Java is almost impossible. Most of the time the apps that are written in C, will remain in C, or they will be re-writen in Java from scratch.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: promise444c5 on March 08, 2024, 09:28:36 PM


What do you mean "migrated"? And more importantly what do you mean "mini C"?

Migration from C to Java is almost impossible. Most of the time the apps that are written in C, will remain in C, or they will be re-writen in Java from scratch.
Although I don't use Java or have knowledge about it wither ....... just saying it's implementation is just like C  so I called it mini C(not interm of it's functionality though).
 "Migrated"=>  migrate to other language  but it was added to their skill stack (forgot to add that earlier).


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: JimmyCoin on March 08, 2024, 11:50:11 PM
im no programming expert but this is my take...

asking this is like asking why anyone creates anything in their language of choice and not in assembly...

newer languages like c++ build on existing languages and make it easier for developers to achieve what they want with less work involved.

its the same reason developers choose unreal engine or unity to build their games and not their own because simply its less work to achieve their goal.


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: promise444c5 on March 12, 2024, 06:31:37 AM

newer languages like c++ build on existing languages and make it easier for developers to achieve what they want with less work involved.


Newer Languages  ::)
C++ has been in existence since 1979 although there were later ammendments for release.
Rust is  newer maybe that's what you meant

Unity=> C# (less work ,less speed)
UnrealEngine => C++ (more work , more speed)


Title: Re: why was bitcoin written in C++ instead of pure C?
Post by: alexeyneu on March 13, 2024, 07:11:23 AM
it used vectors from the start. it's stl and part of c++.you can check say base58 lib. no one can tell if he's good enough in C to do it that way