10 ms·
Save the planet Program in C, avoid Python, Perl
- tehsauce 5y agoThis is a very miscalculated take, please avoid.
- smoldesu 5y agoPerl and Python are scripting languages, their energy savings come from the fact that the programmer is typically the only person who will be running it, so it makes more sense to write something that minimizes screen-on time than it does to micro-optimize an app that hundreds of thousands of people will interact with. It's entirely a matter of scale: if you're working server-side, I'd wager you're saving quite a bit of energy by not using an IDE that constantly relies on static analysis to make sure you're not shooting yourself in the foot.
- dmz73 5y agoYou are right about Perlubie and Python being scripting languages but unfortunately people use them for full applications that use 10 to 100 times the memory and CPU of what is necessary. Now C and C++ are the other side of this coin where they could be 10 to 100 times more efficient than scripting languages but it is often difficult to get that right without a lot of work. But there are a number of languages in between where doing the correct thing is easy and CPU and memory efficiency is close to or on par with best C and C++. So we can have nice things after all!
- tablespoon 5y ago> You are right about [Perl] and Python being scripting languages but unfortunately people use them for full applications that use 10 to 100 times the memory and CPU of what is necessary. And honestly, that would be an improvement. The trend seems to be to write more and more applications in JavaScript with Electron [1], which I unrigorously assume uses 10 to 100 times the memory and CPU of an equivalent Python app (given Electron apps seem to most frequently make my fan spin or have some kind of memory leak requiring a force-kill). [1] Now ranking higher on Google than the subatomic particle: https://www.google.com/search?q=electron https://www.google.com/search?q=electron (https://archive.ph/J2HYI https://archive.ph/J2HYI)
- dralley 5y agoJavascript is faster than Python by a not-insubstantial amount, due to JIT and the sheer number of man hours poured into optimizing the browser Javascript engines. I have no idea about memory consumption. I assume Python does better than Javascript there due to reference counting.
- etaioinshrdlu 5y agoWell, JS on v8 (node.js) is usually more CPU efficient than a Python app due to its good JIT compiler. Perhaps the memory usage is not as great due to requiring a GC. I suspect that Electron apps are so easy to create and run somewhat acceptably, that the trend is for the developer to add more bloat than would otherwise be there. So a very efficient runtime leads to developer laziness.
- weare138 5y agoBut you have to take these results with a grain of salt. Both the Perl and Python tests are implementing binary trees in vanilla Perl and Python. Both Perl and Python have performant libraries written in C which is what you would use in a situation like this.
- jhgb 5y ago> Both the Perl and Python tests are implementing binary trees in vanilla Perl and Python. Well, that's how you judge a language. You write code in it, as opposed to writing it in some different language not under consideration. But a much worse problem seems to be the fact that binary-trees is not much of a representative benchmark. It's mostly a benchmark of your memory management. Unless your programs spend 80% of their time managing memory, they'll probably not match the results of binary-trees.
- emilper 5y agothat is _not_ how you judge a _scripting_ language it is trivial* to add C code to Perl, even when using XS, I guess it is as easy to do the same for Python if you do heavy computations in pure Perl5 or pure Python you're doing it wrong by definition *assuming you can write C
- justinator 5y ago> Perlubie Found the Australian.
- Kranar 5y agoThat is true of Perl, but Python powers web apps viewed by billions of users, including reddit and instagram.
- FpUser 5y agoAnd we also burn coal and other lovely stuff for energy.
- throwaway984393 5y agoPython is just as shitty as Perl, it just has different syntax.
- rodmena 5y agoPython is not only a scripting language. It powers many many websites including Youtube. It's a full power limitless language. Your statement is simply wrong.
- Supermancho 5y ago> Python is not only a scripting language. The Python (programming language) is. Ok, if you want to get pedantic you can talk about the language vs interpreter vs ecosystem? I'm not sure what you are getting at. > It powers many many websites including Youtube. It's a full power limitless language. Lots of things "power" Youtube. I'm not sure how that's important to point out.
- throwaway984393 5y ago> It's a full power limitless language Unless you want to do something crazy like run 2 threads at the same time
- grumpyprole 5y agoPython is not limitless. It has very much reached its limit and has major problems with performance, concurrency/parallelism, static analysis and formal semantics. This is why many refer to it as a "scripting language". This doesn't necessary stop people building billion dollar businesses with it though, look at PHP.
- UncleMeat 5y ago> It powers many many websites including Youtube. And this was such a scalability problem that Youtube decided to spend the unimaginable amount of pain and suffering to rewrite in C++.
- rodmena 5y agoI partially agree with your statement. Writing anything in C++ would cause _unimaginable_ amount of pain and suffering. Better way is to isolate slow CPU heavy stuff and write it in C without suffering.
- dragonwriter 5y ago> Perl and Python are scripting languages, With the exception of shell languages (and its overstated even there), the description “scripting language” is usually wrong and at extremely deceptively reductive, even for languages where that was a motivating or at least early major use case. > their energy savings come from the fact that the programmer is typically the only person who will be running it, Even when languages are used for scripting, that's not true.
- whateveracct 5y agoNot sure if this is satire or some light techie ecofascism
- angulardragon03 5y agoThe “donate via crypto” links at the bottom make it even harder to tell
- beepbooptheory 5y agoI think there is another alternative: slightly goofy but also interesting research.
- Minor49er 5y agoIt seems unusual to have a post that makes an environmentalist statement about computer energy consumption, but then end it by requesting donations via cryptocurrencies which are mined through their enormous consumption of electricity.
- CyberRabbi 5y agoIt’s only unusual if you read things online without a healthy sense a humor.
- snek_case 5y agoEthereum is moving to proof of stake, will hopefully solve that problem.
- viraptor 5y agoYes, but not yet and we're not 100% sure it will actually happen or will retain a lot of users. So if you care about computing efficiency, taking crypto (even ETH) now is a weird choice.
- 0x64 5y ago1. It’s already live on the PoS beacon chain, and has been since December 2020. 2. The specs for the transition are ready and it’ll happen next year. Target is before June. First long-lived Merge testnet goes live next month.
- viraptor 5y agoYes, there's a live test. So as mentioned before: we don't know if it will happen for real transactions, if a meaningful number of people will accept it, and when will it happen. (It's likely, but still months away)
- 0x64 5y agoIt's not a test chain, it's _the_ PoS chain that will be transitioned to. It's running on real Ether, over $30b worth of it. You're incredibly out of touch.
- rodmena 5y agoOh yes, let's reinvent the Erlang/OTP in C just to save CPU cycles (I bet that won't be the case). Let's waste millions of hours of programmers' life, just to make a point. C or any "so called" efficient languages are wonderful for their use cases. Python or Erlang have other use cases. We have all of those languages for a reason.
- the_only_law 5y agoI almost want to stoke the fire and make a joke about rewriting things in rust, as the energy expensive seems comparable. Anyway you can take my Erlang from my cold, dead hands.
- wfleming 5y agoI realize this argument is probably tongue-in-cheek, but if we were to take it at face value it would be interesting to factor in energy costs required to feed/house/etc. the programmers for the additional time it would take to implement a given system in C vs python, and how often would the code need to run to make it balance out?
- neverartful 5y agoUse Nim FTW on both fronts!
- jcelerier 5y agoyep, for instance a good benchmark would be: how long would it take to build a decent and snappy GUI operating system from scratch with a custom html/css/js engine in $LANGUAGE ? To give a data point, in 2021-era C++ it's approximately 3 years with a very large part of it being done by a single person (https://github.com/SerenityOS/serenity https://github.com/SerenityOS/serenity). How long would that take with python ?
- jhgb 5y ago> with a custom html/css/js engine That almost sounds like confusing goals with ways to me. Unless those very specific ways are your goal for some reason, if you were to "build a decent and snappy GUI operating system from scratch", you probably wouldn't end up with those things in it. You'd end up with something more similar to Oberon, Smalltalk, or VPRI's system (was it Frank or something like that?).
- mberning 5y agoIt’s a bit like saying the world would be better off if we went back to pre industrial revolution practices.
- jacobr1 5y agoOr if you look at modern tools on the list, you also see golang and rust.
- synergy20 5y agoMany script language runs C in its modules, or c++ for that matter. From the best analysis it does seem modern c++ could be the optimal performance/energy/speed/safety choice. And yes I'm a proud c/c++ programmer.
- jimbob45 5y agoCame here to say this. The planet is programmed in C - it's just the unimportant parts that aren't.
- jancsika 5y agoI always wondered if setting up those Bitcoin rigs in that abandoned warehouse was just a giant waste of energy. Now I have proof it wasn't. Thanks, C++.
- Zababa 5y agoThe sweet spot seems to be Go, Haskell, Java, Lisp, OCaml and maybe JS.
- millerm 5y agoSide note: I always get annoyed when people that have supposedly written code in assembly call it “assembler“. An assembler is a software tool used to convert your assembly source to machine code. It usually makes me feel that they have actually never written in assembly, and use the term to make themselves sound more experienced, or an authoritative source. As soon as I see the misuse of the word I stop reading. Call it a pedantic pet peeve. I don’t write code in assembly.
- H8crilA 5y agoPlease no, a lot more energy and carbon will be wasted undoing the damage done by full stack engineers now suddenly finding out about memory management problems.
- uncomputation 5y agoHow is Go so high? It’s far higher than even Java or Erlang. Is it due to a high CPU usage that compile times in Go are so fast?
- hmrr 5y agoRuntime footprint and CPU is pretty tiny for Go. It’s shockingly low cost to run it. I am frequently surprised.
- uncomputation 5y agoThat’s what I mean. Go has small memory and CPU usage which is one reason it’s good for cloud stuff, but the results indicate opposite. It’s even higher than Haskell which is strange.
- jhgb 5y agoBinary-trees is just an exceptional case for Go (and an unnatural/unusual program to boot). If you look into the paper (https://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sleFinal.pdf https://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sle..., page 261, Figure 2, bottom left chart), you'll see a different benchmark yielding much better results relative to other languages. You'll find overall results on page 263 in Table 4 which aggregates 27 different benchmarks. There you see that time-wise, Go is roughly comparable to Pascal or C#.
- uncomputation 5y agoI see, thank you.
- Mikeb85 5y agoThis would make sense if all computers ever did was mathematical micro-benchmarks. Can you create a web framework in C that has as many features as Rails or Django? And what's the power consumption of that? Higher level languages do more stuff. It's not like Guido and Matz just woke up one day and were like "fuck your CPU". Plus, compilation requires a decent amount of power, as shown in those graphs. Does every C/C++ project run perfectly with no bugs the first time?
- quelsolaar 5y agoBig companies like Facebook and Google do write their web tech in C/C++ because performance and power consumption does matter. If something written in Rails is ten times slower then in C, that means ten times more servers using ten times more power. As I'm sure you can imagine, cutting a zero of these companies server bills is a big deal. You can buy a lot of hours doing manual memory management for that kind of money.
- notacoward 5y agoI don't know about Google, but that certainly didn't seem to be the case at Facebook. PHP/Hack was the language of choice for front-end stuff, C++ for most of the code in infra services, and Python holding everything together.
- Mikeb85 5y agoYes, both are replacing some PHP/Python bits with C++ AFTER scaling to billions of users... Still curious what the power savings are... I'm sure they've done enough profiling to know their performance is increasing. But are they saving energy? How about the compilation cycles to get to where they are? The carbon footprint of the additional employees? Etc...?
- colanderman 5y agoFacebook runs PHP via their own JIT, HHVM (https://en.wikipedia.org/wiki/HHVM https://en.wikipedia.org/wiki/HHVM). Researching a bit now it appears they've actually migrated to their own subset of PHP called Hack, which is measured in the benchmark, and looks more efficient than even some compiled languages in that benchmark.
- hmrr 5y agoI think they should offset all of these things against the probability that the IDE you have to use has its own ozone hole. That stab is mostly aimed in the direction of C# and Java
- alcover 5y agoFor the moment, using higher-level languages seems a natural go-to. It's comfortable, and energy and hardware are abundant. But this won't last. Many energy sources and metals are peaking and I can imagine a day when efficiency will count heavily.
- Jtsummers 5y agoThis means we'll see more effort in optimizing compilers, but probably not a loss of the higher level languages. They're just too useful when it comes to working on large-scale systems. Do you want to rewrite Linux in hand-optimized assembler? And then rewrite it for every single platform that you may want to run it on?
- tomohawk 5y agoI once re-wrote a non-trivial program in ruby that was originally written in C. The performance and scale of the ruby version was considerably better. Could it have been even better in C? Probably, but it was a lot easier to conceptualize and properly choose the architectural features that made the difference using ruby. These days I would have done the rewrite in golang, and had the best of both worlds.
- anthk 5y ago1) HN shoudn't be dependant on JS 2) There is a gopher proxy for HN: gopher://gopherddit.com 3) Use CLI tools, avoid JS ridden apps. If so, download the video and use mpv offline. Many times less power wasting.
- yayr 5y ago> As a former software engineer who’s mostly worked with C programming, and to a lesser extent assembler, I know in my heart that those are the two most efficient programming languages since they are so close to the hardware. one could argue, that programming languages that are more close to the mind are more efficient. At least when looking at 2nd to n-th order efficiency effects, not just pure runtime performance.
- beepbooptheory 5y agoYeah, maybe taken in isolation they are more efficient, but if your recompiling every minute in development, that's probably gonna add up.
- Jtsummers 5y agoThen don't recompile every minute? Or use a language that supports incremental compilation down to even the function level.
- henning 5y agoIf you're worried about the environment, avoid researching how microprocessors are made with respect to chemicals used for lithography and how much waste water is generated when making a modern microprocessor.
- neuroscihacker 5y agoI've written about this topic before and I think this is not right. Scroll down to "Environmental Impact". https://towardsdatascience.com/high-performance-code-pays-dividends-ce97768b5fa5 https://towardsdatascience.com/high-performance-code-pays-di... "The climate crisis threatens human civilization on a grand scale and electricity is frequently produced from fossil fuel. Electricity is then consumed by the operation of computer code. Google alone used 12.8 Terrawatt-hours in 2019 according to its 2020 environmental report, more than many countries and more than several US states. It seems intuitive that improving code efficiency should reduce environmental impact. Does it? The answer is not at all clear and must be considered on a system by system basis. The main reason is induced demand. ...it will take a centrally coordinated process at both national and international levels that can allocate energy to different industrial and consumer sectors and manage the energy production mix on behalf of the whole of society. Only then we can solve this problem in a rational way that doesn’t depend on luck. In fairness, software companies aren’t power companies, it’s a little ridiculous to expect them to build their own generation. What we can more expect from them is to pay taxes, divest from fossil fuel companies if they hold securities, and hold their total energy consumption under a ceiling set by a regulator while the society changes the energy mix as fast as possible."
- aejnsn 5y agoThis comes from an academic who doesn’t support any code. Why would I spend the time as a developer to do manual memory management under the guise of efficiency, when instead I can support twice (arbitrary) as many apps making a computer do it for me? This is a human, whose carbon footprint is terrible compared to a little memory overhead. SMH. Silly articles.
- quelsolaar 5y agoSlow languages create greenhouse gasses, C does not produce more humans (yet).
- aejnsn 5y agoI understand that premise—read my prior comment again, or do you, like the author, also not understand how code is supported?
- quelsolaar 5y agoI understand perfectly. You are not the first one who thinks its easier to ignore the climate crisis, then to put in money and effort needed to deal with it.
- aejnsn 5y agoIf you want to spend the screen time to prematurely optimize in the name of future savings, knock yourself out. I’ve been doing this long enough to understand where efficiency gains exist—it’s not in human-conceived memory micromanagement.
- dwaltrip 5y agoThe human effort saved by using a less compute-efficient but easier-to-work-with programming language could be redirected to attacking climate change from another angle. We'd have to look at the details to see which one is more effective overall. Although my gut says that "not programming in C" is generally the correct approach for your average piece of software.
- scoofy 5y agoI honestly hate headlines like this. Jokey, tongue-and-cheek takes that effectively treat environmentalism like every little bit counts. It doesn't. We are in the midst of a serious crisis, we know the reasonable solutions we should be taking to avoid catastrophe, and we are collectively choosing to ignore them. It should be treated seriously. If we're going to joke about it, it should be dark comedy.
- ofou 5y agoPerl is the worst programing in terms of energy usage.
- wheelerof4te 5y agoBesides the already mentioned "donate via crypto" red flag, this argument is NULL and void. Different languages were made with a reason, and they solve different problems. Even Python can be efficient when your largest bottleneck is network or disk IO. Nowadays we have Rust, which is slowly catching up to C speed, and sometimes even surpasses it. C is a beautiful language when used in embedded space, where memory allocations are minimal. Once you start throwing mallocs left and right, you lose that simple elegance.
- benibela 5y agoI have been saving the planet by writing all my code in Pascal From that paper, only C and Pascal, are optimal for energy and memory usage. And Pascal has memory safe strings with reference counting. C is just too unsafe. 70% of all security issues are caused by C.
- Tozen 5y agoYet another reason to use Pascal. More people need to do their part to save the planet by writing efficient code, that is also safer, more readable, and more maintainable.
- megous 5y agoOr just use an ad blocker. It's a 0% vs 100% CPU use on some websites.
- sn9 5y agoI think an argument could be made for writing code in a systems programming language like C or Rust to save energy, but I'd be much more interested to know what the same choice would be for front-end development. Could we get something as flexible and expressive and ergonomic as React or Vue with the performance of WASM?
- finneganscat 5y agoIt’s posts like this that make me avoid HN lately. So much smug. Yet for some reason, JavaScript gets a pass. The article doesn’t mention the big web waste of JS. Sounds like they just want to make Python look bad. Personal vendetta-ish.
- ac42 5y agoDoes this factor in the wetware upkeep during the development cycle? Development in C generally is slower than in most of the other languages.
- francisl 5y agoTo be more accurate, it needs one variable. - Butt(s) per feature That includes defects, It's one of many reasons I like new compiled/vm languages like Go, Swift, Nim F#. You got the productivity of python, but near the performance of C. User wins, dev wins and planet wins.
- swiley 5y agoThe compilers, runtimes, and by extension requisite operating systems are fatter though.
- mclightning 5y agoOh, are we doing this now? I mean, if we are, let's get rid of JS/TS and move to Rust or something, anything really.
- anandpowar1 5y agoBefore we choose more efficient languages. How about first limiting low-code and machine-learning systems? I am sure we can shut down hundreds of servers just by not abusing image-captcha, blockchain and cloud for everything.
- Tozen 5y agoThis is a bit deceptive, because we could always go back to writing in assembly language. The point of scripting languages are usually to make creating programs easier, requiring fewer lines and time to create. There are different aspects of efficiency that is being overlooked.