r/cpp • u/Magistr_Y0da • May 23 '24
Is MacBook good for C++ developer?
Hi. I am a C++ developer, and I write code for both Linux and Windows, depending on the project. Currently, in my country (I'm from Ukraine), there are frequent power outages (3 hours with power, 4 hours without, and so on), and I am looking for a laptop with a long-lasting battery. Since MacBooks have excellent battery life, I am considering buying one, but I have a few questions.
Will I experience a significant loss in performance when building a C++ project in Docker using an x64 Ubuntu image and the Rosetta emulator?
Will there be a noticeable drop in performance if I use x64 Windows through an emulator?
Is it worth making these sacrifices, or should I buy a Windows laptop with a less impressive battery?
I have a powerful PC that I’m using for work, and I can use It for building projects, but when the power is on.
59
u/Carl_LaFong May 23 '24
If you use only standard C++, then you can do everything natively on the MacBook and test on Windows and Linux (using a VM or Docker) only as needed to make sure nothing breaks on these platforms. I’ve been doing this for many years.
25
u/othellothewise May 23 '24
That is true but I'll note it's a bit of a pain if you are using more recent C++ features, since apple-clang is always way behind. You can add more modern compilers with homebrew
3
2
u/Potatoswatter May 23 '24
Homebrew is a pain? How so?
8
u/othellothewise May 23 '24
Homebrew isn't a pain, dealing with apple-clang is.
2
u/mallardtheduck May 24 '24
It's a horrible clunky, broken pain. The fact that it installs in a "global" location (/usr/local), but is only usable by a single user is just complete nonsense. There isn't even a supported configuation if your Mac (or Linux; Homebrew works there too, with basically the same broken setup) is used by more than one person!
User-specific stuff goes in that user's home directory.
4
u/bbolli #define val auto const May 24 '24
The /usr/local days are long gone. Now Homebrew lives in /opt/homebrew.
4
u/mallardtheduck May 24 '24
Makes no difference. Still a global location, but a user-specific install.
-4
8
May 23 '24 edited May 24 '24
[removed] — view removed comment
1
u/NilacTheGrim May 29 '24
Apple Clang limitations into account
Not necessarily. I use gcc sometimes and you can just compile with
-static-libstdc++.. and to the outside, the binary looks like like something written in plain-old C.1
May 29 '24
[removed] — view removed comment
1
u/NilacTheGrim May 29 '24
Yes, I know.. I have run into these myself. Annoying a.f..
If you statically-link the C++ lib it should be fine.
Look into static linking C++ lib... it solves 99.9% of these issues.
1
May 29 '24
[removed] — view removed comment
1
u/NilacTheGrim May 29 '24
I know what you are saying and that can definitely happen. However, if you statically link the C++ lib a lot of the stuff works. Note I am using gcc on macOS though -- i never tried statically linking the Apple Clang lib (if they even offer a static lib for it? I have no idea if they do).
6
u/DatBoi_BP May 23 '24
Why not just set up CI/CD on GitHub (or wherever) to test using the different compilers/OSes?
3
-1
u/Far_Understanding883 May 23 '24
Docker. Mac? Windows? What?! Might as well run vmware
3
6
u/pjf_cpp Valgrind developer May 24 '24
macOS is increasingly a nightmare for low level development. You have to beg to be able to use GDB and running dtrace requires that you virtually rootkit the machine.
8
u/Spacebar2018 May 23 '24
I use a macbook and vscode to do 95% of my cross platform development and it works fine.
4
u/Frogeyedpeas May 25 '24 edited Mar 15 '25
pie beneficial airport price different paint humor growth air historical
This post was mass deleted and anonymized with Redact
7
u/cristianadam May 23 '24
I switched to a MacBook Pro M1 Max in December last year. I have now UTM (QEMU frontend) Virtual machines for Windows 11 and Ubuntu 22.04 as native Arm64 installations.
The performance is great, I can compile Qt, Qt Creator, LLVM on battery, but I can do native compilations, without using any emulation.
I have also used docker and colima with a native Arm64 Linux. Colima documentation mentions that it can run with Rosetta.
Windows 11 has its own x64 emulation. Running x64 applications is possible, but for faster compilation one could use arm64_x64 cross-compilation with Visual C++.
The only issue I had was the keyboard on macOS which was different, but by using Karabiner-Elements I had everything as before on Windows / Linux.
I'm quite happy with how things came around.
1
u/CanadianTuero May 23 '24
How would you compare QTM to parallels if you have used it previously?
1
u/cristianadam May 24 '24
I haven't used Parallels. On PC I have used Virtual Box. UTM has some host "spice" tools with drivers. Clipboard and Shared Folder are available and work as expected.
It fits my needs of compiling and running Qt Creator.
3
u/glezmen May 24 '24
I love doing C++ development on my MacBook. I do my current pet project (cmake, docker compose, C++20, etc) on it, and the only one minor problem I encountered is when copying files between socket shares (because of the user ids). I love it :)
3
u/HipstCapitalist May 24 '24
Using Docker, you can 100% produce Windows & Linux builds, I've done so myself. If you're familiar with Docker, it won't be a problem.
That said, and as much as I like my Macbook pro, they cost quite the penny and 32GB of RAM is a requirement if you're going to use Docker. For the same price, you can buy a Lenovo Thinkpad and a battery bank.
Все Буде Україна.
3
u/die_liebe May 26 '24
No, no, no. Don't use a MacBook for C++. It's asking for problems.
The compiler is behind, there is no way to detect memory faults. (No valgrind). If you want to develop with C++, install Linux. There are enough laptops that have long battery life, buy one without OS and install Linux by yourself. Try to buy a laptop with a big screen. In my experience, performance doesn't matter much during development.
Linux emulator in Windows is acceptable, but native Linux is better.
Sorry for your situation.
9
u/thomas999999 May 23 '24
I have no personal experience but i heard that linux runs very well in a vm on the apple silicone macs
26
u/tsukiko May 23 '24
You mean Apple Silicon? Silicone is used for breast implants, not chips
11
5
4
2
5
u/Present-Photograph-8 May 23 '24
I think it's simpler and cheaper to buy big EcoFlow or similar stuff. At least that what I did.
1
2
2
u/NilacTheGrim May 29 '24
I'm on an x86 macbook from 2019. I bought it specifically because it was 1 laptop that could natively run all 3 major platforms under "native emulation" using VMware. Namely: Linux, Windows, and Mac.
The idea of using Rosetta to run Windows now because of the switch to ARM bothers me greatly. I have been hesitant to upgrade my laptop to an ARM-based one as a result.
I think my next laptop will just be an x86 Linux box. Will be 1/2 the price of a comparable Mac, will still be able to run Windows stuff natively via VMware, and will have better build quality.
Honestly build quality on macs has been going downhill for years. Not a fan of their keyboards.. or the stupid touch bar which is a dumb gimmick. Macs have crappy airflow and run hot.. which means the CPU is forced to slow itself down. Maybe on ARM this is not as much of an issue.
They are not at all internally upgradeable...
Don't get me started on the disaster that was the butterfly keyboard tech... etc.
4
u/charliex2 May 23 '24
it is for native, but i've found using parallels etc chews thru the battery.
i do like using vscode in ssh mode if you aren't doing gui work (using a remote computer)
3
u/SergiusTheBest May 23 '24 edited May 23 '24
I don't like the Apple ecosystem so I bought an HP laptop on a recent AMD Ryzen CPU. It lasts up to 11 hours and has great performance. Also you can consider buying a power bank for a laptop or something more powerful like EcoFlow.
x86->ARM translation kills about 20% of performance and a VM hurts the battery life. So the best way is to run everything natively: without a VM and machine code translation.
3
u/LuckiestPersonAlive May 23 '24
I recommend Thinkpad x1 Carbon latest gen instead. It is better in every way.
3
u/Straight_Truth_7451 May 23 '24
I love MacBooks, but nothing beats Linux in general for development and especially with cpp
2
u/i_am_not_sam May 23 '24
I wouldn’t pay this much money out my pocket so I’m glad my company bought me a MacBook Pro. I have the M2 and it’s been my favorite dev machine. I get nearly a full working day on the battery. The performance is a beast. The docker build setup took a little effort until the Rosetta support was added in and now it’s flawless.
I’m sure you and I can’t compare build times but these are my experiences. On the previous Intel line of MacBooks the code took 20 mins for a clean compile (create docker container, install Conan dependencies, build). On a Linux machine this took 1-3 mins but the hardware quality was atrocious and I got an hour out of the battery on a good day while the fan whined and it ran so hot it melted its own power cable. On the M2 a clean build takes 5 minutes. I also run several k3d clusters while I’m building and I’m constantly on my IDE. I’ve screen shared on Teams while all this was running without a blip in performance. Incredible machine.
2
u/serg06 May 23 '24
What'll you code on, XCode?
I thought XCode was terrible, and Visual Studio was the only way to have a positive C++ experience. Very happy to be corrected though.
1
u/mike_kazakov May 24 '24
XCode is good enough. I'm using both Visual Studio (9-to-5 job) and Xcode (pet projects) and both have their pros and cons. Integration level of XCode in some aspects can blow your mind away, e.g. debugging sofware consisting of multiple processes communicating via XPC is completely transparent.
1
u/Far_Understanding883 May 23 '24
Stay away from Apple. Get a real computer and install Linux on it.
1
u/Dark_Lord9 May 23 '24
I can't provide a lot of insight on your problem but if what you want is a computer with low energy consumption, I suggest installing Linux and installing TLP on it. It's a software that will allow you to configure your system's energy consumption and it has a great effect. Couple it with hardware that has a big battery and a not so big cpu and you should have an ideal system.
1
u/Longjumping-Bee-6977 May 24 '24
Buy upgradable Windows/Linux laptop, save extra few hundred bucks, use them to buy powerstation.
1
May 25 '24
Macos makes me crazy with popup permissions every launch of an executable without bundle. Switched to ThinkPad g3
1
1
u/casualPlayerThink May 23 '24
... Will I experience a significant loss in performance when building a C++ project in Docker...
It depends.
...Will there be a noticeable drop in performance if I use x64 Windows through an emulator...
Might be yes, depend on the project. For simple small cross-compiled libs and applications I had no issues
...but when the power is on...
Might be a good idea to consider to buy a in-house battery system (w/ solar panels)
...Since MacBooks have excellent battery life...
This is true. With CLion, bash, one browser a 2019 MacBook pro could work for 7-8 hours if the app/libs/compilation is not too heavy.
1
u/PizzaHoliday5925 May 23 '24
MacBook user here, love it. I also recently got a 13th gen i7 laptop from work and that is very very efficient on power usage. I would easily get most of a working day out of that. You should be good for 5 hours on a modern intel mobile
0
u/leonardosalvatore May 23 '24 edited May 24 '24
Go for a Linux approved Dell or Thinkpad computers, is very important that power management drivers are on spot and then buy USBC battery bank. Charge everything whenever you can. I can do easily 20 hours with vs code and browser.
Providing that you are not working with anything that's heavy on GPU ...
Edit: My linux dev laptops are Precision 5570, Thinkpad T480, Lenovo Legion 7 16ARHA7
-8
35
u/pedersenk May 23 '24
An alternative could be to buy a cheaper, more powerful HP or Thinkpad and use the spare money for a couple of UPS power supplies.
If you are going to depend on batteries a lot, you might want to consider getting a model ThinkPad with a removable battery that you can replace once it starts to degrade. Not sure if MacBooks allow that yet in 2024?