Are there any context-oriented programming language, and what's their use for? - programming-languages

I heard someone talking about Context-Oriented Programming, so I googled it to found out what that means, and it seems like a new paradigm of programming, but also all I found are academic papers talking about the concept.
So I would like to know if there's any language that implements context-orientation and what is this good for?

COP is a programming paradigm supporting software adaptation to the execution context.
It's an alternative to the use of hard-coded conditional statements spread over the application to encode context-dependent behavior.
In the years several COP extensions to various languages have been proposed:
ContextJ and JCop for Java
Context Erlang for Erlang
ContextL for Common Lisp (the first COP extension to a programming language)
SubjectiveC for Objective C
ContextS for Smalltalk
PyContext for Python
ContextR for Ruby
ContextJS for Javascript
and probably many others.
Each concrete language design and implementation comes with different variations of the features of the COP paradigm. For further details you can see A Comparison of Context-oriented
Programming Languages (Malte Appeltauer, Robert Hirschfeld, Michael Haupt, Jens Lincke, Michael Perscheid - 2010).
Also a good introduction / starting point is Context-oriented Programming (Robert Hirschfeld, Pascal Costanza, Oscar Nierstrasz) or Context-Oriented Programming: A Programming Paradigm for Autonomic Systems (Guido Salvaneschi, Carlo Ghezzi, Matteo Pradella - 2013).

Related

Non-Prolog logic programming

Are there any good non-Prolog or Prolog-based logic programming languages ?
Who has or any good experience with it?
I highly recommend The Reasoned Schemer, by Dan Friedman, Oleg Kiselyov, and Will Byrd. It introduces miniKanren, a small (three core operators) logic programming language built atop Scheme. It's a joy to use, particularly with the matche macro that allows unifying pattern matches.
Answer Set Programming is an extremely powerful logic programming paradigm. I've had a lot of success with the clasp/clingo answer set solver.
I was introduced to DLV and models through answer set programming, which is basically logic programming.
Take a look at theorem proof assistants, like Coq, HOL and Isabelle.
Some type systems (e.g., in Agda2) can be regarded as logic programming too.
You might check out CLIPS. It's structured like Lisp (lots of parens) but it's designed for building expert systems; I haven't seen a problem that Prolog solves that CLIPS couldn't. Like Prolog, its based on building facts and then running queries against them.
There's also pretty fast miniKanren implementation written in Clojure, called core.logic.
There are also a few tutorials on using it:
https://github.com/clojure/core.logic/wiki/A-Core.logic-Primer
https://github.com/frenchy64/Logic-Starter/wiki
http://objectcommando.com/blog/2011/11/04/the-magical-island-of-kanren-core-logic-intro-part-1/
http://clojure.com/blog/2011/12/08/lojic-part-two.html
Mercury and Oz spring to mind. There's also Datalog which is a restricted (non-Turing complete) version of Prolog.

Newer programming language than Prolog for logic programming

Is there any newer language than Prolog specialized for logical programming?
Mercury is nice and modern, and resembles prolog.
Mercury is a new logic/functional programming language, which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features. Its highly optimized execution algorithm delivers efficiency far in excess of existing logic programming systems, and close to conventional programming systems. Mercury addresses the problems of large-scale program development, allowing modularity, separate compilation, and numerous optimization/time trade-offs.
There is a quite promising functional logic programming language called Curry. In spite of its newness it should be easy to get used to Curry if you already know Haskell and Prolog as it was directly influenced by these two languages.
Curry combines in a seamless way
features from functional programming
(nested expressions, higher-order
functions, lazy evaluation), logic
programming (logical variables,
partial data structures, built-in
search), and concurrent programming
(concurrent evaluation of expressions
with synchronization on logical
variables).
Don't forget that Prolog is the host for many newer extensions which can be considered languages in their own right. In particular constraint languages like CLP(R), CLP(Q), CLP(FD). More general extensions like CHR, but also many typed approaches.
These languages usually ship as a library in an existing Prolog system. What you get in that setting is often a significantly more mature and stable implementation than from-scratch system can offer. After all, many Prolog systems are almost 30 years old.
Logtalk is an object-oriented logic programming language that extends and leverages the Prolog language with a feature set suitable for programming in the large, focusing in code encapsulation and reuse mechanisms. It's highly portable supporting as a backend compiler most actively maintained Prolog implementations. Other noteworthy features include support for both prototypes and classes, protocols (interfaces), coinduction, component-based programming, event-driven programming, and high-level multi-threading programming. The current distribution include a large set of programming examples, programming tools, libraries, and text editors and syntax highlighters support for programming and publishing source code.
Oz/Mozart is a Multi-paradigm programming language that supports Logic programming as one of it's features. I've never used it so I can't say if it's good. It certainly seems interesting though.
Disclaimer: I work on the Mercury project and would choose Mercury in a choice between Oz/Mozart and Mercury.
None of the other answers has mentioned Picat:
Picat is a simple, and yet powerful, logic-based multi-paradigm programming language aimed for general-purpose applications. Picat is a rule-based language, in which predicates, functions, and actors are defined with pattern-matching rules. Picat incorporates many declarative language features for better productivity of software development, including explicit non-determinism, explicit unification, functions, list comprehensions, constraints, and tabling. Picat also provides imperative language constructs, such as assignments and loops, for programming everyday things. The Picat implementation, which is based on a well-designed virtual machine and incorporates a memory manager that garbage-collects and expands the stacks and data areas when needed, is efficient and scalable. Picat can be used for not only symbolic computations, which is a traditional application domain of declarative languages, but also for scripting and modeling tasks.
Picat looks somewhat similar to Prolog but Picat is a multi-paradigm language:
import util.
input_data(Tri) =>
Lines = read_file_lines("triangle.txt"),
Tri = new_array(Lines.length),
I = 1,
foreach(Line in Lines)
Tri[I] = Line.split().map(to_integer).to_array(),
I := I+1
end.

Essential language paradigms for professional developer

So I guess most (all?) programmers start out learning a mainly imperative/ procedural programming paradigm, and probably learnt some form of object-oriented programming fairly shortly after that. I've read plenty of questions on stackoverflow suggesting functional programming is increasingly important for improved concurrency/ parallelism. Also that programmers should learn many paradigms to improve their skills and broaden their perspectives.
What are some other paradigms (and languages that use it) that are really beneficial to development skills?
There's possibly an argument for looking at a logic language such as Prolog. Other than that, within the universe of functional programming languages there are many varieties (e.g. contrast Haskell, ML, Scala and Scheme). You might want to explore the various dimensions in terms of things like type systems, laziness and syntax.

What do I learn to "enlighten myself with the ways" of functional programming?

I've been coding for a few years now, nothing too complicated. C++ is what I know best. I recently stumbled into Paul Graham's site, coding horror, and now here.
What do I learn to "enlighten myself with the ways" of functional programming? Haskell, Scheme or CLisp?
If you're interested in functional programming, Haskell is the only purely functional language on that list. Common Lisp is a weakly functional mixed-paradigm language, and Scheme is more strongly functional but still not pure. Lisps are interesting for other reasons, but Haskell is pretty much the state of the art for functional programming.
Incidentally, the reason I encourage more strongly functional languages like Haskell is because a large part of "learning functional programming" is learning how to think of your program in a different way. If your language makes it feel natural to write imperatively, it's too easy to fall into that way of thinking and never realize there's a different way to do it.
Of the three, I'd say Scheme is the simplest overall, if that's your main concern. SICP uses Scheme, and is itself a great resource for learning to program the functional way.
However, Common Lisp has many advanced features that make it quite expressive, such as powerful error handling (more powerful than exceptions), multimethods and support for aspect oriented programming.
You might start with one but, in the end, you should study many languages.
All three are good, depends on each person.
If you decide on haskell, this is a great ressource : learnyouahaskell and also real world haskell
As other answers say, all three are good.
But if you decide on Lisp, then I'd suggest you go for Clojure which is perhaps its most recent reincarnation.
'enlighten myself with the ways' of functional programming?
Haskell's the strongest exemplar of the functional style, emphasizing purely functional programming (no side effects), strong static typing, and with a pragmatic implementation with an emphasis on multicore parallelism, while also having a huge community (around 2000 libraries available on http://hackage.haskell.org , and many online resources).
It's somewhat famous for retraining how people think about programming.
But this is advocacy, and not a useful stackoverflow question and answer session. You'll have to decide for yourself what you're looking to learn.
Have you heard of F#, ML or OCaml? These three languages belong to the ML family.
F# is a new ML dialect supported by Microsoft and will be shipped with Visual Studio 2010. The good thing about F# (or other ML languages) is that when you first start you could write imperative code and learn good functional style gradually.
Here's an example I wrote for Project Euler #2. When I first did it, I used imperative style. Later on, I know how to use lazy sequence, which is a powerful functional programming concept.

What are the most important programming languages to know for concepts? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In your opinion, what are the most important languages for a programmer to know? I'm talking about concepts, not about how practical the language is.
List the languages and a reason. For example, Lisp for functional programming, JavaScript for prototype-based OOP, etc.
Must know:
1) C (system programming, understanding of machine architecture)
2) Perl or Python or Ruby (practical day-to-day tasks)
3) Java or C# or C++ (OOP, and quite important to get a job these days)
Really important:
1) Haskell or ML (functional programming; changes the way you think)
2) Lisp or Scheme (power of macros)
Nice additionals:
1) Forth (very low-level, explicit stack operation + joy to write your own interpreter)
2) Assembly languages (know how your CPU works)
3) Erlang (parallel processing)
4) Prolog (logic programming)
5) Smalltalk (true OOP and true interactive developent)
The assembly languages of as many chips as you can learn for low-level knowledge.
C to learn more practical knowledge of low-level workings, since almost all languages are implemented in C.
C++ for object-oriented programming on top of the low-level goodness of C.
Pascal to learn how to work with strong typing.
Java to see how you can shield yourself from low-level concerns.
Perl to learn regular expressions, weak/dynamic typing, and other good things.
Python to see strong/dynamic/duck typing.
Ruby to see how object-orientedness works on top of Perl-esque weak/dynamic typing.
Common Lisp for that functional enlightenment.
Scheme for the emphasis on recursion.
Emacs Lisp so you can extend Emacs.
Haskell to see pure functional programming done right.
APL so you learn how not to write code.
COBOL so you can make mad money maintaining legacy code.
Erlang to really learn about concurrency. (Thanks to Pete Kirkham for correcting me.)
Scala for functional programming on the JVM.
Clojure for a Lisp-like functional language on the JVM.
Prolog to understand logic programming.
D so you can see why all the D fanatics are always so pro-D.
C# so you can program for .NET (and Mono).
F# so you can do functional programming on .NET.
Forth for stack-based languages.
PHP so you can see how not to create a language. (Just kidding. Learn PHP beacause it's really useful for web development.)
JavaScript because it's basically the language for client-side web scripting.
bash for a good, general-purpose scripting language.
Visual Basic so you can read the code your boss wrote. =)
INTERCAL for "fun."
brainfuck so you can torture your friends.
LOLCODE so you can convince them to still be your friends after you subject them to brainfuck.
...And so on.
C for understanding how the most other language(-implementations) and operation systems are implemented
I think the three languages that best combine practicality and coverage of programming concepts would be
C
Python
Javascript
From these languages you can learn low-level system programming, pointers and memory management, static typing, dynamic typing, high-level scripting, event-driven programming, OO programming, functional programming.
Obviously you're not going to get as pure an intro to functional programming as you would with, say, Haskell, but you can learn a lot of the concepts in Python and (especially) Javascript.
It is not the languages rather the paradigms you should know:
procedural (like C, Pascal)
object-oriented (like Java, C++, Smalltalk)
functional (like Lisp, ML, Scala)
If you understood one of these paradigms in one language, it is easy to learn another language in the same paradigm. And there are even more fields specially supported by languages that are important to understand:
parallelism (in Erlang or Scala)
declarative templates (e.g. in C++ or Prolog)
dynamic languages (e.g. JavaScript)
At at last you should always know what goes on under the hoods, so you better have a look at assembler.
I would say:
C or Assembler to understand how the processor work.
Smalltalk (or C#, Java, Python, Ruby, etc) to understand object oriented programming.
Lisp (any Lisp, Scheme, Common Lisp, Clojure) to understand high level programming, meta programming (macros), etc.
Haskell to understand type inference and other functional concepts.
If you are into distributed systems, I'll consider learning Erlang too. Those are the language I recommend learning, even if only superficial, only for the sake of learning even if you never use them to write a real application.
Its best to know a variety. This gives you a better overall perspective of the art of programming, plus, you get to choose the best tool for the job.
My current list would be:-
C - programming close to the machine.
Python - programmers nirvana.
Perl - for when s**t happens.
Java - cause it will keep you in work.
C# - cause it will keep you in work.
lisp, scheme or something functional to get your brain out of a rut.
SQL - for managing large data sets.
JCL, COBOL, VAX DCL, CShell VB - just to remind you how bad things could be!
A good short list:
C for the machine concepts
Haskell for functional programming
Smalltalk (or maybe Ruby or Simula-67) for object-oriented programming
Prolog for logic programming
Icon for backtracking and mind-blowing string processing
Bourne shell for Unix scripting
Might also include
Scheme for macros
Awk or Perl or ... for regular expressions
FORTH for tiny bootstrapping postfix wonderfulness :-)
For concepts, I would choose assembler and Java.
The first because you should know in intimate detail how machines work.
The second because you should understand how to shield yourself from the intimate details of the way machines work :-). By that I mean a language with a rich set of data structures at hand (so really Java could be Python, C++ with Boost and so on).
Well. I'd say learn C and javascript. They are most widely used languages.
You might want to learn Java/some .Net language and/or python/ruby: they're more convenient, tho.
This have the advantage that all those languages are reasonably well designed.
For example, don't learn PHP or C++ because they're a mess. They're used widely, you might want to learn them one day, but they can seriously mess with your mind.
Limbo - a programming language with concurrency and channels, what C should have evolved into. ( see also D, another C successor )
No-one else seems to be mentioning any declarative languages, so here are a few:
Prolog - a declarative language for logic programming
Modelica - a declarative OO language for modelling systems.
XSLT - a declarative language for transforming XML.
For parallelism, you don't get much wider than shader language, and the related OpenCL - typically 512 processors in parallel on a high-end desktop, rather than Erlang's 4 processors in parallel ( though with many scheduled processes ).
This is a good question. I know a lot of people, myself included, get stuck in a rut where we are just churning out code like one would churn out burgers at a McDonald's. Coding becomes too mechanical—we understand how to get things done, but often times we forget why these things get done behind the scenes.
In my world it's been C++/C/ObjectiveC that have taught me the most, even though I write C# every day at work.
For the most part, learning C++ has helped me learn about memory management and how the various objects are stored in memory, etc.—the actual science of programming. What really opened my eyes was the Programming Paradigms class offered at Standford that you can get off of iTunes and I think YouTube.
You already mentioned two, here are a few more:
Java: Java is a good example of OOP 'cause you HAVE to use oop, and it's designed from the ground up to be an OOP language.
BASIC: Although obsolete, it's a good example of procedural languages and it has a very easy syntax.
For web programming: PHP, ANSI-SQL, javascript.
Some people may argue that HTML and CSS are not programming languages. But they are esential for web app development.
For Desktop app development, C++ with the Qt Framework. Qt gives C++ the additional "cross-platform" fizz.
Pascal or Basic for start and to master basics of procedural programming.
At school we learned Haskel for functional programming.
And then one should try assembler or C for getting deep and Java for OOP.
A have no arguments for this - that's only my taste and what I tried.
I would sat C/C++ cause it sets allot of basics for allot of other languages used around the world.
Personally I learned Java/JavaScript->VB(short course fortunately)->C#->C++, with a pinch of PHP and Perl on top of it all. Best part of that line was C# and then moving behind the scene in C++.
Look for a set of different programming languages:
C++ / C# / Java etc.
C / Assembler
Python, Ruby, Lua, Perl etc.
sh, awk, sed, regular expressions
Prolog (or similar)
Haskell / Lisp etc.
It doesn't really matter which ones you choose, but that you choose one from each "category".
Pseudocode for reading/writing documentation. :p
I think knowing C/C++ or any other low level language will help you with understanding the impacts of how managed/script languages works helps. Such as pointers will demystify variable references.
If you want to understand computers and the underlying hardware, C is the single most important language, commonly said to be the lingua franca of computers. The Stackoverflow podcast tends to cover this at least once a week.
There seem to be enough answers on this, so I'll just leave it at that.
You should know a scripting language so that you can prototype your applications faster.
Maybe python/ruby/perl . Groovy is also an alternative if you're a Java guy that likes his java libs.
Alot is already mentioned but I would definitely add C++ (already done) for the following reason:
C++ for learning how to use pointers and get the main idea about them.
Although there is the discussion if c++ is still the 'better' language (all depends on what you want to make really) it never hurts to understand pointers, just in case you do need them ever.
Having a scan through the answers so far I'm surprised I've not seen any mention of actionscript.
I think if you learn some C/C++, then some Java then that should prepare you for pretty much all of the decent languages out there.
I prefer to see my code in action and I find Actionscript 3 (not 2 or 1) along with Flex (which is MXML) great for quickly demoing visual concepts.
So C & Java helps to learn the syntax of the majority of languages.
Actionscript 3 (very similar to java syntax) & MXML for being able to express you code visually very quickly.
C - low level system programming plus to understand generic concepts about how memory is handled, stack, stack frame, heap and so on. These are helpful for understanding higher level languages
C++ - mainly std library (separation of generic algorithms and containers), templates, namespaces, but OO concepts as well. Templates meta programming will give you completely different perspective on writing software, this is compile time execution versus run time execution. Templates inheritance (static vs dynamic polymorphism).
Python - dynamic type system, list comprehension - functional programming (?), no memory management for developer, spaces for indentation
Objective-C - message dispatching (can dispatch to nil), dynamic type system (static as well), late binding, OO concepts
It may sound crazy, but I first learned to program writing VBScript macros for windows. I used a template, which is available here http://vbscript-macro-template.blogspot.com/ and I just added to it and also tried to understand everything that it did. Now, several years later I am writing my own desktop and database applications.
You should start from C and go through C++, Java and the goto WinForms,
Then better goto .NET

Resources