r/shittyprogramming • u/minimaxir • Jan 23 '18
The real cause of global warming is Python.
51
Jan 23 '18
How many watt-hours would be saved if all programs were written in assembly?
134
u/TCV2 Jan 23 '18
We would need to compare that to the amount of watt-hours used to create the amount of alcohol needed to keep programmers from killing themselves.
20
u/royisabau5 Jan 23 '18
And also the caloric content of the waffles and soylent they’d eat during development, pre-suicide of course
28
u/ILikeLenexa Jan 23 '18 edited Jan 23 '18
C has barely any overhead. In fact, on average, compilers are probably better at writing assembly code than programmers. I'm talking about stuff that would be a nightmare for maintenance, but the compiler automates it. Loop unrolling, strength reduction, common sub expression elimination, register allocation to avoid clobbering variables.
Though perhaps we could have an ASM compiler and double the benefits. Oh, that's actually every C compiler, just use the __asm directive.
14
u/pergnib Jan 23 '18
Though perhaps we could have an ASM compiler and double the benefits. Oh, that's actually every C compiler, just use the __asm directive.
Not that this makes your overall comment wrong but it's definitely not every C compiler;
__asmand__asm__directives are extensions of the C language and are only available on some compilers.You won't find
__asmon GCC nor__asm__on MSVC, for example.10
2
u/mr-gaiasoul Jun 09 '18
On average, a skilled ASM dev can reduce the size of his C program and increase its speed by ~25% by creating it directly in ASM compared to C. Source "Randy" something. He wrote this public domain book about CISC x86 ASM programming some 20 years ago or something I think ...
He was referencing several scientific sources in these matters ...
He sounded convincing, and I believed him back then, and still do ...
1
u/ILikeLenexa Jun 09 '18
You can get speed, but not portable speed. The specific set of instructions in your ASM is going to be incorrectly balanced for machines in 15 years. Instead, you should write good C that optimizes well on compilers. Even between manufacturers the relative speed of assembly on the same architecture varies (thus gcc's march flag).
Generally, if you have to beat the compiler, the first step is asking the compiler what it would do at O3.
Gcc has a bit of a high level on doing it: https://gcc.gnu.org/wiki/DontUseInlineAsm
0
u/mr-gaiasoul Jun 09 '18
Instead, you should write good C that optimizes well on compilers
Did you notice how I don't disagree with that ...? ;)
43
Jan 23 '18
Well bitcoin takes up the same amount of energy as Denmark, bitcoin code is written in c. Python is written in c, so at least Denmark.
6
20
u/Negatratoron Jan 23 '18
sounds like a good request for r/theydidthemath
5
Jan 23 '18
Isn't that just an aggregation sub? The actual mathematics is usually done somewhere else.
1
31
1
u/konichiwaaaaaa Mar 03 '18
Green computing is a thing though. But the choice of language has little to do with it.
-13
Jan 23 '18
GLOBAL WARMING AND MOON LANDING ARE HOAXES
17
4
Jan 24 '18
bad bot
3
Jan 24 '18
Are you sure about that? Because I am 100.0% sure that contrarianism is not a bot.
I am a Neural Network being trained to detect spammers | Summon me with
!isbot <username>| ^Optout | Feedback: /r/SpamBotDetection | ^GitHub7
Jan 24 '18
The hardware may be a little squishier than you're used to, but one machine that's been trained to react instinctively to keywords is no different from another.
105
u/flukus Jan 23 '18
The carbon footprint of slow languages is probably significant, especially when you factor in computer upgrades for slow software.
That said, isn't all the heavy lifting for CV libraries done in C anyway?