Is Objective-C a 3GL or 4GL? - objective-c

I'm having a little debate with a friend about Objective-C being a 3GL but he believes it is a 4GL because descriptors make the language english like.
I disagree with this and I know it is sometimes a fine line.
Is Objective-C a third generation language or a fourth generation language?
References to support your answer will be appreciated.

According to the wikipedia definition of a 4gl language:
"A fourth-generation programming language (1970s-1990) (abbreviated 4GL) is a programming language or programming environment designed with a specific purpose in mind, such as the development of commercial business software[1]. In the evolution of computing, the 4GL followed the 3GL in an upward trend toward higher abstraction and statement power. The 4GL was followed by efforts to define and use a 5GL."
Objective-C is definitely not 4gl. It is a superset of C with full object oriented support and dynamic binding. Although mainly used to develop on OS X systems it can be used on *nix as an alternative to c++.

Related

Are there any C-like (in syntax) scripting languages other than JavaScript and PHP?

I am looking for a general-purpose (considering PHP is actually made and initially meant (I understand they are be used different ways some times) for server side Web and JavaScript for client-side web) with C/C++/C#/Java-like syntax. Do you know of such?
Mythryl is a general-purpose scripting languages deliberately designed around C syntax.
Perhaps Pike with Fins
There's also Ch, an embeddable C/C++ interpreter.
Just look through the Comparison of programming languages, and see which ones fit your needs best. You might look at the language with dynamic Type Systems, because those are scripting languages. Hyped languages include Scala, Ruby (with the Ruby on Rails web framework), Groovy and others, if you need a start.
In general, Wikipedia's C language entry lists many: "C has directly or indirectly influenced many later languages such as Java, Perl, Python, PHP, JavaScript, LPC, C# and Unix's C Shell"
Specifically, for general-purpose "scripting" language that is very similar to C, I would strongly recommend Perl which fits the bill perfectly.
Perl's syntax (or at least a sub-set of it) is VERY C-like (to the point that ex-C programmers starting in Perl are unfortunately known to code in "C-ish Perl" style which is pretty much straight up C).
In additional to general syntax ideas, Perl supports a vast majority of C system functions and many other C-isms (e.g. fully functional printf, process control and IPC).
Perl these days is definitely a general purpose language - it is used for anything from web development (including modern frameworks like Catalyst MVC, Plack etc...), to enterprise software development including full blown servers, to system administration scripting and general "scripting" glue tasks.
In addition, it supports both Object Oriented programming (either using classic Perl OOP or using modern Moose), as well as functional programming.
Please note that when evaluating Perl, you should not rely on the numerous myths that exist out there - most of these are due to either people not being sufficiently familiar with Perl, or judging Perl based on a large mass of poor-code-quality dirty scripts written by system administrators who weren't software developers, or judging Perl based on its features in Perl versions that were popular 15 years ago (e.g. any criticism of Perl OOP circa 1998 is pretty much useless unless the person doing it is closely familiar with Moose).
P.S. Since your questions seems to be in "...coming from PHP" context, you should also note that PHP is in fact very similar to a subset of Perl - by design. To quote from php.net:
The syntax itself was similar to that of Perl, albeit much more limited, simple, and somewhat inconsistent.
Matter of fact, PHP started out as a collection of Perl CGI scripts.
I am currently working on a new project called Cpy, using Python's execution engine, but wrting codes in C-syntax. It is built with ANTLR and Python. Take a look at it: http://www.ideawu.com/cpy/
Pawn. Not general purpose (depending on your definition) but very good as a small embedded language.

Alternatives to Object-Oriented Programming?

OOP is probably the most used programming paradigm in today’s software design. My question is – what other paradigm(s) can compete with it and can stand in the place of OOP? To clarify that question, I’m not asking about what other paradigms there are. There are many of them, but I’d like to know which one…
Has been used in practice, not only in theory.
Can compete with OOP, so it can be used in a large project with a minimum of pain.
Can be used to develop a desktop app with business logic, databases, and so on.
Is not used alongside OOP, but as a replacement for OOP.
And if there is any, what are the pros/cons of it, why it is better/worse than OOP, what languages are the best to use it, what about using it in popular languages, has it any design patterns, and can it totally replace OOP?
Functional programming is another programming paradigm that is popular, mostly in academics. The best example of a functional programming language is Haskell and Standard ML.
The fundamental difference between functional programming and object oriented programming is that you are programming in the sense of data flow instead of control flow. See the presentation Taming Effects with Functional Programming by Simon Peyton-Jones for a good introduction.
A good example of functional programming used in the industry is Erlang. It is mostly used in telecommunication, distributed and fault tolerant systems. See the presentation Erlang - Software for a concurrent World by Joe Armstrong.
There are also newer functional programming languages that combine functional programming with OOP. Two good examples are F# for the .NET platform and Scala for the Java platform; they can often use existing libraries on the platform written in other languages.
The trend of new programming languages now is Multi-paradigm, where multiple paradigms like object oriented programming and functional programming are combined in the same language.
Procedural processing was everything before OOP turned up, has produced some large real world applications (in fact, most of them originally) and many operating systems.
It can certainly be used in large scale products with a minimum of pain, and a maximum of performance
First of all please note that many of the programming languages currently in use (especially "higher level languages") are multi-paradigm. That means you are never building programs which are purely OOP (except if you use Smalltalk or Eiffel to build your big projects maybe).
Have a look at PHP for instance:
Has many elements of OOP (since version 5)
Was mostly procedural before
Has elements of declarative programming (e.g. the array functions)
Implemented many elements of functional programming (since version 5.4)
Basically PHP is gluing a lot of different paradigms together (and is a "glue language" itself).
Also Java implements a lot of concepts which are not from the Object-Oriented paradigm (e.g. from functional programming).
Have a look on the list of programming languages by type in Wikipedia: https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Imperative_languages (not 100% accurate).
Functional programming (subset of declerative programming)
Wideley used in practice (it became part of glued languages like PHP, also Java and many others have implemented concepts of functional programming)
Many ideas originate in LISP which is definitely worth a look
You can build whole applications e.g. with Haskell therefore it can "replace" OOP
Procedural programming
C (as a mostly procedural language) is still one of the most widely used languages
Many modern glue-languages were procedural in the beginning
Still many programs are mostly procedural (so if you want it can "replace" OOP)
Logical programming
Most prominent example is Prolog. This is used for specific tasks that benefit from rule-based logical queries
Can not "replace" OOP in terms of building a large project but may replace it in other terms
Declarative / Domain-specific languages in general
Using SQL in your projects? Then they are not purely OOP, SQL is essentially declarative.
Many domain-specific languages (like CSS) are declarative
Imperative programming in general
Tons of applications are not "object-oriented" but simply written in imperative style (e.g. assembly)
Look here for a great thread: https://softwareengineering.stackexchange.com/questions/117092/whats-the-difference-between-imperative-procedural-and-structured-programming
This list is not complete it shall just give an idea. Just note that you usually are using a lot of different paradigms when writing a big application and even each language you are using is implementing multiple paradigms.
OOP is usually considered a good choice for structuring large, complex relationships when modelling data. It is not always the paradigm to go with for many other tasks.
Vector Relational Data Modeling is used to create executable information models with domain relevant semantics within the Global Information Network Architecture, a network resident model broker.
FP - Functional Programming is an extremely popular programming paradigm that has been around for a very long time and has, in more recent years, started becoming more and more prominent. FP favors immutability over mutability, recursion, and functions with no side effects. Some examples of popular fp languages are Erlang, Scala, F#, Haskell and Lisp (among others).
There are no paradigms currently that can genuinely replace OOP. The issue with (benefit of) OOP is that it does a vast amount of work for you- automatically releasing resources, validating data, etc, and it makes it easy to validate code- not to mention that the vast majority of the world's existing libraries are written in an OOP language like C++, C# or Java. The reality of getting along without such large-scale libraries and such is exceedingly doubtful.
In niche or academic worlds, you'll find a lot of Functional Programming. However, if you really want to do a large project, OOP is the only way to go.
I think that generic programming is going to come up as a new paradigm. However, it's really still in the development phase and only C++/D offer genuinely good generic programming.

Why are the interpreters of all popular scripting languages written in C (if not in C at least not in C++)?

I recently asked a question on switching from C++ to C for writing an interpreter for speed and I got a comment from someone asking why on earth I would switch to C for that.
So I found out that I actually don't know why - except that C++ object oriented system has a much higher abstraction and therefore is slower.
Why are the interpreters of all popular scripting languages written in C and not in C++?
If you want to tell me about some other language where the interpreter for it isn't in C, please replace all occurences of popular scripting languages in this question with Ruby, Python, Perl and PHP.
C is a very old language, and is thus supported on pretty much every system available. It is therefore a good choice for any project that needs to be ported everywhere.
Ruby dates back to 1995. If you were writing an interpreter in 1995, what were your options? Java was released in the same year. (And was painfully slow in v1.0 and in many ways, not really worth using)
C++ was not yet standardized, and compiler support for it was very sketchy. (it had also not yet made the transition to the "modern C++" that we use today. I think the STL was proposed for standardization around this time as well. It didn't actually get added to the standard until years later. And even after it was added, it took several more years for 1) compilers to catch up, and 2) people to get used to this generic programming style. Back then, C++ was an OOP language first and foremost, and in many cases, that style of C++ was quite a bit slower than C. (In modern C++ code, that performance difference is pretty much eliminated, partly through better compilers, and partly through better coding styles, less reliance on OOP constructs and more on templates and generic programming)
Python was started in 1991. Perl is even older (1987)
PHP is from 1995 as well, but additionally, and importantly, was created by a guy who knew virtually nothing of programming. (and yes, of course this has shaped the language in many important ways)
The languages you mention were started in C because C was the best bet for a portable, future-proof platform back then.
And while I haven't looked this up, I'm willing to bet that apart from the PHP case, which is shaped by incompetence more than anything, the language designers of the other languages chose C because they *already knew it. So perhaps the lesson is not "C is best", but "the language you already know is best"
There are other reasons why C is often chosen:
experience and accessibility: C is a simple language that is fairly easy to pick up, lowering the barrier of entry. It's also popular, and there are a lot of experienced C programmers around. One reason why these languages have become popular might just be that it was easy to find programmers to help developing the interpreters. C++ is more complex to learn and use well. Today, that might not be so much of a problem, but 10 or 15 years ago?
interoperability: Most languages communicate through C interfaces. Since your fancy new language is going to rely on components written in other languages (especially in early versions when the language itself is limited and has few libraries), it's always nice and simple to call a C function.So since we're going to have some C code anyway, it might be tempting to go all the way and just write the whole thing in C.
performance: C doesn't get in your way much. It doesn't magically make your code fast, but it allows you to achieve good performance. So does C++, of course, or many other languages. But it's true for C as well.
portability: Practically every platform has a C compiler. Until recently, C++ compilers were much more hit and miss.
These reasons don't mean that C is in fact a superior language for writing interpreters (or for anything else), they simply explain some of the motivations that have caused others to write in C.
I'd guess it's because C is pretty much the only language that has a reasonably standard compiler for almost every platform in existence.
I would hazard a guess that it's in part due to 1998 C++ not being standardized until 1998, making achieving portability that much harder.
All those languages you list were developed before that standardization.
Why are the interpreters of all popular scripting languages written in C and not in C++?
What makes you think that they are written in C? In my experience, the majority of implementations for the majority of scripting languages are written in languages other than C.
Here's a couple of examples:
Ruby
BlueRuby: written in ABAP
HotRuby: JavaScript
Red Sun: ActionScript
SmallRuby: Smalltalk/X
MagLev: Ruby, GemStone Smalltalk
Smalltalk.rb: Smalltalk
Alumina: Smalltalk
Cardinal: PIR, NQP, PGE
RubyGoLightly: Go
YARI: Io
JRuby: Java
XRuby: Java
Microsoft IronRuby: C#
the original IronRuby by Wilco Bauwer: C#
Ruby.NET: C#
NETRuby: C#
MacRuby: Objective-C
Rubinius: Ruby, C++
MetaRuby: Ruby
RubyVM: Ruby
Python
IronPython: C#
Jython: Java
Pynie: PIR, NQP, PGE
PyPy: Python, RPython
PHP
P8: Java
Quercus: Java
Phalanger: C#
Perl6
Rakudo: Perl6, PIR, NQP, PGE
Pugs: Haskell
Sprixel: JavaScript
v6.pm: Perl5
Elf: CommonLisp
JavaScript
Narcissus: JavaScript
Ejacs: ELisp
Jint: C#
IronJS: F#
Rhino: Java
Mascara (ECMAScript Harmony Reference Implementation): Python
ECMAScript 4 Reference Implementation: Standard ML
The HotSpot JVM is written in C++, the Animorphic Smalltalk VM (from which HotSpot and V8 are derived) is written in C++, the Self VM (on which the Animorphic Smalltalk VM is based) is written in C++.
Interestingly enough, in many of the above cases, the implementations that are not written in C, are actually faster than the ones written in C.
As an example of two implementations that are written in C, take Lua and CPython. In both cases, they are actually written in a small subset of a very old version of C. The reason for this is that they want to be highly portable. CPython, for example, runs on platform for which a C++ compiler doesn't even exist. Also, Perl was written in 1989, CPython in 1990, Lua in 1993, SpiderMonkey in 1995. C++ wasn't standardized until 1998.
The complexity of C++ is great compared to that of C - many people consider it one of the most complex and error prone languages in existance.
Many of the features of C++ are problematic as well - the STL was standardized many years ago and it still lacks one great implementation.
OOP is certainly great, but it does not outweigh C++'s deficiencies in many scenarios.
Most known compiler books are written with examples in C.
Also two of the major tools lexx (builds a lexer) and yacc (Translates a grammar to C) have support for C.
If the question is about why C and not C++ the answer comes down to the fact that when you implement a scripting language the C++ object model comes into your way. Its so restricted that you will not be able to use it for your own objects.
So you can only use this for the internals and they there you usually do not get enough benefits from C++ over the much simpler C language, which makes it easier to port and distribute.
The only problem when implementing a script language in C are missing coroutine support (you have to switch your stack pointer in some way) and most important there is no way to do exception handling without a lot of overhead (compared to C++).

Methodologies for designing a simple programming language

In my ongoing effort to quench my undying thirst for more programming knowledge I have come up with the idea of attempting to write a (at least for now) simple programming language that compiles into bytecode. The problem is I don't know the first thing about language design. Does anyone have any advice on a methodology to build a parser and what the basic features every language should have? What reading would you recommend for language design? How high level should I be shooting for? Is it unrealistic to hope to be able to include a feature to allow one to inline bytecode in a way similar to gcc allowing inline assembler? Seeing I primarily code in C and Java which would be better for compiler writing?
There are so many ways...
You could look into stack languages and Forth. It's not very useful when it comes to designing other languages, but it's something that can be done very quickly.
You could look into functional languages. Most of them are based on a few simple concepts, and have simple parsing. And, yet, they are very powerful.
And, then, the traditional languages. They are the hardest. You'll need to learn about lexical analysers, parsers, LALR grammars, LL grammars, EBNF and regular languages just to get past the parsing.
Targeting a bytecode is not just a good idea – doing otherwise is just insane, and mostly useless, in a learning exercise.
Do yourself a favour, and look up books and tutorials about compilers.
Either C or Java will do. Java probably has an advantage, as object orientation is a good match for this type of task. My personal recommendation is Scala. It's a good language to do this type of thing, and it will teach you interesting things about language design along the way.
You might want to read a book on compilers first.
For really understanding what's going on, you'll likely want to write your code in C.
Java wouldn't be a bad choice if you wanted to write an interpreted language, such as Jython. But since it sounds like you want to compile down to machine code, it might be easier in C.
I recommend reading the following books:
ANTLR
Language Design Patterns
This will give you tools and techniques for creating parsers, lexers, and compilers for custom languages.

Do high-level programming languages tend to be object-oriented while low-level languages are procedurally oriented?

I'm just getting a bit confused about all the language types out there. What's the difference - if there is one - between the high level / low level languages distinction compared to the object-oriented / procedural distinction? A lot of the analogies seem similar.
The high/low level distinction is more about abstraction than paradigm. Typically, the "lower" you are, the more you have to know about the machine you're running on - its memory, file system, and even processor instruction set.
A high-level language puts a layer of abstraction between you and the machine. It handles the gory details. This is both good and bad. Abstraction takes away some worry but also takes away control.
A high-level language can be procedural, object oriented, functional, etc...
Lower-level languages may not provide concepts like object orientation, because object orientation is an abstraction.
High level/low level refers to the perceived 'closeness' of the language to assembler and machine code (assembler is low-level, C is seen as lower level than C++ or Java, etc).
OO and procedural programming are language facilities provided to support a certain way of designing programs (called programming paradigms). They have nothing to do with if the language is high or low level beyond the fact that an OO language tends to not be low level as assembler doesn't know about objects and classes. There are a lot of other paradigms out there as well, such as functional programming.
not really.
c++ for example is object oriented and it is fairly low level.
"High level" and "low level" are somewhat vague terms that people can disagree about. You can take a look at the amount of abstraction a programming language provides by how much code you have to write to accomplish a particular task, then call the languages which need less code higher level. Of course, then you need a way to measure code size.
There isn't necessarily any causation across these two axes ("paradigm" and "level"), but I think the correlation is that logic and functional languages tend to be highest level, followed shortly by object-oriented languages, with procedural languages typically lower-level.
And not part of the question, but I also think that correlationally, dynamically-typed languages tend to be higher-level than statically-typed ones.
I think it might be an interesting visualization for someone to do a three-dimensional scatter plot of programming languages across the three axes: paradigm (logic/functional/oo/procedural) typing (static/dynamic) and level (see e.g. 'Code Complete' for various metrics on measuring level) .
I think a good analogy to make here is this.
Languages which are object oriented do tend to be higher level than purely functional ones. Look at c++ and c. Yeah c++ is still pretty low level, as mentioned by docesam, but c++ is still higher level than it's purely functional older brother, c.
No, its not quite that simple always, as object orientation isn't the only thing that makes a language high-level, but its definitely an indicator as object orientation means more abstraction over real raw machine instructions.
But object orientation isn't enough to determine which language is the highest level.
I'd look at the following things:
Does the language have static or dynamic typing? (Javascript & Python vs Java and c++)
object oriented or not? (c vs c++)
pure text macros or templates? (c vs c++)
Dynamic Binding vs static binding (again Javascript & Python vs Java & c++)
Does the language support named functions or do you have to use line jumps?
Does the language allow for things like comments?
many more
I like to say that - it all boils down to the machine instruction set. So, regardless of how high-level something is represented, it will still boil down to the machine instructions. So, high-level languages are abstractions of ideas, while low-level ones twiddle closer to the hardware.
The analogies are similar because it all boils down to one thing - machine code!