this post was submitted on 23 Aug 2023
65 points (94.5% liked)

Programming

17366 readers
454 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

The title would probably be confusing, but I could not make it better than this. I noticed that most programming languages are limited to the alphanumerical set along with the special characters present in a general keyboard. I wondered if this posed a barrier for developers on what characters they were limited to program in, or if it was intentional from the start that these keys would be the most optimal characters for a program to be coded in by a human and was later adopted as a standard for every user. Basically, are the modern keyboards built around programming languages or are programming languages built around these keyboards?

all 37 comments
sorted by: hot top controversial new old
[–] themoonisacheese@sh.itjust.works 31 points 1 year ago (2 children)

Pretty much all programming languages in use today have been invented decades after the keyboard.

The keyboard was originally invented for typewriters, but since they don't interact with anything and are self-contained systems, typewriters don't need their keys standardized. However, the keyboard converged as HP, Brother et al. brought the typewriter forward, especially near the end when typewriters were keyboards connected to printers.

Early computers weren't programmed with keyboards at all and used punch cards to be programmed. As you move forwards with the invention of the computer as we know it today, you find out that the modern keyboard was invented to be able to type most characters in use at the time (a classic example is that the @ sign was used by tellers on tills, to mark stuff like 2 units @ $5 per), and actual standards body such as iso and ANSI simply implemented that.

Early personal computers were not powerful enough to compile programs quickly(and compilers were very expensive), so for a while all programming was done either in assembly, which requires very few special characters, or in higher lever languages by people who could pay to get their programs compiled. These higher lever languages, such as B (precursor to C), were often written right on paper by hand, or by typewriter. After this point, home compilers became more and more accessible (the internet basically guaranteed you could get a compiler if needed), and this was the last point in history you could design a language with characters not present on a standard keyboard (you could still have a nonstandard typewriter, or write them by hand for example). After this and the explosion of home computing, people designed their own languages that they were able to use themselves, using their own keyboards.

Worth noting that there exist languages today that you cannot type, pretty much at all. They are however largely considered esolangs (esoteric languages) and most of their use is relegated to the practice of code-golf, in which a programmer tries to accomplish a task using the fewest bytes. Since the characters on a keyboard make up a fraction of all characters available in Unicode or even just ASCII, these languages try to increase the number of things you can do with a single characters by disregarding the fact you can't type most of them, lowering the amount of bytes one needs to do a task.

An example of this is O5AB1E (pronounced "osable"), which has over 250 single-character commands, such as Δ which "repeats code until 'a' doesn't change".

An example (that you can't type) is: yā<ã.Δ¹sŸèOQ

This program gets an input n and a string of numbers, then outputs the first run in the string that sums to n. The program is explained here

[–] jadero@programming.dev 12 points 1 year ago* (last edited 1 year ago) (1 children)

I'd just like to take a moment to commend you on an absolutely exquisite answer.

Given time, there is a slim chance I could have covered the same ground and no chance that it would have been as clear and concise.

Well thanks, that really made my day.

[–] snowe@programming.dev 0 points 1 year ago (2 children)

An example (that you can't type) is: yā<ã.Δ¹sŸèOQ

I think the only thing here you can’t type is the superscript. The rest is easily typeable, at least on a Mac or a smartphone.

[–] themoonisacheese@sh.itjust.works 1 points 1 year ago (1 children)

Well, soft keyboards thend to do that yeah. But nobody is using a smartphone to program.

The point is that nobody is good enough at 05AB1E to type it by hand, everyone just has an idea of what they're trying to accomplish and copy-pastes commands from the documentation.

[–] snowe@programming.dev 2 points 1 year ago

I wasn’t talking just touchscreen keyboards. On Mac you just hold option and you can type almost all of those letters. I do understand your point though. Thanks for explaining

[–] TerrorBite@meow.social 0 points 1 year ago (1 children)

@snowe @themoonisacheese I can type ¹ on a smartphone pretty easily

[–] snowe@programming.dev 2 points 1 year ago (1 children)

Are you typing the character or using markdown to accomplish that?

[–] TerrorBite@meow.social 2 points 1 year ago (1 children)

@snowe Typing the character. With GBoard it's switch to numbers+symbols then press and hold a number (in this case 1) to access fractions and superscripts.

[–] snowe@programming.dev 1 points 1 year ago (1 children)

Hmm Gboard on iphone doesn't do that. Strange. I can hold plenty of other letters and numbers (like 0 to get °), but not 1-9.

[–] TerrorBite@meow.social 1 points 1 year ago (3 children)

@snowe not sure if this image attachment is going to federate correctly from Mastodon to Lemmy

[–] TerrorBite@meow.social 1 points 1 year ago (1 children)
[–] TerrorBite@meow.social 1 points 1 year ago (1 children)
[–] snowe@programming.dev 1 points 1 year ago (1 children)

Woah that’s cool. Wonder why it’s not on iOS. It’s clearly not a limitation, so I’m just guessing google doesn’t want to.

[–] TerrorBite@meow.social 1 points 1 year ago (1 children)

@snowe a very common reason with Google products, I've found; up to and including not wanting to provide that product anymore.

[–] snowe@programming.dev 1 points 1 year ago

😂 yeah, that's why I've been trying to stop using google entirely, it's just asking to lose data or lose a workflow you use, or whatever. I got sick and tired of it.

[–] snowe@programming.dev 1 points 1 year ago (1 children)

It did not. Cool to see federation between mastodon and lemmy though!

[–] TerrorBite@meow.social 1 points 1 year ago

@snowe It's got its quirks. For example, if I am replying to someone who's not on programming.dev then I have to make sure to tag @programming (or another account on the instance) in order for my post to still federate to your server, otherwise only the person I'm replying to would see my reply and it wouldn't show in comments.

I did discover that adding the tag as a trailing reply to a missing comment thread will cause the entire reply chain to federate, so that's neat.

[–] jflorez@sh.itjust.works 17 points 1 year ago (1 children)

Modern keyboards are an evolution of the old typewriter that existed before computers as we know them and programming as we know it existed, so I would say keyboard came first

[–] sylowosa@lemm.ee 2 points 1 year ago (2 children)
[–] mo_ztt@lemmy.world 4 points 1 year ago* (last edited 1 year ago)

He's not completely, though. @marcos had it right about co-evolution -- leaving aside any issues of internationalization, the layout of letters came from typewriters, but the layout of punctuation available was different on different computers for a lot of the early history of programming. Some of the more extreme examples were the Space Cadet Keyboard used at MIT, and APL which more or less required you to use an APL-specific keyboard in order to be able to access all the special symbols that are part of APL. Here's an APL program:

⎕CR 'ProveNonPrime'
Z←ProveNonPrime R
⍝Show all factors of an integer R - except 1 and the number itself,
⍝ i.e., prove Non-Prime. String 'prime' is returned for a Prime integer.
Z←(0=(⍳R)|R)/⍳R  ⍝ Determine all factors for integer R, store into Z
Z←(~(Z∊1,R))/Z   ⍝ Delete 1 and the number as factors for the number from Z.
→(0=⍴Z)/ProveNonPrimeIsPrime               ⍝ If result has zero shape, it has no other factors and is therefore prime
Z←R,(⊂" factors(except 1) "),(⊂Z),⎕TCNL  ⍝ Show the number R, its factors(except 1,itself), and a new line char
→0  ⍝ Done with function if non-prime
ProveNonPrimeIsPrime: Z←R,(⊂" prime"),⎕TCNL  ⍝ function branches here if number was prime

Things became much more standardized when the IBM PC's keyboard became the norm, and were formalized in 1995 with ISO 9995. Then once it stabilized there was a strong incentive for both language designers and keyboard makers to stick with what everyone was used to so they could keep working with the other. But it wasn't always that way.

Edit: Here's what things looked like on an IBM 3276:

(Full size image)

[–] CrunchyBoy@lemmy.world 3 points 1 year ago* (last edited 1 year ago) (2 children)

Fun fact: the standard qwerty layout was made to slow typewriter typing down by putting common keys off the home row and apart from each other. This was done to prevent the little key arm thingies from colliding and jamming when typing quickly.

EDIT: Apparently this is not a fact

[–] fubo@lemmy.world 6 points 1 year ago (1 children)

The point wasn't to slow down typists, but to reduce the number of bigrams (two-letter sequences) that would be typed with adjacent keys, since that's the specific movement that's most likely to cause the key levers to jam.

[–] preciouspupp@sopuli.xyz 1 points 1 year ago

Not true. The current layout is the result of years of evolution based on feedback by typists and vendors.

[–] fubo@lemmy.world 14 points 1 year ago* (last edited 1 year ago) (1 children)

C supports alternate ways of typing some of its punctuation, for programmers whose keyboards didn't support them all. For example, if you can't type [ ] you can use ??( ??) instead. (There are other ones that use angle brackets, but I can't type them here because Lemmy escapes them incorrectly. Irony.)

https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C


The usual example of a programming language using especially unusual characters is APL, where all built-in functions are all represented by single characters, mostly drawn from mathematical notations, Greek alphabet, and so on. For example, is the "sort" function.

[–] OofShoot@beehaw.org 11 points 1 year ago

Programming languages are build around the standard keyboard. Keyboards had most of the symbols you're thinking of from their typewriter days. You can see most of the special characters in these small typewriters from the mid 1900s.

https://dealdashreviewed.com/wp-content/uploads/2015/02/typerwriter.jpg

https://3.bp.blogspot.com/-gdj1kOXgkTY/UqYxNGAxBBI/AAAAAAAA8T0/DTeg3C_ydXM/s1600/71-6zsvcleL._SL1500_.jpg

With things like electric Wheel Writer typewriters, adding extra keys and symbols were less of a complexity issue and you started to see a few more extra symbols.

https://www.imagine41.com/wp-content/uploads/2016/07/ibm_wheelwriter_2500_002_1.jpg

Recognize that there never has been a hard standard for layouts and symbols, just the industry copying and converging on systems that became popular.

[–] Turun@feddit.de 10 points 1 year ago

Not only do the Languages orient themselves to fit to the keyboard, they pretty much only consider the English keyboard layout.

[–] Die4Ever@programming.dev 8 points 1 year ago (2 children)

I won't consider any keyboard to be designed for programming unless it has dedicated keys for characters like {}()&lt;>_+|&amp;!*:" without needing to hold shift for them

[–] driving_crooner@lemmy.eco.br 4 points 1 year ago

There's "programming" layouts, like dvorak-programming that replace the number rows for special characters and you need to shift to get the numbers.

[–] oktux@lemmy.world 3 points 1 year ago (1 children)
[–] BradleyUffner@lemmy.world 3 points 1 year ago (1 children)

Some of the "toy" languages used for code-golf can use some very non standard characters. Saying "all programming languages" is going to be very restrictive.

[–] jvisick@programming.dev 1 points 1 year ago

That’s a little pedantic, don’t you think?