
Programming Languages as Constraints - akkartik
http://tagide.com/blog/research/constraints
======
AnimalMuppet
Constraints provide freedom.

This is not Orwellian newspeak. In a Turing Machine, everything is possible.
But nobody wants to program in it because it's too hard. Same thing with
assembly. Everything that the CPU can do, you can do in assembly. But everyone
wants out of assembly if at all possible. Why? Because the price for the
freedom was too high.

Same thing with jumping to any line in a program. Sure, there are times when
it could make your life easier, but they aren't very many. And what's horrible
is when someone a decade ago, who doesn't even work there anymore, used it to
make _their_ life easier, and you have to figure out their bit of
"cleverness". It's worth not being able to do that in order to keep that from
being done to you. (This is the way civilized society works, by the way. I
give up the freedom to kill random other people in order to not live in a
society where I worry a lot about random other people trying to kill me.)

Within the constraints ("I can't do X"), you find two kinds of freedom. First,
"I no longer have to worry about somebody else doing X in code that I need to
work on". Second, "I gain Y".

For an example of the second kind, garbage collection means that I no longer
have to keep track of when I should free memory. By giving up something (the
ability to allocate and free memory myself), I gained freedom. This is a net
win _if I don 't need the thing I'm giving up_.

You're not trying to write something specific. Give up the things you don't
need in order to write the program you're trying to write, if doing so reduces
the number of things you have to do in order to write that program. Give up
something you weren't going to use anyway in order to have less that _you_
have to do. That's a win.

~~~
harveywi
> Constraints provide freedom.

For a great video on this, see Runar Bjarnason's talk "Constraints Liberate,
Liberties Constrain"
([https://www.youtube.com/watch?v=GqmsQeSzMdw](https://www.youtube.com/watch?v=GqmsQeSzMdw)).

~~~
Retra
I've been slowly working on writing something up on this subject that shows
how the constraint "energy must be conserved" allows us the freedom to solve a
large number of problems just by describing them in terms of energy. Hopefully
to tease out a more clarity on how we can transform abstract symmetries into
practical solutions to real problems.

~~~
catnaroek
> "energy must be conserved"

I like this analogy! Are you thinking of “energy” as some measurement of the
amount of freedom a specification gives implementors to make their own design
decisions? (Possibly modulo some set of changes deemed “trivial”, like
renaming identifiers, reordering independent statements, etc.)

~~~
Retra
I'm thinking of energy in the physics sense.

~~~
catnaroek
Oh, my bad. I'm certainly aware of the usefulness of the conservation of
energy when you need to relate the initial and final states of a physical
system solely under the action of conservative forces. But I thought you were
talking about using the conservation of energy as an analogy for a strategy
for tackling programming problems.

~~~
Retra
Energy is a linguistic construct for solving problems in abstract models of
reality. That's not too different from how programming works, it's just a
different set of models. Thus energy is just a special case of a more general
problem solving technique which can be employed in other domains.

------
btrask
Okay, libraries can't provide new inabilities. But that's why we have linters,
static analyzers, style guides, compiler options and warnings, and ultimately
code reviews and good taste.

I think the big problem (and sometimes benefit) of old languages is their
culture. For example, C programmers don't trust anything written since K&R.
This is both good and bad. Creating a new language doesn't force existing
communities to change; it means creating a new community and either waiting
for the old ones to die off, or (ideally?) driving them into obsolescence.

I remember when Wikipedia was new and there were lots of studies finding
errors in their articles. Instead of replacing Wikipedia, those techniques for
finding errors were simply incorporated into the editing process (as much as
possible). I wish that as new classes of bugs came onto our radar, we could go
back and refine old code instead of throwing it out with the bathwater. (Even
OpenSSL wasn't beyond saving, judging by BoringSSL and LibreSSL. These
projects still need more work, of course.)

~~~
andrepd
>C programmers don't trust anything written since K&R.

C is one of the most used languages in the world, and the number of
programmers is surpassed perhaps only by a handful of languages. That alone
tells me any generalisation you make about C programmers is most probably
erroneous.

~~~
nickpsecurity
"COBOL is one of the most used languages in the world, and the number of lines
of code is surpassed perhaps only by a handful of languages. That alone tells
me any generalisation you make about COBOL programmers is most probably
erroneous."

One a name and one phrase changed but it's still technically true. Clearly
something wrong with your argument unless you think COBOL is also superior to
other languages due to uptake.

~~~
golergka
Comment you're replying to didn't say anything about C being superior or not.

~~~
nickpsecurity
It implied it had good design or worth vs other languages due to massive
uptake vs other languages.

~~~
KMag
My reading of the OP was just that there are tons and tons of C programmers,
who almost certainly use C for many different reasons, and it's hard to
believe any sweeping generalisation of such a large diverse group.... and
therefore it's difficult to believe that none of the large and diverse number
of C programmers trust anything after K&R.

~~~
andrepd
Yes, that was what I meant to say. Nowhere, of course, did I say anything
about C being good or not.

~~~
nickpsecurity
In that case, I take it back.

------
pjmlp
> The ability to refer to memory addresses (all languages, except the C
> family)

Someone should learn about Algol family of programming languages.

~~~
adrianratnapala
My assumption had always been that our modern languages had already done that
for us, so we don't need to.

But you are right, the original statement is absurd. Ada and (at least Turbo-)
Pascal have pointers. And so does Java.

~~~
pjmlp
Algol, * Pascal, Modula-2, Modula-2+, Modula-3, Oberon, Oberon-2, Active
Oberon, Component Pascal, Ada, D, Swift, Rust

And I am not listing all of them.

~~~
icebraining
Even Python, using ctypes.

~~~
pygy_
LuaJIT's FFI also allows to manipulate and dereference arbitrary pointers.

------
sharpercoder
One inability I am thinking about lately is disallowing primitive types on
public members. Take C#, but properties and methods would only allow returning
and taking class/struct types.

This way you enforce strict use of objects, enforcing expressivity. No more
`double meters` but `Meter meters`.

~~~
14113
How you you encode "dimensionless" quantities within such a system?

~~~
tomsmeding
You have stuff like Integer right? Which doesn't really bring you anything...

