Programming languages, like human languages, have idioms; if you use constructions that other people are familiar with you are more likely to be understood, separately from the grammar of the language. This doesn't sound so useful -- wouldn't it be better to just make everything straightforward -- but in coding just as in conversation sometimes you want to express a complex or subtle concept. More importantly, though, idiom helps keep multiple programmers aligned with how the code is expected to work -- so long as they're all using the language in the same way.
Recently I was brought on to a project at work to audit it for places where the code wasn't doing what we thought it was doing. This is not so simple as just reading through 25,000 lines of code written by six authors because that's too much to keep in your head at once. But a first read through did turn up a small handful of places where a data structure did things that were far away from usual coding idiom. One bit in particular did some things that I found surprising and thought would be especially likely to give rise to misunderstandings. Today I went through and looked at the code that used that data structure and sure enough, it expected the data structure to work according to the usual idiom and not the strange one. Clearing up the misconception won't be too hard and maybe the program will work better once I do. Hopefully I can do that in a way that makes it less likely that someone else will have the same misunderstanding in the future.
Recently I was brought on to a project at work to audit it for places where the code wasn't doing what we thought it was doing. This is not so simple as just reading through 25,000 lines of code written by six authors because that's too much to keep in your head at once. But a first read through did turn up a small handful of places where a data structure did things that were far away from usual coding idiom. One bit in particular did some things that I found surprising and thought would be especially likely to give rise to misunderstandings. Today I went through and looked at the code that used that data structure and sure enough, it expected the data structure to work according to the usual idiom and not the strange one. Clearing up the misconception won't be too hard and maybe the program will work better once I do. Hopefully I can do that in a way that makes it less likely that someone else will have the same misunderstanding in the future.
no subject
Date: 2021-09-23 04:51 pm (UTC)