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

Pages: 1-

Critique for my code

Name: Anonymous 2012-12-21 10:06

Give your critique for this snippet, please.

How to improve aesthetics?


int prog (Directory *directory)
{
    int error = 0;

    Compile compile = { directory, null, null, null, null };

    if ((compile.file_depender = tree_new ()) == null)
        goto exception;
    if ((compile.topologics = list_doubly_create ()) == null)
        goto exception;
    if ((compile.dependers = list_singly_create ()) == null)
        goto exception;
    if ((compile.prog_files = list_singly_create ()) == null)
        goto exception;
    if (list_singly_foreach (directory->files, (Function)depender_create, &compile) != 0)
        goto exception;
    if (list_singly_foreach (compile.dependers, (Function)depender_link, &compile) != 0)
        goto exception;
    if (list_doubly_foreach (compile.topologics, (Function)topologic_sort, &compile) != 0)
        goto exception;

    compile.topologics->reverse = 1;

    if (list_doubly_foreach (compile.topologics, (Function)topologic_compile, &compile) != 0)
        goto exception;
    if (list_singly_count (compile.prog_files) == 0)
        goto exit;
    if (compile_app_link (&compile) != 0)
        goto exception;

    goto exit;
exception:
    error = 1;
exit:
    list_singly_foreach (compile.dependers, (Function)depender_destroy, null);
    list_singly_destroy (compile.dependers);
    list_doubly_foreach (compile.topologics, (Function)topologic_destroy, null);
    list_doubly_destroy (compile.topologics);
    list_singly_destroy (compile.prog_files);
    tree_destroy        (compile.file_depender);

    return error;
}


Thank you!

Name: Anonymous 2012-12-21 10:11

Do not use C-like languages

Name: Anonymous 2012-12-21 10:12

It's c

Name: Anonymous 2012-12-21 10:25

'0' and 'null' are for girls.

if (!(compile.file_depender = tree_new())) { open_your_anus(); }
if (list_doubly_foreach(blablahbaalah)) { close_your_anus(); }

Name: Anonymous 2012-12-21 10:31

>>4
okay, one star for you.

Name: Anonymous 2012-12-21 10:39

>>5
Fine. I'll make it kewler. Kewler names, kewl-dood hard tabs, and a kewler layout.


int prog (Directory *dir)
{
    Compile c = { dir, null, null, null, null };
    int error = 0;

    if (!(c.file_depender = tree_new())
     || !(c.topologics = list_doubly_create())
     || !(c.dependers = list_singly_create())
     || !(c.prog_files = list_singly_create())
     || list_singly_foreach(dir->files, (Function) depender_create, &c)
     || list_singly_foreach(c.dependers, (Function) depender_link, &c)
     || list_doubly_foreach(c.topologics, (Function) topologic_sort, &c)
     || (c.topologics->reverse = 1, list_doubly_foreach(c.topologics,
            (Function) topologic_compile, &c))) {
        error = 1;
        goto out;
    }
    if (!list_singly_count(c.prog_files))
        goto out;
    if (list_doubly_foreach(c.topologics, (Function) topologic_sort, &c))
        error = 1;
out:
    list_singly_foreach(c.dependers, (Function) depender_destroy, 0);
    list_singly_destroy(c.dependers);
    list_doubly_foreach(c.topologics, (Function) topologic_destroy, 0);
    list_doubly_destroy(c.topologics);
    list_singly_destroy(c.prog_files);
    tree_destroy(c.file_depender);
    return error;
}

Name: Anonymous 2012-12-21 10:40

Oh, the code tabs still turned the kewl-dood tabs into spaces. =/

Name: Anonymous 2012-12-21 10:43

Oh#2:

Compile c = { dir, 0, 0, 0, 0 };

Name: Anonymous 2012-12-21 10:47

Maybe split it up?

int try_compile(Compile *compile) {
    if ((compile->file_depender = tree_new()) == null)
        return 1;
    if ((compile->topologics = tree_new()) == null)
        return 1;
    if ((compile->dependers = list_singly_create()) == null)
        return 1;
    if ((compile->prog_files = list_singly_create()) == null)
        return 1;
    if (list_singly_foreach(compile->directory->files, (Function)depender_create, compile) != 0)
        return 1;
    if (list_singly_foreach(compile->dependers, (Function)depender_link, compile) != 0)
        return 1;
    if (list_doubly_foreach(compile->topologics, (Function)topologic_sort, compile) != 0)
        return 1;
       
    compile->topologics->reverse = 1;
   
    if (list_doubly_foreach(compile->topologics, (Function)topologic_compile, compile) != 0)
        return 1;
    if (list_singly_count(compile->prog_files) == 0)
        return 1;
    if (compile_app_link(compile) != 0)
        return 1;
       
    return 0;
}

int prog(Directory *directory)
{
    Compile compile = { directory, null, null, null, null };
    int error = try_compile(&compile);
   
    list_singly_foreach(compile.dependers, (Function)depender_destroy, null);
    list_singly_destroy(compile.dependers);
    list_doubly_foreach(compile.topologics, (Function)topologic_destroy, null);
    list_doubly_destroy(compile.topologics);
    list_singly_destroy(compile.prog_files);
    tree_destroy(compile.file_depender);

    return error;
}


(I haven't tested this.)

Name: Anonymous 2012-12-21 10:50

Round #3:

int prog (Directory *dir)
{
    Compile c = { dir, 0, 0, 0, 0 };
    int error;

    error = ((!(c.file_depender = tree_new())
      || !(c.topologics = list_doubly_create())
      || !(c.dependers = list_singly_create())
      || !(c.prog_files = list_singly_create())
      || list_singly_foreach(dir->files, (Function) depender_create, &c)
      || list_singly_foreach(c.dependers, (Function) depender_link, &c)
      || list_doubly_foreach(c.topologics, (Function) topologic_sort, &c)
      || (c.topologics->reverse = 1, list_doubly_foreach(c.topologics,
            (Function) topologic_compile, &c)))
      || (list_singly_count(c.prog_files)
     && list_doubly_foreach(c.topologics, (Function) topologic_sort, &c)));
    list_singly_foreach(c.dependers, (Function) depender_destroy, 0);
    list_singly_destroy(c.dependers);
    list_doubly_foreach(c.topologics, (Function) topologic_destroy, 0);
    list_doubly_destroy(c.topologics);
    list_singly_destroy(c.prog_files);
    tree_destroy(c.file_depender);
    return error;
}

Name: Anonymous 2012-12-21 11:04

>>6
Oh, of course, using one label is enough, good!
>>9
No goto at all, very clean.
>>10
Tight!

Thanks guys. Maybe I should skip singly linked list and just go for doubly and just use "list_".

Name: Anonymous 2012-12-21 11:06

>>11
Rawkk awwwwwnnnnnnn!!!!!!!!11111111111111

Name: Anonymous 2012-12-21 11:47

Name: Anonymous 2012-12-21 16:16

>>10
Exploitation of short circuit evaluation considered harmful but I do it all the time.

Name: Anonymous 2012-12-23 13:45

>>10
Looks like a heap of junk, I'd prefer >>1 over that. Remember that numero uno is being as eligible as possible. Aesthetics second. A bunch of other things, then lastly, impressing autists with valid yet idiotic hacks.

Name: Anonymous 2012-12-23 14:28

>>15
Only a See Programmer would see a new form of syntax as a hack. And within the realm of See you are write! As New Syntax is Hardly Supported! ANSI HS!

Name: Anonymous 2012-12-23 14:56

Only a Boo Programmer would see a new form of Boo as a Boo. And within the realm of Boo you are Boo! As New Boo is Hardly Boo! ANBI HB!

Name: Anonymous 2012-12-23 15:34

(Function) topologic_destroy_anus_lomom

Name: Anonymous 2012-12-23 18:17

Algol-like pseudocode:
using compile;
if yield true on allocation exception in
    file depender := tree new;
    topologics := tree new;
    dependers := list singly create;
    prog files := list singly create
dleiy
andth depender create within files of directory
andth depender link within dependers
andth topologic sort within topologics
then 1 else
    reverse of topologics := 1;
    0
thef topologic compile within topologics
andth length prog files = 0
andth compile app link(compile)
then 1 fi

Name: Anonymous 2012-12-23 19:36

>>15
> Remember that numero uno is being as eligible as possible.
Aesthetics second. A bunch of other things, then lastly,
impressing autists with valid yet idiotic hacks.

Looks like somebody's jealous 'cause he hasn't figured out the '&&', '||', and ',' operators yet.

Name: Anonymous 2012-12-23 22:13

Looks like a candidate for some try..catch.

Name: Anonymous 2012-12-24 1:00

>>21
C doesn't have them.  The usual idiom is to do something clever like >>10, or just give up and use goto to jump to the end of the function after setting an error code.

Name: Anonymous 2012-12-24 1:19

>>22
le smug lisp weenie face

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