Chapter 5 Variables

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 5 Variables Topics Binding Chapter 5 Lifetime Scope Variables Constants Chapter 5: Variables 2 Variables: attributes Binding A variable can be thought of as being completely The assignment statement is really an specified by its 6 basic attributes: instance of a more general phenomenon of 1. Name: identifier attaching various kinds of values to names. 2. Address: memory location(s) The association of a name to an attribute is 3. Value: particular value at a moment called binding 4. Type: range of possible values n Assignment statement binds a value to a 5. Lifetime: when the variable is accessible location. 6. Scope: where in the program it can be accessed n Identifiers are bond to locations, types, and other attributes at various points in the translations of a program. Chapter 5: Variables 3 Chapter 5: Variables 4 Binding Binding Binding time. Bindings happen at different 3. Compile time and invisible points. n Example: bind a variable to a type in C or Java Possible binding times 4. Link time n Example: bind a call to a library function to the 1. Language design time function code. n Bind operator symbols to operations 5. Load time n Example: bind * to multiplication n Example: bind a C static variable to a memory 2. Language implementation time cell. n Example: bind floating point type to a representation (IEEE floating-point format) 6. Runtime n Example: bind a nonstaticlocal variable to a n Example: the data type int in Java is bound to a range of values. memory cell Chapter 5: Variables 5 Chapter 5: Variables 6 1 The Concept of Binding Static and Dynamic Binding Consider the following: A binding is static int C; n it occurs before run time and C := C + 5; n It remains unchanged throughout program execution n Some of the bindings and their binding times A binding is dynamic are: n It occurs during execution or The type of C is bound at compiletime. The set of possible values of C is bound at compiler design n It can change during execution of the program time. As binding time gets earlier: The meaning of the operator + is bound at compiletime (when the types of its operands have been determined) n Efficiency goes up The internal representation of the literal 5 is bound at n Safety goes up compiler design time. The value of C is bound at run time. n Flexibility goes down Chapter 5: Variables 7 Chapter 5: Variables 8 Type Bindings Variable Declarations A variable must be bound to a data type before An explicit declaration is a program statement it can be referenced. used for declaring the types of variables. Two key issues in binding a type to an n Example: identifier: int x; n 1. How is the type specified? Advantage: safer, cheaper 2. When does the binding take place? n Disadvantage: less flexible How? – two kinds of declarations: An implicit declaration is a default mechanism 1. Explicit declarations for specifying types of variables (the first 2. Implicit declarations appearance of the variable in the program) When? - three kinds of type bindings: n Example: in FORTRAN, variables beginning with I-N 1. Static type binding are assumed to be of type integer. 2. Dynamic type binding 3. Type inference Chapter 5: Variables 9 Chapter 5: Variables 10 Variable Declarations Variable Declarations Advantages: convenience Implicit declarations leave more room for Disadvantage: reliability (some typographical and error programmer errors cannot be detected. n Example: In FORTRAN variables left Intermediate position: Names for specific types undeclared will be implicitly declared as an must begin with a given character. integer. n Example: in Perl, variables of type scalar, array and hash structures begin with a $, @, or %, respectively. n Advantages: Different namespaces for different type variables @apple vs. %apple vs. @apple The type of a variable is know through its name. Chapter 5: Variables 11 Chapter 5: Variables 12 2 Dynamic Type Binding Dynamic Type Binding The variable is bound to a type when it is n Disadvantages: Compiler’s type error detection is minimized. assigned a value in an assignment If RHS is not compatible with LHS, the type of LHS is changed as statement. opposed to generating an error. n This issue also appears in static type binding languages like C and n JavaScript and PHP C++ n Example: in JavaScript Must be implemented by a pure interpreter rather than a compiler list = { 2, 4, 6, 8 }; n It is not possible to create machine code instructions whose operand types are not known at compile time. list = 17.3; High cost: n Dynamic binding of objects. n Type checking must be done at runtime n Every variable must know its current type n Advantage: flexibility (generic program units) n A variable might have varying sizes because different type values require different amounts of storage. n Must be interpreted. Chapter 5: Variables 13 Chapter 5: Variables 14 Type Inference Type Inference Rather than by assignment statement, types n Illegal: are determined from the context of the fun square(x) = x * x reference. // can’t deduce anything ( a default value could be Type inferencing is used in some assigned) programming languages including ML, n Fixed Miranda, and Haskell. fun square(x : real) = x * x; Example: // use explicit declaration fun square(x) = (x : real) * x; n Legal: fun square(x) : real = x * (x : real); fun circumf(r) = 3.14159 * r * r; // infer r is real fun time10(x) = 10 * x; // infer s is integer Chapter 5: Variables 15 Chapter 5: Variables 16 Storage Bindings & Lifetime Variables: lifetime Allocation is the process of getting a cell from some pool of available cells. Categories of scalar variables by lifetimes: Deallocation is the process of putting a cell n Static back into the pool. n Stack-dynamic The lifetime of a variable is the time during n Explicit heap-dynamic which it is bound to a particular memory cell. n Implicit hep-dynamic n Begin: when the variable is bound to a specific cell n Ends: when the variable is unbound from that cell. Chapter 5: Variables 17 Chapter 5: Variables 18 3 Static Variables Static Variables Bound to memory cells before execution and remains bound to the same memory cell Disadvantages: throughout execution n If a language only has static variables then n Example: all FORTRAN 77 variables Recursion cannot be supported (lack of flexibility). n Example: C static variables Storage cannot be shared among variables Advantages: (more storage required) n Efficiency (direct addressing) n No allocation/deallocation needed (which is run time overhead) n History-sensitive subprogram support (retain values between separate executions of the subprogram) Chapter 5: Variables 19 Chapter 5: Variables 20 Stack-dynamic Variables Stack-dynamic Variables Storage bindings are created for variables in Advantages: the run time stack when their declaration n Allows recursion statement are elaborated (or execution n Conserves storage reaches the code to which declaration is Disadvantages: attached), but types are statically bound. n Run time overhead for allocation and n If scalar, all attributes except address are deallocation. statically bound n Subprogram cannot be history sensitive Example: local variables in C subprograms and Java n Inefficient references (indirect addressing) methods n Limited by stack size. Chapter 5: Variables 21 Chapter 5: Variables 22 Explicit Heap-dynamic Variables Explicit Heap-dynamic Variables Allocated and deallocated by explicit Disadvantages: directives, specified by the programmer, which take effect during execution. n Unreliable (forgetting to delete) n Difficult of using pointer and reference variables n Referenced only through pointers or correctly references n Inefficient. Example: dynamic objects in C++ (via new/delete, malloc/free) Example: Example: all objects in Java (except primitives) int *intnode; // create a pointer Advantages: … intnode = new int // create the heap-dynamic variable n Provides for dynamic storage management … delete intnode; // deallocate the heap-dynamic variable Chapter 5: Variables 23 Chapter 5: Variables 24 4 Implicit Heap-dynamic Variables Summary Table Allocation and deallocation caused by Variable Storage binding time Dynamic storage Type assignment statements and types not Category from binding determined until assignment. Static Before execution Static n Example: All arrays and strings in Perl and JavaScript n Example: all variables in APL Stack-dynamic When declaration is Run-time stack Static Advantage: highest degree of flexibility elaborated (run time) Disadvantages: Explicit heap- By explicit instruction Heap Static dynamic (run time) n Inefficient because all attributes are dynamic (a lot of overhead) Implicit heap- By assignment (run Heap Dynamic dynamic time) n Loss of error detection Chapter 5: Variables 25 Chapter 5: Variables 26 Type Checking Type Checking Generalizes the concept of operands and A compatible type is one that is either: operators to include subprograms and n Legal for the operator, or assignments: n Allowed under language rules to be implicitly n Subprogram is operator, parameters are converted to a legal type by compiler-generated operands. code. n Assignment is operator, LHS and RHS are n This automatic conversion is called coercion operands. Example: adding an int to a float in Java is allowed, Type checking is the activity of ensuring then int is coerced. that the operands of an operator are of compatible types. A type error is the application of an operator to an operand of an inappropriate type. Chapter 5: Variables 27 Chapter 5: Variables 28 Type Checking Strong Typing If all type bindings are A programming language is strongly typed if n Static: nearly all type checking can be static n Type errors are always detected. n Dynamic: type checking must be dynamic n There is strict enforcement of type rules with no Static type checking is less costly (it is better to exceptions.
Recommended publications
  • Chapter 5 Names, Bindings, and Scopes
    Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 5.2 Names 199 5.3 Variables 200 5.4 The Concept of Binding 203 5.5 Scope 211 5.6 Scope and Lifetime 222 5.7 Referencing Environments 223 5.8 Named Constants 224 Summary • Review Questions • Problem Set • Programming Exercises 227 CMPS401 Class Notes (Chap05) Page 1 / 20 Dr. Kuo-pao Yang Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 Imperative languages are abstractions of von Neumann architecture – Memory: stores both instructions and data – Processor: provides operations for modifying the contents of memory Variables are characterized by a collection of properties or attributes – The most important of which is type, a fundamental concept in programming languages – To design a type, must consider scope, lifetime, type checking, initialization, and type compatibility 5.2 Names 199 5.2.1 Design issues The following are the primary design issues for names: – Maximum length? – Are names case sensitive? – Are special words reserved words or keywords? 5.2.2 Name Forms A name is a string of characters used to identify some entity in a program. Length – If too short, they cannot be connotative – Language examples: . FORTRAN I: maximum 6 . COBOL: maximum 30 . C99: no limit but only the first 63 are significant; also, external names are limited to a maximum of 31 . C# and Java: no limit, and all characters are significant . C++: no limit, but implementers often impose a length limitation because they do not want the symbol table in which identifiers are stored during compilation to be too large and also to simplify the maintenance of that table.
    [Show full text]
  • Gotcha Again More Subtleties in the Verilog and Systemverilog Standards That Every Engineer Should Know
    Gotcha Again More Subtleties in the Verilog and SystemVerilog Standards That Every Engineer Should Know Stuart Sutherland Sutherland HDL, Inc. [email protected] Don Mills LCDM Engineering [email protected] Chris Spear Synopsys, Inc. [email protected] ABSTRACT The definition of gotcha is: “A misfeature of....a programming language...that tends to breed bugs or mistakes because it is both enticingly easy to invoke and completely unexpected and/or unreasonable in its outcome. A classic gotcha in C is the fact that ‘if (a=b) {code;}’ is syntactically valid and sometimes even correct. It puts the value of b into a and then executes code if a is non-zero. What the programmer probably meant was ‘if (a==b) {code;}’, which executes code if a and b are equal.” (http://www.hyperdictionary.com/computing/gotcha). This paper documents 38 gotchas when using the Verilog and SystemVerilog languages. Some of these gotchas are obvious, and some are very subtle. The goal of this paper is to reveal many of the mysteries of Verilog and SystemVerilog, and help engineers understand the important underlying rules of the Verilog and SystemVerilog languages. The paper is a continuation of a paper entitled “Standard Gotchas: Subtleties in the Verilog and SystemVerilog Standards That Every Engineer Should Know” that was presented at the Boston 2006 SNUG conference [1]. SNUG San Jose 2007 1 More Gotchas in Verilog and SystemVerilog Table of Contents 1.0 Introduction ............................................................................................................................3 2.0 Design modeling gotchas .......................................................................................................4 2.1 Overlapped decision statements ................................................................................... 4 2.2 Inappropriate use of unique case statements ...............................................................
    [Show full text]
  • Design and Implementation of Generics for the .NET Common Language Runtime
    Design and Implementation of Generics for the .NET Common Language Runtime Andrew Kennedy Don Syme Microsoft Research, Cambridge, U.K. fakeÒÒ¸d×ÝÑeg@ÑicÖÓ×ÓfغcÓÑ Abstract cally through an interface definition language, or IDL) that is nec- essary for language interoperation. The Microsoft .NET Common Language Runtime provides a This paper describes the design and implementation of support shared type system, intermediate language and dynamic execution for parametric polymorphism in the CLR. In its initial release, the environment for the implementation and inter-operation of multiple CLR has no support for polymorphism, an omission shared by the source languages. In this paper we extend it with direct support for JVM. Of course, it is always possible to “compile away” polymor- parametric polymorphism (also known as generics), describing the phism by translation, as has been demonstrated in a number of ex- design through examples written in an extended version of the C# tensions to Java [14, 4, 6, 13, 2, 16] that require no change to the programming language, and explaining aspects of implementation JVM, and in compilers for polymorphic languages that target the by reference to a prototype extension to the runtime. JVM or CLR (MLj [3], Haskell, Eiffel, Mercury). However, such Our design is very expressive, supporting parameterized types, systems inevitably suffer drawbacks of some kind, whether through polymorphic static, instance and virtual methods, “F-bounded” source language restrictions (disallowing primitive type instanti- type parameters, instantiation at pointer and value types, polymor- ations to enable a simple erasure-based translation, as in GJ and phic recursion, and exact run-time types.
    [Show full text]
  • Advanced Practical Programming for Scientists
    Advanced practical Programming for Scientists Thorsten Koch Zuse Institute Berlin TU Berlin SS2017 The Zen of Python, by Tim Peters (part 1) ▶︎ Beautiful is better than ugly. ▶︎ Explicit is better than implicit. ▶︎ Simple is better than complex. ▶︎ Complex is better than complicated. ▶︎ Flat is better than nested. ▶︎ Sparse is better than dense. ▶︎ Readability counts. ▶︎ Special cases aren't special enough to break the rules. ▶︎ Although practicality beats purity. ▶︎ Errors should never pass silently. ▶︎ Unless explicitly silenced. ▶︎ In the face of ambiguity, refuse the temptation to guess. Advanced Programming 78 Ex1 again • Remember: store the data and compute the geometric mean on this stored data. • If it is not obvious how to compile your program, add a REAME file or a comment at the beginning • It should run as ex1 filenname • If you need to start something (python, python3, ...) provide an executable script named ex1 which calls your program, e.g. #/bin/bash python3 ex1.py $1 • Compare the number of valid values. If you have a lower number, you are missing something. If you have a higher number, send me the wrong line I am missing. File: ex1-100.dat with 100001235 lines Valid values Loc0: 50004466 with GeoMean: 36.781736 Valid values Loc1: 49994581 with GeoMean: 36.782583 Advanced Programming 79 Exercise 1: File Format (more detail) Each line should consists of • a sequence-number, • a location (1 or 2), and • a floating point value > 0. Empty lines are allowed. Comments can start a ”#”. Anything including and after “#” on a line should be ignored.
    [Show full text]
  • Java Programming 2 – Lecture #1 – [email protected]
    Java Programming 2 – Lecture #1 – [email protected] About the Java Programming Language Java is an object-oriented, high-level programming language. It is a platform-neutral language, with a ‘write once run anywhere’ philosophy. This is supported by a virtual machine architecture called the Java Virtual Machine (JVM). Java source programs are compiled to JVM bytecode class files, which are converted to native machine code on platform-specific JVM instances. .java source .class JVM executable code files Java bytecode files JVM machine code compiler runtime Java is currently one of the top programming languages, according to most popularity metrics.1 Since its introduction in the late 1990s, it has rapidly grown in importance due to its familiar programming syntax (C-like), good support for modularity, relatively safe features (e.g. garbage collection) and comprehensive library support. Our First Java Program It is traditional to write a ‘hello world’ program as a first step in a new language: /** * a first example program to print Hello world */ public class Hello { public static void main(String [] args) { System.out.println(“Hello world”); } } Contrast with Python Whereas Python programs are concise, Java programs appear verbose in comparison. Python has dynamic typing, but Java uses static typing. Python scripts are generally interpreted from source, whereas Java programs are compiled to bytecode then executed in a high-performance just-in-time native compiler. 1 E.g. see http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html Supporting User Input in Simple Java Programs There are two ways to receive text-based user input in simple programs like our ‘hello world’ example.
    [Show full text]
  • Using the Java Bridge
    Using the Java Bridge In the worlds of Mac OS X, Yellow Box for Windows, and WebObjects programming, there are two languages in common use: Java and Objective-C. This document describes the Java bridge, a technology from Apple that makes communication between these two languages possible. The first section, ÒIntroduction,Ó gives a brief overview of the bridgeÕs capabilities. For a technical overview of the bridge, see ÒHow the Bridge WorksÓ (page 2). To learn how to expose your Objective-C code to Java, see ÒWrapping Objective-C FrameworksÓ (page 9). If you want to write Java code that references Objective-C classes, see ÒUsing Java-Wrapped Objective-C ClassesÓ (page 6). If you are writing Objective-C code that references Java classes, read ÒUsing Java from Objective-CÓ (page 5). Introduction The original OpenStep system developed by NeXT Software contained a number of object-oriented frameworks written in the Objective-C language. Most developers who used these frameworks wrote their code in Objective-C. In recent years, the number of developers writing Java code has increased dramatically. For the benefit of these programmers, Apple Computer has provided Java APIs for these frameworks: Foundation Kit, AppKit, WebObjects, and Enterprise Objects. They were made possible by using techniques described later in Introduction 1 Using the Java Bridge this document. You can use these same techniques to expose your own Objective-C frameworks to Java code. Java and Objective-C are both object-oriented languages, and they have enough similarities that communication between the two is possible. However, there are some differences between the two languages that you need to be aware of in order to use the bridge effectively.
    [Show full text]
  • Tricore Architecture Manual for a Detailed Discussion of Instruction Set Encoding and Semantics
    User’s Manual, v2.3, Feb. 2007 TriCore 32-bit Unified Processor Core Embedded Applications Binary Interface (EABI) Microcontrollers Edition 2007-02 Published by Infineon Technologies AG 81726 München, Germany © Infineon Technologies AG 2007. All Rights Reserved. Legal Disclaimer The information given in this document shall in no event be regarded as a guarantee of conditions or characteristics (“Beschaffenheitsgarantie”). With respect to any examples or hints given herein, any typical values stated herein and/or any information regarding the application of the device, Infineon Technologies hereby disclaims any and all warranties and liabilities of any kind, including without limitation warranties of non- infringement of intellectual property rights of any third party. Information For further information on technology, delivery terms and conditions and prices please contact your nearest Infineon Technologies Office (www.infineon.com). Warnings Due to technical requirements components may contain dangerous substances. For information on the types in question please contact your nearest Infineon Technologies Office. Infineon Technologies Components may only be used in life-support devices or systems with the express written approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system, or to affect the safety or effectiveness of that device or system. Life support devices or systems are intended to be implanted in the human body, or to support and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may be endangered. User’s Manual, v2.3, Feb.
    [Show full text]
  • Tribits Lifecycle Model Version
    SANDIA REPORT SAND2012-0561 Unlimited Release Printed February 2012 TriBITS Lifecycle Model Version 1.0 A Lean/Agile Software Lifecycle Model for Research-based Computational Science and Engineering and Applied Mathematical Software Roscoe A. Bartlett Michael A. Heroux James M. Willenbring Prepared by Sandia National Laboratories Albuquerque, New Mexico 87185 and Livermore, California 94550 Sandia National Laboratories is a multi-program laboratory managed and operated by Sandia Corporation, a wholly owned subsidiary of Lockheed Martin Corporation, for the U.S. Department of Energys National Nuclear Security Administration under Contract DE-AC04-94AL85000. Approved for public release; further dissemination unlimited. Issued by Sandia National Laboratories, operated for the United States Department of Energy by Sandia Corporation. NOTICE: This report was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government, nor any agency thereof, nor any of their employees, nor any of their contractors, subcontractors, or their employees, make any warranty, express or implied, or assume any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or rep- resent that its use would not infringe privately owned rights. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise, does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government, any agency thereof, or any of their contractors or subcontractors. The views and opinions expressed herein do not necessarily state or reflect those of the United States Government, any agency thereof, or any of their contractors.
    [Show full text]
  • Systemverilog Testbench Constructs VCS®/Vcsi™Version X-2005.06 LCA August 2005
    SystemVerilog Testbench Constructs VCS®/VCSi™Version X-2005.06 LCA August 2005 The SystemVerilog features of the Native Testbench technology in VCS documented here are currently available to customers as a part of an Limited Access program. Using these features requires additional LCA license features. Please contact you local Synopsys AC for more details. Comments? E-mail your comments about this manual to [email protected]. Copyright Notice and Proprietary Information Copyright 2005 Synopsys, Inc. All rights reserved. This software and documentation contain confidential and proprietary information that is the property of Synopsys, Inc. The software and documentation are furnished under a license agreement and may be used or copied only in accordance with the terms of the license agreement. No part of the software and documentation may be reproduced, transmitted, or translated, in any form or by any means, electronic, mechanical, manual, optical, or otherwise, without prior written permission of Synopsys, Inc., or as expressly provided by the license agreement. Destination Control Statement All technical data contained in this publication is subject to the export control laws of the United States of America. Disclosure to nationals of other countries contrary to United States law is prohibited. It is the reader’s responsibility to determine the applicable regulations and to comply with them. Disclaimer SYNOPSYS, INC., AND ITS LICENSORS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING,
    [Show full text]
  • Lecture 2 — Software Correctness
    Lecture 2 — Software Correctness David J. Pearce School of Engineering and Computer Science Victoria University of Wellington Software Correctness RECOMMENDATIONS To Builders and Users of Software Make the most of effective software development technologies and formal methods. A variety of modern technologies — in particular, safe programming languages, static analysis, and formal methods — are likely to reduce the cost and difficulty of producing dependable software. Elementary best practices, such as source code control and systematic defect tracking, should be universally adopted, . –Software for Dependable Systems Patriot Missle 1991, Dhahran - Iraqi Scud missile hits barracks killing 28 soldiers - Patriot system was activated, but missed target by over 600m - Floating point representation of 0.1 was cause (rounding error over time, required 100 hours of continuous operation) See: “Engineering Disasters” https://www.youtube.com/watch?v=EMVBLg2MrLs (Image by Darkone - Own work, CC BY-SA 2.5) Unintended Acceleration? (Overview) Braking Problems (Toyota Prius) Drivers reported “sudden acceleration” when braking By 2010, over seven million cars recalled NASA experts called into investigate Specialists in static analysis Their report had significant redactions though Bookout vs Toyota, 2013 Victim’s awarded $1.5million each Barr provided expert testimony See “Unintended Acceleration and Other Embedded Software bugs”, Michael Barr, 2011 See “An Update on Toyota and Unintended acceleration” Unintended Acceleration? (NASA Analysis) Throttle
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Software II: Principles of Programming Languages Introduction
    Software II: Principles of Programming Languages Lecture 5 – Names, Bindings, and Scopes Introduction • Imperative languages are abstractions of von Neumann architecture – Memory – Processor • Variables are characterized by attributes – To design a type, must consider scope, lifetime, type checking, initialization, and type compatibility Names • Design issues for names: – Are names case sensitive? – Are special words reserved words or keywords? Names (continued) • Length – If too short, they cannot be connotative – Language examples: • FORTRAN 95: maximum of 31 (only 6 in FORTRAN IV) • C99: no limit but only the first 63 are significant; also, external names are limited to a maximum of 31 (only 8 are significant K&R C ) • C#, Ada, and Java: no limit, and all are significant • C++: no limit, but implementers often impose one Names (continued) • Special characters – PHP: all variable names must begin with dollar signs – Perl: all variable names begin with special characters, which specify the variable’s type – Ruby: variable names that begin with @ are instance variables; those that begin with @@ are class variables Names (continued) • Case sensitivity – Disadvantage: readability (names that look alike are different) • Names in the C-based languages are case sensitive • Names in others are not • Worse in C++, Java, and C# because predefined names are mixed case (e.g. IndexOutOfBoundsException ) Names (continued) • Special words – An aid to readability; used to delimit or separate statement clauses • A keyword is a word that is special only
    [Show full text]