Imperative programming constructs (C#) Flashcards
What are imperative programming constructs?
Imperative programming constructs are statements or commands in a programming language that are used to control the flow of execution and perform operations on data. They are used to express the logic of the program in a step-by-step manner
Give examples of imperative programming constructs in C#.
- Assigning values to variables
2.Assigning instances to object references - Performing operations on the values
- Calling methods on object references
- Selective execution using if statements and switch statements
- Repetitive execution using for loops, while loops, foreach loops, etc.
What is static type-checking?
It is a process that checks the type of the program during compile time.
The compiler checks whether the types of all variables, functions, and expressions in the program are compatible and will work correctly at runtime.
What are the advantages of static type-checking?
- Errors can be caught at compile-time, before the program is run.
- Can help to prevent type-related bugs and improve code quality.
- Can provide better performance, as the compiler can optimize code based on the known types.
What are the disadvantages of static type-checking?
- Can be more verbose, as types must be explicitly declared.
- Can be more difficult for beginners to understand, as it requires knowledge of type systems.
- Can be limiting in some cases, where dynamic behavior is desired.
What is dynamic type-checking?
It is a process that checks the type of the program during runtime. In a dynamically typed language, the type of a variable or expression is determined at runtime, and the runtime checks if the types are compatible before executing the code.
What are the advantages of dynamic type-checking?
- Can be more concise, as types don’t need to be explicitly declared.
- Can be easier for beginners to understand, as it allows more flexibility in the code.
- Can be useful in cases where dynamic behavior is desired.
What are the disadvantages of dynamic type-checking?
- Errors may not be caught until runtime, which can make debugging more difficult.
- Can be slower in some cases, as the runtime must perform type checks.
- Can be more prone to type-related bugs if not used carefully.
Is C# a static or dynamic type-checking language?
It is a statically typed language, which means that types are checked at compile-time rather than runtime.
What is a strongly-typed language?
It requires that all variables have a declared type and that the operations performed on them are consistent with that type.
This means that type errors are caught at compile-time, preventing potential runtime errors
What are the advantages of strongly-typed languages?
It helps catch errors at compile-time, which can save time and effort in debugging.
It also allows for better code optimization and can improve performance.
What are the disadvantages of strongly-typed languages?
It can be restrictive and can lead to more verbose code.
Give examples of strongly-typed programming languages
- C#
- Java.
What does weakly-typed languages allow?
They allow type coercion.
What does type coercion mean?
It means that a variable can change its type from one to another as needed. This can lead to errors and bugs that may only surface at runtime.
Give examples of weakly-typed programming languages
- JavaScript.
- PHP.