Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I like C but not its syntax

Name: Anonymous 2014-12-02 12:11

Why hasn't anyone made C that doesn't look like dogshit?

Name: Anonymous 2014-12-03 18:42

>>36
1) C wouldn't need a special syntax for function types because it doesn't have function types. It forces you to use (void *) for all function types.
Wait, what?

typedef int* IntPtr
It's not special syntax.

If simplicity was wanted, why not use s-exps?
Because it would look like shit for C.

Name: Anonymous 2014-12-03 19:02

Okay, OP, here you go. Here's what C might look like with a different syntax and basically no other changes (except fallthrough because fuck that)

function main(argc: Int, argv: [[Char]]) -> Int do
var ch: Int
var stdout_lock: FileLock
setlocale(LC_TYPE, "")
while (ch = getopt(argc, argv, "belnstuv")) != 1 do
case ch of
'b' =>
bflag = nflag = 1
'e' =>
eflag = vflag = 1
'l' =>
lflag = 1
'n' =>
nflag = 1
else
usage()
end case
end while
argv += optind
if lflag then
stdout_lock.l_len = 0
stdout_lock.l_start = 0
stdout_lock.l_type = F_WRLCK
stdout_lock.l_whence = SEEK_SET
if fcntl(STDOUT_FILENO, F_SETLKW, addr_of stdout_lock) == -1 then
err(EXIT_FAILURE, "stdout")
end if
end if

if bflag oror eflag oror nflag oror sflag oror tflag oror vflag then
scanfiles(argv, 1)
else
scanfiles(argv, 0)
end if

if fclose(stdout) then
err(1, "stdout")
end if

exit(rval)
end function


Rewritten from https://github.com/freebsd/freebsd/blob/master/bin/cat/cat.c

Name: Anonymous 2014-12-03 19:21

>>41
C doesn't have function types, it has only pointers to functions which all have the same useless type (void *).

Oh and C in sexps would be awesome.

Name: Anonymous 2014-12-03 19:43

>>42
What happened to the semicolons?

Name: Anonymous 2014-12-03 20:14

>>43
which all have the same useless type (void *)
This is false, void * is a data pointer, not a function pointer. You can't point to a function with void *.

How are pointers to functions useless?

Name: Anonymous 2014-12-03 22:46

Name: Anonymous 2014-12-03 22:49

>>46
install gentoo

Name: Anonymous 2014-12-03 23:04

Try using ALGOL.

Name: Anonymous 2014-12-04 0:28

>>42
There's a good reason we don't write C like that: The English-style keywords are slower and use more memory than punctuation. Maybe you should stick to talking about dynamic languages where that kind of performance hit is deemed acceptable.

Name: Anonymous 2014-12-04 3:05

>>49
I think that English keywords to delimit structural blocks is as stupid as anyone else, but is performance really the way to make that argument? The difference between the resources used by each parser itself should be, like, nothing, compared to later compilation phases, and even less if you avoid the yacc/lex bloat.

Name: Anonymous 2014-12-04 6:56

>>49
No they don't. C is a compiled language, there are no English-style keywords in compiled C code.

Name: Anonymous 2014-12-04 7:35

>>51

no its interpreted language

POOP ME RONG G! POOP ME RONG!

Name: Anonymous 2014-12-04 8:14

>>52
it's actually a programming language.

Name: Anonymous 2014-12-04 12:02

>>53
And a very crappy one at that. No generics, extremely shitty macros, etc.

Name: Anonymous 2014-12-04 12:11

Only generic I need is a bit

Name: Anonymous 2014-12-04 12:12

>>54

Generics can be achieved with function pointers and void *.
Every other language has shitty macros.

Name: Anonymous 2014-12-04 12:17

>>56
Bullshit.

Name: Anonymous 2014-12-04 16:47

I will make a Sexpr-C that translates to C as a gift to >>1 even though I like C's syntax.
Just wait for it.

Name: Anonymous 2014-12-04 17:41

>>58
That would be great, thanks. C could really benefit from a s-exp syntax.

Name: Anonymous 2014-12-04 20:06

>>59
Okay. Here is what the new syntax will look like.

(preprocessor-include-file "stdio.h")

(int main (function-of (int argc) ((pointer-to (pointer-to 'char) argv))))
(begin)
(for-loop)
(begin)
(if-statement (< argc 2))
(begin)
(function-call puts "y")
(end)
(else-statement)
(begin)
(for-loop (int i 1) (< i argc) (++ i))
(begin)
(if-statement (> i 1))
(begin)
(function-call putchar #\space)
(end)
(function-call printf "%s" (array-get argv i))
(end)
(function-call putchar #\n)
(end)
(end)
(end)

Name: Anonymous 2014-12-04 20:18

>>60
I was actually wondering what should I use instead of * for pointers.

Name: Anonymous 2014-12-04 20:25

>>60

How would this look?

char *(*(*(**lol[]) (long double p[2], size_t n)) (int))[10] = { NULL, NULL };
printf("%d\n", (int) (sizeof lol / sizeof lol[0]));

Name: Anonymous 2014-12-04 20:28

>>61
maybe (* (+ argv i))

Name: Anonymous 2014-12-04 20:45

>>61
If you want to be serious and not a little shit like >>60? Something like:
(: p (ref int))
(deref p)

Name: Anonymous 2014-12-05 1:34

>>60
what's the point of using s-exprs if you're using being and end
this is a joke, right

Name: Anonymous 2014-12-05 1:45

>>56
you're mission: check these dub

Name: Anonymous 2014-12-05 2:46

>>65
Programming is never a joke.

Name: Anonymous 2014-12-05 3:49

>>66
Nice bro xD

Name: Anonymous 2014-12-05 5:42

>>54
Generics don't belong in C. Use void* and cast.

Name: Anonymous 2014-12-05 10:20

>>69
In other words, C is useless.

Name: Anonymous 2014-12-05 10:40

>>70
Generics are hardly perfect.

http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29#Covariant_arrays_in_Java_and_C.23

As discussed above, covariant arrays leads to problem with writes into the array. Java and C# deals with this by marking each array object with a type when it is created. Each time a value is stored into an array, the compiler inserts a check that the run-time type of the value is equal to the run-time type of the array. If there is a mismatch, an ArrayStoreException (or ArrayTypeMismatchException in C#) is thrown:

Runtime checks have no place in C.

Name: Anonymous 2014-12-05 10:42

>>71
No, it is subtyping that is highly imperfect. Not generics.

Name: Anonymous 2014-12-05 10:46

No, it is subtyping that is highly imperfect and requires runtime tag checks all the time.

is what I meant.

Name: Anonymous 2014-12-05 10:51

>>72
Wow, you're right. I'm sorry. Please use a term that doesn't remind me of java in the future. But still, although clean generics that don't break with no inheritance could be done in C, you end up messing around with casting so much it isn't that big of a deal to have a data structure consisting of a single type of values and to always cast when you access them. You can't take types too seriously in C. There's too much freedom.

Name: Anonymous 2014-12-05 10:57

>>74
So you're saying that C is like a Lisp without GC then, OK. Greenspun's tenth rule QED.

Name: Anonymous 2014-12-05 11:01

>>75
Greenspun's tenth rule is false. QED.

Name: Huskellfaggot 2014-12-05 11:04

>>75
I would say that lisp is an assembly language. Its core is simply and expressive, yet you can build things of near infinite complexity on top of it. C is the same way, except built upon a differnt assembly language. A real one instead of the lambda calculus. Also, much harder to build skyscrapers in.

Name: Anonymous 2014-12-05 11:57

>>77
assembly language
Assembly language is fast. LITHP is slow. Other than that, you're right. It is much harder to built skyscrapers in.

Name: Anonymous 2014-12-05 12:32

>>74
Since when does the word "generics" associate with Java? Educate yourself:

https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Generic_programming.html

Name: Anonymous 2014-12-05 12:34

Generic programming pioneer Alexander Stepanov wrote: "Generic programming is about abstracting and classifying algorithms and data structures. It gets its inspiration from Knuth and not from type theory. Its goal is the incremental construction of systematic catalogs of useful, efficient and abstract algorithms and data structures. Such an undertaking is still a dream."

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List