I just started looking at Scala, anyone care to point me to some good tutorials? It seems like an interesting language.
functional languages are always a good learn, and will make you look at programming in a totally different light. MIT's first CompSci course is completely in LISP
you should be able to:
* get around in C - pure procedural, but the basis of everything (and learn when goto's are appropriate. seriously, they are not evil)
* know an OO language, and how OO works. C++ preferably, but java and c# count, i guess.
* know functional programming basics
* know how to write every program as a finite state machine
* know how to make C very C++ like
* learn high-level script languages i.e. python, and come to the realization that engineering time is expensive, and that we can always throw more hardware at it
* know your gang of 4 book inside and out.
* learn ugly scripting languages like bash
I can't take you seriously with the goto statement. If you require a goto then it suggests your design is horrible. I cannot think of any single instance were a goto would be acceptable.
Multiple nested loop control
Common cleanup code
Any and all uses of longjmp (which is just goto on steroids)
HalibutPassion FishSwimming in obscurity.Registered Userregular
edited October 2010
I can't think of a single instance in my professional career where a goto was appropriate. Maybe because I don't write apps in assembly or C/C++? That's not to say that my particular sliver of the spectrum of development jobs is the same as everyone else's.
Actually I guess I use them all the time in batch scripts, but that's just because there's no other looping/jumping construct in Windows batch scripts.
Actually I guess I use them all the time in batch scripts, but that's just because there's no other looping/jumping construct in Windows batch scripts.
Just like it's necessary there, you have places where it's appropriate in other languages or areas.
You don't do work in those, that's all.
I use GCC a lot. I've patched in features for it. GCC uses goto.
Machine language uses goto all the time, the higher up in abstraction you are the less you see of it. It's always there though, lurking.
Machine language hardly counts though since it has nothing but gotos and all high level control abstractions are transformed to goto based for implementation
Machine language hardly counts though since it has nothing but gotos and all high level control abstractions are transformed to goto based for implementation
I'm confused, you say hardly counts but then agree with me.
Infidel on
0
Options
HalibutPassion FishSwimming in obscurity.Registered Userregular
Actually I guess I use them all the time in batch scripts, but that's just because there's no other looping/jumping construct in Windows batch scripts.
Just like it's necessary there, you have places where it's appropriate in other languages or areas.
You don't do work in those, that's all.
I use GCC a lot. I've patched in features for it. GCC uses goto.
Machine language uses goto all the time, the higher up in abstraction you are the less you see of it. It's always there though, lurking.
Yeah, I've programmed in assembly where the jump instruction is basically goto, but nothing professionally.
I guess my lack of a need for goto stems from my aversion to low-level languages. I guess I just don't want to do the kind of work that requires it, so I've never needed it.
I would probably take issue with anyone who uses goto in a Java application. Even if goto is the quick and dirty way to get something done, it's probably also the least maintainable way, so it's a good idea to remember that far more time is spent maintaining code than writing it.
I would consider goto on the same level as a highly-nested ternary operator expression. It seems like a good idea at the time, but a month from now you're spending twice as much time figuring out what the hell that code does.
I can't think of a single instance in my professional career where a goto was appropriate. Maybe because I don't write apps in assembly or C/C++? That's not to say that my particular sliver of the spectrum of development jobs is the same as everyone else's.
Actually I guess I use them all the time in batch scripts, but that's just because there's no other looping/jumping construct in Windows batch scripts.
The only time I've considered a goto was in a thrice(+) deep nested loop. I simply redesigned my logic because that was silly anyways.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
hey, I'm having some problems with regular expressions in c#
I'm trying to extract information from a html page
string html;
//webstuff here
//the string html contains a whole html page now, verified.
Regex rx = new Regex("<tbody class=\"result\">(.*)</tbody>");
//trying to get the stuff in between <tbody class="result"> and </tbody>
MatchCollection matches = rx.Matches(html);
foreach (Match match in matches)
{
string htmlInner = match.Groups[1].Value;
textBox.AppendText(htmlinner);
}
now my problem is.. the textbox never contains anything
I am surely doing something wrong, as this is basically my first foray into c# AND regular expressions.. but what?
hey, I'm having some problems with regular expressions in c#
I'm trying to extract information from a html page
string html;
//webstuff here
//the string html contains a whole html page now, verified.
Regex rx = new Regex("<tbody class=\"result\">(.*)</tbody>");
//trying to get the stuff in between <tbody class="result"> and </tbody>
MatchCollection matches = rx.Matches(html);
foreach (Match match in matches)
{
string htmlInner = match.Groups[1].Value;
textBox.AppendText(htmlinner);
}
now my problem is.. the textbox never contains anything
I am surely doing something wrong, as this is basically my first foray into c# AND regular expressions.. but what?
There are two things involved when you have content with newlines in them. First, the ^ and $ beginning/end of line markers work on the whole string, but can find true lines based on newlines if you enable Multiline mode, and then there is whether the . character takes all characters except newlines or accepts every character including them by enabling Singleline.
There are two things involved when you have content with newlines in them. First, the ^ and $ beginning/end of line markers work on the whole string, but can find true lines based on newlines if you enable Multiline mode, and then there is whether the . character takes all characters except newlines or accepts every character including them by enabling Singleline.
Your content most likely has newlines right?
You should probably also use the IgnoreCase option when parsing HTML tags, although that's almost certainly not what's causing the failure.
There are two things involved when you have content with newlines in them. First, the ^ and $ beginning/end of line markers work on the whole string, but can find true lines based on newlines if you enable Multiline mode, and then there is whether the . character takes all characters except newlines or accepts every character including them by enabling Singleline.
Your content most likely has newlines right?
The pattern I want to extract? Yeah it does, I'll try that.
Thanks!
Machine language hardly counts though since it has nothing but gotos and all high level control abstractions are transformed to goto based for implementation
I'm confused, you say hardly counts but then agree with me.
Well it's comparing a high level language to machine code. Your only control structures are limited versions of call and return plus (un)conditional goto
Machine language hardly counts though since it has nothing but gotos and all high level control abstractions are transformed to goto based for implementation
I'm confused, you say hardly counts but then agree with me.
Well it's comparing a high level language to machine code. Your only control structures are limited versions of call and return plus (un)conditional goto
Yes, which is precisely my point in that "the higher up in abstraction you are, the less you'll see or need goto."
Pointing out the bottom end is just demonstrating that.
Hey, it was " RegexOptions.Singleline", btw. Many thanks
Yeah, your C# is fine, that's a Regex specific issue just so you're aware. You'd see this in any other language using regex for the most part, although I like using the perl-style format for these things. (Adding "i" for case insensitivity, "s" for singleline, etc.)
Singleline is a bad name for what it really does, and many point out / bitch about it.
I can't take you seriously with the goto statement. If you require a goto then it suggests your design is horrible. I cannot think of any single instance were a goto would be acceptable.
goto is invaluable in any language (like C) that requires the programmer to manually free memory, file handles, or other resources. Anybody who mindlessly avoids goto (probably because they misunderstood Dijkstra's essay) is practicing cargo-cult programming.
For example, how would you rewrite this code without using goto? Which version do you believe is more readable?
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if ((a = fopen("a.txt", "rb")) == NULL)
goto error;
if ((b = fopen("b.txt", "rb")) == NULL)
goto error;
if ((c = fopen("c.txt", "wb")) == NULL)
goto error;
if ((buf = malloc(1024*sizeof(uint16_t))) == NULL)
goto error;
/* do something (eg, three-way merge) with a, b, c, and buf */
goto cleanup;
error:
rc = 1;
cleanup:
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
I can't take you seriously with the goto statement. If you require a goto then it suggests your design is horrible. I cannot think of any single instance were a goto would be acceptable.
goto is invaluable in any language (like C) that requires the programmer to manually free memory, file handles, or other resources. Anybody who mindlessly avoids goto (probably because they misunderstood Dijkstra's essay) is practicing cargo-cult programming.
For example, how would you rewrite this code without using goto? Which version do you believe is more readable?
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if ((a = fopen("a.txt", "rb")) == NULL)
goto error;
if ((b = fopen("b.txt", "rb")) == NULL)
goto error;
if ((c = fopen("c.txt", "wb")) == NULL)
goto error;
if ((buf = malloc(1024*sizeof(uint16_t))) == NULL)
goto error;
/* do something (eg, three-way merge) with a, b, c, and buf */
goto cleanup;
error:
rc = 1;
cleanup:
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if (!openFile("a.txt", "rb", a))
rc = 1;
if (!openFile("b.txt", "rb", b))
rc = 1;
if (!openFile("c.txt", "wb", c))
rc = 1;
if (!alloc3WayMergeBuffer(buf))
rc = 1;
if(rc == 0)
{
/* do something (eg, three-way merge) with a, b, c, and buf */
}
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
}
int openFile(char* file, char* arg, FILE *f) {
int rc = 0;
if ((f = fopen(file, arg)) == NULL)
rc = 1;
return rc;
}
int alloc3wayMergeBuffer(uint16_t *buf) {
int rc = 0;
if ((buf = malloc(1024*sizeof(uint16_t))) == NULL)
rc = 1;
return rc;
}
I don't do C but I believe something like that would work. You could also give better error handling by providing the user with more information about any access issues. The user won't have to deal with running it 3 times to find out the first time a.txt doesn't exist, then b.txt, then c.txt. You could gather all of those errors in one go and provide the details needed in one shot.
I don't really like how large the some_procedure is, it can be re-factored into something nicer but I don't want to spend too much time.
I can't take you seriously with the goto statement. If you require a goto then it suggests your design is horrible. I cannot think of any single instance were a goto would be acceptable.
goto is invaluable in any language (like C) that requires the programmer to manually free memory, file handles, or other resources. Anybody who mindlessly avoids goto (probably because they misunderstood Dijkstra's essay) is practicing cargo-cult programming.
For example, how would you rewrite this code without using goto? Which version do you believe is more readable?
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if ((a = fopen("a.txt", "rb")) == NULL)
goto error;
if ((b = fopen("b.txt", "rb")) == NULL)
goto error;
if ((c = fopen("c.txt", "wb")) == NULL)
goto error;
if ((buf = malloc(1024*sizeof(uint16_t))) == NULL)
goto error;
/* do something (eg, three-way merge) with a, b, c, and buf */
goto cleanup;
error:
rc = 1;
cleanup:
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
For that particular example, I'd consider something like:
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if(
(a = fopen("a.txt", "rb"))
&&
(b = fopen("b.txt", "rb"))
&&
(c = fopen("c.txt", "wb"))
&&
(buf = malloc(1024*sizeof(uint16_t)))
)
{
// a, b, c, and buf are now all valid
// do something
}
else
rc = 1;
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
}
[strike]Edit: Sorry Lux, C is pass by value, not pass by reference. openFile() would need to be modified slightly to accept a FILE**, I believe.[/strike]
Edit2: Ah, nevermind. Finally read the bottom of your post.
I gave it some more thought and I don't do work that requires me to save every possible cycle I can. In such a situation there could be a good reason for a goto. However I still think, even then, that they should be avoided nearly every single time you think of using one. There are surely better ways to save cycles and keep easily readable code then using goto at risk of creating some spaghetti code.
I can't take you seriously with the goto statement. If you require a goto then it suggests your design is horrible. I cannot think of any single instance were a goto would be acceptable.
Look through the Linux Kernel source code tree. It's a perfectly acceptable flow control statement. Just grep for "goto". Also grep for "fuck" for entertainment.
Off the top of my head -
Clarifying a large nested tree of if-the-else where the purpose of the else is to abort the following actions if any of the if tests fail.
so you would have a bunch of
if (test) {
statements;
} else {
goto fail;
}
it clears readability by a ton.
When you are initializing a device/process that requires multiple steps to be wound in order, and unwound in the opposite order, making sure that you don't execute the unwinding steps to anything that wasn't initialized - the resulting code using is far clearer and more terse.
Another is the loop and a half, often necessary for parsing strings.
The Dijkstra paper has, over time, done more harm than good, because people take the general message of "GOTO IS BAD", but without the nuance which Dijkstra presented it. Go read the paper, its available online freely, and you'll find that the message was more that goto's are harmful in the hands of programmers who didn't have a grasp of what they were doing, but are still useful in many circumstances.
A long time ago, there was a discussion on goto's on LKML, where Linus, in his usual brusque tone, talked about the use of goto's throughout the kernel.
(I've also got a really good flame mail from Linus about his opinion on the Gnome project from [Desktop_Architects], but that one, we'll save for another time)
int some_procedure()
{
FILE *a = NULL, *b = NULL, *c = NULL;
uint16_t *buf = NULL;
int rc = 0;
if (!openFile("a.txt", "rb", a))
rc = 1;
if (!openFile("b.txt", "rb", b))
rc = 1;
if (!openFile("c.txt", "wb", c))
rc = 1;
if (!alloc3WayMergeBuffer(buf))
rc = 1;
if(rc == 0)
{
/* do something (eg, three-way merge) with a, b, c, and buf */
}
free(buf);
if (c) fclose(c);
if (b) fclose(b);
if (a) fclose(a);
return rc;
}
I don't do C but I believe something like that would work. You could also give better error handling by providing the user with more information about any access issues. The user won't have to deal with running it 3 times to find out the first time a.txt doesn't exist, then b.txt, then c.txt. You could gather all of those errors in one go and provide the details needed in one shot.
I don't really like how large the some_procedure is, it can be re-factored into something nicer but I don't want to spend too much time.
Those initial if's should all be checking rc too:
if (!rc && !openFile("b.txt", "rb", b))
rc = 1;
There's no point opening the other files or allocating the buffer if you already know the procedure is going to fail. Which is the real point of the goto idiom Janin mentioned -- you always know at each line that all the previous operations have succeeded, and so there's no chance that anyone will forget to check a failure flag (and eventually, someone will forget). It's the same school of thought that says it's better to allow early returns due to failures than to doggedly enforce a "one exit-point only" approach (the main advantage of using goto here is that it lets you re-use the clean-up code).
Programming-related hypothetical: Would you do someone else's homework for money?
Background: Surfing "gigs" on Craigslist I found a posting asking for someone to complete some short, easy VB projects. I figured I could use a few bucks and sent an email asking what they entailed so I could quote accordingly.
What I got emailed back are pdfs of what are clearly homework assignments, to the point that they're labeled "Chapter 3" and "Chapter 5", etc. They're simple enough and I could knock them out in a few hours.
My wife's of the opinion that A) we could use the money and if he cheats his way through school he's only hurting himself. I'm hesitant, because... well... it's cheating. Even if I'm not the doing the cheating (I've been done with school for years), I'm helping someone else cheat.
I say don't do it. Maybe contact him and see about setting up tutoring sessions instead? That's a long shot, though.
Tamin on
0
Options
HalibutPassion FishSwimming in obscurity.Registered Userregular
edited October 2010
If the dude is obviously trying to cheat, then I wouldn't do it. And in this case he is obviously trying to cheat. Why else would you pay someone money for a few small (and I'm assuming) useless VB projects?
Not that I'm trying to be your internet conscience or anything. BTW, how much money are we talking here?
Halibut on
0
Options
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited October 2010
As I understand it, it's one thing to use goto, it's another thing entirely to base your software's flow structure around it. With one you just have to exercise caution. With another you're just plain doing it wrong.
The plugins in my practicum class enforce single return at end. It's a pain. I mean I understand it's more efficient, but damn.
Actually a lot of things they enforce are a pain.
I'm taking is as practice for real jobs, where you get told to do silly thing all the time. At least that was my experience delivering pizza.
I certainly hope the cheating guy isn't a CS major. Otherwise he's going to have a hard time cheating his way into a paycheck.
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
If the dude is obviously trying to cheat, then I wouldn't do it. And in this case he is obviously trying to cheat. Why else would you pay someone money for a few small (and I'm assuming) useless VB projects?
Not that I'm trying to be your internet conscience or anything. BTW, how much money are we talking here?
I was going to quote him based on the programs, and then he sent them to me and I saw they were homework assignments. Each would probably take less than an hour so I was thinking $25 per, but if he's in high school or college he probably can't afford that.
In any case, I responded with "Sorry, I don't feel comfortable doing someone's homework for them."
As I understand it, it's one thing to use goto, it's another thing entirely to base your software's flow structure around it. With one you just have to exercise caution. With another you're just plain doing it wrong.
The plugins in my practicum class enforce single return at end. It's a pain. I mean I understand it's more efficient, but damn.
Actually a lot of things they enforce are a pain.
I'm taking is as practice for real jobs, where you get told to do silly thing all the time. At least that was my experience delivering pizza.
I certainly hope the cheating guy isn't a CS major. Otherwise he's going to have a hard time cheating his way into a paycheck.
when i started the goto conversation, I only included it as something you NEED to know with C. It's also an interview question that I ask all the time - "When is it appropriate to use a goto". If they answer "never", I have a chance to see how teachable the candidate is. If they answer correctly, I know they have a deeper understanding of programming, and are probably on the more advanced side.
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based. Second, they enforce weird and harmful arbitrary rules, like no goto, single returns, ridiculous amounts of commenting, etc etc etc.
There is a huge disconnect between academia and industry in CS. I've said this before, I wish there was a PE-like cert for software engineers, that didn't include how to make a steam engine run, but tested for actual software-related problem solving skills, and a rounded knowledge of languages, concepts, etc. (Ansi-ish) C, C++, and a functional would be a minimum.
There is a huge disconnect between academia and industry in CS. I've said this before, I wish there was a PE-like cert for software engineers, that didn't include how to make a steam engine run, but tested for actual software-related problem solving skills, and a rounded knowledge of languages, concepts, etc. (Ansi-ish) C, C++, and a functional would be a minimum.
I've said it before here that we should have a professional organization and responsibility, and some people think I'm crazy. :P There are plenty of places where this is necessary imo, and those places usually have to organize their own regulations and such. (medical, military, government, etc.) Some kind of unification under a profession would be nice, since there are a lot of jobs that could go to more competent people for more money.
Infidel on
0
Options
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
I think the most team work I did in school was for controlling a 3 axis mechanical arm. We wrote up a protocol so we can talk to each other over an ethernet cable. One was written in C on the arm, the other piece of software on a windows PC in C#. We didn't do much in terms of multiple people working on the same piece of software however.
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
By far the most valuable course I ever did at university was a year long software engineering project. No lectures, the class is split into groups of ~6, and the lecturers act as 'customers', which you need to book meetings with to request feedback for your product so far and get your user stories checked off. We had one lecturer that would constantly change his mind on everything, and kept requesting/suggesting new features which we'd scramble to work in for him. We hated his bullshit so much, but in hindsight, he was just acting like customers do in the real world.
exis on
0
Options
HalibutPassion FishSwimming in obscurity.Registered Userregular
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
By far the most valuable course I ever did at university was a year long software engineering project. No lectures, the class is split into groups of ~6, and the lecturers act as 'customers', which you need to book meetings with to request feedback for your product so far and get your user stories checked off. We had one lecturer that would constantly change his mind on everything, and kept requesting/suggesting new features which we'd scramble to work in for him. We hated his bullshit so much, but in hindsight, he was just acting like customers do in the real world.
Did you guys follow any kind of agile methodology? Your use of "User Stories" instead of "Use Cases" and also the iterative feedback from your customers/lecturers is what is prompting the question.
Regardless, it sounds like a good class. I didn't learn anything about team project management until I graduated and got a job.
Halibut on
0
Options
Sir CarcassI have been shown the end of my worldRound Rock, TXRegistered Userregular
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
By far the most valuable course I ever did at university was a year long software engineering project. No lectures, the class is split into groups of ~6, and the lecturers act as 'customers', which you need to book meetings with to request feedback for your product so far and get your user stories checked off. We had one lecturer that would constantly change his mind on everything, and kept requesting/suggesting new features which we'd scramble to work in for him. We hated his bullshit so much, but in hindsight, he was just acting like customers do in the real world.
In my CS program there was a "Software Engineering" class and a "Software Engineering Project" class. I took the SE class during the summer, so we didn't get to do too much actual coding, but in the SE Project class we split up into groups of 5 or 6 and each had to write and develop a PalmOS application. It was a pretty fun class.
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
By far the most valuable course I ever did at university was a year long software engineering project. No lectures, the class is split into groups of ~6, and the lecturers act as 'customers', which you need to book meetings with to request feedback for your product so far and get your user stories checked off. We had one lecturer that would constantly change his mind on everything, and kept requesting/suggesting new features which we'd scramble to work in for him. We hated his bullshit so much, but in hindsight, he was just acting like customers do in the real world.
Did you guys follow any kind of agile methodology? Your use of "User Stories" instead of "Use Cases" and also the iterative feedback from your customers/lecturers is what is prompting the question.
Regardless, it sounds like a good class. I didn't learn anything about team project management until I graduated and got a job.
Yep, the recommended methodology was extreme programming. Which worked quite well with the course, since the lecturers could outline a broad problem and give feedback throughout the year, giving students a chance to continually iterate in response.
The guy who ran the course told me that he'd gotten the idea from a SE lecturer at another university, who ran a similar course but would grade at random intervals throughout the year, giving students 24 hours notice that their deliverable was due. Apparently this was deemed a little too harsh, though I can see the merit if it encourages students to actually use an agile process.
exis on
0
Options
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
edited October 2010
I'm so sorry, but I can't see the words "extreme programming" and not think of something like this:
Monkey Ball Warrior on
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
0
Options
grouch993Both a man and a numberRegistered Userregular
edited October 2010
C++ question.
Someone is advocating the declaration of temporary variables in class headers. The stated reason is to avoid the resource hit of creating and destroying objects. This is in a large scale embedded platform. Anyone care to comment on the validity of doing so?
Have some thoughts myself, but wanted to see what others thought.
Posts
Multiple nested loop control
Common cleanup code
Any and all uses of longjmp (which is just goto on steroids)
Actually I guess I use them all the time in batch scripts, but that's just because there's no other looping/jumping construct in Windows batch scripts.
Just like it's necessary there, you have places where it's appropriate in other languages or areas.
You don't do work in those, that's all.
I use GCC a lot. I've patched in features for it. GCC uses goto.
Machine language uses goto all the time, the higher up in abstraction you are the less you see of it. It's always there though, lurking.
I'm confused, you say hardly counts but then agree with me.
Yeah, I've programmed in assembly where the jump instruction is basically goto, but nothing professionally.
I guess my lack of a need for goto stems from my aversion to low-level languages. I guess I just don't want to do the kind of work that requires it, so I've never needed it.
I would probably take issue with anyone who uses goto in a Java application. Even if goto is the quick and dirty way to get something done, it's probably also the least maintainable way, so it's a good idea to remember that far more time is spent maintaining code than writing it.
I would consider goto on the same level as a highly-nested ternary operator expression. It seems like a good idea at the time, but a month from now you're spending twice as much time figuring out what the hell that code does.
The only time I've considered a goto was in a thrice(+) deep nested loop. I simply redesigned my logic because that was silly anyways.
I'm trying to extract information from a html page now my problem is.. the textbox never contains anything
I am surely doing something wrong, as this is basically my first foray into c# AND regular expressions.. but what?
Try the Multiline regex option.
There are two things involved when you have content with newlines in them. First, the ^ and $ beginning/end of line markers work on the whole string, but can find true lines based on newlines if you enable Multiline mode, and then there is whether the . character takes all characters except newlines or accepts every character including them by enabling Singleline.
Your content most likely has newlines right?
You should probably also use the IgnoreCase option when parsing HTML tags, although that's almost certainly not what's causing the failure.
The pattern I want to extract? Yeah it does, I'll try that.
Thanks!
Well it's comparing a high level language to machine code. Your only control structures are limited versions of call and return plus (un)conditional goto
Yes, which is precisely my point in that "the higher up in abstraction you are, the less you'll see or need goto."
Pointing out the bottom end is just demonstrating that.
Yeah, your C# is fine, that's a Regex specific issue just so you're aware. You'd see this in any other language using regex for the most part, although I like using the perl-style format for these things. (Adding "i" for case insensitivity, "s" for singleline, etc.)
Singleline is a bad name for what it really does, and many point out / bitch about it.
For example, how would you rewrite this code without using goto? Which version do you believe is more readable?
I don't do C but I believe something like that would work. You could also give better error handling by providing the user with more information about any access issues. The user won't have to deal with running it 3 times to find out the first time a.txt doesn't exist, then b.txt, then c.txt. You could gather all of those errors in one go and provide the details needed in one shot.
I don't really like how large the some_procedure is, it can be re-factored into something nicer but I don't want to spend too much time.
For that particular example, I'd consider something like:
[strike]Edit: Sorry Lux, C is pass by value, not pass by reference. openFile() would need to be modified slightly to accept a FILE**, I believe.[/strike]
Edit2: Ah, nevermind. Finally read the bottom of your post.
Look through the Linux Kernel source code tree. It's a perfectly acceptable flow control statement. Just grep for "goto". Also grep for "fuck" for entertainment.
Off the top of my head -
Clarifying a large nested tree of if-the-else where the purpose of the else is to abort the following actions if any of the if tests fail.
so you would have a bunch of
if (test) {
statements;
} else {
goto fail;
}
it clears readability by a ton.
When you are initializing a device/process that requires multiple steps to be wound in order, and unwound in the opposite order, making sure that you don't execute the unwinding steps to anything that wasn't initialized - the resulting code using is far clearer and more terse.
Another is the loop and a half, often necessary for parsing strings.
The Dijkstra paper has, over time, done more harm than good, because people take the general message of "GOTO IS BAD", but without the nuance which Dijkstra presented it. Go read the paper, its available online freely, and you'll find that the message was more that goto's are harmful in the hands of programmers who didn't have a grasp of what they were doing, but are still useful in many circumstances.
A long time ago, there was a discussion on goto's on LKML, where Linus, in his usual brusque tone, talked about the use of goto's throughout the kernel.
(I've also got a really good flame mail from Linus about his opinion on the Gnome project from [Desktop_Architects], but that one, we'll save for another time)
Joe's Stream.
Those initial if's should all be checking rc too:
There's no point opening the other files or allocating the buffer if you already know the procedure is going to fail. Which is the real point of the goto idiom Janin mentioned -- you always know at each line that all the previous operations have succeeded, and so there's no chance that anyone will forget to check a failure flag (and eventually, someone will forget). It's the same school of thought that says it's better to allow early returns due to failures than to doggedly enforce a "one exit-point only" approach (the main advantage of using goto here is that it lets you re-use the clean-up code).
Background: Surfing "gigs" on Craigslist I found a posting asking for someone to complete some short, easy VB projects. I figured I could use a few bucks and sent an email asking what they entailed so I could quote accordingly.
What I got emailed back are pdfs of what are clearly homework assignments, to the point that they're labeled "Chapter 3" and "Chapter 5", etc. They're simple enough and I could knock them out in a few hours.
My wife's of the opinion that A) we could use the money and if he cheats his way through school he's only hurting himself. I'm hesitant, because... well... it's cheating. Even if I'm not the doing the cheating (I've been done with school for years), I'm helping someone else cheat.
What say you?
Robots Will Be Our Superiors (Blog)
http://michaelhermes.com
Not that I'm trying to be your internet conscience or anything. BTW, how much money are we talking here?
The plugins in my practicum class enforce single return at end. It's a pain. I mean I understand it's more efficient, but damn.
Actually a lot of things they enforce are a pain.
I'm taking is as practice for real jobs, where you get told to do silly thing all the time. At least that was my experience delivering pizza.
I certainly hope the cheating guy isn't a CS major. Otherwise he's going to have a hard time cheating his way into a paycheck.
I was going to quote him based on the programs, and then he sent them to me and I saw they were homework assignments. Each would probably take less than an hour so I was thinking $25 per, but if he's in high school or college he probably can't afford that.
In any case, I responded with "Sorry, I don't feel comfortable doing someone's homework for them."
Robots Will Be Our Superiors (Blog)
http://michaelhermes.com
when i started the goto conversation, I only included it as something you NEED to know with C. It's also an interview question that I ask all the time - "When is it appropriate to use a goto". If they answer "never", I have a chance to see how teachable the candidate is. If they answer correctly, I know they have a deeper understanding of programming, and are probably on the more advanced side.
As for CompSci projects, most don't resemble real world projects at ALL. First, most are done in single-person environments, when every industry projects are always team based. Second, they enforce weird and harmful arbitrary rules, like no goto, single returns, ridiculous amounts of commenting, etc etc etc.
There is a huge disconnect between academia and industry in CS. I've said this before, I wish there was a PE-like cert for software engineers, that didn't include how to make a steam engine run, but tested for actual software-related problem solving skills, and a rounded knowledge of languages, concepts, etc. (Ansi-ish) C, C++, and a functional would be a minimum.
Joe's Stream.
I've said it before here that we should have a professional organization and responsibility, and some people think I'm crazy. :P There are plenty of places where this is necessary imo, and those places usually have to organize their own regulations and such. (medical, military, government, etc.) Some kind of unification under a profession would be nice, since there are a lot of jobs that could go to more competent people for more money.
Yeh. I was very excited about taking this Programming Practicum course, because I assumed it would be the whole class getting together and writing a big project collaberatively. Instead, it's turning out to be Intro to Java - Bonus Round, with more rules.
Don't get me wrong, I'm learning things. But how to work as a team is not one of them.
I think the most team work I did in school was for controlling a 3 axis mechanical arm. We wrote up a protocol so we can talk to each other over an ethernet cable. One was written in C on the arm, the other piece of software on a windows PC in C#. We didn't do much in terms of multiple people working on the same piece of software however.
By far the most valuable course I ever did at university was a year long software engineering project. No lectures, the class is split into groups of ~6, and the lecturers act as 'customers', which you need to book meetings with to request feedback for your product so far and get your user stories checked off. We had one lecturer that would constantly change his mind on everything, and kept requesting/suggesting new features which we'd scramble to work in for him. We hated his bullshit so much, but in hindsight, he was just acting like customers do in the real world.
Did you guys follow any kind of agile methodology? Your use of "User Stories" instead of "Use Cases" and also the iterative feedback from your customers/lecturers is what is prompting the question.
Regardless, it sounds like a good class. I didn't learn anything about team project management until I graduated and got a job.
In my CS program there was a "Software Engineering" class and a "Software Engineering Project" class. I took the SE class during the summer, so we didn't get to do too much actual coding, but in the SE Project class we split up into groups of 5 or 6 and each had to write and develop a PalmOS application. It was a pretty fun class.
Yep, the recommended methodology was extreme programming. Which worked quite well with the course, since the lecturers could outline a broad problem and give feedback throughout the year, giving students a chance to continually iterate in response.
The guy who ran the course told me that he'd gotten the idea from a SE lecturer at another university, who ran a similar course but would grade at random intervals throughout the year, giving students 24 hours notice that their deliverable was due. Apparently this was deemed a little too harsh, though I can see the merit if it encourages students to actually use an agile process.
Someone is advocating the declaration of temporary variables in class headers. The stated reason is to avoid the resource hit of creating and destroying objects. This is in a large scale embedded platform. Anyone care to comment on the validity of doing so?
Have some thoughts myself, but wanted to see what others thought.