18 ms·
Starting a tech startup with C++
- jgh 11y agoAh one of our core systems is in C++, though it is for video processing and needs to work with multiple platforms. I suppose nobody has questioned the C++ choice because its a more "typical" use-case
- ilya1 11y agoSounds very inspiring. Any other good places to start learning about C++ 11/14 for complete beginners with JS and other programming languages? I'm very much interested to create proof-of-concept for high performance SaaS services and play with C++ as it might be useful to build Node.js extension later.
- blub 11y agoProgramming - principles and practice using C++[1] should be appropriate for beginners. It's a long book at 1000+ pages, but it is designed for novices and explains subjects such as why one needs functions, how to handle errors, GUIs, testing, etc. The C++ Programming language (4th ed)[2] is for experienced programmers. A tour of C++ is the short version of the former.[3] [1]: http://www.stroustrup.com/programming.html http://www.stroustrup.com/programming.html [2]: http://www.stroustrup.com/4th.html http://www.stroustrup.com/4th.html [3]: http://www.stroustrup.com/Tour.html http://www.stroustrup.com/Tour.html
- ilya1 11y agoOhh... thnx! Nothing changed since I graduated in 2001 ... I recollect Stroustrup since then. It's still C++ bible.
- johannes1234321 11y agoIn the language many things changed and you should look a the books which focus on C++11/14 no the old stuff.
- palunon 11y agoIt isn't the same edition, the language have changed a lot ;)
- shepardrtc 11y agoThe [1] book is exceptionally good for beginners. He completely rewrote it with C++11 and refocused beginners on some key changes to the language to make it much easier.
- axefrog 11y agoTry http://learncpp.com http://learncpp.com
- MattHarrington 11y agoI think the best book for complete beginners is "Jumping into C++" by Alex Allain. From there, move on to "C++ Primer Plus" by Stephen Prata.
- JabavuAdams 11y agoStack Overflow's Definitive C++ Book Collection: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list http://stackoverflow.com/questions/388242/the-definitive-c-b...
- jlg23 11y agoNot to mention the time saved in testing due to the compiler catching many errors only unit tests could catch in python.
- blub 11y agoI was glad when Python added type annotations, but the Python community is aggressive about preferring dynamic typing. Don't think the chances are that great to use them in a real project. Perl 6's gradual type system seems interesting and one plus of Go is that it brought some well-deserved attention to concise static typing.
- deleted 11y ago[deleted]
- pacaro 11y agoI'm curious as to has this plays out at scale. If you can reduce the number of machines needed by a factor of 10, then apart from the hardware/power savings, there are staffing savings too. Managing 1000 machines is different from managing 10,000
- bnastic 11y agoIt's sad that you need to justify using one of the most established and longest serving languages/platforms ever.
- sgeisenh 11y agoI don't think it is sad. You explained why it is necessary, C++ has been around for a while, is/was great but there are now languages that can compete in terms of performance with fewer drawbacks in terms of security and undefined behavior. If you're starting from scratch, it is important to strongly consider which language and platform best suits your needs. Anecdotally, a lot of companies have found success using newer languages because they tend to attract a better proportion of talented people.
- n00b101 11y ago> there are now languages that can compete in terms of performance Such as?
- steveklabnik 11y agoIf Rust code is slower than equivalent C++, it's a bug. We track performance bugs, please file them :)
- nickpsecurity 11y agoI like the quip but that's barely an answer given OP avoided Rust specifically. There's a difference between a high-performing language in development (and debugging) vs a high-performing language with over a decade of work into its tooling and support. The latter's strengths and weaknesses are known through and through with many implementation and library problems likely worked out long ago. So, if it was apples to apples, I'd probably cite Ada, Eiffel, Modula-3, or Component Pascal as the closest to C++ in terms of performance and key features while being safer and more readable. Each has had years of work, support from commercial sector (except Modula-3 now), and programs tend to work more than break after a compile. That said, your Rust work is exciting and I hope it gets in that same category. It's just so new and evolving that its not in C++'s class in terms of risk or predictability. Not yet.
- theyoungestgun 11y agoI like these "You CAN do X with Y!" types of posts - especially when it's not the same drum being banged over and over. I think there's a really big part of this case study that isn't mentioned (perhaps because there is currently no data): bringing on more engineers. It really seems as if the number of C++ developers ready to be a part of the startup ecosystem is small. That is the impression that sites like HN leaves me with at least.
- bluejekyll 11y agoI'm more curious as to the decision not to stick with Rust. Sounds like there was a prototype. I'm guessing there were some libraries missing. Would be cool to know more about that.
- dikaiosune 11y agoRust's ecosystem is super young, and up until May '15 the language had breaking changes occurring pretty frequently (daily? I wasn't using it back then so I'm not sure). I've been really enjoying using it, but I imagine that this startup began work before Rust hit 1.0, or very nearly afterward.
- steveklabnik 11y agoSometimes more than once per day :) Crates.io has 3700 crates in stock. That said, there are still gaps, like with any young ecosystem. It's really progressing nicely though. And given Rust's domain, there are packages for really interesting stuff, like OS dev...
- avita1 11y agoDitto. I'm also curious if D ever came up. My impression is that it was (until recently) much more stable than rust.
- bluejekyll 11y agoRust has been remarkable stable since the 1.0 realease.
- avita1 11y agoSure, I was referring to pre-1.0 rust ;)
- tuyguntn 11y agoEvery word has its own place, every place has its own word Starting startup with language X depends on how that language were used in industry, starting hardware startup with Python/Ruby is strange, but for web startup its totally fine. Now think about creating web site in C++ with average C++ developer. There is also cost of talent, if you own expert C++ developer than probably writing web site in C++ can make sense, because you have a talent who can manage and fix every bug/feature. Finding professional Python/Ruby web site developers are easier than finding C++ web site developer.
- Cshelton 11y agoI think you hit the nail on the head early in the post. C++ is what you are most comfortable with. I believe that is the number one reasoning, at first at least (prototype, mvp stage), in deciding that language/stack to use. Use what you know the best as the tech lead, everything else will fall into place.
- petke 11y ago> Manual memory management is the most popular misconception of C++. Since C++11, it is now recommended to use std::shared_ptr or std::unique_ptr for automatic memory management. There is a small computational cost to maintaining referenced pointers but it’s minuscule and the safety outweighs this cost. I think another misconception is that you need pointers at all. Smart pointers are still pointers. Its better to use value semantic all the way when you can. And you usually can. Why place something on the heap if it can live on the stack?
- steveklabnik 11y agoIt's true that stack allocation is often better, and should be preferred, but that doesn't mean the heap isn't useful.
- drderidder 11y agoWell said! Dynamic memory allocation is a really big performance hit, and in a lot of cases you can pre-allocate data structures on the stack for serious speed improvements. Avoiding DMA was one of the secrets for writing blazing fast real time systems stuff when I was in telecom. I don't think those benefits have gone away.
- kristoffer 11y agoYou and I can't possibly have the same definition of DMA. It is essential to low latency data communication both in the embedded and server domain.
- bitwize 11y ago"Dynamic memory allocation", not "direct memory access".
- kristoffer 11y agoAh never seen dynamic memory allocation written as DMA before. Maybe obvious from the context but DMA really only has one meaning for me :)
- hakcermani 11y agoWondering how Swift will play in this arena now that is open sourced - and performance ? According to this (http://www.primatelabs.com/blog/2014/12/swift-performance http://www.primatelabs.com/blog/2014/12/swift-performance) for some workloads does approach C++.
- samfisher83 11y agoI would find it hard to believe that c++ can be that much faster for many websites since the bottleneck would be the I/O subsystem. I don't understand how they are getting this 40x speed up. I wonder what the benchmark looks like.
- ploxiln 11y agoIt's not that a single request is 40x faster (it may be no faster), it's that 40x requests can be handled in the same amount of time. The limitation is then the processing of the connections both in userspace and in the kernel, and the cost of all the system calls. This is easy enough to test with ab (apache bench), siege, or jmeter, by just cranking up the number of concurrent requests. I've seen 100x differences in implementations of web servers before, 40x for python vs c++ is pretty believable.
- emcq 11y agoIn an optimized system the bottleneck will be I/O. However elements like serialization, many function calls, and extraneous memory copies chips away at performance to the point it matters and its difficult to address these problems directly in languages outside of C/C++. Today you can get 15MB/s to S3. A not uncommon mysql node might do 10MB/s. Good luck trying to push that throughput with python or Ruby on a single process through a http response. Much faster I/O exists with sequential HD, SSD, and RAM based I/O. Most networks are built with 1Gbit Ethernet allowing 100MB/s that won't get saturated in the slower languages without going parallel which can increase total system complexity and lines of code.
- jcyw 11y agoIts more like, with 2gb ram and 2.0ghz cpu, how many requests can you handle? Its not surprising language like C++ would win.
- nickpsecurity 11y agoFunny you say that given I'm dusting off an old laptop that has a 1.xGhz Core Duo CPU and 2GB of RAM. It's the next one to be used for performance and stress testing. The reason? Anything that can't run snappy on that box is just bloated or wasting resources. Lean, native code tends to do the job nicely. :) Note: Also good to do it on cheap, throwaways because this sort of thing burns out the CPU's. Better that box than my main one.
- melted 11y agoFor databases, C/C++ is still the only reasonable choice. For OLAP cubes in particular, you want to keep as much data in memory as possible as efficiently as possible, and drop down to SSE intrinsics where needed. C++ lets you do just that. Frontend can be in any language you like.
- pcwalton 11y agoThere are several other languages that have "ability keep as much data in memory as possible as efficiently as possible" and "drop down to SSE intrinsics" as features. C and C++ by no means have a monopoly here.
- melted 11y agoHow battle tested are those languages? How many outstanding bugs do they have in their compilers and libraries? How good is tooling support? How easy is it to find competent programmers? How well do they interoperate with existing high performance libraries? That's just a small sample of issues you need to consider when starting a serious project. I maintain that it's hard to compete with C/C++ on all of those criteria.
- pcwalton 11y agoMoving the goalposts to "every single advantage C++ might possibly possess" isn't very interesting. The idea that using a new language can only be justified if the language surpasses C++ in every conceivable way is very 1995, pre-PL Renaissance thinking. In reality, you can only choose programming languages by balancing all the factors in question, and C++ has plenty of disadvantages for databases: it's unsafe, it's difficult to learn, compile times are poor, there's no package manager, etc.
- melted 11y agoSays someone who has quite obviously never worked on database engines. Package manager? LOL. What language are you programming in, Ruby?
- deleted 11y ago[deleted]
- mbreese 11y agoAnd then they show how the type can now be inferred with "auto": auto start = std::chrono::system_clock::now();
- shock-value 11y agoI guess you totally missed the comment "//here's the verbose version" as well as the entire context for that code snippet?
- steven2012 11y agoThe main problem I imagine is as the platform/codebase matures, there may be compatibility issues as the compiler changes, as the underlying hardware changes, etc. This is something that is well hidden by a language like Python. I remember having to support a cross-database and cross-platform C/C++ server back in the day, and the maintenance was a nightmare. Having the luxury of virtualizing your hardware makes this step a lot easier, that's for sure.
- jcyw 11y agoNo one doubs the performance of C++. What I would really like to see is arguments about speed of development, ease of testing, etc. This articles argues alot about language features or libraries, but what about the bigger picture? It is not enough for the HTTP server be fast. It also needs to do REST API, auth, etc. How does that compare to for example node/js.
- JoeAltmaier 11y agoOne C++ advantage is, at 40X the horsepower, they didn't have to deal with scaling configuration right away. They can put that off, and deal with proving their product instead.
- jcyw 11y agoThe argument is you do not need a load balancer because performance of one host is good enough. But that would become a single point of failure. And thats why AWS is so awesome. Start with an autoscaling group when you create your ec2 instance, you dont really need alot configuration.
- ufmace 11y agoI wonder why the choice of language is framed as being between C++ and Ruby/Python? Yes, C++ is known for being fast while suffering from a shortage of easy libraries and being more verbose to write and intellectually challenging to write in, while the mainstream dynamic languages are known for being not so fast but having a vast array of handy, easy to integrate libraries and being fast to develop in. But I think there's a number of choices between the two that seem worth considering. C#/.NET doesn't get a lot of love from the startup community, but it's mature, stable, fast, full of advanced features, and has good library support. Java and other JVM languages have similar advantages and better compatibility with Unix-based OSes. Java itself is a little long in the tooth, but there is the option of alternate JVM languages. I'd probably be most tempted to check out Go if I was working on something that absolutely had to wring the best possible performance out of my hardware. I don't honestly know that much about it, but it has a reputation for getting you most of the performance of C++ without the complexity. But I will say that if the author has lots of experience in C++ and comfort with the ecosystem, and not much in any of those other languages, then by all means go with C++. Getting your product out there is more important than getting the perfect language.
- pcwalton 11y ago> I'd probably be most tempted to check out Go if I was working on something that absolutely had to wring the best possible performance out of my hardware. I don't honestly know that much about it, but it has a reputation for getting you most of the performance of C++ without the complexity. Go isn't billed as a language that is designed to do that. It's faster than Ruby and Python, for sure, but it made many runtime performance sacrifices in the name of ease of use and compilation speed.
- zippoxer 11y agoThe GC has been drastically improved recently and going to get another improvement in the next release - Go 1.6. Either way, if Python was considered, Go isn't less fit to be considered.
- 11y ago
- ambulancechaser 11y agoI would like to see one other aspect discussed though: quickness to market. At my job, we are rewriting some pretty terrible vb5 code. It's easy to just WTF a lot, and complain that there are truly insane things inside of it. The flipside of that, is that this code was quickly built and quickly allowed for a revenue stream. The author mentioned that thrown away python code provides no value, but I'm not convinced of that statement. The development time could have been significantly shortened, allowing for a revenue stream while the site was rebuilt in C++. While this may seem like wasted development, it could have created incoming money at three months rather than eight months, helping keep the lights on. Further, there are conceivably problems that would come about during development that would impact their design, which they would have to figure out. Solving these problems are irrespective of the language implementation, and using a dynamic but slower language could help them nail down theoretical issues in algorithms, api, and infrastructure, before coding in the c++ system. A counter point to this though, is that often, there is no budget for a rewrite. I'm wondering if they would be constrained by the prototype becomes long lasting production like in our case.
- deleted 11y ago[deleted]
- rileymat2 11y agoAdditionally, Python plays well with C, so perhaps some of the performance killing portions could have been replaced with C.
- vram22 11y agoNot only that. A lot of the modules in the Python standard library are written in C; some may be thin wrappers over the corresponding C library. So when you call that code in your app, it runs at (nearly) the speed of C. Same could apply to other languages like Ruby too, that follow that model.
- Lumocra 11y agoAren't a lot of startups using dynamic languages because those are more popular? We use Javascript everywhere since that makes it a lot more easy to hire new people.
- l1ambda 11y agohttps://www.techempower.com/benchmarks/ https://www.techempower.com/benchmarks/ also show the fastest HTTP servers are written in C++.
- pcwalton 11y ago> There is a small computational cost to maintaining referenced pointers but it’s minuscule and the safety outweighs this cost. Atomic reference counting does not have minuscule costs. See, for example, http://www.hboehm.info/gc/nonmoving/html/slide_11.html http://www.hboehm.info/gc/nonmoving/html/slide_11.html In particular, note that if you use shared_ptr everywhere you will be end up with much slower code than you would have if you had a good GC. In other words, you end up slower than Java, with less safety and more verbosity. Browser engines have used custom non-thread-safe reference counted pointers where possible extensively for this reason. Furthermore, I always have to say it: shared_ptr is not memory safe.
- YuriNiyazov 11y agoI don't think that auto start = std::chrono::system_clock::now(); // benchmark something here auto end = std::chrono::system_clock::now(); is concise. I think that start, end = benchmark do # benchmark something here end is concise.