<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}
p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Something I've advocated for a while is that testing gets taught early when working with teaching programming classes. I've seen way too many graduate juniors seeing testing for the first time when they hit the industry. As such it's probably important to look at how we go from no/low ceremony to the next thing. No ceremony with tests, multiple methods with tests, etc. It might be nice to see something like the following just work as part of the considerations of this proposal:<br></div><div><br></div><div>CalculatorTest.java:<br></div><div><br></div><div>Calcluator _calculator;<br></div><div><br></div><div>void addTest() { ... }<br></div><div>void subtractTest() { ... }<br></div><div><br></div><div id="sig57107865"><div class="signature">-- </div><div class="signature">Josh McKinney</div><div class="signature">joshka.net</div><div class="signature"><br></div></div><div><br></div><div>On Thu, Sep 29, 2022, at 3:20 PM, John Rose wrote:<br></div><blockquote type="cite" id="qt" style=""><div style="font-family:sans-serif;"><div class="qt-markdown" style="white-space:normal;"><p dir="auto">On 28 Sep 2022, at 13:49, Remi Forax wrote:<br></p></div><div class="qt-plaintext" style="white-space:normal;"><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:5px;margin-left:0px;padding-left:5px;border-left-color:rgb(119, 119, 119);border-left-style:solid;border-left-width:2px;color:rgb(119, 119, 119);"><p dir="auto"><br></p><div>- We should not be able to declare fields inside a classless class, students strugle at the beginning to make the difference between a field and a local variable. <br></div><div>Every syntax that make that distinction murkier is a bad idea. <br></div><div>So perhaps what we want is a classless container of methods, not a classless class.<br></div><p><br></p></blockquote></div><div class="qt-markdown" style="white-space:normal;"><p dir="auto">Hmmm… That would be an interface. I’ll pull on that thread a little:<br></p><p dir="auto">An interface has no non-static fields and (bonus) its static fields are always constant. So you can teach interface <i>as a container</i> without getting into mutability.<br></p><p dir="auto">Methods would have to be implicitly decorated with <code style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0.4em;padding-bottom:0px;padding-left:0.4em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(247, 247, 247);">default</code> in an anonymous <i>interface</i>.<br></p><p dir="auto">The execution of an instance-main anonymous interface would look almost <i>exactly</i> like that for a class:<br></p><p dir="auto"><code style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0.4em;padding-bottom:0px;padding-left:0.4em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(247, 247, 247);">public static void main(String[] av) { new <ThisClass>(){}.main(); }</code><br></p><p dir="auto">The only difference is the <code style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0.4em;padding-bottom:0px;padding-left:0.4em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(247, 247, 247);">{}</code>. Abstracts would be forbidden in an anonymous interface: Every method has a body, just as every field has an initializer.<br></p><p dir="auto">Bonus: No instance initializers, since it’s an interface. (No constructors either.) So the headaches about initialization-related syntaxes go away without additional special pleading.<br></p><p dir="auto">Objection: <i>That’s no interface!</i> Well, true. Except it is an interface to the system, being a launch point. (Is that just a bad pun?) Also, folks use interfaces today as an idiom for a lightweight container of Java code (at least, I do that).<br></p><p dir="auto">Bonus: If the “instance main” feature is supported <i>only for interface containers</i> then some issues of accidentally creating a main (in existing code) go away, simply because the attack surface (for accidents) gets smaller. Yes, that’s a yucky bonus.<br></p></div></div></blockquote><div><br></div></body></html>