3

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.

  • Cast is pretty much always simply cast regardless of tense, the exception being casting. That said, casted has been around for a long time and wouldn't be misunderstood (though many frown upon it). See this link for some more information. – Doc Jan 17 '14 at 20:54
  • 1
    This is a special sense and a causative one at that. Zero-derived causatives are often regular, even with an irregular intransitive. Like shine, shone, shone (vi) vs shine, shined, shined (vt). So it could be either one. So the correct way to find out is to ask English-speaking programmers which one they use. More on the subject of monosyllabic t/d-final uninflected verbs here (click on -- show quoted text -- to get the context). – John Lawler Jan 17 '14 at 21:03
  • 1
    I would personally use ‘casted’ in the sense of casting someone for a play, or of putting a cast on someone (“They casted him for the role” and “Her leg was casted”), but when coding, I would say, for example, “I cast the float as a string”, and “The float was recast as a string”. – Janus Bahs Jacquet Jan 17 '14 at 21:08
  • @JanusBahsJacquet Interesting. I can’t say casted at all. – tchrist Jan 17 '14 at 21:17
  • I'm not sure I'd ever have used casted myself - it has a distinctly "dated" flavour to me, bordering on the archaic. But it's interesting that this is one of relatively few verbs bucking what I see as a slow but steady drift towards regularising the conjugation. – FumbleFingers Jan 17 '14 at 22:09
3

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.

  • John Lawler is less terse (and, I'd say, more accurate here). – Edwin Ashworth Jan 17 '14 at 23:20
  • @EdwinAshworth Perhaps, although I'd dispute his assertion that "the correct way to find out is to ask English-speaking programmers which one they use." The road to grammar hell is paved with English-speaking programmers... (And the intersection of "people who care about speaking and writing English well" and "programmers" is likely a rather small set.) – Gnawme Jan 17 '14 at 23:32
  • On the other hand, it's specialists who are best at defining terms and usages in their field, in spite of the fact that there will be disagreements and sloppiness even amongst them. Here, there are the already existing versions cast and casted for them to choose between; I can't see that one is inherently 'better' than the other. It seems OD doesn't mention domains (eg fishing, dramas ...). Preferences are often domain-related. – Edwin Ashworth Jan 18 '14 at 10:44
  • All answers have made valid points. Personally, I've chosen to go with "cast". I'll accept this answer because it cites an authoritative source, terse though it may be. – Daniel Wolf Jan 18 '14 at 20:36
  • OED will almost certainly also include 'casted', but perhaps with a usage note. This thread states 'Casted is an old form ... In current usage, however, casted is gaining ground, especially where cast means either (1) to assemble actors for a performance, or (2) to throw out bait and/or a lure on a fishing line. (Both these senses have extended metaphorical uses where casted is likewise used at least some of the time). Many people object to casted, but that doesn’t change the fact that it is catching on and not likely to go away soon.' – Edwin Ashworth Jan 19 '14 at 11:23
2

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.

  • + 1 for useful, relevant information. I disagree, however, that this is a good reason to prefer cast when speaking English rather than programming. – TimLymington Jan 17 '14 at 23:42
  • When speaking English in general, I agree. When speaking English about things other than programming with programmers, I also agree. When speaking English to a philosopher about philosophy, "valid" means something different than it does in common usage. Likewise, when speaking English to a programmer about programming, there are domain-specific contingencies that carry some weight. – Jonathan Van Matre Jan 17 '14 at 23:53
  • First, cast is used in programming in other contexts, and SQL is not the origin of it in this sense, so SQL isn't authoritative. Second, I would certainly write CONVERTed in talking about having used that operation, and I am far from alone in that. Third, true-blooded programmers prefer CAST because it's the standard, more than brevity. Fourth, CONVERT is more flexible, so there are times when it is worth using. – Jon Hanna Jan 18 '14 at 0:42
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.

1

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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.