Past tense of “to cast” in the programming sense

In programming, to cast (also: to typecast) means to convert an object from one type to another (see Wikipedia).

I'd like to know the correct past tense of to cast in this sense. Is it cast or casted?

I'm aware that there is already a similar question: Can “casted” be the past tense of “cast”? However, that question has only one answer mentioning this particular usage of the word, and it doesn't quote any sources.


Solution 1:

Oxford Dictionaries rather tersely states that past and past participle of cast is cast. So:

As a novice programmer, I had blithely cast opaque pointers to pointers of unsigned char to access the raw bytes contained therein.

Solution 2:

At issue here is the fact that programmers often find it beneficial to deliberately go against what would generally be good style.

We mix dialects to match keywords and member names (e.g. those of us who have a dialect in which the spelling is colour will use color to refer to the codes that represent colours and the methods that act upon them), we bastardise orthography to match the legacy of technical limitations of earlier systems (it's traditional to implement façade patterns with facade objects, though there's no good reason for that with modern languages), we mess with typography so that I might say "The method takes two ints and returns another", switching font-style mid-word.

And as such, we do some pretty strange things, due to the fact that we are using English to describe a form of expression that is not English but which does often use English words.

But some of us can also speak and write English reasonably well, so unless we've a reason for writing "close" to the style of a program, we won't. E.g. we'll say int in some contexts and integer in others.

In those contexts where one isn't directly mirroring a given language syntax (including those cases where the language one uses doesn't have a cast keyword, method or function involved in its approach to casting), I would certainly expect cast, rather than casted.

In those contexts where one does, I personally only abuse normal English if it's impossible to do so without altering the word that appears in the code. E.g. if I had a goose class I'd refer to them as gooses because geese changes the word used in the code, but I'd use children rather than childs. Other coders differ in how far they'll do violence to the code or to plain English.

As such, I'd use cast even if there was a cast keyword or function name, like in SQL. Those programmers more prepared to go further from normal English than I am may or may not (there isn't really a need to).

In all, I'd expect to see some people use casted though I wouldn't myself, because it would be in a context where bending the normal rules has a value that makes it worth doing.

And I'd also expect some people to just use it anyway; some people do in the other senses of the word, and while it sounds awkward to me (even though it passes my normal "good enough for Shakespeare, good enough for me" test), there have been lots of other cases where -ed forms of the past tense grew upon verbs that once hadn't had them before, so I wouldn't complain too loudly.

All of which doesn't really give a very firm answer, but then once you're breaking the rules as programmers do with our jargon, you're not going to have a clear rule any more, by definition. I'd summarise as "no, except when they do" and a personal recommendation to use cast oneself.

Solution 3:

CAST is a standard keyword in SQL languages (standard in ANSI SQL since SQL-92, and in other varieties since earlier than that). As a database professional who follows the industry, I see both forms of the past tense being used frequently in the major industry publications and blogs.

Programmers are generally comfortable with this kind of lexical ambiguity. Programming languages themselves often have multiple words to accomplish the same operation. For example, in Microsoft's T-SQL there is a CONVERT keyword that performs the same function as the CAST keyword, but with a different syntax.

Any true-blooded programmer prefers CAST to CONVERT, though, for its brevity and efficiency. Fewer characters counts for points in code golf, and often for better performance in the real world.

Therefore, give the edge to cast over casted, for its equally admirable brevity.

In programmers' terms, you'll be reducing your technical debt.

Solution 4:

I found this thread after flinching at the Qt description of QAbstractNativeEventFilter

On X11, eventType is set to "xcb_generic_event_t", and the message can be casted to a xcb_generic_event_t pointer.

This revealed that I have an innate aversion to "casted" even though I cannot recall trying to use the term in a programming context. Then again, I might hesitate to write "... can be cast to a ..." in case the reader thought I was employing a phonetic trick (sounds like "cassed" or, even, "past").

Being faced with mockery from either direction, I am pleased to have the support of most of the contributions in this thread.

Even "the die is cast" is available to be quoted during an aggressive defence. :)