Re:Why Crystal Is My Next Language
by sriram_malhar on Monday June 11, 2018 @12:47PM
(#17285971)
Wut?
What he said. Turbo Pascal 7 a better designed language than Go, for the most part.
Re:Why Crystal Is My Next Language
by sriram_malhar on Monday June 11, 2018 @10:51PM
(#17290361)
I'd like an example or two.
Enumerations in Turbo Pascal
type Colours = (Red, White, Blue);
Enumerations in Go type Colours int
const (
Red Colours = iota
White
Blue
)
FFI in Turbo Pascal function Sin(const num: Integer): Double; external 'ext name';
FFI in Go (requires external help from a C compiler) // #include <stdio.h>
// #include <errno.h>
import "C"
func Sin (num uint) float32 {
return C.sin
}
Reference parameters in Turbo Pascal with null safety thanks type system procedure Swap(var a,b:Integer);
var
temp: Integer;
begin
temp:=a;
a:=b;
b:=temp
end;
Swap(x, y)
Swap(nil, y) { compiler error: Got "Pointer" expected "SmallInt" }
Reference parameters in Go (no type safety via type system, manual testing for nil required) func Swap (a *int, b*int) {
var temp = *a
*a = *b
*b = temp
}
Swap(&x, &y)
Swap(nil, &y) { runtime error: Invalid memory address or nil pointer dereference }
I was also tempted to move the time scale from 1992 to 2009, but then I wouldn't be able to reproduce the generics from Object Pascal in Go.Ah, and Turbo Pascal 5.5 was compiling around 34 000 lines/minute in computers whose CPUs were maxed at about 30 MHZ, http://edn.embarcadero.com/article/20803
Re:Why Crystal Is My Next Language
by YouAreGreat on Tuesday June 12, 2018 @06:40AM
(#17292102)
The way I remember it, Pascal enums were useless.
Regarding nil safety, did Pascal allow something along the line of the following?
var x: ^int;
...
x^ := nil;
Swap(x^, y)Useless to those that didn't understood how to take advantage of them.
They can be used as indexes, range validation, access control in variant records to simulate sum types.
Enumerations are so useless that majority of modern languages have direct support for them.
Yes, it did allow your contrived example, which seldom occurred in practice because proficient Pascal programmers only used pointers when other type safe alternatives weren't possible.
Even the last version of Turbo Pascal for MS-DOS (7.0) was more feature rich, ignoring the lack of GC for a moment.