Lectures: Tuesday, 14:00, S3 (Pavel Ježek)
Labs:
Monday, 12:20, SU2 (Matyáš Brabec)
Thursday, 15:40, SW2 (Filip Kliber)
Page in SIS: NPRG035
Grading: Credit and exam
Table of contents
[in Czech] Zde jsou informace pro studenty anglické paralelky předmětu Programování v jazyce C#. Pro českou verzi si v záhlaví stránky přepněte jazyk do češtiny.
Lectures outline
1. lecture
- Course introduction, exam
- Differences in representation of variables in memory layout in Python, C++ and C# languages
- Differences between reference and value types, passing arguments by value
- Memory overhead of reference types, class
Type record (class),record struct
Materials
2. lecture
- Reminder of the difference between reference and value types, decided at type declaration
- Examples of typically reference or typically of value types
- Implicit typed variables (
var),newwithout type name in the context where it is obvious (parameter, declaration) - Fields vs. properties in types,
readonly - Automatically implemented properties
- Allocation on the GC heap, zeroing memory, constructors, initializers
initproperty setters (C#9),requiredkeyword (C#11)- Primary constructor for
record classandrecord struct - Nullable value types,
is nulloperator
3. lecture
- Reminder of nullable value types
nullin runtime of .NET (CLR) and accessingnullleading toNullReferenceException- Nullable reference types (C#8)
- Duck typing in Python, dynamically typed languages
- Interface in C#, interface table
Iwithin a typeA : Iand finding a method by tracking several pointers in situation likeI i = new A(); i.m1(); - Hiding base methods via
newkeyword and finding a correct method that will be called - The
isoperator andInvalidCastException, including the more recent variantvariable is Type newVariable - Properties (not fields) as part of the contract in interface
4. lecture
- Non-portability (dependency on platform) of compiled C++
- Solving the portability by universal executable (fat binary) on MacOS
- Compilation of C# code (
csc.exe) into (portable) assembly (.dll) to be later JIT (Just in time) compiled on specific platform - Optimization options of JIT or AOT (Ahead of time) compilation
- CIL (Common intermediate language), metadata in assembly
- Running of C# programu using
dotnetcommand and via compiled.exe(windows only) ildasm(part of .NET SDK) ailspy(standalone) tools, debugging information (.pdbfile),.ctor- Inheritance in C#, calling instance methods (hidden
thisparameter) - Abstract class, common ancestor
object, calling a constructor of parent usingbase isoperator,Typetype,GetType()method andtypeofoperator
Recommended Literature
- Joseph Albahari: C# 12 in a Nutshell: The Definitive Reference, O’Reilly Media, 2023 (i.e. on Amazon UK)
- Jon Skeet: C# in Depth (4th Edition), Manning Publications, March 2019 (i.e. on Amazon UK)
- C# Language Specification version 8
Alternatively
- Mark Michaelis with Eric Lippert: Essential C# 5.0, Addison-Wesley, 2013 (i.e. on Amazon UK)
- Jeffrey Richter: CLR via C# (4th Edition), Microsoft Press, December 2012 (i.e. on Amazon UK)
- Christian Nagel, Evjen, Jay Glynn, Karli Watson, Morgan Skinner: Professional C# 4.0 and .NET 4, Wrox, John Wiley & Sons, March 2010 (i.e. on Amazon UK
Practicals outline
1. practicals
- Introductory lecture, credit requirements (also available on this very page), concept of practicals
- Visual Studio and alternatives, ReCodEx, GitLab
- Practicing differences between reference and value types, sizes of variables and instances, alignment/padding, arrays, allocation and layout on heap
- For next week
- (5 points) Word Counting
- (5 points) Word Frequency
2. practicals
- Key aspects of the solution (general)
- functional (within specification)
- effective (within use)
- nice (maintainable, extensible, documented)
- Reading words:
File.ReadAllText(not enough separation of where the data is and how the data is read)
- Where is the data:
File.OpenTextornew StreamReader(orConsole.In,StringReader), asTextReader(and as a counterpart relation betweenStreamWriter,StringWriter,Console.OutasTextWriter)
- How are they read?
- ✖
ReadToEnd(problem with large files) - ✔
ReadLine(possible problem with long lines) - ✔
Read(by characters; note that the function returnsint) - the difference between splitting words (
string.Splitand the variant withStringSplitOptions.RemoveEmptyEntries) and composing words (string += char, respectivelyStringBuilder)
- ✖
- More top-down approach (without technical details)
- some
WordReaderthat can pullstringas words fromTextReader - some
WordProcessor(WordCounter,WordFrequencyCounter) that can take astringas a word and process it (and maybe arrange the output somehow) - some common part (arguments, errors, connections), demonstrated on LineCounter
- some
- Assignment of new tasks Paragraph word count (and input) and To sum, or not to sum (input and output)
- Additional videos:
- xUnit testing framework, integration with VS, creating projects, project reference, writing tests, integration tests,
Assert
- xUnit testing framework, integration with VS, creating projects, project reference, writing tests, integration tests,
3. practicals
- Deadline extension for Paragraph Word Counting and To count, or not to count
- Reminder of
interfaceas specification of a contract and examples - Contract directly in a form of a type (and a difference to python duck-typing)
- Contract using an enumeration type (
enum) (contract, values) - Discussion about possible object-oriented design of first four assignments
interface IWordReaderand implementationWordReaderByLines,WordReaderByClassinterface IWordProcessorand implementationWordCounter,WordFrequencyCounter,ParagraphWordCounter,TableSummarizer- glue-code to connect those by using the interfaces
- What methods should
IWordReaderhave, what is their return type, what parameters, where to read words from? - What methods should
IWordProcessorhave, what is their return type, what parameters, where to write output to? stringvs.string?vs.Token
- For next week
- (4+4 points) fix your solutions of Paragraph Word Counting and To count, or not to count (if it didn’t pass all tests in ReCodExu)
- (5+5 points) submit integration tests in xUnit, nUnit or MSTest framework (at least 10 test scenarios per assignment)
- (0+0 points) improve your solutions of Paragraph Word Counting and To count, or not to count (will be useful for next assignment)
4. practicals
- Different ways of representing user roles in the application
- Using implicit
Typeand object hierarchy, with data and without data - Using
enums, example - Using the explicit
Roleclass, example - Using a more complex object hierarchy, example
- Using interfaces, example
- Discussion about efficiency, clarity, use of individual approaches, control during runtime, during translation
- Using implicit
- Implementation of
TokenandTokenReader, design pattern Decorator/Wrapper, debugging messages using design pattern decorator - Different approaches to check if the character is whitespace and speed differences
ITokenProcessorwhich can process all kinds of tokens sounds like a good idea, but it leads to a bad design and a cumbersome implementation- For next week: (8 points) Text justification
- +3 points for integration tests submitted after the solution
- +5 points for integration tests submitted before the solution (and the solution then passes reasonably well)
Information about the Exam
Primary part of the exam consist of written part including around 6 to 8 questions (which might include sub-questions). Every question has a visible maximal amount of points that can be awarded for the question (=N). For correct answer, the student will receive N points for the question; for incomplete, but overall good answer (i.e. some part of the answer is missing or is incorrect), the student will receive 0.5 * N points; in other cases, the student will receive 0 points (i.e. if the answer is missing completely or is mostly incorrect).
The student can receive up to 10 points from the Exam. The mapping between points and grade is as follows:
| Points from the exam | Awarded grade |
|---|---|
| 10 – 8.5 | 1 |
| 8 – 6.5 | 2 |
| 6 – 5 | 3 |
| 4.5 – 0 | 4 |
The written part of the exam takes up to 150 minutes (i.e. 20 minutes for each question, with 30 minutes extra time). The exam is usually graded the same day. Rarely, the student might be invited to further explain his answers or answer follow up questions. This optional oral part usually takes place online, via Zoom platform. The evaluation is always based on written part of the Exam, which means that student can’t be awarded with more than 0 points for a question without an answer.
For illustration, here follows a list of some exams from previous years:
- 1.2.2021 (PDF)
Requirements for the Credit
In order to receive the credit, it is necessary to fulfill three requirements:
1. Practical Test
Fully implement a simple task within a 3 hour time limit. Takes place during the examination period in computer lab on the local computers. You have five attempts to complete the test in total, but you can attempt the test only three times during the winter examination period (and two times during summer examination period).
2. Final Project
Deadlines:
- Specification: 10. 7. 2026
- Demonstration of the final (fully functional, according to the specification) version of the application, including both user and development documentation.
-
- deadline: 7. 8. 2026
-
- deadline: 4. 9. 2026
-
You can use single project to complete several courses about C# and .NET, if the project is complex enough:
- Requirements for NPRG035:
- Demonstrated before the 1. deadline: 30kB of source code written in the C# language
- Demonstrated after the 1. deadline: 45kB of source code written in the C# language
- Demonstrated after the 2. deadline: 60kB of source code written in the C# language
- Requirements for NPRG035 + NPRG038
- Demonstrated before the 1. deadline: 45kB of source code written in the C# language
- Demonstrated after the 1. deadline: 60kB of source code written in the C# language
- Demonstrated after the 2. deadline: 90kB of source code written in the C# language
Source code is the code you (and only you) wrote in the C# language. Comments and tests are included, but everything has to be reasonable.
Final Project for Advanced C# Programming require additional (nontrivial) usage of features and techniques taught during lectures of that course.
ATTENTION! Personal presentation is part of submission. For the demonstration, prepare some form of presentation where you show the main functions of the program + the main problems solved + an outline of the architecture.
3. Homeworks
During the semester, homework will be gradually assigned for which you will receive points upon completion. Your requirement will be recognized if you earn a sufficient number of points. Earning a larger number of points can help you gain points towards the exam according to the table below. At least 90 points are required to recognize this requirement.
You can find all homework gradually in ReCodEx for NPRG035. NOTE: The standard deadline for tasks assigned is 7 days (i.e., by the start of next week’s practicals)! NOTE: ReCodEx only evaluates functional requirements resulting from the assignment. However, the unspecified part of the assignment includes requirements beyond just the functionality of the program (e.g., design, decomposition, testing, …).
Warning: Homework is an independent task aimed at assessing the student’s ability to independently develop a complex program in C#. If it is found that a student submitted someone else’s solution (e.g., several students submitted different instances of the same solution for one homework assignment, etc.), it will be considered a cheating attempt. All such students will not pass the NPRG035 course this academic year and will lose the opportunity to recognize completed obligations next year; disciplinary action may also be recommended for their expulsion from study by the UK MFF disciplinary committee!
Using external sources to solve homework (StackOverflow, ChatGPT, …) is only allowed in the manner explained in the first exercise and with a citation of the source (StackOverflow answer, ChatGPT chat). Not citing the source, and thus presenting someone else’s code as your own, is also considered a cheating attempt, with the above implications.
You can earn points towards the exam for an above-standard number of points from the assignments, as follows:
- min. 90 points = “I Can Win” level → one of the requirements for credit fulfilled, specifically the “exercise requirements” point
- min. 110 points → gaining 1.25 strong points towards the NPRG035 exam
- min. 130 points = “Hardcore” level → gaining an additional 0.75 strong points towards the NPRG035 exam
- min. 160 points = “Nightmare!” level → gaining 0.5 weak points towards the NPRG035 exam
- min. 210 points = “Mission Impossible” level → gaining another 0.5 weak points towards the NPRG035 exam
- min. 252 points = “divine level” → for 1 year, the title “goddess of all Csharpism” or “god of all Csharpism” is conferred
Therefore, up to 2 strong bonus points and up to 1 weak bonus point can be earned towards the NPRG035 exam (see slides from the first lecture for exam evaluation). Note — these strong bonus points will only be counted during the 1st attempt at passing the exam (i.e., in their 2nd or 3rd attempts, everyone has 0 strong bonus points). There is no distinction as to why a student comes to the 2nd or 3rd term (i.e., whether they declined a grade in the 1st term). Weak bonus points will be counted in all attempts to pass the exam in that year, but note: weak bonus points cannot break the barrier between grades 4 and 3 (i.e., if after adding strong bonus points the grade still comes out as 4, then weak bonus points are not counted in the exam result). Bonus points are only counted in the year in which the student earned them.
Note: Virtual exercises are intended for students who do not wish to attend exercises (e.g., because last year they only needed to finish the credit program, pass the credit test, etc.).
Acknowledgement of requirements from past years
If the student was enrolled in this course during the last academic year and fulfilled only some of the requirements for the credit, the teacher can, upon student’s request, acknowledge the fulfillment of requirement from the last year (homeworks, Practical Test or Final Project). The topic (specification) of Final Project does not need to be acknowledged by new teacher. If the student succeeded in the exam, but didn’t receive the credit, it is possible, upon student’s request, acknowledge the result of the exam. This is a good will of teachers of this course and students can’t enforce this on study department!

