Hacker News new | past | comments | ask | show | jobs | submit login

How much of a speedup did you get switching over to Rob Pike style includes?



I had to look this up:

Rob Pike’s rule is that header files should not include other header files; they should only document which other header files they depend on so programmers can directly include those other header files in their .c files.

https://bytes.com/topic/c/answers/217074-rob-pikes-simple-in...


This seems like the kind of thing that a compiler should be good at instead of making the user jump through hoops.


I'm glad Rob Pike didn't contribute to Go, that'd have been catastrophic to my productivity! Imagine having tools do work instead of users, it'd be like a world without lawyers. Anyhow, I've got to refactor my WIP code for the 10th time today since unused variables are compiler errors. Seeya!


Wow, I hadn't heard of that one. It sounds very unpleasant.

I have the exact opposite rule -- it should always be OK to include a header file on its own. As a corollary, headers must include or forward-declare everything they need.


If the .h file is documenting which other header files it needs, what keeps that documentation up to date. This sounds like a very painful way to work, where .h files fail to compile (with very strange error messages because of the way C++ works) and then you have to hunt down the missing dependency.


In my header libraries I have checks like this which produce a meaningful error message:

    #if !defined(SOKOL_GFX_INCLUDED)
    #error "Please include sokol_gfx.h before sokol_shape.h"
    #endif




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: