Skip to content

Latest commit

 

History

History
43 lines (34 loc) · 1.63 KB

AssignmentFeedback.md

File metadata and controls

43 lines (34 loc) · 1.63 KB
layout title
page
Scala Style Guide

On this page we publish feedback notes which are specific to individual asignments. For feedback which applies to coding style in general, visit the Scala Style Guide wiki page.

Week 3: Object-Oriented Sets (TweetSet)

The following table indicates how often each of the issues occured during this assignment (the Scala Style Guide describes the first 12 issues).

#1 (casts)1 %
#2 (indent)12 %
#3 (line length)37 %
#4 (use locals)0 %
#5 (good names)13 %
#6 (common subexpr)59 %
#7 (copy-paste)54 %
#8 (semicolons)20 %
#9 (print stmts)1 %
#10 (return)0 %
#11 (vars)4 %
#12 (redundant if)0 %
#3.1 (union)52 %

#3.1 Union should be implemented using dynamic method invocation

Instead of implementing union in the base class TweetSet and testing for isEmpty, a more elegant solution is to keep union abstract in the base class and provide an implementation in each subclass:

abstract class TweetSet {
  def union(that: TweetSet): TweetSet
}
class Empty extends TweetSet {
  def union(that: TweetSet): TweetSet = ???
}
class NonEmpty extends TweetSet {
  def union(that: TweetSet): TweetSet = ???
}