program 1633, "public notice," from L.L. programma "proclamation, edict," from Gk. programma (gen. programmatos) "a written public notice," from stem of prographein "to write publicly," from pro- "forth" + graphein "to write." General sense of "a definite plan or scheme" is recorded from 1837. Meaning "list of pieces at a concert, playbill" first recorded 1805 and retains the original sense. That of "objects or events suggested by music" is from 1854. Sense of "broadcasting presentation" is from 1923. Computer sense (n.,v.) is from 1945; hence programmer "person who programs computers," attested . from 1948. Spelling programme, sometimes preferred in Britain, is from French and began to be used early 19c. The verb in the fig. sense of "to train to behave in a predetermined way" is from 1963.
Example Sentences for programming
The programming is shallowed to the lowest (and widest) common denominator.
The sappy one set the leg and withdrew, programming a call for the next day.
Further on he found the programming screen, which clicked off the progress of the flight in hours, minutes, and seconds.
The operator was sitting at the programming punch, carefully going over a long streamer of tape.
No stronger proof of this can be given than the Boolean logic embedded in computer hardware and programming languages.
Then they found big ones, rank on rank of cabinets, long consoles studded with lights and buttons, programming machines.
Taking a guest around Disney World was like programming a playlist for a date or a car-trip.
To assist the IBM programming staff in reflecting customer requirements in the specification of new programming systems.
This enables management to communicate more easily with the programming staff.
At least one full-time technician-programmer would be needed for maintenance and programming.
I participated interview event with Amazon and receive email from Amazon recruiter that the team was happy with my performance and would be giving me offer at Amazon Vancouver Office, Canada. However,17 days later i still not get an official offer. I did several follow up with the recruiter within the period, just to get some "they are finding team for me" response. What could go wrong? Why is it in my case that the offer is being process so slow?
What is the Big O of that algorithm? What happens at runtime?
What's the algorithm to transform the sentence "the brown fox ran fast" in "eht nworb xof nar tsaf" (reverse any word)
A gaming application assigns a sessionid to each player every time they start a new session. These sessionid are all unique and can be selected from 1 to 10^6 numbers. A get() and put() function is used to assign and then release the sessionid for each user. A released session id can then be reused and assigned to another player. How can you write the get() and put() function to handle this in time and space optimized manner?
Write a merger and separator for Linked List.
is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Developing on wearable platforms is new and challenging. An app developer is asked to make dynamic user experiences that compare to what customers see on their mobile phones and web pages on small screens. If content is too dynamic, the device’s battery drains faster; if the user is charging the device, they are not using your app.
Connect IQ combines three W’s:
Wear - Garmin’s experience in power management, activity tracking, and ANT or ANT+ sensors means you will spend more time wearing our product and less time charging it.
Where - Location awareness is at the center of our products. Our products don’t become dead weight without a smart phone, but become more alive with one.
Ware - Garmin’s new Connect IQ app system allows for developers to extend their apps into Garmin’s wearable ecosystem.
Connect IQ products provide the best of what Garmin has to offer like beautiful design, location awareness, and efficient power management with the Connect IQ app system. Using the Connect IQ SDK, developers can create apps for Connect IQ devices and distribute them via the Connect IQ Store.
Monkey C is an object-oriented language built from the ground up, designed for easy app development on wearable devices. The goal of Monkey C is to round the sharp edges of making a wearable app, letting developers focus more on the customer and less on resource constraints. It uses reference counting to automatically clean up memory, freeing you from focusing on memory management. In addition, the resource compiler helps you import fonts and images to easily convert them between devices.
If you’ve worked with dynamic languages in the past like Java™, PHP, Ruby, or Python™, Monkey C should be very familiar.
Devices and APIs
The problem of API Fragmentation is a challenge for app developers. If a developer takes advantage of new APIs, newer devices with less customer penetration may be targeted. If only established APIs are used, apps may not take advantage of new capabilities.
Unlike cell phones, Garmin devices are all wildly different from each other: round screens versus square screens, touch screens versus buttons, and a different array of sensors depending on device purpose. While the Java philosophy of “write once run anywhere” is a notable goal, creating a universal API that crosses every Garmin device would inevitably become a lowest common denominator API.
Rather than attempting to abstract away differences in devices, Connect IQ APIs are tailored to the devices they run on. If a device has a magnetometer, the device should have available the Magnetometer API. If two devices each have a magnetometer, the API should be the same between them. If a device does not have a magnetometer, it will not provide that API.
The Tao of Connect IQ
There is a rhyme and reason behind Monkey C to make it easier for developers to support the Garmin ecosystem of products:
The developer chooses what devices to support
Connect IQ apps can run across multiple devices, but the intended devices are up to the developer. Not every device will be aimed at the markets the developer wants to target or provide the experience the developer wants to provide. The developer should not be forced to support devices they don’t want to.
The developer tools should help developers support multiple devices
The developer tools lessen the weight of supporting multiple devices. The Resource Compiler hides device specific palettes and orientations from the developer. It also allows per device override of resources, allowing different images, fonts, and page layouts to be specified in the resources XML. The simulator needs to expose only the APIs a particular device supports so the developer can test device support.
Similar devices should have similar APIs
Not all devices will be equal, but there is often commonality between them. Two different watches may have different display technologies, but they both support bitmaps, fonts, user events, ANT/ANT+, and BLE. A developer writing a sports app should not have to completely rewrite their app to support multiple devices.
At runtime, the developer can ask what the system ‘has’
Connect IQ applications are dynamically linked to the system. If an app makes a reference to an API that does not exist on a particular system, the app will fail at runtime when the app references the API, not at load time like C++. This allows an app to avoid making the call by taking advantage of the ‘ has ’ operator.
There are four main use cases for third party developers to interact with the watch:
Watch Faces - These replace the main watch face and are the home screen of the watch.
Data Fields - Data fields run within Garmin activities. They allow developers to compute values based off of the current activity, such as running, biking, etc.
Widgets - Widgets are full screen pages that can be embedded into the main page loop. They are loaded when brought on-screen and shut down when the user switches to the next widget. Widgets will timeout and automatically shutdown after a device specific period of inactivity.
Wearable Apps - Started from the action list, wearable apps can be used to implement use cases like third party activities, games, and other user-initiated actions. Apps push a page onto the UI and exit when the user backs out of the last page of the page stack. While running, the app has full control of the UI.
When it comes to robotic flocks, do you control each machine individually or the entire swarm overall? A new programming language allows both.
July 29, 2015
One of the more fascinating sights of an autumn evening is the flocking behaviour of starlings as they lurch and swoop in extraordinary demonstrations of aerodynamic synchronisation.
It turns out that these complex displays come about as a result of a simple set of rules that govern how the birds fly relatively to each other. Indeed, this flocking has been relatively straightforward to simulate on computer for many years.
But it has never been repeated with flying robots or ground-based ones for that matter, for two reasons. First because nobody has built robots with the same agility and speed. But even with less agile robots, the task is tricky because of the second reason: there is no easy way to control such a flock.
The first factor is changing rapidly. Cheap, capable robotsвЂ”flying or otherwiseвЂ“have caused an explosion of interest in flocks and swarms. Numerous researchers, hobbyists and artists are experimenting with these machines and hoping to study and exploit and the swarming behaviour they generate.
These groups are all finding that controlling large numbers of identical robots is something of a challenge. And in the absence of an established programming language, they are having to tackle the same problems in the same ways. In other words, they are re-inventing the wheel.
Today, Carlo Pinciroli at the Ecole Polytechnique de Montreal in Canada and a few pals say they have developed a programming language for just this purpose. вЂњWe present Buzz, a novel programming language for heterogeneous robot swarms,вЂќ they say.
There are two opposing approaches to controlling a swarm. The first is a bottom up method in which each robot is controlled individually. ThatвЂ™s useful for fine tuning the interaction between specific robots but becomes increasingly difficult to manage as the size of the swarm increase.
The opposing method is a top down approach in which the swarm is controlled as a whole. ThatвЂ™s much more effective for large swarms but does not allow for the fine tuning of individual robot behaviours.
Pinciroli and co say their new language allows both methods. вЂњWe believe that a language for robot swarms must combine both bottom-up and top-down primitives, allowing the developer to pick the most comfortable level of abstraction to express a swarm algorithm,вЂќ they say.
They say that Buzz also allows commands to be combined in intuitive ways with predictable results that make it relatively easy to use. It is also scalable and so can be used effectively in swarms of varying sizes.
They go on to show various examples of how the language works in practice and leads to self -organised behaviour using relatively simple rules, just like real swarms and flocks.
ThatвЂ™s interesting work that has the power to become a technology amplifier. Pinciroli and co say that the absence of a standardised programming language for swarms is a significant barrier to future progress because there is no easy way for researchers to share their work and build on each otherвЂ™s breakthroughs.
вЂњWe believe that one of the most important aspects of Buzz is its potential to become an enabler for future research on real-world, complex swarm robotics systems,вЂќ says the team.
And they have ambitious plans for the future. For example, they want to create a library of well-known swarm behaviours that will become building blocks for the future work of others.
Interesting stuff which may mean that the extraordinary flocks you see on future autumn evenings may not be starlings at all.
Ref: arxiv.org/abs/1507.05946В : Buzz: An Extensible Programming Language for Self-Organizing Heterogeneous Robot Swarms
Become an MIT Technology Review Insider for in-depth analysis and unparalleled perspective.
Emerging Technology from the arXiv covers the latest ideas and technologies that appear on the Physics arXiv preprint server. It is part of the Physics arXiv Blog. Email: … More KentuckyFC@arxivblog.com
Subscribe to Continue Reading
Uh ohвЂ“you've read all of your free articles for this month.
See international, alumni and other pricing options
Already an Insider?
Have a magazine subscription?
Artificial intelligence and robots are transforming how we work and live.
As robots get good at mimicking human behavior, people can be deceived into thinking they have human intelligence. So letвЂ™s put them to the test.
by Angelica Lim
A StarCraft gamer won 4-0 in the worldвЂ™s first contest between AI systems and professional human players.
by Yoochul Kim and Minhyung Lee
Quantum computers will soon surpass conventional ones, but it will take time to make the machines useful.
In partnership with Couchbase
In partnership with Pure Storage
Presented in partnership with VMware
Everything included in Insider Basic, plus the digital magazine, extensive archive, ad-free web experience, and discounts to partner offerings and MIT Technology Review events.
Unlimited 24/7 access to MIT Technology ReviewвЂ™s website
The Download: our daily newsletter of what's important in technology and innovation
Bimonthly print magazine (6 issues per year)
Bimonthly digital/PDF edition
Access to the magazine PDF archiveвЂ”thousands of articles going back to 1899 at your fingertips
Special interest publications
Discount to MIT Technology Review events
Special discounts to select partner offerings
Ad-free web experience
The mission of MIT Technology Review is to equip its audiences with the intelligence to understand a world shaped by technology.
A good programmer is someone who looks both ways before crossing a one-way street. -- Doug Linder, systems administrator
A most important, but also most elusive, aspect of any tool is its influence on the habits of those who train themselves in its use. If the tool is a programming language this influence is, whether we like it or not, an influence on our thinking habits. -- Edsger Dijkstra, computer scientist
Being abstract is something profoundly different from being vague. The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise. -- Edsger Dijkstra
Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer. -- Edsger Dijkstra
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup, developer of the C++ programming language
Commentary: most debugging problems are fixed easily; identifying the location of the problem is hard. -- unknown
Considering the current sad state of our computer programs, software development is clearly still a black art, and cannot yet be called an engineering discipline. -- Bill Clinton, former President of the United States
For a long time it puzzled me how something so expensive, so leading edge, could be so useless, and then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. -- Bill Bryson, author, from Notes from a Big Country
Given enough eyeballs, all bugs are shallow (e.g., given a large enough beta-tester and co-developer base, almost every problem will be characterized quickly and the fix obvious to someone). -- Eric S. Raymond, programmer and advocate of open source software, from The Cathedral and the Bazaar
Good code is its own best documentation. As you're about to add a comment, ask yourself, 'How can I improve the code so that this comment isn't needed?' Improve the code and then document it to make it even clearer. -- Steve McConnell, software engineer and author, from Code Complete
Hey! It compiles! Ship it! -- unknown
Inside every well-written large program is a well-written small program. -- Charles Antony Richard Hoare, computer scientist
It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter. -- Nathaniel S. Borenstein, computer scientist
Managing programmers is like herding cats. -- unknown
Measuring programming progress by lines of code is like measuring aircraft building progress by weight. -- Bill Gates, co-founder of Microsoft Corporation
More good code has been written in languages denounced as bad than in languages proclaimed wonderful -- much more. -- Bjarne Stroustrup, from The Design and Evolution of C++
Programs must be written for people to read, and only incidentally for machines to execute. -- Harold Abelson and Gerald Jay Sussman, computer scientists and authors, from The Structure and Interpretation of Computer Programs
Real programmers don't comment their code. If it was hard to write, it should be hard to understand. -- unknown
Simplicity is prerequisite for reliability. -- Edsger Dijkstra
The C programming language -- a language which combines the flexibility of assembly language with the power of assembly language. -- unknown
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. -- Tom Cargill, object-oriented programming expert at Bell Labs
The important point is that the cost of adding a feature isn't just the time it takes to code it. The cost also includes the addition of an obstacle to future expansion. Sure, any given feature list can be implemented, given enough coding time. But in addition to coming out late, you will usually wind up with a codebase that is so fragile that new ideas that should be dead-simple wind up taking longer and longer to work into the tangled existing web. The trick is to pick the features that don't fight each other. -- John Carmack, computer game programmer
The key to performance is elegance, not battalions of special cases. The terrible temptation to tweak should be resisted unless the payoff is really noticeable. -- Jon Bently and M. Douglas McIlroy, both computer scientists at Bell Labs
The last good thing written in C was Franz Schubert's Symphony Number 9. -- Erwin Dieterich, programmer
The problem with using C++ . is that there's already a strong tendency in the language to require you to know everything before you can do anything. -- Larry Wall, developer of the Perl language
The sooner you start to code, the longer the program will take. -- Roy Carlson, University of Wisconsin
The value of a prototype is in the education it gives you, not in the code itself. -- Alan Cooper, software author, from The Inmates are Running the Asylum
There are only two kinds of programming languages: those people always bitch about and those nobody uses. -- Bjarne Stroustrup
There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies. -- Charles Antony Richard Hoare
Ugly programs are like ugly suspension bridges: they're much more liable to collapse than pretty ones, because the way humans (especially engineer-humans) perceive beauty is intimately related to our ability to process and understand complexity. A language that makes it hard to write elegant code makes it hard to write good code. -- Eric S. Raymond
Weeks of programming can save you hours of planning. -- unknown
When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers cannot speak English. -- unknown
What do ParaSail, "modern" C++ and Rust have in common? They focus on "pointer free programming" (ok, maybe Rust doesn't, but it uses similar mechanisms). In this blog post I am exploring how we can move Nim into this direction. My goals are:
Memory safety without GC.
Make passing data between threads more efficient.
Make it more natural to write code with excellent performance.
A simpler programming model: Pointers introduce aliasing, this means programs are hard to reason about, this affects optimizers as well as programmers.
The title gave it away: We are going to get into this state of programming Valhalla by eliminating pointers. Of course for low level programming Nim's ptr type is here to stay but I hope to avoid ref as far as reasonable in the standard library. ( ref might become an atomic RC'ed pointer.) As a nice side-effect, nil ceases to be a problem too. Instead of ref object we will use object more, this implies the var vs "no var" distinction will be used more often, another benefit in my opinion.
What's wrong with Nim's GC?
Not much per se (hey, it's likely faster than the alternatives that I'm exploring here) but it makes interoperability with most of what's outside of Nim's ecosystem harder:
Python has its own GC and while building a Nim DLL that Python can load works, it would be even easier if the DLL wouldn't need special code that ensures the GC's conservative stack scanning works.
C++ game engines are based on RAII and wrapping a C++ object in a Nim ref object that calls a C++ destructor in a GC finalizer adds overhead. This applies to almost every big C or C++ project.
The conservative stack scanning can fail for more unusual targets like Emscripten. (Workarounds exist though.)
I have spent far more time now in fixing GC related bugs or optimizing the GC than I ever spent in hunting down memory leaks or corruptions. Memory safety is not negotiable but we should attempt to get it without a runtime that grows ever more complex.
Nim's containers should be value types. Explicit move semantics as well as a special optimizer will eliminate most copies.
Almost all containers keep the number of elements they hold and so instead of nil we get a much nicer state len == 0 that is not as prone to crashes as nil . When a container is moved, its length becomes 0.
Strings and seqs will support O(1) slicing, other containers might also produce a "view" into their interiors. Slices break up the clear ownership semantics that we're after and so will probably be restricted to parameters much like openArray .
Trees do not require pointers to be constructed, a seq can do the same:
However often only 1 or 0 entries are possible and so a seq would be overkill. opt is a container that can be full or empty, just like the well known Option type from other languages.
Under the hood opt[Note] uses a pointer, it has to, otherwise a construct like the above would take up an infinite amount of memory ("a node contains nodes which contain nodes which . "). But since this pointer is not exposed, it doesn't destroy the value semantics. It can be argued that opt[T] is very much a unique pointer that adheres to the copy vs move distinction.
Destructors, assignment and moves
The existing Nim supports moving via shallowCopy , this is a bit ugly so from now on a move shall be written as <- . Note that <- is not a real new operator here, I used it only to emphasize in the examples where a move occurs.
Value semantics make it easy to determine the lifetime of an object, when it goes out of scope, its attached resources can be freed, that means its destructor is called. If it was moved (if it escapes) instead, some internal state in the object or container reflects this and the destruction can be prevented. An optimization pass is allowed to remove destructor calls, likewise a copy propagation pass is allowed to remove assignments.
There are in fact two places where destruction can occur: At scope exit and at assignment, x = y means "destroy x; copy y into x". This is often inefficient:
This constructs 2 strings via the readLine calls that are then copied into the table t . At the scope exit of main the original strings key and val are freed.
This naive code does 2 copies and 4 destructions. We can do much better with swap :
This code now only does the required minimum of 2 destructions. It also quite ugly, key and val are forced to be var 's and after the move into the table t they can be accessed and contain the old table entries. This can occasionally be useful but more often we would like to keep the let and instead accessing the value after it was moved should produce a compile-time error.
This is made possible by sink parameters. A sink parameter is like a var parameter but let variables can be passed to it and afterwards a simple control flow analysis prohibits accesses to the location. With sink the example looks as follows:
Alternatively we can simply allow to pass a let to a var parameter and then it means it's moved.
Btw let key = stdin.readLine() will always be transformed into let key <- stdin.readLine() .
Optimizing copies into moves
Consider this example:
Since key is accessed after the assignment a = key it has to be copied into the array slot. But without the echo key statement the value can be moved. And so that's what the compiler does for us. Blurring the distinction between moves and copies means that code can evolve without "friction".
Every construction needs to be paired with a destruction in order to prevent memory leaks. It also must be destroyed exactly once in order to prevent corruptions. The secret to get memory safety from this model lies in the fact that calls to destructors are always inserted by the compiler.
But what is a construction? Nim has no traditional constructors. The answer is that the result of every proc counts as construction. This is no big loss as return values tend to be bad for high performance code. More on this later.
Code generation for destructors
Naive destructors for trees are recursive. This means they can lead to stack overflows and can lead to missed deadlines in a realtime setting. The default code generation for them thus uses an explicit stack that interacts with the memory allocator to implement lazy freeing. Or maybe we can introduce a lazyDestroy proc that should be used in strategic places. The implementation could look like this:
This is really just a variant of "object pooling".
Now that we have gained these insights, we can finally write down the precise rules when copies, moves and destroys happen:
var x = y is handled as var x; x = y . x , y here are arbitrary locations, f and g are routines that take an arbitrary number of arguments, z a local variable.
In the current implementation lastReadOf z is approximated by "z is read and written only once and that is done in the same basic block". Later versions of the Nim compiler will detect this case more precisely.
The key insight here is that assignments are resolved into several distinct semantics that do "the right thing". Containers should thus be written to leverage the builtin assignment!
To see what this means, let's look at C++: In C++ there is a distinction between moves and copies and this distinction bubbles up in the APIs, for example std::vector has
In Nim we can do better thanks to its template feature (which has nothing to do with C++'s templates):
Thanks to add being a template the final assignment is not hidden from the compiler and so it is allowed to use the most effective form. The implementation uses the unsafe ptr and addr constructs, but it is generally accepted now that a language's core containers are allowed to do that.
This way of writing containers works for more complex cases too:
Note how rule 3 ensures that t.a[h].key = k is transformed into a move since k is never used again afterwards. (Optimizing away the temporary k completely is a story for another time.)
Given these new insights, I assume that sink parameters are not required at all. Keeps the language simpler.
Templates also help in avoiding copies introduced by getters:
If we replace template get with proc get here rule 5 would apply and produce:
Here is an outline of how Nim's standard strings can be implemented with this new scheme. The code is reasonable straight-forward, but you always need to keep two things in mind:
Assignments and copies need to destroy the old destination.
Self assignments need to work.
Unfortunately the signatures do not match, =move takes 2 var parameters but according to the transformation rules move(a, f()) or move(a, lastRead b) are produced and these are not addressable locations! So we need different type-bound operator called =sink that is used instead.
The compiler only invokes sink . move is an explicit programmer optimization. Which can usually also be written as swap operation.
Return values are harmful
Nim's stdlib contains the following coding pattern for the toString$ operator:
(The declaration of the Node type is left as an excercise for the reader.) The reason for this workaround with the helper proc is that it lets us use result: var string , a single string buffer we keep appending to. The naive implementation would instead produce much more allocations and concatenations. We gain a lot by constructing (or in this case: appending) the result directly where it will end up.
Now imagine we want to embed this string in a larger context like an HTML page, helper is actually the much more useful interface for speed. This answers the old question "should procs operate inplace or return a new value?".
Excessive inplace operations do lead to a code style that is completely statement-based, the dataflow is much harder to see than in the more FP'ish expression-based style. What Nim needs is a transformation from expression based style to statement style. This transformation is really simple, given a proc like:
A call to it missing the final parameter p(args) is rewritten to (var tmp: T; p(args, tmp); tmp) . Ideally the compiler would introduce the minimum of required temporaries in nested calls but such an optimization is far away and one can always choose to write the more efficient version directly.
Second class types or parameter passing modes like var or the imagined sink have the problem that they cannot be put into an object. This is more severe than it first seems as any kind of threading or tasking system requires a "reification" of the argument list into a task object that is then sent to a queue or thread. In fact in the current Nim neither await nor spawn supports invoking a proc with var parameters and even capturing such a parameter in a closure does not work! The current workaround is to use ptr for these. Maybe somebody will come up with a better solution.
There is a pdf version of this book with nicer typesetting available for download.
You may also watch me teaching this material to a live audience.
For some time now I’ve been floating the idea of writing a book about category theory that would be targeted at programmers. Mind you, not computer scientists but programmers — engineers rather than scientists. I know this sounds crazy and I am properly scared. I can’t deny that there is a huge gap between science and engineering because I have worked on both sides of the divide. But I’ve always felt a very strong compulsion to explain things. I have tremendous admiration for Richard Feynman who was the master of simple explanations. I know I’m no Feynman, but I will try my best. I’m starting by publishing this preface — which is supposed to motivate the reader to learn category theory — in hopes of starting a discussion and soliciting feedback.
I will attempt, in the space of a few paragraphs, to convince you that this book is written for you, and whatever objections you might have to learning one of the most abstract branches of mathematics in your “copious spare time” are totally unfounded.
My optimism is based on several observations. First, category theory is a treasure trove of extremely useful programming ideas. Haskell programmers have been tapping this resource for a long time, and the ideas are slowly percolating into other languages, but this process is too slow. We need to speed it up.
Second, there are many different kinds of math, and they appeal to different audiences. You might be allergic to calculus or algebra, but it doesn’t mean you won’t enjoy category theory. I would go as far as to argue that category theory is the kind of math that is particularly well suited for the minds of programmers. That’s because category theory — rather than dealing with particulars — deals with structure. It deals with the kind of structure that makes programs composable.
Composition is at the very root of category theory — it’s part of the definition of the category itself. And I will argue strongly that composition is the essence of programming. We’ve been composing things forever, long before some great engineer came up with the idea of a subroutine. Some time ago the principles of structural programming revolutionized programming because they made blocks of code composable. Then came object oriented programming, which is all about composing objects. Functional programming is not only about composing functions and algebraic data structures — it makes concurrency composable — something that’s virtually impossible with other programming paradigms.
Third, I have a secret weapon, a butcher’s knife, with which I will butcher math to make it more palatable to programmers. When you’re a professional mathematician, you have to be very careful to get all your assumptions straight, qualify every statement properly, and construct all your proofs rigorously. This makes mathematical papers and books extremely hard to read for an outsider. I’m a physicist by training, and in physics we made amazing advances using informal reasoning. Mathematicians laughed at the Dirac delta function, which was made up on the spot by the great physicist P. A. M. Dirac to solve some differential equations. They stopped laughing when they discovered a completely new branch of calculus called distribution theory that formalized Dirac’s insights.
Of course when using hand-waving arguments you run the risk of saying something blatantly wrong, so I will try to make sure that there is solid mathematical theory behind informal arguments in this book. I do have a worn-out copy of Saunders Mac Lane’s Category Theory for the Working Mathematician on my nightstand.
Since this is category theory for programmers I will illustrate all major concepts using computer code. You are probably aware that functional languages are closer to math than the more popular imperative languages. They also offer more abstracting power. So a natural temptation would be to say: You must learn Haskell before the bounty of category theory becomes available to you. But that would imply that category theory has no application outside of functional programming and that’s simply not true. So I will provide a lot of C++ examples. Granted, you’ll have to overcome some ugly syntax, the patterns might not stand out from the background of verbosity, and you might be forced to do some copy and paste in lieu of higher abstraction, but that’s just the lot of a C++ programmer.
But you’re not off the hook as far as Haskell is concerned. You don’t have to become a Haskell programmer, but you need it as a language for sketching and documenting ideas to be implemented in C++. That’s exactly how I got started with Haskell. I found its terse syntax and powerful type system a great help in understanding and implementing C++ templates, data structures, and algorithms. But since I can’t expect the readers to already know Haskell, I will introduce it slowly and explain everything as I go.
If you’re an experienced programmer, you might be asking yourself: I’ve been coding for so long without worrying about category theory or functional methods, so what’s changed? Surely you can’t help but notice that there’s been a steady stream of new functional features invading imperative languages. Even Java, the bastion of object-oriented programming, let the lambdas in C++ has recently been evolving at a frantic pace — a new standard every few years — trying to catch up with the changing world. All this activity is in preparation for a disruptive change or, as we physicist call it, a phase transition. If you keep heating water, it will eventually start boiling. We are now in the position of a frog that must decide if it should continue swimming in increasingly hot water, or start looking for some alternatives.
One of the forces that are driving the big change is the multicore revolution. The prevailing programming paradigm, object oriented programming, doesn’t buy you anything in the realm of concurrency and parallelism, and instead encourages dangerous and buggy design. Data hiding, the basic premise of object orientation, when combined with sharing and mutation, becomes a recipe for data races. The idea of combining a mutex with the data it protects is nice but, unfortunately, locks don’t compose, and lock hiding makes deadlocks more likely and harder to debug.
But even in the absence of concurrency, the growing complexity of software systems is testing the limits of scalability of the imperative paradigm. To put it simply, side effects are getting out of hand. Granted, functions that have side effects are often convenient and easy to write. Their effects can in principle be encoded in their names and in the comments. A function called SetPassword or WriteFile is obviously mutating some state and generating side effects, and we are used to dealing with that. It’s only when we start composing functions that have side effects on top of other functions that have side effects, and so on, that things start getting hairy. It’s not that side effects are inherently bad — it’s the fact that they are hidden from view that makes them impossible to manage at larger scales. Side effects don’t scale, and imperative programming is all about side effects.
Changes in hardware and the growing complexity of software are forcing us to rethink the foundations of programming. Just like the builders of Europe’s great gothic cathedrals we’ve been honing our craft to the limits of material and structure. There is an unfinished gothic cathedral in Beauvais, France, that stands witness to this deeply human struggle with limitations. It was intended to beat all previous records of height and lightness, but it suffered a series of collapses. Ad hoc measures like iron rods and wooden supports keep it from disintegrating, but obviously a lot of things went wrong. From a modern perspective, it’s a miracle that so many gothic structures had been successfully completed without the help of modern material science, computer modelling, finite element analysis, and general math and physics. I hope future generations will be as admiring of the programming skills we’ve been displaying in building complex operating systems, web servers, and the internet infrastructure. And, frankly, they should, because we’ve done all this based on very flimsy theoretical foundations. We have to fix those foundations if we want to move forward.
Ad hoc measures preventing the Beauvais cathedral from collapsing
Leave a Reply Cancel reply
This is wonderful news! So looking forward to see the rest of the book. Thank you so much!
I will gladly pay a hefty sum for such a tome. In other words, I’m pumped!
This book would be very welcome indeed. I really believe we are at a point where we need to recognise the difference between computer science and programming. Programmers need help applying computer science and books like this would help enormously.
I’m “off the hook” as far as c++ is concerned. I mean seriously – besides diving into category theory I’ve got put up with arguably one of the ugliest programming language syntax out there? No way.
This gentleman has been working on for CS majors for a while.
Looking forward to reading it.
I presume you’re publishing this book serially or is it already published and this is just a reprint of its existing forward?
Sounds like a really interesting project! How far have you gotten in thinking about how such a book would differ from, say, Pierce’s?
Though I’m pretty dang far from being a category theorist, I think a lot of writing about it from a programming perspective ends up badly burying the lead. Here’s my little essay about what I think that is:
Lastly, I agree that software engineering is in a major transitional phase related to concurrency. However of the two dimensions of concurrency — parallelism and interactivity — I think that interactivity is the more significant for most developers.
It’s totally a work in progress. I’m currently in the middle of the first chapter. Defining a category, talking about types and functions, composition, etc. Also drawing some piggie diagrams 😉
Looking forward to getting my hands on it 🙂
I’ve considered writing a practical applications of category theory book myself — it is desperately needed. Its exciting to see far more capable hands undertake the effort! I’ll be first in line to buy it when it is released.
I’m really looking forward to this! Thanks for doing it!
It would be nice if you wrote it with Early Access Program (or maybe just online on GitHub).
This sounds really awesome in all respects apart from C++ (unless you’re specifically aiming this at the C++ community, that is, in which case fair enough!)
If you’re aiming it at a general audience, I’d argue that relatively few programmers these days are familiar with C++ outside of certain performance-critical niches, and that learning category theory is hard enough without also having to learn C++ first ;). If you want a pragmatic “lowest common denominator” engineering language in which to illustrate the concepts without assuming knowledge of FP, hate to say it but maybe just pick Java?
Really though, I would have thought most of the target audience for this would be familiar enough with a functional programming language to cope with a presentation centered slightly more around FP, although agreed that examples in other languages would be advisable too. It seems FP is where most programmers first get a taste for category theory, though.
On another note, I think the hard sell for me as a programmer (as opposed to a maths geek — I’m sort of both) when it comes to category theory has always been that nagging feeling that the concepts are too abstract for the setting in which they’re used, that they’re being thrown around gratuitously by people (and I count myself one) who find them interesting. Phrasing a problem and its solution in highly abstract generalised language can sometimes obfuscate a solution more than it casts light on it, so it’s always a trade-off. Does the code re-use, genericity, sharing of insights and intuitions, truly merit the abstract setting and the abstract language? Do we close ourselves off needlessly from other engineers by indulging too much in this kind of programming style?
Rather than claim that this debate has been settled either way, I’d rather just say that I’d hope a book for engineers (as opposed to computer scientists) on this topic would very much engage with this debate and all the nuance of it. As an engineer I feel it’s healthy to always have that devil’s advocate in the back of your mind asking “is this abstraction worth it?”, and I’d hope the book would too, if that’s not too much of a challenge 🙂
Good luck with the project anyway, I’ll be really interested to see what emerges!
As an old hand in the game of professional programming, I am always willing to understand how ”Computer Science” can help people like me in writing better programs. Yours could be the right thing for me. Bravo!
Way back I started reading a few CT books but wasn’t able to think of useful ways to apply it to my programming. Your book would be welcome. Count me a first day buyer when it’s ready.
This is one of the most effective prefaces for a programming book that I have read in a while. Looking forward to the rest of the book. Keep up the good work!
I’m intrigued and I’d like to say I would buy the book, but the C++ aspect is a big negative for me. I’d rather not learn C++ while learning category theory. I agree with Matthew that C# or Java would reach a much wider audience if you are looking to use a traditional imperative language. Haskell would work for me, too.
I was very enthusiastic when I saw this article, and immediately decided to buy the book. Alas, as soon as I read that code would be in C++, I gave up.
I’d rather see a kind of functional pseudocode than c++, but prefer Haskell, of course. For the same reason I didn’t buy “Functional programming in Scala” in spite of great reviews, because I think OO languages are totally unsuitable for learning FP concepts. As Josh said above – C++ – no way. Sorry.
This sounds just like what I’m looking for!
Having tried going through several CT books, the ideas are usually too abstract to truly grok the ideas and see how they can be applied to one’s own domains.
Many CT concepts (e.g. Monads) are like design-patterns: (1) many people have rediscovered them in different context for solving similar problems – but have not necessarily seen the generic nature of the solution; (2) you don’t necessarily need to “implement” the concept as a concrete generic tool. If you grok the pattern/concept you “reify” it in your code for your domain. You use the insights provided by the more abstract and general understanding to make the solution more correct/testable/robust/generalizable etc.
There should be lots and lots of (“reified”) examples showing what stuff does, how it works and how it is helpful in different contexts. Lots of examples help reaching the craved “Aha! Moment”.
I, for one, am looking forward to reading it. If you need reviewers, sign me up 🙂
Hi there, you’re undertaking a great endeavour for the programming community.
I’ve been searching for a book like this for some time now.
As other have said, I don’t feel C++ would be a choice supported by the general audience. If possible, I suggest you could switch to C#, which is not too far from C++ but I guess would be considered less cumbersome and be more acceptable for most people.
Anyway, good luck.
Do you intend to publish it “traditionally” or as a self-supported ebook (like on leanpub or similar platform)?
I think modern C++ is a fantastic choice! Or, a variety of languages.
I would definitely read that book!
I’ve been following your blog for a while now, so I look forward to the book and learning about category theory.
Please use GitHub (or something similar) => the community can comment and give you pull requests to make it the best it can be.
You have a Feynmanesque gift for explaining and analogizing abstract things like monads so I am definitely looking forward to this.
Particularly, I miss this kind of initiative in the C++ world.
This sounds great. I’m very excited to read this when it’s available.
I wouldn’t worry about the choice of language. Modern C++ is a good pragmatic compromise for showing how things translate into the paradigm that most programmers are used to. Also, if the book is good, you’ll have an army of people lining up to translate the examples into their favourite language, myself included.
Good luck and above all, have fun writing.
Hi Jos, Scala is a functional language, right?
I fully support the idea of using C++ in this book. I think that alone sets this book apart, as no other books are doing so. Of course, using another language like Haskell is necessary in the meantime. Maybe you should use more than two to meet the biggest possible audience. I wouldn’t mind comparing Haskell, Scheme, and C++ code simultaneously. 🙂
All sounds good to me – I’ve been learning Haskell for several years, trying to apply functional techniques in my C++ as well (resulting in (yet another) Either monad approximation recently), and a better understanding of category theory would go down very nicely…
I’m looking forward to it! I think it was really well written. I especially like the paragraph [But even in the absence of concurrency…all about side effects].
Thank you so much for this work !
I’m very glad you’re presenting the imperative side in C++. It may, as you note, not be the prettiest language, but I think that to effectively expose such abstract concepts as those found in category theory requires (or is greatly aided by) as much abstractive power as possible— and among the common tongues, C++ is second to none in that regard.
I think the sentence “you may appreciate the thought that functions and algorithms from the Haskell standard library come with proofs of correctness” is not true. Where are the proofs of correctness?
Amazing work so far! I’m eager to keep reading, and I hope that you might convert this from a set of blog posts to an actual book (EPUB, PDF, TXT) that I could show people who don’t understand yet. Please, keep up the excellent work!
This is exactly the article I have been waiting for. Can’t wait to read more !!
I’m a Haskell baby, an engineer, find much of the language tough going and am hoping this article will give me another perspective. The little I’ve read so far gives me some hope
May I suggest that a Concept Map that gives an overview of “Category Theory for Programmers” will be very helpful to get a good grasp of Category Theory?
The following website has quite a bit of information what Concept Maps are, how they help in encapsulating and passing knowledge, how they can be developed, and also has tool that can be used to develop Concept Maps–
I have just read this one and I keep asking myself, “when is this book going to be printed? I need to have one copy of it, yes, for my nightstand also, and for my professional growth.”
Your style of writing is very lucid. I’m not the brightest pencil in the shed, but you have me interested because you may be able to help me understand it.
I am very thankful about this stuff! is there a change you could compile an ebook etc. from these chapters? I would like to read this from kindle/paper.
Looks nice Bartosz!! I’m really exited about this. Will there be a physical book also?
Maybe you can do the book on Github so others can also contribute.
Looking forward to part 2.
Huh! I was just about to ask Bartosz to keep the book posts on GitHub for easy commenting and review. +1
Just came across this and this is absolutely great. Diving into the chapters already available. Thanks for Haskel && C++ combination. I think that is a great choice of language for the topic.
And yeah, do NOT put it on Github (or any other bitbucket) please..
Seems like there’s been a pause in the articles. Hopefully it picks back up, I was really enjoying following along!
These are really great articles for someone like me who’s try to understand all the category stuff behind packages on hackage, say lens, i will keep watching your update!
I can’t believe this! Just yesterday, while thinking about the problems of understanding how the Haskell type system works, I thought “If only somebody wrote a book on Category Theory for programmers”. And here it is! Thank you for this effort.
What a great read! I really enjoyed this and more than anything loved the gothic cathedrals as an example. Thank you.
I earnestly hope that the recent date of the last post means the monad post is coming soon! This looks great!
Hi, about that book on your night stand; is it accessible without a solid bqckground in group theory? Or is it something I should wait with
@sestu: Mac Lane has examples from various branches of mathematics: vector spaces, groups, rings, etc., but these are not essential to understanding his main ideas. Having said that, it’s a book for a working mathematician, which means it’s written in a very terse style. Without some experience in reading math papers, it’s very hard to follow. As a more gentle introduction, I would suggest Lawvere and Schanuel, Conceptual Mathematics.
psst, it’s Beauvais not Bauvais 🙂
Thanks for this wonderful serie.
@Denis: Oops! In my defence, the spelling was correct under the picture.
@bartosz Agreed: Conceptual Mathematics is a far clearer presentation of beginning category theory and the best book widely available on the topic. Your book is another leap in clarity just as great as the gulf between these two books.
Excellent insight and enthusiasm. Have you considered the MEAP program? I’d purchase your work-in-progress today.
I wonder whether a print book be available. I’m ready to pay for it. Great job! I’m a professional programmer and a math hobbyist (mostly abstract algebra). I found this book very conceivable for a programmer. I’m now on Natural Transformations and can’t stop reading 🙂 Thank you, Bartosz.
Wow!, this really good. Thank you
Thanks for this! It was the perfect next step, for me.
I’m struggling with Challenge 6 in your Functorality chapter: Make std::map profunctorial. I got rmap working, but I’m stuck on lmap. I wonder if you might have time to look at what I’ve done and comment:
Thanks, in advance, for any time you can afford this!
@BartoszMilewski, thanks for the great book!
I’m recording my responses to your challenges, in the form of an IHaskell notebook, which is viewable here:
@BartoszMilewski I’m wondering, how long it took you to learn all of that? Or were you born with that knowledge? =)
I must say, I’m struggling a bit with concepts, I’m reading aside books about the theory, returning to your posts, rethinking something… I see though that it’s useful, and I’m curious, how long it took for you to came to that level, and was it actually hard? What did you do in the absence of blog posts by Bartosz Milewski?
@Constantine: It took me a very long time. Not so much category theory itself — that I started studying just a few years ago — but the general background in mathematics. I went to a high school with extended program in mathematics, where I learned the basics of logic, axiomatic theory, geometry and calculus. Then I studied physics, which involved a lot of higher math. I was taught calculus through Banach and Hilbert spaces, and algebra through group theory and fibre bundles. So I had a very strong background in math when I switched to programming.
Do I struggle reading math books and articles? You bet! But I just keep at it and don’t give up. The trick is not to think about the ultimate goal, but to enjoy the process of learning. This has become so much easier nowadays, with all the resources available through the internet.
Thank you very much. Wonderful trove of information. Would have wished if we could have had this course in our under grad! Thanks again for sharing.
Very interesting. I’m looking forward to reading the body of the book. As for your “butcher knife”, the history of thought is replete with sharp instruments: natural scientists use Ockham’s Razor, and philosophers are familiar with Hume’s Guillotine. Perhaps we hackers will come to speak of Milewski’s Cleaver.
You have “keep if from disintegrating” instead of “keep it from”…
(And thanks a lot for this!)
The most valuable posts about category theory : very clear and I learn alot!
Thank you for all your excellent material on category theory, I am really looking forward to the book! I was wondering whether you are planning to cover anything related to “zip” and “zipWith” from a category theory perspective? I am a programmer and – mainly thanks to your blog – I have developed an interest in category theory. In programming zips are very common, and n-ary zips can be defined in a quite general way. I am thinking something like Hoogendijk’s “A generic theory of datatypes”, specifically “Chapter 5 – A Class of Commuting Relators”. Unfortunately, the text is not nearly as accessible as your material. Anyway, I just thought I’d leave it here as a suggestion. Keep up the great work!
Dear doctor Milewski, I read the material on your website and follow your lectures on YouTube. You are a good lecturer and, also, a prefect writer. Thank you for your efforts in simplifying things! I just wanted to say that I think there is a typo in this page: “in. C++” should be replaced with “in C++.” Thank you again.
@Ali Ghanbari: Thank you! And fixed!
I am one of your “fans”. 🙂 This Haskell and Category Theory “stuff” is the best I have seen in 30 years of profession and another 26 in childhood education.
I have read this blog several times. I love your youtube lessons, too.
We need to translate it into other languages (german first, please).
How do we deal with copyright issues?
Just throwing this idea out for your consideration: have you thought about opensourcing your book and moving it over to Wikibooks.org?
Wikibookifying will allow others to contribute to your book, translate it into multiple languages, and maintain your book in the event that you shut down your blog.
Hello Bartosz, I really like your blog and your videos, I just wanted to ask you if it is possible to have a pdf version of your posts?
@Dame, Unfortunately, I don’t have a PDF version of my post. I write them directly in HTML.
Bartosz, I add my praise to all the other praise you have received already. Like you, I am a theoretical physicist working in computing with a love for the mathematics underlying both physics and computer science. Have you considered self-publishing? You could use a crowdfunding site like Kickstarter or Indiegogo to raise money for the book with some sort of premium to funders (like a free ebook). I would be willing to contribute, and it sounds like others would as well.
Thank you! It’s not a problem of money but of time. Writing a book is a very time-consuming process.
what is the order parameter in the phase transition ?
Just chiming in to say that your explanations are of top-notch quality. I loved your example of how the list functor isn’t representable in one of your posts on the Yoneda lemma. Thanks so much for your hard work in making this content, and for making it available to the public!
Typo page 6 on mobi edition. Even java….let the lambdas in [missing ‘.’] C++ …..
Sad face when I saw C++ was going to be used!
Sad face when I saw C++ was going to be used!
I think it’s justified. If you expected a functional language, like Haskell — then there’s no reason in this blog series. Because Haskell advertises Category Theory, there’s no way you know Haskell, and never read anything about that.
I made this epic book into a PDF! You can download it (+ LaTeX sources) here: https://github.com/hmemcpy/milewski-ctfp-pdf
Wow, the PDF is super-nice! It seems Bartosz is happy about this work too. Great job!
Thank you so much for your awesome work sir! Like you said I completely forgot about math – hope you will be gentle – I am just starting!