The Big Programming Thread - Page 835
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Askelad
France20 Posts
| ||
![]()
TheEmulator
28079 Posts
| ||
maybenexttime
Poland5419 Posts
I am learning how to create a simple dialog box GUI in Matlab, and I am not sure what is the proper way to handle invalid inputs. Namely, the pattern repeats itself: I have the parameter name, default value variable name, condition, and the error message. Should I create a function that uses this pattern or leave it as it is now? Is it more proper to have explicit if statements or to reduce the number of lines considerably by making the if statements implicit (hidden in a dedicated function). + Show Spoiler + while open_prompt | ||
Blisse
Canada3710 Posts
In which case no need to make a function | ||
maybenexttime
Poland5419 Posts
On February 05 2017 17:38 Blisse wrote: IMO this would be a better pattern
In which case no need to make a function Thanks for your input. I am, however, not sure this is going to maintain the same functionality. In my code the dialog box has a set of default values: default_initial = {'10', '0', '10', '1', '1', '1'}. By checking the validity of each input value individually, I can either replace the default value with the valid input value (default_initial{2} = answer_initial{2}) or make the field empty (default_initial{2} = ''). if (str2double(answer_initial{2}) >= 0) & ... If I were to put all actions in the very last if statement, then upon opening the dialog box again (in the next iteration of the while loop) the initial default values would be used, and all valid inputs would be lost. | ||
Shield
Bulgaria4824 Posts
On February 05 2017 12:58 Askelad wrote: Makes even less sense. Seriously what was that rant about the irrationals... Educate yourself: https://en.wikipedia.org/wiki/Irrational_number On February 05 2017 12:17 travis wrote: since it (understandably) turned into a semantics argument, I'll let everyone know that I selected all of the options and got the answer correct. It doesn't seem the best answer to me. Real numbers should be better because others do not mention irrational numbers. Or did you select real numbers too? | ||
Nesserev
Belgium2760 Posts
| ||
Shield
Bulgaria4824 Posts
On February 05 2017 22:57 Nesserev wrote: Uh, lol what? That's kind of uncalled for, especially because it's clear that you're in the wrong here. Sorry, but the one that needs a lesson is you... a lesson in not being an idiot, and perhaps set theory. You should focus on this: "for all x in D[there exists a y in D ( x < y)]" That statement is true for any number set Travis listed. If D is either the set of integers, natural numbers or rational numbers, there's zero reason to consider irrational numbers, because irrational numbers aren't in those sets... How can 'true' be more correct than 'true'? So, where is your confusion coming from? All that I can think of is that you didn't parse the question correctly, and think D is supposed to be any random interval of real numbers? And you seem to be reinforcing this idea because you're grasping back at irrational numbers... Dude, you're wrong and you need to be taught how not to be an idiot. Or go study some math? Integers: true (for all x in D[there exists a y in D ( x < y)]) Rational numbers: true (for all x in D[there exists a y in D ( x < y)]) Natural numbers: true (for all x in D[there exists a y in D ( x < y)]) Set of real numbers has integers, rational numbers and natural numbers. So, all of above is true. Plus, irrational numbers which are in the set of real numbers. E.g. x = √2 y = √3 x < y The set of real numbers is BIGGER than the union of natural numbers, integers and rationals. | ||
spinesheath
Germany8679 Posts
| ||
Shield
Bulgaria4824 Posts
On February 05 2017 23:59 spinesheath wrote: For the record: The question asks for which set a condition holds, not which set among the list is the best match or anything like that. So you have to evaluate each set by itself. As per the wording of the question, the answer is "it is true for all 4 sets". Nobody is doubting that integers are part of the real numbers, it just has nothing to do with the question. Sure, I was asking travis if he chose all 4 but some people can't argue in a respectful way. On February 05 2017 12:58 Askelad wrote: Makes even less sense. Seriously what was that rant about the irrationals... | ||
Hanh
146 Posts
| ||
Deleted User 3420
24492 Posts
how do I remove the encryption from within vim I don't want it to be encrypted anymore ok I figured it out :set key= vim is weird though.. I had to exit with :wq and not :x or it wasn't saving the change.. no idea why. wtf tbh | ||
Wrath
3174 Posts
On February 06 2017 00:36 travis wrote: I encrypted my vim file how do I remove the encryption from within vim I don't want it to be encrypted anymore ok I figured it out :set key= vim is weird though.. I had to exit with :wq and not :x or it wasn't saving the change.. no idea why. wtf tbh Wasn't always :wq to save and :q! to exit without saving? Never heard of :x before. | ||
Hanh
146 Posts
| ||
Deleted User 3420
24492 Posts
why does this:
simply print an empty line and then ask me for a character and size it doesn't even give me a chance to input a character the first time whelp, figured it out any time you have a scanf you're gonna need a whitespace before your next scanf? that's so annoying | ||
Shield
Bulgaria4824 Posts
![]() You might want to read this answer because your whitespace should be first: http://stackoverflow.com/a/13543113 | ||
Blisse
Canada3710 Posts
On February 05 2017 18:54 maybenexttime wrote: Thanks for your input. I am, however, not sure this is going to maintain the same functionality. In my code the dialog box has a set of default values: default_initial = {'10', '0', '10', '1', '1', '1'}. By checking the validity of each input value individually, I can either replace the default value with the valid input value (default_initial{2} = answer_initial{2}) or make the field empty (default_initial{2} = ''). if (str2double(answer_initial{2}) >= 0) & ... If I were to put all actions in the very last if statement, then upon opening the dialog box again (in the next iteration of the while loop) the initial default values would be used, and all valid inputs would be lost. Not totally certain I'm walking through your logic and explanation in the same way, but there is no next iteration of the loop if you've put all the action in the else block - the loop exits. The `action` in my example would be doing whatever you needed with the answer_initial (in this case copying each value to default_initial). edit: ohh okay I see what you mean by losing all the valid values on the next iteration, when the user enters valid and invalid values you want to keep the valid values and not set the invalid ones. Let me think about that.. edit2: i think your way is fine if you have that requirement. in that case i think it'd be nice to make a function. generally i disagree with making extra functions "for readability" if that function is only used once. the exception would be in cases where you'd expect that function to exist, i.e. client::isConnected(). in this case i'd like a somewhat generic function like `bool setArrayValueIfTrue(arr, index, value, cond)`. | ||
maybenexttime
Poland5419 Posts
On February 06 2017 07:56 Blisse wrote: + Show Spoiler + On February 05 2017 18:54 maybenexttime wrote: Thanks for your input. I am, however, not sure this is going to maintain the same functionality. In my code the dialog box has a set of default values: default_initial = {'10', '0', '10', '1', '1', '1'}. By checking the validity of each input value individually, I can either replace the default value with the valid input value (default_initial{2} = answer_initial{2}) or make the field empty (default_initial{2} = ''). if (str2double(answer_initial{2}) >= 0) & ... If I were to put all actions in the very last if statement, then upon opening the dialog box again (in the next iteration of the while loop) the initial default values would be used, and all valid inputs would be lost. Not totally certain I'm walking through your logic and explanation in the same way, but there is no next iteration of the loop if you've put all the action in the else block - the loop exits. The `action` in my example would be doing whatever you needed with the answer_initial (in this case copying each value to default_initial). edit: ohh okay I see what you mean by losing all the valid values on the next iteration, when the user enters valid and invalid values you want to keep the valid values and not set the invalid ones. Let me think about that.. edit2: i think your way is fine if you have that requirement. in that case i think it'd be nice to make a function. generally i disagree with making extra functions "for readability" if that function is only used once. the exception would be in cases where you'd expect that function to exist, i.e. client::isConnected(). in this case i'd like a somewhat generic function like `bool setArrayValueIfTrue(arr, index, value, cond)`. Thank you! I might have a few more questions regarding putting such recurring patterns into functions, but I'll give it a try myself first. | ||
Silvanel
Poland4691 Posts
I know this post isnt very productive. I just wanted to share my excitement. | ||
AKnopf
Germany259 Posts
On February 06 2017 18:31 Silvanel wrote: So our customer just recently acccepted the software. Its a great feeling that work You (and few hundred other people) have been doing for last year and a half did not go in vain. Will be deployed to market in next 1-2 months. I know this post isnt very productive. I just wanted to share my excitement. Sharing positive feelings should never be considered unproductive. :-) Congrats! It's always such a nice feeling to have your work published, even if it's only a small fix or a simple feature the customer needs. A satisfied customer is almost as good as the feeling when jenkins works and your latest commit doesn't break the test suite. ;-D | ||
| ||