Docsity

Readability Control Statements - Programming Languages - Lecture Slides, Slides of Programming Languages

Partial preview of the text

Download Readability Control Statements - Programming Languages - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

Readability - Control Statements

  • Hazards of goto
  • Restricted use was needed and useful as

well

  • Probably not an issue any more

Readability - Syntax

  • Variable names
  • Special keywords for signaling the start and end of key words.

if (some condition) do this now do this

if (some condition) then do this end if now do this

Writability

  • Support for abstraction
  • Expressivity
    • Constructs that make it convenient to write programs e.g. for set data type in Pascal we do not have an equivalent in C

Orthogonality

  • Relatively small number of components that can be combined in a relatively small number of ways to get the desired results.
  • Closely associated with simplicity
  • The more orthogonal the design the fewer exceptions - makes it easier to learn, read, and write
  • The meaning of an orthogonal feature is independent of the context – symmetry and consistency. - e.g. pointers

Orthogonality

  • C
    • You can return structures but not arrays
    • An array can be returned if it is inside a structure
    • A member of a structure can be any data type except void or the structure of the same type
    • An array element can be any data type except void
    • Everything is passed by value except arrays
    • Pointer arithmetic
      • a+5 means what?
      • a + b
    • Use of void as a type in a structure

Orthogonality

The Other side

  • In C – all statements return some value

and hence can be used in expressions.

  • Logic and arithmetic expressions can be intermixed
  • Can cause side effects
  • Can cause cryptic code
  • A[i] , i[A]
  • Since languages need large number of

components, too much orthogonality can cause problems.