[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


File: 1430476720981.jpg (51.75 KB, 400x267, 400:267, semantic_bullshit.jpg)

f6eb08 No.2344

Not being too srs here, but sometimes I like to fantasize about how certain language semantics could be altered. Came up with this earlier:

void eg() {
// Series of if statements, typical for any C-styled language:
if (a) {}
else if (b) {}
else {}

// If you wanted loops, you can (in C):
if (a) while (a) {}
else if (b) while (b) {}
else while (c) {
// This last condition is exactly equivalent to:
// else if (c) while (c) {}
// "while ()" performs a check, defeating the point of "else"
}
// Which brings us to:

// Changing the semantics of while, for, and else:
while (a) {
// "while" and "for" can now be used to create a series of conditions, like "if".
}
else while (b) {
// Now, instead of ending the series of if statements, "else while"
// is treated like an "else if" where "else while (condition)"
// functions like "else if (condition)"
break; // will exit the entire series of blocks, skipping over "else"
}
else {
// This block is executed when neither condition (a) nor (b) are true.
}

// There is no point in an "else" or "default" loop
// since loops perform an "if" check by definition.

// …With one exception, a "do while ()" loop performs no check:
if (a) {}
else do {
// "else do while ()" is already possible in C and already functions
// the same way as in this example. It is just an "else".
} while (c);

// These examples could be mixed:
while (a) {}
else if (b) {}
else for (int i = 0; i < c; ++i) {}
else do {} while (d);
}

I'm sure plenty of you have ideas. Post them, or if you're feeling frisky, tell me how stupid mine is. Consider this a semantic masturbation thread for autists.

f6eb08 No.2345

> // This last condition is exactly equivalent to:

> // else if (c) while (c) {}

> // "while ()" performs a check, defeating the point of "else"

correction: it's equivalent, except it ends the if, else if, else sequence, allowing no further conditions.


c4f60f No.2347

>>2344

Python has something a bit like that:

>https://stackoverflow.com/questions/3295938/else-clause-on-python-while-statement

>I'm sure plenty of you have ideas. Post them

I kind of wish C standardised using "0"-length arrays at the end of data structures, i.e.:

struct muh_struct {
int some_bullshit;
int muh_flexible_array[0];
};

The Official Syntax™ for flexible array members:

struct muh_struct {
int some_bullshit;
int muh_flexible_array[];
};

logically makes sense (it's an array with an undefined size), but in practice it looks like it was done on accident (like the programmer completely forgot to put in a size, or meant to use a pointer instead, or…).


b2e387 No.2378

>>2344

you could probably implement some of that

http://www.chiark.greenend.org.uk/~sgtatham/mp/




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]