Skip to content

Smallest piece of code in the world?

April 24, 2014
tags:

It has been said that the smallest piece of code in the world is the C code shown below for copying strings.

while (*d++ = *s++);

That is just a whopping 17 characters long! Really?

I’ll do that in Scheme/Lisp:

(set! d s)

There 9 characters long.

Advertisements
4 Comments leave one →
  1. rayburgemeestre permalink
    April 29, 2014 2:44 am

    Scheme/Lisp seems bloated, in C++ it’s as easy as: “d = s;”
    (:trollface:)

    • April 29, 2014 9:13 am

      I got the information on the C++ code in a discussion at stackoverflow so I just took their word for it being a former C++ developer myself. But that solution you gave is not copying a string, it is assigning a pointer to be the same, there are no separate areas. The lisp code I gave gives you the notion of copy.

  2. April 29, 2014 10:15 pm

    Sure thing, but as pointed out in a LinkedIn discussion, Lisp has a richer semantics than C/C++ – Let see you destroy a pointer. Lisp has no such thing. No leaks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: