45

From a reasonably common programming language, which do you find to be the most mind-bending?

I have been listening to a lot of programming podcasts and taking some time to learn some new languages that are being considered upcoming, and important. I'm not necessarily talking about BrainFuck, but which language would you consider to be one that challenges the common programming paradigms?

For me, I did some functional and logic (for example, Prolog) programming in the 1990s, so I can't say that I find anything special there.

I am far from being an expert in it, but even today the most mind-bending programming language for me is Perl. Not because "Hello World" is hard to implement, but rather there is so much lexical flexibility that some of the hardest solutions can be decomposed so poetically that I have to walk outside away from my terminal to clear my head. I'm not saying I'd likely sell a commercial software implementation, just that there is a distinct reason Perl is so (in)famous. Just look at the basic list of books on it.

So, what is your mind-bending language that promotes your better programming and practices?

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Jé Queue
  • 3,937
  • 2
  • 29
  • 37

26 Answers26

73

APL

This language is incredibly powerful and very terse, it will hurt your brain.

For starters it's tricky to use without a custom keyboard, or at least a keyboard overlay to show up all the obscure symbols it uses.

APL Keyboard

Then the language is of the vector/array-based paradigm and specialises towards complex linear algebra. The original version did not even have loop constructs, anything and everything done by chaining rather unusual array operators together.

  • strip_tags() anybody? (borrowed from Wikipedia)

strip_tags() ala APL

Orbling
  • 5,696
  • 1
  • 32
  • 38
  • 18
    +1 for showing the keyboard – tcrosley Jan 07 '11 at 20:24
  • 5
    @tcrosley: It's nice if you have a real one: http://www.wickensonline.co.uk/apl/unicomp-apl-top-large.jpg – Orbling Jan 07 '11 at 20:35
  • 4
    And if it wasn't already mind-bending enough, there were some operators that required using the backspace/overstrike key. For example, matrix inverse was the square box (over the L key) overstruck with a divide sign (the one next to the backarrow key in the upper right corner of the keyboard image). – Tangurena Jan 07 '11 at 20:37
  • @Tangurena: That simplified layout I put in the answer is nice and clear at a size that fits - the true scope of the beauty/madness is more accurately reflected with the keyboard image I posted in the comments. – Orbling Jan 07 '11 at 20:40
  • 2
    I'm having flashbacks to the early 1980s when I did APL to do high level statistical regression analysis, people still use that? Shudder. – HLGEM Jan 07 '11 at 20:59
  • 1
    @HLGEM: Well they do use it a fair bit in the financial sector still. The modern version has .NET integration and everything, to all things there is a season. – Orbling Jan 07 '11 at 21:18
  • 2
    I did lots of APL once - it still holds a nostalgic spot for me... I loved it at the time. – quickly_now Jan 08 '11 at 00:28
  • @Orbling: that's an image of a newish APL keyboard (ALT key). Anyone got a picture of an old one? I remember working on a hardcopy APL terminal back in about 1976. I had to help out a developer who couldn't use it - her fingernails were too long, so I had to learn enough APL to help her out! – John Saunders Jan 08 '11 at 16:23
  • @Orbling: Oh My God! It's even more cryptic than Perl, I certainly thought I'd never encounter such thing in a real world language. Who in their right might would ever think of creating such beast ? – Matthieu M. Jan 08 '11 at 16:28
  • 1
    @Matthieu M.: Who would create such a beast? Mathematicians. It's effectively a nice (exceptionally powerful/complex) algebra notation. To quote the alternative title of a recent paper appearing in Vector: **APL is not for programmers** (http://www.vector.org.uk/?vol=24&no=4&art=karman) Also, Perl isn't cryptic! (well, not at less you want it to be: http://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0014.html) – Orbling Jan 08 '11 at 18:08
  • @Orbling: it was quite a rhetorical question in fact, I understand that the notation is powerful, my claim is that you'd better either have the handbook at hand, because whenever you stumble on an unknown symbol, you'll be hardpressed to deduce its meaning from its representation :) – Matthieu M. Jan 08 '11 at 19:48
  • 2
    @Matthieu M.: Very true, the learning curve is so steep it is practically vertical. – Orbling Jan 09 '11 at 00:26
  • @John Saunders: Do you mean something like the old IBM 2741 http://en.wikipedia.org/wiki/IBM_2741, that had an APL mode on a hardcopy terminal, using those Selectric typewriter balls. http://en.wikipedia.org/wiki/IBM_Selectric_typewriter#The_Selectric_as_computer_terminal – Orbling Jan 09 '11 at 20:07
  • 2
    Heh, or Conway's game of life in one line of APL: http://catpad.net/michael/APLLife.gif – Earlz Jan 10 '11 at 06:15
  • @Earlz: I nearly posted that example in my question, but figured it would be less well known to this community than the `strip_tags()` example. It's amazing you can get something so profound in to such a small representation. – Orbling Jan 10 '11 at 10:52
  • 2
    YouTube video describing Conway's game of life in APL (if you can follow it - you're an automatic hire): http://www.youtube.com/watch?v=a9xAKttWgP4 – Gary Apr 28 '11 at 16:18
  • @Gary Rowe: Just got around to watching that. Absolutely magnificent, very clear and easy enough to understand (assuming you have a firm grounding in linear algebra) - the beauty of the language is unparalleled in my book. – Orbling May 27 '11 at 11:13
  • 1
    @Orbling And I thought I had a busy schedule.... ;-) – Gary May 28 '11 at 07:08
  • 1
    Whenever I see someone doing something in APL, I keep imagining the characters floating onto the screen in a wispy Harry Potter-like manner. – Rei Miyasaka Aug 16 '11 at 05:27
  • 1
    As a native speaker of APL, I found looping and (later) pure machine code on the CDP1802 microprocessor to be mind-bending. I always found handling big data to be a bit tedious until I learned about the Icon programming language (http://en.wikipedia.org/wiki/Icon_%28programming_language%29) in the mid-80s. Implicit iteration having been made commonplace by Python and Ruby has made me a very happy programmer. – Andrew Beals Mar 12 '12 at 14:17
  • @AndrewBeals: I would agree with you heavily there. The standard imperative 3GL iteration mechanisms can be extremely cumbersome if you are used to vector or functional programming, particularly when multiple dimensions are at play. I have not used [Icon](http://www.cs.arizona.edu/icon/) in.. ages.. late-90s perhaps. Now you mention it, I see how much of a forerunner it was for the hybrid imperative-functional languages we see today, with a good bit of vector thrown in. Very good sequence generators and commands like `every` made it good. Text IO specialist, things I would use Perl for. – Orbling Mar 12 '12 at 14:50
56

Haskell. It is very close to being purely functional, which most people are not accustomed to; very demanding, which is helpful once you know what you're doing but frustrating until then; has a rather cryptic, highly symbolic syntax, which is great once you know it but opaque before that...the list goes on.

Also, it's simply impossible to format the stuff in a way that looks good to me.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Jon Purdy
  • 20,437
  • 7
  • 63
  • 95
  • 7
    I would have said Haskell too, but not because it's cryptic. While it may certainly be difficult to understand, the mind-bending thing is about the theory behind it. Monad and Arrows are still a domain I have not conquered :) – Matthieu M. Jan 07 '11 at 19:34
  • 2
    @Matthieu: Monads and arrows are definitely mind-bending. – Larry Coleman Jan 07 '11 at 19:39
  • 11
    Why "Very close to being purely functional"? It is purely functional. – dan_waterworth Jan 07 '11 at 20:03
  • 3
    @dan_waterworth: If a language has any facility for side-effects, it's not purely functional. Haskell cleanly encapsulates side-effects and sequence using monads, but they're there nonetheless. Good style may be to minimise them, but...they're there nonetheless. It is an insult to say it's not purely functional? A purely functional general-purpose programming language would hardly be useful! – Jon Purdy Jan 07 '11 at 20:12
  • 3
    I'll refer you to http://haskell.org/ then, surely the homepage isn't wrong. This is how I think of it, haskell never executes impure functions during it's execution, but haskell's execution does return an impure function that does do impure things. Haskell itself is still purely functional. – dan_waterworth Jan 07 '11 at 20:18
  • @dan_waterworth: Anything that Haskell does *is* Haskell itself! Alright, if you arbitrarily exclude the feature of Haskell that makes it impure, then it's pure. But by that I could say that *any* language is purely functional. – Jon Purdy Jan 07 '11 at 20:30
  • 1
    @Jon, but you can't call impure functions in Haskell, you can only compose them, that makes it pure. Purely functional languages can do IO, if you don't buy it with haskell, take a look at mercury. – dan_waterworth Jan 07 '11 at 20:34
  • 1
    @dan_waterworth: Oh, sure. They're just called *for* you, in the order you specify. There's no real difference. – Jon Purdy Jan 07 '11 at 20:58
  • 1
    @Jon, there's a difference when it comes to optimization. – dan_waterworth Jan 07 '11 at 21:00
  • 2
    @dan_waterworth, @Jon - You really have to pretend. When it comes down to it even Haskell compiles to machine code that mutates registers and memory. So really you are both wrong if you want to be so black and white about it. – ChaosPandion Jan 07 '11 at 21:15
  • 1
    @ChaosPandion, we can't both be wrong, it's either purely functional or it's not, there's no semi-purely functional. – dan_waterworth Jan 07 '11 at 21:17
  • 2
    There's no such thing as a purely functional language, not a useful one anyway. Without *some* side effects, it might as well be a black box. – Robert Harvey Jan 07 '11 at 21:19
  • 4
    I'd like to quote myself and add to how Haskell will bend your mind: "Haskell prevents you from shoving things under the carpet, forces you to deal with the structure of your program explicitly, and it teaches you a language to describe these structures: the language of types. Understanding types, particularly rich types as is Haskell, will make you a better programmer in any language." http://programmers.stackexchange.com/questions/28950/is-haskells-type-system-an-obstacle-to-understanding-functional-programming/33172#33172 – Waquo Jan 07 '11 at 21:29
  • 2
    I can see I'm fighting a losing battle here, but you can have a purely functional language that does IO. Look at mercury, it has pure functions that do IO. How? Because in mercury IO functions take a 'state of the world' value and return the new 'state of the world', that means that referential transparency is preserved for every function, even the IO ones! – dan_waterworth Jan 07 '11 at 21:31
  • 1
    @dan: That's a common explanation for Haskell's `IO` monad too, but it falls short as soon as the outside world is modified from anything outside - e.g. OS, other programs, user, new input to peripherals, etc. Care to explain how this works except perhaps on an embedded system in a sterilized lab? –  Jan 07 '11 at 21:34
  • 14
    Haskell is a purely functional programming language. The code you write in Haskell is purely functional (as long as you don't use unsafePerformIO and the like). The IO-Monad is purely functional, if you believe otherwise, you don't understand how monads are used to model control-flow in a purely functional way. Think of your program as a shopping list of IO-actions, with a shopping list being just a pure data structure, no side-effects, and the language runtime being the shopper that performs the side-effects. – Waquo Jan 07 '11 at 21:35
  • 3
    Has someone linked to the following yet: http://stackoverflow.com/questions/3117583/is-haskell-truly-pure-is-any-language-that-deals-with-input-and-output-outside-t . As far as I can follow the argument (which isn't very), there's a distinction between purity of specification and purity of execution. But the distinction flies so far over my head it may as well be in orbit... – rtperson Jan 07 '11 at 21:37
  • 1
    @delnan, yes ok, imagine instead of the 'state of the world', the value was a little more concrete. Let's say it's the current time, every IO function takes the previous latest known current time and produces a new, more accurate one. Can you find any issues with this model? – dan_waterworth Jan 07 '11 at 21:45
  • @dan: Wouldn't the result still depend on when exactly the next IO function is invoked? –  Jan 07 '11 at 21:48
  • 2
    @delnan, yes it would, but as, in order to do this, you have to have linear types (otherwise the world could be copied) this doesn't pose a problem. Another representation is an incrementing value, in essence it counts the number of IO function calls. – dan_waterworth Jan 07 '11 at 21:55
  • 1
    @dan: So the world can't be copied, fine. But aren't the IO functions still impure, as they return a different new state for the same input state depending on when they are called? You gave an example of something that can be modeled purely (counting IO calls), but so far you failed to show how this can model the (totally impure) outside world in a pure way. –  Jan 07 '11 at 21:58
  • 2
    @delnan, Ah, but because the value is always increasing, an IO function can never be called with the same 'world value' twice, so they can never receive the same input values and hence are pure. – dan_waterworth Jan 07 '11 at 22:02
  • @dan: But that's not the point, or do I miss the topic of the debate? I though the issue was *purely* functional IO, not making sure the same value isn't used twice. Because when you want to model IO with pure functions, I see more pressing issues than that. –  Jan 07 '11 at 22:04
  • 1
    @delnan, but because a value can never be used twice and is always passed to IO functions the IO function always remain referentially transparent, they always return the same output for the same input. It has to be the case because they can never receive the same input twice. – dan_waterworth Jan 07 '11 at 22:06
  • @dan: I'm not sure if "never gets the same input twice -> can't give different output for the same input -> is pure" works. Granted, it may even be correct, strictly speaking, for some definition of a pure function (I have to note that Wikipedia names a second constraint for pure functions, that it does not have observable side effect, e.g. changing the state of an output device - but I don't know if that's a common definition; it would make this argument moot though) –  Jan 07 '11 at 22:16
  • 2
    @dan_waterworth: How about this: in a purely functional language, the state of the program could be expressed as a function of time, and thus would be reversible. Haskell provides a facility for irreversible operations, therefore it is not purely functional. I'm not entirely sure what the point of arguing this is anyway, since total functional purity, like any such radical language design element, is of rather limited use. – Jon Purdy Jan 07 '11 at 22:17
  • 1
    @delnan, I think a better definition is: "a pure function doesn't base it's output on anything that's not in it's arguments". As an argument to each IO function is 'the world' then it's entirely possible for IO functions to modify and return a new version of it. – dan_waterworth Jan 07 '11 at 22:24
  • @dan: An IO function must incorporate everything that happend in the outside world (files created or removed or changed, devices added or removed, etc.) in the new state, right? How can it do so from the old state? It can't, it must peek at the outside world - which changes over time, not with the old state passed as argument - so with this definition, your IO functions would be inherently impure (as intuition suggests). Perhaps more predictable, but still impure. –  Jan 07 '11 at 22:29
  • @dan_waterworth: This conversation would've been significantly shorter if we'd been working under the same assumptions from the beginning. – Jon Purdy Jan 07 '11 at 22:31
  • 8
    @Jon, how about, we agree that: Haskell, the language, is purely functional, but it's runtime system is not. The execution of a haskell program is impure, but the program itself is pure. – dan_waterworth Jan 07 '11 at 22:32
  • @delnan, it doesn't need to keep track of the entire outside world because it can't revisit it. Granted, you may think that you have to be able to recalculate any function at any time in order for it to be pure, but with a linear type system, you can construct functions that no-one could dispute as pure that you couldn't revisit. – dan_waterworth Jan 07 '11 at 22:37
  • @dan_waterworth: Agreed. – Jon Purdy Jan 07 '11 at 22:44
  • @dan: Let's assume your reasoning it's formally correct. Okay, onto next step: Does it buy us anything (as opposed to e.g. the IO monad)? Optimization oppoturnities? Any semantic differences? (Also agreed with "Haskell, the language, is purely functional, but it's runtime system is not. The execution of a haskell program is impure, but the program itself is pure.") –  Jan 07 '11 at 22:45
  • 2
    @delnan, Both the IO monad and the 'state of the world' models tell the compiler the same thing. In essence, they give the compiler a flow diagram. Here's the interesting bit, given an optimal flow diagram for a problem (only gives the bare minimum of sequencing), it's possible for a compiler to generate an optimal program. Obviously current compilers can't do this, but as compilers get better they will be able to transform this information better than your average C programmer (especially with the rise of multicore). – dan_waterworth Jan 07 '11 at 23:00
  • 4
    @dan_waterworth: Good defence, didn't realise the argument was raging or would've assisted. A language is a pre-compilation state, how it runs is something else. The language is purely functional. – Orbling Jan 08 '11 at 01:09
  • 3
    I'm giving this answer +1, not solely for the answer itself, but for the interesting "comment" discussion that it triggered. ^^ – gablin Jan 08 '11 at 11:12
  • 3
    +1 On my 3rd Haskell lecture, I suddenly realized "this is what programming is all about", and I'm still having that feeling now and then, 13 years later :) – Macke Jan 08 '11 at 20:26
  • 1
    changed 'strict' to demanding because that has a special meaning for programming languages –  Jul 03 '12 at 13:41
30

Prolog. It was just so different than any other language I had used when I was first exposed to it. I like it, so I don't hate the syntax or anything.

Matt H
  • 2,133
  • 16
  • 22
  • 2
    I approached Prolog as reverse programming, wanting to know my answers already and then program to get the questions :) – Jé Queue Jan 07 '11 at 19:49
  • 1
    @Xepoch: I think you may be right there, Prolog is formulating the question. One of the only proper 5GL languages in use. – Orbling Jan 07 '11 at 20:07
  • In general I think Prolog is ever so interesting and exceptionally powerful, but I have great trouble getting my head fully around cut placement (`!`). – Orbling Jan 07 '11 at 20:08
  • +1 for Prolog, I had an artificial intelligence course that used Prolog and that is only the only computer science course that I have done poorly in. – rjzii Jan 07 '11 at 21:00
  • Prolog isn't a functional programming language though. Being soured on functional by Prolog is like being soured on procedural programming by Lisp. – JUST MY correct OPINION Jan 08 '11 at 04:57
  • One surprising thing about Prolog is that a basic prolog interpreter is actually surprisingly simple to implement. The fundamental algorithms behind it (e.g. unification and resolution) turned out to be much simpler than I thought they would be. – Tikhon Jelvis Jul 03 '12 at 19:43
24

I will agree with you on Perl. It's the most ugly syntax I've ever seen. They say, that even Perl developers cannot remember what they have written the day after.

Sorantis
  • 2,720
  • 17
  • 24
  • 2
    Def +1 on Perl. I was always particularly fond of (I believe they are called) 'implied' variables. Makes for great write-only code. – GrandmasterB Jan 07 '11 at 22:31
  • 2
    Everyone writes Perl so differently that they might as well be writing different languages- you don't have to just learn how Perl works to pick up someone else's code in it, you also have to learn how that particular person used it. – glenatron Jan 08 '11 at 00:32
  • 3
    Bah to this answer and both comments on it. Well written perl is easy to read and write. Baby-perl written by newbies is simple, if verbose. The only "unreadable" perl is either obfuscated on purpose, or scripting one-liners. – Sean McMillan Oct 07 '11 at 14:42
22

I would have to say Forth. The notation that all operations are stack manipulations. In its pure form there are no local variables to use.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Jeff
  • 1,318
  • 9
  • 10
  • Forth is a lovely language, though I agree it can be a bit of a strain on the brain to begin with. – Orbling Jan 07 '11 at 19:37
  • 10
    FORTH is a wonderful language. When I was first learning programming in the early 80s, I had an Atari 400 and my choices were interpreted BASIC, Assembly and FORTH. I used all three extensively, but FORTH more than any other. I still have Leo Brodie's ultra-classic Starting FORTH and Thinking FORTH books. In fact, if I were asked to create a self-hosting language from scratch on a new hardware system, I would choose FORTH without hesitation. – Adam Crossland Jan 07 '11 at 19:39
  • 3
    @Adam Crossland: Thinking FORTH is a great book, you might be interested in this link: http://thinking-forth.sourceforge.net/ – Orbling Jan 07 '11 at 20:42
  • 1
    @Orbling: great minds think alike. Not more then 10 minutes ago, I put the PDF on my Kindle. – Adam Crossland Jan 07 '11 at 20:50
  • 1
    @Adam Crossland: A fine place for it. That book is generally helpful for programmers, should be on the reading list for people - interested in FORTH or not. – Orbling Jan 07 '11 at 20:55
  • 1
    I entirely agree. It has a very great deal to say about how we think about solving problems generally. Brodie is such a lucid thinker and clear writer. His works are a joy to me. – Adam Crossland Jan 07 '11 at 21:00
  • I think Forth is nice. It doesn't compare to things like C# and other modern languages, but the language is very small. It is the general consensus that Forth is the easiest (usable)interpretter to make. And the language features themselves are very easy to learn. Using the limited features of the language is the biggest challenge. – Earlz Jan 10 '11 at 06:08
21

Ruby.

This makes me want to kill myself:

1.month.from.now()

(I could have the exact syntax wrong, but you get the point).

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Matthew Read
  • 2,001
  • 17
  • 22
  • 1
    I agree that it seems to be a bit much, especially for everyday programming tasks, but why does it make you want to kill yourself? That's also not the language itself, that's the API of a library. You could also have written: 1 month from now. It makes for good DSLs. – Matt H Jan 07 '11 at 19:28
  • 23
    OMG. Who ever thought this was a good idea? – EpsilonVector Jan 07 '11 at 19:59
  • 5
    You may not like it, but it doesn't bend my mind. In fact, I can easily tell what the result _should_ be. – Berin Loritsch Jan 07 '11 at 20:18
  • 8
    The mind-bending is not with the reading, it's with the writing. Coming up with this nonsense is difficult, and having to memorize/lookup all the built-in functions/properties is ridiculous. – Matthew Read Jan 07 '11 at 20:23
  • 7
    To be fair, this is not part of the standard Ruby library. It's an extension added by the Rails framework. When you do a lot of date manipulation or need quick relative dates it helps. Outside that arena, it makes little sense. – Berin Loritsch Jan 07 '11 at 20:26
  • 55
    Is it only me that thinks this looks awesome, and is possibly a good reason to learn Ruby? – Orbling Jan 07 '11 at 20:37
  • 9
    It is awesome to read, yes. But does this mean I can write 3.months.from.last.month.if.it.was.a.leap.year? No. Or at least, I don't *think* so. If I can...RoR can be the first telepathic language ever. – morganpdx Jan 07 '11 at 20:49
  • 3
    @morganpdk - I'm not sure that's really the point at hand. That's not valid in Ruby (based on any existing libraries). Matthew's sample is. You can't compare apples to make-believe oranges. – Craige Jan 07 '11 at 20:52
  • 1
    @Craige: But, as a programmer, you can develop your own make-believe oranges and have them instantiated in to reality. Ah, the divinity of coding. – Orbling Jan 07 '11 at 20:57
  • 4
    To be fair, I hate **all** of Ruby. This was just a handy example ... and this sort of thing seems to be accepted in the Ruby community, whereas it would be shunned in most others. – Matthew Read Jan 07 '11 at 21:03
  • 3
    But is it that Ruby bends your mind, or you just plain don't like it? It seems to me like the latter. – Berin Loritsch Jan 07 '11 at 21:06
  • 15
    What is wrong `DateTime.Now.AddMonths(1);`? These *features* hardly make the code more readable. *(I'm not saying C# has the best syntax. You can shift it to any languages conventions and it will still apply.)* – ChaosPandion Jan 07 '11 at 21:13
  • 2
    @Berin Yes, I woke up one day and decided to hate Ruby without any reasons behind it, such as mind-bending. Downvote my answer and be a fanboy elsewhere. – Matthew Read Jan 07 '11 at 21:30
  • 5
    @Matthew Read - Dude, the question isn't "What language do you hate", it's "What language bends your mind?" Ruby uses the same '.' syntax that is used in python, java, c, c++, c#... and the example that you give is from a library. So are you saying that you find `Array.each{|k| puts k}`, or `Object.new()` to be mindbending in a *bad* way? – philosodad Jan 07 '11 at 23:33
  • 5
    The thing is you don't have to spend all your time looking through the documentation because you think "in an ideal world, how would this work" and then just type it. Nine times out of ten, that is what is built into Ruby. I think as programmers we tend to get our minds bent out of shape by languages that insist we shall do things in the language way, rather than the language trying to get out of our way and work the same as we think. Ruby gets out the way and lets you program. – glenatron Jan 08 '11 at 00:29
  • @glenatron: Well said, I really do not like prescriptive, "thou shall not... so sayeth the lord (language overlords)", style languages. They are hard to adapt with as they force-fit the programmer to the designers philosophy, rather than providing flexible approach roads to tackling a problem. – Orbling Jan 08 '11 at 01:13
  • 1
    I actually agree, btw, that Ruby is mind-bending. But mostly because I've been competent to solve my own coding problems in Ruby for a long time, but I'm still only on the outer edges of what I *could* be writing. – philosodad Jan 08 '11 at 02:37
  • 2
    I'm just going to believe this answer was sarcastic. :p – Shreyas Satish Jan 08 '11 at 16:50
  • Ruby was designed to be concise, yet human readable. This isn't actual code, and there isn't nearly as much "magic" keyword things in Ruby as you say, and what magic there is, there usually is a replacement "conventional" function. If you were going to gripe about Ruby you should've griped about how every gem/library changes base classes and suddenly 1+1 can equal "abc" and other weird stuff. Or the fact that the programmers say that proper Ruby code at least writes half of itself. (ie, way too much meta programming) – Earlz Jan 10 '11 at 06:06
  • 1
    When you have a REPL environment and you can grep any object's methods, the only mind bending thing is that it's possible, without straining too hard, to write really intuitive, readable code that doesn't hurt. But some people like their kingdoms of nouns. – JasonTrue Jan 10 '11 at 06:14
  • 1
    @ChaosPandion - not much mindbending in _that_ now, is there? –  Nov 11 '11 at 22:47
18

Brainfuck

Anyone who can honestly write this mockery of a language shouldn't even need a thread like this.

Hello World (pointers, left; explaination, right):

+++++ +++++             initialize counter (cell #0) to 10
[                       use loop to set the next four cells to 70/100/30/10
    > +++++ ++              add  7 to cell #1
    > +++++ +++++           add 10 to cell #2 
    > +++                   add  3 to cell #3
    > +                     add  1 to cell #4
    <<<< -                  decrement counter (cell #0)
]                   
> ++ .                  print 'H'
> + .                   print 'e'
+++++ ++ .              print 'l'
.                       print 'l'
+++ .                   print 'o'
> ++ .                  print ' '
<< +++++ +++++ +++++ .  print 'W'
> .                     print 'o'
+++ .                   print 'r'
----- - .               print 'l'
----- --- .             print 'd'
> + .                   print '!'
> .                     print '\n'
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
17

Lisp is my latest mind-bending language.

I've taken the monads and functional programming from Haskell with me, and now I have macros to work with. I'm just getting into CLOS and haven't touched the condition system at all.

Larry Coleman
  • 6,101
  • 2
  • 25
  • 34
  • I don't even like the Lisps (with the possible exception of Clojure -- I still haven't made up my mind there) and gave you a +1. The mind-bending part is certainly there and what I learnt from Lisp, even though I don't use it, informed much of what I do in other languages. – JUST MY correct OPINION Jan 10 '11 at 06:27
14

MUMPS

This is a language that pops up from time to time in stories online and has the added honor of being in actual production use storing critical life-safety information (that is, patient records). However, this is also a language where terseness is appreciated and functions such as the following might appear in production code (example from the Wikipedia article on the topic):

s A="String" F i=1:1:$L(A) W $c($S($A($E(A,i))<91:$A($E(A,i))-52#26+65,1:$A($E(A,i))-84#26+97))
Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
rjzii
  • 11,274
  • 6
  • 46
  • 71
  • wow, you're not joking are you? I didn't oversleep and suddenly it's April 1st? Nothing with that many parentheses and dollar signs should be anywhere near my patient records. – dan_waterworth Jan 07 '11 at 21:11
  • @dan_waterworth - I wish I was, but InterSystems is actually one of the companies out there that works with MUMPS although you will sometimes also see it going by M. – rjzii Jan 07 '11 at 21:16
  • @Rob Z, note to self: stay away from InterSystems =P btw, I can see how this would bend the mind and also that it promotes good programming practises (by serving as a warning rather than example though), so +1 – dan_waterworth Jan 07 '11 at 21:22
  • 1
    My first ever programming job was with a company that specialized in MUMPS! Sadly I'd done a university course on web development so they put me in company's newly-formed ASP team instead of with the old hands, but MUMPS was the language we were trained in for our first few weeks. Maybe I had a lucky escape... – thesunneversets Jan 07 '11 at 21:52
  • 1
    Anybody that posted here from Madison Wisconsin? Verona, really? – Hans Passant Jan 07 '11 at 22:44
  • +1 You know, I like terseness. But there is a point where the nested brackets start to move and hypnotise you. – Orbling Jan 08 '11 at 01:18
  • 1
    I do believe thedailywtf.com has a whole section dedicated to MUMPS. Doesn't look like a language I'd want to touch. – Tyanna Jan 08 '11 at 02:55
  • My uncle actually use to work in Mumps. He said the most interesting part of the language is that the database is a core unavoidable part of the language. – Earlz Jan 10 '11 at 06:02
  • @Tyanna - I've linked a couple of thedailywtf.com stories in the answer. – rjzii Jan 10 '11 at 12:54
  • 1
    I remember learning M in academia, and thinking it was interesting as a special purpose language. The terseness it allows is like a perverse sort of minification. In my naivete, I figured production code would contain little of the language's extreme shorthand. The first and only time I saw a production M codebase my gut tightened... it looked just like your example. Oh, the horror! – ajk Aug 31 '11 at 18:20
13

I'd say Coq, or another implementation of dependent type theory. Haskell's type system is not very expressive comparatively. Moving to a more expressive type system (for example, the calculus of constructions (CoC)) allows you to do some neat things, like proving properties of programs within the language, and embedding strong invariants into your types which can be checked statically.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
  • 2
    Any Dependent Type system/prover/language would probably rate more confusing than the regular languages, so +1. – Orbling Jan 09 '11 at 19:36
  • 1
    Formal verification of programs is something I'm just starting out on. It certainly bends the mind and is becoming increasing useful in the real world. +1 – dan_waterworth Jan 09 '11 at 21:26
7

Objective-C. To be fair, I only studied it extremely briefly and disliked the syntax at first glance so much that I gave up on it.

Since it is such a (relatively) common language (mainly for Mac/iPhone/iPad development), I'm sure it's actually somewhat decent once you get used to it.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
jnevelson
  • 649
  • 1
  • 6
  • 11
  • 2
    Well, it probably does qualify as a bit mind-bending, but I like it. It might help if you realize `[foo bar]` is just syntactic sugar for `objc_sendMsg(foo, "bar");` which in turn looks up the function pointer (it's a special "bar", not a generic one). Did you realize it's fully duck typed? – Per Johansson Nov 03 '11 at 18:32
  • Objective-C is just an enormous syntactic sugar around runtime functions. Once you get used to `[receiver doStuff:arg]` it looks pretty much like a dynamic java – toasted_flakes Nov 24 '13 at 10:39
6

I pick Mercury.

Mercury bent my mind by showing me that even pure languages can do I/O.

The way this works is that I/O functions in Mercury take a 'state of the world' value and return a new 'state of the world' value. So I/O functions in Mercury transform the world and hence purity is maintained.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
dan_waterworth
  • 7,287
  • 2
  • 34
  • 45
6

It has to be Scheme, surely. Trying to explain call-with-current-continuation always hurts my brain, but once you understand it you can make incredibly elegant solutions.

Want to stop part-way through an algorithm and hand control to someone else? Sure!

Want to resume the same continuation several times? Of course!

Want to pause execution of an algorithm, redefine a function, then resume execution with the original stack but an updated global state? No problem! And do this several times with different changes to the global state but the same stack re-entry point? For you, sir, anything!

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Cameron Skinner
  • 401
  • 2
  • 7
  • +1 LOL + "For you, sir, anything!" Apart from almost being a line in a song in Oliver!, it is also a good aspiration for a language to have. – Orbling Jan 08 '11 at 04:53
  • 1
    Scheme is not the only language with explicit continuations. [Haskell](http://en.wikibooks.org/wiki/Haskell/Continuation_passing_style "Haskell/Continuation-Passing Style"), for example, supports it just fine and just as mind-bendingly. – JUST MY correct OPINION Jan 08 '11 at 05:06
  • 4
    It's arguably more mind-bendy in Haskell, since it (call/cc) is implemented as a library and not a language feature. But maybe that makes it less mind-bendy. – Logan Capaldo Jan 08 '11 at 19:29
  • I think it's simultaneously both more and less mind-bending. Keeping that contradiction in my head bends my mind. So in the end Haskell is more mind-bending. :) – JUST MY correct OPINION Jan 10 '11 at 06:31
  • The cool thing about Scheme (and *Ruby*!) continuations **is** that they are *built-in* into the language. Haskell basically just adds it's monadic syntax around ordinary continuation passing style, which you can do in Scheme too. But having call/cc built-in *everywhere* without having to embed the whole thing in a monadic construct definitely allows many mind-bending constructs. – Dario Jan 26 '11 at 20:40
  • @Cameron - I learned exactly what call/cc did by adding it to the ELK implementation we extended at my employer at the time to meet the R4RS specification. The truly mind-bendy part of that project (aside from re-learning a LISP-like language) was trying to fit a full Scheme implementation that had not only a GUI, but also a rich set of multimedia display options built into a general-purpose data browser onto a Windows 3.1 platform while simultaneously writing the MacOS front-end for it. Needless to say, the Windows part of my job took much more time... – Andrew Beals Mar 12 '12 at 14:32
4

I used to use an ancient editor called TECO (Text Editor and COmparator), which was a very powerful text modification language, with all sorts of macro capability. I don't remember the exact famous quote about it but the gist was"any random collection of 20 characters is almost always a legitimate TECO program, and will change your file (it is an editor) in a fundamentally unpredicatable manner. I remember writing a Fortran to PL1 converter in about a page of TECO code.

Omega Centauri
  • 237
  • 1
  • 2
  • 5
    *"One of the more entertaining games to play with TECO is to type your name in as a command line and try to guess what it does. Just about any possible typing error while talking with TECO will probably destroy your program, or even worse-- introduce subtle and mysterious bugs in a once working subroutine."* Man, those were the days! – JUST MY correct OPINION Jan 08 '11 at 05:08
  • 1
    TECO was also the original base of EMACS. EMACS started off as just a collection of TECO macros! – Gabe Jan 08 '11 at 08:08
  • @Omega: it's necessary to say which TECO you're referring to. DEC TECO, as shipped with TOPS-10, or MIT TECO, the one written in MIDAS. This latter TECO is what EMACS was written in. It's also how EMACS was extended. I used to hack EMACS instead of passing classes. – John Saunders Jan 08 '11 at 16:18
  • I only used DEC TECO. And yes those were the days (to be young again).... – Omega Centauri Jan 08 '11 at 21:14
  • 1
    Makes me remember typing in Vim command mode – ron Jan 09 '11 at 18:23
  • Call ... call the ... the doctor! I'm having ... TECO FLASHBACKS!!! – Peter Rowell Feb 15 '11 at 03:00
  • Worked with TECO on a PDP-11/70 running RSTS/E. It had a corresponding visual editor. I dumped its code on to my screen and at first thought it was binary. But then I realized that the visual editor was just one pages-long TECO macro. I learned a lot about the TECO language and found some undocumented commands by deciphering the 'source' of that visual editor. – Justsalt Dec 30 '11 at 13:16
3

REBOL

It's built around the notion of code-as-data, like Lisp is. The language's adherents have a hard time explaining what its unique benefits are over other approaches in that family, and usually wind up shrugging and saying something like "Well the guy who designed the AmigaOS came up with it, the standard library is included and microscopic, and once you 'get' it that will be like taking the red Matrix pill and you'll never want to go back."

The trouble with it is partially that it's quirky and hasn't precisely defined which programmers are its market. But also partially because many of the people advocating it just suck at explaining. :)

But Douglas Crockford used to be a fan, drew some inspiration from it with the creation of JSON, and has suggested people look into it as recently as October, 2010:

"Ted Neward did a really good job of moderating the panel on 'Future of Programming Languages'. At the end of the panel, Ted asked the panelists which languages they though people should be learning in order to get new ideas. The list included Io (Bruce Tate), Rebol (Douglas Crockford), Forth and Factor (Alex Payne), Scheme and Assembler (Josh Bloch), and Clojure (Guy Steele)."

Source: sauria.com

I think it's worth looking at for anyone looking to stretch how they think about language design and extensibility. Now that it's open source (after 18 years of proprietary development) the usual disclaimers I used to give for keeping it at arm's length no longer apply... it's worth a look! The community has even gotten out of their proprietary Rebol-based messaging program and started chatting on Stack Overflow (much to my surprise!)

  • 1
    I avoid REBOL because its sole practical implementation is a non-standardized, non-open piece of software that is changed at the whimsy of its owning corporation. (Rebol 2 vs. Rebol 3...) If it is ever standardized or opened I'll be taking another look but until that day Rebol remains off of my toolbelt. – JUST MY correct OPINION Jan 10 '11 at 06:34
  • 1
    @JUSTMYcorrectOPINION perhaps the day has come to take another look! Rebol 3 is [now Apache2 licensed software](http://hostilefork.com/2013/01/11/logo-design-for-rebol/). We've even got a [RebolBot](http://stackapps.com/questions/3960/rebolbot-a-chat-bot-for-the-chat-rooms) here in the [Rebol and Red chat room](http://chat.stackoverflow.com/rooms/291/rebol-and-red) on StackOverflow to help us with demo'ing the language. *([Red](http://www.red-lang.org/) is another open source Rebol variant that is showing some very interesting promise as a hybrid compiled version.)* – HostileFork says dont trust SE Jul 03 '13 at 05:39
3

Assembly has been the most "mind bending" to me, but I'm just starting it.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Anto
  • 11,157
  • 13
  • 67
  • 103
  • what makes it worse is it is OS & hardware dependent – Dave Jan 09 '11 at 18:33
  • What about it makes it so? Straight instructions without explicit grouping order? something else? – Jé Queue Jan 09 '11 at 22:45
  • well, in particular, I dislike how unclear the program flow easily turns out to look. It isn't easy to read quickly. – Anto Jan 09 '11 at 22:55
  • 2
    Ah, the Cincinnati Milacron 2200B: Variable word length combined with runtime modification of the *address* of a JMP. It made LSD look tame. – Peter Rowell Feb 15 '11 at 03:08
3

Lisp. Learning it is a series of small epiphanies, each of which will totally change the way you think about solving programming problems.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
David Kendal
  • 165
  • 7
2

I would say from the lengths that many people go to avoid having to directly write it, that developers find SQL to be mind-bending. I guess many people just don't naturally think in terms of sets.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
HLGEM
  • 28,709
  • 4
  • 67
  • 116
  • SQL certainly bends the mind, but it doesn't help me to write better code. – dan_waterworth Jan 07 '11 at 21:09
  • 4
    SQL is as natural to me as BASIC, just me. Amazing how easy DB-backed application can be when your grasp full data handling in SQL. – Jé Queue Jan 07 '11 at 21:19
  • @dan_waterworth, I think SQL can help you writer smaller and more concise code by putting more logic into SQL vs. handling most conditionals and subsequent queries back at the app. – Jé Queue Jan 07 '11 at 21:20
  • @Xepoch, I think, if there's anything that the rise of ORMs has taught us, it's that people don't like to write in SQL if they can avoid it. They'd much rather write in their own language. – dan_waterworth Jan 07 '11 at 21:25
  • I guess using anything that can write better code than you can is a good thing. – JeffO Jan 07 '11 at 22:08
  • A whole 'nother topic on ORMs, but my project success was increased by orders of magnitude once I finally started treating SQL as a first-class language ("How I stopped worrying and learned to love SQL" :-) ). – Jé Queue Jan 07 '11 at 22:22
  • @Xepoch: As @dan_waterworth mentions, many people tend to avoid SQL for anything other than basic retrieval/storage, with some basic searching. I think the reason for this is one of coupling as opposed to being "mind bending". I have never been overly keen on making my code too dependent on what SQL implementation is available in any given location, and not at all keen on prescribing a particular incarnation. Until relatively recently my old company servers only had MySQL 4.1 installed, so no stored procs or views. – Orbling Jan 08 '11 at 01:21
  • SQL is easy for a human to write. It's difficult, or at least cumbersome, for a human to write a program to write. Notable(stupid) inconsistencies include the difference between `insert` and `update`. As well as tons of odd keywords – Earlz Jan 10 '11 at 05:57
2

Pure

Pure is a functional language based on term rewriting. I like it, it is both sparse and expressive, if a little bit understated.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Aliud Alius
  • 131
  • 3
  • +1 Functional means vector, exceptionally powerful language that. As a descendant of q (which owes a bit to APL) and borrowing a ton from Haskell et al. It certainly warrants mention. – Orbling Jan 08 '11 at 01:26
2

It might not be the most mind-bending, but it has been by far the hardest for me to learn (I thought Haskell and assembly language were easier!)

That is the set of HDL languages, notably, VHDL (and Verilog to a lesser extent)

Getting over the fact that every "function" runs at the same time is incredibly difficult and you can not avoid the shift to parallelizing absolutely everything. Of course, this is only border-line a programming language though.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
Earlz
  • 22,658
  • 7
  • 46
  • 60
  • I did a little VHDL once. I had a real epiphany moment when I suddenly realized that, as I was adding code, effectively more and more hardware would appear to implement that code and it was all running simultaneously. Like multithreaded programming with truly unlimited simultaneously executing threads; maybe people with access to unlimited nodes on EC2 or map-reduce clusters get a similar buzz. (But shortly afterwards I came to appreciate what a complete pain it is to implement anything non-trivial in these langauges, and ran away). – timday Jan 10 '11 at 20:14
  • 1
    Being electrical engineer I didn't have much problem with the simultaneity, it was quite a liberation in fact. As for the pain of implementation, well the uP is a niche-solution to specific classes of problems that transform the problem to solution that can be described as algorithms, a concept originally taken from mathematics. A problem with inherent parallelism is among the problems easy solvable and VHDL and FPGA's come in handy at that times. –  Mar 17 '11 at 08:22
  • Yeah, VHDL is freaky if you are not already a programmer and used to working w/ multiple simultaneous blocks. – shieldfoss Jul 15 '13 at 14:28
1

Tcl

I started to learn it once, but as I learned enough to make sense I really disliked the way it made my brain feel. That would seem to qualify as mind-bending.

David Thornley
  • 20,238
  • 2
  • 55
  • 82
  • 1
    I did a lot of Tcl programming around 1995-1997 for no particularly good reason. When I started looking for a new job in 1998, every recruiter in the entire Bay Area tried to get me in to interview for poorly-paid, high-pressure VIGNETTE gigs. I quickly removed it from my resume. I considered giving you a hard time over this, as I remembered Tcl as being really easy, but I kind of wish that I had learned Python instead, in retrospect. – Adam Crossland Jan 07 '11 at 20:56
  • Tcl is definitely an acquired taste. Personally I think the design of the language is genius -- no other language fits my brain as well as Tcl does, but I know I'm in the minority. Love it or hate it, learning it requires that you rethink how languages should work. – Bryan Oakley Jun 17 '11 at 15:52
1

Turing machine language, obviously. It is extremely powerful, provably superior to all other programming languages that exist, and guaranteed to hurt your brain if you try to use it.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
user12667
  • 101
  • 1
  • 6
    I have to object to claiming that its provably superior. The term superior suggests bringing subjective issues into account. Also, if we run C on a computer with infinite memory (which is only fair because a Turing machine runs with infinite memory) they are equivalent in power. – Winston Ewert Jan 08 '11 at 04:02
  • 2
    @Winston: The tape of a turing machine does not have to be infinite. It only needs to have a tape factory at each end that can manufacture additional tape as needed :) – Mike Dunlavey Jan 08 '11 at 19:43
  • "Provably superior" is by definition an objective term. It means that any language can be implemented on a Turing machine, but not every language can implement a Turing machine. Of course, that's also true for languages like C as well, provided infinite memory and infinite stack. – user12667 Jan 08 '11 at 21:44
  • BrainFuck as mentioned already in the question, and it's pretty much Turing's machine language. – Mchl Jan 08 '11 at 22:27
  • 1
    That shows that a Turing machine is more powerful. The problem is that, at least as I'd use the term, claiming a language to be superior would also take into account ease of use, availability, etc. – Winston Ewert Jan 09 '11 at 00:54
  • Additionally, almost every programming language is turing-complete making it equal in power (ignoring memory size issues) to a turing machine. – Winston Ewert Jan 09 '11 at 00:55
  • @Mike: Right - and a C program can use removable media. Same principal. Didn't stop some friends of mine (from back when mag tape was everywhere) from filling out a standard requisition form for some infinite-length tapes. – David Thornley Jan 10 '11 at 19:09
1

C

Pointers, memory management and type casting all take a lot of thought and are easy to get wrong. The lack of built-in data structures like hash tables or lists means you either have to devise your own or find a third-party library and learn its API.

david4dev
  • 648
  • 3
  • 7
-1

CIL

CIL, the Common Intermediate Language that all .NET programs compile to, a kind of an object-oriented assembly. It's interesting for me to try write or read code in it and comparing its constructs to those of C# that I already know. It's a good way to learn more what .NET does behind the scenes. And it can be useful for things like dynamic code generation or rewriting existing compiled code using Mono Cecil.

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
svick
  • 9,999
  • 1
  • 37
  • 51
  • 2
    or bytecode for that matter too? – Jé Queue Nov 17 '11 at 22:14
  • If you mean Java bytecode, then I have no experience with it whatsoever, so I'm not in a position to recommend it as mind-bending. – svick Nov 17 '11 at 22:32
  • I wouldn't really compare Java-Bytecode and CIL, as Java-Bytecode is already compiled and CIL will get compiled at runtime (Just-In-Time-Compiler of .net) – basti Jul 04 '12 at 09:25
  • @chiffre Under most circumstances Java Bytecode and CIL work exactly the same. In both cases, you have source code (C# or Java) that gets compiled to a binary intermediary language at “compile-time” (CIL or Java Bytecode), which then gets compiled to actual machine code at “runtime”, by a JIT compiler. – svick Jul 04 '12 at 10:25
-1

TeX counts as a language, since it is Turing complete, and I consider it quite mind-bending. A language for typesetting math, (and books on programming)...

Peter Mortensen
  • 1,050
  • 2
  • 12
  • 14
-1

JESS (Java Expert System Shell). Embedded in a Java environment, this adaptation of CLIPS is a functional rule based expert system language. Trying to map real Java objects as facts and find the right questions to ask to get the results you expect is a real challenge. Less so if you are familiar with expert system theory, but when you are coming from a pure OOP mindset it doesn't fit well. NOTE: CLIPS is not Lisp, but looks like it. Yet another mind bender.

Once you get past the initial learning curve, it is pretty powerful and pretty darn quick to come up with the answers.

Berin Loritsch
  • 45,784
  • 7
  • 87
  • 160
  • Jess is a modern version of CLIPS which was also embeddable as a sort of scripting/logic engine for your own applications. – Tangurena Jan 07 '11 at 20:32
  • Ok, I stand corrected. http://www.haskel.com/corp/details/0,10294,CLI1_DIV139_ETI9759,00.html Nevertheless, it requires a very different mindset from the language it is embedded in. – Berin Loritsch Jan 07 '11 at 20:46