The following code is an example of what I think would qualify as pseudocode, since it does not execute in any language but the logic is correct.
string checkRubric(gpa, major)
bool brake = false
num lastRange
num rangeCounter
string assignment = "unassigned"
array bus['business']= array('person a'=>array(0, 2.9), 'person b'=>array(3, 4))
array cis['computer science']= array('person c'=>array(0, 2.9), 'person d'=>array(3, 4))
array lib['english']= array('person e'=>array(0, 4))
array rubric = array(bus, cis, lib)
foreach (rubric as fieldAr)
foreach (fieldAr as field => advisorAr)
if (major == field)
foreach (advisorAr as advisor => gpaRangeAr)
rangeCounter = 0
foreach (gpaRangeAr as gpaValue)
if (rangeCounter < 1)
lastRange = gpaValue
else if (gpa >= lastRange && gpa <= gpaValue)
assignment = advisor
brake = true
break
endif
rangeCounter++
endforeach
if (brake == true)
break
endif
endforeach
if (brake == true)
break
endif
endif
endforeach
if (brake == true)
break
endif
endforeach
return assignment
For the past couple of weeks I've been trying to create a clear definition of what pseudocode actually is. Is it relative to the programmer or is there an actual clearcut syntax? I say pseudocode is any code that does not execute, how about you? Thanks (links to this subject welcome)
There is no fixed definition of pseudocode. It's any notation that you expect your audience to understand to get your point across. The important idea is that it is intended for humans to read, not computers, so it doesn't have to be precise. You can include the details that are important to your exposition, and omit the ones that are not.
Shamelessly ripped from Wikipedia:
Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. Pseudocode typically omits details that are not essential for human understanding of the algorithm, such as variable declarations, system-specific code and subroutines.
There is a lot of code that does not execute. That does not mean it is pseudocode. Your "psuedocode" has a lot of extra stuff that non-programmers will not understand. Instead of being pseudocode, your "psuedocode" language is very, very close to an actual language.
Pseudocode should, in theory, be implementation independant. It presents logical steps in plain language of what to do. It is intended for human interpretation, not machine execution.
OP's example is a bit closer to actual code than pseudocode. For example, ++
is not found in all languages. It could also have a very different meaning in others.
Pseudo-code is any compact, human readable explanation of an algorithm or program. Since your program is not readable to me, I would say that it is not quite pseudo-code. Here is an example of pseudo-code:
def sum(x): result = 0 for each entry in x: add current entry to result report result
Or, in a slightly different style:
sum(x): Let x be an array Let result be an integer representing the result, initially 0 for item in x: result += item return result
You can use elements of a particular syntax (and, in fact, my pseudo-code tends to look a lot like Python), but it needs to be understandable by a wide audience and should not be obstructed by syntax. For example, I use "+=", but this is because it is highly compact and convenient, not because it is required. If you found "endforeach" helpful and convenient in your exposition, it would have been ok; however, I would argue that such a thing does not belong in pseudo-code as it looks more stinted than helpful or explanatory.
Well, if I don't compile/link my C++ code, it won't execute, so I don't think "Code that doesn't execute" is an acceptable definition.
Likewise scripting languages aren't executed, they're often times interpreted.
My definition of pseudo code would be:
"[Concise] Code that is syntax agnostic, written to convey a function, behavior, or algorithm.""
An outline of a program, written in a form that can easily be converted into real programming statements.
Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules. It is simply one step - an important one - in producing the final code. The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With