Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.

Share tech news, updates, or what's on your mind.

Sign up to Post

A couple of weeks ago I wrote about the immutable fluent object builder pattern, and how to increase semantic significance and clean code.
 
This is useful in object-oriented programming languages like java, c#, etc.
 
The resulting object builder could have a clean, fluent API that could look like this:
 
final Car pontiacMontana2007 = Car.builder()
.with(Brand.of("Pontiac"))
.with(Model.of("Montana"))
.with(BuildYear.of(2007))
.with(Seats.of(7))
.build();
 
But in many examples of such a builder pattern written in java, the API becomes slightly different, and simultaneously semantically less significant:
 
final Car pontiacMontana2007 = Car.builder()
.withBrand("Pontiac")
.witModel("Montana")
.withBuildYear(2007)
.withSeats(7)
.build();
 
Wait, what? Did the java developers just throw out the data type system, and reduce both Brand and Model to String, and both BuildYear and Seats to int?
 
Yes, yes they did.
 
But why?
 
Well, that's because of limitations forced upon them by the java language developers: in their infinite wisdom, they made the String and Integer classes final. And that means, that a data type for Brand, which SHOULD have subclassed String, CANNOT subclass String.
 
And that unfortunately has lead to 3 solutions:
 
1. Reimplement String in a non-final, extendable way;
 
2. Envelope a String value in a decorator class;
 
3. Give up and just use String.
 
Why am I making this point?
 
Because I want it understood that many design …
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.