• I signed up for Computer Programming 1, instead I get CP1-where-I'll-learn-Fundamntls
    69 replies, posted
[QUOTE=admiral_Cola;18556491]It is more used as a deterrent because break can be used to escape loops and such which means that for certain assignments people can get away with deviating from the objectives.[/quote] Assignments are to be completed by reaching a certain goal. If this goal can be reached in an elegant, short way with a break statement, then there's no reason against using break. [quote] Again break was accepted, but in your case; break is nothing if you are being so :smug: about it you can use try/catch statements and impress the fuck out of your teacher.[/QUOTE] Wait, let me get this straight... "Don't use break! Use a try {} catch {} instead!" ... :bang:
If there were to be a programming class at my school, I'd be teaching it. I'm not saying I'm incredibly awesome at programming (although I am :smug:). No teacher or other student has the slightest idea how to program, or do anything slightly impressing on computers apart from Alt+Shift+Print Screen (which isn't impressing at all). [editline]07:43PM[/editline] Oh shit... I [highlight][i]posted[/i][/highlight]!
[QUOTE=Deco Da Man;18561092]Alt+Shift+Print Screen (which isn't impressing at all). [/QUOTE] What what does that do?
[QUOTE=nullsquared;18561221]What what does that do?[/QUOTE] [img]http://screensnapr.com/u/jd0b99.png[/img] [img]http://screensnapr.com/u/ucifnn.png[/img]
[img]http://www.facepunch.com/image.php?u=129856&dateline=1258919707[/img]
[img]http://www.facepunch.com/image.php?u=164627&dateline=1257466207[/img] In my programming 1 class I'm doing more teaching than the teacher does, and my classmates say I do a better job at it. I don't think I'll do programming 2, I'll probably do independent study where I can go at my own speed without having weeks to do a 7 line program. Example: Dim chrFirst As Char = Me.txtName.Text.Chars(0) Dim chrLast As Char = Me.txtName.Text.Chars(Me.txtName.Text.IndexOf(" ") + 1) she gave us a week to do that. (only chapter six of visual basic) I did it two months earlier than she assigned it though.
[QUOTE=luck_or_loss;18567361]visual basic[/QUOTE] There is yout problem [editline]05:05PM[/editline] [QUOTE=nullsquared;18561014]Assignments are to be completed by reaching a certain goal. If this goal can be reached in an elegant, short way with a break statement, then there's no reason against using break. [/QUOTE] The point of the assignment is to learn what segment of programming you should be learning. If i have a homework built around loops, I should learn how to make the loop work, as opposed to breaking out if shit hits the fan. I understand that in practice, break is commonly used. But I am talking about the education system I am in right now. Sorry that a University is interested in teaching a student how to do something right as opposed to doing it fast. [QUOTE=nullsquared;18561014] Wait, let me get this straight... "Don't use break! Use a try {} catch {} instead!" ... :bang:[/QUOTE] A try/catch can do exactly what he wanted, it would give him a clean error and tell him that line=null. Doing the break method as decribed is equivalent to the programmer sticking his fingers in his ears and saying "lalala." Nothing wrong with that, but a try/catch is better for this instance. I don't see why you have to resort to personal attacks against my e-person, i am trying to give some sound advice and my own perspective.
[QUOTE=admiral_Cola;18568843] The point of the assignment is to learn what segment of programming you should be learning. If i have a homework built around loops, I should learn how to make the loop work, as opposed to breaking out if shit hits the fan. I understand that in practice, break is commonly used. But I am talking about the education system I am in right now. Sorry that a University is interested in teaching a student how to do something right as opposed to doing it fast. [/quote] ........ but if "shit hits the fan" and the loop is meant to quit, you're [i]supposed to[/i] use break.. The the whole point of break. You seem to think it's some sort of evil trick or something. [quote] A try/catch can do exactly what he wanted, it would give him a clean error and tell him that line=null. Doing the break method as decribed is equivalent to the programmer sticking his fingers in his ears and saying "lalala." Nothing wrong with that, but a try/catch is better for this instance. [/QUOTE] No it's not? Line being null is not an error, it means that the end of input was reached. If the end of input was reached, then the loop quits and whatever happens after the loop starts doing its thing. Exceptions are for just that, exceptional situations. If it's an error to not input exactly N numbers, for example, you might throw an exception. But if the current code is the code receiving the input, then there's no point in throwing an exception, only to catch it one block up. Using some sort of "input is good" flag should be done, like so: [cpp] ArrayList<Integer> nums = new ArrayList<Integer>(); for (int i = 0; i < 5 && in.hasNext(); ++i) nums.add(in.nextInt()); // check for errors if (nums.size() < 5) // oh no, not enough numbers // do something ; [/cpp]
[QUOTE=nullsquared;18569661]........ but if "shit hits the fan" and the loop is meant to quit, you're [i]supposed to[/i] use break.. The the whole point of break. You seem to think it's some sort of evil trick or something. [/QUOTE] If you're righting a for loop for an assignment and you have to break to get out of the loop; you wrote the loop wrong. I am not bashing the break; again, I talk from a educated perspective. this is about schools where the original argument is derived from. It's not evil, nothing in programming is; because it is inanimate. [QUOTE=nullsquared;18569661] No it's not? Line being null is not an error, it means that the end of input was reached. If the end of input was reached, then the loop quits and whatever happens after the loop starts doing its thing. Exceptions are for just that, exceptional situations. If it's an error to not input exactly N numbers, for example, you might throw an exception. But if the current code is the code receiving the input, then there's no point in throwing an exception, only to catch it one block up. Using some sort of "input is good" flag should be done, like so: [cpp] ArrayList<Integer> nums = new ArrayList<Integer>(); for (int i = 0; i < 5 && in.hasNext(); ++i) nums.add(in.nextInt()); // check for errors if (nums.size() < 5) // oh no, not enough numbers // do something ; [/cpp][/QUOTE] Reexamining the code; the break isnt needed and neither is the try/catch. The way it was [I]supposed[/I] to be would have ended the loop without the need to break. Again a scenario where robust writing can evade a break. I am not against the break; in fact I'd use them all the time. Again it is just my university's rules, and don't say something like "The University is dumb lol" because I learned a lot without the need to use break or continue.
[QUOTE=admiral_Cola;18568843]There is yout problem [editline]05:05PM[/editline] The point of the assignment is to learn what segment of programming you should be learning. If i have a homework built around loops, I should learn how to make the loop work, as opposed to breaking out if shit hits the fan. I understand that in practice, break is commonly used. But I am talking about the education system I am in right now. Sorry that a University is interested in teaching a student how to do something right as opposed to doing it fast. A try/catch can do exactly what he wanted, it would give him a clean error and tell him that line=null. Doing the break method as decribed is equivalent to the programmer sticking his fingers in his ears and saying "lalala." Nothing wrong with that, but a try/catch is better for this instance. I don't see why you have to resort to personal attacks against my e-person, i am trying to give some sound advice and my own perspective.[/QUOTE] I didn't mention what the loop was really used for, but the assignment was to read the first 5 lines of a file and print them out. Line would be null if there were less than five lines, so it really did need to just quit looping. It wasn't a "shit just hit the fan" moment, it was a "looks like we're out of stuff to read" moment. But yeah, in some cases, shit might have hit the fan. In a case like that, I'd probably use a catch{} or an if statement to set the String to some sort of default value and let the loop keep going rather than letting it remain null.
Sorry, you need to Log In to post a reply to this thread.