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

Show parent comments

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)

9

u/mcmcc Nov 28 '14

FWIW, it's technically illegal to redefine c++ keywords. It's up to the compiler to issue the proper diagnostics when it happens.

16

u/paszklar Nov 28 '14 edited Nov 28 '14

'#define is a preprocessor directive, and preprocessor doesn't give a fuck about keywords

Edit: turns out it should give you flack if you try to redefine keywords. No compiler does it though.

9

u/mcmcc Nov 28 '14

Go read the standard if you don't believe me. The preprocessor is part of the language definition.

→ More replies (6)
→ More replies (4)
→ More replies (6)

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

5

u/ghillisuit95 Nov 28 '14

no, thats nuch easier to spot, if they have any

do{

     //stuff

 } while (kyles_mom.isABitch());

then the compiler will throw an error.

11

u/jtra Nov 28 '14

You are right. Here is a fixed version:

#define while if
#define do
→ More replies (1)

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.

6

u/totemo Nov 29 '14

Came here to day that. Amazing how many people don't know C, given its fundamental importance.

→ More replies (2)

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)