Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing pure code without using third-party header files [closed]

Tags:

c++

c

As try to learn C/C++, I'm always finding it frustrating that I need to use the header files. It makes it seem like it's not my code, but I am using some other person's code instead. I simply want it to be pure, and be written by myself without using the header files.

I know for certain that C/C++ includes libraries that can give the developer some functions in order to for example create a vector. The Boost library are similar to that, but again, I want to write my own code, and maybe create my own library for my work.

But is this possible? If I wrote my own header files for C/C++ that almost acted like the iostream.h file for example, only that I've made it my own, and optimized it, will it be beneficial for my applications/projects, or should I just use the standard library that is included with the programming languages?

like image 595
user3919837 Avatar asked Nov 29 '22 11:11

user3919837


2 Answers

My answer comes, at least partially, in the form of a rhetorical question:

Are you also going to write your own compiler?

You're always using something that someone else wrote, and for general-purpose use this is a very, very good thing. Why? Because they are the experts in their field, because they are multiple people, and because their code has gone through decades of rigorous peer review, thorough testing by millions upon millions of people, and many iterations of improved versions.

Shying away from that as an instinct is one thing, but refusing to use standard headers due to it is quite another, especially when you draw the line so arbitrarily.

In short, there is a damned good reason why the C++ standard defines the standard library and why your compiler vendor ships an implementation of it. My strong recommendation is that you work to that principle.

…which is why mine is not a "slippery slope" argument!

like image 55
Lightness Races in Orbit Avatar answered Apr 27 '23 20:04

Lightness Races in Orbit


Off course you should use the standard library. The only reasons not do so are:

  • The class you want does not exist.
  • You are a pro C++ programmer and something about its implementation really annoys you.
  • You as a beginner want to learn something by trying to build your own simple data storage types (like for instance any vector type )

Your thoughts about "all should be made by yourself" are not that uncommon, but once you've implemented one of the standard types and have spent hours on it while your actual project hasn't progressed one line and when your new "own" type still misses half of the functionality - Then you'll realize that using an existing library (especially the standard library or well known others like boost) might actually be a clever thing.

like image 22
bluewater2 Avatar answered Apr 27 '23 21:04

bluewater2