5 ms·
Ask HN: C++ devs who went C only
Any C++ devs who got off the train and went C-only to focus their skill set and spend more time on picking up other archtectural type skills instead of keeping up with the new features and standards?
- ActorNightly 2y agoI went from C++ for personal projects to Python for wrapper and C libraries with Python callable code. I basically prototype shit in pure python, and then if i decide i need more speed, I just rewrite the thing in C extension. Its pretty easy to do. ChatGPT can even do 90% of the work for you.
- remram 2y agoHave you tried Cython, numba, and the like?
- ActorNightly 2y agoNo real need. Python 3.12 without any C is usually fast enough for pretty much anything I do. Most of the bottleneck is latency, and for stuff I was using C for, mainly OpenCV for image processing, pytorch already has all the kernels that can run on Nvidia hardware that are way faster anyways.
- remram 2y agoI'm confused, you said you sometimes rewrite code as a C extension...? Have you considered Cython or numba for that?
- ActorNightly 2y agoNo, I used to just python.h, as per https://docs.python.org/3/extending/extending.html https://docs.python.org/3/extending/extending.html I currently don't do that anymore.
- beyondCritics 2y agoI have seen that managers decided to let something rewritten in C, for various reasons, mostly to set the language culture. It seems obvious to me, that no C++ coder would switch voluntarily to C, since then he would reminded of the features he is missing every day glaringly. So either you switch to Zig, Rust,... or (if you are finally fed up) to a functional language or you choose to code in a certain subset.
- dyingkneepad 2y agoI am a dev who work mostly on C-only codebases and it's so... relaxing when I get the opportunity to write C++ so I can use stuff like std::vector or std::string. I think of C++ as a scripting language. On the other hand, I'm not looking forward to reading other people's C++.
- hnthrowaway0328 2y agoMind if I ask what do you do? I'm trying a long shot to break into some C jobs but so far stuck with my data engineering job(yeah I know it's a long shot)
- dyingkneepad 2y agoSorry I can't give details about my specific job. Companies that require C programmers: - Companies that manufacture hardware (drivers are often in C). People often think little when they think about Hardware, but it's much more than usually comes to mind. I bet you didn't think about Cars and Tractors when you thought Hardware. - Companies that develop operating systems (like Google, which develops multiple OSes, Microsoft, Sony, Nintendo, Cisco, Synology, Apple, Samsung, etc). - Companies that use or write low-level system libraries or software that needs to be absolutely fast (think OpenSSL (security), networking stuff, databases, gaming engines, virtualization, compilers, AI, virus scanners, etc). - Companies that do Open Source stuff (a lot of Linux stuff is still written in C). Good luck!
- hnthrowaway0328 2y agoThanks for the information. I guess my next step is to join the right company and slowly transfer to a good position.
- pjmlp 2y agoYikes, C instead of C++, only when customers leave me no alternative.
- softwaredoug 2y agoHow about C w/ Python? I think Python is better at high-level bits than C++ IMO, and you can use C or Cython modules that expose functionality that has to be fast.
- pubby 2y agoI've seen a few people/companies do this and it always baffles me. You don't have to use every C++ feature in existence, but a little bit here and there is far more productive and safe than writing C.
- kazinator 2y agoYou do, if you have to work with an existing code base in which every feature in existence was used. Even if you start a new greenfield project and get to impose your own coding convention that includes what C++ features should be used, it won't stay that way when people come on board who have different ideas.
- tsegratis 2y agoQuestion from a dummy: could you list those features? Would help me a lot. Link to webpages fine too
- pubby 2y agoI mean it depends on the project and scope, but if you just write C-style code but use unique_ptr, vector, string, and <algorithm>, you're already at an advantage.
- hnthrowaway0328 2y agoYeah and auto. Unique pointers really make one think about ownership.
- roeles 2y agoI would recommend replacing macros with constexpr to allow type checking.
- dswilkerson 2y agoThink in object orientation: Put related nouns and verbs together: it is much easier to organize your thoughts using constructors and methods. However do not use virtual methods unless you really must, and if you do, make the class a well-defined explicit interface having only abstract methods. That said, avoid using implementation inheritance: overriding one defined method for another. Get rid of pointers: When passing objects by reference, using references instead of pointers, especially reference to const, makes code much easier to read. When combined with vector instead of raw arrays, most uses of raw pointers go away. Do not implement your own fancy data structures: instead use the Standard Template Library. I use STL map, set, and vector all of the time and they remove the need for most other data-structures. Also, when you can, use iterators to traverse these containers, rather than the visitor pattern. Using iterators keeps the control flow of the client contiguous, so it is much more flexible than visitors.
- GianFabien 2y agoC++ has become a large language. Within any team it seems that each member has their preferred subset of the language. Going back to C only makes sense where C++ features do yield benefits. Personally I prefer code-reviews and project level standards/conventions to maintain cohesion and consistency.
- thesuperbigfrog 2y agoSome thoughts and reasons from the Zero MQ developer: https://250bpm.com/blog:4/ https://250bpm.com/blog:4/ https://250bpm.com/blog:8/ https://250bpm.com/blog:8/
- Rochus 2y agoThat's interesting, thanks for the links.
- Rochus 2y agoThe rapid succession of new standards obviously overwhelms the compiler developers. Personally, I prefer code that is compatible with as many toolchains as possible and therefore stick with old standard versions. There is hardly a feature of the new standards that I miss. In the case of embedded systems with limited resources, I continue to work with C (and soon Micron).