|
quick programming question
#346943 - 11/12/15 03:29 PM
|
|
|
In my current class, we are required to assess our own code, as well as 2 random other students' code. It is pseudo code, so it doesn't really conform to a specific language, so I must ask: Will the following work in ANY language?
If Variable NOT == 0
instead of
If Variable == NOT0
or whatever the format is supposed to be... Variable == NOT(0), maybe?
I know the simple thing in this case is !=, but the chapter for this assignment introduced AND, OR, and NOT, and data validation, and students are encouraged to use the new concepts in every chapter's work.
Within an If statement like that... would it crash the program or just simply not validate the data as you intended?
|
Just broke my personal record for number of consecutive days without dying!
|
|
RATMNL |
Patron Saint of the Totally F*cked
|
|
|
Reged: 02/02/13
|
Posts: 425
|
Loc: 026, NL
|
|
Send PM
|
|
|
Re: quick programming question
[Re: URherenow]
#346945 - 11/12/15 03:57 PM
|
|
|
I guess.. not using the != (why you wouldn't I don't know)
if(Var == NOT 0)
in var NOT == 0, you called the variable by the name of NOT. It will not find it and therefor crash
Edited by RATMNL (11/12/15 04:00 PM)
|
"Those voices in his head might not be real, but they have really good ideas!"
|
|
Pi |
Allergic to life
|
|
|
Reged: 09/20/03
|
Posts: 6449
|
Loc: Room 101
|
|
Send PM
|
|
|
Re: quick programming question
[Re: URherenow]
#346949 - 11/12/15 05:36 PM
|
|
|
> In my current class, we are required to assess our own code, as well as 2 random > other students' code. It is pseudo code, so it doesn't really conform to a specific > language, so I must ask: Will the following work in ANY language? > > If Variable NOT == 0
NOT is an unary operator. == (equal to) is a binary operator. Placing the NOT there will make it negate the equal to operator. So that specific syntax has to fail in every language I know of. Only these constructs would work, be it pseudocode or real code in a specific language: if variable == not(0) if not(variable == 0)
One could argue that in certain situations, a minus sign (-) is also an unary operator but it wouldn't matter in this example since the operator precedence would unambiguously interpret the following in the same way: if variable == not -1 if variable == not(-1)
However even if you forget about operator precedence and specify parentheses all around everything, it's clear that the construct you ask about doesn't make sense: if variable not(== 0)
Operator precedence has always been one of my weak spots in writing code so I tend to overuse parentheses to ensure that things are interpreted in the way I need.
|
Wound up, can't sleep, can't do anything right, little honey / Oh, since I set my eyes on you. / I tell you the truth. I can't get it right / Get it right / Since I met you...
|
|
|
Re: quick programming question
[Re: RATMNL]
#346960 - 11/13/15 01:56 AM
|
|
|
> I guess.. not using the != > (why you wouldn't I don't know) > Like I said... using newly introduced concepts. != was already covered. Granted, NOT is more suited for use in expressions NOT( c * v > 155 )
or whatever... but this is a prelude to programming class, so it's full of people who have never seen source code in their life...
My dilemma is, do I take points away for the mistake, or do I outright score this portion as 0, because it could not solve the problem (which it couldn't if the program simply would error out or crash. The grading criteria clearly states to grade as 0 if the solution does not solve the problem. This IF statement was just to prevent division by zero, and not necessarily required to get the correct output as long as the user did not enter a 0 for input).
I hate this aspect of the class, because my assessment seems to actually affect the student's score. I'm highly against this because... students who may or may not understand what the hell is going on, having the ability to affect MY grade? Crazy...
|
Just broke my personal record for number of consecutive days without dying!
|
|
|
Re: quick programming question
[Re: URherenow]
#346963 - 11/13/15 02:56 AM
|
|
|
|
|
Re: quick programming question
[Re: Pi]
#346965 - 11/13/15 05:29 AM
|
|
|
> > If Variable NOT == 0 > > NOT is an unary operator. == (equal to) is a binary operator. Placing the NOT there > will make it negate the equal to operator. So that specific syntax has to fail in > every language I know of. Only these constructs would work, be it pseudocode or real > code in a specific language: > if variable == not(0) > if not(variable == 0)
I agree with this.
Additionally you say "It is pseudo code, so it doesn't really conform to a specific language". However, even pseudo code has to have rules and syntax or it's meaningless. What are the rules of this pseudo code language regarding the usage of NOT? Were you given any examples in the book? Assuming you have a book.
|
GroovyMAME support forum on BYOAC
|
|
|
Re: quick programming question
[Re: Robbbert]
#346969 - 11/13/15 08:04 AM
|
|
|
> COBOL: doesn't use symbols, everything is the full words. IF C NOT EQUALS 7 MOVE 8 TO > DD.
That's reasonably close to the given situation.
|
|
|
|
Re: quick programming question
[Re: TriggerFin]
#346971 - 11/13/15 11:22 AM
|
|
|
> > COBOL: doesn't use symbols, everything is the full words. IF C NOT EQUALS 7 MOVE 8 > TO > > DD. > > That's reasonably close to the given situation.
I venture to say, reasonably close enough to NOT have to assign zero points for the problem.
Thanks!
|
Just broke my personal record for number of consecutive days without dying!
|
|