6 ms·
Sure, if your goal is to build a compiler that outputs the fastest possible code. If your goal is to apply the "principle of least surprise" to the generated m
by bitwize 6y ago
Sure, if your goal is to build a compiler that outputs the fastest possible code.
If your goal is to apply the "principle of least surprise" to the generated machine code, then that eliminates or constrains most interesting optimizations, including procedure inlining, dead code elision, and compile-time evaluation.
Go is a "principle of least surprise" language, based on a vision of simplicity for C that hasn't existed among actual C implementations (outside of maybe Plan 9) for decades now. It's yet more suckless idiocy: sacrifice everything, including utility and friendliness to end users, to buy "simplicity" for hackers. No wonder the suckless folks love Go so much.
- tgv 6y agoThat seems rather unwarranted attempt at vilification of the language, worded in an odd way: if something sucks, it's bad, so suckless would actually be positive? But why? What's Go done to you? A few if err != nil { ... } statements too many?
- oehtXRwMkIs 6y agoLook up suckless. It has a specific meaning and history.
- dgellow 6y agoSuckless is promoting C99 and disregards anything with a GC. https://suckless.org/coding_style/ https://suckless.org/coding_style/
- MaxBarraclough 6y ago> All variable declarations at top of block. And they say they want their C code to suck less? Why voluntarily open the door to read-before-write undefined-behaviour? The lifetime of a local should be as short as it reasonably can be.
- panpanna 6y agoDoesn't C99 warn you if you make such mistakes?
- flohofwoe 6y agoOn some compilers (gcc and clang at least) only when the warning is enabled (e.g. with -Wall). But I agree that it's a bit silly to on hand recommend C99, and on the other hand, not take advantage of C99 features. It seems like the rules have been written against C89, and the "use unextended C99" only slipped in later.
- yvdriess 6y agoMy take on this: pro: - Storage concerns are separated and grouped at the top. - Logic code is more compact, helping readability. - Stack use can be determined at a glance. - Looking up a variable's type is faster in cases where a variable is used throughout the code block. This is good to optimize, as you constantly need to look up variables when reading C code. - Reflects that object lifetime of any stack storage object is the same regardless of where it is declared in the code block. cons: - For long functions, the distance between use an declaration lines can impair looking up a var's type. (having to scroll to get to the top of your function is a sign you need to break it up though) - In many cases, a variable is only used in one location in the block and has a meaningful static initialization. Local declarations in this case readability, as it does not have to be looked up. - "-Wuninitialized" exists, but passing pointer and defining 'default' value style can still cause read-before-write. I tend to an in-between style, where code is grouped where it makes sense with group-local variables declared in front. Variables that are used throughout the entire code block body are declared at the very top.
- raverbashing 6y agoWell but that's not what's at play here Inlining basic functions shouldn't be surprising to anyone since the 80's? 90's? Unless you compile with -O0 or has a good reason to not inline it. Compilers are usually good at it. Same with the runtime checking every time if a given processor flag exists. What I suppose most runtimes do is replace a function pointer or have a function shin then add a call dynamically to the correct function. Not calling a function repeatedly to check if a processor feature exists.
- lloeki 6y ago> Go is a "principle of least surprise" language, based on a vision of simplicity for C that hasn't existed among actual C implementations (outside of maybe Plan 9) for decades now. It's yet more suckless idiocy Have you considered that this Go opinion might not be “idiocy” but desirable qualities in some use cases? It seems quite inappropriate to bash on Go for realising a vision that solves such a use case, in turn assuming no such use case exists, just as it is inappropriate to vilify Ruby or Python for for having a very dynamic object model and method calling/message passing, witch results in non-optimisable call paths because they have to be resolved every single time. Go’s consistency, reliability, and ease in debugging and exploring is definitely a really good feature that I gladly trade a few microseconds for.
- jashmatthews 6y ago> Ruby or Python for for having a very dynamic object model and method calling/message passing, witch results in non-optimisable call paths because they have to be resolved every single time. The Ruby implementations don't really do that. They use "inline caches" so this lookup normally only happens once per call-site.
- monocasa 6y agoIf there's only one backing type being looked up. If there's more than one, the inline cache thrashs like they're saying.
- jashmatthews 6y agoJRuby has had polymorphic inline caches for like a decade and CRuby will actually cache multiple types in the method cache as long as they cache the same method since https://github.com/ruby/ruby/pull/2583 https://github.com/ruby/ruby/pull/2583
- monocasa 6y agoJRuby is JVM and not really what I'm talking about. And still on CRuby if you have any dynacism, you thrash your cache.
- michaelcampbell 6y agoIndeed. My impression was that go was meant not to "produce the quickest code" but to "produce the code the quickest". The compile speed is one huge use case.
- Someone 6y agoFor the popcnt example, I think that, if a compiler takes it upon itself to detect, at runtime, whether the CPU supports it, it also should make sure it does so reasonably efficiently. After all, the reason this was added must have been because it’s faster than a hand-coded version. The alternative of doing neither would be fine to, and could better fit that “principle of least surprise”, but, of course, also would leave more low-level work to do for go programmers.
- OnlyOneCannolo 6y ago> Go is more about software engineering than programming language research. Or to rephrase, it is about language design in the service of software engineering. [1] This isn't suckless philosophy applied for the sole benefit of compiler writers. It's a compiler whose primary customers explicitly include tool developers. [1] https://talks.golang.org/2012/splash.article https://talks.golang.org/2012/splash.article