this is a very good blog post՝ back to basics about strings in C and Pascal. i suggest you to read it, and now i’ll tell you something else:
in Oberon, Wirth decided to give up on Pascal strings, and use zero terminated strings.
however, there is no need to run by the whole array to find out the length of the string. we don’t even need to have a separate field that holds the length՝ compiler knows the length of the static string.
thus it can do compile time tests. for example we have the following Oberon source՝
MODULE tst;
IMPORT Out;
VAR i: SHORTINT;
str: ARRAY 1024 OF CHAR;
BEGIN
FOR i := 0 TO LEN(str) DO
Out.Int(i, 0); Out.Ln
END;
END tst.
lets try to compile it՝
[2020-09-02 16:00:20] $ voc -m tst.Mod
tst.Mod Compiling tst.
9: FOR i := 0 TO LEN(str) DO
^
pos 102 err 113 incompatible assignment
Module compilation failed.
[2020-09-02 16:00:21] $
voc compiles Oberon source to C, which is very good to illustrate what happens. if we have՝
str: ARRAY 16 OF CHAR;
then the output C code will be՝
static CHAR tst_str[16];
nothing more։ no field for the length.
still, this՝
FOR i := 0 TO LEN(str) DO
will translate to՝
tst_i = 0;
while (tst_i <= 16) {
as i said we know the length at compile time. doesn’t matter if you generate C or assembly, you already know the number, you can put the number to the output assembly code as well.
when we write a function which receives strings, we should not knowt the length of the received string, we just use ARRAY OF CHAR
as an argument՝
MODULE tst2;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*;
VAR
s0: ARRAY 32 OF CHAR;
s1: ARRAY 64 OF CHAR;
BEGIN
addStrs(s0, s1);
END test;
END tst2.
therefore C code will be՝
static void tst2_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* here we think we can do smth useful */
}
void tst2_test (void)
{
CHAR s0[32];
CHAR s1[64];
tst2_addStrs((void*)s0, 32, (void*)s1, 64);
}
as we see՝ the function also gets the length of strings. and if we do LEN(a)
we get the length without any calculations.
now let’s see how dynamic strings work՝
MODULE tst3;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*(i: INTEGER);
VAR
s: ARRAY 32 OF CHAR;
ps: POINTER TO ARRAY OF CHAR;
BEGIN
NEW(ps, i);
addStrs(s, ps^);
END test;
END tst3.
now we hase a static string՝ s and we allocate a dynamic string with its pointer ps
.
lets assume we don’t know the size of ps^
string (^
means dereference) and we will receive the length of the allocated string as a function argument. it is not known at compile time.
first function remains unchanged, second function gets translated like this՝
static void tst3_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* do smth useful here */
}
void tst3_test (INT16 i)
{
CHAR s[32];
struct {
ADDRESS len[1];
CHAR data[1];
} *ps = NIL;
ps = __NEWARR(NIL, 1, 1, 1, 1, ((ADDRESS)(i)));
tst3_addStrs((void*)s, 32, (void*)ps->data, ps->len[0]);
}
the _NEWARR
is a bit more complicated function, which is a part of the runtime.
but we can understand what it does՝ it allocates a space in the heap, and the pointer ps
we get now points to the struct
, which has a data
field and len
field.
this is a runtime information, and in this case we have to keep a separate field for the length of the string.
that’s it.
#oberon #c #pascal #wirth #programming #programming-languages #programming_languages #design #implementation #vishap #voc #compiler #compilation #strings #string #heap #stack #storage #storage-management #storage_management #length
Inappropriate deallocation of dynamic storage is a well-known source of catastrophic program failures. In the context of nonextensible applications, such as statically linked programs, this problem can (in theory) be mastered by a careful programmer; for extensible programs, it cannot! There is always the possibility that a module may be added to a program later on; such an extension can introduce additional references to objects of which the implementor of the core modules is unaware. Therefore, Oberon neither requires nor allows explicit deallocation of dynamic storage.
#oberon #gc #programming #programming_languages
The language, however, makes veryfew assumptions about the environment. If not available from a given operating system, dynamic module loading, command invocation, and automaticgarbage collection can be introduced by a small run-time system. In principle, it is possible to forego dynamic loading and to create traditional, staticallylinked applications, but this is anachronistic for the challenges of today’s software systems. Automatic garbage collection is indispensable for reliable,extensible software systems and is probably the biggest culture clash between Oberon and other compiled languages such as Pascal, C, or C++.
#oberon #gc #programming #programming_languages
Modula and Modula-2 went nowhere not because they’re particularly high level languages (they’re not much higher than C!) but because they didn’t have a quasi-free operating system spreading like a virus to bolster their popularity. At the time Unix was almost unique in being a semi-capable operating system written in a portable language that wasn’t wrapped up in billions of proprietary licensing arrangements (because AT&T didn’t notice there was a potential market for it until after the cat had escaped the bag).
#modula #modula-2 #modula2 #c #programming-languages #programming_languages #unix
interesting, important discussion https://github.com/modula3/cm3/issues/42
i think the requestor is right. may be i need tot initialize the array with other values, why spend time to initialize it to zeros?
#programming #programming_languages #modula #modula-3 #design
A good language design may be summarized in five catch phrases: simplicity, security, fast translation, efficient object code, and readability.
http://norayr.am/papers/Hoare_Hints.pdf #hoare #programming_languages #design #programming #computer_science
http://simula67.at.ifi.uio.no/50years/ 50 years anniversary of Simula, the first object-oriented programming language.
#simula #programming-languages #programming_languages #programming
C, Rust, Pascal and Go are the best in terms of energy consumption!
https://jaxenter.com/energy-efficient-programming-languages-137264.html
#golang #c #rust #pascal #energy #programming-languages #programming_languages #programming
TIL swift allows emojis as variables
yes, that’s a very useful feature of the modern languages, and unicode will allow to use one exact symbol instead of =>, <=, and most importantly ==, by mapping keys, so that we’ll avoid problems like if (a=b)
which is always true. (:
#programming #programming-languages #programming_languages #emoji #unicode
@{Antranig Vartanian ; antranigv@spyurk.am} told me that he met Paul Vixie, author of vixie-cron. (: Here, in Yerevan. At some conference. And Paul said that he loves Modula-3 and Wirthian languages. And he was writing in Modula-3 and he has an article about it. http://www.redbarn.org/node/20
#Modula-3 #Vixie #programming_languages #programming #Yerevan
if you are forced to use a subset of the language due to its complexity, then they failed to offer an useful language.
from #oberon room on freenode.
#programming #programming-languages #programming_languages #chat #talk
today we were discussing different spacecraft accidents caused by/related to software, discussed Arian-5 case, and I remembered a Soviet case, where there was a problem with decimal separator and Fortran compiler. Decimal separator in USSR was comma, but in Fortran code it should be the dot.
Also, Fortran compiler did not consider using comma instead of the dot as an error, but as different code. And my friend said - the same is possible to do in C++ - and sent me the illustration.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
if (1,2!=1.2)
{
cout << (1,2) << endl;
}
return 0;
}
if you run it, you’ll get
Hello World
2
(:
#safety #programming #mistakes #safe #c++ #code #example #programming-languages #programming_languages #arian #fortran #source
C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C.
Linus Torvalds, here.
#linus #linus_torvalds #git #programming_languages #programming-languages #c++ #c #programming
very interesting discussion for me https://github.com/modula3/cm3/issues/12
What do you think about implementing properties in Objects?
OBJECT
...
PROPERTIES
intValue : INTEGER READ GetIntValue() WRITE SetIntValue();
I wouldn’t mind adding some things like this as long as they are very obviously simple syntactic sugar for existing operations. This looks like something like that…
shouldn’t it be, though
PROPERTIES
intValue : INTEGER
READ := GetIntValue() : INTEGER
WRITE := SetIntValue(to : INTEGER);
to more closely match the syntax for methods.
Also it won’t work on RECORDs, which is a bit odd.
I suppose it follows the existing property (which I would not want to break) that you can almost always change a T = REF RECORD … to T = OBJECT … without breaking anything, but not the other way around.
#modula #programming #programming_languages #modula-3 #cm3 #modula3 #compiler
i love to read threads like this
#oberon #oberon-2 #programming #programming_languages #history #discussion #usenet
A striking example of this phenomenon has recently been provided by Ada. If Ada is going to provide a standard, that standard had better be unambiguously documented. At least two groups have had a go at it; both efforts resulted in formal texts of about 600 pages, i.e. many times longer than needed to ensure the impossibility of ever establishing firmly that the two documents define the same programming language. The fault of the patent unmanageability of these two documents lies neither with the two groups that composed them, nor with the formalisms they have adopted, but entirely with the language itself: only by not providing a formal definition themselves, could its designers hide that they were proposing an unmanageable monstrum. That Ada will decrease the pain of programming and increase the trustworthiness of our designs to within acceptable limits is one of those fictions for which a military education is needed in order to believe in it.
#ada #programming #dod #design #programming_languages #programming #dijkstra
interest in pascal and haskell rises and fades together with study periods.
#screenshot #programming_languages #ada #pascal #haskell #study #programming
how C evolved http://pastebin.com/UAQaWuWG
so it wasn’t designed from scratch indeed. it had to pass evolutionary process. and that’s not always about best design.
#C #programming #programming_languages
amazing story on how he wrote a C compiler in 40 days: http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html
#compiler #programming #programming_languages #language
I have managed to port Wirth’s PICL language compiler (which generates code for PIC16F84) to GNU/Linux(used voc to compile it), I mean, it’s possible to run it, compile sample programs with it on my desktop. Now need to make some more improvements and write a manual so that people can use it.
#pic #pic16f84 #embedded #embedded_programming #programming #screenshot #compiler #wirth #picl #programming_languages #hardware #hardware_programming #oberon
discussing go, one says:
why this func incTwo(a, b int) (c, d int) not (int c, d) incTwo(int a, b);
and why var v2 string not var string v2;
answer:
because compare
int (*(*fp)(int (*)(int, int), int))(int, int) and f func(func(int,int) int, int) func(int, int) int
#go #syntax #grammar #programming #programming_languages #code #notation
The way they write functional programs for decidedly non-functional problems is through a trick called a monad, which I will not explain and nobody understands anyway, but the point is, in the hands of a very clever programmer, functional programming “can” be used in many more places than you would naively expect.
And that is really the problem. It works at first and then it keeps working until suddenly it doesn’t. And this
communismfunctionalism spreads ideologically until yourcountrycodebase is saddled with debt and nobody can bail you out because you have a lot of monads and nobody can understand them.
#structs #classes #functional_programming #imperative_programming #programming #monads #apple #siwft #programming_languages #software #development #design