Pitch: dowhatiwant keyword

Swift programmers frequently encounter programming problems that require writing lots of code. Writing code is hard and boring. From a pedagogical perspective, teaching people how to write lots of code takes up time that could be spent bikeshedding the syntax of an important new language concept, finishing that novel you always wanted to get around to, or feeding your carnivorous plants.

Introduction

I propose a new keyword spelled dowhatiwant. Many proposals have been written over the years to make Swift easier and more powerful. The problem is that they only tackle one feature at a time. The dowhatiwant keyword subsumes all of these features, presenting a much simpler and more comprehensive solution that drastically reduces the amount of code written as well as making the language much easier to understand. With less code, the chances of introducing bugs are greatly reduced, and with so little to complain about, even Siracusa might be sort of happy with it.

Motivation

Writing in code-maker make head hurt. Internet not help. But dowhatiwant do it for me.

Proposed solution

By writing the following code:

/*
Copyright 2019 my 90s Quake handle ^_sKuL_kULLeCtOr_^

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

dowhatiwant

At this point, the compiler generates the necessary code.

Detailed design

The details of the implementation are an implementation detail. Describing those details would violate the spirit of this pitch. Therefore, they are necessarily left up to the compiler team. They can update the implementation details whenever they want to take advantage of sick new technologies, leading to the illest apps. Your friends will be all, "How did you write this app?" and you'll give them a knowing wink, and they won't know why you did, but you will.

Source compatibility

I thought about this a little bit in the shower where I got my last five great ideas, and I couldn't think of anything that would break, so it's totes an additive feature.

Examples

The classic Currency Converter sample application can be replaced with the following:

dowhatiwant

Teachers will love the ease of grading assignments from students, which will typically take the form:

dowhatiwant

With this feature, responding to the hard problem of consciousness is no problem for the Swift compiler:

dowhatiwant

Errors are handled as follows:

dowhatiwant
dowhatiwant
^--------------- Error: I already did that.

Alternatives considered

Teaching programmers about algorithms, program design, and, what's that term called, first principles

This solution carries with it an enormous degree of time and energy overhead. Besides, a comprehensive playground that teaches these concepts, grades them, and charges the appropriate fees can be written as follows:

dowhatiwant

The credit card processing service can be written similarly.

Different spellings

A cursory survey of developers resulted in 5,472 alternate spellings, including but not limited to:

doitforme
doitnow
insertcodehere
makemycode
finishcopland
feedmeseymore
besuretohitsubscribeandSMASHthatlikebutton

followed by 5,465 comedy emoji spellings.

Effect on Swift itself

Naturally, with so little Swift code being written, the next step will be to deprecate the entirety of the language and encourage users to adopt the new keyword going forward, providing a migration step in Xcode to ease the transition. Future updates to the compiler can take advantage of the new language feature as follows:

dowhatiwant
13 Likes

This would make self-hosting easier…

9 Likes

Doing what any particular person wants strikes me as a particularly unsafe language feature. Given the copious existing research on this topic, fulfilling the half-baked wishes of specific individuals would initially result in a series of amusing shenanigans, but as the intertwined consequences/counterwishes inevitably escalate in scope, amusement would quickly turn into horror, ultimately ending in some self-inflicted global catastrophe.

As Swift is to be a safe language, perhaps we would be better off implementing a slightly modified approach:

dowhatweneed

If correctly implemented, this will never have any other result than the compiler destroying itself the first time this construct is used in a program. Therefore, it's relatively easy to implement and to test -- certainly much easier than the dowhatiwant variant.

14 Likes

An amendment to the pitch is currently in the works to incorporate the latest feedback. The new keyword will be called:

dowhatideserve

This should mitigate concerns over the global consequences of giving users what they want. It will also improve the quality of the App Store by dishing out some much-deserved rewards or punishments from an objective, authoritative source.

The compiler work for determining what users deserve is implemented as follows:

dowhatiwant
5 Likes

This seems like a reasonable compromise, as long as we follow existing custom and add an unsafe prefix to the unsafe construct:

_unsafelydowhatiwant

To prevent misuse, I believe this should be an internal facility that's only available to stdlib developers.

6 Likes

+1 To this version. This is a feature I've been waiting on since at least 1998.

3 Likes

I'm generally +1 on this, but I think you should consider camel case for the keyword name, and may want to require parens afterward to allow parameterizing the expansion in future releases.

Should we sugar this further by introducing an emoji keyword?

3 Likes
Terms of Service

Privacy Policy

Cookie Policy