Live data from Hacker News

Giving Ada a Chance

ajxs.me

171–180 of 261 posts

Re: Giving Ada a Chance

#171

Earlier quoted context omitted.

I feel that Python will be known in the future as the language that caused a generation to have a crippled sense of reasoning about how to design computer programs. It's lack of a normal, standard scoping model alone teaches a very flawed reasoning about computer programs.

It's lack of a normal, standard scoping model alone teaches a very flawed reasoning about computer programs. Scoping in class definitions is weird, yes. But is that your complaint? What's wrong with the scoping model in general?

It's not merely that.

That for-loops work by assignment rather than creating a new scope, or that if-conditions do not create a new scope for their arms is most unusual.

Not only does it not teach programmers to properly reason about scope, but it results into subtle bugs that are easy to miss. Consider the following:

  list = []
  for x in iterator:
    list.append(lambda y: some_code_that_closes_over(x))
This almost certainly does not behave as the programmer intended, for the for-loop does not create a new scope, so all iterations of the loop share the same scope, and thus every closure that closes over `x` handles the same `x`, which will have the value that `x` had at the last loop, thus effectively mutating the closure after appending it to the list, so that the list will only contain effectively identical closures.

The proper way do it is by using the fact that functions do create a scope:

  list = []
  def loop_function(x):
    list.append(lambda y: some_code_that_coses_over(x))
  for x in iterator:
    loop_function(x)
Certainly code that looks quite hackey to work around the lack of normal, expected block scoping.

Re: Giving Ada a Chance

#172

> It is possible to define a struct type in C with bit-fields for the individual elements, however the C standard does not guarantee the layout and order of the individual fields. As a professional embedded developer who uses bitfields to access registers every day, this doesn't really make a practical difference. On any bare-metal or embedded project you will rely on the behaviour of your compiler, and portability i…

Having direct control over this type of thing is important when updating the fields of a persistent data structure. I've had to deal with mistake before, where the original developer thought the layout matched what they specified, but the actual layout that got persisted didn't match. For compatibility, the broken layout stuck around forever, and special rules were required to detect this.

Re: Giving Ada a Chance

#174
post #119

I like the "clean feel" of Ada's syntax: it combines the elegance of Python with a bit more structure and does not suffer from Python's significant whitespace issues. The so-called "Ada comb" structure that is used for packages, subprograms, and even declare blocks makes it easy to find what you are looking for because it makes the source code more regular. The "Ada comb" is formed by the shape of the source code wit…

> The so-called "Ada comb" structure that is used for packages, subprograms, and even declare blocks makes it easy to find what you are looking for because it makes the source code more regular. "Declare" blocks are a PITA. I don't mean the declaration part in the subprogram example you quoted (that's fine), but having to use explicit "declare" blocks to create new variables in the scope of a loop or a conditional. Y…

These seem contrived. Ada supports encapsulation, at the procedure or package level. I would just declare up-front the A,B,C,D variables .... I don't see what the begin/end blocks buy you kn these examples.

Re: Giving Ada a Chance

#176

Earlier quoted context omitted.

It's lack of a normal, standard scoping model alone teaches a very flawed reasoning about computer programs. Scoping in class definitions is weird, yes. But is that your complaint? What's wrong with the scoping model in general?

It's not merely that. That for-loops work by assignment rather than creating a new scope, or that if-conditions do not create a new scope for their arms is most unusual. Not only does it not teach programmers to properly reason about scope, but it results into subtle bugs that are easy to miss. Consider the following: list = [] for x in iterator: list.append(lambda y: some_code_that_closes_over(x)) This almost certai…

How about not using lambdas which create accidental closures all over and use partial functions, instead?

    list.append(functools.partial(some_code_that_closes_over, x))
If you replace a lambda with a function definition in the for loop, it's easier to see the scoping issue is actually a closure. And that makes sense because lambda is shorthand for a function.

Re: Giving Ada a Chance

#177
post #39

> I can’t help but think that complicated programming paradigms would seem more intuitive to beginners if taught through Ada instead of C and its derivative languages, as is common in computer science and engineering faculties worldwide. At my university, the first courses you took in CS used Ada. I think it was a really good choice but I was in the minority I guess because after my year they switched to either using…

> People found it frustrating how much work it'd take to get their programs to even compile Makes sense if they're students working on small projects. Ada is explicitly designed to make large programs readable, and willingly trades off on writeability when the two come into conflict. It isn't going to shine if you're writing small 'single shot' applications, that isn't what Ada is for. (Ada also commits to using many…

I really think a semantic facelift would do wonders for ADA, and shouldn't make much of a difference for readability. I know a lot of people are turned off by this.

Re: Giving Ada a Chance

#178
post #154

Earlier quoted context omitted.

One area where I think Ada has the edge is providing language constructs that make bare metal programming safer. Concepts like 'dangling pointers' and 'memory leaks' aren't relevant in a programming environment without a heap. In bare-metal programming on a microcontroller you're more likely working within a flat memory model where the 'memory safety' provided by some modern programming languages is less relevant. Ar…

You can absolutely cause a pointer to dangle without heap allocation. Pointers can point to the stack too. You also have stuff like iterator invalidation, which is sort of a special case of a dangling pointer.

You're absolutely right. Pardon me. I should have written the more specific 'use-after-free'.

Re: Giving Ada a Chance

#179
post #176

Earlier quoted context omitted.

It's not merely that. That for-loops work by assignment rather than creating a new scope, or that if-conditions do not create a new scope for their arms is most unusual. Not only does it not teach programmers to properly reason about scope, but it results into subtle bugs that are easy to miss. Consider the following: list = [] for x in iterator: list.append(lambda y: some_code_that_closes_over(x)) This almost certai…

How about not using lambdas which create accidental closures all over and use partial functions, instead? list.append(functools.partial(some_code_that_closes_over, x)) If you replace a lambda with a function definition in the for loop, it's easier to see the scoping issue is actually a closure. And that makes sense because lambda is shorthand for a function.

Because the code that closes over can be arbitrarily complicated. I simply used code that only called a function with a single argument as a minimal example.

Apart from that, your code technically does not do the same thing as it calls the inner function with two arguments, whereas mine simply discards the second argument.

Re: Giving Ada a Chance

#180
post #39

> I can’t help but think that complicated programming paradigms would seem more intuitive to beginners if taught through Ada instead of C and its derivative languages, as is common in computer science and engineering faculties worldwide. At my university, the first courses you took in CS used Ada. I think it was a really good choice but I was in the minority I guess because after my year they switched to either using…

what school did you go to? My university (Radford) did teach Ada as well the first year, way back in 1999, and switched to Java after it. I liked Ada a lot, but Java gave me employment after school.

They were teaching Ada in the Intro to Computer Science classes at Truman State in the mid-2000's as well. I think they eventually switched to Python sometime after I graduated 2008.
Post reply on HN