bai gamit kaayo na nako ang GOTO bai kay awa ha...
Example:
Private Sub Form_load()
On error Goto Here
Adod1.recordsource = "select * from Tinfo where EmpId = '" & Text1.text & "' "
Adodc1.Refresh
Here: Exit Sub
End Sub
bai gamit kaayo na nako ang GOTO bai kay awa ha...
Example:
Private Sub Form_load()
On error Goto Here
Adod1.recordsource = "select * from Tinfo where EmpId = '" & Text1.text & "' "
Adodc1.Refresh
Here: Exit Sub
End Sub
Hehehehe... sa VB mana... syempre gamit jud diba...
How about in C/C++
kung ganahan ka makahibaw jud kun gunsa gamit ana ug kung ngano naay goto nga command..try ug download ug linux kernel source code(maski unsa nga version), then browse through the codes unya sabta..tan aw di ba daghan gamit ang goto
just because it's in linux kernel it doesnt mean it's useful and not avaoidable. They're humans pud baya.Originally Posted by zengatsu
well i think it is useful..i think the performance wouldnt be the same if they didnt use it..about sa usefulness sad diay niya bay, i dont think that functionality will be provided if it has no use at all..Originally Posted by gloryhunter
from gen_init_cpio.c:
static int cpio_mkfile(const char *name, const char *location,
unsigned int mode, uid_t uid, gid_t gid)
{
char s[256];
char *filebuf = NULL;
struct stat buf;
int file = -1;
int retval;
int rc = -1;
mode |= S_IFREG;
retval = stat (location, &buf);
if (retval) {
fprintf (stderr, "File %s could not be located\n", location);
goto error;
}
file = open (location, O_RDONLY);
if (file < 0) {
fprintf (stderr, "File %s could not be opened for reading\n", location);
goto error;
}
filebuf = malloc(buf.st_size);
if (!filebuf) {
fprintf (stderr, "out of memory\n");
goto error;
}
retval = read (file, filebuf, buf.st_size);
if (retval < 0) {
fprintf (stderr, "Can not read %s file\n", location);
goto error;
}
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
mode, /* mode */
(long) uid, /* uid */
(long) gid, /* gid */
1, /* nlink */
(long) buf.st_mtime, /* mtime */
(int) buf.st_size, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
(unsigned)strlen(name) + 1,/* namesize */
0); /* chksum */
push_hdr(s);
push_string(name);
push_pad();
fwrite(filebuf, buf.st_size, 1, stdout);
offset += buf.st_size;
push_pad();
rc = 0;
error:
if (filebuf) free(filebuf);
if (file >= 0) close(file);
return rc;
}
tan awa ninyo mga syo, i dont think ispagiti code na eh..depende ra na sa pag code bay uy..kung ma spaghetti imong code if mugamit ka ug goto, pasabot ana dili kamao or plain tapulan lang ka
Not a good code for me.. Just like you are coding in Visual Basic...Originally Posted by zengatsu
Maybe the developers are not good in software designing....
If that code will be reviewed together with the Senior Developers and Leaders, Im sure you get failed...
Maybe in assembly language, that is acceptable.....
That type of coding I think exists from 80's but currently since different coding standard and optimzation exist, that is not recommended.
@xyberblue: How would you recode that then? So that it would become a good code for you? oh and by the way, that for the 2.6.14 kernel..the latest stable build as of this post..so i dont think this is an 80s type of coding but if it is, i think 80s has a good style too
Mostly error trapping just issue a return type and issue an error message to the main functions. I think that's not best code to show that goto should take part. There something part in the kernel that is so difficult to return to the exact part of the program. The code above can be revised and not a good example of the usefulness of goto. Though I have not read all the code yet in kernel but I believe there is something there that goto is justifiable...Originally Posted by zengatsu
actually the sample code is doing exactly what you said..you know error trapping and return type..thing is, to make the code elegant for better performance, the goto part is needed..you cud actually rewrite it in a short circuit kind of way like you log a message if you find an error then return directly to the main function, but then freeing of the buffer and the closing of the file has to be included inside each of your if statements..or you cud enclose all the steps in separate if-else statements then check for errors and return types from previous statements before executing any of the following statement then finally return to the calling function, which wud be more work of the processor..this code is actually an efficient one and an elegant one at that
and its also an example of a code supporting the claim that using goto will not turn your code into ispagiti code..ill just post a sample of the codes youre looking for when i stumble upon such a code..im sure i will..im tinkering with the kernel right now..tuon2 lang..heheheh..till then, peace mga bro!!!
Similar Threads |
|