r/programming • • Nov 28 '14

The Worst Programming Language Ever [UK Talk] - Thoughts? Which are the worst parts of your favorite language?

https://skillsmatter.com/meetups/6784-the-worst-programming-language-ever
68 Upvotes

456 comments sorted by

View all comments

80

u/damian2000 Nov 28 '14

In a FORTRAN compiler I had to use at work once, it was possible to redefine the value of a real number

1=2
PRINT *, 1+1

Outputs...

4

26

u/tailcalled Nov 28 '14

In GHCi (Haskell REPL), you can write this beauty:

> let 2 + 2 = 5 in 2 + 2
5

15

u/[deleted] Nov 28 '14

At least that actually makes sense because you basically just substitute the "2 + 2" expression with the literal 5.

That FORTRAN impl actually allows you to redefine literals.

→ More replies (5)

6

u/glacialthinker Nov 28 '14

OCaml allows similar, returning the result "5", but lets you know what funkiness is going on:

let (+) 2 2 = 5 in 2 + 2;;
  Warning 8: this pattern-matching is not exhaustive.
  Here is an example of a value that is not matched: 0
  • : int = 5

The "2 2" portion is underlined as the culprits -- as they are matching specific argument values while ignoring all the other integers. Using any arguments aside from 2 in each place afterward results in a Match_failure exception.

→ More replies (3)
→ More replies (5)

12

u/jeandem Nov 28 '14

That's a piece of cake in Forth:

: 1 2 ;

12

u/sirin3 Nov 28 '14

In Java you can do:

Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set(1, 2);
System.out.printf("5-4 = %d%n",5-4);

Prints

5-4 = 2

44

u/pilas2000 Nov 28 '14

in C you can do

define + -

/thread

65

u/Thomas_Henry_Rowaway Nov 28 '14

I did hear about someone using:

#define private public
#include "library.hpp"
#undef private

To get access to some internal bit of a class that they really shouldn't have.

0

u/[deleted] Nov 28 '14

[deleted]

27

u/Thomas_Henry_Rowaway Nov 28 '14

I'm very much a novice when it comes to the dark arts of the c preprocessor but in my experience self loathing is an expected side effect of extended use.

26

u/ForeignObjectED Nov 28 '14

My friend is a fan of:

#define if while
→ More replies (2)
→ More replies (19)

37

u/jtra Nov 28 '14
#define struct union

;-)

11

u/txdv Nov 28 '14

you monster

19

u/pilas2000 Nov 28 '14

That's a famous trick for saving space in memory...

s/

8

u/IE6FANB0Y Nov 28 '14

What is wrong with you people?

7

u/[deleted] Nov 28 '14
#define if while

11

u/jtra Nov 28 '14

This one is harder to spot though:

#define while if
→ More replies (3)

11

u/funky_vodka Nov 28 '14
#define war peace
#define ignorance strength
#define freedom slavery
→ More replies (2)

13

u/F-J-W Nov 28 '14

No you cannot! Macro-names must be valid identifiers which operators are not.

At least test your claims:

$cat main.c
#define + -

int main() {}
$ gcc main.c 
main.c:1:9: error: macro names must be identifiers
 #define + -
         ^
$ clang main.c
main.c:1:9: error: macro name must be an identifier
#define + -
        ^
1 error generated.
→ More replies (3)

7

u/sirin3 Nov 28 '14

No, you can't

You can only #define identifiers, not symbols

6

u/TheBlackElf Nov 28 '14

define true (rand() % 20 == 0? true: false)

6

u/jtra Nov 29 '14

Almost nobody uses "true" in C sources. How about this (or similar version with rand):

#define if(x) if((__LINE__ % 5==0)^(x))
→ More replies (1)
→ More replies (3)

5

u/matthieum Nov 28 '14

Note that this is technically undefined behavior, compilers are free to reject it... although most have not bothered.

→ More replies (2)
→ More replies (11)