source: doc/theses/jiada_liang_MMath/conclusion.tex @ 7568e5c

Last change on this file since 7568e5c was 7568e5c, checked in by JiadaL <j82liang@…>, 10 hours ago

Minor update on the thesis (add auto initialization and update future work

  • Property mode set to 100644
File size: 5.4 KB
Line 
1\chapter{Conclusion}
2\label{c:conclusion}
3
4The goal of this work is to extend the simple and unsafe enumeration type in the C programming language into a complex and safe enumeration type in the \CFA programming language while maintaining backward compatibility with C.
5Within this goal, the new \CFA enumeration should align with the analogous enumeration features in other languages to match modern programming expectations.
6Hence, the \CFA enumeration features are borrowed from a number of programming languages, but engineered to work and play with \CFA's type system and feature set.
7
8Strong type-checking of enumeration initialization and assignment provides additional safety, ensuring an enumeration only contains its enumerators.
9Overloading and scoping of enumerators significantly reduces the naming problem, providing a better software-engineering environment, with fewer name clashes and the ability to disambiguate those that cannot be implicitly resolved.
10Typed enumerations solve the data-harmonization problem increasing safety through better software engineering.
11Moreover, integrating enumerations with existing control structures provides a consistent upgrade for programmers and a succinct and secure mechanism to enumerate with the new loop-range feature.
12Generalization and reuse are supported by incorporating the new enumeration type using the \CFA trait system.
13Enumeration traits define the meaning of an enumeration, allowing functions to be written that work on any enumeration, such as the reading and printing an enumeration.
14Using advanced duck typing, existing C enumerations can be extended so they work with all of the enumeration features, providing for legacy C code to be moved forward into the modern \CFA programming domain.
15Finally, I expanded the \CFA project's test-suite with multiple enumeration features tests with respect to implicit conversions, control structures, inheritance, interaction with the polymorphic types, and the features built on top of enumeration traits.
16These tests ensure future \CFA work does not accidentally break the new enumeration system.
17
18The conclusion is that the new \CFA enumeration mechanisms achieve the initial goals, providing C programmers with an intuitive enumeration mechanism for handling modern programming requirements.
19
20
21\section{Future Work}
22
23The following are ideas to improve and extend the work in this thesis.
24\begin{enumerate}
25\item
26There are still corner cases being found in the current \CFA enumeration implementation.
27Fixing some of these corner cases requires changes to the \CFA resolver or extensions to \CFA. %, like compile-time constant-expression evaluation.
28When these changes are made, it should be straightforward to update the \CFA enumeration implementation to work with them.
29\item
30Currently, some aspects of the enumeration trait system require explicitly including the file @enum.hfa@, which can lead to problems.
31It should be possible to have this file included implicitly by updating the \CFA prelude.
32\item
33There are multiple \CFA features being developed i parallel with enumerations.
34Two closely related features are iterator and namespace.
35Enumerations may have to be modified to dovetail with these features.
36For example, enumerating with range loops does not align with the current iterator design, so some changes will be necessary.
37\item
38C already provides @const@-style aliasing using the \emph{unnamed} enumerator \see{\VRef{s:TypeName}}, even if the name @enum@ is misleading (@const@ would be better).
39Given the existence of this form, it is conceivable to extend it with types other than @int@.
40\begin{cfa}
41enum { Size = 20u, PI = 3.14159L, Jack = L"John" };
42\end{cfa}
43which matches with @const@ aliasing in other programming languages.
44Here, the type of the enumerator is the type of the initialization constant, \eg @typeof( 20u )@ for @Size@ implies @unsigned int@.
45Auto-initialization is restricted to the case where all constants are @int@, matching with C.
46As seen in \VRef{s:EnumeratorTyping}, this feature is just a shorthand for multiple typed-enumeration declarations.
47\begin{cfa}
48enum( unsigned int ) { Size = 20u };
49enum( long double ) { PI = 3.14159L };
50enum( wchar_t * ) { Jack = L"John" };
51\end{cfa}
52There are several new features have been proposed or are developing in parallel with enumerations.
53Two closely related features are iterator and namespace.
54
55Enumerating features, and range loops in particular, are currently implemented as loops unique to \CFA enumeration and do not align with the
56general iterator pattern. They can be adapted to the iterator interface when it comes to maturity.
57
58Currently, \CFA implements a namespace feature for enumerated types only. There is recently a proposal by Andrew to
59generalize the concept of namespace to other types. The enumeration scope will be revisited to follow the same semantics
60as other types. Also to improve the granularity of scope control, we propose the following extension:
61\begin{cfa}
62enum E1 { @!@A, @^@B, C };
63enum E2 @!@ { @!@A, @^@B, C };
64\end{cfa}
65Here, @'!'@ means the enumerator is scoped, and @'^'@ means the enumerator is unscoped.
66For @E1@, @A@ is scoped; @B@ and @C@ are unscoped.
67For @E2@, @A@, and @C@ are scoped; @B@ is unscoped.
68Finding a use case is important to justify this extension.
69\item
70An extension mentioned in \VRef{s:Ada} is using @typedef@ to create an enumerator alias.
71\begin{cfa}
72enum(int) RGB { @Red@, @Green@, Blue };
73enum(int) Traffic_Light { @Red@, Yellow, @Green@ };
74typedef RGB.Red OtherRed; // alias
75\end{cfa}
76\end{enumerate}
Note: See TracBrowser for help on using the repository browser.