
Starting a tech startup with C++ - n3mes1s
https://medium.com/@jamesperry/starting-a-tech-startup-with-c-6b5d5856e6de#.wv0nsmicb
======
ambulancechaser
I 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.

~~~
rileymat2
Additionally, Python plays well with C, so perhaps some of the performance
killing portions could have been replaced with C.

~~~
vram22
Not 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.

------
petke
> 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?

~~~
srean
You mean C++ programmers allocate n object on the heap even when its lifetime
is the same as the scope of the containing block ?

Unless its such a large huge object that stackoverflow is a possibility I cant
imagine why would one do that.

~~~
yongjik
I don't think C++ supports variable length arrays?

So, if you want to allocate N objects, where N is not known at compile time,
(I think) you have to use heap allocation anyway. Normally I just use
vector<>, and call reserve() if I feel like extra performance-y. Sure, it's
much slower than C99-style variable length arrays, but 99% of the time it's
still fast enough.

More importantly, it plays nice with other C++ functionalities. For example,
zero-copy construction using emplace_back() inside a for loop. (And if you
throw an exception in the middle you're guaranteed that destructors are called
exactly for those that are already constructed.)

~~~
CyberDildonics
You can still use alloca in C++

~~~
srean
Yes and I have at times, but its living a little dangerously. Even if it
returns a non-null pointer it does not mean you can write there safely.

------
ufmace
I 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
> 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
The 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.

~~~
pcwalton
> The GC has been drastically improved recently and going to get another
> improvement in the next release - Go 1.6.

I wasn't just referring to the GC.

------
bnastic
It's sad that you need to justify using one of the most established and
longest serving languages/platforms ever.

~~~
thrownaway2424
Indeed, the given strawman alternative languages (Ruby and Python) are far,
far worse for productivity. Python changes are totally unreviewable since one
cannot in any way reason about the correctness of a function call without
reading the definition of the function itself, and all the functions to which
it passes the arguments, all the way down, which of course takes forever. At
least with C++ you can reason that if a change compiles it has not made any
dramatically stupid type errors. You still need to think about whether any
unnecessary temporaries or copies were made, or questionable assignments, but
you need only think about that one level deep. Is seems to me far more
dangerous to suggest writing new code in Python.

~~~
hifier
Ummm, unit tests? The compiler offers a false sense of security. Type safety
is not correctness.

~~~
avita1
Not to dredge up this debate for the umpteenth time, but the same can be said
of unit tests: they are not a proof of correctness, and they often give you a
false sense of security.

~~~
thrownaway2424
The Internet has, indeed, conducted this argument thousands of times. My point
here is only about the difficulty of reviewing Python code. I find myself
sometimes having to hold up a piece of paper to the screen to see if the
indentation has been done right, in addition to the aforementioned function-
body-reading chores. Of course my opinion is of no concern to people except
those who work with me, from whom I refuse to review Python code. It's just
not worth my time.

~~~
hifier
My point is that there are tools and techniques that will solve these problems
in ways that are more valuable than the compiler's type system.

If you seriously "refuse to review Python code" because you feel you need to
visually check indentation, I think you might want to take a step back and
evaluate your methods.

------
pacaro
I'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

------
pcwalton
> 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.

------
theyoungestgun
I 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.

------
melted
For 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
There 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
How 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
Moving 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
Says someone who has quite obviously never worked on database engines. Package
manager? LOL. What language are you programming in, Ruby?

~~~
tomjakubowski
pcwalton works on a web browser engine, which I'd say is at least as
"complicated" as a database engine. He's already stated the benefits Cargo
brings to Servo's development (as compared to working on, say, Gecko)
elsewhere. What makes you think a package manager wouldn't be useful for a
database engine which may want to, just as an example, provide a web server
for queries or administration? [1][2]

(Honestly, I'd rather call Cargo a "project manager" , because it does far
more than manage packages -- it builds your project and its dependencies, too.
Having a completely standard way to build applications and libraries is an
_enormous_ win over C++. The discovery and management of a project's packaged
dependencies is of secondary importance to me.)

[1]:
[http://docs.basho.com/riak/latest/dev/references/http/](http://docs.basho.com/riak/latest/dev/references/http/)
[2]: [https://www.rethinkdb.com/docs/administration-
tools/](https://www.rethinkdb.com/docs/administration-tools/)

~~~
melted
Compared to DBs browser code bases are lax and buggy beyond belief. Want to
take a second and a gig of RAM opening a page? Go right ahead. Browser
crashes? We're "sorry", wait for next release 2 weeks from now. No
multitenancy. No having to deal with data of arbitrary size. No transactions.
No writing anything complicated to disk. Etc, etc. You're comparing things
that really require completely different levels of rigor, sophistication and
engineering skill. Last I checked, BTW, all currently shipping browsers are
written in C++.

~~~
pcwalton
Browsers certainly do have to deal with multitenancy (although we don't call
it by that name), data of arbitrary size, transactions, and complicated on-
disk data structures.

In any case, you now seem to be primarily interested in arguing that database
programmers are smarter than all other programmers, which, needless to say, is
about the most uninteresting conversation we could possibly be having.

------
jlg23
Not to mention the time saved in testing due to the compiler catching many
errors only unit tests could catch in python.

~~~
blub
I 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.

------
ilya1
Sounds 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
Programming - 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
Ohh... thnx! Nothing changed since I graduated in 2001 ... I recollect
Stroustrup since then. It's still C++ bible.

~~~
johannes1234321
In the language many things changed and you should look a the books which
focus on C++11/14 no the old stuff.

------
bluejekyll
I'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
Rust'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
Sometimes 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...

------
tuyguntn
_Every 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.

------
jgh
Ah 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

------
hakcermani
Wondering 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++.

~~~
melling
What's the state of Swift for web development? Are web frameworks starting to
appear?

~~~
kahseng
There's perfect.org that came out in Nov 2015.

------
Cshelton
I 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.

------
YuriNiyazov
I 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.

------
l1ambda
[https://www.techempower.com/benchmarks/](https://www.techempower.com/benchmarks/)
also show the fastest HTTP servers are written in C++.

------
jcyw
No 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
One 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
The 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.

------
Lumocra
Aren'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.

------
steven2012
The 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.

------
samfisher83
I 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.

~~~
jcyw
Its more like, with 2gb ram and 2.0ghz cpu, how many requests can you handle?
Its not surprising language like C++ would win.

~~~
nickpsecurity
Funny 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.

