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

Languages with GOTO

Name: suomynonA 2007-07-17 12:49 ID:sJhm9IHJ

Is there a modern programming language which has GOTO function in it? I know basic from a millenia ago and recently learned java, and well I hated OOP, but I could live with it if I had goto.

Name: Anonymous 2007-07-17 13:19 ID:OLxRAl5o

If you want to be succesful in programing, DONT USE GOTO
It makes hard to manage spigetti code.  Just learn a real language. and no, java dosnt have goto.

Name: Anonymous 2007-07-17 13:20 ID:Hlzkdp1E

You can use goto in Python. It's considered very pythonic and is a recommended best practice.

http://entrian.com/goto/

Name: Anonymous 2007-07-17 13:55 ID:iAfpsAX4

C++ has goto.

Name: Anonymous 2007-07-17 13:55 ID:+EkgJc4r

Most modern programming languages have goto, they just spell it T-H-R-O-W.

Name: Anonymous 2007-07-17 14:34 ID:7UcD/Lgu

>>5
Lol Truth.

Name: Anonymous 2007-07-17 14:44 ID:7SUedsqK

>>1
Goto is useful, but not for what you want to do.

java, and well I hated OOP
Of course. Java has the poorest object system I know.

I could live with it if I had goto.
WTF, what would you do with it?

If you want to be succesful in programing, DONT USE GOTO
Except if you use it in the form of tail calls, exceptions, or break/continue, for example.

>>3
Witty.

Name: Anonymous 2007-07-17 16:00 ID:4hlbAvg8

PHP 6 has throw and goto!

Name: Anonymous 2007-07-17 16:27 ID:2+WK9M+7

>>2
It's even harder to read deeply indented code.

Java has goto, it's called break with a label.

Name: Anonymous 2007-07-17 16:35 ID:7SUedsqK

>>9
Don't tell him. Break with a label is one of the features that are useful, but not in the cases most programmers will want to use them. I'd allow break with label and goto, but in order to use them you'd have to declare:

#define _EXPERT_PROGRAMMER_

Name: Anonymous 2007-07-17 16:45 ID:qDjd3K0y

GOTO CONSIDERED DANGEROUS

Name: Anonymous 2007-07-17 16:52 ID:jg6dahoJ

>>7
Except if you use it in the form of tail calls, exceptions, or break/continue, for example.

thats not GOTO

Name: Anonymous 2007-07-17 16:54 ID:7SUedsqK

99.9% of the times goto has been used in the last 15 years, it has been misused. As for the 0.1% of the times where it was actually a good idea, none of the programmers who like to use goto would understand why.

In the past 4 years working in this business, I found goto useful for two times.

Name: Anonymous 2007-07-17 17:45 ID:Heaven

int main(){
 int n=arc4random();
 return a(n);
}

int a(int n){ return b(n-1); }
int b(int n){ return n?a(n):n; }

Name: Anonymous 2007-07-17 18:36 ID:UU5Eg94T

>>13
Only four years? You've got a lot to learn, junior.

Name: Anonymous 2007-07-17 19:08 ID:7SUedsqK

>>15
Professionally.

Name: Anonymous 2007-07-18 6:58 ID:lvf9nY4G

Name: Anonymous 2007-07-18 7:52 ID:WkIT+GGo

>>13
Agree. I've only used goto about 3 times in C++, two of those were out of pure laziness and the other one was an optimisation for speed critical code. The alternative for the third one would have been much worse.

Name: Anonymous 2007-07-18 19:14 ID:FkSXquQU

common lisp is what you want. A real, flexible object system, imperative and functional programming, logic, and macros. And it has goto!

Name: Anonymous 2007-07-18 19:22 ID:+9nzGV6v

>>14

(lambda (lambda x (lambda x (lambda x x) (lambda x (lambda (lambda x x) (lambda (lambda x (lambda x x) x) ) (lambda x x) lambda x) x )))

Does the same but is EXPERT PROGRAMMATION and is O(ln(ln(ln(ln(ln(ln(x ln(x)))))))).

True EXPERT PROGRAMMERS who've read SICP know that goto is unneccesary to construct an arbitrary program.

Name: Anonymous 2007-07-19 3:19 ID:eQovlAaX

>>20
I AM A CHAMPION PROGRAMMER, I HAVE READ K&R BECAUSE SICP IS A BEGINNER BOOK

Name: Anonymous 2007-07-19 4:58 ID:UjVITlR4

Any language with an inline assembler will allow you.  Just chuck in a label and a JMP instruction.  Then spend your life debugging.

Name: Anonymous 2007-07-19 5:14 ID:VK3c3dVw

Lambda, the ultimate goto

Name: Anonymous 2007-07-19 7:17 ID:QBsD/4JS

>>21
NO I DON'T GET THE IDEA BECAUSE YOUR CODE IS POORLY FORMATTED AND POOL-STILL-AIDS IS NOT USED, YOU DIDN'T TEST YOUR CODE, YOU ARE NOT AN EXPERT PROGRAMMER, YOU CAN'T USE IRC WELL, YOU CAN'T TAB COMPLETE, AND YOU CAN'T GOOGLE WHICH MEANS YOU'RE PROBABLY TOO BUSY JERKING OFF OR PLAYING VIDEO GAMES, DIE WELL, KID.

Name: Anonymous 2007-07-19 11:47 ID:84V+rEu/

Problem:
You have a function that does something, and in some cases it fails to do it, and there are some actions that need to be done after it failed.
I don't want to copy/paste code many times, and writing another function that handles the situation is out of question (writing #defines, too).
Solution: gotos. And i don't see any other solutions (in c, at least, and c++'s fancy throw/catch are the same thing as >>5 said). This is used alot in linux kernel.

Name: Anonymous 2007-07-19 12:16 ID:Heaven

>>25
int failed=do_something();
if(failed){
 do_some_shit();
 do_more_shit();
}

Name: Anonymous 2007-07-19 14:13 ID:84V+rEu/

>>26
you mean this, yes?

int a(void){
int failed=do_something();
if(failed){
 do_some_shit();
 do_more_shit();
}
return 0;
}

int b(void){
int failed=do_something();
if(failed){
 do_some_shit();
 do_more_shit();
}
return 1;
}

int b(void){
int failed=do_something();
if(failed){
 do_some_shit();
 do_more_shit();
}
return 2;
}

great solution, really.

Name: Anonymous 2007-07-19 14:39 ID:QBsD/4JS

goto is good for freeing things up in C on error.

int alloc_some_things()
{
  T *foo = malloc(sizeof(*foo));
  if (foo != NULL)
  {
     foo->member = malloc(sizeof(*foo->member));
     if (foo->member != NULL)
     {
         foo->another = malloc(sizeof(*foo->another));
         if (foo->another != NULL)
         {
             return foo;
         } else goto free_member;
     }  else goto free_foo;
  } else goto failure;
  free_member: free(foo->member);
  free_foo: free(foo);

  failure:
  return NULL;
}

Name: Anonymous 2007-07-19 14:41 ID:QBsD/4JS

>>28
Although that *does* depend on how you want to deal with it. You could of course just use assert(foo = malloc(sizeof *foo)); and that will abort() on failure, but you probably don't want to do that in a library.

Name: Anonymous 2007-07-19 16:03 ID:bKSfkdkf

>>28
LOL, very well put.

Name: Anonymous 2007-07-19 16:11 ID:bKSfkdkf

>>28

1) Learn C
2) Learn to write functions
3) Learn that GOTO is fucking useless

heres a better version of that code which doesn't use goto.
its shorter and easier to understand and modify.
You are a dumb fuck.


int alloc_some_things() { // this should be T but other poster is a fucking goto using idiot.
  T * foo;
 
  foo = malloc(sizeof(*foo));
  if(foo) {
    foo->member = malloc(sizeof(*foo->member));
    if(foo->member) {
      foo->another = malloc(sizeof(*foo->another));
      if(foo->another) {
    return foo; // THANK GOD WE ALLOCATED STUFF
      }
      free(foo->member);
    }
    free(foo);
  }
 
  return NULL; // learn C you fucking idiot.
}

Name: Anonymous 2007-07-19 19:53 ID:8wGLwsNB

int alloc_some_things() {
  T* foo;
  void* member;
  void* another;
  foo = malloc(sizeof(*foo));
  member = malloc(sizeof(*foo->member));
  another = malloc(sizeof(*foo->another);
  if(foo && member && another)
  {
     foo->member = member;
     foo->another = another;
  }
  else
  {
     free(foo); // free is ok on NULL
     free(member); // free is ok on NULL
     free(another); // free is ok on NULL
  }
  return NULL;
}

or, if you like some wild macro action:

#define RETURNFREE(val) freevec(autofree); return val

int alloc_some_things() {
  T* foo;
  void* member;
  void* another;
  void* autofree[] = {foo, member, another};
  foo = malloc(sizeof(*foo));
  member = malloc(sizeof(*foo->member));
  another = malloc(sizeof(*foo->another);
  if(BIG NESTED STUFF)
  {
........ ok ? then return
  }
  else
....
  {
    RETURNFREE
  }
  another big nesst.....

   RETURNFREE! AGAIN YOU DONT HAVE TO REWRITE THE CODE
  return NULL;
}

NOTE: I don't guarantee compilation on these code examples.
NOTE2: you can do this better with nested procedures, which the gnu extensions to C allow.

Name: Anonymous 2007-07-19 20:07 ID:bKSfkdkf

>>32
your first codepaste is an OK idea but I personally hate this style for the obvious reasons, in particular its not semantically equivalent to the original faggot.

Name: Anonymous 2007-07-19 20:38 ID:QBsD/4JS

>>31
sometimes it is not as simple as that, which is where goto has use. clearly my example did not communicate that to you. shrug

Name: Anonymous 2007-07-19 20:43 ID:QBsD/4JS

the funny thing is I never actually use goto and write it like >>31, but goto has its use where it is the least horrible thing to use for a given problem, like everything else. that's all I have left to say

Name: Anonymous 2007-07-19 22:39 ID:bKSfkdkf

>>34
that what ALL goto using faggots say to me, none of them can EVER produce an actual example of where goto is better.
MY CONCLUSION: GOTO FUCKING SUCKS DONT USE IT.

Name: Anonymous 2007-07-19 23:09 ID:Heaven

>>27
no.

Name: Anonymous 2007-07-19 23:11 ID:0hO7/Wyv

klibc, vsnprintf.c:

                switch (ch) {
                case 'P':    /* Upper case pointer */
                    flags |= FL_UPPER;
                    /* fall through */
                case 'p':    /* Pointer */
                    base = 16;
                    prec = (CHAR_BIT*sizeof(void *)+3)/4;
                    flags |= FL_HASH;
                    val = (uintmax_t)(uintptr_t)
                        va_arg(ap, void *);
                    goto is_integer;

                case 'd':    /* Signed decimal output */
                case 'i':
                    base = 10;
                    flags |= FL_SIGNED;

[...]

                    /* fall through */
                case 'x':    /* Hexadecimal */
                    base = 16;
                    goto is_unsigned;

                is_unsigned:
                    switch (rank) {
                    case rank_char:
                        val = (uintmax_t)
                            (unsigned char)
                            va_arg(ap, unsigned
                                   int);
                        break;

Name: Anonymous 2007-07-19 23:21 ID:QBsD/4JS

>>36
argumentum ad logicam etc

Name: Anonymous 2007-07-19 23:24 ID:0hO7/Wyv

Also read this: http://kerneltrap.org/node/553/2131

tl;dr:
>dealing with error situations that don't happen very often, in such a way that the error handling code doesn't clutter up the main code path.

>No, you've been brainwashed by CS people who thought that Niklaus Wirth actually knew what he was talking about. He didn't. He doesn't have a frigging clue.

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