IT-Consultant: Charles Pegge > Software Design and Development Issues

Improvements in Programming Languages

(1/8) > >>

Charles Pegge:

There are over 8000 recorded programming languages, past and present, so inventing them is not that difficult.
With many of these languages, just about any computation is possible, but with varying degrees of difficulty and complexity.

What makes a language easy to use? Will it compile and execute efficiently? Is it easy to read, - to trace errors or modify? Can the language be used to develop itself or generate new code?

What are the strengths and weaknesses in moderm programming languages like C++ BASIC Java, Python or XML?

Is it possible to take the best features of all of these languages and meld them into one unified system that is not deficient in any quarter? Would the result be a monster?

These questions, I believe are answerable, when it comes down to specifics, and the possibilities of simplification will become apparent.

This thread is for some dreaming along this theme, and since this site is mostly about PowerBasic, that will be a good starting point.


Charles Pegge:

BASIC and C

Developed in 1963 as a computer science teaching aid, Beginners All-purpose Instruction Code, was designed to make short, easy to understand code that could be picked up rapidly by people with very limited experience.
because it was a compact but complete language, it was widely adopted as a standard for home computers in the late seventies, usually on 8 to 16kbyte ROM. Turn on the computer, and up came the BASIC editor after about 1 second.

With the rise to dominance of the Microsoft based PC, C/C++ became the language of professional software developers and BASIC, as a standard language, supplied with the PC was left to languish in its primitive form.

This gave the opportunity for other developers to come in, but resulted in divergent versions of the language.
Turbobasic, later to become Powerbasic  made its appearance in the late 80s, as an exceptionally efficient and well specified compiler.

In the 90s Windows and its graphical user interface displaced most MSDOS applications and drove the development of BASIC to be able to interface the complex operating system calls needed to drive windows, and interface with windows applications. This required the adoption of a number of C type constructs eg pointers, and passing parameters by value.

But While Powerbasic can do most of the things that C does, it has not gone all the way to acquire fully fledged C++ capabilities. Judging by the misuse of C++, resulting in the massive inflation of code size in Windows based systems, and tangle of complexity, this is quite understandable. Even the C++ Stream library which basically manages strings anf files adds 500k of code to the executable. But C++ has many virtues, that do not lead inevitably to monstrous code.

Anyway here is a cursory list comparing the two languages.

The Virtues of modern compiled BASIC

Keywords with obvious meaning.
Block structured programming.
Rich Kernel of Functions.
Built in Strings handling.
Built in Memory management / automatic garbage collection.
Macros
contains most of the functionality of C

The virtues of C++

Scoping of variables in namespaces and blocks.
Initialisation of variables at declaration.
Encapsulation.
Overloading.
Object Oriented Programming: Inheritance, classes and objects.
elemental enough to form basis of higher level languages.
widely used across many platforms.


Some BASIC vices

verbose syntax.
ad hoc syntax eg File operations.
The name itself: BASIC is sophisticated not basic.


Some C++ vices

confusing use of symbol combinations.
multiple meanings of curly braces - difficult to read.
features leading to bloated code: Templates.
no automatic garbage collection.
lack of intrinsic functions - just about everything requires a library / include.

Combining the languages

Powerbasic already has most of the C capability, using different words/symbols, therefore adopting C++ extensions would not mangle the syntax in any way. In fact it would produce a much clearer expression of the logic by dispensing with many of the confusing symbol combinations, overused in C/C++.


Some weakness in both BASIC and C++

missing interpretive or Just-In-Time compilation capability.
cannot support Functional Programming paradigm.

These are weaknesses that are inevitable in any purely compiled language. For the flexibility that is demanded by many situations, an interpretive layer is required or a Just-In-Time compiler as part of the run-time system. One of the causes of bloating in C++ is trying to make a statically compiled language look flexible. - all variations in parameter types have to be catered for prior to execution. The same is true for BASIC but its generous built-in string handling capabilities, make interpretative operations much simpler to accomplish.

...to be continued...

Charles Pegge:
SIMPLIFYING PROGRAMMING LANGUAGES

Removing unnecessary syntax and structures, makes a language easier to learn and easier to check for errors.

Some radical ideas!

Operator precedence

by observing strict left to right evaluation of an expression, all ambiguities are removed for a minimal cost of a few extra brackets and all ambiguities are removed.
Compilation is simplified.

Control Structures

IF ELSEIF ELSE CASE FOR WHILE REPEAT REDO EXIT can all be replace with a unified construct which simplifies logical checking. It goes something like this:

{
 if a then exit
 if b then
  ...
 end if
 if c then repeat
 if d then goto label
}

..
label:

The curly braces delineate a block.
There is a single line 'if..then' and a multi-line 'if .. then .. end if.'
'exit' forces an early exit to the end of the block.
'repeat' directs the execution back to the beginning of the block
'goto' can be used specifically to jump out of nested blocks or to jump over other blocks.

Thus Occam's razor has been applied and no other control structures are needed.

Not only does this make programming logic cleaner, it also simplifies compilation, which is
essential if Just-in-Time methods are used.

...

Charles Pegge:
< :)> SUPPORTING MARKUP </ :)>

Reserving <> Brackets

There are not enough bracket types in the basic ascii character set to do all the things we need to express. In particular, there is a fundamental conflict between the inequality symbols and brackets used in markup languages, and other uses. Syntactically the simplest way to resolve this is to do away with the inequality symbols and replace them with assembler-like mnemonics thus:

LT <
LE <=
GT >
GE >=
NE <>

also

EQ ==
This does away with the confusion between 'equality' and 'assignment' by reserving '=' exclusively for the latter.


if (a GE 42)and(b EQ 80) then c=4
 
As you can see, the solution is not verbose and in my view reads better.

We now have a pair of symbols which are available exclusively for use as brackets, and no longer need to continually switch contexts. And one of the main uses for these brackets is Markup expressions.


Using markup ro define objects and complex data structures.

It goes without saying that life on the internet without markup languages is almost inconceivable. Within procedural languages too, they could be used for declaring, building and manipulating objects and data structures.

In an interpretive language, objects can be represented in a string, for example:

screwA="_
 <type> screw</>
 <material> steel</>
 <coating> phosphate</>
 <diam>#3.5</>
 <length>#38</>
 <thread> double</>
 <head>
   <shape> bugle</>
  <top> posidrive</>
 </head>
"

Its elements are referred to like this:
 srewA.length
 screwA.head.shape

New objects are created simply by copying the string content:
 new screwB=screwA

which in turn may be modified in several ways:

  screwB.head.top="slotted"   changing a property

  screwB+="<cost>#0.02</>"  adding a property

  screwB.head+="<diam>#6.0</>"  inserting a property

  screwB.head=""  removing a group of properties

If necessary code can also be efficiently embedded in a markup field.

What is proposed here is a very simple form of markup language where attributes are not used within tags. The tags only contain names. And the end tag may or may not contain the name. That is just a matter of clarity.





....

Charles Pegge:
PASSING AND RETURNING PARAMETERS


Functions with default parameters

function CreateWindowX( x=100, y=100, width=512, height=256, sysmenu=0 )
...
end function

various ways to call the function:

  CreateWindowX( )  use all default values

  CreateWindowX( 200, 200 )    set x and y positions only

  CreateWindowX( , , 250, 250 )    set width and height only

  CreateWindowX( sysmenu=1 )    use all the defaulr values except for sysmenu

  CreateWindowX( width=800, x=50 )  use all default values execpt for x and width

Passing blocks of data by reference

For sets of contiguous data.

new a[100]=-1   Create an aray of 100 numbers of value -1
a[10]=1,2,3,4,5,6,7,8,9,10 now put some numbers into the array starting at a[10]
lookat(ref a[12])

...

function lookat(p)
 p[0]?
 p[1]?
 p[10]?
end function

results:
12
13
-1



end function

Returning data by reference

If a block of data is passed by reference, it is possible to write back into any of the elements.
To ensure clarity of intention in the code, any variables that were not created within the function,
should be preceded by set before they are written to.

example:

new vector[100]

vector[1]=1,2,3
addv(ref v[1],2,4,6)
$ Result: `v[1]` `v[2]` `v[3]`  Result: 3 6 9
...

function addv(v,a,b,c)
 set v[0]+=a; v[1]+=b; v[2]+=c
end function






..to be expanded..

Navigation

[0] Message Index

[#] Next page

Go to full version