Paving the on-ramp
Josh McKinney
java at lists.joshka.net
Fri Sep 30 00:49:09 UTC 2022
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:
CalculatorTest.java:
Calcluator _calculator;
void addTest() { ... }
void subtractTest() { ... }
--
Josh McKinney
joshka.net
On Thu, Sep 29, 2022, at 3:20 PM, John Rose wrote:
> On 28 Sep 2022, at 13:49, Remi Forax wrote:
>
>>
>>
>> - 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.
>> Every syntax that make that distinction murkier is a bad idea.
>> So perhaps what we want is a classless container of methods, not a classless class.
>>
>>
> Hmmm… That would be an interface. I’ll pull on that thread a little:
>
> An interface has no non-static fields and (bonus) its static fields are always constant. So you can teach interface *as a container* without getting into mutability.
>
> Methods would have to be implicitly decorated with `default` in an anonymous *interface*.
>
> The execution of an instance-main anonymous interface would look almost *exactly* like that for a class:
>
> `public static void main(String[] av) { new <ThisClass>(){}.main(); }`
>
> The only difference is the `{}`. Abstracts would be forbidden in an anonymous interface: Every method has a body, just as every field has an initializer.
>
> 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.
>
> Objection: *That’s no interface!* 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).
>
> Bonus: If the “instance main” feature is supported *only for interface containers* 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20220929/56b7cef1/attachment.htm>
More information about the amber-spec-observers
mailing list